@superdurable/connector-aweber 0.1.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.1.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.1.0"
7
+ "version": "0.2.1"
8
8
  },
9
9
  "factories": [
10
10
  {
@@ -50,13 +50,10 @@
50
50
  "type": "integer"
51
51
  },
52
52
  "offset": {
53
- "description": "Offset is the zero-based number of accounts to skip.",
53
+ "description": "Offset is the zero-based number of accounts to skip; zero starts at the first account.",
54
54
  "type": "integer"
55
55
  }
56
56
  },
57
- "required": [
58
- "offset"
59
- ],
60
57
  "type": "object"
61
58
  }
62
59
  }
@@ -6,46 +6,60 @@ 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;
46
60
  }
47
61
  var ListAccountsInputSchema = z.strictObject({
48
- "offset": z.number().int(),
62
+ "offset": z.number().int().optional(),
49
63
  "limit": z.number().int().optional()
50
64
  });
51
65
  var AccountSchema = z.strictObject({
@@ -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. */
@@ -35,8 +41,8 @@ declare function decodeSharedCredentials(value: unknown): Credentials;
35
41
  type CredentialSource = RefreshingCredentialProvider<Credentials>;
36
42
  /** ListAccountsInput selects an offset-based page of authorized accounts. */
37
43
  interface ListAccountsInput {
38
- /** Offset is the zero-based number of accounts to skip. */
39
- "offset": number;
44
+ /** Offset is the zero-based number of accounts to skip; zero starts at the first account. */
45
+ "offset"?: number | undefined;
40
46
  /** Limit is the maximum account count; zero uses the provider default of 100. */
41
47
  "limit"?: number | undefined;
42
48
  }
@@ -60,7 +66,7 @@ interface AccountsPage {
60
66
  }
61
67
  /** Runtime validator for ListAccountsInput. */
62
68
  declare const ListAccountsInputSchema: z.ZodObject<{
63
- offset: z.ZodNumber;
69
+ offset: z.ZodOptional<z.ZodNumber>;
64
70
  limit: z.ZodOptional<z.ZodNumber>;
65
71
  }, z.core.$strict>;
66
72
  /** Runtime validator for Account. */
@@ -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-DD87GHHn.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-DD87GHHn.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-4ZPFSYR3.js";
23
+ } from "./chunk-6JJJ2HGP.js";
22
24
 
23
25
  // src/generated/steps.ts
24
26
  import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
@@ -116,15 +118,18 @@ var ListAccountsOperation = class {
116
118
  }
117
119
  /** Project account IDs and company names from a bounded JSON response. */
118
120
  async invoke(call, input) {
119
- if (!input || !Number.isSafeInteger(input.offset) || input.offset < 0 || input.limit !== void 0 && (!Number.isSafeInteger(input.limit) || input.limit < 0 || input.limit > 100))
121
+ const offset = input?.offset ?? 0;
122
+ if (!input || !Number.isSafeInteger(offset) || offset < 0 || input.limit !== void 0 && (!Number.isSafeInteger(input.limit) || input.limit < 0 || input.limit > 100))
120
123
  return branch("defect", "VALIDATION", "offset or limit is invalid");
121
124
  const limit = input.limit || 100;
122
- const query = new URLSearchParams({ "ws.size": String(limit), "ws.start": String(input.offset) });
125
+ const query = new URLSearchParams({ "ws.size": String(limit), "ws.start": String(offset) });
123
126
  const exchange = await this.client.get(call, `/1.0/accounts?${query.toString()}`);
124
127
  const failed = classifyRead(exchange);
125
128
  if (failed) return failed;
126
129
  const document = parseDocument(exchange.body);
127
- if (!document || !Array.isArray(document.entries) || typeof document.start !== "number" || !Number.isSafeInteger(document.start) || document.start !== input.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)
128
133
  return branch("invalidResponse", "PROTOCOL", "AWeber returned invalid account JSON");
129
134
  const accounts = [];
130
135
  for (const item of document.entries) {
@@ -132,7 +137,7 @@ var ListAccountsOperation = class {
132
137
  return branch("invalidResponse", "PROTOCOL", "AWeber returned invalid account JSON");
133
138
  accounts.push({ id: String(item.id), company: item.company });
134
139
  }
135
- return newQueryBranch("listed", { accounts, offset: input.offset, limit, total: document.total_size });
140
+ return newQueryBranch("listed", { accounts, offset, limit, total });
136
141
  }
137
142
  };
138
143
  function classifyRead(exchange) {
@@ -151,12 +156,17 @@ function isRateLimit(body) {
151
156
  }
152
157
  function parseDocument(body) {
153
158
  try {
154
- const value = JSON.parse(Buffer.from(body).toString("utf8"));
159
+ const value = JSON.parse(Buffer.from(body).toString("utf8"), decodeProviderField);
155
160
  return isObject(value) ? value : void 0;
156
161
  } catch {
157
162
  return void 0;
158
163
  }
159
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
+ }
160
170
  function isObject(value) {
161
171
  return !!value && typeof value === "object" && !Array.isArray(value);
162
172
  }
@@ -229,7 +239,8 @@ var AWeberClient = class {
229
239
  return failedExchange("request");
230
240
  }
231
241
  const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"), this.now());
232
- 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 };
233
244
  return { status: response.status, body: response.body, retryAfterMs };
234
245
  }
235
246
  };
@@ -240,6 +251,21 @@ function header(headers, name) {
240
251
  const value = Object.entries(headers).find(([key]) => key.toLowerCase() === name.toLowerCase())?.[1];
241
252
  return Array.isArray(value) ? value[0] ?? "" : value ?? "";
242
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
+ }
243
269
 
244
270
  // src/project.ts
245
271
  function encodeCredentials(credentials) {
@@ -265,6 +291,7 @@ export {
265
291
  ConfigSchema,
266
292
  Connection,
267
293
  ConnectorID,
294
+ CredentialMaterialError,
268
295
  ListAccountsBranch,
269
296
  ListAccountsBranchDefect,
270
297
  ListAccountsBranchInvalidResponse,
@@ -277,6 +304,7 @@ export {
277
304
  ProviderID,
278
305
  decodeCredentials,
279
306
  decodeSharedCredentials,
307
+ isCredentialMaterialError,
280
308
  newConnection,
281
309
  newConnectionWithOperations,
282
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-DD87GHHn.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,13 +5,11 @@ import {
5
5
  ListAccountsInputSchema,
6
6
  ProviderID,
7
7
  newConnectionWithOperations
8
- } from "./chunk-4ZPFSYR3.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";
12
- var emptyListAccountsInput = ListAccountsInputSchema.parse({
13
- "offset": 0
14
- });
12
+ var emptyListAccountsInput = ListAccountsInputSchema.parse({});
15
13
  var emptyAccount = AccountSchema.parse({
16
14
  "id": "",
17
15
  "company": ""
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdurable/connector-aweber",
3
- "version": "0.1.0",
3
+ "version": "0.2.1",
4
4
  "license": "MIT",
5
5
  "description": "AWeber connector for Dex TypeScript applications",
6
6
  "repository": {