@sdeck/plugin-spotify 0.0.0-stage → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +106 -0
- package/dist/api.d.ts.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1316 -0
- package/dist/index.js.map +12 -0
- package/dist/panels.d.ts +11 -0
- package/dist/panels.d.ts.map +1 -0
- package/package.json +60 -4
- package/src/api.ts +425 -0
- package/src/index.tsx +873 -0
- package/src/panels.tsx +261 -0
- package/README.md +0 -3
package/dist/api.d.ts
ADDED
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
export declare const SCOPES: string[];
|
|
2
|
+
export interface Endpoints {
|
|
3
|
+
accounts: string;
|
|
4
|
+
api: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const SPOTIFY: Endpoints;
|
|
7
|
+
export declare function createPkce(): {
|
|
8
|
+
verifier: string;
|
|
9
|
+
challenge: string;
|
|
10
|
+
};
|
|
11
|
+
export interface SignIn {
|
|
12
|
+
/** Where to send the user. */
|
|
13
|
+
url: string;
|
|
14
|
+
/** Resolves once they approved and the tokens are saved. */
|
|
15
|
+
done: Promise<void>;
|
|
16
|
+
cancel(): void;
|
|
17
|
+
}
|
|
18
|
+
export interface ClientOptions {
|
|
19
|
+
clientId: () => string;
|
|
20
|
+
tokens: {
|
|
21
|
+
get(): string | undefined;
|
|
22
|
+
set(refresh: string | undefined): Promise<void>;
|
|
23
|
+
};
|
|
24
|
+
endpoints?: Endpoints;
|
|
25
|
+
fetch?: typeof fetch;
|
|
26
|
+
}
|
|
27
|
+
export type Method = "GET" | "PUT" | "POST" | "DELETE";
|
|
28
|
+
export declare class RateLimited extends Error {
|
|
29
|
+
readonly retryAfterMs: number;
|
|
30
|
+
constructor(retryAfterMs: number);
|
|
31
|
+
}
|
|
32
|
+
/** Not signed in: there is nothing to retry until the user signs in. */
|
|
33
|
+
export declare class SignedOut extends Error {
|
|
34
|
+
constructor(message?: string);
|
|
35
|
+
}
|
|
36
|
+
export declare class SpotifyClient {
|
|
37
|
+
#private;
|
|
38
|
+
constructor(options: ClientOptions);
|
|
39
|
+
get signedIn(): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Starts signing in: listens on `http://127.0.0.1:<port>/callback` (which must be one of the
|
|
42
|
+
* app's redirect URIs) until the user approves, or five minutes pass.
|
|
43
|
+
*/
|
|
44
|
+
signIn(port: number, timeoutMs?: number): SignIn;
|
|
45
|
+
signOut(): Promise<void>;
|
|
46
|
+
/**
|
|
47
|
+
* Calls the API; resolves with the JSON answer, or `undefined` for an empty one. `body` is sent
|
|
48
|
+
* as JSON.
|
|
49
|
+
*/
|
|
50
|
+
request(method: Method, path: string, query?: Record<string, string>, body?: unknown): Promise<unknown>;
|
|
51
|
+
}
|
|
52
|
+
export interface Player {
|
|
53
|
+
playing: boolean;
|
|
54
|
+
/** The track or episode's `spotify:` URI, `""` when nothing is playing. */
|
|
55
|
+
uri: string;
|
|
56
|
+
track: string;
|
|
57
|
+
artist: string;
|
|
58
|
+
album: string;
|
|
59
|
+
/** Cover art URL (about 300 px), `""` when there is none. */
|
|
60
|
+
art: string;
|
|
61
|
+
/** 0–100 through the track. */
|
|
62
|
+
progress: number;
|
|
63
|
+
positionMs: number;
|
|
64
|
+
durationMs: number;
|
|
65
|
+
volume: number | undefined;
|
|
66
|
+
shuffle: boolean;
|
|
67
|
+
repeat: "off" | "track" | "context";
|
|
68
|
+
device: string;
|
|
69
|
+
deviceId: string;
|
|
70
|
+
/** The playlist, album or artist being played, `""` when there is none. */
|
|
71
|
+
context: string;
|
|
72
|
+
}
|
|
73
|
+
export declare const IDLE: Player;
|
|
74
|
+
/** Reads the answer of `GET /me/player` (empty when nothing is playing anywhere). */
|
|
75
|
+
export declare function parsePlayer(body: unknown): Player;
|
|
76
|
+
declare const KINDS: readonly ["track", "episode", "album", "playlist", "artist", "show"];
|
|
77
|
+
export type ItemKind = (typeof KINDS)[number];
|
|
78
|
+
/**
|
|
79
|
+
* The `spotify:` URI in a URI or an open.spotify.com link (`…/intl-de/track/<id>?si=…`), or
|
|
80
|
+
* undefined if it is neither.
|
|
81
|
+
*/
|
|
82
|
+
export declare function spotifyUri(text: string): {
|
|
83
|
+
uri: string;
|
|
84
|
+
kind: ItemKind;
|
|
85
|
+
} | undefined;
|
|
86
|
+
/** What `PUT /me/player/play` needs to play a URI: one item, or a list to play through. */
|
|
87
|
+
export declare function playBody(uri: string, kind: ItemKind): Record<string, unknown>;
|
|
88
|
+
export interface Playlist {
|
|
89
|
+
id: string;
|
|
90
|
+
uri: string;
|
|
91
|
+
name: string;
|
|
92
|
+
/** The user may add to it: theirs, or one they collaborate on. */
|
|
93
|
+
writable: boolean;
|
|
94
|
+
}
|
|
95
|
+
/** Reads a page of `GET /me/playlists`; `me` is the user's id. */
|
|
96
|
+
export declare function parsePlaylists(body: unknown, me: string): Playlist[];
|
|
97
|
+
export interface Device {
|
|
98
|
+
id: string;
|
|
99
|
+
name: string;
|
|
100
|
+
type: string;
|
|
101
|
+
active: boolean;
|
|
102
|
+
}
|
|
103
|
+
/** Reads `GET /me/player/devices`, leaving out devices that can't be controlled. */
|
|
104
|
+
export declare function parseDevices(body: unknown): Device[];
|
|
105
|
+
export {};
|
|
106
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,MAAM,UAUlB,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,GAAG,EAAE,MAAM,CAAC;CACb;AAED,eAAO,MAAM,OAAO,EAAE,SAGrB,CAAC;AAEF,wBAAgB,UAAU;;;EAIzB;AAED,MAAM,WAAW,MAAM;IACrB,8BAA8B;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,4DAA4D;IAC5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IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,GAAG,QAAQ,EAAE,CAoBpE;AAED,MAAM,WAAW,MAAM;IACrB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,oFAAoF;AACpF,wBAAgB,YAAY,CAAC,IAAI,EAAE,OAAO,GAAG,MAAM,EAAE,CAapD"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { type Player } from "./api.ts";
|
|
2
|
+
export * from "./api.ts";
|
|
3
|
+
export declare const DEFAULT_PORT = 43821;
|
|
4
|
+
/** The repeat mode after `mode`, in the order Spotify's own button uses. */
|
|
5
|
+
export declare function nextRepeat(mode: Player["repeat"]): Player["repeat"];
|
|
6
|
+
declare const _default: import("@sdeck/plugin").PluginDef;
|
|
7
|
+
export default _default;
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AAmBA,OAAO,EAEL,KAAK,MAAM,EAWZ,MAAM,UAAU,CAAC;AAIlB,cAAc,UAAU,CAAC;AAEzB,eAAO,MAAM,YAAY,QAAQ,CAAC;AAwZlC,4EAA4E;AAC5E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,CAEnE"}
|