Reshuffle connectors for eidr.org
npm install reshuffle-eidr-connectornpm install reshuffle-eidr-connector
js
const { Reshuffle, HttpConnector } = require('reshuffle')
const { EIDRConnector } = require('reshuffle-eidr-connector')
const app = new Reshuffle()
const eidr = new EIDRConnector(app, {
userId: process.env.EIDR_USERID,
partyId: process.env.EIDR_PARTYID,
password: process.env.EIDR_PASSWORD,
})
const http = new HttpConnector(app)
http.on({ method: 'GET', path: '/query' }, async (event) => {
const name = (event.req.query.name || '').trim()
if (name.length === 0) {
return event.res.status(400).send('Missing name')
}
try {
const { results } = await eidr.query({ title: { exact: name } })
return event.res.json(results)
} catch (e) {
return event.res.status(e.status).json({
error: e.message,
details: e.details,
})
}
})
app.start(8000)
`
#### Table of Contents
Configuration Configuration options
_Connector actions_:
info Get connector information
query Search for media information
resolve Get information for one media resource
simpleQuery Simple search for media information
##### Configuration options
`js
const app = new Reshuffle()
const eidrConnector = new EIDRConnector(app)
`
This default initialization will allow access to all public available EIDR
functions, including ID resolution. Some functions, including query and
ID registration, require EIDR membership credentials. Credentials can
be passed as an object in the form:
`ts
{
userId: string
partyId: string
password?: string
shaddow?: string
domain?: string
}
`
The userId and partyId are mandatory and provided by EIDR to its members.
Either password or shaddow (the base64 encoded MD5 hash of password) must
also be provided. The domain can used left out in most cases unless there
is a specific reason to use a mirror service.
Credentials can also be passed as a string with the following format:
Eidr .
Credentials can be passed as a second argument to the connector's constructor:
`js
const credentials = { ... }
const eidrConnector = new EIDRConnector(app, credentials)
`
or as the last optional argument to priviledged actions like query.
This method is usedful when building an service or API to allow third patries
to perform queries or other priviledged operations against the EIDR registry.
#### Connector actions
##### Info action
_Definition:_
`
() => {
eidrApiVersion: string,
eidrConnectorVersion: string,
}
`
_Usage:_
`js
const info = await eidrConnector.info()
`
Get connector information.
##### Query action
_Definition:_
`
(
query: object | string,
options?: object,
credentials?: string | object,
) => {
totalMatches: number,
results: object[],
}
`
_Usage:_
`js
const q = '(/FullMetadata/BaseObjectData/ResourceName "abominable")'
// Get first 25 results
const { results } = await eidrConnector.query(q)
// Get results 11 - 20
const { results } = await eidrConnector.query(
q,
{ pageNumber: 2, pageSize: 10 },
)
`
or
`js
const id = '10.5240/DF48-AB62-4486-C185-9E1B-4'
const { results } = await eidrConnector.query({ title: { exact: name } })
`
Search the EIDR database for matches to the query. You can specify the query
using EIDR XML query language or the EIDR Proxy JSON query language.
The optional options object supports the following optional fields:
* pageNumber?: number - Results page number (default is 1)
* pageSize?: number - Results page size (default is 25)
* root?: string - EIDR ID for rooted queries
See the Configuration section above for more details about
access credentials.
##### Resolve action
_Definition:_
`
(
id: string,
) => {
// media information
}
`
_Usage:_
`js
const id = '10.5240/DF48-AB62-4486-C185-9E1B-4'
const info = await eidrConnector.resolve(id)
`
Get the full information for the media resource (movie, tv show etc) with
the specified id. The full information can be very details, as described
in page 21 of the
EIDR API Specification.
##### Simple Query action
_Definition:_
`
(
exprOrObj: string | object,
compareFunction?: (a: object, b: object) => number,
credentials?: string | object,
) => object[]
`
_Usage:_
`js
const id = '10.5240/DF48-AB62-4486-C185-9E1B-4'
const results = await eidrConnector.simpleQuery({
name,
movie: true,
valid: true,
StructuralType: 'Performance',
})
`
Search the EIDR database for matches to the query. See query above
for details.
The Simple Query action does not support pagination and returns the results
array directly to the caller. The results are automatically sorted by
descending order of release date. You can control the sort order by specifying
a compareFunction` that behaves like the one used by