Reference / @open-music-sdk/core / tClientOptions
Interface: tClientOptions
Defined in: packages/core/src/client.ts:94
What createClient takes. Only developerToken is needed. Each option is checked at creation, so a mistake is a TypeError there and not on the first request; what a provider gives, and what a store holds, are checked when used.
Only undefined leaves an option out: null is a mistake like any other value. An option is one the object holds itself. One it inherits, or that other code has put on Object.prototype, is not one.
Properties
developerToken
developerToken: string | tTokenProvider;Defined in: packages/core/src/client.ts:99
The developer token, or a function that gives one when a request needs it, such as a minter or a fetcher from @open-music-sdk/developer-token. A string is checked here to be a token; a function's answer where it is sent.
fetch?
optional fetch?: {
(input, init?): Promise<Response>;
(input, init?): Promise<Response>;
};Defined in: packages/core/src/client.ts:107
What sends each request. Default: the global fetch.
Call Signature
(input, init?): Promise<Response>;Parameters
input
RequestInfo | URL
init?
RequestInit
Returns
Promise<Response>
Call Signature
(input, init?): Promise<Response>;Parameters
input
string | Request | URL
init?
RequestInit
Returns
Promise<Response>
onRequest?
optional onRequest?: (req) => void;Defined in: packages/core/src/client.ts:116
Called just before each attempt is sent, with the final Request. Its headers hold the developer token and, where it is sent, the Music User Token, so a hook that logs requests logs both tokens.
Parameters
req
Request
Returns
void
onResponse?
optional onResponse?: (res, req, outcome) => void;Defined in: packages/core/src/client.ts:123
Called once per response, after the client is done with it: the body has been read and the outcome decided. outcome.error is what the request will throw unless a retry succeeds. The body has been read, so take it from outcome.body, not from res.json(). req is the Request onRequest is handed, token headers and all, so a hook that logs it logs the tokens.
Parameters
res
Response
req
Request
outcome
Returns
void
rateLimit?
optional rateLimit?: tRateLimiter;Defined in: packages/core/src/client.ts:111
Opt-in token bucket. Share one instance across every client using the same developer token.
retry?
optional retry?: false | tRetryPolicy;Defined in: packages/core/src/client.ts:109
false disables retries; a plain object sets the policy field by field. Default: 2 attempts, 250 ms base, 4 s cap, full jitter, Retry-After honoured.
storefront?
optional storefront?: string;Defined in: packages/core/src/client.ts:105
Catalog storefront, by its id, such as "us": one segment of a path. Without it, storefront() resolves the listener's from /v1/me/storefront.
userToken?
optional userToken?: string | tTokenProvider;Defined in: packages/core/src/client.ts:101
Binds the client to one listener. Alternatively set userTokenStore and use forUser().
userTokenStore?
optional userTokenStore?: tUserTokenStore;Defined in: packages/core/src/client.ts:103
Where forUser() finds a listener's token. Needs get, set and delete; the client itself calls only get.