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

oclc-copy-resource

v2.2.1

Published

Accesses OCLC's WMS Copy Resource Service

Downloads

4

Readme

node-oclc-copy-resource

Accesses OCLC's WMS Copy Resource Service, which is a part of the Collection Management API.

Usage

var WSKey = require('oclc-wskey')
var CopyResource = require('oclc-copy-resource')
var user = {
  principalID: 'principalID',
  principalIDNS: 'principalIDNS'
}
var key = new WSKey('public key', 'secret key', user)
var cr = new CopyResource(128807, key)

cr.barcode(12345678, function (err, item) {
  if (err) throw err

  console.log(item)
})

var cr = new CopyResource(instID, wskey)

Creates a new CopyResource instance

cr.read(copyID, callback)

Accesses a single copy via copyID.

cr.search(searchObj[, opts], callback)

Performs a search using either an OCLC number or barcode. searchObj is an object with either oclc or barcode as the key. opts is an object with the keys startIndex and itemsPerPage (defaults to 1 and 10, respectively).

cr.barcode(barcode[, opts], callback)

Wrapper for cr.search({barcode: barcode}, opts, callback).

cr.oclc(oclcNum[, opts], callback)

Wrapper for `cr.search({oclc: oclcNum}, opts, callback)

cr.update(copyID || searchObj, opts, transformFunction, callback)

NOTE this is super experimental and could have bad consequences if not used carefully (like, wipe-away-all-of-your-copy-data-for-an-item bad).

Adds update support. Retrieves the copy resource object using cr.read when a copyID is provided, or cr.search when a search object is provided. The opts parameter is optional and is only passed to search operations. Only barcode searching is provided and is not recommended if updating periodicals or items with many (> 10) copies attached (see below).

transformFunction is a user-provided function that edits the copy resource document (which is passed as its sole parameter). This function should return the updated document, which will then be converted to XML and PUT to the OCLC servers. If a false-y value is returned, callback is passed the formatted results from search and the update is never sent.

callback receives function (err, result) {} and is optional (but note that any errors that occur are passed to this function).

When updating the copy resource document, be sure to stick with OCLC's JSON conventions (elements that are arrays vs. not). The xmlify transform function is a little lenient with some elements, but isn't entirely consistent (I'm workin' on it!).

usage

cr = new CopyResource(128807, wskey)
cr.update(12345678, transform, callback)

// add a note
function transform (doc) {
  doc.holding[0].note.push({type: 'PUBLIC', value: 'Staff Pick, 3/2016'})
  return doc
}

function callback (err, result) {
  if (err) {
    // handle the error
  }

  else {
    // handle the updated copy resource record
    console.log('updated!')
  }
}

Example: Handling items with multiple holdings using a barcode

var search = {barcode: 31542002390221}
cr.update(search, transform, callback)

function transform (doc) {
  var holdings = doc.holding
  holding.forEach(function (h) {
    if (h.pieceDesignation.indexOf(search.barcode) > -1) {
      h.note.push({type: 'PUBLIC', value: 'Staff Pick, 3/2016'})
    }
  })

  doc.holding = holdings
  return doc
}