@superdurable/connector-dropbox 0.2.0 → 0.3.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 -2
- package/dex-connector.json +265 -2
- package/dist/{chunk-SWXGPJ62.js → chunk-RMQLFGNQ.js} +422 -21
- package/dist/{connection-CufXPwNo.d.ts → connection-Csm3tCeA.d.ts} +100 -1
- package/dist/index.d.ts +272 -7
- package/dist/index.js +493 -21
- package/dist/mock.d.ts +91 -2
- package/dist/mock.js +85 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11,6 +11,23 @@ import {
|
|
|
11
11
|
ContinueFolderDefinition,
|
|
12
12
|
ContinueFolderInputSchema,
|
|
13
13
|
ContinueFolderMetadata,
|
|
14
|
+
CopyPathBranch,
|
|
15
|
+
CopyPathBranchCopied,
|
|
16
|
+
CopyPathBranchDefect,
|
|
17
|
+
CopyPathBranchProviderRejected,
|
|
18
|
+
CopyPathBranchUncertain,
|
|
19
|
+
CopyPathDefinition,
|
|
20
|
+
CopyPathMetadata,
|
|
21
|
+
CredentialMaterialError,
|
|
22
|
+
DeletePathBranch,
|
|
23
|
+
DeletePathBranchDefect,
|
|
24
|
+
DeletePathBranchDeleted,
|
|
25
|
+
DeletePathBranchInvalidResponse,
|
|
26
|
+
DeletePathBranchProviderRejected,
|
|
27
|
+
DeletePathDefinition,
|
|
28
|
+
DeletePathInputSchema,
|
|
29
|
+
DeletePathMetadata,
|
|
30
|
+
DeletedPathSchema,
|
|
14
31
|
DownloadFileBranch,
|
|
15
32
|
DownloadFileBranchDefect,
|
|
16
33
|
DownloadFileBranchDownloaded,
|
|
@@ -22,6 +39,15 @@ import {
|
|
|
22
39
|
DownloadFileInputSchema,
|
|
23
40
|
DownloadFileMetadata,
|
|
24
41
|
DownloadedFileSchema,
|
|
42
|
+
EnsureFolderBranch,
|
|
43
|
+
EnsureFolderBranchDefect,
|
|
44
|
+
EnsureFolderBranchEnsured,
|
|
45
|
+
EnsureFolderBranchInvalidResponse,
|
|
46
|
+
EnsureFolderBranchProviderRejected,
|
|
47
|
+
EnsureFolderDefinition,
|
|
48
|
+
EnsureFolderInputSchema,
|
|
49
|
+
EnsureFolderMetadata,
|
|
50
|
+
EnsuredFolderSchema,
|
|
25
51
|
EntryMetadataSchema,
|
|
26
52
|
FolderPageSchema,
|
|
27
53
|
GetMetadataBranch,
|
|
@@ -42,7 +68,24 @@ import {
|
|
|
42
68
|
ListFolderDefinition,
|
|
43
69
|
ListFolderInputSchema,
|
|
44
70
|
ListFolderMetadata,
|
|
71
|
+
MovePathBranch,
|
|
72
|
+
MovePathBranchDefect,
|
|
73
|
+
MovePathBranchMoved,
|
|
74
|
+
MovePathBranchProviderRejected,
|
|
75
|
+
MovePathBranchUncertain,
|
|
76
|
+
MovePathDefinition,
|
|
77
|
+
MovePathMetadata,
|
|
45
78
|
ProviderID,
|
|
79
|
+
SearchFilesBranch,
|
|
80
|
+
SearchFilesBranchDefect,
|
|
81
|
+
SearchFilesBranchFound,
|
|
82
|
+
SearchFilesBranchInvalidResponse,
|
|
83
|
+
SearchFilesBranchProviderRejected,
|
|
84
|
+
SearchFilesDefinition,
|
|
85
|
+
SearchFilesInputSchema,
|
|
86
|
+
SearchFilesMetadata,
|
|
87
|
+
SearchFilesPageSchema,
|
|
88
|
+
TransferPathInputSchema,
|
|
46
89
|
UploadFileBranch,
|
|
47
90
|
UploadFileBranchDefect,
|
|
48
91
|
UploadFileBranchInvalidResponse,
|
|
@@ -58,10 +101,11 @@ import {
|
|
|
58
101
|
emptyEntryMetadata,
|
|
59
102
|
emptyFolderPage,
|
|
60
103
|
emptyUploadedFile,
|
|
104
|
+
isCredentialMaterialError,
|
|
61
105
|
newConnection,
|
|
62
106
|
newConnectionWithOperations,
|
|
63
107
|
newProjectCredentialProvider
|
|
64
|
-
} from "./chunk-
|
|
108
|
+
} from "./chunk-RMQLFGNQ.js";
|
|
65
109
|
|
|
66
110
|
// src/client.ts
|
|
67
111
|
import {
|
|
@@ -70,10 +114,12 @@ import {
|
|
|
70
114
|
resolveCredential
|
|
71
115
|
} from "@superdurable/connectors-sdk";
|
|
72
116
|
import { ManifestCredentialRefreshDriver } from "@superdurable/connectors-sdk/oauthtoken";
|
|
117
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
73
118
|
import {
|
|
74
119
|
BodyTooLargeError,
|
|
75
120
|
isHeaderSafeCredential,
|
|
76
121
|
parseRetryAfter,
|
|
122
|
+
ProviderTransportError,
|
|
77
123
|
sendProviderRequest,
|
|
78
124
|
validateBaseURL
|
|
79
125
|
} from "@superdurable/connectors-sdk/providerhttp";
|
|
@@ -151,11 +197,19 @@ var CredentialFields = {
|
|
|
151
197
|
|
|
152
198
|
// src/operations.ts
|
|
153
199
|
import {
|
|
200
|
+
definitionMaxSends,
|
|
154
201
|
newMutationBranch,
|
|
155
202
|
newMutationRetry,
|
|
203
|
+
newMutationUncertain,
|
|
156
204
|
newQueryBranch,
|
|
157
205
|
newQueryRetry
|
|
158
206
|
} from "@superdurable/connectors-sdk";
|
|
207
|
+
import {
|
|
208
|
+
CheckpointError,
|
|
209
|
+
DispatchNotAllowedError,
|
|
210
|
+
InsufficientTimeError,
|
|
211
|
+
newFence
|
|
212
|
+
} from "@superdurable/connectors-sdk/singledispatch";
|
|
159
213
|
function failure(operation, kind, message) {
|
|
160
214
|
return { kind, provider: "dropbox", operation, message };
|
|
161
215
|
}
|
|
@@ -370,21 +424,312 @@ var UploadFileOperation = class {
|
|
|
370
424
|
if (content.toString("base64") !== input.contentBase64) return uploadFailure("defect", "VALIDATION", "upload content must be bounded Base64");
|
|
371
425
|
if (content.length > this.client.maxUploadBytes) return uploadFailure("defect", "VALIDATION", "upload content must be bounded Base64");
|
|
372
426
|
const exchange = await this.client.upload(call, input.path, content);
|
|
373
|
-
if (exchange.error === "credential"
|
|
427
|
+
if (exchange.error === "credential" && exchange.status === 0) {
|
|
428
|
+
if ((call.context?.attempt ?? 1) > 1) return uploadRetry("AUTHENTICATION", "connection credentials are unavailable or invalid after a possible earlier upload");
|
|
429
|
+
return uploadFailure("defect", "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
430
|
+
}
|
|
431
|
+
if (exchange.error === "credential") return uploadRetry("PROTOCOL", "Dropbox echoed the access token, so the overwrite is repeated", exchange.retryAfterMs);
|
|
374
432
|
if (exchange.error === "refresh") return uploadRetry("AVAILABILITY", "Dropbox credentials could not be refreshed");
|
|
375
433
|
if (exchange.error === "request") return uploadRetry("TRANSPORT", "Dropbox upload request failed");
|
|
376
434
|
if (exchange.status === 429) return uploadRetry("RATE_LIMIT", "Dropbox rate limited the upload", exchange.retryAfterMs);
|
|
377
435
|
if (exchange.status === 408 || exchange.status >= 500) return uploadRetry("AVAILABILITY", "Dropbox upload is temporarily unavailable", exchange.retryAfterMs);
|
|
378
|
-
if (exchange.status !== 200) return uploadFailure("providerRejected", "PROVIDER_REJECTION", `Dropbox rejected HTTP ${exchange.status}`);
|
|
379
|
-
if (exchange.
|
|
436
|
+
if (exchange.status !== 200 && isDefiniteUploadRefusal(exchange)) return uploadFailure("providerRejected", "PROVIDER_REJECTION", `Dropbox rejected HTTP ${exchange.status}`);
|
|
437
|
+
if (exchange.status !== 200) return uploadRetry("PROTOCOL", `Dropbox answered the overwrite with unsettled HTTP ${exchange.status}`, exchange.retryAfterMs);
|
|
438
|
+
if (exchange.error === "tooLarge") return uploadRetry("RESPONSE_TOO_LARGE", "Dropbox upload metadata exceeded the configured limit");
|
|
380
439
|
if (exchange.error) return uploadRetry("TRANSPORT", "Dropbox upload response was interrupted");
|
|
381
440
|
try {
|
|
382
441
|
return newMutationBranch("uploaded", { file: decodeEntry(objectBody(exchange.body), true) });
|
|
383
442
|
} catch {
|
|
384
|
-
return
|
|
443
|
+
return uploadRetry("PROTOCOL", "Dropbox returned invalid upload metadata");
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
};
|
|
447
|
+
var definiteRefusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
|
|
448
|
+
function isDefiniteUploadRefusal(exchange) {
|
|
449
|
+
if (exchange.error) return false;
|
|
450
|
+
let wire;
|
|
451
|
+
try {
|
|
452
|
+
wire = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
|
|
453
|
+
} catch {
|
|
454
|
+
wire = void 0;
|
|
455
|
+
}
|
|
456
|
+
const fields = wire && typeof wire === "object" && !Array.isArray(wire) ? wire : void 0;
|
|
457
|
+
if (fields && fields.id !== void 0 && fields.id !== null && fields.id !== "") return false;
|
|
458
|
+
if (definiteRefusalStatuses.has(exchange.status)) return true;
|
|
459
|
+
return exchange.status === 409 && typeof fields?.error_summary === "string" && fields.error_summary !== "";
|
|
460
|
+
}
|
|
461
|
+
var SearchFilesOperation = class {
|
|
462
|
+
/** Bind the Dropbox client. */
|
|
463
|
+
constructor(client) {
|
|
464
|
+
this.client = client;
|
|
465
|
+
if (!client) throw new TypeError("Dropbox client is required");
|
|
466
|
+
}
|
|
467
|
+
client;
|
|
468
|
+
/** Return the generated search contract. */
|
|
469
|
+
definition() {
|
|
470
|
+
return SearchFilesDefinition;
|
|
471
|
+
}
|
|
472
|
+
/** Search once with a validated path and page size. */
|
|
473
|
+
async invoke(call, input) {
|
|
474
|
+
const operation = "searchFiles";
|
|
475
|
+
const zero = { entries: [], hasMore: false };
|
|
476
|
+
const { query, path = "", maxResults = 0 } = input;
|
|
477
|
+
if (!query || /^\p{White_Space}|\p{White_Space}$/u.test(query) || Buffer.byteLength(query) > 1e3 || Buffer.from(query).toString("utf8") !== query || !validPath(path, true) || !Number.isInteger(maxResults) || maxResults < 0 || maxResults > 1e3)
|
|
478
|
+
return queryFailure(operation, "defect", "VALIDATION", "search query, path, or page size is invalid", zero);
|
|
479
|
+
const options = { max_results: maxResults || 20, ...path && { path } };
|
|
480
|
+
const exchange = await this.client.postJSON(call, "/2/files/search_v2", { query, options });
|
|
481
|
+
const failed = queryDecision(operation, exchange, zero);
|
|
482
|
+
if (failed) return failed;
|
|
483
|
+
try {
|
|
484
|
+
return newQueryBranch("found", decodeSearchPage(exchange.body));
|
|
485
|
+
} catch {
|
|
486
|
+
return queryFailure(operation, "invalidResponse", "PROTOCOL", "Dropbox returned invalid JSON", zero);
|
|
385
487
|
}
|
|
386
488
|
}
|
|
387
489
|
};
|
|
490
|
+
var EnsureFolderOperation = class {
|
|
491
|
+
/** Bind the Dropbox client. */
|
|
492
|
+
constructor(client) {
|
|
493
|
+
this.client = client;
|
|
494
|
+
if (!client) throw new TypeError("Dropbox client is required");
|
|
495
|
+
}
|
|
496
|
+
client;
|
|
497
|
+
/** Return the generated folder contract. */
|
|
498
|
+
definition() {
|
|
499
|
+
return EnsureFolderDefinition;
|
|
500
|
+
}
|
|
501
|
+
/** Use the stable call ID for the receipt. */
|
|
502
|
+
idempotencyKey(callId) {
|
|
503
|
+
return callId;
|
|
504
|
+
}
|
|
505
|
+
/** Ensure the folder without autorenaming. */
|
|
506
|
+
async invoke(call, input) {
|
|
507
|
+
const operation = "ensureFolder";
|
|
508
|
+
const { path } = input;
|
|
509
|
+
if (!absolutePath(path))
|
|
510
|
+
return fileBranch(operation, "defect", { path: "" }, "VALIDATION", "folder path must be absolute");
|
|
511
|
+
const exchange = await this.client.postJSON(call, "/2/files/create_folder_v2", { path, autorename: false });
|
|
512
|
+
return classifyFileWrite(operation, exchange, { path }, "ensured", "path/conflict/folder", "folder");
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var DeletePathOperation = class {
|
|
516
|
+
/** Bind the Dropbox client. */
|
|
517
|
+
constructor(client) {
|
|
518
|
+
this.client = client;
|
|
519
|
+
if (!client) throw new TypeError("Dropbox client is required");
|
|
520
|
+
}
|
|
521
|
+
client;
|
|
522
|
+
/** Return the generated deletion contract. */
|
|
523
|
+
definition() {
|
|
524
|
+
return DeletePathDefinition;
|
|
525
|
+
}
|
|
526
|
+
/** Use the stable call ID for the receipt. */
|
|
527
|
+
idempotencyKey(callId) {
|
|
528
|
+
return callId;
|
|
529
|
+
}
|
|
530
|
+
/** Delete the selected path or ID. */
|
|
531
|
+
async invoke(call, input) {
|
|
532
|
+
const operation = "deletePath";
|
|
533
|
+
const { path } = input;
|
|
534
|
+
if (!validPath(path, false) || path.startsWith("rev:"))
|
|
535
|
+
return fileBranch(operation, "defect", { path: "" }, "VALIDATION", "delete path is invalid");
|
|
536
|
+
const exchange = await this.client.postJSON(call, "/2/files/delete_v2", { path });
|
|
537
|
+
return classifyFileWrite(operation, exchange, { path }, "deleted", "path_lookup/not_found");
|
|
538
|
+
}
|
|
539
|
+
};
|
|
540
|
+
var CopyPathOperation = class {
|
|
541
|
+
/** Bind the Dropbox client. */
|
|
542
|
+
constructor(client) {
|
|
543
|
+
this.client = client;
|
|
544
|
+
if (!client) throw new TypeError("Dropbox client is required");
|
|
545
|
+
}
|
|
546
|
+
client;
|
|
547
|
+
/** Return the generated copy contract. */
|
|
548
|
+
definition() {
|
|
549
|
+
return CopyPathDefinition;
|
|
550
|
+
}
|
|
551
|
+
/** Use the stable call ID for dispatch and receipts. */
|
|
552
|
+
idempotencyKey(callId) {
|
|
553
|
+
return callId;
|
|
554
|
+
}
|
|
555
|
+
/** Copy without autorenaming the destination. */
|
|
556
|
+
invoke(call, input) {
|
|
557
|
+
return transferPath(this.client, call, input, this.definition(), "/2/files/copy_v2", "copied");
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
var MovePathOperation = class {
|
|
561
|
+
/** Bind the Dropbox client. */
|
|
562
|
+
constructor(client) {
|
|
563
|
+
this.client = client;
|
|
564
|
+
if (!client) throw new TypeError("Dropbox client is required");
|
|
565
|
+
}
|
|
566
|
+
client;
|
|
567
|
+
/** Return the generated move contract. */
|
|
568
|
+
definition() {
|
|
569
|
+
return MovePathDefinition;
|
|
570
|
+
}
|
|
571
|
+
/** Use the stable call ID for dispatch and receipts. */
|
|
572
|
+
idempotencyKey(callId) {
|
|
573
|
+
return callId;
|
|
574
|
+
}
|
|
575
|
+
/** Move or rename without autorenaming the destination. */
|
|
576
|
+
invoke(call, input) {
|
|
577
|
+
return transferPath(this.client, call, input, this.definition(), "/2/files/move_v2", "moved");
|
|
578
|
+
}
|
|
579
|
+
};
|
|
580
|
+
function decodeSearchPage(body) {
|
|
581
|
+
const answer = objectBody(body);
|
|
582
|
+
const cursor = requiredString(answer, "cursor");
|
|
583
|
+
if (!Array.isArray(answer.matches) || typeof answer.has_more !== "boolean" || answer.has_more && !cursor)
|
|
584
|
+
throw new TypeError("Dropbox search page is incomplete");
|
|
585
|
+
const entries = answer.matches.map((match) => decodeEntry(match?.metadata?.metadata));
|
|
586
|
+
return { entries, hasMore: answer.has_more, ...cursor && { cursor } };
|
|
587
|
+
}
|
|
588
|
+
function absolutePath(path) {
|
|
589
|
+
return path.startsWith("/") && !path.endsWith("/") && validPath(path, false);
|
|
590
|
+
}
|
|
591
|
+
function fileBranch(operation, branch, empty, kind, message) {
|
|
592
|
+
return newMutationBranch(branch, empty, {}, failure(operation, kind, message));
|
|
593
|
+
}
|
|
594
|
+
function fileRetry(operation, kind, message, delay = 0) {
|
|
595
|
+
return newMutationRetry(failure(operation, kind, message), delay);
|
|
596
|
+
}
|
|
597
|
+
function definiteWriteRefusal(exchange) {
|
|
598
|
+
let summary;
|
|
599
|
+
try {
|
|
600
|
+
const answer = objectBody(exchange.body);
|
|
601
|
+
if ("metadata" in answer) return false;
|
|
602
|
+
summary = requiredString(answer, "error_summary");
|
|
603
|
+
} catch {
|
|
604
|
+
return false;
|
|
605
|
+
}
|
|
606
|
+
if (exchange.status === 409) return summary.startsWith("to/conflict/file/");
|
|
607
|
+
return !!summary && [400, 401, 403, 404, 411, 413, 414, 415, 422].includes(exchange.status);
|
|
608
|
+
}
|
|
609
|
+
function classifyFileWrite(operation, exchange, value, success, acceptedConflict, requiredKind = "") {
|
|
610
|
+
const { status, error, retryAfterMs } = exchange;
|
|
611
|
+
const zero = { path: "" };
|
|
612
|
+
if (error === "credential")
|
|
613
|
+
return fileBranch(operation, "defect", zero, "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
614
|
+
if (error === "refresh") return fileRetry(operation, "AVAILABILITY", "Dropbox credentials could not be refreshed");
|
|
615
|
+
if (error === "request") return fileRetry(operation, "TRANSPORT", "Dropbox request failed");
|
|
616
|
+
if (status === 429) return fileRetry(operation, "RATE_LIMIT", "Dropbox rate limited the request", retryAfterMs);
|
|
617
|
+
if (status === 408 || status >= 500) return fileRetry(operation, "AVAILABILITY", "Dropbox is temporarily unavailable", retryAfterMs);
|
|
618
|
+
if (status === 409 && errorSummary(exchange.body).startsWith(acceptedConflict)) return newMutationBranch(success, value);
|
|
619
|
+
if (status !== 200) return !error && definiteWriteRefusal(exchange) ? fileBranch(operation, "providerRejected", zero, "PROVIDER_REJECTION", `Dropbox rejected HTTP ${status}`) : fileRetry(operation, "AVAILABILITY", "Dropbox write outcome is unknown", retryAfterMs);
|
|
620
|
+
if (error === "tooLarge") return fileRetry(operation, "RESPONSE_TOO_LARGE", "Dropbox response exceeded the configured limit", retryAfterMs);
|
|
621
|
+
if (error) return fileRetry(operation, "TRANSPORT", "Dropbox response was interrupted");
|
|
622
|
+
try {
|
|
623
|
+
const entry = decodeEntry(objectBody(exchange.body).metadata);
|
|
624
|
+
if (requiredKind && entry.kind !== requiredKind) throw new TypeError("unexpected Dropbox entry kind");
|
|
625
|
+
return newMutationBranch(success, value);
|
|
626
|
+
} catch {
|
|
627
|
+
return fileRetry(operation, "PROTOCOL", "Dropbox returned invalid JSON", retryAfterMs);
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function samePath(left, right) {
|
|
631
|
+
const literal = left.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
632
|
+
return new RegExp("^" + literal + "(?![\\s\\S])", "iu").test(right);
|
|
633
|
+
}
|
|
634
|
+
async function transferPath(client, call, input, definition, endpoint, success) {
|
|
635
|
+
const operation = definition.operation.operationId;
|
|
636
|
+
const { fromPath, toPath } = input;
|
|
637
|
+
if (!validPath(fromPath, false) || fromPath.startsWith("rev:") || !absolutePath(toPath) || samePath(fromPath, toPath))
|
|
638
|
+
return fileBranch(operation, "defect", emptyEntryMetadata, "VALIDATION", "source or destination path is invalid");
|
|
639
|
+
const maxSends = call.maxSendsOverride ?? definitionMaxSends(definition);
|
|
640
|
+
let fence;
|
|
641
|
+
try {
|
|
642
|
+
fence = newFence(call, definition.stepDefaults.executeMethodTimeoutMs ?? 3e4, { maxSends });
|
|
643
|
+
} catch {
|
|
644
|
+
return fileBranch(operation, "defect", emptyEntryMetadata, "LOCAL_DEFECT", "transfer dispatch fence is unavailable");
|
|
645
|
+
}
|
|
646
|
+
const decision = fence.decide();
|
|
647
|
+
if (decision.kind === "failClosed") return fileRetry(operation, "AVAILABILITY", "transfer checkpoint cannot be trusted");
|
|
648
|
+
const prior = decision.priorSendUpperBound ?? 0;
|
|
649
|
+
if (prior || decision.kind !== "sendAllowed") {
|
|
650
|
+
const read = await client.postJSON(call, "/2/files/get_metadata", { path: toPath });
|
|
651
|
+
const outcome = transferReadBack(operation, success, read, decision);
|
|
652
|
+
if (outcome) return outcome;
|
|
653
|
+
}
|
|
654
|
+
const send = client.postJSON.bind(client, call, endpoint, { from_path: fromPath, to_path: toPath, autorename: false });
|
|
655
|
+
let exchange;
|
|
656
|
+
try {
|
|
657
|
+
exchange = await fence.dispatch(send);
|
|
658
|
+
} catch (error) {
|
|
659
|
+
if (error instanceof CheckpointError || error instanceof InsufficientTimeError || error instanceof DispatchNotAllowedError || error instanceof AggregateError && error.errors.some((cause) => cause instanceof InsufficientTimeError))
|
|
660
|
+
return fileRetry(operation, "AVAILABILITY", "transfer was not dispatched");
|
|
661
|
+
throw error;
|
|
662
|
+
}
|
|
663
|
+
return classifyTransfer(fence, operation, success, toPath, exchange, prior, maxSends);
|
|
664
|
+
}
|
|
665
|
+
function transferReadBack(operation, success, response, decision) {
|
|
666
|
+
const requiresConfirmation = decision.kind === "readBackRequired";
|
|
667
|
+
if (!response.error && response.status === 200) {
|
|
668
|
+
try {
|
|
669
|
+
const entry = decodeEntry(objectBody(response.body));
|
|
670
|
+
if (decision.marker?.providerId === entry.id) return newMutationBranch(success, entry);
|
|
671
|
+
if (requiresConfirmation) return transferUncertain(operation, "destination exists but cannot be attributed to this call");
|
|
672
|
+
return void 0;
|
|
673
|
+
} catch {
|
|
674
|
+
return fileRetry(operation, "AVAILABILITY", "destination read-back is unavailable", response.retryAfterMs);
|
|
675
|
+
}
|
|
676
|
+
}
|
|
677
|
+
if (!response.error && response.status === 409 && errorSummary(response.body).startsWith("path/not_found"))
|
|
678
|
+
return requiresConfirmation ? transferUncertain(operation, "send cap reached and destination is absent") : void 0;
|
|
679
|
+
return fileRetry(operation, "AVAILABILITY", "destination read-back is unavailable", response.retryAfterMs);
|
|
680
|
+
}
|
|
681
|
+
async function classifyTransfer(fence, operation, success, destination, exchange, prior, maxSends) {
|
|
682
|
+
const { error, status, retryAfterMs } = exchange;
|
|
683
|
+
if (error === "credential") {
|
|
684
|
+
if (prior) return fileRetry(operation, "AVAILABILITY", "earlier transfer may have succeeded");
|
|
685
|
+
await recordResend(fence);
|
|
686
|
+
return fileBranch(operation, "defect", emptyEntryMetadata, "AUTHENTICATION", "connection credentials are unavailable or invalid");
|
|
687
|
+
}
|
|
688
|
+
if (error === "refresh") {
|
|
689
|
+
await recordResend(fence);
|
|
690
|
+
return fileRetry(operation, "AVAILABILITY", "Dropbox credentials could not be refreshed");
|
|
691
|
+
}
|
|
692
|
+
if (error === "request") return fileRetry(operation, "TRANSPORT", "Dropbox transfer request failed");
|
|
693
|
+
if (status === 429 || status === 503) {
|
|
694
|
+
if (!await recordResend(fence)) return fileRetry(operation, "AVAILABILITY", "transfer retry checkpoint is unavailable");
|
|
695
|
+
return fileRetry(operation, status === 429 ? "RATE_LIMIT" : "AVAILABILITY", "Dropbox did not process the transfer", retryAfterMs);
|
|
696
|
+
}
|
|
697
|
+
if (status === 408 || status >= 500)
|
|
698
|
+
return fileRetry(operation, "AVAILABILITY", "Dropbox transfer outcome is unknown", retryAfterMs);
|
|
699
|
+
if (status !== 200) {
|
|
700
|
+
if (error || prior || !definiteWriteRefusal(exchange)) {
|
|
701
|
+
return prior + 1 >= maxSends ? transferUncertain(operation, "transfer outcome cannot be confirmed") : fileRetry(operation, "AVAILABILITY", "transfer outcome is unknown", retryAfterMs);
|
|
702
|
+
}
|
|
703
|
+
if (!await recordResend(fence)) return fileRetry(operation, "AVAILABILITY", "refusal checkpoint unavailable");
|
|
704
|
+
return fileBranch(operation, "providerRejected", emptyEntryMetadata, "PROVIDER_REJECTION", `Dropbox rejected transfer with HTTP ${status}`);
|
|
705
|
+
}
|
|
706
|
+
if (error) return fileRetry(operation, "TRANSPORT", "Dropbox transfer response was interrupted");
|
|
707
|
+
let entry;
|
|
708
|
+
try {
|
|
709
|
+
entry = decodeEntry(objectBody(exchange.body).metadata);
|
|
710
|
+
if (!samePath(entry.pathDisplay, destination)) throw new TypeError("unexpected destination");
|
|
711
|
+
} catch {
|
|
712
|
+
return fileRetry(operation, "PROTOCOL", "Dropbox transfer identity was invalid");
|
|
713
|
+
}
|
|
714
|
+
try {
|
|
715
|
+
await fence.recordProviderId(entry.id);
|
|
716
|
+
} catch (checkpointError) {
|
|
717
|
+
if (!(checkpointError instanceof CheckpointError)) throw checkpointError;
|
|
718
|
+
}
|
|
719
|
+
return newMutationBranch(success, entry);
|
|
720
|
+
}
|
|
721
|
+
async function recordResend(fence) {
|
|
722
|
+
try {
|
|
723
|
+
await fence.recordCanResend();
|
|
724
|
+
} catch (error) {
|
|
725
|
+
if (error instanceof CheckpointError) return false;
|
|
726
|
+
throw error;
|
|
727
|
+
}
|
|
728
|
+
return true;
|
|
729
|
+
}
|
|
730
|
+
function transferUncertain(operation, message) {
|
|
731
|
+
return newMutationUncertain(emptyEntryMetadata, failure(operation, "AVAILABILITY", message));
|
|
732
|
+
}
|
|
388
733
|
|
|
389
734
|
// src/client.ts
|
|
390
735
|
var DropboxClient = class {
|
|
@@ -444,12 +789,32 @@ var DropboxClient = class {
|
|
|
444
789
|
uploadFile() {
|
|
445
790
|
return new UploadFileOperation(this);
|
|
446
791
|
}
|
|
792
|
+
/** Bind the searchFiles operation. */
|
|
793
|
+
searchFiles() {
|
|
794
|
+
return new SearchFilesOperation(this);
|
|
795
|
+
}
|
|
796
|
+
/** Bind the ensureFolder operation. */
|
|
797
|
+
ensureFolder() {
|
|
798
|
+
return new EnsureFolderOperation(this);
|
|
799
|
+
}
|
|
800
|
+
/** Bind the deletePath operation. */
|
|
801
|
+
deletePath() {
|
|
802
|
+
return new DeletePathOperation(this);
|
|
803
|
+
}
|
|
804
|
+
/** Bind the copyPath operation. */
|
|
805
|
+
copyPath() {
|
|
806
|
+
return new CopyPathOperation(this);
|
|
807
|
+
}
|
|
808
|
+
/** Bind the movePath operation. */
|
|
809
|
+
movePath() {
|
|
810
|
+
return new MovePathOperation(this);
|
|
811
|
+
}
|
|
447
812
|
/** Post one JSON request to the Dropbox RPC API. */
|
|
448
|
-
postJSON(call, path, payload) {
|
|
813
|
+
postJSON(call, path, payload, signal = call.context.cancellationSignal) {
|
|
449
814
|
return this.post(call, this.baseURL + path, Buffer.from(JSON.stringify(payload)), {
|
|
450
815
|
Accept: "application/json",
|
|
451
816
|
"Content-Type": "application/json"
|
|
452
|
-
}, this.maxResponseBytes);
|
|
817
|
+
}, this.maxResponseBytes, false, signal);
|
|
453
818
|
}
|
|
454
819
|
/** Download one file using Dropbox's content endpoint. */
|
|
455
820
|
download(call, path) {
|
|
@@ -464,21 +829,15 @@ var DropboxClient = class {
|
|
|
464
829
|
"Content-Type": "application/octet-stream"
|
|
465
830
|
}, this.maxResponseBytes);
|
|
466
831
|
}
|
|
467
|
-
async post(call, url, body, headers, successLimit, isDownload = false) {
|
|
468
|
-
let
|
|
832
|
+
async post(call, url, body, headers, successLimit, isDownload = false, signal = call.context.cancellationSignal) {
|
|
833
|
+
let credentials;
|
|
469
834
|
try {
|
|
470
|
-
|
|
471
|
-
if (!(credentials.accessToken instanceof SecretString)) return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: "credential" };
|
|
472
|
-
token = credentials.accessToken.reveal();
|
|
835
|
+
credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
|
|
473
836
|
} catch (error) {
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
body: new Uint8Array(),
|
|
477
|
-
metadata: "",
|
|
478
|
-
retryAfterMs: 0,
|
|
479
|
-
error: error instanceof ReauthorizationRequiredError ? "credential" : "refresh"
|
|
480
|
-
};
|
|
837
|
+
const isTerminal = error instanceof ReauthorizationRequiredError || error instanceof ObjectNotFoundError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || isCredentialMaterialError(error);
|
|
838
|
+
return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: isTerminal ? "credential" : "refresh" };
|
|
481
839
|
}
|
|
840
|
+
const token = credentials.accessToken instanceof SecretString ? credentials.accessToken.reveal() : "";
|
|
482
841
|
if (!token || !isHeaderSafeCredential(token)) return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: "credential" };
|
|
483
842
|
const endpoint = new URL(url);
|
|
484
843
|
const request = {
|
|
@@ -492,7 +851,7 @@ var DropboxClient = class {
|
|
|
492
851
|
maxResponseBytes: Math.max(successLimit, this.maxResponseBytes),
|
|
493
852
|
addressPolicy: endpoint.protocol === "http:" ? "privateNetworkHTTP" : "publicHTTPS",
|
|
494
853
|
timeoutMs: this.timeoutMs,
|
|
495
|
-
signal
|
|
854
|
+
signal,
|
|
496
855
|
...body === void 0 ? {} : { body }
|
|
497
856
|
};
|
|
498
857
|
let response;
|
|
@@ -510,6 +869,15 @@ var DropboxClient = class {
|
|
|
510
869
|
error: "tooLarge"
|
|
511
870
|
};
|
|
512
871
|
}
|
|
872
|
+
if (error instanceof ProviderTransportError && error.status !== void 0) {
|
|
873
|
+
return {
|
|
874
|
+
status: error.status,
|
|
875
|
+
body: new Uint8Array(),
|
|
876
|
+
metadata: "",
|
|
877
|
+
retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now()),
|
|
878
|
+
error: "read"
|
|
879
|
+
};
|
|
880
|
+
}
|
|
513
881
|
return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: "request" };
|
|
514
882
|
}
|
|
515
883
|
const metadata = isDownload ? header(response.headers, "dropbox-api-result") : "";
|
|
@@ -596,7 +964,7 @@ function newDownloadFileStep(configuration) {
|
|
|
596
964
|
] });
|
|
597
965
|
}
|
|
598
966
|
function newUploadFileStep(configuration) {
|
|
599
|
-
const { connection, connectionName, uploaded, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
967
|
+
const { connection, connectionName, uploaded, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
600
968
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
601
969
|
return newMutationStep({ ...stepConfiguration, operation: connection.operations.uploadFile(), connection: connection.reference, branches: [
|
|
602
970
|
goToBranch("uploaded", uploaded),
|
|
@@ -605,6 +973,56 @@ function newUploadFileStep(configuration) {
|
|
|
605
973
|
...defect ? [goToBranch("defect", defect)] : []
|
|
606
974
|
] });
|
|
607
975
|
}
|
|
976
|
+
function newSearchFilesStep(configuration) {
|
|
977
|
+
const { connection, connectionName, found, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
978
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
979
|
+
return newQueryStep({ ...stepConfiguration, operation: connection.operations.searchFiles(), connection: connection.reference, branches: [
|
|
980
|
+
goToBranch("found", found),
|
|
981
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
982
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
983
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
984
|
+
] });
|
|
985
|
+
}
|
|
986
|
+
function newEnsureFolderStep(configuration) {
|
|
987
|
+
const { connection, connectionName, ensured, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
988
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
989
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.ensureFolder(), connection: connection.reference, branches: [
|
|
990
|
+
goToBranch("ensured", ensured),
|
|
991
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
992
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
993
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
994
|
+
] });
|
|
995
|
+
}
|
|
996
|
+
function newDeletePathStep(configuration) {
|
|
997
|
+
const { connection, connectionName, deleted, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
998
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
999
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.deletePath(), connection: connection.reference, branches: [
|
|
1000
|
+
goToBranch("deleted", deleted),
|
|
1001
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1002
|
+
...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
|
|
1003
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1004
|
+
] });
|
|
1005
|
+
}
|
|
1006
|
+
function newCopyPathStep(configuration) {
|
|
1007
|
+
const { connection, connectionName, copied, providerRejected, uncertain, defect, ...stepConfiguration } = configuration;
|
|
1008
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1009
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.copyPath(), connection: connection.reference, branches: [
|
|
1010
|
+
goToBranch("copied", copied),
|
|
1011
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1012
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : [],
|
|
1013
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1014
|
+
] });
|
|
1015
|
+
}
|
|
1016
|
+
function newMovePathStep(configuration) {
|
|
1017
|
+
const { connection, connectionName, moved, providerRejected, uncertain, defect, ...stepConfiguration } = configuration;
|
|
1018
|
+
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
1019
|
+
return newMutationStep({ ...stepConfiguration, operation: connection.operations.movePath(), connection: connection.reference, branches: [
|
|
1020
|
+
goToBranch("moved", moved),
|
|
1021
|
+
...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
|
|
1022
|
+
...uncertain ? [goToBranch("uncertain", uncertain)] : [],
|
|
1023
|
+
...defect ? [goToBranch("defect", defect)] : []
|
|
1024
|
+
] });
|
|
1025
|
+
}
|
|
608
1026
|
export {
|
|
609
1027
|
ConfigSchema,
|
|
610
1028
|
Connection,
|
|
@@ -619,6 +1037,25 @@ export {
|
|
|
619
1037
|
ContinueFolderInputSchema,
|
|
620
1038
|
ContinueFolderMetadata,
|
|
621
1039
|
ContinueFolderOperation,
|
|
1040
|
+
CopyPathBranch,
|
|
1041
|
+
CopyPathBranchCopied,
|
|
1042
|
+
CopyPathBranchDefect,
|
|
1043
|
+
CopyPathBranchProviderRejected,
|
|
1044
|
+
CopyPathBranchUncertain,
|
|
1045
|
+
CopyPathDefinition,
|
|
1046
|
+
CopyPathMetadata,
|
|
1047
|
+
CopyPathOperation,
|
|
1048
|
+
CredentialMaterialError,
|
|
1049
|
+
DeletePathBranch,
|
|
1050
|
+
DeletePathBranchDefect,
|
|
1051
|
+
DeletePathBranchDeleted,
|
|
1052
|
+
DeletePathBranchInvalidResponse,
|
|
1053
|
+
DeletePathBranchProviderRejected,
|
|
1054
|
+
DeletePathDefinition,
|
|
1055
|
+
DeletePathInputSchema,
|
|
1056
|
+
DeletePathMetadata,
|
|
1057
|
+
DeletePathOperation,
|
|
1058
|
+
DeletedPathSchema,
|
|
622
1059
|
DownloadFileBranch,
|
|
623
1060
|
DownloadFileBranchDefect,
|
|
624
1061
|
DownloadFileBranchDownloaded,
|
|
@@ -632,6 +1069,16 @@ export {
|
|
|
632
1069
|
DownloadFileOperation,
|
|
633
1070
|
DownloadedFileSchema,
|
|
634
1071
|
DropboxClient,
|
|
1072
|
+
EnsureFolderBranch,
|
|
1073
|
+
EnsureFolderBranchDefect,
|
|
1074
|
+
EnsureFolderBranchEnsured,
|
|
1075
|
+
EnsureFolderBranchInvalidResponse,
|
|
1076
|
+
EnsureFolderBranchProviderRejected,
|
|
1077
|
+
EnsureFolderDefinition,
|
|
1078
|
+
EnsureFolderInputSchema,
|
|
1079
|
+
EnsureFolderMetadata,
|
|
1080
|
+
EnsureFolderOperation,
|
|
1081
|
+
EnsuredFolderSchema,
|
|
635
1082
|
EntryMetadataSchema,
|
|
636
1083
|
FolderPageSchema,
|
|
637
1084
|
GetMetadataBranch,
|
|
@@ -654,7 +1101,26 @@ export {
|
|
|
654
1101
|
ListFolderInputSchema,
|
|
655
1102
|
ListFolderMetadata,
|
|
656
1103
|
ListFolderOperation,
|
|
1104
|
+
MovePathBranch,
|
|
1105
|
+
MovePathBranchDefect,
|
|
1106
|
+
MovePathBranchMoved,
|
|
1107
|
+
MovePathBranchProviderRejected,
|
|
1108
|
+
MovePathBranchUncertain,
|
|
1109
|
+
MovePathDefinition,
|
|
1110
|
+
MovePathMetadata,
|
|
1111
|
+
MovePathOperation,
|
|
657
1112
|
ProviderID,
|
|
1113
|
+
SearchFilesBranch,
|
|
1114
|
+
SearchFilesBranchDefect,
|
|
1115
|
+
SearchFilesBranchFound,
|
|
1116
|
+
SearchFilesBranchInvalidResponse,
|
|
1117
|
+
SearchFilesBranchProviderRejected,
|
|
1118
|
+
SearchFilesDefinition,
|
|
1119
|
+
SearchFilesInputSchema,
|
|
1120
|
+
SearchFilesMetadata,
|
|
1121
|
+
SearchFilesOperation,
|
|
1122
|
+
SearchFilesPageSchema,
|
|
1123
|
+
TransferPathInputSchema,
|
|
658
1124
|
UploadFileBranch,
|
|
659
1125
|
UploadFileBranchDefect,
|
|
660
1126
|
UploadFileBranchInvalidResponse,
|
|
@@ -668,12 +1134,18 @@ export {
|
|
|
668
1134
|
decodeCredentials,
|
|
669
1135
|
decodeSharedCredentials,
|
|
670
1136
|
header,
|
|
1137
|
+
isCredentialMaterialError,
|
|
671
1138
|
newConnection,
|
|
672
1139
|
newConnectionWithOperations,
|
|
673
1140
|
newContinueFolderStep,
|
|
1141
|
+
newCopyPathStep,
|
|
1142
|
+
newDeletePathStep,
|
|
674
1143
|
newDownloadFileStep,
|
|
1144
|
+
newEnsureFolderStep,
|
|
675
1145
|
newGetMetadataStep,
|
|
676
1146
|
newListFolderStep,
|
|
1147
|
+
newMovePathStep,
|
|
677
1148
|
newProjectConnection,
|
|
1149
|
+
newSearchFilesStep,
|
|
678
1150
|
newUploadFileStep
|
|
679
1151
|
};
|