@superdurable/connector-box 0.1.1 → 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/dist/index.js CHANGED
@@ -1,8 +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,
5
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,
6
63
  DownloadFileBranch,
7
64
  DownloadFileBranchDefect,
8
65
  DownloadFileBranchDownloaded,
@@ -14,7 +71,87 @@ import {
14
71
  DownloadFileInputSchema,
15
72
  DownloadFileMetadata,
16
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,
17
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,
18
155
  UploadFileBranch,
19
156
  UploadFileBranchDefect,
20
157
  UploadFileBranchInvalidResponse,
@@ -27,13 +164,17 @@ import {
27
164
  UploadedFileSchema,
28
165
  decodeCredentials,
29
166
  decodeSharedCredentials,
167
+ decodeSignedInteger,
30
168
  emptyDownloadedFile,
31
169
  emptyUploadedFile,
170
+ exactIntegerJSONCodec,
32
171
  isCredentialMaterialError,
33
172
  newConnection,
34
173
  newConnectionWithOperations,
35
- newProjectCredentialProvider
36
- } from "./chunk-C3MMWLYU.js";
174
+ newProjectCredentialProvider,
175
+ parseExactIntegerJSON,
176
+ parseJSONNumberTokens
177
+ } from "./chunk-7RYWT7W3.js";
37
178
 
38
179
  // src/client.ts
39
180
  import { randomBytes } from "crypto";
@@ -297,6 +438,578 @@ function refusal(status) {
297
438
  return uploadBranch("providerRejected", "PROVIDER_REJECTION", `Box rejected HTTP ${status}`);
298
439
  }
299
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
+ }
1012
+
300
1013
  // src/client.ts
301
1014
  var BoxClient = class {
302
1015
  /** Validated API endpoint. */
@@ -343,6 +1056,66 @@ var BoxClient = class {
343
1056
  uploadFile() {
344
1057
  return new UploadFileOperation(this);
345
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
+ }
346
1119
  /** Download one file, following only Box's signed HTTPS content URL. */
347
1120
  async download(call, fileID) {
348
1121
  const token = await this.resolveToken(call);
@@ -379,30 +1152,36 @@ var BoxClient = class {
379
1152
  async upload(call, fileID, name, content) {
380
1153
  const token = await this.resolveToken(call);
381
1154
  if (typeof token !== "string") return token;
382
- const boundary = "dexbox" + randomBytes(12).toString("hex");
383
- const escapedName = name.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/[\r\n]/g, "_");
384
- const body = Buffer.concat([
385
- Buffer.from(`--${boundary}\r
386
- Content-Disposition: form-data; name="attributes"\r
387
- \r
388
- ${JSON.stringify({ name })}\r
389
- `),
390
- Buffer.from(`--${boundary}\r
391
- Content-Disposition: form-data; name="file"; filename="${escapedName}"\r
392
- Content-Type: application/octet-stream\r
393
- \r
394
- `),
395
- Buffer.from(content),
396
- Buffer.from(`\r
397
- --${boundary}--\r
398
- `)
399
- ]);
1155
+ const { body, contentType } = encodeBoxMultipart({ name }, name, content);
400
1156
  return this.request(call, "POST", this.uploadBaseURL + `/2.0/files/${fileID}/content`, {
401
1157
  Authorization: "Bearer " + token,
402
1158
  Accept: "application/json",
403
- "Content-Type": `multipart/form-data; boundary=${boundary}`
1159
+ "Content-Type": contentType
404
1160
  }, this.maxResponseBytes, token, body);
405
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
+ }
406
1185
  async resolveToken(call) {
407
1186
  let credentials;
408
1187
  try {
@@ -414,7 +1193,7 @@ Content-Type: application/octet-stream\r
414
1193
  const token = credentials.accessToken instanceof SecretString ? credentials.accessToken.reveal() : "";
415
1194
  return token && isHeaderSafeCredential(token) ? token : emptyExchange("credential");
416
1195
  }
417
- 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) {
418
1197
  const request = {
419
1198
  url,
420
1199
  method,
@@ -422,7 +1201,7 @@ Content-Type: application/octet-stream\r
422
1201
  maxResponseBytes: Math.max(successLimit, this.maxResponseBytes),
423
1202
  addressPolicy: new URL(url).protocol === "http:" ? "privateNetworkHTTP" : "publicHTTPS",
424
1203
  timeoutMs: this.timeoutMs,
425
- signal: call.context.cancellationSignal,
1204
+ signal,
426
1205
  ...body === void 0 ? {} : { body }
427
1206
  };
428
1207
  let response;
@@ -435,6 +1214,12 @@ Content-Type: application/octet-stream\r
435
1214
  requestSent: true,
436
1215
  retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
437
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
+ };
438
1223
  if (error instanceof ProviderTransportError) return {
439
1224
  ...emptyExchange("request"),
440
1225
  requestSent: !error.isProvablyNotSent
@@ -442,7 +1227,7 @@ Content-Type: application/octet-stream\r
442
1227
  return emptyExchange("request");
443
1228
  }
444
1229
  const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
445
- const location = response.status === 302 ? header(response.headers, "location") : "";
1230
+ const location = captureRedirect && response.status === 302 ? header(response.headers, "location") : "";
446
1231
  if (location.includes(token) || Buffer.from(response.body).includes(token))
447
1232
  return { status: response.status, body: new Uint8Array(), retryAfterMs, requestSent: true, error: "credential" };
448
1233
  const limit = response.status === 200 ? successLimit : this.maxResponseBytes;
@@ -450,6 +1235,27 @@ Content-Type: application/octet-stream\r
450
1235
  return { status: response.status, body: response.body, retryAfterMs, requestSent: true, ...location ? { location } : {} };
451
1236
  }
452
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
+ }
453
1259
  function emptyExchange(error) {
454
1260
  return { status: 0, body: new Uint8Array(), retryAfterMs: 0, requestSent: false, error };
455
1261
  }
@@ -487,12 +1293,96 @@ function newProjectConnection(project, connectionName, options = {}) {
487
1293
 
488
1294
  // src/generated/steps.ts
489
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
+ }
490
1380
  function newDownloadFileStep(configuration) {
491
- const { connection, connectionName, downloaded, notFound, tooLarge, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
1381
+ const { connection, connectionName, downloaded, notFound: notFound2, tooLarge, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
492
1382
  if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
493
1383
  return newQueryStep({ ...stepConfiguration, operation: connection.operations.downloadFile(), connection: connection.reference, branches: [
494
1384
  goToBranch("downloaded", downloaded),
495
- ...notFound ? [goToBranch("notFound", notFound)] : [],
1385
+ ...notFound2 ? [goToBranch("notFound", notFound2)] : [],
496
1386
  ...tooLarge ? [goToBranch("tooLarge", tooLarge)] : [],
497
1387
  ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
498
1388
  ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
@@ -500,11 +1390,86 @@ function newDownloadFileStep(configuration) {
500
1390
  ] });
501
1391
  }
502
1392
  function newUploadFileStep(configuration) {
503
- 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;
504
1394
  if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
505
1395
  return newMutationStep({ ...stepConfiguration, operation: connection.operations.uploadFile(), connection: connection.reference, branches: [
506
1396
  goToBranch("uploaded", uploaded2),
507
- ...notFound ? [goToBranch("notFound", notFound)] : [],
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)] : [],
508
1473
  ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
509
1474
  ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
510
1475
  ...defect ? [goToBranch("defect", defect)] : []
@@ -512,10 +1477,73 @@ function newUploadFileStep(configuration) {
512
1477
  }
513
1478
  export {
514
1479
  BoxClient,
1480
+ BoxFileSchema,
1481
+ BoxFolderSchema,
1482
+ BoxItemPageSchema,
1483
+ BoxItemSchema,
515
1484
  ConfigSchema,
516
1485
  Connection,
517
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,
518
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,
519
1547
  DownloadFileBranch,
520
1548
  DownloadFileBranchDefect,
521
1549
  DownloadFileBranchDownloaded,
@@ -528,7 +1556,96 @@ export {
528
1556
  DownloadFileMetadata,
529
1557
  DownloadFileOperation,
530
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,
531
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,
532
1649
  UploadFileBranch,
533
1650
  UploadFileBranchDefect,
534
1651
  UploadFileBranchInvalidResponse,
@@ -542,11 +1659,30 @@ export {
542
1659
  UploadedFileSchema,
543
1660
  decodeCredentials,
544
1661
  decodeSharedCredentials,
1662
+ decodeSignedInteger,
1663
+ exactIntegerJSONCodec,
545
1664
  header,
546
1665
  isCredentialMaterialError,
547
1666
  newConnection,
548
1667
  newConnectionWithOperations,
1668
+ newCopyFileStep,
1669
+ newCopyFolderStep,
1670
+ newCreateFileStep,
1671
+ newCreateFolderStep,
1672
+ newDeleteFileStep,
1673
+ newDeleteFolderStep,
549
1674
  newDownloadFileStep,
1675
+ newGetFileStep,
1676
+ newGetFolderStep,
1677
+ newListFolderItemsStep,
550
1678
  newProjectConnection,
551
- newUploadFileStep
1679
+ newSearchFilesStep,
1680
+ newSearchFoldersStep,
1681
+ newShareFileStep,
1682
+ newShareFolderStep,
1683
+ newUpdateFileStep,
1684
+ newUpdateFolderStep,
1685
+ newUploadFileStep,
1686
+ parseExactIntegerJSON,
1687
+ parseJSONNumberTokens
552
1688
  };