@keystrokehq/spotify 0.0.1
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/LICENSE +21 -0
- package/README.md +113 -0
- package/dist/_official/index.d.mts +32 -0
- package/dist/_official/index.mjs +3 -0
- package/dist/_runtime/index.d.mts +1 -0
- package/dist/_runtime/index.mjs +1 -0
- package/dist/albums.d.mts +265 -0
- package/dist/albums.mjs +72 -0
- package/dist/artists.d.mts +237 -0
- package/dist/artists.mjs +84 -0
- package/dist/audio-analysis.d.mts +91 -0
- package/dist/audio-analysis.mjs +19 -0
- package/dist/audio-features.d.mts +61 -0
- package/dist/audio-features.mjs +31 -0
- package/dist/audiobooks.d.mts +176 -0
- package/dist/audiobooks.mjs +59 -0
- package/dist/browse.d.mts +74 -0
- package/dist/browse.mjs +31 -0
- package/dist/categories.d.mts +118 -0
- package/dist/categories.mjs +66 -0
- package/dist/chapters.d.mts +163 -0
- package/dist/chapters.mjs +39 -0
- package/dist/client.d.mts +3486 -0
- package/dist/client.mjs +758 -0
- package/dist/connection.d.mts +2 -0
- package/dist/connection.mjs +3 -0
- package/dist/episodes.d.mts +149 -0
- package/dist/episodes.mjs +39 -0
- package/dist/errors.d.mts +34 -0
- package/dist/errors.mjs +89 -0
- package/dist/events.d.mts +613 -0
- package/dist/events.mjs +55 -0
- package/dist/factory-tZba6Hij.mjs +8 -0
- package/dist/follow.d.mts +83 -0
- package/dist/follow.mjs +65 -0
- package/dist/genres.d.mts +14 -0
- package/dist/genres.mjs +19 -0
- package/dist/index.d.mts +1 -0
- package/dist/index.mjs +1 -0
- package/dist/integration-DQ5Egd4f.d.mts +41 -0
- package/dist/integration-ykoImsCq.mjs +78 -0
- package/dist/library.d.mts +472 -0
- package/dist/library.mjs +225 -0
- package/dist/markets.d.mts +14 -0
- package/dist/markets.mjs +20 -0
- package/dist/me.d.mts +169 -0
- package/dist/me.mjs +58 -0
- package/dist/messaging.d.mts +1 -0
- package/dist/messaging.mjs +1 -0
- package/dist/operations.d.mts +6 -0
- package/dist/operations.mjs +237 -0
- package/dist/player.d.mts +877 -0
- package/dist/player.mjs +220 -0
- package/dist/playlists.d.mts +546 -0
- package/dist/playlists.mjs +243 -0
- package/dist/recommendations.d.mts +144 -0
- package/dist/recommendations.mjs +137 -0
- package/dist/schemas.d.mts +3312 -0
- package/dist/schemas.mjs +460 -0
- package/dist/search.d.mts +389 -0
- package/dist/search.mjs +42 -0
- package/dist/shows.d.mts +159 -0
- package/dist/shows.mjs +59 -0
- package/dist/tracks.d.mts +173 -0
- package/dist/tracks.mjs +37 -0
- package/dist/triggers.d.mts +45 -0
- package/dist/triggers.mjs +201 -0
- package/dist/users.d.mts +35 -0
- package/dist/users.mjs +20 -0
- package/dist/verification.d.mts +1 -0
- package/dist/verification.mjs +1 -0
- package/package.json +187 -0
package/dist/player.mjs
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
import { spotifyDeviceSchema, spotifyIdSchema, spotifyMarketSchema, spotifyMutationSuccessSchema, spotifyPlaybackStateSchema, spotifyQueueSchema, spotifyRecentlyPlayedPageSchema, spotifyUriSchema } from "./schemas.mjs";
|
|
2
|
+
import { createSpotifyClient } from "./client.mjs";
|
|
3
|
+
import { t as spotifyOperation } from "./factory-tZba6Hij.mjs";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
|
|
6
|
+
//#region src/player.ts
|
|
7
|
+
const emptyInputSchema = z.object({});
|
|
8
|
+
const playbackTypesSchema = z.array(z.enum(["track", "episode"])).min(1).optional();
|
|
9
|
+
const deviceIdSchema = spotifyIdSchema.optional();
|
|
10
|
+
const currentlyPlayingInputSchema = z.object({
|
|
11
|
+
market: spotifyMarketSchema.optional(),
|
|
12
|
+
additionalTypes: playbackTypesSchema
|
|
13
|
+
});
|
|
14
|
+
const transferPlaybackInputSchema = z.object({
|
|
15
|
+
deviceIds: z.array(spotifyIdSchema).min(1).max(50),
|
|
16
|
+
play: z.boolean().optional()
|
|
17
|
+
});
|
|
18
|
+
const playbackOffsetSchema = z.object({
|
|
19
|
+
position: z.number().int().nonnegative().optional(),
|
|
20
|
+
uri: spotifyUriSchema.optional()
|
|
21
|
+
}).refine((value) => value.position !== void 0 || value.uri !== void 0, { error: "Playback offset must include a position or uri." });
|
|
22
|
+
const startOrResumePlaybackInputSchema = z.object({
|
|
23
|
+
deviceId: deviceIdSchema,
|
|
24
|
+
contextUri: spotifyUriSchema.optional(),
|
|
25
|
+
uris: z.array(spotifyUriSchema).min(1).max(100).optional(),
|
|
26
|
+
offset: playbackOffsetSchema.optional(),
|
|
27
|
+
positionMs: z.number().int().nonnegative().optional()
|
|
28
|
+
});
|
|
29
|
+
const withOptionalDeviceIdSchema = z.object({ deviceId: deviceIdSchema });
|
|
30
|
+
const seekToPositionInputSchema = withOptionalDeviceIdSchema.extend({ positionMs: z.number().int().nonnegative() });
|
|
31
|
+
const repeatModeInputSchema = withOptionalDeviceIdSchema.extend({ state: z.enum([
|
|
32
|
+
"track",
|
|
33
|
+
"context",
|
|
34
|
+
"off"
|
|
35
|
+
]) });
|
|
36
|
+
const playbackVolumeInputSchema = withOptionalDeviceIdSchema.extend({ volumePercent: z.number().int().min(0).max(100) });
|
|
37
|
+
const shuffleModeInputSchema = withOptionalDeviceIdSchema.extend({ state: z.boolean() });
|
|
38
|
+
const getRecentlyPlayedInputSchema = z.object({
|
|
39
|
+
limit: z.number().int().positive().max(50).optional(),
|
|
40
|
+
after: z.number().int().nonnegative().optional(),
|
|
41
|
+
before: z.number().int().nonnegative().optional()
|
|
42
|
+
}).refine((value) => !(value.after !== void 0 && value.before !== void 0), { error: "Specify only one of after or before." });
|
|
43
|
+
const addToQueueInputSchema = withOptionalDeviceIdSchema.extend({ uri: spotifyUriSchema });
|
|
44
|
+
const availableDevicesResponseSchema = z.object({ devices: z.array(spotifyDeviceSchema) });
|
|
45
|
+
function hasPlaybackBody(input) {
|
|
46
|
+
return input.contextUri !== void 0 || input.uris !== void 0 || input.offset !== void 0 || input.positionMs !== void 0;
|
|
47
|
+
}
|
|
48
|
+
const getPlaybackState = spotifyOperation({
|
|
49
|
+
id: "get_playback_state",
|
|
50
|
+
name: "Get Playback State",
|
|
51
|
+
description: "Fetch the current Spotify playback state for the connected account.",
|
|
52
|
+
input: z.object({ market: spotifyMarketSchema.optional() }),
|
|
53
|
+
output: spotifyPlaybackStateSchema.nullable(),
|
|
54
|
+
run: async (input, credentials) => {
|
|
55
|
+
return createSpotifyClient(credentials).player.getPlaybackState(input.market);
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
const transferPlayback = spotifyOperation({
|
|
59
|
+
id: "transfer_playback",
|
|
60
|
+
name: "Transfer Playback",
|
|
61
|
+
description: "Transfer Spotify playback to another available device.",
|
|
62
|
+
input: transferPlaybackInputSchema,
|
|
63
|
+
output: spotifyMutationSuccessSchema,
|
|
64
|
+
needsApproval: true,
|
|
65
|
+
run: async (input, credentials) => {
|
|
66
|
+
return createSpotifyClient(credentials).player.transferPlayback(input);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
const getAvailableDevices = spotifyOperation({
|
|
70
|
+
id: "get_available_devices",
|
|
71
|
+
name: "Get Available Devices",
|
|
72
|
+
description: "List Spotify devices available for playback.",
|
|
73
|
+
input: emptyInputSchema,
|
|
74
|
+
output: availableDevicesResponseSchema,
|
|
75
|
+
run: async (_input, credentials) => {
|
|
76
|
+
return createSpotifyClient(credentials).player.getAvailableDevices();
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
const getCurrentlyPlaying = spotifyOperation({
|
|
80
|
+
id: "get_currently_playing",
|
|
81
|
+
name: "Get Currently Playing",
|
|
82
|
+
description: "Fetch the currently playing Spotify track or episode, if any.",
|
|
83
|
+
input: currentlyPlayingInputSchema,
|
|
84
|
+
output: spotifyPlaybackStateSchema.nullable(),
|
|
85
|
+
run: async (input, credentials) => {
|
|
86
|
+
return createSpotifyClient(credentials).player.getCurrentlyPlaying({
|
|
87
|
+
market: input.market,
|
|
88
|
+
additional_types: input.additionalTypes
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
const startOrResumePlayback = spotifyOperation({
|
|
93
|
+
id: "start_or_resume_playback",
|
|
94
|
+
name: "Start Or Resume Playback",
|
|
95
|
+
description: "Start or resume Spotify playback on an active or selected device.",
|
|
96
|
+
input: startOrResumePlaybackInputSchema,
|
|
97
|
+
output: spotifyMutationSuccessSchema,
|
|
98
|
+
needsApproval: true,
|
|
99
|
+
run: async (input, credentials) => {
|
|
100
|
+
const client = createSpotifyClient(credentials);
|
|
101
|
+
const body = hasPlaybackBody(input) ? {
|
|
102
|
+
contextUri: input.contextUri,
|
|
103
|
+
uris: input.uris,
|
|
104
|
+
offset: input.offset,
|
|
105
|
+
positionMs: input.positionMs
|
|
106
|
+
} : void 0;
|
|
107
|
+
return client.player.startOrResumePlayback(body, input.deviceId);
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
const pausePlayback = spotifyOperation({
|
|
111
|
+
id: "pause_playback",
|
|
112
|
+
name: "Pause Playback",
|
|
113
|
+
description: "Pause Spotify playback on the current or selected device.",
|
|
114
|
+
input: withOptionalDeviceIdSchema,
|
|
115
|
+
output: spotifyMutationSuccessSchema,
|
|
116
|
+
needsApproval: true,
|
|
117
|
+
run: async (input, credentials) => {
|
|
118
|
+
return createSpotifyClient(credentials).player.pausePlayback(input.deviceId);
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
const skipToNext = spotifyOperation({
|
|
122
|
+
id: "skip_to_next",
|
|
123
|
+
name: "Skip To Next",
|
|
124
|
+
description: "Skip to the next Spotify item in the active queue.",
|
|
125
|
+
input: withOptionalDeviceIdSchema,
|
|
126
|
+
output: spotifyMutationSuccessSchema,
|
|
127
|
+
needsApproval: true,
|
|
128
|
+
run: async (input, credentials) => {
|
|
129
|
+
return createSpotifyClient(credentials).player.skipToNext(input.deviceId);
|
|
130
|
+
}
|
|
131
|
+
});
|
|
132
|
+
const skipToPrevious = spotifyOperation({
|
|
133
|
+
id: "skip_to_previous",
|
|
134
|
+
name: "Skip To Previous",
|
|
135
|
+
description: "Skip to the previous Spotify item in the active queue.",
|
|
136
|
+
input: withOptionalDeviceIdSchema,
|
|
137
|
+
output: spotifyMutationSuccessSchema,
|
|
138
|
+
needsApproval: true,
|
|
139
|
+
run: async (input, credentials) => {
|
|
140
|
+
return createSpotifyClient(credentials).player.skipToPrevious(input.deviceId);
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
const seekToPosition = spotifyOperation({
|
|
144
|
+
id: "seek_to_position",
|
|
145
|
+
name: "Seek To Position",
|
|
146
|
+
description: "Seek the currently playing Spotify item to a new playback position.",
|
|
147
|
+
input: seekToPositionInputSchema,
|
|
148
|
+
output: spotifyMutationSuccessSchema,
|
|
149
|
+
needsApproval: true,
|
|
150
|
+
run: async (input, credentials) => {
|
|
151
|
+
return createSpotifyClient(credentials).player.seekToPosition(input.positionMs, input.deviceId);
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
const setRepeatMode = spotifyOperation({
|
|
155
|
+
id: "set_repeat_mode",
|
|
156
|
+
name: "Set Repeat Mode",
|
|
157
|
+
description: "Set Spotify repeat mode for the current or selected device.",
|
|
158
|
+
input: repeatModeInputSchema,
|
|
159
|
+
output: spotifyMutationSuccessSchema,
|
|
160
|
+
needsApproval: true,
|
|
161
|
+
run: async (input, credentials) => {
|
|
162
|
+
return createSpotifyClient(credentials).player.setRepeatMode(input.state, input.deviceId);
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
const setPlaybackVolume = spotifyOperation({
|
|
166
|
+
id: "set_playback_volume",
|
|
167
|
+
name: "Set Playback Volume",
|
|
168
|
+
description: "Set Spotify playback volume on the current or selected device.",
|
|
169
|
+
input: playbackVolumeInputSchema,
|
|
170
|
+
output: spotifyMutationSuccessSchema,
|
|
171
|
+
needsApproval: true,
|
|
172
|
+
run: async (input, credentials) => {
|
|
173
|
+
return createSpotifyClient(credentials).player.setPlaybackVolume(input.volumePercent, input.deviceId);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
const setShuffleMode = spotifyOperation({
|
|
177
|
+
id: "set_shuffle_mode",
|
|
178
|
+
name: "Set Shuffle Mode",
|
|
179
|
+
description: "Enable or disable Spotify shuffle mode.",
|
|
180
|
+
input: shuffleModeInputSchema,
|
|
181
|
+
output: spotifyMutationSuccessSchema,
|
|
182
|
+
needsApproval: true,
|
|
183
|
+
run: async (input, credentials) => {
|
|
184
|
+
return createSpotifyClient(credentials).player.setShuffleMode(input.state, input.deviceId);
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
const getRecentlyPlayed = spotifyOperation({
|
|
188
|
+
id: "get_recently_played",
|
|
189
|
+
name: "Get Recently Played",
|
|
190
|
+
description: "List recently played Spotify tracks for the connected account.",
|
|
191
|
+
input: getRecentlyPlayedInputSchema,
|
|
192
|
+
output: spotifyRecentlyPlayedPageSchema,
|
|
193
|
+
run: async (input, credentials) => {
|
|
194
|
+
return createSpotifyClient(credentials).player.getRecentlyPlayed(input);
|
|
195
|
+
}
|
|
196
|
+
});
|
|
197
|
+
const addToQueue = spotifyOperation({
|
|
198
|
+
id: "add_to_queue",
|
|
199
|
+
name: "Add To Queue",
|
|
200
|
+
description: "Add a track or episode to the Spotify playback queue.",
|
|
201
|
+
input: addToQueueInputSchema,
|
|
202
|
+
output: spotifyMutationSuccessSchema,
|
|
203
|
+
needsApproval: true,
|
|
204
|
+
run: async (input, credentials) => {
|
|
205
|
+
return createSpotifyClient(credentials).player.addToQueue(input.uri, input.deviceId);
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
const getQueue = spotifyOperation({
|
|
209
|
+
id: "get_queue",
|
|
210
|
+
name: "Get Queue",
|
|
211
|
+
description: "Fetch the current Spotify playback queue.",
|
|
212
|
+
input: emptyInputSchema,
|
|
213
|
+
output: spotifyQueueSchema,
|
|
214
|
+
run: async (_input, credentials) => {
|
|
215
|
+
return createSpotifyClient(credentials).player.getQueue();
|
|
216
|
+
}
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
//#endregion
|
|
220
|
+
export { addToQueue, getAvailableDevices, getCurrentlyPlaying, getPlaybackState, getQueue, getRecentlyPlayed, pausePlayback, seekToPosition, setPlaybackVolume, setRepeatMode, setShuffleMode, skipToNext, skipToPrevious, startOrResumePlayback, transferPlayback };
|