@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,67 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-move_v2
2
+
3
+ const { ArgsWarden, logDeep } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['fromPath'],
10
+ ['toPath'],
11
+ ]);
12
+
13
+ const dropboxFileMove = async (
14
+ credsPayload,
15
+ fromPath,
16
+ toPath,
17
+ {
18
+ allowSharedFolder = false,
19
+ autorename = false,
20
+ allowOwnershipTransfer = false,
21
+ fetchClient = dropboxClient,
22
+ } = {},
23
+ ) => {
24
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
25
+ credsPayload,
26
+ fromPath,
27
+ toPath,
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: '/files/move_v2',
38
+ body: {
39
+ from_path: fromPath,
40
+ to_path: toPath,
41
+ allow_shared_folder: allowSharedFolder,
42
+ autorename,
43
+ allow_ownership_transfer: allowOwnershipTransfer,
44
+ },
45
+ },
46
+ });
47
+
48
+ const { ok, data, error } = response;
49
+ if (!ok) {
50
+ logDeep({ error });
51
+ return { ok: false, error };
52
+ }
53
+
54
+ return {
55
+ ok: true,
56
+ data: data.metadata ?? data,
57
+ };
58
+ };
59
+
60
+ const funcApiConfig = {
61
+ argsWarden,
62
+ };
63
+
64
+ module.exports = {
65
+ dropboxFileMove,
66
+ funcApiConfig,
67
+ };
@@ -0,0 +1,129 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-upload
2
+ // Max 150 MB for a single /files/upload call. Larger files need upload sessions.
3
+
4
+ const fs = require('fs').promises;
5
+ const pathModule = require('path');
6
+
7
+ const { ArgsWarden, valueProvided, logDeep } = require('../utils');
8
+ const { credsValidator } = require('../validators');
9
+ const { dropboxContentClient } = require('../dropbox/dropbox.utils');
10
+
11
+ const fileDataValidator = (fileData) => {
12
+ if (!fileData || typeof fileData !== 'object') {
13
+ return false;
14
+ }
15
+ const { filePath, fileSource, contents } = fileData;
16
+ return valueProvided(filePath)
17
+ || valueProvided(fileSource)
18
+ || valueProvided(contents);
19
+ };
20
+
21
+ const argsWarden = new ArgsWarden([
22
+ ['credsPayload', credsValidator],
23
+ ['path'],
24
+ ['fileData', fileDataValidator],
25
+ ]);
26
+
27
+ const dropboxFileUpload = async (
28
+ credsPayload,
29
+ path,
30
+ fileData,
31
+ {
32
+ mode = 'add', // 'add' | 'overwrite' | { '.tag': 'update', update: rev }
33
+ autorename = false,
34
+ mute = false,
35
+ strictConflict = false,
36
+ clientModified,
37
+ fetchClient = dropboxContentClient,
38
+ } = {},
39
+ ) => {
40
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
41
+ credsPayload,
42
+ path,
43
+ fileData,
44
+ });
45
+ if (rejectResponse) {
46
+ return rejectResponse;
47
+ }
48
+
49
+ let body;
50
+ if (valueProvided(fileData.filePath)) {
51
+ body = await fs.readFile(fileData.filePath);
52
+ } else if (valueProvided(fileData.fileSource)) {
53
+ body = Buffer.isBuffer(fileData.fileSource)
54
+ ? fileData.fileSource
55
+ : Buffer.from(fileData.fileSource, fileData.encoding || 'utf8');
56
+ } else if (valueProvided(fileData.contents)) {
57
+ body = Buffer.isBuffer(fileData.contents)
58
+ ? fileData.contents
59
+ : Buffer.from(fileData.contents, fileData.encoding || 'utf8');
60
+ }
61
+
62
+ if (!body) {
63
+ return {
64
+ ok: false,
65
+ error: {
66
+ code: 'INVALID_FILE_DATA',
67
+ message: 'Provide filePath, fileSource, or contents',
68
+ },
69
+ };
70
+ }
71
+
72
+ // If path ends with / or is empty folder style, append basename from filePath.
73
+ let uploadPath = path;
74
+ if (fileData.filePath && (path.endsWith('/') || path === '')) {
75
+ uploadPath = `${ path.replace(/\/$/, '') }/${ pathModule.basename(fileData.filePath) }`;
76
+ }
77
+
78
+ const arg = {
79
+ path: uploadPath,
80
+ mode,
81
+ autorename,
82
+ mute,
83
+ strict_conflict: strictConflict,
84
+ ...(clientModified !== undefined && { client_modified: clientModified }),
85
+ };
86
+
87
+ const response = await fetchClient.fetch({
88
+ context: { credsPayload },
89
+ requestPayload: {
90
+ method: 'post',
91
+ url: '/files/upload',
92
+ headers: {
93
+ 'Dropbox-API-Arg': JSON.stringify(arg),
94
+ 'Content-Type': 'application/octet-stream',
95
+ },
96
+ body,
97
+ },
98
+ });
99
+
100
+ const { ok, data, error } = response;
101
+ if (!ok) {
102
+ logDeep({ error });
103
+ return { ok: false, error };
104
+ }
105
+
106
+ return {
107
+ ok: true,
108
+ data,
109
+ };
110
+ };
111
+
112
+ const funcApiConfig = {
113
+ argsWarden,
114
+ };
115
+
116
+ module.exports = {
117
+ dropboxFileUpload,
118
+ funcApiConfig,
119
+ };
120
+
121
+ /*
122
+ curl -X POST "http://localhost:8000/dropboxFileUpload" \
123
+ -H "Content-Type: application/json" \
124
+ -d '{
125
+ "credsPayload": { "credsPath": "dropbox" },
126
+ "path": "/Homework/math/hello.txt",
127
+ "fileData": { "contents": "hello world" }
128
+ }'
129
+ */
@@ -0,0 +1,68 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-create_folder_v2
2
+
3
+ const { ArgsWarden, logDeep } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['path'],
10
+ ]);
11
+
12
+ const dropboxFolderCreate = async (
13
+ credsPayload,
14
+ path,
15
+ {
16
+ autorename = false,
17
+ fetchClient = dropboxClient,
18
+ } = {},
19
+ ) => {
20
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
21
+ credsPayload,
22
+ path,
23
+ });
24
+ if (rejectResponse) {
25
+ return rejectResponse;
26
+ }
27
+
28
+ const response = await fetchClient.fetch({
29
+ context: { credsPayload },
30
+ requestPayload: {
31
+ method: 'post',
32
+ url: '/files/create_folder_v2',
33
+ body: {
34
+ path,
35
+ autorename,
36
+ },
37
+ },
38
+ });
39
+
40
+ const { ok, data, error } = response;
41
+ if (!ok) {
42
+ logDeep({ error });
43
+ return { ok: false, error };
44
+ }
45
+
46
+ return {
47
+ ok: true,
48
+ data: data.metadata ?? data,
49
+ };
50
+ };
51
+
52
+ const funcApiConfig = {
53
+ argsWarden,
54
+ };
55
+
56
+ module.exports = {
57
+ dropboxFolderCreate,
58
+ funcApiConfig,
59
+ };
60
+
61
+ /*
62
+ curl -X POST "http://localhost:8000/dropboxFolderCreate" \
63
+ -H "Content-Type: application/json" \
64
+ -d '{
65
+ "credsPayload": { "credsPath": "dropbox" },
66
+ "path": "/Homework/math"
67
+ }'
68
+ */
@@ -0,0 +1,66 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
2
+
3
+ const { ArgsWarden } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxGet } = require('../dropbox/dropboxGet');
6
+ const { MAX_PER_PAGE } = require('../dropbox/dropbox.constants');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ]);
11
+
12
+ // path: "" for root. recursive walks the whole subtree.
13
+ const dropboxFolderList = async (
14
+ credsPayload,
15
+ {
16
+ path = '',
17
+ recursive = false,
18
+ includeDeleted = false,
19
+ includeMediaInfo = false,
20
+ includeMountedFolders = true,
21
+ includeNonDownloadableFiles = true,
22
+ perPage = MAX_PER_PAGE,
23
+ fetchClient,
24
+ ...getterOptions
25
+ } = {},
26
+ ) => {
27
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
28
+ credsPayload,
29
+ });
30
+ if (rejectResponse) {
31
+ return rejectResponse;
32
+ }
33
+
34
+ return dropboxGet(credsPayload, '/files/list_folder', {
35
+ body: {
36
+ path,
37
+ recursive,
38
+ include_deleted: includeDeleted,
39
+ include_media_info: includeMediaInfo,
40
+ include_mounted_folders: includeMountedFolders,
41
+ include_non_downloadable_files: includeNonDownloadableFiles,
42
+ },
43
+ perPage,
44
+ resultsKey: 'entries',
45
+ fetchClient,
46
+ ...getterOptions,
47
+ });
48
+ };
49
+
50
+ const funcApiConfig = {
51
+ argsWarden,
52
+ };
53
+
54
+ module.exports = {
55
+ dropboxFolderList,
56
+ funcApiConfig,
57
+ };
58
+
59
+ /*
60
+ curl -X POST "http://localhost:8000/dropboxFolderList" \
61
+ -H "Content-Type: application/json" \
62
+ -d '{
63
+ "credsPayload": { "credsPath": "dropbox" },
64
+ "options": { "path": "/Homework" }
65
+ }'
66
+ */
@@ -0,0 +1,158 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
2
+
3
+ const { ArgsWarden, Getter } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+ const { MAX_PER_PAGE } = require('../dropbox/dropbox.constants');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ['url'],
11
+ ]);
12
+
13
+ const dropboxGetPacket = async (
14
+ credsPayload,
15
+ url,
16
+ {
17
+ body = {},
18
+ perPage = MAX_PER_PAGE,
19
+ fetchClient = dropboxClient,
20
+ } = {},
21
+ ) => {
22
+ // When continuing, Dropbox wants only { cursor } on list_folder/continue.
23
+ const isContinue = url.includes('/continue') || body.cursor;
24
+
25
+ const requestBody = isContinue
26
+ ? { cursor: body.cursor }
27
+ : {
28
+ ...body,
29
+ ...(body.limit === undefined && {
30
+ limit: Math.min(perPage, MAX_PER_PAGE),
31
+ }),
32
+ };
33
+
34
+ return fetchClient.fetch({
35
+ requestPayload: {
36
+ method: 'post',
37
+ url,
38
+ body: requestBody,
39
+ },
40
+ context: {
41
+ credsPayload,
42
+ },
43
+ });
44
+ };
45
+
46
+ const dropboxGetPaginator = async (currentParams, response) => {
47
+ if (!response?.ok) {
48
+ return [true];
49
+ }
50
+
51
+ const { has_more: hasMore, cursor } = response.data ?? {};
52
+ if (!hasMore || !cursor) {
53
+ return [true];
54
+ }
55
+
56
+ const { args, options } = currentParams;
57
+ const [, initialUrl] = args;
58
+
59
+ // Switch to the matching continue endpoint when still on the initial path.
60
+ let continueUrl = initialUrl;
61
+ if (!continueUrl.includes('/continue')) {
62
+ continueUrl = `${ initialUrl.replace(/\/$/, '') }/continue`;
63
+ }
64
+
65
+ return [false, {
66
+ args: [args[0], continueUrl],
67
+ options: {
68
+ ...options,
69
+ body: {
70
+ cursor,
71
+ },
72
+ },
73
+ }];
74
+ };
75
+
76
+ const dropboxGet = async (
77
+ returnGetter,
78
+
79
+ credsPayload,
80
+ url,
81
+ {
82
+ body,
83
+ perPage = MAX_PER_PAGE,
84
+ resultsKey = 'entries',
85
+ fetchClient,
86
+ ...getterOptions
87
+ } = {},
88
+ ) => {
89
+
90
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
91
+ credsPayload,
92
+ url,
93
+ });
94
+ if (rejectResponse) {
95
+ return rejectResponse;
96
+ }
97
+
98
+ const getter = new Getter(
99
+ {
100
+ args: [credsPayload, url],
101
+ options: {
102
+ body,
103
+ perPage,
104
+ fetchClient,
105
+ },
106
+ },
107
+ {
108
+ func: dropboxGetPacket,
109
+ digester: (response) => {
110
+ if (!response?.ok) {
111
+ return [];
112
+ }
113
+
114
+ if (resultsKey) {
115
+ return response.data?.[resultsKey] ?? [];
116
+ }
117
+
118
+ return response.data ?? [];
119
+ },
120
+ paginator: dropboxGetPaginator,
121
+ ...getterOptions,
122
+ },
123
+ );
124
+
125
+ if (returnGetter) {
126
+ return getter;
127
+ }
128
+
129
+ const data = await getter.run({ returnAll: true });
130
+
131
+ return {
132
+ ok: true,
133
+ data,
134
+ };
135
+ };
136
+
137
+ const funcApiConfig = {
138
+ argsWarden,
139
+ };
140
+
141
+ module.exports = {
142
+ dropboxGet: (...args) => dropboxGet(false, ...args),
143
+ dropboxGetter: (...args) => dropboxGet(true, ...args),
144
+ funcApiConfig,
145
+ };
146
+
147
+ /*
148
+ curl -X POST "http://localhost:8000/dropboxGet" \
149
+ -H "Content-Type: application/json" \
150
+ -d '{
151
+ "credsPayload": { "credsPath": "dropbox" },
152
+ "url": "/files/list_folder",
153
+ "options": {
154
+ "body": { "path": "" },
155
+ "perPage": 100
156
+ }
157
+ }'
158
+ */
@@ -0,0 +1,161 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#files-search_v2
2
+
3
+ const { ArgsWarden, Getter, logDeep } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+ const { MAX_PER_PAGE } = require('../dropbox/dropbox.constants');
7
+
8
+ const argsWarden = new ArgsWarden([
9
+ ['credsPayload', credsValidator],
10
+ ['query'],
11
+ ]);
12
+
13
+ const dropboxSearchPacket = async (
14
+ credsPayload,
15
+ query,
16
+ {
17
+ body = {},
18
+ perPage = 100,
19
+ fetchClient = dropboxClient,
20
+ } = {},
21
+ ) => {
22
+ if (body.cursor) {
23
+ return fetchClient.fetch({
24
+ context: { credsPayload },
25
+ requestPayload: {
26
+ method: 'post',
27
+ url: '/files/search/continue_v2',
28
+ body: { cursor: body.cursor },
29
+ },
30
+ });
31
+ }
32
+
33
+ return fetchClient.fetch({
34
+ context: { credsPayload },
35
+ requestPayload: {
36
+ method: 'post',
37
+ url: '/files/search_v2',
38
+ body: {
39
+ query,
40
+ options: {
41
+ max_results: Math.min(perPage, MAX_PER_PAGE),
42
+ ...(body.options || {}),
43
+ },
44
+ ...(body.match_field_options && {
45
+ match_field_options: body.match_field_options,
46
+ }),
47
+ },
48
+ },
49
+ });
50
+ };
51
+
52
+ const dropboxSearchPaginator = async (currentParams, response) => {
53
+ if (!response?.ok) {
54
+ return [true];
55
+ }
56
+
57
+ const { has_more: hasMore, cursor } = response.data ?? {};
58
+ if (!hasMore || !cursor) {
59
+ return [true];
60
+ }
61
+
62
+ const { args, options } = currentParams;
63
+
64
+ return [false, {
65
+ args,
66
+ options: {
67
+ ...options,
68
+ body: {
69
+ cursor,
70
+ },
71
+ },
72
+ }];
73
+ };
74
+
75
+ const dropboxSearch = async (
76
+ returnGetter,
77
+
78
+ credsPayload,
79
+ query,
80
+ {
81
+ path,
82
+ fileStatus,
83
+ filenameOnly,
84
+ maxResults,
85
+ fileCategories,
86
+ accountId,
87
+ perPage = 100,
88
+ fetchClient,
89
+ ...getterOptions
90
+ } = {},
91
+ ) => {
92
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
93
+ credsPayload,
94
+ query,
95
+ });
96
+ if (rejectResponse) {
97
+ return rejectResponse;
98
+ }
99
+
100
+ const options = {
101
+ ...(path !== undefined && { path }),
102
+ ...(fileStatus !== undefined && { file_status: fileStatus }),
103
+ ...(filenameOnly !== undefined && { filename_only: filenameOnly }),
104
+ ...(maxResults !== undefined && { max_results: maxResults }),
105
+ ...(fileCategories !== undefined && { file_categories: fileCategories }),
106
+ ...(accountId !== undefined && { account_id: accountId }),
107
+ };
108
+
109
+ const getter = new Getter(
110
+ {
111
+ args: [credsPayload, query],
112
+ options: {
113
+ body: { options },
114
+ perPage: maxResults ?? perPage,
115
+ fetchClient,
116
+ },
117
+ },
118
+ {
119
+ func: dropboxSearchPacket,
120
+ digester: (response) => {
121
+ if (!response?.ok) {
122
+ return [];
123
+ }
124
+ return response.data?.matches ?? [];
125
+ },
126
+ paginator: dropboxSearchPaginator,
127
+ ...getterOptions,
128
+ },
129
+ );
130
+
131
+ if (returnGetter) {
132
+ return getter;
133
+ }
134
+
135
+ const data = await getter.run({ returnAll: true });
136
+
137
+ return {
138
+ ok: true,
139
+ data,
140
+ };
141
+ };
142
+
143
+ const funcApiConfig = {
144
+ argsWarden,
145
+ };
146
+
147
+ module.exports = {
148
+ dropboxSearch: (...args) => dropboxSearch(false, ...args),
149
+ dropboxSearchGetter: (...args) => dropboxSearch(true, ...args),
150
+ funcApiConfig,
151
+ };
152
+
153
+ /*
154
+ curl -X POST "http://localhost:8000/dropboxSearch" \
155
+ -H "Content-Type: application/json" \
156
+ -d '{
157
+ "credsPayload": { "credsPath": "dropbox" },
158
+ "query": "prime",
159
+ "options": { "path": "/Homework" }
160
+ }'
161
+ */
@@ -0,0 +1,68 @@
1
+ // https://www.dropbox.com/developers/documentation/http/documentation#sharing-create_shared_link_with_settings
2
+
3
+ const { ArgsWarden, logDeep } = require('../utils');
4
+ const { credsValidator } = require('../validators');
5
+ const { dropboxClient } = require('../dropbox/dropbox.utils');
6
+
7
+ const argsWarden = new ArgsWarden([
8
+ ['credsPayload', credsValidator],
9
+ ['path'],
10
+ ]);
11
+
12
+ const dropboxSharedLinkCreate = async (
13
+ credsPayload,
14
+ path,
15
+ {
16
+ settings,
17
+ fetchClient = dropboxClient,
18
+ } = {},
19
+ ) => {
20
+ const rejectResponse = await argsWarden.responseIfRejectingArgs({
21
+ credsPayload,
22
+ path,
23
+ });
24
+ if (rejectResponse) {
25
+ return rejectResponse;
26
+ }
27
+
28
+ const response = await fetchClient.fetch({
29
+ context: { credsPayload },
30
+ requestPayload: {
31
+ method: 'post',
32
+ url: '/sharing/create_shared_link_with_settings',
33
+ body: {
34
+ path,
35
+ ...(settings !== undefined && { settings }),
36
+ },
37
+ },
38
+ });
39
+
40
+ const { ok, data, error } = response;
41
+ if (!ok) {
42
+ logDeep({ error });
43
+ return { ok: false, error };
44
+ }
45
+
46
+ return {
47
+ ok: true,
48
+ data,
49
+ };
50
+ };
51
+
52
+ const funcApiConfig = {
53
+ argsWarden,
54
+ };
55
+
56
+ module.exports = {
57
+ dropboxSharedLinkCreate,
58
+ funcApiConfig,
59
+ };
60
+
61
+ /*
62
+ curl -X POST "http://localhost:8000/dropboxSharedLinkCreate" \
63
+ -H "Content-Type: application/json" \
64
+ -d '{
65
+ "credsPayload": { "credsPath": "dropbox" },
66
+ "path": "/Homework/math/Prime_Numbers.txt"
67
+ }'
68
+ */