Skip to content
Client
Server

Reference / @open-music-sdk/browser / tBrowserClientOptions

Interface: tBrowserClientOptions ​

Defined in: integrations/browser/src/client.ts:11

Invalid values throw a TypeError when the client is made.

Extends ​

Properties ​

endpoint? ​

ts
readonly optional endpoint?: tFetcherOptions;

Defined in: integrations/browser/src/client.ts:24

The endpoint's own options: a fetch for it, with the credentials or headers it needs, timeoutMs, and refreshAheadSeconds. The client's own fetch is for Apple, and never reaches the endpoint; this one is for the endpoint, and never reaches Apple.


fetch? ​

ts
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 ​

ts
(input, init?): Promise<Response>;

MDN Reference

Parameters ​
input ​

URL | RequestInfo

init? ​

RequestInit

Returns ​

Promise<Response>

Call Signature ​

ts
(input, init?): Promise<Response>;

MDN Reference

Parameters ​
input ​

string | Request | URL

init? ​

RequestInit

Returns ​

Promise<Response>

Inherited from ​

ts
Omit.fetch

onRequest? ​

ts
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

Inherited from ​

ts
Omit.onRequest

onResponse? ​

ts
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 ​

tResponseOutcome

Returns ​

void

Inherited from ​

ts
Omit.onResponse

rateLimit? ​

ts
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.

Inherited from ​

ts
Omit.rateLimit

retry? ​

ts
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.

Inherited from ​

ts
Omit.retry

storefront? ​

ts
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.

Inherited from ​

ts
Omit.storefront

tokenUrl ​

ts
readonly tokenUrl: string | URL;

Defined in: integrations/browser/src/client.ts:18

Where tokenEndpoint of @open-music-sdk/server is mounted. A relative URL resolves against the page's address when the client is made, and stays there: a route the page moves to later, a <base> put into it later, or a change to the URL object later, moves nothing. Where there is no page, as in a server render, a relative URL is left to resolve at the first fetch, which rejects with a TypeError where there is still no page.


userToken? ​

ts
optional userToken?: string | tTokenProvider;

Defined in: packages/core/src/client.ts:101

Binds the client to one listener. Alternatively set userTokenStore and use forUser().

Inherited from ​

ts
Omit.userToken

userTokenStore? ​

ts
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.

Inherited from ​

ts
Omit.userTokenStore

MIT licensed. Not affiliated with, endorsed by, or sponsored by Apple Inc. Apple Music and MusicKit are trademarks of Apple Inc.