@olc-sales/api-client
v1.1.1
Published
Shared OLC service-to-service HTTP clients - JSON API read client and OAuth client-credentials token provider
Readme
@olc-sales/api-client
Shared service-to-service HTTP client pieces, extracted from the near-identical
copies in olc-events, olc-search, olc-notifications, olc-data and
olc-entitlements.
createJsonApiClient(opts)–getResource/getResources/getRelatedagainst an OLC JSON API. 404 on single/related fetches resolves tonull.version: 'auto'uses v2 for capitalised resource types, else v1.maxConcurrentoptionally throttles via Bottleneck. Also hascreateResource(type, data, headers?)/updateResource(type, id, data, headers?)(JSON:API body, 404 also resolves tonull),retryOnAuthFailure(one retry with a freshgetToken()on 401/403) and an optionallogger(info/error). Memoisation is left to the consumer.createServiceToken(tokenUri, clientId, clientSecret)– OAuth client-credentials token provider (cached until 1 min before expiry, concurrent callers share one fetch). Pass it asgetToken.
const { createJsonApiClient, createServiceToken } = require('@olc-sales/api-client')
const identity = createJsonApiClient({
baseUrl: config.api.identity,
applicationId: 'olc-events',
apiKey: config.api.key,
getToken: createServiceToken(`${config.api.identity}/oauth/token`, id, secret)
})axios, qs and bottleneck are peer dependencies.
Build
yarn build # tsc -> dist/