npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@nypl/nypl-data-api-client

v2.0.0

Published

Simple client for interacting with NYPL's internal data api

Downloads

1,649

Readme

NYPL Data API Client

Node module for interacting with the NYPL Platform API

Installation

npm i @nypl/nypl-data-api-client --save

Usage

Initialize a client (see ClientConstructorOptions):

const NyplClient = require('@nypl/nypl-data-api-client')
const client = new NyplClient({
  base_url: 'http://[FQDN].com/api/v0.1/',
  oauth_key: 'oauth-key',
  oauth_secret 'top-secret-oauth-secret',
  oauth_url: 'https://[fqdn]/'
})

Docs

See usage.md for complete documentation of Client methods and use.

(Usage doc is generated via ./node_modules/.bin/jsdoc2md lib/client.js > usage.md.)

Examples

To authenticate and fetch a bib (all GETs authenticate first, by default):

  try {
    const resp = await client.get('bibs/sierra-nypl/17746307')
    const bib = resp.data
    console.log('Got bib: ' + bib.title)
  } catch (e) => {
    console.error('Error authenticating or fetching bib: ', e)
  }

To get the "Item" stream schema, which doesn't require authentication:

  const resp = await client.get('current-schemas/Item', { authenticate: false })
  const schema = resp.data
  // Now we can build an avro encoder by parsing the escaped "schema" prop:
  const avroType = require('avsc').parse(JSON.parse(schema.schema))

To get patron id 12345678 (note you must auth with an account that has the 'read:patron' role):

  const resp = await client.get('patrons/12345678')
  const patron = resp.data
  if (!patron) throw new Error('Could not find patron')

  const pType = Object.keys(patron.fixedFields).map((key) => patron.fixedFields[key])
    .filter((fixed) => fixed.label === 'Patron Type')[0]
    .value
  const name = patron.names[0]
  const barcode = patron.barCodes[0]

  console.log('Patron:')
  console.log('  Name: ' + name)
  console.log('  Barcode: ' + barcode)
  console.log('  Patron Type: ' + pType)

To POST a new "TestSchema" schema:

  const resp = await client.post('schemas/TestSchema', { name: "TestSchema", type: "record", fields: [ ... ] })
  if (resp.data.stream !== 'TestSchema') throw Error('Error creating schema...')

CLI

A small CLI exists for common tasks.

Set up:

git clone [email protected]:NYPL/node-nypl-data-api-client.git
cd node-nypl-data-api-client
nvm use; npm i

cp .env-example .env
# Fill in missing details in .env

To fetch the first 25 bibs:

./bin/nypl-data-api.js get bibs

To fetch a specific bib:

./bin/nypl-data-api.js get bibs/sierra-nypl/11040445

To create a hold-request:

./bin/nypl-data-api.js post hold-requests '{ "record": "1234", "patron": ... }'

To specify a different .env, use the --envfile param (e.g. --envfile .env-qa)

A special schema command is provided for updating schemas. To post a new schema, run the following to upload the content of the given jsonfile to schemas/[name]

./bin/nypl-data-api.js schema post [name] [jsonfile]

Contributing

  1. Cut feature branchs from main
  2. After review, merge to main
  3. Bump version in package.json & note changes in CHANGELOG.md
  4. git tag -a v[version]
  5. npm publish

Testing

npm test