@drawbridge/drawbridge-utils 0.0.158 → 0.0.160

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/pricing.cjs CHANGED
@@ -490,7 +490,6 @@ var organization = {
490
490
 
491
491
  // index.js
492
492
  var import_currency_codes = require("currency-codes");
493
- var import_nanoid = require("nanoid");
494
493
 
495
494
  // lib/color.js
496
495
  var import_tinycolor2 = __toESM(require("tinycolor2"), 1);
@@ -553,8 +552,11 @@ var style = {
553
552
  }
554
553
  };
555
554
 
555
+ // lib/nanoid.js
556
+ var import_nanoid = require("nanoid");
557
+ var generate = (0, import_nanoid.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 8);
558
+
556
559
  // index.js
557
- var nanoid = (0, import_nanoid.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 8);
558
560
  var infinite = 1e300;
559
561
  var megabyte = 1024 * 1024;
560
562
  var gigabyte = megabyte * 1024;
@@ -7,9 +7,10 @@ import './usage.cjs';
7
7
  import './features.cjs';
8
8
  import './index.cjs';
9
9
  import 'currency-codes';
10
- import 'nanoid';
11
10
  import './color.cjs';
12
11
  import 'tinycolor2';
12
+ import './nanoid.cjs';
13
+ import 'nanoid';
13
14
 
14
15
  // Pricing — the one file you open to see every customer-facing number.
15
16
  //
package/dist/pricing.d.ts CHANGED
@@ -7,9 +7,10 @@ import './usage.js';
7
7
  import './features.js';
8
8
  import './index.js';
9
9
  import 'currency-codes';
10
- import 'nanoid';
11
10
  import './color.js';
12
11
  import 'tinycolor2';
12
+ import './nanoid.js';
13
+ import 'nanoid';
13
14
 
14
15
  // Pricing — the one file you open to see every customer-facing number.
15
16
  //
package/dist/pricing.js CHANGED
@@ -438,7 +438,6 @@ var organization = {
438
438
 
439
439
  // index.js
440
440
  import { code, data } from "currency-codes";
441
- import { customAlphabet } from "nanoid";
442
441
 
443
442
  // lib/color.js
444
443
  import tinycolor from "tinycolor2";
@@ -501,8 +500,11 @@ var style = {
501
500
  }
502
501
  };
503
502
 
503
+ // lib/nanoid.js
504
+ import { customAlphabet } from "nanoid";
505
+ var generate = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 8);
506
+
504
507
  // index.js
505
- var nanoid = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 8);
506
508
  var infinite = 1e300;
507
509
  var megabyte = 1024 * 1024;
508
510
  var gigabyte = megabyte * 1024;
@@ -1356,7 +1356,6 @@ var organization = {
1356
1356
 
1357
1357
  // index.js
1358
1358
  var import_currency_codes = require("currency-codes");
1359
- var import_nanoid = require("nanoid");
1360
1359
 
1361
1360
  // lib/color.js
1362
1361
  var import_tinycolor2 = __toESM(require("tinycolor2"), 1);
@@ -1419,8 +1418,11 @@ var style = {
1419
1418
  }
1420
1419
  };
1421
1420
 
1421
+ // lib/nanoid.js
1422
+ var import_nanoid = require("nanoid");
1423
+ var generate = (0, import_nanoid.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 8);
1424
+
1422
1425
  // index.js
1423
- var nanoid = (0, import_nanoid.customAlphabet)("0123456789abcdefghijklmnopqrstuvwxyz", 8);
1424
1426
  var infinite = 1e300;
1425
1427
  var megabyte = 1024 * 1024;
1426
1428
  var gigabyte = megabyte * 1024;
@@ -2171,11 +2173,11 @@ var drawbridge_default2 = {
2171
2173
  // and repeat STOPs collapse onto the unique { channel, address,
2172
2174
  // organization } index instead of erroring.
2173
2175
  process: ({ context }) => {
2174
- var _a, _b;
2175
- if ((context == null ? void 0 : context.topic) === "email.events") return summariseEvents(context == null ? void 0 : context.data);
2176
+ var _a, _b, _c;
2177
+ if ((context == null ? void 0 : context.topic) === "email.events") return summariseEvents((_a = context == null ? void 0 : context.data) == null ? void 0 : _a.events);
2176
2178
  if ((context == null ? void 0 : context.topic) === "sms.status") return statusCallback(context == null ? void 0 : context.data);
2177
- const keyword = String(((_a = context == null ? void 0 : context.data) == null ? void 0 : _a.Body) || "").trim().toUpperCase();
2178
- const address = toE164((_b = context == null ? void 0 : context.data) == null ? void 0 : _b.From);
2179
+ const keyword = String(((_b = context == null ? void 0 : context.data) == null ? void 0 : _b.Body) || "").trim().toUpperCase();
2180
+ const address = toE164((_c = context == null ? void 0 : context.data) == null ? void 0 : _c.From);
2179
2181
  if (!address) return { message: "Inbound SMS carried no usable sender number.", skipped: true };
2180
2182
  if (STOP_KEYWORDS.includes(keyword)) {
2181
2183
  return {
@@ -2224,8 +2226,18 @@ var drawbridge_default2 = {
2224
2226
  // acceptable because SendGrid only retries a non-2xx, and the cost of a
2225
2227
  // duplicate here is a second buffer row rather than a repeated side
2226
2228
  // effect. Revisit if this ever writes suppressions.
2229
+ //
2230
+ // THE BATCH IS WRAPPED, and it has to be. SendGrid posts a JSON ARRAY
2231
+ // where every other vendor posts an object, and drawbridge-api's
2232
+ // schema/buffer.js declares `data : { bsonType : 'object' }` — which in
2233
+ // JSON Schema does NOT match an array. Writing the array raw fails
2234
+ // validation, answers 500, and puts SendGrid into a retry loop for a
2235
+ // webhook we would never accept.
2236
+ //
2237
+ // Wrapped here rather than widening the schema: `data` stays one shape
2238
+ // for every consumer, and the vendor that is odd carries the oddity.
2227
2239
  receive: ({ channel, payload }) => ({
2228
- data: payload,
2240
+ data: channel === "email" ? { events: payload } : payload,
2229
2241
  provider: { id: channel === "email" ? null : (payload == null ? void 0 : payload.MessageSid) || null }
2230
2242
  }),
2231
2243
  // TWILIO'S SCHEME, from docs.twilio.com/usage/security: take the full
@@ -2560,8 +2572,8 @@ var drawbridge_default2 = {
2560
2572
  // owner is not a member document, so a solo merchant has nothing to
2561
2573
  // pick and could never save the step.
2562
2574
  members: { of: "string", type: "array" },
2563
- message: { required: true, type: "string" },
2564
- subject: { required: true, type: "string" }
2575
+ message: { max: 2e3, required: true, type: "string" },
2576
+ subject: { max: 150, required: true, type: "string" }
2565
2577
  },
2566
2578
  triggers: ["schedule.day", "schedule.week", "schedule.month"],
2567
2579
  usage: { actions: 0 }
@@ -2584,8 +2596,8 @@ var drawbridge_default2 = {
2584
2596
  queue: "notification",
2585
2597
  settings: {
2586
2598
  members: { of: "string", type: "array" },
2587
- message: { type: "string" },
2588
- subject: { type: "string" }
2599
+ message: { max: 2e3, type: "string" },
2600
+ subject: { max: 150, type: "string" }
2589
2601
  },
2590
2602
  triggers: ["lead.insert"],
2591
2603
  // Zero is a PRICE, and a deliberate one. Declared rather than omitted
@@ -2599,8 +2611,8 @@ var drawbridge_default2 = {
2599
2611
  key: "Email \u2014 Send email",
2600
2612
  queue: "notification",
2601
2613
  settings: {
2602
- message: { required: true, type: "string" },
2603
- subject: { required: true, type: "string" }
2614
+ message: { max: 2e3, required: true, type: "string" },
2615
+ subject: { max: 150, required: true, type: "string" }
2604
2616
  },
2605
2617
  triggers: ["lead.insert"],
2606
2618
  // ONE SOURCE FOR THE PRICE. lib/pricing.js is the index of every
@@ -2629,8 +2641,8 @@ var drawbridge_default2 = {
2629
2641
  key: "Send an SMS",
2630
2642
  queue: "notification",
2631
2643
  settings: {
2632
- message: { required: true, type: "string" },
2633
- subject: { required: true, type: "string" }
2644
+ message: { max: 1600, required: true, type: "string" },
2645
+ subject: { max: 150, required: true, type: "string" }
2634
2646
  },
2635
2647
  // Priced per SEGMENT and billed from the first, which the send
2636
2648
  // resolves from the message length. This is the floor.
@@ -3593,7 +3605,7 @@ var mailchimp_default2 = {
3593
3605
 
3594
3606
  // lib/connections/providers/shopify.js
3595
3607
  var import_node_crypto5 = require("crypto");
3596
- var import_nanoid2 = require("nanoid");
3608
+ var import_nanoid3 = require("nanoid");
3597
3609
 
3598
3610
  // lib/connections/icons/shopify.js
3599
3611
  var shopify_default = `<svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
@@ -3623,7 +3635,7 @@ var import_crypto2 = __toESM(require("crypto"), 1);
3623
3635
 
3624
3636
  // lib/token.js
3625
3637
  var import_crypto = __toESM(require("crypto"), 1);
3626
- var generate = (bytes = 32, encoding = "base64url") => {
3638
+ var generate2 = (bytes = 32, encoding = "base64url") => {
3627
3639
  const buf = import_crypto.default.randomBytes(bytes);
3628
3640
  return encoding ? buf.toString(encoding) : buf;
3629
3641
  };
@@ -3632,7 +3644,7 @@ var generate = (bytes = 32, encoding = "base64url") => {
3632
3644
  var ALGORITHM = "aes-256-gcm";
3633
3645
  var getKey = () => Buffer.from(process.env.ENCRYPT_CONNECTION_SECRET, "hex");
3634
3646
  var encrypt = (value) => {
3635
- const iv = generate(12, null);
3647
+ const iv = generate2(12, null);
3636
3648
  const cipher = import_crypto2.default.createCipheriv(ALGORITHM, getKey(), iv);
3637
3649
  const data2 = Buffer.concat([
3638
3650
  cipher.update(JSON.stringify(value), "utf8"),
@@ -3707,7 +3719,7 @@ var attributeLineItems = (lineItems = []) => lineItems.reduce(
3707
3719
  },
3708
3720
  { attrMap: {}, attributedGross: 0, attributedLines: [] }
3709
3721
  );
3710
- var generateDiscountCode = (0, import_nanoid2.customAlphabet)("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 8);
3722
+ var generateDiscountCode = (0, import_nanoid3.customAlphabet)("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", 8);
3711
3723
  var ORDER_EVENT_HANDLE = slugify("drawbridge-orders");
3712
3724
  var REFRESH_TOKEN_FRESHNESS_BUFFER_MS = 5 * 24 * 60 * 60 * 1e3;
3713
3725
  var OAUTH_ERROR_SOURCE = "oauth";
@@ -15,9 +15,10 @@ import './plans.cjs';
15
15
  import './features.cjs';
16
16
  import './index.cjs';
17
17
  import 'currency-codes';
18
- import 'nanoid';
19
18
  import './color.cjs';
20
19
  import 'tinycolor2';
20
+ import './nanoid.cjs';
21
+ import 'nanoid';
21
22
  import './email.cjs';
22
23
  import './safe-http.cjs';
23
24
  import 'dns';
@@ -15,9 +15,10 @@ import './plans.js';
15
15
  import './features.js';
16
16
  import './index.js';
17
17
  import 'currency-codes';
18
- import 'nanoid';
19
18
  import './color.js';
20
19
  import 'tinycolor2';
20
+ import './nanoid.js';
21
+ import 'nanoid';
21
22
  import './email.js';
22
23
  import './safe-http.js';
23
24
  import 'dns';
package/dist/providers.js CHANGED
@@ -1310,7 +1310,6 @@ var organization = {
1310
1310
 
1311
1311
  // index.js
1312
1312
  import { code, data } from "currency-codes";
1313
- import { customAlphabet } from "nanoid";
1314
1313
 
1315
1314
  // lib/color.js
1316
1315
  import tinycolor from "tinycolor2";
@@ -1373,8 +1372,11 @@ var style = {
1373
1372
  }
1374
1373
  };
1375
1374
 
1375
+ // lib/nanoid.js
1376
+ import { customAlphabet } from "nanoid";
1377
+ var generate = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 8);
1378
+
1376
1379
  // index.js
1377
- var nanoid = customAlphabet("0123456789abcdefghijklmnopqrstuvwxyz", 8);
1378
1380
  var infinite = 1e300;
1379
1381
  var megabyte = 1024 * 1024;
1380
1382
  var gigabyte = megabyte * 1024;
@@ -2125,11 +2127,11 @@ var drawbridge_default2 = {
2125
2127
  // and repeat STOPs collapse onto the unique { channel, address,
2126
2128
  // organization } index instead of erroring.
2127
2129
  process: ({ context }) => {
2128
- var _a, _b;
2129
- if ((context == null ? void 0 : context.topic) === "email.events") return summariseEvents(context == null ? void 0 : context.data);
2130
+ var _a, _b, _c;
2131
+ if ((context == null ? void 0 : context.topic) === "email.events") return summariseEvents((_a = context == null ? void 0 : context.data) == null ? void 0 : _a.events);
2130
2132
  if ((context == null ? void 0 : context.topic) === "sms.status") return statusCallback(context == null ? void 0 : context.data);
2131
- const keyword = String(((_a = context == null ? void 0 : context.data) == null ? void 0 : _a.Body) || "").trim().toUpperCase();
2132
- const address = toE164((_b = context == null ? void 0 : context.data) == null ? void 0 : _b.From);
2133
+ const keyword = String(((_b = context == null ? void 0 : context.data) == null ? void 0 : _b.Body) || "").trim().toUpperCase();
2134
+ const address = toE164((_c = context == null ? void 0 : context.data) == null ? void 0 : _c.From);
2133
2135
  if (!address) return { message: "Inbound SMS carried no usable sender number.", skipped: true };
2134
2136
  if (STOP_KEYWORDS.includes(keyword)) {
2135
2137
  return {
@@ -2178,8 +2180,18 @@ var drawbridge_default2 = {
2178
2180
  // acceptable because SendGrid only retries a non-2xx, and the cost of a
2179
2181
  // duplicate here is a second buffer row rather than a repeated side
2180
2182
  // effect. Revisit if this ever writes suppressions.
2183
+ //
2184
+ // THE BATCH IS WRAPPED, and it has to be. SendGrid posts a JSON ARRAY
2185
+ // where every other vendor posts an object, and drawbridge-api's
2186
+ // schema/buffer.js declares `data : { bsonType : 'object' }` — which in
2187
+ // JSON Schema does NOT match an array. Writing the array raw fails
2188
+ // validation, answers 500, and puts SendGrid into a retry loop for a
2189
+ // webhook we would never accept.
2190
+ //
2191
+ // Wrapped here rather than widening the schema: `data` stays one shape
2192
+ // for every consumer, and the vendor that is odd carries the oddity.
2181
2193
  receive: ({ channel, payload }) => ({
2182
- data: payload,
2194
+ data: channel === "email" ? { events: payload } : payload,
2183
2195
  provider: { id: channel === "email" ? null : (payload == null ? void 0 : payload.MessageSid) || null }
2184
2196
  }),
2185
2197
  // TWILIO'S SCHEME, from docs.twilio.com/usage/security: take the full
@@ -2514,8 +2526,8 @@ var drawbridge_default2 = {
2514
2526
  // owner is not a member document, so a solo merchant has nothing to
2515
2527
  // pick and could never save the step.
2516
2528
  members: { of: "string", type: "array" },
2517
- message: { required: true, type: "string" },
2518
- subject: { required: true, type: "string" }
2529
+ message: { max: 2e3, required: true, type: "string" },
2530
+ subject: { max: 150, required: true, type: "string" }
2519
2531
  },
2520
2532
  triggers: ["schedule.day", "schedule.week", "schedule.month"],
2521
2533
  usage: { actions: 0 }
@@ -2538,8 +2550,8 @@ var drawbridge_default2 = {
2538
2550
  queue: "notification",
2539
2551
  settings: {
2540
2552
  members: { of: "string", type: "array" },
2541
- message: { type: "string" },
2542
- subject: { type: "string" }
2553
+ message: { max: 2e3, type: "string" },
2554
+ subject: { max: 150, type: "string" }
2543
2555
  },
2544
2556
  triggers: ["lead.insert"],
2545
2557
  // Zero is a PRICE, and a deliberate one. Declared rather than omitted
@@ -2553,8 +2565,8 @@ var drawbridge_default2 = {
2553
2565
  key: "Email \u2014 Send email",
2554
2566
  queue: "notification",
2555
2567
  settings: {
2556
- message: { required: true, type: "string" },
2557
- subject: { required: true, type: "string" }
2568
+ message: { max: 2e3, required: true, type: "string" },
2569
+ subject: { max: 150, required: true, type: "string" }
2558
2570
  },
2559
2571
  triggers: ["lead.insert"],
2560
2572
  // ONE SOURCE FOR THE PRICE. lib/pricing.js is the index of every
@@ -2583,8 +2595,8 @@ var drawbridge_default2 = {
2583
2595
  key: "Send an SMS",
2584
2596
  queue: "notification",
2585
2597
  settings: {
2586
- message: { required: true, type: "string" },
2587
- subject: { required: true, type: "string" }
2598
+ message: { max: 1600, required: true, type: "string" },
2599
+ subject: { max: 150, required: true, type: "string" }
2588
2600
  },
2589
2601
  // Priced per SEGMENT and billed from the first, which the send
2590
2602
  // resolves from the message length. This is the floor.
@@ -3577,7 +3589,7 @@ import crypto2 from "crypto";
3577
3589
 
3578
3590
  // lib/token.js
3579
3591
  import crypto from "crypto";
3580
- var generate = (bytes = 32, encoding = "base64url") => {
3592
+ var generate2 = (bytes = 32, encoding = "base64url") => {
3581
3593
  const buf = crypto.randomBytes(bytes);
3582
3594
  return encoding ? buf.toString(encoding) : buf;
3583
3595
  };
@@ -3586,7 +3598,7 @@ var generate = (bytes = 32, encoding = "base64url") => {
3586
3598
  var ALGORITHM = "aes-256-gcm";
3587
3599
  var getKey = () => Buffer.from(process.env.ENCRYPT_CONNECTION_SECRET, "hex");
3588
3600
  var encrypt = (value) => {
3589
- const iv = generate(12, null);
3601
+ const iv = generate2(12, null);
3590
3602
  const cipher = crypto2.createCipheriv(ALGORITHM, getKey(), iv);
3591
3603
  const data2 = Buffer.concat([
3592
3604
  cipher.update(JSON.stringify(value), "utf8"),
package/package.json CHANGED
@@ -88,6 +88,11 @@
88
88
  "import": "./dist/nanoid.js",
89
89
  "require": "./dist/nanoid.cjs"
90
90
  },
91
+ "./notification": {
92
+ "types": "./dist/notification.d.ts",
93
+ "import": "./dist/notification.js",
94
+ "require": "./dist/notification.cjs"
95
+ },
91
96
  "./oauth": {
92
97
  "types": "./dist/oauth/index.d.ts",
93
98
  "import": "./dist/oauth/index.js",
@@ -216,5 +221,5 @@
216
221
  "prepublishOnly": ". \"$HOME/.nvm/nvm.sh\" && nvm use && tsup && node --test"
217
222
  },
218
223
  "types": "dist/index.d.ts",
219
- "version": "0.0.158"
224
+ "version": "0.0.160"
220
225
  }