@drawbridge/drawbridge-utils 0.0.115 → 0.0.117

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.
@@ -1,7 +1,7 @@
1
1
  import { authToken } from './oauth.cjs';
2
2
  export { consentUrl, pkcePair } from './oauth.cjs';
3
- import { channels } from '../pricing.cjs';
4
3
  import { request } from '../http.cjs';
4
+ import { channels } from '../pricing.cjs';
5
5
  import crypto, { createHmac, timingSafeEqual } from 'node:crypto';
6
6
  import { safeRequest } from '../safe-http.cjs';
7
7
  import '../plans.cjs';
@@ -603,7 +603,13 @@ var attentive = {
603
603
  // connection DOCUMENT carries its own `errors` array and is spread OVER the
604
604
  // resolved manifest downstream, so a top-level one would never render.
605
605
  content : {
606
- confirm : 'Disconnecting revokes Drawbridge\'s access to your Attentive account. Your subscribers stay in both Attentive and Drawbridge — neither list is deleted.',
606
+ // SAYS WHAT ACTUALLY HAPPENS. This used to promise that disconnecting
607
+ // revokes Drawbridge's access, and it cannot: Attentive documents no
608
+ // revocation endpoint, and their authentication page states an access
609
+ // token "does not expire". So the grant survives a disconnect forever
610
+ // unless the merchant removes the integration at Attentive, and the copy
611
+ // has to say so rather than let them believe otherwise.
612
+ 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 — neither list is deleted.',
607
613
  description : [
608
614
  'Attentive is where your SMS marketing lives, and this connection is becoming the way your Drawbridge contacts sync into an Attentive segment.',
609
615
  'You authorize Drawbridge from inside Attentive and can revoke that access there at any time. Drawbridge never sees or stores your Attentive password.',
@@ -645,8 +651,15 @@ var attentive = {
645
651
  // account-identity endpoint to enrich them with — Klaviyo's connect
646
652
  // reads the account name back; this has nothing cited to read. The
647
653
  // callback stores the tokens and skips enrichment on `unimplemented`.
648
- connect : {},
649
- disconnect : {},
654
+ // FALSE, NOT {}. `{}` means "supported, implemented in the repo with the
655
+ // dependencies", and nothing anywhere implements either of these —
656
+ // there is nothing for them to do. The exchange already yields the
657
+ // tokens and Attentive documents no account-identity endpoint to
658
+ // enrich them with, so connect has nothing to add; and they document
659
+ // no revocation endpoint at all, so disconnect has nothing to call.
660
+ // Recorded as a decision rather than left as an unkept promise.
661
+ connect : false,
662
+ disconnect : false,
650
663
  probe : false,
651
664
  scopes : false,
652
665
  // THE ONE THING WRAPPED, and it is about the response rather than the
@@ -762,231 +775,18 @@ var attentive = {
762
775
  title : 'Attentive'
763
776
  };
764
777
 
765
- // Drawbridge, exported from the brand kit and left as authored the fills are the
766
- // vendor's own mark, not a recolour.
767
- //
768
- // A .js wrapper around otherwise untouched SVG so `node --test` can run against
769
- // lib/ directly. A bare .svg import would need a bundler loader and force the
770
- // tests onto dist/, which is a worse trade than one line of wrapper.
771
- var icon$3 = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
772
- <rect width="500" height="500" fill="#BAEC5F"/>
773
- <g clip-path="url(#clip0_2115_2832)">
774
- <path d="M140.224 127.586L174.803 188.73V311.176L140 372.32L176.084 392.031L216.111 321.753V178.278L176.341 108L140.224 127.586Z" fill="#0D1314"/>
775
- <path d="M360.001 127.523L323.693 108.282L284.948 178.498V321.596L322.923 391.749L359.393 372.79L326.224 311.52V188.73L360.001 127.523Z" fill="#0D1314"/>
776
- </g>
777
- <defs>
778
- <clipPath id="clip0_2115_2832">
779
- <rect width="220" height="284" fill="white" transform="translate(140 108)"/>
780
- </clipPath>
781
- </defs>
782
- </svg>`;
783
-
784
- // Drawbridge itself — the PRIVATE connection.
778
+ // DRAWBRIDGE'S OWN HUBSPOT PORTAL, kept in step with account signups so the
779
+ // campaign a customer arrived on is on their contact record.
785
780
  //
786
- // Nobody connects this. There is no credential, no consent, and no card on the
787
- // connections page. It exists because a workflow step points at a hook, and the
788
- // six most common steps sending an email, alerting a member, syncing a segment
789
- // are things Drawbridge does rather than things a vendor does.
790
- //
791
- // Before this, those steps were the exception: every other step resolved through
792
- // a manifest and these resolved through a hardcoded registry in drawbridge-sync.
793
- // One exception is all it takes for "every step is a declaration pointing at a
794
- // hook" to stop being a rule somebody can rely on.
781
+ // It sits beside lib/sendgrid.js and lib/twilio.js because it is the same kind
782
+ // of thing: a vendor client for an account DRAWBRIDGE holds, not one a merchant
783
+ // connects. It used to be a connection manifest of its own, which read as though
784
+ // HubSpot were a vendor a merchant could pick it never was, and the slug is
785
+ // better kept free for the day a merchant-facing HubSpot connection exists.
795
786
  //
796
- // PRIVATE is a real distinction, not a flag to hide a card. A public connection
797
- // answers "can this merchant connect it" through `requires` and a plan feature.
798
- // A private one is always present, in every deployment, for every organization —
799
- // so it declares neither, and build() knows not to ask.
800
- var drawbridge = {
801
- auth : {
802
- type : 'none'
803
- },
804
- content : {
805
- confirm : 'This connection is part of Drawbridge and cannot be disconnected.',
806
- description : [
807
- '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.'
808
- ],
809
- excerpt : 'The steps Drawbridge runs itself.',
810
- guide : [
811
- 'Nothing to do. These steps are available in every workflow builder.'
812
- ]
813
- },
814
- exclusive : false,
815
- fields : [],
816
- group : 'developer',
817
- // EVERY BODY LIVES IN drawbridge-sync. Sending needs the provider clients, the
818
- // suppression collection and the queues; segment sync needs the streams. A
819
- // published package carrying those makes every consumer carry them, which is
820
- // the reason `{}` exists as an answer.
821
- hooks : {
822
- auth : {
823
- // Nothing to connect, revoke, probe or re-scope.
824
- connect : false,
825
- disconnect : false,
826
- probe : false,
827
- scopes : false,
828
- token : false
829
- },
830
- commerce : false,
831
- contacts : { remove : false, sync : false },
832
- email : {
833
- digest : {},
834
- // To organization members. NEVER suppressed and never billed: an
835
- // entrant's opt-out must not silence an alert to staff, and staff mail is
836
- // not a metered send.
837
- notify : {},
838
- // To a lead. Suppression applies and the send is billed.
839
- send : {}
840
- },
841
- inbound : false,
842
- lifecycle : false,
843
- resources : {
844
- audiences : false,
845
- prices : false,
846
- products : false,
847
- promotions : false
848
- },
849
- segment : { sync : {} },
850
- sms : { send : {} },
851
- webhook : false
852
- },
853
- icon: icon$3,
854
- // PRIVATE: never in the catalog, always available to the builder.
855
- private : true,
856
- requires : [],
857
- slug : 'drawbridge',
858
- // Always on. There is no credential that could go bad and no configuration a
859
- // merchant could leave half-finished.
860
- status : () => 'active',
861
- // DERIVED FROM drawbridge-api/lib/workflows.js, not invented. Every value
862
- // below — trigger, billable, settings — is what that catalog and the workflow
863
- // route already enforce today, because this replaces them rather than
864
- // competing with them.
865
- //
866
- // NOT HERE, deliberately:
867
- //
868
- // step.segment.sync a SYSTEM step, dispatched by drawbridge-sync rather
869
- // than offered in the builder. It fans out, so the shell
870
- // opens its step document and the chunks close it.
871
- steps : {
872
-
873
- email : {
874
-
875
- // SCHEDULE-TRIGGERED, not lead-triggered: it is offered under Daily,
876
- // Weekly and Monthly. Those triggers had offered no steps at all, so a
877
- // scheduled workflow was selectable and inert until this landed.
878
- digest : () => ({
879
- hook : 'email.digest',
880
- key : 'Email — Digest',
881
- queue : 'notification',
882
- settings : {
883
- // The organization OWNER is always a recipient, resolved in sync,
884
- // so this is additional recipients rather than the list. It cannot
885
- // be required: the members endpoint is owner-gated and the owner is
886
- // not a member document, so a solo merchant has nothing to pick and
887
- // could never save the step.
888
- members : { of : 'string', type : 'array' },
889
- message : { required : true, type : 'string' },
890
- subject : { required : true, type : 'string' }
891
- },
892
- triggers : [ 'schedule.day', 'schedule.week', 'schedule.month' ],
893
- usage : { actions : 0 }
894
- }),
895
-
896
- // To organization MEMBERS. Never suppressed — an entrant's opt-out must
897
- // not silence an alert to staff — and not billed.
898
- notify : () => ({
899
- hook : 'email.notify',
900
- key : 'Email — Notification',
901
- queue : 'notification',
902
- settings : {
903
- members : { of : 'string', type : 'array' },
904
- message : { required : true, type : 'string' },
905
- subject : { required : true, type : 'string' }
906
- },
907
- triggers : [ 'lead.insert' ],
908
- // Zero is a PRICE, and a deliberate one. Declared rather than omitted
909
- // so "this is free" and "nobody decided" stay different statements;
910
- // completeStep bills only when actions > 0.
911
- usage : { actions : 0 }
912
- }),
913
-
914
- // To a LEAD. Suppression applies and the send is billed.
915
- send : () => ({
916
- hook : 'email.send',
917
- key : 'Email — Send email',
918
- queue : 'notification',
919
- settings : {
920
- message : { required : true, type : 'string' },
921
- subject : { required : true, type : 'string' }
922
- },
923
- triggers : [ 'lead.insert' ],
924
- // ONE SOURCE FOR THE PRICE. lib/pricing.js is the index of every
925
- // customer-facing number; the handler read it too, so the same fact
926
- // was stated in two places and only one of them was reviewed.
927
- usage : { actions : channels.email.actionsPerSend }
928
- })
929
-
930
- },
931
-
932
- // WITHDRAWN, which is a third thing from builder and system: declared,
933
- // routed and runnable, but never offered.
934
- //
935
- // It went when the twilio connection did — a connection-gated step with no
936
- // connection to gate on could only ever render permanently disabled. Stored
937
- // workflows still carry it, so it must keep running, and enums.step.type
938
- // keeps it for the same reason.
939
- //
940
- // NO TRIGGERS is what keeps it out of the builder: the catalog derives from
941
- // triggers, so a step with none is unreachable by a merchant without a
942
- // second list saying so.
943
- //
944
- // Platform SMS returns as a base step the way email did. That is this entry
945
- // gaining triggers, not a new one.
946
- sms : {
947
-
948
- send : () => ({
949
- hook : 'sms.send',
950
- key : 'Send an SMS',
951
- queue : 'notification',
952
- settings : {
953
- message : { required : true, type : 'string' },
954
- subject : { required : true, type : 'string' }
955
- },
956
- // Priced per SEGMENT and billed from the first, which the send
957
- // resolves from the message length. This is the floor.
958
- usage : { actions : channels.sms.actionsPerSegment },
959
- withdrawn : true
960
- })
961
-
962
- },
963
-
964
- segment : {
965
-
966
- // FANS OUT. It evaluates every contact in the organization against every
967
- // segment, which is too much for one job — so the hook returns chunks and
968
- // the shell defers completion: openStep writes the document with a slot
969
- // per chunk, and whichever chunk lands last closes it and resumes the
970
- // chain.
971
- //
972
- // It carries a hook like every other step. An earlier version declared
973
- // none, on the theory that fan-out was a second protocol the shell could
974
- // not run; it is the same protocol with the ending deferred, and a step
975
- // declaring no hook is silently SKIPPED by the runner.
976
- sync : () => ({
977
- description : 'Recalculates segment membership on a daily schedule.',
978
- hook : 'segment.sync',
979
- key : 'Segment Sync',
980
- queue : 'segment',
981
- system : true
982
- })
787
+ // The hooks are wired into the private `drawbridge` manifest's contacts slot;
788
+ // drawbridge-sync's user stream calls them by that name.
983
789
 
984
- }
985
-
986
- },
987
- tasks : () => [],
988
- title : 'Drawbridge'
989
- };
990
790
 
991
791
  // HubSpot — PRIVATE, and Drawbridge's own CRM rather than a merchant's.
992
792
  //
@@ -1207,35 +1007,7 @@ const lookup = async ({ email, fetcher, token }) => {
1207
1007
 
1208
1008
  };
1209
1009
 
1210
- var hubspot = {
1211
- auth : {
1212
- // A Private App token from our own portal. Nothing to connect, nothing to
1213
- // consent to, and no merchant involved.
1214
- type : 'none'
1215
- },
1216
- content : {
1217
- confirm : 'This connection is part of Drawbridge and cannot be disconnected.',
1218
- description : [
1219
- 'Drawbridge keeps its own HubSpot portal in step with account signups, so the campaign a customer arrived on is on their contact record.'
1220
- ],
1221
- excerpt : 'Drawbridge\'s own CRM sync.',
1222
- guide : [
1223
- 'Nothing to do. This is internal to Drawbridge.'
1224
- ]
1225
- },
1226
- exclusive : false,
1227
- fields : [],
1228
- group : 'contacts',
1229
- hooks : {
1230
- auth : {
1231
- connect : false,
1232
- disconnect : false,
1233
- probe : false,
1234
- scopes : false,
1235
- token : false
1236
- },
1237
- commerce : false,
1238
- contacts : {
1010
+ const contacts = {
1239
1011
 
1240
1012
  // FORGET A CONTACT, by id or by email. Account deletion — the caller had
1241
1013
  // to search then remove, which is one round trip it should not have to
@@ -1301,8 +1073,92 @@ var hubspot = {
1301
1073
 
1302
1074
  }
1303
1075
 
1076
+ };
1077
+
1078
+ // Drawbridge, exported from the brand kit and left as authored — the fills are the
1079
+ // vendor's own mark, not a recolour.
1080
+ //
1081
+ // A .js wrapper around otherwise untouched SVG so `node --test` can run against
1082
+ // lib/ directly. A bare .svg import would need a bundler loader and force the
1083
+ // tests onto dist/, which is a worse trade than one line of wrapper.
1084
+ var icon$3 = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
1085
+ <rect width="500" height="500" fill="#BAEC5F"/>
1086
+ <g clip-path="url(#clip0_2115_2832)">
1087
+ <path d="M140.224 127.586L174.803 188.73V311.176L140 372.32L176.084 392.031L216.111 321.753V178.278L176.341 108L140.224 127.586Z" fill="#0D1314"/>
1088
+ <path d="M360.001 127.523L323.693 108.282L284.948 178.498V321.596L322.923 391.749L359.393 372.79L326.224 311.52V188.73L360.001 127.523Z" fill="#0D1314"/>
1089
+ </g>
1090
+ <defs>
1091
+ <clipPath id="clip0_2115_2832">
1092
+ <rect width="220" height="284" fill="white" transform="translate(140 108)"/>
1093
+ </clipPath>
1094
+ </defs>
1095
+ </svg>`;
1096
+
1097
+ // Drawbridge itself — the PRIVATE connection.
1098
+ //
1099
+ // Nobody connects this. There is no credential, no consent, and no card on the
1100
+ // connections page. It exists because a workflow step points at a hook, and the
1101
+ // six most common steps — sending an email, alerting a member, syncing a segment
1102
+ // — are things Drawbridge does rather than things a vendor does.
1103
+ //
1104
+ // Before this, those steps were the exception: every other step resolved through
1105
+ // a manifest and these resolved through a hardcoded registry in drawbridge-sync.
1106
+ // One exception is all it takes for "every step is a declaration pointing at a
1107
+ // hook" to stop being a rule somebody can rely on.
1108
+ //
1109
+ // PRIVATE is a real distinction, not a flag to hide a card. A public connection
1110
+ // answers "can this merchant connect it" through `requires` and a plan feature.
1111
+ // A private one is always present, in every deployment, for every organization —
1112
+ // so it declares neither, and build() knows not to ask.
1113
+ var drawbridge = {
1114
+ auth : {
1115
+ type : 'none'
1116
+ },
1117
+ content : {
1118
+ confirm : 'This connection is part of Drawbridge and cannot be disconnected.',
1119
+ description : [
1120
+ '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.'
1121
+ ],
1122
+ excerpt : 'The steps Drawbridge runs itself.',
1123
+ guide : [
1124
+ 'Nothing to do. These steps are available in every workflow builder.'
1125
+ ]
1126
+ },
1127
+ exclusive : false,
1128
+ fields : [],
1129
+ group : 'developer',
1130
+ // EVERY BODY LIVES IN drawbridge-sync. Sending needs the provider clients, the
1131
+ // suppression collection and the queues; segment sync needs the streams. A
1132
+ // published package carrying those makes every consumer carry them, which is
1133
+ // the reason `{}` exists as an answer.
1134
+ hooks : {
1135
+ auth : {
1136
+ // Nothing to connect, revoke, probe or re-scope.
1137
+ connect : false,
1138
+ disconnect : false,
1139
+ probe : false,
1140
+ scopes : false,
1141
+ token : false
1142
+ },
1143
+ commerce : false,
1144
+ // DRAWBRIDGE'S OWN CRM. Not a merchant's — this keeps our HubSpot portal in
1145
+ // step with account signups, and drawbridge-sync's user stream calls it.
1146
+ //
1147
+ // A real implementation here rather than `{}` because the bodies are pure
1148
+ // HTTP against a token: no controller, no queue, nothing that would have to
1149
+ // live in the service. lib/hubspot.js holds them, beside lib/sendgrid.js
1150
+ // and lib/twilio.js, which are the same kind of thing — vendor clients for
1151
+ // accounts DRAWBRIDGE holds rather than ones a merchant connects.
1152
+ contacts,
1153
+ email : {
1154
+ digest : {},
1155
+ // To organization members. NEVER suppressed and never billed: an
1156
+ // entrant's opt-out must not silence an alert to staff, and staff mail is
1157
+ // not a metered send.
1158
+ notify : {},
1159
+ // To a lead. Suppression applies and the send is billed.
1160
+ send : {}
1304
1161
  },
1305
- email : false,
1306
1162
  inbound : false,
1307
1163
  lifecycle : false,
1308
1164
  resources : {
@@ -1311,22 +1167,157 @@ var hubspot = {
1311
1167
  products : false,
1312
1168
  promotions : false
1313
1169
  },
1314
- segment : false,
1315
- sms : false,
1170
+ segment : { sync : {} },
1171
+ sms : { send : {} },
1316
1172
  webhook : false
1317
1173
  },
1318
1174
  icon: icon$3,
1319
- // Borrowed: the Drawbridge mark, because this is ours and never rendered.
1175
+ // PRIVATE: never in the catalog, always available to the builder.
1320
1176
  private : true,
1321
- // Absent the token the hooks no-op, so a deployment without a portal simply
1322
- // contributes nothing rather than failing.
1323
- requires : [ 'HUBSPOT_ACCESS_TOKEN' ],
1324
- slug : 'hubspot',
1177
+ // NOTHING, and HUBSPOT_ACCESS_TOKEN in particular must not be here.
1178
+ //
1179
+ // `requires` gates AVAILABILITY: a name in it that is unset removes the whole
1180
+ // connection. This one is private and contributes every base workflow step —
1181
+ // email.send, sms.send, segment.sync — so gating it on a CRM token would take
1182
+ // all of them away from any deployment without a HubSpot portal, to protect a
1183
+ // sync that is best-effort and already no-ops without a token.
1184
+ //
1185
+ // The test 'a vendor is only available when its environment is configured'
1186
+ // caught exactly that: availableConnections({}) went from [ 'drawbridge' ] to
1187
+ // empty the moment this was added.
1188
+ requires : [],
1189
+ slug : 'drawbridge',
1190
+ // Always on. There is no credential that could go bad and no configuration a
1191
+ // merchant could leave half-finished.
1325
1192
  status : () => 'active',
1326
- // No workflow steps. The hooks are called by the user stream, not the builder.
1327
- steps : {},
1193
+ // DERIVED FROM drawbridge-api/lib/workflows.js, not invented. Every value
1194
+ // below — trigger, billable, settings — is what that catalog and the workflow
1195
+ // route already enforce today, because this replaces them rather than
1196
+ // competing with them.
1197
+ //
1198
+ // NOT HERE, deliberately:
1199
+ //
1200
+ // step.segment.sync a SYSTEM step, dispatched by drawbridge-sync rather
1201
+ // than offered in the builder. It fans out, so the shell
1202
+ // opens its step document and the chunks close it.
1203
+ steps : {
1204
+
1205
+ email : {
1206
+
1207
+ // SCHEDULE-TRIGGERED, not lead-triggered: it is offered under Daily,
1208
+ // Weekly and Monthly. Those triggers had offered no steps at all, so a
1209
+ // scheduled workflow was selectable and inert until this landed.
1210
+ digest : () => ({
1211
+ hook : 'email.digest',
1212
+ key : 'Email — Digest',
1213
+ queue : 'notification',
1214
+ settings : {
1215
+ // The organization OWNER is always a recipient, resolved in sync,
1216
+ // so this is additional recipients rather than the list. It cannot
1217
+ // be required: the members endpoint is owner-gated and the owner is
1218
+ // not a member document, so a solo merchant has nothing to pick and
1219
+ // could never save the step.
1220
+ members : { of : 'string', type : 'array' },
1221
+ message : { required : true, type : 'string' },
1222
+ subject : { required : true, type : 'string' }
1223
+ },
1224
+ triggers : [ 'schedule.day', 'schedule.week', 'schedule.month' ],
1225
+ usage : { actions : 0 }
1226
+ }),
1227
+
1228
+ // To organization MEMBERS. Never suppressed — an entrant's opt-out must
1229
+ // not silence an alert to staff — and not billed.
1230
+ notify : () => ({
1231
+ hook : 'email.notify',
1232
+ key : 'Email — Notification',
1233
+ queue : 'notification',
1234
+ settings : {
1235
+ members : { of : 'string', type : 'array' },
1236
+ message : { required : true, type : 'string' },
1237
+ subject : { required : true, type : 'string' }
1238
+ },
1239
+ triggers : [ 'lead.insert' ],
1240
+ // Zero is a PRICE, and a deliberate one. Declared rather than omitted
1241
+ // so "this is free" and "nobody decided" stay different statements;
1242
+ // completeStep bills only when actions > 0.
1243
+ usage : { actions : 0 }
1244
+ }),
1245
+
1246
+ // To a LEAD. Suppression applies and the send is billed.
1247
+ send : () => ({
1248
+ hook : 'email.send',
1249
+ key : 'Email — Send email',
1250
+ queue : 'notification',
1251
+ settings : {
1252
+ message : { required : true, type : 'string' },
1253
+ subject : { required : true, type : 'string' }
1254
+ },
1255
+ triggers : [ 'lead.insert' ],
1256
+ // ONE SOURCE FOR THE PRICE. lib/pricing.js is the index of every
1257
+ // customer-facing number; the handler read it too, so the same fact
1258
+ // was stated in two places and only one of them was reviewed.
1259
+ usage : { actions : channels.email.actionsPerSend }
1260
+ })
1261
+
1262
+ },
1263
+
1264
+ // WITHDRAWN, which is a third thing from builder and system: declared,
1265
+ // routed and runnable, but never offered.
1266
+ //
1267
+ // It went when the twilio connection did — a connection-gated step with no
1268
+ // connection to gate on could only ever render permanently disabled. Stored
1269
+ // workflows still carry it, so it must keep running, and enums.step.type
1270
+ // keeps it for the same reason.
1271
+ //
1272
+ // NO TRIGGERS is what keeps it out of the builder: the catalog derives from
1273
+ // triggers, so a step with none is unreachable by a merchant without a
1274
+ // second list saying so.
1275
+ //
1276
+ // Platform SMS returns as a base step the way email did. That is this entry
1277
+ // gaining triggers, not a new one.
1278
+ sms : {
1279
+
1280
+ send : () => ({
1281
+ hook : 'sms.send',
1282
+ key : 'Send an SMS',
1283
+ queue : 'notification',
1284
+ settings : {
1285
+ message : { required : true, type : 'string' },
1286
+ subject : { required : true, type : 'string' }
1287
+ },
1288
+ // Priced per SEGMENT and billed from the first, which the send
1289
+ // resolves from the message length. This is the floor.
1290
+ usage : { actions : channels.sms.actionsPerSegment },
1291
+ withdrawn : true
1292
+ })
1293
+
1294
+ },
1295
+
1296
+ segment : {
1297
+
1298
+ // FANS OUT. It evaluates every contact in the organization against every
1299
+ // segment, which is too much for one job — so the hook returns chunks and
1300
+ // the shell defers completion: openStep writes the document with a slot
1301
+ // per chunk, and whichever chunk lands last closes it and resumes the
1302
+ // chain.
1303
+ //
1304
+ // It carries a hook like every other step. An earlier version declared
1305
+ // none, on the theory that fan-out was a second protocol the shell could
1306
+ // not run; it is the same protocol with the ending deferred, and a step
1307
+ // declaring no hook is silently SKIPPED by the runner.
1308
+ sync : () => ({
1309
+ description : 'Recalculates segment membership on a daily schedule.',
1310
+ hook : 'segment.sync',
1311
+ key : 'Segment Sync',
1312
+ queue : 'segment',
1313
+ system : true
1314
+ })
1315
+
1316
+ }
1317
+
1318
+ },
1328
1319
  tasks : () => [],
1329
- title : 'HubSpot'
1320
+ title : 'Drawbridge'
1330
1321
  };
1331
1322
 
1332
1323
  // Klaviyo, exported from the brand kit and left as authored — the fills are the
@@ -1931,15 +1922,16 @@ var icon$1 = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xm
1931
1922
  <path d="M360.476 284.243C360.35 283.835 359.618 281.204 358.647 278.052L356.621 272.648C360.575 266.696 360.645 261.405 360.124 258.393C359.531 254.519 357.693 250.944 354.89 248.205C351.766 244.94 345.363 241.563 336.385 239.044L331.671 237.736C331.643 237.524 331.418 226.619 331.235 221.933C331.08 218.555 330.798 213.264 329.152 208.058C327.182 200.993 323.791 194.858 319.527 190.876C331.277 178.717 338.594 165.307 338.58 153.81C338.538 131.703 311.379 124.976 277.902 138.851L270.824 141.863C270.795 141.835 258.004 129.283 257.821 129.128C219.63 95.8334 100.327 228.476 138.49 260.687L146.835 267.737C144.581 273.775 143.781 280.259 144.499 286.664C145.414 295.543 149.973 304.029 157.375 310.6C164.411 316.82 173.684 320.788 182.648 320.774C197.494 354.998 231.408 375.965 271.175 377.161C313.842 378.427 349.641 358.403 364.67 322.435C365.641 319.916 369.806 308.546 369.806 298.513C369.792 288.409 364.093 284.229 360.476 284.243ZM185.913 311.149C184.613 311.381 183.293 311.48 181.973 311.445C169.083 311.079 155.166 299.483 153.787 285.735C152.253 270.537 160.02 258.829 173.783 256.071C175.415 255.72 177.414 255.537 179.552 255.635C187.264 256.085 198.606 261.996 201.209 278.784C203.517 293.63 199.858 308.785 185.913 311.149ZM171.545 246.953C163.179 248.499 155.744 253.244 150.817 260.18C148.045 257.873 142.909 253.426 142.008 251.681C134.635 237.693 150.043 210.478 160.823 195.111C187.405 157.145 229.086 128.424 248.393 133.603C251.517 134.503 261.902 146.563 261.902 146.563C261.902 146.563 242.623 157.244 224.724 172.16C200.646 190.735 182.423 217.697 171.545 246.953ZM306.792 305.464C306.937 305.403 307.057 305.295 307.134 305.157C307.211 305.019 307.239 304.86 307.214 304.704C307.205 304.61 307.178 304.519 307.133 304.436C307.088 304.353 307.027 304.28 306.954 304.221C306.88 304.162 306.796 304.118 306.705 304.092C306.614 304.066 306.519 304.059 306.426 304.071C306.426 304.071 286.246 307.054 267.179 300.089C269.247 293.348 274.792 295.754 283.137 296.444C296.108 297.209 309.116 295.802 321.623 292.279C330.25 289.788 341.592 284.905 350.401 277.953C353.384 284.497 354.425 291.674 354.425 291.674C354.425 291.674 356.719 291.265 358.647 292.447C360.476 293.573 361.799 295.895 360.898 301.89C359.027 313.119 354.271 322.224 346.235 330.611C341.236 336.036 335.277 340.492 328.659 343.754C324.983 345.691 321.151 347.32 317.205 348.623C286.964 358.487 256.006 347.638 246.029 324.321C245.224 322.535 244.556 320.691 244.03 318.804C239.781 303.438 243.383 285.032 254.655 273.408C255.372 272.676 256.09 271.804 256.09 270.706C256.09 269.806 255.499 268.835 255.007 268.131C251.066 262.418 237.374 252.666 240.132 233.795C242.088 220.23 253.951 210.689 265.012 211.252L267.826 211.421C272.611 211.702 276.79 212.307 280.73 212.49C287.344 212.758 293.268 211.801 300.304 205.947C302.683 203.949 304.582 202.246 307.791 201.711C308.128 201.627 308.973 201.359 310.647 201.416C312.365 201.485 314.032 202.015 315.474 202.949C321.103 206.693 321.905 215.783 322.214 222.439C322.383 226.225 322.848 235.414 322.988 238.031C323.354 244.054 324.944 244.912 328.125 245.954C329.94 246.573 331.615 246.995 334.077 247.713C341.521 249.781 345.968 251.934 348.754 254.65C350.198 256.049 351.13 257.893 351.4 259.885C352.315 266.316 346.432 274.252 330.925 281.457C313.954 289.324 293.367 291.322 279.154 289.732L274.173 289.169C262.774 287.649 256.315 302.34 263.14 312.402C267.545 318.889 279.52 323.11 291.523 323.11C319.006 323.139 340.142 311.402 348.023 301.242L348.642 300.356C349.008 299.765 348.712 299.469 348.22 299.779C341.817 304.169 313.279 321.619 282.771 316.384C282.771 316.384 279.056 315.765 275.678 314.442C273.005 313.429 267.362 310.811 266.686 305.042C291.27 312.683 306.792 305.478 306.792 305.464ZM220.671 194.971C230.127 184.051 241.765 174.538 252.206 169.219C252.558 169.022 252.938 169.43 252.741 169.754C251.46 172 250.476 174.403 249.814 176.902C249.73 177.282 250.138 177.592 250.461 177.353C256.963 172.934 268.248 168.192 278.155 167.601C278.251 167.584 278.351 167.601 278.436 167.65C278.521 167.698 278.586 167.775 278.621 167.866C278.656 167.957 278.658 168.058 278.627 168.151C278.596 168.244 278.533 168.323 278.451 168.375C276.809 169.634 275.342 171.105 274.088 172.751C273.891 173.032 274.074 173.44 274.426 173.44C281.378 173.483 291.186 175.903 297.56 179.491C297.982 179.745 297.673 180.575 297.209 180.462C287.527 178.253 271.724 176.564 255.288 180.575C240.597 184.149 229.396 189.666 221.248 195.618C220.826 195.899 220.333 195.351 220.671 194.971Z" fill="#231E15"/>
1932
1923
  </svg>`;
1933
1924
 
1934
- // EVERY ACCOUNT LIVES BEHIND A DATA-CENTRE PREFIX, and the key carries it as a
1935
- // suffix `...-us19` means us19.api.mailchimp.com. There is no fixed host to
1936
- // call, which is Mailchimp's oldest quirk and the reason its future OAuth flow
1937
- // needs a metadata call the other vendors do not.
1938
- const base = ( apiKey ) => {
1939
-
1940
- const dc = String( apiKey || '' ).split( '-' ).pop();
1925
+ // EVERY ACCOUNT LIVES BEHIND A DATA-CENTRE PREFIX — us1, us19 and there is no
1926
+ // fixed host to call. Mailchimp's oldest quirk, and the reason its OAuth needs a
1927
+ // metadata call the other vendors do not.
1928
+ //
1929
+ // Under keys the prefix was the key's own suffix (`...-us19`). Under OAuth it is
1930
+ // whatever auth.connect stored from /oauth2/metadata, which is why that hook is
1931
+ // not enrichment: without `dc` there is nowhere to send a request.
1932
+ const base = ( dc ) => {
1941
1933
 
1942
- if( ! dc || dc === apiKey ) throw new Error( 'That Mailchimp key carries no data centre suffix, so there is no host to call' );
1934
+ if( ! dc ) throw new Error( 'This Mailchimp connection has no data centre stored, so there is no host to call' );
1943
1935
 
1944
1936
  return 'https://' + dc + '.api.mailchimp.com/3.0';
1945
1937
 
@@ -1947,40 +1939,54 @@ const base = ( apiKey ) => {
1947
1939
 
1948
1940
  // Mailchimp — contact sync, not a sender.
1949
1941
  var mailchimp = {
1950
- // Keys TODAY. Mailchimp integrations authenticate with OAuth 2 (authorization
1951
- // code) and that is where this goes, so the endpoints are recorded here
1952
- // rather than researched again later:
1942
+ // OAUTH 2, authorization code. Every url below is quoted from
1943
+ // mailchimp.com/developer/marketing/guides/access-user-data-oauth-2/ rather
1944
+ // than remembered.
1953
1945
  //
1954
- // authorize https://login.mailchimp.com/oauth2/authorize
1955
- // token https://login.mailchimp.com/oauth2/token
1956
- // metadata https://login.mailchimp.com/oauth2/metadata
1946
+ // THE METADATA CALL IS MAILCHIMP'S QUIRK and cannot be skipped: an access
1947
+ // token alone cannot call the Marketing API, because every account lives
1948
+ // behind a data-centre prefix (us1, us19...) that only GET
1949
+ // login.mailchimp.com/oauth2/metadata returns — and every subsequent request
1950
+ // needs it in the HOST. That is why auth.connect below is a real function:
1951
+ // the standard exchange does not know where to send anything afterwards.
1957
1952
  //
1958
- // The metadata call is Mailchimp's quirk and cannot be skipped: the access
1959
- // token alone is not enough to call the Marketing API, because every account
1960
- // lives behind a data-centre prefix (us1, us19...) that only that call
1961
- // returns and every subsequent request needs in its host. No PKCE.
1953
+ // No PKCE. No scopes the docs describe none. And no refresh token: "Mailchimp
1954
+ // Marketing access tokens do not expire, so you don't need to use a
1955
+ // refresh_token", so tokenSettings stores no expiry and isStale reads that as
1956
+ // nothing to refresh toward.
1962
1957
  //
1963
- // Switching is filling in auth.oauth and moving the apiKey field out. It is
1964
- // still a publish -- a manifest change always is -- but a value change
1965
- // rather than a shape one.
1958
+ // auth.token stays false: the exchange is POST form-encoded with grant_type,
1959
+ // client_id, client_secret, redirect_uri and code, which is exactly the
1960
+ // runner's default nothing to wrap.
1966
1961
  auth : {
1967
- type : 'keys'
1962
+ oauth : {
1963
+ client : {
1964
+ id : 'MAILCHIMP_OAUTH_CLIENT_ID',
1965
+ secret : 'MAILCHIMP_OAUTH_CLIENT_SECRET'
1966
+ },
1967
+ urls : {
1968
+ authorize : 'https://login.mailchimp.com/oauth2/authorize',
1969
+ redirect : '/api/connection/mailchimp/callback',
1970
+ token : 'https://login.mailchimp.com/oauth2/token'
1971
+ }
1972
+ },
1973
+ type : 'oauth'
1968
1974
  },
1969
1975
  // EVERYTHING A MERCHANT READS. `errors` belongs in here rather than at the
1970
1976
  // top level because the connection DOCUMENT carries its own `errors` array
1971
1977
  // and the document is spread OVER the resolved manifest downstream — a
1972
1978
  // top-level one would be replaced by that array and never render.
1973
1979
  content : {
1974
- confirm : 'Disconnecting removes your stored Mailchimp key. Your contacts stay in both Drawbridge and Mailchimp — neither list is deleted.',
1980
+ 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 — neither list is deleted.',
1975
1981
  description : [
1976
1982
  'Drawbridge no longer sends email through Mailchimp. Notification email now sends from Drawbridge itself, and verifying a domain under Networking in your organization settings puts your own brand in the from line.',
1977
- 'This connection is becoming the way your Drawbridge contacts sync into a Mailchimp audience. Audience syncing is not live yet, so a key stored here does nothing today.'
1983
+ 'This connection is becoming the way your Drawbridge contacts sync into a Mailchimp audience. Audience syncing is not live yet, so connecting today does nothing except choose the audience it will use when it ships.'
1978
1984
  ],
1979
1985
  excerpt : 'Sync your Drawbridge contacts into a Mailchimp audience.',
1980
1986
  guide : [
1981
- 'In Mailchimp, open Account & billing, then Extras, then API keys.',
1982
- 'Create a key and copy it.',
1983
- 'Paste it here. The key ends in a data-centre suffix like -us19, which tells Drawbridge which Mailchimp server your account is on.'
1987
+ 'Press Connect. Drawbridge sends you to Mailchimp to approve access.',
1988
+ 'Sign in to Mailchimp if you are not already, and choose the account to connect.',
1989
+ 'You come back here to pick the audience your contacts should sync into.'
1984
1990
  ]
1985
1991
  },
1986
1992
  // Mailchimp and SendGrid shared a group while they were SENDERS, where an org
@@ -1990,15 +1996,6 @@ var mailchimp = {
1990
1996
  exclusive : false,
1991
1997
  feature : 'organization:connection:mailchimp',
1992
1998
  fields : [
1993
- {
1994
- input : 'password',
1995
- key : 'apiKey',
1996
- label : 'Mailchimp API key',
1997
- message : 'Your Mailchimp API key',
1998
- placeholder : '••••••••••••••••••••••••••••••••-us1',
1999
- redact : true,
2000
- required : true
2001
- },
2002
1999
  {
2003
2000
  input : 'select',
2004
2001
  key : 'audience',
@@ -2018,16 +2015,55 @@ var mailchimp = {
2018
2015
  hooks : {
2019
2016
 
2020
2017
  auth : {
2021
- // Implemented outside this package: storing a typed key needs no vendor
2022
- // call, so the api's own form handler does it.
2023
- connect : {},
2024
- disconnect : {},
2018
+ // WHERE THE ACCOUNT LIVES. Not enrichment without this the connection
2019
+ // is unusable, because the Marketing API host is per-account and only
2020
+ // this call knows it. The callback merges what this returns into the
2021
+ // stored settings, which is how `dc` reaches every later request.
2022
+ //
2023
+ // The header here is `OAuth <token>`, not Bearer — that is specific to
2024
+ // the metadata endpoint. Marketing API calls take Bearer; see the
2025
+ // audiences hook.
2026
+ connect : async ({ fetcher = fetch, tokens }) => {
2027
+
2028
+ const response = await fetcher( 'https://login.mailchimp.com/oauth2/metadata', {
2029
+ headers : {
2030
+ authorization : 'OAuth ' + tokens?.accessToken
2031
+ },
2032
+ signal : AbortSignal.timeout( 15000 )
2033
+ });
2034
+
2035
+ if( ! response.ok ){
2036
+
2037
+ throw Object.assign(
2038
+ new Error( 'Mailchimp would not say which data centre this account is on (' + response.status + ')' ),
2039
+ { status : response.status }
2040
+ );
2041
+
2042
+ }
2043
+
2044
+ const body = await response.json();
2045
+
2046
+ // No dc means no host to call. Failing here is better than storing a
2047
+ // connection that reads Active and 404s on its first request.
2048
+ if( ! body?.dc ) throw new Error( 'Mailchimp returned no data centre for this account' );
2049
+
2050
+ return { dc : body.dc };
2051
+
2052
+ },
2053
+ // Nothing to call. A merchant revokes Drawbridge from Mailchimp's own
2054
+ // Authorized Apps page; the docs describe no revocation endpoint for us
2055
+ // to call on their behalf.
2056
+ disconnect : false,
2025
2057
  probe : false,
2026
2058
  scopes : false,
2027
- // Keys today. When Mailchimp's OAuth lands this becomes a wrapper that
2028
- // follows the exchange with /oauth2/metadata the data-centre call that
2029
- // is the whole reason its OAuth cannot be pure configuration.
2030
- token : false
2059
+ // The plain exchange. Mailchimp takes the client as FORM FIELDS
2060
+ // (grant_type, client_id, client_secret, redirect_uri, code), which is
2061
+ // the runner's default so no `basic : true` as Klaviyo needs.
2062
+ //
2063
+ // build() requires an oauth manifest to name this explicitly rather than
2064
+ // letting it default, which caught this file declaring `false` on the
2065
+ // first import after the conversion.
2066
+ token : authToken
2031
2067
  },
2032
2068
  commerce : false,
2033
2069
  contacts : { remove : false, sync : false },
@@ -2050,18 +2086,21 @@ var mailchimp = {
2050
2086
  // successful — the same silent truncation Klaviyo has, at a different
2051
2087
  // number. Paged against total_items so an account past a thousand still
2052
2088
  // resolves.
2053
- audiences : async ({ cursor, fetcher = fetch, limit = 100, search, settings }) => {
2089
+ audiences : async ({ cursor, fetcher = fetch, limit = 100, search, settings, token }) => {
2054
2090
 
2055
- const key = settings?.apiKey;
2091
+ // Bearer, not Basic. Mailchimp's fundamentals doc states "API keys and
2092
+ // OAuth 2 tokens can be used to make authenticated requests the same
2093
+ // way", so one header serves both — the Basic form this used under
2094
+ // keys was never OAuth-compatible.
2095
+ const dc = settings?.dc;
2056
2096
 
2057
2097
  const count = Math.min( limit, 1000 );
2058
2098
  const offset = Number( cursor || 0 );
2059
2099
 
2060
2100
  const response = await fetcher(
2061
- base( key ) + '/lists?count=' + count + '&offset=' + offset + '&fields=lists.id,lists.name,total_items',
2101
+ base( dc ) + '/lists?count=' + count + '&offset=' + offset + '&fields=lists.id,lists.name,total_items',
2062
2102
  {
2063
- // Basic with any username Mailchimp reads only the password half.
2064
- headers : { authorization : 'Basic ' + Buffer.from( 'drawbridge:' + key ).toString( 'base64' ) },
2103
+ headers : { authorization : 'Bearer ' + token },
2065
2104
  signal : AbortSignal.timeout( 15000 )
2066
2105
  }
2067
2106
  );
@@ -2111,6 +2150,13 @@ var mailchimp = {
2111
2150
  webhook : false
2112
2151
  },
2113
2152
  icon: icon$1,
2153
+ // The OAuth client this deployment registered. Without both, the vendor drops
2154
+ // out of availableConnections rather than offering a Connect button that
2155
+ // cannot complete.
2156
+ requires : [
2157
+ 'MAILCHIMP_OAUTH_CLIENT_ID',
2158
+ 'MAILCHIMP_OAUTH_CLIENT_SECRET'
2159
+ ],
2114
2160
  slug : 'mailchimp',
2115
2161
  // A key with no audience chosen is authenticated and inert. Mailchimp also
2116
2162
  // needs its merge fields created on that audience before any Drawbridge total
@@ -2322,10 +2368,30 @@ var shopify = {
2322
2368
  // re-registers rather than answering "is this token still good", and
2323
2369
  // scope drift is its own hook because a token can be perfectly valid
2324
2370
  // while the grant is too narrow.
2325
- connect : {},
2326
- disconnect : {},
2371
+ //
2372
+ // connect and disconnect are FALSE rather than `{}`: there is nothing to
2373
+ // call on either side. The install already hands the callback everything
2374
+ // it stores, and a Shopify grant is withdrawn by UNINSTALLING the app in
2375
+ // Shopify admin — which Drawbridge learns about from the app_uninstalled
2376
+ // webhook rather than by asking. `{}` claimed a body implemented
2377
+ // elsewhere; none exists, and none could.
2378
+ connect : false,
2379
+ disconnect : false,
2327
2380
  probe : false,
2328
- scopes : {},
2381
+
2382
+ // WHETHER THE GRANT IS STILL WIDE ENOUGH. A token can be perfectly valid
2383
+ // and still too narrow — a deploy that adds a scope leaves every existing
2384
+ // install short of it, and no webhook fires to say so.
2385
+ //
2386
+ // The comparison is the vendor's, so it belongs here. Reading WHICH
2387
+ // scopes a store granted is not: that lives in the `shop` collection and
2388
+ // needs a controller, which is precisely what a hook in a published
2389
+ // package must not be handed. The caller reads the grant and passes the
2390
+ // string; this answers what is missing from it.
2391
+ //
2392
+ // `shopify` is injected for the same reason it is everywhere else — this
2393
+ // package cannot import @drawbridge/shopify, which depends on it.
2394
+ scopes : ({ scope, shopify }) => ( scope ? shopify.oauth.missingScopes( scope ) : null ),
2329
2395
  // Shopify's install grant is exchanged inside its own app flow, not
2330
2396
  // through the shared OAuth runner.
2331
2397
  token : false
@@ -2683,10 +2749,12 @@ var webhook = {
2683
2749
  // connect generates a secret rather than proving a credential.
2684
2750
  hooks : {
2685
2751
  auth : {
2686
- // Minting and clearing a secret needs no vendor call, so the api's own
2687
- // handler does both.
2688
- connect : {},
2689
- disconnect : {},
2752
+ // FALSE, NOT {}. There is no vendor here at all connecting mints a
2753
+ // secret and disconnecting clears it, both done by the api's own
2754
+ // handler. `{}` would promise a body implemented elsewhere, and none
2755
+ // exists or could.
2756
+ connect : false,
2757
+ disconnect : false,
2690
2758
  probe : false,
2691
2759
  scopes : false,
2692
2760
  // Nothing to mint. Connecting generates a secret; there is no vendor.
@@ -3250,7 +3318,6 @@ const stepLabels = ( catalog = connections ) => Object.fromEntries(
3250
3318
  const connections = Object.freeze({
3251
3319
  attentive : build( attentive ),
3252
3320
  drawbridge : build( drawbridge ),
3253
- hubspot : build( hubspot ),
3254
3321
  klaviyo : build( klaviyo ),
3255
3322
  mailchimp : build( mailchimp ),
3256
3323
  shopify : build( shopify ),