@drawbridge/drawbridge-utils 0.0.124 → 0.0.126
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 +138 -25
- package/dist/connections/index.d.cts +171 -15
- package/dist/connections/index.d.ts +171 -15
- package/dist/connections/index.js +132 -19
- package/dist/providers.cjs +135 -22
- package/dist/providers.js +129 -16
- package/package.json +1 -1
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { authToken } from './oauth.js';
|
|
2
2
|
export { consentUrl, pkcePair } from './oauth.js';
|
|
3
3
|
import { toE164, detectCountry } from '../phone.js';
|
|
4
|
+
import crypto, { createHmac, timingSafeEqual, createHash, randomUUID } from 'node:crypto';
|
|
4
5
|
import { request } from '../http.js';
|
|
5
6
|
import { channels } from '../pricing.js';
|
|
6
|
-
import crypto, { createHash, createHmac, timingSafeEqual, randomUUID } from 'node:crypto';
|
|
7
7
|
import { customAlphabet } from 'nanoid';
|
|
8
8
|
import { toCanonicalEmail } from '../email.js';
|
|
9
9
|
import { conversionRate } from '../plans.js';
|
|
@@ -282,7 +282,7 @@ const HOOK_EFFECTS = Object.freeze([ 'enqueues', 'events', 'writes' ]);
|
|
|
282
282
|
// The controller methods a described write may become. Only the two that a hook
|
|
283
283
|
// has ever needed — a deletion is a cascade, and cascades are owned by
|
|
284
284
|
// drawbridge-sync's streams rather than by a step.
|
|
285
|
-
const WRITE_OPERATIONS = Object.freeze([ 'create', 'update' ]);
|
|
285
|
+
const WRITE_OPERATIONS = Object.freeze([ 'create', 'delete', 'update' ]);
|
|
286
286
|
|
|
287
287
|
// READ A HOOK'S EFFECTS, or refuse them.
|
|
288
288
|
//
|
|
@@ -414,13 +414,15 @@ const effectsOf = ( answer ) => {
|
|
|
414
414
|
|
|
415
415
|
}
|
|
416
416
|
|
|
417
|
-
|
|
417
|
+
// A delete says WHICH, not WHAT — its query is its whole statement.
|
|
418
|
+
if( write.operation !== 'delete' && ! write?.data ) throw new Error( 'A described write on ' + write.collection + ' carries no data' );
|
|
418
419
|
|
|
419
|
-
// AN UPDATE WITH NO QUERY IS EVERY DOCUMENT IN THE COLLECTION.
|
|
420
|
-
// rather than survived, because the controller would happily
|
|
421
|
-
|
|
420
|
+
// AN UPDATE OR DELETE WITH NO QUERY IS EVERY DOCUMENT IN THE COLLECTION.
|
|
421
|
+
// Refused here rather than survived, because the controller would happily
|
|
422
|
+
// run it.
|
|
423
|
+
if( [ 'delete', 'update' ].includes( write.operation ) && ! write.query ){
|
|
422
424
|
|
|
423
|
-
throw new Error( 'A described
|
|
425
|
+
throw new Error( 'A described ' + write.operation + ' on ' + write.collection + ' has no query — that is every document in it' );
|
|
424
426
|
|
|
425
427
|
}
|
|
426
428
|
|
|
@@ -1233,7 +1235,11 @@ var attentive = {
|
|
|
1233
1235
|
|
|
1234
1236
|
},
|
|
1235
1237
|
// WHY, in the merchant's words, and what to do about it.
|
|
1236
|
-
|
|
1238
|
+
// ONLY FOR A LIVE GRANT. A disconnected or errored connection's next step
|
|
1239
|
+
// is reconnecting — prompting "choose a segment" there asks the merchant to
|
|
1240
|
+
// configure a grant that no longer exists. `pending` is exactly this task's
|
|
1241
|
+
// moment: the grant is good and the segment is the missing half.
|
|
1242
|
+
tasks : ( data ) => ( ! [ 'active', 'pending' ].includes( data?.status ) || data?.settings?.segment
|
|
1237
1243
|
? []
|
|
1238
1244
|
: [
|
|
1239
1245
|
{
|
|
@@ -1573,6 +1579,14 @@ var icon$3 = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xm
|
|
|
1573
1579
|
</defs>
|
|
1574
1580
|
</svg>`;
|
|
1575
1581
|
|
|
1582
|
+
// TWILIO'S OWN KEYWORD LISTS. STOP-family withdraws consent for the number —
|
|
1583
|
+
// platform-wide, because every organization sends from the same platform number,
|
|
1584
|
+
// so a withdrawal cannot be scoped narrower than the number it was sent to.
|
|
1585
|
+
// START-family re-subscribes. Anything else is a real reply and none of our
|
|
1586
|
+
// business.
|
|
1587
|
+
const STOP_KEYWORDS = [ 'STOP', 'STOPALL', 'UNSUBSCRIBE', 'CANCEL', 'END', 'QUIT' ];
|
|
1588
|
+
const START_KEYWORDS = [ 'START', 'UNSTOP', 'YES' ];
|
|
1589
|
+
|
|
1576
1590
|
// Drawbridge itself — the PRIVATE connection.
|
|
1577
1591
|
//
|
|
1578
1592
|
// Nobody connects this. There is no credential, no consent, and no card on the
|
|
@@ -1927,7 +1941,113 @@ var drawbridge = {
|
|
|
1927
1941
|
}
|
|
1928
1942
|
|
|
1929
1943
|
},
|
|
1930
|
-
|
|
1944
|
+
// INBOUND SMS to the platform number. Twilio's webhook, verified and
|
|
1945
|
+
// processed HERE — the manifest owns its own inbound, the same as every
|
|
1946
|
+
// other vendor, and the bespoke webhooks route + the handler that lived in
|
|
1947
|
+
// sync's buffer table are gone.
|
|
1948
|
+
inbound : {
|
|
1949
|
+
|
|
1950
|
+
// EVERY POST ON THIS CHANNEL IS AN INBOUND MESSAGE. Twilio sends no
|
|
1951
|
+
// topic header — the registered url IS the topic.
|
|
1952
|
+
event : () => 'message.inbound',
|
|
1953
|
+
|
|
1954
|
+
// STOP AND START, AS DESCRIBED WRITES. A withdrawn number is withdrawn
|
|
1955
|
+
// for everyone — organization : null is the platform floor canSend()
|
|
1956
|
+
// reads on every send path. $setOnInsert + upsert so webhook replays
|
|
1957
|
+
// and repeat STOPs collapse onto the unique { channel, address,
|
|
1958
|
+
// organization } index instead of erroring.
|
|
1959
|
+
process : ({ context }) => {
|
|
1960
|
+
|
|
1961
|
+
const keyword = String( context?.data?.Body || '' ).trim().toUpperCase();
|
|
1962
|
+
const address = toE164( context?.data?.From );
|
|
1963
|
+
|
|
1964
|
+
if( ! address ) return { message : 'Inbound SMS carried no usable sender number.', skipped : true };
|
|
1965
|
+
|
|
1966
|
+
if( STOP_KEYWORDS.includes( keyword ) ){
|
|
1967
|
+
|
|
1968
|
+
return {
|
|
1969
|
+
message : 'STOP recorded — ' + address + ' is suppressed on SMS everywhere.',
|
|
1970
|
+
request : { keyword },
|
|
1971
|
+
writes : [ {
|
|
1972
|
+
collection : 'suppression',
|
|
1973
|
+
data : {
|
|
1974
|
+
$setOnInsert : {
|
|
1975
|
+
address,
|
|
1976
|
+
channel : 'sms',
|
|
1977
|
+
organization : null,
|
|
1978
|
+
reason : keyword,
|
|
1979
|
+
source : 'stop'
|
|
1980
|
+
}
|
|
1981
|
+
},
|
|
1982
|
+
operation : 'update',
|
|
1983
|
+
options : { upsert : true },
|
|
1984
|
+
query : {
|
|
1985
|
+
address,
|
|
1986
|
+
channel : 'sms',
|
|
1987
|
+
organization : null
|
|
1988
|
+
}
|
|
1989
|
+
} ]
|
|
1990
|
+
};
|
|
1991
|
+
|
|
1992
|
+
}
|
|
1993
|
+
|
|
1994
|
+
if( START_KEYWORDS.includes( keyword ) ){
|
|
1995
|
+
|
|
1996
|
+
return {
|
|
1997
|
+
message : 'START recorded — ' + address + ' can receive SMS again.',
|
|
1998
|
+
request : { keyword },
|
|
1999
|
+
writes : [ {
|
|
2000
|
+
collection : 'suppression',
|
|
2001
|
+
operation : 'delete',
|
|
2002
|
+
query : {
|
|
2003
|
+
address,
|
|
2004
|
+
channel : 'sms',
|
|
2005
|
+
organization : null
|
|
2006
|
+
}
|
|
2007
|
+
} ]
|
|
2008
|
+
};
|
|
2009
|
+
|
|
2010
|
+
}
|
|
2011
|
+
|
|
2012
|
+
return { message : 'A real reply, not a keyword — nothing to record.', skipped : true };
|
|
2013
|
+
|
|
2014
|
+
},
|
|
2015
|
+
|
|
2016
|
+
receive : ({ payload }) => ({
|
|
2017
|
+
data : payload,
|
|
2018
|
+
provider : { id : payload?.MessageSid || null }
|
|
2019
|
+
}),
|
|
2020
|
+
|
|
2021
|
+
// TWILIO'S SCHEME, from docs.twilio.com/usage/security: take the full
|
|
2022
|
+
// registered url, sort the POST parameters alphabetically (Unix-style,
|
|
2023
|
+
// case-sensitive), append each name and value with no delimiters, sign
|
|
2024
|
+
// with HMAC-SHA1 keyed by the AuthToken, base64 — compared against
|
|
2025
|
+
// X-Twilio-Signature. It signs the URL rather than the raw body, which
|
|
2026
|
+
// is exactly why the shared body-HMAC verifier cannot cover it and this
|
|
2027
|
+
// hook exists.
|
|
2028
|
+
verify : ({ body, headers, secret, url }) => {
|
|
2029
|
+
|
|
2030
|
+
// OUR misconfiguration, never a forgery — a missing credential must
|
|
2031
|
+
// not be answered 401.
|
|
2032
|
+
if( ! secret ) throw Object.assign( new Error( 'Missing webhook secret: TWILIO_AUTH_TOKEN' ), { status : 500 });
|
|
2033
|
+
|
|
2034
|
+
const params = new URLSearchParams( String( body || '' ) );
|
|
2035
|
+
|
|
2036
|
+
const signed = url + [ ...params.keys() ].sort().map( ( key ) => key + params.get( key ) ).join( '' );
|
|
2037
|
+
|
|
2038
|
+
const expected = createHmac( 'sha1', secret ).update( signed ).digest( 'base64' );
|
|
2039
|
+
const provided = String( headers?.[ 'x-twilio-signature' ] || '' );
|
|
2040
|
+
|
|
2041
|
+
const matches = expected.length === provided.length
|
|
2042
|
+
&& timingSafeEqual( Buffer.from( expected ), Buffer.from( provided ) );
|
|
2043
|
+
|
|
2044
|
+
if( ! matches ) throw Object.assign( new Error( 'Invalid Twilio signature' ), { status : 401 });
|
|
2045
|
+
|
|
2046
|
+
return Object.fromEntries( params );
|
|
2047
|
+
|
|
2048
|
+
}
|
|
2049
|
+
|
|
2050
|
+
},
|
|
1931
2051
|
lifecycle : false,
|
|
1932
2052
|
resources : {
|
|
1933
2053
|
audiences : false,
|
|
@@ -2196,6 +2316,19 @@ var drawbridge = {
|
|
|
2196
2316
|
webhook : false
|
|
2197
2317
|
},
|
|
2198
2318
|
icon: icon$3,
|
|
2319
|
+
|
|
2320
|
+
// WHERE TWILIO PUTS THINGS on an inbound request, and WHICH credential
|
|
2321
|
+
// verifies it. `secret` names the drawbridge provider's smsToken — the route
|
|
2322
|
+
// resolves the name to the stored value and hands it to verify.
|
|
2323
|
+
inbound : {
|
|
2324
|
+
headers : {
|
|
2325
|
+
id : 'i-twilio-idempotency-token',
|
|
2326
|
+
signature : 'x-twilio-signature'
|
|
2327
|
+
},
|
|
2328
|
+
signature : {
|
|
2329
|
+
secret : 'TWILIO_AUTH_TOKEN'
|
|
2330
|
+
}
|
|
2331
|
+
},
|
|
2199
2332
|
// PRIVATE: never in the catalog, always available to the builder.
|
|
2200
2333
|
private : true,
|
|
2201
2334
|
// THE PLATFORM'S OWN SENDING CREDENTIALS — SendGrid, Twilio, and the internal
|
|
@@ -2959,7 +3092,11 @@ var klaviyo = {
|
|
|
2959
3092
|
|
|
2960
3093
|
},
|
|
2961
3094
|
// WHY, in the merchant's words, and what to do about it.
|
|
2962
|
-
|
|
3095
|
+
// ONLY FOR A LIVE GRANT. A disconnected or errored connection's next step
|
|
3096
|
+
// is reconnecting — prompting "choose a list" there asks the merchant to
|
|
3097
|
+
// configure a grant that no longer exists. `pending` is exactly this task's
|
|
3098
|
+
// moment: the grant is good and the list is the missing half.
|
|
3099
|
+
tasks : ( data ) => ( ! [ 'active', 'pending' ].includes( data?.status ) || data?.settings?.list
|
|
2963
3100
|
? []
|
|
2964
3101
|
: [
|
|
2965
3102
|
{
|
|
@@ -3089,7 +3226,7 @@ var mailchimp = {
|
|
|
3089
3226
|
content : {
|
|
3090
3227
|
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.',
|
|
3091
3228
|
description : [
|
|
3092
|
-
'Drawbridge no longer sends email through Mailchimp. Notification email now sends from Drawbridge itself, and verifying a domain under
|
|
3229
|
+
'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.',
|
|
3093
3230
|
'Connecting Mailchimp lets Drawbridge sync the contacts your campaigns collect into a Mailchimp audience, so the people who enter a giveaway can be marketed to alongside the rest of your list.',
|
|
3094
3231
|
'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.',
|
|
3095
3232
|
'Someone who unsubscribed inside Mailchimp keeps that choice: a resync only sets the status of a subscriber Mailchimp has never seen before.'
|
|
@@ -3392,7 +3529,11 @@ var mailchimp = {
|
|
|
3392
3529
|
|
|
3393
3530
|
},
|
|
3394
3531
|
// WHY, in the merchant's words, and what to do about it.
|
|
3395
|
-
|
|
3532
|
+
// ONLY FOR A LIVE GRANT. A disconnected or errored connection's next step
|
|
3533
|
+
// is reconnecting — prompting "choose a audience" there asks the merchant to
|
|
3534
|
+
// configure a grant that no longer exists. `pending` is exactly this task's
|
|
3535
|
+
// moment: the grant is good and the audience is the missing half.
|
|
3536
|
+
tasks : ( data ) => ( ! [ 'active', 'pending' ].includes( data?.status ) || data?.settings?.audience
|
|
3396
3537
|
? []
|
|
3397
3538
|
: [
|
|
3398
3539
|
{
|
|
@@ -5003,7 +5144,12 @@ var webhook = {
|
|
|
5003
5144
|
// pressing Connect will do; afterwards it states the verification the
|
|
5004
5145
|
// merchant's own endpoint has to perform, because a signed payload nobody
|
|
5005
5146
|
// checks is an unsigned payload.
|
|
5006
|
-
|
|
5147
|
+
// The connect prompt only where connecting is not already the card's whole
|
|
5148
|
+
// story: a disconnected or errored document renders a Connect action itself,
|
|
5149
|
+
// and a task repeating it talks over the button.
|
|
5150
|
+
tasks : ( { settings, status } = {} ) => ( [ 'disconnected', 'error' ].includes( status )
|
|
5151
|
+
? []
|
|
5152
|
+
: settings?.secret
|
|
5007
5153
|
? [
|
|
5008
5154
|
{
|
|
5009
5155
|
message : 'Compute HMAC-SHA256( secret, body ) and compare against the X-Drawbridge-Signature header to confirm each payload.',
|
|
@@ -5017,7 +5163,7 @@ var webhook = {
|
|
|
5017
5163
|
title : 'Webhook signing'
|
|
5018
5164
|
}
|
|
5019
5165
|
]
|
|
5020
|
-
|
|
5166
|
+
),
|
|
5021
5167
|
title : 'Webhooks'
|
|
5022
5168
|
};
|
|
5023
5169
|
|
|
@@ -5315,7 +5461,17 @@ const build = ( manifest ) => {
|
|
|
5315
5461
|
// A vendor that receives from the outside must say where it puts the event
|
|
5316
5462
|
// name. Without it the receiver has nothing to dispatch on, and the failure
|
|
5317
5463
|
// is a request accepted and dropped rather than an error.
|
|
5318
|
-
|
|
5464
|
+
//
|
|
5465
|
+
// A vendor may derive the event from the CHANNEL instead — Twilio sends no
|
|
5466
|
+
// topic header, so drawbridge's inbound.event is a constant and the
|
|
5467
|
+
// registered url is the topic. What is required is that SOMETHING names the
|
|
5468
|
+
// event: a declared header, or an event hook that answers without one. The
|
|
5469
|
+
// build cannot see inside the function, so the hook's existence is the
|
|
5470
|
+
// declaration — and a hook that returns nothing still fails at the route,
|
|
5471
|
+
// where a null event is refused before it is buffered.
|
|
5472
|
+
if( implemented( manifest.hooks, 'inbound.event' )
|
|
5473
|
+
&& typeof manifest.hooks?.inbound?.event !== 'function'
|
|
5474
|
+
&& ! manifest.inbound?.headers?.event ){
|
|
5319
5475
|
|
|
5320
5476
|
throw new Error( manifest.slug + ' implements inbound.event but declares no inbound.headers.event' );
|
|
5321
5477
|
|
|
@@ -177,7 +177,7 @@ var HOOKS = Object.freeze({
|
|
|
177
177
|
])
|
|
178
178
|
});
|
|
179
179
|
var HOOK_EFFECTS = Object.freeze(["enqueues", "events", "writes"]);
|
|
180
|
-
var WRITE_OPERATIONS = Object.freeze(["create", "update"]);
|
|
180
|
+
var WRITE_OPERATIONS = Object.freeze(["create", "delete", "update"]);
|
|
181
181
|
var HOOK_PROPS = Object.freeze([
|
|
182
182
|
"channel",
|
|
183
183
|
"clientId",
|
|
@@ -237,9 +237,9 @@ var effectsOf = (answer) => {
|
|
|
237
237
|
if (!WRITE_OPERATIONS.includes(write == null ? void 0 : write.operation)) {
|
|
238
238
|
throw new Error("A described write on " + write.collection + " needs an operation \u2014 one of " + WRITE_OPERATIONS.join(", "));
|
|
239
239
|
}
|
|
240
|
-
if (!(write == null ? void 0 : write.data)) throw new Error("A described write on " + write.collection + " carries no data");
|
|
241
|
-
if (
|
|
242
|
-
throw new Error("A described
|
|
240
|
+
if (write.operation !== "delete" && !(write == null ? void 0 : write.data)) throw new Error("A described write on " + write.collection + " carries no data");
|
|
241
|
+
if (["delete", "update"].includes(write.operation) && !write.query) {
|
|
242
|
+
throw new Error("A described " + write.operation + " on " + write.collection + " has no query \u2014 that is every document in it");
|
|
243
243
|
}
|
|
244
244
|
if (write.operation === "create" && write.query) {
|
|
245
245
|
throw new Error("A described create on " + write.collection + " carries a query \u2014 create does not filter");
|
|
@@ -819,9 +819,13 @@ var attentive_default2 = {
|
|
|
819
819
|
}
|
|
820
820
|
},
|
|
821
821
|
// WHY, in the merchant's words, and what to do about it.
|
|
822
|
+
// ONLY FOR A LIVE GRANT. A disconnected or errored connection's next step
|
|
823
|
+
// is reconnecting — prompting "choose a segment" there asks the merchant to
|
|
824
|
+
// configure a grant that no longer exists. `pending` is exactly this task's
|
|
825
|
+
// moment: the grant is good and the segment is the missing half.
|
|
822
826
|
tasks: (data2) => {
|
|
823
827
|
var _a;
|
|
824
|
-
return ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.segment) ? [] : [
|
|
828
|
+
return !["active", "pending"].includes(data2 == null ? void 0 : data2.status) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.segment) ? [] : [
|
|
825
829
|
{
|
|
826
830
|
message: "Choose which Attentive segment your contacts should sync into. Until you do, nothing is being synced.",
|
|
827
831
|
title: "Choose a segment"
|
|
@@ -831,6 +835,9 @@ var attentive_default2 = {
|
|
|
831
835
|
title: "Attentive"
|
|
832
836
|
};
|
|
833
837
|
|
|
838
|
+
// lib/connections/providers/drawbridge.js
|
|
839
|
+
import { createHmac, timingSafeEqual } from "crypto";
|
|
840
|
+
|
|
834
841
|
// lib/http.js
|
|
835
842
|
var DEFAULT_TIMEOUT_MS = 15e3;
|
|
836
843
|
var request = async ({
|
|
@@ -1657,6 +1664,8 @@ var channels = {
|
|
|
1657
1664
|
};
|
|
1658
1665
|
|
|
1659
1666
|
// lib/connections/providers/drawbridge.js
|
|
1667
|
+
var STOP_KEYWORDS = ["STOP", "STOPALL", "UNSUBSCRIBE", "CANCEL", "END", "QUIT"];
|
|
1668
|
+
var START_KEYWORDS = ["START", "UNSTOP", "YES"];
|
|
1660
1669
|
var interpolate = (template, data2) => {
|
|
1661
1670
|
if (!template) return template;
|
|
1662
1671
|
return template.replace(/\{\{(\w+)\}\}/g, (_, key) => (data2 == null ? void 0 : data2[key]) != null ? String(data2[key]) : "{{" + key + "}}");
|
|
@@ -1884,7 +1893,88 @@ var drawbridge_default2 = {
|
|
|
1884
1893
|
};
|
|
1885
1894
|
}
|
|
1886
1895
|
},
|
|
1887
|
-
|
|
1896
|
+
// INBOUND SMS to the platform number. Twilio's webhook, verified and
|
|
1897
|
+
// processed HERE — the manifest owns its own inbound, the same as every
|
|
1898
|
+
// other vendor, and the bespoke webhooks route + the handler that lived in
|
|
1899
|
+
// sync's buffer table are gone.
|
|
1900
|
+
inbound: {
|
|
1901
|
+
// EVERY POST ON THIS CHANNEL IS AN INBOUND MESSAGE. Twilio sends no
|
|
1902
|
+
// topic header — the registered url IS the topic.
|
|
1903
|
+
event: () => "message.inbound",
|
|
1904
|
+
// STOP AND START, AS DESCRIBED WRITES. A withdrawn number is withdrawn
|
|
1905
|
+
// for everyone — organization : null is the platform floor canSend()
|
|
1906
|
+
// reads on every send path. $setOnInsert + upsert so webhook replays
|
|
1907
|
+
// and repeat STOPs collapse onto the unique { channel, address,
|
|
1908
|
+
// organization } index instead of erroring.
|
|
1909
|
+
process: ({ context }) => {
|
|
1910
|
+
var _a, _b;
|
|
1911
|
+
const keyword = String(((_a = context == null ? void 0 : context.data) == null ? void 0 : _a.Body) || "").trim().toUpperCase();
|
|
1912
|
+
const address = toE164((_b = context == null ? void 0 : context.data) == null ? void 0 : _b.From);
|
|
1913
|
+
if (!address) return { message: "Inbound SMS carried no usable sender number.", skipped: true };
|
|
1914
|
+
if (STOP_KEYWORDS.includes(keyword)) {
|
|
1915
|
+
return {
|
|
1916
|
+
message: "STOP recorded \u2014 " + address + " is suppressed on SMS everywhere.",
|
|
1917
|
+
request: { keyword },
|
|
1918
|
+
writes: [{
|
|
1919
|
+
collection: "suppression",
|
|
1920
|
+
data: {
|
|
1921
|
+
$setOnInsert: {
|
|
1922
|
+
address,
|
|
1923
|
+
channel: "sms",
|
|
1924
|
+
organization: null,
|
|
1925
|
+
reason: keyword,
|
|
1926
|
+
source: "stop"
|
|
1927
|
+
}
|
|
1928
|
+
},
|
|
1929
|
+
operation: "update",
|
|
1930
|
+
options: { upsert: true },
|
|
1931
|
+
query: {
|
|
1932
|
+
address,
|
|
1933
|
+
channel: "sms",
|
|
1934
|
+
organization: null
|
|
1935
|
+
}
|
|
1936
|
+
}]
|
|
1937
|
+
};
|
|
1938
|
+
}
|
|
1939
|
+
if (START_KEYWORDS.includes(keyword)) {
|
|
1940
|
+
return {
|
|
1941
|
+
message: "START recorded \u2014 " + address + " can receive SMS again.",
|
|
1942
|
+
request: { keyword },
|
|
1943
|
+
writes: [{
|
|
1944
|
+
collection: "suppression",
|
|
1945
|
+
operation: "delete",
|
|
1946
|
+
query: {
|
|
1947
|
+
address,
|
|
1948
|
+
channel: "sms",
|
|
1949
|
+
organization: null
|
|
1950
|
+
}
|
|
1951
|
+
}]
|
|
1952
|
+
};
|
|
1953
|
+
}
|
|
1954
|
+
return { message: "A real reply, not a keyword \u2014 nothing to record.", skipped: true };
|
|
1955
|
+
},
|
|
1956
|
+
receive: ({ payload }) => ({
|
|
1957
|
+
data: payload,
|
|
1958
|
+
provider: { id: (payload == null ? void 0 : payload.MessageSid) || null }
|
|
1959
|
+
}),
|
|
1960
|
+
// TWILIO'S SCHEME, from docs.twilio.com/usage/security: take the full
|
|
1961
|
+
// registered url, sort the POST parameters alphabetically (Unix-style,
|
|
1962
|
+
// case-sensitive), append each name and value with no delimiters, sign
|
|
1963
|
+
// with HMAC-SHA1 keyed by the AuthToken, base64 — compared against
|
|
1964
|
+
// X-Twilio-Signature. It signs the URL rather than the raw body, which
|
|
1965
|
+
// is exactly why the shared body-HMAC verifier cannot cover it and this
|
|
1966
|
+
// hook exists.
|
|
1967
|
+
verify: ({ body, headers, secret, url }) => {
|
|
1968
|
+
if (!secret) throw Object.assign(new Error("Missing webhook secret: TWILIO_AUTH_TOKEN"), { status: 500 });
|
|
1969
|
+
const params = new URLSearchParams(String(body || ""));
|
|
1970
|
+
const signed = url + [...params.keys()].sort().map((key) => key + params.get(key)).join("");
|
|
1971
|
+
const expected = createHmac("sha1", secret).update(signed).digest("base64");
|
|
1972
|
+
const provided = String((headers == null ? void 0 : headers["x-twilio-signature"]) || "");
|
|
1973
|
+
const matches = expected.length === provided.length && timingSafeEqual(Buffer.from(expected), Buffer.from(provided));
|
|
1974
|
+
if (!matches) throw Object.assign(new Error("Invalid Twilio signature"), { status: 401 });
|
|
1975
|
+
return Object.fromEntries(params);
|
|
1976
|
+
}
|
|
1977
|
+
},
|
|
1888
1978
|
lifecycle: false,
|
|
1889
1979
|
resources: {
|
|
1890
1980
|
audiences: false,
|
|
@@ -2063,6 +2153,18 @@ var drawbridge_default2 = {
|
|
|
2063
2153
|
webhook: false
|
|
2064
2154
|
},
|
|
2065
2155
|
icon: drawbridge_default,
|
|
2156
|
+
// WHERE TWILIO PUTS THINGS on an inbound request, and WHICH credential
|
|
2157
|
+
// verifies it. `secret` names the drawbridge provider's smsToken — the route
|
|
2158
|
+
// resolves the name to the stored value and hands it to verify.
|
|
2159
|
+
inbound: {
|
|
2160
|
+
headers: {
|
|
2161
|
+
id: "i-twilio-idempotency-token",
|
|
2162
|
+
signature: "x-twilio-signature"
|
|
2163
|
+
},
|
|
2164
|
+
signature: {
|
|
2165
|
+
secret: "TWILIO_AUTH_TOKEN"
|
|
2166
|
+
}
|
|
2167
|
+
},
|
|
2066
2168
|
// PRIVATE: never in the catalog, always available to the builder.
|
|
2067
2169
|
private: true,
|
|
2068
2170
|
// THE PLATFORM'S OWN SENDING CREDENTIALS — SendGrid, Twilio, and the internal
|
|
@@ -2678,9 +2780,13 @@ var klaviyo_default2 = {
|
|
|
2678
2780
|
}
|
|
2679
2781
|
},
|
|
2680
2782
|
// WHY, in the merchant's words, and what to do about it.
|
|
2783
|
+
// ONLY FOR A LIVE GRANT. A disconnected or errored connection's next step
|
|
2784
|
+
// is reconnecting — prompting "choose a list" there asks the merchant to
|
|
2785
|
+
// configure a grant that no longer exists. `pending` is exactly this task's
|
|
2786
|
+
// moment: the grant is good and the list is the missing half.
|
|
2681
2787
|
tasks: (data2) => {
|
|
2682
2788
|
var _a;
|
|
2683
|
-
return ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.list) ? [] : [
|
|
2789
|
+
return !["active", "pending"].includes(data2 == null ? void 0 : data2.status) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.list) ? [] : [
|
|
2684
2790
|
{
|
|
2685
2791
|
message: "Choose which Klaviyo list your contacts should sync into. Until you do, nothing is being synced.",
|
|
2686
2792
|
title: "Choose a list"
|
|
@@ -2765,7 +2871,7 @@ var mailchimp_default2 = {
|
|
|
2765
2871
|
content: {
|
|
2766
2872
|
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.",
|
|
2767
2873
|
description: [
|
|
2768
|
-
"Drawbridge no longer sends email through Mailchimp. Notification email now sends from Drawbridge itself, and verifying a domain under
|
|
2874
|
+
"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.",
|
|
2769
2875
|
"Connecting Mailchimp lets Drawbridge sync the contacts your campaigns collect into a Mailchimp audience, so the people who enter a giveaway can be marketed to alongside the rest of your list.",
|
|
2770
2876
|
"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.",
|
|
2771
2877
|
"Someone who unsubscribed inside Mailchimp keeps that choice: a resync only sets the status of a subscriber Mailchimp has never seen before."
|
|
@@ -2993,9 +3099,13 @@ var mailchimp_default2 = {
|
|
|
2993
3099
|
}
|
|
2994
3100
|
},
|
|
2995
3101
|
// WHY, in the merchant's words, and what to do about it.
|
|
3102
|
+
// ONLY FOR A LIVE GRANT. A disconnected or errored connection's next step
|
|
3103
|
+
// is reconnecting — prompting "choose a audience" there asks the merchant to
|
|
3104
|
+
// configure a grant that no longer exists. `pending` is exactly this task's
|
|
3105
|
+
// moment: the grant is good and the audience is the missing half.
|
|
2996
3106
|
tasks: (data2) => {
|
|
2997
3107
|
var _a;
|
|
2998
|
-
return ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.audience) ? [] : [
|
|
3108
|
+
return !["active", "pending"].includes(data2 == null ? void 0 : data2.status) || ((_a = data2 == null ? void 0 : data2.settings) == null ? void 0 : _a.audience) ? [] : [
|
|
2999
3109
|
{
|
|
3000
3110
|
message: "Choose which Mailchimp audience your contacts should sync into. Until you do, nothing is being synced.",
|
|
3001
3111
|
title: "Choose an audience"
|
|
@@ -3017,7 +3127,7 @@ var shopify_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill=
|
|
|
3017
3127
|
</svg>`;
|
|
3018
3128
|
|
|
3019
3129
|
// lib/connections/inbound.js
|
|
3020
|
-
import { createHmac, timingSafeEqual } from "crypto";
|
|
3130
|
+
import { createHmac as createHmac2, timingSafeEqual as timingSafeEqual2 } from "crypto";
|
|
3021
3131
|
var verifySignature = ({ body, descriptor, headers, secret }) => {
|
|
3022
3132
|
if (!secret) {
|
|
3023
3133
|
throw Object.assign(new Error("Missing webhook secret: " + descriptor.signature.secret), { status: 500 });
|
|
@@ -3026,10 +3136,10 @@ var verifySignature = ({ body, descriptor, headers, secret }) => {
|
|
|
3026
3136
|
if (!provided) {
|
|
3027
3137
|
throw Object.assign(new Error("Missing webhook signature"), { status: 401 });
|
|
3028
3138
|
}
|
|
3029
|
-
const digest =
|
|
3139
|
+
const digest = createHmac2(descriptor.signature.algorithm, secret).update(body).digest(descriptor.signature.encoding);
|
|
3030
3140
|
const digestBuffer = Buffer.from(digest, descriptor.signature.encoding);
|
|
3031
3141
|
const providedBuffer = Buffer.from(provided, descriptor.signature.encoding);
|
|
3032
|
-
if (digestBuffer.length !== providedBuffer.length || !
|
|
3142
|
+
if (digestBuffer.length !== providedBuffer.length || !timingSafeEqual2(digestBuffer, providedBuffer)) {
|
|
3033
3143
|
throw Object.assign(new Error("Invalid webhook signature"), { status: 401 });
|
|
3034
3144
|
}
|
|
3035
3145
|
return JSON.parse(body.toString());
|
|
@@ -4333,7 +4443,10 @@ var webhook_default = {
|
|
|
4333
4443
|
// pressing Connect will do; afterwards it states the verification the
|
|
4334
4444
|
// merchant's own endpoint has to perform, because a signed payload nobody
|
|
4335
4445
|
// checks is an unsigned payload.
|
|
4336
|
-
|
|
4446
|
+
// The connect prompt only where connecting is not already the card's whole
|
|
4447
|
+
// story: a disconnected or errored document renders a Connect action itself,
|
|
4448
|
+
// and a task repeating it talks over the button.
|
|
4449
|
+
tasks: ({ settings, status } = {}) => ["disconnected", "error"].includes(status) ? [] : (settings == null ? void 0 : settings.secret) ? [
|
|
4337
4450
|
{
|
|
4338
4451
|
message: "Compute HMAC-SHA256( secret, body ) and compare against the X-Drawbridge-Signature header to confirm each payload.",
|
|
4339
4452
|
title: "Requests must be verified",
|
|
@@ -4358,7 +4471,7 @@ var leaves = (node, path = []) => Object.entries(node || {}).flatMap(
|
|
|
4358
4471
|
([key, value]) => typeof value === "function" ? [[[...path, key].join("."), value]] : value && typeof value === "object" ? leaves(value, [...path, key]) : []
|
|
4359
4472
|
);
|
|
4360
4473
|
var build = (manifest) => {
|
|
4361
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
4474
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
|
|
4362
4475
|
if (!(manifest == null ? void 0 : manifest.slug)) throw new Error("A connection needs a slug");
|
|
4363
4476
|
if (!(manifest == null ? void 0 : manifest.title)) throw new Error(manifest.slug + " needs a title");
|
|
4364
4477
|
if (!(manifest == null ? void 0 : manifest.private) && !(manifest == null ? void 0 : manifest.feature)) throw new Error(manifest.slug + " needs a plan feature key");
|
|
@@ -4437,16 +4550,16 @@ var build = (manifest) => {
|
|
|
4437
4550
|
);
|
|
4438
4551
|
}
|
|
4439
4552
|
}
|
|
4440
|
-
if (implemented(manifest.hooks, "inbound.event") &&
|
|
4553
|
+
if (implemented(manifest.hooks, "inbound.event") && typeof ((_l = (_k = manifest.hooks) == null ? void 0 : _k.inbound) == null ? void 0 : _l.event) !== "function" && !((_n = (_m = manifest.inbound) == null ? void 0 : _m.headers) == null ? void 0 : _n.event)) {
|
|
4441
4554
|
throw new Error(manifest.slug + " implements inbound.event but declares no inbound.headers.event");
|
|
4442
4555
|
}
|
|
4443
|
-
if (implemented(manifest.hooks, "inbound.verify") && !((
|
|
4556
|
+
if (implemented(manifest.hooks, "inbound.verify") && !((_p = (_o = manifest.inbound) == null ? void 0 : _o.headers) == null ? void 0 : _p.signature)) {
|
|
4444
4557
|
throw new Error(manifest.slug + " implements inbound.verify but declares no inbound.headers.signature");
|
|
4445
4558
|
}
|
|
4446
4559
|
if (typeof (manifest == null ? void 0 : manifest.status) !== "function") {
|
|
4447
4560
|
throw new Error(manifest.slug + " must declare status( data ) \u2014 return null to accept the connection's own status, or { message, status } to override it");
|
|
4448
4561
|
}
|
|
4449
|
-
if (!Array.isArray((
|
|
4562
|
+
if (!Array.isArray((_q = manifest == null ? void 0 : manifest.content) == null ? void 0 : _q.guide) || !manifest.content.guide.length) {
|
|
4450
4563
|
throw new Error(manifest.slug + " needs content.guide \u2014 an array of steps for its page");
|
|
4451
4564
|
}
|
|
4452
4565
|
if (typeof (manifest == null ? void 0 : manifest.status) !== "function") {
|
|
@@ -4458,8 +4571,8 @@ var build = (manifest) => {
|
|
|
4458
4571
|
}
|
|
4459
4572
|
for (const [domain, verbs] of Object.entries(HOOKS)) {
|
|
4460
4573
|
for (const verb of verbs) {
|
|
4461
|
-
const hook = (
|
|
4462
|
-
if (((
|
|
4574
|
+
const hook = (_s = (_r = manifest.hooks) == null ? void 0 : _r[domain]) == null ? void 0 : _s[verb];
|
|
4575
|
+
if (((_t = manifest.hooks) == null ? void 0 : _t[domain]) === false) continue;
|
|
4463
4576
|
if (hook !== false && !implemented({ [domain]: { [verb]: hook } }, domain + "." + verb)) {
|
|
4464
4577
|
throw new Error(manifest.slug + " must answer hooks." + domain + "." + verb + " \u2014 false, a function, or {} if another repo implements it");
|
|
4465
4578
|
}
|