@foxtware/mineral 0.1.28 → 0.1.29

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.
Files changed (63) hide show
  1. package/.creds.yml.sample +14 -2
  2. package/AGENTS.md +7 -0
  3. package/_build_scripts/createNewFunction.js +26 -3
  4. package/api/dropbox/docs.md +7 -0
  5. package/api/dropbox/dropbox.constants.js +10 -0
  6. package/api/dropbox/dropbox.utils.js +67 -0
  7. package/api/dropbox/dropboxAccountGet.js +64 -0
  8. package/api/dropbox/dropboxFileCopy.js +67 -0
  9. package/api/dropbox/dropboxFileDelete.js +89 -0
  10. package/api/dropbox/dropboxFileDownload.js +139 -0
  11. package/api/dropbox/dropboxFileMetadataGet.js +100 -0
  12. package/api/dropbox/dropboxFileMove.js +67 -0
  13. package/api/dropbox/dropboxFileUpload.js +129 -0
  14. package/api/dropbox/dropboxFolderCreate.js +68 -0
  15. package/api/dropbox/dropboxFolderList.js +66 -0
  16. package/api/dropbox/dropboxGet.js +158 -0
  17. package/api/dropbox/dropboxSearch.js +161 -0
  18. package/api/dropbox/dropboxSharedLinkCreate.js +68 -0
  19. package/api/dropbox/dropboxSpaceUsageGet.js +55 -0
  20. package/api/dropbox/dropboxTemporaryLinkGet.js +75 -0
  21. package/api/google/docs.md +1 -0
  22. package/api/google/google.constants.js +1 -0
  23. package/api/google/google.utils.js +21 -0
  24. package/api/google/googleanalyticsMetadataGet.js +62 -0
  25. package/api/google/googleanalyticsRealtimeReportRun.js +103 -0
  26. package/api/google/googleanalyticsReportRun.js +114 -0
  27. package/api/shopify/shopify.utils.js +53 -4
  28. package/api/shopify/shopifyMetaobjectCreate.js +13 -6
  29. package/api/shopify/shopifyMetaobjectDelete.js +90 -0
  30. package/api/shopify/shopifyMetaobjectGet.js +80 -0
  31. package/api/shopify/shopifyMetaobjectUpdate.js +108 -0
  32. package/api/shopify/shopifyStorefrontSearch.js +158 -0
  33. package/api/spotify/docs.md +8 -0
  34. package/api/spotify/spotify.constants.js +12 -0
  35. package/api/spotify/spotify.utils.js +106 -0
  36. package/api/spotify/spotifyAlbumGet.js +76 -0
  37. package/api/spotify/spotifyAlbumTracksGet.js +49 -0
  38. package/api/spotify/spotifyArtistAlbumsGet.js +55 -0
  39. package/api/spotify/spotifyArtistGet.js +71 -0
  40. package/api/spotify/spotifyArtistTopTracksGet.js +56 -0
  41. package/api/spotify/spotifyGet.js +171 -0
  42. package/api/spotify/spotifyMeGet.js +48 -0
  43. package/api/spotify/spotifyPlayerCurrentlyPlayingGet.js +62 -0
  44. package/api/spotify/spotifyPlayerDevicesGet.js +51 -0
  45. package/api/spotify/spotifyPlayerGet.js +63 -0
  46. package/api/spotify/spotifyPlayerNext.js +55 -0
  47. package/api/spotify/spotifyPlayerPause.js +55 -0
  48. package/api/spotify/spotifyPlayerPlay.js +70 -0
  49. package/api/spotify/spotifyPlayerPrevious.js +55 -0
  50. package/api/spotify/spotifyPlaylistCreate.js +63 -0
  51. package/api/spotify/spotifyPlaylistGet.js +91 -0
  52. package/api/spotify/spotifyPlaylistItemsAdd.js +61 -0
  53. package/api/spotify/spotifyPlaylistItemsGet.js +58 -0
  54. package/api/spotify/spotifyPlaylistItemsRemove.js +67 -0
  55. package/api/spotify/spotifyPlaylistUpdate.js +64 -0
  56. package/api/spotify/spotifyPlaylistsGet.js +47 -0
  57. package/api/spotify/spotifySavedTracksGet.js +46 -0
  58. package/api/spotify/spotifySavedTracksRemove.js +59 -0
  59. package/api/spotify/spotifySavedTracksSave.js +59 -0
  60. package/api/spotify/spotifySearch.js +174 -0
  61. package/api/spotify/spotifyTrackGet.js +76 -0
  62. package/package.json +1 -1
  63. package/server.js +3 -1
@@ -0,0 +1,174 @@
1
+ // https://developer.spotify.com/documentation/web-api/reference/search
2
+
3
+ const { ArgsWarden, Getter } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { spotifyClient } = require('../spotify/spotify.utils');
6
+ const { MAX_SEARCH_PER_PAGE } = require('../spotify/spotify.constants');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ['query'],
11
+ ['types'],
12
+ ]);
13
+
14
+ const digSearchResults = (data, types) => {
15
+ const typeList = (Array.isArray(types) ? types : String(types).split(','))
16
+ .map((t) => t.trim())
17
+ .filter(Boolean);
18
+
19
+ // Flatten matches across requested types, tagging each with its type key.
20
+ const out = [];
21
+ for (const type of typeList) {
22
+ const key = type.endsWith('s') ? type : `${ type }s`;
23
+ const page = data?.[key];
24
+ const items = page?.items ?? [];
25
+ for (const item of items) {
26
+ out.push({ type: key, ...item });
27
+ }
28
+ }
29
+ return out;
30
+ };
31
+
32
+ const spotifySearchPacket = async (
33
+ credsPayload,
34
+ query,
35
+ types,
36
+ {
37
+ params = {},
38
+ perPage = MAX_SEARCH_PER_PAGE,
39
+ fetchClient = spotifyClient,
40
+ } = {},
41
+ ) => {
42
+ const typeParam = Array.isArray(types) ? types.join(',') : types;
43
+
44
+ return fetchClient.fetch({
45
+ context: { credsPayload },
46
+ requestPayload: {
47
+ method: 'get',
48
+ url: '/search',
49
+ params: {
50
+ q: query,
51
+ type: typeParam,
52
+ limit: Math.min(perPage, MAX_SEARCH_PER_PAGE),
53
+ offset: 0,
54
+ ...params,
55
+ },
56
+ },
57
+ });
58
+ };
59
+
60
+ const spotifySearchPaginator = async (currentParams, response) => {
61
+ if (!response?.ok) {
62
+ return [true];
63
+ }
64
+
65
+ const data = response.data ?? {};
66
+ // Any requested type still having a next URL means we continue.
67
+ const hasNext = Object.values(data).some(
68
+ (page) => page && typeof page === 'object' && page.next,
69
+ );
70
+ if (!hasNext) {
71
+ return [true];
72
+ }
73
+
74
+ const { args, options } = currentParams;
75
+ const { params = {}, perPage = MAX_SEARCH_PER_PAGE } = options;
76
+ const currentOffset = Number(params.offset ?? 0);
77
+ const pageLimit = Number(params.limit ?? perPage);
78
+
79
+ return [false, {
80
+ args,
81
+ options: {
82
+ ...options,
83
+ params: {
84
+ ...params,
85
+ offset: currentOffset + pageLimit,
86
+ limit: pageLimit,
87
+ },
88
+ },
89
+ }];
90
+ };
91
+
92
+ const spotifySearch = async (
93
+ returnGetter,
94
+
95
+ credsPayload,
96
+ query,
97
+ types,
98
+ {
99
+ market,
100
+ includeExternal,
101
+ perPage = MAX_SEARCH_PER_PAGE,
102
+ fetchClient,
103
+ ...getterOptions
104
+ } = {},
105
+ ) => {
106
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
107
+ credsPayload,
108
+ query,
109
+ types,
110
+ });
111
+ if (rejectResponse) {
112
+ return rejectResponse;
113
+ }
114
+
115
+ const typeList = Array.isArray(types) ? types : String(types).split(',');
116
+
117
+ const getter = new Getter(
118
+ {
119
+ args: [credsPayload, query, types],
120
+ options: {
121
+ params: {
122
+ ...(market !== undefined && { market }),
123
+ ...(includeExternal !== undefined && {
124
+ include_external: includeExternal,
125
+ }),
126
+ },
127
+ perPage,
128
+ fetchClient,
129
+ },
130
+ },
131
+ {
132
+ func: spotifySearchPacket,
133
+ digester: (response) => {
134
+ if (!response?.ok) {
135
+ return [];
136
+ }
137
+ return digSearchResults(response.data, typeList);
138
+ },
139
+ paginator: spotifySearchPaginator,
140
+ ...getterOptions,
141
+ },
142
+ );
143
+
144
+ if (returnGetter) {
145
+ return getter;
146
+ }
147
+
148
+ const data = await getter.run({ returnAll: true });
149
+
150
+ return {
151
+ ok: true,
152
+ data,
153
+ };
154
+ };
155
+
156
+ const funcApiConfig = {
157
+ argsWarden,
158
+ };
159
+
160
+ module.exports = {
161
+ spotifySearch: (...args) => spotifySearch(false, ...args),
162
+ spotifySearchGetter: (...args) => spotifySearch(true, ...args),
163
+ funcApiConfig,
164
+ };
165
+
166
+ /*
167
+ curl -X POST "http://localhost:8000/spotifySearch" \
168
+ -H "Content-Type: application/json" \
169
+ -d '{
170
+ "credsPayload": { "credsPath": "spotify" },
171
+ "query": "radiohead",
172
+ "types": ["artist", "album"]
173
+ }'
174
+ */
@@ -0,0 +1,76 @@
1
+ // https://developer.spotify.com/documentation/web-api/reference/get-track
2
+
3
+ const { ArgsWarden, actionSingleOrMultiple, 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
+ ['trackId'],
10
+ ]);
11
+
12
+ const spotifyTrackGetSingle = async (
13
+ credsPayload,
14
+ trackId,
15
+ {
16
+ market,
17
+ fetchClient = spotifyClient,
18
+ } = {},
19
+ ) => {
20
+ const response = await fetchClient.fetch({
21
+ context: { credsPayload },
22
+ requestPayload: {
23
+ method: 'get',
24
+ url: `/tracks/${ trackId }`,
25
+ params: {
26
+ ...(market !== undefined && { market }),
27
+ },
28
+ },
29
+ });
30
+
31
+ const { ok, data, error } = response;
32
+ if (!ok) {
33
+ logDeep({ error });
34
+ return { ok: false, error };
35
+ }
36
+
37
+ return { ok: true, data };
38
+ };
39
+
40
+ const spotifyTrackGet = async (
41
+ credsPayload,
42
+ trackId,
43
+ {
44
+ market,
45
+ queueRunOptions,
46
+ fetchClient,
47
+ } = {},
48
+ ) => {
49
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
50
+ credsPayload,
51
+ trackId,
52
+ });
53
+ if (rejectResponse) {
54
+ return rejectResponse;
55
+ }
56
+
57
+ return actionSingleOrMultiple(
58
+ trackId,
59
+ spotifyTrackGetSingle,
60
+ (trackIdItem) => ({
61
+ args: [credsPayload, trackIdItem, { market, fetchClient }],
62
+ }),
63
+ {
64
+ ...(queueRunOptions ? { queueRunOptions } : {}),
65
+ },
66
+ );
67
+ };
68
+
69
+ const funcApiConfig = {
70
+ argsWarden,
71
+ };
72
+
73
+ module.exports = {
74
+ spotifyTrackGet,
75
+ funcApiConfig,
76
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@foxtware/mineral",
3
- "version": "0.1.28",
3
+ "version": "0.1.29",
4
4
  "bin": {
5
5
  "mineral": "bin/mineral.js"
6
6
  },
package/server.js CHANGED
@@ -200,11 +200,13 @@ const logStartup = ({
200
200
  if (api_dirs.length) {
201
201
  console.log('Extra API dirs:', api_dirs.join(', '));
202
202
  }
203
-
203
+
204
+ /*
204
205
  console.log('Registered routes:');
205
206
  for (const route of [...routeHandlers.keys()].sort()) {
206
207
  console.log(route);
207
208
  }
209
+ */
208
210
  };
209
211
 
210
212
  const startServer = (options = {}) => {