1.1.1 • Published 3 months ago

@nypl/sierra-wrapper v1.1.1

Weekly downloads
1
License
Apache-2
Repository
github
Last release
3 months ago

sierra-wrapper

A basic node wrapper for the III Sierra v3/v6 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 POST PUT or DELETE request:

  • get
  • post
  • deleteRequest
  • put

Usage

Load the client as follows:

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

Authenticating

To configure credentials there are three options:

  1. Store credentials 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

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

wrapper.config('./path/to/config.json')
  1. You can pass in an options object with the same format as the json above, and pass it in to the same function
wrapper.config(options)
  1. You can also set your credentials via environment variables: SIERRA_KEY, SIERRA_SECRET, SIERRA_BASE

Querying

The following retrieves a bunch of bib ids:

const printBibIds = async () => {
  try {
    const bibs = await wrapper.get('bibs')
    console.log('Got bibs:', bibs.entries.map(b => b.id))
  } catch (e) {
    console.log(e.message)
  }
}

API

config(configOrFile) ⇒ boolean

Loads a config object, passed or from disk Returns: boolean - did it load or not

ParamTypeDescription
configOrFileobject | stringThe object with the credentials or a path to a json file with the credentials

authenticate()

Called internally to retrieve an access token before all calls. Requests an auth token from the sierra API and stores it for future use. It automatically reattempts when there is an empty response from Sierra (a not uncommon error).

get(path)

Makes a get request to ${exports.credsBase}${path} and returns the response. It automatically reattempts when there is an empty response from Sierra (a not uncommon error).

resolves to the result:

{"id":1001006,"expirationDate":"2019-01-07","patronType":10,"patronCodes":{"pcode1":"-","pcode2":"-","pcode3":2,"pcode4":0},"homeLibraryCode":"hd","message":{"code":"-","accountMessages":["LBR6@columbia.edu"]}

post(path, data)

Makes a post request to ${exports.credsBase}${path} and returns the response

resolves to the result:

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

put(path, data)

Makes a post request to ${exports.credsBase}${path}. The response is just a status code.

deleteRequest(path)

Makes a delete request to ${exports.credsBase}${path}. The response is just a status code.

getSingleBib(bibId)

Requests a single bib data from the API

Return format: Object

ParamTypeDescription
bibIdstringthe bnumber of the bib you want to request

getRangeBib(bibIdStart, bibIdEnd)

Requests a bib range from the API

Return format: Object

ParamTypeDescription
bibIdStartstringthe bnumber of the bib you want to request
bibIdEndstringthe bnumber of the bib you want to request

getRangeItem(itemIdStart, itemIdEnd)

Requests an item range from the API

Return format: Object

ParamTypeDescription
itemIdStartstringthe bnumber of the bib you want to request
itemIdEndstringthe bnumber of the bib you want to request

getBibItems(bibId)

Requests all the items of a specified bib id Return format: [ Object, Object ]

ParamTypeDescription
bibIdstringthe bnumber of the bib you want to request

getMultiBibBasic(bibsIds)

Requests multiple bibs, but no orders or locations

Return format: Object

ParamTypeDescription
bibsIdsarrayan array of bib id strings

getMultiItemBasic(itemIds)

Requests multiple items

Return format: Object

ParamTypeDescription
itemIdsarrayarray of item ids

Contributing

  1. Cut feature branch from master
  2. Before making pull request, run npm version <update_type>, indicating patch, minor, or major changes, according to semantic versioning
  3. After PR is approved, run npm publish
  4. Go to your package page (https://npmjs.com/package/) to check that the package version has been updated

Testing

Run unit tests via:

npm test

See ./test/installation-test for scripts to validate a release before publication.

1.1.1

3 months ago

1.1.0

4 months ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.3.0

6 years ago

0.2.0

7 years ago