@superdurable/connector-box 0.1.0 → 0.2.0
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/README.md +4 -1
- package/dex-connector.json +897 -24
- package/dist/chunk-7RYWT7W3.js +1653 -0
- package/dist/connection-BIbBd41p.d.ts +509 -0
- package/dist/index.d.ts +904 -7
- package/dist/index.js +1207 -47
- package/dist/mock.d.ts +293 -3
- package/dist/mock.js +275 -1
- package/package.json +4 -4
- package/dist/chunk-F5T3YIDN.js +0 -299
- package/dist/connection-BzNkxQQZ.d.ts +0 -118
package/dist/index.js
CHANGED
|
@@ -1,7 +1,65 @@
|
|
|
1
1
|
import {
|
|
2
|
+
BoxFileSchema,
|
|
3
|
+
BoxFolderSchema,
|
|
4
|
+
BoxItemPageSchema,
|
|
5
|
+
BoxItemSchema,
|
|
2
6
|
ConfigSchema,
|
|
3
7
|
Connection,
|
|
4
8
|
ConnectorID,
|
|
9
|
+
CopyBoxFileInputSchema,
|
|
10
|
+
CopyBoxFolderInputSchema,
|
|
11
|
+
CopyFileBranch,
|
|
12
|
+
CopyFileBranchCopied,
|
|
13
|
+
CopyFileBranchDefect,
|
|
14
|
+
CopyFileBranchProviderRejected,
|
|
15
|
+
CopyFileBranchUncertain,
|
|
16
|
+
CopyFileDefinition,
|
|
17
|
+
CopyFileMetadata,
|
|
18
|
+
CopyFolderBranch,
|
|
19
|
+
CopyFolderBranchCopied,
|
|
20
|
+
CopyFolderBranchDefect,
|
|
21
|
+
CopyFolderBranchProviderRejected,
|
|
22
|
+
CopyFolderBranchUncertain,
|
|
23
|
+
CopyFolderDefinition,
|
|
24
|
+
CopyFolderMetadata,
|
|
25
|
+
CreateBoxFileInputSchema,
|
|
26
|
+
CreateBoxFolderInputSchema,
|
|
27
|
+
CreateFileBranch,
|
|
28
|
+
CreateFileBranchCreated,
|
|
29
|
+
CreateFileBranchDefect,
|
|
30
|
+
CreateFileBranchProviderRejected,
|
|
31
|
+
CreateFileBranchUncertain,
|
|
32
|
+
CreateFileDefinition,
|
|
33
|
+
CreateFileMetadata,
|
|
34
|
+
CreateFolderBranch,
|
|
35
|
+
CreateFolderBranchCreated,
|
|
36
|
+
CreateFolderBranchDefect,
|
|
37
|
+
CreateFolderBranchProviderRejected,
|
|
38
|
+
CreateFolderBranchUncertain,
|
|
39
|
+
CreateFolderDefinition,
|
|
40
|
+
CreateFolderMetadata,
|
|
41
|
+
CreatedBoxFileSchema,
|
|
42
|
+
CreatedBoxItemSchema,
|
|
43
|
+
CredentialMaterialError,
|
|
44
|
+
DeleteFileBranch,
|
|
45
|
+
DeleteFileBranchDefect,
|
|
46
|
+
DeleteFileBranchDeleted,
|
|
47
|
+
DeleteFileBranchInvalidResponse,
|
|
48
|
+
DeleteFileBranchNotFound,
|
|
49
|
+
DeleteFileBranchProviderRejected,
|
|
50
|
+
DeleteFileDefinition,
|
|
51
|
+
DeleteFileInputSchema,
|
|
52
|
+
DeleteFileMetadata,
|
|
53
|
+
DeleteFolderBranch,
|
|
54
|
+
DeleteFolderBranchDefect,
|
|
55
|
+
DeleteFolderBranchDeleted,
|
|
56
|
+
DeleteFolderBranchInvalidResponse,
|
|
57
|
+
DeleteFolderBranchNotFound,
|
|
58
|
+
DeleteFolderBranchProviderRejected,
|
|
59
|
+
DeleteFolderDefinition,
|
|
60
|
+
DeleteFolderInputSchema,
|
|
61
|
+
DeleteFolderMetadata,
|
|
62
|
+
DeletedBoxItemSchema,
|
|
5
63
|
DownloadFileBranch,
|
|
6
64
|
DownloadFileBranchDefect,
|
|
7
65
|
DownloadFileBranchDownloaded,
|
|
@@ -13,7 +71,87 @@ import {
|
|
|
13
71
|
DownloadFileInputSchema,
|
|
14
72
|
DownloadFileMetadata,
|
|
15
73
|
DownloadedFileSchema,
|
|
74
|
+
GetFileBranch,
|
|
75
|
+
GetFileBranchDefect,
|
|
76
|
+
GetFileBranchFound,
|
|
77
|
+
GetFileBranchInvalidResponse,
|
|
78
|
+
GetFileBranchNotFound,
|
|
79
|
+
GetFileBranchProviderRejected,
|
|
80
|
+
GetFileDefinition,
|
|
81
|
+
GetFileInputSchema,
|
|
82
|
+
GetFileMetadata,
|
|
83
|
+
GetFolderBranch,
|
|
84
|
+
GetFolderBranchDefect,
|
|
85
|
+
GetFolderBranchFound,
|
|
86
|
+
GetFolderBranchInvalidResponse,
|
|
87
|
+
GetFolderBranchNotFound,
|
|
88
|
+
GetFolderBranchProviderRejected,
|
|
89
|
+
GetFolderDefinition,
|
|
90
|
+
GetFolderInputSchema,
|
|
91
|
+
GetFolderMetadata,
|
|
92
|
+
ListFolderItemsBranch,
|
|
93
|
+
ListFolderItemsBranchDefect,
|
|
94
|
+
ListFolderItemsBranchInvalidResponse,
|
|
95
|
+
ListFolderItemsBranchListed,
|
|
96
|
+
ListFolderItemsBranchNotFound,
|
|
97
|
+
ListFolderItemsBranchProviderRejected,
|
|
98
|
+
ListFolderItemsDefinition,
|
|
99
|
+
ListFolderItemsInputSchema,
|
|
100
|
+
ListFolderItemsMetadata,
|
|
16
101
|
ProviderID,
|
|
102
|
+
SearchFilesBranch,
|
|
103
|
+
SearchFilesBranchDefect,
|
|
104
|
+
SearchFilesBranchFound,
|
|
105
|
+
SearchFilesBranchInvalidResponse,
|
|
106
|
+
SearchFilesBranchProviderRejected,
|
|
107
|
+
SearchFilesDefinition,
|
|
108
|
+
SearchFilesInputSchema,
|
|
109
|
+
SearchFilesMetadata,
|
|
110
|
+
SearchFoldersBranch,
|
|
111
|
+
SearchFoldersBranchDefect,
|
|
112
|
+
SearchFoldersBranchFound,
|
|
113
|
+
SearchFoldersBranchInvalidResponse,
|
|
114
|
+
SearchFoldersBranchProviderRejected,
|
|
115
|
+
SearchFoldersDefinition,
|
|
116
|
+
SearchFoldersInputSchema,
|
|
117
|
+
SearchFoldersMetadata,
|
|
118
|
+
ShareBoxFileInputSchema,
|
|
119
|
+
ShareBoxFolderInputSchema,
|
|
120
|
+
ShareFileBranch,
|
|
121
|
+
ShareFileBranchDefect,
|
|
122
|
+
ShareFileBranchInvalidResponse,
|
|
123
|
+
ShareFileBranchNotFound,
|
|
124
|
+
ShareFileBranchProviderRejected,
|
|
125
|
+
ShareFileBranchShared,
|
|
126
|
+
ShareFileDefinition,
|
|
127
|
+
ShareFileMetadata,
|
|
128
|
+
ShareFolderBranch,
|
|
129
|
+
ShareFolderBranchDefect,
|
|
130
|
+
ShareFolderBranchInvalidResponse,
|
|
131
|
+
ShareFolderBranchNotFound,
|
|
132
|
+
ShareFolderBranchProviderRejected,
|
|
133
|
+
ShareFolderBranchShared,
|
|
134
|
+
ShareFolderDefinition,
|
|
135
|
+
ShareFolderMetadata,
|
|
136
|
+
UpdateBoxFileInputSchema,
|
|
137
|
+
UpdateBoxFolderInputSchema,
|
|
138
|
+
UpdateFileBranch,
|
|
139
|
+
UpdateFileBranchDefect,
|
|
140
|
+
UpdateFileBranchInvalidResponse,
|
|
141
|
+
UpdateFileBranchNotFound,
|
|
142
|
+
UpdateFileBranchProviderRejected,
|
|
143
|
+
UpdateFileBranchUpdated,
|
|
144
|
+
UpdateFileDefinition,
|
|
145
|
+
UpdateFileMetadata,
|
|
146
|
+
UpdateFolderBranch,
|
|
147
|
+
UpdateFolderBranchDefect,
|
|
148
|
+
UpdateFolderBranchInvalidResponse,
|
|
149
|
+
UpdateFolderBranchNotFound,
|
|
150
|
+
UpdateFolderBranchProviderRejected,
|
|
151
|
+
UpdateFolderBranchUpdated,
|
|
152
|
+
UpdateFolderDefinition,
|
|
153
|
+
UpdateFolderMetadata,
|
|
154
|
+
UpdatedBoxItemSchema,
|
|
17
155
|
UploadFileBranch,
|
|
18
156
|
UploadFileBranchDefect,
|
|
19
157
|
UploadFileBranchInvalidResponse,
|
|
@@ -26,12 +164,17 @@ import {
|
|
|
26
164
|
UploadedFileSchema,
|
|
27
165
|
decodeCredentials,
|
|
28
166
|
decodeSharedCredentials,
|
|
167
|
+
decodeSignedInteger,
|
|
29
168
|
emptyDownloadedFile,
|
|
30
169
|
emptyUploadedFile,
|
|
170
|
+
exactIntegerJSONCodec,
|
|
171
|
+
isCredentialMaterialError,
|
|
31
172
|
newConnection,
|
|
32
173
|
newConnectionWithOperations,
|
|
33
|
-
newProjectCredentialProvider
|
|
34
|
-
|
|
174
|
+
newProjectCredentialProvider,
|
|
175
|
+
parseExactIntegerJSON,
|
|
176
|
+
parseJSONNumberTokens
|
|
177
|
+
} from "./chunk-7RYWT7W3.js";
|
|
35
178
|
|
|
36
179
|
// src/client.ts
|
|
37
180
|
import { randomBytes } from "crypto";
|
|
@@ -41,6 +184,7 @@ import {
|
|
|
41
184
|
resolveCredential
|
|
42
185
|
} from "@superdurable/connectors-sdk";
|
|
43
186
|
import { ManifestCredentialRefreshDriver } from "@superdurable/connectors-sdk/oauthtoken";
|
|
187
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
44
188
|
import {
|
|
45
189
|
BodyTooLargeError,
|
|
46
190
|
ProviderTransportError,
|
|
@@ -216,24 +360,22 @@ var UploadFileOperation = class {
|
|
|
216
360
|
if (content.toString("base64") !== input.contentBase64 || content.length > this.client.maxUploadBytes)
|
|
217
361
|
return uploadBranch("defect", "VALIDATION", "Box upload content must be bounded Base64");
|
|
218
362
|
const digest = createHash("sha1").update(content).digest("hex").toUpperCase();
|
|
363
|
+
const isLaterAttempt = (call.context?.attempt ?? 1) > 1;
|
|
219
364
|
const first = await this.client.getFileMetadata(call, input.fileId);
|
|
220
|
-
const initial = initialMetadata(first, input.fileId);
|
|
365
|
+
const initial = initialMetadata(first, input.fileId, isLaterAttempt);
|
|
221
366
|
if ("decision" in initial) return initial.decision;
|
|
222
367
|
const metadata = initial.metadata;
|
|
223
368
|
if (matches(metadata, input.fileId, digest, content.length)) return uploaded(metadata);
|
|
224
369
|
const exchange = await this.client.upload(call, input.fileId, metadata.name, content);
|
|
225
|
-
if (exchange.error === "credential" && !exchange.requestSent)
|
|
226
|
-
return uploadBranch("defect", "AUTHENTICATION", "Box credentials are unavailable or invalid");
|
|
370
|
+
if (exchange.error === "credential" && !exchange.requestSent) return credentialFailure(isLaterAttempt);
|
|
227
371
|
if (exchange.error === "refresh") return uploadRetry("AVAILABILITY", "Box credentials could not be refreshed");
|
|
228
372
|
if (exchange.error === "request" && !exchange.requestSent)
|
|
229
373
|
return uploadRetry("TRANSPORT", "Box upload did not leave the process");
|
|
230
374
|
if (exchange.status === 429) return uploadRetry("RATE_LIMIT", "Box rate limited the upload", exchange.retryAfterMs);
|
|
231
375
|
if (exchange.status === 408 || exchange.status >= 500)
|
|
232
376
|
return uploadRetry("AVAILABILITY", "Box upload is temporarily unavailable", exchange.retryAfterMs);
|
|
233
|
-
if (exchange
|
|
377
|
+
if (isDefiniteRefusal(exchange)) return refusal(exchange.status);
|
|
234
378
|
const isAccepted = exchange.status === 200 || exchange.status === 201;
|
|
235
|
-
if (exchange.status !== 0 && !isAccepted)
|
|
236
|
-
return uploadBranch("providerRejected", "PROVIDER_REJECTION", `Box rejected HTTP ${exchange.status}`);
|
|
237
379
|
if (isAccepted && !exchange.error) {
|
|
238
380
|
try {
|
|
239
381
|
const wire = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
|
|
@@ -255,25 +397,618 @@ var UploadFileOperation = class {
|
|
|
255
397
|
return uploadRetry("TRANSPORT", "Box replacement could not be confirmed by read-back", readback.retryAfterMs);
|
|
256
398
|
}
|
|
257
399
|
};
|
|
258
|
-
function initialMetadata(exchange, fileID) {
|
|
259
|
-
if (exchange.error === "credential") return { decision:
|
|
400
|
+
function initialMetadata(exchange, fileID, isLaterAttempt) {
|
|
401
|
+
if (exchange.error === "credential" && exchange.status === 0) return { decision: credentialFailure(isLaterAttempt) };
|
|
402
|
+
if (exchange.error === "credential") return { decision: uploadRetry("PROTOCOL", "Box metadata echoed the access token", exchange.retryAfterMs) };
|
|
260
403
|
if (exchange.error === "refresh") return { decision: uploadRetry("AVAILABILITY", "Box credentials could not be refreshed") };
|
|
261
404
|
if (exchange.error === "request") return { decision: uploadRetry("TRANSPORT", "Box metadata request failed") };
|
|
262
405
|
if (exchange.status === 429) return { decision: uploadRetry("RATE_LIMIT", "Box rate limited metadata lookup", exchange.retryAfterMs) };
|
|
263
406
|
if (exchange.status === 408 || exchange.status >= 500)
|
|
264
407
|
return { decision: uploadRetry("AVAILABILITY", "Box metadata is temporarily unavailable", exchange.retryAfterMs) };
|
|
265
|
-
if (exchange
|
|
408
|
+
if (isDefiniteRefusal(exchange)) return { decision: refusal(exchange.status) };
|
|
266
409
|
if (exchange.status !== 200)
|
|
267
|
-
return { decision:
|
|
268
|
-
if (exchange.error === "tooLarge")
|
|
269
|
-
return { decision: uploadBranch("invalidResponse", "RESPONSE_TOO_LARGE", "Box metadata exceeds the configured limit") };
|
|
410
|
+
return { decision: uploadRetry("PROTOCOL", `Box answered metadata lookup with unexpected HTTP ${exchange.status}`, exchange.retryAfterMs) };
|
|
411
|
+
if (exchange.error === "tooLarge") return { decision: uploadRetry("RESPONSE_TOO_LARGE", "Box metadata exceeds the configured limit") };
|
|
270
412
|
if (exchange.error) return { decision: uploadRetry("TRANSPORT", "Box metadata response was interrupted") };
|
|
271
413
|
try {
|
|
272
414
|
return { metadata: decodeMetadata(exchange.body, fileID) };
|
|
273
415
|
} catch {
|
|
274
|
-
return { decision:
|
|
416
|
+
return { decision: uploadRetry("PROTOCOL", "Box returned invalid file metadata") };
|
|
275
417
|
}
|
|
276
418
|
}
|
|
419
|
+
function credentialFailure(isLaterAttempt) {
|
|
420
|
+
if (isLaterAttempt) return uploadRetry("AUTHENTICATION", "Box credentials are unavailable or invalid after a possible earlier upload");
|
|
421
|
+
return uploadBranch("defect", "AUTHENTICATION", "Box credentials are unavailable or invalid");
|
|
422
|
+
}
|
|
423
|
+
var definiteRefusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
|
|
424
|
+
function isDefiniteRefusal(exchange) {
|
|
425
|
+
if (exchange.error || !definiteRefusalStatuses.has(exchange.status)) return false;
|
|
426
|
+
let wire;
|
|
427
|
+
try {
|
|
428
|
+
wire = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
|
|
429
|
+
} catch {
|
|
430
|
+
return true;
|
|
431
|
+
}
|
|
432
|
+
if (!wire || typeof wire !== "object" || Array.isArray(wire)) return true;
|
|
433
|
+
const fields = wire;
|
|
434
|
+
return fields.type !== "file" && (fields.entries === void 0 || fields.entries === null);
|
|
435
|
+
}
|
|
436
|
+
function refusal(status) {
|
|
437
|
+
if (status === 404) return uploadBranch("notFound", "NOT_FOUND", "Box did not find the file");
|
|
438
|
+
return uploadBranch("providerRejected", "PROVIDER_REJECTION", `Box rejected HTTP ${status}`);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// src/management.ts
|
|
442
|
+
import { createHash as createHash2 } from "crypto";
|
|
443
|
+
import {
|
|
444
|
+
definitionMaxSends,
|
|
445
|
+
newMutationBranch as newMutationBranch2,
|
|
446
|
+
newMutationRetry as newMutationRetry2,
|
|
447
|
+
newMutationUncertain,
|
|
448
|
+
newQueryBranch as newQueryBranch2,
|
|
449
|
+
newQueryRetry as newQueryRetry2
|
|
450
|
+
} from "@superdurable/connectors-sdk";
|
|
451
|
+
import { CheckpointError, DispatchNotAllowedError, Fence, InsufficientTimeError } from "@superdurable/connectors-sdk/singledispatch";
|
|
452
|
+
var itemIDPattern = /^[0-9]{1,40}(?![\s\S])/;
|
|
453
|
+
var accessLevels = /* @__PURE__ */ new Set(["open", "company", "collaborators"]);
|
|
454
|
+
var refusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
|
|
455
|
+
var Operation = class {
|
|
456
|
+
/** Bind an authenticated Box client. */
|
|
457
|
+
constructor(client) {
|
|
458
|
+
this.client = client;
|
|
459
|
+
}
|
|
460
|
+
client;
|
|
461
|
+
failure(problem) {
|
|
462
|
+
return { kind: problem.kind, provider: "box", operation: this.operation, message: problem.message };
|
|
463
|
+
}
|
|
464
|
+
};
|
|
465
|
+
var ReadOperation = class extends Operation {
|
|
466
|
+
/** Return the manifest-generated Query definition. */
|
|
467
|
+
definition() {
|
|
468
|
+
return this.contract;
|
|
469
|
+
}
|
|
470
|
+
defect(empty, message) {
|
|
471
|
+
return newQueryBranch2("defect", empty, {}, this.failure({ kind: "VALIDATION", message }));
|
|
472
|
+
}
|
|
473
|
+
async read(call, path, empty, branch, decode, hasNotFound = true) {
|
|
474
|
+
const exchange = await this.client.itemRequest(call, "GET", path);
|
|
475
|
+
let problem = commonProblem(exchange, false);
|
|
476
|
+
if (!problem && exchange.status !== 200)
|
|
477
|
+
problem = exchange.status === 404 && hasNotFound ? notFound() : rejected(exchange.status);
|
|
478
|
+
if (!problem) {
|
|
479
|
+
if (exchange.error === "tooLarge")
|
|
480
|
+
problem = { branch: "invalidResponse", kind: "RESPONSE_TOO_LARGE", message: "Box response exceeded the configured limit" };
|
|
481
|
+
else if (exchange.error) problem = { kind: "TRANSPORT", message: "Box response was interrupted" };
|
|
482
|
+
else {
|
|
483
|
+
try {
|
|
484
|
+
return newQueryBranch2(branch, decode(decodeResponse(exchange.body)));
|
|
485
|
+
} catch {
|
|
486
|
+
problem = { branch: "invalidResponse", kind: "PROTOCOL", message: "Box response is incomplete or malformed" };
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
}
|
|
490
|
+
return problem.branch ? newQueryBranch2(problem.branch, empty, {}, this.failure(problem)) : newQueryRetry2(this.failure(problem), problem.delay);
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
var WriteOperation = class extends Operation {
|
|
494
|
+
/** Return the manifest-generated Mutation definition. */
|
|
495
|
+
definition() {
|
|
496
|
+
return this.contract;
|
|
497
|
+
}
|
|
498
|
+
/** Correlate attempts with the original Dex call. */
|
|
499
|
+
idempotencyKey(callID) {
|
|
500
|
+
return callID;
|
|
501
|
+
}
|
|
502
|
+
outcome(empty, problem) {
|
|
503
|
+
if (problem.branch === "uncertain") return newMutationUncertain(empty, this.failure(problem));
|
|
504
|
+
if (problem.branch) return newMutationBranch2(problem.branch, empty, {}, this.failure(problem));
|
|
505
|
+
return newMutationRetry2(this.failure(problem), problem.delay);
|
|
506
|
+
}
|
|
507
|
+
defect(empty, message) {
|
|
508
|
+
return this.outcome(empty, { branch: "defect", kind: "VALIDATION", message });
|
|
509
|
+
}
|
|
510
|
+
async write(call, request) {
|
|
511
|
+
const exchange = await this.client.itemRequest(call, request.method, request.path, request.payload);
|
|
512
|
+
const isDelete = request.method === "DELETE";
|
|
513
|
+
let problem = commonProblem(exchange, true);
|
|
514
|
+
if (!problem && exchange.status !== (isDelete ? 204 : 200)) {
|
|
515
|
+
if (definiteRefusal(exchange)) problem = exchange.status === 404 ? notFound() : rejected(exchange.status);
|
|
516
|
+
else problem = { kind: "AVAILABILITY", message: "Box write outcome is unknown" };
|
|
517
|
+
}
|
|
518
|
+
if (!problem) {
|
|
519
|
+
if (isDelete && (exchange.body.length || exchange.error === "tooLarge"))
|
|
520
|
+
problem = { kind: "PROTOCOL", message: "Box returned unexpected deletion content" };
|
|
521
|
+
else if (exchange.error === "tooLarge")
|
|
522
|
+
problem = { kind: "RESPONSE_TOO_LARGE", message: "Box response exceeded the configured limit" };
|
|
523
|
+
else if (exchange.error) problem = { kind: "TRANSPORT", message: "Box response was interrupted" };
|
|
524
|
+
else {
|
|
525
|
+
try {
|
|
526
|
+
return newMutationBranch2(request.branch, request.decode(isDelete ? void 0 : decodeResponse(exchange.body)));
|
|
527
|
+
} catch {
|
|
528
|
+
problem = { kind: "PROTOCOL", message: "Box response is incomplete or malformed" };
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return this.outcome(request.empty, problem);
|
|
533
|
+
}
|
|
534
|
+
async create(call, request) {
|
|
535
|
+
const maxSends = call.maxSendsOverride ?? definitionMaxSends(this.contract);
|
|
536
|
+
let fence;
|
|
537
|
+
try {
|
|
538
|
+
fence = new Fence(call, this.contract.stepDefaults.executeMethodTimeoutMs, { maxSends });
|
|
539
|
+
} catch {
|
|
540
|
+
return this.outcome(request.empty, { branch: "defect", kind: "LOCAL_DEFECT", message: "dispatch fence is unavailable" });
|
|
541
|
+
}
|
|
542
|
+
const decision = fence.decide();
|
|
543
|
+
const unavailable = { kind: "AVAILABILITY", message: "Box creation checkpoint is unavailable" };
|
|
544
|
+
if (decision.kind === "failClosed") return this.outcome(request.empty, unavailable);
|
|
545
|
+
if (decision.kind === "readBackRequired" || decision.kind === "readBackThenResendAllowed") {
|
|
546
|
+
const destination = await this.readDestination(call, request);
|
|
547
|
+
if (destination === "unavailable")
|
|
548
|
+
return this.outcome(request.empty, { kind: "AVAILABILITY", message: "Box destination read-back is unavailable" });
|
|
549
|
+
if (decision.kind === "readBackRequired") {
|
|
550
|
+
const message = {
|
|
551
|
+
matched: "matching destination does not identify this Box write",
|
|
552
|
+
conflicted: "destination name conflicts with a possible Box write",
|
|
553
|
+
absent: "send cap reached without confirming the Box write"
|
|
554
|
+
}[destination];
|
|
555
|
+
return this.uncertain(request.empty, message);
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
const priorSends = decision.priorSendUpperBound ?? 0;
|
|
559
|
+
const canResend = priorSends + 1 < maxSends;
|
|
560
|
+
const payload = { name: request.name, parent: { id: request.parentId } };
|
|
561
|
+
const file = request.file ? { name: request.name, content: request.file.content } : void 0;
|
|
562
|
+
const send = await this.client.prepareItemRequest(call, "POST", request.path, payload, file);
|
|
563
|
+
if (typeof send !== "function") {
|
|
564
|
+
if (priorSends) return this.outcome(request.empty, { kind: "AVAILABILITY", message: "connection unavailable after a possible create" });
|
|
565
|
+
try {
|
|
566
|
+
await fence.recordNotSent();
|
|
567
|
+
} catch {
|
|
568
|
+
return this.outcome(request.empty, unavailable);
|
|
569
|
+
}
|
|
570
|
+
return this.outcome(request.empty, send.error === "credential" ? { branch: "defect", kind: "AUTHENTICATION", message: "Box credentials are unavailable or invalid" } : { kind: "AVAILABILITY", message: "credential refresh unavailable" });
|
|
571
|
+
}
|
|
572
|
+
let exchange;
|
|
573
|
+
try {
|
|
574
|
+
exchange = await fence.dispatch(send);
|
|
575
|
+
} catch (error) {
|
|
576
|
+
if (error instanceof CheckpointError || error instanceof DispatchNotAllowedError || error instanceof InsufficientTimeError)
|
|
577
|
+
return this.outcome(request.empty, unavailable);
|
|
578
|
+
return this.unknownCreate(call, request, canResend);
|
|
579
|
+
}
|
|
580
|
+
if (exchange.status === 429 || exchange.status === 503) {
|
|
581
|
+
if (!await recordRefusal(fence)) return this.outcome(request.empty, unavailable);
|
|
582
|
+
return this.outcome(request.empty, {
|
|
583
|
+
kind: exchange.status === 429 ? "RATE_LIMIT" : "AVAILABILITY",
|
|
584
|
+
message: "Box did not process the create",
|
|
585
|
+
delay: exchange.retryAfterMs
|
|
586
|
+
});
|
|
587
|
+
}
|
|
588
|
+
if (exchange.error || exchange.status === 408 || exchange.status >= 500)
|
|
589
|
+
return this.unknownCreate(call, request, canResend, exchange.retryAfterMs);
|
|
590
|
+
if (exchange.status !== 200 && exchange.status !== 201) {
|
|
591
|
+
if (!priorSends && definiteRefusal(exchange)) {
|
|
592
|
+
if (!await recordRefusal(fence)) return this.outcome(request.empty, unavailable);
|
|
593
|
+
return this.outcome(request.empty, rejected(exchange.status));
|
|
594
|
+
}
|
|
595
|
+
return this.unknownCreate(call, request, canResend);
|
|
596
|
+
}
|
|
597
|
+
try {
|
|
598
|
+
return newMutationBranch2(request.branch, request.decode(decodeResponse(exchange.body)));
|
|
599
|
+
} catch {
|
|
600
|
+
return this.unknownCreate(call, request, canResend);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
uncertain(empty, message) {
|
|
604
|
+
return this.outcome(empty, { branch: "uncertain", kind: "TRANSPORT", message });
|
|
605
|
+
}
|
|
606
|
+
async unknownCreate(call, request, canResend, delay = 0) {
|
|
607
|
+
if (canResend || await this.readDestination(call, request) === "unavailable")
|
|
608
|
+
return this.outcome(request.empty, { kind: "AVAILABILITY", message: "Box create outcome is unknown", delay });
|
|
609
|
+
return this.uncertain(request.empty, "send cap reached without a request-unique confirmation");
|
|
610
|
+
}
|
|
611
|
+
async readDestination(call, request) {
|
|
612
|
+
const fields = request.file ? "id,type,name,sha1,size" : "id,type,name";
|
|
613
|
+
for (let offset = 0; offset <= 1e4; offset += 1e3) {
|
|
614
|
+
const path = `/2.0/folders/${request.parentId}/items?fields=${fields}&limit=1000&offset=${offset}`;
|
|
615
|
+
const exchange = await this.client.itemRequest(call, "GET", path);
|
|
616
|
+
if (exchange.error || exchange.status !== 200) return "unavailable";
|
|
617
|
+
let count;
|
|
618
|
+
let total;
|
|
619
|
+
try {
|
|
620
|
+
const raw = decodeResponse(exchange.body);
|
|
621
|
+
if (request.file) {
|
|
622
|
+
const document = object(raw);
|
|
623
|
+
const files = entries(document).map(fileFields);
|
|
624
|
+
count = files.length;
|
|
625
|
+
total = integerValue(integer(document, "total_count"));
|
|
626
|
+
if (total < 0n) return "unavailable";
|
|
627
|
+
const match = files.find((file) => file.name === request.name);
|
|
628
|
+
if (match) return validID(match.id) && match.type === "file" && match.sha1.toUpperCase() === request.file.digest && integerValue(match.size) === BigInt(request.file.content.length) ? "matched" : "conflicted";
|
|
629
|
+
} else {
|
|
630
|
+
const page = itemPage(raw);
|
|
631
|
+
const match = page.entries.find((item) => item.name === request.name);
|
|
632
|
+
if (match) return match.type === request.itemType ? "matched" : "conflicted";
|
|
633
|
+
count = page.entries.length;
|
|
634
|
+
total = integerValue(page.total_count);
|
|
635
|
+
}
|
|
636
|
+
} catch {
|
|
637
|
+
return "unavailable";
|
|
638
|
+
}
|
|
639
|
+
if (BigInt(offset + count) >= total) return "absent";
|
|
640
|
+
if (!count) return "unavailable";
|
|
641
|
+
}
|
|
642
|
+
return "unavailable";
|
|
643
|
+
}
|
|
644
|
+
};
|
|
645
|
+
var ChangeItem = class extends WriteOperation {
|
|
646
|
+
async update(call, itemType, id, branch, name, parent, access) {
|
|
647
|
+
const payload = {};
|
|
648
|
+
if (name) payload.name = name;
|
|
649
|
+
if (parent) payload.parent = { id: parent };
|
|
650
|
+
if (access) payload.shared_link = { access };
|
|
651
|
+
const path = `/2.0/${itemType}s/${id}?fields=id,type,name,parent,shared_link`;
|
|
652
|
+
return this.write(call, { method: "PUT", path, empty: emptyUpdatedItem, branch, payload, decode: (raw) => {
|
|
653
|
+
const value = object(raw);
|
|
654
|
+
const item = identity(value);
|
|
655
|
+
const parentId = text(nested(value, "parent"), "id");
|
|
656
|
+
const link = nested(value, "shared_link");
|
|
657
|
+
const linkURL = text(link, "url"), linkAccess = text(link, "access");
|
|
658
|
+
if (item.id !== id || item.type !== itemType || !item.name || name && item.name !== name || parent && parentId !== parent || access && (!linkURL || linkAccess !== access))
|
|
659
|
+
throw new TypeError("Box update response differs from request");
|
|
660
|
+
return { ...item, ...parentId ? { parentId } : {} };
|
|
661
|
+
} });
|
|
662
|
+
}
|
|
663
|
+
};
|
|
664
|
+
var emptyItem = { id: "", type: "", name: "", parentId: "" };
|
|
665
|
+
var emptyCreatedFile = { fileId: "", name: "", sha1: "", parentId: "" };
|
|
666
|
+
var emptyUpdatedItem = { id: "", type: "", name: "" };
|
|
667
|
+
var emptyPage = { entries: [], limit: 0, offset: 0, total_count: 0 };
|
|
668
|
+
var CreateFolderOperation = class extends WriteOperation {
|
|
669
|
+
operation = "createFolder";
|
|
670
|
+
contract = CreateFolderDefinition;
|
|
671
|
+
/** Create one named Box folder under a parent folder. */
|
|
672
|
+
async invoke(call, input) {
|
|
673
|
+
if (!validID(input.parentId, true) || !validName(input.name))
|
|
674
|
+
return this.defect(emptyItem, "Box source ID, destination ID, or name is invalid");
|
|
675
|
+
return this.create(call, {
|
|
676
|
+
path: "/2.0/folders",
|
|
677
|
+
name: input.name,
|
|
678
|
+
parentId: input.parentId,
|
|
679
|
+
itemType: "folder",
|
|
680
|
+
branch: "created",
|
|
681
|
+
empty: emptyItem,
|
|
682
|
+
decode: (raw) => createdItem(raw, "folder", input.parentId, input.name)
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
var CopyFileOperation = class extends WriteOperation {
|
|
687
|
+
operation = "copyFile";
|
|
688
|
+
contract = CopyFileDefinition;
|
|
689
|
+
/** Copy a Box file to a parent folder under an explicit name. */
|
|
690
|
+
async invoke(call, input) {
|
|
691
|
+
if (!validID(input.fileId) || !validID(input.parentId, true) || !validName(input.name))
|
|
692
|
+
return this.defect(emptyItem, "Box source ID, destination ID, or name is invalid");
|
|
693
|
+
return this.create(call, {
|
|
694
|
+
path: `/2.0/files/${input.fileId}/copy`,
|
|
695
|
+
name: input.name,
|
|
696
|
+
parentId: input.parentId,
|
|
697
|
+
itemType: "file",
|
|
698
|
+
branch: "copied",
|
|
699
|
+
empty: emptyItem,
|
|
700
|
+
decode: (raw) => createdItem(raw, "file", input.parentId, input.name)
|
|
701
|
+
});
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
var CopyFolderOperation = class extends WriteOperation {
|
|
705
|
+
operation = "copyFolder";
|
|
706
|
+
contract = CopyFolderDefinition;
|
|
707
|
+
/** Copy a Box folder to a parent folder under an explicit name. */
|
|
708
|
+
async invoke(call, input) {
|
|
709
|
+
if (!validID(input.folderId) || !validID(input.parentId, true) || !validName(input.name))
|
|
710
|
+
return this.defect(emptyItem, "Box source ID, destination ID, or name is invalid");
|
|
711
|
+
return this.create(call, {
|
|
712
|
+
path: `/2.0/folders/${input.folderId}/copy`,
|
|
713
|
+
name: input.name,
|
|
714
|
+
parentId: input.parentId,
|
|
715
|
+
itemType: "folder",
|
|
716
|
+
branch: "copied",
|
|
717
|
+
empty: emptyItem,
|
|
718
|
+
decode: (raw) => createdItem(raw, "folder", input.parentId, input.name)
|
|
719
|
+
});
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
var UpdateFileOperation = class extends ChangeItem {
|
|
723
|
+
operation = "updateFile";
|
|
724
|
+
contract = UpdateFileDefinition;
|
|
725
|
+
/** Rename or move a file, or create or change its shared link. */
|
|
726
|
+
async invoke(call, input) {
|
|
727
|
+
const { fileId, name = "", parentId = "", sharedLinkAccess = "" } = input;
|
|
728
|
+
if (!validID(fileId) || !validUpdate(name, parentId, sharedLinkAccess))
|
|
729
|
+
return this.defect(emptyUpdatedItem, "Box item ID or update fields are invalid");
|
|
730
|
+
return this.update(call, "file", fileId, "updated", name, parentId, sharedLinkAccess);
|
|
731
|
+
}
|
|
732
|
+
};
|
|
733
|
+
var UpdateFolderOperation = class extends ChangeItem {
|
|
734
|
+
operation = "updateFolder";
|
|
735
|
+
contract = UpdateFolderDefinition;
|
|
736
|
+
/** Rename or move a folder, or create or change its shared link. */
|
|
737
|
+
async invoke(call, input) {
|
|
738
|
+
const { folderId, name = "", parentId = "", sharedLinkAccess = "" } = input;
|
|
739
|
+
if (!validID(folderId) || !validUpdate(name, parentId, sharedLinkAccess))
|
|
740
|
+
return this.defect(emptyUpdatedItem, "Box item ID or update fields are invalid");
|
|
741
|
+
return this.update(call, "folder", folderId, "updated", name, parentId, sharedLinkAccess);
|
|
742
|
+
}
|
|
743
|
+
};
|
|
744
|
+
var ShareFileOperation = class extends ChangeItem {
|
|
745
|
+
operation = "shareFile";
|
|
746
|
+
contract = ShareFileDefinition;
|
|
747
|
+
/** Create or replace a Box file's shared link access. */
|
|
748
|
+
async invoke(call, input) {
|
|
749
|
+
if (!validID(input.fileId) || !accessLevels.has(input.access))
|
|
750
|
+
return this.defect(emptyUpdatedItem, "Box item ID or shared link access is invalid");
|
|
751
|
+
return this.update(call, "file", input.fileId, "shared", "", "", input.access);
|
|
752
|
+
}
|
|
753
|
+
};
|
|
754
|
+
var ShareFolderOperation = class extends ChangeItem {
|
|
755
|
+
operation = "shareFolder";
|
|
756
|
+
contract = ShareFolderDefinition;
|
|
757
|
+
/** Create or replace a Box folder's shared link access. */
|
|
758
|
+
async invoke(call, input) {
|
|
759
|
+
if (!validID(input.folderId) || !accessLevels.has(input.access))
|
|
760
|
+
return this.defect(emptyUpdatedItem, "Box item ID or shared link access is invalid");
|
|
761
|
+
return this.update(call, "folder", input.folderId, "shared", "", "", input.access);
|
|
762
|
+
}
|
|
763
|
+
};
|
|
764
|
+
var CreateFileOperation = class extends WriteOperation {
|
|
765
|
+
operation = "createFile";
|
|
766
|
+
contract = CreateFileDefinition;
|
|
767
|
+
/** Upload one new bounded file under a Box folder. */
|
|
768
|
+
async invoke(call, input) {
|
|
769
|
+
if (!validID(input.parentId, true) || !validName(input.name))
|
|
770
|
+
return this.defect(emptyCreatedFile, "Box parent ID or file name is invalid");
|
|
771
|
+
const content = boundedUpload(input.contentBase64, this.client.maxUploadBytes);
|
|
772
|
+
if (!content) return this.defect(emptyCreatedFile, "Box upload content must be bounded nonempty Base64");
|
|
773
|
+
const digest = createHash2("sha1").update(content).digest("hex").toUpperCase();
|
|
774
|
+
return this.create(call, {
|
|
775
|
+
path: "/2.0/files/content",
|
|
776
|
+
name: input.name,
|
|
777
|
+
parentId: input.parentId,
|
|
778
|
+
itemType: "file",
|
|
779
|
+
file: { content, digest },
|
|
780
|
+
branch: "created",
|
|
781
|
+
empty: emptyCreatedFile,
|
|
782
|
+
decode: (raw) => createdFile(raw, input.parentId, input.name, digest, content.length)
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
var GetFileOperation = class extends ReadOperation {
|
|
787
|
+
operation = "getFile";
|
|
788
|
+
contract = GetFileDefinition;
|
|
789
|
+
/** Retrieve one Box file's metadata. */
|
|
790
|
+
async invoke(call, input) {
|
|
791
|
+
const empty = { id: "", type: "", name: "", size: 0, sha1: "" };
|
|
792
|
+
if (!validID(input.fileId)) return this.defect(empty, "Box file ID must contain decimal digits");
|
|
793
|
+
return this.read(call, `/2.0/files/${input.fileId}?fields=id,type,name,sha1,size`, empty, "found", (raw) => {
|
|
794
|
+
const file = fileFields(raw);
|
|
795
|
+
if (file.id !== input.fileId || file.type !== "file" || !file.name || integerValue(file.size) < 0n)
|
|
796
|
+
throw new TypeError("Box file metadata is invalid");
|
|
797
|
+
return file;
|
|
798
|
+
});
|
|
799
|
+
}
|
|
800
|
+
};
|
|
801
|
+
var GetFolderOperation = class extends ReadOperation {
|
|
802
|
+
operation = "getFolder";
|
|
803
|
+
contract = GetFolderDefinition;
|
|
804
|
+
/** Retrieve one Box folder's metadata. */
|
|
805
|
+
async invoke(call, input) {
|
|
806
|
+
const empty = { id: "", type: "", name: "" };
|
|
807
|
+
if (!validID(input.folderId, true)) return this.defect(empty, "Box folder ID must contain decimal digits");
|
|
808
|
+
return this.read(call, `/2.0/folders/${input.folderId}?fields=id,type,name`, empty, "found", (raw) => {
|
|
809
|
+
const folder = identity(object(raw));
|
|
810
|
+
if (folder.id !== input.folderId || folder.type !== "folder" || !folder.name)
|
|
811
|
+
throw new TypeError("Box folder metadata is invalid");
|
|
812
|
+
return folder;
|
|
813
|
+
});
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
var ListFolderItemsOperation = class extends ReadOperation {
|
|
817
|
+
operation = "listFolderItems";
|
|
818
|
+
contract = ListFolderItemsDefinition;
|
|
819
|
+
/** List one page of files and folders in a Box folder. */
|
|
820
|
+
async invoke(call, input) {
|
|
821
|
+
const { folderId, limit = 0, offset = 0 } = input;
|
|
822
|
+
if (!validID(folderId, true) || !validPage(limit, offset, 1e3))
|
|
823
|
+
return this.defect(emptyPage, "Box folder ID or page bounds are invalid");
|
|
824
|
+
return this.read(call, withQuery(`/2.0/folders/${folderId}/items`, pageParameters(limit, offset)), emptyPage, "listed", itemPage);
|
|
825
|
+
}
|
|
826
|
+
};
|
|
827
|
+
var SearchFilesOperation = class extends ReadOperation {
|
|
828
|
+
operation = "searchFiles";
|
|
829
|
+
contract = SearchFilesDefinition;
|
|
830
|
+
/** Search accessible Box files by a text query. */
|
|
831
|
+
async invoke(call, input) {
|
|
832
|
+
const { query, limit = 0, offset = 0 } = input;
|
|
833
|
+
if (!query.trim() || !validPage(limit, offset, 200))
|
|
834
|
+
return this.defect(emptyPage, "Box search query or page bounds are invalid");
|
|
835
|
+
const path = withQuery("/2.0/search", { query, type: "file", ...pageParameters(limit, offset) });
|
|
836
|
+
return this.read(call, path, emptyPage, "found", itemPage, false);
|
|
837
|
+
}
|
|
838
|
+
};
|
|
839
|
+
var SearchFoldersOperation = class extends ReadOperation {
|
|
840
|
+
operation = "searchFolders";
|
|
841
|
+
contract = SearchFoldersDefinition;
|
|
842
|
+
/** Search accessible Box folders by a text query. */
|
|
843
|
+
async invoke(call, input) {
|
|
844
|
+
const { query, limit = 0, offset = 0 } = input;
|
|
845
|
+
if (!query.trim() || !validPage(limit, offset, 200))
|
|
846
|
+
return this.defect(emptyPage, "Box search query or page bounds are invalid");
|
|
847
|
+
const path = withQuery("/2.0/search", { query, type: "folder", ...pageParameters(limit, offset) });
|
|
848
|
+
return this.read(call, path, emptyPage, "found", itemPage, false);
|
|
849
|
+
}
|
|
850
|
+
};
|
|
851
|
+
var DeleteFileOperation = class extends WriteOperation {
|
|
852
|
+
operation = "deleteFile";
|
|
853
|
+
contract = DeleteFileDefinition;
|
|
854
|
+
/** Delete one Box file by ID. */
|
|
855
|
+
async invoke(call, input) {
|
|
856
|
+
const id = input.fileId;
|
|
857
|
+
if (!validID(id)) return this.defect({ id: "" }, "Box item ID is invalid");
|
|
858
|
+
return this.write(call, {
|
|
859
|
+
method: "DELETE",
|
|
860
|
+
path: `/2.0/files/${id}`,
|
|
861
|
+
empty: { id: "" },
|
|
862
|
+
branch: "deleted",
|
|
863
|
+
decode: () => ({ id })
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
var DeleteFolderOperation = class extends WriteOperation {
|
|
868
|
+
operation = "deleteFolder";
|
|
869
|
+
contract = DeleteFolderDefinition;
|
|
870
|
+
/** Delete one empty Box folder by ID. */
|
|
871
|
+
async invoke(call, input) {
|
|
872
|
+
const id = input.folderId;
|
|
873
|
+
if (!validID(id)) return this.defect({ id: "" }, "Box item ID is invalid");
|
|
874
|
+
return this.write(call, {
|
|
875
|
+
method: "DELETE",
|
|
876
|
+
path: `/2.0/folders/${id}`,
|
|
877
|
+
empty: { id: "" },
|
|
878
|
+
branch: "deleted",
|
|
879
|
+
decode: () => ({ id })
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
};
|
|
883
|
+
async function recordRefusal(fence) {
|
|
884
|
+
try {
|
|
885
|
+
await fence.recordCanResend();
|
|
886
|
+
return true;
|
|
887
|
+
} catch {
|
|
888
|
+
return false;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
function notFound() {
|
|
892
|
+
return { branch: "notFound", kind: "NOT_FOUND", message: "Box item was not found" };
|
|
893
|
+
}
|
|
894
|
+
function rejected(status) {
|
|
895
|
+
return { branch: "providerRejected", kind: "PROVIDER_REJECTION", message: `Box rejected HTTP ${status}` };
|
|
896
|
+
}
|
|
897
|
+
function commonProblem(exchange, write) {
|
|
898
|
+
if (exchange.error === "credential") {
|
|
899
|
+
if (write && exchange.status) return { kind: "AUTHENTICATION", message: "Box response contained credential material" };
|
|
900
|
+
return { branch: "defect", kind: "AUTHENTICATION", message: "Box credentials are unavailable or invalid" };
|
|
901
|
+
}
|
|
902
|
+
if (exchange.error === "request" || exchange.error === "refresh")
|
|
903
|
+
return { kind: "AVAILABILITY", message: "Box provider request failed" };
|
|
904
|
+
if (exchange.status === 429 || exchange.status === 408 || exchange.status >= 500)
|
|
905
|
+
return {
|
|
906
|
+
kind: exchange.status === 429 ? "RATE_LIMIT" : "AVAILABILITY",
|
|
907
|
+
message: "Box provider is temporarily unavailable",
|
|
908
|
+
delay: exchange.retryAfterMs
|
|
909
|
+
};
|
|
910
|
+
return void 0;
|
|
911
|
+
}
|
|
912
|
+
function definiteRefusal(exchange) {
|
|
913
|
+
if (exchange.error || !refusalStatuses.has(exchange.status)) return false;
|
|
914
|
+
try {
|
|
915
|
+
const value = object(decodeResponse(exchange.body));
|
|
916
|
+
const type = text(value, "type");
|
|
917
|
+
return Boolean(text(value, "code")) && !text(value, "id") && type !== "file" && type !== "folder";
|
|
918
|
+
} catch {
|
|
919
|
+
return false;
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
function validID(value, root = false) {
|
|
923
|
+
return itemIDPattern.test(value) && (root || value !== "0");
|
|
924
|
+
}
|
|
925
|
+
function validName(value) {
|
|
926
|
+
return Boolean(value.trim()) && Buffer.byteLength(value) <= 255 && !value.includes("/");
|
|
927
|
+
}
|
|
928
|
+
function validUpdate(name, parent, access) {
|
|
929
|
+
return Boolean(name || parent || access) && (!name || Boolean(name.trim())) && (!parent || validID(parent, true)) && (!access || accessLevels.has(access));
|
|
930
|
+
}
|
|
931
|
+
function validPage(limit, offset, maximum) {
|
|
932
|
+
return Number.isInteger(limit) && Number.isInteger(offset) && limit >= 0 && limit <= maximum && offset >= 0 && offset <= 1e4;
|
|
933
|
+
}
|
|
934
|
+
function pageParameters(limit, offset) {
|
|
935
|
+
return { ...limit ? { limit: String(limit) } : {}, ...offset ? { offset: String(offset) } : {} };
|
|
936
|
+
}
|
|
937
|
+
function withQuery(base, parameters) {
|
|
938
|
+
const query = new URLSearchParams(parameters);
|
|
939
|
+
query.sort();
|
|
940
|
+
const encoded = query.toString().replaceAll("*", "%2A").replaceAll("%7E", "~");
|
|
941
|
+
return encoded ? base + "?" + encoded : base;
|
|
942
|
+
}
|
|
943
|
+
function boundedUpload(encoded, maximum) {
|
|
944
|
+
if (Math.floor(Buffer.byteLength(encoded) / 4) * 3 > maximum) return void 0;
|
|
945
|
+
const base64 = encoded.replace(/[\r\n]/g, "");
|
|
946
|
+
const content = Buffer.from(base64, "base64");
|
|
947
|
+
if (!content.length || content.length > maximum || content.toString("base64") !== base64) return void 0;
|
|
948
|
+
return content;
|
|
949
|
+
}
|
|
950
|
+
function decodeResponse(body) {
|
|
951
|
+
return parseJSONNumberTokens(new TextDecoder("utf-8", { fatal: true }).decode(body));
|
|
952
|
+
}
|
|
953
|
+
function object(value) {
|
|
954
|
+
if (value === null || typeof value !== "object" || Array.isArray(value) || JSON.isRawJSON(value))
|
|
955
|
+
throw new TypeError("expected a Box JSON object");
|
|
956
|
+
return value;
|
|
957
|
+
}
|
|
958
|
+
function nested(value, key) {
|
|
959
|
+
return value[key] == null ? {} : object(value[key]);
|
|
960
|
+
}
|
|
961
|
+
function text(value, key) {
|
|
962
|
+
const field = value[key];
|
|
963
|
+
if (field == null) return "";
|
|
964
|
+
if (typeof field !== "string") throw new TypeError(`invalid Box text field ${key}`);
|
|
965
|
+
return field;
|
|
966
|
+
}
|
|
967
|
+
function integer(value, key) {
|
|
968
|
+
return decodeSignedInteger(value[key] ?? 0);
|
|
969
|
+
}
|
|
970
|
+
function integerValue(value) {
|
|
971
|
+
return BigInt(typeof value === "number" ? value : value.rawJSON);
|
|
972
|
+
}
|
|
973
|
+
function identity(value) {
|
|
974
|
+
return { id: text(value, "id"), type: text(value, "type"), name: text(value, "name") };
|
|
975
|
+
}
|
|
976
|
+
function fileFields(value) {
|
|
977
|
+
const raw = value === null ? {} : object(value);
|
|
978
|
+
return { ...identity(raw), sha1: text(raw, "sha1"), size: integer(raw, "size") };
|
|
979
|
+
}
|
|
980
|
+
function entries(raw) {
|
|
981
|
+
if (!Array.isArray(raw.entries)) throw new TypeError("Box entries are missing");
|
|
982
|
+
return raw.entries;
|
|
983
|
+
}
|
|
984
|
+
function itemPage(raw) {
|
|
985
|
+
const page = object(raw);
|
|
986
|
+
const items = entries(page).map((entry) => {
|
|
987
|
+
const item = identity(object(entry));
|
|
988
|
+
if (!validID(item.id, true) || !item.name || !["file", "folder", "web_link"].includes(item.type))
|
|
989
|
+
throw new TypeError("Box page has an invalid item");
|
|
990
|
+
return item;
|
|
991
|
+
});
|
|
992
|
+
const limit = integer(page, "limit"), offset = integer(page, "offset"), count = integer(page, "total_count");
|
|
993
|
+
if ([limit, offset, count].some((value) => integerValue(value) < 0n)) throw new TypeError("Box page metadata is invalid");
|
|
994
|
+
return { entries: items, limit, offset, total_count: count };
|
|
995
|
+
}
|
|
996
|
+
function createdItem(raw, itemType, parent, name) {
|
|
997
|
+
const wire = object(raw);
|
|
998
|
+
const item = identity(wire);
|
|
999
|
+
const parentId = text(nested(wire, "parent"), "id");
|
|
1000
|
+
if (!validID(item.id) || item.type !== itemType || item.name !== name || parentId !== parent)
|
|
1001
|
+
throw new TypeError("Box created item differs from request");
|
|
1002
|
+
return { ...item, parentId };
|
|
1003
|
+
}
|
|
1004
|
+
function createdFile(raw, parentId, name, digest, size) {
|
|
1005
|
+
const items = entries(object(raw));
|
|
1006
|
+
if (items.length !== 1) throw new TypeError("Box did not return one created file");
|
|
1007
|
+
const file = fileFields(items[0]);
|
|
1008
|
+
if (!validID(file.id) || file.type !== "file" || file.name !== name || file.sha1.toUpperCase() !== digest || integerValue(file.size) !== BigInt(size))
|
|
1009
|
+
throw new TypeError("Box created file differs from request");
|
|
1010
|
+
return { fileId: file.id, name, parentId, sha1: file.sha1.toUpperCase() };
|
|
1011
|
+
}
|
|
277
1012
|
|
|
278
1013
|
// src/client.ts
|
|
279
1014
|
var BoxClient = class {
|
|
@@ -321,6 +1056,66 @@ var BoxClient = class {
|
|
|
321
1056
|
uploadFile() {
|
|
322
1057
|
return new UploadFileOperation(this);
|
|
323
1058
|
}
|
|
1059
|
+
/** Bind the createFolder operation. */
|
|
1060
|
+
createFolder() {
|
|
1061
|
+
return new CreateFolderOperation(this);
|
|
1062
|
+
}
|
|
1063
|
+
/** Bind the copyFile operation. */
|
|
1064
|
+
copyFile() {
|
|
1065
|
+
return new CopyFileOperation(this);
|
|
1066
|
+
}
|
|
1067
|
+
/** Bind the copyFolder operation. */
|
|
1068
|
+
copyFolder() {
|
|
1069
|
+
return new CopyFolderOperation(this);
|
|
1070
|
+
}
|
|
1071
|
+
/** Bind the updateFile operation. */
|
|
1072
|
+
updateFile() {
|
|
1073
|
+
return new UpdateFileOperation(this);
|
|
1074
|
+
}
|
|
1075
|
+
/** Bind the updateFolder operation. */
|
|
1076
|
+
updateFolder() {
|
|
1077
|
+
return new UpdateFolderOperation(this);
|
|
1078
|
+
}
|
|
1079
|
+
/** Bind the shareFile operation. */
|
|
1080
|
+
shareFile() {
|
|
1081
|
+
return new ShareFileOperation(this);
|
|
1082
|
+
}
|
|
1083
|
+
/** Bind the shareFolder operation. */
|
|
1084
|
+
shareFolder() {
|
|
1085
|
+
return new ShareFolderOperation(this);
|
|
1086
|
+
}
|
|
1087
|
+
/** Bind the createFile operation. */
|
|
1088
|
+
createFile() {
|
|
1089
|
+
return new CreateFileOperation(this);
|
|
1090
|
+
}
|
|
1091
|
+
/** Bind the getFile operation. */
|
|
1092
|
+
getFile() {
|
|
1093
|
+
return new GetFileOperation(this);
|
|
1094
|
+
}
|
|
1095
|
+
/** Bind the getFolder operation. */
|
|
1096
|
+
getFolder() {
|
|
1097
|
+
return new GetFolderOperation(this);
|
|
1098
|
+
}
|
|
1099
|
+
/** Bind the listFolderItems operation. */
|
|
1100
|
+
listFolderItems() {
|
|
1101
|
+
return new ListFolderItemsOperation(this);
|
|
1102
|
+
}
|
|
1103
|
+
/** Bind the searchFiles operation. */
|
|
1104
|
+
searchFiles() {
|
|
1105
|
+
return new SearchFilesOperation(this);
|
|
1106
|
+
}
|
|
1107
|
+
/** Bind the searchFolders operation. */
|
|
1108
|
+
searchFolders() {
|
|
1109
|
+
return new SearchFoldersOperation(this);
|
|
1110
|
+
}
|
|
1111
|
+
/** Bind the deleteFile operation. */
|
|
1112
|
+
deleteFile() {
|
|
1113
|
+
return new DeleteFileOperation(this);
|
|
1114
|
+
}
|
|
1115
|
+
/** Bind the deleteFolder operation. */
|
|
1116
|
+
deleteFolder() {
|
|
1117
|
+
return new DeleteFolderOperation(this);
|
|
1118
|
+
}
|
|
324
1119
|
/** Download one file, following only Box's signed HTTPS content URL. */
|
|
325
1120
|
async download(call, fileID) {
|
|
326
1121
|
const token = await this.resolveToken(call);
|
|
@@ -357,42 +1152,48 @@ var BoxClient = class {
|
|
|
357
1152
|
async upload(call, fileID, name, content) {
|
|
358
1153
|
const token = await this.resolveToken(call);
|
|
359
1154
|
if (typeof token !== "string") return token;
|
|
360
|
-
const
|
|
361
|
-
const escapedName = name.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/[\r\n]/g, "_");
|
|
362
|
-
const body = Buffer.concat([
|
|
363
|
-
Buffer.from(`--${boundary}\r
|
|
364
|
-
Content-Disposition: form-data; name="attributes"\r
|
|
365
|
-
\r
|
|
366
|
-
${JSON.stringify({ name })}\r
|
|
367
|
-
`),
|
|
368
|
-
Buffer.from(`--${boundary}\r
|
|
369
|
-
Content-Disposition: form-data; name="file"; filename="${escapedName}"\r
|
|
370
|
-
Content-Type: application/octet-stream\r
|
|
371
|
-
\r
|
|
372
|
-
`),
|
|
373
|
-
Buffer.from(content),
|
|
374
|
-
Buffer.from(`\r
|
|
375
|
-
--${boundary}--\r
|
|
376
|
-
`)
|
|
377
|
-
]);
|
|
1155
|
+
const { body, contentType } = encodeBoxMultipart({ name }, name, content);
|
|
378
1156
|
return this.request(call, "POST", this.uploadBaseURL + `/2.0/files/${fileID}/content`, {
|
|
379
1157
|
Authorization: "Bearer " + token,
|
|
380
1158
|
Accept: "application/json",
|
|
381
|
-
"Content-Type":
|
|
1159
|
+
"Content-Type": contentType
|
|
382
1160
|
}, this.maxResponseBytes, token, body);
|
|
383
1161
|
}
|
|
1162
|
+
/** Send a bounded request against the configured Box API. */
|
|
1163
|
+
async itemRequest(call, method, path, payload) {
|
|
1164
|
+
const send = await this.prepareItemRequest(call, method, path, payload);
|
|
1165
|
+
return typeof send === "function" ? send(call.context.cancellationSignal) : send;
|
|
1166
|
+
}
|
|
1167
|
+
/** Resolve credentials outside the fence and bind them to one metadata request. */
|
|
1168
|
+
async prepareItemRequest(call, method, path, payload, file) {
|
|
1169
|
+
if (!path.startsWith("/2.0/")) return emptyExchange("request");
|
|
1170
|
+
const token = await this.resolveToken(call);
|
|
1171
|
+
if (typeof token !== "string") return token;
|
|
1172
|
+
const headers = { Authorization: "Bearer " + token, Accept: "application/json" };
|
|
1173
|
+
let body;
|
|
1174
|
+
if (file) {
|
|
1175
|
+
const multipart = encodeBoxMultipart(payload ?? {}, file.name, file.content);
|
|
1176
|
+
body = multipart.body;
|
|
1177
|
+
headers["Content-Type"] = multipart.contentType;
|
|
1178
|
+
} else if (payload !== void 0) {
|
|
1179
|
+
body = Buffer.from(JSON.stringify(payload));
|
|
1180
|
+
headers["Content-Type"] = "application/json";
|
|
1181
|
+
}
|
|
1182
|
+
const url = (file ? this.uploadBaseURL : this.baseURL) + path;
|
|
1183
|
+
return (signal) => this.request(call, method, url, headers, this.maxResponseBytes, token, body, signal, false);
|
|
1184
|
+
}
|
|
384
1185
|
async resolveToken(call) {
|
|
385
|
-
let
|
|
1186
|
+
let credentials;
|
|
386
1187
|
try {
|
|
387
|
-
|
|
388
|
-
if (!(credentials.accessToken instanceof SecretString)) return emptyExchange("credential");
|
|
389
|
-
token = credentials.accessToken.reveal();
|
|
1188
|
+
credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
|
|
390
1189
|
} catch (error) {
|
|
391
|
-
|
|
1190
|
+
const isTerminal = error instanceof ReauthorizationRequiredError || error instanceof ObjectNotFoundError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || isCredentialMaterialError(error);
|
|
1191
|
+
return emptyExchange(isTerminal ? "credential" : "refresh");
|
|
392
1192
|
}
|
|
1193
|
+
const token = credentials.accessToken instanceof SecretString ? credentials.accessToken.reveal() : "";
|
|
393
1194
|
return token && isHeaderSafeCredential(token) ? token : emptyExchange("credential");
|
|
394
1195
|
}
|
|
395
|
-
async request(call, method, url, headers, successLimit, token, body) {
|
|
1196
|
+
async request(call, method, url, headers, successLimit, token, body, signal = call.context.cancellationSignal, captureRedirect = true) {
|
|
396
1197
|
const request = {
|
|
397
1198
|
url,
|
|
398
1199
|
method,
|
|
@@ -400,7 +1201,7 @@ Content-Type: application/octet-stream\r
|
|
|
400
1201
|
maxResponseBytes: Math.max(successLimit, this.maxResponseBytes),
|
|
401
1202
|
addressPolicy: new URL(url).protocol === "http:" ? "privateNetworkHTTP" : "publicHTTPS",
|
|
402
1203
|
timeoutMs: this.timeoutMs,
|
|
403
|
-
signal
|
|
1204
|
+
signal,
|
|
404
1205
|
...body === void 0 ? {} : { body }
|
|
405
1206
|
};
|
|
406
1207
|
let response;
|
|
@@ -413,6 +1214,12 @@ Content-Type: application/octet-stream\r
|
|
|
413
1214
|
requestSent: true,
|
|
414
1215
|
retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
|
|
415
1216
|
};
|
|
1217
|
+
if (error instanceof ProviderTransportError && !captureRedirect && error.status !== void 0) return {
|
|
1218
|
+
...emptyExchange("read"),
|
|
1219
|
+
status: error.status,
|
|
1220
|
+
requestSent: true,
|
|
1221
|
+
retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
|
|
1222
|
+
};
|
|
416
1223
|
if (error instanceof ProviderTransportError) return {
|
|
417
1224
|
...emptyExchange("request"),
|
|
418
1225
|
requestSent: !error.isProvablyNotSent
|
|
@@ -420,7 +1227,7 @@ Content-Type: application/octet-stream\r
|
|
|
420
1227
|
return emptyExchange("request");
|
|
421
1228
|
}
|
|
422
1229
|
const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
|
|
423
|
-
const location = response.status === 302 ? header(response.headers, "location") : "";
|
|
1230
|
+
const location = captureRedirect && response.status === 302 ? header(response.headers, "location") : "";
|
|
424
1231
|
if (location.includes(token) || Buffer.from(response.body).includes(token))
|
|
425
1232
|
return { status: response.status, body: new Uint8Array(), retryAfterMs, requestSent: true, error: "credential" };
|
|
426
1233
|
const limit = response.status === 200 ? successLimit : this.maxResponseBytes;
|
|
@@ -428,6 +1235,27 @@ Content-Type: application/octet-stream\r
|
|
|
428
1235
|
return { status: response.status, body: response.body, retryAfterMs, requestSent: true, ...location ? { location } : {} };
|
|
429
1236
|
}
|
|
430
1237
|
};
|
|
1238
|
+
function encodeBoxMultipart(attributes, name, content) {
|
|
1239
|
+
const boundary = "dexbox" + randomBytes(12).toString("hex");
|
|
1240
|
+
const escapedName = name.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/[\r\n]/g, "_");
|
|
1241
|
+
const body = Buffer.concat([
|
|
1242
|
+
Buffer.from(`--${boundary}\r
|
|
1243
|
+
Content-Disposition: form-data; name="attributes"\r
|
|
1244
|
+
\r
|
|
1245
|
+
${JSON.stringify(attributes)}\r
|
|
1246
|
+
`),
|
|
1247
|
+
Buffer.from(`--${boundary}\r
|
|
1248
|
+
Content-Disposition: form-data; name="file"; filename="${escapedName}"\r
|
|
1249
|
+
Content-Type: application/octet-stream\r
|
|
1250
|
+
\r
|
|
1251
|
+
`),
|
|
1252
|
+
Buffer.from(content),
|
|
1253
|
+
Buffer.from(`\r
|
|
1254
|
+
--${boundary}--\r
|
|
1255
|
+
`)
|
|
1256
|
+
]);
|
|
1257
|
+
return { body, contentType: `multipart/form-data; boundary=${boundary}` };
|
|
1258
|
+
}
|
|
431
1259
|
function emptyExchange(error) {
|
|
432
1260
|
return { status: 0, body: new Uint8Array(), retryAfterMs: 0, requestSent: false, error };
|
|
433
1261
|
}
|
|
@@ -465,12 +1293,96 @@ function newProjectConnection(project, connectionName, options = {}) {
|
|
|
465
1293
|
|
|
466
1294
|
// src/generated/steps.ts
|
|
467
1295
|
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
1296
|
+
function newCreateFolderStep(configuration) {
|
|
1297
|
+
const { connection, connectionName, created, providerRejected, defect, uncertain, ...stepConfiguration } = configuration;
|
|
1298
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1299
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.createFolder(), connection: connection.reference, branches: [
|
|
1300
|
+
goToBranch("created", created),
|
|
1301
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1302
|
+
...defect ? [goToBranch("defect", defect)] : [],
|
|
1303
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : []
|
|
1304
|
+
] });
|
|
1305
|
+
}
|
|
1306
|
+
function newCopyFileStep(configuration) {
|
|
1307
|
+
const { connection, connectionName, copied, providerRejected, defect, uncertain, ...stepConfiguration } = configuration;
|
|
1308
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1309
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.copyFile(), connection: connection.reference, branches: [
|
|
1310
|
+
goToBranch("copied", copied),
|
|
1311
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1312
|
+
...defect ? [goToBranch("defect", defect)] : [],
|
|
1313
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : []
|
|
1314
|
+
] });
|
|
1315
|
+
}
|
|
1316
|
+
function newCopyFolderStep(configuration) {
|
|
1317
|
+
const { connection, connectionName, copied, providerRejected, defect, uncertain, ...stepConfiguration } = configuration;
|
|
1318
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1319
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.copyFolder(), connection: connection.reference, branches: [
|
|
1320
|
+
goToBranch("copied", copied),
|
|
1321
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1322
|
+
...defect ? [goToBranch("defect", defect)] : [],
|
|
1323
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : []
|
|
1324
|
+
] });
|
|
1325
|
+
}
|
|
1326
|
+
function newUpdateFileStep(configuration) {
|
|
1327
|
+
const { connection, connectionName, updated, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
1328
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1329
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateFile(), connection: connection.reference, branches: [
|
|
1330
|
+
goToBranch("updated", updated),
|
|
1331
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1332
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1333
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1334
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1335
|
+
] });
|
|
1336
|
+
}
|
|
1337
|
+
function newUpdateFolderStep(configuration) {
|
|
1338
|
+
const { connection, connectionName, updated, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
1339
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1340
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.updateFolder(), connection: connection.reference, branches: [
|
|
1341
|
+
goToBranch("updated", updated),
|
|
1342
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1343
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1344
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1345
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1346
|
+
] });
|
|
1347
|
+
}
|
|
1348
|
+
function newShareFileStep(configuration) {
|
|
1349
|
+
const { connection, connectionName, shared, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
1350
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1351
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.shareFile(), connection: connection.reference, branches: [
|
|
1352
|
+
goToBranch("shared", shared),
|
|
1353
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1354
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1355
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1356
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1357
|
+
] });
|
|
1358
|
+
}
|
|
1359
|
+
function newShareFolderStep(configuration) {
|
|
1360
|
+
const { connection, connectionName, shared, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
1361
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1362
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.shareFolder(), connection: connection.reference, branches: [
|
|
1363
|
+
goToBranch("shared", shared),
|
|
1364
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1365
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1366
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1367
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1368
|
+
] });
|
|
1369
|
+
}
|
|
1370
|
+
function newCreateFileStep(configuration) {
|
|
1371
|
+
const { connection, connectionName, created, providerRejected, defect, uncertain, ...stepConfiguration } = configuration;
|
|
1372
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1373
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.createFile(), connection: connection.reference, branches: [
|
|
1374
|
+
goToBranch("created", created),
|
|
1375
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1376
|
+
...defect ? [goToBranch("defect", defect)] : [],
|
|
1377
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : []
|
|
1378
|
+
] });
|
|
1379
|
+
}
|
|
468
1380
|
function newDownloadFileStep(configuration) {
|
|
469
|
-
const { connection, connectionName, downloaded, notFound, tooLarge, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1381
|
+
const { connection, connectionName, downloaded, notFound: notFound2, tooLarge, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
470
1382
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
471
1383
|
return newQueryStep({ ...stepConfiguration, operation: connection.operations.downloadFile(), connection: connection.reference, branches: [
|
|
472
1384
|
goToBranch("downloaded", downloaded),
|
|
473
|
-
...
|
|
1385
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
474
1386
|
...tooLarge ? [goToBranch("tooLarge", tooLarge)] : [],
|
|
475
1387
|
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
476
1388
|
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
@@ -478,11 +1390,86 @@ function newDownloadFileStep(configuration) {
|
|
|
478
1390
|
] });
|
|
479
1391
|
}
|
|
480
1392
|
function newUploadFileStep(configuration) {
|
|
481
|
-
const { connection, connectionName, uploaded: uploaded2, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1393
|
+
const { connection, connectionName, uploaded: uploaded2, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
482
1394
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
483
1395
|
return newMutationStep({ ...stepConfiguration, operation: connection.operations.uploadFile(), connection: connection.reference, branches: [
|
|
484
1396
|
goToBranch("uploaded", uploaded2),
|
|
485
|
-
...
|
|
1397
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1398
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1399
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1400
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1401
|
+
] });
|
|
1402
|
+
}
|
|
1403
|
+
function newGetFileStep(configuration) {
|
|
1404
|
+
const { connection, connectionName, found, notFound: notFound2, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1405
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1406
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getFile(), connection: connection.reference, branches: [
|
|
1407
|
+
goToBranch("found", found),
|
|
1408
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1409
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1410
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1411
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1412
|
+
] });
|
|
1413
|
+
}
|
|
1414
|
+
function newGetFolderStep(configuration) {
|
|
1415
|
+
const { connection, connectionName, found, notFound: notFound2, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1416
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1417
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.getFolder(), connection: connection.reference, branches: [
|
|
1418
|
+
goToBranch("found", found),
|
|
1419
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1420
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1421
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1422
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1423
|
+
] });
|
|
1424
|
+
}
|
|
1425
|
+
function newListFolderItemsStep(configuration) {
|
|
1426
|
+
const { connection, connectionName, listed, notFound: notFound2, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1427
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1428
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.listFolderItems(), connection: connection.reference, branches: [
|
|
1429
|
+
goToBranch("listed", listed),
|
|
1430
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1431
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1432
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1433
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1434
|
+
] });
|
|
1435
|
+
}
|
|
1436
|
+
function newSearchFilesStep(configuration) {
|
|
1437
|
+
const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1438
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1439
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.searchFiles(), connection: connection.reference, branches: [
|
|
1440
|
+
goToBranch("found", found),
|
|
1441
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1442
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1443
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1444
|
+
] });
|
|
1445
|
+
}
|
|
1446
|
+
function newSearchFoldersStep(configuration) {
|
|
1447
|
+
const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
1448
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1449
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.searchFolders(), connection: connection.reference, branches: [
|
|
1450
|
+
goToBranch("found", found),
|
|
1451
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1452
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1453
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1454
|
+
] });
|
|
1455
|
+
}
|
|
1456
|
+
function newDeleteFileStep(configuration) {
|
|
1457
|
+
const { connection, connectionName, deleted, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
1458
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1459
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteFile(), connection: connection.reference, branches: [
|
|
1460
|
+
goToBranch("deleted", deleted),
|
|
1461
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
1462
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1463
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1464
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1465
|
+
] });
|
|
1466
|
+
}
|
|
1467
|
+
function newDeleteFolderStep(configuration) {
|
|
1468
|
+
const { connection, connectionName, deleted, notFound: notFound2, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
1469
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1470
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deleteFolder(), connection: connection.reference, branches: [
|
|
1471
|
+
goToBranch("deleted", deleted),
|
|
1472
|
+
...notFound2 ? [goToBranch("notFound", notFound2)] : [],
|
|
486
1473
|
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
487
1474
|
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
488
1475
|
...defect ? [goToBranch("defect", defect)] : []
|
|
@@ -490,9 +1477,73 @@ function newUploadFileStep(configuration) {
|
|
|
490
1477
|
}
|
|
491
1478
|
export {
|
|
492
1479
|
BoxClient,
|
|
1480
|
+
BoxFileSchema,
|
|
1481
|
+
BoxFolderSchema,
|
|
1482
|
+
BoxItemPageSchema,
|
|
1483
|
+
BoxItemSchema,
|
|
493
1484
|
ConfigSchema,
|
|
494
1485
|
Connection,
|
|
495
1486
|
ConnectorID,
|
|
1487
|
+
CopyBoxFileInputSchema,
|
|
1488
|
+
CopyBoxFolderInputSchema,
|
|
1489
|
+
CopyFileBranch,
|
|
1490
|
+
CopyFileBranchCopied,
|
|
1491
|
+
CopyFileBranchDefect,
|
|
1492
|
+
CopyFileBranchProviderRejected,
|
|
1493
|
+
CopyFileBranchUncertain,
|
|
1494
|
+
CopyFileDefinition,
|
|
1495
|
+
CopyFileMetadata,
|
|
1496
|
+
CopyFileOperation,
|
|
1497
|
+
CopyFolderBranch,
|
|
1498
|
+
CopyFolderBranchCopied,
|
|
1499
|
+
CopyFolderBranchDefect,
|
|
1500
|
+
CopyFolderBranchProviderRejected,
|
|
1501
|
+
CopyFolderBranchUncertain,
|
|
1502
|
+
CopyFolderDefinition,
|
|
1503
|
+
CopyFolderMetadata,
|
|
1504
|
+
CopyFolderOperation,
|
|
1505
|
+
CreateBoxFileInputSchema,
|
|
1506
|
+
CreateBoxFolderInputSchema,
|
|
1507
|
+
CreateFileBranch,
|
|
1508
|
+
CreateFileBranchCreated,
|
|
1509
|
+
CreateFileBranchDefect,
|
|
1510
|
+
CreateFileBranchProviderRejected,
|
|
1511
|
+
CreateFileBranchUncertain,
|
|
1512
|
+
CreateFileDefinition,
|
|
1513
|
+
CreateFileMetadata,
|
|
1514
|
+
CreateFileOperation,
|
|
1515
|
+
CreateFolderBranch,
|
|
1516
|
+
CreateFolderBranchCreated,
|
|
1517
|
+
CreateFolderBranchDefect,
|
|
1518
|
+
CreateFolderBranchProviderRejected,
|
|
1519
|
+
CreateFolderBranchUncertain,
|
|
1520
|
+
CreateFolderDefinition,
|
|
1521
|
+
CreateFolderMetadata,
|
|
1522
|
+
CreateFolderOperation,
|
|
1523
|
+
CreatedBoxFileSchema,
|
|
1524
|
+
CreatedBoxItemSchema,
|
|
1525
|
+
CredentialMaterialError,
|
|
1526
|
+
DeleteFileBranch,
|
|
1527
|
+
DeleteFileBranchDefect,
|
|
1528
|
+
DeleteFileBranchDeleted,
|
|
1529
|
+
DeleteFileBranchInvalidResponse,
|
|
1530
|
+
DeleteFileBranchNotFound,
|
|
1531
|
+
DeleteFileBranchProviderRejected,
|
|
1532
|
+
DeleteFileDefinition,
|
|
1533
|
+
DeleteFileInputSchema,
|
|
1534
|
+
DeleteFileMetadata,
|
|
1535
|
+
DeleteFileOperation,
|
|
1536
|
+
DeleteFolderBranch,
|
|
1537
|
+
DeleteFolderBranchDefect,
|
|
1538
|
+
DeleteFolderBranchDeleted,
|
|
1539
|
+
DeleteFolderBranchInvalidResponse,
|
|
1540
|
+
DeleteFolderBranchNotFound,
|
|
1541
|
+
DeleteFolderBranchProviderRejected,
|
|
1542
|
+
DeleteFolderDefinition,
|
|
1543
|
+
DeleteFolderInputSchema,
|
|
1544
|
+
DeleteFolderMetadata,
|
|
1545
|
+
DeleteFolderOperation,
|
|
1546
|
+
DeletedBoxItemSchema,
|
|
496
1547
|
DownloadFileBranch,
|
|
497
1548
|
DownloadFileBranchDefect,
|
|
498
1549
|
DownloadFileBranchDownloaded,
|
|
@@ -505,7 +1556,96 @@ export {
|
|
|
505
1556
|
DownloadFileMetadata,
|
|
506
1557
|
DownloadFileOperation,
|
|
507
1558
|
DownloadedFileSchema,
|
|
1559
|
+
GetFileBranch,
|
|
1560
|
+
GetFileBranchDefect,
|
|
1561
|
+
GetFileBranchFound,
|
|
1562
|
+
GetFileBranchInvalidResponse,
|
|
1563
|
+
GetFileBranchNotFound,
|
|
1564
|
+
GetFileBranchProviderRejected,
|
|
1565
|
+
GetFileDefinition,
|
|
1566
|
+
GetFileInputSchema,
|
|
1567
|
+
GetFileMetadata,
|
|
1568
|
+
GetFileOperation,
|
|
1569
|
+
GetFolderBranch,
|
|
1570
|
+
GetFolderBranchDefect,
|
|
1571
|
+
GetFolderBranchFound,
|
|
1572
|
+
GetFolderBranchInvalidResponse,
|
|
1573
|
+
GetFolderBranchNotFound,
|
|
1574
|
+
GetFolderBranchProviderRejected,
|
|
1575
|
+
GetFolderDefinition,
|
|
1576
|
+
GetFolderInputSchema,
|
|
1577
|
+
GetFolderMetadata,
|
|
1578
|
+
GetFolderOperation,
|
|
1579
|
+
ListFolderItemsBranch,
|
|
1580
|
+
ListFolderItemsBranchDefect,
|
|
1581
|
+
ListFolderItemsBranchInvalidResponse,
|
|
1582
|
+
ListFolderItemsBranchListed,
|
|
1583
|
+
ListFolderItemsBranchNotFound,
|
|
1584
|
+
ListFolderItemsBranchProviderRejected,
|
|
1585
|
+
ListFolderItemsDefinition,
|
|
1586
|
+
ListFolderItemsInputSchema,
|
|
1587
|
+
ListFolderItemsMetadata,
|
|
1588
|
+
ListFolderItemsOperation,
|
|
508
1589
|
ProviderID,
|
|
1590
|
+
SearchFilesBranch,
|
|
1591
|
+
SearchFilesBranchDefect,
|
|
1592
|
+
SearchFilesBranchFound,
|
|
1593
|
+
SearchFilesBranchInvalidResponse,
|
|
1594
|
+
SearchFilesBranchProviderRejected,
|
|
1595
|
+
SearchFilesDefinition,
|
|
1596
|
+
SearchFilesInputSchema,
|
|
1597
|
+
SearchFilesMetadata,
|
|
1598
|
+
SearchFilesOperation,
|
|
1599
|
+
SearchFoldersBranch,
|
|
1600
|
+
SearchFoldersBranchDefect,
|
|
1601
|
+
SearchFoldersBranchFound,
|
|
1602
|
+
SearchFoldersBranchInvalidResponse,
|
|
1603
|
+
SearchFoldersBranchProviderRejected,
|
|
1604
|
+
SearchFoldersDefinition,
|
|
1605
|
+
SearchFoldersInputSchema,
|
|
1606
|
+
SearchFoldersMetadata,
|
|
1607
|
+
SearchFoldersOperation,
|
|
1608
|
+
ShareBoxFileInputSchema,
|
|
1609
|
+
ShareBoxFolderInputSchema,
|
|
1610
|
+
ShareFileBranch,
|
|
1611
|
+
ShareFileBranchDefect,
|
|
1612
|
+
ShareFileBranchInvalidResponse,
|
|
1613
|
+
ShareFileBranchNotFound,
|
|
1614
|
+
ShareFileBranchProviderRejected,
|
|
1615
|
+
ShareFileBranchShared,
|
|
1616
|
+
ShareFileDefinition,
|
|
1617
|
+
ShareFileMetadata,
|
|
1618
|
+
ShareFileOperation,
|
|
1619
|
+
ShareFolderBranch,
|
|
1620
|
+
ShareFolderBranchDefect,
|
|
1621
|
+
ShareFolderBranchInvalidResponse,
|
|
1622
|
+
ShareFolderBranchNotFound,
|
|
1623
|
+
ShareFolderBranchProviderRejected,
|
|
1624
|
+
ShareFolderBranchShared,
|
|
1625
|
+
ShareFolderDefinition,
|
|
1626
|
+
ShareFolderMetadata,
|
|
1627
|
+
ShareFolderOperation,
|
|
1628
|
+
UpdateBoxFileInputSchema,
|
|
1629
|
+
UpdateBoxFolderInputSchema,
|
|
1630
|
+
UpdateFileBranch,
|
|
1631
|
+
UpdateFileBranchDefect,
|
|
1632
|
+
UpdateFileBranchInvalidResponse,
|
|
1633
|
+
UpdateFileBranchNotFound,
|
|
1634
|
+
UpdateFileBranchProviderRejected,
|
|
1635
|
+
UpdateFileBranchUpdated,
|
|
1636
|
+
UpdateFileDefinition,
|
|
1637
|
+
UpdateFileMetadata,
|
|
1638
|
+
UpdateFileOperation,
|
|
1639
|
+
UpdateFolderBranch,
|
|
1640
|
+
UpdateFolderBranchDefect,
|
|
1641
|
+
UpdateFolderBranchInvalidResponse,
|
|
1642
|
+
UpdateFolderBranchNotFound,
|
|
1643
|
+
UpdateFolderBranchProviderRejected,
|
|
1644
|
+
UpdateFolderBranchUpdated,
|
|
1645
|
+
UpdateFolderDefinition,
|
|
1646
|
+
UpdateFolderMetadata,
|
|
1647
|
+
UpdateFolderOperation,
|
|
1648
|
+
UpdatedBoxItemSchema,
|
|
509
1649
|
UploadFileBranch,
|
|
510
1650
|
UploadFileBranchDefect,
|
|
511
1651
|
UploadFileBranchInvalidResponse,
|
|
@@ -519,10 +1659,30 @@ export {
|
|
|
519
1659
|
UploadedFileSchema,
|
|
520
1660
|
decodeCredentials,
|
|
521
1661
|
decodeSharedCredentials,
|
|
1662
|
+
decodeSignedInteger,
|
|
1663
|
+
exactIntegerJSONCodec,
|
|
522
1664
|
header,
|
|
1665
|
+
isCredentialMaterialError,
|
|
523
1666
|
newConnection,
|
|
524
1667
|
newConnectionWithOperations,
|
|
1668
|
+
newCopyFileStep,
|
|
1669
|
+
newCopyFolderStep,
|
|
1670
|
+
newCreateFileStep,
|
|
1671
|
+
newCreateFolderStep,
|
|
1672
|
+
newDeleteFileStep,
|
|
1673
|
+
newDeleteFolderStep,
|
|
525
1674
|
newDownloadFileStep,
|
|
1675
|
+
newGetFileStep,
|
|
1676
|
+
newGetFolderStep,
|
|
1677
|
+
newListFolderItemsStep,
|
|
526
1678
|
newProjectConnection,
|
|
527
|
-
|
|
1679
|
+
newSearchFilesStep,
|
|
1680
|
+
newSearchFoldersStep,
|
|
1681
|
+
newShareFileStep,
|
|
1682
|
+
newShareFolderStep,
|
|
1683
|
+
newUpdateFileStep,
|
|
1684
|
+
newUpdateFolderStep,
|
|
1685
|
+
newUploadFileStep,
|
|
1686
|
+
parseExactIntegerJSON,
|
|
1687
|
+
parseJSONNumberTokens
|
|
528
1688
|
};
|