@drawbridge/drawbridge-utils 0.0.168 → 0.0.170

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.
@@ -205,7 +205,20 @@ var HOOKS = Object.freeze({
205
205
  "digest"
206
206
  ]),
207
207
  sms: Object.freeze(["send"]),
208
- segment: Object.freeze(["sync"]),
208
+ segment: Object.freeze([
209
+ // Make this segment's object exist at the vendor, carrying the segment's
210
+ // current title, and describe the row that points at it. IDEMPOTENT: the
211
+ // same call creates it, renames it after an edit, and backfills a segment
212
+ // that predates the connection — so one hook serves every path and there
213
+ // is no create-vs-update branch to keep in step.
214
+ "register",
215
+ // Remove the vendor object this connection's row points at. Called with
216
+ // the pre-image on a segment delete, because by then the document is gone.
217
+ "remove",
218
+ // Recalculate Drawbridge-side membership. Private to the drawbridge
219
+ // manifest; a vendor does not own who is in a Drawbridge segment.
220
+ "sync"
221
+ ]),
209
222
  // OUTBOUND DELIVERY to an address the merchant owns, rather than to a vendor.
210
223
  // The Webhooks connection is the only thing here with no third party behind
211
224
  // it, and the destination is per STEP rather than per connection.
@@ -350,6 +363,8 @@ var STEPS = Object.freeze({
350
363
  "email.digest": "Digest",
351
364
  "email.notify": "Notification",
352
365
  "email.send": "Send email",
366
+ "segment.register": "Register segment",
367
+ "segment.remove": "Remove segment",
353
368
  "segment.sync": "Sync segment",
354
369
  "sms.send": "Send SMS",
355
370
  "webhook.send": "Send webhook"
@@ -513,7 +528,16 @@ var tokenSettings = ({ existing = {}, now = Date.now(), tokens }) => ({
513
528
  ...tokens.expiresIn && {
514
529
  expiresAt: new Date(now + tokens.expiresIn * 1e3).toISOString()
515
530
  },
516
- ...tokens.scope && { scope: tokens.scope }
531
+ // A VENDOR NEED NOT RETURN `scope` ON A REFRESH. Klaviyo documents it on the
532
+ // authorization_code response and documents no response body at all for the
533
+ // refresh grant, so taking the minted value alone drops the stored one. That
534
+ // matters because `scope` is load-bearing: the segment hooks gate on
535
+ // `segments:write` and answer `skipped` when it is absent, so a connection
536
+ // that dropped it disables its whole segment half without failing anything
537
+ // and shows a reconnect task that reconnecting has already fixed.
538
+ ...(tokens.scope || existing.scope) && {
539
+ scope: tokens.scope || existing.scope
540
+ }
517
541
  });
518
542
  var accessToken = async ({
519
543
  clientId,
@@ -576,6 +600,98 @@ var detectCountry = (value) => {
576
600
  }
577
601
  };
578
602
 
603
+ // lib/connections/segment-rows.js
604
+ var import_node_crypto2 = require("crypto");
605
+ var row = ({ connection: connection2, data: data2, manifest, row: described }) => {
606
+ var _a, _b;
607
+ return {
608
+ connection: connection2 == null ? void 0 : connection2.id,
609
+ // ALWAYS A STRING. Mailchimp tag ids are integers, Klaviyo segment ids are
610
+ // strings, and one type in the schema is one comparison in the $or below.
611
+ id: String(described == null ? void 0 : described.id),
612
+ slug: connection2 == null ? void 0 : connection2.slug,
613
+ type: described == null ? void 0 : described.type,
614
+ // NULL, NEVER UNDEFINED: undefined drops the key, and the schema requires it.
615
+ // The url is built HERE, while the settings are decrypted and the vendor
616
+ // facts are in hand — an api reading the row later has neither.
617
+ url: ((_b = (_a = manifest == null ? void 0 : manifest.urls) == null ? void 0 : _a.segment) == null ? void 0 : _b.call(_a, { ...described, id: String(described == null ? void 0 : described.id) }, data2)) || null
618
+ };
619
+ };
620
+ var segmentRowWrites = ({ connection: connection2, data: data2, manifest, row: described, segment }) => {
621
+ const built = row({ connection: connection2, data: data2, manifest, row: described });
622
+ return [
623
+ // PUSH IF ABSENT. The $ne guard is what makes a second concurrent register
624
+ // add nothing rather than a duplicate row for one connection.
625
+ {
626
+ collection: "segment",
627
+ data: { $push: { connections: built } },
628
+ operation: "update",
629
+ query: {
630
+ id: segment == null ? void 0 : segment.id,
631
+ "connections.connection": { $ne: connection2 == null ? void 0 : connection2.id }
632
+ }
633
+ },
634
+ // SET IF DIFFERENT. $elemMatch selects this connection's row only when one
635
+ // of its three mutable fields disagrees, so the steady state — the same
636
+ // vendor object, the same url — matches nothing and writes nothing.
637
+ {
638
+ collection: "segment",
639
+ data: { $set: { "connections.$": built } },
640
+ operation: "update",
641
+ query: {
642
+ id: segment == null ? void 0 : segment.id,
643
+ connections: {
644
+ $elemMatch: {
645
+ connection: connection2 == null ? void 0 : connection2.id,
646
+ $or: [
647
+ { id: { $ne: built.id } },
648
+ { type: { $ne: built.type } },
649
+ { url: { $ne: built.url } }
650
+ ]
651
+ }
652
+ }
653
+ }
654
+ }
655
+ ];
656
+ };
657
+ var segmentRowRemoveWrites = ({ connection: connection2, segment }) => [
658
+ {
659
+ collection: "segment",
660
+ data: { $pull: { connections: { connection: connection2 == null ? void 0 : connection2.id } } },
661
+ operation: "update",
662
+ query: { id: segment == null ? void 0 : segment.id }
663
+ }
664
+ ];
665
+ var segmentRowFor = ({ connection: connection2, segment }) => ((segment == null ? void 0 : segment.connections) || []).find((entry) => (entry == null ? void 0 : entry.connection) === (connection2 == null ? void 0 : connection2.id));
666
+ var currentSegment = async ({ read, segment }) => {
667
+ if (!(read == null ? void 0 : read.get) || !(segment == null ? void 0 : segment.id)) return segment;
668
+ return read.get({
669
+ collection: "segment",
670
+ query: { id: segment.id }
671
+ });
672
+ };
673
+ var driftEnqueues = async ({ applied, read, segment, workflow }) => {
674
+ if (!(workflow == null ? void 0 : workflow.id)) return [];
675
+ const fresh = await currentSegment({ read, segment });
676
+ if (!(fresh == null ? void 0 : fresh.id) || fresh.title === applied) return [];
677
+ return [{
678
+ data: {
679
+ triggerData: {
680
+ organization: fresh.organization || (workflow == null ? void 0 : workflow.organization),
681
+ segment: fresh
682
+ },
683
+ workflowId: workflow == null ? void 0 : workflow.id
684
+ },
685
+ name: "execute",
686
+ options: {
687
+ jobId: "workflow.insert.execute." + (workflow == null ? void 0 : workflow.id) + ".segment.register." + fresh.id + ".drift." + Date.now() + "." + (0, import_node_crypto2.randomUUID)().slice(0, 8),
688
+ removeOnComplete: true,
689
+ removeOnFail: true
690
+ },
691
+ queue: "workflow"
692
+ }];
693
+ };
694
+
579
695
  // lib/connections/providers/attentive.js
580
696
  var api = async (path, { fetcher = fetch, method = "GET", payload, token }) => {
581
697
  const response = await fetcher("https://api.attentivemobile.com" + path, {
@@ -628,7 +744,7 @@ var attentive_default2 = {
628
744
  // has to say so rather than let them believe otherwise.
629
745
  confirm: "Disconnecting removes Drawbridge's stored Attentive token. Attentive does not offer a way for us to revoke it, so remove the Drawbridge integration in Attentive as well if you want its access fully withdrawn. Your subscribers stay in both Attentive and Drawbridge \u2014 neither list is deleted.",
630
746
  description: [
631
- "Attentive is where your SMS marketing lives, and this connection syncs the contacts your campaigns collect into an Attentive segment \u2014 subscribed for marketing and added to the segment you choose.",
747
+ "This connection syncs the contacts your campaigns collect into your Attentive account \u2014 subscribed for marketing, and added to the segment you choose.",
632
748
  "You authorize Drawbridge from inside Attentive and can revoke that access there at any time. Drawbridge never sees or stores your Attentive password.",
633
749
  "Anyone who has opted out in Drawbridge is sent to Attentive as an unsubscribe rather than omitted, so a person who asked not to be contacted stays suppressed in both systems instead of quietly reappearing.",
634
750
  "Attentive accepts these updates and applies them in the background, so a contact appears in your segment shortly after the sync rather than the instant it runs."
@@ -670,10 +786,9 @@ var attentive_default2 = {
670
786
  }
671
787
  ],
672
788
  group: "contacts",
673
- // A HOOK'S VALUE IS ITS ANSWER. The consent is stored and can be revoked;
674
- // nothing else is built yet, because subscriber sync has not shipped. Every
675
- // false here is "not yet" rather than "never" — when the sync lands, probe
676
- // and contacts.sync are the first to flip.
789
+ // WHAT THIS VENDOR DOES AND DOES NOT DO is the value of each hook below, not
790
+ // a paragraph up here that goes stale the moment one of them is implemented
791
+ // which is exactly what happened to the note this replaces.
677
792
  hooks: {
678
793
  auth: {
679
794
  // FALSE, NOT {}. `{}` means "supported, implemented in the repo with the
@@ -686,7 +801,7 @@ var attentive_default2 = {
686
801
  // nobody re-derives it. Klaviyo's connect reads the account name back so
687
802
  // the card is not blank; Attentive's card stays blank. There IS an
688
803
  // endpoint — GET https://api.attentivemobile.com/v1/me, Bearer, described
689
- // on docs.attentive.com/pages/authentication/ as returning "information
804
+ // on docs.attentive.com/docs/authentication as returning "information
690
805
  // specific to your company" — but its RESPONSE SCHEMA is published
691
806
  // nowhere we can read: the docs show the curl and no body. Reading
692
807
  // `body.name` would be a guess, and a guess here fails at the worst
@@ -853,7 +968,62 @@ var attentive_default2 = {
853
968
  products: false,
854
969
  promotions: false
855
970
  },
856
- segment: false,
971
+ segment: {
972
+ // A FOUNDATION, AND HONEST ABOUT IT. Attentive's segments API can create
973
+ // one with an externalId we choose (docs.attentive.com/reference/
974
+ // createsegment.md, fetched 2026-09-11: POST /v2/segments, `name`
975
+ // required, `externalId` optional and "auto-generated if not supplied"),
976
+ // which would give a real per-segment object — but it takes
977
+ // segments:write, and scopes ride on the app registration, which does not
978
+ // exist yet.
979
+ //
980
+ // So the row points at the connection-level segment the merchant chose,
981
+ // `type` says so, and turning this into a per-segment object later is a
982
+ // change to this file and nothing else: create with
983
+ // externalId = segment.id, PATCH to rename, archive on remove. Their
984
+ // update and archive endpoints are BOTH keyed by external id
985
+ // (docs.attentive.com/reference/patchsegmentbyexternalid.md and
986
+ // /deletesegmentbyexternalid.md, fetched 2026-09-11), so the segment id we
987
+ // already hold addresses every one of the three calls.
988
+ //
989
+ // NO DRIFT CHECK, unlike the other two: the row points at the
990
+ // connection's own segment and the link is the index page, so nothing
991
+ // here depends on the Drawbridge segment's title — a rename has nothing
992
+ // to apply and nothing to race with. That comes back with the
993
+ // per-segment object.
994
+ //
995
+ // THE RE-READ STAYS ALL THE SAME. It changes nothing today, and this is
996
+ // the simplest of the three registers and therefore the one the next
997
+ // vendor gets copied from — one job id serves four dispatch sites, so a
998
+ // copy that trusts context.segment applies whichever trigger data won
999
+ // the race, at a vendor where the title does matter.
1000
+ register: async ({ connection: connection2, context, manifest, settings }, { read } = {}) => {
1001
+ const segment = await currentSegment({ read, segment: context == null ? void 0 : context.segment });
1002
+ if (!(segment == null ? void 0 : segment.id) || segment.system) return { message: "That segment is not one this connection publishes.", skipped: true };
1003
+ if (!(settings == null ? void 0 : settings.segment)) return { message: "No Attentive segment is chosen for this connection.", skipped: true };
1004
+ return {
1005
+ events: [{
1006
+ event: "organization.segments",
1007
+ payload: { id: segment.id },
1008
+ room: "organization." + (connection2 == null ? void 0 : connection2.organization)
1009
+ }],
1010
+ message: "Contacts in this segment are added to the Attentive segment chosen on this connection.",
1011
+ writes: segmentRowWrites({
1012
+ connection: connection2,
1013
+ data: { ...connection2, settings },
1014
+ manifest,
1015
+ row: { id: settings.segment, type: "segment" },
1016
+ segment
1017
+ })
1018
+ };
1019
+ },
1020
+ // NOT OURS TO DELETE. The segment on this connection is the merchant's,
1021
+ // and it is where every Drawbridge segment's contacts go — removing it
1022
+ // because one Drawbridge segment was deleted would empty the others.
1023
+ remove: false,
1024
+ // Drawbridge-side membership belongs to the private manifest.
1025
+ sync: false
1026
+ },
857
1027
  sms: false,
858
1028
  webhook: false
859
1029
  },
@@ -882,6 +1052,21 @@ var attentive_default2 = {
882
1052
  "ATTENTIVE_OAUTH_CLIENT_ID",
883
1053
  "ATTENTIVE_OAUTH_CLIENT_SECRET"
884
1054
  ],
1055
+ // THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
1056
+ review: {
1057
+ api: "https://docs.attentive.com/reference/listsegments",
1058
+ dashboard: "https://docs.attentive.com/docs/segments",
1059
+ // THIS PAGE DOES NOT LIST EVERY SCOPE. Its table names five —
1060
+ // events:write, ecommerce:write, subscriptions:write, attributes:write,
1061
+ // privacy_requests:write — and says nothing about segments:read or
1062
+ // segments:write, which the segments API this manifest calls does take.
1063
+ // The header at the top of this file carries that distinction; it is
1064
+ // repeated here so a reviewer following the link is not misled by what the
1065
+ // table omits (fetched 2026-09-11).
1066
+ scopes: "https://docs.attentive.com/docs/authentication",
1067
+ content: "2026-09-11",
1068
+ verified: null
1069
+ },
885
1070
  slug: "attentive",
886
1071
  // A consent with no segment chosen is authenticated and inert — the sync needs
887
1072
  // somewhere to put people — so the card says Pending rather than Active over
@@ -919,6 +1104,24 @@ var attentive_default2 = {
919
1104
  triggers: ["lead.insert", "segment.contact.add"],
920
1105
  usage: { actions: 1 }
921
1106
  })
1107
+ },
1108
+ segment: {
1109
+ // SYSTEM, so the builder never offers it and a merchant POST refuses it:
1110
+ // this fires from the segment's own lifecycle, not from a workflow
1111
+ // somebody assembled. The trigger is declared here rather than hard-coded
1112
+ // in drawbridge-sync.
1113
+ //
1114
+ // REGISTER ONLY. There is no remove step because hooks.segment.remove is
1115
+ // declined, and build() refuses a step pointing at a hook this vendor does
1116
+ // not implement — so the two are one decision, enforced at import.
1117
+ register: () => ({
1118
+ description: "Records which Attentive segment a Drawbridge segment's contacts are added to.",
1119
+ hook: "segment.register",
1120
+ key: "Attentive Segment Register",
1121
+ queue: "connection",
1122
+ system: true,
1123
+ trigger: { event: "segment.register", type: "event" }
1124
+ })
922
1125
  }
923
1126
  },
924
1127
  // WHY, in the merchant's words, and what to do about it.
@@ -935,14 +1138,28 @@ var attentive_default2 = {
935
1138
  }
936
1139
  ];
937
1140
  },
938
- title: "Attentive"
1141
+ title: "Attentive",
1142
+ // ATTENTIVE'S SEGMENTS INDEX. There is no documented per-segment url, and the
1143
+ // only identifier we hold is the API's externalId, which their UI may not
1144
+ // path by — so this lands on the list, where the merchant finds it by name.
1145
+ // A per-segment link arrives with the per-segment object (see hooks.segment).
1146
+ //
1147
+ // THE PATH ITSELF IS NOT PUBLISHED ANYWHERE CITABLE, the same gap Klaviyo's
1148
+ // segment url carries. What is on record is that the segments area lives at
1149
+ // ui.attentivemobile.com/segments — its /segments/create/ and /segments/manual
1150
+ // sub-routes are publicly indexed pages (fetched 2026-09-11) — while the /all
1151
+ // tab is not, and Attentive's help centre refuses automated fetches. The dev
1152
+ // walk-through confirms this against a real account before promote.
1153
+ urls: {
1154
+ segment: () => "https://ui.attentivemobile.com/segments/all"
1155
+ }
939
1156
  };
940
1157
 
941
1158
  // lib/connections/providers/drawbridge.js
942
- var import_node_crypto3 = require("crypto");
1159
+ var import_node_crypto4 = require("crypto");
943
1160
 
944
1161
  // lib/connections/inbound.js
945
- var import_node_crypto2 = require("crypto");
1162
+ var import_node_crypto3 = require("crypto");
946
1163
  var verifySignature = ({ body, descriptor, headers, secret }) => {
947
1164
  if (!secret) {
948
1165
  throw Object.assign(new Error("Missing webhook secret: " + descriptor.signature.secret), { status: 500 });
@@ -951,10 +1168,10 @@ var verifySignature = ({ body, descriptor, headers, secret }) => {
951
1168
  if (!provided) {
952
1169
  throw Object.assign(new Error("Missing webhook signature"), { status: 401 });
953
1170
  }
954
- const digest = (0, import_node_crypto2.createHmac)(descriptor.signature.algorithm, secret).update(body).digest(descriptor.signature.encoding);
1171
+ const digest = (0, import_node_crypto3.createHmac)(descriptor.signature.algorithm, secret).update(body).digest(descriptor.signature.encoding);
955
1172
  const digestBuffer = Buffer.from(digest, descriptor.signature.encoding);
956
1173
  const providedBuffer = Buffer.from(provided, descriptor.signature.encoding);
957
- if (digestBuffer.length !== providedBuffer.length || !(0, import_node_crypto2.timingSafeEqual)(digestBuffer, providedBuffer)) {
1174
+ if (digestBuffer.length !== providedBuffer.length || !(0, import_node_crypto3.timingSafeEqual)(digestBuffer, providedBuffer)) {
958
1175
  throw Object.assign(new Error("Invalid webhook signature"), { status: 401 });
959
1176
  }
960
1177
  return JSON.parse(body.toString());
@@ -979,7 +1196,7 @@ var verifyEcdsa = ({ body, descriptor, headers, secret }) => {
979
1196
  throw Object.assign(new Error("Stale webhook signature"), { status: 401 });
980
1197
  }
981
1198
  const payload = Buffer.concat([Buffer.from(String(timestamp), "utf8"), body]);
982
- const verified = (0, import_node_crypto2.createVerify)("sha256").update(payload).verify(asPem(secret), Buffer.from(provided, "base64"));
1199
+ const verified = (0, import_node_crypto3.createVerify)("sha256").update(payload).verify(asPem(secret), Buffer.from(provided, "base64"));
983
1200
  if (!verified) {
984
1201
  throw Object.assign(new Error("Invalid webhook signature"), { status: 401 });
985
1202
  }
@@ -2055,7 +2272,7 @@ var drawbridge_default2 = {
2055
2272
  content: {
2056
2273
  confirm: "This connection is part of Drawbridge and cannot be disconnected.",
2057
2274
  description: [
2058
- "Drawbridge sends your notification email and SMS, keeps your segments in sync, and posts to your own endpoints. These are built in rather than connected, so there is nothing here to set up."
2275
+ "Drawbridge sends your notification emails and your entrants' emails, and recalculates segment membership on a schedule. It is always on and needs nothing connected."
2059
2276
  ],
2060
2277
  excerpt: "The steps Drawbridge runs itself.",
2061
2278
  guide: [
@@ -2353,9 +2570,9 @@ var drawbridge_default2 = {
2353
2570
  if (!secret) throw Object.assign(new Error("Missing webhook secret: TWILIO_AUTH_TOKEN"), { status: 500 });
2354
2571
  const params = new URLSearchParams(String(body || ""));
2355
2572
  const signed = url + [...params.keys()].sort().map((key) => key + params.get(key)).join("");
2356
- const expected = (0, import_node_crypto3.createHmac)("sha1", secret).update(signed).digest("base64");
2573
+ const expected = (0, import_node_crypto4.createHmac)("sha1", secret).update(signed).digest("base64");
2357
2574
  const provided = String((headers == null ? void 0 : headers["x-twilio-signature"]) || "");
2358
- const matches = expected.length === provided.length && (0, import_node_crypto3.timingSafeEqual)(Buffer.from(expected), Buffer.from(provided));
2575
+ const matches = expected.length === provided.length && (0, import_node_crypto4.timingSafeEqual)(Buffer.from(expected), Buffer.from(provided));
2359
2576
  if (!matches) throw Object.assign(new Error("Invalid Twilio signature"), { status: 401 });
2360
2577
  return Object.fromEntries(params);
2361
2578
  }
@@ -2368,6 +2585,11 @@ var drawbridge_default2 = {
2368
2585
  promotions: false
2369
2586
  },
2370
2587
  segment: {
2588
+ // NOT DRAWBRIDGE'S. Registering a segment means creating an object at a
2589
+ // vendor, and this manifest has no vendor behind it — the three that do
2590
+ // implement these.
2591
+ register: false,
2592
+ remove: false,
2371
2593
  // RECALCULATE SEGMENT MEMBERSHIP. The one FAN-OUT hook: it evaluates every
2372
2594
  // contact in an organization against every segment, which is too much for
2373
2595
  // one job, so it returns chunks and the shell defers completion.
@@ -2643,6 +2865,33 @@ var drawbridge_default2 = {
2643
2865
  // caught exactly that: availableConnections({}) went from [ 'drawbridge' ] to
2644
2866
  // empty the moment this was added.
2645
2867
  requires: [],
2868
+ // PRIVATE, NOT VENDORLESS. SendGrid, Twilio and HubSpot are behind this
2869
+ // manifest, so `false` would be a lie about which reads were made.
2870
+ //
2871
+ // ONE ENTRY PER VENDOR, because three vendors are three reads. A single
2872
+ // citation here would evidence one of them and read as though it covered all
2873
+ // three, which is the omission this key exists to catch.
2874
+ review: {
2875
+ api: {
2876
+ // lib/hubspot.js posts to /crm/v3/objects/contacts.
2877
+ hubspot: "https://developers.hubspot.com/docs/reference/api/crm/objects/contacts",
2878
+ // lib/sendgrid.js posts to /v3/mail/send.
2879
+ sendgrid: "https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send",
2880
+ // lib/twilio.js posts to /2010-04-01/Accounts/{Sid}/Messages.json, and
2881
+ // hooks.inbound.verify reads the MessageStatus this resource documents.
2882
+ twilio: "https://www.twilio.com/docs/messaging/api/message-resource"
2883
+ },
2884
+ dashboard: {
2885
+ hubspot: "https://knowledge.hubspot.com/contacts/create-contacts",
2886
+ sendgrid: "https://www.twilio.com/docs/sendgrid/ui/analytics-and-reporting/email-activity-feed",
2887
+ twilio: "https://www.twilio.com/docs/messaging/guides/debugging-tools"
2888
+ },
2889
+ // An admin types these keys in; there is no merchant consent and no scope
2890
+ // model on any of the three.
2891
+ scopes: false,
2892
+ content: "2026-09-11",
2893
+ verified: null
2894
+ },
2646
2895
  slug: "drawbridge",
2647
2896
  // Always on. There is no credential that could go bad and no configuration a
2648
2897
  // merchant could leave half-finished.
@@ -2834,6 +3083,8 @@ var api2 = async (path, { fetcher = fetch, method = "GET", payload, token }) =>
2834
3083
  }
2835
3084
  return response.status === 204 ? null : response.json();
2836
3085
  };
3086
+ var segmentName = (title) => "Drawbridge: " + title;
3087
+ var canManageSegments = (settings) => String((settings == null ? void 0 : settings.scope) || "").split(/\s+/).includes("segments:write");
2837
3088
  var klaviyo_default2 = {
2838
3089
  // OAuth 2.1, and PKCE is REQUIRED rather than recommended: Klaviyo refuses an
2839
3090
  // exchange without a code_verifier matching the challenge the consent
@@ -2863,9 +3114,21 @@ var klaviyo_default2 = {
2863
3114
  // exchange, and a copy here would be a second answer that goes stale.
2864
3115
  expiry: 90 * 24 * 60 * 60,
2865
3116
  pkce: true,
3117
+ // EVERY SCOPE THE MANIFEST'S HOOKS NEED, not the ones today's hooks use.
3118
+ // Klaviyo holds scopes on the APP — "Pinpoint which scopes your app uses
3119
+ // and set them using a space-separated list"
3120
+ // (developers.klaviyo.com/en/docs/create_a_public_oauth_app, fetched
3121
+ // 2026-09-11) — and a merchant's token only ever carries what they
3122
+ // consented to, so a scope added later is a reconnect for every one of
3123
+ // them. That is what segments cost when they were left out here.
3124
+ //
2866
3125
  // Space separated. accounts:read is required by Klaviyo on every app
2867
- // and must stay in the list; the rest are what a contact sync needs.
2868
- scopes: "accounts:read lists:read lists:write profiles:read profiles:write",
3126
+ // and must stay in the list; the rest are what a contact sync and the
3127
+ // segment hooks need — Get Segments lists `segments:read`, Create,
3128
+ // Update and Delete Segment each list `segments:write`
3129
+ // (raw.githubusercontent.com/klaviyo/openapi/main/openapi/stable.json,
3130
+ // revision 2026-07-15, fetched 2026-09-11).
3131
+ scopes: "accounts:read lists:read lists:write profiles:read profiles:write segments:read segments:write",
2869
3132
  // EVERY VENDOR URL, in one place. `revoke` used to be a literal inside
2870
3133
  // the disconnect hook — three vendor addresses, two of them declared,
2871
3134
  // which is exactly the kind of split that goes unnoticed.
@@ -2914,9 +3177,10 @@ var klaviyo_default2 = {
2914
3177
  // Shown at disconnect, so it says what is lost and what is not.
2915
3178
  confirm: "Disconnecting revokes Drawbridge's access to your Klaviyo account. Your profiles and lists stay in both Klaviyo and Drawbridge \u2014 neither is deleted.",
2916
3179
  description: [
2917
- "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.",
3180
+ "Connecting Klaviyo lets Drawbridge sync the contacts your campaigns collect into a Klaviyo list, so you can market to the people who enter a giveaway alongside the rest of your audience.",
2918
3181
  "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.",
2919
- "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."
3182
+ "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.",
3183
+ "Drawbridge writes its own properties onto the profiles it syncs: how many of your campaigns someone entered, their entries, draws and orders, the revenue their orders attributed to your campaigns, and which Drawbridge segments they are in. You can build Klaviyo segments and flows on any of them."
2920
3184
  ],
2921
3185
  // KEYED BY WHAT FAILED, not nested inside it. Errors are the thing most
2922
3186
  // likely to grow — resources.* has already earned somewhere to put "we
@@ -3073,6 +3337,7 @@ var klaviyo_default2 = {
3073
3337
  if (!email) return { message: "That lead has no email address to sync.", skipped: true };
3074
3338
  const person = (context == null ? void 0 : context.contact) || null;
3075
3339
  const totals = (person == null ? void 0 : person.totals) || {};
3340
+ const count = (value) => typeof value === "number" ? value : (value == null ? void 0 : value.total) || 0;
3076
3341
  const profile = await api2("/profile-import", {
3077
3342
  fetcher,
3078
3343
  method: "POST",
@@ -3086,13 +3351,13 @@ var klaviyo_default2 = {
3086
3351
  drawbridge_campaigns: (person.campaigns || []).length,
3087
3352
  drawbridge_draws: totals.draws || 0,
3088
3353
  drawbridge_entries: totals.entries || 0,
3089
- drawbridge_orders: totals.orders || 0,
3354
+ drawbridge_orders: count(totals.orders),
3090
3355
  // Campaign-attributed, NOT lifetime. A merchant running
3091
3356
  // Shopify already has lifetime revenue in Klaviyo through
3092
3357
  // Klaviyo's own integration; what only we can say is how
3093
3358
  // much a campaign drove. Named so the two cannot be
3094
3359
  // mistaken for one another in a segment builder.
3095
- drawbridge_revenue: totals.gross || 0
3360
+ drawbridge_revenue: count(totals.gross)
3096
3361
  },
3097
3362
  // THE DRAWBRIDGE SEGMENTS THEY ARE IN, as a list property the
3098
3363
  // merchant builds Klaviyo segments on top of. Klaviyo owns no
@@ -3111,7 +3376,14 @@ var klaviyo_default2 = {
3111
3376
  // `segments` is null when the run carried no contact document,
3112
3377
  // meaning nobody looked — different from [], which means they
3113
3378
  // are in none. Null omits the key and merge leaves it alone.
3114
- ...segments && { drawbridge_segments: segments.map((entry) => entry.title).filter(Boolean) }
3379
+ ...segments && { drawbridge_segments: segments.map((entry) => entry.title).filter(Boolean) },
3380
+ // THE IDS, which is what a Drawbridge-made segment's definition
3381
+ // filters on. Ids rather than titles, so renaming a segment is a
3382
+ // name change at Klaviyo and not a resync of every profile.
3383
+ //
3384
+ // The titles stay beside them: merchants have been building
3385
+ // their own segments on that array since it shipped.
3386
+ ...segments && { drawbridge_segment_ids: segments.map((entry) => entry.id).filter(Boolean) }
3115
3387
  }
3116
3388
  },
3117
3389
  type: "profile"
@@ -3155,17 +3427,141 @@ var klaviyo_default2 = {
3155
3427
  };
3156
3428
  }
3157
3429
  },
3158
- // A WHOLE DOMAIN CAN DECLINE AT ONCE. Klaviyo sends us nothing and we
3159
- // register nothing with it, so listing four falses would be noise around a
3160
- // single decision. Still explicit absence would not say whether anybody
3161
- // considered it.
3162
- // Drawbridge sends its own notification email and SMS, and owns its own
3163
- // segments — see the private `drawbridge` manifest. A vendor answering
3164
- // these would be a second sender, which is the arrangement the platform
3165
- // sender replaced.
3430
+ // Drawbridge sends its own notification email. A vendor answering this
3431
+ // would be a second sender, which is the arrangement the platform sender
3432
+ // replaced. Declined as one line rather than one per verb, because the whole
3433
+ // domain is one decision — still explicit, since absence would not say
3434
+ // whether anybody considered it.
3166
3435
  email: false,
3167
- segment: false,
3436
+ // SEGMENTS ARE SHARED, not owned by one side. Drawbridge holds the
3437
+ // membership — see the private `drawbridge` manifest, and `sync : false`
3438
+ // below — while register and remove keep a Klaviyo segment standing for
3439
+ // each Drawbridge segment, so the merchant can target one in their own
3440
+ // flows.
3441
+ segment: {
3442
+ // THE KLAVIYO SEGMENT THIS DRAWBRIDGE SEGMENT BECOMES.
3443
+ //
3444
+ // Klaviyo owns no writable membership — its segments are computed from
3445
+ // rules — so the segment we create is DEFINED BY the profile property
3446
+ // contacts.sync writes. The definition filters on the Drawbridge
3447
+ // segment's ID, never its title, which is what makes a rename one PATCH
3448
+ // instead of a resync of every profile in it.
3449
+ register: async ({ connection: connection2, context, manifest, settings, token, workflow }, { fetcher, read } = {}) => {
3450
+ var _a, _b, _c, _d, _e;
3451
+ const segment = await currentSegment({ read, segment: context == null ? void 0 : context.segment });
3452
+ if (!(segment == null ? void 0 : segment.id) || segment.system) return { message: "That segment is not one this connection publishes.", skipped: true };
3453
+ if (!canManageSegments(settings)) {
3454
+ return {
3455
+ message: "Reconnect Klaviyo to let Drawbridge manage segments \u2014 this connection was made before that permission was asked for.",
3456
+ skipped: true
3457
+ };
3458
+ }
3459
+ const name = segmentName(segment.title);
3460
+ const existing = segmentRowFor({ connection: connection2, segment });
3461
+ let id = null;
3462
+ if (existing == null ? void 0 : existing.id) {
3463
+ try {
3464
+ const found = await api2("/segments/" + existing.id, { fetcher, token });
3465
+ id = ((_a = found == null ? void 0 : found.data) == null ? void 0 : _a.id) ?? existing.id;
3466
+ if (((_c = (_b = found == null ? void 0 : found.data) == null ? void 0 : _b.attributes) == null ? void 0 : _c.name) !== name) {
3467
+ await api2("/segments/" + existing.id, {
3468
+ fetcher,
3469
+ method: "PATCH",
3470
+ payload: { data: { attributes: { name }, id: existing.id, type: "segment" } },
3471
+ token
3472
+ });
3473
+ }
3474
+ } catch (error) {
3475
+ if (error.status !== 404) throw error;
3476
+ id = null;
3477
+ }
3478
+ }
3479
+ if (!id) {
3480
+ const search = await api2("/segments?filter=" + encodeURIComponent('equals(name,"' + name.replace(/"/g, '\\"') + '")'), { fetcher, token });
3481
+ id = ((_d = ((search == null ? void 0 : search.data) || []).find((entry) => {
3482
+ var _a2;
3483
+ return ((_a2 = entry == null ? void 0 : entry.attributes) == null ? void 0 : _a2.name) === name;
3484
+ })) == null ? void 0 : _d.id) ?? null;
3485
+ }
3486
+ if (!id) {
3487
+ const created = await api2("/segments", {
3488
+ fetcher,
3489
+ method: "POST",
3490
+ // THE DEFINITION IS THE MEMBERSHIP. Create Segment requires one
3491
+ // — `name` and `definition` are both required on its attributes
3492
+ // — and a custom profile property is addressed as
3493
+ // "properties['property name']", tested with a list filter whose
3494
+ // operator is `contains`
3495
+ // (raw.githubusercontent.com/klaviyo/openapi/main/openapi/stable.json,
3496
+ // revision 2026-07-15, fetched 2026-09-11).
3497
+ payload: {
3498
+ data: {
3499
+ attributes: {
3500
+ definition: {
3501
+ condition_groups: [{
3502
+ conditions: [{
3503
+ filter: { operator: "contains", type: "list", value: segment.id },
3504
+ property: "properties['drawbridge_segment_ids']",
3505
+ type: "profile-property"
3506
+ }]
3507
+ }]
3508
+ },
3509
+ name
3510
+ },
3511
+ type: "segment"
3512
+ }
3513
+ },
3514
+ token
3515
+ });
3516
+ id = (_e = created == null ? void 0 : created.data) == null ? void 0 : _e.id;
3517
+ }
3518
+ if (!id) return { message: "Klaviyo returned no segment id.", skipped: true };
3519
+ return {
3520
+ // A RENAME THAT ARRIVED WHILE THIS RAN was dropped by the
3521
+ // coalescing job id, so the last thing this does is look again.
3522
+ enqueues: await driftEnqueues({ applied: segment.title, read, segment, workflow }),
3523
+ events: [{
3524
+ event: "organization.segments",
3525
+ payload: { id: segment.id },
3526
+ room: "organization." + (connection2 == null ? void 0 : connection2.organization)
3527
+ }],
3528
+ message: 'Klaviyo is carrying this segment as "' + name + '".',
3529
+ writes: segmentRowWrites({
3530
+ connection: connection2,
3531
+ data: { ...connection2, settings },
3532
+ manifest,
3533
+ row: { id, type: "segment" },
3534
+ segment
3535
+ })
3536
+ };
3537
+ },
3538
+ // NO RE-READ. The segment is already deleted; the pre-image is the only
3539
+ // copy, and it carries the row naming what to delete.
3540
+ remove: async ({ connection: connection2, context, settings, token }, { fetcher } = {}) => {
3541
+ const segment = context == null ? void 0 : context.segment;
3542
+ const existing = segmentRowFor({ connection: connection2, segment });
3543
+ if (!(existing == null ? void 0 : existing.id)) return { message: "Klaviyo was never carrying this segment.", skipped: true };
3544
+ if (!canManageSegments(settings)) {
3545
+ return { message: "Reconnect Klaviyo to let Drawbridge manage segments.", skipped: true };
3546
+ }
3547
+ try {
3548
+ await api2("/segments/" + existing.id, { fetcher, method: "DELETE", token });
3549
+ } catch (error) {
3550
+ if (error.status !== 404) throw error;
3551
+ }
3552
+ return {
3553
+ message: "Klaviyo is no longer carrying this segment.",
3554
+ writes: segmentRowRemoveWrites({ connection: connection2, segment })
3555
+ };
3556
+ },
3557
+ // Drawbridge-side membership belongs to the private manifest.
3558
+ sync: false
3559
+ },
3560
+ // Declined for the same reason as `email` above: Drawbridge sends its own
3561
+ // notification SMS, and a vendor answering this would be a second sender.
3168
3562
  sms: false,
3563
+ // Klaviyo sends us nothing — no inbound message to receive, no signature
3564
+ // to verify.
3169
3565
  inbound: false,
3170
3566
  // Nothing to set up or tear down at the vendor: the grant is the whole
3171
3567
  // integration. What CAN rot is the grant itself, so health is the one
@@ -3286,6 +3682,18 @@ var klaviyo_default2 = {
3286
3682
  "KLAVIYO_OAUTH_CLIENT_ID",
3287
3683
  "KLAVIYO_OAUTH_CLIENT_SECRET"
3288
3684
  ],
3685
+ // THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
3686
+ review: {
3687
+ api: "https://developers.klaviyo.com/en/reference/api_overview",
3688
+ dashboard: "https://help.klaviyo.com/hc/en-us/articles/115005078647",
3689
+ // THE SCOPE TABLE, not the OAuth walk-through. set_up_oauth carries one
3690
+ // example scope string and nothing to check a manifest against; this page
3691
+ // lists the scopes each API takes, segments:read and segments:write among
3692
+ // them (fetched 2026-09-11).
3693
+ scopes: "https://developers.klaviyo.com/en/docs/authenticate_",
3694
+ content: "2026-09-11",
3695
+ verified: null
3696
+ },
3289
3697
  slug: "klaviyo",
3290
3698
  // ONE OF THE FOUR STATES AND NOTHING ELSE — the reason sits in `tasks`, which
3291
3699
  // is already the merchant-facing copy channel and is already rendered.
@@ -3316,7 +3724,8 @@ var klaviyo_default2 = {
3316
3724
  hook: "lifecycle.health",
3317
3725
  key: "Klaviyo Connection Health",
3318
3726
  queue: "connection",
3319
- system: true
3727
+ system: true,
3728
+ trigger: { event: "day", type: "schedule" }
3320
3729
  })
3321
3730
  }
3322
3731
  },
@@ -3360,6 +3769,28 @@ var klaviyo_default2 = {
3360
3769
  usage: { actions: 1 }
3361
3770
  };
3362
3771
  }
3772
+ },
3773
+ segment: {
3774
+ // SYSTEM, so the builder never offers it and a merchant POST refuses it:
3775
+ // these fire from the segment's own lifecycle, not from a workflow
3776
+ // somebody assembled. The trigger is declared here rather than hard-coded
3777
+ // in drawbridge-sync.
3778
+ register: () => ({
3779
+ description: "Keeps a matching Klaviyo segment for each Drawbridge segment, built on the segment ids Drawbridge writes onto your profiles.",
3780
+ hook: "segment.register",
3781
+ key: "Klaviyo Segment Register",
3782
+ queue: "connection",
3783
+ system: true,
3784
+ trigger: { event: "segment.register", type: "event" }
3785
+ }),
3786
+ remove: () => ({
3787
+ description: "Deletes the Klaviyo segment for a Drawbridge segment when the segment is deleted.",
3788
+ hook: "segment.remove",
3789
+ key: "Klaviyo Segment Remove",
3790
+ queue: "connection",
3791
+ system: true,
3792
+ trigger: { event: "segment.remove", type: "event" }
3793
+ })
3363
3794
  }
3364
3795
  },
3365
3796
  // WHY, in the merchant's words, and what to do about it.
@@ -3369,18 +3800,36 @@ var klaviyo_default2 = {
3369
3800
  // moment: the grant is good and the list is the missing half.
3370
3801
  tasks: (data2) => {
3371
3802
  var _a;
3372
- return !["active", "pending"].includes(data2 == null ? void 0 : data2.status) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.list) ? [] : [
3373
- {
3803
+ if (!["active", "pending"].includes(data2 == null ? void 0 : data2.status)) return [];
3804
+ return [
3805
+ // A connection made before segments were requested is authenticated and
3806
+ // cannot manage them, and no error surfaces anywhere else — the register
3807
+ // runs skip rather than fail.
3808
+ ...canManageSegments(data2 == null ? void 0 : data2.settings) ? [] : [{
3809
+ message: "Drawbridge now keeps a Klaviyo segment in step with each of your Drawbridge segments. Reconnect Klaviyo to allow it.",
3810
+ title: "Reconnect Klaviyo"
3811
+ }],
3812
+ ...((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.list) ? [] : [{
3374
3813
  message: "Choose which Klaviyo list your contacts should sync into. Until you do, nothing is being synced.",
3375
3814
  title: "Choose a list"
3376
- }
3815
+ }]
3377
3816
  ];
3378
3817
  },
3379
- title: "Klaviyo"
3818
+ title: "Klaviyo",
3819
+ // KLAVIYO PUBLISHES NO DASHBOARD URLS in its API reference. What is on record
3820
+ // is its own help centre on a list: "you can find a list's ID in the URL in
3821
+ // your browser when viewing this list"
3822
+ // (help.klaviyo.com/hc/en-us/articles/115005078647, fetched 2026-09-11), and a
3823
+ // segment's page is the sibling form of it. The path itself is NOT published
3824
+ // anywhere citable, so the dev walk-through confirms this against a real
3825
+ // account before promote.
3826
+ urls: {
3827
+ segment: (row2) => (row2 == null ? void 0 : row2.id) ? "https://www.klaviyo.com/segment/" + row2.id : null
3828
+ }
3380
3829
  };
3381
3830
 
3382
3831
  // lib/connections/providers/mailchimp.js
3383
- var import_node_crypto4 = require("crypto");
3832
+ var import_node_crypto5 = require("crypto");
3384
3833
 
3385
3834
  // lib/connections/icons/mailchimp.js
3386
3835
  var mailchimp_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -3412,7 +3861,9 @@ var api3 = async (path, { dc, fetcher = fetch, method = "GET", payload, token })
3412
3861
  }
3413
3862
  return response.status === 204 ? null : response.json();
3414
3863
  };
3415
- var subscriberHash = (email) => (0, import_node_crypto4.createHash)("md5").update(String(email).trim().toLowerCase()).digest("hex");
3864
+ var subscriberHash = (email) => (0, import_node_crypto5.createHash)("md5").update(String(email).trim().toLowerCase()).digest("hex");
3865
+ var TAG_NAME_LIMIT = 100;
3866
+ var tagName = (title) => ("Drawbridge: " + title).slice(0, TAG_NAME_LIMIT);
3416
3867
  var mailchimp_default2 = {
3417
3868
  // OAUTH 2, authorization code. Every url below is quoted from
3418
3869
  // mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/ rather
@@ -3455,7 +3906,7 @@ var mailchimp_default2 = {
3455
3906
  confirm: "Disconnecting removes Drawbridge's stored Mailchimp access. You can also remove Drawbridge from the Authorized Apps page in your Mailchimp account. Your contacts stay in both Drawbridge and Mailchimp \u2014 neither list is deleted.",
3456
3907
  description: [
3457
3908
  "Drawbridge no longer sends email through Mailchimp. Notification email now sends from Drawbridge itself, and verifying a domain under Messaging in your organization settings puts your own brand in the from line.",
3458
- "Connecting Mailchimp lets Drawbridge sync the contacts your campaigns collect into a Mailchimp audience, so the people who enter a giveaway can be marketed to alongside the rest of your list.",
3909
+ "Connecting Mailchimp lets Drawbridge sync the contacts your campaigns collect into a Mailchimp audience, so you can market to the people who enter a giveaway alongside the rest of your list.",
3459
3910
  "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.",
3460
3911
  "Someone who unsubscribed inside Mailchimp keeps that choice: a resync only sets the status of a subscriber Mailchimp has never seen before."
3461
3912
  ],
@@ -3468,6 +3919,7 @@ var mailchimp_default2 = {
3468
3919
  "Sign in to Mailchimp if you are not already, and choose the account to connect.",
3469
3920
  "You come back here to pick the audience your contacts should sync into.",
3470
3921
  "The connection shows Pending until you pick an audience, then Active.",
3922
+ 'Each of your Drawbridge segments appears in that audience as a tag named "Drawbridge: " plus the segment name. Renaming a segment in Drawbridge renames its tag, and deleting the segment deletes the tag.',
3471
3923
  "You can remove Drawbridge at any time from the Authorized Apps page in your Mailchimp account."
3472
3924
  ]
3473
3925
  },
@@ -3493,10 +3945,9 @@ var mailchimp_default2 = {
3493
3945
  }
3494
3946
  ],
3495
3947
  group: "contacts",
3496
- // A HOOK'S VALUE IS ITS ANSWER. A key is stored and can be removed; nothing
3497
- // else is built yet, because audience sync has not shipped. Every false here
3498
- // is "not yet" rather than "never" when the sync lands, probe and
3499
- // contacts.sync are the first to flip.
3948
+ // WHAT THIS VENDOR DOES AND DOES NOT DO is the value of each hook below, not
3949
+ // a paragraph up here that goes stale the moment one of them is implemented
3950
+ // which is exactly what happened to the note this replaces.
3500
3951
  hooks: {
3501
3952
  auth: {
3502
3953
  // WHERE THE ACCOUNT LIVES. Not enrichment — without this the connection
@@ -3550,26 +4001,32 @@ var mailchimp_default2 = {
3550
4001
  // why there is no create-or-update branch here. Quoted from Mailchimp's
3551
4002
  // Marketing API reference for the list-members resource.
3552
4003
  sync: async ({ connection: connection2, lead, segments, settings, suppressed, token }, { fetcher, read } = {}) => {
3553
- var _a, _b;
4004
+ var _a, _b, _c;
3554
4005
  const audience = settings == null ? void 0 : settings.audience;
3555
4006
  if (!audience) return { message: "No Mailchimp audience is chosen for this connection.", skipped: true };
3556
4007
  const email = ((_b = (_a = lead == null ? void 0 : lead.canonical) == null ? void 0 : _a.email) == null ? void 0 : _b.value) || (lead == null ? void 0 : lead.email);
3557
4008
  if (!email) return { message: "That lead has no email address to sync.", skipped: true };
3558
4009
  const hash = subscriberHash(email);
4010
+ const [firstName, ...restOfName] = String((lead == null ? void 0 : lead.name) || "").trim().split(/\s+/).filter(Boolean);
4011
+ const lastName = restOfName.join(" ");
4012
+ const phone = ((_c = lead == null ? void 0 : lead.phone) == null ? void 0 : _c.number) || null;
4013
+ const mergeFields = {
4014
+ ...firstName && { FNAME: firstName },
4015
+ ...lastName && { LNAME: lastName },
4016
+ ...phone && { PHONE: phone }
4017
+ };
3559
4018
  const member = await api3("/lists/" + audience + "/members/" + hash, {
3560
4019
  dc: settings == null ? void 0 : settings.dc,
3561
4020
  fetcher,
3562
4021
  method: "PUT",
3563
4022
  payload: {
3564
4023
  email_address: email,
3565
- // FNAME ONLY. Unlike Klaviyo, Mailchimp's custom fields are not
3566
- // schemaless a merge tag that does not exist on the audience is
3567
- // refused, taking the whole request with it and FNAME is one of
3568
- // the two tags every audience is created with. The Drawbridge
3569
- // totals Klaviyo receives cannot travel until something registers
3570
- // merge fields on the chosen audience, which is lifecycle.register's
3571
- // job and is not built.
3572
- ...(lead == null ? void 0 : lead.name) && { merge_fields: { FNAME: String(lead.name).trim().split(/\s+/)[0] } },
4024
+ // Built above. Omitted entirely when there is nothing to say, so a
4025
+ // lead with only an address does not send an empty object. The
4026
+ // Drawbridge totals Klaviyo receives still cannot travel this way
4027
+ // those are custom tags, and registering them on the chosen audience
4028
+ // is lifecycle.register's job and is not built.
4029
+ ...Object.keys(mergeFields).length > 0 && { merge_fields: mergeFields },
3573
4030
  ...suppressed && { status: "unsubscribed" },
3574
4031
  status_if_new: suppressed ? "unsubscribed" : "subscribed"
3575
4032
  },
@@ -3592,7 +4049,7 @@ var mailchimp_default2 = {
3592
4049
  });
3593
4050
  const joined = new Set(segments.map((entry) => entry.title));
3594
4051
  const tags = (owned || []).map((entry) => entry.title).filter(Boolean).map((title) => ({
3595
- name: "Drawbridge: " + title,
4052
+ name: tagName(title),
3596
4053
  status: joined.has(title) ? "active" : "inactive"
3597
4054
  }));
3598
4055
  if (tags.length > 0) {
@@ -3615,12 +4072,122 @@ var mailchimp_default2 = {
3615
4072
  };
3616
4073
  }
3617
4074
  },
3618
- // Drawbridge sends its own notification email and SMS, and owns its own
3619
- // segments see the private `drawbridge` manifest. A vendor answering
3620
- // these would be a second sender, which is the arrangement the platform
3621
- // sender replaced.
4075
+ // Drawbridge sends its own notification email. A vendor answering this
4076
+ // would be a second sender, which is the arrangement the platform sender
4077
+ // replaced.
3622
4078
  email: false,
3623
- segment: false,
4079
+ // SEGMENTS ARE SHARED, not owned by one side. Drawbridge holds the
4080
+ // membership — see the private `drawbridge` manifest, and `sync : false`
4081
+ // below — while register and remove keep a Mailchimp tag standing for each
4082
+ // Drawbridge segment, so the merchant can target one in their own audience.
4083
+ segment: {
4084
+ // THE TAG THIS SEGMENT IS, held by id at last.
4085
+ //
4086
+ // Tags ARE static segments in Mailchimp's model — same collection, same
4087
+ // ids — so this creates one through /segments and the member write goes
4088
+ // on attaching people to it by name. Both address the same object. The
4089
+ // segment schema says it outright: "The type of segment. Static segments
4090
+ // are now known as tags"
4091
+ // (api.mailchimp.com/schema/3.0/Definitions/Lists/Segments/Response.json,
4092
+ // fetched 2026-09-12 — the root Swagger.json carries no prose, only $refs
4093
+ // into fragment files like this one).
4094
+ //
4095
+ // IDEMPOTENT ON EVERY PATH: called on create, on rename, on a connection
4096
+ // finishing its configuration, and on the backfill migration, it converges. That is what lets one hook serve
4097
+ // all four without a create-vs-update branch anywhere else.
4098
+ register: async ({ connection: connection2, context, manifest, settings, token, workflow }, { fetcher, read } = {}) => {
4099
+ var _a;
4100
+ const audience = settings == null ? void 0 : settings.audience;
4101
+ if (!audience) return { message: "No Mailchimp audience is chosen for this connection.", skipped: true };
4102
+ const segment = await currentSegment({ read, segment: context == null ? void 0 : context.segment });
4103
+ if (!(segment == null ? void 0 : segment.id) || segment.system) return { message: "That segment is not one this connection publishes.", skipped: true };
4104
+ const name = tagName(segment.title);
4105
+ const existing = segmentRowFor({ connection: connection2, segment });
4106
+ let id = null;
4107
+ if (existing == null ? void 0 : existing.id) {
4108
+ try {
4109
+ const found = await api3("/lists/" + audience + "/segments/" + existing.id, { dc: settings == null ? void 0 : settings.dc, fetcher, token });
4110
+ id = (found == null ? void 0 : found.id) ?? existing.id;
4111
+ if ((found == null ? void 0 : found.name) !== name) {
4112
+ await api3("/lists/" + audience + "/segments/" + existing.id, {
4113
+ dc: settings == null ? void 0 : settings.dc,
4114
+ fetcher,
4115
+ method: "PATCH",
4116
+ payload: { name },
4117
+ token
4118
+ });
4119
+ }
4120
+ } catch (error) {
4121
+ if (error.status !== 404) throw error;
4122
+ id = null;
4123
+ }
4124
+ }
4125
+ if (!id) {
4126
+ const search = await api3("/lists/" + audience + "/tag-search?name=" + encodeURIComponent(name), { dc: settings == null ? void 0 : settings.dc, fetcher, token });
4127
+ id = ((_a = ((search == null ? void 0 : search.tags) || []).find((tag) => (tag == null ? void 0 : tag.name) === name)) == null ? void 0 : _a.id) ?? null;
4128
+ }
4129
+ if (!id) {
4130
+ const created = await api3("/lists/" + audience + "/segments", {
4131
+ dc: settings == null ? void 0 : settings.dc,
4132
+ fetcher,
4133
+ method: "POST",
4134
+ // STATIC WITH NO MEMBERS. The member sync attaches people by
4135
+ // name; this call only has to make the object exist. Mailchimp's
4136
+ // own wording for the empty array: "Passing an empty array will
4137
+ // create a static segment without any subscribers."
4138
+ payload: { name, static_segment: [] },
4139
+ token
4140
+ });
4141
+ id = created == null ? void 0 : created.id;
4142
+ }
4143
+ if (!id) return { message: "Mailchimp returned no tag id.", skipped: true };
4144
+ const audienceDetail = await api3("/lists/" + audience + "?fields=web_id", { dc: settings == null ? void 0 : settings.dc, fetcher, token });
4145
+ return {
4146
+ // A RENAME THAT ARRIVED WHILE THIS RAN was dropped by the
4147
+ // coalescing job id, so the last thing this does is look again.
4148
+ enqueues: await driftEnqueues({ applied: segment.title, read, segment, workflow }),
4149
+ events: [{
4150
+ event: "organization.segments",
4151
+ payload: { id: segment.id },
4152
+ room: "organization." + (connection2 == null ? void 0 : connection2.organization)
4153
+ }],
4154
+ message: 'Mailchimp is carrying this segment as the tag "' + name + '".',
4155
+ writes: segmentRowWrites({
4156
+ connection: connection2,
4157
+ data: { ...connection2, settings },
4158
+ manifest,
4159
+ row: { id, type: "tag", webId: audienceDetail == null ? void 0 : audienceDetail.web_id },
4160
+ segment
4161
+ })
4162
+ };
4163
+ },
4164
+ // THE TAG GOES WITH THE SEGMENT. Leaving it behind is the orphan this
4165
+ // whole pair exists to stop — every member would keep a label for a
4166
+ // segment that no longer exists.
4167
+ remove: async ({ connection: connection2, context, settings, token }, { fetcher } = {}) => {
4168
+ const segment = context == null ? void 0 : context.segment;
4169
+ const existing = segmentRowFor({ connection: connection2, segment });
4170
+ if (!(existing == null ? void 0 : existing.id)) return { message: "Mailchimp was never carrying this segment.", skipped: true };
4171
+ try {
4172
+ await api3("/lists/" + (settings == null ? void 0 : settings.audience) + "/segments/" + existing.id, {
4173
+ dc: settings == null ? void 0 : settings.dc,
4174
+ fetcher,
4175
+ method: "DELETE",
4176
+ token
4177
+ });
4178
+ } catch (error) {
4179
+ if (error.status !== 404) throw error;
4180
+ }
4181
+ return {
4182
+ message: "Mailchimp is no longer carrying this segment.",
4183
+ writes: segmentRowRemoveWrites({ connection: connection2, segment })
4184
+ };
4185
+ },
4186
+ // Drawbridge-side membership belongs to the private manifest.
4187
+ sync: false
4188
+ },
4189
+ // Declined for the same reason as `email` above: Drawbridge sends its own
4190
+ // notification SMS, and a vendor answering this would be a second sender.
3624
4191
  sms: false,
3625
4192
  inbound: false,
3626
4193
  lifecycle: false,
@@ -3683,6 +4250,16 @@ var mailchimp_default2 = {
3683
4250
  "MAILCHIMP_OAUTH_CLIENT_ID",
3684
4251
  "MAILCHIMP_OAUTH_CLIENT_SECRET"
3685
4252
  ],
4253
+ // THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
4254
+ review: {
4255
+ api: "https://mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/",
4256
+ dashboard: "https://mailchimp.com/help/manage-tags/",
4257
+ // NO SCOPES EXIST. Mailchimp's OAuth guide describes none, and a token is
4258
+ // account-wide — so there is nothing to request and nothing to re-consent.
4259
+ scopes: false,
4260
+ content: "2026-09-11",
4261
+ verified: null
4262
+ },
3686
4263
  slug: "mailchimp",
3687
4264
  // A grant with no audience chosen is authenticated and useless — the sync has
3688
4265
  // nowhere to put anyone — so the card must say Pending rather than Active over
@@ -3728,6 +4305,30 @@ var mailchimp_default2 = {
3728
4305
  // adds this step, and what is charged when it runs.
3729
4306
  usage: { actions: 1 }
3730
4307
  })
4308
+ },
4309
+ segment: {
4310
+ // SYSTEM, so the builder never offers it and a merchant POST refuses it:
4311
+ // these fire from the segment's own lifecycle, not from a workflow
4312
+ // somebody assembled.
4313
+ //
4314
+ // The trigger is declared HERE rather than hard-coded in drawbridge-sync,
4315
+ // which is what lets a vendor arrive with its own without a queue edit.
4316
+ register: () => ({
4317
+ description: "Keeps a matching tag in your Mailchimp audience for each Drawbridge segment, and renames it when the segment is renamed.",
4318
+ hook: "segment.register",
4319
+ key: "Mailchimp Segment Register",
4320
+ queue: "connection",
4321
+ system: true,
4322
+ trigger: { event: "segment.register", type: "event" }
4323
+ }),
4324
+ remove: () => ({
4325
+ description: "Deletes the Mailchimp tag for a Drawbridge segment when the segment is deleted.",
4326
+ hook: "segment.remove",
4327
+ key: "Mailchimp Segment Remove",
4328
+ queue: "connection",
4329
+ system: true,
4330
+ trigger: { event: "segment.remove", type: "event" }
4331
+ })
3731
4332
  }
3732
4333
  },
3733
4334
  // WHY, in the merchant's words, and what to do about it.
@@ -3744,11 +4345,27 @@ var mailchimp_default2 = {
3744
4345
  }
3745
4346
  ];
3746
4347
  },
3747
- title: "Mailchimp"
4348
+ title: "Mailchimp",
4349
+ // THE MERCHANT'S OWN ADMIN. Mailchimp's list schema states the shape outright:
4350
+ // the web_id field is "The ID used in the Mailchimp web application. View this
4351
+ // list in your Mailchimp account at
4352
+ // https://{dc}.admin.mailchimp.com/lists/members/?id={web_id}"
4353
+ // (api.mailchimp.com/schema/3.0/Definitions/Lists/Response.json, fetched
4354
+ // 2026-09-11).
4355
+ //
4356
+ // It lands on the audience's contacts, where the Drawbridge tag is one filter
4357
+ // away. Mailchimp documents no url that pre-selects a tag, so this stops one
4358
+ // click short rather than guessing at one that could break silently.
4359
+ urls: {
4360
+ segment: (row2, data2) => {
4361
+ var _a;
4362
+ return ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.dc) && (row2 == null ? void 0 : row2.webId) ? "https://" + data2.settings.dc + ".admin.mailchimp.com/lists/members/?id=" + row2.webId : null;
4363
+ }
4364
+ }
3748
4365
  };
3749
4366
 
3750
4367
  // lib/connections/providers/shopify.js
3751
- var import_node_crypto5 = require("crypto");
4368
+ var import_node_crypto6 = require("crypto");
3752
4369
  var import_nanoid3 = require("nanoid");
3753
4370
 
3754
4371
  // lib/connections/icons/shopify.js
@@ -3845,6 +4462,28 @@ var attributeLineItems = (lineItems = []) => lineItems.reduce(
3845
4462
  { attrMap: {}, attributedGross: 0, attributedLines: [] }
3846
4463
  );
3847
4464
  var generateDiscountCode = (0, import_nanoid3.customAlphabet)("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 8);
4465
+ var blockedReason = (discount) => {
4466
+ var _a;
4467
+ if ((discount == null ? void 0 : discount.status) === "EXPIRED") return "This discount has expired.";
4468
+ const buyers = (_a = discount == null ? void 0 : discount.context) == null ? void 0 : _a.__typename;
4469
+ if (buyers && buyers !== "DiscountBuyerSelectionAll") {
4470
+ return "This discount is limited to specific buyers in Shopify, so a code issued to an entrant won't work. Set it to all customers to use it here.";
4471
+ }
4472
+ ;
4473
+ if (typeof (discount == null ? void 0 : discount.usageLimit) === "number" && discount.usageLimit > 0 && ((discount == null ? void 0 : discount.asyncUsageCount) || 0) >= discount.usageLimit) {
4474
+ return "This discount has reached its total usage limit.";
4475
+ }
4476
+ ;
4477
+ return null;
4478
+ };
4479
+ var discountWarning = (discount) => {
4480
+ if ((discount == null ? void 0 : discount.status) === "SCHEDULED") {
4481
+ return "This discount hasn't started yet, so codes issued before it does won't work until then.";
4482
+ }
4483
+ ;
4484
+ if (discount == null ? void 0 : discount.appliesOncePerCustomer) return "Each customer can use this discount only once.";
4485
+ return null;
4486
+ };
3848
4487
  var ORDER_EVENT_HANDLE = slugify("drawbridge-orders");
3849
4488
  var REFRESH_TOKEN_FRESHNESS_BUFFER_MS = 5 * 24 * 60 * 60 * 1e3;
3850
4489
  var OAUTH_ERROR_SOURCE = "oauth";
@@ -3892,7 +4531,7 @@ var shopify_default2 = {
3892
4531
  description: [
3893
4532
  "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.",
3894
4533
  "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.",
3895
- "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 resources."
4534
+ "Drawbridge reads your products, records orders placed through your campaigns, and can issue discount codes. Order and product updates reach Drawbridge through the app's own webhooks, which Shopify applies when the app is installed."
3896
4535
  ],
3897
4536
  errors: {
3898
4537
  connect: {
@@ -3906,7 +4545,7 @@ var shopify_default2 = {
3906
4545
  "Open the Drawbridge listing on the Shopify App Store.",
3907
4546
  "Install the app on the store you want to connect. It opens in Shopify admin and stays there.",
3908
4547
  "Approve the Drawbridge plan when prompted \u2014 during install, or from the connection page here. The connection shows Pending until you do, then Active.",
3909
- "Come back here \u2014 the connections list updates on its own once the install lands."
4548
+ "Come back here \u2014 the connections list updates on its own once the install finishes."
3910
4549
  ],
3911
4550
  // Names where the link GOES rather than what it does: installing happens on
3912
4551
  // the App Store listing, and the dashboard must never imply a store can be
@@ -4282,9 +4921,11 @@ var shopify_default2 = {
4282
4921
  phone: customerPhone
4283
4922
  } : null;
4284
4923
  const source = (connection2 == null ? void 0 : connection2.source) ? { domain: connection2.source.domain, id: connection2.source.id } : void 0;
4285
- const orderDocId = (existingOrder == null ? void 0 : existingOrder.id) || (isConversion && !backfill ? mintId() : null);
4924
+ const createsOrder = !backfill && (isConversion || Boolean(discount));
4925
+ const orderDocId = (existingOrder == null ? void 0 : existingOrder.id) || (createsOrder ? mintId() : null);
4926
+ const redemptionDocId = discount ? mintId() : null;
4286
4927
  const writes = [];
4287
- if (isConversion && !backfill) {
4928
+ if (createsOrder) {
4288
4929
  writes.push({
4289
4930
  collection: "order",
4290
4931
  data: {
@@ -4305,15 +4946,25 @@ var shopify_default2 = {
4305
4946
  provider: { id: String(orderId), slug: "shopify" },
4306
4947
  purchasedAt,
4307
4948
  rate,
4949
+ // Null on a conversion that matched no code of ours; the
4950
+ // backfill branch below sets it when one arrives later.
4951
+ redemption: redemptionDocId,
4308
4952
  source,
4309
- status: "completed"
4953
+ status: "completed",
4954
+ type: isConversion ? "conversion" : "redemption"
4310
4955
  },
4311
4956
  operation: "create"
4312
4957
  });
4313
4958
  if (org == null ? void 0 : org.usage) {
4314
4959
  writes.push({
4315
4960
  collection: "usage",
4316
- data: { $inc: { "totals.revenue": gross } },
4961
+ // TWO METERS, NOT ONE SUMMED. `revenue` has always meant
4962
+ // conversion revenue and is the figure the fee is charged
4963
+ // against, so redemption money gets its own key rather than
4964
+ // changing what an existing number means.
4965
+ data: {
4966
+ $inc: isConversion ? { "totals.revenue": gross } : { "totals.redemptionRevenue": gross }
4967
+ },
4317
4968
  operation: "update",
4318
4969
  query: { id: org.usage }
4319
4970
  });
@@ -4321,7 +4972,12 @@ var shopify_default2 = {
4321
4972
  if (leadId) {
4322
4973
  writes.push({
4323
4974
  collection: "lead",
4324
- data: { $inc: { "totals.orders": 1 } },
4975
+ // Same grouped shape the contact carries, so a lead and the
4976
+ // contact built from it cannot be read two different ways.
4977
+ data: { $inc: {
4978
+ "totals.orders.total": 1,
4979
+ ...isConversion ? { "totals.orders.conversions": 1 } : { "totals.orders.redemptions": 1 }
4980
+ } },
4325
4981
  operation: "update",
4326
4982
  options: { bypassDocumentValidation: true },
4327
4983
  query: { id: leadId }
@@ -4340,6 +4996,7 @@ var shopify_default2 = {
4340
4996
  customer,
4341
4997
  discount,
4342
4998
  gross,
4999
+ id: redemptionDocId,
4343
5000
  lead: leadId,
4344
5001
  order: orderDocId,
4345
5002
  organization: campaignOrganization,
@@ -4368,6 +5025,14 @@ var shopify_default2 = {
4368
5025
  query: { id: leadId }
4369
5026
  });
4370
5027
  }
5028
+ if (backfill && orderDocId && redemptionDocId) {
5029
+ writes.push({
5030
+ collection: "order",
5031
+ data: { $set: { redemption: redemptionDocId } },
5032
+ operation: "update",
5033
+ query: { id: orderDocId }
5034
+ });
5035
+ }
4371
5036
  }
4372
5037
  const billable = (org == null ? void 0 : org.billingProvider) === "shopify" && fee > 0 && !backfill;
4373
5038
  const providerRow = billable ? await read.get({ collection: "provider", query: { slug: "shopify" } }) : null;
@@ -4746,7 +5411,7 @@ var shopify_default2 = {
4746
5411
  event: "shopify.register.webhooks"
4747
5412
  },
4748
5413
  name: "register",
4749
- options: { jobId: "connection.update.register." + workflow.connection + "." + (0, import_node_crypto5.randomUUID)() },
5414
+ options: { jobId: "connection.update.register." + workflow.connection + "." + (0, import_node_crypto6.randomUUID)() },
4750
5415
  queue: "connection"
4751
5416
  }],
4752
5417
  message: ((scopesMissing == null ? void 0 : scopesMissing.length) ? "Health check: ping ok, webhooks reconciled \u2014 connection errored, granted scopes are missing: " + scopesMissing.join(", ") + "." : refreshTokenRotated ? "Health check passed \u2014 refresh token rotated, ping ok, webhooks reconciled." : "Health check passed \u2014 ping ok, webhooks reconciled.") + (sourceRepaired ? " Billing source repaired from the live shop." : "") + (metered === null ? " No usage line on the store's approved plan \u2014 order billing needs the merchant to approve the updated plan." : ""),
@@ -4860,10 +5525,19 @@ var shopify_default2 = {
4860
5525
  // picker stores, which is why the tail is taken here rather than by
4861
5526
  // each caller that happened to remember.
4862
5527
  items: ((discounts == null ? void 0 : discounts.edges) || []).map((edge) => {
4863
- var _a2, _b2, _c;
5528
+ var _a2, _b2;
5529
+ const node = ((_a2 = edge == null ? void 0 : edge.node) == null ? void 0 : _a2.codeDiscount) || {};
4864
5530
  return {
4865
- id: String(((_a2 = edge == null ? void 0 : edge.node) == null ? void 0 : _a2.id) || "").split("/").pop(),
4866
- title: (_c = (_b2 = edge == null ? void 0 : edge.node) == null ? void 0 : _b2.codeDiscount) == null ? void 0 : _c.title
5531
+ // Null when the discount can be used, a sentence when it cannot.
5532
+ // The picker greys the row and shows this instead of hiding it:
5533
+ // a discount the merchant can see in Shopify admin, missing here
5534
+ // with no explanation, reads as a bug in us.
5535
+ blocked: blockedReason(node),
5536
+ id: String(((_b2 = edge == null ? void 0 : edge.node) == null ? void 0 : _b2.id) || "").split("/").pop(),
5537
+ // Usable, but not in the way the merchant probably expects.
5538
+ // Shown beside the row without stopping them.
5539
+ warning: discountWarning(node),
5540
+ title: node.title
4867
5541
  };
4868
5542
  }),
4869
5543
  pageInfo: {
@@ -4878,20 +5552,6 @@ var shopify_default2 = {
4878
5552
  },
4879
5553
  icon: shopify_default,
4880
5554
  inbound,
4881
- // THE DEEP LINK into this store's Drawbridge app inside Shopify admin.
4882
- //
4883
- // Here rather than in drawbridge-api, which had `slug === 'shopify' && {...}`
4884
- // in the shared resolver — a hardcoded vendor branch in code every vendor runs
4885
- // through, which is the arrangement these manifests exist to remove.
4886
- //
4887
- // Undefined until a shop is linked, so the Manage button only appears on a
4888
- // connected connection. The app handle is NAMED by `requires` and read from
4889
- // the env the resolver passes, never from process.env here.
4890
- manage: (data2, env) => {
4891
- var _a;
4892
- const shop = (data2 == null ? void 0 : data2.shop) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.domain);
4893
- return shop ? "https://admin.shopify.com/store/" + String(shop).replace(".myshopify.com", "") + "/apps/" + (env == null ? void 0 : env.SHOPIFY_APP_HANDLE) : void 0;
4894
- },
4895
5555
  // DRAWBRIDGE'S OWN CREDENTIALS for this vendor, as opposed to a merchant's —
4896
5556
  // what an admin types on the provider screen. The four names below are exactly
4897
5557
  // what `requires` gates on, which is the point of declaring them together: a
@@ -4937,6 +5597,14 @@ var shopify_default2 = {
4937
5597
  "SHOPIFY_APP_LISTING_URL",
4938
5598
  "SHOPIFY_APP_HANDLE"
4939
5599
  ],
5600
+ // THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
5601
+ review: {
5602
+ api: "https://shopify.dev/docs/api/admin-graphql",
5603
+ dashboard: "https://help.shopify.com/en/manual/apps",
5604
+ scopes: "https://shopify.dev/docs/api/usage/access-scopes",
5605
+ content: "2026-09-11",
5606
+ verified: null
5607
+ },
4940
5608
  slug: "shopify",
4941
5609
  // The install is the whole configuration — Shopify hands back the shop and
4942
5610
  // there is nothing further to choose. `shop` absent means the install did not
@@ -5024,8 +5692,11 @@ var shopify_default2 = {
5024
5692
  })
5025
5693
  },
5026
5694
  // SYSTEM STEPS: dispatched by drawbridge-sync itself rather than offered
5027
- // in the builder, so they carry no trigger and no usage. Declared because
5028
- // the routing table and the system-workflow descriptions both read here.
5695
+ // in the builder, so they carry no usage. These two are fired by a webhook
5696
+ // arriving rather than by a workflow trigger, so they name none either —
5697
+ // and naming none is what stops a workflow being provisioned for them.
5698
+ // Declared because the routing table and the system-workflow descriptions
5699
+ // both read here.
5029
5700
  order: {
5030
5701
  record: () => ({
5031
5702
  description: "Records an order and billing charge when a purchase is made via a Drawbridge campaign link.",
@@ -5057,7 +5728,8 @@ var shopify_default2 = {
5057
5728
  hook: "lifecycle.health",
5058
5729
  key: "Shopify Connection Health",
5059
5730
  queue: "connection",
5060
- system: true
5731
+ system: true,
5732
+ trigger: { event: "day", type: "schedule" }
5061
5733
  })
5062
5734
  },
5063
5735
  // Audit-only. The "Shopify Token Activity" system workflow lists these
@@ -5118,11 +5790,34 @@ var shopify_default2 = {
5118
5790
  ] : []
5119
5791
  ];
5120
5792
  },
5121
- title: "Shopify"
5793
+ title: "Shopify",
5794
+ // THE VENDOR'S OWN ADMIN, one function per thing worth linking to. It lives
5795
+ // here rather than at the top level so a second link (a product, an order)
5796
+ // is a key in this object instead of a new manifest key nobody agreed on.
5797
+ //
5798
+ // AND HERE RATHER THAN IN drawbridge-api, which had `slug === 'shopify' &&
5799
+ // {...}` in the shared resolver — a hardcoded vendor branch in code every
5800
+ // vendor runs through, which is the arrangement these manifests exist to
5801
+ // remove.
5802
+ //
5803
+ // Never projected: the api composes connect.manage from it, and
5804
+ // resolveConnection drops the object, because a url built from settings is
5805
+ // built where the settings are already decrypted.
5806
+ urls: {
5807
+ // Undefined until a shop is linked, so the Manage button only appears on a
5808
+ // connected connection. The app handle is NAMED by `requires` and read from
5809
+ // the env its caller passes — the api's resolve() hands it the stored
5810
+ // credentials, never process.env.
5811
+ manage: (data2, env) => {
5812
+ var _a;
5813
+ const shop = (data2 == null ? void 0 : data2.shop) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.domain);
5814
+ return shop ? "https://admin.shopify.com/store/" + String(shop).replace(".myshopify.com", "") + "/apps/" + (env == null ? void 0 : env.SHOPIFY_APP_HANDLE) : void 0;
5815
+ }
5816
+ }
5122
5817
  };
5123
5818
 
5124
5819
  // lib/connections/providers/webhook.js
5125
- var import_node_crypto6 = __toESM(require("crypto"), 1);
5820
+ var import_node_crypto7 = __toESM(require("crypto"), 1);
5126
5821
 
5127
5822
  // lib/safe-http.js
5128
5823
  var import_dns2 = __toESM(require("dns"), 1);
@@ -5276,7 +5971,7 @@ var signature = ({ body, settings }) => {
5276
5971
  return [
5277
5972
  "t=" + timestamp,
5278
5973
  ...[settings.secret, ...previous].map(
5279
- (secret) => "v1=" + import_node_crypto6.default.createHmac("sha256", secret).update(payload).digest("hex")
5974
+ (secret) => "v1=" + import_node_crypto7.default.createHmac("sha256", secret).update(payload).digest("hex")
5280
5975
  )
5281
5976
  ].join(",");
5282
5977
  };
@@ -5298,7 +5993,7 @@ var webhook_default = {
5298
5993
  content: {
5299
5994
  confirm: "Disconnecting stops Drawbridge from sending signed webhook payloads to your endpoint.",
5300
5995
  description: [
5301
- "Drawbridge can POST event payloads to your endpoint as activity happens in your account, so your own systems can react in real time.",
5996
+ "Drawbridge can POST event payloads to your endpoint as activity happens in your account, so your own systems can react to it.",
5302
5997
  "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."
5303
5998
  ],
5304
5999
  excerpt: "Sign outgoing webhook payloads with an HMAC secret to verify authenticity.",
@@ -5399,6 +6094,9 @@ var webhook_default = {
5399
6094
  // Gated on the encryption secret: without it the signing secret could not be
5400
6095
  // stored safely, so the connection must not be offered at all.
5401
6096
  requires: ["ENCRYPT_CONNECTION_SECRET"],
6097
+ // NO THIRD PARTY AT ALL. There is no vendor reference to read, no dashboard
6098
+ // to link to and no scope to request: connecting mints a secret.
6099
+ review: false,
5402
6100
  // Outbound only. inbound.* is false because the direction is the point: we
5403
6101
  // sign and POST to the merchant's endpoint, they never call us. Every other
5404
6102
  // false follows from there being no third party to authenticate against —
@@ -5788,7 +6486,7 @@ var redactSettings = ({ slug: slug2, settings }) => {
5788
6486
  var publicConnectionKeys = Object.freeze([
5789
6487
  "actions",
5790
6488
  // API-COMPOSED, not manifest-declared: the api's resolve() builds it from
5791
- // auth.type, content.redirect and the manifest's manage() — the client reads
6489
+ // auth.type, content.redirect and the manifest's urls.manage() — the client reads
5792
6490
  // connect.type to choose entered-vs-installed, connect.redirect for the App
5793
6491
  // Store link, connect.manage for the admin deep link. It was dropped from
5794
6492
  // this list when the manifests stopped declaring it, which stripped the
@@ -5843,7 +6541,7 @@ var projectConnection = (record) => {
5843
6541
  var resolveConnection = (item, data2, env = {}) => {
5844
6542
  if (!item) return item;
5845
6543
  return Object.fromEntries(
5846
- Object.entries(item).filter(([key]) => !["auth", "enabled", "fields", "hooks", "inbound", "provider", "requires", "status", "steps", "supports"].includes(key)).map(([key, value]) => [
6544
+ Object.entries(item).filter(([key]) => !["auth", "enabled", "fields", "hooks", "inbound", "provider", "requires", "review", "status", "steps", "supports", "urls"].includes(key)).map(([key, value]) => [
5847
6545
  key,
5848
6546
  typeof value === "function" ? value(data2, env) : value
5849
6547
  ])