@superdurable/connector-adobe-marketo 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,3 @@
1
- # Temporary Holding Version
1
+ # Marketo 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
+ Implements `getLead` for a lead ID and names. Go-recorded conformance covers exact requests, branches, retries, and outputs. Configure a Marketo API-Only user and Custom service using the [connection guide](../README.md). The [runnable Dex Flow](examples/lead-inspection/README.md) exercises the package. Live Marketo authorization remains unverified.
@@ -0,0 +1,65 @@
1
+ {
2
+ "connectorId": "adobe-marketo",
3
+ "releaseTag": "connectors/adobe/marketo/go/v0.1.0",
4
+ "package": {
5
+ "ecosystem": "npm",
6
+ "name": "@superdurable/connector-adobe-marketo",
7
+ "version": "0.1.0"
8
+ },
9
+ "factories": [
10
+ {
11
+ "name": "newGetLeadStep",
12
+ "kind": "query",
13
+ "operationId": "getLead",
14
+ "inputType": "GetLeadInput",
15
+ "description": "Read one lead's ID and names by Marketo lead ID without returning email or other profile fields.",
16
+ "fields": {
17
+ "stepType": "stepType",
18
+ "annotations": "annotations",
19
+ "connectionName": "connectionName",
20
+ "resultAttribute": "resultAttribute"
21
+ },
22
+ "branches": [
23
+ {
24
+ "id": "found",
25
+ "field": "found",
26
+ "optional": false
27
+ },
28
+ {
29
+ "id": "notFound",
30
+ "field": "notFound",
31
+ "optional": true
32
+ },
33
+ {
34
+ "id": "providerRejected",
35
+ "field": "providerRejected",
36
+ "optional": true
37
+ },
38
+ {
39
+ "id": "invalidResponse",
40
+ "field": "invalidResponse",
41
+ "optional": true
42
+ },
43
+ {
44
+ "id": "defect",
45
+ "field": "defect",
46
+ "optional": true
47
+ }
48
+ ],
49
+ "inputSchema": {
50
+ "additionalProperties": false,
51
+ "description": "GetLeadInput selects one non-secret positive Marketo lead ID.",
52
+ "properties": {
53
+ "leadId": {
54
+ "description": "LeadID is the ID shown on a lead detail page or returned by a lead query.",
55
+ "type": "integer"
56
+ }
57
+ },
58
+ "required": [
59
+ "leadId"
60
+ ],
61
+ "type": "object"
62
+ }
63
+ }
64
+ ]
65
+ }
@@ -0,0 +1,134 @@
1
+ // src/generated/models.ts
2
+ import { z } from "zod";
3
+ import { SecretString } from "@superdurable/connectors-sdk";
4
+ var ConfigSchema = z.object({
5
+ "restEndpoint": z.string(),
6
+ "tokenEndpoint": z.string(),
7
+ "timeoutMs": z.number().int().optional(),
8
+ "maxResponseBytes": z.number().int().optional()
9
+ });
10
+ function decodeCredentials(value) {
11
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
12
+ const fields = value;
13
+ const allowed = /* @__PURE__ */ new Set(["access_token", "client_id", "client_secret"]);
14
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
15
+ if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new TypeError("credential access_token has an invalid type");
16
+ if (fields["client_id"] != null && !(typeof fields["client_id"] === "string")) throw new TypeError("credential client_id has an invalid type");
17
+ if (fields["client_secret"] != null && !(typeof fields["client_secret"] === "string")) throw new TypeError("credential client_secret has an invalid type");
18
+ const credentials = {};
19
+ if (!fields["client_id"]) throw new TypeError("credential client_id is required");
20
+ credentials.clientId = fields["client_id"] ?? "";
21
+ if (!fields["client_secret"]) throw new TypeError("credential client_secret is required");
22
+ credentials.clientSecret = new SecretString(fields["client_secret"] ?? "");
23
+ credentials.accessToken = new SecretString(fields["access_token"] ?? "");
24
+ return credentials;
25
+ }
26
+ function decodeSharedCredentials(value) {
27
+ if (!value || typeof value !== "object" || Array.isArray(value)) throw new TypeError("credential fields are invalid");
28
+ const fields = value;
29
+ const allowed = /* @__PURE__ */ new Set(["access_token", "client_id", "client_secret"]);
30
+ if (Object.keys(fields).some((key) => !allowed.has(key))) throw new TypeError("stored credential does not match the connector credential fields");
31
+ if (fields["access_token"] != null && !(typeof fields["access_token"] === "string")) throw new TypeError("credential access_token has an invalid type");
32
+ if (fields["client_id"] != null && !(typeof fields["client_id"] === "string")) throw new TypeError("credential client_id has an invalid type");
33
+ if (fields["client_secret"] != null && !(typeof fields["client_secret"] === "string")) throw new TypeError("credential client_secret has an invalid type");
34
+ const credentials = {};
35
+ if (!fields["client_id"]) throw new TypeError("credential client_id is required");
36
+ credentials.clientId = fields["client_id"] ?? "";
37
+ credentials.clientSecret = new SecretString(fields["client_secret"] ?? "");
38
+ if (!fields["access_token"]) throw new TypeError("credential access_token is required");
39
+ credentials.accessToken = new SecretString(fields["access_token"] ?? "");
40
+ return credentials;
41
+ }
42
+ var GetLeadInputSchema = z.strictObject({
43
+ "leadId": z.number().int()
44
+ });
45
+ var LeadProfileSchema = z.strictObject({
46
+ "id": z.number().int(),
47
+ "firstName": z.string(),
48
+ "lastName": z.string()
49
+ });
50
+
51
+ // src/generated/definitions.ts
52
+ var ConnectorID = "adobe-marketo";
53
+ var ProviderID = "adobe";
54
+ var GetLeadBranch = {
55
+ Found: "found",
56
+ NotFound: "notFound",
57
+ ProviderRejected: "providerRejected",
58
+ InvalidResponse: "invalidResponse",
59
+ Defect: "defect"
60
+ };
61
+ var GetLeadBranchFound = GetLeadBranch.Found;
62
+ var GetLeadBranchNotFound = GetLeadBranch.NotFound;
63
+ var GetLeadBranchProviderRejected = GetLeadBranch.ProviderRejected;
64
+ var GetLeadBranchInvalidResponse = GetLeadBranch.InvalidResponse;
65
+ var GetLeadBranchDefect = GetLeadBranch.Defect;
66
+ var GetLeadDefinition = {
67
+ operation: { connectorId: ConnectorID, operationId: "getLead" },
68
+ branches: [
69
+ { id: "found", description: "Marketo returned the selected lead." },
70
+ { id: "notFound", description: "Marketo returned no lead for the ID.", optional: true },
71
+ { id: "providerRejected", description: "Marketo conclusively rejected the request.", optional: true },
72
+ { id: "invalidResponse", description: "Marketo returned malformed or oversized JSON.", optional: true },
73
+ { id: "defect", description: "Local input or connection configuration is invalid.", optional: true }
74
+ ],
75
+ stepDefaults: { executeMethodTimeoutMs: 3e4, executeDurability: "async" }
76
+ };
77
+ var GetLeadMetadata = { kind: "query", idempotency: "none", authorization: "required" };
78
+
79
+ // src/generated/connection.ts
80
+ import { ConnectionRefSchema } from "@superdurable/connectors-sdk";
81
+ import { newRefreshingCredentialProvider } from "@superdurable/connectors-sdk/projectconfig";
82
+ var Connection = class {
83
+ /** Stable provider and connection name. */
84
+ reference;
85
+ /** Bound provider operations. */
86
+ operations;
87
+ /** Validate a reference and bind operations. */
88
+ constructor(reference, operations) {
89
+ this.reference = ConnectionRefSchema.parse(reference);
90
+ if (this.reference.provider !== ProviderID) throw new TypeError("connection provider differs from the manifest");
91
+ if (!operations) throw new TypeError("connector operations are required");
92
+ this.operations = operations;
93
+ }
94
+ };
95
+ function newConnection(client, reference) {
96
+ if (!client) throw new TypeError("connector client is required");
97
+ return new Connection(reference, client);
98
+ }
99
+ function newConnectionWithOperations(operations, reference) {
100
+ return new Connection(reference, operations);
101
+ }
102
+ function newProjectConnection(project, connectionName, createClient) {
103
+ if (!project) throw new TypeError("loaded project is required");
104
+ const reference = ConnectionRefSchema.parse({ provider: ProviderID, name: connectionName });
105
+ const selected = project.configuration.connections.find((entry) => entry.connectorId === ConnectorID && entry.connectionName === connectionName);
106
+ if (!selected || selected.provider !== ProviderID) throw new TypeError("project connection is not configured");
107
+ return newConnection(createClient(project, connectionName), reference);
108
+ }
109
+ function newProjectCredentialProvider(project, connectionName, decode, encode, decodeShared) {
110
+ return newRefreshingCredentialProvider(project.connections, { connectorId: ConnectorID, connectionName }, decode, encode, decodeShared);
111
+ }
112
+
113
+ export {
114
+ ConfigSchema,
115
+ decodeCredentials,
116
+ decodeSharedCredentials,
117
+ GetLeadInputSchema,
118
+ LeadProfileSchema,
119
+ ConnectorID,
120
+ ProviderID,
121
+ GetLeadBranch,
122
+ GetLeadBranchFound,
123
+ GetLeadBranchNotFound,
124
+ GetLeadBranchProviderRejected,
125
+ GetLeadBranchInvalidResponse,
126
+ GetLeadBranchDefect,
127
+ GetLeadDefinition,
128
+ GetLeadMetadata,
129
+ Connection,
130
+ newConnection,
131
+ newConnectionWithOperations,
132
+ newProjectConnection,
133
+ newProjectCredentialProvider
134
+ };
@@ -0,0 +1,81 @@
1
+ import { RefreshingCredentialProvider, SecretString, Query, ConnectionRef } from '@superdurable/connectors-sdk';
2
+ import { z } from 'zod';
3
+
4
+ /** Connector configuration; omitted fields use manifest defaults. */
5
+ interface Config {
6
+ /** Non-secret subscription REST endpoint from https://app.marketo.com/ > Admin > Integration > Web Services > REST API > Endpoint. Copy the complete HTTPS URL ending in /rest, such as https://123-ABC-456.mktorest.com/rest; blank prevents requests. */
7
+ restEndpoint: string;
8
+ /** Non-secret Identity URL from https://app.marketo.com/ > Admin > Integration > Web Services > REST API > Identity, followed by /oauth/token. Enter a complete HTTPS URL ending in /identity/oauth/token on the same subscription host as restEndpoint; blank prevents token minting. */
9
+ tokenEndpoint: string;
10
+ /** Maximum duration of one lead read as a positive Go duration. Leave blank for the displayed default; increase only for slow Marketo responses. Runtime value in milliseconds. */
11
+ timeoutMs?: number;
12
+ /** Maximum bytes in one complete lead response as a positive integer. Leave blank for the displayed default; increase only for unusually large responses. */
13
+ maxResponseBytes?: number;
14
+ }
15
+ /** Runtime schema for manifest configuration. */
16
+ declare const ConfigSchema: z.ZodObject<{
17
+ restEndpoint: z.ZodString;
18
+ tokenEndpoint: z.ZodString;
19
+ timeoutMs: z.ZodOptional<z.ZodNumber>;
20
+ maxResponseBytes: z.ZodOptional<z.ZodNumber>;
21
+ }, z.core.$strip>;
22
+ /** Private connector credentials resolved by the host. */
23
+ interface Credentials {
24
+ /** Secret short-lived token derived from the custom service's Client ID and Client Secret. Leave blank for automatic minting; never paste a token. */
25
+ accessToken?: SecretString;
26
+ /** Non-secret Client ID from https://app.marketo.com/ > Admin > Integration > LaunchPoint > your Custom service > View Details. Copy the complete value; blank prevents token minting. */
27
+ clientId: string;
28
+ /** Secret Client Secret from https://app.marketo.com/ > Admin > Integration > LaunchPoint > your Custom service > View Details. Store only in Dex Web; blank prevents token minting. */
29
+ clientSecret: SecretString;
30
+ }
31
+ /** Decode private credential fields for the connector. */
32
+ declare function decodeCredentials(value: unknown): Credentials;
33
+ /** Decode shared credential fields for the connector. */
34
+ declare function decodeSharedCredentials(value: unknown): Credentials;
35
+ /** Host-owned source of private connector credentials. */
36
+ type CredentialSource = RefreshingCredentialProvider<Credentials>;
37
+ /** GetLeadInput selects one non-secret positive Marketo lead ID. */
38
+ interface GetLeadInput {
39
+ /** LeadID is the ID shown on a lead detail page or returned by a lead query. */
40
+ "leadId": number;
41
+ }
42
+ /** LeadProfile contains the selected ID and optional names, excluding email and other fields. */
43
+ interface LeadProfile {
44
+ /** ID is the Marketo lead ID. */
45
+ "id": number;
46
+ /** FirstName is the lead's first name, or empty when absent. */
47
+ "firstName": string;
48
+ /** LastName is the lead's last name, or empty when absent. */
49
+ "lastName": string;
50
+ }
51
+ /** Runtime validator for GetLeadInput. */
52
+ declare const GetLeadInputSchema: z.ZodObject<{
53
+ leadId: z.ZodNumber;
54
+ }, z.core.$strict>;
55
+ /** Runtime validator for LeadProfile. */
56
+ declare const LeadProfileSchema: z.ZodObject<{
57
+ id: z.ZodNumber;
58
+ firstName: z.ZodString;
59
+ lastName: z.ZodString;
60
+ }, z.core.$strict>;
61
+
62
+ /** Typed operations supplied by a client or mock. */
63
+ interface Operations {
64
+ /** Invoke getLead through this connection. */
65
+ getLead(): Query<GetLeadInput, LeadProfile>;
66
+ }
67
+ /** Named connector connection kept outside Flow state. */
68
+ declare class Connection<BoundOperations = Operations> {
69
+ /** Stable provider and connection name. */
70
+ readonly reference: ConnectionRef;
71
+ /** Bound provider operations. */
72
+ readonly operations: BoundOperations;
73
+ /** Validate a reference and bind operations. */
74
+ constructor(reference: ConnectionRef, operations: BoundOperations);
75
+ }
76
+ /** Bind a client to a named connection. */
77
+ declare function newConnection(client: Operations, reference: ConnectionRef): Connection;
78
+ /** Bind scripted operations to a named connection. */
79
+ declare function newConnectionWithOperations(operations: Operations, reference: ConnectionRef): Connection;
80
+
81
+ export { Connection as C, type GetLeadInput as G, type LeadProfile as L, type Operations as O, type Config as a, type CredentialSource as b, ConfigSchema as c, type Credentials as d, GetLeadInputSchema as e, LeadProfileSchema as f, decodeCredentials as g, decodeSharedCredentials as h, newConnectionWithOperations as i, newConnection as n };
@@ -0,0 +1,98 @@
1
+ import { G as GetLeadInput, L as LeadProfile, C as Connection, O as Operations, a as Config, b as CredentialSource } from './connection-lQR7OxHI.js';
2
+ export { c as ConfigSchema, d as Credentials, e as GetLeadInputSchema, f as LeadProfileSchema, g as decodeCredentials, h as decodeSharedCredentials, n as newConnection, i as newConnectionWithOperations } from './connection-lQR7OxHI.js';
3
+ import { QueryDefinition, QueryStepConfig, Query, QueryResult, QueryStep, Call, QueryAttempt } 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 = "adobe-marketo";
11
+ /** Provider identity for named connections. */
12
+ declare const ProviderID = "adobe";
13
+ /** Branch IDs for getLead. */
14
+ declare const GetLeadBranch: {
15
+ readonly Found: "found";
16
+ readonly NotFound: "notFound";
17
+ readonly ProviderRejected: "providerRejected";
18
+ readonly InvalidResponse: "invalidResponse";
19
+ readonly Defect: "defect";
20
+ };
21
+ /** Marketo returned the selected lead. */
22
+ declare const GetLeadBranchFound: "found";
23
+ /** Marketo returned no lead for the ID. */
24
+ declare const GetLeadBranchNotFound: "notFound";
25
+ /** Marketo conclusively rejected the request. */
26
+ declare const GetLeadBranchProviderRejected: "providerRejected";
27
+ /** Marketo returned malformed or oversized JSON. */
28
+ declare const GetLeadBranchInvalidResponse: "invalidResponse";
29
+ /** Local input or connection configuration is invalid. */
30
+ declare const GetLeadBranchDefect: "defect";
31
+ /** Manifest definition for getLead. */
32
+ declare const GetLeadDefinition: QueryDefinition;
33
+ /** Manifest metadata for getLead. */
34
+ declare const GetLeadMetadata: {
35
+ readonly kind: "query";
36
+ readonly idempotency: "none";
37
+ readonly authorization: "required";
38
+ };
39
+
40
+ /** Configuration for the getLead connector Step. */
41
+ interface GetLeadStepConfig<StepInput, OperationInput = GetLeadInput, OperationOutput = LeadProfile> extends Omit<QueryStepConfig<StepInput, OperationInput, OperationOutput>, 'operation' | 'connection' | 'branches'> {
42
+ /** Named connection supplying this operation. */
43
+ connection: Connection<{
44
+ getLead(): Query<OperationInput, OperationOutput>;
45
+ }>;
46
+ /** Name matching the bound connection. */
47
+ connectionName: string;
48
+ /** Marketo returned the selected lead. */
49
+ found: StepTarget<QueryResult<OperationOutput>>;
50
+ /** Marketo returned no lead for the ID. */
51
+ notFound?: StepTarget<QueryResult<OperationOutput>>;
52
+ /** Marketo conclusively rejected the request. */
53
+ providerRejected?: StepTarget<QueryResult<OperationOutput>>;
54
+ /** Marketo returned malformed or oversized JSON. */
55
+ invalidResponse?: StepTarget<QueryResult<OperationOutput>>;
56
+ /** Local input or connection configuration is invalid. */
57
+ defect?: StepTarget<QueryResult<OperationOutput>>;
58
+ }
59
+ /** Build the getLead Step from a named connection. */
60
+ declare function newGetLeadStep<StepInput, OperationInput = GetLeadInput, OperationOutput = LeadProfile>(configuration: GetLeadStepConfig<StepInput, OperationInput, OperationOutput>): QueryStep<StepInput, OperationInput, OperationOutput>;
61
+
62
+ /** Open one named Marketo connection from Dex project configuration. */
63
+ declare function newProjectConnection(project: LoadedProject, connectionName: string): Connection<Operations>;
64
+
65
+ /** Injectable provider sender for tests and local applications. */
66
+ interface MarketoClientOptions {
67
+ /** Provider sender; omitted uses the SDK transport. */ send?: (request: ProviderRequest) => Promise<ProviderResponse>;
68
+ }
69
+ interface Exchange {
70
+ status: number;
71
+ body: Uint8Array;
72
+ retryAfterMs: number;
73
+ error?: 'credential' | 'request' | 'tooLarge';
74
+ }
75
+ /** Authenticated Marketo client for selected lead fields. */
76
+ declare class MarketoClient {
77
+ private readonly credentials;
78
+ private readonly restEndpoint;
79
+ private readonly timeoutMs;
80
+ private readonly maxResponseBytes;
81
+ private readonly send;
82
+ private readonly refreshDriver;
83
+ /** Validate subscription endpoints without contacting Marketo. */
84
+ constructor(config: Config, credentials: CredentialSource, options?: MarketoClientOptions);
85
+ /** Bind the getLead Query. */ getLead(): GetLeadOperation;
86
+ /** Resolve the token and perform one bounded lead lookup. */
87
+ get(call: Call, leadID: number): Promise<Exchange>;
88
+ }
89
+ /** Read one lead's ID and names from Marketo. */
90
+ declare class GetLeadOperation implements Query<GetLeadInput, LeadProfile> {
91
+ private readonly client;
92
+ /** Bind one Marketo client. */ constructor(client: MarketoClient);
93
+ /** Return the generated Query contract. */ definition(): QueryDefinition;
94
+ /** Classify lead lookup outcomes consistently with Go. */
95
+ invoke(call: Call, input: GetLeadInput): Promise<QueryAttempt<LeadProfile>>;
96
+ }
97
+
98
+ export { Config, Connection, ConnectorID, CredentialSource, GetLeadBranch, GetLeadBranchDefect, GetLeadBranchFound, GetLeadBranchInvalidResponse, GetLeadBranchNotFound, GetLeadBranchProviderRejected, GetLeadDefinition, GetLeadInput, GetLeadMetadata, GetLeadOperation, type GetLeadStepConfig, LeadProfile, MarketoClient, type MarketoClientOptions, ProviderID, newGetLeadStep, newProjectConnection };
package/dist/index.js ADDED
@@ -0,0 +1,306 @@
1
+ import {
2
+ ConfigSchema,
3
+ Connection,
4
+ ConnectorID,
5
+ GetLeadBranch,
6
+ GetLeadBranchDefect,
7
+ GetLeadBranchFound,
8
+ GetLeadBranchInvalidResponse,
9
+ GetLeadBranchNotFound,
10
+ GetLeadBranchProviderRejected,
11
+ GetLeadDefinition,
12
+ GetLeadInputSchema,
13
+ GetLeadMetadata,
14
+ LeadProfileSchema,
15
+ ProviderID,
16
+ decodeCredentials,
17
+ decodeSharedCredentials,
18
+ newConnection,
19
+ newConnectionWithOperations,
20
+ newProjectConnection,
21
+ newProjectCredentialProvider
22
+ } from "./chunk-N4RSR7PL.js";
23
+
24
+ // src/generated/steps.ts
25
+ import { goToBranch, newQueryStep } from "@superdurable/connectors-sdk";
26
+ function newGetLeadStep(configuration) {
27
+ const { connection, connectionName, found, notFound, providerRejected, invalidResponse, defect, ...stepConfiguration } = configuration;
28
+ if (!connection || connection.reference.name !== connectionName) throw new TypeError("Step connection name differs from the bound connection");
29
+ return newQueryStep({ ...stepConfiguration, operation: connection.operations.getLead(), connection: connection.reference, branches: [
30
+ goToBranch("found", found),
31
+ ...notFound ? [goToBranch("notFound", notFound)] : [],
32
+ ...providerRejected ? [goToBranch("providerRejected", providerRejected)] : [],
33
+ ...invalidResponse ? [goToBranch("invalidResponse", invalidResponse)] : [],
34
+ ...defect ? [goToBranch("defect", defect)] : []
35
+ ] });
36
+ }
37
+
38
+ // src/project.ts
39
+ import { z } from "zod";
40
+
41
+ // src/client.ts
42
+ import { ReauthorizationRequiredError, SecretString, newQueryBranch, newQueryRetry, resolveCredential } from "@superdurable/connectors-sdk";
43
+ import { ManifestCredentialRefreshDriver } from "@superdurable/connectors-sdk/oauthtoken";
44
+ import { BodyTooLargeError, isHeaderSafeCredential, parseRetryAfter, sendProviderRequest, validateBaseURL } from "@superdurable/connectors-sdk/providerhttp";
45
+
46
+ // src/generated/refresh.ts
47
+ var Authorization = {
48
+ "clientCredentials": {
49
+ "clientIDCredential": "client_id",
50
+ "clientSecretCredential": "client_secret",
51
+ "credentialMappings": [
52
+ {
53
+ "credential": "access_token",
54
+ "source": "access_token"
55
+ }
56
+ ],
57
+ "missingExpiry": "reject",
58
+ "storedMissingExpiry": "refresh",
59
+ "terminalErrorCodes": [
60
+ "invalid_client",
61
+ "unauthorized_client",
62
+ "invalid_scope"
63
+ ],
64
+ "tokenEndpoint": {
65
+ "fromSetting": "tokenEndpoint"
66
+ },
67
+ "tokenEndpointAuthMethod": "client_secret_post",
68
+ "tokenExchangeTimeout": "8s"
69
+ },
70
+ "fields": [
71
+ {
72
+ "name": "client_id",
73
+ "required": true,
74
+ "type": "string"
75
+ },
76
+ {
77
+ "name": "client_secret",
78
+ "required": true,
79
+ "type": "secretString"
80
+ },
81
+ {
82
+ "name": "access_token",
83
+ "required": false,
84
+ "type": "secretString"
85
+ }
86
+ ],
87
+ "refreshable": true,
88
+ "type": "apiKey"
89
+ };
90
+ var CredentialFields = {
91
+ "access_token": "accessToken",
92
+ "client_id": "clientId",
93
+ "client_secret": "clientSecret"
94
+ };
95
+
96
+ // src/client.ts
97
+ var emptyProfile = () => ({ id: 0, firstName: "", lastName: "" });
98
+ function subscriptionURL(value, suffix) {
99
+ const checked = validateBaseURL(value);
100
+ const parsed = new URL(checked);
101
+ const isSubscription = parsed.protocol === "https:" && parsed.hostname.toLowerCase().endsWith(".mktorest.com");
102
+ if (!isSubscription || parsed.pathname !== suffix || parsed.search || parsed.hash || parsed.username || parsed.password || parsed.port)
103
+ throw new TypeError(`Marketo endpoint must end in ${suffix} on a subscription host`);
104
+ return checked.replace(/\/$/, "");
105
+ }
106
+ var MarketoClient = class {
107
+ /** Validate subscription endpoints without contacting Marketo. */
108
+ constructor(config, credentials, options = {}) {
109
+ this.credentials = credentials;
110
+ if (!config || !credentials) throw new TypeError("Marketo configuration and credentials are required");
111
+ this.restEndpoint = subscriptionURL(config.restEndpoint, "/rest");
112
+ const tokenEndpoint = subscriptionURL(config.tokenEndpoint, "/identity/oauth/token");
113
+ if (new URL(this.restEndpoint).hostname !== new URL(tokenEndpoint).hostname)
114
+ throw new TypeError("Marketo REST and Identity URLs must use the same subscription host");
115
+ this.timeoutMs = config.timeoutMs ?? 15e3;
116
+ this.maxResponseBytes = config.maxResponseBytes ?? 1048576;
117
+ if (!Number.isSafeInteger(this.timeoutMs) || this.timeoutMs <= 0 || !Number.isSafeInteger(this.maxResponseBytes) || this.maxResponseBytes <= 0)
118
+ throw new TypeError("Marketo request limits must be positive integers");
119
+ this.send = options.send ?? sendProviderRequest;
120
+ this.refreshDriver = new ManifestCredentialRefreshDriver({
121
+ providerName: "Adobe Marketo Engage",
122
+ auth: Authorization,
123
+ credentialFields: CredentialFields,
124
+ settings: { tokenEndpoint: config.tokenEndpoint }
125
+ });
126
+ }
127
+ credentials;
128
+ restEndpoint;
129
+ timeoutMs;
130
+ maxResponseBytes;
131
+ send;
132
+ refreshDriver;
133
+ /** Bind the getLead Query. */
134
+ getLead() {
135
+ return new GetLeadOperation(this);
136
+ }
137
+ /** Resolve the token and perform one bounded lead lookup. */
138
+ async get(call, leadID) {
139
+ let token;
140
+ try {
141
+ const credentials = await resolveCredential(this.credentials, call, this.refreshDriver, call.context.cancellationSignal);
142
+ token = credentials.accessToken instanceof SecretString ? credentials.accessToken.reveal() : "";
143
+ } catch (error) {
144
+ return emptyExchange(error instanceof ReauthorizationRequiredError ? "credential" : "request");
145
+ }
146
+ if (!isHeaderSafeCredential(token)) return emptyExchange("credential");
147
+ const query = new URLSearchParams({ fields: "id,firstName,lastName" });
148
+ const request = {
149
+ url: `${this.restEndpoint}/v1/lead/${leadID}.json?${query}`,
150
+ method: "GET",
151
+ headers: { Accept: "application/json", Authorization: `Bearer ${token}` },
152
+ maxResponseBytes: this.maxResponseBytes,
153
+ timeoutMs: this.timeoutMs,
154
+ addressPolicy: "publicHTTPS",
155
+ signal: call.context.cancellationSignal
156
+ };
157
+ let response;
158
+ let isTooLarge = false;
159
+ try {
160
+ response = await this.send(request);
161
+ } catch (error) {
162
+ if (error instanceof BodyTooLargeError && error.status !== void 0) {
163
+ response = { status: error.status, headers: error.headers ?? {}, body: new Uint8Array() };
164
+ isTooLarge = true;
165
+ } else return emptyExchange("request");
166
+ }
167
+ const retryAfterMs = parseRetryAfter(header(response.headers, "retry-after"));
168
+ if (isTooLarge || response.body.length > this.maxResponseBytes)
169
+ return { status: response.status, body: new Uint8Array(), retryAfterMs, error: "tooLarge" };
170
+ return { status: response.status, body: response.body, retryAfterMs };
171
+ }
172
+ };
173
+ var GetLeadOperation = class {
174
+ /** Bind one Marketo client. */
175
+ constructor(client) {
176
+ this.client = client;
177
+ }
178
+ client;
179
+ /** Return the generated Query contract. */
180
+ definition() {
181
+ return GetLeadDefinition;
182
+ }
183
+ /** Classify lead lookup outcomes consistently with Go. */
184
+ async invoke(call, input) {
185
+ if (!Number.isSafeInteger(input?.leadId) || input.leadId <= 0)
186
+ return terminal("defect", "VALIDATION", "Marketo lead ID must be positive");
187
+ const exchange = await this.client.get(call, input.leadId);
188
+ if (exchange.error === "credential") return terminal("defect", "AUTHENTICATION", "Marketo connection needs authorization");
189
+ if (exchange.error === "request") return retry("TRANSPORT", "Marketo request failed");
190
+ if (exchange.status === 429) return retry("RATE_LIMIT", "Marketo rate limited the request", exchange.retryAfterMs);
191
+ if (exchange.status === 408 || exchange.status >= 500) return retry("AVAILABILITY", "Marketo is temporarily unavailable", exchange.retryAfterMs);
192
+ if (exchange.status !== 200) return terminal("providerRejected", "PROVIDER_REJECTION", `Marketo rejected HTTP ${exchange.status}`);
193
+ if (exchange.error === "tooLarge") return terminal("invalidResponse", "RESPONSE_TOO_LARGE", "Marketo response exceeded the configured limit");
194
+ const decoded = decodeLead(exchange.body, input.leadId);
195
+ if (decoded.kind === "found") return newQueryBranch("found", decoded.profile);
196
+ if (decoded.kind === "rateLimit") return retry("RATE_LIMIT", "Marketo quota or concurrency limit was reached", exchange.retryAfterMs);
197
+ if (decoded.kind === "availability") return retry("AVAILABILITY", "Marketo is temporarily unavailable", exchange.retryAfterMs);
198
+ if (decoded.kind === "tokenExpired") return retry("AUTHENTICATION", "Marketo access token expired", exchange.retryAfterMs);
199
+ return terminal(decoded.kind, decoded.failure, "Marketo lead lookup did not return a profile");
200
+ }
201
+ };
202
+ function decodeLead(body, requestedID) {
203
+ let raw;
204
+ try {
205
+ raw = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
206
+ } catch {
207
+ return { kind: "invalidResponse", failure: "PROTOCOL" };
208
+ }
209
+ if (!isObject(raw) || typeof raw.success !== "boolean") return { kind: "invalidResponse", failure: "PROTOCOL" };
210
+ if (!raw.success) {
211
+ if (!Array.isArray(raw.errors) || raw.errors.length === 0 || !isObject(raw.errors[0]) || typeof raw.errors[0].code !== "string")
212
+ return { kind: "invalidResponse", failure: "PROTOCOL" };
213
+ const code = raw.errors[0].code;
214
+ if (["606", "607", "615"].includes(code)) return { kind: "rateLimit" };
215
+ if (["604", "608", "611", "614", "500", "502"].includes(code)) return { kind: "availability" };
216
+ if (code === "702") return { kind: "notFound", failure: "NOT_FOUND" };
217
+ if (code === "602") return { kind: "tokenExpired" };
218
+ return { kind: "providerRejected", failure: code === "601" ? "AUTHENTICATION" : "PROVIDER_REJECTION" };
219
+ }
220
+ if (!Array.isArray(raw.result) || raw.result.length > 1) return { kind: "invalidResponse", failure: "PROTOCOL" };
221
+ if (raw.result.length === 0) return { kind: "notFound", failure: "NOT_FOUND" };
222
+ const lead = raw.result[0];
223
+ if (!isObject(lead) || !Number.isSafeInteger(lead.id) || lead.id !== requestedID || !optionalString(lead.firstName) || !optionalString(lead.lastName))
224
+ return { kind: "invalidResponse", failure: "PROTOCOL" };
225
+ return { kind: "found", profile: { id: requestedID, firstName: typeof lead.firstName === "string" ? lead.firstName : "", lastName: typeof lead.lastName === "string" ? lead.lastName : "" } };
226
+ }
227
+ function optionalString(value) {
228
+ return value === void 0 || value === null || typeof value === "string";
229
+ }
230
+ function isObject(value) {
231
+ return typeof value === "object" && value !== null && !Array.isArray(value);
232
+ }
233
+ function emptyExchange(error) {
234
+ return { status: 0, body: new Uint8Array(), retryAfterMs: 0, error };
235
+ }
236
+ function failure(kind, message) {
237
+ return { provider: "adobe-marketo", operation: "getLead", kind, message };
238
+ }
239
+ function terminal(branch, kind, message) {
240
+ return newQueryBranch(branch, emptyProfile(), {}, failure(kind, message));
241
+ }
242
+ function retry(kind, message, delay = 0) {
243
+ return newQueryRetry(failure(kind, message), delay);
244
+ }
245
+ function header(headers, name) {
246
+ const entry = Object.entries(headers).find(([key]) => key.toLowerCase() === name)?.[1];
247
+ return Array.isArray(entry) ? entry[0] ?? "" : entry ?? "";
248
+ }
249
+
250
+ // src/project.ts
251
+ function encodeCredentials(credentials) {
252
+ return { client_id: credentials.clientId, client_secret: credentials.clientSecret.reveal(), access_token: credentials.accessToken?.reveal() ?? "" };
253
+ }
254
+ function newProjectConnection2(project, connectionName) {
255
+ return newProjectConnection(project, connectionName, (loadedProject, name) => {
256
+ const selected = loadedProject.configuration.connections.find((entry) => entry.connectorId === "adobe-marketo" && entry.connectionName === name);
257
+ if (!selected) throw new TypeError("Marketo project connection is not configured");
258
+ const fields = z.strictObject({ restEndpoint: z.string(), tokenEndpoint: z.string(), timeout: z.union([z.string(), z.number().int()]).optional(), maxResponseBytes: z.number().int().optional() }).parse(selected.configuration);
259
+ const timeoutMs = typeof fields.timeout === "number" ? Math.ceil(fields.timeout / 1e6) : fields.timeout ? parseDurationMilliseconds(fields.timeout) : void 0;
260
+ const config = {
261
+ restEndpoint: fields.restEndpoint,
262
+ tokenEndpoint: fields.tokenEndpoint,
263
+ ...timeoutMs !== void 0 ? { timeoutMs } : {},
264
+ ...fields.maxResponseBytes !== void 0 ? { maxResponseBytes: fields.maxResponseBytes } : {}
265
+ };
266
+ const credentials = newProjectCredentialProvider(loadedProject, name, decodeCredentials, encodeCredentials, decodeSharedCredentials);
267
+ return new MarketoClient(config, credentials);
268
+ });
269
+ }
270
+ function parseDurationMilliseconds(value) {
271
+ let remaining = value;
272
+ let milliseconds = 0;
273
+ const units = { ns: 1e-6, us: 1e-3, "\xB5s": 1e-3, ms: 1, s: 1e3, m: 6e4, h: 36e5 };
274
+ while (remaining) {
275
+ const part = /^(\d+(?:\.\d+)?)(ns|us|µs|ms|s|m|h)/.exec(remaining);
276
+ if (!part) throw new TypeError("Marketo timeout must be a positive Go duration");
277
+ milliseconds += Number(part[1]) * (units[part[2] ?? ""] ?? NaN);
278
+ remaining = remaining.slice(part[0].length);
279
+ }
280
+ if (!Number.isSafeInteger(milliseconds) || milliseconds <= 0) throw new TypeError("Marketo timeout must resolve to positive whole milliseconds");
281
+ return milliseconds;
282
+ }
283
+ export {
284
+ ConfigSchema,
285
+ Connection,
286
+ ConnectorID,
287
+ GetLeadBranch,
288
+ GetLeadBranchDefect,
289
+ GetLeadBranchFound,
290
+ GetLeadBranchInvalidResponse,
291
+ GetLeadBranchNotFound,
292
+ GetLeadBranchProviderRejected,
293
+ GetLeadDefinition,
294
+ GetLeadInputSchema,
295
+ GetLeadMetadata,
296
+ GetLeadOperation,
297
+ LeadProfileSchema,
298
+ MarketoClient,
299
+ ProviderID,
300
+ decodeCredentials,
301
+ decodeSharedCredentials,
302
+ newConnection,
303
+ newConnectionWithOperations,
304
+ newGetLeadStep,
305
+ newProjectConnection2 as newProjectConnection
306
+ };
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, C as Connection, G as GetLeadInput, L as LeadProfile } from './connection-lQR7OxHI.js';
4
+ import 'zod';
5
+
6
+ /** Go zero value for GetLeadInput in scripted cases. */
7
+ declare const emptyGetLeadInput: GetLeadInput;
8
+ /** Go zero value for LeadProfile in scripted cases. */
9
+ declare const emptyLeadProfile: LeadProfile;
10
+ /** Script the found branch. */
11
+ declare function getLeadFound(value: LeadProfile, failure?: Failure): Case<LeadProfile>;
12
+ /** Script the notFound branch. */
13
+ declare function getLeadNotFound(value: LeadProfile, failure?: Failure): Case<LeadProfile>;
14
+ /** Script the providerRejected branch. */
15
+ declare function getLeadProviderRejected(value: LeadProfile, failure?: Failure): Case<LeadProfile>;
16
+ /** Script the invalidResponse branch. */
17
+ declare function getLeadInvalidResponse(value: LeadProfile, failure?: Failure): Case<LeadProfile>;
18
+ /** Script the defect branch. */
19
+ declare function getLeadDefect(value: LeadProfile, failure?: Failure): Case<LeadProfile>;
20
+ /** Script a safe retry of getLead. */
21
+ declare function getLeadRetry(failure: Failure, retryAfterMs?: number): Case<LeadProfile>;
22
+ /** Manifest scenario foundDefault for getLead. */
23
+ declare function getLeadFoundDefault(): Case<LeadProfile>;
24
+ /** Default getLead scenario. */
25
+ declare function getLeadDefault(): Case<LeadProfile>;
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
+ getLead(): MockQuery<GetLeadInput, LeadProfile>;
32
+ assertNoFailures(): void;
33
+ }
34
+
35
+ export { GeneratedMock, GeneratedMock as Mock, emptyGetLeadInput, emptyLeadProfile, getLeadDefault, getLeadDefect, getLeadFound, getLeadFoundDefault, getLeadInvalidResponse, getLeadNotFound, getLeadProviderRejected, getLeadRetry };
package/dist/mock.js ADDED
@@ -0,0 +1,74 @@
1
+ import {
2
+ GetLeadDefinition,
3
+ GetLeadInputSchema,
4
+ LeadProfileSchema,
5
+ ProviderID,
6
+ newConnectionWithOperations
7
+ } from "./chunk-N4RSR7PL.js";
8
+
9
+ // src/generated/mock.ts
10
+ import { branchCase, retryCase, newQuery } from "@superdurable/connectors-sdk/connectormock";
11
+ var emptyGetLeadInput = GetLeadInputSchema.parse({
12
+ "leadId": 0
13
+ });
14
+ var emptyLeadProfile = LeadProfileSchema.parse({
15
+ "id": 0,
16
+ "firstName": "",
17
+ "lastName": ""
18
+ });
19
+ function getLeadFound(value, failure) {
20
+ return branchCase("found", value, failure);
21
+ }
22
+ function getLeadNotFound(value, failure) {
23
+ return branchCase("notFound", value, failure);
24
+ }
25
+ function getLeadProviderRejected(value, failure) {
26
+ return branchCase("providerRejected", value, failure);
27
+ }
28
+ function getLeadInvalidResponse(value, failure) {
29
+ return branchCase("invalidResponse", value, failure);
30
+ }
31
+ function getLeadDefect(value, failure) {
32
+ return branchCase("defect", value, failure);
33
+ }
34
+ function getLeadRetry(failure, retryAfterMs = 0) {
35
+ return retryCase(failure, retryAfterMs);
36
+ }
37
+ function getLeadFoundDefault() {
38
+ const value = LeadProfileSchema.parse({ "firstName": "Sample", "id": 318581, "lastName": "Lead" });
39
+ return branchCase("found", value);
40
+ }
41
+ function getLeadDefault() {
42
+ return getLeadFoundDefault();
43
+ }
44
+ var GeneratedMock = class {
45
+ #getLead;
46
+ #connection;
47
+ constructor(connectionName) {
48
+ this.#getLead = newQuery(GetLeadDefinition).default(getLeadDefault());
49
+ this.#connection = newConnectionWithOperations(this, { provider: ProviderID, name: connectionName });
50
+ }
51
+ connection() {
52
+ return this.#connection;
53
+ }
54
+ getLead() {
55
+ return this.#getLead;
56
+ }
57
+ assertNoFailures() {
58
+ this.#getLead.assertNoFailures();
59
+ }
60
+ };
61
+ export {
62
+ GeneratedMock,
63
+ GeneratedMock as Mock,
64
+ emptyGetLeadInput,
65
+ emptyLeadProfile,
66
+ getLeadDefault,
67
+ getLeadDefect,
68
+ getLeadFound,
69
+ getLeadFoundDefault,
70
+ getLeadInvalidResponse,
71
+ getLeadNotFound,
72
+ getLeadProviderRejected,
73
+ getLeadRetry
74
+ };
package/package.json CHANGED
@@ -1,6 +1,61 @@
1
1
  {
2
2
  "name": "@superdurable/connector-adobe-marketo",
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": "Marketo connector for Dex TypeScript applications",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/superdurable/dex-connectors-library.git",
9
+ "directory": "connectors/adobe/marketo/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/lead-inspection/worker.ts",
42
+ "example:start": "tsx examples/lead-inspection/start.ts",
43
+ "check": "npm run typecheck && npm run lint && npm test && npm run build"
44
+ },
45
+ "dependencies": {
46
+ "@superdurable/connectors-sdk": "0.7.0",
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
+ }