@superdurable/connector-brevo 0.1.1 → 0.1.2
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/README.md +1 -1
- package/dex-connector.json +43 -4
- package/dist/{chunk-NI2F5J36.js → chunk-DSBPG24K.js} +29 -0
- package/dist/{connection-BmKZ2txn.d.ts → connection-DAhpVtMQ.d.ts} +9 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +31 -16
- package/dist/mock.d.ts +1 -1
- package/dist/mock.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Brevo TypeScript connector
|
|
2
2
|
|
|
3
|
-
Install `@superdurable/connector-brevo@0.1.
|
|
3
|
+
Install `@superdurable/connector-brevo@0.1.2` for Dex TypeScript applications.
|
|
4
4
|
The package implements `createOrUpdateContact` and `getContact`, and exports
|
|
5
5
|
typed Step factories, connection helpers, generated models, and manifest mocks.
|
|
6
6
|
Both operations accept plain RFC 5322 addresses using the same parsed-address check as the Go connector.
|
package/dex-connector.json
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"connectorId": "brevo",
|
|
3
|
-
"releaseTag": "connectors/brevo/go/v0.2.
|
|
3
|
+
"releaseTag": "connectors/brevo/go/v0.2.1",
|
|
4
4
|
"package": {
|
|
5
5
|
"ecosystem": "npm",
|
|
6
6
|
"name": "@superdurable/connector-brevo",
|
|
7
|
-
"version": "0.1.
|
|
7
|
+
"version": "0.1.2"
|
|
8
8
|
},
|
|
9
9
|
"factories": [
|
|
10
10
|
{
|
|
11
11
|
"name": "newCreateOrUpdateContactStep",
|
|
12
12
|
"kind": "mutation",
|
|
13
13
|
"operationId": "createOrUpdateContact",
|
|
14
|
+
"inputType": "CreateOrUpdateContactInput",
|
|
15
|
+
"description": "Create a contact by email or set its specified attributes when it already exists.",
|
|
14
16
|
"fields": {
|
|
15
17
|
"stepType": "stepType",
|
|
16
18
|
"annotations": "annotations",
|
|
@@ -38,12 +40,35 @@
|
|
|
38
40
|
"field": "defect",
|
|
39
41
|
"optional": true
|
|
40
42
|
}
|
|
41
|
-
]
|
|
43
|
+
],
|
|
44
|
+
"inputSchema": {
|
|
45
|
+
"additionalProperties": false,
|
|
46
|
+
"description": "CreateOrUpdateContactInput supplies an email and absolute attribute values.",
|
|
47
|
+
"properties": {
|
|
48
|
+
"attributes": {
|
|
49
|
+
"additionalProperties": {
|
|
50
|
+
"type": "string"
|
|
51
|
+
},
|
|
52
|
+
"description": "Attributes sets existing Brevo contact attributes by their uppercase names.",
|
|
53
|
+
"type": "object"
|
|
54
|
+
},
|
|
55
|
+
"email": {
|
|
56
|
+
"description": "Email identifies the contact and must be a plain email address.",
|
|
57
|
+
"type": "string"
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
"required": [
|
|
61
|
+
"email"
|
|
62
|
+
],
|
|
63
|
+
"type": "object"
|
|
64
|
+
}
|
|
42
65
|
},
|
|
43
66
|
{
|
|
44
67
|
"name": "newGetContactStep",
|
|
45
68
|
"kind": "query",
|
|
46
69
|
"operationId": "getContact",
|
|
70
|
+
"inputType": "GetContactInput",
|
|
71
|
+
"description": "Get a Brevo contact by email address.",
|
|
47
72
|
"fields": {
|
|
48
73
|
"stepType": "stepType",
|
|
49
74
|
"annotations": "annotations",
|
|
@@ -76,7 +101,21 @@
|
|
|
76
101
|
"field": "defect",
|
|
77
102
|
"optional": true
|
|
78
103
|
}
|
|
79
|
-
]
|
|
104
|
+
],
|
|
105
|
+
"inputSchema": {
|
|
106
|
+
"additionalProperties": false,
|
|
107
|
+
"description": "GetContactInput identifies a contact by email.",
|
|
108
|
+
"properties": {
|
|
109
|
+
"email": {
|
|
110
|
+
"description": "Email is a plain email address.",
|
|
111
|
+
"type": "string"
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
"required": [
|
|
115
|
+
"email"
|
|
116
|
+
],
|
|
117
|
+
"type": "object"
|
|
118
|
+
}
|
|
80
119
|
}
|
|
81
120
|
]
|
|
82
121
|
}
|
|
@@ -1,10 +1,36 @@
|
|
|
1
1
|
// src/generated/models.ts
|
|
2
2
|
import { z } from "zod";
|
|
3
|
+
import { SecretString } from "@superdurable/connectors-sdk";
|
|
3
4
|
var ConfigSchema = z.object({
|
|
4
5
|
"baseUrl": z.string().optional(),
|
|
5
6
|
"timeoutMs": z.number().int().optional(),
|
|
6
7
|
"maxResponseBytes": z.number().int().optional()
|
|
7
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
|
+
}
|
|
23
|
+
function decodeCredentials(value) {
|
|
24
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw new CredentialMaterialError("credential fields are invalid");
|
|
25
|
+
const fields = value;
|
|
26
|
+
const allowed = /* @__PURE__ */ new Set(["api_key"]);
|
|
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["api_key"] != null && !(typeof fields["api_key"] === "string")) throw new CredentialMaterialError("credential api_key has an invalid type");
|
|
29
|
+
const credentials = {};
|
|
30
|
+
if (!fields["api_key"]) throw new CredentialMaterialError("credential api_key is required");
|
|
31
|
+
credentials.apiKey = new SecretString(fields["api_key"] ?? "");
|
|
32
|
+
return credentials;
|
|
33
|
+
}
|
|
8
34
|
var CreateOrUpdateContactInputSchema = z.strictObject({
|
|
9
35
|
"email": z.string(),
|
|
10
36
|
"attributes": z.record(z.string(), z.string()).optional()
|
|
@@ -103,6 +129,9 @@ function newProjectConnection(project, connectionName, createClient) {
|
|
|
103
129
|
|
|
104
130
|
export {
|
|
105
131
|
ConfigSchema,
|
|
132
|
+
CredentialMaterialError,
|
|
133
|
+
isCredentialMaterialError,
|
|
134
|
+
decodeCredentials,
|
|
106
135
|
CreateOrUpdateContactInputSchema,
|
|
107
136
|
ContactWriteResultSchema,
|
|
108
137
|
GetContactInputSchema,
|
|
@@ -21,6 +21,14 @@ interface Credentials {
|
|
|
21
21
|
/** Secret Brevo API key from https://app.brevo.com/settings/keys/api after Settings > SMTP & API > API keys > Generate a new API key; copy the displayed string once. Blank prevents requests. */
|
|
22
22
|
apiKey: SecretString;
|
|
23
23
|
}
|
|
24
|
+
/** Stored credential material that fails the connector credential checks, so no retry can succeed. */
|
|
25
|
+
declare class CredentialMaterialError extends TypeError {
|
|
26
|
+
constructor(message: string);
|
|
27
|
+
}
|
|
28
|
+
/** Report malformed stored credential material, also behind the SDK provider's decoding TypeError. */
|
|
29
|
+
declare function isCredentialMaterialError(error: unknown): boolean;
|
|
30
|
+
/** Decode private credential fields for the connector. */
|
|
31
|
+
declare function decodeCredentials(value: unknown): Credentials;
|
|
24
32
|
/** Host-owned source of private connector credentials. */
|
|
25
33
|
type CredentialSource = CredentialProvider<Credentials>;
|
|
26
34
|
/** CreateOrUpdateContactInput supplies an email and absolute attribute values. */
|
|
@@ -95,4 +103,4 @@ declare function newConnection(client: Operations, reference: ConnectionRef): Co
|
|
|
95
103
|
/** Bind scripted operations to a named connection. */
|
|
96
104
|
declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
|
|
97
105
|
|
|
98
|
-
export { type CreateOrUpdateContactInput as C, type GetContactInput as G, type Operations as O, type ContactWriteResult as a, Connection as b, type Contact as c, type Config as d, type Credentials as e, ConfigSchema as f, ContactSchema as g, ContactWriteResultSchema as h, CreateOrUpdateContactInputSchema as i, type CredentialSource as
|
|
106
|
+
export { type CreateOrUpdateContactInput as C, type GetContactInput as G, type Operations as O, type ContactWriteResult as a, Connection as b, type Contact as c, type Config as d, type Credentials as e, ConfigSchema as f, ContactSchema as g, ContactWriteResultSchema as h, CreateOrUpdateContactInputSchema as i, CredentialMaterialError as j, type CredentialSource as k, GetContactInputSchema as l, decodeCredentials as m, isCredentialMaterialError as n, newConnection as o, newConnectionWithOperations as p };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CreateOrUpdateContactInput, a as ContactWriteResult, b as Connection, G as GetContactInput, c as Contact, O as Operations, d as Config, e as Credentials } from './connection-
|
|
2
|
-
export { f as ConfigSchema, g as ContactSchema, h as ContactWriteResultSchema, i as CreateOrUpdateContactInputSchema, j as
|
|
1
|
+
import { C as CreateOrUpdateContactInput, a as ContactWriteResult, b as Connection, G as GetContactInput, c as Contact, O as Operations, d as Config, e as Credentials } from './connection-DAhpVtMQ.js';
|
|
2
|
+
export { f as ConfigSchema, g as ContactSchema, h as ContactWriteResultSchema, i as CreateOrUpdateContactInputSchema, j as CredentialMaterialError, k as CredentialSource, l as GetContactInputSchema, m as decodeCredentials, n as isCredentialMaterialError, o as newConnection, p as newConnectionWithOperations } from './connection-DAhpVtMQ.js';
|
|
3
3
|
import * as _superdurable_connectors_sdk from '@superdurable/connectors-sdk';
|
|
4
4
|
import { MutationDefinition, QueryDefinition, MutationStepConfig, Mutation, MutationResult, QueryStepConfig, Query, QueryResult, MutationStep, QueryStep, Call, MutationAttempt, QueryAttempt, CredentialProvider, Failure } from '@superdurable/connectors-sdk';
|
|
5
5
|
import { StepTarget } from '@superdurable/dex';
|
package/dist/index.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
CreateOrUpdateContactDefinition,
|
|
13
13
|
CreateOrUpdateContactInputSchema,
|
|
14
14
|
CreateOrUpdateContactMetadata,
|
|
15
|
+
CredentialMaterialError,
|
|
15
16
|
GetContactBranch,
|
|
16
17
|
GetContactBranchDefect,
|
|
17
18
|
GetContactBranchFound,
|
|
@@ -22,10 +23,12 @@ import {
|
|
|
22
23
|
GetContactInputSchema,
|
|
23
24
|
GetContactMetadata,
|
|
24
25
|
ProviderID,
|
|
26
|
+
decodeCredentials,
|
|
27
|
+
isCredentialMaterialError,
|
|
25
28
|
newConnection,
|
|
26
29
|
newConnectionWithOperations,
|
|
27
30
|
newProjectConnection
|
|
28
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-DSBPG24K.js";
|
|
29
32
|
|
|
30
33
|
// src/generated/steps.ts
|
|
31
34
|
import { goToBranch, newMutationStep, newQueryStep } from "@superdurable/connectors-sdk";
|
|
@@ -53,12 +56,14 @@ function newGetContactStep(configuration) {
|
|
|
53
56
|
|
|
54
57
|
// src/project.ts
|
|
55
58
|
import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
|
|
56
|
-
import { z } from "zod";
|
|
59
|
+
import { z as z2 } from "zod";
|
|
57
60
|
|
|
58
61
|
// src/client.ts
|
|
59
62
|
import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
|
|
60
|
-
import { SecretString } from "@superdurable/connectors-sdk";
|
|
63
|
+
import { ReauthorizationRequiredError, SecretString } from "@superdurable/connectors-sdk";
|
|
64
|
+
import { ConnectionNotSelectedError, CredentialBrokerRejectedError, ObjectNotFoundError } from "@superdurable/connectors-sdk/projectconfig";
|
|
61
65
|
import emailAddresses from "email-addresses";
|
|
66
|
+
import { z } from "zod";
|
|
62
67
|
|
|
63
68
|
// src/operations.ts
|
|
64
69
|
import { newMutationBranch, newMutationRetry, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
|
|
@@ -94,11 +99,13 @@ var CreateOrUpdateContactOperation = class {
|
|
|
94
99
|
if (body.byteLength > 1 << 20) return newMutationBranch("defect", emptyWrite, {}, brevoFailure(operation, "VALIDATION", "contact payload is invalid or too large"));
|
|
95
100
|
const exchange = await this.client.exchange(call, operation, "POST", "/contacts", body);
|
|
96
101
|
if ("failure" in exchange) {
|
|
97
|
-
if (exchange.classification === "retry") return newMutationRetry(exchange.failure);
|
|
98
|
-
return newMutationBranch(
|
|
102
|
+
if (exchange.classification === "retry" || exchange.classification === "invalidResponse") return newMutationRetry(exchange.failure);
|
|
103
|
+
return newMutationBranch("defect", emptyWrite, {}, exchange.failure);
|
|
99
104
|
}
|
|
100
105
|
const { response } = exchange;
|
|
101
106
|
if (isRetryableStatus(response.status)) return newMutationRetry(brevoFailure(operation, "AVAILABILITY", "Brevo contact request is temporarily unavailable"), this.client.retryAfter(response));
|
|
107
|
+
if (response.status !== 201 && response.status !== 204 && ![400, 401, 403, 404, 411, 413, 414, 415, 422].includes(response.status))
|
|
108
|
+
return newMutationRetry(brevoFailure(operation, "AVAILABILITY", `Brevo answered the contact request with HTTP ${response.status}`));
|
|
102
109
|
if (response.status !== 201 && response.status !== 204) return newMutationBranch("providerRejected", emptyWrite, {}, brevoFailure(operation, rejectionFailureKind(response.status), `Brevo rejected contact request with HTTP ${response.status}`));
|
|
103
110
|
if (response.status === 204) return newMutationBranch("saved", { email: input.email, created: false });
|
|
104
111
|
try {
|
|
@@ -106,7 +113,7 @@ var CreateOrUpdateContactOperation = class {
|
|
|
106
113
|
if (!decoded || typeof decoded !== "object" || !("id" in decoded) || typeof decoded.id !== "number" || !Number.isSafeInteger(decoded.id) || decoded.id <= 0) throw new TypeError("invalid ID");
|
|
107
114
|
return newMutationBranch("saved", { id: decoded.id, email: input.email, created: true });
|
|
108
115
|
} catch {
|
|
109
|
-
return
|
|
116
|
+
return newMutationRetry(brevoFailure(operation, "PROTOCOL", "Brevo returned an invalid contact ID"));
|
|
110
117
|
}
|
|
111
118
|
}
|
|
112
119
|
};
|
|
@@ -179,15 +186,17 @@ var BrevoClient = class {
|
|
|
179
186
|
}
|
|
180
187
|
/** Send one authenticated request and classify transport failures. */
|
|
181
188
|
async exchange(call, operation, method, path, body) {
|
|
182
|
-
|
|
189
|
+
const unusable = { failure: brevoFailure(operation, "AUTHENTICATION", "Brevo connection credentials are unavailable or invalid"), classification: "defect", retryAfterMs: 0 };
|
|
190
|
+
let credentials;
|
|
183
191
|
try {
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
} catch {
|
|
189
|
-
return { failure: brevoFailure(operation, "AUTHENTICATION", "Brevo connection credentials are unavailable or invalid"), classification: "defect", retryAfterMs: 0 };
|
|
192
|
+
credentials = await this.credentials.resolve(call, call.context.cancellationSignal);
|
|
193
|
+
} catch (error) {
|
|
194
|
+
if (isTerminalCredentialError(error)) return unusable;
|
|
195
|
+
return { failure: brevoFailure(operation, "AVAILABILITY", "Brevo connection credentials are temporarily unavailable"), classification: "retry", retryAfterMs: 0 };
|
|
190
196
|
}
|
|
197
|
+
if (!(credentials?.apiKey instanceof SecretString)) return unusable;
|
|
198
|
+
const apiKey = credentials.apiKey.reveal();
|
|
199
|
+
if (!isHeaderSafeCredential(apiKey)) return unusable;
|
|
191
200
|
try {
|
|
192
201
|
const response = await this.send({
|
|
193
202
|
url: this.baseUrl + path,
|
|
@@ -216,6 +225,9 @@ var BrevoClient = class {
|
|
|
216
225
|
return parseRetryAfter(Array.isArray(value) ? value[0] ?? "" : value ?? "", this.now());
|
|
217
226
|
}
|
|
218
227
|
};
|
|
228
|
+
function isTerminalCredentialError(error) {
|
|
229
|
+
return isCredentialMaterialError(error) || error instanceof ReauthorizationRequiredError || error instanceof ObjectNotFoundError || error instanceof ConnectionNotSelectedError || error instanceof CredentialBrokerRejectedError || error instanceof z.ZodError;
|
|
230
|
+
}
|
|
219
231
|
function brevoFailure(operation, kind, message) {
|
|
220
232
|
return { kind, provider: "brevo", operation, message };
|
|
221
233
|
}
|
|
@@ -237,7 +249,7 @@ function newProjectConnection2(project, connectionName) {
|
|
|
237
249
|
return newProjectConnection(project, connectionName, (loadedProject, name) => {
|
|
238
250
|
const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "brevo" && entry.connectionName === name);
|
|
239
251
|
if (!selected) throw new TypeError("Brevo project connection is not configured");
|
|
240
|
-
const fields =
|
|
252
|
+
const fields = z2.strictObject({ baseUrl: z2.string().optional(), timeout: z2.union([z2.string(), z2.number().int()]).optional(), maxResponseBytes: z2.number().int().optional() }).parse(selected.configuration);
|
|
241
253
|
const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
|
|
242
254
|
const config = {
|
|
243
255
|
...fields.baseUrl !== void 0 ? { baseUrl: fields.baseUrl } : {},
|
|
@@ -247,8 +259,8 @@ function newProjectConnection2(project, connectionName) {
|
|
|
247
259
|
const credentials = {
|
|
248
260
|
async resolve(_call, signal) {
|
|
249
261
|
const privateFields = await loadedProject.resolveCredential("brevo", name, signal);
|
|
250
|
-
|
|
251
|
-
return { apiKey: new SecretString2(
|
|
262
|
+
const decoded = z2.object({ api_key: z2.string() }).parse(privateFields);
|
|
263
|
+
return { apiKey: new SecretString2(decoded.api_key) };
|
|
252
264
|
}
|
|
253
265
|
};
|
|
254
266
|
return new BrevoClient(config, credentials);
|
|
@@ -283,6 +295,7 @@ export {
|
|
|
283
295
|
CreateOrUpdateContactInputSchema,
|
|
284
296
|
CreateOrUpdateContactMetadata,
|
|
285
297
|
CreateOrUpdateContactOperation,
|
|
298
|
+
CredentialMaterialError,
|
|
286
299
|
GetContactBranch,
|
|
287
300
|
GetContactBranchDefect,
|
|
288
301
|
GetContactBranchFound,
|
|
@@ -294,6 +307,8 @@ export {
|
|
|
294
307
|
GetContactMetadata,
|
|
295
308
|
GetContactOperation,
|
|
296
309
|
ProviderID,
|
|
310
|
+
decodeCredentials,
|
|
311
|
+
isCredentialMaterialError,
|
|
297
312
|
newConnection,
|
|
298
313
|
newConnectionWithOperations,
|
|
299
314
|
newCreateOrUpdateContactStep,
|
package/dist/mock.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MockMutation, MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
|
|
2
2
|
import { Failure } from '@superdurable/connectors-sdk';
|
|
3
|
-
import { O as Operations, b as Connection, C as CreateOrUpdateContactInput, a as ContactWriteResult, G as GetContactInput, c as Contact } from './connection-
|
|
3
|
+
import { O as Operations, b as Connection, C as CreateOrUpdateContactInput, a as ContactWriteResult, G as GetContactInput, c as Contact } from './connection-DAhpVtMQ.js';
|
|
4
4
|
import 'zod';
|
|
5
5
|
|
|
6
6
|
/** Go zero value for CreateOrUpdateContactInput in scripted cases. */
|
package/dist/mock.js
CHANGED
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
GetContactInputSchema,
|
|
8
8
|
ProviderID,
|
|
9
9
|
newConnectionWithOperations
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-DSBPG24K.js";
|
|
11
11
|
|
|
12
12
|
// src/generated/mock.ts
|
|
13
13
|
import { branchCase, retryCase, newMutation, newQuery } from "@superdurable/connectors-sdk/connectormock";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@superdurable/connector-brevo",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Brevo contact operations for Dex Flows",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -25,7 +25,8 @@
|
|
|
25
25
|
"./mock": {
|
|
26
26
|
"types": "./dist/mock.d.ts",
|
|
27
27
|
"import": "./dist/mock.js"
|
|
28
|
-
}
|
|
28
|
+
},
|
|
29
|
+
"./dex-connector.json": "./dex-connector.json"
|
|
29
30
|
},
|
|
30
31
|
"files": [
|
|
31
32
|
"dist",
|