@superdurable/connector-box 0.0.0-stage → 0.1.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 ADDED
@@ -0,0 +1,528 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ DownloadFileBranch,
6
+ DownloadFileBranchDefect,
7
+ DownloadFileBranchDownloaded,
8
+ DownloadFileBranchInvalidResponse,
9
+ DownloadFileBranchNotFound,
10
+ DownloadFileBranchProviderRejected,
11
+ DownloadFileBranchTooLarge,
12
+ DownloadFileDefinition,
13
+ DownloadFileInputSchema,
14
+ DownloadFileMetadata,
15
+ DownloadedFileSchema,
16
+ ProviderID,
17
+ UploadFileBranch,
18
+ UploadFileBranchDefect,
19
+ UploadFileBranchInvalidResponse,
20
+ UploadFileBranchNotFound,
21
+ UploadFileBranchProviderRejected,
22
+ UploadFileBranchUploaded,
23
+ UploadFileDefinition,
24
+ UploadFileInputSchema,
25
+ UploadFileMetadata,
26
+ UploadedFileSchema,
27
+ decodeCredentials,
28
+ decodeSharedCredentials,
29
+ emptyDownloadedFile,
30
+ emptyUploadedFile,
31
+ newConnection,
32
+ newConnectionWithOperations,
33
+ newProjectCredentialProvider
34
+ } from "./chunk-F5T3YIDN.js";
35
+
36
+ // src/client.ts
37
+ import { randomBytes } from "crypto";
38
+ import {
39
+ ReauthorizationRequiredError,
40
+ SecretString,
41
+ resolveCredential
42
+ } from "@superdurable/connectors-sdk";
43
+ import { ManifestCredentialRefreshDriver } from "@superdurable/connectors-sdk/oauthtoken";
44
+ import {
45
+ BodyTooLargeError,
46
+ ProviderTransportError,
47
+ isHeaderSafeCredential,
48
+ parseRetryAfter,
49
+ sendProviderRequest,
50
+ validateBaseURL
51
+ } from "@superdurable/connectors-sdk/providerhttp";
52
+
53
+ // src/generated/refresh.ts
54
+ var Authorization = {
55
+ "fields": [
56
+ {
57
+ "name": "oauth_client_id",
58
+ "required": true,
59
+ "type": "string"
60
+ },
61
+ {
62
+ "name": "oauth_client_secret",
63
+ "required": true,
64
+ "type": "secretString"
65
+ },
66
+ {
67
+ "name": "access_token",
68
+ "required": true,
69
+ "type": "secretString"
70
+ },
71
+ {
72
+ "name": "refresh_token",
73
+ "required": true,
74
+ "type": "secretString"
75
+ }
76
+ ],
77
+ "oauth2": {
78
+ "clientIDCredential": "oauth_client_id",
79
+ "clientSecretCredential": "oauth_client_secret",
80
+ "credentialMappings": [
81
+ {
82
+ "credential": "access_token",
83
+ "source": "access_token"
84
+ },
85
+ {
86
+ "credential": "refresh_token",
87
+ "source": "refresh_token"
88
+ }
89
+ ],
90
+ "refresh": {
91
+ "missingExpiry": "reject",
92
+ "requiredScopes": [
93
+ "root_readwrite"
94
+ ],
95
+ "scopeSeparators": "whitespaceAndComma",
96
+ "storedMissingExpiry": "refresh",
97
+ "terminalErrorCodes": [
98
+ "invalid_grant",
99
+ "invalid_client",
100
+ "unauthorized_client"
101
+ ],
102
+ "tokenExchangeTimeout": "15s"
103
+ },
104
+ "scopes": [
105
+ "root_readwrite"
106
+ ],
107
+ "tokenEndpoint": "https://api.box.com/oauth2/token",
108
+ "tokenEndpointAuthMethod": "client_secret_post"
109
+ },
110
+ "refreshable": true,
111
+ "type": "oauth2"
112
+ };
113
+ var CredentialFields = {
114
+ "access_token": "accessToken",
115
+ "oauth_client_id": "oauthClientId",
116
+ "oauth_client_secret": "oauthClientSecret",
117
+ "refresh_token": "refreshToken"
118
+ };
119
+
120
+ // src/operations.ts
121
+ import { createHash } from "crypto";
122
+ import {
123
+ newMutationBranch,
124
+ newMutationRetry,
125
+ newQueryBranch,
126
+ newQueryRetry
127
+ } from "@superdurable/connectors-sdk";
128
+ function failure(operation, kind, message) {
129
+ return { kind, provider: "box", operation, message };
130
+ }
131
+ function downloadBranch(branch, kind, message) {
132
+ return newQueryBranch(branch, emptyDownloadedFile, {}, failure("downloadFile", kind, message));
133
+ }
134
+ function downloadRetry(kind, message, delay = 0) {
135
+ return newQueryRetry(failure("downloadFile", kind, message), delay);
136
+ }
137
+ function uploadBranch(branch, kind, message) {
138
+ return newMutationBranch(branch, emptyUploadedFile, {}, failure("uploadFile", kind, message));
139
+ }
140
+ function uploadRetry(kind, message, delay = 0) {
141
+ return newMutationRetry(failure("uploadFile", kind, message), delay);
142
+ }
143
+ function validFileID(value) {
144
+ return /^[0-9]{1,40}$/.test(value);
145
+ }
146
+ function decodeMetadata(body, fileID) {
147
+ const value = JSON.parse(Buffer.from(body).toString("utf8"));
148
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("Box file metadata is not an object");
149
+ const record = value;
150
+ const { id, type, name, sha1, size } = record;
151
+ if (id !== fileID || type !== "file" || typeof name !== "string" || !name || typeof sha1 !== "string" || !/^[0-9a-fA-F]{40}$/.test(sha1) || typeof size !== "number" || !Number.isSafeInteger(size) || size < 0)
152
+ throw new TypeError("Box file metadata is incomplete");
153
+ return { fileID, kind: type, name, sha1, size };
154
+ }
155
+ function matches(metadata, fileID, digest, size) {
156
+ return metadata.fileID === fileID && metadata.kind === "file" && !!metadata.name && metadata.sha1.toUpperCase() === digest && metadata.size === size;
157
+ }
158
+ function uploaded(metadata) {
159
+ return newMutationBranch("uploaded", { fileId: metadata.fileID, name: metadata.name, sha1: metadata.sha1.toUpperCase() });
160
+ }
161
+ var DownloadFileOperation = class {
162
+ /** Bind the provider client. */
163
+ constructor(client) {
164
+ this.client = client;
165
+ if (!client) throw new TypeError("Box client is required");
166
+ }
167
+ client;
168
+ /** Return stable manifest metadata. */
169
+ definition() {
170
+ return DownloadFileDefinition;
171
+ }
172
+ /** Download bytes, classify provider responses, and encode bounded content. */
173
+ async invoke(call, input) {
174
+ input = DownloadFileInputSchema.parse(input);
175
+ if (!validFileID(input.fileId)) return downloadBranch("defect", "VALIDATION", "Box file ID must contain only decimal digits");
176
+ const exchange = await this.client.download(call, input.fileId);
177
+ if (exchange.error === "credential") return downloadBranch("defect", "AUTHENTICATION", "Box credentials are unavailable or invalid");
178
+ if (exchange.error === "refresh") return downloadRetry("AVAILABILITY", "Box credentials could not be refreshed");
179
+ if (exchange.error === "request") return downloadRetry("TRANSPORT", "Box download request failed");
180
+ if (exchange.status === 429) return downloadRetry("RATE_LIMIT", "Box rate limited the download", exchange.retryAfterMs);
181
+ if (exchange.status === 408 || exchange.status >= 500) return downloadRetry("AVAILABILITY", "Box download is temporarily unavailable", exchange.retryAfterMs);
182
+ if (exchange.status === 202) return downloadRetry("AVAILABILITY", "Box file is not ready for download", exchange.retryAfterMs);
183
+ if (exchange.error === "invalidRedirect") return downloadBranch("invalidResponse", "PROTOCOL", "Box returned an unsafe download redirect");
184
+ if (exchange.status !== 200 && exchange.error === "tooLarge")
185
+ return downloadBranch("invalidResponse", "RESPONSE_TOO_LARGE", "Box error response exceeds the configured limit");
186
+ if (exchange.status === 404) return downloadBranch("notFound", "NOT_FOUND", "Box did not find the file");
187
+ if (exchange.status !== 200) return downloadBranch("providerRejected", "PROVIDER_REJECTION", `Box rejected HTTP ${exchange.status}`);
188
+ if (exchange.error === "tooLarge") return downloadBranch("tooLarge", "RESPONSE_TOO_LARGE", "Box file exceeds the configured download limit");
189
+ if (exchange.error) return downloadRetry("TRANSPORT", "Box download response was interrupted");
190
+ return newQueryBranch("downloaded", { fileId: input.fileId, contentBase64: Buffer.from(exchange.body).toString("base64"), contentBytes: exchange.body.length });
191
+ }
192
+ };
193
+ var UploadFileOperation = class {
194
+ /** Bind the provider client. */
195
+ constructor(client) {
196
+ this.client = client;
197
+ if (!client) throw new TypeError("Box client is required");
198
+ }
199
+ client;
200
+ /** Return stable manifest metadata. */
201
+ definition() {
202
+ return UploadFileDefinition;
203
+ }
204
+ /** Record stable call identity; Box receives no request key. */
205
+ idempotencyKey(callID, _input) {
206
+ void _input;
207
+ return callID;
208
+ }
209
+ /** Compare current content, replace once, and read back ambiguous outcomes. */
210
+ async invoke(call, input) {
211
+ input = UploadFileInputSchema.parse(input);
212
+ if (!validFileID(input.fileId)) return uploadBranch("defect", "VALIDATION", "Box file ID must contain only decimal digits");
213
+ if (Math.ceil(input.contentBase64.length / 4) * 3 > this.client.maxUploadBytes)
214
+ return uploadBranch("defect", "VALIDATION", "Box upload exceeds the configured byte limit");
215
+ const content = Buffer.from(input.contentBase64, "base64");
216
+ if (content.toString("base64") !== input.contentBase64 || content.length > this.client.maxUploadBytes)
217
+ return uploadBranch("defect", "VALIDATION", "Box upload content must be bounded Base64");
218
+ const digest = createHash("sha1").update(content).digest("hex").toUpperCase();
219
+ const first = await this.client.getFileMetadata(call, input.fileId);
220
+ const initial = initialMetadata(first, input.fileId);
221
+ if ("decision" in initial) return initial.decision;
222
+ const metadata = initial.metadata;
223
+ if (matches(metadata, input.fileId, digest, content.length)) return uploaded(metadata);
224
+ const exchange = await this.client.upload(call, input.fileId, metadata.name, content);
225
+ if (exchange.error === "credential" && !exchange.requestSent)
226
+ return uploadBranch("defect", "AUTHENTICATION", "Box credentials are unavailable or invalid");
227
+ if (exchange.error === "refresh") return uploadRetry("AVAILABILITY", "Box credentials could not be refreshed");
228
+ if (exchange.error === "request" && !exchange.requestSent)
229
+ return uploadRetry("TRANSPORT", "Box upload did not leave the process");
230
+ if (exchange.status === 429) return uploadRetry("RATE_LIMIT", "Box rate limited the upload", exchange.retryAfterMs);
231
+ if (exchange.status === 408 || exchange.status >= 500)
232
+ return uploadRetry("AVAILABILITY", "Box upload is temporarily unavailable", exchange.retryAfterMs);
233
+ if (exchange.status === 404) return uploadBranch("notFound", "NOT_FOUND", "Box did not find the file");
234
+ const isAccepted = exchange.status === 200 || exchange.status === 201;
235
+ if (exchange.status !== 0 && !isAccepted)
236
+ return uploadBranch("providerRejected", "PROVIDER_REJECTION", `Box rejected HTTP ${exchange.status}`);
237
+ if (isAccepted && !exchange.error) {
238
+ try {
239
+ const wire = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
240
+ if (wire && typeof wire === "object" && "entries" in wire && Array.isArray(wire.entries) && wire.entries.length === 1) {
241
+ const returned = decodeMetadata(Buffer.from(JSON.stringify(wire.entries[0])), input.fileId);
242
+ if (matches(returned, input.fileId, digest, content.length)) return uploaded(returned);
243
+ }
244
+ } catch {
245
+ }
246
+ }
247
+ const readback = await this.client.getFileMetadata(call, input.fileId);
248
+ if (readback.status === 200 && !readback.error) {
249
+ try {
250
+ const confirmed = decodeMetadata(readback.body, input.fileId);
251
+ if (matches(confirmed, input.fileId, digest, content.length)) return uploaded(confirmed);
252
+ } catch {
253
+ }
254
+ }
255
+ return uploadRetry("TRANSPORT", "Box replacement could not be confirmed by read-back", readback.retryAfterMs);
256
+ }
257
+ };
258
+ function initialMetadata(exchange, fileID) {
259
+ if (exchange.error === "credential") return { decision: uploadBranch("defect", "AUTHENTICATION", "Box credentials are unavailable or invalid") };
260
+ if (exchange.error === "refresh") return { decision: uploadRetry("AVAILABILITY", "Box credentials could not be refreshed") };
261
+ if (exchange.error === "request") return { decision: uploadRetry("TRANSPORT", "Box metadata request failed") };
262
+ if (exchange.status === 429) return { decision: uploadRetry("RATE_LIMIT", "Box rate limited metadata lookup", exchange.retryAfterMs) };
263
+ if (exchange.status === 408 || exchange.status >= 500)
264
+ return { decision: uploadRetry("AVAILABILITY", "Box metadata is temporarily unavailable", exchange.retryAfterMs) };
265
+ if (exchange.status === 404) return { decision: uploadBranch("notFound", "NOT_FOUND", "Box did not find the file") };
266
+ if (exchange.status !== 200)
267
+ return { decision: uploadBranch("providerRejected", "PROVIDER_REJECTION", `Box rejected HTTP ${exchange.status}`) };
268
+ if (exchange.error === "tooLarge")
269
+ return { decision: uploadBranch("invalidResponse", "RESPONSE_TOO_LARGE", "Box metadata exceeds the configured limit") };
270
+ if (exchange.error) return { decision: uploadRetry("TRANSPORT", "Box metadata response was interrupted") };
271
+ try {
272
+ return { metadata: decodeMetadata(exchange.body, fileID) };
273
+ } catch {
274
+ return { decision: uploadBranch("invalidResponse", "PROTOCOL", "Box returned invalid file metadata") };
275
+ }
276
+ }
277
+
278
+ // src/client.ts
279
+ var BoxClient = class {
280
+ /** Validated API endpoint. */
281
+ baseURL;
282
+ /** Validated upload endpoint. */
283
+ uploadBaseURL;
284
+ /** Timeout for one request. */
285
+ timeoutMs;
286
+ /** Error and metadata response limit. */
287
+ maxResponseBytes;
288
+ /** Download content limit. */
289
+ maxDownloadBytes;
290
+ /** Replacement content limit. */
291
+ maxUploadBytes;
292
+ credentials;
293
+ refreshDriver;
294
+ send;
295
+ now;
296
+ /** Validate configuration and inject dependencies without network access. */
297
+ constructor(config, credentials, options = {}) {
298
+ if (!config || !credentials) throw new TypeError("Box configuration and credentials are required");
299
+ this.baseURL = validateBaseURL(config.baseUrl || "https://api.box.com");
300
+ this.uploadBaseURL = validateBaseURL(config.uploadBaseUrl || "https://upload.box.com/api");
301
+ this.timeoutMs = config.timeoutMs || 15e3;
302
+ this.maxResponseBytes = config.maxResponseBytes || 2097152;
303
+ this.maxDownloadBytes = config.maxDownloadBytes || 1048576;
304
+ this.maxUploadBytes = config.maxUploadBytes || 1048576;
305
+ if (![this.timeoutMs, this.maxResponseBytes, this.maxDownloadBytes, this.maxUploadBytes].every((value) => Number.isSafeInteger(value) && value > 0)) throw new TypeError("Box request limits must be positive integers");
306
+ if (this.maxUploadBytes > 50 * 1024 * 1024) throw new TypeError("Box direct upload limit exceeds 50 MiB");
307
+ this.credentials = credentials;
308
+ this.refreshDriver = options.refreshDriver ?? new ManifestCredentialRefreshDriver({
309
+ providerName: "Box",
310
+ auth: Authorization,
311
+ credentialFields: CredentialFields
312
+ });
313
+ this.send = options.send ?? sendProviderRequest;
314
+ this.now = options.now ?? (() => /* @__PURE__ */ new Date());
315
+ }
316
+ /** Bind the bounded download Query. */
317
+ downloadFile() {
318
+ return new DownloadFileOperation(this);
319
+ }
320
+ /** Bind the bounded replacement Mutation. */
321
+ uploadFile() {
322
+ return new UploadFileOperation(this);
323
+ }
324
+ /** Download one file, following only Box's signed HTTPS content URL. */
325
+ async download(call, fileID) {
326
+ const token = await this.resolveToken(call);
327
+ if (typeof token !== "string") return token;
328
+ const first = await this.request(
329
+ call,
330
+ "GET",
331
+ this.baseURL + `/2.0/files/${fileID}/content`,
332
+ { Authorization: "Bearer " + token },
333
+ this.maxDownloadBytes,
334
+ token
335
+ );
336
+ if (first.status !== 302 || first.error) return first;
337
+ const location = first.location ?? "";
338
+ if (!isBoxDownloadURL(location)) return { ...first, body: new Uint8Array(), error: "invalidRedirect" };
339
+ const second = await this.request(call, "GET", location, {}, this.maxDownloadBytes, token);
340
+ if (second.status === 302 && !second.error) return { ...second, body: new Uint8Array(), error: "invalidRedirect" };
341
+ return second;
342
+ }
343
+ /** Read one file's current identity and digest. */
344
+ async getFileMetadata(call, fileID) {
345
+ const token = await this.resolveToken(call);
346
+ if (typeof token !== "string") return token;
347
+ return this.request(
348
+ call,
349
+ "GET",
350
+ this.baseURL + `/2.0/files/${fileID}?fields=id,type,name,sha1,size`,
351
+ { Authorization: "Bearer " + token, Accept: "application/json" },
352
+ this.maxResponseBytes,
353
+ token
354
+ );
355
+ }
356
+ /** Replace current content with Box's attributes-first multipart request. */
357
+ async upload(call, fileID, name, content) {
358
+ const token = await this.resolveToken(call);
359
+ if (typeof token !== "string") return token;
360
+ const boundary = "dexbox" + randomBytes(12).toString("hex");
361
+ const escapedName = name.replace(/\\/g, "\\\\").replace(/"/g, '\\"').replace(/[\r\n]/g, "_");
362
+ const body = Buffer.concat([
363
+ Buffer.from(`--${boundary}\r
364
+ Content-Disposition: form-data; name="attributes"\r
365
+ \r
366
+ ${JSON.stringify({ name })}\r
367
+ `),
368
+ Buffer.from(`--${boundary}\r
369
+ Content-Disposition: form-data; name="file"; filename="${escapedName}"\r
370
+ Content-Type: application/octet-stream\r
371
+ \r
372
+ `),
373
+ Buffer.from(content),
374
+ Buffer.from(`\r
375
+ --${boundary}--\r
376
+ `)
377
+ ]);
378
+ return this.request(call, "POST", this.uploadBaseURL + `/2.0/files/${fileID}/content`, {
379
+ Authorization: "Bearer " + token,
380
+ Accept: "application/json",
381
+ "Content-Type": `multipart/form-data; boundary=${boundary}`
382
+ }, this.maxResponseBytes, token, body);
383
+ }
384
+ async resolveToken(call) {
385
+ let token;
386
+ try {
387
+ const credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
388
+ if (!(credentials.accessToken instanceof SecretString)) return emptyExchange("credential");
389
+ token = credentials.accessToken.reveal();
390
+ } catch (error) {
391
+ return emptyExchange(error instanceof ReauthorizationRequiredError ? "credential" : "refresh");
392
+ }
393
+ return token && isHeaderSafeCredential(token) ? token : emptyExchange("credential");
394
+ }
395
+ async request(call, method, url, headers, successLimit, token, body) {
396
+ const request = {
397
+ url,
398
+ method,
399
+ headers: { ...headers, "User-Agent": "Dex Connector (https://superdurable.io)" },
400
+ maxResponseBytes: Math.max(successLimit, this.maxResponseBytes),
401
+ addressPolicy: new URL(url).protocol === "http:" ? "privateNetworkHTTP" : "publicHTTPS",
402
+ timeoutMs: this.timeoutMs,
403
+ signal: call.context.cancellationSignal,
404
+ ...body === void 0 ? {} : { body }
405
+ };
406
+ let response;
407
+ try {
408
+ response = await this.send(request);
409
+ } catch (error) {
410
+ if (error instanceof BodyTooLargeError) return {
411
+ ...emptyExchange("tooLarge"),
412
+ status: error.status ?? 0,
413
+ requestSent: true,
414
+ retryAfterMs: parseRetryAfter(header(error.headers ?? {}, "retry-after"), this.now())
415
+ };
416
+ if (error instanceof ProviderTransportError) return {
417
+ ...emptyExchange("request"),
418
+ requestSent: !error.isProvablyNotSent
419
+ };
420
+ return emptyExchange("request");
421
+ }
422
+ const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
423
+ const location = response.status === 302 ? header(response.headers, "location") : "";
424
+ if (location.includes(token) || Buffer.from(response.body).includes(token))
425
+ return { status: response.status, body: new Uint8Array(), retryAfterMs, requestSent: true, error: "credential" };
426
+ const limit = response.status === 200 ? successLimit : this.maxResponseBytes;
427
+ if (response.body.length > limit) return { status: response.status, body: new Uint8Array(), retryAfterMs, requestSent: true, error: "tooLarge" };
428
+ return { status: response.status, body: response.body, retryAfterMs, requestSent: true, ...location ? { location } : {} };
429
+ }
430
+ };
431
+ function emptyExchange(error) {
432
+ return { status: 0, body: new Uint8Array(), retryAfterMs: 0, requestSent: false, error };
433
+ }
434
+ function isBoxDownloadURL(value) {
435
+ if (!value || value.length > 8192) return false;
436
+ try {
437
+ const url = new URL(value);
438
+ return url.protocol === "https:" && url.hostname.endsWith(".boxcloud.com") && !url.username && !url.password && !url.port && !url.hash && !!url.pathname;
439
+ } catch {
440
+ return false;
441
+ }
442
+ }
443
+ function header(headers, name) {
444
+ const entry = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
445
+ return Array.isArray(entry) ? entry[0] ?? "" : entry ?? "";
446
+ }
447
+
448
+ // src/project.ts
449
+ function encodeCredentials(credentials) {
450
+ return {
451
+ oauth_client_id: credentials.oauthClientId,
452
+ oauth_client_secret: credentials.oauthClientSecret.reveal(),
453
+ access_token: credentials.accessToken.reveal(),
454
+ refresh_token: credentials.refreshToken.reveal()
455
+ };
456
+ }
457
+ function newProjectConnection(project, connectionName, options = {}) {
458
+ if (!project) throw new TypeError("Box project is required");
459
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === "box" && entry.connectionName === connectionName);
460
+ if (!selected || selected.provider !== "box") throw new TypeError("Box project connection is not configured");
461
+ const config = ConfigSchema.parse(selected.configuration);
462
+ const provider = newProjectCredentialProvider(project, connectionName, decodeCredentials, encodeCredentials, decodeSharedCredentials);
463
+ return newConnection(new BoxClient(config, provider, options), { provider: "box", name: connectionName });
464
+ }
465
+
466
+ // src/generated/steps.ts
467
+ import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
468
+ function newDownloadFileStep(configuration) {
469
+ const { connection, connectionName, downloaded, notFound, tooLarge, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
470
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
471
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.downloadFile(), connection: connection.reference, branches: [
472
+ goToBranch("downloaded", downloaded),
473
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
474
+ ...tooLarge ? [goToBranch("tooLarge", tooLarge)] : [],
475
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
476
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
477
+ ...defect ? [goToBranch("defect", defect)] : []
478
+ ] });
479
+ }
480
+ function newUploadFileStep(configuration) {
481
+ const { connection, connectionName, uploaded: uploaded2, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
482
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
483
+ return newMutationStep({ ...stepConfiguration, operation: connection.operations.uploadFile(), connection: connection.reference, branches: [
484
+ goToBranch("uploaded", uploaded2),
485
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
486
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
487
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
488
+ ...defect ? [goToBranch("defect", defect)] : []
489
+ ] });
490
+ }
491
+ export {
492
+ BoxClient,
493
+ ConfigSchema,
494
+ Connection,
495
+ ConnectorID,
496
+ DownloadFileBranch,
497
+ DownloadFileBranchDefect,
498
+ DownloadFileBranchDownloaded,
499
+ DownloadFileBranchInvalidResponse,
500
+ DownloadFileBranchNotFound,
501
+ DownloadFileBranchProviderRejected,
502
+ DownloadFileBranchTooLarge,
503
+ DownloadFileDefinition,
504
+ DownloadFileInputSchema,
505
+ DownloadFileMetadata,
506
+ DownloadFileOperation,
507
+ DownloadedFileSchema,
508
+ ProviderID,
509
+ UploadFileBranch,
510
+ UploadFileBranchDefect,
511
+ UploadFileBranchInvalidResponse,
512
+ UploadFileBranchNotFound,
513
+ UploadFileBranchProviderRejected,
514
+ UploadFileBranchUploaded,
515
+ UploadFileDefinition,
516
+ UploadFileInputSchema,
517
+ UploadFileMetadata,
518
+ UploadFileOperation,
519
+ UploadedFileSchema,
520
+ decodeCredentials,
521
+ decodeSharedCredentials,
522
+ header,
523
+ newConnection,
524
+ newConnectionWithOperations,
525
+ newDownloadFileStep,
526
+ newProjectConnection,
527
+ newUploadFileStep
528
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,58 @@
1
+ import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
2
+ import { Failure } from '@superdurable/connectors-sdk';
3
+ import { O as Operations, d as Connection, D as DownloadFileInput, a as DownloadedFile, U as UploadFileInput, b as UploadedFile } from './connection-BzNkxQQZ.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for DownloadFileInput in scripted cases. */
7
+ declare const emptyDownloadFileInput: DownloadFileInput;
8
+ /** Go zero value for DownloadedFile in scripted cases. */
9
+ declare const emptyDownloadedFile: DownloadedFile;
10
+ /** Go zero value for UploadFileInput in scripted cases. */
11
+ declare const emptyUploadFileInput: UploadFileInput;
12
+ /** Go zero value for UploadedFile in scripted cases. */
13
+ declare const emptyUploadedFile: UploadedFile;
14
+ /** Script the downloaded branch. */
15
+ declare function downloadFileDownloaded(value: DownloadedFile, failure?: Failure): Case<DownloadedFile>;
16
+ /** Script the notFound branch. */
17
+ declare function downloadFileNotFound(value: DownloadedFile, failure?: Failure): Case<DownloadedFile>;
18
+ /** Script the tooLarge branch. */
19
+ declare function downloadFileTooLarge(value: DownloadedFile, failure?: Failure): Case<DownloadedFile>;
20
+ /** Script the providerRejected branch. */
21
+ declare function downloadFileProviderRejected(value: DownloadedFile, failure?: Failure): Case<DownloadedFile>;
22
+ /** Script the invalidResponse branch. */
23
+ declare function downloadFileInvalidResponse(value: DownloadedFile, failure?: Failure): Case<DownloadedFile>;
24
+ /** Script the defect branch. */
25
+ declare function downloadFileDefect(value: DownloadedFile, failure?: Failure): Case<DownloadedFile>;
26
+ /** Script a safe retry of downloadFile. */
27
+ declare function downloadFileRetry(failure: Failure, retryAfterMs?: number): Case<DownloadedFile>;
28
+ /** Manifest scenario downloadedDefault for downloadFile. */
29
+ declare function downloadFileDownloadedDefault(): Case<DownloadedFile>;
30
+ /** Default downloadFile scenario. */
31
+ declare function downloadFileDefault(): Case<DownloadedFile>;
32
+ /** Script the uploaded branch. */
33
+ declare function uploadFileUploaded(value: UploadedFile, failure?: Failure): Case<UploadedFile>;
34
+ /** Script the notFound branch. */
35
+ declare function uploadFileNotFound(value: UploadedFile, failure?: Failure): Case<UploadedFile>;
36
+ /** Script the providerRejected branch. */
37
+ declare function uploadFileProviderRejected(value: UploadedFile, failure?: Failure): Case<UploadedFile>;
38
+ /** Script the invalidResponse branch. */
39
+ declare function uploadFileInvalidResponse(value: UploadedFile, failure?: Failure): Case<UploadedFile>;
40
+ /** Script the defect branch. */
41
+ declare function uploadFileDefect(value: UploadedFile, failure?: Failure): Case<UploadedFile>;
42
+ /** Script a safe retry of uploadFile. */
43
+ declare function uploadFileRetry(failure: Failure, retryAfterMs?: number): Case<UploadedFile>;
44
+ /** Manifest scenario uploadedDefault for uploadFile. */
45
+ declare function uploadFileUploadedDefault(): Case<UploadedFile>;
46
+ /** Default uploadFile scenario. */
47
+ declare function uploadFileDefault(): Case<UploadedFile>;
48
+ /** Scripted operations and manifest defaults for this connector. */
49
+ declare class GeneratedMock implements Operations {
50
+ #private;
51
+ constructor(connectionName: string);
52
+ connection(): Connection;
53
+ downloadFile(): MockQuery<DownloadFileInput, DownloadedFile>;
54
+ uploadFile(): MockMutation<UploadFileInput, UploadedFile>;
55
+ assertNoFailures(): void;
56
+ }
57
+
58
+ export { GeneratedMock, downloadFileDefault, downloadFileDefect, downloadFileDownloaded, downloadFileDownloadedDefault, downloadFileInvalidResponse, downloadFileNotFound, downloadFileProviderRejected, downloadFileRetry, downloadFileTooLarge, emptyDownloadFileInput, emptyDownloadedFile, emptyUploadFileInput, emptyUploadedFile, uploadFileDefault, uploadFileDefect, uploadFileInvalidResponse, uploadFileNotFound, uploadFileProviderRejected, uploadFileRetry, uploadFileUploaded, uploadFileUploadedDefault };
package/dist/mock.js ADDED
@@ -0,0 +1,48 @@
1
+ import {
2
+ GeneratedMock,
3
+ downloadFileDefault,
4
+ downloadFileDefect,
5
+ downloadFileDownloaded,
6
+ downloadFileDownloadedDefault,
7
+ downloadFileInvalidResponse,
8
+ downloadFileNotFound,
9
+ downloadFileProviderRejected,
10
+ downloadFileRetry,
11
+ downloadFileTooLarge,
12
+ emptyDownloadFileInput,
13
+ emptyDownloadedFile,
14
+ emptyUploadFileInput,
15
+ emptyUploadedFile,
16
+ uploadFileDefault,
17
+ uploadFileDefect,
18
+ uploadFileInvalidResponse,
19
+ uploadFileNotFound,
20
+ uploadFileProviderRejected,
21
+ uploadFileRetry,
22
+ uploadFileUploaded,
23
+ uploadFileUploadedDefault
24
+ } from "./chunk-F5T3YIDN.js";
25
+ export {
26
+ GeneratedMock,
27
+ downloadFileDefault,
28
+ downloadFileDefect,
29
+ downloadFileDownloaded,
30
+ downloadFileDownloadedDefault,
31
+ downloadFileInvalidResponse,
32
+ downloadFileNotFound,
33
+ downloadFileProviderRejected,
34
+ downloadFileRetry,
35
+ downloadFileTooLarge,
36
+ emptyDownloadFileInput,
37
+ emptyDownloadedFile,
38
+ emptyUploadFileInput,
39
+ emptyUploadedFile,
40
+ uploadFileDefault,
41
+ uploadFileDefect,
42
+ uploadFileInvalidResponse,
43
+ uploadFileNotFound,
44
+ uploadFileProviderRejected,
45
+ uploadFileRetry,
46
+ uploadFileUploaded,
47
+ uploadFileUploadedDefault
48
+ };