@drawbridge/drawbridge-utils 0.0.152 → 0.0.154

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.
@@ -38,7 +38,9 @@ __export(providers_exports, {
38
38
  providerMemo: () => providerMemo,
39
39
  providerSettings: () => providerSettings,
40
40
  providerSlugs: () => providerSlugs,
41
- saveProviderSettings: () => saveProviderSettings
41
+ saveProviderSettings: () => saveProviderSettings,
42
+ vendorSettings: () => vendorSettings,
43
+ vendors: () => vendors
42
44
  });
43
45
  module.exports = __toCommonJS(providers_exports);
44
46
 
@@ -765,10 +767,16 @@ var attentive_default2 = {
765
767
  // `redact` marks a secret — never returned by the api, and blank on save means
766
768
  // keep the stored value. `required` drives the live check.
767
769
  provider: {
768
- fields: [
769
- { input: "text", key: "clientId", credential: "ATTENTIVE_OAUTH_CLIENT_ID", label: "Client ID", message: "From our app's registration in the Attentive developer portal.", required: true },
770
- { input: "password", key: "clientSecret", credential: "ATTENTIVE_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID in the Attentive developer portal.", redact: true, required: true }
771
- ]
770
+ vendors: {
771
+ attentive: {
772
+ fields: [
773
+ { input: "text", key: "clientId", credential: "ATTENTIVE_OAUTH_CLIENT_ID", label: "Client ID", message: "From our app's registration in the Attentive developer portal.", required: true },
774
+ { input: "password", key: "clientSecret", credential: "ATTENTIVE_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID in the Attentive developer portal.", redact: true, required: true }
775
+ ],
776
+ icon: attentive_default,
777
+ name: "Attentive"
778
+ }
779
+ }
772
780
  },
773
781
  requires: [
774
782
  "ATTENTIVE_OAUTH_CLIENT_ID",
@@ -1034,6 +1042,43 @@ var drawbridge_default = `<svg width="500" height="500" viewBox="0 0 500 500" fi
1034
1042
  </defs>
1035
1043
  </svg>`;
1036
1044
 
1045
+ // lib/connections/icons/hubspot.js
1046
+ var hubspot_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
1047
+ <rect width="500" height="500" fill="#FF7A59"/>
1048
+ <circle cx="290" cy="290" r="78" stroke="white" stroke-width="30"/>
1049
+ <circle cx="290" cy="290" r="18" fill="white"/>
1050
+ <path d="M290 212V150" stroke="white" stroke-width="30" stroke-linecap="round"/>
1051
+ <circle cx="290" cy="125" r="28" fill="white"/>
1052
+ <path d="M270 137L172 96" stroke="white" stroke-width="22" stroke-linecap="round"/>
1053
+ <circle cx="160" cy="91" r="20" fill="white"/>
1054
+ <path d="M233 347L184 396" stroke="white" stroke-width="26" stroke-linecap="round"/>
1055
+ <circle cx="172" cy="408" r="22" fill="white"/>
1056
+ </svg>`;
1057
+
1058
+ // lib/connections/icons/sendgrid.js
1059
+ var sendgrid_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
1060
+ <rect width="500" height="500" fill="#F1FAFF"/>
1061
+ <g clip-path="url(#clip0_1011_2743)">
1062
+ <path d="M366.676 134.534V289.172H289.203V366.487H134.258L134.258 289.171L134.256 289.172V211.851H211.729V134.534H366.676Z" fill="#9DD6E3"/>
1063
+ <path d="M134.258 366.488H211.731V289.169H134.258V366.488Z" fill="#3F72AB"/>
1064
+ <path d="M289.203 289.172H366.677V211.852H289.203V289.172Z" fill="#00A9D1"/>
1065
+ <path d="M211.729 211.853H289.202V134.534H211.729V211.853Z" fill="#00A9D1"/>
1066
+ <path d="M211.729 289.17H289.202V211.852H211.729V289.17Z" fill="#2191C4"/>
1067
+ <path d="M289.203 211.853H366.677V134.534H289.203V211.853Z" fill="#3F72AB"/>
1068
+ </g>
1069
+ <defs>
1070
+ <clipPath id="clip0_1011_2743">
1071
+ <rect width="232.42" height="231.956" fill="white" transform="translate(134.256 134.534)"/>
1072
+ </clipPath>
1073
+ </defs>
1074
+ </svg>`;
1075
+
1076
+ // lib/connections/icons/twilio.js
1077
+ var twilio_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
1078
+ <rect width="500" height="500" fill="#F22F46"/>
1079
+ <path d="M250 134.954C186.341 134.954 134.954 186.341 134.954 250C134.954 313.659 186.341 365.047 250 365.047C313.659 365.047 365.047 313.659 365.047 250C365.047 186.341 313.659 134.954 250 134.954ZM250 334.368C203.215 334.368 165.633 296.786 165.633 250C165.633 203.215 203.215 165.633 250 165.633C296.786 165.633 334.368 203.215 334.368 250C334.368 296.786 296.786 334.368 250 334.368ZM302.155 221.622C302.155 234.661 291.417 245.399 278.378 245.399C265.34 245.399 254.602 234.661 254.602 221.622C254.602 208.584 265.34 197.846 278.378 197.846C291.417 197.846 302.155 208.584 302.155 221.622ZM302.155 278.378C302.155 291.417 291.417 302.155 278.378 302.155C265.34 302.155 254.602 291.417 254.602 278.378C254.602 265.34 265.34 254.602 278.378 254.602C291.417 254.602 302.155 265.34 302.155 278.378ZM245.399 278.378C245.399 291.417 234.661 302.155 221.622 302.155C208.584 302.155 197.846 291.417 197.846 278.378C197.846 265.34 208.584 254.602 221.622 254.602C234.661 254.602 245.399 265.34 245.399 278.378ZM245.399 221.622C245.399 234.661 234.661 245.399 221.622 245.399C208.584 245.399 197.846 234.661 197.846 221.622C197.846 208.584 208.584 197.846 221.622 197.846C234.661 197.846 245.399 208.584 245.399 221.622Z" fill="white"/>
1080
+ </svg>`;
1081
+
1037
1082
  // lib/transactions.js
1038
1083
  var import_drawbridge_telemetry = require("@drawbridge/drawbridge-telemetry");
1039
1084
 
@@ -2200,37 +2245,56 @@ var drawbridge_default2 = {
2200
2245
  //
2201
2246
  // They belong on THIS manifest because this is the connection that sends: the
2202
2247
  // email, sms and segment hooks below are the only things that spend them, and
2203
- // a private connection is still where a vendor fact lives.
2248
+ // a private connection is still where a vendor fact lives. They are THREE
2249
+ // VENDORS, not one, and each is its own row and its own admin card — so
2250
+ // SendGrid reads live on a deployment that never configured Twilio, instead
2251
+ // of one card for all three that could only ever be as live as its weakest.
2204
2252
  //
2205
2253
  // UNLIKE every public vendor, none of these appear in `requires` — see the
2206
2254
  // comment there. Availability and configuration are different questions, and a
2207
2255
  // missing CRM token must not take every base workflow step away.
2256
+ //
2257
+ // ponytail: the field keys keep the names they had on the shared row
2258
+ // (smsSid, hubspotToken) so the readers destructuring vendorSettings() did
2259
+ // not move. Rename them to sid/token when those readers are next touched.
2208
2260
  provider: {
2209
- fields: [
2210
- { input: "email", key: "accountSender", credential: "SENDGRID_FROM_ADDRESS", label: "Account sender", message: "Verification codes and security alerts send from here.", required: true },
2211
- { input: "password", key: "apiKey", credential: "SENDGRID_API_KEY", label: "SendGrid API key", message: "SendGrid dashboard, Settings, API Keys \u2014 full access for sends.", redact: true, required: true },
2212
- // NOT required. The CRM sync is best-effort internal tooling and no-ops
2213
- // without a token requiring it would make the whole drawbridge provider
2214
- // read not-live over something no merchant ever sees.
2215
- { input: "password", key: "hubspotToken", credential: "HUBSPOT_ACCESS_TOKEN", label: "HubSpot access token", message: "Drawbridge's own CRM portal. Internal \u2014 no merchant sees this.", redact: true },
2216
- // Optional: SENDGRID_SEND_FROM_ADDRESS is not boot-required in sync
2217
- // either. Unset, it degrades to the account sender rather than
2218
- // refusing to start.
2219
- { input: "email", key: "leadSender", credential: "SENDGRID_SEND_FROM_ADDRESS", label: "Lead sender", message: "The default for lead-facing mail when a merchant has not verified their own domain." },
2220
- // NOT required, the three of them together. SendGrid alone is enough to
2221
- // run the platform — sign-in codes, notifications and every lead-facing
2222
- // mail are email. Requiring Twilio here made the whole drawbridge
2223
- // provider read not-live on a deployment that never sends SMS, over a
2224
- // channel it was not using.
2225
- //
2261
+ vendors: {
2262
+ sendgrid: {
2263
+ fields: [
2264
+ { input: "email", key: "accountSender", credential: "SENDGRID_FROM_ADDRESS", label: "Account sender", message: "Verification codes and security alerts send from here.", required: true },
2265
+ { input: "password", key: "apiKey", credential: "SENDGRID_API_KEY", label: "SendGrid API key", message: "SendGrid dashboard, Settings, API Keys \u2014 full access for sends.", redact: true, required: true },
2266
+ // Optional: SENDGRID_SEND_FROM_ADDRESS is not boot-required in sync
2267
+ // either. Unset, it degrades to the account sender rather than
2268
+ // refusing to start.
2269
+ { input: "email", key: "leadSender", credential: "SENDGRID_SEND_FROM_ADDRESS", label: "Lead sender", message: "The default for lead-facing mail when a merchant has not verified their own domain." }
2270
+ ],
2271
+ icon: sendgrid_default,
2272
+ name: "SendGrid"
2273
+ },
2226
2274
  // Missing, SMS is LOCKED DOWN rather than broken: every send path
2227
2275
  // refuses cleanly (queue/notification.js cancels, the otc stream skips
2228
2276
  // and logs), the number-purchase routes deny, and identityDefaults.sms
2229
- // hides the org's SMS settings entirely.
2230
- { input: "text", key: "smsFrom", credential: "TWILIO_ACCOUNT_FROM", label: "SMS number", message: "Without Twilio credentials, SMS is disabled across the platform." },
2231
- { input: "password", key: "smsSid", credential: "TWILIO_ACCOUNT_SID", label: "Twilio account SID", message: "Twilio console home \u2014 the AC\u2026 identifier on the account dashboard.", redact: true },
2232
- { input: "password", key: "smsToken", credential: "TWILIO_AUTH_TOKEN", label: "Twilio auth token", message: "Beside the account SID on the Twilio console dashboard.", redact: true }
2233
- ]
2277
+ // hides the org's SMS settings entirely. The card reads not live, which
2278
+ // is the truth about Twilio and says nothing about email.
2279
+ twilio: {
2280
+ fields: [
2281
+ { input: "text", key: "smsFrom", credential: "TWILIO_ACCOUNT_FROM", label: "SMS number", message: "Without Twilio credentials, SMS is disabled across the platform.", required: true },
2282
+ { input: "password", key: "smsSid", credential: "TWILIO_ACCOUNT_SID", label: "Twilio account SID", message: "Twilio console home \u2014 the AC\u2026 identifier on the account dashboard.", redact: true, required: true },
2283
+ { input: "password", key: "smsToken", credential: "TWILIO_AUTH_TOKEN", label: "Twilio auth token", message: "Beside the account SID on the Twilio console dashboard.", redact: true, required: true }
2284
+ ],
2285
+ icon: twilio_default,
2286
+ name: "Twilio"
2287
+ },
2288
+ // The CRM sync is best-effort internal tooling and no-ops without a
2289
+ // token. Not live here costs nothing a merchant can see.
2290
+ hubspot: {
2291
+ fields: [
2292
+ { input: "password", key: "hubspotToken", credential: "HUBSPOT_ACCESS_TOKEN", label: "HubSpot access token", message: "Drawbridge's own CRM portal. Internal \u2014 no merchant sees this.", redact: true, required: true }
2293
+ ],
2294
+ icon: hubspot_default,
2295
+ name: "HubSpot"
2296
+ }
2297
+ }
2234
2298
  },
2235
2299
  // NOTHING, and HUBSPOT_ACCESS_TOKEN in particular must not be here.
2236
2300
  //
@@ -2816,12 +2880,20 @@ var klaviyo_default2 = {
2816
2880
  // DRAWBRIDGE'S OWN CREDENTIALS for this vendor, as opposed to a merchant's —
2817
2881
  // what an admin types on the provider screen. Declared here rather than in a
2818
2882
  // table in lib/providers.js, so a vendor's credentials sit beside the
2819
- // `requires` that names the same variables.
2883
+ // `requires` that names the same variables. Keyed by the VENDOR that holds
2884
+ // them — here the vendor and the connection are the same thing, which is not
2885
+ // true of every manifest.
2820
2886
  provider: {
2821
- fields: [
2822
- { input: "text", key: "clientId", credential: "KLAVIYO_OAUTH_CLIENT_ID", label: "Client ID", message: "From our app in the Klaviyo developer portal (developers.klaviyo.com).", required: true },
2823
- { input: "password", key: "clientSecret", credential: "KLAVIYO_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID on the Klaviyo app.", redact: true, required: true }
2824
- ]
2887
+ vendors: {
2888
+ klaviyo: {
2889
+ fields: [
2890
+ { input: "text", key: "clientId", credential: "KLAVIYO_OAUTH_CLIENT_ID", label: "Client ID", message: "From our app in the Klaviyo developer portal (developers.klaviyo.com).", required: true },
2891
+ { input: "password", key: "clientSecret", credential: "KLAVIYO_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID on the Klaviyo app.", redact: true, required: true }
2892
+ ],
2893
+ icon: klaviyo_default,
2894
+ name: "Klaviyo"
2895
+ }
2896
+ }
2825
2897
  },
2826
2898
  requires: [
2827
2899
  "KLAVIYO_OAUTH_CLIENT_ID",
@@ -3164,10 +3236,16 @@ var mailchimp_default2 = {
3164
3236
  // what an admin types on the provider screen, beside the `requires` naming the
3165
3237
  // same variables.
3166
3238
  provider: {
3167
- fields: [
3168
- { input: "text", key: "clientId", credential: "MAILCHIMP_OAUTH_CLIENT_ID", label: "Client ID", message: "From our registered app \u2014 Mailchimp account, Extras, Registered apps.", required: true },
3169
- { input: "password", key: "clientSecret", credential: "MAILCHIMP_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID on the registered app.", redact: true, required: true }
3170
- ]
3239
+ vendors: {
3240
+ mailchimp: {
3241
+ fields: [
3242
+ { input: "text", key: "clientId", credential: "MAILCHIMP_OAUTH_CLIENT_ID", label: "Client ID", message: "From our registered app \u2014 Mailchimp account, Extras, Registered apps.", required: true },
3243
+ { input: "password", key: "clientSecret", credential: "MAILCHIMP_OAUTH_CLIENT_SECRET", label: "Client secret", message: "Beside the Client ID on the registered app.", redact: true, required: true }
3244
+ ],
3245
+ icon: mailchimp_default,
3246
+ name: "Mailchimp"
3247
+ }
3248
+ }
3171
3249
  },
3172
3250
  // The OAuth client this deployment registered. Without both, the vendor drops
3173
3251
  // out of availableConnections rather than offering a Connect button that
@@ -3977,7 +4055,9 @@ var shopify_default2 = {
3977
4055
  enqueues: [{
3978
4056
  data: { product: productId, providerId, shop: connection2.shop },
3979
4057
  name: "workflow",
3980
- options: { jobId: "product.workflow.shopify." + providerId + "." + Date.now() },
4058
+ // The numeric id, not the gid: BullMQ refuses a custom id with a
4059
+ // colon in it, and every gid carries two.
4060
+ options: { jobId: "product.workflow.shopify." + context.id + "." + Date.now() },
3981
4061
  queue: "product.shopify"
3982
4062
  }],
3983
4063
  message: "Product sync queued from Shopify webhook.",
@@ -4423,28 +4503,34 @@ var shopify_default2 = {
4423
4503
  // name required by the manifest and enterable nowhere is a vendor that can
4424
4504
  // never go live from the admin screen.
4425
4505
  provider: {
4426
- fields: [
4427
- { input: "text", key: "apiKey", credential: "SHOPIFY_API_KEY", label: "API key", message: "The app's Client ID \u2014 Dev Dashboard, the app, Settings.", required: true },
4428
- { input: "password", key: "apiSecret", credential: "SHOPIFY_API_SECRET", label: "API secret", message: "The app's Client secret, beside the Client ID in the app's settings.", redact: true, required: true },
4429
- { input: "text", key: "appHandle", credential: "SHOPIFY_APP_HANDLE", label: "App handle", message: "The app's URL handle (for example drawbridge-development), from the app's configuration.", required: true },
4430
- { input: "text", key: "listingUrl", credential: "SHOPIFY_APP_LISTING_URL", label: "App listing URL", message: 'Where "View on the Shopify App Store" sends merchants \u2014 the public listing, or the Dev Dashboard install link for the dev app.', required: true },
4431
- // The usage meter's event handle, when the plan config's meter ever
4432
- // changes: stored value overrides the built-in default
4433
- // (events.order.handle) at the mint point, and `format : 'slug'`
4434
- // normalizes it on save a handle can carry no spaces or capitals,
4435
- // and classification against it is case-sensitive. Optional: empty
4436
- // means the default, and the sender still refuses any handle that
4437
- // disagrees with the transaction it minted.
4438
- { format: "slug", input: "text", key: "orderEventHandle", label: "Order event handle", message: "Must match the usage meter's Handle field on the plan exactly \u2014 lowercase and hyphens. Leave empty to use drawbridge-orders.", required: false, setting: true },
4439
- // The Partner API credential set — the ONE place meter billing is
4440
- // observable (CHARGE_USAGE accrual events). Org id and numeric app
4441
- // id come from the Partner Dashboard; the token from Settings
4442
- // Partner API clients (Manage-apps permission). All optional: the
4443
- // accrual probe simply stays off until they exist.
4444
- { input: "text", key: "partnerOrgId", label: "Partner organization ID", message: "The number in the Partner Dashboard URL \u2014 partners.shopify.com/<this number>/\u2026 \u2014 NOT the admin organization_id from the app listing link.", required: false, setting: true },
4445
- { input: "text", key: "partnerAppId", label: "Partner app ID (numeric)", message: "The numeric id in the app's Partner Dashboard URL \u2014 not the Client ID.", required: false, setting: true },
4446
- { input: "password", key: "partnerToken", label: "Partner API token", message: "Partner Dashboard, Settings, Partner API clients \u2014 create one with Manage apps and paste the prtapi_ token.", redact: true, required: false, setting: true }
4447
- ]
4506
+ vendors: {
4507
+ shopify: {
4508
+ fields: [
4509
+ { input: "text", key: "apiKey", credential: "SHOPIFY_API_KEY", label: "API key", message: "The app's Client ID \u2014 Dev Dashboard, the app, Settings.", required: true },
4510
+ { input: "password", key: "apiSecret", credential: "SHOPIFY_API_SECRET", label: "API secret", message: "The app's Client secret, beside the Client ID in the app's settings.", redact: true, required: true },
4511
+ { input: "text", key: "appHandle", credential: "SHOPIFY_APP_HANDLE", label: "App handle", message: "The app's URL handle (for example drawbridge-development), from the app's configuration.", required: true },
4512
+ { input: "text", key: "listingUrl", credential: "SHOPIFY_APP_LISTING_URL", label: "App listing URL", message: 'Where "View on the Shopify App Store" sends merchants \u2014 the public listing, or the Dev Dashboard install link for the dev app.', required: true },
4513
+ // The usage meter's event handle, when the plan config's meter ever
4514
+ // changes: stored value overrides the built-in default
4515
+ // (events.order.handle) at the mint point, and `format : 'slug'`
4516
+ // normalizes it on save a handle can carry no spaces or capitals,
4517
+ // and classification against it is case-sensitive. Optional: empty
4518
+ // means the default, and the sender still refuses any handle that
4519
+ // disagrees with the transaction it minted.
4520
+ { format: "slug", input: "text", key: "orderEventHandle", label: "Order event handle", message: "Must match the usage meter's Handle field on the plan exactly \u2014 lowercase and hyphens. Leave empty to use drawbridge-orders.", required: false, setting: true },
4521
+ // The Partner API credential set the ONE place meter billing is
4522
+ // observable (CHARGE_USAGE accrual events). Org id and numeric app
4523
+ // id come from the Partner Dashboard; the token from Settings →
4524
+ // Partner API clients (Manage-apps permission). All optional: the
4525
+ // accrual probe simply stays off until they exist.
4526
+ { input: "text", key: "partnerOrgId", label: "Partner organization ID", message: "The number in the Partner Dashboard URL \u2014 partners.shopify.com/<this number>/\u2026 \u2014 NOT the admin organization_id from the app listing link.", required: false, setting: true },
4527
+ { input: "text", key: "partnerAppId", label: "Partner app ID (numeric)", message: "The numeric id in the app's Partner Dashboard URL \u2014 not the Client ID.", required: false, setting: true },
4528
+ { input: "password", key: "partnerToken", label: "Partner API token", message: "Partner Dashboard, Settings, Partner API clients \u2014 create one with Manage apps and paste the prtapi_ token.", redact: true, required: false, setting: true }
4529
+ ],
4530
+ icon: shopify_default,
4531
+ name: "Shopify"
4532
+ }
4533
+ }
4448
4534
  },
4449
4535
  // A pre-launch integration: it only surfaces once the App Store listing
4450
4536
  // exists and the app is fully configured. Requiring all four means it can
@@ -4925,8 +5011,19 @@ var implemented = (hooks, path) => {
4925
5011
  var leaves = (node, path = []) => Object.entries(node || {}).flatMap(
4926
5012
  ([key, value]) => typeof value === "function" ? [[[...path, key].join("."), value]] : value && typeof value === "object" ? leaves(value, [...path, key]) : []
4927
5013
  );
5014
+ var checkIcon = (owner, icon) => {
5015
+ if (typeof icon !== "string" || !icon.includes("<svg")) {
5016
+ throw new Error(owner + " needs an icon \u2014 the svg markup itself, not a path to one");
5017
+ }
5018
+ if (!icon.includes("viewBox")) {
5019
+ throw new Error(owner + " icon has no viewBox, so it cannot scale");
5020
+ }
5021
+ if (icon.includes("<image")) {
5022
+ throw new Error(owner + " icon wraps a raster \u2014 re-export it as vector shapes");
5023
+ }
5024
+ };
4928
5025
  var build = (manifest) => {
4929
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
5026
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
4930
5027
  if (!(manifest == null ? void 0 : manifest.slug)) throw new Error("A connection needs a slug");
4931
5028
  if (!(manifest == null ? void 0 : manifest.title)) throw new Error(manifest.slug + " needs a title");
4932
5029
  if (!(manifest == null ? void 0 : manifest.private) && !(manifest == null ? void 0 : manifest.feature)) throw new Error(manifest.slug + " needs a plan feature key");
@@ -4956,46 +5053,53 @@ var build = (manifest) => {
4956
5053
  }
4957
5054
  }
4958
5055
  }
4959
- for (const field2 of ((_c = manifest.provider) == null ? void 0 : _c.fields) || []) {
4960
- if (!(field2 == null ? void 0 : field2.key) || !(field2 == null ? void 0 : field2.label)) {
4961
- throw new Error(manifest.slug + " declares a provider field with no key or label");
4962
- }
4963
- if (!INPUTS.includes(field2.input)) {
4964
- throw new Error(manifest.slug + ".provider." + field2.key + " needs an input the admin form can render \u2014 one of " + INPUTS.join(", "));
5056
+ if ((_c = manifest.provider) == null ? void 0 : _c.fields) {
5057
+ throw new Error(manifest.slug + " declares provider.fields \u2014 fields live under provider.vendors.<vendor> now, keyed by the vendor that holds them");
5058
+ }
5059
+ const declaredKeys = /* @__PURE__ */ new Set();
5060
+ for (const [vendor, declared] of Object.entries(((_d = manifest.provider) == null ? void 0 : _d.vendors) || {})) {
5061
+ if (!(declared == null ? void 0 : declared.name)) throw new Error(manifest.slug + " declares vendor " + vendor + " with no name");
5062
+ checkIcon(manifest.slug + " vendor " + vendor, declared.icon);
5063
+ if (!Array.isArray(declared.fields) || !declared.fields.length) {
5064
+ throw new Error(manifest.slug + " declares vendor " + vendor + " with no fields \u2014 a vendor nothing is typed into holds nothing");
4965
5065
  }
4966
- if (field2.input === "password" && !field2.redact) {
4967
- throw new Error(manifest.slug + ".provider." + field2.key + " is a password and must declare redact : true \u2014 the api would hand the value back");
5066
+ for (const field2 of declared.fields) {
5067
+ if (!(field2 == null ? void 0 : field2.key) || !(field2 == null ? void 0 : field2.label)) {
5068
+ throw new Error(manifest.slug + " declares a provider field with no key or label");
5069
+ }
5070
+ if (!INPUTS.includes(field2.input)) {
5071
+ throw new Error(manifest.slug + ".provider." + field2.key + " needs an input the admin form can render \u2014 one of " + INPUTS.join(", "));
5072
+ }
5073
+ if (field2.input === "password" && !field2.redact) {
5074
+ throw new Error(manifest.slug + ".provider." + field2.key + " is a password and must declare redact : true \u2014 the api would hand the value back");
5075
+ }
5076
+ if (declaredKeys.has(field2.key)) {
5077
+ throw new Error(manifest.slug + " declares " + field2.key + " under two vendors \u2014 vendorSettings() merges them and one would win");
5078
+ }
5079
+ declaredKeys.add(field2.key);
4968
5080
  }
4969
5081
  }
4970
- if (typeof (manifest == null ? void 0 : manifest.icon) !== "string" || !manifest.icon.includes("<svg")) {
4971
- throw new Error(manifest.slug + " needs an icon \u2014 the svg markup itself, not a path to one");
4972
- }
4973
- if (!manifest.icon.includes("viewBox")) {
4974
- throw new Error(manifest.slug + " icon has no viewBox, so it cannot scale");
4975
- }
4976
- if (manifest.icon.includes("<image")) {
4977
- throw new Error(manifest.slug + " icon wraps a raster \u2014 re-export it as vector shapes");
4978
- }
5082
+ checkIcon(manifest.slug, manifest == null ? void 0 : manifest.icon);
4979
5083
  if (!GROUPS.includes(manifest == null ? void 0 : manifest.group)) {
4980
5084
  throw new Error(manifest.slug + " needs a group \u2014 one of " + GROUPS.join(", "));
4981
5085
  }
4982
- if ((_d = manifest == null ? void 0 : manifest.connect) == null ? void 0 : _d.type) {
5086
+ if ((_e = manifest == null ? void 0 : manifest.connect) == null ? void 0 : _e.type) {
4983
5087
  throw new Error(manifest.slug + " declares connect.type \u2014 that is auth.type now");
4984
5088
  }
4985
- if (!AUTH_TYPES.includes((_e = manifest == null ? void 0 : manifest.auth) == null ? void 0 : _e.type)) {
5089
+ if (!AUTH_TYPES.includes((_f = manifest == null ? void 0 : manifest.auth) == null ? void 0 : _f.type)) {
4986
5090
  throw new Error(manifest.slug + " needs auth.type \u2014 one of " + AUTH_TYPES.join(", "));
4987
5091
  }
4988
5092
  if (manifest.auth.type === "oauth") {
4989
5093
  for (const field2 of OAUTH_FIELDS) {
4990
- if (!((_f = manifest.auth.oauth) == null ? void 0 : _f[field2])) {
5094
+ if (!((_g = manifest.auth.oauth) == null ? void 0 : _g[field2])) {
4991
5095
  throw new Error(manifest.slug + " is oauth and must declare auth.oauth." + field2);
4992
5096
  }
4993
5097
  }
4994
- if (typeof ((_h = (_g = manifest.hooks) == null ? void 0 : _g.auth) == null ? void 0 : _h.token) !== "function") {
5098
+ if (typeof ((_i = (_h = manifest.hooks) == null ? void 0 : _h.auth) == null ? void 0 : _i.token) !== "function") {
4995
5099
  throw new Error(manifest.slug + " is oauth and must implement hooks.auth.token \u2014 point it at authToken() or wrap it");
4996
5100
  }
4997
5101
  for (const url of OAUTH_URLS) {
4998
- if (!((_j = (_i = manifest.auth.oauth) == null ? void 0 : _i.urls) == null ? void 0 : _j[url])) {
5102
+ if (!((_k = (_j = manifest.auth.oauth) == null ? void 0 : _j.urls) == null ? void 0 : _k[url])) {
4999
5103
  throw new Error(manifest.slug + " is oauth and must declare auth.oauth.urls." + url);
5000
5104
  }
5001
5105
  }
@@ -5005,16 +5109,16 @@ var build = (manifest) => {
5005
5109
  );
5006
5110
  }
5007
5111
  }
5008
- if (implemented(manifest.hooks, "inbound.event") && typeof ((_l = (_k = manifest.hooks) == null ? void 0 : _k.inbound) == null ? void 0 : _l.event) !== "function" && !((_n = (_m = manifest.inbound) == null ? void 0 : _m.headers) == null ? void 0 : _n.event)) {
5112
+ if (implemented(manifest.hooks, "inbound.event") && typeof ((_m = (_l = manifest.hooks) == null ? void 0 : _l.inbound) == null ? void 0 : _m.event) !== "function" && !((_o = (_n = manifest.inbound) == null ? void 0 : _n.headers) == null ? void 0 : _o.event)) {
5009
5113
  throw new Error(manifest.slug + " implements inbound.event but declares no inbound.headers.event");
5010
5114
  }
5011
- if (implemented(manifest.hooks, "inbound.verify") && !((_p = (_o = manifest.inbound) == null ? void 0 : _o.headers) == null ? void 0 : _p.signature)) {
5115
+ if (implemented(manifest.hooks, "inbound.verify") && !((_q = (_p = manifest.inbound) == null ? void 0 : _p.headers) == null ? void 0 : _q.signature)) {
5012
5116
  throw new Error(manifest.slug + " implements inbound.verify but declares no inbound.headers.signature");
5013
5117
  }
5014
5118
  if (typeof (manifest == null ? void 0 : manifest.status) !== "function") {
5015
5119
  throw new Error(manifest.slug + " must declare status( data ) \u2014 return null to accept the connection's own status, or { message, status } to override it");
5016
5120
  }
5017
- if (!Array.isArray((_q = manifest == null ? void 0 : manifest.content) == null ? void 0 : _q.guide) || !manifest.content.guide.length) {
5121
+ if (!Array.isArray((_r = manifest == null ? void 0 : manifest.content) == null ? void 0 : _r.guide) || !manifest.content.guide.length) {
5018
5122
  throw new Error(manifest.slug + " needs content.guide \u2014 an array of steps for its page");
5019
5123
  }
5020
5124
  if (typeof (manifest == null ? void 0 : manifest.status) !== "function") {
@@ -5026,8 +5130,8 @@ var build = (manifest) => {
5026
5130
  }
5027
5131
  for (const [domain, verbs] of Object.entries(HOOKS)) {
5028
5132
  for (const verb of verbs) {
5029
- const hook = (_s = (_r = manifest.hooks) == null ? void 0 : _r[domain]) == null ? void 0 : _s[verb];
5030
- if (((_t = manifest.hooks) == null ? void 0 : _t[domain]) === false) continue;
5133
+ const hook = (_t = (_s = manifest.hooks) == null ? void 0 : _s[domain]) == null ? void 0 : _t[verb];
5134
+ if (((_u = manifest.hooks) == null ? void 0 : _u[domain]) === false) continue;
5031
5135
  if (hook !== false && !implemented({ [domain]: { [verb]: hook } }, domain + "." + verb)) {
5032
5136
  throw new Error(manifest.slug + " must answer hooks." + domain + "." + verb + " \u2014 false, a function, or {} if another repo implements it");
5033
5137
  }
@@ -5072,6 +5176,44 @@ var connections = Object.freeze({
5072
5176
  shopify: build(shopify_default2),
5073
5177
  webhook: build(webhook_default)
5074
5178
  });
5179
+ var canonical = (field2) => JSON.stringify(Object.fromEntries(Object.entries(field2).sort()));
5180
+ var mergeVendors = (catalog) => {
5181
+ var _a;
5182
+ const merged = {};
5183
+ const claimed = /* @__PURE__ */ new Map();
5184
+ for (const [slug2, manifest] of Object.entries(catalog)) {
5185
+ for (const [vendor, declared] of Object.entries(((_a = manifest.provider) == null ? void 0 : _a.vendors) || {})) {
5186
+ const held = merged[vendor] || (merged[vendor] = { fields: [], icon: declared.icon, name: declared.name });
5187
+ if (held.name !== declared.name) {
5188
+ throw new Error(slug2 + " names vendor " + vendor + ' "' + declared.name + '" but another manifest names it "' + held.name + '"');
5189
+ }
5190
+ if (held.icon !== declared.icon) {
5191
+ throw new Error(slug2 + " declares a different icon for vendor " + vendor + " than another manifest \u2014 one vendor, one mark");
5192
+ }
5193
+ for (const field2 of declared.fields) {
5194
+ const existing = held.fields.find((entry) => entry.key === field2.key);
5195
+ if (existing) {
5196
+ if (canonical(existing) !== canonical(field2)) {
5197
+ throw new Error(slug2 + " declares " + vendor + "." + field2.key + " differently from another manifest \u2014 a field two connections spend is declared identically in both");
5198
+ }
5199
+ continue;
5200
+ }
5201
+ if (field2.credential) {
5202
+ const owner = claimed.get(field2.credential);
5203
+ if (owner) {
5204
+ throw new Error(field2.credential + " is claimed by both " + owner + " and " + vendor + "." + field2.key + " \u2014 one would silently overwrite the other");
5205
+ }
5206
+ claimed.set(field2.credential, vendor + "." + field2.key);
5207
+ }
5208
+ held.fields.push(field2);
5209
+ }
5210
+ }
5211
+ }
5212
+ return Object.freeze(Object.fromEntries(
5213
+ Object.entries(merged).map(([vendor, held]) => [vendor, Object.freeze({ ...held, fields: Object.freeze(held.fields) })])
5214
+ ));
5215
+ };
5216
+ var vendors = mergeVendors(connections);
5075
5217
  (() => {
5076
5218
  var _a;
5077
5219
  const routes = {};
@@ -5144,11 +5286,8 @@ var publicConnectionKeys = Object.freeze([
5144
5286
  ]);
5145
5287
 
5146
5288
  // lib/providers.js
5147
- var providerFields = (slug2) => {
5148
- var _a;
5149
- return Object.hasOwn(connections, slug2) ? ((_a = connections[slug2].provider) == null ? void 0 : _a.fields) || [] : [];
5150
- };
5151
- var providerSlugs = () => Object.keys(connections).filter((slug2) => connections[slug2].provider).sort();
5289
+ var providerFields = (slug2) => Object.hasOwn(vendors, slug2) ? vendors[slug2].fields : [];
5290
+ var providerSlugs = () => Object.keys(vendors).sort();
5152
5291
  var isLive = (slug2, settings) => {
5153
5292
  const fields2 = providerFields(slug2);
5154
5293
  if (!fields2.length) return false;
@@ -5173,6 +5312,15 @@ var providerSettings = async ({ controller, slug: slug2 }) => {
5173
5312
  providerMemo.set(slug2, { at: Date.now(), value });
5174
5313
  return value;
5175
5314
  };
5315
+ var vendorSettings = async ({ controller, slug: slug2 }) => {
5316
+ var _a;
5317
+ const declared = Object.hasOwn(connections, slug2) ? Object.keys(((_a = connections[slug2].provider) == null ? void 0 : _a.vendors) || {}) : [];
5318
+ let merged = {};
5319
+ for (const vendor of declared) {
5320
+ merged = { ...merged, ...await providerSettings({ controller, slug: vendor }) };
5321
+ }
5322
+ return merged;
5323
+ };
5176
5324
  var saveProviderSettings = async ({ authenticated, clear, controller, settings, slug: slug2 }) => {
5177
5325
  const fields2 = providerFields(slug2);
5178
5326
  if (!fields2.length) return null;
@@ -5235,5 +5383,7 @@ var providerCredentials = async ({ controller }) => {
5235
5383
  providerMemo,
5236
5384
  providerSettings,
5237
5385
  providerSlugs,
5238
- saveProviderSettings
5386
+ saveProviderSettings,
5387
+ vendorSettings,
5388
+ vendors
5239
5389
  });
@@ -1,4 +1,4 @@
1
- import { connections, mergeSettings } from './connections/index.cjs';
1
+ import { vendors, mergeSettings, connections } from './connections/index.cjs';
2
2
  import { decrypt, encrypt } from './encrypt.cjs';
3
3
  import { slugify } from './slugify.cjs';
4
4
  import './connections/oauth.cjs';
@@ -58,27 +58,26 @@ import 'slugify';
58
58
  // `requires` and auth.oauth.client did not have to change when the storage
59
59
  // moved into the database.
60
60
  //
61
- // So the declaration lives on the manifest as `provider : { fields }`, build()
62
- // checks its shape at import, and this module is now only the reading, memoizing
63
- // and encrypting around it.
61
+ // A manifest declares the fields it spends under `provider.vendors.<vendor>`,
62
+ // connections/index.js merges every manifest's declarations into one entry per
63
+ // vendor, and this module is only the reading, memoizing and encrypting around
64
+ // that. The `provider` collection is keyed the same way: one row per vendor.
64
65
  //
65
- // Object.hasOwn, not `connections[ slug ] ||` — a bare property read walks the
66
- // prototype chain, and connections[ 'constructor' ] is a function whose .length
67
- // is 1, so the route's "does this vendor exist" guard passed for it and reached
68
- // the database before throwing.
66
+ // Object.hasOwn, not `vendors[ slug ] ||` — a bare property read walks the
67
+ // prototype chain, and vendors[ 'constructor' ] is a function whose .length is
68
+ // 1, so the route's "does this vendor exist" guard passed for it and reached the
69
+ // database before throwing.
69
70
  const providerFields = ( slug ) => (
70
- Object.hasOwn( connections, slug ) ? ( connections[ slug ].provider?.fields || [] ) : []
71
+ Object.hasOwn( vendors, slug ) ? vendors[ slug ].fields : []
71
72
  );
72
73
 
73
74
  // The vendors an admin can configure, in a stable order.
74
75
  //
75
- // DERIVED FROM WHO DECLARES A PROVIDER BLOCK, not from the catalog: `webhook` is
76
- // a connection with no vendor behind it — nothing to authenticate against and
76
+ // DERIVED FROM WHO DECLARES A VENDOR, not from the catalog: `webhook` is a
77
+ // connection with no vendor behind it — nothing to authenticate against and
77
78
  // nothing to type — so it must not appear on a screen whose whole purpose is
78
79
  // entering credentials.
79
- const providerSlugs = () => Object.keys( connections )
80
- .filter( ( slug ) => connections[ slug ].provider )
81
- .sort();
80
+ const providerSlugs = () => Object.keys( vendors ).sort();
82
81
 
83
82
  // LIVE IS DERIVED, never stored. A stored flag is a second thing to keep in
84
83
  // sync and goes stale the moment a row is edited by hand.
@@ -171,6 +170,29 @@ const providerSettings = async ({ controller, slug }) => {
171
170
 
172
171
  };
173
172
 
173
+ // EVERYTHING A CONNECTION SPENDS, merged across the vendors its manifest
174
+ // declares. `drawbridge` reads SendGrid, Twilio and HubSpot as one object, the
175
+ // way it did when they sat on one row — the row split, the readers did not.
176
+ //
177
+ // Safe to merge because build() refuses a manifest whose vendors share a field
178
+ // key. Each vendor read is memoized on its own, so three vendors are three Map
179
+ // lookups inside the window.
180
+ const vendorSettings = async ({ controller, slug }) => {
181
+
182
+ const declared = Object.hasOwn( connections, slug ) ? Object.keys( connections[ slug ].provider?.vendors || {} ) : [];
183
+
184
+ let merged = {};
185
+
186
+ for( const vendor of declared ){
187
+
188
+ merged = { ...merged, ...await providerSettings({ controller, slug : vendor }) };
189
+
190
+ }
191
+
192
+ return merged;
193
+
194
+ };
195
+
174
196
  // Write a vendor's credentials.
175
197
  //
176
198
  // ONLY THE DECLARED FIELDS. The body arrives over the wire, so anything in it
@@ -325,4 +347,4 @@ const providerCredentials = async ({ controller }) => {
325
347
 
326
348
  };
327
349
 
328
- export { clearProviderMemo, isLive, mask, providerCredentials, providerEnvNames, providerFields, providerMemo, providerSettings, providerSlugs, saveProviderSettings };
350
+ export { clearProviderMemo, isLive, mask, providerCredentials, providerEnvNames, providerFields, providerMemo, providerSettings, providerSlugs, saveProviderSettings, vendorSettings, vendors };