@foxtware/mineral 0.1.28 → 0.1.30
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/.creds.yml.sample +35 -2
- package/AGENTS.md +7 -0
- package/_build_scripts/createNewFunction.js +26 -3
- package/api/dpd/docs.md +6 -0
- package/api/dpd/dpd.constants.js +9 -0
- package/api/dpd/dpd.utils.js +145 -0
- package/api/dpd/dpdTrackingGet.js +64 -0
- package/api/dropbox/docs.md +7 -0
- package/api/dropbox/dropbox.constants.js +10 -0
- package/api/dropbox/dropbox.utils.js +67 -0
- package/api/dropbox/dropboxAccountGet.js +64 -0
- package/api/dropbox/dropboxFileCopy.js +67 -0
- package/api/dropbox/dropboxFileDelete.js +89 -0
- package/api/dropbox/dropboxFileDownload.js +139 -0
- package/api/dropbox/dropboxFileMetadataGet.js +100 -0
- package/api/dropbox/dropboxFileMove.js +67 -0
- package/api/dropbox/dropboxFileUpload.js +129 -0
- package/api/dropbox/dropboxFolderCreate.js +68 -0
- package/api/dropbox/dropboxFolderList.js +66 -0
- package/api/dropbox/dropboxGet.js +158 -0
- package/api/dropbox/dropboxSearch.js +161 -0
- package/api/dropbox/dropboxSharedLinkCreate.js +68 -0
- package/api/dropbox/dropboxSpaceUsageGet.js +55 -0
- package/api/dropbox/dropboxTemporaryLinkGet.js +75 -0
- package/api/fedex/docs.md +6 -0
- package/api/fedex/fedex.constants.js +11 -0
- package/api/fedex/fedex.utils.js +151 -0
- package/api/fedex/fedexTrackingGet.js +76 -0
- package/api/google/docs.md +1 -0
- package/api/google/google.constants.js +1 -0
- package/api/google/google.utils.js +21 -0
- package/api/google/googleanalyticsMetadataGet.js +62 -0
- package/api/google/googleanalyticsRealtimeReportRun.js +103 -0
- package/api/google/googleanalyticsReportRun.js +114 -0
- package/api/paypal/docs.md +14 -0
- package/api/paypal/paypal.constants.js +13 -0
- package/api/paypal/paypal.utils.js +166 -0
- package/api/paypal/paypalAccessTokenGet.js +81 -0
- package/api/paypal/paypalAuthorizationCapture.js +75 -0
- package/api/paypal/paypalAuthorizationGet.js +57 -0
- package/api/paypal/paypalBalancesGet.js +65 -0
- package/api/paypal/paypalCaptureGet.js +57 -0
- package/api/paypal/paypalCaptureRefund.js +78 -0
- package/api/paypal/paypalOrderAuthorize.js +69 -0
- package/api/paypal/paypalOrderCapture.js +69 -0
- package/api/paypal/paypalOrderCreate.js +81 -0
- package/api/paypal/paypalOrderGet.js +57 -0
- package/api/paypal/paypalRefundGet.js +57 -0
- package/api/paypal/paypalTransactionsGet.js +101 -0
- package/api/paypal/paypalUserInfoGet.js +62 -0
- package/api/royalmail/docs.md +6 -0
- package/api/royalmail/royalmail.constants.js +7 -0
- package/api/royalmail/royalmail.utils.js +55 -0
- package/api/royalmail/royalmailTrackingGet.js +70 -0
- package/api/shopify/shopify.utils.js +65 -4
- package/api/shopify/shopifyMetaobjectCreate.js +13 -6
- package/api/shopify/shopifyMetaobjectDelete.js +90 -0
- package/api/shopify/shopifyMetaobjectGet.js +80 -0
- package/api/shopify/shopifyMetaobjectUpdate.js +108 -0
- package/api/shopify/shopifyStorefrontSearch.js +158 -0
- package/api/spotify/docs.md +8 -0
- package/api/spotify/spotify.constants.js +12 -0
- package/api/spotify/spotify.utils.js +106 -0
- package/api/spotify/spotifyAlbumGet.js +76 -0
- package/api/spotify/spotifyAlbumTracksGet.js +49 -0
- package/api/spotify/spotifyArtistAlbumsGet.js +55 -0
- package/api/spotify/spotifyArtistGet.js +71 -0
- package/api/spotify/spotifyArtistTopTracksGet.js +56 -0
- package/api/spotify/spotifyGet.js +171 -0
- package/api/spotify/spotifyMeGet.js +48 -0
- package/api/spotify/spotifyPlayerCurrentlyPlayingGet.js +62 -0
- package/api/spotify/spotifyPlayerDevicesGet.js +51 -0
- package/api/spotify/spotifyPlayerGet.js +63 -0
- package/api/spotify/spotifyPlayerNext.js +55 -0
- package/api/spotify/spotifyPlayerPause.js +55 -0
- package/api/spotify/spotifyPlayerPlay.js +70 -0
- package/api/spotify/spotifyPlayerPrevious.js +55 -0
- package/api/spotify/spotifyPlaylistCreate.js +63 -0
- package/api/spotify/spotifyPlaylistGet.js +91 -0
- package/api/spotify/spotifyPlaylistItemsAdd.js +61 -0
- package/api/spotify/spotifyPlaylistItemsGet.js +58 -0
- package/api/spotify/spotifyPlaylistItemsRemove.js +67 -0
- package/api/spotify/spotifyPlaylistUpdate.js +64 -0
- package/api/spotify/spotifyPlaylistsGet.js +47 -0
- package/api/spotify/spotifySavedTracksGet.js +46 -0
- package/api/spotify/spotifySavedTracksRemove.js +59 -0
- package/api/spotify/spotifySavedTracksSave.js +59 -0
- package/api/spotify/spotifySearch.js +174 -0
- package/api/spotify/spotifyTrackGet.js +76 -0
- package/api/starshipit/starshipitProductUpdate.js +102 -0
- package/api/starshipit/starshipitProductsGet.js +2 -2
- package/api/stylearcade/stylearcadeGet.js +5 -2
- package/api/utils.js +39 -0
- package/package.json +1 -1
- package/server.js +3 -1
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/concepts/api-calls#pagination
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, Getter } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
const { MAX_PER_PAGE } = require('../spotify/spotify.constants');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['url'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const digResults = (data, resultsKey) => {
|
|
14
|
+
if (resultsKey) {
|
|
15
|
+
// Nested e.g. tracks.items or playlists.items
|
|
16
|
+
const value = resultsKey.split('.').reduce(
|
|
17
|
+
(node, key) => node?.[key],
|
|
18
|
+
data,
|
|
19
|
+
);
|
|
20
|
+
if (Array.isArray(value)) {
|
|
21
|
+
return value;
|
|
22
|
+
}
|
|
23
|
+
return value != null ? [value] : [];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (Array.isArray(data?.items)) {
|
|
27
|
+
return data.items;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (Array.isArray(data)) {
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return [];
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const spotifyGetPacket = async (
|
|
38
|
+
credsPayload,
|
|
39
|
+
url,
|
|
40
|
+
{
|
|
41
|
+
params,
|
|
42
|
+
perPage = MAX_PER_PAGE,
|
|
43
|
+
fetchClient = spotifyClient,
|
|
44
|
+
} = {},
|
|
45
|
+
) => {
|
|
46
|
+
return fetchClient.fetch({
|
|
47
|
+
requestPayload: {
|
|
48
|
+
method: 'get',
|
|
49
|
+
url,
|
|
50
|
+
params: {
|
|
51
|
+
limit: Math.min(perPage, MAX_PER_PAGE),
|
|
52
|
+
offset: 0,
|
|
53
|
+
...params,
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
context: {
|
|
57
|
+
credsPayload,
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
const spotifyGetPaginator = async (currentParams, response) => {
|
|
63
|
+
if (!response?.ok) {
|
|
64
|
+
return [true];
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const page = response.data ?? {};
|
|
68
|
+
// Spotify paging objects expose next (URL) or offset/limit/total.
|
|
69
|
+
if (page.next == null && page.items) {
|
|
70
|
+
const { offset = 0, limit = 0, total = 0 } = page;
|
|
71
|
+
if (offset + limit >= total || page.items.length === 0) {
|
|
72
|
+
return [true];
|
|
73
|
+
}
|
|
74
|
+
} else if (!page.next) {
|
|
75
|
+
return [true];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const { args, options } = currentParams;
|
|
79
|
+
const { params = {}, perPage = MAX_PER_PAGE } = options;
|
|
80
|
+
const currentOffset = Number(params.offset ?? 0);
|
|
81
|
+
const pageLimit = Number(params.limit ?? perPage);
|
|
82
|
+
|
|
83
|
+
return [false, {
|
|
84
|
+
args,
|
|
85
|
+
options: {
|
|
86
|
+
...options,
|
|
87
|
+
params: {
|
|
88
|
+
...params,
|
|
89
|
+
offset: currentOffset + pageLimit,
|
|
90
|
+
limit: pageLimit,
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
}];
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const spotifyGet = async (
|
|
97
|
+
returnGetter,
|
|
98
|
+
|
|
99
|
+
credsPayload,
|
|
100
|
+
url,
|
|
101
|
+
{
|
|
102
|
+
params,
|
|
103
|
+
perPage = MAX_PER_PAGE,
|
|
104
|
+
resultsKey = 'items',
|
|
105
|
+
fetchClient,
|
|
106
|
+
...getterOptions
|
|
107
|
+
} = {},
|
|
108
|
+
) => {
|
|
109
|
+
|
|
110
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
111
|
+
credsPayload,
|
|
112
|
+
url,
|
|
113
|
+
});
|
|
114
|
+
if (rejectResponse) {
|
|
115
|
+
return rejectResponse;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
const getter = new Getter(
|
|
119
|
+
{
|
|
120
|
+
args: [credsPayload, url],
|
|
121
|
+
options: {
|
|
122
|
+
params,
|
|
123
|
+
perPage,
|
|
124
|
+
fetchClient,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
func: spotifyGetPacket,
|
|
129
|
+
digester: (response) => {
|
|
130
|
+
if (!response?.ok) {
|
|
131
|
+
return [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
return digResults(response.data, resultsKey);
|
|
135
|
+
},
|
|
136
|
+
paginator: spotifyGetPaginator,
|
|
137
|
+
...getterOptions,
|
|
138
|
+
},
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
if (returnGetter) {
|
|
142
|
+
return getter;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
const data = await getter.run({ returnAll: true });
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
ok: true,
|
|
149
|
+
data,
|
|
150
|
+
};
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const funcApiConfig = {
|
|
154
|
+
argsWarden,
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
module.exports = {
|
|
158
|
+
spotifyGet: (...args) => spotifyGet(false, ...args),
|
|
159
|
+
spotifyGetter: (...args) => spotifyGet(true, ...args),
|
|
160
|
+
funcApiConfig,
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/*
|
|
164
|
+
curl -X POST "http://localhost:8000/spotifyGet" \
|
|
165
|
+
-H "Content-Type: application/json" \
|
|
166
|
+
-d '{
|
|
167
|
+
"credsPayload": { "credsPath": "spotify" },
|
|
168
|
+
"url": "/me/playlists",
|
|
169
|
+
"options": { "perPage": 20 }
|
|
170
|
+
}'
|
|
171
|
+
*/
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/get-current-users-profile
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyMeGet = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
fetchClient = spotifyClient,
|
|
15
|
+
} = {},
|
|
16
|
+
) => {
|
|
17
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
18
|
+
credsPayload,
|
|
19
|
+
});
|
|
20
|
+
if (rejectResponse) {
|
|
21
|
+
return rejectResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const response = await fetchClient.fetch({
|
|
25
|
+
context: { credsPayload },
|
|
26
|
+
requestPayload: {
|
|
27
|
+
method: 'get',
|
|
28
|
+
url: '/me',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const { ok, data, error } = response;
|
|
33
|
+
if (!ok) {
|
|
34
|
+
logDeep({ error });
|
|
35
|
+
return { ok: false, error };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return { ok: true, data };
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const funcApiConfig = {
|
|
42
|
+
argsWarden,
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
spotifyMeGet,
|
|
47
|
+
funcApiConfig,
|
|
48
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/get-the-users-currently-playing-track
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerCurrentlyPlayingGet = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
market,
|
|
15
|
+
additionalTypes,
|
|
16
|
+
fetchClient = spotifyClient,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
});
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const response = await fetchClient.fetch({
|
|
27
|
+
context: { credsPayload },
|
|
28
|
+
requestPayload: {
|
|
29
|
+
method: 'get',
|
|
30
|
+
url: '/me/player/currently-playing',
|
|
31
|
+
params: {
|
|
32
|
+
...(market !== undefined && { market }),
|
|
33
|
+
...(additionalTypes !== undefined && {
|
|
34
|
+
additional_types: Array.isArray(additionalTypes)
|
|
35
|
+
? additionalTypes.join(',')
|
|
36
|
+
: additionalTypes,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
if (response.ok && (response.data == null || response.data === '')) {
|
|
43
|
+
return { ok: true, data: null };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const { ok, data, error } = response;
|
|
47
|
+
if (!ok) {
|
|
48
|
+
logDeep({ error });
|
|
49
|
+
return { ok: false, error };
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return { ok: true, data };
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const funcApiConfig = {
|
|
56
|
+
argsWarden,
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
module.exports = {
|
|
60
|
+
spotifyPlayerCurrentlyPlayingGet,
|
|
61
|
+
funcApiConfig,
|
|
62
|
+
};
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/get-a-users-available-devices
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerDevicesGet = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
fetchClient = spotifyClient,
|
|
15
|
+
} = {},
|
|
16
|
+
) => {
|
|
17
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
18
|
+
credsPayload,
|
|
19
|
+
});
|
|
20
|
+
if (rejectResponse) {
|
|
21
|
+
return rejectResponse;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const response = await fetchClient.fetch({
|
|
25
|
+
context: { credsPayload },
|
|
26
|
+
requestPayload: {
|
|
27
|
+
method: 'get',
|
|
28
|
+
url: '/me/player/devices',
|
|
29
|
+
},
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
const { ok, data, error } = response;
|
|
33
|
+
if (!ok) {
|
|
34
|
+
logDeep({ error });
|
|
35
|
+
return { ok: false, error };
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
ok: true,
|
|
40
|
+
data: data.devices ?? data,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const funcApiConfig = {
|
|
45
|
+
argsWarden,
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
module.exports = {
|
|
49
|
+
spotifyPlayerDevicesGet,
|
|
50
|
+
funcApiConfig,
|
|
51
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/get-information-about-the-users-current-playback
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerGet = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
market,
|
|
15
|
+
additionalTypes,
|
|
16
|
+
fetchClient = spotifyClient,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
20
|
+
credsPayload,
|
|
21
|
+
});
|
|
22
|
+
if (rejectResponse) {
|
|
23
|
+
return rejectResponse;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const response = await fetchClient.fetch({
|
|
27
|
+
context: { credsPayload },
|
|
28
|
+
requestPayload: {
|
|
29
|
+
method: 'get',
|
|
30
|
+
url: '/me/player',
|
|
31
|
+
params: {
|
|
32
|
+
...(market !== undefined && { market }),
|
|
33
|
+
...(additionalTypes !== undefined && {
|
|
34
|
+
additional_types: Array.isArray(additionalTypes)
|
|
35
|
+
? additionalTypes.join(',')
|
|
36
|
+
: additionalTypes,
|
|
37
|
+
}),
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// 204 = nothing currently playing / no active device
|
|
43
|
+
if (response.ok && (response.data == null || response.data === '')) {
|
|
44
|
+
return { ok: true, data: null };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const { ok, data, error } = response;
|
|
48
|
+
if (!ok) {
|
|
49
|
+
logDeep({ error });
|
|
50
|
+
return { ok: false, error };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { ok: true, data };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const funcApiConfig = {
|
|
57
|
+
argsWarden,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
spotifyPlayerGet,
|
|
62
|
+
funcApiConfig,
|
|
63
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/skip-users-playback-to-next-track
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerNext = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
deviceId,
|
|
15
|
+
fetchClient = spotifyClient,
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
19
|
+
credsPayload,
|
|
20
|
+
});
|
|
21
|
+
if (rejectResponse) {
|
|
22
|
+
return rejectResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const response = await fetchClient.fetch({
|
|
26
|
+
context: { credsPayload },
|
|
27
|
+
requestPayload: {
|
|
28
|
+
method: 'post',
|
|
29
|
+
url: '/me/player/next',
|
|
30
|
+
params: {
|
|
31
|
+
...(deviceId !== undefined && { device_id: deviceId }),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const { ok, data, error } = response;
|
|
37
|
+
if (!ok) {
|
|
38
|
+
logDeep({ error });
|
|
39
|
+
return { ok: false, error };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
ok: true,
|
|
44
|
+
data: data ?? null,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const funcApiConfig = {
|
|
49
|
+
argsWarden,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
spotifyPlayerNext,
|
|
54
|
+
funcApiConfig,
|
|
55
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/pause-a-users-playback
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerPause = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
deviceId,
|
|
15
|
+
fetchClient = spotifyClient,
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
19
|
+
credsPayload,
|
|
20
|
+
});
|
|
21
|
+
if (rejectResponse) {
|
|
22
|
+
return rejectResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const response = await fetchClient.fetch({
|
|
26
|
+
context: { credsPayload },
|
|
27
|
+
requestPayload: {
|
|
28
|
+
method: 'put',
|
|
29
|
+
url: '/me/player/pause',
|
|
30
|
+
params: {
|
|
31
|
+
...(deviceId !== undefined && { device_id: deviceId }),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const { ok, data, error } = response;
|
|
37
|
+
if (!ok) {
|
|
38
|
+
logDeep({ error });
|
|
39
|
+
return { ok: false, error };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
ok: true,
|
|
44
|
+
data: data ?? null,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const funcApiConfig = {
|
|
49
|
+
argsWarden,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
spotifyPlayerPause,
|
|
54
|
+
funcApiConfig,
|
|
55
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/start-a-users-playback
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerPlay = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
deviceId,
|
|
15
|
+
contextUri,
|
|
16
|
+
uris,
|
|
17
|
+
offset,
|
|
18
|
+
positionMs,
|
|
19
|
+
fetchClient = spotifyClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
23
|
+
credsPayload,
|
|
24
|
+
});
|
|
25
|
+
if (rejectResponse) {
|
|
26
|
+
return rejectResponse;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const body = {
|
|
30
|
+
...(contextUri !== undefined && { context_uri: contextUri }),
|
|
31
|
+
...(uris !== undefined && {
|
|
32
|
+
uris: Array.isArray(uris) ? uris : [uris],
|
|
33
|
+
}),
|
|
34
|
+
...(offset !== undefined && { offset }),
|
|
35
|
+
...(positionMs !== undefined && { position_ms: positionMs }),
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const response = await fetchClient.fetch({
|
|
39
|
+
context: { credsPayload },
|
|
40
|
+
requestPayload: {
|
|
41
|
+
method: 'put',
|
|
42
|
+
url: '/me/player/play',
|
|
43
|
+
params: {
|
|
44
|
+
...(deviceId !== undefined && { device_id: deviceId }),
|
|
45
|
+
},
|
|
46
|
+
// Spotify accepts empty body to resume.
|
|
47
|
+
body: Object.keys(body).length ? body : {},
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const { ok, data, error } = response;
|
|
52
|
+
if (!ok) {
|
|
53
|
+
logDeep({ error });
|
|
54
|
+
return { ok: false, error };
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return {
|
|
58
|
+
ok: true,
|
|
59
|
+
data: data ?? null,
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const funcApiConfig = {
|
|
64
|
+
argsWarden,
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
module.exports = {
|
|
68
|
+
spotifyPlayerPlay,
|
|
69
|
+
funcApiConfig,
|
|
70
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/skip-users-playback-to-previous-track
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
]);
|
|
10
|
+
|
|
11
|
+
const spotifyPlayerPrevious = async (
|
|
12
|
+
credsPayload,
|
|
13
|
+
{
|
|
14
|
+
deviceId,
|
|
15
|
+
fetchClient = spotifyClient,
|
|
16
|
+
} = {},
|
|
17
|
+
) => {
|
|
18
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
19
|
+
credsPayload,
|
|
20
|
+
});
|
|
21
|
+
if (rejectResponse) {
|
|
22
|
+
return rejectResponse;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const response = await fetchClient.fetch({
|
|
26
|
+
context: { credsPayload },
|
|
27
|
+
requestPayload: {
|
|
28
|
+
method: 'post',
|
|
29
|
+
url: '/me/player/previous',
|
|
30
|
+
params: {
|
|
31
|
+
...(deviceId !== undefined && { device_id: deviceId }),
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
const { ok, data, error } = response;
|
|
37
|
+
if (!ok) {
|
|
38
|
+
logDeep({ error });
|
|
39
|
+
return { ok: false, error };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
ok: true,
|
|
44
|
+
data: data ?? null,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const funcApiConfig = {
|
|
49
|
+
argsWarden,
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
module.exports = {
|
|
53
|
+
spotifyPlayerPrevious,
|
|
54
|
+
funcApiConfig,
|
|
55
|
+
};
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
// https://developer.spotify.com/documentation/web-api/reference/create-playlist
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, logDeep } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { spotifyClient } = require('../spotify/spotify.utils');
|
|
6
|
+
|
|
7
|
+
const argsWarden = new ArgsWarden([
|
|
8
|
+
['credsPayload', credsValidator],
|
|
9
|
+
['userId'],
|
|
10
|
+
['name'],
|
|
11
|
+
]);
|
|
12
|
+
|
|
13
|
+
const spotifyPlaylistCreate = async (
|
|
14
|
+
credsPayload,
|
|
15
|
+
userId,
|
|
16
|
+
name,
|
|
17
|
+
{
|
|
18
|
+
public: isPublic = true,
|
|
19
|
+
collaborative = false,
|
|
20
|
+
description,
|
|
21
|
+
fetchClient = spotifyClient,
|
|
22
|
+
} = {},
|
|
23
|
+
) => {
|
|
24
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
25
|
+
credsPayload,
|
|
26
|
+
userId,
|
|
27
|
+
name,
|
|
28
|
+
});
|
|
29
|
+
if (rejectResponse) {
|
|
30
|
+
return rejectResponse;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const response = await fetchClient.fetch({
|
|
34
|
+
context: { credsPayload },
|
|
35
|
+
requestPayload: {
|
|
36
|
+
method: 'post',
|
|
37
|
+
url: `/users/${ userId }/playlists`,
|
|
38
|
+
body: {
|
|
39
|
+
name,
|
|
40
|
+
public: isPublic,
|
|
41
|
+
collaborative,
|
|
42
|
+
...(description !== undefined && { description }),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
const { ok, data, error } = response;
|
|
48
|
+
if (!ok) {
|
|
49
|
+
logDeep({ error });
|
|
50
|
+
return { ok: false, error };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return { ok: true, data };
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const funcApiConfig = {
|
|
57
|
+
argsWarden,
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
module.exports = {
|
|
61
|
+
spotifyPlaylistCreate,
|
|
62
|
+
funcApiConfig,
|
|
63
|
+
};
|