@foxtware/mineral 0.1.27 → 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 (178) hide show
  1. package/.creds.yml.sample +29 -0
  2. package/AGENTS.md +24 -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/fastsimon/.gitkeep +0 -0
  22. package/api/fastsimon/docs.md +14 -0
  23. package/api/fastsimon/fastsimon.constants.js +18 -0
  24. package/api/fastsimon/fastsimon.utils.js +246 -0
  25. package/api/fastsimon/fastsimonSearch.js +84 -0
  26. package/api/figma/docs.md +3 -3
  27. package/api/figma/figma.constants.js +1 -1
  28. package/api/figma/figma.utils.js +13 -2
  29. package/api/figma/figmaActivityLogsGet.js +44 -0
  30. package/api/figma/figmaAiUsageDailyGet.js +44 -0
  31. package/api/figma/figmaComponentGet.js +48 -0
  32. package/api/figma/figmaComponentSetGet.js +48 -0
  33. package/api/figma/figmaDevResourcesCreate.js +47 -0
  34. package/api/figma/figmaDevResourcesUpdate.js +47 -0
  35. package/api/figma/figmaDeveloperLogsCreate.js +47 -0
  36. package/api/figma/figmaDiscoveryGet.js +44 -0
  37. package/api/figma/figmaFileCommentCreate.js +50 -0
  38. package/api/figma/figmaFileCommentDelete.js +51 -0
  39. package/api/figma/figmaFileCommentReactionCreate.js +53 -0
  40. package/api/figma/figmaFileCommentReactionDelete.js +51 -0
  41. package/api/figma/figmaFileCommentReactionsGet.js +51 -0
  42. package/api/figma/figmaFileCommentsGet.js +48 -0
  43. package/api/figma/figmaFileComponentSetsGet.js +48 -0
  44. package/api/figma/figmaFileComponentsGet.js +48 -0
  45. package/api/figma/figmaFileDevResourceDelete.js +51 -0
  46. package/api/figma/figmaFileDevResourcesGet.js +48 -0
  47. package/api/figma/figmaFileGet.js +48 -0
  48. package/api/figma/figmaFileImageFillsGet.js +48 -0
  49. package/api/figma/figmaFileImagesGet.js +48 -0
  50. package/api/figma/figmaFileMetaGet.js +48 -0
  51. package/api/figma/figmaFileNodesGet.js +48 -0
  52. package/api/figma/figmaFileStylesGet.js +48 -0
  53. package/api/figma/figmaFileVersionsGet.js +48 -0
  54. package/api/figma/figmaFolderFilesGet.js +48 -0
  55. package/api/figma/figmaFolderFoldersGet.js +48 -0
  56. package/api/figma/figmaFolderMetaGet.js +48 -0
  57. package/api/figma/figmaGet.js +15 -63
  58. package/api/figma/figmaMeGet.js +53 -0
  59. package/api/figma/figmaOembedGet.js +44 -0
  60. package/api/figma/figmaPaymentsGet.js +44 -0
  61. package/api/figma/figmaProjectFilesGet.js +48 -0
  62. package/api/figma/figmaProjectMetaGet.js +48 -0
  63. package/api/figma/figmaStyleGet.js +48 -0
  64. package/api/figma/figmaTeamComponentSetsGet.js +48 -0
  65. package/api/figma/figmaTeamComponentsGet.js +48 -0
  66. package/api/figma/figmaTeamFoldersGet.js +48 -0
  67. package/api/figma/figmaTeamProjectsGet.js +48 -0
  68. package/api/figma/figmaTeamStylesGet.js +48 -0
  69. package/api/figma/figmaTeamWebhooksGet.js +47 -0
  70. package/api/figma/figmaVariablesLocalGet.js +48 -0
  71. package/api/figma/figmaVariablesPublishedGet.js +48 -0
  72. package/api/figma/figmaVariablesUpdate.js +50 -0
  73. package/api/figma/figmaWebhookCreate.js +47 -0
  74. package/api/figma/figmaWebhookDelete.js +48 -0
  75. package/api/figma/figmaWebhookGet.js +46 -0
  76. package/api/figma/figmaWebhookRequestsGet.js +47 -0
  77. package/api/figma/figmaWebhookUpdate.js +50 -0
  78. package/api/figma/figmaWebhooksGet.js +47 -0
  79. package/api/google/docs.md +1 -0
  80. package/api/google/google.constants.js +1 -0
  81. package/api/google/google.utils.js +21 -0
  82. package/api/google/googleanalyticsMetadataGet.js +62 -0
  83. package/api/google/googleanalyticsRealtimeReportRun.js +103 -0
  84. package/api/google/googleanalyticsReportRun.js +114 -0
  85. package/api/gorgias/gorgiasTicketCreate.js +1 -1
  86. package/api/gorgias/gorgiasTicketMessageCreate.js +1 -1
  87. package/api/gorgias/gorgiasTicketUpdate.js +1 -1
  88. package/api/linear/linearAttachmentCreate.js +1 -1
  89. package/api/linear/linearCommentCreate.js +1 -1
  90. package/api/linear/linearCommentUpdate.js +1 -1
  91. package/api/linear/linearIssueLabelCreate.js +1 -1
  92. package/api/linear/linearIssueUpdate.js +1 -1
  93. package/api/linear/linearProjectCreate.js +1 -1
  94. package/api/linear/linearProjectUpdate.js +1 -1
  95. package/api/linear/linearWebhookCreate.js +1 -1
  96. package/api/salesforce/salesforce.constants.js +13 -0
  97. package/api/salesforce/salesforce.utils.js +61 -0
  98. package/api/salesforce/salesforceAuthGet.js +115 -0
  99. package/api/salesforce/salesforceComposite.js +79 -0
  100. package/api/salesforce/salesforceCompositeBatch.js +73 -0
  101. package/api/salesforce/salesforceLimitsGet.js +55 -0
  102. package/api/salesforce/salesforceQuery.js +69 -0
  103. package/api/salesforce/salesforceQueryAll.js +62 -0
  104. package/api/salesforce/salesforceQueryMore.js +75 -0
  105. package/api/salesforce/salesforceRecentItemsGet.js +63 -0
  106. package/api/salesforce/salesforceResourcesGet.js +55 -0
  107. package/api/salesforce/salesforceSearch.js +62 -0
  108. package/api/salesforce/salesforceSobjectBasicInfoGet.js +81 -0
  109. package/api/salesforce/salesforceSobjectBlobGet.js +67 -0
  110. package/api/salesforce/salesforceSobjectCollectionCreate.js +78 -0
  111. package/api/salesforce/salesforceSobjectCollectionDelete.js +70 -0
  112. package/api/salesforce/salesforceSobjectCollectionGet.js +75 -0
  113. package/api/salesforce/salesforceSobjectCollectionUpdate.js +74 -0
  114. package/api/salesforce/salesforceSobjectCreate.js +66 -0
  115. package/api/salesforce/salesforceSobjectDelete.js +86 -0
  116. package/api/salesforce/salesforceSobjectDeleteByExternalId.js +91 -0
  117. package/api/salesforce/salesforceSobjectDeletedGet.js +71 -0
  118. package/api/salesforce/salesforceSobjectDescribe.js +81 -0
  119. package/api/salesforce/salesforceSobjectDescribeLayouts.js +64 -0
  120. package/api/salesforce/salesforceSobjectGet.js +93 -0
  121. package/api/salesforce/salesforceSobjectGetByExternalId.js +98 -0
  122. package/api/salesforce/salesforceSobjectTreeCreate.js +79 -0
  123. package/api/salesforce/salesforceSobjectUpdate.js +94 -0
  124. package/api/salesforce/salesforceSobjectUpdatedGet.js +71 -0
  125. package/api/salesforce/salesforceSobjectUpsert.js +74 -0
  126. package/api/salesforce/salesforceSobjectsDescribeGlobal.js +55 -0
  127. package/api/salesforce/salesforceVersionsGet.js +62 -0
  128. package/api/shopify/shopify.utils.js +53 -4
  129. package/api/shopify/shopifyMetaobjectCreate.js +79 -0
  130. package/api/shopify/shopifyMetaobjectDelete.js +90 -0
  131. package/api/shopify/shopifyMetaobjectGet.js +80 -0
  132. package/api/shopify/shopifyMetaobjectUpdate.js +108 -0
  133. package/api/shopify/shopifyStorefrontSearch.js +158 -0
  134. package/api/spotify/docs.md +8 -0
  135. package/api/spotify/spotify.constants.js +12 -0
  136. package/api/spotify/spotify.utils.js +106 -0
  137. package/api/spotify/spotifyAlbumGet.js +76 -0
  138. package/api/spotify/spotifyAlbumTracksGet.js +49 -0
  139. package/api/spotify/spotifyArtistAlbumsGet.js +55 -0
  140. package/api/spotify/spotifyArtistGet.js +71 -0
  141. package/api/spotify/spotifyArtistTopTracksGet.js +56 -0
  142. package/api/spotify/spotifyGet.js +171 -0
  143. package/api/spotify/spotifyMeGet.js +48 -0
  144. package/api/spotify/spotifyPlayerCurrentlyPlayingGet.js +62 -0
  145. package/api/spotify/spotifyPlayerDevicesGet.js +51 -0
  146. package/api/spotify/spotifyPlayerGet.js +63 -0
  147. package/api/spotify/spotifyPlayerNext.js +55 -0
  148. package/api/spotify/spotifyPlayerPause.js +55 -0
  149. package/api/spotify/spotifyPlayerPlay.js +70 -0
  150. package/api/spotify/spotifyPlayerPrevious.js +55 -0
  151. package/api/spotify/spotifyPlaylistCreate.js +63 -0
  152. package/api/spotify/spotifyPlaylistGet.js +91 -0
  153. package/api/spotify/spotifyPlaylistItemsAdd.js +61 -0
  154. package/api/spotify/spotifyPlaylistItemsGet.js +58 -0
  155. package/api/spotify/spotifyPlaylistItemsRemove.js +67 -0
  156. package/api/spotify/spotifyPlaylistUpdate.js +64 -0
  157. package/api/spotify/spotifyPlaylistsGet.js +47 -0
  158. package/api/spotify/spotifySavedTracksGet.js +46 -0
  159. package/api/spotify/spotifySavedTracksRemove.js +59 -0
  160. package/api/spotify/spotifySavedTracksSave.js +59 -0
  161. package/api/spotify/spotifySearch.js +174 -0
  162. package/api/spotify/spotifyTrackGet.js +76 -0
  163. package/api/tableau/tableau.constants.js +8 -0
  164. package/api/tableau/tableau.utils.js +93 -0
  165. package/api/tableau/tableauGet.js +174 -0
  166. package/api/tableau/tableauUserAdd.js +16 -94
  167. package/api/tableau/tableauUsersGet.js +46 -134
  168. package/api/tagalys/docs.md +2 -2
  169. package/api/tagalys/tagalys.constants.js +17 -0
  170. package/api/tagalys/tagalys.utils.js +125 -0
  171. package/api/tagalys/tagalysAnalyticsEventSend.js +125 -0
  172. package/api/tagalys/tagalysCollectionGet.js +100 -0
  173. package/api/tagalys/tagalysPopularSearchesGet.js +60 -0
  174. package/api/tagalys/tagalysRecommendationGet.js +109 -0
  175. package/api/tagalys/tagalysSearch.js +15 -89
  176. package/api/tagalys/tagalysSearchSuggestionsGet.js +76 -0
  177. package/package.json +2 -1
  178. 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
+ */