Simple client library for OAI-PMH
npm install @indexdata/oai-pmhCopyright (C) 2022 Index Data Aps.
This software is distributed under the terms of the Apache License, Version 2.0. See the file "LICENSE" for more information.
This is a very simple
OAI-PMH
client library, written because
all the various existing libraries known to Node
are abandonware or undocumented.
It exists primarily for the use ofui-harvester-admin
but should be of wider utility.
First, create an OAI-PMH client object associated with a specific service:
import OaiPmh from '@indexdata/oai-pmh';
const oaiPmh = new OaiPmh('https://ora.ox.ac.uk/oai2');
Now you can use it to ask the server to identify itself, supply a list of sets, etc:
const identity = await oaiPmh.identify();
const sets = await oaiPmh.listSets();
const formats = await oaiPmh.listMetadataFormats();
At present, only the Identify, ListSets and ListMetadataFormat verbs are supported: we will add others as we have a need for them. The optional parameters to the second and third of these are ignored.
All methods return a promise that resolves to a JavaScript object containing the data returned from the service. So for example:
formats.ListMetadataFormats[0].metadataFormat.map(x => {
console.log(prefix '${x.metadataPrefix} -> ${});
});
See the very simple example code.
The package file includes a dependencies on timers and stream even though we don't use those packages directly. This is because the xml2js library needs them but doesn't have dependencies, probably because it's relying on the behavior of Babel before v5.x which used to polyfill various node.js core modules.
Understandably, when a browser loads the FOLIO SPA from one origin, it's unhappy about letting that SPA make OAI-PMH requests (or any HTTP requests) to other origins. We will need to figure out a way to address this in production, but for development it suffices to use thelocal-cors-anywhere
web proxy. Install globally withyarn global add local-cors-anywhere
and run asenv PORT=8081 ~/.yarn/bin/local-cors-anywhere.
Then prefix OAI-PMH service URLs withhttp://localhost:8081/,
so that the SPA accesses services at URLs like
http://localhost:8081/https://ora.ox.ac.uk/oai2