@superdurable/connector-campaignmonitor 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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Super Durable
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,5 @@
1
- # Temporary Holding Version
1
+ # Campaign Monitor TypeScript connector
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ This package implements `listClients` for Dex TypeScript Flows. It replays the Go reference's provider requests, branches, retries, and exact outputs through shared conformance scenarios. Only client IDs and names enter Flow results.
4
+
5
+ For an account you control, sign in at [Campaign Monitor](https://login.createsend.com/l), open Profile image > Account settings > API keys ([guide](https://help.campaignmonitor.com/articles/Knowledge/api-keys)), and save the full key in Dex secret `api_key`. Leave `baseUrl` blank for the API v3.3 default. The package uses the key as the HTTP Basic username with an empty password. Public integrations should use OAuth. See the [connector README](../README.md) and [runnable example](examples/client-discovery/README.md). Live provider authorization remains unverified.
@@ -0,0 +1,52 @@
1
+ {
2
+ "connectorId": "campaignmonitor",
3
+ "releaseTag": "connectors/campaignmonitor/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-campaignmonitor",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newListClientsStep",
12
+ "kind": "query",
13
+ "operationId": "listClients",
14
+ "inputType": "ListClientsInput",
15
+ "description": "List IDs and names of clients accessible to the Campaign Monitor account.",
16
+ "fields": {
17
+ "stepType": "stepType",
18
+ "annotations": "annotations",
19
+ "connectionName": "connectionName",
20
+ "resultAttribute": "resultAttribute"
21
+ },
22
+ "branches": [
23
+ {
24
+ "id": "listed",
25
+ "field": "listed",
26
+ "optional": false
27
+ },
28
+ {
29
+ "id": "providerRejected",
30
+ "field": "providerRejected",
31
+ "optional": true
32
+ },
33
+ {
34
+ "id": "invalidResponse",
35
+ "field": "invalidResponse",
36
+ "optional": true
37
+ },
38
+ {
39
+ "id": "defect",
40
+ "field": "defect",
41
+ "optional": true
42
+ }
43
+ ],
44
+ "inputSchema": {
45
+ "additionalProperties": false,
46
+ "description": "ListClientsInput selects the account's accessible clients without filters.",
47
+ "properties": {},
48
+ "type": "object"
49
+ }
50
+ }
51
+ ]
52
+ }
@@ -0,0 +1,103 @@
1
+ // src/generated/models.ts
2
+ import { z } from "zod";
3
+ import { SecretString } from "@superdurable/connectors-sdk";
4
+ var ConfigSchema = z.object({
5
+ "baseUrl": z.string().optional(),
6
+ "timeoutMs": z.number().int().optional(),
7
+ "maxResponseBytes": z.number().int().optional()
8
+ });
9
+ function decodeCredentials(value) {
10
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
11
+ const fields = value;
12
+ const allowed = /* @__PURE__ */ new Set(["api_key"]);
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["api_key"] != null && !(typeof fields["api_key"] === "string")) throw new TypeError("credential api_key has an invalid type");
15
+ const credentials = {};
16
+ if (!fields["api_key"]) throw new TypeError("credential api_key is required");
17
+ credentials.apiKey = new SecretString(fields["api_key"] ?? "");
18
+ return credentials;
19
+ }
20
+ var ListClientsInputSchema = z.strictObject({});
21
+ var ClientMetadataSchema = z.strictObject({
22
+ "id": z.string(),
23
+ "name": z.string()
24
+ });
25
+ var ClientsListSchema = z.strictObject({
26
+ "clients": z.array(ClientMetadataSchema).nullable()
27
+ });
28
+
29
+ // src/generated/definitions.ts
30
+ var ConnectorID = "campaignmonitor";
31
+ var ProviderID = "campaignmonitor";
32
+ var ListClientsBranch = {
33
+ Listed: "listed",
34
+ ProviderRejected: "providerRejected",
35
+ InvalidResponse: "invalidResponse",
36
+ Defect: "defect"
37
+ };
38
+ var ListClientsBranchListed = ListClientsBranch.Listed;
39
+ var ListClientsBranchProviderRejected = ListClientsBranch.ProviderRejected;
40
+ var ListClientsBranchInvalidResponse = ListClientsBranch.InvalidResponse;
41
+ var ListClientsBranchDefect = ListClientsBranch.Defect;
42
+ var ListClientsDefinition = {
43
+ operation: { connectorId: ConnectorID, operationId: "listClients" },
44
+ branches: [
45
+ { id: "listed", description: "Campaign Monitor returned the account's clients." },
46
+ { id: "providerRejected", description: "Campaign Monitor conclusively rejected the request.", optional: true },
47
+ { id: "invalidResponse", description: "Campaign Monitor returned malformed or oversized JSON.", optional: true },
48
+ { id: "defect", description: "Connection credentials are invalid.", optional: true }
49
+ ],
50
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
51
+ };
52
+ var ListClientsMetadata = { kind: "query", idempotency: "none", authorization: "required" };
53
+
54
+ // src/generated/connection.ts
55
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
56
+ var Connection = class {
57
+ /** Stable provider and connection name. */
58
+ reference;
59
+ /** Bound provider operations. */
60
+ operations;
61
+ /** Validate a reference and bind operations. */
62
+ constructor(reference, operations) {
63
+ this.reference = ConnectionRefSchema.parse(reference);
64
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
65
+ if (!operations) throw new TypeError("connector operations are required");
66
+ this.operations = operations;
67
+ }
68
+ };
69
+ function newConnection(client, reference) {
70
+ if (!client) throw new TypeError("connector client is required");
71
+ return new Connection(reference, client);
72
+ }
73
+ function newConnectionWithOperations(operations, reference) {
74
+ return new Connection(reference, operations);
75
+ }
76
+ function newProjectConnection(project, connectionName, createClient) {
77
+ if (!project) throw new TypeError("loaded project is required");
78
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
79
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
80
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
81
+ return newConnection(createClient(project, connectionName), reference);
82
+ }
83
+
84
+ export {
85
+ ConfigSchema,
86
+ decodeCredentials,
87
+ ListClientsInputSchema,
88
+ ClientMetadataSchema,
89
+ ClientsListSchema,
90
+ ConnectorID,
91
+ ProviderID,
92
+ ListClientsBranch,
93
+ ListClientsBranchListed,
94
+ ListClientsBranchProviderRejected,
95
+ ListClientsBranchInvalidResponse,
96
+ ListClientsBranchDefect,
97
+ ListClientsDefinition,
98
+ ListClientsMetadata,
99
+ Connection,
100
+ newConnection,
101
+ newConnectionWithOperations,
102
+ newProjectConnection
103
+ };
@@ -0,0 +1,77 @@
1
+ import { SecretString, CredentialProvider, Query, ConnectionRef } from '@superdurable/connectors-sdk';
2
+ import { z } from 'zod';
3
+
4
+ /** Connector configuration; omitted fields use manifest defaults. */
5
+ interface Config {
6
+ /** HTTPS Campaign Monitor API v3.3 root. Blank uses the displayed default; override only for a compatible private test endpoint. */
7
+ baseUrl?: string;
8
+ /** Maximum duration of one API request as a positive Go duration such as 15s or 1m. Blank uses the displayed default; increase for slow responses. Runtime value in milliseconds. */
9
+ timeoutMs?: number;
10
+ /** Positive maximum complete API response in bytes. Blank uses the displayed default; increase for accounts with many clients. Oversized responses select invalidResponse. */
11
+ maxResponseBytes?: number;
12
+ }
13
+ /** Runtime schema for manifest configuration. */
14
+ declare const ConfigSchema: z.ZodObject<{
15
+ baseUrl: z.ZodOptional<z.ZodString>;
16
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
17
+ maxResponseBytes: z.ZodOptional<z.ZodNumber>;
18
+ }, z.core.$strip>;
19
+ /** Private connector credentials resolved by the host. */
20
+ interface Credentials {
21
+ /** Secret API key. Sign in at https://login.createsend.com/l, then open Profile image > Account settings > API keys. Generate or show and copy the full key; blank makes calls select defect. Rotate it on that page when retired. */
22
+ apiKey: SecretString;
23
+ }
24
+ /** Decode private credential fields for the connector. */
25
+ declare function decodeCredentials(value: unknown): Credentials;
26
+ /** Host-owned source of private connector credentials. */
27
+ type CredentialSource = CredentialProvider<Credentials>;
28
+ /** ListClientsInput selects the account's accessible clients without filters. */
29
+ interface ListClientsInput {
30
+ }
31
+ /** ClientMetadata identifies one Campaign Monitor client without secrets. */
32
+ interface ClientMetadata {
33
+ /** ID is the provider's client identifier. */
34
+ "id": string;
35
+ /** Name is the client display name. */
36
+ "name": string;
37
+ }
38
+ /** ClientsList contains all returned client identities. */
39
+ interface ClientsList {
40
+ /** Clients is the account's accessible client list. */
41
+ "clients": Array<ClientMetadata> | null;
42
+ }
43
+ /** Runtime validator for ListClientsInput. */
44
+ declare const ListClientsInputSchema: z.ZodObject<{}, z.core.$strict>;
45
+ /** Runtime validator for ClientMetadata. */
46
+ declare const ClientMetadataSchema: z.ZodObject<{
47
+ id: z.ZodString;
48
+ name: z.ZodString;
49
+ }, z.core.$strict>;
50
+ /** Runtime validator for ClientsList. */
51
+ declare const ClientsListSchema: z.ZodObject<{
52
+ clients: z.ZodNullable<z.ZodArray<z.ZodObject<{
53
+ id: z.ZodString;
54
+ name: z.ZodString;
55
+ }, z.core.$strict>>>;
56
+ }, z.core.$strict>;
57
+
58
+ /** Typed operations supplied by a client or mock. */
59
+ interface Operations {
60
+ /** Invoke listClients through this connection. */
61
+ listClients(): Query<ListClientsInput, ClientsList>;
62
+ }
63
+ /** Named connector connection kept outside Flow state. */
64
+ declare class Connection<BoundOperations = Operations> {
65
+ /** Stable provider and connection name. */
66
+ readonly reference: ConnectionRef;
67
+ /** Bound provider operations. */
68
+ readonly operations: BoundOperations;
69
+ /** Validate a reference and bind operations. */
70
+ constructor(reference: ConnectionRef, operations: BoundOperations);
71
+ }
72
+ /** Bind a client to a named connection. */
73
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
74
+ /** Bind scripted operations to a named connection. */
75
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
76
+
77
+ export { type ClientsList as C, type ListClientsInput as L, type Operations as O, Connection as a, type Config as b, type Credentials as c, type ClientMetadata as d, ClientMetadataSchema as e, ClientsListSchema as f, ConfigSchema as g, type CredentialSource as h, ListClientsInputSchema as i, decodeCredentials as j, newConnectionWithOperations as k, newConnection as n };
@@ -0,0 +1,93 @@
1
+ import { L as ListClientsInput, C as ClientsList, a as Connection, O as Operations, b as Config, c as Credentials } from './connection-CcQeWY_i.js';
2
+ export { d as ClientMetadata, e as ClientMetadataSchema, f as ClientsListSchema, g as ConfigSchema, h as CredentialSource, i as ListClientsInputSchema, j as decodeCredentials, n as newConnection, k as newConnectionWithOperations } from './connection-CcQeWY_i.js';
3
+ import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, CredentialProvider, Call, QueryAttempt, Failure } from '@superdurable/connectors-sdk';
4
+ import { StepTarget } from '@superdurable/dex';
5
+ import { LoadedProject } from '@superdurable/connectors-sdk/projectconfig';
6
+ import { ProviderRequest, ProviderResponse } from '@superdurable/connectors-sdk/providerhttp';
7
+ import 'zod';
8
+
9
+ /** Stable connector identity. */
10
+ declare const ConnectorID = "campaignmonitor";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "campaignmonitor";
13
+ /** Branch IDs for listClients. */
14
+ declare const ListClientsBranch: {
15
+ readonly Listed: "listed";
16
+ readonly ProviderRejected: "providerRejected";
17
+ readonly InvalidResponse: "invalidResponse";
18
+ readonly Defect: "defect";
19
+ };
20
+ /** Campaign Monitor returned the account's clients. */
21
+ declare const ListClientsBranchListed: "listed";
22
+ /** Campaign Monitor conclusively rejected the request. */
23
+ declare const ListClientsBranchProviderRejected: "providerRejected";
24
+ /** Campaign Monitor returned malformed or oversized JSON. */
25
+ declare const ListClientsBranchInvalidResponse: "invalidResponse";
26
+ /** Connection credentials are invalid. */
27
+ declare const ListClientsBranchDefect: "defect";
28
+ /** Manifest definition for listClients. */
29
+ declare const ListClientsDefinition: QueryDefinition;
30
+ /** Manifest metadata for listClients. */
31
+ declare const ListClientsMetadata: {
32
+ readonly kind: "query";
33
+ readonly idempotency: "none";
34
+ readonly authorization: "required";
35
+ };
36
+
37
+ /** Configuration for the listClients connector Step. */
38
+ interface ListClientsStepConfig<StepInput, OperationInput = ListClientsInput, OperationOutput = ClientsList> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
39
+ /** Named connection supplying this operation. */
40
+ connection: Connection<{
41
+ listClients(): Query<OperationInput, OperationOutput>;
42
+ }>;
43
+ /** Name matching the bound connection. */
44
+ connectionName: string;
45
+ /** Campaign Monitor returned the account's clients. */
46
+ listed: StepTarget<QueryResult<OperationOutput>>;
47
+ /** Campaign Monitor conclusively rejected the request. */
48
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
49
+ /** Campaign Monitor returned malformed or oversized JSON. */
50
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
51
+ /** Connection credentials are invalid. */
52
+ defect?: StepTarget<QueryResult<OperationOutput>>;
53
+ }
54
+ /** Build the listClients Step from a named connection. */
55
+ declare function newListClientsStep<StepInput, OperationInput = ListClientsInput, OperationOutput = ClientsList>(configuration: ListClientsStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
56
+
57
+ /** Open one named Campaign Monitor connection from Dex project configuration. */
58
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
59
+
60
+ /** Optional transport dependency for provider tests and local Dex examples. */
61
+ interface CampaignMonitorClientOptions {
62
+ /** One bounded provider request sender. */ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
63
+ }
64
+ interface ProviderOutcome {
65
+ body?: Uint8Array;
66
+ branch?: string;
67
+ failure?: Failure;
68
+ retry?: boolean;
69
+ retryAfterMs?: number;
70
+ }
71
+ /** Authenticated Campaign Monitor API v3.3 client with call-time API key resolution. */
72
+ declare class CampaignMonitorClient {
73
+ private readonly credentials;
74
+ private readonly baseUrl;
75
+ private readonly timeoutMs;
76
+ private readonly maxResponseBytes;
77
+ private readonly sendRequest;
78
+ /** Validate account configuration without contacting Campaign Monitor. */
79
+ constructor(config: Config, credentials: CredentialProvider<Credentials>, options?: CampaignMonitorClientOptions);
80
+ /** Bind the client discovery Query. */ listClients(): ListClientsOperation;
81
+ /** Send one read and classify transport, HTTP, and response-size outcomes. */
82
+ exchange(call: Call): Promise<ProviderOutcome>;
83
+ }
84
+ /** Read client IDs and names without provider credentials or billing fields. */
85
+ declare class ListClientsOperation implements Query<ListClientsInput, ClientsList> {
86
+ private readonly client;
87
+ /** Bind the provider client. */ constructor(client: CampaignMonitorClient);
88
+ /** Return the manifest-generated operation definition. */ definition(): QueryDefinition;
89
+ /** Read the account's accessible clients. */
90
+ invoke(call: Call, input: ListClientsInput): Promise<QueryAttempt<ClientsList>>;
91
+ }
92
+
93
+ export { CampaignMonitorClient, type CampaignMonitorClientOptions, ClientsList, Config, Connection, ConnectorID, Credentials, ListClientsBranch, ListClientsBranchDefect, ListClientsBranchInvalidResponse, ListClientsBranchListed, ListClientsBranchProviderRejected, ListClientsDefinition, ListClientsInput, ListClientsMetadata, ListClientsOperation, type ListClientsStepConfig, ProviderID, newListClientsStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,204 @@
1
+ import {
2
+ ClientMetadataSchema,
3
+ ClientsListSchema,
4
+ ConfigSchema,
5
+ Connection,
6
+ ConnectorID,
7
+ ListClientsBranch,
8
+ ListClientsBranchDefect,
9
+ ListClientsBranchInvalidResponse,
10
+ ListClientsBranchListed,
11
+ ListClientsBranchProviderRejected,
12
+ ListClientsDefinition,
13
+ ListClientsInputSchema,
14
+ ListClientsMetadata,
15
+ ProviderID,
16
+ decodeCredentials,
17
+ newConnection,
18
+ newConnectionWithOperations,
19
+ newProjectConnection
20
+ } from "./chunk-VKND2LIG.js";
21
+
22
+ // src/generated/steps.ts
23
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
24
+ function newListClientsStep(configuration) {
25
+ const { connection, connectionName, listed, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
26
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
27
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.listClients(), connection: connection.reference, branches: [
28
+ goToBranch("listed", listed),
29
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
30
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
31
+ ...defect ? [goToBranch("defect", defect)] : []
32
+ ] });
33
+ }
34
+
35
+ // src/project.ts
36
+ import { SecretString as SecretString2 } from "@superdurable/connectors-sdk";
37
+ import { z } from "zod";
38
+
39
+ // src/client.ts
40
+ import { SecretString, newQueryBranch, newQueryRetry } from "@superdurable/connectors-sdk";
41
+ import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
42
+ var emptyClients = () => ({ clients: [] });
43
+ var CampaignMonitorClient = class {
44
+ /** Validate account configuration without contacting Campaign Monitor. */
45
+ constructor(config, credentials, options = {}) {
46
+ this.credentials = credentials;
47
+ if (!credentials) throw new TypeError("Campaign Monitor credential source is required");
48
+ this.baseUrl = validateBaseURL(config.baseUrl || "https://api.createsend.com/api/v3.3");
49
+ this.timeoutMs = config.timeoutMs || 15e3;
50
+ this.maxResponseBytes = config.maxResponseBytes || 1048576;
51
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0) throw new TypeError("Campaign Monitor timeout is invalid");
52
+ if (!Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0) throw new TypeError("Campaign Monitor response limit is invalid");
53
+ this.sendRequest = options.send ?? sendProviderRequest;
54
+ }
55
+ credentials;
56
+ baseUrl;
57
+ timeoutMs;
58
+ maxResponseBytes;
59
+ sendRequest;
60
+ /** Bind the client discovery Query. */
61
+ listClients() {
62
+ return new ListClientsOperation(this);
63
+ }
64
+ /** Send one read and classify transport, HTTP, and response-size outcomes. */
65
+ async exchange(call) {
66
+ let apiKey;
67
+ try {
68
+ const resolved = await this.credentials.resolve(call, call.context.cancellationSignal);
69
+ apiKey = resolved.apiKey instanceof SecretString ? resolved.apiKey.reveal() : "";
70
+ } catch {
71
+ return { branch: "defect", failure: failure("AUTHENTICATION", "connection credentials are unavailable or invalid") };
72
+ }
73
+ if (!apiKey || !isHeaderSafeCredential(apiKey)) return { branch: "defect", failure: failure("AUTHENTICATION", "connection credentials are unavailable or invalid") };
74
+ const request = {
75
+ url: `${this.baseUrl}/clients.json`,
76
+ method: "GET",
77
+ headers: { Accept: "application/json", Authorization: `Basic ${Buffer.from(`${apiKey}:`, "utf8").toString("base64")}` },
78
+ maxResponseBytes: this.maxResponseBytes,
79
+ timeoutMs: this.timeoutMs,
80
+ addressPolicy: this.baseUrl.startsWith("https://") ? "publicHTTPS" : "privateNetworkHTTP",
81
+ signal: call.context.cancellationSignal
82
+ };
83
+ let response;
84
+ try {
85
+ response = await this.sendRequest(request);
86
+ } catch (error) {
87
+ if (error instanceof BodyTooLargeError && error.status !== void 0) {
88
+ response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
89
+ if (response.status === 200) return { branch: "invalidResponse", failure: failure("RESPONSE_TOO_LARGE", "Campaign Monitor response exceeded the configured limit") };
90
+ } else return { retry: true, failure: failure("TRANSPORT", "Campaign Monitor request failed") };
91
+ }
92
+ const status = response.status;
93
+ const retryAfter = parseRetryAfter(headerValue(response.headers["retry-after"]));
94
+ if (status === 429) return { retry: true, retryAfterMs: retryAfter, failure: failure("RATE_LIMIT", "Campaign Monitor rate limited the request") };
95
+ if (status === 408 || status >= 500) return { retry: true, retryAfterMs: retryAfter, failure: failure("AVAILABILITY", "Campaign Monitor is temporarily unavailable") };
96
+ if (status !== 200) return { branch: "providerRejected", failure: failure("PROVIDER_REJECTION", `Campaign Monitor rejected HTTP ${status}`) };
97
+ if (response.body.length > this.maxResponseBytes) return { branch: "invalidResponse", failure: failure("RESPONSE_TOO_LARGE", "Campaign Monitor response exceeded the configured limit") };
98
+ return { body: response.body };
99
+ }
100
+ };
101
+ var ListClientsOperation = class {
102
+ /** Bind the provider client. */
103
+ constructor(client) {
104
+ this.client = client;
105
+ }
106
+ client;
107
+ /** Return the manifest-generated operation definition. */
108
+ definition() {
109
+ return ListClientsDefinition;
110
+ }
111
+ /** Read the account's accessible clients. */
112
+ async invoke(call, input) {
113
+ if (!input || typeof input !== "object") return newQueryBranch("defect", emptyClients(), {}, failure("VALIDATION", "client list input is invalid"));
114
+ const result = await this.client.exchange(call);
115
+ if (result.retry) return newQueryRetry(result.failure, result.retryAfterMs);
116
+ if (result.failure) return newQueryBranch(result.branch, emptyClients(), {}, result.failure);
117
+ const document = parseJSON(result.body);
118
+ if (!Array.isArray(document)) return invalid();
119
+ const clients = [];
120
+ for (const item of document) {
121
+ if (!isObject(item) || typeof item.ClientID !== "string" || !item.ClientID || typeof item.Name !== "string" || !item.Name) return invalid();
122
+ clients.push({ id: item.ClientID, name: item.Name });
123
+ }
124
+ return newQueryBranch("listed", { clients });
125
+ }
126
+ };
127
+ function failure(kind, message) {
128
+ return { provider: "campaignmonitor", operation: "listClients", kind, message };
129
+ }
130
+ function invalid() {
131
+ return newQueryBranch("invalidResponse", emptyClients(), {}, failure("PROTOCOL", "Campaign Monitor returned invalid JSON"));
132
+ }
133
+ function isObject(value) {
134
+ return typeof value === "object" && value !== null && !Array.isArray(value);
135
+ }
136
+ function parseJSON(body) {
137
+ try {
138
+ return JSON.parse(Buffer.from(body).toString("utf8"));
139
+ } catch {
140
+ return void 0;
141
+ }
142
+ }
143
+ function headerValue(value) {
144
+ return Array.isArray(value) ? value[0] ?? "" : value ?? "";
145
+ }
146
+
147
+ // src/project.ts
148
+ function newProjectConnection2(project, connectionName) {
149
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
150
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "campaignmonitor" && entry.connectionName === name);
151
+ if (!selected) throw new TypeError("Campaign Monitor project connection is not configured");
152
+ const fields = z.strictObject({ baseUrl: z.string().optional(), timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
153
+ const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
154
+ const config = {
155
+ ...fields.baseUrl ? { baseUrl: fields.baseUrl } : {},
156
+ ...timeoutMs !== void 0 ? { timeoutMs } : {},
157
+ ...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
158
+ };
159
+ const credentials = {
160
+ async resolve(_call, signal) {
161
+ const privateFields = await loadedProject.resolveCredential("campaignmonitor", name, signal);
162
+ if (typeof privateFields.api_key !== "string") throw new TypeError("Campaign Monitor API Key is unavailable");
163
+ return { apiKey: new SecretString2(privateFields.api_key) };
164
+ }
165
+ };
166
+ return new CampaignMonitorClient(config, credentials);
167
+ });
168
+ }
169
+ function parseDurationMilliseconds(value) {
170
+ let remaining = value;
171
+ let milliseconds = 0;
172
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
173
+ while (remaining) {
174
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
175
+ if (!part) throw new TypeError("Campaign Monitor timeout must be a positive Go duration");
176
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
177
+ remaining = remaining.slice(part[0].length);
178
+ }
179
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Campaign Monitor timeout must resolve to positive whole milliseconds");
180
+ return milliseconds;
181
+ }
182
+ export {
183
+ CampaignMonitorClient,
184
+ ClientMetadataSchema,
185
+ ClientsListSchema,
186
+ ConfigSchema,
187
+ Connection,
188
+ ConnectorID,
189
+ ListClientsBranch,
190
+ ListClientsBranchDefect,
191
+ ListClientsBranchInvalidResponse,
192
+ ListClientsBranchListed,
193
+ ListClientsBranchProviderRejected,
194
+ ListClientsDefinition,
195
+ ListClientsInputSchema,
196
+ ListClientsMetadata,
197
+ ListClientsOperation,
198
+ ProviderID,
199
+ decodeCredentials,
200
+ newConnection,
201
+ newConnectionWithOperations,
202
+ newListClientsStep,
203
+ newProjectConnection2 as newProjectConnection
204
+ };
package/dist/mock.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import { MockQuery, Case } from '@superdurable/connectors-sdk/connectormock';
2
+ import { Failure } from '@superdurable/connectors-sdk';
3
+ import { O as Operations, a as Connection, L as ListClientsInput, C as ClientsList, d as ClientMetadata } from './connection-CcQeWY_i.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for ListClientsInput in scripted cases. */
7
+ declare const emptyListClientsInput: ListClientsInput;
8
+ /** Go zero value for ClientMetadata in scripted cases. */
9
+ declare const emptyClientMetadata: ClientMetadata;
10
+ /** Go zero value for ClientsList in scripted cases. */
11
+ declare const emptyClientsList: ClientsList;
12
+ /** Script the listed branch. */
13
+ declare function listClientsListed(value: ClientsList, failure?: Failure): Case<ClientsList>;
14
+ /** Script the providerRejected branch. */
15
+ declare function listClientsProviderRejected(value: ClientsList, failure?: Failure): Case<ClientsList>;
16
+ /** Script the invalidResponse branch. */
17
+ declare function listClientsInvalidResponse(value: ClientsList, failure?: Failure): Case<ClientsList>;
18
+ /** Script the defect branch. */
19
+ declare function listClientsDefect(value: ClientsList, failure?: Failure): Case<ClientsList>;
20
+ /** Script a safe retry of listClients. */
21
+ declare function listClientsRetry(failure: Failure, retryAfterMs?: number): Case<ClientsList>;
22
+ /** Manifest scenario listedDefault for listClients. */
23
+ declare function listClientsListedDefault(): Case<ClientsList>;
24
+ /** Default listClients scenario. */
25
+ declare function listClientsDefault(): Case<ClientsList>;
26
+ /** Scripted operations and manifest defaults for this connector. */
27
+ declare class GeneratedMock implements Operations {
28
+ #private;
29
+ constructor(connectionName: string);
30
+ connection(): Connection;
31
+ listClients(): MockQuery<ListClientsInput, ClientsList>;
32
+ assertNoFailures(): void;
33
+ }
34
+
35
+ export { GeneratedMock, GeneratedMock as Mock, emptyClientMetadata, emptyClientsList, emptyListClientsInput, listClientsDefault, listClientsDefect, listClientsInvalidResponse, listClientsListed, listClientsListedDefault, listClientsProviderRejected, listClientsRetry };
package/dist/mock.js ADDED
@@ -0,0 +1,72 @@
1
+ import {
2
+ ClientMetadataSchema,
3
+ ClientsListSchema,
4
+ ListClientsDefinition,
5
+ ListClientsInputSchema,
6
+ ProviderID,
7
+ newConnectionWithOperations
8
+ } from "./chunk-VKND2LIG.js";
9
+
10
+ // src/generated/mock.ts
11
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
12
+ var emptyListClientsInput = ListClientsInputSchema.parse({});
13
+ var emptyClientMetadata = ClientMetadataSchema.parse({
14
+ "id": "",
15
+ "name": ""
16
+ });
17
+ var emptyClientsList = ClientsListSchema.parse({
18
+ "clients": []
19
+ });
20
+ function listClientsListed(value, failure) {
21
+ return branchCase("listed", value, failure);
22
+ }
23
+ function listClientsProviderRejected(value, failure) {
24
+ return branchCase("providerRejected", value, failure);
25
+ }
26
+ function listClientsInvalidResponse(value, failure) {
27
+ return branchCase("invalidResponse", value, failure);
28
+ }
29
+ function listClientsDefect(value, failure) {
30
+ return branchCase("defect", value, failure);
31
+ }
32
+ function listClientsRetry(failure, retryAfterMs = 0) {
33
+ return retryCase(failure, retryAfterMs);
34
+ }
35
+ function listClientsListedDefault() {
36
+ const value = ClientsListSchema.parse({ "clients": [{ "id": "sample-client-id", "name": "Sample Client" }] });
37
+ return branchCase("listed", value);
38
+ }
39
+ function listClientsDefault() {
40
+ return listClientsListedDefault();
41
+ }
42
+ var GeneratedMock = class {
43
+ #listClients;
44
+ #connection;
45
+ constructor(connectionName) {
46
+ this.#listClients = newQuery(ListClientsDefinition).default(listClientsDefault());
47
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
48
+ }
49
+ connection() {
50
+ return this.#connection;
51
+ }
52
+ listClients() {
53
+ return this.#listClients;
54
+ }
55
+ assertNoFailures() {
56
+ this.#listClients.assertNoFailures();
57
+ }
58
+ };
59
+ export {
60
+ GeneratedMock,
61
+ GeneratedMock as Mock,
62
+ emptyClientMetadata,
63
+ emptyClientsList,
64
+ emptyListClientsInput,
65
+ listClientsDefault,
66
+ listClientsDefect,
67
+ listClientsInvalidResponse,
68
+ listClientsListed,
69
+ listClientsListedDefault,
70
+ listClientsProviderRejected,
71
+ listClientsRetry
72
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-campaignmonitor",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "license": "MIT",
5
+ "description": "Campaign Monitor connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/campaignmonitor/typescript"
10
+ },
11
+ "type": "module",
12
+ "engines": {
13
+ "node": "^22.0.0 || ^24.0.0"
14
+ },
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "types": "./dist/index.d.ts",
20
+ "import": "./dist/index.js"
21
+ },
22
+ "./mock": {
23
+ "types": "./dist/mock.d.ts",
24
+ "import": "./dist/mock.js"
25
+ },
26
+ "./dex-connector.json": "./dex-connector.json"
27
+ },
28
+ "files": [
29
+ "dist",
30
+ "README.md",
31
+ "LICENSE",
32
+ "dex-connector.json"
33
+ ],
34
+ "scripts": {
35
+ "prepack": "npm run build",
36
+ "build": "tsup src/index.ts src/mock.ts --format esm --dts --clean",
37
+ "typecheck": "tsc --noEmit",
38
+ "lint": "eslint src test examples",
39
+ "test": "vitest run --exclude test/integration/**",
40
+ "test:integration": "vitest run test/integration/*.integration.test.ts",
41
+ "example:worker": "tsx examples/client-discovery/worker.ts",
42
+ "example:start": "tsx examples/client-discovery/start.ts",
43
+ "check": "npm run typecheck && npm run lint && npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@superdurable/connectors-sdk": "0.1.1",
47
+ "@superdurable/dex": ">=1.28.0",
48
+ "zod": "^4.1.0"
49
+ },
50
+ "devDependencies": {
51
+ "@eslint/js": "^9.0.0",
52
+ "@types/node": "^22.0.0",
53
+ "eslint": "^9.0.0",
54
+ "tsup": "^8.0.0",
55
+ "tsx": "^4.23.15",
56
+ "typescript": "^5.9.0",
57
+ "typescript-eslint": "^8.0.0",
58
+ "vitest": "^3.0.0",
59
+ "yaml": "^2.9.1"
60
+ }
61
+ }