@foxtware/mineral 0.1.16 → 0.1.18
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 +16 -7
- package/AGENTS.md +3 -0
- package/_build_scripts/publish.js +15 -1
- package/api/backblaze/backblaze.constants.js +11 -0
- package/api/backblaze/backblaze.utils.js +322 -0
- package/api/backblaze/backblazeBucketsGet.js +68 -0
- package/api/backblaze/backblazeFileDelete.js +62 -0
- package/api/backblaze/backblazeFileHide.js +62 -0
- package/api/backblaze/backblazeFileUpload.js +142 -0
- package/api/backblaze/backblazeFilesGet.js +85 -0
- package/api/backblaze/backblazeGet.js +139 -0
- package/api/backblaze/docs.md +6 -0
- package/api/etsy/etsyListingInventoryUpdate.js +11 -11
- package/api/etsy/etsyListingUpdate.js +1 -1
- package/api/gorgias/gorgias.constants.js +8 -0
- package/api/gorgias/gorgias.utils.js +46 -0
- package/api/gorgias/gorgiasAccountGet.js +51 -0
- package/api/gorgias/gorgiasCustomerGet.js +70 -0
- package/api/gorgias/gorgiasCustomersGet.js +56 -0
- package/api/gorgias/gorgiasGet.js +150 -0
- package/api/gorgias/gorgiasGetSingle.js +26 -0
- package/api/gorgias/gorgiasMessagesGet.js +56 -0
- package/api/gorgias/gorgiasTagsGet.js +52 -0
- package/api/gorgias/gorgiasTicketCreate.js +66 -0
- package/api/gorgias/gorgiasTicketGet.js +70 -0
- package/api/gorgias/gorgiasTicketMessageCreate.js +65 -0
- package/api/gorgias/gorgiasTicketMessagesGet.js +66 -0
- package/api/gorgias/gorgiasTicketUpdate.js +62 -0
- package/api/gorgias/gorgiasTicketsGet.js +58 -0
- package/api/gorgias/gorgiasUsersGet.js +52 -0
- package/api/gorgias/gorgiasViewItemsGet.js +57 -0
- package/api/gorgias/gorgiasViewsGet.js +72 -0
- package/api/linear/docs.md +6 -0
- package/api/linear/linear.constants.js +3 -0
- package/api/linear/linear.utils.js +59 -0
- package/api/linear/linearAttachmentCreate.js +77 -0
- package/api/linear/linearAttachmentDelete.js +68 -0
- package/api/linear/linearCommentCreate.js +77 -0
- package/api/linear/linearCommentDelete.js +68 -0
- package/api/linear/linearCommentGet.js +77 -0
- package/api/linear/linearCommentUpdate.js +87 -0
- package/api/linear/linearCommentsGet.js +70 -0
- package/api/linear/linearCyclesGet.js +67 -0
- package/api/linear/linearGet.js +218 -0
- package/api/linear/linearIssueAddLabel.js +77 -0
- package/api/linear/linearIssueArchive.js +74 -0
- package/api/linear/linearIssueCreate.js +94 -0
- package/api/linear/linearIssueDelete.js +74 -0
- package/api/linear/linearIssueGet.js +87 -0
- package/api/linear/linearIssueLabelCreate.js +81 -0
- package/api/linear/linearIssueLabelsGet.js +66 -0
- package/api/linear/linearIssueRemoveLabel.js +77 -0
- package/api/linear/linearIssueUpdate.js +96 -0
- package/api/linear/linearIssuesGet.js +39 -63
- package/api/linear/linearOrganizationGet.js +64 -0
- package/api/linear/linearProjectCreate.js +92 -0
- package/api/linear/linearProjectGet.js +74 -0
- package/api/linear/linearProjectUpdate.js +80 -0
- package/api/linear/linearProjectsGet.js +71 -0
- package/api/linear/linearTeamGet.js +71 -0
- package/api/linear/linearTeamsGet.js +66 -0
- package/api/linear/linearUserGet.js +72 -0
- package/api/linear/linearUsersGet.js +71 -0
- package/api/linear/linearViewerGet.js +65 -0
- package/api/linear/linearWebhookCreate.js +77 -0
- package/api/linear/linearWebhookDelete.js +68 -0
- package/api/linear/linearWebhooksGet.js +67 -0
- package/api/linear/linearWorkflowStatesGet.js +73 -0
- package/api/pipe17/pipe17.utils.js +7 -20
- package/api/pipe17/pipe17ArrivalGet.js +1 -1
- package/api/pipe17/pipe17FulfillmentGet.js +1 -1
- package/api/pipe17/pipe17InventoryItemGet.js +1 -1
- package/api/pipe17/pipe17JobGet.js +11 -24
- package/api/pipe17/pipe17LocationGet.js +1 -1
- package/api/pipe17/pipe17OrderGet.js +1 -1
- package/api/pipe17/pipe17ProductGet.js +1 -1
- package/api/pipe17/pipe17PurchaseGet.js +1 -1
- package/api/pipe17/pipe17ReceiptGet.js +1 -1
- package/api/pipe17/pipe17ReturnGet.js +1 -1
- package/api/shopify/shopifyFileCreate.js +107 -0
- package/api/shopify/shopifyMetafieldDefinitionCreate.js +2 -0
- package/api/shopify/shopifyMetafieldDefinitionGet.js +108 -0
- package/api/shopify/shopifyMetafieldDefinitionPropagate.js +167 -0
- package/api/shopify/shopifyThemeFileGet.js +112 -0
- package/api/shopify/shopifyThemeFilePropagate.js +410 -0
- package/api/shopify/shopifyThemeFilesUpsert.js +88 -0
- package/api/starshipit/starshipit.utils.js +1 -0
- package/api/starshipit/starshipitOrderGet.js +2 -10
- package/api/utils.js +12 -4
- package/hosting/deployFromHostingYml.js +2 -2
- package/hosting/execCommand.js +19 -2
- package/package.json +1 -1
- package/server.utils.js +1 -1
package/.creds.yml.sample
CHANGED
|
@@ -78,27 +78,36 @@ etsy:
|
|
|
78
78
|
SHARED_SECRET: _________________________
|
|
79
79
|
|
|
80
80
|
clickup:
|
|
81
|
-
API_KEY:
|
|
81
|
+
API_KEY: pk_____________________________
|
|
82
82
|
|
|
83
83
|
asana:
|
|
84
84
|
ACCESS_TOKEN: __________________________
|
|
85
85
|
|
|
86
86
|
notion:
|
|
87
|
-
API_KEY:
|
|
87
|
+
API_KEY: secret_________________________
|
|
88
88
|
|
|
89
89
|
discord:
|
|
90
|
-
BOT_TOKEN:
|
|
90
|
+
BOT_TOKEN: _____________________________
|
|
91
91
|
|
|
92
92
|
telnyx:
|
|
93
|
-
API_KEY:
|
|
93
|
+
API_KEY: KEY____________________________
|
|
94
94
|
|
|
95
95
|
figma:
|
|
96
|
-
API_KEY:
|
|
96
|
+
API_KEY: figd___________________________
|
|
97
97
|
|
|
98
98
|
pipe17:
|
|
99
|
-
API_KEY:
|
|
99
|
+
API_KEY: _______________________________
|
|
100
100
|
sandbox:
|
|
101
|
-
API_KEY:
|
|
101
|
+
API_KEY: _____________________________
|
|
102
|
+
|
|
103
|
+
backblaze:
|
|
104
|
+
APP_ID: ________________________________
|
|
105
|
+
API_KEY: _______________________________
|
|
106
|
+
|
|
107
|
+
gorgias:
|
|
108
|
+
DOMAIN: ________________________________
|
|
109
|
+
EMAIL: _________________________________
|
|
110
|
+
API_KEY: _______________________________
|
|
102
111
|
|
|
103
112
|
google:
|
|
104
113
|
SERVICE_ACCOUNT_JSON:
|
package/AGENTS.md
CHANGED
|
@@ -17,6 +17,9 @@ Notes for AI assistants working in this directory. **Read this file at the start
|
|
|
17
17
|
- Refer to _example.js files for reference on how functions are laid out, e.g. use of argsWarden.
|
|
18
18
|
- If other functions in the platform use fetchClient as passed through options, support it as well.
|
|
19
19
|
- skim an existing platform of the same shape before considering inventing a new pattern.
|
|
20
|
+
- docs.md in each platform should not describe the details of our implementation, handlers or anything relating to Mineral. It is for describing the platform's API itself and does not change based on what we do with it. It should also be brief.
|
|
21
|
+
- Usually when making a function that gets multiples of a resource, it should be implemented as a Getter, with a paginator and digester. If done in this way, export platformThingGet and platformThingGetter, using the .bind() syntax seen in other Get functions.
|
|
22
|
+
- When making functions that act on single resources, consider using actionSingleOrMultiple to allow a queue of actions.
|
|
20
23
|
|
|
21
24
|
## API clients
|
|
22
25
|
- Base URLs for platform clients should live in `{platform}.constants.js`, not creds, if they are static for all users of the API.
|
|
@@ -53,7 +53,21 @@ const ensureLoggedIn = () => {
|
|
|
53
53
|
stdio: 'pipe',
|
|
54
54
|
});
|
|
55
55
|
} catch {
|
|
56
|
-
|
|
56
|
+
console.log('Not logged in to npm. Running `npm login`…');
|
|
57
|
+
execSync('npm login', {
|
|
58
|
+
cwd: mineralRoot,
|
|
59
|
+
stdio: 'inherit',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
try {
|
|
63
|
+
execSync('npm whoami', {
|
|
64
|
+
cwd: mineralRoot,
|
|
65
|
+
encoding: 'utf8',
|
|
66
|
+
stdio: 'pipe',
|
|
67
|
+
});
|
|
68
|
+
} catch {
|
|
69
|
+
throw new Error('Still not logged in to npm. Use an account that can publish @foxtware/mineral.');
|
|
70
|
+
}
|
|
57
71
|
}
|
|
58
72
|
};
|
|
59
73
|
|
|
@@ -0,0 +1,322 @@
|
|
|
1
|
+
const crypto = require('crypto');
|
|
2
|
+
|
|
3
|
+
const { BASE_URL, B2_API_VERSION_PATH } = require('../backblaze/backblaze.constants');
|
|
4
|
+
const { resolveCreds } = require('../pipelineSteps');
|
|
5
|
+
const {
|
|
6
|
+
appendUrlToBase,
|
|
7
|
+
credsFromPayload,
|
|
8
|
+
customFetch,
|
|
9
|
+
FetchClient,
|
|
10
|
+
fetchClientCommonSteps,
|
|
11
|
+
objHasAny,
|
|
12
|
+
} = require('../utils');
|
|
13
|
+
|
|
14
|
+
const bucketIdentifierValidator = (bucketIdentifier) => {
|
|
15
|
+
return objHasAny(bucketIdentifier, [
|
|
16
|
+
'bucketId',
|
|
17
|
+
'bucketName',
|
|
18
|
+
]);
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
const sessionCacheKeyForCredsPayload = (credsPayload) => {
|
|
22
|
+
if (credsPayload?.credsPath) {
|
|
23
|
+
return credsPayload.credsPath;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return JSON.stringify(credsPayload);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const backblazeSessionsByKey = new Map();
|
|
30
|
+
|
|
31
|
+
const getBackblazeSession = async (credsPayload) => {
|
|
32
|
+
const cacheKey = sessionCacheKeyForCredsPayload(credsPayload);
|
|
33
|
+
|
|
34
|
+
if (backblazeSessionsByKey.has(cacheKey)) {
|
|
35
|
+
return {
|
|
36
|
+
ok: true,
|
|
37
|
+
data: backblazeSessionsByKey.get(cacheKey),
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const creds = await credsFromPayload(credsPayload);
|
|
42
|
+
const { APP_ID, API_KEY } = creds ?? {};
|
|
43
|
+
|
|
44
|
+
if (!APP_ID || !API_KEY) {
|
|
45
|
+
return {
|
|
46
|
+
ok: false,
|
|
47
|
+
error: {
|
|
48
|
+
code: 'MISSING_BACKBLAZE_CREDS',
|
|
49
|
+
message: 'backblaze creds require APP_ID and API_KEY',
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const basicToken = Buffer
|
|
55
|
+
.from(`${ APP_ID }:${ API_KEY }`)
|
|
56
|
+
.toString('base64');
|
|
57
|
+
|
|
58
|
+
const authorizeResponse = await customFetch(
|
|
59
|
+
`${ BASE_URL }${ B2_API_VERSION_PATH }/b2_authorize_account`,
|
|
60
|
+
{
|
|
61
|
+
method: 'get',
|
|
62
|
+
headers: {
|
|
63
|
+
Authorization: `Basic ${ basicToken }`,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
if (!authorizeResponse.ok) {
|
|
69
|
+
return authorizeResponse;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
accountId,
|
|
74
|
+
authorizationToken,
|
|
75
|
+
apiUrl,
|
|
76
|
+
downloadUrl,
|
|
77
|
+
} = authorizeResponse.data ?? {};
|
|
78
|
+
|
|
79
|
+
if (!accountId || !authorizationToken || !apiUrl) {
|
|
80
|
+
return {
|
|
81
|
+
ok: false,
|
|
82
|
+
error: {
|
|
83
|
+
code: 'INVALID_AUTHORIZE_RESPONSE',
|
|
84
|
+
message: 'b2_authorize_account response missing accountId, authorizationToken, or apiUrl',
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
const session = {
|
|
90
|
+
accountId,
|
|
91
|
+
authorizationToken,
|
|
92
|
+
apiUrl,
|
|
93
|
+
downloadUrl,
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
backblazeSessionsByKey.set(cacheKey, session);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
ok: true,
|
|
100
|
+
data: session,
|
|
101
|
+
};
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
const attachBackblazeSession = async (state) => {
|
|
105
|
+
const { context } = state;
|
|
106
|
+
const { credsPayload, session } = context;
|
|
107
|
+
|
|
108
|
+
if (session) {
|
|
109
|
+
return {};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const sessionResponse = await getBackblazeSession(credsPayload);
|
|
113
|
+
|
|
114
|
+
if (!sessionResponse.ok) {
|
|
115
|
+
return {
|
|
116
|
+
breakChain: true,
|
|
117
|
+
response: sessionResponse,
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
return {
|
|
122
|
+
context: {
|
|
123
|
+
...context,
|
|
124
|
+
session: sessionResponse.data,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const useBackblazeApiUrl = async (state) => {
|
|
130
|
+
const { requestPayload, context } = state;
|
|
131
|
+
const { session } = context;
|
|
132
|
+
|
|
133
|
+
return {
|
|
134
|
+
requestPayload: {
|
|
135
|
+
...requestPayload,
|
|
136
|
+
url: appendUrlToBase(session.apiUrl, requestPayload.url),
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const useBackblazeAuthorizationHeader = async (state) => {
|
|
142
|
+
const { requestPayload, context } = state;
|
|
143
|
+
const { session } = context;
|
|
144
|
+
|
|
145
|
+
return {
|
|
146
|
+
requestPayload: {
|
|
147
|
+
...requestPayload,
|
|
148
|
+
headers: {
|
|
149
|
+
Authorization: session.authorizationToken,
|
|
150
|
+
...requestPayload.headers,
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
const backblazeClient = new FetchClient({
|
|
157
|
+
pipeline: [
|
|
158
|
+
resolveCreds,
|
|
159
|
+
attachBackblazeSession,
|
|
160
|
+
useBackblazeAuthorizationHeader,
|
|
161
|
+
useBackblazeApiUrl,
|
|
162
|
+
'fetch',
|
|
163
|
+
fetchClientCommonSteps.exitEarlyOnNotOk,
|
|
164
|
+
fetchClientCommonSteps.digToPath,
|
|
165
|
+
],
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
const publicFileUrlForBucketName = ({
|
|
169
|
+
downloadUrl,
|
|
170
|
+
bucketName,
|
|
171
|
+
fileName,
|
|
172
|
+
}) => {
|
|
173
|
+
if (!downloadUrl || !bucketName || !fileName) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
const encodedFileName = encodeURIComponent(fileName)
|
|
178
|
+
.replace(/%2F/g, '/');
|
|
179
|
+
|
|
180
|
+
return `${ downloadUrl }/file/${ bucketName }/${ encodedFileName }`;
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
const sha1HexForBuffer = (buffer) => {
|
|
184
|
+
return crypto
|
|
185
|
+
.createHash('sha1')
|
|
186
|
+
.update(buffer)
|
|
187
|
+
.digest('hex');
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const backblazeUploadFileBytes = async ({
|
|
191
|
+
credsPayload,
|
|
192
|
+
session,
|
|
193
|
+
bucketId,
|
|
194
|
+
fileName,
|
|
195
|
+
fileBytes,
|
|
196
|
+
contentType = 'b2/x-auto',
|
|
197
|
+
}) => {
|
|
198
|
+
let resolvedSession = session;
|
|
199
|
+
|
|
200
|
+
if (!resolvedSession) {
|
|
201
|
+
const sessionResponse = await getBackblazeSession(credsPayload);
|
|
202
|
+
|
|
203
|
+
if (!sessionResponse.ok) {
|
|
204
|
+
return sessionResponse;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
({ data: resolvedSession } = sessionResponse);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
const uploadUrlResponse = await backblazeClient.fetch({
|
|
211
|
+
requestPayload: {
|
|
212
|
+
method: 'post',
|
|
213
|
+
url: `${ B2_API_VERSION_PATH }/b2_get_upload_url`,
|
|
214
|
+
body: { bucketId },
|
|
215
|
+
},
|
|
216
|
+
context: {
|
|
217
|
+
credsPayload,
|
|
218
|
+
session: resolvedSession,
|
|
219
|
+
},
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
if (!uploadUrlResponse.ok) {
|
|
223
|
+
return uploadUrlResponse;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
const {
|
|
227
|
+
uploadUrl,
|
|
228
|
+
authorizationToken: uploadAuthorizationToken,
|
|
229
|
+
} = uploadUrlResponse.data ?? {};
|
|
230
|
+
|
|
231
|
+
if (!uploadUrl || !uploadAuthorizationToken) {
|
|
232
|
+
return {
|
|
233
|
+
ok: false,
|
|
234
|
+
error: {
|
|
235
|
+
code: 'INVALID_UPLOAD_URL_RESPONSE',
|
|
236
|
+
message: 'b2_get_upload_url response missing uploadUrl or authorizationToken',
|
|
237
|
+
},
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
const contentSha1 = sha1HexForBuffer(fileBytes);
|
|
242
|
+
|
|
243
|
+
return customFetch(uploadUrl, {
|
|
244
|
+
method: 'post',
|
|
245
|
+
headers: {
|
|
246
|
+
Authorization: uploadAuthorizationToken,
|
|
247
|
+
'X-Bz-File-Name': encodeURIComponent(fileName),
|
|
248
|
+
'X-Bz-Content-Sha1': contentSha1,
|
|
249
|
+
'Content-Type': contentType,
|
|
250
|
+
},
|
|
251
|
+
body: fileBytes,
|
|
252
|
+
});
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
const resolveBucketIdFromIdentifier = async (
|
|
256
|
+
credsPayload,
|
|
257
|
+
bucketIdentifier,
|
|
258
|
+
{
|
|
259
|
+
fetchClient,
|
|
260
|
+
} = {},
|
|
261
|
+
) => {
|
|
262
|
+
const {
|
|
263
|
+
bucketId,
|
|
264
|
+
bucketName,
|
|
265
|
+
} = bucketIdentifier;
|
|
266
|
+
|
|
267
|
+
if (bucketId) {
|
|
268
|
+
return {
|
|
269
|
+
ok: true,
|
|
270
|
+
data: bucketId,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (!bucketName) {
|
|
275
|
+
return {
|
|
276
|
+
ok: false,
|
|
277
|
+
error: {
|
|
278
|
+
code: 'BUCKET_NOT_FOUND',
|
|
279
|
+
message: 'Provide bucketId or bucketName',
|
|
280
|
+
},
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const { backblazeBucketsGet } = require('../backblaze/backblazeBucketsGet');
|
|
285
|
+
|
|
286
|
+
const bucketsResponse = await backblazeBucketsGet(credsPayload, {
|
|
287
|
+
bucketName,
|
|
288
|
+
fetchClient,
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
if (!bucketsResponse.ok) {
|
|
292
|
+
return bucketsResponse;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const bucket = bucketsResponse.data?.find(
|
|
296
|
+
(candidate) => candidate.bucketName === bucketName,
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
if (!bucket?.bucketId) {
|
|
300
|
+
return {
|
|
301
|
+
ok: false,
|
|
302
|
+
error: {
|
|
303
|
+
code: 'BUCKET_NOT_FOUND',
|
|
304
|
+
message: `Bucket ${ bucketName } not found`,
|
|
305
|
+
},
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return {
|
|
310
|
+
ok: true,
|
|
311
|
+
data: bucket.bucketId,
|
|
312
|
+
};
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
module.exports = {
|
|
316
|
+
backblazeClient,
|
|
317
|
+
bucketIdentifierValidator,
|
|
318
|
+
getBackblazeSession,
|
|
319
|
+
publicFileUrlForBucketName,
|
|
320
|
+
backblazeUploadFileBytes,
|
|
321
|
+
resolveBucketIdFromIdentifier,
|
|
322
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
// https://www.backblaze.com/apidocs/b2-list-buckets
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { B2_API_VERSION_PATH } = require('../backblaze/backblaze.constants');
|
|
6
|
+
const { backblazeClient, getBackblazeSession } = require('../backblaze/backblaze.utils');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
]);
|
|
11
|
+
|
|
12
|
+
const backblazeBucketsGet = async (
|
|
13
|
+
credsPayload,
|
|
14
|
+
{
|
|
15
|
+
bucketName,
|
|
16
|
+
fetchClient = backblazeClient,
|
|
17
|
+
} = {},
|
|
18
|
+
) => {
|
|
19
|
+
|
|
20
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
21
|
+
credsPayload,
|
|
22
|
+
});
|
|
23
|
+
if (rejectResponse) {
|
|
24
|
+
return rejectResponse;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const sessionResponse = await getBackblazeSession(credsPayload);
|
|
28
|
+
|
|
29
|
+
if (!sessionResponse.ok) {
|
|
30
|
+
return sessionResponse;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const { data: session } = sessionResponse;
|
|
34
|
+
const { accountId } = session;
|
|
35
|
+
|
|
36
|
+
return fetchClient.fetch({
|
|
37
|
+
requestPayload: {
|
|
38
|
+
method: 'post',
|
|
39
|
+
url: `${ B2_API_VERSION_PATH }/b2_list_buckets`,
|
|
40
|
+
body: {
|
|
41
|
+
accountId,
|
|
42
|
+
...bucketName && { bucketName },
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
context: {
|
|
46
|
+
credsPayload,
|
|
47
|
+
session,
|
|
48
|
+
resultPath: 'buckets',
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const funcApiConfig = {
|
|
54
|
+
argsWarden,
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
module.exports = {
|
|
58
|
+
backblazeBucketsGet,
|
|
59
|
+
funcApiConfig,
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/*
|
|
63
|
+
curl -X POST "http://localhost:8000/backblazeBucketsGet" \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d '{
|
|
66
|
+
"credsPayload": { "credsPath": "backblaze" }
|
|
67
|
+
}'
|
|
68
|
+
*/
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// https://www.backblaze.com/apidocs/b2-delete-file-version
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { B2_API_VERSION_PATH } = require('../backblaze/backblaze.constants');
|
|
6
|
+
const { backblazeClient } = require('../backblaze/backblaze.utils');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['fileName'],
|
|
11
|
+
['fileId'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const backblazeFileDelete = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
fileName,
|
|
17
|
+
fileId,
|
|
18
|
+
{
|
|
19
|
+
fetchClient = backblazeClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
24
|
+
credsPayload,
|
|
25
|
+
fileName,
|
|
26
|
+
fileId,
|
|
27
|
+
});
|
|
28
|
+
if (rejectResponse) {
|
|
29
|
+
return rejectResponse;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return fetchClient.fetch({
|
|
33
|
+
requestPayload: {
|
|
34
|
+
method: 'post',
|
|
35
|
+
url: `${ B2_API_VERSION_PATH }/b2_delete_file_version`,
|
|
36
|
+
body: {
|
|
37
|
+
fileName,
|
|
38
|
+
fileId,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
context: { credsPayload },
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const funcApiConfig = {
|
|
46
|
+
argsWarden,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
backblazeFileDelete,
|
|
51
|
+
funcApiConfig,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
curl -X POST "http://localhost:8000/backblazeFileDelete" \
|
|
56
|
+
-H "Content-Type: application/json" \
|
|
57
|
+
-d '{
|
|
58
|
+
"credsPayload": { "credsPath": "backblaze" },
|
|
59
|
+
"fileName": "hello.txt",
|
|
60
|
+
"fileId": "REPLACE_FILE_ID"
|
|
61
|
+
}'
|
|
62
|
+
*/
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// https://www.backblaze.com/apidocs/b2-hide-file
|
|
2
|
+
|
|
3
|
+
const { ArgsWarden } = require('../utils');
|
|
4
|
+
const { credsValidator } = require('../validators');
|
|
5
|
+
const { B2_API_VERSION_PATH } = require('../backblaze/backblaze.constants');
|
|
6
|
+
const { backblazeClient } = require('../backblaze/backblaze.utils');
|
|
7
|
+
|
|
8
|
+
const argsWarden = new ArgsWarden([
|
|
9
|
+
['credsPayload', credsValidator],
|
|
10
|
+
['fileName'],
|
|
11
|
+
['fileId'],
|
|
12
|
+
]);
|
|
13
|
+
|
|
14
|
+
const backblazeFileHide = async (
|
|
15
|
+
credsPayload,
|
|
16
|
+
fileName,
|
|
17
|
+
fileId,
|
|
18
|
+
{
|
|
19
|
+
fetchClient = backblazeClient,
|
|
20
|
+
} = {},
|
|
21
|
+
) => {
|
|
22
|
+
|
|
23
|
+
const rejectResponse = await argsWarden.responseIfRejectingArgs({
|
|
24
|
+
credsPayload,
|
|
25
|
+
fileName,
|
|
26
|
+
fileId,
|
|
27
|
+
});
|
|
28
|
+
if (rejectResponse) {
|
|
29
|
+
return rejectResponse;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return fetchClient.fetch({
|
|
33
|
+
requestPayload: {
|
|
34
|
+
method: 'post',
|
|
35
|
+
url: `${ B2_API_VERSION_PATH }/b2_hide_file`,
|
|
36
|
+
body: {
|
|
37
|
+
fileName,
|
|
38
|
+
fileId,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
context: { credsPayload },
|
|
42
|
+
});
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
const funcApiConfig = {
|
|
46
|
+
argsWarden,
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
module.exports = {
|
|
50
|
+
backblazeFileHide,
|
|
51
|
+
funcApiConfig,
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
curl -X POST "http://localhost:8000/backblazeFileHide" \
|
|
56
|
+
-H "Content-Type: application/json" \
|
|
57
|
+
-d '{
|
|
58
|
+
"credsPayload": { "credsPath": "backblaze" },
|
|
59
|
+
"fileName": "hello.txt",
|
|
60
|
+
"fileId": "REPLACE_FILE_ID"
|
|
61
|
+
}'
|
|
62
|
+
*/
|