@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.
- package/dist/connections/index.cjs +795 -97
- package/dist/connections/index.d.cts +1216 -96
- package/dist/connections/index.d.ts +1216 -96
- package/dist/connections/index.js +784 -86
- package/dist/providers.cjs +799 -101
- package/dist/providers.js +788 -90
- package/package.json +1 -1
package/dist/providers.js
CHANGED
|
@@ -129,7 +129,20 @@ var HOOKS = Object.freeze({
|
|
|
129
129
|
"digest"
|
|
130
130
|
]),
|
|
131
131
|
sms: Object.freeze(["send"]),
|
|
132
|
-
segment: Object.freeze([
|
|
132
|
+
segment: Object.freeze([
|
|
133
|
+
// Make this segment's object exist at the vendor, carrying the segment's
|
|
134
|
+
// current title, and describe the row that points at it. IDEMPOTENT: the
|
|
135
|
+
// same call creates it, renames it after an edit, and backfills a segment
|
|
136
|
+
// that predates the connection — so one hook serves every path and there
|
|
137
|
+
// is no create-vs-update branch to keep in step.
|
|
138
|
+
"register",
|
|
139
|
+
// Remove the vendor object this connection's row points at. Called with
|
|
140
|
+
// the pre-image on a segment delete, because by then the document is gone.
|
|
141
|
+
"remove",
|
|
142
|
+
// Recalculate Drawbridge-side membership. Private to the drawbridge
|
|
143
|
+
// manifest; a vendor does not own who is in a Drawbridge segment.
|
|
144
|
+
"sync"
|
|
145
|
+
]),
|
|
133
146
|
// OUTBOUND DELIVERY to an address the merchant owns, rather than to a vendor.
|
|
134
147
|
// The Webhooks connection is the only thing here with no third party behind
|
|
135
148
|
// it, and the destination is per STEP rather than per connection.
|
|
@@ -238,6 +251,8 @@ var STEPS = Object.freeze({
|
|
|
238
251
|
"email.digest": "Digest",
|
|
239
252
|
"email.notify": "Notification",
|
|
240
253
|
"email.send": "Send email",
|
|
254
|
+
"segment.register": "Register segment",
|
|
255
|
+
"segment.remove": "Remove segment",
|
|
241
256
|
"segment.sync": "Sync segment",
|
|
242
257
|
"sms.send": "Send SMS",
|
|
243
258
|
"webhook.send": "Send webhook"
|
|
@@ -373,7 +388,16 @@ var tokenSettings = ({ existing = {}, now = Date.now(), tokens }) => ({
|
|
|
373
388
|
...tokens.expiresIn && {
|
|
374
389
|
expiresAt: new Date(now + tokens.expiresIn * 1e3).toISOString()
|
|
375
390
|
},
|
|
376
|
-
|
|
391
|
+
// A VENDOR NEED NOT RETURN `scope` ON A REFRESH. Klaviyo documents it on the
|
|
392
|
+
// authorization_code response and documents no response body at all for the
|
|
393
|
+
// refresh grant, so taking the minted value alone drops the stored one. That
|
|
394
|
+
// matters because `scope` is load-bearing: the segment hooks gate on
|
|
395
|
+
// `segments:write` and answer `skipped` when it is absent, so a connection
|
|
396
|
+
// that dropped it disables its whole segment half without failing anything
|
|
397
|
+
// and shows a reconnect task that reconnecting has already fixed.
|
|
398
|
+
...(tokens.scope || existing.scope) && {
|
|
399
|
+
scope: tokens.scope || existing.scope
|
|
400
|
+
}
|
|
377
401
|
});
|
|
378
402
|
var accessToken = async ({
|
|
379
403
|
clientId,
|
|
@@ -436,6 +460,98 @@ var detectCountry = (value) => {
|
|
|
436
460
|
}
|
|
437
461
|
};
|
|
438
462
|
|
|
463
|
+
// lib/connections/segment-rows.js
|
|
464
|
+
import { randomUUID } from "crypto";
|
|
465
|
+
var row = ({ connection: connection2, data: data2, manifest, row: described }) => {
|
|
466
|
+
var _a, _b;
|
|
467
|
+
return {
|
|
468
|
+
connection: connection2 == null ? void 0 : connection2.id,
|
|
469
|
+
// ALWAYS A STRING. Mailchimp tag ids are integers, Klaviyo segment ids are
|
|
470
|
+
// strings, and one type in the schema is one comparison in the $or below.
|
|
471
|
+
id: String(described == null ? void 0 : described.id),
|
|
472
|
+
slug: connection2 == null ? void 0 : connection2.slug,
|
|
473
|
+
type: described == null ? void 0 : described.type,
|
|
474
|
+
// NULL, NEVER UNDEFINED: undefined drops the key, and the schema requires it.
|
|
475
|
+
// The url is built HERE, while the settings are decrypted and the vendor
|
|
476
|
+
// facts are in hand — an api reading the row later has neither.
|
|
477
|
+
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
|
|
478
|
+
};
|
|
479
|
+
};
|
|
480
|
+
var segmentRowWrites = ({ connection: connection2, data: data2, manifest, row: described, segment }) => {
|
|
481
|
+
const built = row({ connection: connection2, data: data2, manifest, row: described });
|
|
482
|
+
return [
|
|
483
|
+
// PUSH IF ABSENT. The $ne guard is what makes a second concurrent register
|
|
484
|
+
// add nothing rather than a duplicate row for one connection.
|
|
485
|
+
{
|
|
486
|
+
collection: "segment",
|
|
487
|
+
data: { $push: { connections: built } },
|
|
488
|
+
operation: "update",
|
|
489
|
+
query: {
|
|
490
|
+
id: segment == null ? void 0 : segment.id,
|
|
491
|
+
"connections.connection": { $ne: connection2 == null ? void 0 : connection2.id }
|
|
492
|
+
}
|
|
493
|
+
},
|
|
494
|
+
// SET IF DIFFERENT. $elemMatch selects this connection's row only when one
|
|
495
|
+
// of its three mutable fields disagrees, so the steady state — the same
|
|
496
|
+
// vendor object, the same url — matches nothing and writes nothing.
|
|
497
|
+
{
|
|
498
|
+
collection: "segment",
|
|
499
|
+
data: { $set: { "connections.$": built } },
|
|
500
|
+
operation: "update",
|
|
501
|
+
query: {
|
|
502
|
+
id: segment == null ? void 0 : segment.id,
|
|
503
|
+
connections: {
|
|
504
|
+
$elemMatch: {
|
|
505
|
+
connection: connection2 == null ? void 0 : connection2.id,
|
|
506
|
+
$or: [
|
|
507
|
+
{ id: { $ne: built.id } },
|
|
508
|
+
{ type: { $ne: built.type } },
|
|
509
|
+
{ url: { $ne: built.url } }
|
|
510
|
+
]
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
];
|
|
516
|
+
};
|
|
517
|
+
var segmentRowRemoveWrites = ({ connection: connection2, segment }) => [
|
|
518
|
+
{
|
|
519
|
+
collection: "segment",
|
|
520
|
+
data: { $pull: { connections: { connection: connection2 == null ? void 0 : connection2.id } } },
|
|
521
|
+
operation: "update",
|
|
522
|
+
query: { id: segment == null ? void 0 : segment.id }
|
|
523
|
+
}
|
|
524
|
+
];
|
|
525
|
+
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));
|
|
526
|
+
var currentSegment = async ({ read, segment }) => {
|
|
527
|
+
if (!(read == null ? void 0 : read.get) || !(segment == null ? void 0 : segment.id)) return segment;
|
|
528
|
+
return read.get({
|
|
529
|
+
collection: "segment",
|
|
530
|
+
query: { id: segment.id }
|
|
531
|
+
});
|
|
532
|
+
};
|
|
533
|
+
var driftEnqueues = async ({ applied, read, segment, workflow }) => {
|
|
534
|
+
if (!(workflow == null ? void 0 : workflow.id)) return [];
|
|
535
|
+
const fresh = await currentSegment({ read, segment });
|
|
536
|
+
if (!(fresh == null ? void 0 : fresh.id) || fresh.title === applied) return [];
|
|
537
|
+
return [{
|
|
538
|
+
data: {
|
|
539
|
+
triggerData: {
|
|
540
|
+
organization: fresh.organization || (workflow == null ? void 0 : workflow.organization),
|
|
541
|
+
segment: fresh
|
|
542
|
+
},
|
|
543
|
+
workflowId: workflow == null ? void 0 : workflow.id
|
|
544
|
+
},
|
|
545
|
+
name: "execute",
|
|
546
|
+
options: {
|
|
547
|
+
jobId: "workflow.insert.execute." + (workflow == null ? void 0 : workflow.id) + ".segment.register." + fresh.id + ".drift." + Date.now() + "." + randomUUID().slice(0, 8),
|
|
548
|
+
removeOnComplete: true,
|
|
549
|
+
removeOnFail: true
|
|
550
|
+
},
|
|
551
|
+
queue: "workflow"
|
|
552
|
+
}];
|
|
553
|
+
};
|
|
554
|
+
|
|
439
555
|
// lib/connections/providers/attentive.js
|
|
440
556
|
var api = async (path, { fetcher = fetch, method = "GET", payload, token }) => {
|
|
441
557
|
const response = await fetcher("https://api.attentivemobile.com" + path, {
|
|
@@ -488,7 +604,7 @@ var attentive_default2 = {
|
|
|
488
604
|
// has to say so rather than let them believe otherwise.
|
|
489
605
|
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.",
|
|
490
606
|
description: [
|
|
491
|
-
"
|
|
607
|
+
"This connection syncs the contacts your campaigns collect into your Attentive account \u2014 subscribed for marketing, and added to the segment you choose.",
|
|
492
608
|
"You authorize Drawbridge from inside Attentive and can revoke that access there at any time. Drawbridge never sees or stores your Attentive password.",
|
|
493
609
|
"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.",
|
|
494
610
|
"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."
|
|
@@ -530,10 +646,9 @@ var attentive_default2 = {
|
|
|
530
646
|
}
|
|
531
647
|
],
|
|
532
648
|
group: "contacts",
|
|
533
|
-
//
|
|
534
|
-
//
|
|
535
|
-
//
|
|
536
|
-
// and contacts.sync are the first to flip.
|
|
649
|
+
// WHAT THIS VENDOR DOES AND DOES NOT DO is the value of each hook below, not
|
|
650
|
+
// a paragraph up here that goes stale the moment one of them is implemented
|
|
651
|
+
// — which is exactly what happened to the note this replaces.
|
|
537
652
|
hooks: {
|
|
538
653
|
auth: {
|
|
539
654
|
// FALSE, NOT {}. `{}` means "supported, implemented in the repo with the
|
|
@@ -546,7 +661,7 @@ var attentive_default2 = {
|
|
|
546
661
|
// nobody re-derives it. Klaviyo's connect reads the account name back so
|
|
547
662
|
// the card is not blank; Attentive's card stays blank. There IS an
|
|
548
663
|
// endpoint — GET https://api.attentivemobile.com/v1/me, Bearer, described
|
|
549
|
-
// on docs.attentive.com/
|
|
664
|
+
// on docs.attentive.com/docs/authentication as returning "information
|
|
550
665
|
// specific to your company" — but its RESPONSE SCHEMA is published
|
|
551
666
|
// nowhere we can read: the docs show the curl and no body. Reading
|
|
552
667
|
// `body.name` would be a guess, and a guess here fails at the worst
|
|
@@ -713,7 +828,62 @@ var attentive_default2 = {
|
|
|
713
828
|
products: false,
|
|
714
829
|
promotions: false
|
|
715
830
|
},
|
|
716
|
-
segment:
|
|
831
|
+
segment: {
|
|
832
|
+
// A FOUNDATION, AND HONEST ABOUT IT. Attentive's segments API can create
|
|
833
|
+
// one with an externalId we choose (docs.attentive.com/reference/
|
|
834
|
+
// createsegment.md, fetched 2026-09-11: POST /v2/segments, `name`
|
|
835
|
+
// required, `externalId` optional and "auto-generated if not supplied"),
|
|
836
|
+
// which would give a real per-segment object — but it takes
|
|
837
|
+
// segments:write, and scopes ride on the app registration, which does not
|
|
838
|
+
// exist yet.
|
|
839
|
+
//
|
|
840
|
+
// So the row points at the connection-level segment the merchant chose,
|
|
841
|
+
// `type` says so, and turning this into a per-segment object later is a
|
|
842
|
+
// change to this file and nothing else: create with
|
|
843
|
+
// externalId = segment.id, PATCH to rename, archive on remove. Their
|
|
844
|
+
// update and archive endpoints are BOTH keyed by external id
|
|
845
|
+
// (docs.attentive.com/reference/patchsegmentbyexternalid.md and
|
|
846
|
+
// /deletesegmentbyexternalid.md, fetched 2026-09-11), so the segment id we
|
|
847
|
+
// already hold addresses every one of the three calls.
|
|
848
|
+
//
|
|
849
|
+
// NO DRIFT CHECK, unlike the other two: the row points at the
|
|
850
|
+
// connection's own segment and the link is the index page, so nothing
|
|
851
|
+
// here depends on the Drawbridge segment's title — a rename has nothing
|
|
852
|
+
// to apply and nothing to race with. That comes back with the
|
|
853
|
+
// per-segment object.
|
|
854
|
+
//
|
|
855
|
+
// THE RE-READ STAYS ALL THE SAME. It changes nothing today, and this is
|
|
856
|
+
// the simplest of the three registers and therefore the one the next
|
|
857
|
+
// vendor gets copied from — one job id serves four dispatch sites, so a
|
|
858
|
+
// copy that trusts context.segment applies whichever trigger data won
|
|
859
|
+
// the race, at a vendor where the title does matter.
|
|
860
|
+
register: async ({ connection: connection2, context, manifest, settings }, { read } = {}) => {
|
|
861
|
+
const segment = await currentSegment({ read, segment: context == null ? void 0 : context.segment });
|
|
862
|
+
if (!(segment == null ? void 0 : segment.id) || segment.system) return { message: "That segment is not one this connection publishes.", skipped: true };
|
|
863
|
+
if (!(settings == null ? void 0 : settings.segment)) return { message: "No Attentive segment is chosen for this connection.", skipped: true };
|
|
864
|
+
return {
|
|
865
|
+
events: [{
|
|
866
|
+
event: "organization.segments",
|
|
867
|
+
payload: { id: segment.id },
|
|
868
|
+
room: "organization." + (connection2 == null ? void 0 : connection2.organization)
|
|
869
|
+
}],
|
|
870
|
+
message: "Contacts in this segment are added to the Attentive segment chosen on this connection.",
|
|
871
|
+
writes: segmentRowWrites({
|
|
872
|
+
connection: connection2,
|
|
873
|
+
data: { ...connection2, settings },
|
|
874
|
+
manifest,
|
|
875
|
+
row: { id: settings.segment, type: "segment" },
|
|
876
|
+
segment
|
|
877
|
+
})
|
|
878
|
+
};
|
|
879
|
+
},
|
|
880
|
+
// NOT OURS TO DELETE. The segment on this connection is the merchant's,
|
|
881
|
+
// and it is where every Drawbridge segment's contacts go — removing it
|
|
882
|
+
// because one Drawbridge segment was deleted would empty the others.
|
|
883
|
+
remove: false,
|
|
884
|
+
// Drawbridge-side membership belongs to the private manifest.
|
|
885
|
+
sync: false
|
|
886
|
+
},
|
|
717
887
|
sms: false,
|
|
718
888
|
webhook: false
|
|
719
889
|
},
|
|
@@ -742,6 +912,21 @@ var attentive_default2 = {
|
|
|
742
912
|
"ATTENTIVE_OAUTH_CLIENT_ID",
|
|
743
913
|
"ATTENTIVE_OAUTH_CLIENT_SECRET"
|
|
744
914
|
],
|
|
915
|
+
// THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
|
|
916
|
+
review: {
|
|
917
|
+
api: "https://docs.attentive.com/reference/listsegments",
|
|
918
|
+
dashboard: "https://docs.attentive.com/docs/segments",
|
|
919
|
+
// THIS PAGE DOES NOT LIST EVERY SCOPE. Its table names five —
|
|
920
|
+
// events:write, ecommerce:write, subscriptions:write, attributes:write,
|
|
921
|
+
// privacy_requests:write — and says nothing about segments:read or
|
|
922
|
+
// segments:write, which the segments API this manifest calls does take.
|
|
923
|
+
// The header at the top of this file carries that distinction; it is
|
|
924
|
+
// repeated here so a reviewer following the link is not misled by what the
|
|
925
|
+
// table omits (fetched 2026-09-11).
|
|
926
|
+
scopes: "https://docs.attentive.com/docs/authentication",
|
|
927
|
+
content: "2026-09-11",
|
|
928
|
+
verified: null
|
|
929
|
+
},
|
|
745
930
|
slug: "attentive",
|
|
746
931
|
// A consent with no segment chosen is authenticated and inert — the sync needs
|
|
747
932
|
// somewhere to put people — so the card says Pending rather than Active over
|
|
@@ -779,6 +964,24 @@ var attentive_default2 = {
|
|
|
779
964
|
triggers: ["lead.insert", "segment.contact.add"],
|
|
780
965
|
usage: { actions: 1 }
|
|
781
966
|
})
|
|
967
|
+
},
|
|
968
|
+
segment: {
|
|
969
|
+
// SYSTEM, so the builder never offers it and a merchant POST refuses it:
|
|
970
|
+
// this fires from the segment's own lifecycle, not from a workflow
|
|
971
|
+
// somebody assembled. The trigger is declared here rather than hard-coded
|
|
972
|
+
// in drawbridge-sync.
|
|
973
|
+
//
|
|
974
|
+
// REGISTER ONLY. There is no remove step because hooks.segment.remove is
|
|
975
|
+
// declined, and build() refuses a step pointing at a hook this vendor does
|
|
976
|
+
// not implement — so the two are one decision, enforced at import.
|
|
977
|
+
register: () => ({
|
|
978
|
+
description: "Records which Attentive segment a Drawbridge segment's contacts are added to.",
|
|
979
|
+
hook: "segment.register",
|
|
980
|
+
key: "Attentive Segment Register",
|
|
981
|
+
queue: "connection",
|
|
982
|
+
system: true,
|
|
983
|
+
trigger: { event: "segment.register", type: "event" }
|
|
984
|
+
})
|
|
782
985
|
}
|
|
783
986
|
},
|
|
784
987
|
// WHY, in the merchant's words, and what to do about it.
|
|
@@ -795,7 +998,21 @@ var attentive_default2 = {
|
|
|
795
998
|
}
|
|
796
999
|
];
|
|
797
1000
|
},
|
|
798
|
-
title: "Attentive"
|
|
1001
|
+
title: "Attentive",
|
|
1002
|
+
// ATTENTIVE'S SEGMENTS INDEX. There is no documented per-segment url, and the
|
|
1003
|
+
// only identifier we hold is the API's externalId, which their UI may not
|
|
1004
|
+
// path by — so this lands on the list, where the merchant finds it by name.
|
|
1005
|
+
// A per-segment link arrives with the per-segment object (see hooks.segment).
|
|
1006
|
+
//
|
|
1007
|
+
// THE PATH ITSELF IS NOT PUBLISHED ANYWHERE CITABLE, the same gap Klaviyo's
|
|
1008
|
+
// segment url carries. What is on record is that the segments area lives at
|
|
1009
|
+
// ui.attentivemobile.com/segments — its /segments/create/ and /segments/manual
|
|
1010
|
+
// sub-routes are publicly indexed pages (fetched 2026-09-11) — while the /all
|
|
1011
|
+
// tab is not, and Attentive's help centre refuses automated fetches. The dev
|
|
1012
|
+
// walk-through confirms this against a real account before promote.
|
|
1013
|
+
urls: {
|
|
1014
|
+
segment: () => "https://ui.attentivemobile.com/segments/all"
|
|
1015
|
+
}
|
|
799
1016
|
};
|
|
800
1017
|
|
|
801
1018
|
// lib/connections/providers/drawbridge.js
|
|
@@ -1915,7 +2132,7 @@ var drawbridge_default2 = {
|
|
|
1915
2132
|
content: {
|
|
1916
2133
|
confirm: "This connection is part of Drawbridge and cannot be disconnected.",
|
|
1917
2134
|
description: [
|
|
1918
|
-
"Drawbridge sends your notification
|
|
2135
|
+
"Drawbridge sends your notification emails and your entrants' emails, and recalculates segment membership on a schedule. It is always on and needs nothing connected."
|
|
1919
2136
|
],
|
|
1920
2137
|
excerpt: "The steps Drawbridge runs itself.",
|
|
1921
2138
|
guide: [
|
|
@@ -2228,6 +2445,11 @@ var drawbridge_default2 = {
|
|
|
2228
2445
|
promotions: false
|
|
2229
2446
|
},
|
|
2230
2447
|
segment: {
|
|
2448
|
+
// NOT DRAWBRIDGE'S. Registering a segment means creating an object at a
|
|
2449
|
+
// vendor, and this manifest has no vendor behind it — the three that do
|
|
2450
|
+
// implement these.
|
|
2451
|
+
register: false,
|
|
2452
|
+
remove: false,
|
|
2231
2453
|
// RECALCULATE SEGMENT MEMBERSHIP. The one FAN-OUT hook: it evaluates every
|
|
2232
2454
|
// contact in an organization against every segment, which is too much for
|
|
2233
2455
|
// one job, so it returns chunks and the shell defers completion.
|
|
@@ -2503,6 +2725,33 @@ var drawbridge_default2 = {
|
|
|
2503
2725
|
// caught exactly that: availableConnections({}) went from [ 'drawbridge' ] to
|
|
2504
2726
|
// empty the moment this was added.
|
|
2505
2727
|
requires: [],
|
|
2728
|
+
// PRIVATE, NOT VENDORLESS. SendGrid, Twilio and HubSpot are behind this
|
|
2729
|
+
// manifest, so `false` would be a lie about which reads were made.
|
|
2730
|
+
//
|
|
2731
|
+
// ONE ENTRY PER VENDOR, because three vendors are three reads. A single
|
|
2732
|
+
// citation here would evidence one of them and read as though it covered all
|
|
2733
|
+
// three, which is the omission this key exists to catch.
|
|
2734
|
+
review: {
|
|
2735
|
+
api: {
|
|
2736
|
+
// lib/hubspot.js posts to /crm/v3/objects/contacts.
|
|
2737
|
+
hubspot: "https://developers.hubspot.com/docs/reference/api/crm/objects/contacts",
|
|
2738
|
+
// lib/sendgrid.js posts to /v3/mail/send.
|
|
2739
|
+
sendgrid: "https://www.twilio.com/docs/sendgrid/api-reference/mail-send/mail-send",
|
|
2740
|
+
// lib/twilio.js posts to /2010-04-01/Accounts/{Sid}/Messages.json, and
|
|
2741
|
+
// hooks.inbound.verify reads the MessageStatus this resource documents.
|
|
2742
|
+
twilio: "https://www.twilio.com/docs/messaging/api/message-resource"
|
|
2743
|
+
},
|
|
2744
|
+
dashboard: {
|
|
2745
|
+
hubspot: "https://knowledge.hubspot.com/contacts/create-contacts",
|
|
2746
|
+
sendgrid: "https://www.twilio.com/docs/sendgrid/ui/analytics-and-reporting/email-activity-feed",
|
|
2747
|
+
twilio: "https://www.twilio.com/docs/messaging/guides/debugging-tools"
|
|
2748
|
+
},
|
|
2749
|
+
// An admin types these keys in; there is no merchant consent and no scope
|
|
2750
|
+
// model on any of the three.
|
|
2751
|
+
scopes: false,
|
|
2752
|
+
content: "2026-09-11",
|
|
2753
|
+
verified: null
|
|
2754
|
+
},
|
|
2506
2755
|
slug: "drawbridge",
|
|
2507
2756
|
// Always on. There is no credential that could go bad and no configuration a
|
|
2508
2757
|
// merchant could leave half-finished.
|
|
@@ -2694,6 +2943,8 @@ var api2 = async (path, { fetcher = fetch, method = "GET", payload, token }) =>
|
|
|
2694
2943
|
}
|
|
2695
2944
|
return response.status === 204 ? null : response.json();
|
|
2696
2945
|
};
|
|
2946
|
+
var segmentName = (title) => "Drawbridge: " + title;
|
|
2947
|
+
var canManageSegments = (settings) => String((settings == null ? void 0 : settings.scope) || "").split(/\s+/).includes("segments:write");
|
|
2697
2948
|
var klaviyo_default2 = {
|
|
2698
2949
|
// OAuth 2.1, and PKCE is REQUIRED rather than recommended: Klaviyo refuses an
|
|
2699
2950
|
// exchange without a code_verifier matching the challenge the consent
|
|
@@ -2723,9 +2974,21 @@ var klaviyo_default2 = {
|
|
|
2723
2974
|
// exchange, and a copy here would be a second answer that goes stale.
|
|
2724
2975
|
expiry: 90 * 24 * 60 * 60,
|
|
2725
2976
|
pkce: true,
|
|
2977
|
+
// EVERY SCOPE THE MANIFEST'S HOOKS NEED, not the ones today's hooks use.
|
|
2978
|
+
// Klaviyo holds scopes on the APP — "Pinpoint which scopes your app uses
|
|
2979
|
+
// and set them using a space-separated list"
|
|
2980
|
+
// (developers.klaviyo.com/en/docs/create_a_public_oauth_app, fetched
|
|
2981
|
+
// 2026-09-11) — and a merchant's token only ever carries what they
|
|
2982
|
+
// consented to, so a scope added later is a reconnect for every one of
|
|
2983
|
+
// them. That is what segments cost when they were left out here.
|
|
2984
|
+
//
|
|
2726
2985
|
// Space separated. accounts:read is required by Klaviyo on every app
|
|
2727
|
-
// and must stay in the list; the rest are what a contact sync
|
|
2728
|
-
|
|
2986
|
+
// and must stay in the list; the rest are what a contact sync and the
|
|
2987
|
+
// segment hooks need — Get Segments lists `segments:read`, Create,
|
|
2988
|
+
// Update and Delete Segment each list `segments:write`
|
|
2989
|
+
// (raw.githubusercontent.com/klaviyo/openapi/main/openapi/stable.json,
|
|
2990
|
+
// revision 2026-07-15, fetched 2026-09-11).
|
|
2991
|
+
scopes: "accounts:read lists:read lists:write profiles:read profiles:write segments:read segments:write",
|
|
2729
2992
|
// EVERY VENDOR URL, in one place. `revoke` used to be a literal inside
|
|
2730
2993
|
// the disconnect hook — three vendor addresses, two of them declared,
|
|
2731
2994
|
// which is exactly the kind of split that goes unnoticed.
|
|
@@ -2774,9 +3037,10 @@ var klaviyo_default2 = {
|
|
|
2774
3037
|
// Shown at disconnect, so it says what is lost and what is not.
|
|
2775
3038
|
confirm: "Disconnecting revokes Drawbridge's access to your Klaviyo account. Your profiles and lists stay in both Klaviyo and Drawbridge \u2014 neither is deleted.",
|
|
2776
3039
|
description: [
|
|
2777
|
-
"Connecting Klaviyo lets Drawbridge sync the contacts your campaigns collect into a Klaviyo list, so the people who enter a giveaway
|
|
3040
|
+
"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.",
|
|
2778
3041
|
"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.",
|
|
2779
|
-
"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."
|
|
3042
|
+
"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.",
|
|
3043
|
+
"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."
|
|
2780
3044
|
],
|
|
2781
3045
|
// KEYED BY WHAT FAILED, not nested inside it. Errors are the thing most
|
|
2782
3046
|
// likely to grow — resources.* has already earned somewhere to put "we
|
|
@@ -2933,6 +3197,7 @@ var klaviyo_default2 = {
|
|
|
2933
3197
|
if (!email) return { message: "That lead has no email address to sync.", skipped: true };
|
|
2934
3198
|
const person = (context == null ? void 0 : context.contact) || null;
|
|
2935
3199
|
const totals = (person == null ? void 0 : person.totals) || {};
|
|
3200
|
+
const count = (value) => typeof value === "number" ? value : (value == null ? void 0 : value.total) || 0;
|
|
2936
3201
|
const profile = await api2("/profile-import", {
|
|
2937
3202
|
fetcher,
|
|
2938
3203
|
method: "POST",
|
|
@@ -2946,13 +3211,13 @@ var klaviyo_default2 = {
|
|
|
2946
3211
|
drawbridge_campaigns: (person.campaigns || []).length,
|
|
2947
3212
|
drawbridge_draws: totals.draws || 0,
|
|
2948
3213
|
drawbridge_entries: totals.entries || 0,
|
|
2949
|
-
drawbridge_orders: totals.orders
|
|
3214
|
+
drawbridge_orders: count(totals.orders),
|
|
2950
3215
|
// Campaign-attributed, NOT lifetime. A merchant running
|
|
2951
3216
|
// Shopify already has lifetime revenue in Klaviyo through
|
|
2952
3217
|
// Klaviyo's own integration; what only we can say is how
|
|
2953
3218
|
// much a campaign drove. Named so the two cannot be
|
|
2954
3219
|
// mistaken for one another in a segment builder.
|
|
2955
|
-
drawbridge_revenue: totals.gross
|
|
3220
|
+
drawbridge_revenue: count(totals.gross)
|
|
2956
3221
|
},
|
|
2957
3222
|
// THE DRAWBRIDGE SEGMENTS THEY ARE IN, as a list property the
|
|
2958
3223
|
// merchant builds Klaviyo segments on top of. Klaviyo owns no
|
|
@@ -2971,7 +3236,14 @@ var klaviyo_default2 = {
|
|
|
2971
3236
|
// `segments` is null when the run carried no contact document,
|
|
2972
3237
|
// meaning nobody looked — different from [], which means they
|
|
2973
3238
|
// are in none. Null omits the key and merge leaves it alone.
|
|
2974
|
-
...segments && { drawbridge_segments: segments.map((entry) => entry.title).filter(Boolean) }
|
|
3239
|
+
...segments && { drawbridge_segments: segments.map((entry) => entry.title).filter(Boolean) },
|
|
3240
|
+
// THE IDS, which is what a Drawbridge-made segment's definition
|
|
3241
|
+
// filters on. Ids rather than titles, so renaming a segment is a
|
|
3242
|
+
// name change at Klaviyo and not a resync of every profile.
|
|
3243
|
+
//
|
|
3244
|
+
// The titles stay beside them: merchants have been building
|
|
3245
|
+
// their own segments on that array since it shipped.
|
|
3246
|
+
...segments && { drawbridge_segment_ids: segments.map((entry) => entry.id).filter(Boolean) }
|
|
2975
3247
|
}
|
|
2976
3248
|
},
|
|
2977
3249
|
type: "profile"
|
|
@@ -3015,17 +3287,141 @@ var klaviyo_default2 = {
|
|
|
3015
3287
|
};
|
|
3016
3288
|
}
|
|
3017
3289
|
},
|
|
3018
|
-
//
|
|
3019
|
-
//
|
|
3020
|
-
//
|
|
3021
|
-
//
|
|
3022
|
-
//
|
|
3023
|
-
// segments — see the private `drawbridge` manifest. A vendor answering
|
|
3024
|
-
// these would be a second sender, which is the arrangement the platform
|
|
3025
|
-
// sender replaced.
|
|
3290
|
+
// Drawbridge sends its own notification email. A vendor answering this
|
|
3291
|
+
// would be a second sender, which is the arrangement the platform sender
|
|
3292
|
+
// replaced. Declined as one line rather than one per verb, because the whole
|
|
3293
|
+
// domain is one decision — still explicit, since absence would not say
|
|
3294
|
+
// whether anybody considered it.
|
|
3026
3295
|
email: false,
|
|
3027
|
-
|
|
3296
|
+
// SEGMENTS ARE SHARED, not owned by one side. Drawbridge holds the
|
|
3297
|
+
// membership — see the private `drawbridge` manifest, and `sync : false`
|
|
3298
|
+
// below — while register and remove keep a Klaviyo segment standing for
|
|
3299
|
+
// each Drawbridge segment, so the merchant can target one in their own
|
|
3300
|
+
// flows.
|
|
3301
|
+
segment: {
|
|
3302
|
+
// THE KLAVIYO SEGMENT THIS DRAWBRIDGE SEGMENT BECOMES.
|
|
3303
|
+
//
|
|
3304
|
+
// Klaviyo owns no writable membership — its segments are computed from
|
|
3305
|
+
// rules — so the segment we create is DEFINED BY the profile property
|
|
3306
|
+
// contacts.sync writes. The definition filters on the Drawbridge
|
|
3307
|
+
// segment's ID, never its title, which is what makes a rename one PATCH
|
|
3308
|
+
// instead of a resync of every profile in it.
|
|
3309
|
+
register: async ({ connection: connection2, context, manifest, settings, token, workflow }, { fetcher, read } = {}) => {
|
|
3310
|
+
var _a, _b, _c, _d, _e;
|
|
3311
|
+
const segment = await currentSegment({ read, segment: context == null ? void 0 : context.segment });
|
|
3312
|
+
if (!(segment == null ? void 0 : segment.id) || segment.system) return { message: "That segment is not one this connection publishes.", skipped: true };
|
|
3313
|
+
if (!canManageSegments(settings)) {
|
|
3314
|
+
return {
|
|
3315
|
+
message: "Reconnect Klaviyo to let Drawbridge manage segments \u2014 this connection was made before that permission was asked for.",
|
|
3316
|
+
skipped: true
|
|
3317
|
+
};
|
|
3318
|
+
}
|
|
3319
|
+
const name = segmentName(segment.title);
|
|
3320
|
+
const existing = segmentRowFor({ connection: connection2, segment });
|
|
3321
|
+
let id = null;
|
|
3322
|
+
if (existing == null ? void 0 : existing.id) {
|
|
3323
|
+
try {
|
|
3324
|
+
const found = await api2("/segments/" + existing.id, { fetcher, token });
|
|
3325
|
+
id = ((_a = found == null ? void 0 : found.data) == null ? void 0 : _a.id) ?? existing.id;
|
|
3326
|
+
if (((_c = (_b = found == null ? void 0 : found.data) == null ? void 0 : _b.attributes) == null ? void 0 : _c.name) !== name) {
|
|
3327
|
+
await api2("/segments/" + existing.id, {
|
|
3328
|
+
fetcher,
|
|
3329
|
+
method: "PATCH",
|
|
3330
|
+
payload: { data: { attributes: { name }, id: existing.id, type: "segment" } },
|
|
3331
|
+
token
|
|
3332
|
+
});
|
|
3333
|
+
}
|
|
3334
|
+
} catch (error) {
|
|
3335
|
+
if (error.status !== 404) throw error;
|
|
3336
|
+
id = null;
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
if (!id) {
|
|
3340
|
+
const search = await api2("/segments?filter=" + encodeURIComponent('equals(name,"' + name.replace(/"/g, '\\"') + '")'), { fetcher, token });
|
|
3341
|
+
id = ((_d = ((search == null ? void 0 : search.data) || []).find((entry) => {
|
|
3342
|
+
var _a2;
|
|
3343
|
+
return ((_a2 = entry == null ? void 0 : entry.attributes) == null ? void 0 : _a2.name) === name;
|
|
3344
|
+
})) == null ? void 0 : _d.id) ?? null;
|
|
3345
|
+
}
|
|
3346
|
+
if (!id) {
|
|
3347
|
+
const created = await api2("/segments", {
|
|
3348
|
+
fetcher,
|
|
3349
|
+
method: "POST",
|
|
3350
|
+
// THE DEFINITION IS THE MEMBERSHIP. Create Segment requires one
|
|
3351
|
+
// — `name` and `definition` are both required on its attributes
|
|
3352
|
+
// — and a custom profile property is addressed as
|
|
3353
|
+
// "properties['property name']", tested with a list filter whose
|
|
3354
|
+
// operator is `contains`
|
|
3355
|
+
// (raw.githubusercontent.com/klaviyo/openapi/main/openapi/stable.json,
|
|
3356
|
+
// revision 2026-07-15, fetched 2026-09-11).
|
|
3357
|
+
payload: {
|
|
3358
|
+
data: {
|
|
3359
|
+
attributes: {
|
|
3360
|
+
definition: {
|
|
3361
|
+
condition_groups: [{
|
|
3362
|
+
conditions: [{
|
|
3363
|
+
filter: { operator: "contains", type: "list", value: segment.id },
|
|
3364
|
+
property: "properties['drawbridge_segment_ids']",
|
|
3365
|
+
type: "profile-property"
|
|
3366
|
+
}]
|
|
3367
|
+
}]
|
|
3368
|
+
},
|
|
3369
|
+
name
|
|
3370
|
+
},
|
|
3371
|
+
type: "segment"
|
|
3372
|
+
}
|
|
3373
|
+
},
|
|
3374
|
+
token
|
|
3375
|
+
});
|
|
3376
|
+
id = (_e = created == null ? void 0 : created.data) == null ? void 0 : _e.id;
|
|
3377
|
+
}
|
|
3378
|
+
if (!id) return { message: "Klaviyo returned no segment id.", skipped: true };
|
|
3379
|
+
return {
|
|
3380
|
+
// A RENAME THAT ARRIVED WHILE THIS RAN was dropped by the
|
|
3381
|
+
// coalescing job id, so the last thing this does is look again.
|
|
3382
|
+
enqueues: await driftEnqueues({ applied: segment.title, read, segment, workflow }),
|
|
3383
|
+
events: [{
|
|
3384
|
+
event: "organization.segments",
|
|
3385
|
+
payload: { id: segment.id },
|
|
3386
|
+
room: "organization." + (connection2 == null ? void 0 : connection2.organization)
|
|
3387
|
+
}],
|
|
3388
|
+
message: 'Klaviyo is carrying this segment as "' + name + '".',
|
|
3389
|
+
writes: segmentRowWrites({
|
|
3390
|
+
connection: connection2,
|
|
3391
|
+
data: { ...connection2, settings },
|
|
3392
|
+
manifest,
|
|
3393
|
+
row: { id, type: "segment" },
|
|
3394
|
+
segment
|
|
3395
|
+
})
|
|
3396
|
+
};
|
|
3397
|
+
},
|
|
3398
|
+
// NO RE-READ. The segment is already deleted; the pre-image is the only
|
|
3399
|
+
// copy, and it carries the row naming what to delete.
|
|
3400
|
+
remove: async ({ connection: connection2, context, settings, token }, { fetcher } = {}) => {
|
|
3401
|
+
const segment = context == null ? void 0 : context.segment;
|
|
3402
|
+
const existing = segmentRowFor({ connection: connection2, segment });
|
|
3403
|
+
if (!(existing == null ? void 0 : existing.id)) return { message: "Klaviyo was never carrying this segment.", skipped: true };
|
|
3404
|
+
if (!canManageSegments(settings)) {
|
|
3405
|
+
return { message: "Reconnect Klaviyo to let Drawbridge manage segments.", skipped: true };
|
|
3406
|
+
}
|
|
3407
|
+
try {
|
|
3408
|
+
await api2("/segments/" + existing.id, { fetcher, method: "DELETE", token });
|
|
3409
|
+
} catch (error) {
|
|
3410
|
+
if (error.status !== 404) throw error;
|
|
3411
|
+
}
|
|
3412
|
+
return {
|
|
3413
|
+
message: "Klaviyo is no longer carrying this segment.",
|
|
3414
|
+
writes: segmentRowRemoveWrites({ connection: connection2, segment })
|
|
3415
|
+
};
|
|
3416
|
+
},
|
|
3417
|
+
// Drawbridge-side membership belongs to the private manifest.
|
|
3418
|
+
sync: false
|
|
3419
|
+
},
|
|
3420
|
+
// Declined for the same reason as `email` above: Drawbridge sends its own
|
|
3421
|
+
// notification SMS, and a vendor answering this would be a second sender.
|
|
3028
3422
|
sms: false,
|
|
3423
|
+
// Klaviyo sends us nothing — no inbound message to receive, no signature
|
|
3424
|
+
// to verify.
|
|
3029
3425
|
inbound: false,
|
|
3030
3426
|
// Nothing to set up or tear down at the vendor: the grant is the whole
|
|
3031
3427
|
// integration. What CAN rot is the grant itself, so health is the one
|
|
@@ -3146,6 +3542,18 @@ var klaviyo_default2 = {
|
|
|
3146
3542
|
"KLAVIYO_OAUTH_CLIENT_ID",
|
|
3147
3543
|
"KLAVIYO_OAUTH_CLIENT_SECRET"
|
|
3148
3544
|
],
|
|
3545
|
+
// THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
|
|
3546
|
+
review: {
|
|
3547
|
+
api: "https://developers.klaviyo.com/en/reference/api_overview",
|
|
3548
|
+
dashboard: "https://help.klaviyo.com/hc/en-us/articles/115005078647",
|
|
3549
|
+
// THE SCOPE TABLE, not the OAuth walk-through. set_up_oauth carries one
|
|
3550
|
+
// example scope string and nothing to check a manifest against; this page
|
|
3551
|
+
// lists the scopes each API takes, segments:read and segments:write among
|
|
3552
|
+
// them (fetched 2026-09-11).
|
|
3553
|
+
scopes: "https://developers.klaviyo.com/en/docs/authenticate_",
|
|
3554
|
+
content: "2026-09-11",
|
|
3555
|
+
verified: null
|
|
3556
|
+
},
|
|
3149
3557
|
slug: "klaviyo",
|
|
3150
3558
|
// ONE OF THE FOUR STATES AND NOTHING ELSE — the reason sits in `tasks`, which
|
|
3151
3559
|
// is already the merchant-facing copy channel and is already rendered.
|
|
@@ -3176,7 +3584,8 @@ var klaviyo_default2 = {
|
|
|
3176
3584
|
hook: "lifecycle.health",
|
|
3177
3585
|
key: "Klaviyo Connection Health",
|
|
3178
3586
|
queue: "connection",
|
|
3179
|
-
system: true
|
|
3587
|
+
system: true,
|
|
3588
|
+
trigger: { event: "day", type: "schedule" }
|
|
3180
3589
|
})
|
|
3181
3590
|
}
|
|
3182
3591
|
},
|
|
@@ -3220,6 +3629,28 @@ var klaviyo_default2 = {
|
|
|
3220
3629
|
usage: { actions: 1 }
|
|
3221
3630
|
};
|
|
3222
3631
|
}
|
|
3632
|
+
},
|
|
3633
|
+
segment: {
|
|
3634
|
+
// SYSTEM, so the builder never offers it and a merchant POST refuses it:
|
|
3635
|
+
// these fire from the segment's own lifecycle, not from a workflow
|
|
3636
|
+
// somebody assembled. The trigger is declared here rather than hard-coded
|
|
3637
|
+
// in drawbridge-sync.
|
|
3638
|
+
register: () => ({
|
|
3639
|
+
description: "Keeps a matching Klaviyo segment for each Drawbridge segment, built on the segment ids Drawbridge writes onto your profiles.",
|
|
3640
|
+
hook: "segment.register",
|
|
3641
|
+
key: "Klaviyo Segment Register",
|
|
3642
|
+
queue: "connection",
|
|
3643
|
+
system: true,
|
|
3644
|
+
trigger: { event: "segment.register", type: "event" }
|
|
3645
|
+
}),
|
|
3646
|
+
remove: () => ({
|
|
3647
|
+
description: "Deletes the Klaviyo segment for a Drawbridge segment when the segment is deleted.",
|
|
3648
|
+
hook: "segment.remove",
|
|
3649
|
+
key: "Klaviyo Segment Remove",
|
|
3650
|
+
queue: "connection",
|
|
3651
|
+
system: true,
|
|
3652
|
+
trigger: { event: "segment.remove", type: "event" }
|
|
3653
|
+
})
|
|
3223
3654
|
}
|
|
3224
3655
|
},
|
|
3225
3656
|
// WHY, in the merchant's words, and what to do about it.
|
|
@@ -3229,14 +3660,32 @@ var klaviyo_default2 = {
|
|
|
3229
3660
|
// moment: the grant is good and the list is the missing half.
|
|
3230
3661
|
tasks: (data2) => {
|
|
3231
3662
|
var _a;
|
|
3232
|
-
|
|
3233
|
-
|
|
3663
|
+
if (!["active", "pending"].includes(data2 == null ? void 0 : data2.status)) return [];
|
|
3664
|
+
return [
|
|
3665
|
+
// A connection made before segments were requested is authenticated and
|
|
3666
|
+
// cannot manage them, and no error surfaces anywhere else — the register
|
|
3667
|
+
// runs skip rather than fail.
|
|
3668
|
+
...canManageSegments(data2 == null ? void 0 : data2.settings) ? [] : [{
|
|
3669
|
+
message: "Drawbridge now keeps a Klaviyo segment in step with each of your Drawbridge segments. Reconnect Klaviyo to allow it.",
|
|
3670
|
+
title: "Reconnect Klaviyo"
|
|
3671
|
+
}],
|
|
3672
|
+
...((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.list) ? [] : [{
|
|
3234
3673
|
message: "Choose which Klaviyo list your contacts should sync into. Until you do, nothing is being synced.",
|
|
3235
3674
|
title: "Choose a list"
|
|
3236
|
-
}
|
|
3675
|
+
}]
|
|
3237
3676
|
];
|
|
3238
3677
|
},
|
|
3239
|
-
title: "Klaviyo"
|
|
3678
|
+
title: "Klaviyo",
|
|
3679
|
+
// KLAVIYO PUBLISHES NO DASHBOARD URLS in its API reference. What is on record
|
|
3680
|
+
// is its own help centre on a list: "you can find a list's ID in the URL in
|
|
3681
|
+
// your browser when viewing this list"
|
|
3682
|
+
// (help.klaviyo.com/hc/en-us/articles/115005078647, fetched 2026-09-11), and a
|
|
3683
|
+
// segment's page is the sibling form of it. The path itself is NOT published
|
|
3684
|
+
// anywhere citable, so the dev walk-through confirms this against a real
|
|
3685
|
+
// account before promote.
|
|
3686
|
+
urls: {
|
|
3687
|
+
segment: (row2) => (row2 == null ? void 0 : row2.id) ? "https://www.klaviyo.com/segment/" + row2.id : null
|
|
3688
|
+
}
|
|
3240
3689
|
};
|
|
3241
3690
|
|
|
3242
3691
|
// lib/connections/providers/mailchimp.js
|
|
@@ -3273,6 +3722,8 @@ var api3 = async (path, { dc, fetcher = fetch, method = "GET", payload, token })
|
|
|
3273
3722
|
return response.status === 204 ? null : response.json();
|
|
3274
3723
|
};
|
|
3275
3724
|
var subscriberHash = (email) => createHash2("md5").update(String(email).trim().toLowerCase()).digest("hex");
|
|
3725
|
+
var TAG_NAME_LIMIT = 100;
|
|
3726
|
+
var tagName = (title) => ("Drawbridge: " + title).slice(0, TAG_NAME_LIMIT);
|
|
3276
3727
|
var mailchimp_default2 = {
|
|
3277
3728
|
// OAUTH 2, authorization code. Every url below is quoted from
|
|
3278
3729
|
// mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/ rather
|
|
@@ -3315,7 +3766,7 @@ var mailchimp_default2 = {
|
|
|
3315
3766
|
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.",
|
|
3316
3767
|
description: [
|
|
3317
3768
|
"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.",
|
|
3318
|
-
"Connecting Mailchimp lets Drawbridge sync the contacts your campaigns collect into a Mailchimp audience, so the people who enter a giveaway
|
|
3769
|
+
"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.",
|
|
3319
3770
|
"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.",
|
|
3320
3771
|
"Someone who unsubscribed inside Mailchimp keeps that choice: a resync only sets the status of a subscriber Mailchimp has never seen before."
|
|
3321
3772
|
],
|
|
@@ -3328,6 +3779,7 @@ var mailchimp_default2 = {
|
|
|
3328
3779
|
"Sign in to Mailchimp if you are not already, and choose the account to connect.",
|
|
3329
3780
|
"You come back here to pick the audience your contacts should sync into.",
|
|
3330
3781
|
"The connection shows Pending until you pick an audience, then Active.",
|
|
3782
|
+
'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.',
|
|
3331
3783
|
"You can remove Drawbridge at any time from the Authorized Apps page in your Mailchimp account."
|
|
3332
3784
|
]
|
|
3333
3785
|
},
|
|
@@ -3353,10 +3805,9 @@ var mailchimp_default2 = {
|
|
|
3353
3805
|
}
|
|
3354
3806
|
],
|
|
3355
3807
|
group: "contacts",
|
|
3356
|
-
//
|
|
3357
|
-
//
|
|
3358
|
-
//
|
|
3359
|
-
// contacts.sync are the first to flip.
|
|
3808
|
+
// WHAT THIS VENDOR DOES AND DOES NOT DO is the value of each hook below, not
|
|
3809
|
+
// a paragraph up here that goes stale the moment one of them is implemented
|
|
3810
|
+
// — which is exactly what happened to the note this replaces.
|
|
3360
3811
|
hooks: {
|
|
3361
3812
|
auth: {
|
|
3362
3813
|
// WHERE THE ACCOUNT LIVES. Not enrichment — without this the connection
|
|
@@ -3410,26 +3861,32 @@ var mailchimp_default2 = {
|
|
|
3410
3861
|
// why there is no create-or-update branch here. Quoted from Mailchimp's
|
|
3411
3862
|
// Marketing API reference for the list-members resource.
|
|
3412
3863
|
sync: async ({ connection: connection2, lead, segments, settings, suppressed, token }, { fetcher, read } = {}) => {
|
|
3413
|
-
var _a, _b;
|
|
3864
|
+
var _a, _b, _c;
|
|
3414
3865
|
const audience = settings == null ? void 0 : settings.audience;
|
|
3415
3866
|
if (!audience) return { message: "No Mailchimp audience is chosen for this connection.", skipped: true };
|
|
3416
3867
|
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);
|
|
3417
3868
|
if (!email) return { message: "That lead has no email address to sync.", skipped: true };
|
|
3418
3869
|
const hash = subscriberHash(email);
|
|
3870
|
+
const [firstName, ...restOfName] = String((lead == null ? void 0 : lead.name) || "").trim().split(/\s+/).filter(Boolean);
|
|
3871
|
+
const lastName = restOfName.join(" ");
|
|
3872
|
+
const phone = ((_c = lead == null ? void 0 : lead.phone) == null ? void 0 : _c.number) || null;
|
|
3873
|
+
const mergeFields = {
|
|
3874
|
+
...firstName && { FNAME: firstName },
|
|
3875
|
+
...lastName && { LNAME: lastName },
|
|
3876
|
+
...phone && { PHONE: phone }
|
|
3877
|
+
};
|
|
3419
3878
|
const member = await api3("/lists/" + audience + "/members/" + hash, {
|
|
3420
3879
|
dc: settings == null ? void 0 : settings.dc,
|
|
3421
3880
|
fetcher,
|
|
3422
3881
|
method: "PUT",
|
|
3423
3882
|
payload: {
|
|
3424
3883
|
email_address: email,
|
|
3425
|
-
//
|
|
3426
|
-
//
|
|
3427
|
-
//
|
|
3428
|
-
//
|
|
3429
|
-
//
|
|
3430
|
-
|
|
3431
|
-
// job and is not built.
|
|
3432
|
-
...(lead == null ? void 0 : lead.name) && { merge_fields: { FNAME: String(lead.name).trim().split(/\s+/)[0] } },
|
|
3884
|
+
// Built above. Omitted entirely when there is nothing to say, so a
|
|
3885
|
+
// lead with only an address does not send an empty object. The
|
|
3886
|
+
// Drawbridge totals Klaviyo receives still cannot travel this way —
|
|
3887
|
+
// those are custom tags, and registering them on the chosen audience
|
|
3888
|
+
// is lifecycle.register's job and is not built.
|
|
3889
|
+
...Object.keys(mergeFields).length > 0 && { merge_fields: mergeFields },
|
|
3433
3890
|
...suppressed && { status: "unsubscribed" },
|
|
3434
3891
|
status_if_new: suppressed ? "unsubscribed" : "subscribed"
|
|
3435
3892
|
},
|
|
@@ -3452,7 +3909,7 @@ var mailchimp_default2 = {
|
|
|
3452
3909
|
});
|
|
3453
3910
|
const joined = new Set(segments.map((entry) => entry.title));
|
|
3454
3911
|
const tags = (owned || []).map((entry) => entry.title).filter(Boolean).map((title) => ({
|
|
3455
|
-
name:
|
|
3912
|
+
name: tagName(title),
|
|
3456
3913
|
status: joined.has(title) ? "active" : "inactive"
|
|
3457
3914
|
}));
|
|
3458
3915
|
if (tags.length > 0) {
|
|
@@ -3475,12 +3932,122 @@ var mailchimp_default2 = {
|
|
|
3475
3932
|
};
|
|
3476
3933
|
}
|
|
3477
3934
|
},
|
|
3478
|
-
// Drawbridge sends its own notification email
|
|
3479
|
-
//
|
|
3480
|
-
//
|
|
3481
|
-
// sender replaced.
|
|
3935
|
+
// Drawbridge sends its own notification email. A vendor answering this
|
|
3936
|
+
// would be a second sender, which is the arrangement the platform sender
|
|
3937
|
+
// replaced.
|
|
3482
3938
|
email: false,
|
|
3483
|
-
|
|
3939
|
+
// SEGMENTS ARE SHARED, not owned by one side. Drawbridge holds the
|
|
3940
|
+
// membership — see the private `drawbridge` manifest, and `sync : false`
|
|
3941
|
+
// below — while register and remove keep a Mailchimp tag standing for each
|
|
3942
|
+
// Drawbridge segment, so the merchant can target one in their own audience.
|
|
3943
|
+
segment: {
|
|
3944
|
+
// THE TAG THIS SEGMENT IS, held by id at last.
|
|
3945
|
+
//
|
|
3946
|
+
// Tags ARE static segments in Mailchimp's model — same collection, same
|
|
3947
|
+
// ids — so this creates one through /segments and the member write goes
|
|
3948
|
+
// on attaching people to it by name. Both address the same object. The
|
|
3949
|
+
// segment schema says it outright: "The type of segment. Static segments
|
|
3950
|
+
// are now known as tags"
|
|
3951
|
+
// (api.mailchimp.com/schema/3.0/Definitions/Lists/Segments/Response.json,
|
|
3952
|
+
// fetched 2026-09-12 — the root Swagger.json carries no prose, only $refs
|
|
3953
|
+
// into fragment files like this one).
|
|
3954
|
+
//
|
|
3955
|
+
// IDEMPOTENT ON EVERY PATH: called on create, on rename, on a connection
|
|
3956
|
+
// finishing its configuration, and on the backfill migration, it converges. That is what lets one hook serve
|
|
3957
|
+
// all four without a create-vs-update branch anywhere else.
|
|
3958
|
+
register: async ({ connection: connection2, context, manifest, settings, token, workflow }, { fetcher, read } = {}) => {
|
|
3959
|
+
var _a;
|
|
3960
|
+
const audience = settings == null ? void 0 : settings.audience;
|
|
3961
|
+
if (!audience) return { message: "No Mailchimp audience is chosen for this connection.", skipped: true };
|
|
3962
|
+
const segment = await currentSegment({ read, segment: context == null ? void 0 : context.segment });
|
|
3963
|
+
if (!(segment == null ? void 0 : segment.id) || segment.system) return { message: "That segment is not one this connection publishes.", skipped: true };
|
|
3964
|
+
const name = tagName(segment.title);
|
|
3965
|
+
const existing = segmentRowFor({ connection: connection2, segment });
|
|
3966
|
+
let id = null;
|
|
3967
|
+
if (existing == null ? void 0 : existing.id) {
|
|
3968
|
+
try {
|
|
3969
|
+
const found = await api3("/lists/" + audience + "/segments/" + existing.id, { dc: settings == null ? void 0 : settings.dc, fetcher, token });
|
|
3970
|
+
id = (found == null ? void 0 : found.id) ?? existing.id;
|
|
3971
|
+
if ((found == null ? void 0 : found.name) !== name) {
|
|
3972
|
+
await api3("/lists/" + audience + "/segments/" + existing.id, {
|
|
3973
|
+
dc: settings == null ? void 0 : settings.dc,
|
|
3974
|
+
fetcher,
|
|
3975
|
+
method: "PATCH",
|
|
3976
|
+
payload: { name },
|
|
3977
|
+
token
|
|
3978
|
+
});
|
|
3979
|
+
}
|
|
3980
|
+
} catch (error) {
|
|
3981
|
+
if (error.status !== 404) throw error;
|
|
3982
|
+
id = null;
|
|
3983
|
+
}
|
|
3984
|
+
}
|
|
3985
|
+
if (!id) {
|
|
3986
|
+
const search = await api3("/lists/" + audience + "/tag-search?name=" + encodeURIComponent(name), { dc: settings == null ? void 0 : settings.dc, fetcher, token });
|
|
3987
|
+
id = ((_a = ((search == null ? void 0 : search.tags) || []).find((tag) => (tag == null ? void 0 : tag.name) === name)) == null ? void 0 : _a.id) ?? null;
|
|
3988
|
+
}
|
|
3989
|
+
if (!id) {
|
|
3990
|
+
const created = await api3("/lists/" + audience + "/segments", {
|
|
3991
|
+
dc: settings == null ? void 0 : settings.dc,
|
|
3992
|
+
fetcher,
|
|
3993
|
+
method: "POST",
|
|
3994
|
+
// STATIC WITH NO MEMBERS. The member sync attaches people by
|
|
3995
|
+
// name; this call only has to make the object exist. Mailchimp's
|
|
3996
|
+
// own wording for the empty array: "Passing an empty array will
|
|
3997
|
+
// create a static segment without any subscribers."
|
|
3998
|
+
payload: { name, static_segment: [] },
|
|
3999
|
+
token
|
|
4000
|
+
});
|
|
4001
|
+
id = created == null ? void 0 : created.id;
|
|
4002
|
+
}
|
|
4003
|
+
if (!id) return { message: "Mailchimp returned no tag id.", skipped: true };
|
|
4004
|
+
const audienceDetail = await api3("/lists/" + audience + "?fields=web_id", { dc: settings == null ? void 0 : settings.dc, fetcher, token });
|
|
4005
|
+
return {
|
|
4006
|
+
// A RENAME THAT ARRIVED WHILE THIS RAN was dropped by the
|
|
4007
|
+
// coalescing job id, so the last thing this does is look again.
|
|
4008
|
+
enqueues: await driftEnqueues({ applied: segment.title, read, segment, workflow }),
|
|
4009
|
+
events: [{
|
|
4010
|
+
event: "organization.segments",
|
|
4011
|
+
payload: { id: segment.id },
|
|
4012
|
+
room: "organization." + (connection2 == null ? void 0 : connection2.organization)
|
|
4013
|
+
}],
|
|
4014
|
+
message: 'Mailchimp is carrying this segment as the tag "' + name + '".',
|
|
4015
|
+
writes: segmentRowWrites({
|
|
4016
|
+
connection: connection2,
|
|
4017
|
+
data: { ...connection2, settings },
|
|
4018
|
+
manifest,
|
|
4019
|
+
row: { id, type: "tag", webId: audienceDetail == null ? void 0 : audienceDetail.web_id },
|
|
4020
|
+
segment
|
|
4021
|
+
})
|
|
4022
|
+
};
|
|
4023
|
+
},
|
|
4024
|
+
// THE TAG GOES WITH THE SEGMENT. Leaving it behind is the orphan this
|
|
4025
|
+
// whole pair exists to stop — every member would keep a label for a
|
|
4026
|
+
// segment that no longer exists.
|
|
4027
|
+
remove: async ({ connection: connection2, context, settings, token }, { fetcher } = {}) => {
|
|
4028
|
+
const segment = context == null ? void 0 : context.segment;
|
|
4029
|
+
const existing = segmentRowFor({ connection: connection2, segment });
|
|
4030
|
+
if (!(existing == null ? void 0 : existing.id)) return { message: "Mailchimp was never carrying this segment.", skipped: true };
|
|
4031
|
+
try {
|
|
4032
|
+
await api3("/lists/" + (settings == null ? void 0 : settings.audience) + "/segments/" + existing.id, {
|
|
4033
|
+
dc: settings == null ? void 0 : settings.dc,
|
|
4034
|
+
fetcher,
|
|
4035
|
+
method: "DELETE",
|
|
4036
|
+
token
|
|
4037
|
+
});
|
|
4038
|
+
} catch (error) {
|
|
4039
|
+
if (error.status !== 404) throw error;
|
|
4040
|
+
}
|
|
4041
|
+
return {
|
|
4042
|
+
message: "Mailchimp is no longer carrying this segment.",
|
|
4043
|
+
writes: segmentRowRemoveWrites({ connection: connection2, segment })
|
|
4044
|
+
};
|
|
4045
|
+
},
|
|
4046
|
+
// Drawbridge-side membership belongs to the private manifest.
|
|
4047
|
+
sync: false
|
|
4048
|
+
},
|
|
4049
|
+
// Declined for the same reason as `email` above: Drawbridge sends its own
|
|
4050
|
+
// notification SMS, and a vendor answering this would be a second sender.
|
|
3484
4051
|
sms: false,
|
|
3485
4052
|
inbound: false,
|
|
3486
4053
|
lifecycle: false,
|
|
@@ -3543,6 +4110,16 @@ var mailchimp_default2 = {
|
|
|
3543
4110
|
"MAILCHIMP_OAUTH_CLIENT_ID",
|
|
3544
4111
|
"MAILCHIMP_OAUTH_CLIENT_SECRET"
|
|
3545
4112
|
],
|
|
4113
|
+
// THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
|
|
4114
|
+
review: {
|
|
4115
|
+
api: "https://mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/",
|
|
4116
|
+
dashboard: "https://mailchimp.com/help/manage-tags/",
|
|
4117
|
+
// NO SCOPES EXIST. Mailchimp's OAuth guide describes none, and a token is
|
|
4118
|
+
// account-wide — so there is nothing to request and nothing to re-consent.
|
|
4119
|
+
scopes: false,
|
|
4120
|
+
content: "2026-09-11",
|
|
4121
|
+
verified: null
|
|
4122
|
+
},
|
|
3546
4123
|
slug: "mailchimp",
|
|
3547
4124
|
// A grant with no audience chosen is authenticated and useless — the sync has
|
|
3548
4125
|
// nowhere to put anyone — so the card must say Pending rather than Active over
|
|
@@ -3588,6 +4165,30 @@ var mailchimp_default2 = {
|
|
|
3588
4165
|
// adds this step, and what is charged when it runs.
|
|
3589
4166
|
usage: { actions: 1 }
|
|
3590
4167
|
})
|
|
4168
|
+
},
|
|
4169
|
+
segment: {
|
|
4170
|
+
// SYSTEM, so the builder never offers it and a merchant POST refuses it:
|
|
4171
|
+
// these fire from the segment's own lifecycle, not from a workflow
|
|
4172
|
+
// somebody assembled.
|
|
4173
|
+
//
|
|
4174
|
+
// The trigger is declared HERE rather than hard-coded in drawbridge-sync,
|
|
4175
|
+
// which is what lets a vendor arrive with its own without a queue edit.
|
|
4176
|
+
register: () => ({
|
|
4177
|
+
description: "Keeps a matching tag in your Mailchimp audience for each Drawbridge segment, and renames it when the segment is renamed.",
|
|
4178
|
+
hook: "segment.register",
|
|
4179
|
+
key: "Mailchimp Segment Register",
|
|
4180
|
+
queue: "connection",
|
|
4181
|
+
system: true,
|
|
4182
|
+
trigger: { event: "segment.register", type: "event" }
|
|
4183
|
+
}),
|
|
4184
|
+
remove: () => ({
|
|
4185
|
+
description: "Deletes the Mailchimp tag for a Drawbridge segment when the segment is deleted.",
|
|
4186
|
+
hook: "segment.remove",
|
|
4187
|
+
key: "Mailchimp Segment Remove",
|
|
4188
|
+
queue: "connection",
|
|
4189
|
+
system: true,
|
|
4190
|
+
trigger: { event: "segment.remove", type: "event" }
|
|
4191
|
+
})
|
|
3591
4192
|
}
|
|
3592
4193
|
},
|
|
3593
4194
|
// WHY, in the merchant's words, and what to do about it.
|
|
@@ -3604,11 +4205,27 @@ var mailchimp_default2 = {
|
|
|
3604
4205
|
}
|
|
3605
4206
|
];
|
|
3606
4207
|
},
|
|
3607
|
-
title: "Mailchimp"
|
|
4208
|
+
title: "Mailchimp",
|
|
4209
|
+
// THE MERCHANT'S OWN ADMIN. Mailchimp's list schema states the shape outright:
|
|
4210
|
+
// the web_id field is "The ID used in the Mailchimp web application. View this
|
|
4211
|
+
// list in your Mailchimp account at
|
|
4212
|
+
// https://{dc}.admin.mailchimp.com/lists/members/?id={web_id}"
|
|
4213
|
+
// (api.mailchimp.com/schema/3.0/Definitions/Lists/Response.json, fetched
|
|
4214
|
+
// 2026-09-11).
|
|
4215
|
+
//
|
|
4216
|
+
// It lands on the audience's contacts, where the Drawbridge tag is one filter
|
|
4217
|
+
// away. Mailchimp documents no url that pre-selects a tag, so this stops one
|
|
4218
|
+
// click short rather than guessing at one that could break silently.
|
|
4219
|
+
urls: {
|
|
4220
|
+
segment: (row2, data2) => {
|
|
4221
|
+
var _a;
|
|
4222
|
+
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;
|
|
4223
|
+
}
|
|
4224
|
+
}
|
|
3608
4225
|
};
|
|
3609
4226
|
|
|
3610
4227
|
// lib/connections/providers/shopify.js
|
|
3611
|
-
import { randomUUID } from "crypto";
|
|
4228
|
+
import { randomUUID as randomUUID2 } from "crypto";
|
|
3612
4229
|
import { customAlphabet as customAlphabet2 } from "nanoid";
|
|
3613
4230
|
|
|
3614
4231
|
// lib/connections/icons/shopify.js
|
|
@@ -3724,6 +4341,28 @@ var attributeLineItems = (lineItems = []) => lineItems.reduce(
|
|
|
3724
4341
|
{ attrMap: {}, attributedGross: 0, attributedLines: [] }
|
|
3725
4342
|
);
|
|
3726
4343
|
var generateDiscountCode = customAlphabet2("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 8);
|
|
4344
|
+
var blockedReason = (discount) => {
|
|
4345
|
+
var _a;
|
|
4346
|
+
if ((discount == null ? void 0 : discount.status) === "EXPIRED") return "This discount has expired.";
|
|
4347
|
+
const buyers = (_a = discount == null ? void 0 : discount.context) == null ? void 0 : _a.__typename;
|
|
4348
|
+
if (buyers && buyers !== "DiscountBuyerSelectionAll") {
|
|
4349
|
+
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.";
|
|
4350
|
+
}
|
|
4351
|
+
;
|
|
4352
|
+
if (typeof (discount == null ? void 0 : discount.usageLimit) === "number" && discount.usageLimit > 0 && ((discount == null ? void 0 : discount.asyncUsageCount) || 0) >= discount.usageLimit) {
|
|
4353
|
+
return "This discount has reached its total usage limit.";
|
|
4354
|
+
}
|
|
4355
|
+
;
|
|
4356
|
+
return null;
|
|
4357
|
+
};
|
|
4358
|
+
var discountWarning = (discount) => {
|
|
4359
|
+
if ((discount == null ? void 0 : discount.status) === "SCHEDULED") {
|
|
4360
|
+
return "This discount hasn't started yet, so codes issued before it does won't work until then.";
|
|
4361
|
+
}
|
|
4362
|
+
;
|
|
4363
|
+
if (discount == null ? void 0 : discount.appliesOncePerCustomer) return "Each customer can use this discount only once.";
|
|
4364
|
+
return null;
|
|
4365
|
+
};
|
|
3727
4366
|
var ORDER_EVENT_HANDLE = slugify("drawbridge-orders");
|
|
3728
4367
|
var REFRESH_TOKEN_FRESHNESS_BUFFER_MS = 5 * 24 * 60 * 60 * 1e3;
|
|
3729
4368
|
var OAUTH_ERROR_SOURCE = "oauth";
|
|
@@ -3771,7 +4410,7 @@ var shopify_default2 = {
|
|
|
3771
4410
|
description: [
|
|
3772
4411
|
"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.",
|
|
3773
4412
|
"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.",
|
|
3774
|
-
"
|
|
4413
|
+
"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."
|
|
3775
4414
|
],
|
|
3776
4415
|
errors: {
|
|
3777
4416
|
connect: {
|
|
@@ -3785,7 +4424,7 @@ var shopify_default2 = {
|
|
|
3785
4424
|
"Open the Drawbridge listing on the Shopify App Store.",
|
|
3786
4425
|
"Install the app on the store you want to connect. It opens in Shopify admin and stays there.",
|
|
3787
4426
|
"Approve the Drawbridge plan when prompted \u2014 during install, or from the connection page here. The connection shows Pending until you do, then Active.",
|
|
3788
|
-
"Come back here \u2014 the connections list updates on its own once the install
|
|
4427
|
+
"Come back here \u2014 the connections list updates on its own once the install finishes."
|
|
3789
4428
|
],
|
|
3790
4429
|
// Names where the link GOES rather than what it does: installing happens on
|
|
3791
4430
|
// the App Store listing, and the dashboard must never imply a store can be
|
|
@@ -4161,9 +4800,11 @@ var shopify_default2 = {
|
|
|
4161
4800
|
phone: customerPhone
|
|
4162
4801
|
} : null;
|
|
4163
4802
|
const source = (connection2 == null ? void 0 : connection2.source) ? { domain: connection2.source.domain, id: connection2.source.id } : void 0;
|
|
4164
|
-
const
|
|
4803
|
+
const createsOrder = !backfill && (isConversion || Boolean(discount));
|
|
4804
|
+
const orderDocId = (existingOrder == null ? void 0 : existingOrder.id) || (createsOrder ? mintId() : null);
|
|
4805
|
+
const redemptionDocId = discount ? mintId() : null;
|
|
4165
4806
|
const writes = [];
|
|
4166
|
-
if (
|
|
4807
|
+
if (createsOrder) {
|
|
4167
4808
|
writes.push({
|
|
4168
4809
|
collection: "order",
|
|
4169
4810
|
data: {
|
|
@@ -4184,15 +4825,25 @@ var shopify_default2 = {
|
|
|
4184
4825
|
provider: { id: String(orderId), slug: "shopify" },
|
|
4185
4826
|
purchasedAt,
|
|
4186
4827
|
rate,
|
|
4828
|
+
// Null on a conversion that matched no code of ours; the
|
|
4829
|
+
// backfill branch below sets it when one arrives later.
|
|
4830
|
+
redemption: redemptionDocId,
|
|
4187
4831
|
source,
|
|
4188
|
-
status: "completed"
|
|
4832
|
+
status: "completed",
|
|
4833
|
+
type: isConversion ? "conversion" : "redemption"
|
|
4189
4834
|
},
|
|
4190
4835
|
operation: "create"
|
|
4191
4836
|
});
|
|
4192
4837
|
if (org == null ? void 0 : org.usage) {
|
|
4193
4838
|
writes.push({
|
|
4194
4839
|
collection: "usage",
|
|
4195
|
-
|
|
4840
|
+
// TWO METERS, NOT ONE SUMMED. `revenue` has always meant
|
|
4841
|
+
// conversion revenue and is the figure the fee is charged
|
|
4842
|
+
// against, so redemption money gets its own key rather than
|
|
4843
|
+
// changing what an existing number means.
|
|
4844
|
+
data: {
|
|
4845
|
+
$inc: isConversion ? { "totals.revenue": gross } : { "totals.redemptionRevenue": gross }
|
|
4846
|
+
},
|
|
4196
4847
|
operation: "update",
|
|
4197
4848
|
query: { id: org.usage }
|
|
4198
4849
|
});
|
|
@@ -4200,7 +4851,12 @@ var shopify_default2 = {
|
|
|
4200
4851
|
if (leadId) {
|
|
4201
4852
|
writes.push({
|
|
4202
4853
|
collection: "lead",
|
|
4203
|
-
|
|
4854
|
+
// Same grouped shape the contact carries, so a lead and the
|
|
4855
|
+
// contact built from it cannot be read two different ways.
|
|
4856
|
+
data: { $inc: {
|
|
4857
|
+
"totals.orders.total": 1,
|
|
4858
|
+
...isConversion ? { "totals.orders.conversions": 1 } : { "totals.orders.redemptions": 1 }
|
|
4859
|
+
} },
|
|
4204
4860
|
operation: "update",
|
|
4205
4861
|
options: { bypassDocumentValidation: true },
|
|
4206
4862
|
query: { id: leadId }
|
|
@@ -4219,6 +4875,7 @@ var shopify_default2 = {
|
|
|
4219
4875
|
customer,
|
|
4220
4876
|
discount,
|
|
4221
4877
|
gross,
|
|
4878
|
+
id: redemptionDocId,
|
|
4222
4879
|
lead: leadId,
|
|
4223
4880
|
order: orderDocId,
|
|
4224
4881
|
organization: campaignOrganization,
|
|
@@ -4247,6 +4904,14 @@ var shopify_default2 = {
|
|
|
4247
4904
|
query: { id: leadId }
|
|
4248
4905
|
});
|
|
4249
4906
|
}
|
|
4907
|
+
if (backfill && orderDocId && redemptionDocId) {
|
|
4908
|
+
writes.push({
|
|
4909
|
+
collection: "order",
|
|
4910
|
+
data: { $set: { redemption: redemptionDocId } },
|
|
4911
|
+
operation: "update",
|
|
4912
|
+
query: { id: orderDocId }
|
|
4913
|
+
});
|
|
4914
|
+
}
|
|
4250
4915
|
}
|
|
4251
4916
|
const billable = (org == null ? void 0 : org.billingProvider) === "shopify" && fee > 0 && !backfill;
|
|
4252
4917
|
const providerRow2 = billable ? await read.get({ collection: "provider", query: { slug: "shopify" } }) : null;
|
|
@@ -4625,7 +5290,7 @@ var shopify_default2 = {
|
|
|
4625
5290
|
event: "shopify.register.webhooks"
|
|
4626
5291
|
},
|
|
4627
5292
|
name: "register",
|
|
4628
|
-
options: { jobId: "connection.update.register." + workflow.connection + "." +
|
|
5293
|
+
options: { jobId: "connection.update.register." + workflow.connection + "." + randomUUID2() },
|
|
4629
5294
|
queue: "connection"
|
|
4630
5295
|
}],
|
|
4631
5296
|
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." : ""),
|
|
@@ -4739,10 +5404,19 @@ var shopify_default2 = {
|
|
|
4739
5404
|
// picker stores, which is why the tail is taken here rather than by
|
|
4740
5405
|
// each caller that happened to remember.
|
|
4741
5406
|
items: ((discounts == null ? void 0 : discounts.edges) || []).map((edge) => {
|
|
4742
|
-
var _a2, _b2
|
|
5407
|
+
var _a2, _b2;
|
|
5408
|
+
const node = ((_a2 = edge == null ? void 0 : edge.node) == null ? void 0 : _a2.codeDiscount) || {};
|
|
4743
5409
|
return {
|
|
4744
|
-
|
|
4745
|
-
|
|
5410
|
+
// Null when the discount can be used, a sentence when it cannot.
|
|
5411
|
+
// The picker greys the row and shows this instead of hiding it:
|
|
5412
|
+
// a discount the merchant can see in Shopify admin, missing here
|
|
5413
|
+
// with no explanation, reads as a bug in us.
|
|
5414
|
+
blocked: blockedReason(node),
|
|
5415
|
+
id: String(((_b2 = edge == null ? void 0 : edge.node) == null ? void 0 : _b2.id) || "").split("/").pop(),
|
|
5416
|
+
// Usable, but not in the way the merchant probably expects.
|
|
5417
|
+
// Shown beside the row without stopping them.
|
|
5418
|
+
warning: discountWarning(node),
|
|
5419
|
+
title: node.title
|
|
4746
5420
|
};
|
|
4747
5421
|
}),
|
|
4748
5422
|
pageInfo: {
|
|
@@ -4757,20 +5431,6 @@ var shopify_default2 = {
|
|
|
4757
5431
|
},
|
|
4758
5432
|
icon: shopify_default,
|
|
4759
5433
|
inbound,
|
|
4760
|
-
// THE DEEP LINK into this store's Drawbridge app inside Shopify admin.
|
|
4761
|
-
//
|
|
4762
|
-
// Here rather than in drawbridge-api, which had `slug === 'shopify' && {...}`
|
|
4763
|
-
// in the shared resolver — a hardcoded vendor branch in code every vendor runs
|
|
4764
|
-
// through, which is the arrangement these manifests exist to remove.
|
|
4765
|
-
//
|
|
4766
|
-
// Undefined until a shop is linked, so the Manage button only appears on a
|
|
4767
|
-
// connected connection. The app handle is NAMED by `requires` and read from
|
|
4768
|
-
// the env the resolver passes, never from process.env here.
|
|
4769
|
-
manage: (data2, env) => {
|
|
4770
|
-
var _a;
|
|
4771
|
-
const shop = (data2 == null ? void 0 : data2.shop) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.domain);
|
|
4772
|
-
return shop ? "https://admin.shopify.com/store/" + String(shop).replace(".myshopify.com", "") + "/apps/" + (env == null ? void 0 : env.SHOPIFY_APP_HANDLE) : void 0;
|
|
4773
|
-
},
|
|
4774
5434
|
// DRAWBRIDGE'S OWN CREDENTIALS for this vendor, as opposed to a merchant's —
|
|
4775
5435
|
// what an admin types on the provider screen. The four names below are exactly
|
|
4776
5436
|
// what `requires` gates on, which is the point of declaring them together: a
|
|
@@ -4816,6 +5476,14 @@ var shopify_default2 = {
|
|
|
4816
5476
|
"SHOPIFY_APP_LISTING_URL",
|
|
4817
5477
|
"SHOPIFY_APP_HANDLE"
|
|
4818
5478
|
],
|
|
5479
|
+
// THE CHECKLIST'S RECEIPT — see drawbridge-docs reference/connection-hooks.md.
|
|
5480
|
+
review: {
|
|
5481
|
+
api: "https://shopify.dev/docs/api/admin-graphql",
|
|
5482
|
+
dashboard: "https://help.shopify.com/en/manual/apps",
|
|
5483
|
+
scopes: "https://shopify.dev/docs/api/usage/access-scopes",
|
|
5484
|
+
content: "2026-09-11",
|
|
5485
|
+
verified: null
|
|
5486
|
+
},
|
|
4819
5487
|
slug: "shopify",
|
|
4820
5488
|
// The install is the whole configuration — Shopify hands back the shop and
|
|
4821
5489
|
// there is nothing further to choose. `shop` absent means the install did not
|
|
@@ -4903,8 +5571,11 @@ var shopify_default2 = {
|
|
|
4903
5571
|
})
|
|
4904
5572
|
},
|
|
4905
5573
|
// SYSTEM STEPS: dispatched by drawbridge-sync itself rather than offered
|
|
4906
|
-
// in the builder, so they carry no
|
|
4907
|
-
//
|
|
5574
|
+
// in the builder, so they carry no usage. These two are fired by a webhook
|
|
5575
|
+
// arriving rather than by a workflow trigger, so they name none either —
|
|
5576
|
+
// and naming none is what stops a workflow being provisioned for them.
|
|
5577
|
+
// Declared because the routing table and the system-workflow descriptions
|
|
5578
|
+
// both read here.
|
|
4908
5579
|
order: {
|
|
4909
5580
|
record: () => ({
|
|
4910
5581
|
description: "Records an order and billing charge when a purchase is made via a Drawbridge campaign link.",
|
|
@@ -4936,7 +5607,8 @@ var shopify_default2 = {
|
|
|
4936
5607
|
hook: "lifecycle.health",
|
|
4937
5608
|
key: "Shopify Connection Health",
|
|
4938
5609
|
queue: "connection",
|
|
4939
|
-
system: true
|
|
5610
|
+
system: true,
|
|
5611
|
+
trigger: { event: "day", type: "schedule" }
|
|
4940
5612
|
})
|
|
4941
5613
|
},
|
|
4942
5614
|
// Audit-only. The "Shopify Token Activity" system workflow lists these
|
|
@@ -4997,7 +5669,30 @@ var shopify_default2 = {
|
|
|
4997
5669
|
] : []
|
|
4998
5670
|
];
|
|
4999
5671
|
},
|
|
5000
|
-
title: "Shopify"
|
|
5672
|
+
title: "Shopify",
|
|
5673
|
+
// THE VENDOR'S OWN ADMIN, one function per thing worth linking to. It lives
|
|
5674
|
+
// here rather than at the top level so a second link (a product, an order)
|
|
5675
|
+
// is a key in this object instead of a new manifest key nobody agreed on.
|
|
5676
|
+
//
|
|
5677
|
+
// AND HERE RATHER THAN IN drawbridge-api, which had `slug === 'shopify' &&
|
|
5678
|
+
// {...}` in the shared resolver — a hardcoded vendor branch in code every
|
|
5679
|
+
// vendor runs through, which is the arrangement these manifests exist to
|
|
5680
|
+
// remove.
|
|
5681
|
+
//
|
|
5682
|
+
// Never projected: the api composes connect.manage from it, and
|
|
5683
|
+
// resolveConnection drops the object, because a url built from settings is
|
|
5684
|
+
// built where the settings are already decrypted.
|
|
5685
|
+
urls: {
|
|
5686
|
+
// Undefined until a shop is linked, so the Manage button only appears on a
|
|
5687
|
+
// connected connection. The app handle is NAMED by `requires` and read from
|
|
5688
|
+
// the env its caller passes — the api's resolve() hands it the stored
|
|
5689
|
+
// credentials, never process.env.
|
|
5690
|
+
manage: (data2, env) => {
|
|
5691
|
+
var _a;
|
|
5692
|
+
const shop = (data2 == null ? void 0 : data2.shop) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.domain);
|
|
5693
|
+
return shop ? "https://admin.shopify.com/store/" + String(shop).replace(".myshopify.com", "") + "/apps/" + (env == null ? void 0 : env.SHOPIFY_APP_HANDLE) : void 0;
|
|
5694
|
+
}
|
|
5695
|
+
}
|
|
5001
5696
|
};
|
|
5002
5697
|
|
|
5003
5698
|
// lib/connections/providers/webhook.js
|
|
@@ -5177,7 +5872,7 @@ var webhook_default = {
|
|
|
5177
5872
|
content: {
|
|
5178
5873
|
confirm: "Disconnecting stops Drawbridge from sending signed webhook payloads to your endpoint.",
|
|
5179
5874
|
description: [
|
|
5180
|
-
"Drawbridge can POST event payloads to your endpoint as activity happens in your account, so your own systems can react
|
|
5875
|
+
"Drawbridge can POST event payloads to your endpoint as activity happens in your account, so your own systems can react to it.",
|
|
5181
5876
|
"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."
|
|
5182
5877
|
],
|
|
5183
5878
|
excerpt: "Sign outgoing webhook payloads with an HMAC secret to verify authenticity.",
|
|
@@ -5278,6 +5973,9 @@ var webhook_default = {
|
|
|
5278
5973
|
// Gated on the encryption secret: without it the signing secret could not be
|
|
5279
5974
|
// stored safely, so the connection must not be offered at all.
|
|
5280
5975
|
requires: ["ENCRYPT_CONNECTION_SECRET"],
|
|
5976
|
+
// NO THIRD PARTY AT ALL. There is no vendor reference to read, no dashboard
|
|
5977
|
+
// to link to and no scope to request: connecting mints a secret.
|
|
5978
|
+
review: false,
|
|
5281
5979
|
// Outbound only. inbound.* is false because the direction is the point: we
|
|
5282
5980
|
// sign and POST to the merchant's endpoint, they never call us. Every other
|
|
5283
5981
|
// false follows from there being no third party to authenticate against —
|
|
@@ -5584,7 +6282,7 @@ var mergeSettings = ({ existing, incoming }) => {
|
|
|
5584
6282
|
var publicConnectionKeys = Object.freeze([
|
|
5585
6283
|
"actions",
|
|
5586
6284
|
// API-COMPOSED, not manifest-declared: the api's resolve() builds it from
|
|
5587
|
-
// auth.type, content.redirect and the manifest's manage() — the client reads
|
|
6285
|
+
// auth.type, content.redirect and the manifest's urls.manage() — the client reads
|
|
5588
6286
|
// connect.type to choose entered-vs-installed, connect.redirect for the App
|
|
5589
6287
|
// Store link, connect.manage for the admin deep link. It was dropped from
|
|
5590
6288
|
// this list when the manifests stopped declaring it, which stripped the
|
|
@@ -5643,20 +6341,20 @@ var clearProviderMemo = () => providerMemo.clear();
|
|
|
5643
6341
|
var providerRow = async ({ controller, slug: slug2 }) => {
|
|
5644
6342
|
const memoized = providerMemo.get(slug2);
|
|
5645
6343
|
if (memoized && Date.now() - memoized.at < MEMO_TTL_MS) return memoized.value;
|
|
5646
|
-
const
|
|
6344
|
+
const row2 = await controller.get({
|
|
5647
6345
|
collection: "provider",
|
|
5648
6346
|
query: { slug: slug2 }
|
|
5649
6347
|
});
|
|
5650
6348
|
const value = {
|
|
5651
|
-
enabled: (
|
|
5652
|
-
settings: (
|
|
6349
|
+
enabled: (row2 == null ? void 0 : row2.enabled) !== false,
|
|
6350
|
+
settings: (row2 == null ? void 0 : row2.settings) ? decrypt(row2.settings) : {}
|
|
5653
6351
|
};
|
|
5654
6352
|
providerMemo.set(slug2, { at: Date.now(), value });
|
|
5655
6353
|
return value;
|
|
5656
6354
|
};
|
|
5657
6355
|
var providerSettings = async ({ controller, includeDisabled = false, slug: slug2 }) => {
|
|
5658
|
-
const
|
|
5659
|
-
return
|
|
6356
|
+
const row2 = await providerRow({ controller, slug: slug2 });
|
|
6357
|
+
return row2.enabled || includeDisabled ? row2.settings : {};
|
|
5660
6358
|
};
|
|
5661
6359
|
var vendorEnabled = async ({ controller, vendor }) => (await providerRow({ controller, slug: vendor })).enabled;
|
|
5662
6360
|
var vendorSettings = async ({ controller, slug: slug2 }) => {
|