npm

Don't miss out on this year's npm Pride t-shirt designs!Order your favorites here »

@nypl/sierra-wrapper

0.3.0 • Public • Published

sierra-wrapper

A basic node wrapper for the III Sierra v3 API

The wrapper currently supports:

  • Authorizing
  • Returning a single, multiple and range Bib records
  • Returning a single, multiple and range Item records
  • Returning item records belonging to a single Bib record

In addition there are general methods that can be used to make any GET or POST request:

-apiGet -apiPost

More endpoint will be added as the need arises.


To use make sure you have your credentials stored in a json file in the format:

{
    "key": "YOURKEY",
    "secret": "YOURSECRET",
    "base": "https://your.domain.name.org/iii/sierra-api/v3/"
}

You then authorize and request by

//  starting v0.2.0 use require ('@nypl/sierra-wrapper') but for versions before that (we encourage you to
//  update to latest and change client to reflect the new require format) use require ('sierra-wrapper')

var wrapper = require('@nypl/sierra-wrapper')

var loadedConfig = wrapper.loadConfig('./path/to/config.json')
wrapper.auth((error, results) => {
  if (error) console.log(error)
  wrapper.requestSingleBib('14628261', (errorBibReq, results) => {
    if (errorBibReq) console.log(errorBibReq)
    console.log(results)
  })
})

You can also set your credentials via environment variables: SIERRA_KEY, SIERRA_SECRET, SIERRA_BASE


Functions

loadConfig(configOrFile)boolean

Loads a config object, passed or from disk

auth(cb)

Requests an auth token from the sierra API and stores it for future use, it also setups a time to renew the token

requestSingleBib(bibId, cb)

Requests a single bib data from the API

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/bibs/17292415?fields=default,fixedFields,varFields,normTitle,normAuthor,orders,locations' }

requestRangeBib(bibIdStart, bibIdEnd, cb)

Requests a bib range from the API

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/bibs/?limit=1&id=17292415&fields=default,fixedFields,varFields,normTitle,normAuthor,orders,locations' }

requestRangeItem(itemIdStart, itemIdEnd, cb)

Requests an item range from the API

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/items/?limit=1&id=17292415&fields=default,fixedFields,varFields,normTitle,normAuthor,orders,locations' }

requestBibItems(bibId, cb)

Requests all the items of a specified bib id Return format: { data: { total: 2, entries: [ [Object], [Object] ] }, url: [ 'https://catalog.library.org/iii/sierra-api/v3/items/?bibIds=17292415&fields=default,fixedFields,varFields&offset=0' ] }

requestMultiBibBasic(bibsIds, cb)

Requests multiple bibs, but no orders or locations

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/bibs/?id=14628261,14628262,14628263,14628264,14628265,14628266,14628267,14628268,14628269,14628270&fields=default,fixedFields,varFields,normTitle,normAuthor' }

requestMultiItemBasic(itemIds, cb)

Requests multiple items

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/items/?id=10000000,10000100,10000200,10000300,10000400,10000500,10000600,10000700,10000800,10000900,10001000&fields=default,fixedFields,varFields' }

loadConfig(configOrFile) ⇒ boolean

Loads a config object, passed or from disk

Kind: global function Returns: boolean - did it load or not

Param Type Description
configOrFile object | string The object with the credentials or a path to a json file with the credentials

auth(cb)

Requests an auth token from the sierra API and stores it for future use, it also setups a time to renew the token

Kind: global function

Param Type Description
cb function callback

promiseAuth(cb)

The same as auth, but returns a promise which resolves to the value of the callback

requestSingleBib(bibId, cb)

Requests a single bib data from the API

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/bibs/17292415?fields=default,fixedFields,varFields,normTitle,normAuthor,orders,locations' }

Kind: global function

Param Type Description
bibId string the bnumber of the bib you want to request
cb function callback

requestRangeBib(bibIdStart, bibIdEnd, cb)

Requests a bib range from the API

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/bibs/?limit=1&id=17292415&fields=default,fixedFields,varFields,normTitle,normAuthor,orders,locations' }

Kind: global function

Param Type Description
bibIdStart string the bnumber of the bib you want to request
bibIdEnd string the bnumber of the bib you want to request
cb function callback

requestRangeItem(itemIdStart, itemIdEnd, cb)

Requests an item range from the API

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/items/?limit=1&id=17292415&fields=default,fixedFields,varFields,normTitle,normAuthor,orders,locations' }

Kind: global function

Param Type Description
itemIdStart string the bnumber of the bib you want to request
itemIdEnd string the bnumber of the bib you want to request
cb function callback

requestBibItems(bibId, cb)

Requests all the items of a specified bib id Return format: { data: { total: 2, entries: [ [Object], [Object] ] }, url: [ 'https://catalog.library.org/iii/sierra-api/v3/items/?bibIds=17292415&fields=default,fixedFields,varFields&offset=0' ] }

Kind: global function

Param Type Description
bibId string the bnumber of the bib you want to request
cb function callback

requestMultiBibBasic(bibsIds, cb)

Requests multiple bibs, but no orders or locations

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/bibs/?id=14628261,14628262,14628263,14628264,14628265,14628266,14628267,14628268,14628269,14628270&fields=default,fixedFields,varFields,normTitle,normAuthor' }

Kind: global function

Param Type Description
bibsIds array an array of bib id strings
cb function callback

requestMultiItemBasic(itemIds, cb)

Requests multiple items

Return format: { data: { total: 1, entries: [ [Object] ] }, url: 'https://catalog.library.org/iii/sierra-api/v3/items/?id=10000000,10000100,10000200,10000300,10000400,10000500,10000600,10000700,10000800,10000900,10001000&fields=default,fixedFields,varFields' }

Kind: global function

Param Type Description
itemIds array array of item ids
cb function callback

apiGet(path, cb)

Makes a get request to ${exports.credsBase}${path} and then returns a promise which resolves or rejects to the value of the callback.

For example apiGet('patrons/1001006', (errorItemReq, results) => { if (errorItemReq) console.log(errorItemReq) return results })

resolves to the result:

{"data":{"total":1,"entries":[{"id":1001006,"expirationDate":"2019-01-07","patronType":10,"patronCodes":{"pcode1":"-","pcode2":"-","pcode3":2,"pcode4":0},"homeLibraryCode":"hd","message":{"code":"-","accountMessages":["LBR6@columbia.edu"]},"blockInfo":{"code":"-"},"moneyOwed":0}]},"url":"https://nypl-sierra-test.iii.com/iii/sierra-api/v3/patrons/1001006"}

apiPost(path, data, cb)

Makes a post request to ${exports.credsBase}${path} and returns a promise resolving to the value of the callback. For example:

apiPost('patrons/1001006/holds/requests', body, (errorItemReq, results) => { if (errorItemReq) return errorItemReq return false }) })

resolves to the result:

{ code: 132, specificCode: 2, httpStatus: 500, name: 'XCirc error', description: 'XCirc error : Bib record cannot be loaded' }

Keywords

none

install

npm i @nypl/sierra-wrapper

Downloadsweekly downloads

8

version

0.3.0

license

Apache-2

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
  • avatar
Report a vulnerability