@drawbridge/drawbridge-utils 0.0.135 → 0.0.136

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.
@@ -1031,6 +1031,74 @@ var drawbridge_default = `<svg width="500" height="500" viewBox="0 0 500 500" fi
1031
1031
  </defs>
1032
1032
  </svg>`;
1033
1033
 
1034
+ // lib/transactions.js
1035
+ var import_drawbridge_telemetry = require("@drawbridge/drawbridge-telemetry");
1036
+
1037
+ // lib/billing.js
1038
+ var import_drawbridge_telemetry2 = require("@drawbridge/drawbridge-telemetry");
1039
+ var logger = (0, import_drawbridge_telemetry2.createLogger)();
1040
+ var MARKUP = 1.3;
1041
+ var cost = {
1042
+ // gemini-3.5-flash — verified against Google's pricing page 2026-07-09:
1043
+ // $0.15 cached / $1.50 input / $9.00 output per 1M tokens (thinking billed at
1044
+ // output). ~3.6x the retired 2.5-flash output rate.
1045
+ "gemini-3.5-flash": {
1046
+ cached: 15,
1047
+ input: 150,
1048
+ output: 900
1049
+ },
1050
+ // gemini-3.5-flash-lite — verified against Google's pricing page 2026-08-20:
1051
+ // $0.03 cached / $0.30 input / $2.50 output per 1M tokens (thinking billed at
1052
+ // output). A fifth of flash on input, ~a quarter on output. Growth's assistant
1053
+ // ranks the feed on this tier — one call per page — so its rows were the
1054
+ // unpriced ones until now.
1055
+ "gemini-3.5-flash-lite": {
1056
+ cached: 3,
1057
+ input: 30,
1058
+ output: 250
1059
+ },
1060
+ "gemini-2.5-flash": {
1061
+ cached: 3,
1062
+ input: 30,
1063
+ output: 250
1064
+ },
1065
+ "gemini-2.5-flash-image": {
1066
+ cached: 3,
1067
+ input: 30,
1068
+ output: 3e3
1069
+ },
1070
+ // gemini-3-pro-image-preview — verified against Google's pricing page
1071
+ // 2026-08-12: $2.00 input / $12.00 text output per 1M, and image output
1072
+ // tokens at ~$120/1M (a 1K-2K image is 1120 tokens = $0.134, a 4K image
1073
+ // 2000 tokens = $0.24). Encoded the flash-image way: one flat output rate
1074
+ // that reproduces the per-image price from the tokens usageMetadata
1075
+ // reports. Growth's hero generation runs this model today.
1076
+ "gemini-3-pro-image-preview": {
1077
+ cached: 20,
1078
+ input: 200,
1079
+ output: 12e3
1080
+ }
1081
+ };
1082
+ var toolCost = {
1083
+ search: 3.5
1084
+ };
1085
+ var toolPricing = Object.fromEntries(
1086
+ Object.entries(toolCost).map(([tool, value]) => [
1087
+ tool,
1088
+ Math.ceil(value * MARKUP)
1089
+ ])
1090
+ );
1091
+ var pricing = Object.fromEntries(
1092
+ Object.entries(cost).map(([model, rates]) => [
1093
+ model,
1094
+ {
1095
+ cached: Math.round(rates.cached * MARKUP),
1096
+ input: Math.round(rates.input * MARKUP),
1097
+ output: Math.round(rates.output * MARKUP)
1098
+ }
1099
+ ])
1100
+ );
1101
+
1034
1102
  // lib/features.js
1035
1103
  var page = {
1036
1104
  qrcode: {
@@ -1493,74 +1561,6 @@ var conversionRate = (subscription) => {
1493
1561
  return ((_a = resolvePlan(subscription)) == null ? void 0 : _a.conversion) ?? free.conversion;
1494
1562
  };
1495
1563
 
1496
- // lib/transactions.js
1497
- var import_drawbridge_telemetry = require("@drawbridge/drawbridge-telemetry");
1498
-
1499
- // lib/billing.js
1500
- var import_drawbridge_telemetry2 = require("@drawbridge/drawbridge-telemetry");
1501
- var logger = (0, import_drawbridge_telemetry2.createLogger)();
1502
- var MARKUP = 1.3;
1503
- var cost = {
1504
- // gemini-3.5-flash — verified against Google's pricing page 2026-07-09:
1505
- // $0.15 cached / $1.50 input / $9.00 output per 1M tokens (thinking billed at
1506
- // output). ~3.6x the retired 2.5-flash output rate.
1507
- "gemini-3.5-flash": {
1508
- cached: 15,
1509
- input: 150,
1510
- output: 900
1511
- },
1512
- // gemini-3.5-flash-lite — verified against Google's pricing page 2026-08-20:
1513
- // $0.03 cached / $0.30 input / $2.50 output per 1M tokens (thinking billed at
1514
- // output). A fifth of flash on input, ~a quarter on output. Growth's assistant
1515
- // ranks the feed on this tier — one call per page — so its rows were the
1516
- // unpriced ones until now.
1517
- "gemini-3.5-flash-lite": {
1518
- cached: 3,
1519
- input: 30,
1520
- output: 250
1521
- },
1522
- "gemini-2.5-flash": {
1523
- cached: 3,
1524
- input: 30,
1525
- output: 250
1526
- },
1527
- "gemini-2.5-flash-image": {
1528
- cached: 3,
1529
- input: 30,
1530
- output: 3e3
1531
- },
1532
- // gemini-3-pro-image-preview — verified against Google's pricing page
1533
- // 2026-08-12: $2.00 input / $12.00 text output per 1M, and image output
1534
- // tokens at ~$120/1M (a 1K-2K image is 1120 tokens = $0.134, a 4K image
1535
- // 2000 tokens = $0.24). Encoded the flash-image way: one flat output rate
1536
- // that reproduces the per-image price from the tokens usageMetadata
1537
- // reports. Growth's hero generation runs this model today.
1538
- "gemini-3-pro-image-preview": {
1539
- cached: 20,
1540
- input: 200,
1541
- output: 12e3
1542
- }
1543
- };
1544
- var toolCost = {
1545
- search: 3.5
1546
- };
1547
- var toolPricing = Object.fromEntries(
1548
- Object.entries(toolCost).map(([tool, value]) => [
1549
- tool,
1550
- Math.ceil(value * MARKUP)
1551
- ])
1552
- );
1553
- var pricing = Object.fromEntries(
1554
- Object.entries(cost).map(([model, rates]) => [
1555
- model,
1556
- {
1557
- cached: Math.round(rates.cached * MARKUP),
1558
- input: Math.round(rates.input * MARKUP),
1559
- output: Math.round(rates.output * MARKUP)
1560
- }
1561
- ])
1562
- );
1563
-
1564
1564
  // lib/pricing.js
1565
1565
  var emailPlans = {
1566
1566
  essentials50k: {
@@ -1630,6 +1630,33 @@ var sending = {
1630
1630
  plan: emailPlan,
1631
1631
  plans: emailPlans,
1632
1632
  title: emailPlans[emailPlan].title
1633
+ },
1634
+ // What one outbound SMS SEGMENT costs us, against what channels.sms below
1635
+ // sells it for. Here for the same reason the email figures are: this file is
1636
+ // where a rate is found without knowing whose module owns it — and its
1637
+ // absence is why "does an SMS action cover its cost" could not be answered
1638
+ // from this repo at all.
1639
+ //
1640
+ // US toll-free outbound, read from Twilio's SMS pricing page 2026-09-03
1641
+ // (https://www.twilio.com/en-us/sms/pricing/us): $0.0083 per segment, plus a
1642
+ // carrier fee that varies by the DESTINATION carrier — $0.0035 AT&T, $0.0045
1643
+ // T-Mobile / Verizon / US Cellular, $0.004 everywhere else. CENTS per
1644
+ // segment, like every other rate in this file.
1645
+ //
1646
+ // WORST CASE, deliberately. A price floor computed from the average is a
1647
+ // floor that half of real traffic sits underneath.
1648
+ //
1649
+ // A segment is 153 GSM-7 characters once a message spans more than one — or
1650
+ // 67 if the body contains a single emoji or curly quote, which flips the
1651
+ // whole message to UCS-2. Twilio reports the count as `num_segments` on the
1652
+ // Message resource, which is what the send bills on.
1653
+ sms: {
1654
+ baseCents: 0.83,
1655
+ // The dearest carrier fee, not the mean: see WORST CASE above.
1656
+ carrierCents: 0.45,
1657
+ // Stated, not summed — 0.83 + 0.45 is 1.2800000000000002 in binary
1658
+ // floating point, and this number is compared against money.
1659
+ segmentCostCents: 1.28
1633
1660
  }
1634
1661
  };
1635
1662
  var channels = {
@@ -1645,6 +1672,9 @@ var channels = {
1645
1672
  includedInAllowance: false
1646
1673
  }
1647
1674
  };
1675
+ var MINIMUM_ACTION_CENTS = Math.round(
1676
+ sending.sms.segmentCostCents / channels.sms.actionsPerSegment * MARKUP * 1e3
1677
+ ) / 1e3;
1648
1678
 
1649
1679
  // lib/connections/providers/drawbridge.js
1650
1680
  var STOP_KEYWORDS = ["STOP", "STOPALL", "UNSUBSCRIBE", "CANCEL", "END", "QUIT"];
@@ -1669,13 +1699,16 @@ var teamRecipients = async ({ memberIds = [], organization: organization2, read
1669
1699
  ]
1670
1700
  }) : [];
1671
1701
  const seen = /* @__PURE__ */ new Set();
1672
- return [owner, ...members].filter((member) => {
1673
- if (!(member == null ? void 0 : member.id) || !(member == null ? void 0 : member.email)) return false;
1674
- const address = member.email.toLowerCase();
1675
- if (seen.has(address)) return false;
1676
- seen.add(address);
1677
- return true;
1678
- });
1702
+ return {
1703
+ org,
1704
+ recipients: [owner, ...members].filter((member) => {
1705
+ if (!(member == null ? void 0 : member.id) || !(member == null ? void 0 : member.email)) return false;
1706
+ const address = member.email.toLowerCase();
1707
+ if (seen.has(address)) return false;
1708
+ seen.add(address);
1709
+ return true;
1710
+ })
1711
+ };
1679
1712
  };
1680
1713
  var queueNotification = (data2) => ({ collection: "notification", data: data2, operation: "create" });
1681
1714
  var drawbridge_default2 = {
@@ -1751,7 +1784,7 @@ var drawbridge_default2 = {
1751
1784
  const count = Number((counted == null ? void 0 : counted.count) || 0);
1752
1785
  const request2 = { campaign, count, days };
1753
1786
  if (!count) return { message: "No new leads in the period \u2014 digest skipped.", request: request2, response: { skipped: true }, skipped: true };
1754
- const recipients = await teamRecipients({
1787
+ const { recipients } = await teamRecipients({
1755
1788
  memberIds: ((_d = step.settings) == null ? void 0 : _d.members) || [],
1756
1789
  organization: workflow.organization,
1757
1790
  read
@@ -1787,7 +1820,7 @@ var drawbridge_default2 = {
1787
1820
  var _a;
1788
1821
  const memberIds = ((_a = step.settings) == null ? void 0 : _a.members) || [];
1789
1822
  const request2 = { members: memberIds.length };
1790
- const recipients = await teamRecipients({ memberIds, organization: workflow.organization, read });
1823
+ const { org, recipients } = await teamRecipients({ memberIds, organization: workflow.organization, read });
1791
1824
  if (!recipients.length) {
1792
1825
  return {
1793
1826
  message: "No owner or accepted member with an email address \u2014 team notification skipped.",
@@ -1797,32 +1830,37 @@ var drawbridge_default2 = {
1797
1830
  };
1798
1831
  }
1799
1832
  const bucket = Math.floor(Date.now() / (15 * 60 * 1e3));
1833
+ const campaign = (context == null ? void 0 : context.campaign) ? await read.get({ collection: "campaign", query: { id: context.campaign } }) : null;
1834
+ const link = (context == null ? void 0 : context.campaign) && (context == null ? void 0 : context.lead) ? {
1835
+ href: "/organizations/" + workflow.organization + "/campaigns/" + context.campaign + "/leads/" + context.lead,
1836
+ text: "View lead"
1837
+ } : null;
1838
+ const body = ((context == null ? void 0 : context.email) || "Someone") + " just entered" + ((campaign == null ? void 0 : campaign.title) ? " " + campaign.title : "") + ((org == null ? void 0 : org.title) ? " at " + org.title : "") + ".";
1839
+ const subject = "New lead" + ((campaign == null ? void 0 : campaign.title) ? " \u2014 " + campaign.title : "");
1800
1840
  return {
1801
1841
  message: "Team notification queued for " + recipients.length + " recipient(s).",
1802
1842
  request: request2,
1803
1843
  response: { notified: recipients.length },
1804
- writes: recipients.map((member) => {
1805
- var _a2, _b;
1806
- return {
1807
- ...queueNotification({
1808
- audience: "member",
1809
- // Per workflow, recipient AND bucket, so one recipient's damper
1810
- // can never swallow another's mail and a later bucket is never
1811
- // mistaken for a duplicate of an earlier one.
1812
- key: "team.notify." + workflow.id + "." + member.id + "." + bucket,
1813
- message: interpolate((_a2 = step.settings) == null ? void 0 : _a2.message, context),
1814
- organization: workflow.organization,
1815
- send: { type: "email", email: member.email },
1816
- title: interpolate((_b = step.settings) == null ? void 0 : _b.subject, context),
1817
- workflow: workflow.id
1818
- }),
1819
- // E11000 IS THE DAMPER WORKING: this recipient has already been
1820
- // told within the bucket. Declared per write rather than assumed by
1821
- // the shell, because on every other write here a duplicate key is a
1822
- // real failure.
1823
- ignoreDuplicate: true
1824
- };
1825
- })
1844
+ writes: recipients.map((member) => ({
1845
+ ...queueNotification({
1846
+ audience: "member",
1847
+ // Per workflow, recipient AND bucket, so one recipient's damper
1848
+ // can never swallow another's mail and a later bucket is never
1849
+ // mistaken for a duplicate of an earlier one.
1850
+ key: "team.notify." + workflow.id + "." + member.id + "." + bucket,
1851
+ link,
1852
+ message: body,
1853
+ organization: workflow.organization,
1854
+ send: { type: "email", email: member.email },
1855
+ title: subject,
1856
+ workflow: workflow.id
1857
+ }),
1858
+ // E11000 IS THE DAMPER WORKING: this recipient has already been
1859
+ // told within the bucket. Declared per write rather than assumed by
1860
+ // the shell, because on every other write here a duplicate key is a
1861
+ // real failure.
1862
+ ignoreDuplicate: true
1863
+ }))
1826
1864
  };
1827
1865
  },
1828
1866
  // Drawbridge sends lead-facing email itself — no merchant provider gates
@@ -2228,14 +2266,24 @@ var drawbridge_default2 = {
2228
2266
  }),
2229
2267
  // To organization MEMBERS. Never suppressed — an entrant's opt-out must
2230
2268
  // not silence an alert to staff — and not billed.
2269
+ //
2270
+ // ITS COPY IS WRITTEN, NOT ASKED FOR. This says the same thing every
2271
+ // time — a lead arrived, here it is — so the merchant chooses who hears
2272
+ // it, not how it reads, and the hook composes the subject, the body and
2273
+ // the link to the lead.
2274
+ //
2275
+ // `message` and `subject` stay declared, optional and IGNORED: stored
2276
+ // workflows still carry them and the api validates settings with
2277
+ // noUnknown().strict(), so dropping the keys would 400 the next save of
2278
+ // a workflow built before this.
2231
2279
  notify: () => ({
2232
2280
  hook: "email.notify",
2233
2281
  key: "Email \u2014 Notification",
2234
2282
  queue: "notification",
2235
2283
  settings: {
2236
2284
  members: { of: "string", type: "array" },
2237
- message: { required: true, type: "string" },
2238
- subject: { required: true, type: "string" }
2285
+ message: { type: "string" },
2286
+ subject: { type: "string" }
2239
2287
  },
2240
2288
  triggers: ["lead.insert"],
2241
2289
  // Zero is a PRICE, and a deliberate one. Declared rather than omitted
@@ -6,6 +6,10 @@ import './phone.cjs';
6
6
  import 'libphonenumber-js';
7
7
  import './http.cjs';
8
8
  import './pricing.cjs';
9
+ import './billing.cjs';
10
+ import './transactions.cjs';
11
+ import '@drawbridge/drawbridge-telemetry';
12
+ import './usage.cjs';
9
13
  import './plans.cjs';
10
14
  import './features.cjs';
11
15
  import './index.cjs';
@@ -13,10 +17,6 @@ import 'currency-codes';
13
17
  import 'nanoid';
14
18
  import './color.cjs';
15
19
  import 'tinycolor2';
16
- import './usage.cjs';
17
- import './billing.cjs';
18
- import './transactions.cjs';
19
- import '@drawbridge/drawbridge-telemetry';
20
20
  import './email.cjs';
21
21
  import './safe-http.cjs';
22
22
  import 'dns';
@@ -6,6 +6,10 @@ import './phone.js';
6
6
  import 'libphonenumber-js';
7
7
  import './http.js';
8
8
  import './pricing.js';
9
+ import './billing.js';
10
+ import './transactions.js';
11
+ import '@drawbridge/drawbridge-telemetry';
12
+ import './usage.js';
9
13
  import './plans.js';
10
14
  import './features.js';
11
15
  import './index.js';
@@ -13,10 +17,6 @@ import 'currency-codes';
13
17
  import 'nanoid';
14
18
  import './color.js';
15
19
  import 'tinycolor2';
16
- import './usage.js';
17
- import './billing.js';
18
- import './transactions.js';
19
- import '@drawbridge/drawbridge-telemetry';
20
20
  import './email.js';
21
21
  import './safe-http.js';
22
22
  import 'dns';