@superdurable/connector-aweber 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": "aweber",
3
- "releaseTag": "connectors/aweber/go/v0.2.0",
3
+ "releaseTag": "connectors/aweber/go/v0.2.1",
4
4
  "package": {
5
5
  "ecosystem": "npm",
6
6
  "name": "@superdurable/connector-aweber",
7
- "version": "0.2.0"
7
+ "version": "0.2.1"
8
8
  },
9
9
  "factories": [
10
10
  {
@@ -6,40 +6,54 @@ var ConfigSchema = z.object({
6
6
  "timeoutMs": z.number().int().optional(),
7
7
  "maxResponseBytes": z.number().int().optional()
8
8
  });
9
+ var CredentialMaterialError = class extends TypeError {
10
+ constructor(message) {
11
+ super(message);
12
+ this.name = "CredentialMaterialError";
13
+ }
14
+ };
15
+ var sdkCredentialDecodingFailureMessages = /* @__PURE__ */ new Set([
16
+ "project credential decoding failed",
17
+ "shared project credential decoding failed",
18
+ "project credential decoding failed: this connector version does not support shared credentials"
19
+ ]);
20
+ function isCredentialMaterialError(error) {
21
+ return error instanceof CredentialMaterialError || error instanceof TypeError && sdkCredentialDecodingFailureMessages.has(error.message);
22
+ }
9
23
  function decodeCredentials(value) {
10
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
24
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
11
25
  const fields = value;
12
26
  const allowed = /* @__PURE__ */ new Set(["access_token", "oauth_client_id", "oauth_client_secret", "refresh_token"]);
13
- if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
14
- if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new TypeError("credential access_token has an invalid type");
15
- if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new TypeError("credential oauth_client_id has an invalid type");
16
- if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new TypeError("credential oauth_client_secret has an invalid type");
17
- if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new TypeError("credential refresh_token has an invalid type");
27
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
28
+ if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new CredentialMaterialError("credential access_token has an invalid type");
29
+ if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new CredentialMaterialError("credential oauth_client_id has an invalid type");
30
+ if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new CredentialMaterialError("credential oauth_client_secret has an invalid type");
31
+ if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new CredentialMaterialError("credential refresh_token has an invalid type");
18
32
  const credentials = {};
19
- if (!fields["oauth_client_id"]) throw new TypeError("credential oauth_client_id is required");
33
+ if (!fields["oauth_client_id"]) throw new CredentialMaterialError("credential oauth_client_id is required");
20
34
  credentials.oauthClientId = fields["oauth_client_id"] ?? "";
21
- if (!fields["oauth_client_secret"]) throw new TypeError("credential oauth_client_secret is required");
35
+ if (!fields["oauth_client_secret"]) throw new CredentialMaterialError("credential oauth_client_secret is required");
22
36
  credentials.oauthClientSecret = new SecretString(fields["oauth_client_secret"] ?? "");
23
- if (!fields["access_token"]) throw new TypeError("credential access_token is required");
37
+ if (!fields["access_token"]) throw new CredentialMaterialError("credential access_token is required");
24
38
  credentials.accessToken = new SecretString(fields["access_token"] ?? "");
25
- if (!fields["refresh_token"]) throw new TypeError("credential refresh_token is required");
39
+ if (!fields["refresh_token"]) throw new CredentialMaterialError("credential refresh_token is required");
26
40
  credentials.refreshToken = new SecretString(fields["refresh_token"] ?? "");
27
41
  return credentials;
28
42
  }
29
43
  function decodeSharedCredentials(value) {
30
- if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
44
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
31
45
  const fields = value;
32
46
  const allowed = /* @__PURE__ */ new Set(["access_token", "oauth_client_id", "oauth_client_secret", "refresh_token"]);
33
- if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
34
- if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new TypeError("credential access_token has an invalid type");
35
- if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new TypeError("credential oauth_client_id has an invalid type");
36
- if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new TypeError("credential oauth_client_secret has an invalid type");
37
- if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new TypeError("credential refresh_token has an invalid type");
47
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new CredentialMaterialError("stored credential does not match the connector credential fields");
48
+ if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new CredentialMaterialError("credential access_token has an invalid type");
49
+ if (fields["oauth_client_id"] != null && !(typeof fields["oauth_client_id"] === "string")) throw new CredentialMaterialError("credential oauth_client_id has an invalid type");
50
+ if (fields["oauth_client_secret"] != null && !(typeof fields["oauth_client_secret"] === "string")) throw new CredentialMaterialError("credential oauth_client_secret has an invalid type");
51
+ if (fields["refresh_token"] != null && !(typeof fields["refresh_token"] === "string")) throw new CredentialMaterialError("credential refresh_token has an invalid type");
38
52
  const credentials = {};
39
- if (!fields["oauth_client_id"]) throw new TypeError("credential oauth_client_id is required");
53
+ if (!fields["oauth_client_id"]) throw new CredentialMaterialError("credential oauth_client_id is required");
40
54
  credentials.oauthClientId = fields["oauth_client_id"] ?? "";
41
55
  credentials.oauthClientSecret = new SecretString(fields["oauth_client_secret"] ?? "");
42
- if (!fields["access_token"]) throw new TypeError("credential access_token is required");
56
+ if (!fields["access_token"]) throw new CredentialMaterialError("credential access_token is required");
43
57
  credentials.accessToken = new SecretString(fields["access_token"] ?? "");
44
58
  credentials.refreshToken = new SecretString(fields["refresh_token"] ?? "");
45
59
  return credentials;
@@ -113,6 +127,8 @@ function newProjectCredentialProvider(project, connectionName, decode, encode, d
113
127
 
114
128
  export {
115
129
  ConfigSchema,
130
+ CredentialMaterialError,
131
+ isCredentialMaterialError,
116
132
  decodeCredentials,
117
133
  decodeSharedCredentials,
118
134
  ListAccountsInputSchema,
@@ -27,6 +27,12 @@ interface Credentials {
27
27
  /** Secret refresh token supplied by AWeber consent and rotated by Dex. Never enter it manually; blank requires reauthorization. */
28
28
  refreshToken: SecretString;
29
29
  }
30
+ /** Stored credential material that fails the connector credential checks, so no retry can succeed. */
31
+ declare class CredentialMaterialError extends TypeError {
32
+ constructor(message: string);
33
+ }
34
+ /** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
35
+ declare function isCredentialMaterialError(error: unknown): boolean;
30
36
  /** Decode private credential fields for the connector. */
31
37
  declare function decodeCredentials(value: unknown): Credentials;
32
38
  /** Decode shared credential fields for the connector. */
@@ -98,4 +104,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
98
104
  /** Bind scripted operations to a named connection. */
99
105
  declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
100
106
 
101
- export { type AccountsPage as A, Connection as C, type ListAccountsInput as L, type Operations as O, type Config as a, type Credentials as b, type Account as c, AccountSchema as d, AccountsPageSchema as e, ConfigSchema as f, type CredentialSource as g, ListAccountsInputSchema as h, decodeCredentials as i, decodeSharedCredentials as j, newConnectionWithOperations as k, newConnection as n };
107
+ export { type AccountsPage as A, Connection as C, type ListAccountsInput as L, type Operations as O, type Config as a, type Credentials as b, type Account as c, AccountSchema as d, AccountsPageSchema as e, ConfigSchema as f, CredentialMaterialError as g, type CredentialSource as h, ListAccountsInputSchema as i, decodeCredentials as j, decodeSharedCredentials as k, isCredentialMaterialError as l, newConnectionWithOperations as m, newConnection as n };
package/dist/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { L as ListAccountsInput, A as AccountsPage, C as Connection, a as Config, b as Credentials, O as Operations } from './connection-C55dNn1o.js';
2
- export { c as Account, d as AccountSchema, e as AccountsPageSchema, f as ConfigSchema, g as CredentialSource, h as ListAccountsInputSchema, i as decodeCredentials, j as decodeSharedCredentials, n as newConnection, k as newConnectionWithOperations } from './connection-C55dNn1o.js';
1
+ import { L as ListAccountsInput, A as AccountsPage, C as Connection, a as Config, b as Credentials, O as Operations } from './connection-D6i07AKv.js';
2
+ export { c as Account, d as AccountSchema, e as AccountsPageSchema, f as ConfigSchema, g as CredentialMaterialError, h as CredentialSource, i as ListAccountsInputSchema, j as decodeCredentials, k as decodeSharedCredentials, l as isCredentialMaterialError, n as newConnection, m as newConnectionWithOperations } from './connection-D6i07AKv.js';
3
3
  import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, Call, QueryAttempt, CredentialProvider, CredentialRefreshDriver } from '@superdurable/connectors-sdk';
4
4
  import { StepTarget } from '@superdurable/dex';
5
5
  import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  ConfigSchema,
5
5
  Connection,
6
6
  ConnectorID,
7
+ CredentialMaterialError,
7
8
  ListAccountsBranch,
8
9
  ListAccountsBranchDefect,
9
10
  ListAccountsBranchInvalidResponse,
@@ -15,10 +16,11 @@ import {
15
16
  ProviderID,
16
17
  decodeCredentials,
17
18
  decodeSharedCredentials,
19
+ isCredentialMaterialError,
18
20
  newConnection,
19
21
  newConnectionWithOperations,
20
22
  newProjectCredentialProvider
21
- } from "./chunk-GPA62WB3.js";
23
+ } from "./chunk-6JJJ2HGP.js";
22
24
 
23
25
  // src/generated/steps.ts
24
26
  import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
@@ -125,7 +127,9 @@ var ListAccountsOperation = class {
125
127
  const failed = classifyRead(exchange);
126
128
  if (failed) return failed;
127
129
  const document = parseDocument(exchange.body);
128
- if (!document || !Array.isArray(document.entries) || typeof document.start !== "number" || !Number.isSafeInteger(document.start) || document.start !== offset || typeof document.total_size !== "number" || !Number.isSafeInteger(document.total_size) || document.total_size < document.entries.length)
130
+ const start = document?.start ?? 0;
131
+ const total = document?.total_size ?? 0;
132
+ if (!document || !Array.isArray(document.entries) || start !== offset || typeof total !== "number" || !Number.isSafeInteger(total) || total < document.entries.length)
129
133
  return branch("invalidResponse", "PROTOCOL", "AWeber returned invalid account JSON");
130
134
  const accounts = [];
131
135
  for (const item of document.entries) {
@@ -133,7 +137,7 @@ var ListAccountsOperation = class {
133
137
  return branch("invalidResponse", "PROTOCOL", "AWeber returned invalid account JSON");
134
138
  accounts.push({ id: String(item.id), company: item.company });
135
139
  }
136
- return newQueryBranch("listed", { accounts, offset, limit, total: document.total_size });
140
+ return newQueryBranch("listed", { accounts, offset, limit, total });
137
141
  }
138
142
  };
139
143
  function classifyRead(exchange) {
@@ -152,12 +156,17 @@ function isRateLimit(body) {
152
156
  }
153
157
  function parseDocument(body) {
154
158
  try {
155
- const value = JSON.parse(Buffer.from(body).toString("utf8"));
159
+ const value = JSON.parse(Buffer.from(body).toString("utf8"), decodeProviderField);
156
160
  return isObject(value) ? value : void 0;
157
161
  } catch {
158
162
  return void 0;
159
163
  }
160
164
  }
165
+ function decodeProviderField(_key, value, context) {
166
+ if (typeof value === "number" && context?.source && !/^-?\d+$/.test(context.source)) return NaN;
167
+ if (isObject(value)) return Object.fromEntries(Object.entries(value).map(([name, field]) => [name.toLowerCase(), field]));
168
+ return value;
169
+ }
161
170
  function isObject(value) {
162
171
  return !!value && typeof value === "object" && !Array.isArray(value);
163
172
  }
@@ -230,7 +239,8 @@ var AWeberClient = class {
230
239
  return failedExchange("request");
231
240
  }
232
241
  const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
233
- if (Buffer.from(response.body).includes(token)) return { ...failedExchange("credential"), status: response.status, retryAfterMs };
242
+ if (response.body.byteLength > this.maxResponseBytes) return { ...failedExchange("tooLarge"), status: response.status, retryAfterMs };
243
+ if (containsAccessToken(response.body, token)) return { ...failedExchange("credential"), status: response.status, retryAfterMs };
234
244
  return { status: response.status, body: response.body, retryAfterMs };
235
245
  }
236
246
  };
@@ -241,6 +251,21 @@ function header(headers, name) {
241
251
  const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
242
252
  return Array.isArray(value) ? value[0] ?? "" : value ?? "";
243
253
  }
254
+ function containsAccessToken(body, token) {
255
+ const bytes = Buffer.from(body);
256
+ if (bytes.includes(token)) return true;
257
+ if (!bytes.includes(92)) return false;
258
+ for (const match of bytes.toString("utf8").matchAll(/"(?:[^"\\]|\\.)*"/g)) {
259
+ if (!match[0].includes("\\")) continue;
260
+ try {
261
+ const decoded = JSON.parse(match[0]);
262
+ if (decoded.includes(token)) return true;
263
+ } catch {
264
+ continue;
265
+ }
266
+ }
267
+ return false;
268
+ }
244
269
 
245
270
  // src/project.ts
246
271
  function encodeCredentials(credentials) {
@@ -266,6 +291,7 @@ export {
266
291
  ConfigSchema,
267
292
  Connection,
268
293
  ConnectorID,
294
+ CredentialMaterialError,
269
295
  ListAccountsBranch,
270
296
  ListAccountsBranchDefect,
271
297
  ListAccountsBranchInvalidResponse,
@@ -278,6 +304,7 @@ export {
278
304
  ProviderID,
279
305
  decodeCredentials,
280
306
  decodeSharedCredentials,
307
+ isCredentialMaterialError,
281
308
  newConnection,
282
309
  newConnectionWithOperations,
283
310
  newListAccountsStep,
package/dist/mock.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
2
2
  import { Failure } from '@superdurable/connectors-sdk';
3
- import { O as Operations, C as Connection, L as ListAccountsInput, A as AccountsPage, c as Account } from './connection-C55dNn1o.js';
3
+ import { O as Operations, C as Connection, L as ListAccountsInput, A as AccountsPage, c as Account } from './connection-D6i07AKv.js';
4
4
  import 'zod';
5
5
 
6
6
  /** Go zero value for ListAccountsInput in scripted cases. */
package/dist/mock.js CHANGED
@@ -5,7 +5,7 @@ import {
5
5
  ListAccountsInputSchema,
6
6
  ProviderID,
7
7
  newConnectionWithOperations
8
- } from "./chunk-GPA62WB3.js";
8
+ } from "./chunk-6JJJ2HGP.js";
9
9
 
10
10
  // src/generated/mock.ts
11
11
  import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/connector-aweber",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "AWeber connector for Dex TypeScript applications",
6
6
  "repository": {