@wwdrew/expo-spotify-sdk
Version:
Expo module wrapping the native Spotify iOS (v5) and Android (v4) SDKs for OAuth authentication and App Remote playback control
55 lines • 1.92 kB
TypeScript
/**
* The six Spotify resource types accepted by App Remote APIs.
*/
export type SpotifyResourceType = "track" | "album" | "playlist" | "artist" | "show" | "episode";
/**
* Branded string type for Spotify URIs (`spotify:<type>:<id>`).
*
* Construct via `SpotifyURI.from(str)` (validates) or
* `SpotifyURI.unsafe(str)` (skips validation — use only when the source is
* trusted, e.g. a URI that came back from the Spotify SDK itself).
*/
export type SpotifyURI = string & {
readonly __brand: "SpotifyURI";
};
/**
* Helpers for constructing, validating and decomposing {@link SpotifyURI}
* values.
*
* @example
* ```ts
* const uri = SpotifyURI.from("spotify:track:4uLU6hMCjMI75M1A2tKUQC");
* const { type, id } = SpotifyURI.parse(uri);
* const rebuilt = SpotifyURI.build("track", id);
* ```
*/
export declare const SpotifyURI: {
/**
* Cast `uri` to {@link SpotifyURI} after validation.
* Throws a plain `Error` if the URI does not match the `spotify:<type>:<id>`
* format — use at app-code call sites where you want early feedback.
*/
readonly from: (uri: string) => SpotifyURI;
/**
* Cast `uri` to {@link SpotifyURI} without validation.
* Use only for URIs that originate from the Spotify SDK itself (i.e. already
* known-valid values coming back over the bridge).
*/
readonly unsafe: (uri: string) => SpotifyURI;
/**
* Decompose a {@link SpotifyURI} into its `{ type, id }` parts.
*/
readonly parse: (uri: SpotifyURI) => {
type: SpotifyResourceType;
id: string;
};
/**
* Build a {@link SpotifyURI} from a resource type and ID.
*/
readonly build: (type: SpotifyResourceType, id: string) => SpotifyURI;
/**
* Type-guard: returns `true` if `uri` is a valid Spotify URI string.
*/
readonly isValid: (uri: string) => uri is SpotifyURI;
};
//# sourceMappingURL=index.d.ts.map