@superdurable/connector-dropbox 0.2.1 → 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-HC4YIUZK.js → chunk-RMQLFGNQ.js} +387 -2
- package/dist/{connection-DtKKxEuC.d.ts → connection-Csm3tCeA.d.ts} +94 -1
- package/dist/index.d.ts +270 -5
- package/dist/index.js +460 -6
- package/dist/mock.d.ts +91 -2
- package/dist/mock.js +85 -1
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -11,7 +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,
|
|
14
21
|
CredentialMaterialError,
|
|
22
|
+
DeletePathBranch,
|
|
23
|
+
DeletePathBranchDefect,
|
|
24
|
+
DeletePathBranchDeleted,
|
|
25
|
+
DeletePathBranchInvalidResponse,
|
|
26
|
+
DeletePathBranchProviderRejected,
|
|
27
|
+
DeletePathDefinition,
|
|
28
|
+
DeletePathInputSchema,
|
|
29
|
+
DeletePathMetadata,
|
|
30
|
+
DeletedPathSchema,
|
|
15
31
|
DownloadFileBranch,
|
|
16
32
|
DownloadFileBranchDefect,
|
|
17
33
|
DownloadFileBranchDownloaded,
|
|
@@ -23,6 +39,15 @@ import {
|
|
|
23
39
|
DownloadFileInputSchema,
|
|
24
40
|
DownloadFileMetadata,
|
|
25
41
|
DownloadedFileSchema,
|
|
42
|
+
EnsureFolderBranch,
|
|
43
|
+
EnsureFolderBranchDefect,
|
|
44
|
+
EnsureFolderBranchEnsured,
|
|
45
|
+
EnsureFolderBranchInvalidResponse,
|
|
46
|
+
EnsureFolderBranchProviderRejected,
|
|
47
|
+
EnsureFolderDefinition,
|
|
48
|
+
EnsureFolderInputSchema,
|
|
49
|
+
EnsureFolderMetadata,
|
|
50
|
+
EnsuredFolderSchema,
|
|
26
51
|
EntryMetadataSchema,
|
|
27
52
|
FolderPageSchema,
|
|
28
53
|
GetMetadataBranch,
|
|
@@ -43,7 +68,24 @@ import {
|
|
|
43
68
|
ListFolderDefinition,
|
|
44
69
|
ListFolderInputSchema,
|
|
45
70
|
ListFolderMetadata,
|
|
71
|
+
MovePathBranch,
|
|
72
|
+
MovePathBranchDefect,
|
|
73
|
+
MovePathBranchMoved,
|
|
74
|
+
MovePathBranchProviderRejected,
|
|
75
|
+
MovePathBranchUncertain,
|
|
76
|
+
MovePathDefinition,
|
|
77
|
+
MovePathMetadata,
|
|
46
78
|
ProviderID,
|
|
79
|
+
SearchFilesBranch,
|
|
80
|
+
SearchFilesBranchDefect,
|
|
81
|
+
SearchFilesBranchFound,
|
|
82
|
+
SearchFilesBranchInvalidResponse,
|
|
83
|
+
SearchFilesBranchProviderRejected,
|
|
84
|
+
SearchFilesDefinition,
|
|
85
|
+
SearchFilesInputSchema,
|
|
86
|
+
SearchFilesMetadata,
|
|
87
|
+
SearchFilesPageSchema,
|
|
88
|
+
TransferPathInputSchema,
|
|
47
89
|
UploadFileBranch,
|
|
48
90
|
UploadFileBranchDefect,
|
|
49
91
|
UploadFileBranchInvalidResponse,
|
|
@@ -63,7 +105,7 @@ import {
|
|
|
63
105
|
newConnection,
|
|
64
106
|
newConnectionWithOperations,
|
|
65
107
|
newProjectCredentialProvider
|
|
66
|
-
} from "./chunk-
|
|
108
|
+
} from "./chunk-RMQLFGNQ.js";
|
|
67
109
|
|
|
68
110
|
// src/client.ts
|
|
69
111
|
import {
|
|
@@ -77,6 +119,7 @@ import {
|
|
|
77
119
|
BodyTooLargeError,
|
|
78
120
|
isHeaderSafeCredential,
|
|
79
121
|
parseRetryAfter,
|
|
122
|
+
ProviderTransportError,
|
|
80
123
|
sendProviderRequest,
|
|
81
124
|
validateBaseURL
|
|
82
125
|
} from "@superdurable/connectors-sdk/providerhttp";
|
|
@@ -154,11 +197,19 @@ var CredentialFields = {
|
|
|
154
197
|
|
|
155
198
|
// src/operations.ts
|
|
156
199
|
import {
|
|
200
|
+
definitionMaxSends,
|
|
157
201
|
newMutationBranch,
|
|
158
202
|
newMutationRetry,
|
|
203
|
+
newMutationUncertain,
|
|
159
204
|
newQueryBranch,
|
|
160
205
|
newQueryRetry
|
|
161
206
|
} from "@superdurable/connectors-sdk";
|
|
207
|
+
import {
|
|
208
|
+
CheckpointError,
|
|
209
|
+
DispatchNotAllowedError,
|
|
210
|
+
InsufficientTimeError,
|
|
211
|
+
newFence
|
|
212
|
+
} from "@superdurable/connectors-sdk/singledispatch";
|
|
162
213
|
function failure(operation, kind, message) {
|
|
163
214
|
return { kind, provider: "dropbox", operation, message };
|
|
164
215
|
}
|
|
@@ -407,6 +458,278 @@ function isDefiniteUploadRefusal(exchange) {
|
|
|
407
458
|
if (definiteRefusalStatuses.has(exchange.status)) return true;
|
|
408
459
|
return exchange.status === 409 && typeof fields?.error_summary === "string" && fields.error_summary !== "";
|
|
409
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);
|
|
487
|
+
}
|
|
488
|
+
}
|
|
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
|
+
}
|
|
410
733
|
|
|
411
734
|
// src/client.ts
|
|
412
735
|
var DropboxClient = class {
|
|
@@ -466,12 +789,32 @@ var DropboxClient = class {
|
|
|
466
789
|
uploadFile() {
|
|
467
790
|
return new UploadFileOperation(this);
|
|
468
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
|
+
}
|
|
469
812
|
/** Post one JSON request to the Dropbox RPC API. */
|
|
470
|
-
postJSON(call, path, payload) {
|
|
813
|
+
postJSON(call, path, payload, signal = call.context.cancellationSignal) {
|
|
471
814
|
return this.post(call, this.baseURL + path, Buffer.from(JSON.stringify(payload)), {
|
|
472
815
|
Accept: "application/json",
|
|
473
816
|
"Content-Type": "application/json"
|
|
474
|
-
}, this.maxResponseBytes);
|
|
817
|
+
}, this.maxResponseBytes, false, signal);
|
|
475
818
|
}
|
|
476
819
|
/** Download one file using Dropbox's content endpoint. */
|
|
477
820
|
download(call, path) {
|
|
@@ -486,7 +829,7 @@ var DropboxClient = class {
|
|
|
486
829
|
"Content-Type": "application/octet-stream"
|
|
487
830
|
}, this.maxResponseBytes);
|
|
488
831
|
}
|
|
489
|
-
async post(call, url, body, headers, successLimit, isDownload = false) {
|
|
832
|
+
async post(call, url, body, headers, successLimit, isDownload = false, signal = call.context.cancellationSignal) {
|
|
490
833
|
let credentials;
|
|
491
834
|
try {
|
|
492
835
|
credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
|
|
@@ -508,7 +851,7 @@ var DropboxClient = class {
|
|
|
508
851
|
maxResponseBytes: Math.max(successLimit, this.maxResponseBytes),
|
|
509
852
|
addressPolicy: endpoint.protocol === "http:" ? "privateNetworkHTTP" : "publicHTTPS",
|
|
510
853
|
timeoutMs: this.timeoutMs,
|
|
511
|
-
signal
|
|
854
|
+
signal,
|
|
512
855
|
...body === void 0 ? {} : { body }
|
|
513
856
|
};
|
|
514
857
|
let response;
|
|
@@ -526,6 +869,15 @@ var DropboxClient = class {
|
|
|
526
869
|
error: "tooLarge"
|
|
527
870
|
};
|
|
528
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
|
+
}
|
|
529
881
|
return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: "request" };
|
|
530
882
|
}
|
|
531
883
|
const metadata = isDownload ? header(response.headers, "dropbox-api-result") : "";
|
|
@@ -612,7 +964,7 @@ function newDownloadFileStep(configuration) {
|
|
|
612
964
|
] });
|
|
613
965
|
}
|
|
614
966
|
function newUploadFileStep(configuration) {
|
|
615
|
-
const { connection, connectionName, uploaded, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
|
|
967
|
+
const { connection, connectionName, uploaded, providerRejected, invalidResponse, defect, maxSends, ...stepConfiguration } = configuration;
|
|
616
968
|
if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
|
|
617
969
|
return newMutationStep({ ...stepConfiguration, operation: connection.operations.uploadFile(), connection: connection.reference, branches: [
|
|
618
970
|
goToBranch("uploaded", uploaded),
|
|
@@ -621,6 +973,56 @@ function newUploadFileStep(configuration) {
|
|
|
621
973
|
...defect ? [goToBranch("defect", defect)] : []
|
|
622
974
|
] });
|
|
623
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
|
+
}
|
|
624
1026
|
export {
|
|
625
1027
|
ConfigSchema,
|
|
626
1028
|
Connection,
|
|
@@ -635,7 +1037,25 @@ export {
|
|
|
635
1037
|
ContinueFolderInputSchema,
|
|
636
1038
|
ContinueFolderMetadata,
|
|
637
1039
|
ContinueFolderOperation,
|
|
1040
|
+
CopyPathBranch,
|
|
1041
|
+
CopyPathBranchCopied,
|
|
1042
|
+
CopyPathBranchDefect,
|
|
1043
|
+
CopyPathBranchProviderRejected,
|
|
1044
|
+
CopyPathBranchUncertain,
|
|
1045
|
+
CopyPathDefinition,
|
|
1046
|
+
CopyPathMetadata,
|
|
1047
|
+
CopyPathOperation,
|
|
638
1048
|
CredentialMaterialError,
|
|
1049
|
+
DeletePathBranch,
|
|
1050
|
+
DeletePathBranchDefect,
|
|
1051
|
+
DeletePathBranchDeleted,
|
|
1052
|
+
DeletePathBranchInvalidResponse,
|
|
1053
|
+
DeletePathBranchProviderRejected,
|
|
1054
|
+
DeletePathDefinition,
|
|
1055
|
+
DeletePathInputSchema,
|
|
1056
|
+
DeletePathMetadata,
|
|
1057
|
+
DeletePathOperation,
|
|
1058
|
+
DeletedPathSchema,
|
|
639
1059
|
DownloadFileBranch,
|
|
640
1060
|
DownloadFileBranchDefect,
|
|
641
1061
|
DownloadFileBranchDownloaded,
|
|
@@ -649,6 +1069,16 @@ export {
|
|
|
649
1069
|
DownloadFileOperation,
|
|
650
1070
|
DownloadedFileSchema,
|
|
651
1071
|
DropboxClient,
|
|
1072
|
+
EnsureFolderBranch,
|
|
1073
|
+
EnsureFolderBranchDefect,
|
|
1074
|
+
EnsureFolderBranchEnsured,
|
|
1075
|
+
EnsureFolderBranchInvalidResponse,
|
|
1076
|
+
EnsureFolderBranchProviderRejected,
|
|
1077
|
+
EnsureFolderDefinition,
|
|
1078
|
+
EnsureFolderInputSchema,
|
|
1079
|
+
EnsureFolderMetadata,
|
|
1080
|
+
EnsureFolderOperation,
|
|
1081
|
+
EnsuredFolderSchema,
|
|
652
1082
|
EntryMetadataSchema,
|
|
653
1083
|
FolderPageSchema,
|
|
654
1084
|
GetMetadataBranch,
|
|
@@ -671,7 +1101,26 @@ export {
|
|
|
671
1101
|
ListFolderInputSchema,
|
|
672
1102
|
ListFolderMetadata,
|
|
673
1103
|
ListFolderOperation,
|
|
1104
|
+
MovePathBranch,
|
|
1105
|
+
MovePathBranchDefect,
|
|
1106
|
+
MovePathBranchMoved,
|
|
1107
|
+
MovePathBranchProviderRejected,
|
|
1108
|
+
MovePathBranchUncertain,
|
|
1109
|
+
MovePathDefinition,
|
|
1110
|
+
MovePathMetadata,
|
|
1111
|
+
MovePathOperation,
|
|
674
1112
|
ProviderID,
|
|
1113
|
+
SearchFilesBranch,
|
|
1114
|
+
SearchFilesBranchDefect,
|
|
1115
|
+
SearchFilesBranchFound,
|
|
1116
|
+
SearchFilesBranchInvalidResponse,
|
|
1117
|
+
SearchFilesBranchProviderRejected,
|
|
1118
|
+
SearchFilesDefinition,
|
|
1119
|
+
SearchFilesInputSchema,
|
|
1120
|
+
SearchFilesMetadata,
|
|
1121
|
+
SearchFilesOperation,
|
|
1122
|
+
SearchFilesPageSchema,
|
|
1123
|
+
TransferPathInputSchema,
|
|
675
1124
|
UploadFileBranch,
|
|
676
1125
|
UploadFileBranchDefect,
|
|
677
1126
|
UploadFileBranchInvalidResponse,
|
|
@@ -689,9 +1138,14 @@ export {
|
|
|
689
1138
|
newConnection,
|
|
690
1139
|
newConnectionWithOperations,
|
|
691
1140
|
newContinueFolderStep,
|
|
1141
|
+
newCopyPathStep,
|
|
1142
|
+
newDeletePathStep,
|
|
692
1143
|
newDownloadFileStep,
|
|
1144
|
+
newEnsureFolderStep,
|
|
693
1145
|
newGetMetadataStep,
|
|
694
1146
|
newListFolderStep,
|
|
1147
|
+
newMovePathStep,
|
|
695
1148
|
newProjectConnection,
|
|
1149
|
+
newSearchFilesStep,
|
|
696
1150
|
newUploadFileStep
|
|
697
1151
|
};
|