@drawbridge/components 0.1.47 → 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 (114) 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.js +1 -0
  10. package/dist/bridge/form-subdomain.mjs +2 -1
  11. package/dist/bridge/lib/age-gate.js +12 -0
  12. package/dist/bridge/lib/age-gate.mjs +11 -0
  13. package/dist/bridge/lib/cart.js +79 -0
  14. package/dist/bridge/lib/cart.mjs +48 -0
  15. package/dist/bridge/lib/checkout-kit.js +2 -32
  16. package/dist/bridge/lib/checkout-kit.mjs +2 -32
  17. package/dist/bridge/product-tile.js +9 -6
  18. package/dist/bridge/product-tile.mjs +9 -6
  19. package/dist/bridge/template-layout.js +237 -122
  20. package/dist/bridge/template-layout.mjs +237 -122
  21. package/dist/bridge/template-modal.js +28 -73
  22. package/dist/bridge/template-modal.mjs +29 -74
  23. package/dist/dashboard/buttons-subscription.js +1 -1
  24. package/dist/dashboard/buttons-subscription.mjs +1 -1
  25. package/dist/dashboard/campaign-form.js +7 -2
  26. package/dist/dashboard/campaign-form.mjs +7 -2
  27. package/dist/dashboard/card-order.js +22 -4
  28. package/dist/dashboard/card-order.mjs +22 -4
  29. package/dist/dashboard/embed-stripe.js +145 -0
  30. package/dist/dashboard/embed-stripe.mjs +116 -0
  31. package/dist/dashboard/form-admin-provider.js +71 -17
  32. package/dist/dashboard/form-admin-provider.mjs +71 -17
  33. package/dist/dashboard/form-file-upload.js +3 -2
  34. package/dist/dashboard/form-file-upload.mjs +4 -3
  35. package/dist/dashboard/form-organization-campaign-advertisements.js +47 -6
  36. package/dist/dashboard/form-organization-campaign-advertisements.mjs +47 -6
  37. package/dist/dashboard/form-organization-campaign-field-birthday.js +193 -0
  38. package/dist/dashboard/form-organization-campaign-field-birthday.mjs +164 -0
  39. package/dist/dashboard/form-organization-campaign-field-rating.js +246 -0
  40. package/dist/dashboard/form-organization-campaign-field-rating.mjs +217 -0
  41. package/dist/dashboard/form-organization-campaign.js +82 -0
  42. package/dist/dashboard/form-organization-campaign.mjs +81 -0
  43. package/dist/dashboard/form-organization-connection.js +48 -6
  44. package/dist/dashboard/form-organization-connection.mjs +48 -7
  45. package/dist/dashboard/form-organization-product.js +1461 -0
  46. package/dist/dashboard/form-organization-product.mjs +1425 -0
  47. package/dist/dashboard/form-organization-workflow.js +72 -1
  48. package/dist/dashboard/form-organization-workflow.mjs +69 -1
  49. package/dist/dashboard/form-otc.js +4 -5
  50. package/dist/dashboard/form-otc.mjs +4 -5
  51. package/dist/dashboard/form-stripe.js +12 -5
  52. package/dist/dashboard/form-stripe.mjs +12 -5
  53. package/dist/dashboard/input-fields.js +11 -158
  54. package/dist/dashboard/input-fields.mjs +11 -158
  55. package/dist/dashboard/input-file.js +21 -4
  56. package/dist/dashboard/input-file.mjs +21 -4
  57. package/dist/dashboard/input-gallery.js +201 -0
  58. package/dist/dashboard/input-gallery.mjs +172 -0
  59. package/dist/dashboard/lib/connection-controls.js +5 -2
  60. package/dist/dashboard/lib/connection-controls.mjs +3 -1
  61. package/dist/dashboard/lib/form-page.js +1 -1
  62. package/dist/dashboard/lib/form-page.mjs +1 -1
  63. package/dist/dashboard/lib/products.js +169 -0
  64. package/dist/dashboard/lib/products.mjs +135 -0
  65. package/dist/dashboard/lib/settings-paths.js +35 -0
  66. package/dist/dashboard/lib/settings-paths.mjs +11 -0
  67. package/dist/dashboard/lib/uppy.js +10 -1
  68. package/dist/dashboard/lib/uppy.mjs +11 -2
  69. package/dist/dashboard/order-sections.js +456 -6
  70. package/dist/dashboard/order-sections.mjs +453 -7
  71. package/dist/dashboard/provider-ui.js +9 -7
  72. package/dist/dashboard/provider-ui.mjs +9 -7
  73. package/dist/dashboard/shipping-rates.js +404 -0
  74. package/dist/dashboard/shipping-rates.mjs +371 -0
  75. package/dist/dashboard/template-buyer.js +301 -0
  76. package/dist/dashboard/template-buyer.mjs +267 -0
  77. package/dist/input-checkbox.js +28 -10
  78. package/dist/input-checkbox.mjs +28 -10
  79. package/dist/product.js +96 -24
  80. package/dist/product.mjs +97 -25
  81. package/dist/shared/lib/helpers.js +54 -6
  82. package/dist/shared/lib/helpers.mjs +53 -8
  83. package/dist/shared/order-summary.js +139 -0
  84. package/dist/shared/order-summary.mjs +110 -0
  85. package/package.json +74 -4
  86. package/types/bridge/cart-drawer.d.ts +31 -0
  87. package/types/bridge/fields.d.ts +14 -2
  88. package/types/bridge/form-subdomain-checkout.d.ts +20 -0
  89. package/types/bridge/form-subdomain-shop-modal.d.ts +27 -3
  90. package/types/bridge/lib/age-gate.d.ts +5 -0
  91. package/types/bridge/lib/cart.d.ts +44 -0
  92. package/types/bridge/lib/checkout-kit.d.ts +2 -10
  93. package/types/dashboard/card-order.d.ts +6 -0
  94. package/types/dashboard/embed-stripe.d.ts +25 -0
  95. package/types/dashboard/form-admin-provider.d.ts +9 -2
  96. package/types/dashboard/form-file-upload.d.ts +2 -1
  97. package/types/dashboard/form-organization-campaign-advertisements.d.ts +3 -0
  98. package/types/dashboard/form-organization-campaign-field-birthday.d.ts +31 -0
  99. package/types/dashboard/form-organization-campaign-field-rating.d.ts +33 -0
  100. package/types/dashboard/form-organization-campaign.d.ts +3 -0
  101. package/types/dashboard/form-organization-connection.d.ts +11 -0
  102. package/types/dashboard/form-organization-product.d.ts +24 -0
  103. package/types/dashboard/form-otc.d.ts +5 -1
  104. package/types/dashboard/form-stripe.d.ts +3 -2
  105. package/types/dashboard/input-file.d.ts +2 -0
  106. package/types/dashboard/input-gallery.d.ts +14 -0
  107. package/types/dashboard/lib/products.d.ts +14 -0
  108. package/types/dashboard/lib/settings-paths.d.ts +5 -0
  109. package/types/dashboard/order-sections.d.ts +24 -1
  110. package/types/dashboard/shipping-rates.d.ts +26 -0
  111. package/types/dashboard/template-buyer.d.ts +50 -0
  112. package/types/input-checkbox.d.ts +2 -0
  113. package/types/shared/lib/helpers.d.ts +4 -0
  114. package/types/shared/order-summary.d.ts +19 -0
@@ -0,0 +1,79 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var cart_exports = {};
19
+ __export(cart_exports, {
20
+ canCheckout: () => canCheckout,
21
+ cartAlive: () => cartAlive,
22
+ cartCount: () => cartCount,
23
+ cartKey: () => cartKey,
24
+ continueRequest: () => continueRequest,
25
+ lineNote: () => lineNote,
26
+ productImage: () => productImage,
27
+ recommendedRow: () => recommendedRow,
28
+ withQuantity: () => withQuantity
29
+ });
30
+ module.exports = __toCommonJS(cart_exports);
31
+ var import_cdn = require("@drawbridge/drawbridge-utils/cdn");
32
+ var import_products = require("@drawbridge/drawbridge-utils/products");
33
+ const cartKey = ({ campaign, subdomain }) => "drawbridge.cart." + subdomain + "." + campaign;
34
+ const DAY = 24 * 60 * 60 * 1e3;
35
+ const cartAlive = (made, now = Date.now()) => Number.isFinite(Number(made)) && Number(made) > 0 && now - Number(made) <= import_products.CART_DAYS * DAY;
36
+ const cartCount = (cart) => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + ((line == null ? void 0 : line.quantity) || 0), 0);
37
+ const withQuantity = (cart, id, quantity) => cart && {
38
+ ...cart,
39
+ lines: (cart.lines || []).map((line) => line.id === id ? { ...line, quantity } : line).filter((line) => line.quantity > 0)
40
+ };
41
+ const lineNote = (line, cut = []) => (line == null ? void 0 : line.availableForSale) === false ? "Sold out" : (cut || []).includes(line == null ? void 0 : line.id) && Number.isFinite(line == null ? void 0 : line.left) ? "Only " + line.left + " left" : null;
42
+ const canCheckout = (cart) => ((cart == null ? void 0 : cart.lines) || []).length > 0 && !cart.lines.some((line) => line.availableForSale === false);
43
+ const continueRequest = ({ cartId, email, params, preview = false }) => !preview && cartId ? {
44
+ body: {
45
+ cartId,
46
+ email
47
+ },
48
+ endpoint: "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart",
49
+ method: "PUT"
50
+ } : null;
51
+ const productImage = (product, size) => {
52
+ var _a;
53
+ const variant = ((product == null ? void 0 : product.variants) || []).find((item) => (item == null ? void 0 : item.availableForSale) !== false) || null;
54
+ const first = (_a = product == null ? void 0 : product.images) == null ? void 0 : _a[0];
55
+ const file = (first == null ? void 0 : first.file) && typeof first.file === "object" ? first.file : null;
56
+ return file && ((0, import_cdn.cdnSrc)(file, size, file.updatedAt) || (0, import_cdn.cdnSrc)(file, "original", file.updatedAt)) || (first == null ? void 0 : first.url) || (variant == null ? void 0 : variant.image) || (product == null ? void 0 : product.image) || null;
57
+ };
58
+ const recommendedRow = (product) => {
59
+ const variant = ((product == null ? void 0 : product.variants) || []).find((item) => (item == null ? void 0 : item.availableForSale) !== false) || null;
60
+ return {
61
+ currency: (variant == null ? void 0 : variant.currency) || null,
62
+ id: product == null ? void 0 : product.id,
63
+ image: productImage(product, "100x100"),
64
+ price: Number.isFinite(variant == null ? void 0 : variant.price) ? variant.price : null,
65
+ title: (product == null ? void 0 : product.title) || ""
66
+ };
67
+ };
68
+ // Annotate the CommonJS export names for ESM import in node:
69
+ 0 && (module.exports = {
70
+ canCheckout,
71
+ cartAlive,
72
+ cartCount,
73
+ cartKey,
74
+ continueRequest,
75
+ lineNote,
76
+ productImage,
77
+ recommendedRow,
78
+ withQuantity
79
+ });
@@ -0,0 +1,48 @@
1
+ import { cdnSrc } from "@drawbridge/drawbridge-utils/cdn";
2
+ import { CART_DAYS } from "@drawbridge/drawbridge-utils/products";
3
+ const cartKey = ({ campaign, subdomain }) => "drawbridge.cart." + subdomain + "." + campaign;
4
+ const DAY = 24 * 60 * 60 * 1e3;
5
+ const cartAlive = (made, now = Date.now()) => Number.isFinite(Number(made)) && Number(made) > 0 && now - Number(made) <= CART_DAYS * DAY;
6
+ const cartCount = (cart) => ((cart == null ? void 0 : cart.lines) || []).reduce((sum, line) => sum + ((line == null ? void 0 : line.quantity) || 0), 0);
7
+ const withQuantity = (cart, id, quantity) => cart && {
8
+ ...cart,
9
+ lines: (cart.lines || []).map((line) => line.id === id ? { ...line, quantity } : line).filter((line) => line.quantity > 0)
10
+ };
11
+ const lineNote = (line, cut = []) => (line == null ? void 0 : line.availableForSale) === false ? "Sold out" : (cut || []).includes(line == null ? void 0 : line.id) && Number.isFinite(line == null ? void 0 : line.left) ? "Only " + line.left + " left" : null;
12
+ const canCheckout = (cart) => ((cart == null ? void 0 : cart.lines) || []).length > 0 && !cart.lines.some((line) => line.availableForSale === false);
13
+ const continueRequest = ({ cartId, email, params, preview = false }) => !preview && cartId ? {
14
+ body: {
15
+ cartId,
16
+ email
17
+ },
18
+ endpoint: "/subdomain/" + (params == null ? void 0 : params.subdomain) + "/page/" + (params == null ? void 0 : params.slug) + "/cart",
19
+ method: "PUT"
20
+ } : null;
21
+ const productImage = (product, size) => {
22
+ var _a;
23
+ const variant = ((product == null ? void 0 : product.variants) || []).find((item) => (item == null ? void 0 : item.availableForSale) !== false) || null;
24
+ const first = (_a = product == null ? void 0 : product.images) == null ? void 0 : _a[0];
25
+ const file = (first == null ? void 0 : first.file) && typeof first.file === "object" ? first.file : null;
26
+ return file && (cdnSrc(file, size, file.updatedAt) || cdnSrc(file, "original", file.updatedAt)) || (first == null ? void 0 : first.url) || (variant == null ? void 0 : variant.image) || (product == null ? void 0 : product.image) || null;
27
+ };
28
+ const recommendedRow = (product) => {
29
+ const variant = ((product == null ? void 0 : product.variants) || []).find((item) => (item == null ? void 0 : item.availableForSale) !== false) || null;
30
+ return {
31
+ currency: (variant == null ? void 0 : variant.currency) || null,
32
+ id: product == null ? void 0 : product.id,
33
+ image: productImage(product, "100x100"),
34
+ price: Number.isFinite(variant == null ? void 0 : variant.price) ? variant.price : null,
35
+ title: (product == null ? void 0 : product.title) || ""
36
+ };
37
+ };
38
+ export {
39
+ canCheckout,
40
+ cartAlive,
41
+ cartCount,
42
+ cartKey,
43
+ continueRequest,
44
+ lineNote,
45
+ productImage,
46
+ recommendedRow,
47
+ withQuantity
48
+ };
@@ -31,7 +31,6 @@ __export(checkout_kit_exports, {
31
31
  ensureCheckoutKit: () => ensureCheckoutKit
32
32
  });
33
33
  module.exports = __toCommonJS(checkout_kit_exports);
34
- var import_fetch = require("@drawbridge/drawbridge-utils/fetch");
35
34
  var import_inapp_spy = __toESM(require("inapp-spy"));
36
35
  let registration = null;
37
36
  const ensureCheckoutKit = () => {
@@ -84,42 +83,13 @@ const openCheckoutPopup = ({ checkoutUrl, onClose, onComplete }) => {
84
83
  return true;
85
84
  };
86
85
  const checkout = async ({
87
- advertisement,
88
- affiliate,
89
- campaign,
90
86
  checkoutUrl,
91
- lines,
92
87
  onClose,
93
88
  onComplete,
94
89
  onOpen,
95
- onRedirect,
96
- organization,
97
- page,
98
- slug,
99
- subdomain
90
+ onRedirect
100
91
  }) => {
101
- let url = checkoutUrl;
102
- if (!url && lines) {
103
- const attributes = [
104
- ...campaign ? [{ key: "_drwbrdg_ca", value: campaign }] : [],
105
- ...organization ? [{ key: "_drwbrdg_or", value: organization }] : [],
106
- ...advertisement ? [{ key: "_drwbrdg_ad", value: advertisement }] : [],
107
- ...affiliate ? [{ key: "_drwbrdg_af", value: affiliate }] : [],
108
- ...page ? [{ key: "_drwbrdg_pg", value: page }] : []
109
- ];
110
- const { result } = await (0, import_fetch.request)({
111
- body: {
112
- lines: lines.map((line) => ({
113
- ...line,
114
- attributes
115
- }))
116
- },
117
- endpoint: "/subdomain/" + subdomain + "/page/" + slug + "/cart",
118
- method: "POST"
119
- });
120
- url = result == null ? void 0 : result.checkoutUrl;
121
- }
122
- ;
92
+ const url = checkoutUrl;
123
93
  if (!url) return null;
124
94
  const opened = openCheckoutPopup({
125
95
  checkoutUrl: url,
@@ -1,4 +1,3 @@
1
- import { request } from "@drawbridge/drawbridge-utils/fetch";
2
1
  import InAppSpy from "inapp-spy";
3
2
  let registration = null;
4
3
  const ensureCheckoutKit = () => {
@@ -51,42 +50,13 @@ const openCheckoutPopup = ({ checkoutUrl, onClose, onComplete }) => {
51
50
  return true;
52
51
  };
53
52
  const checkout = async ({
54
- advertisement,
55
- affiliate,
56
- campaign,
57
53
  checkoutUrl,
58
- lines,
59
54
  onClose,
60
55
  onComplete,
61
56
  onOpen,
62
- onRedirect,
63
- organization,
64
- page,
65
- slug,
66
- subdomain
57
+ onRedirect
67
58
  }) => {
68
- let url = checkoutUrl;
69
- if (!url && lines) {
70
- const attributes = [
71
- ...campaign ? [{ key: "_drwbrdg_ca", value: campaign }] : [],
72
- ...organization ? [{ key: "_drwbrdg_or", value: organization }] : [],
73
- ...advertisement ? [{ key: "_drwbrdg_ad", value: advertisement }] : [],
74
- ...affiliate ? [{ key: "_drwbrdg_af", value: affiliate }] : [],
75
- ...page ? [{ key: "_drwbrdg_pg", value: page }] : []
76
- ];
77
- const { result } = await request({
78
- body: {
79
- lines: lines.map((line) => ({
80
- ...line,
81
- attributes
82
- }))
83
- },
84
- endpoint: "/subdomain/" + subdomain + "/page/" + slug + "/cart",
85
- method: "POST"
86
- });
87
- url = result == null ? void 0 : result.checkoutUrl;
88
- }
89
- ;
59
+ const url = checkoutUrl;
90
60
  if (!url) return null;
91
61
  const opened = openCheckoutPopup({
92
62
  checkoutUrl: url,
@@ -33,9 +33,10 @@ __export(product_tile_exports, {
33
33
  module.exports = __toCommonJS(product_tile_exports);
34
34
  var import_jsx_runtime = require("react/jsx-runtime");
35
35
  var import_image = __toESM(require("next/image"));
36
- var import_drawbridge_utils = require("@drawbridge/drawbridge-utils");
36
+ var import_helpers = require("../shared/lib/helpers");
37
37
  var import_button = __toESM(require("../shared/button"));
38
38
  var import_styles = require("../styles");
39
+ var import_cart = require("./lib/cart");
39
40
  const CardProduct = ({
40
41
  eager,
41
42
  title,
@@ -45,13 +46,16 @@ const CardProduct = ({
45
46
  variants,
46
47
  ...rest
47
48
  }) => {
48
- var _a, _b, _c, _d;
49
+ var _a, _b, _c;
49
50
  const available = (variants || []).filter((variant) => variant.availableForSale);
50
51
  const price = ((_a = available[0]) == null ? void 0 : _a.price) || null;
51
52
  const currency = ((_b = available[0]) == null ? void 0 : _b.currency) || null;
52
- const image = ((_c = available[0]) == null ? void 0 : _c.image) || (rest == null ? void 0 : rest.image) || null;
53
+ const image = (0, import_cart.productImage)({
54
+ ...rest,
55
+ variants
56
+ }, "400x400");
53
57
  const textSize = stacked ? "text-base" : "text-xs sm:text-sm";
54
- const imageRadius = ((_d = style == null ? void 0 : style.image) == null ? void 0 : _d.radius) != null ? style.image.radius + "px" : "12px";
58
+ const imageRadius = ((_c = style == null ? void 0 : style.image) == null ? void 0 : _c.radius) != null ? style.image.radius + "px" : "12px";
55
59
  return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
56
60
  import_button.default,
57
61
  {
@@ -99,9 +103,8 @@ const CardProduct = ({
99
103
  ...{
100
104
  className: textSize + " font-bold text-center mb-1"
101
105
  },
102
- children: available.length > 0 && price ? (0, import_drawbridge_utils.formatCurrency)({
106
+ children: available.length > 0 && price ? (0, import_helpers.money)({
103
107
  code: currency,
104
- display: "parts",
105
108
  value: price
106
109
  }) : "Unavailable"
107
110
  }
@@ -1,9 +1,10 @@
1
1
  "use client";
2
2
  import { jsx, jsxs } from "react/jsx-runtime";
3
3
  import Image from "next/image";
4
- import { formatCurrency } from "@drawbridge/drawbridge-utils";
4
+ import { money } from "../shared/lib/helpers.mjs";
5
5
  import Button from "../shared/button.mjs";
6
6
  import { headerStyle } from "../styles.mjs";
7
+ import { productImage } from "./lib/cart.mjs";
7
8
  const CardProduct = ({
8
9
  eager,
9
10
  title,
@@ -13,13 +14,16 @@ const CardProduct = ({
13
14
  variants,
14
15
  ...rest
15
16
  }) => {
16
- var _a, _b, _c, _d;
17
+ var _a, _b, _c;
17
18
  const available = (variants || []).filter((variant) => variant.availableForSale);
18
19
  const price = ((_a = available[0]) == null ? void 0 : _a.price) || null;
19
20
  const currency = ((_b = available[0]) == null ? void 0 : _b.currency) || null;
20
- const image = ((_c = available[0]) == null ? void 0 : _c.image) || (rest == null ? void 0 : rest.image) || null;
21
+ const image = productImage({
22
+ ...rest,
23
+ variants
24
+ }, "400x400");
21
25
  const textSize = stacked ? "text-base" : "text-xs sm:text-sm";
22
- const imageRadius = ((_d = style == null ? void 0 : style.image) == null ? void 0 : _d.radius) != null ? style.image.radius + "px" : "12px";
26
+ const imageRadius = ((_c = style == null ? void 0 : style.image) == null ? void 0 : _c.radius) != null ? style.image.radius + "px" : "12px";
23
27
  return /* @__PURE__ */ jsx(
24
28
  Button,
25
29
  {
@@ -67,9 +71,8 @@ const CardProduct = ({
67
71
  ...{
68
72
  className: textSize + " font-bold text-center mb-1"
69
73
  },
70
- children: available.length > 0 && price ? formatCurrency({
74
+ children: available.length > 0 && price ? money({
71
75
  code: currency,
72
- display: "parts",
73
76
  value: price
74
77
  }) : "Unavailable"
75
78
  }