@superdurable/connector-dropbox 0.2.0 → 0.2.1

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.
@@ -1,10 +1,10 @@
1
1
  {
2
2
  "connectorId": "dropbox",
3
- "releaseTag": "connectors/dropbox/go/v0.2.0",
3
+ "releaseTag": "connectors/dropbox/go/v0.2.1",
4
4
  "package": {
5
5
  "ecosystem": "npm",
6
6
  "name": "@superdurable/connector-dropbox",
7
- "version": "0.2.0"
7
+ "version": "0.2.1"
8
8
  },
9
9
  "factories": [
10
10
  {
@@ -9,40 +9,54 @@ var ConfigSchema = z.object({
9
9
  "maxDownloadBytes": z.number().int().optional(),
10
10
  "maxUploadBytes": z.number().int().optional()
11
11
  });
12
+ var CredentialMaterialError = class extends TypeError {
13
+ constructor(message) {
14
+ super(message);
15
+ this.name = "CredentialMaterialError";
16
+ }
17
+ };
18
+ var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
19
+ "project credential decoding failed",
20
+ "shared project credential decoding failed",
21
+ "project credential decoding failed: this connector version does not support shared credentials"
22
+ ]);
23
+ function isCredentialMaterialError(error) {
24
+ return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
25
+ }
12
26
  function decodeCredentials(value) {
13
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
27
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
14
28
  const fields = value;
15
29
  const allowed = /* @__PURE__ */ new Set(["access_token", "oauth_client_id", "oauth_client_secret", "refresh_token"]);
16
- if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
17
- if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new TypeError("credential access_token has an invalid type");
18
- if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new TypeError("credential oauth_client_id has an invalid type");
19
- if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new TypeError("credential oauth_client_secret has an invalid type");
20
- if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new TypeError("credential refresh_token has an invalid type");
30
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
31
+ if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new CredentialMaterialError("credential access_token has an invalid type");
32
+ if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new CredentialMaterialError("credential oauth_client_id has an invalid type");
33
+ if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new CredentialMaterialError("credential oauth_client_secret has an invalid type");
34
+ if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new CredentialMaterialError("credential refresh_token has an invalid type");
21
35
  const credentials = {};
22
- if (!fields["oauth_client_id"]) throw new TypeError("credential oauth_client_id is required");
36
+ if (!fields["oauth_client_id"]) throw new CredentialMaterialError("credential oauth_client_id is required");
23
37
  credentials.oauthClientId = fields["oauth_client_id"] ?? "";
24
- if (!fields["oauth_client_secret"]) throw new TypeError("credential oauth_client_secret is required");
38
+ if (!fields["oauth_client_secret"]) throw new CredentialMaterialError("credential oauth_client_secret is required");
25
39
  credentials.oauthClientSecret = new SecretString(fields["oauth_client_secret"] ?? "");
26
- if (!fields["access_token"]) throw new TypeError("credential access_token is required");
40
+ if (!fields["access_token"]) throw new CredentialMaterialError("credential access_token is required");
27
41
  credentials.accessToken = new SecretString(fields["access_token"] ?? "");
28
- if (!fields["refresh_token"]) throw new TypeError("credential refresh_token is required");
42
+ if (!fields["refresh_token"]) throw new CredentialMaterialError("credential refresh_token is required");
29
43
  credentials.refreshToken = new SecretString(fields["refresh_token"] ?? "");
30
44
  return credentials;
31
45
  }
32
46
  function decodeSharedCredentials(value) {
33
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
47
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
34
48
  const fields = value;
35
49
  const allowed = /* @__PURE__ */ new Set(["access_token", "oauth_client_id", "oauth_client_secret", "refresh_token"]);
36
- if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
37
- if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new TypeError("credential access_token has an invalid type");
38
- if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new TypeError("credential oauth_client_id has an invalid type");
39
- if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new TypeError("credential oauth_client_secret has an invalid type");
40
- if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new TypeError("credential refresh_token has an invalid type");
50
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
51
+ if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new CredentialMaterialError("credential access_token has an invalid type");
52
+ if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new CredentialMaterialError("credential oauth_client_id has an invalid type");
53
+ if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new CredentialMaterialError("credential oauth_client_secret has an invalid type");
54
+ if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new CredentialMaterialError("credential refresh_token has an invalid type");
41
55
  const credentials = {};
42
- if (!fields["oauth_client_id"]) throw new TypeError("credential oauth_client_id is required");
56
+ if (!fields["oauth_client_id"]) throw new CredentialMaterialError("credential oauth_client_id is required");
43
57
  credentials.oauthClientId = fields["oauth_client_id"] ?? "";
44
58
  credentials.oauthClientSecret = new SecretString(fields["oauth_client_secret"] ?? "");
45
- if (!fields["access_token"]) throw new TypeError("credential access_token is required");
59
+ if (!fields["access_token"]) throw new CredentialMaterialError("credential access_token is required");
46
60
  credentials.accessToken = new SecretString(fields["access_token"] ?? "");
47
61
  credentials.refreshToken = new SecretString(fields["refresh_token"] ?? "");
48
62
  return credentials;
@@ -201,7 +215,7 @@ var UploadFileDefinition = {
201
215
  branches: [
202
216
  { id: "uploaded", description: "Dropbox stored the replacement file content." },
203
217
  { id: "providerRejected", description: "Dropbox conclusively rejected the upload.", optional: true },
204
- { id: "invalidResponse", description: "Dropbox returned malformed or oversized upload metadata.", optional: true },
218
+ { id: "invalidResponse", description: "Retained for compatibility and no longer selected: malformed or oversized upload metadata now retries the overwrite.", optional: true },
205
219
  { id: "defect", description: "Local input or connection credentials are invalid.", optional: true }
206
220
  ],
207
221
  stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
@@ -441,6 +455,8 @@ var GeneratedMock = class {
441
455
 
442
456
  export {
443
457
  ConfigSchema,
458
+ CredentialMaterialError,
459
+ isCredentialMaterialError,
444
460
  decodeCredentials,
445
461
  decodeSharedCredentials,
446
462
  ListFolderInputSchema,
@@ -36,6 +36,12 @@ interface Credentials {
36
36
  /** Secret refresh token returned because offline access is requested. Dex stores it for automatic renewal; blank means reauthorization is required after access-token expiry. */
37
37
  refreshToken: SecretString;
38
38
  }
39
+ /** Stored credential material that fails the connector credential checks, so no retry can succeed. */
40
+ declare class CredentialMaterialError extends TypeError {
41
+ constructor(message: string);
42
+ }
43
+ /** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
44
+ declare function isCredentialMaterialError(error: unknown): boolean;
39
45
  /** Decode private credential fields for the connector. */
40
46
  declare function decodeCredentials(value: unknown): Credentials;
41
47
  /** Decode shared credential fields for the connector. */
@@ -193,4 +199,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
193
199
  /** Bind scripted operations to a named connection. */
194
200
  declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
195
201
 
196
- export { type ContinueFolderInput as C, type DownloadFileInput as D, type EntryMetadata as E, type FolderPage as F, type GetMetadataInput as G, type ListFolderInput as L, type Operations as O, type UploadFileInput as U, type DownloadedFile as a, type UploadedFile as b, type Config as c, type Credentials as d, Connection as e, ConfigSchema as f, ContinueFolderInputSchema as g, type CredentialSource as h, DownloadFileInputSchema as i, DownloadedFileSchema as j, EntryMetadataSchema as k, FolderPageSchema as l, GetMetadataInputSchema as m, ListFolderInputSchema as n, UploadFileInputSchema as o, UploadedFileSchema as p, decodeCredentials as q, decodeSharedCredentials as r, newConnection as s, newConnectionWithOperations as t };
202
+ export { type ContinueFolderInput as C, type DownloadFileInput as D, type EntryMetadata as E, type FolderPage as F, type GetMetadataInput as G, type ListFolderInput as L, type Operations as O, type UploadFileInput as U, type DownloadedFile as a, type UploadedFile as b, type Config as c, type Credentials as d, Connection as e, ConfigSchema as f, ContinueFolderInputSchema as g, CredentialMaterialError as h, type CredentialSource as i, DownloadFileInputSchema as j, DownloadedFileSchema as k, EntryMetadataSchema as l, FolderPageSchema as m, GetMetadataInputSchema as n, ListFolderInputSchema as o, UploadFileInputSchema as p, UploadedFileSchema as q, decodeCredentials as r, decodeSharedCredentials as s, isCredentialMaterialError as t, newConnection as u, newConnectionWithOperations as v };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as ContinueFolderInput, F as FolderPage, L as ListFolderInput, G as GetMetadataInput, E as EntryMetadata, D as DownloadFileInput, a as DownloadedFile, U as UploadFileInput, b as UploadedFile, c as Config, d as Credentials, e as Connection, O as Operations } from './connection-CufXPwNo.js';
2
- export { f as ConfigSchema, g as ContinueFolderInputSchema, h as CredentialSource, i as DownloadFileInputSchema, j as DownloadedFileSchema, k as EntryMetadataSchema, l as FolderPageSchema, m as GetMetadataInputSchema, n as ListFolderInputSchema, o as UploadFileInputSchema, p as UploadedFileSchema, q as decodeCredentials, r as decodeSharedCredentials, s as newConnection, t as newConnectionWithOperations } from './connection-CufXPwNo.js';
1
+ import { C as ContinueFolderInput, F as FolderPage, L as ListFolderInput, G as GetMetadataInput, E as EntryMetadata, D as DownloadFileInput, a as DownloadedFile, U as UploadFileInput, b as UploadedFile, c as Config, d as Credentials, e as Connection, O as Operations } from './connection-DtKKxEuC.js';
2
+ export { f as ConfigSchema, g as ContinueFolderInputSchema, h as CredentialMaterialError, i as CredentialSource, j as DownloadFileInputSchema, k as DownloadedFileSchema, l as EntryMetadataSchema, m as FolderPageSchema, n as GetMetadataInputSchema, o as ListFolderInputSchema, p as UploadFileInputSchema, q as UploadedFileSchema, r as decodeCredentials, s as decodeSharedCredentials, t as isCredentialMaterialError, u as newConnection, v as newConnectionWithOperations } from './connection-DtKKxEuC.js';
3
3
  import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
4
4
  import { QueryDefinition, MutationDefinition, Query, Call, QueryAttempt, Mutation, MutationAttempt, CredentialProvider, CredentialRefreshDriver, QueryStepConfig, QueryResult, MutationStepConfig, MutationResult, QueryStep, MutationStep } from '@superdurable/connectors-sdk';
5
5
  import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
@@ -129,7 +129,7 @@ declare const UploadFileBranch: {
129
129
  declare const UploadFileBranchUploaded: "uploaded";
130
130
  /** Dropbox conclusively rejected the upload. */
131
131
  declare const UploadFileBranchProviderRejected: "providerRejected";
132
- /** Dropbox returned malformed or oversized upload metadata. */
132
+ /** Retained for compatibility and no longer selected: malformed or oversized upload metadata now retries the overwrite. */
133
133
  declare const UploadFileBranchInvalidResponse: "invalidResponse";
134
134
  /** Local input or connection credentials are invalid. */
135
135
  declare const UploadFileBranchDefect: "defect";
@@ -329,7 +329,7 @@ interface UploadFileStepConfig<StepInput, OperationInput = UploadFileInput, Oper
329
329
  uploaded: StepTarget<MutationResult<OperationOutput>>;
330
330
  /** Dropbox conclusively rejected the upload. */
331
331
  providerRejected?: StepTarget<MutationResult<OperationOutput>>;
332
- /** Dropbox returned malformed or oversized upload metadata. */
332
+ /** Retained for compatibility and no longer selected: malformed or oversized upload metadata now retries the overwrite. */
333
333
  invalidResponse?: StepTarget<MutationResult<OperationOutput>>;
334
334
  /** Local input or connection credentials are invalid. */
335
335
  defect?: StepTarget<MutationResult<OperationOutput>>;
package/dist/index.js CHANGED
@@ -11,6 +11,7 @@ import {
11
11
  ContinueFolderDefinition,
12
12
  ContinueFolderInputSchema,
13
13
  ContinueFolderMetadata,
14
+ CredentialMaterialError,
14
15
  DownloadFileBranch,
15
16
  DownloadFileBranchDefect,
16
17
  DownloadFileBranchDownloaded,
@@ -58,10 +59,11 @@ import {
58
59
  emptyEntryMetadata,
59
60
  emptyFolderPage,
60
61
  emptyUploadedFile,
62
+ isCredentialMaterialError,
61
63
  newConnection,
62
64
  newConnectionWithOperations,
63
65
  newProjectCredentialProvider
64
- } from "./chunk-SWXGPJ62.js";
66
+ } from "./chunk-HC4YIUZK.js";
65
67
 
66
68
  // src/client.ts
67
69
  import {
@@ -70,6 +72,7 @@ import {
70
72
  resolveCredential
71
73
  } from "@superdurable/connectors-sdk";
72
74
  import { ManifestCredentialRefreshDriver } from "@superdurable/connectors-sdk/oauthtoken";
75
+ import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
73
76
  import {
74
77
  BodyTooLargeError,
75
78
  isHeaderSafeCredential,
@@ -370,21 +373,40 @@ var UploadFileOperation = class {
370
373
  if (content.toString("base64") !== input.contentBase64) return uploadFailure("defect", "VALIDATION", "upload content must be bounded Base64");
371
374
  if (content.length > this.client.maxUploadBytes) return uploadFailure("defect", "VALIDATION", "upload content must be bounded Base64");
372
375
  const exchange = await this.client.upload(call, input.path, content);
373
- if (exchange.error === "credential") return uploadFailure("defect", "AUTHENTICATION", "connection credentials are unavailable or invalid");
376
+ if (exchange.error === "credential" && exchange.status === 0) {
377
+ if ((call.context?.attempt ?? 1) > 1) return uploadRetry("AUTHENTICATION", "connection credentials are unavailable or invalid after a possible earlier upload");
378
+ return uploadFailure("defect", "AUTHENTICATION", "connection credentials are unavailable or invalid");
379
+ }
380
+ if (exchange.error === "credential") return uploadRetry("PROTOCOL", "Dropbox echoed the access token, so the overwrite is repeated", exchange.retryAfterMs);
374
381
  if (exchange.error === "refresh") return uploadRetry("AVAILABILITY", "Dropbox credentials could not be refreshed");
375
382
  if (exchange.error === "request") return uploadRetry("TRANSPORT", "Dropbox upload request failed");
376
383
  if (exchange.status === 429) return uploadRetry("RATE_LIMIT", "Dropbox rate limited the upload", exchange.retryAfterMs);
377
384
  if (exchange.status === 408 || exchange.status >= 500) return uploadRetry("AVAILABILITY", "Dropbox upload is temporarily unavailable", exchange.retryAfterMs);
378
- if (exchange.status !== 200) return uploadFailure("providerRejected", "PROVIDER_REJECTION", `Dropbox rejected HTTP ${exchange.status}`);
379
- if (exchange.error === "tooLarge") return uploadFailure("invalidResponse", "RESPONSE_TOO_LARGE", "Dropbox upload metadata exceeded the configured limit");
385
+ if (exchange.status !== 200 && isDefiniteUploadRefusal(exchange)) return uploadFailure("providerRejected", "PROVIDER_REJECTION", `Dropbox rejected HTTP ${exchange.status}`);
386
+ if (exchange.status !== 200) return uploadRetry("PROTOCOL", `Dropbox answered the overwrite with unsettled HTTP ${exchange.status}`, exchange.retryAfterMs);
387
+ if (exchange.error === "tooLarge") return uploadRetry("RESPONSE_TOO_LARGE", "Dropbox upload metadata exceeded the configured limit");
380
388
  if (exchange.error) return uploadRetry("TRANSPORT", "Dropbox upload response was interrupted");
381
389
  try {
382
390
  return newMutationBranch("uploaded", { file: decodeEntry(objectBody(exchange.body), true) });
383
391
  } catch {
384
- return uploadFailure("invalidResponse", "PROTOCOL", "Dropbox returned invalid upload metadata");
392
+ return uploadRetry("PROTOCOL", "Dropbox returned invalid upload metadata");
385
393
  }
386
394
  }
387
395
  };
396
+ var definiteRefusalStatuses = /* @__PURE__ */ new Set([400, 401, 403, 404, 411, 413, 414, 415, 422]);
397
+ function isDefiniteUploadRefusal(exchange) {
398
+ if (exchange.error) return false;
399
+ let wire;
400
+ try {
401
+ wire = JSON.parse(Buffer.from(exchange.body).toString("utf8"));
402
+ } catch {
403
+ wire = void 0;
404
+ }
405
+ const fields = wire && typeof wire === "object" && !Array.isArray(wire) ? wire : void 0;
406
+ if (fields && fields.id !== void 0 && fields.id !== null && fields.id !== "") return false;
407
+ if (definiteRefusalStatuses.has(exchange.status)) return true;
408
+ return exchange.status === 409 && typeof fields?.error_summary === "string" && fields.error_summary !== "";
409
+ }
388
410
 
389
411
  // src/client.ts
390
412
  var DropboxClient = class {
@@ -465,20 +487,14 @@ var DropboxClient = class {
465
487
  }, this.maxResponseBytes);
466
488
  }
467
489
  async post(call, url, body, headers, successLimit, isDownload = false) {
468
- let token;
490
+ let credentials;
469
491
  try {
470
- const credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
471
- if (!(credentials.accessToken instanceof SecretString)) return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: "credential" };
472
- token = credentials.accessToken.reveal();
492
+ credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
473
493
  } catch (error) {
474
- return {
475
- status: 0,
476
- body: new Uint8Array(),
477
- metadata: "",
478
- retryAfterMs: 0,
479
- error: error instanceof ReauthorizationRequiredError ? "credential" : "refresh"
480
- };
494
+ const isTerminal = error instanceof ReauthorizationRequiredError || error instanceof ObjectNotFoundError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || isCredentialMaterialError(error);
495
+ return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: isTerminal ? "credential" : "refresh" };
481
496
  }
497
+ const token = credentials.accessToken instanceof SecretString ? credentials.accessToken.reveal() : "";
482
498
  if (!token || !isHeaderSafeCredential(token)) return { status: 0, body: new Uint8Array(), metadata: "", retryAfterMs: 0, error: "credential" };
483
499
  const endpoint = new URL(url);
484
500
  const request = {
@@ -619,6 +635,7 @@ export {
619
635
  ContinueFolderInputSchema,
620
636
  ContinueFolderMetadata,
621
637
  ContinueFolderOperation,
638
+ CredentialMaterialError,
622
639
  DownloadFileBranch,
623
640
  DownloadFileBranchDefect,
624
641
  DownloadFileBranchDownloaded,
@@ -668,6 +685,7 @@ export {
668
685
  decodeCredentials,
669
686
  decodeSharedCredentials,
670
687
  header,
688
+ isCredentialMaterialError,
671
689
  newConnection,
672
690
  newConnectionWithOperations,
673
691
  newContinueFolderStep,
package/dist/mock.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MockQuery, MockMutation, Case } from '@superdurable/connectors-sdk/connectormock';
2
2
  import { Failure } from '@superdurable/connectors-sdk';
3
- import { O as Operations, e as Connection, L as ListFolderInput, F as FolderPage, G as GetMetadataInput, E as EntryMetadata, C as ContinueFolderInput, D as DownloadFileInput, a as DownloadedFile, U as UploadFileInput, b as UploadedFile } from './connection-CufXPwNo.js';
3
+ import { O as Operations, e as Connection, L as ListFolderInput, F as FolderPage, G as GetMetadataInput, E as EntryMetadata, C as ContinueFolderInput, D as DownloadFileInput, a as DownloadedFile, U as UploadFileInput, b as UploadedFile } from './connection-DtKKxEuC.js';
4
4
  import 'zod';
5
5
 
6
6
  /** Go zero value for ListFolderInput in scripted cases. */
package/dist/mock.js CHANGED
@@ -49,7 +49,7 @@ import {
49
49
  uploadFileRetry,
50
50
  uploadFileUploaded,
51
51
  uploadFileUploadedDefault
52
- } from "./chunk-SWXGPJ62.js";
52
+ } from "./chunk-HC4YIUZK.js";
53
53
  export {
54
54
  GeneratedMock,
55
55
  continueFolderCursorExpired,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/connector-dropbox",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "Dropbox file operations for Dex TypeScript Flows",
5
5
  "license": "MIT",
6
6
  "repository": {