@cimplify/sdk 0.53.0 → 0.55.0

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 (43) hide show
  1. package/dist/advanced.d.mts +1 -1
  2. package/dist/advanced.d.ts +1 -1
  3. package/dist/advanced.js +20 -20
  4. package/dist/advanced.mjs +1 -1
  5. package/dist/{chunk-EJUKGJTZ.js → chunk-6W3AH4QW.js} +2 -2
  6. package/dist/{chunk-NEK7CVE2.mjs → chunk-F4WS3OIF.mjs} +1 -1
  7. package/dist/{chunk-B3Y4C4A7.mjs → chunk-I4IXPQIX.mjs} +7 -4
  8. package/dist/{chunk-YJLOOC3L.js → chunk-JGBDWEPJ.js} +7 -4
  9. package/dist/chunk-JYPLT56O.js +272 -0
  10. package/dist/{chunk-IJ32BXKZ.js → chunk-MW7ICTVK.js} +35 -35
  11. package/dist/{chunk-6QZQQRBB.mjs → chunk-SQ7U3BWY.mjs} +1 -1
  12. package/dist/chunk-XYI4NXWG.mjs +259 -0
  13. package/dist/{client-D1Gknspz.d.mts → client-Bhvlelij.d.mts} +1 -1
  14. package/dist/{client-Bj2apl_y.d.mts → client-DKg-5OWu.d.mts} +16 -1
  15. package/dist/{client-306peWZ0.d.ts → client-Dfg_hmkP.d.ts} +16 -1
  16. package/dist/{client-C2bKMy5g.d.ts → client-DlGJqSDd.d.ts} +1 -1
  17. package/dist/index.d.mts +18 -3
  18. package/dist/index.d.ts +18 -3
  19. package/dist/index.js +160 -72
  20. package/dist/index.mjs +91 -3
  21. package/dist/react.d.mts +52 -5
  22. package/dist/react.d.ts +52 -5
  23. package/dist/react.js +592 -512
  24. package/dist/react.mjs +136 -58
  25. package/dist/server.d.mts +59 -35
  26. package/dist/server.d.ts +59 -35
  27. package/dist/server.js +160 -79
  28. package/dist/server.mjs +153 -78
  29. package/dist/{ads-C2c2Aald.d.mts → sign-in-TL01-awQ.d.mts} +17 -1
  30. package/dist/{ads-C2c2Aald.d.ts → sign-in-TL01-awQ.d.ts} +17 -1
  31. package/dist/styles.css +1 -1
  32. package/dist/testing/suite.d.mts +2 -2
  33. package/dist/testing/suite.d.ts +2 -2
  34. package/dist/testing/suite.js +22 -22
  35. package/dist/testing/suite.mjs +3 -3
  36. package/dist/testing.d.mts +2 -2
  37. package/dist/testing.d.ts +2 -2
  38. package/dist/testing.js +78 -78
  39. package/dist/testing.mjs +4 -4
  40. package/package.json +2 -1
  41. package/registry/account.json +1 -1
  42. package/dist/chunk-MN4PNKJA.js +0 -129
  43. package/dist/chunk-NRDRVZ62.mjs +0 -119
@@ -1,4 +1,4 @@
1
- export { k as AuthService, z as BusinessService, O as CartOperations, P as CatalogueQueries, a8 as CheckoutOperations, a8 as CheckoutService, ae as CimplifyElement, af as CimplifyElements, aB as ELEMENT_TYPES, aC as EVENT_TYPES, aF as ElementEventType, aG as ElementOptions, aH as ElementType, aL as ElementsOptions, aR as FetchQuoteInput, aY as FxService, a$ as GetProductsOptions, b1 as InventoryService, b8 as LinkService, bc as LiteService, bj as MESSAGE_TYPES, bI as OrderQueries, bY as PriceQuote, c2 as QuoteBundleSelectionInput, c3 as QuoteCompositeSelectionInput, c4 as QuoteDynamicBuckets, c5 as QuoteStatus, c6 as QuoteUiMessage, c8 as RefreshQuoteInput, c9 as RefreshQuoteResult, cA as SchedulingService, dc as createElements } from './client-Bj2apl_y.mjs';
1
+ export { k as AuthService, z as BusinessService, O as CartOperations, P as CatalogueQueries, a8 as CheckoutOperations, a8 as CheckoutService, ae as CimplifyElement, af as CimplifyElements, aB as ELEMENT_TYPES, aC as EVENT_TYPES, aF as ElementEventType, aG as ElementOptions, aH as ElementType, aL as ElementsOptions, aR as FetchQuoteInput, aY as FxService, a$ as GetProductsOptions, b1 as InventoryService, b8 as LinkService, bc as LiteService, bj as MESSAGE_TYPES, bI as OrderQueries, bY as PriceQuote, c2 as QuoteBundleSelectionInput, c3 as QuoteCompositeSelectionInput, c4 as QuoteDynamicBuckets, c5 as QuoteStatus, c6 as QuoteUiMessage, c8 as RefreshQuoteInput, c9 as RefreshQuoteResult, cA as SchedulingService, dc as createElements } from './client-DKg-5OWu.mjs';
2
2
  import './product-B_kS4Oxa.mjs';
3
3
  import './payment-DVS7ZUEp.mjs';
4
4
 
@@ -1,4 +1,4 @@
1
- export { k as AuthService, z as BusinessService, O as CartOperations, P as CatalogueQueries, a8 as CheckoutOperations, a8 as CheckoutService, ae as CimplifyElement, af as CimplifyElements, aB as ELEMENT_TYPES, aC as EVENT_TYPES, aF as ElementEventType, aG as ElementOptions, aH as ElementType, aL as ElementsOptions, aR as FetchQuoteInput, aY as FxService, a$ as GetProductsOptions, b1 as InventoryService, b8 as LinkService, bc as LiteService, bj as MESSAGE_TYPES, bI as OrderQueries, bY as PriceQuote, c2 as QuoteBundleSelectionInput, c3 as QuoteCompositeSelectionInput, c4 as QuoteDynamicBuckets, c5 as QuoteStatus, c6 as QuoteUiMessage, c8 as RefreshQuoteInput, c9 as RefreshQuoteResult, cA as SchedulingService, dc as createElements } from './client-306peWZ0.js';
1
+ export { k as AuthService, z as BusinessService, O as CartOperations, P as CatalogueQueries, a8 as CheckoutOperations, a8 as CheckoutService, ae as CimplifyElement, af as CimplifyElements, aB as ELEMENT_TYPES, aC as EVENT_TYPES, aF as ElementEventType, aG as ElementOptions, aH as ElementType, aL as ElementsOptions, aR as FetchQuoteInput, aY as FxService, a$ as GetProductsOptions, b1 as InventoryService, b8 as LinkService, bc as LiteService, bj as MESSAGE_TYPES, bI as OrderQueries, bY as PriceQuote, c2 as QuoteBundleSelectionInput, c3 as QuoteCompositeSelectionInput, c4 as QuoteDynamicBuckets, c5 as QuoteStatus, c6 as QuoteUiMessage, c8 as RefreshQuoteInput, c9 as RefreshQuoteResult, cA as SchedulingService, dc as createElements } from './client-Dfg_hmkP.js';
2
2
  import './product-B_kS4Oxa.js';
3
3
  import './payment-sn-yGL7v.js';
4
4
 
package/dist/advanced.js CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkYJLOOC3L_js = require('./chunk-YJLOOC3L.js');
3
+ var chunkJGBDWEPJ_js = require('./chunk-JGBDWEPJ.js');
4
4
  require('./chunk-7Y2O3E4D.js');
5
5
  require('./chunk-XA3ZNR75.js');
6
6
  require('./chunk-OWW5GUSB.js');
@@ -9,77 +9,77 @@ require('./chunk-OWW5GUSB.js');
9
9
 
10
10
  Object.defineProperty(exports, "AuthService", {
11
11
  enumerable: true,
12
- get: function () { return chunkYJLOOC3L_js.AuthService; }
12
+ get: function () { return chunkJGBDWEPJ_js.AuthService; }
13
13
  });
14
14
  Object.defineProperty(exports, "BusinessService", {
15
15
  enumerable: true,
16
- get: function () { return chunkYJLOOC3L_js.BusinessService; }
16
+ get: function () { return chunkJGBDWEPJ_js.BusinessService; }
17
17
  });
18
18
  Object.defineProperty(exports, "CartOperations", {
19
19
  enumerable: true,
20
- get: function () { return chunkYJLOOC3L_js.CartOperations; }
20
+ get: function () { return chunkJGBDWEPJ_js.CartOperations; }
21
21
  });
22
22
  Object.defineProperty(exports, "CatalogueQueries", {
23
23
  enumerable: true,
24
- get: function () { return chunkYJLOOC3L_js.CatalogueQueries; }
24
+ get: function () { return chunkJGBDWEPJ_js.CatalogueQueries; }
25
25
  });
26
26
  Object.defineProperty(exports, "CheckoutOperations", {
27
27
  enumerable: true,
28
- get: function () { return chunkYJLOOC3L_js.CheckoutService; }
28
+ get: function () { return chunkJGBDWEPJ_js.CheckoutService; }
29
29
  });
30
30
  Object.defineProperty(exports, "CheckoutService", {
31
31
  enumerable: true,
32
- get: function () { return chunkYJLOOC3L_js.CheckoutService; }
32
+ get: function () { return chunkJGBDWEPJ_js.CheckoutService; }
33
33
  });
34
34
  Object.defineProperty(exports, "CimplifyElement", {
35
35
  enumerable: true,
36
- get: function () { return chunkYJLOOC3L_js.CimplifyElement; }
36
+ get: function () { return chunkJGBDWEPJ_js.CimplifyElement; }
37
37
  });
38
38
  Object.defineProperty(exports, "CimplifyElements", {
39
39
  enumerable: true,
40
- get: function () { return chunkYJLOOC3L_js.CimplifyElements; }
40
+ get: function () { return chunkJGBDWEPJ_js.CimplifyElements; }
41
41
  });
42
42
  Object.defineProperty(exports, "ELEMENT_TYPES", {
43
43
  enumerable: true,
44
- get: function () { return chunkYJLOOC3L_js.ELEMENT_TYPES; }
44
+ get: function () { return chunkJGBDWEPJ_js.ELEMENT_TYPES; }
45
45
  });
46
46
  Object.defineProperty(exports, "EVENT_TYPES", {
47
47
  enumerable: true,
48
- get: function () { return chunkYJLOOC3L_js.EVENT_TYPES; }
48
+ get: function () { return chunkJGBDWEPJ_js.EVENT_TYPES; }
49
49
  });
50
50
  Object.defineProperty(exports, "FxService", {
51
51
  enumerable: true,
52
- get: function () { return chunkYJLOOC3L_js.FxService; }
52
+ get: function () { return chunkJGBDWEPJ_js.FxService; }
53
53
  });
54
54
  Object.defineProperty(exports, "InventoryService", {
55
55
  enumerable: true,
56
- get: function () { return chunkYJLOOC3L_js.InventoryService; }
56
+ get: function () { return chunkJGBDWEPJ_js.InventoryService; }
57
57
  });
58
58
  Object.defineProperty(exports, "LinkService", {
59
59
  enumerable: true,
60
- get: function () { return chunkYJLOOC3L_js.LinkService; }
60
+ get: function () { return chunkJGBDWEPJ_js.LinkService; }
61
61
  });
62
62
  Object.defineProperty(exports, "LiteService", {
63
63
  enumerable: true,
64
- get: function () { return chunkYJLOOC3L_js.LiteService; }
64
+ get: function () { return chunkJGBDWEPJ_js.LiteService; }
65
65
  });
66
66
  Object.defineProperty(exports, "MESSAGE_TYPES", {
67
67
  enumerable: true,
68
- get: function () { return chunkYJLOOC3L_js.MESSAGE_TYPES; }
68
+ get: function () { return chunkJGBDWEPJ_js.MESSAGE_TYPES; }
69
69
  });
70
70
  Object.defineProperty(exports, "OrderQueries", {
71
71
  enumerable: true,
72
- get: function () { return chunkYJLOOC3L_js.OrderQueries; }
72
+ get: function () { return chunkJGBDWEPJ_js.OrderQueries; }
73
73
  });
74
74
  Object.defineProperty(exports, "SchedulingService", {
75
75
  enumerable: true,
76
- get: function () { return chunkYJLOOC3L_js.SchedulingService; }
76
+ get: function () { return chunkJGBDWEPJ_js.SchedulingService; }
77
77
  });
78
78
  Object.defineProperty(exports, "createElements", {
79
79
  enumerable: true,
80
- get: function () { return chunkYJLOOC3L_js.createElements; }
80
+ get: function () { return chunkJGBDWEPJ_js.createElements; }
81
81
  });
82
82
  Object.defineProperty(exports, "generateIdempotencyKey", {
83
83
  enumerable: true,
84
- get: function () { return chunkYJLOOC3L_js.generateIdempotencyKey; }
84
+ get: function () { return chunkJGBDWEPJ_js.generateIdempotencyKey; }
85
85
  });
package/dist/advanced.mjs CHANGED
@@ -1,4 +1,4 @@
1
- export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-B3Y4C4A7.mjs';
1
+ export { AuthService, BusinessService, CartOperations, CatalogueQueries, CheckoutService as CheckoutOperations, CheckoutService, CimplifyElement, CimplifyElements, ELEMENT_TYPES, EVENT_TYPES, FxService, InventoryService, LinkService, LiteService, MESSAGE_TYPES, OrderQueries, SchedulingService, createElements, generateIdempotencyKey } from './chunk-I4IXPQIX.mjs';
2
2
  import './chunk-TD3AY34U.mjs';
3
3
  import './chunk-AMZXALF6.mjs';
4
4
  import './chunk-3G6RQLXK.mjs';
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var chunkHCZTBWU4_js = require('./chunk-HCZTBWU4.js');
4
- var chunkIJ32BXKZ_js = require('./chunk-IJ32BXKZ.js');
4
+ var chunkMW7ICTVK_js = require('./chunk-MW7ICTVK.js');
5
5
  var zod = require('zod');
6
6
 
7
7
  var cimplifyRegistry = zod.z.registry();
@@ -614,7 +614,7 @@ function createTestClient(options = {}) {
614
614
  if (echoed) sessionToken = echoed;
615
615
  return res;
616
616
  };
617
- const client = chunkIJ32BXKZ_js.createCimplifyClient({
617
+ const client = chunkMW7ICTVK_js.createCimplifyClient({
618
618
  baseUrl: TEST_BASE_URL,
619
619
  // Link mock lives at /v1/link on the same Hono app, so point the SDK's
620
620
  // separate Link transport at the same TEST_BASE_URL.
@@ -1,5 +1,5 @@
1
1
  import { createMockApp } from './chunk-3G4QCENX.mjs';
2
- import { createCimplifyClient } from './chunk-6QZQQRBB.mjs';
2
+ import { createCimplifyClient } from './chunk-SQ7U3BWY.mjs';
3
3
  import { z } from 'zod';
4
4
 
5
5
  var cimplifyRegistry = z.registry();
@@ -1791,14 +1791,17 @@ var LinkService = class {
1791
1791
  if (options?.status) params.set("status", options.status);
1792
1792
  if (options?.limit) params.set("limit", String(options.limit));
1793
1793
  if (options?.offset) params.set("offset", String(options.offset));
1794
+ if (options?.businessId) params.set("business_id", options.businessId);
1794
1795
  const query = params.toString();
1795
1796
  const path = query ? `/v1/link/orders?${query}` : "/v1/link/orders";
1796
1797
  return safe(this.client.linkGet(path));
1797
1798
  }
1798
- async getOrder(orderId) {
1799
- return safe(
1800
- this.client.linkGet(`/v1/link/orders/${encodePathSegment(orderId)}`)
1801
- );
1799
+ async getOrder(orderId, options) {
1800
+ const params = new URLSearchParams();
1801
+ if (options?.businessId) params.set("business_id", options.businessId);
1802
+ const query = params.toString();
1803
+ const path = query ? `/v1/link/orders/${encodePathSegment(orderId)}?${query}` : `/v1/link/orders/${encodePathSegment(orderId)}`;
1804
+ return safe(this.client.linkGet(path));
1802
1805
  }
1803
1806
  async enroll(data, opts) {
1804
1807
  const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
@@ -1793,14 +1793,17 @@ var LinkService = class {
1793
1793
  if (options?.status) params.set("status", options.status);
1794
1794
  if (options?.limit) params.set("limit", String(options.limit));
1795
1795
  if (options?.offset) params.set("offset", String(options.offset));
1796
+ if (options?.businessId) params.set("business_id", options.businessId);
1796
1797
  const query = params.toString();
1797
1798
  const path = query ? `/v1/link/orders?${query}` : "/v1/link/orders";
1798
1799
  return safe(this.client.linkGet(path));
1799
1800
  }
1800
- async getOrder(orderId) {
1801
- return safe(
1802
- this.client.linkGet(`/v1/link/orders/${encodePathSegment(orderId)}`)
1803
- );
1801
+ async getOrder(orderId, options) {
1802
+ const params = new URLSearchParams();
1803
+ if (options?.businessId) params.set("business_id", options.businessId);
1804
+ const query = params.toString();
1805
+ const path = query ? `/v1/link/orders/${encodePathSegment(orderId)}?${query}` : `/v1/link/orders/${encodePathSegment(orderId)}`;
1806
+ return safe(this.client.linkGet(path));
1804
1807
  }
1805
1808
  async enroll(data, opts) {
1806
1809
  const idempotencyKey = opts?.idempotencyKey ?? generateIdempotencyKey();
@@ -0,0 +1,272 @@
1
+ 'use strict';
2
+
3
+ // src/utils/variant.ts
4
+ function stripProductPrefix(variantName, productName) {
5
+ if (!variantName || !productName) return variantName || productName;
6
+ const lower = variantName.toLowerCase().trim();
7
+ if (lower === "default" || lower === "standard") return productName;
8
+ if (lower.endsWith("-default") || lower.endsWith("-standard")) return productName;
9
+ if (variantName.startsWith(productName)) {
10
+ const rest = variantName.slice(productName.length);
11
+ const match = rest.match(/^\s*[-–—]\s*(.*)/);
12
+ if (match && match[1].length > 0) return match[1];
13
+ }
14
+ const lowerProduct = productName.toLowerCase().trim();
15
+ if (lower.startsWith(lowerProduct)) {
16
+ const rest = variantName.slice(productName.length);
17
+ const match = rest.match(/^\s*[-–—]\s*(.*)/);
18
+ if (match && match[1].length > 0) return match[1];
19
+ }
20
+ const lastDash = variantName.lastIndexOf("-");
21
+ if (lastDash > 0 && lastDash < variantName.length - 1) {
22
+ const prefix = variantName.slice(0, lastDash).trim();
23
+ const suffix = variantName.slice(lastDash + 1).trim();
24
+ if (suffix.length > 0 && prefix.length > suffix.length * 2) {
25
+ return suffix;
26
+ }
27
+ }
28
+ return variantName;
29
+ }
30
+ function getVariantDisplayName(variant, productName) {
31
+ if (variant.display_attributes?.length) {
32
+ return variant.display_attributes.map((a) => a.value_name).join(" / ");
33
+ }
34
+ if (variant.name) {
35
+ return productName ? stripProductPrefix(variant.name, productName) : variant.name;
36
+ }
37
+ return productName || (variant.is_default ? "Default" : "Option");
38
+ }
39
+
40
+ // src/types/product.ts
41
+ var PRODUCT_TYPE = {
42
+ Product: "product",
43
+ Service: "service",
44
+ Digital: "digital",
45
+ Bundle: "bundle",
46
+ Composite: "composite"
47
+ };
48
+ var RENDER_HINT = {
49
+ Food: "food",
50
+ Physical: "physical",
51
+ General: "general"
52
+ };
53
+ var DURATION_UNIT = {
54
+ Minutes: "minutes",
55
+ Hours: "hours",
56
+ Days: "days",
57
+ Nights: "nights",
58
+ Weeks: "weeks",
59
+ Months: "months",
60
+ Years: "years"
61
+ };
62
+ var INPUT_FIELD_TYPE = {
63
+ Text: "text",
64
+ Textarea: "textarea",
65
+ Number: "number",
66
+ Select: "select",
67
+ Radio: "radio",
68
+ Checkbox: "checkbox",
69
+ Color: "color",
70
+ Date: "date",
71
+ File: "file",
72
+ Image: "image",
73
+ Url: "url",
74
+ Address: "address",
75
+ Phone: "phone",
76
+ Email: "email",
77
+ DateTime: "date_time",
78
+ Time: "time",
79
+ Signature: "signature",
80
+ MultiSelect: "multi_select",
81
+ DateRange: "date_range",
82
+ Location: "location"
83
+ };
84
+
85
+ // src/internal/pkce.ts
86
+ var VERIFIER_BYTES = 64;
87
+ async function generatePkce() {
88
+ const random = new Uint8Array(VERIFIER_BYTES);
89
+ crypto.getRandomValues(random);
90
+ const verifier = base64UrlEncode(random);
91
+ const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
92
+ const challenge = base64UrlEncode(new Uint8Array(digest));
93
+ return { verifier, challenge, method: "S256" };
94
+ }
95
+ function generateState(byteLength = 16) {
96
+ const buf = new Uint8Array(byteLength);
97
+ crypto.getRandomValues(buf);
98
+ return base64UrlEncode(buf);
99
+ }
100
+ function base64UrlEncode(bytes) {
101
+ let str = "";
102
+ for (const byte of bytes) str += String.fromCharCode(byte);
103
+ return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
104
+ }
105
+
106
+ // src/internal/modal-iframe.ts
107
+ function openModalIframe(opts) {
108
+ const overlay = document.createElement("div");
109
+ overlay.dataset.cimplifyModal = "1";
110
+ Object.assign(overlay.style, {
111
+ position: "fixed",
112
+ inset: "0",
113
+ background: "rgba(15, 18, 24, 0.55)",
114
+ zIndex: "2147483647",
115
+ display: "grid",
116
+ placeItems: "center",
117
+ backdropFilter: "blur(2px)"
118
+ });
119
+ const card = document.createElement("div");
120
+ Object.assign(card.style, {
121
+ width: `${opts.width ?? 440}px`,
122
+ maxWidth: "calc(100vw - 24px)",
123
+ height: `${opts.height ?? 620}px`,
124
+ maxHeight: "calc(100vh - 48px)",
125
+ background: "#fff",
126
+ borderRadius: "14px",
127
+ overflow: "hidden",
128
+ boxShadow: "0 24px 64px rgba(0,0,0,0.25)"
129
+ });
130
+ const iframe = document.createElement("iframe");
131
+ iframe.src = opts.src;
132
+ iframe.style.width = "100%";
133
+ iframe.style.height = "100%";
134
+ iframe.style.border = "none";
135
+ iframe.setAttribute(
136
+ "sandbox",
137
+ opts.sandbox ?? "allow-scripts allow-same-origin allow-forms allow-popups"
138
+ );
139
+ iframe.setAttribute("allow", "publickey-credentials-get; publickey-credentials-create");
140
+ card.appendChild(iframe);
141
+ overlay.appendChild(card);
142
+ document.body.appendChild(overlay);
143
+ const close = () => {
144
+ overlay.remove();
145
+ document.removeEventListener("keydown", onKey);
146
+ opts.onClose?.();
147
+ };
148
+ const onKey = (e) => {
149
+ if (e.key === "Escape") close();
150
+ };
151
+ overlay.addEventListener("click", (e) => {
152
+ if (e.target === overlay) close();
153
+ });
154
+ document.addEventListener("keydown", onKey);
155
+ return { iframe, close };
156
+ }
157
+
158
+ // src/sign-in.ts
159
+ var DEFAULT_AUTH_URL = "https://auth.cimplify.io";
160
+ var DEFAULT_SCOPE = "openid email phone profile";
161
+ async function startSignIn(opts) {
162
+ const authUrl = (opts.authUrl ?? DEFAULT_AUTH_URL).replace(/\/$/, "");
163
+ const callbackUri = opts.callbackUri ?? "/auth/callback";
164
+ const pkce = await generatePkce();
165
+ const state = generateState();
166
+ const params = new URLSearchParams({
167
+ response_type: "code",
168
+ response_mode: "web_message",
169
+ client_id: opts.clientId,
170
+ redirect_uri: opts.redirectUri,
171
+ scope: opts.scope ?? DEFAULT_SCOPE,
172
+ state,
173
+ code_challenge: pkce.challenge,
174
+ code_challenge_method: pkce.method
175
+ });
176
+ if (opts.loginHint) params.set("login_hint", opts.loginHint);
177
+ if (opts.prompt) params.set("prompt", opts.prompt);
178
+ const src = `${authUrl}/oauth/authorize?${params.toString()}`;
179
+ const expectedOrigin = new URL(authUrl).origin;
180
+ const modal = openModalIframe({
181
+ src,
182
+ onClose: () => {
183
+ window.removeEventListener("message", handler);
184
+ }
185
+ });
186
+ const handler = async (event) => {
187
+ if (event.origin !== expectedOrigin) return;
188
+ const data = event.data;
189
+ if (!data || typeof data !== "object" || data.type !== "authorization_response") return;
190
+ const response = data.response;
191
+ if (response.error) {
192
+ modal.close();
193
+ opts.onError?.({ error: response.error, description: response.error_description });
194
+ return;
195
+ }
196
+ if (!response.code) return;
197
+ if (response.state !== state) {
198
+ modal.close();
199
+ opts.onError?.({ error: "state_mismatch" });
200
+ return;
201
+ }
202
+ try {
203
+ const res = await fetch(callbackUri, {
204
+ method: "POST",
205
+ credentials: "include",
206
+ headers: { "Content-Type": "application/json" },
207
+ body: JSON.stringify({ code: response.code, codeVerifier: pkce.verifier, state })
208
+ });
209
+ if (!res.ok) {
210
+ const body = await res.text().catch(() => "");
211
+ opts.onError?.({ error: "callback_failed", description: body });
212
+ modal.close();
213
+ return;
214
+ }
215
+ modal.close();
216
+ opts.onSuccess?.();
217
+ } catch (e) {
218
+ opts.onError?.({ error: "callback_exception", description: String(e) });
219
+ modal.close();
220
+ }
221
+ };
222
+ window.addEventListener("message", handler);
223
+ }
224
+
225
+ // src/assets/url.ts
226
+ var DEFAULT_CDN_BASE_URL = "https://storefrontassetscdn.cimplify.io";
227
+ var CIMPLIFY_CDN_HOSTS = [
228
+ "storefrontassetscdn.cimplify.io",
229
+ "cdn.cimplify.io",
230
+ "static-tmp.cimplify.io"
231
+ ];
232
+ var ABSOLUTE_URL_RE = /^https?:\/\//i;
233
+ var MOCK_PASSTHROUGH_RE = /^\/(img|elements|_mock)\//;
234
+ function assetUrl(path, opts = {}) {
235
+ if (!path) return path;
236
+ if (ABSOLUTE_URL_RE.test(path)) return appendTransform(path, opts);
237
+ if (MOCK_PASSTHROUGH_RE.test(path)) return appendTransform(path, opts);
238
+ const base = (opts.base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
239
+ const normalized = path.replace(/^\/+/, "");
240
+ return appendTransform(`${base}/${normalized}`, opts);
241
+ }
242
+ function isCimplifyAsset(src, base) {
243
+ if (!src) return false;
244
+ if (!ABSOLUTE_URL_RE.test(src)) return true;
245
+ if (MOCK_PASSTHROUGH_RE.test(src)) return true;
246
+ const resolvedBase = (base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
247
+ if (resolvedBase && src.startsWith(resolvedBase)) return true;
248
+ return CIMPLIFY_CDN_HOSTS.some((host) => src.startsWith(`https://${host}/`));
249
+ }
250
+ function appendTransform(url, t) {
251
+ const params = new URLSearchParams();
252
+ if (t.w != null) params.set("w", String(t.w));
253
+ if (t.h != null) params.set("h", String(t.h));
254
+ if (t.quality != null) params.set("quality", String(t.quality));
255
+ if (t.format != null) params.set("format", t.format);
256
+ const query = params.toString();
257
+ if (!query) return url;
258
+ return `${url}${url.includes("?") ? "&" : "?"}${query}`;
259
+ }
260
+
261
+ exports.CIMPLIFY_CDN_HOSTS = CIMPLIFY_CDN_HOSTS;
262
+ exports.DEFAULT_CDN_BASE_URL = DEFAULT_CDN_BASE_URL;
263
+ exports.DURATION_UNIT = DURATION_UNIT;
264
+ exports.INPUT_FIELD_TYPE = INPUT_FIELD_TYPE;
265
+ exports.PRODUCT_TYPE = PRODUCT_TYPE;
266
+ exports.RENDER_HINT = RENDER_HINT;
267
+ exports.assetUrl = assetUrl;
268
+ exports.generatePkce = generatePkce;
269
+ exports.generateState = generateState;
270
+ exports.getVariantDisplayName = getVariantDisplayName;
271
+ exports.isCimplifyAsset = isCimplifyAsset;
272
+ exports.startSignIn = startSignIn;