@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,139 @@
|
|
|
1
|
+
// https://www.dropbox.com/developers/documentation/http/documentation#files-download
|
|
2
|
+
// Returns file metadata plus contents as base64 (JSON-safe).
|
|
3
|
+
|
|
4
|
+
const { ArgsWarden, actionSingleOrMultiple, logDeep } = require('../utils');
|
|
5
|
+
const { credsValidator } = require('../validators');
|
|
6
|
+
const { customFetch, appendUrlToBase, credsFromPayload } = require('../utils');
|
|
7
|
+
const { DROPBOX_CONTENT_BASE_URL } = require('../dropbox/dropbox.constants');
|
|
8
|
+
|
|
9
|
+
const argsWarden = new ArgsWarden([
|
|
10
|
+
['credsPayload', credsValidator],
|
|
11
|
+
['path'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const dropboxFileDownloadSingle = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
path,
|
|
17
|
+
{
|
|
18
|
+
rev,
|
|
19
|
+
// When true, return raw ArrayBuffer in data.contentsBuffer instead of base64
|
|
20
|
+
// (not useful over funcApi JSON; kept for in-process callers).
|
|
21
|
+
asBuffer = false,
|
|
22
|
+
} = {},
|
|
23
|
+
) => {
|
|
24
|
+
const creds = await credsFromPayload(credsPayload);
|
|
25
|
+
const { ACCESS_TOKEN } = creds ?? {};
|
|
26
|
+
|
|
27
|
+
if (!ACCESS_TOKEN) {
|
|
28
|
+
return {
|
|
29
|
+
ok: false,
|
|
30
|
+
error: {
|
|
31
|
+
code: 'MISSING_DROPBOX_CREDS',
|
|
32
|
+
message: 'dropbox creds require ACCESS_TOKEN',
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const arg = {
|
|
38
|
+
path,
|
|
39
|
+
...(rev !== undefined && { rev }),
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const url = appendUrlToBase(DROPBOX_CONTENT_BASE_URL, '/files/download');
|
|
43
|
+
|
|
44
|
+
// customFetch so we can read Dropbox-API-Result header + binary body.
|
|
45
|
+
const response = await customFetch(url, {
|
|
46
|
+
method: 'post',
|
|
47
|
+
headers: {
|
|
48
|
+
Authorization: `Bearer ${ ACCESS_TOKEN }`,
|
|
49
|
+
'Dropbox-API-Arg': JSON.stringify(arg),
|
|
50
|
+
},
|
|
51
|
+
// Empty body; Dropbox still expects POST.
|
|
52
|
+
body: '',
|
|
53
|
+
responseParser: async (res) => {
|
|
54
|
+
const resultHeader = res.headers.get('dropbox-api-result');
|
|
55
|
+
let metadata = null;
|
|
56
|
+
if (resultHeader) {
|
|
57
|
+
try {
|
|
58
|
+
metadata = JSON.parse(resultHeader);
|
|
59
|
+
} catch {
|
|
60
|
+
metadata = { raw: resultHeader };
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
65
|
+
return {
|
|
66
|
+
metadata,
|
|
67
|
+
buffer,
|
|
68
|
+
};
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
if (!response.ok) {
|
|
73
|
+
logDeep({ error: response.error ?? response.data });
|
|
74
|
+
return {
|
|
75
|
+
ok: false,
|
|
76
|
+
error: response.error ?? response.data,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const { metadata, buffer } = response.data;
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
ok: true,
|
|
84
|
+
data: {
|
|
85
|
+
...(metadata || {}),
|
|
86
|
+
...(asBuffer
|
|
87
|
+
? { contentsBuffer: buffer }
|
|
88
|
+
: { contentsBase64: buffer.toString('base64') }),
|
|
89
|
+
size: buffer.length,
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const dropboxFileDownload = async (
|
|
95
|
+
credsPayload,
|
|
96
|
+
path,
|
|
97
|
+
{
|
|
98
|
+
rev,
|
|
99
|
+
asBuffer,
|
|
100
|
+
queueRunOptions,
|
|
101
|
+
} = {},
|
|
102
|
+
) => {
|
|
103
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
104
|
+
credsPayload,
|
|
105
|
+
path,
|
|
106
|
+
});
|
|
107
|
+
if (rejectResponse) {
|
|
108
|
+
return rejectResponse;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
return actionSingleOrMultiple(
|
|
112
|
+
path,
|
|
113
|
+
dropboxFileDownloadSingle,
|
|
114
|
+
(pathItem) => ({
|
|
115
|
+
args: [credsPayload, pathItem, { rev, asBuffer }],
|
|
116
|
+
}),
|
|
117
|
+
{
|
|
118
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const funcApiConfig = {
|
|
124
|
+
argsWarden,
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
module.exports = {
|
|
128
|
+
dropboxFileDownload,
|
|
129
|
+
funcApiConfig,
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
/*
|
|
133
|
+
curl -X POST "http://localhost:8000/dropboxFileDownload" \
|
|
134
|
+
-H "Content-Type: application/json" \
|
|
135
|
+
-d '{
|
|
136
|
+
"credsPayload": { "credsPath": "dropbox" },
|
|
137
|
+
"path": "/Homework/math/Prime_Numbers.txt"
|
|
138
|
+
}'
|
|
139
|
+
*/
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// https://www.dropbox.com/developers/documentation/http/documentation#files-get_metadata
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden, actionSingleOrMultiple, 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 dropboxFileMetadataGetSingle = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
path,
|
|
15
|
+
{
|
|
16
|
+
includeMediaInfo = false,
|
|
17
|
+
includeDeleted = false,
|
|
18
|
+
includeHasExplicitSharedMembers = false,
|
|
19
|
+
fetchClient = dropboxClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
const response = await fetchClient.fetch({
|
|
23
|
+
context: { credsPayload },
|
|
24
|
+
requestPayload: {
|
|
25
|
+
method: 'post',
|
|
26
|
+
url: '/files/get_metadata',
|
|
27
|
+
body: {
|
|
28
|
+
path,
|
|
29
|
+
include_media_info: includeMediaInfo,
|
|
30
|
+
include_deleted: includeDeleted,
|
|
31
|
+
include_has_explicit_shared_members: includeHasExplicitSharedMembers,
|
|
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,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
const dropboxFileMetadataGet = async (
|
|
49
|
+
credsPayload,
|
|
50
|
+
path,
|
|
51
|
+
{
|
|
52
|
+
includeMediaInfo,
|
|
53
|
+
includeDeleted,
|
|
54
|
+
includeHasExplicitSharedMembers,
|
|
55
|
+
queueRunOptions,
|
|
56
|
+
fetchClient,
|
|
57
|
+
} = {},
|
|
58
|
+
) => {
|
|
59
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
60
|
+
credsPayload,
|
|
61
|
+
path,
|
|
62
|
+
});
|
|
63
|
+
if (rejectResponse) {
|
|
64
|
+
return rejectResponse;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return actionSingleOrMultiple(
|
|
68
|
+
path,
|
|
69
|
+
dropboxFileMetadataGetSingle,
|
|
70
|
+
(pathItem) => ({
|
|
71
|
+
args: [credsPayload, pathItem, {
|
|
72
|
+
includeMediaInfo,
|
|
73
|
+
includeDeleted,
|
|
74
|
+
includeHasExplicitSharedMembers,
|
|
75
|
+
fetchClient,
|
|
76
|
+
}],
|
|
77
|
+
}),
|
|
78
|
+
{
|
|
79
|
+
...(queueRunOptions ? { queueRunOptions } : {}),
|
|
80
|
+
},
|
|
81
|
+
);
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
const funcApiConfig = {
|
|
85
|
+
argsWarden,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
module.exports = {
|
|
89
|
+
dropboxFileMetadataGet,
|
|
90
|
+
funcApiConfig,
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
/*
|
|
94
|
+
curl -X POST "http://localhost:8000/dropboxFileMetadataGet" \
|
|
95
|
+
-H "Content-Type: application/json" \
|
|
96
|
+
-d '{
|
|
97
|
+
"credsPayload": { "credsPath": "dropbox" },
|
|
98
|
+
"path": "/Homework/math/Prime_Numbers.txt"
|
|
99
|
+
}'
|
|
100
|
+
*/
|
|
@@ -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
|
+
*/
|