@drawbridge/components 0.1.46 → 0.1.48

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.
Files changed (162) hide show
  1. package/dist/bridge/cart-drawer.js +152 -0
  2. package/dist/bridge/cart-drawer.mjs +123 -0
  3. package/dist/bridge/fields.js +278 -0
  4. package/dist/bridge/fields.mjs +276 -1
  5. package/dist/bridge/form-subdomain-checkout.js +687 -0
  6. package/dist/bridge/form-subdomain-checkout.mjs +665 -0
  7. package/dist/bridge/form-subdomain-shop-modal.js +234 -274
  8. package/dist/bridge/form-subdomain-shop-modal.mjs +233 -275
  9. package/dist/bridge/form-subdomain-shop.js +4 -1
  10. package/dist/bridge/form-subdomain-shop.mjs +4 -1
  11. package/dist/bridge/form-subdomain.js +24 -5
  12. package/dist/bridge/form-subdomain.mjs +25 -6
  13. package/dist/bridge/lib/age-gate.js +12 -0
  14. package/dist/bridge/lib/age-gate.mjs +11 -0
  15. package/dist/bridge/lib/cart.js +79 -0
  16. package/dist/bridge/lib/cart.mjs +48 -0
  17. package/dist/bridge/lib/checkout-kit.js +2 -32
  18. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  19. package/dist/bridge/lib/entry.js +41 -0
  20. package/dist/bridge/lib/entry.mjs +40 -0
  21. package/dist/bridge/product-tile.js +13 -6
  22. package/dist/bridge/product-tile.mjs +13 -6
  23. package/dist/bridge/template-layout.js +263 -129
  24. package/dist/bridge/template-layout.mjs +264 -130
  25. package/dist/bridge/template-modal.js +39 -74
  26. package/dist/bridge/template-modal.mjs +40 -75
  27. package/dist/dashboard/avatar.js +2 -3
  28. package/dist/dashboard/avatar.mjs +2 -3
  29. package/dist/dashboard/buttons-subscription.js +1 -1
  30. package/dist/dashboard/buttons-subscription.mjs +1 -1
  31. package/dist/dashboard/campaign-form.js +179 -155
  32. package/dist/dashboard/campaign-form.mjs +179 -155
  33. package/dist/dashboard/campaign-share.js +347 -0
  34. package/dist/dashboard/campaign-share.mjs +314 -0
  35. package/dist/dashboard/card-affiliate.js +1 -1
  36. package/dist/dashboard/card-affiliate.mjs +1 -1
  37. package/dist/dashboard/card-campaign-switch.js +4 -1
  38. package/dist/dashboard/card-campaign-switch.mjs +4 -1
  39. package/dist/dashboard/card-order.js +22 -4
  40. package/dist/dashboard/card-order.mjs +22 -4
  41. package/dist/dashboard/embed-stripe.js +145 -0
  42. package/dist/dashboard/embed-stripe.mjs +116 -0
  43. package/dist/dashboard/form-admin-provider.js +71 -17
  44. package/dist/dashboard/form-admin-provider.mjs +71 -17
  45. package/dist/dashboard/form-file-upload.js +3 -2
  46. package/dist/dashboard/form-file-upload.mjs +4 -3
  47. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  48. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  49. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  50. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  51. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  52. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  53. package/dist/dashboard/form-organization-campaign-page.js +73 -39
  54. package/dist/dashboard/form-organization-campaign-page.mjs +73 -39
  55. package/dist/dashboard/form-organization-campaign.js +82 -0
  56. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  57. package/dist/dashboard/form-organization-connection.js +48 -6
  58. package/dist/dashboard/form-organization-connection.mjs +48 -7
  59. package/dist/dashboard/form-organization-product.js +1461 -0
  60. package/dist/dashboard/form-organization-product.mjs +1425 -0
  61. package/dist/dashboard/form-organization-workflow.js +72 -1
  62. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  63. package/dist/dashboard/form-otc.js +4 -5
  64. package/dist/dashboard/form-otc.mjs +4 -5
  65. package/dist/dashboard/form-stripe.js +12 -5
  66. package/dist/dashboard/form-stripe.mjs +12 -5
  67. package/dist/dashboard/input-combobox.js +6 -0
  68. package/dist/dashboard/input-combobox.mjs +6 -0
  69. package/dist/dashboard/input-fields.js +37 -161
  70. package/dist/dashboard/input-fields.mjs +37 -161
  71. package/dist/dashboard/input-file.js +21 -4
  72. package/dist/dashboard/input-file.mjs +21 -4
  73. package/dist/dashboard/input-font.js +2 -0
  74. package/dist/dashboard/input-font.mjs +2 -0
  75. package/dist/dashboard/input-gallery.js +201 -0
  76. package/dist/dashboard/input-gallery.mjs +172 -0
  77. package/dist/dashboard/input-group-ai.js +15 -3
  78. package/dist/dashboard/input-group-ai.mjs +15 -3
  79. package/dist/dashboard/lib/ab-tests.js +2 -2
  80. package/dist/dashboard/lib/ab-tests.mjs +2 -2
  81. package/dist/dashboard/lib/connection-controls.js +5 -2
  82. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  83. package/dist/dashboard/lib/form-page.js +1 -1
  84. package/dist/dashboard/lib/form-page.mjs +1 -1
  85. package/dist/dashboard/lib/menu.js +19 -0
  86. package/dist/dashboard/lib/menu.mjs +18 -0
  87. package/dist/dashboard/lib/products.js +169 -0
  88. package/dist/dashboard/lib/products.mjs +135 -0
  89. package/dist/dashboard/lib/settings-paths.js +35 -0
  90. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  91. package/dist/dashboard/lib/uppy.js +10 -1
  92. package/dist/dashboard/lib/uppy.mjs +11 -2
  93. package/dist/dashboard/menu.js +13 -2
  94. package/dist/dashboard/menu.mjs +13 -2
  95. package/dist/dashboard/order-sections.js +456 -6
  96. package/dist/dashboard/order-sections.mjs +453 -7
  97. package/dist/dashboard/preview.js +119 -52
  98. package/dist/dashboard/preview.mjs +119 -52
  99. package/dist/dashboard/provider-ui.js +9 -7
  100. package/dist/dashboard/provider-ui.mjs +9 -7
  101. package/dist/dashboard/recharts.js +10 -4
  102. package/dist/dashboard/recharts.mjs +10 -4
  103. package/dist/dashboard/shipping-rates.js +404 -0
  104. package/dist/dashboard/shipping-rates.mjs +371 -0
  105. package/dist/dashboard/template-buyer.js +301 -0
  106. package/dist/dashboard/template-buyer.mjs +267 -0
  107. package/dist/dashboard/template-dashboard.js +11 -1
  108. package/dist/dashboard/template-dashboard.mjs +11 -1
  109. package/dist/dashboard/template-design.js +209 -130
  110. package/dist/dashboard/template-design.mjs +210 -131
  111. package/dist/dashboard/template-ui.js +157 -55
  112. package/dist/dashboard/template-ui.mjs +158 -56
  113. package/dist/icons/flags.js +134 -0
  114. package/dist/icons/flags.mjs +115 -0
  115. package/dist/input-checkbox.js +28 -10
  116. package/dist/input-checkbox.mjs +28 -10
  117. package/dist/product.js +96 -24
  118. package/dist/product.mjs +97 -25
  119. package/dist/shared/carousel.js +14 -5
  120. package/dist/shared/carousel.mjs +14 -5
  121. package/dist/shared/lib/helpers.js +54 -6
  122. package/dist/shared/lib/helpers.mjs +53 -8
  123. package/dist/shared/order-summary.js +139 -0
  124. package/dist/shared/order-summary.mjs +110 -0
  125. package/package.json +84 -4
  126. package/types/bridge/cart-drawer.d.ts +31 -0
  127. package/types/bridge/fields.d.ts +14 -2
  128. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  129. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  130. package/types/bridge/form-subdomain.d.ts +13 -0
  131. package/types/bridge/lib/age-gate.d.ts +5 -0
  132. package/types/bridge/lib/cart.d.ts +44 -0
  133. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  134. package/types/bridge/lib/entry.d.ts +5 -0
  135. package/types/bridge/product-tile.d.ts +2 -0
  136. package/types/dashboard/campaign-share.d.ts +16 -0
  137. package/types/dashboard/card-order.d.ts +6 -0
  138. package/types/dashboard/embed-stripe.d.ts +25 -0
  139. package/types/dashboard/form-admin-provider.d.ts +9 -2
  140. package/types/dashboard/form-file-upload.d.ts +2 -1
  141. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  142. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  143. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  144. package/types/dashboard/form-organization-campaign-page.d.ts +8 -1
  145. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  146. package/types/dashboard/form-organization-connection.d.ts +11 -0
  147. package/types/dashboard/form-organization-product.d.ts +24 -0
  148. package/types/dashboard/form-otc.d.ts +5 -1
  149. package/types/dashboard/form-stripe.d.ts +3 -2
  150. package/types/dashboard/input-combobox.d.ts +2 -0
  151. package/types/dashboard/input-file.d.ts +2 -0
  152. package/types/dashboard/input-gallery.d.ts +14 -0
  153. package/types/dashboard/lib/products.d.ts +14 -0
  154. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  155. package/types/dashboard/order-sections.d.ts +24 -1
  156. package/types/dashboard/preview.d.ts +11 -3
  157. package/types/dashboard/shipping-rates.d.ts +26 -0
  158. package/types/dashboard/template-buyer.d.ts +50 -0
  159. package/types/icons/flags.d.ts +5 -0
  160. package/types/input-checkbox.d.ts +2 -0
  161. package/types/shared/lib/helpers.d.ts +4 -0
  162. package/types/shared/order-summary.d.ts +19 -0
@@ -42,7 +42,7 @@ const useCampaignSwitch = ({ campaign, onError, onSuccess }) => {
42
42
  });
43
43
  };
44
44
  };
45
- const SwitchLock = ({ disabled, onChange, value }) => /* @__PURE__ */ jsxs(
45
+ const SwitchLock = ({ disabled, name, onChange, value }) => /* @__PURE__ */ jsxs(
46
46
  "span",
47
47
  {
48
48
  ...{
@@ -63,6 +63,8 @@ const SwitchLock = ({ disabled, onChange, value }) => /* @__PURE__ */ jsxs(
63
63
  InputSwitch,
64
64
  {
65
65
  ...{
66
+ // Impeccable audit, 2026-11-21: the switch is named for its row.
67
+ "aria-label": name,
66
68
  disabled,
67
69
  onChange,
68
70
  value
@@ -78,6 +80,7 @@ const SwitchRow = ({ description, lock, onChange, title, value }) => {
78
80
  {
79
81
  ...{
80
82
  disabled: Boolean(lock),
83
+ name: typeof title === "string" ? title : void 0,
81
84
  onChange,
82
85
  value
83
86
  }
@@ -34,11 +34,14 @@ var import_jsx_runtime = require("react/jsx-runtime");
34
34
  var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
35
35
  var import_card_data_item = __toESM(require("./card-data-item"));
36
36
  var import_card_shortcut = __toESM(require("./card-shortcut"));
37
+ var import_button = __toESM(require("../shared/button"));
38
+ var import_products = require("./lib/products");
37
39
  var import_answer_rows = require("./answer-rows");
38
40
  const className = "p-3 bg-white rounded shadow-[0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)]";
39
41
  const attributions = {
40
42
  conversion: "A campaign link brought the buyer to checkout, so the conversion fee applies.",
41
- redemption: "The buyer used one of your discount codes, so no fee applies."
43
+ redemption: "The buyer used one of your discount codes, so no fee applies.",
44
+ sale: "This sale came through your campaign page, so the sales fee applies."
42
45
  };
43
46
  const date = (value) => value ? (0, import_drawbridge_utils.formatDateString)({
44
47
  date: value,
@@ -64,7 +67,7 @@ const lineSummary = ({ code, price, quantity = 0, variantTitle }) => [
64
67
  variantTitle,
65
68
  typeof price === "number" ? (0, import_drawbridge_utils.formatNumber)(quantity) + " \xD7 " + (0, import_drawbridge_utils.formatCurrency)({ code, value: price }) : "Quantity " + (0, import_drawbridge_utils.formatNumber)(quantity)
66
69
  ].filter(Boolean).join(" \xB7 ");
67
- const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
70
+ const Lines = ({ code, label, lines, onResend, untitled }) => lines.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
68
71
  "div",
69
72
  {
70
73
  ...{
@@ -90,7 +93,20 @@ const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PU
90
93
  import_card_shortcut.default,
91
94
  {
92
95
  ...{
93
- description: lineSummary({ code, ...line }),
96
+ ...onResend && typeof line.file === "string" && {
97
+ controls: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
98
+ import_button.default,
99
+ {
100
+ ...{
101
+ onClick: onResend,
102
+ size: "small",
103
+ variant: "secondary"
104
+ },
105
+ children: "Resend download"
106
+ }
107
+ )
108
+ },
109
+ description: [lineSummary({ code, ...line }), typeof line.file === "string" ? (0, import_products.downloadsText)(line.downloads || 0) : null].filter(Boolean).join(" \xB7 "),
94
110
  image: line.image,
95
111
  title: line.title || untitled
96
112
  }
@@ -249,6 +265,7 @@ const CardOrder = ({
249
265
  gross = 0,
250
266
  lines = [],
251
267
  net = 0,
268
+ onResend,
252
269
  provider,
253
270
  purchasedAt,
254
271
  rate,
@@ -279,7 +296,7 @@ const CardOrder = ({
279
296
  className: "space-y-6"
280
297
  },
281
298
  children: [
282
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: attributions[type] || attributions.conversion }),
299
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: attributions[(provider == null ? void 0 : provider.slug) === "stripe" ? "sale" : type] || attributions.conversion }),
283
300
  /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
284
301
  "div",
285
302
  {
@@ -362,6 +379,7 @@ const CardOrder = ({
362
379
  label: "Products",
363
380
  // A store line always has a price.
364
381
  lines: lines.map((line) => ({ ...line, price: line.price || 0 })),
382
+ onResend,
365
383
  untitled: "Untitled product"
366
384
  }
367
385
  }
@@ -2,11 +2,14 @@ import { jsx, jsxs } from "react/jsx-runtime";
2
2
  import { formatCurrency, formatDateString, formatNumber } from "@drawbridge/drawbridge-utils";
3
3
  import CardDataItem from "./card-data-item.mjs";
4
4
  import CardShortcut from "./card-shortcut.mjs";
5
+ import Button from "../shared/button.mjs";
6
+ import { downloadsText } from "./lib/products.mjs";
5
7
  import { answerRows } from "./answer-rows.mjs";
6
8
  const className = "p-3 bg-white rounded shadow-[0_1px_3px_0_rgb(0_0_0/0.1),0_1px_2px_-1px_rgb(0_0_0/0.1)]";
7
9
  const attributions = {
8
10
  conversion: "A campaign link brought the buyer to checkout, so the conversion fee applies.",
9
- redemption: "The buyer used one of your discount codes, so no fee applies."
11
+ redemption: "The buyer used one of your discount codes, so no fee applies.",
12
+ sale: "This sale came through your campaign page, so the sales fee applies."
10
13
  };
11
14
  const date = (value) => value ? formatDateString({
12
15
  date: value,
@@ -32,7 +35,7 @@ const lineSummary = ({ code, price, quantity = 0, variantTitle }) => [
32
35
  variantTitle,
33
36
  typeof price === "number" ? formatNumber(quantity) + " \xD7 " + formatCurrency({ code, value: price }) : "Quantity " + formatNumber(quantity)
34
37
  ].filter(Boolean).join(" \xB7 ");
35
- const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PURE__ */ jsxs(
38
+ const Lines = ({ code, label, lines, onResend, untitled }) => lines.length > 0 && /* @__PURE__ */ jsxs(
36
39
  "div",
37
40
  {
38
41
  ...{
@@ -58,7 +61,20 @@ const Lines = ({ code, label, lines, untitled }) => lines.length > 0 && /* @__PU
58
61
  CardShortcut,
59
62
  {
60
63
  ...{
61
- description: lineSummary({ code, ...line }),
64
+ ...onResend && typeof line.file === "string" && {
65
+ controls: /* @__PURE__ */ jsx(
66
+ Button,
67
+ {
68
+ ...{
69
+ onClick: onResend,
70
+ size: "small",
71
+ variant: "secondary"
72
+ },
73
+ children: "Resend download"
74
+ }
75
+ )
76
+ },
77
+ description: [lineSummary({ code, ...line }), typeof line.file === "string" ? downloadsText(line.downloads || 0) : null].filter(Boolean).join(" \xB7 "),
62
78
  image: line.image,
63
79
  title: line.title || untitled
64
80
  }
@@ -217,6 +233,7 @@ const CardOrder = ({
217
233
  gross = 0,
218
234
  lines = [],
219
235
  net = 0,
236
+ onResend,
220
237
  provider,
221
238
  purchasedAt,
222
239
  rate,
@@ -247,7 +264,7 @@ const CardOrder = ({
247
264
  className: "space-y-6"
248
265
  },
249
266
  children: [
250
- /* @__PURE__ */ jsx("p", { children: attributions[type] || attributions.conversion }),
267
+ /* @__PURE__ */ jsx("p", { children: attributions[(provider == null ? void 0 : provider.slug) === "stripe" ? "sale" : type] || attributions.conversion }),
251
268
  /* @__PURE__ */ jsxs(
252
269
  "div",
253
270
  {
@@ -330,6 +347,7 @@ const CardOrder = ({
330
347
  label: "Products",
331
348
  // A store line always has a price.
332
349
  lines: lines.map((line) => ({ ...line, price: line.price || 0 })),
350
+ onResend,
333
351
  untitled: "Untitled product"
334
352
  }
335
353
  }
@@ -0,0 +1,145 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var embed_stripe_exports = {};
29
+ __export(embed_stripe_exports, {
30
+ default: () => embed_stripe_default
31
+ });
32
+ module.exports = __toCommonJS(embed_stripe_exports);
33
+ var import_jsx_runtime = require("react/jsx-runtime");
34
+ var import_react = require("react");
35
+ var import_react_query = require("@tanstack/react-query");
36
+ var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
37
+ var import_pure = require("@stripe/connect-js/pure");
38
+ var import_loader = __toESM(require("../shared/loader"));
39
+ var import_card_task = __toESM(require("./card-task"));
40
+ const instances = /* @__PURE__ */ new Map();
41
+ const appearance = {
42
+ variables: {
43
+ actionPrimaryColorText: "#000000",
44
+ borderRadius: "4px",
45
+ buttonPrimaryColorBackground: "#000000",
46
+ buttonPrimaryColorBorder: "#000000",
47
+ buttonPrimaryColorText: "#FFFFFF",
48
+ colorPrimary: "#000000",
49
+ colorText: "#000000",
50
+ fontFamily: 'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
51
+ formAccentColor: "#000000"
52
+ }
53
+ };
54
+ const connect = (endpoint, publishableKey) => {
55
+ if (!instances.has(endpoint)) {
56
+ instances.set(endpoint, (0, import_pure.loadConnectAndInitialize)({
57
+ appearance,
58
+ fetchClientSecret: async () => {
59
+ var _a, _b;
60
+ return (_b = (_a = await (0, import_fetch.request)({ endpoint, method: "POST" })) == null ? void 0 : _a.result) == null ? void 0 : _b.clientSecret;
61
+ },
62
+ publishableKey
63
+ }));
64
+ }
65
+ return instances.get(endpoint);
66
+ };
67
+ const EmbedStripe = ({
68
+ component,
69
+ endpoint,
70
+ onClose,
71
+ onExit,
72
+ onNotificationsChange,
73
+ payment
74
+ }) => {
75
+ var _a, _b;
76
+ const container = (0, import_react.useRef)(null);
77
+ const publishableKey = (_b = (_a = (0, import_react_query.useQueryClient)().getQueryData(["app"])) == null ? void 0 : _a.credentials) == null ? void 0 : _b.stripePublishableKey;
78
+ const handlers = (0, import_react.useRef)({});
79
+ handlers.current = { onClose, onExit, onNotificationsChange };
80
+ const [state, setState] = (0, import_react.useState)("loading");
81
+ (0, import_react.useEffect)(
82
+ () => {
83
+ var _a2, _b2, _c, _d;
84
+ setState("loading");
85
+ const failed = () => {
86
+ instances.delete(endpoint);
87
+ setState((state2) => state2 === "ready" ? state2 : "error");
88
+ };
89
+ if (!publishableKey) {
90
+ setState("error");
91
+ return;
92
+ }
93
+ const instance = connect(endpoint, publishableKey);
94
+ instance.debugInstance().catch(failed);
95
+ const element = instance.create(component.replace(/_/g, "-"));
96
+ element.setOnLoaderStart(() => setState("ready"));
97
+ element.setOnLoadError(failed);
98
+ (_a2 = element.setOnExit) == null ? void 0 : _a2.call(element, () => {
99
+ var _a3, _b3;
100
+ return (_b3 = (_a3 = handlers.current).onExit) == null ? void 0 : _b3.call(_a3);
101
+ });
102
+ (_b2 = element.setOnClose) == null ? void 0 : _b2.call(element, () => {
103
+ var _a3, _b3;
104
+ return (_b3 = (_a3 = handlers.current).onClose) == null ? void 0 : _b3.call(_a3);
105
+ });
106
+ if (payment) (_c = element.setPayment) == null ? void 0 : _c.call(element, payment);
107
+ (_d = element.setOnNotificationsChange) == null ? void 0 : _d.call(element, (response) => {
108
+ var _a3, _b3;
109
+ return (_b3 = (_a3 = handlers.current).onNotificationsChange) == null ? void 0 : _b3.call(_a3, response);
110
+ });
111
+ container.current.appendChild(element);
112
+ return () => element.remove();
113
+ },
114
+ [component, endpoint, payment, publishableKey]
115
+ );
116
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(
117
+ "div",
118
+ {
119
+ ...{
120
+ className: state === "loading" ? "relative min-h-24" : "relative"
121
+ },
122
+ children: [
123
+ state === "loading" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_loader.default, {}),
124
+ state === "error" && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
125
+ import_card_task.default,
126
+ {
127
+ ...{
128
+ message: "We could not load that from Stripe",
129
+ type: "error"
130
+ }
131
+ }
132
+ ),
133
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
134
+ "div",
135
+ {
136
+ ...{
137
+ ref: container
138
+ }
139
+ }
140
+ )
141
+ ]
142
+ }
143
+ );
144
+ };
145
+ var embed_stripe_default = EmbedStripe;
@@ -0,0 +1,116 @@
1
+ import { jsx, jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { useQueryClient } from "@tanstack/react-query";
4
+ import { request } from "@drawbridge/drawbridge-utils/fetch";
5
+ import { loadConnectAndInitialize } from "@stripe/connect-js/pure";
6
+ import Loader from "../shared/loader.mjs";
7
+ import CardTask from "./card-task.mjs";
8
+ const instances = /* @__PURE__ */ new Map();
9
+ const appearance = {
10
+ variables: {
11
+ actionPrimaryColorText: "#000000",
12
+ borderRadius: "4px",
13
+ buttonPrimaryColorBackground: "#000000",
14
+ buttonPrimaryColorBorder: "#000000",
15
+ buttonPrimaryColorText: "#FFFFFF",
16
+ colorPrimary: "#000000",
17
+ colorText: "#000000",
18
+ fontFamily: 'ui-sans-serif, system-ui, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"',
19
+ formAccentColor: "#000000"
20
+ }
21
+ };
22
+ const connect = (endpoint, publishableKey) => {
23
+ if (!instances.has(endpoint)) {
24
+ instances.set(endpoint, loadConnectAndInitialize({
25
+ appearance,
26
+ fetchClientSecret: async () => {
27
+ var _a, _b;
28
+ return (_b = (_a = await request({ endpoint, method: "POST" })) == null ? void 0 : _a.result) == null ? void 0 : _b.clientSecret;
29
+ },
30
+ publishableKey
31
+ }));
32
+ }
33
+ return instances.get(endpoint);
34
+ };
35
+ const EmbedStripe = ({
36
+ component,
37
+ endpoint,
38
+ onClose,
39
+ onExit,
40
+ onNotificationsChange,
41
+ payment
42
+ }) => {
43
+ var _a, _b;
44
+ const container = useRef(null);
45
+ const publishableKey = (_b = (_a = useQueryClient().getQueryData(["app"])) == null ? void 0 : _a.credentials) == null ? void 0 : _b.stripePublishableKey;
46
+ const handlers = useRef({});
47
+ handlers.current = { onClose, onExit, onNotificationsChange };
48
+ const [state, setState] = useState("loading");
49
+ useEffect(
50
+ () => {
51
+ var _a2, _b2, _c, _d;
52
+ setState("loading");
53
+ const failed = () => {
54
+ instances.delete(endpoint);
55
+ setState((state2) => state2 === "ready" ? state2 : "error");
56
+ };
57
+ if (!publishableKey) {
58
+ setState("error");
59
+ return;
60
+ }
61
+ const instance = connect(endpoint, publishableKey);
62
+ instance.debugInstance().catch(failed);
63
+ const element = instance.create(component.replace(/_/g, "-"));
64
+ element.setOnLoaderStart(() => setState("ready"));
65
+ element.setOnLoadError(failed);
66
+ (_a2 = element.setOnExit) == null ? void 0 : _a2.call(element, () => {
67
+ var _a3, _b3;
68
+ return (_b3 = (_a3 = handlers.current).onExit) == null ? void 0 : _b3.call(_a3);
69
+ });
70
+ (_b2 = element.setOnClose) == null ? void 0 : _b2.call(element, () => {
71
+ var _a3, _b3;
72
+ return (_b3 = (_a3 = handlers.current).onClose) == null ? void 0 : _b3.call(_a3);
73
+ });
74
+ if (payment) (_c = element.setPayment) == null ? void 0 : _c.call(element, payment);
75
+ (_d = element.setOnNotificationsChange) == null ? void 0 : _d.call(element, (response) => {
76
+ var _a3, _b3;
77
+ return (_b3 = (_a3 = handlers.current).onNotificationsChange) == null ? void 0 : _b3.call(_a3, response);
78
+ });
79
+ container.current.appendChild(element);
80
+ return () => element.remove();
81
+ },
82
+ [component, endpoint, payment, publishableKey]
83
+ );
84
+ return /* @__PURE__ */ jsxs(
85
+ "div",
86
+ {
87
+ ...{
88
+ className: state === "loading" ? "relative min-h-24" : "relative"
89
+ },
90
+ children: [
91
+ state === "loading" && /* @__PURE__ */ jsx(Loader, {}),
92
+ state === "error" && /* @__PURE__ */ jsx(
93
+ CardTask,
94
+ {
95
+ ...{
96
+ message: "We could not load that from Stripe",
97
+ type: "error"
98
+ }
99
+ }
100
+ ),
101
+ /* @__PURE__ */ jsx(
102
+ "div",
103
+ {
104
+ ...{
105
+ ref: container
106
+ }
107
+ }
108
+ )
109
+ ]
110
+ }
111
+ );
112
+ };
113
+ var embed_stripe_default = EmbedStripe;
114
+ export {
115
+ embed_stripe_default as default
116
+ };
@@ -33,6 +33,7 @@ __export(form_admin_provider_exports, {
33
33
  module.exports = __toCommonJS(form_admin_provider_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_react = require("react");
36
+ var import_react_query = require("@tanstack/react-query");
36
37
  var import_form = require("../shared/lib/form");
37
38
  var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
38
39
  var import_yup = __toESM(require("../shared/lib/yup"));
@@ -44,11 +45,18 @@ var import_input_switch = __toESM(require("../shared/input-switch"));
44
45
  var import_card_task = __toESM(require("./card-task"));
45
46
  var import_input_secret = __toESM(require("./input-secret"));
46
47
  var import_button = __toESM(require("../shared/button"));
47
- const schemaFor = (field) => {
48
+ var import_form_organization_connection = require("./form-organization-connection");
49
+ var import_settings_paths = require("./lib/settings-paths");
50
+ const schemaFor = (field, enabled) => {
48
51
  if (field.input === "switch") return import_yup.default.boolean().label(field.label);
49
52
  const rule = field.input === "email" ? import_yup.default.string().label(field.label).email() : import_yup.default.string().label(field.label);
50
- return field.required && !field.redact ? rule.when("enabled", { is: false, otherwise: (s) => s.required(), then: (s) => s.nullable() }) : rule.nullable();
53
+ return enabled && field.required && !field.redact && !field.hook ? rule.required() : rule.nullable();
51
54
  };
55
+ const shape = (tree) => import_yup.default.object(
56
+ Object.fromEntries(
57
+ Object.entries(tree).map(([key, node]) => [key, import_yup.default.isSchema(node) ? node : shape(node)])
58
+ )
59
+ );
52
60
  const FormAdminProvider = ({
53
61
  onError,
54
62
  onSuccess,
@@ -61,25 +69,37 @@ const FormAdminProvider = ({
61
69
  // A row that has never been touched has no answer stored and is on, so
62
70
  // the box starts checked rather than empty.
63
71
  enabled: (values == null ? void 0 : values.enabled) !== false,
64
- ...Object.fromEntries(
65
- fields.map((field) => {
66
- var _a, _b;
67
- return [
68
- field.key,
69
- field.input === "switch" ? ((_a = values == null ? void 0 : values.settings) == null ? void 0 : _a[field.key]) === true : field.redact ? "" : ((_b = values == null ? void 0 : values.settings) == null ? void 0 : _b[field.key]) ?? ""
70
- ];
71
- })
72
+ ...(0, import_settings_paths.nestPaths)(
73
+ fields.map((field) => [
74
+ field.key,
75
+ field.input === "switch" ? (0, import_settings_paths.readPath)(values == null ? void 0 : values.settings, field.key) === true : field.redact ? "" : (0, import_settings_paths.readPath)(values == null ? void 0 : values.settings, field.key) ?? ""
76
+ ])
72
77
  )
73
78
  }),
74
79
  [fields, values]
75
80
  );
76
81
  const schema = (0, import_react.useMemo)(
77
- () => import_yup.default.object({
82
+ () => import_yup.default.lazy((data) => shape({
78
83
  enabled: import_yup.default.boolean().label("Enabled"),
79
- ...Object.fromEntries(fields.map((field) => [field.key, schemaFor(field)]))
80
- }),
84
+ ...(0, import_settings_paths.nestPaths)(fields.map((field) => [field.key, schemaFor(field, (data == null ? void 0 : data.enabled) !== false)]))
85
+ })),
81
86
  [fields]
82
87
  );
88
+ const hooked = (0, import_react.useMemo)(() => fields.filter((field) => field.hook), [fields]);
89
+ const sourced = (0, import_react_query.useQueries)({
90
+ queries: hooked.map((field) => ({
91
+ enabled: Boolean(values == null ? void 0 : values.slug),
92
+ queryFn: async () => {
93
+ const { result } = await (0, import_fetch.request)({
94
+ endpoint: "/admin/provider/" + (values == null ? void 0 : values.slug) + "/hook/" + field.hook,
95
+ params: { limit: 100 }
96
+ });
97
+ return ((result == null ? void 0 : result.items) || []).map((item) => ({ label: item.title, value: item.id }));
98
+ },
99
+ queryKey: ["admin-provider-hook", values == null ? void 0 : values.slug, field.hook, values == null ? void 0 : values.settings]
100
+ }))
101
+ });
102
+ const optionsFor = Object.fromEntries(hooked.map((field, index) => [field.key, sourced[index]]));
83
103
  const [clearing, setClearing] = (0, import_react.useState)([]);
84
104
  (0, import_react.useEffect)(() => setClearing([]), [values == null ? void 0 : values.slug]);
85
105
  const { control, formState, handleSubmit } = (0, import_form.useForm)({
@@ -104,10 +124,20 @@ const FormAdminProvider = ({
104
124
  // admin then TYPED INTO is a replacement, not a removal. The api
105
125
  // applies `clear` after `settings`, so naming a key that also
106
126
  // carries a value deleted the value just typed and answered "Saved".
107
- clear: clearing.filter((key) => !(data == null ? void 0 : data[key])),
127
+ //
128
+ // `clear` stays a list of dotted keys; `settings` goes nested,
129
+ // the shape the api stores.
130
+ //
131
+ // A PICKER EMPTIED IS A REMOVAL TOO. Its trash empties the value,
132
+ // and blank would keep the saved one, so a picker that held a
133
+ // saved value and is empty now is named here as well.
134
+ clear: [
135
+ ...clearing.filter((key) => !(0, import_settings_paths.readPath)(data, key)),
136
+ ...fields.filter((field) => field.hook && !(0, import_settings_paths.readPath)(data, field.key) && (0, import_settings_paths.readPath)(values == null ? void 0 : values.settings, field.key)).map((field) => field.key)
137
+ ],
108
138
  enabled: Boolean(data == null ? void 0 : data.enabled),
109
- settings: Object.fromEntries(
110
- fields.map((field) => [field.key, (data == null ? void 0 : data[field.key]) ?? ""])
139
+ settings: (0, import_settings_paths.nestPaths)(
140
+ fields.map((field) => [field.key, (0, import_settings_paths.readPath)(data, field.key) ?? ""])
111
141
  )
112
142
  },
113
143
  endpoint: "/admin/provider/" + (values == null ? void 0 : values.slug),
@@ -233,11 +263,35 @@ const FormAdminProvider = ({
233
263
  value
234
264
  }
235
265
  }
266
+ ) : field.input === "select" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
267
+ import_input_group.default,
268
+ {
269
+ ...{
270
+ error: (_a = (0, import_settings_paths.readPath)(formState == null ? void 0 : formState.errors, field.key)) == null ? void 0 : _a.message,
271
+ input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
272
+ import_form_organization_connection.Editable,
273
+ {
274
+ ...{
275
+ endpoint: "/admin/provider/" + (values == null ? void 0 : values.slug) + "/hook/" + field.hook,
276
+ field,
277
+ onChange,
278
+ titleFor: (id) => {
279
+ var _a2, _b2, _c;
280
+ return ((_c = (_b2 = (_a2 = optionsFor[field.key]) == null ? void 0 : _a2.data) == null ? void 0 : _b2.find((option) => option.value === id)) == null ? void 0 : _c.label) || id;
281
+ },
282
+ value
283
+ }
284
+ }
285
+ ),
286
+ label: field.label,
287
+ message: field.message
288
+ }
289
+ }
236
290
  ) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
237
291
  import_input_group.default,
238
292
  {
239
293
  ...{
240
- error: (_b = (_a = formState == null ? void 0 : formState.errors) == null ? void 0 : _a[field.key]) == null ? void 0 : _b.message,
294
+ error: (_b = (0, import_settings_paths.readPath)(formState == null ? void 0 : formState.errors, field.key)) == null ? void 0 : _b.message,
241
295
  input: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
242
296
  import_input_text.default,
243
297
  {