@drawbridge/drawbridge-utils 0.0.106 → 0.0.107

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.
@@ -0,0 +1,983 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // lib/connections/index.js
20
+ var connections_exports = {};
21
+ __export(connections_exports, {
22
+ AUTH_TYPES: () => AUTH_TYPES,
23
+ CATEGORIES: () => CATEGORIES,
24
+ HOOKS: () => HOOKS,
25
+ HOOK_NAMES: () => HOOK_NAMES,
26
+ INPUTS: () => INPUTS,
27
+ OAUTH_FIELDS: () => OAUTH_FIELDS,
28
+ OUTCOMES: () => OUTCOMES,
29
+ availableConnections: () => availableConnections,
30
+ build: () => build,
31
+ connectFields: () => connectFields,
32
+ connectionSteps: () => connectionSteps,
33
+ connections: () => connections,
34
+ consentUrl: () => consentUrl,
35
+ exchange: () => exchange,
36
+ hookSupport: () => hookSupport,
37
+ mergeSettings: () => mergeSettings,
38
+ pkcePair: () => pkcePair,
39
+ projectConnection: () => projectConnection,
40
+ publicConnectionKeys: () => publicConnectionKeys,
41
+ publicSettingsBySlug: () => publicSettingsBySlug,
42
+ redactSettings: () => redactSettings,
43
+ refresh: () => refresh,
44
+ resolveConnection: () => resolveConnection,
45
+ runHook: () => runHook,
46
+ scopesMessage: () => scopesMessage,
47
+ stepQueues: () => stepQueues
48
+ });
49
+ module.exports = __toCommonJS(connections_exports);
50
+
51
+ // lib/connections/contract.js
52
+ var HOOKS = Object.freeze({
53
+ // Proving and holding the credential.
54
+ auth: Object.freeze([
55
+ // Accept what the merchant supplied — a form submission or an OAuth
56
+ // callback — and store what is needed to call the vendor later.
57
+ "connect",
58
+ // Is the stored credential still good? Answered by the cheapest real call
59
+ // the vendor offers, never by inspecting what we stored: a key that was
60
+ // revoked at the vendor still looks perfect in our database.
61
+ "probe",
62
+ // Which permissions we asked for and no longer hold. Distinct from probe:
63
+ // the credential can be valid and the grant still be too narrow.
64
+ "scopes",
65
+ // Revoke at the vendor and drop what we hold.
66
+ "disconnect"
67
+ ]),
68
+ // What happens around connecting and disconnecting, beyond the credential.
69
+ lifecycle: Object.freeze([
70
+ // Post-connect setup: register the vendor's webhooks, create the system
71
+ // workflows that describe them.
72
+ "register",
73
+ // Re-pull vendor state we mirror, after a reconnect or on a schedule.
74
+ "rehydrate",
75
+ // Undo `register` — deregister webhooks, release anything reserved.
76
+ "cleanup"
77
+ ]),
78
+ // Receiving from the vendor.
79
+ inbound: Object.freeze([
80
+ // Prove the request came from the vendor. Signature schemes differ per
81
+ // vendor, which is exactly why this is a hook and not one shared function.
82
+ "verify",
83
+ // Name the event, from wherever this vendor puts it.
84
+ "topic",
85
+ // Do the work the event implies.
86
+ "handle"
87
+ ]),
88
+ // Vendor data a campaign draws on. Named for what every store platform has,
89
+ // not for what Shopify calls it: Shopify says discounts, Stripe says coupons
90
+ // and promotion codes, BigCommerce says coupons and promotions.
91
+ catalog: Object.freeze([
92
+ "products",
93
+ // Shopify folds price into the product variant; Stripe makes Price a
94
+ // first-class object beside Product. Declared so a vendor that separates
95
+ // them has somewhere to answer.
96
+ "prices",
97
+ "promotions"
98
+ ])
99
+ });
100
+ var HOOK_NAMES = Object.freeze(
101
+ Object.entries(HOOKS).flatMap(([domain, verbs]) => verbs.map((verb) => domain + "." + verb))
102
+ );
103
+ var OUTCOMES = Object.freeze({
104
+ answered: "answered",
105
+ disconnected: "disconnected",
106
+ failed: "failed",
107
+ // Declared supported, implemented in a consumer rather than in this package —
108
+ // sync owns the step handlers and lifecycle jobs. Different from unsupported,
109
+ // which means the vendor cannot do it at all.
110
+ unimplemented: "unimplemented",
111
+ unsupported: "unsupported"
112
+ });
113
+ var AUTH_TYPES = Object.freeze(["generated", "install", "keys", "oauth"]);
114
+ var CATEGORIES = Object.freeze(["commerce", "contacts", "developer", "messaging"]);
115
+ var OAUTH_FIELDS = Object.freeze(["authorize", "client", "redirect", "token"]);
116
+ var INPUTS = Object.freeze([
117
+ "checkbox",
118
+ "email",
119
+ "number",
120
+ "password",
121
+ "select",
122
+ "text",
123
+ "textarea",
124
+ "url"
125
+ ]);
126
+
127
+ // lib/connections/oauth.js
128
+ var import_node_crypto = require("crypto");
129
+ var credentials = ({ clientId, clientSecret, descriptor }) => (descriptor == null ? void 0 : descriptor.clientAuth) === "basic" ? {
130
+ headers: { authorization: "Basic " + Buffer.from(clientId + ":" + clientSecret).toString("base64") },
131
+ body: {}
132
+ } : {
133
+ headers: {},
134
+ body: { client_id: clientId, client_secret: clientSecret }
135
+ };
136
+ var pkcePair = () => {
137
+ const verifier = (0, import_node_crypto.randomBytes)(32).toString("base64url");
138
+ return {
139
+ challenge: (0, import_node_crypto.createHash)("sha256").update(verifier).digest("base64url"),
140
+ method: "S256",
141
+ verifier
142
+ };
143
+ };
144
+ var consentUrl = ({ challenge, clientId, descriptor, redirect, state } = {}) => {
145
+ if (!clientId) throw new Error("This deployment has no OAuth client configured, so there is nothing to consent through");
146
+ if (!(descriptor == null ? void 0 : descriptor.authorize)) throw new Error("This connection declares no authorize url");
147
+ if (descriptor.pkce && !challenge) throw new Error("This connection requires PKCE, so a code challenge is not optional");
148
+ return descriptor.authorize + "?" + new URLSearchParams({
149
+ // The descriptor's own params go FIRST, so a vendor quirk cannot quietly
150
+ // overwrite one of the fields below that every consent carries.
151
+ ...descriptor.params || {},
152
+ client_id: clientId,
153
+ redirect_uri: redirect,
154
+ response_type: "code",
155
+ ...descriptor.scopes && { scope: descriptor.scopes },
156
+ ...descriptor.pkce && {
157
+ code_challenge: challenge,
158
+ code_challenge_method: "S256"
159
+ },
160
+ state
161
+ });
162
+ };
163
+ var exchange = async ({ clientId, clientSecret, code, descriptor, fetcher = fetch, redirect, verifier } = {}) => {
164
+ if (!(descriptor == null ? void 0 : descriptor.token)) throw new Error("This connection declares no token url");
165
+ if (descriptor.pkce && !verifier) throw new Error("This connection requires PKCE, so the code verifier is not optional");
166
+ const client = credentials({ clientId, clientSecret, descriptor });
167
+ const response = await fetcher(descriptor.token, {
168
+ body: new URLSearchParams({
169
+ ...client.body,
170
+ code: decodeURIComponent(String(code || "").trim()),
171
+ grant_type: "authorization_code",
172
+ redirect_uri: redirect,
173
+ ...descriptor.pkce && { code_verifier: verifier }
174
+ }),
175
+ headers: { "content-type": "application/x-www-form-urlencoded", ...client.headers },
176
+ method: "POST",
177
+ signal: AbortSignal.timeout(15e3)
178
+ });
179
+ const body = await response.json().catch(() => ({}));
180
+ if (!response.ok) {
181
+ throw new Error("The vendor refused the exchange (" + response.status + ")" + ((body == null ? void 0 : body.error) ? ": " + body.error : ""));
182
+ }
183
+ if (!body.access_token) throw new Error("The vendor returned no access token");
184
+ return {
185
+ accessToken: body.access_token,
186
+ expiresIn: body.expires_in || null,
187
+ refreshToken: body.refresh_token || null,
188
+ scope: body.scope || null
189
+ };
190
+ };
191
+ var refresh = async ({ clientId, clientSecret, descriptor, fetcher = fetch, refreshToken } = {}) => {
192
+ if (!clientId || !clientSecret) throw new Error("This deployment has no OAuth client configured, so no token can be minted");
193
+ if (!refreshToken) throw new Error("Nothing has been consented to yet, so there is no refresh token to spend");
194
+ if (!(descriptor == null ? void 0 : descriptor.token)) throw new Error("This connection declares no token url");
195
+ const client = credentials({ clientId, clientSecret, descriptor });
196
+ const response = await fetcher(descriptor.token, {
197
+ body: new URLSearchParams({
198
+ ...client.body,
199
+ grant_type: "refresh_token",
200
+ refresh_token: refreshToken
201
+ }),
202
+ headers: { "content-type": "application/x-www-form-urlencoded", ...client.headers },
203
+ method: "POST",
204
+ signal: AbortSignal.timeout(15e3)
205
+ });
206
+ if (!response.ok) throw new Error("The vendor refused the refresh token (" + response.status + ") \u2014 reconnect the connection");
207
+ const body = await response.json();
208
+ return {
209
+ accessToken: body.access_token,
210
+ expiresIn: body.expires_in || null,
211
+ // A vendor that rotates its refresh token returns a new one, and dropping
212
+ // it silently invalidates the stored grant on the NEXT refresh rather
213
+ // than this one — a failure a day late and nowhere near its cause.
214
+ refreshToken: body.refresh_token || null
215
+ };
216
+ };
217
+
218
+ // lib/connections/icons/klaviyo.js
219
+ var klaviyo_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
220
+ <rect width="500" height="500" fill="white"/>
221
+ <path d="M365.047 327.038H134.954V172.964H365.047L316.856 250.001L365.047 327.038Z" fill="#232121"/>
222
+ </svg>`;
223
+
224
+ // lib/connections/klaviyo.js
225
+ var klaviyo_default2 = {
226
+ // OAuth 2.1, and PKCE is REQUIRED rather than recommended: Klaviyo refuses an
227
+ // exchange without a code_verifier matching the challenge the consent
228
+ // carried. Most vendors treat it as optional hardening; this one does not,
229
+ // which is why it is a descriptor flag and not a global.
230
+ //
231
+ // clientAuth is the other thing Klaviyo does differently. The token endpoint
232
+ // wants HTTP Basic — base64( client_id : client_secret ) in an Authorization
233
+ // header — and rejects the same pair sent as form fields, which is how every
234
+ // Google product wants it.
235
+ auth: {
236
+ oauth: {
237
+ authorize: "https://a.klaviyo.com/oauth/authorize",
238
+ // NAMES the env vars holding OUR application's client. One identity,
239
+ // every merchant — the token is the merchant's and arrives from their
240
+ // own consent, which is what stops one organization reading another's
241
+ // data.
242
+ client: {
243
+ id: "KLAVIYO_OAUTH_CLIENT_ID",
244
+ secret: "KLAVIYO_OAUTH_CLIENT_SECRET"
245
+ },
246
+ clientAuth: "basic",
247
+ pkce: true,
248
+ // DECLARED, never derived from the slug. It is registered in Klaviyo's
249
+ // app settings and they refuse anything that does not byte-match, so
250
+ // it is a fact about someone else's records rather than a string this
251
+ // code computes. Deriving one from a provider key produced
252
+ // redirect_uri_mismatch on a connection nobody had touched.
253
+ redirect: "/api/connection/klaviyo/callback",
254
+ // Space separated. accounts:read is required by Klaviyo on every app
255
+ // and must stay in the list; the rest are what a contact sync needs.
256
+ scopes: "accounts:read lists:read lists:write profiles:read profiles:write",
257
+ token: "https://a.klaviyo.com/oauth/token"
258
+ },
259
+ type: "oauth"
260
+ },
261
+ category: "contacts",
262
+ confirm: "Disconnecting revokes Drawbridge's access to your Klaviyo account. Your profiles and lists stay in both Klaviyo and Drawbridge \u2014 neither is deleted.",
263
+ connect: {
264
+ errors: {
265
+ denied: "The Klaviyo authorization was declined, so nothing was connected.",
266
+ invalid: "We couldn't complete the Klaviyo connection. Try connecting again."
267
+ }
268
+ },
269
+ description: [
270
+ "Connecting Klaviyo lets Drawbridge sync the contacts your campaigns collect into a Klaviyo list, so the people who enter a giveaway can be marketed to alongside the rest of your audience.",
271
+ "You authorize Drawbridge from inside Klaviyo and can revoke that access there at any time. Drawbridge never sees or stores your Klaviyo password, and only asks for the permissions listed on the consent screen.",
272
+ "Anyone who has opted out in Drawbridge is synced as unsubscribed rather than omitted, so a person who asked not to be contacted stays suppressed in both systems instead of quietly reappearing."
273
+ ],
274
+ excerpt: "Sync the contacts your campaigns collect into a Klaviyo list.",
275
+ feature: "organization:connection:klaviyo",
276
+ // Nothing typed. The consent returns the grant, and the account it belongs to
277
+ // is read back from Klaviyo rather than asked for.
278
+ fields: [
279
+ {
280
+ key: "account",
281
+ label: "Klaviyo account"
282
+ }
283
+ ],
284
+ icon: klaviyo_default,
285
+ label: "klaviyo",
286
+ requires: [
287
+ "KLAVIYO_OAUTH_CLIENT_ID",
288
+ "KLAVIYO_OAUTH_CLIENT_SECRET"
289
+ ],
290
+ setup: [
291
+ "Press Connect. Drawbridge sends you to Klaviyo to approve access.",
292
+ "Sign in to Klaviyo if you are not already, and choose the account to connect.",
293
+ "Approve the permissions Klaviyo lists. You are returned here and the connection shows Active.",
294
+ "You can revoke access at any time from Klaviyo, under Integrations."
295
+ ],
296
+ slug: "klaviyo",
297
+ // No steps yet. The sync itself is unbuilt, and a step offered in the builder
298
+ // that nothing runs is worse than no step at all — the merchant configures it
299
+ // and waits for something that never happens.
300
+ steps: {},
301
+ supports: {
302
+ "auth.connect": true,
303
+ "auth.disconnect": true,
304
+ // The refresh mint IS the probe: a revoked or rotated grant fails there in
305
+ // Klaviyo's own words rather than as an empty sync three steps later.
306
+ "auth.probe": true,
307
+ // Klaviyo scopes are fixed at app level and re-consented, not drifted.
308
+ "auth.scopes": false,
309
+ "catalog.prices": false,
310
+ "catalog.products": false,
311
+ "catalog.promotions": false,
312
+ "inbound.handle": false,
313
+ "inbound.topic": false,
314
+ "inbound.verify": false,
315
+ "lifecycle.cleanup": false,
316
+ "lifecycle.register": false,
317
+ "lifecycle.rehydrate": false
318
+ },
319
+ title: "Klaviyo"
320
+ };
321
+
322
+ // lib/connections/icons/mailchimp.js
323
+ var mailchimp_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
324
+ <rect width="500" height="500" fill="#FFE01B"/>
325
+ <path d="M310.633 243.561C312.49 243.336 314.249 243.308 315.882 243.561C316.81 241.394 316.979 237.665 316.149 233.598C314.882 227.561 313.18 223.917 309.662 224.508C306.13 225.071 305.989 229.433 307.269 235.47C307.973 238.847 309.24 241.746 310.633 243.561ZM280.392 248.332C282.925 249.429 284.473 250.147 285.05 249.542C285.458 249.148 285.345 248.36 284.74 247.375C283.112 245.042 280.844 243.229 278.211 242.154C275.397 240.982 272.328 240.556 269.301 240.916C266.274 241.275 263.391 242.41 260.93 244.209C259.256 245.447 257.666 247.15 257.863 248.191C257.961 248.515 258.186 248.782 258.777 248.895C260.17 249.049 265.025 246.587 270.64 246.249C274.608 245.968 277.859 247.206 280.392 248.332ZM275.312 251.216C272.047 251.737 270.232 252.807 269.078 253.848C268.079 254.72 267.488 255.649 267.488 256.339L267.741 256.93L268.262 257.127C269.008 257.127 270.668 256.479 270.668 256.479C275.228 254.861 278.253 255.044 281.25 255.382C282.897 255.579 283.671 255.663 284.037 255.1C284.135 254.931 284.29 254.608 283.938 254.059C283.15 252.778 279.843 250.682 275.312 251.216ZM300.416 261.855C302.654 262.953 305.102 262.502 305.904 260.884C306.735 259.266 305.567 257.056 303.329 255.973C301.106 254.861 298.643 255.283 297.841 256.902C297.039 258.52 298.207 260.757 300.416 261.855ZM314.742 249.317C312.94 249.289 311.449 251.259 311.393 253.764C311.35 256.254 312.8 258.281 314.615 258.295C316.43 258.323 317.922 256.339 317.964 253.862C318.006 251.385 316.571 249.359 314.742 249.317ZM193.103 294.108C192.653 293.545 191.907 293.7 191.189 293.897C190.683 293.995 190.12 294.136 189.515 294.122C188.909 294.134 188.308 293.998 187.767 293.726C187.225 293.454 186.757 293.054 186.405 292.56C185.575 291.294 185.617 289.394 186.546 287.241L186.968 286.27C188.431 283.019 190.838 277.559 188.122 272.367C187.234 270.534 185.908 268.948 184.261 267.75C182.614 266.553 180.697 265.78 178.679 265.5C176.772 265.256 174.835 265.469 173.026 266.123C171.218 266.776 169.591 267.85 168.28 269.257C164.284 273.661 163.679 279.684 164.439 281.823C164.734 282.611 165.184 282.822 165.494 282.864C166.169 282.963 167.169 282.456 167.802 280.754L167.999 280.219C168.28 279.318 168.801 277.63 169.659 276.307C170.717 274.689 172.375 273.558 174.267 273.162C176.159 272.766 178.131 273.138 179.749 274.196C182.563 276.039 183.619 279.473 182.423 282.752C181.803 284.455 180.804 287.691 181.015 290.351C181.466 295.74 184.815 297.907 187.77 298.175C190.669 298.273 192.695 296.655 193.216 295.459C193.511 294.713 193.258 294.277 193.103 294.108Z" fill="#231E15"/>
326
+ <path d="M360.476 284.243C360.35 283.835 359.618 281.204 358.647 278.052L356.621 272.648C360.575 266.696 360.645 261.405 360.124 258.393C359.531 254.519 357.693 250.944 354.89 248.205C351.766 244.94 345.363 241.563 336.385 239.044L331.671 237.736C331.643 237.524 331.418 226.619 331.235 221.933C331.08 218.555 330.798 213.264 329.152 208.058C327.182 200.993 323.791 194.858 319.527 190.876C331.277 178.717 338.594 165.307 338.58 153.81C338.538 131.703 311.379 124.976 277.902 138.851L270.824 141.863C270.795 141.835 258.004 129.283 257.821 129.128C219.63 95.8334 100.327 228.476 138.49 260.687L146.835 267.737C144.581 273.775 143.781 280.259 144.499 286.664C145.414 295.543 149.973 304.029 157.375 310.6C164.411 316.82 173.684 320.788 182.648 320.774C197.494 354.998 231.408 375.965 271.175 377.161C313.842 378.427 349.641 358.403 364.67 322.435C365.641 319.916 369.806 308.546 369.806 298.513C369.792 288.409 364.093 284.229 360.476 284.243ZM185.913 311.149C184.613 311.381 183.293 311.48 181.973 311.445C169.083 311.079 155.166 299.483 153.787 285.735C152.253 270.537 160.02 258.829 173.783 256.071C175.415 255.72 177.414 255.537 179.552 255.635C187.264 256.085 198.606 261.996 201.209 278.784C203.517 293.63 199.858 308.785 185.913 311.149ZM171.545 246.953C163.179 248.499 155.744 253.244 150.817 260.18C148.045 257.873 142.909 253.426 142.008 251.681C134.635 237.693 150.043 210.478 160.823 195.111C187.405 157.145 229.086 128.424 248.393 133.603C251.517 134.503 261.902 146.563 261.902 146.563C261.902 146.563 242.623 157.244 224.724 172.16C200.646 190.735 182.423 217.697 171.545 246.953ZM306.792 305.464C306.937 305.403 307.057 305.295 307.134 305.157C307.211 305.019 307.239 304.86 307.214 304.704C307.205 304.61 307.178 304.519 307.133 304.436C307.088 304.353 307.027 304.28 306.954 304.221C306.88 304.162 306.796 304.118 306.705 304.092C306.614 304.066 306.519 304.059 306.426 304.071C306.426 304.071 286.246 307.054 267.179 300.089C269.247 293.348 274.792 295.754 283.137 296.444C296.108 297.209 309.116 295.802 321.623 292.279C330.25 289.788 341.592 284.905 350.401 277.953C353.384 284.497 354.425 291.674 354.425 291.674C354.425 291.674 356.719 291.265 358.647 292.447C360.476 293.573 361.799 295.895 360.898 301.89C359.027 313.119 354.271 322.224 346.235 330.611C341.236 336.036 335.277 340.492 328.659 343.754C324.983 345.691 321.151 347.32 317.205 348.623C286.964 358.487 256.006 347.638 246.029 324.321C245.224 322.535 244.556 320.691 244.03 318.804C239.781 303.438 243.383 285.032 254.655 273.408C255.372 272.676 256.09 271.804 256.09 270.706C256.09 269.806 255.499 268.835 255.007 268.131C251.066 262.418 237.374 252.666 240.132 233.795C242.088 220.23 253.951 210.689 265.012 211.252L267.826 211.421C272.611 211.702 276.79 212.307 280.73 212.49C287.344 212.758 293.268 211.801 300.304 205.947C302.683 203.949 304.582 202.246 307.791 201.711C308.128 201.627 308.973 201.359 310.647 201.416C312.365 201.485 314.032 202.015 315.474 202.949C321.103 206.693 321.905 215.783 322.214 222.439C322.383 226.225 322.848 235.414 322.988 238.031C323.354 244.054 324.944 244.912 328.125 245.954C329.94 246.573 331.615 246.995 334.077 247.713C341.521 249.781 345.968 251.934 348.754 254.65C350.198 256.049 351.13 257.893 351.4 259.885C352.315 266.316 346.432 274.252 330.925 281.457C313.954 289.324 293.367 291.322 279.154 289.732L274.173 289.169C262.774 287.649 256.315 302.34 263.14 312.402C267.545 318.889 279.52 323.11 291.523 323.11C319.006 323.139 340.142 311.402 348.023 301.242L348.642 300.356C349.008 299.765 348.712 299.469 348.22 299.779C341.817 304.169 313.279 321.619 282.771 316.384C282.771 316.384 279.056 315.765 275.678 314.442C273.005 313.429 267.362 310.811 266.686 305.042C291.27 312.683 306.792 305.478 306.792 305.464ZM220.671 194.971C230.127 184.051 241.765 174.538 252.206 169.219C252.558 169.022 252.938 169.43 252.741 169.754C251.46 172 250.476 174.403 249.814 176.902C249.73 177.282 250.138 177.592 250.461 177.353C256.963 172.934 268.248 168.192 278.155 167.601C278.251 167.584 278.351 167.601 278.436 167.65C278.521 167.698 278.586 167.775 278.621 167.866C278.656 167.957 278.658 168.058 278.627 168.151C278.596 168.244 278.533 168.323 278.451 168.375C276.809 169.634 275.342 171.105 274.088 172.751C273.891 173.032 274.074 173.44 274.426 173.44C281.378 173.483 291.186 175.903 297.56 179.491C297.982 179.745 297.673 180.575 297.209 180.462C287.527 178.253 271.724 176.564 255.288 180.575C240.597 184.149 229.396 189.666 221.248 195.618C220.826 195.899 220.333 195.351 220.671 194.971Z" fill="#231E15"/>
327
+ </svg>`;
328
+
329
+ // lib/connections/mailchimp.js
330
+ var mailchimp_default2 = {
331
+ // Keys TODAY. Mailchimp integrations authenticate with OAuth 2 (authorization
332
+ // code) and that is where this goes, so the endpoints are recorded here
333
+ // rather than researched again later:
334
+ //
335
+ // authorize https://login.mailchimp.com/oauth2/authorize
336
+ // token https://login.mailchimp.com/oauth2/token
337
+ // metadata https://login.mailchimp.com/oauth2/metadata
338
+ //
339
+ // The metadata call is Mailchimp's quirk and cannot be skipped: the access
340
+ // token alone is not enough to call the Marketing API, because every account
341
+ // lives behind a data-centre prefix (us1, us19...) that only that call
342
+ // returns and every subsequent request needs in its host. No PKCE.
343
+ //
344
+ // Switching is filling in auth.oauth and moving the apiKey field out. It is
345
+ // still a publish -- a manifest change always is -- but a value change
346
+ // rather than a shape one.
347
+ auth: {
348
+ type: "keys"
349
+ },
350
+ category: "contacts",
351
+ confirm: "Disconnecting removes your stored Mailchimp key. Your contacts stay in both Drawbridge and Mailchimp \u2014 neither list is deleted.",
352
+ description: [
353
+ "Drawbridge no longer sends email through Mailchimp. Notification email now sends from Drawbridge itself, and verifying a domain under Networking in your organization settings puts your own brand in the from line.",
354
+ "This connection is becoming the way your Drawbridge contacts sync into a Mailchimp audience. Audience syncing is not live yet, so a key stored here does nothing today."
355
+ ],
356
+ excerpt: "Sync your Drawbridge contacts into a Mailchimp audience.",
357
+ feature: "organization:connection:mailchimp",
358
+ fields: [
359
+ {
360
+ input: "password",
361
+ key: "apiKey",
362
+ label: "Mailchimp API key",
363
+ message: "Your Mailchimp API key",
364
+ placeholder: "\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022\u2022-us1",
365
+ redact: true,
366
+ required: true
367
+ }
368
+ ],
369
+ icon: mailchimp_default,
370
+ label: "mailchimp",
371
+ // Uniform surface, honest answers. A key is stored and can be removed; nothing
372
+ // else is built yet, because audience sync has not shipped. Every false here
373
+ // is "not yet", not "never" — when the sync lands, probe and catalog become
374
+ // the first two to flip.
375
+ supports: {
376
+ "auth.connect": true,
377
+ "auth.disconnect": true,
378
+ "auth.probe": false,
379
+ "auth.scopes": false,
380
+ "catalog.prices": false,
381
+ "catalog.products": false,
382
+ "catalog.promotions": false,
383
+ "inbound.handle": false,
384
+ "inbound.topic": false,
385
+ "inbound.verify": false,
386
+ "lifecycle.cleanup": false,
387
+ "lifecycle.register": false,
388
+ "lifecycle.rehydrate": false
389
+ },
390
+ setup: [
391
+ "In Mailchimp, open Account & billing, then Extras, then API keys.",
392
+ "Create a key and copy it.",
393
+ "Paste it here. The key ends in a data-centre suffix like -us19, which tells Drawbridge which Mailchimp server your account is on."
394
+ ],
395
+ slug: "mailchimp",
396
+ // No steps: audience sync has not shipped, so this vendor contributes nothing
397
+ // to a workflow yet. An empty steps object is the honest declaration — the
398
+ // catalog renders the connection, and no builder offers a step it cannot run.
399
+ steps: {},
400
+ tasks: () => [
401
+ {
402
+ message: "Contact syncing to Mailchimp audiences has not shipped yet, and this connection no longer sends your email. Nothing is being sent to Mailchimp right now.",
403
+ title: "Audience sync not available yet",
404
+ type: "warning"
405
+ }
406
+ ],
407
+ title: "Mailchimp"
408
+ };
409
+
410
+ // lib/connections/icons/shopify.js
411
+ var shopify_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
412
+ <rect width="500" height="500" fill="white"/>
413
+ <path fill-rule="evenodd" clip-rule="evenodd" d="M309.524 407.192L308.799 128.423C306.921 126.545 303.258 127.112 301.827 127.531L292.29 130.487C291.113 126.613 289.585 122.854 287.726 119.258C280.959 106.337 271.069 99.5052 259.096 99.4866H259.059C258.259 99.4866 257.469 99.5609 256.67 99.626L256.577 99.6353C256.231 99.2089 255.871 98.7935 255.499 98.3897C250.293 92.8125 243.601 90.0889 235.588 90.3213C220.139 90.7675 204.755 101.941 192.271 121.786C183.487 135.757 176.823 153.298 174.917 166.878L144.493 176.313C135.542 179.129 135.263 179.408 134.082 187.858C133.199 194.253 109.766 375.69 109.766 375.69L306.159 409.692L309.524 407.192ZM245.181 103.065C242.569 101.346 239.511 100.546 235.885 100.621C212.033 101.308 191.23 138.611 185.923 163.467L208.771 156.384L212.851 155.119C215.845 139.336 223.355 122.957 233.181 112.416C236.616 108.639 240.671 105.477 245.172 103.065H245.181ZM224.145 151.615L256.94 141.446C257.042 132.894 256.112 120.252 251.836 111.329C247.282 113.207 243.452 116.497 240.7 119.444C233.329 127.373 227.315 139.466 224.155 151.615H224.145ZM267.211 138.267L282.455 133.536C280.02 125.616 274.238 112.342 262.517 110.111C266.161 119.527 267.099 130.431 267.211 138.267Z" fill="#95BF47"/>
414
+ <path d="M353.528 149.156C352.356 149.063 329.657 148.709 329.657 148.709C329.657 148.709 310.666 130.249 308.789 128.362C308.062 127.691 307.141 127.268 306.158 127.153V409.64L391.257 388.456C391.257 388.456 356.53 153.366 356.307 151.758C356.199 151.075 355.866 150.448 355.361 149.976C354.856 149.505 354.216 149.216 353.528 149.156Z" fill="#5E8E3E"/>
415
+ <path d="M258.993 193.019L249.103 230.052C249.103 230.052 238.079 225.023 225 225.85C205.833 227.059 205.628 239.171 205.824 242.21C206.865 258.756 250.376 262.381 252.821 301.171C254.745 331.688 236.656 352.574 210.592 354.21C179.313 356.19 162.089 337.711 162.089 337.711L168.716 309.472C168.716 309.472 186.052 322.569 199.921 321.686C208.993 321.119 212.228 313.738 211.903 308.514C210.536 286.921 175.102 288.185 172.862 252.695C170.985 222.811 190.57 192.554 233.803 189.821C250.46 188.762 258.993 193.028 258.993 193.028" fill="white"/>
416
+ </svg>`;
417
+
418
+ // lib/connections/shopify.js
419
+ var shopify_default2 = {
420
+ // INSTALL, not oauth. The grant is an OAuth grant, but the merchant never
421
+ // sees a consent screen we sent them to -- they start at the App Store, and
422
+ // the install completes inside Shopify admin without redirecting back. A
423
+ // Connect button here would be lying about where connecting happens.
424
+ auth: {
425
+ type: "install"
426
+ },
427
+ category: "commerce",
428
+ confirm: "Disconnecting deactivates all products from this store, drafts any advertisements that use them, disables Shopify steps in your workflows until you reconnect, and stops revenue tracking for this organization.",
429
+ // How connecting is DESCRIBED — the copy and destination. What kind of connect
430
+ // it is lives in auth.type, once, so the two cannot disagree.
431
+ //
432
+ // The redirect title is copy: it names where the link GOES rather than what it
433
+ // does, since installing happens on the App Store listing and the dashboard
434
+ // must never imply a store can be linked from inside it.
435
+ connect: {
436
+ errors: {
437
+ conflict: "This store is already connected to another Drawbridge organization.",
438
+ currency: "This store settles in a currency we can't bill yet. Connect a store with a supported settlement currency.",
439
+ invalid: "We couldn't verify the install. Please try connecting again from the Shopify App Store."
440
+ },
441
+ redirect: {
442
+ env: "SHOPIFY_APP_LISTING_URL",
443
+ title: "View on the Shopify App Store"
444
+ }
445
+ },
446
+ description: [
447
+ "Installing the Drawbridge app from the Shopify App Store links your store to a single Drawbridge organization and makes your product catalog available inside Drawbridge, so you can feature products in your campaigns and advertisements.",
448
+ "Drawbridge attributes orders that originate from your campaigns \u2014 matched through cart parameters and lead-mapped discount codes \u2014 so you can see the revenue each campaign drives.",
449
+ "On connect, Drawbridge registers webhooks for product and order updates to keep your catalog and revenue in sync. Disconnecting removes those webhooks and unlinks the catalog."
450
+ ],
451
+ excerpt: "Connect your Shopify store to feature products in your campaigns and track conversions.",
452
+ feature: "organization:connection:shopify",
453
+ fields: [
454
+ {
455
+ // `shop` on the connection record wins when present — it is written by
456
+ // the install, while settings.domain is the stored copy.
457
+ from: "shop",
458
+ key: "domain",
459
+ label: "Store domain"
460
+ }
461
+ ],
462
+ group: "ecommerce",
463
+ // WHERE THIS VENDOR PUTS THINGS ON AN INBOUND REQUEST. Header names are facts
464
+ // about someone else's product, so they belong beside the rest of the vendor
465
+ // rather than as string literals in a route — which is where they were, and
466
+ // is why a second inbound vendor meant a second route file.
467
+ //
468
+ // `signature` describes an HMAC scheme the shared verifier can run: hash the
469
+ // raw body with the named secret and compare, constant-time, against the
470
+ // header. Vendors whose scheme is not that shape — Stripe signs a timestamped
471
+ // payload — declare no signature block and implement inbound.verify instead.
472
+ // That is why verify is a hook and not config.
473
+ inbound: {
474
+ headers: {
475
+ id: "x-shopify-webhook-id",
476
+ shop: "x-shopify-shop-domain",
477
+ signature: "x-shopify-hmac-sha256",
478
+ topic: "x-shopify-topic"
479
+ },
480
+ signature: {
481
+ algorithm: "sha256",
482
+ encoding: "base64",
483
+ secret: "SHOPIFY_API_SECRET"
484
+ }
485
+ },
486
+ icon: shopify_default,
487
+ label: "shopify",
488
+ // A pre-launch integration: it only surfaces once the App Store listing
489
+ // exists and the app is fully configured. Requiring all four means it can
490
+ // never render half-configured — and absence of any one excludes the
491
+ // connection AND every step below it.
492
+ requires: [
493
+ "SHOPIFY_API_KEY",
494
+ "SHOPIFY_API_SECRET",
495
+ "SHOPIFY_APP_LISTING_URL",
496
+ "SHOPIFY_APP_HANDLE"
497
+ ],
498
+ // The only vendor implementing most of the surface, which is why it was the
499
+ // one every slug branch in three repos was written for.
500
+ //
501
+ // auth.probe is false deliberately: the health check re-registers webhooks
502
+ // rather than answering "is this token still good", and scope drift is its own
503
+ // hook because a token can be perfectly valid while the grant is too narrow.
504
+ supports: {
505
+ "auth.connect": true,
506
+ "auth.disconnect": true,
507
+ "auth.probe": false,
508
+ "auth.scopes": true,
509
+ // Shopify has no separate price resource — a price belongs to a product
510
+ // variant and arrives with it, so there is nothing for prices to answer
511
+ // that products does not already.
512
+ "catalog.prices": false,
513
+ "catalog.products": true,
514
+ "catalog.promotions": true,
515
+ "inbound.handle": true,
516
+ "inbound.topic": true,
517
+ "inbound.verify": true,
518
+ "lifecycle.cleanup": true,
519
+ "lifecycle.register": true,
520
+ "lifecycle.rehydrate": true
521
+ },
522
+ setup: [
523
+ "Open the Drawbridge listing on the Shopify App Store.",
524
+ "Install the app on the store you want to connect. It opens in Shopify admin and stays there.",
525
+ "Choose a plan when Shopify asks. The connection shows Pending until you do, then Active.",
526
+ "Come back here \u2014 the connections list updates on its own once the install lands."
527
+ ],
528
+ slug: "shopify",
529
+ // Step types name the CAPABILITY, not this vendor. A second store platform
530
+ // implements the same four commerce steps, and the connection on the step
531
+ // says which store it runs against — so a merchant sees one "Create
532
+ // customer", not one per platform. The three connection.* steps are not
533
+ // commerce at all: any vendor holding a rotating credential needs them.
534
+ steps: {
535
+ "step.commerce.customer.insert": {
536
+ billable: true,
537
+ key: "Create customer",
538
+ queue: "connection",
539
+ returns: [
540
+ { key: "shopifyCustomerId", label: "Shopify Customer ID" }
541
+ ],
542
+ settings: {},
543
+ triggers: ["lead.insert"]
544
+ },
545
+ "step.commerce.code.issue": {
546
+ billable: true,
547
+ key: "Issue a discount code",
548
+ queue: "connection",
549
+ returns: [
550
+ { key: "shopifyDiscountCode", label: "Shopify Discount Code" },
551
+ { key: "shopifyDiscountId", label: "Shopify Discount ID" }
552
+ ],
553
+ settings: {
554
+ discount: {
555
+ required: true,
556
+ shape: {
557
+ id: { required: true, type: "string" }
558
+ },
559
+ type: "object"
560
+ }
561
+ },
562
+ triggers: ["lead.insert"]
563
+ },
564
+ // System steps: dispatched by sync itself rather than offered in the
565
+ // builder, so they carry no trigger. They are declared because the
566
+ // routing table and the system-workflow descriptions both read from here.
567
+ // Not a webhook monitor, despite the name it carried. Webhooks are
568
+ // declarative — declared in the app's toml, applied by Shopify to every
569
+ // install — so nothing registers or checks them here. This rotates the
570
+ // access token before Shopify's idle window closes, and reconciles the
571
+ // scopes the store granted against the ones the app now needs.
572
+ "step.connection.health.check": {
573
+ description: "Keeps store access working \u2014 refreshes the access token before it goes stale and reports when the store's approved permissions fall behind.",
574
+ key: "Shopify Connection Health",
575
+ queue: "connection",
576
+ system: true
577
+ },
578
+ "step.commerce.order.record": {
579
+ description: "Records an order and billing charge when a purchase is made via a Drawbridge campaign link.",
580
+ key: "Shopify Order Tracking",
581
+ queue: "connection",
582
+ system: true
583
+ },
584
+ "step.commerce.product.sync": {
585
+ description: "Syncs Shopify product data on webhook updates.",
586
+ key: "Shopify Product Sync",
587
+ queue: "connection",
588
+ system: true
589
+ },
590
+ // Audit-only. The "Shopify Token Activity" system workflow lists these for
591
+ // descriptive grouping, but its audit step docs are written manually at
592
+ // OAuth time — the workflow is never dispatched. Routing is declared
593
+ // defensively so that if it ever IS dispatched, the job lands on a real
594
+ // queue and the handler lookup misses cleanly instead of throwing
595
+ // "Unknown step type".
596
+ "step.connection.token.exchange": {
597
+ key: "Shopify Token Exchange",
598
+ queue: "connection",
599
+ system: true
600
+ },
601
+ "step.connection.token.refresh": {
602
+ key: "Shopify Token Refresh",
603
+ queue: "connection",
604
+ system: true
605
+ }
606
+ },
607
+ title: "Shopify"
608
+ };
609
+
610
+ // lib/connections/icons/drawbridge.js
611
+ var drawbridge_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
612
+ <rect width="500" height="500" fill="#BAEC5F"/>
613
+ <g clip-path="url(#clip0_2115_2832)">
614
+ <path d="M140.224 127.586L174.803 188.73V311.176L140 372.32L176.084 392.031L216.111 321.753V178.278L176.341 108L140.224 127.586Z" fill="#0D1314"/>
615
+ <path d="M360.001 127.523L323.693 108.282L284.948 178.498V321.596L322.923 391.749L359.393 372.79L326.224 311.52V188.73L360.001 127.523Z" fill="#0D1314"/>
616
+ </g>
617
+ <defs>
618
+ <clipPath id="clip0_2115_2832">
619
+ <rect width="220" height="284" fill="white" transform="translate(140 108)"/>
620
+ </clipPath>
621
+ </defs>
622
+ </svg>`;
623
+
624
+ // lib/connections/webhook.js
625
+ var webhook_default = {
626
+ // Connecting GENERATES the secret rather than storing one the merchant typed,
627
+ // so the buttons say what actually happens.
628
+ actions: {
629
+ create: "Connect",
630
+ update: "Regenerate secret"
631
+ },
632
+ // GENERATED. There is no third party and nothing to authenticate against --
633
+ // connecting mints a secret rather than proving a credential.
634
+ auth: {
635
+ type: "generated"
636
+ },
637
+ category: "developer",
638
+ confirm: "Disconnecting stops Drawbridge from sending signed webhook payloads to your endpoint.",
639
+ description: [
640
+ "Drawbridge can POST event payloads to your endpoint as activity happens in your account, so your own systems can react in real time.",
641
+ "Generate a signing secret and Drawbridge signs every request with it. Your endpoint recomputes the signature to confirm each payload genuinely came from Drawbridge before acting on it."
642
+ ],
643
+ excerpt: "Sign outgoing webhook payloads with an HMAC secret to verify authenticity.",
644
+ feature: "organization:connection:webhook",
645
+ fields: [
646
+ {
647
+ // No `input`: Drawbridge generates this, the merchant never types it.
648
+ // No `redact` either — it is shared with the merchant's own endpoint
649
+ // rather than being a third-party credential, so it round-trips for
650
+ // them to copy and configure.
651
+ copy: true,
652
+ key: "secret",
653
+ label: "Signing secret"
654
+ }
655
+ ],
656
+ // Borrowed: this is the Drawbridge mark, because Webhooks has none of its own.
657
+ // It is the one card that reads wrong — our logo among vendor logos — and it
658
+ // wants a mark of its own when there is one.
659
+ icon: drawbridge_default,
660
+ label: "webhook",
661
+ // Gated on the encryption secret: without it the signing secret could not be
662
+ // stored safely, so the connection must not be offered at all.
663
+ requires: ["ENCRYPT_CONNECTION_SECRET"],
664
+ // Outbound only. inbound.* is false because the direction is the point: we
665
+ // sign and POST to the merchant's endpoint, they never call us. Every other
666
+ // false follows from there being no third party to authenticate against —
667
+ // connect generates a secret rather than proving a credential.
668
+ supports: {
669
+ "auth.connect": true,
670
+ "auth.disconnect": true,
671
+ "auth.probe": false,
672
+ "auth.scopes": false,
673
+ "catalog.prices": false,
674
+ "catalog.products": false,
675
+ "catalog.promotions": false,
676
+ "inbound.handle": false,
677
+ "inbound.topic": false,
678
+ "inbound.verify": false,
679
+ "lifecycle.cleanup": false,
680
+ "lifecycle.register": false,
681
+ "lifecycle.rehydrate": false
682
+ },
683
+ setup: [
684
+ "Press Connect. Drawbridge generates a signing secret and shows it here.",
685
+ "Copy the secret into your own endpoint.",
686
+ "On each request, compute HMAC-SHA256 of the raw body using the secret and compare it against the X-Drawbridge-Signature header before acting on the payload."
687
+ ],
688
+ slug: "webhook",
689
+ steps: {
690
+ "step.webhook.send": {
691
+ billable: true,
692
+ key: "Send webhook",
693
+ queue: "webhook",
694
+ returns: [],
695
+ settings: {
696
+ url: { format: "url", required: true, type: "string" }
697
+ },
698
+ triggers: ["lead.insert", "lead.delete"]
699
+ }
700
+ },
701
+ // The card the connection page raises. Before connecting it explains what
702
+ // pressing Connect will do; afterwards it states the verification the
703
+ // merchant's own endpoint has to perform, because a signed payload nobody
704
+ // checks is an unsigned payload.
705
+ tasks: ({ settings }) => (settings == null ? void 0 : settings.secret) ? [
706
+ {
707
+ message: "Compute HMAC-SHA256( secret, body ) and compare against the X-Drawbridge-Signature header to confirm each payload.",
708
+ title: "Requests must be verified",
709
+ type: "warning"
710
+ }
711
+ ] : [
712
+ {
713
+ message: "Connect to generate a signing secret. Drawbridge signs every webhook it sends with it.",
714
+ title: "Webhook signing"
715
+ }
716
+ ],
717
+ title: "Webhooks"
718
+ };
719
+
720
+ // lib/connections/index.js
721
+ var QUEUES = ["connection", "notification", "segment", "webhook"];
722
+ var build = (manifest) => {
723
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
724
+ if (!(manifest == null ? void 0 : manifest.slug)) throw new Error("A connection needs a slug");
725
+ if (!(manifest == null ? void 0 : manifest.title)) throw new Error(manifest.slug + " needs a title");
726
+ if (!(manifest == null ? void 0 : manifest.feature)) throw new Error(manifest.slug + " needs a plan feature key");
727
+ if (!(manifest == null ? void 0 : manifest.excerpt)) throw new Error(manifest.slug + " needs an excerpt for its card");
728
+ if (!Array.isArray(manifest == null ? void 0 : manifest.description) || !manifest.description.length) {
729
+ throw new Error(manifest.slug + " needs a description \u2014 an array of paragraphs for its page");
730
+ }
731
+ for (const field of manifest.fields || []) {
732
+ if (!(field == null ? void 0 : field.key) || !(field == null ? void 0 : field.label)) {
733
+ throw new Error(manifest.slug + " declares a field with no key or label");
734
+ }
735
+ if (field.input && !INPUTS.includes(field.input)) {
736
+ throw new Error(manifest.slug + "." + field.key + " declares an unknown input: " + field.input + " \u2014 one of " + INPUTS.join(", "));
737
+ }
738
+ if (field.input === "select" && !(field.options || []).length) {
739
+ throw new Error(manifest.slug + "." + field.key + " is a select and must declare options");
740
+ }
741
+ }
742
+ if (typeof (manifest == null ? void 0 : manifest.icon) !== "string" || !manifest.icon.includes("<svg")) {
743
+ throw new Error(manifest.slug + " needs an icon \u2014 the svg markup itself, not a path to one");
744
+ }
745
+ if (!manifest.icon.includes("viewBox")) {
746
+ throw new Error(manifest.slug + " icon has no viewBox, so it cannot scale");
747
+ }
748
+ if (manifest.icon.includes("<image")) {
749
+ throw new Error(manifest.slug + " icon wraps a raster \u2014 re-export it as vector shapes");
750
+ }
751
+ if (!CATEGORIES.includes(manifest == null ? void 0 : manifest.category)) {
752
+ throw new Error(manifest.slug + " needs a category \u2014 one of " + CATEGORIES.join(", "));
753
+ }
754
+ if ((_a = manifest == null ? void 0 : manifest.connect) == null ? void 0 : _a.type) {
755
+ throw new Error(manifest.slug + " declares connect.type \u2014 that is auth.type now");
756
+ }
757
+ if (!AUTH_TYPES.includes((_b = manifest == null ? void 0 : manifest.auth) == null ? void 0 : _b.type)) {
758
+ throw new Error(manifest.slug + " needs auth.type \u2014 one of " + AUTH_TYPES.join(", "));
759
+ }
760
+ if (manifest.auth.type === "oauth") {
761
+ for (const field of OAUTH_FIELDS) {
762
+ if (!((_c = manifest.auth.oauth) == null ? void 0 : _c[field])) {
763
+ throw new Error(manifest.slug + " is oauth and must declare auth.oauth." + field);
764
+ }
765
+ }
766
+ }
767
+ if (((_d = manifest.supports) == null ? void 0 : _d["inbound.topic"]) && !((_f = (_e = manifest.inbound) == null ? void 0 : _e.headers) == null ? void 0 : _f.topic)) {
768
+ throw new Error(manifest.slug + " supports inbound.topic but declares no inbound.headers.topic");
769
+ }
770
+ if (((_g = manifest.supports) == null ? void 0 : _g["inbound.verify"]) && !((_i = (_h = manifest.inbound) == null ? void 0 : _h.headers) == null ? void 0 : _i.signature)) {
771
+ throw new Error(manifest.slug + " supports inbound.verify but declares no inbound.headers.signature");
772
+ }
773
+ if (!Array.isArray(manifest == null ? void 0 : manifest.setup) || !manifest.setup.length) {
774
+ throw new Error(manifest.slug + " needs a setup guide \u2014 an array of steps for its page");
775
+ }
776
+ for (const [name, hook] of Object.entries(manifest.hooks || {})) {
777
+ if (!HOOK_NAMES.includes(name)) {
778
+ throw new Error(manifest.slug + " implements an unknown hook: " + name);
779
+ }
780
+ if (typeof hook !== "function") {
781
+ throw new Error(manifest.slug + " declares hook " + name + " but it is not a function");
782
+ }
783
+ if (((_j = manifest.supports) == null ? void 0 : _j[name]) !== true) {
784
+ throw new Error(manifest.slug + " implements " + name + " but declares supports[ '" + name + "' ] false");
785
+ }
786
+ }
787
+ const supports = manifest.supports || {};
788
+ for (const name of HOOK_NAMES) {
789
+ if (typeof supports[name] !== "boolean") {
790
+ throw new Error(manifest.slug + " must declare supports[ '" + name + "' ] as true or false");
791
+ }
792
+ }
793
+ for (const name of Object.keys(supports)) {
794
+ if (!HOOK_NAMES.includes(name)) {
795
+ throw new Error(manifest.slug + " declares an unknown hook: " + name);
796
+ }
797
+ }
798
+ for (const [type, step] of Object.entries(manifest.steps || {})) {
799
+ if (!type.startsWith("step.")) {
800
+ throw new Error(manifest.slug + " declares a step type that is not step.<domain>.<verb>: " + type);
801
+ }
802
+ if (!(step == null ? void 0 : step.key)) throw new Error(manifest.slug + " step " + type + " needs a key \u2014 the label the builder shows");
803
+ if (!QUEUES.includes(step == null ? void 0 : step.queue)) {
804
+ throw new Error(manifest.slug + " step " + type + " needs a queue \u2014 one of " + QUEUES.join(", "));
805
+ }
806
+ }
807
+ return Object.freeze({
808
+ ...manifest,
809
+ fields: Object.freeze(manifest.fields || []),
810
+ hooks: Object.freeze(manifest.hooks || {}),
811
+ inbound: Object.freeze(manifest.inbound || {}),
812
+ setup: Object.freeze(manifest.setup || []),
813
+ supports: Object.freeze(supports),
814
+ requires: Object.freeze(manifest.requires || []),
815
+ steps: Object.freeze(manifest.steps || {})
816
+ });
817
+ };
818
+ var connections = Object.freeze({
819
+ klaviyo: build(klaviyo_default2),
820
+ mailchimp: build(mailchimp_default2),
821
+ shopify: build(shopify_default2),
822
+ webhook: build(webhook_default)
823
+ });
824
+ (() => {
825
+ const owners = {};
826
+ for (const [slug, manifest] of Object.entries(connections)) {
827
+ for (const type of Object.keys(manifest.steps)) {
828
+ if (owners[type]) {
829
+ throw new Error("Step " + type + " is declared by both " + owners[type] + " and " + slug);
830
+ }
831
+ owners[type] = slug;
832
+ }
833
+ }
834
+ })();
835
+ var availableConnections = (env = {}) => Object.fromEntries(
836
+ Object.entries(connections).filter(
837
+ ([, manifest]) => manifest.requires.every((name) => Boolean(env[name]))
838
+ )
839
+ );
840
+ var publicSettingsBySlug = Object.fromEntries(
841
+ Object.entries(connections).map(([slug, manifest]) => [
842
+ slug,
843
+ manifest.fields.filter((field) => !field.redact).map((field) => field.key)
844
+ ])
845
+ );
846
+ var connectionSteps = (env = {}) => Object.entries(availableConnections(env)).flatMap(
847
+ ([slug, manifest]) => Object.entries(manifest.steps).map(([type, step]) => ({ ...step, slug, type }))
848
+ );
849
+ var hookSupport = (name) => ({
850
+ no: Object.keys(connections).filter((slug) => !connections[slug].supports[name]),
851
+ yes: Object.keys(connections).filter((slug) => connections[slug].supports[name])
852
+ });
853
+ var connectFields = (slug) => {
854
+ var _a;
855
+ return (((_a = connections[slug]) == null ? void 0 : _a.fields) || []).map(({ copy, from, input, key, label, message, options, placeholder, redact, required }) => ({
856
+ ...copy && { copy: true },
857
+ ...from && { from },
858
+ ...input && { input },
859
+ key,
860
+ label,
861
+ ...message && { message },
862
+ ...options && { options },
863
+ ...placeholder && { placeholder },
864
+ required: Boolean(required),
865
+ // A UI hint, not a leak: the form uses it to stop requiring the field once
866
+ // the connection exists, and to say "leave blank to keep" — because the GET
867
+ // response deliberately never returns the stored value.
868
+ secret: Boolean(redact)
869
+ }));
870
+ };
871
+ var runHook = async (slug, name, args = {}) => {
872
+ var _a, _b;
873
+ const manifest = connections[slug];
874
+ if (!manifest) return { outcome: OUTCOMES.unsupported, reason: "no such connection: " + slug };
875
+ if (!((_a = manifest.supports) == null ? void 0 : _a[name])) return { outcome: OUTCOMES.unsupported, reason: slug + " does not implement " + name };
876
+ const hook = (_b = manifest.hooks) == null ? void 0 : _b[name];
877
+ if (typeof hook !== "function") {
878
+ return { outcome: OUTCOMES.unimplemented, reason: slug + " implements " + name + " outside this package" };
879
+ }
880
+ try {
881
+ return { outcome: OUTCOMES.answered, result: await hook(args) };
882
+ } catch (error) {
883
+ return { error: (error == null ? void 0 : error.message) || "failed", outcome: OUTCOMES.failed };
884
+ }
885
+ };
886
+ var stepQueues = (env = {}) => Object.fromEntries(
887
+ connectionSteps(env).map((step) => [step.type, step.queue])
888
+ );
889
+ var scopesMessage = "Shopify permissions are out of date. Open the Drawbridge app in your Shopify admin to approve the updated permissions.";
890
+ var mergeSettings = ({ existing, incoming }) => {
891
+ if (!existing || typeof existing !== "object") return incoming;
892
+ const merged = { ...existing };
893
+ for (const [key, value] of Object.entries(incoming || {})) {
894
+ if (value !== void 0 && value !== null && value !== "") {
895
+ merged[key] = value;
896
+ }
897
+ ;
898
+ }
899
+ ;
900
+ return merged;
901
+ };
902
+ var redactSettings = ({ slug, settings }) => {
903
+ if (!settings || typeof settings !== "object") return settings;
904
+ const allowed = publicSettingsBySlug[slug] || [];
905
+ return Object.fromEntries(
906
+ Object.entries(settings).filter(([key]) => allowed.includes(key))
907
+ );
908
+ };
909
+ var publicConnectionKeys = Object.freeze([
910
+ "actions",
911
+ "category",
912
+ "confirm",
913
+ "connect",
914
+ "createdAt",
915
+ "errors",
916
+ "description",
917
+ "excerpt",
918
+ "fields",
919
+ "group",
920
+ "id",
921
+ "image",
922
+ "label",
923
+ "setup",
924
+ "settings",
925
+ "shop",
926
+ "slug",
927
+ "status",
928
+ "tasks",
929
+ "title",
930
+ "updatedAt",
931
+ "warnings"
932
+ ]);
933
+ var projectConnection = (record) => {
934
+ if (!record || typeof record !== "object") return record;
935
+ return publicConnectionKeys.reduce(
936
+ (accumulator, key) => {
937
+ if (record[key] !== void 0) {
938
+ accumulator[key] = record[key];
939
+ }
940
+ ;
941
+ return accumulator;
942
+ },
943
+ {}
944
+ );
945
+ };
946
+ var resolveConnection = (item, data) => {
947
+ if (!item) return item;
948
+ return Object.fromEntries(
949
+ Object.entries(item).filter(([key]) => !["auth", "enabled", "fields", "inbound", "requires", "steps", "supports"].includes(key)).map(([key, value]) => [
950
+ key,
951
+ typeof value === "function" ? value(data) : value
952
+ ])
953
+ );
954
+ };
955
+ // Annotate the CommonJS export names for ESM import in node:
956
+ 0 && (module.exports = {
957
+ AUTH_TYPES,
958
+ CATEGORIES,
959
+ HOOKS,
960
+ HOOK_NAMES,
961
+ INPUTS,
962
+ OAUTH_FIELDS,
963
+ OUTCOMES,
964
+ availableConnections,
965
+ build,
966
+ connectFields,
967
+ connectionSteps,
968
+ connections,
969
+ consentUrl,
970
+ exchange,
971
+ hookSupport,
972
+ mergeSettings,
973
+ pkcePair,
974
+ projectConnection,
975
+ publicConnectionKeys,
976
+ publicSettingsBySlug,
977
+ redactSettings,
978
+ refresh,
979
+ resolveConnection,
980
+ runHook,
981
+ scopesMessage,
982
+ stepQueues
983
+ });