Reference / @open-music-sdk/user-token / KvUserTokenStore
Class: KvUserTokenStore
Defined in: user-token/src/stores.ts:93
Keeps each token under prefix + userId in a key-value namespace, as the namespace stores it. Neither store here encrypts, so whoever can read the namespace reads the tokens: wrap kv to encrypt. Workers KV can take up to a minute for a token just stored or deleted to look that way elsewhere, and Apple's 403 stays the authority.
Implements
tUserTokenStoreAsyncDisposable
Constructors
Constructor
new KvUserTokenStore(kv, options?): KvUserTokenStore;Defined in: user-token/src/stores.ts:104
The namespace and the prefix are checked and taken here, once; the options object is not looked at again.
Parameters
kv
The namespace, or anything with its get, put and delete.
options?
tKvStoreOptions = {}
The prefix each key starts with.
Returns
KvUserTokenStore
Throws
TypeError if kv lacks get, put or delete, options is not a plain object, or prefix is not a string.
Methods
[asyncDispose]()
[asyncDispose](): Promise<void>;Defined in: user-token/src/stores.ts:150
dispose(), for await using: nothing to release.
Returns
Promise<void>
Implementation of
AsyncDisposable.[asyncDispose]delete()
delete(userId): Promise<void>;Defined in: user-token/src/stores.ts:140
Forgets a user's token: removes prefix + userId from the namespace.
Parameters
userId
string
The id it was set under.
Returns
Promise<void>
Throws
Whatever kv.delete rejects with.
Implementation of
dispose()
dispose(): void;Defined in: user-token/src/stores.ts:145
Does nothing: the namespace belongs to the platform, and the tokens in it outlive this store.
Returns
void
get()
get(userId): Promise<string | undefined>;Defined in: user-token/src/stores.ts:119
The token kept for a user, read from the namespace under prefix + userId.
Parameters
userId
string
The id the token was set under.
Returns
Promise<string | undefined>
The token, or undefined when the namespace has nothing there.
Throws
Whatever kv.get rejects with.
Implementation of
set()
set(userId, token): Promise<void>;Defined in: user-token/src/stores.ts:130
Keeps a token for a user, written to the namespace under prefix + userId in place of what is there.
Parameters
userId
string
The id to keep it under: the app's own, as forUser() is given it.
token
string
The Music User Token, stored as the namespace stores a string.
Returns
Promise<void>
Throws
Whatever kv.put rejects with.