@cimplify/sdk 0.65.0 → 0.67.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 (53) 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-AVQL3TSJ.js → chunk-3QSW33RG.js} +389 -78
  6. package/dist/chunk-E6T5VJMG.mjs +156 -0
  7. package/dist/{chunk-WDTFIIY6.mjs → chunk-FNK6UZOE.mjs} +2 -2
  8. package/dist/{chunk-3G4QCENX.mjs → chunk-FVGVJ4TC.mjs} +12 -50
  9. package/dist/chunk-IQLJJW2H.js +168 -0
  10. package/dist/{chunk-PKYZBKZD.mjs → chunk-JAPCAZN4.mjs} +10 -29
  11. package/dist/{chunk-R6363CC7.mjs → chunk-QQMDEGAK.mjs} +382 -79
  12. package/dist/{chunk-VKID3QUE.js → chunk-SH6HJW4A.js} +4 -4
  13. package/dist/{chunk-VAMZPBA4.js → chunk-SSLFZPAI.js} +44 -63
  14. package/dist/{chunk-HCZTBWU4.js → chunk-SXGFJEME.js} +12 -50
  15. package/dist/{client-BS5lNWWH.d.mts → client-ByI_3jfL.d.mts} +33 -20
  16. package/dist/{client-p1Iofyc9.d.ts → client-CQlEWH5j.d.ts} +1 -1
  17. package/dist/{client-QTrsv6Gu.d.ts → client-DVFQoDtI.d.ts} +33 -20
  18. package/dist/{client-XoswXzib.d.mts → client-Dd82KQ_G.d.mts} +1 -1
  19. package/dist/index.d.mts +2 -2
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +80 -81
  22. package/dist/index.mjs +4 -5
  23. package/dist/mock/cli.mjs +12 -50
  24. package/dist/mock/library.js +12 -50
  25. package/dist/mock/library.mjs +12 -50
  26. package/dist/mock/msw.js +12 -50
  27. package/dist/mock/msw.mjs +12 -50
  28. package/dist/react.d.mts +4 -7
  29. package/dist/react.d.ts +4 -7
  30. package/dist/react.js +63 -71
  31. package/dist/react.mjs +5 -13
  32. package/dist/server.d.mts +18 -3
  33. package/dist/server.d.ts +18 -3
  34. package/dist/server.js +175 -29
  35. package/dist/server.mjs +167 -25
  36. package/dist/{sign-in-dr7m09nm.d.ts → sign-in-RFuWZOgF.d.mts} +6 -1
  37. package/dist/{sign-in-dr7m09nm.d.mts → sign-in-RFuWZOgF.d.ts} +6 -1
  38. package/dist/styles.css +1 -1
  39. package/dist/testing/msw.js +2 -2
  40. package/dist/testing/msw.mjs +1 -1
  41. package/dist/testing/suite.d.mts +2 -2
  42. package/dist/testing/suite.d.ts +2 -2
  43. package/dist/testing/suite.js +23 -23
  44. package/dist/testing/suite.mjs +4 -4
  45. package/dist/testing.d.mts +2 -2
  46. package/dist/testing.d.ts +2 -2
  47. package/dist/testing.js +79 -79
  48. package/dist/testing.mjs +5 -5
  49. package/package.json +1 -1
  50. package/dist/chunk-2AU263DK.mjs +0 -323
  51. package/dist/chunk-6DMHVQ42.js +0 -338
  52. package/dist/chunk-DKT62WQW.js +0 -53
  53. package/dist/chunk-XSOYJLMZ.mjs +0 -45
@@ -1,323 +0,0 @@
1
- import { encodePkceState, PKCE_COOKIE, PKCE_COOKIE_PATH, PKCE_COOKIE_MAX_AGE_SECONDS, getAuthorizationEndpoint, DEFAULT_ISSUER } from './chunk-XSOYJLMZ.mjs';
2
-
3
- // src/gallery.ts
4
- function dedupe(urls) {
5
- const seen = /* @__PURE__ */ new Set();
6
- const out = [];
7
- for (const url of urls) {
8
- if (url && !seen.has(url)) {
9
- seen.add(url);
10
- out.push(url);
11
- }
12
- }
13
- return out;
14
- }
15
- function resolveGallery(product, selectedVariantId) {
16
- const variant = selectedVariantId ? product.variants?.find((v) => v.id === selectedVariantId) : void 0;
17
- if (variant?.images?.length) return dedupe(variant.images);
18
- if (product.images?.length) return dedupe(product.images);
19
- const firstWithImages = product.variants?.find((v) => v.images?.length);
20
- if (firstWithImages?.images?.length) return dedupe(firstWithImages.images);
21
- return product.image_url ? [product.image_url] : [];
22
- }
23
- function allGalleryImages(product) {
24
- const seen = /* @__PURE__ */ new Set();
25
- const out = [];
26
- const push = (url, variantId) => {
27
- if (url && !seen.has(url)) {
28
- seen.add(url);
29
- out.push({ url, variantId });
30
- }
31
- };
32
- push(product.image_url, null);
33
- for (const url of product.images ?? []) push(url, null);
34
- for (const variant of product.variants ?? []) {
35
- for (const url of variant.images ?? []) push(url, variant.id);
36
- }
37
- return out;
38
- }
39
-
40
- // src/utils/variant.ts
41
- function stripProductPrefix(variantName, productName) {
42
- if (!variantName || !productName) return variantName || productName;
43
- const lower = variantName.toLowerCase().trim();
44
- if (lower === "default" || lower === "standard") return productName;
45
- if (lower.endsWith("-default") || lower.endsWith("-standard")) return productName;
46
- if (variantName.startsWith(productName)) {
47
- const rest = variantName.slice(productName.length);
48
- const match = rest.match(/^\s*[-–—]\s*(.*)/);
49
- if (match && match[1].length > 0) return match[1];
50
- }
51
- const lowerProduct = productName.toLowerCase().trim();
52
- if (lower.startsWith(lowerProduct)) {
53
- const rest = variantName.slice(productName.length);
54
- const match = rest.match(/^\s*[-–—]\s*(.*)/);
55
- if (match && match[1].length > 0) return match[1];
56
- }
57
- const lastDash = variantName.lastIndexOf("-");
58
- if (lastDash > 0 && lastDash < variantName.length - 1) {
59
- const prefix = variantName.slice(0, lastDash).trim();
60
- const suffix = variantName.slice(lastDash + 1).trim();
61
- if (suffix.length > 0 && prefix.length > suffix.length * 2) {
62
- return suffix;
63
- }
64
- }
65
- return variantName;
66
- }
67
- function getVariantDisplayName(variant, productName) {
68
- if (variant.display_attributes?.length) {
69
- return variant.display_attributes.map((a) => a.value_name).join(" / ");
70
- }
71
- if (variant.name) {
72
- return productName ? stripProductPrefix(variant.name, productName) : variant.name;
73
- }
74
- return productName || (variant.is_default ? "Default" : "Option");
75
- }
76
-
77
- // src/types/product.ts
78
- var PRODUCT_TYPE = {
79
- Product: "product",
80
- Service: "service",
81
- Digital: "digital",
82
- Bundle: "bundle",
83
- Composite: "composite"
84
- };
85
- var RENDER_HINT = {
86
- Food: "food",
87
- Physical: "physical",
88
- General: "general"
89
- };
90
- var DURATION_UNIT = {
91
- Minutes: "minutes",
92
- Hours: "hours",
93
- Days: "days",
94
- Nights: "nights",
95
- Weeks: "weeks",
96
- Months: "months",
97
- Years: "years"
98
- };
99
- var INPUT_FIELD_TYPE = {
100
- Text: "text",
101
- Textarea: "textarea",
102
- Number: "number",
103
- Select: "select",
104
- Radio: "radio",
105
- Checkbox: "checkbox",
106
- Color: "color",
107
- Date: "date",
108
- File: "file",
109
- Image: "image",
110
- Url: "url",
111
- Address: "address",
112
- Phone: "phone",
113
- Email: "email",
114
- DateTime: "date_time",
115
- Time: "time",
116
- Signature: "signature",
117
- MultiSelect: "multi_select",
118
- DateRange: "date_range",
119
- Location: "location"
120
- };
121
-
122
- // src/internal/pkce.ts
123
- var VERIFIER_BYTES = 64;
124
- async function generatePkce() {
125
- const random = new Uint8Array(VERIFIER_BYTES);
126
- crypto.getRandomValues(random);
127
- const verifier = base64UrlEncode(random);
128
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
129
- const challenge = base64UrlEncode(new Uint8Array(digest));
130
- return { verifier, challenge, method: "S256" };
131
- }
132
- function generateState(byteLength = 16) {
133
- const buf = new Uint8Array(byteLength);
134
- crypto.getRandomValues(buf);
135
- return base64UrlEncode(buf);
136
- }
137
- function base64UrlEncode(bytes) {
138
- let str = "";
139
- for (const byte of bytes) str += String.fromCharCode(byte);
140
- return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
141
- }
142
-
143
- // src/internal/modal-iframe.ts
144
- function openModalIframe(opts) {
145
- const overlay = document.createElement("div");
146
- overlay.dataset.cimplifyModal = "1";
147
- Object.assign(overlay.style, {
148
- position: "fixed",
149
- inset: "0",
150
- background: "rgba(15, 18, 24, 0.55)",
151
- zIndex: "2147483647",
152
- display: "grid",
153
- placeItems: "center",
154
- backdropFilter: "blur(2px)"
155
- });
156
- const card = document.createElement("div");
157
- Object.assign(card.style, {
158
- width: `${opts.width ?? 480}px`,
159
- maxWidth: "calc(100vw - 24px)",
160
- height: `${opts.height ?? 720}px`,
161
- maxHeight: "calc(100vh - 32px)"
162
- });
163
- const iframe = document.createElement("iframe");
164
- iframe.src = opts.src;
165
- iframe.style.width = "100%";
166
- iframe.style.height = "100%";
167
- iframe.style.border = "none";
168
- iframe.style.background = "transparent";
169
- iframe.setAttribute(
170
- "sandbox",
171
- opts.sandbox ?? "allow-scripts allow-same-origin allow-forms allow-popups"
172
- );
173
- iframe.setAttribute("allow", "publickey-credentials-get; publickey-credentials-create");
174
- card.appendChild(iframe);
175
- overlay.appendChild(card);
176
- document.body.appendChild(overlay);
177
- const close = () => {
178
- overlay.remove();
179
- document.removeEventListener("keydown", onKey);
180
- opts.onClose?.();
181
- };
182
- const onKey = (e) => {
183
- if (e.key === "Escape") close();
184
- };
185
- overlay.addEventListener("click", (e) => {
186
- if (e.target === overlay) close();
187
- });
188
- document.addEventListener("keydown", onKey);
189
- return { iframe, close };
190
- }
191
-
192
- // src/sign-in.ts
193
- var DEFAULT_SCOPE = "openid email phone profile";
194
- function resolveAuthorizeEndpoint(opts) {
195
- if (opts.authUrl) {
196
- return Promise.resolve(`${opts.authUrl.replace(/\/$/, "")}/oauth/authorize`);
197
- }
198
- return getAuthorizationEndpoint(opts.issuer ?? DEFAULT_ISSUER);
199
- }
200
- async function startSignIn(opts) {
201
- const callbackUri = opts.callbackUri ?? "/auth/callback";
202
- const pkce = await generatePkce();
203
- const state = generateState();
204
- const authorizeEndpoint = await resolveAuthorizeEndpoint(opts);
205
- if ((opts.mode ?? "redirect") === "redirect") {
206
- startRedirectSignIn(opts, authorizeEndpoint, pkce, state);
207
- return;
208
- }
209
- const params = new URLSearchParams({
210
- response_type: "code",
211
- response_mode: "web_message",
212
- client_id: opts.clientId,
213
- redirect_uri: opts.redirectUri,
214
- scope: opts.scope ?? DEFAULT_SCOPE,
215
- state,
216
- code_challenge: pkce.challenge,
217
- code_challenge_method: pkce.method
218
- });
219
- if (opts.loginHint) params.set("login_hint", opts.loginHint);
220
- if (opts.prompt) params.set("prompt", opts.prompt);
221
- const src = `${authorizeEndpoint}?${params.toString()}`;
222
- const expectedOrigin = new URL(authorizeEndpoint).origin;
223
- const modal = openModalIframe({
224
- src,
225
- onClose: () => {
226
- window.removeEventListener("message", handler);
227
- }
228
- });
229
- const handler = async (event) => {
230
- if (event.origin !== expectedOrigin) return;
231
- const data = event.data;
232
- if (!data || typeof data !== "object" || data.type !== "authorization_response") return;
233
- const response = data.response;
234
- if (response.error) {
235
- modal.close();
236
- opts.onError?.({ error: response.error, description: response.error_description });
237
- return;
238
- }
239
- if (!response.code) return;
240
- if (response.state !== state) {
241
- modal.close();
242
- opts.onError?.({ error: "state_mismatch" });
243
- return;
244
- }
245
- try {
246
- const res = await fetch(callbackUri, {
247
- method: "POST",
248
- credentials: "include",
249
- headers: { "Content-Type": "application/json" },
250
- body: JSON.stringify({ code: response.code, codeVerifier: pkce.verifier, state })
251
- });
252
- if (!res.ok) {
253
- const body = await res.text().catch(() => "");
254
- opts.onError?.({ error: "callback_failed", description: body });
255
- modal.close();
256
- return;
257
- }
258
- modal.close();
259
- opts.onSuccess?.();
260
- } catch (e) {
261
- opts.onError?.({ error: "callback_exception", description: String(e) });
262
- modal.close();
263
- }
264
- };
265
- window.addEventListener("message", handler);
266
- }
267
- function startRedirectSignIn(opts, authorizeEndpoint, pkce, state) {
268
- const returnTo = opts.returnTo ?? window.location.pathname + window.location.search;
269
- const cookieValue = encodePkceState({ verifier: pkce.verifier, state, returnTo });
270
- const secure = window.location.protocol === "https:" ? "; Secure" : "";
271
- document.cookie = `${PKCE_COOKIE}=${cookieValue}; Path=${PKCE_COOKIE_PATH}; Max-Age=${PKCE_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax${secure}`;
272
- const params = new URLSearchParams({
273
- response_type: "code",
274
- response_mode: "query",
275
- client_id: opts.clientId,
276
- redirect_uri: opts.redirectUri,
277
- scope: opts.scope ?? DEFAULT_SCOPE,
278
- state,
279
- code_challenge: pkce.challenge,
280
- code_challenge_method: pkce.method
281
- });
282
- if (opts.loginHint) params.set("login_hint", opts.loginHint);
283
- if (opts.prompt) params.set("prompt", opts.prompt);
284
- window.location.assign(`${authorizeEndpoint}?${params.toString()}`);
285
- }
286
-
287
- // src/assets/url.ts
288
- var DEFAULT_CDN_BASE_URL = "https://storefrontassetscdn.cimplify.io";
289
- var CIMPLIFY_CDN_HOSTS = [
290
- "storefrontassetscdn.cimplify.io",
291
- "cdn.cimplify.io",
292
- "static-tmp.cimplify.io"
293
- ];
294
- var ABSOLUTE_URL_RE = /^https?:\/\//i;
295
- var MOCK_PASSTHROUGH_RE = /^\/(img|elements|_mock)\//;
296
- function assetUrl(path, opts = {}) {
297
- if (!path) return path;
298
- if (ABSOLUTE_URL_RE.test(path)) return appendTransform(path, opts);
299
- if (MOCK_PASSTHROUGH_RE.test(path)) return appendTransform(path, opts);
300
- const base = (opts.base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
301
- const normalized = path.replace(/^\/+/, "");
302
- return appendTransform(`${base}/${normalized}`, opts);
303
- }
304
- function isCimplifyAsset(src, base) {
305
- if (!src) return false;
306
- if (!ABSOLUTE_URL_RE.test(src)) return true;
307
- if (MOCK_PASSTHROUGH_RE.test(src)) return true;
308
- const resolvedBase = (base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
309
- if (resolvedBase && src.startsWith(resolvedBase)) return true;
310
- return CIMPLIFY_CDN_HOSTS.some((host) => src.startsWith(`https://${host}/`));
311
- }
312
- function appendTransform(url, t) {
313
- const params = new URLSearchParams();
314
- if (t.w != null) params.set("w", String(t.w));
315
- if (t.h != null) params.set("h", String(t.h));
316
- if (t.quality != null) params.set("quality", String(t.quality));
317
- if (t.format != null) params.set("format", t.format);
318
- const query = params.toString();
319
- if (!query) return url;
320
- return `${url}${url.includes("?") ? "&" : "?"}${query}`;
321
- }
322
-
323
- export { CIMPLIFY_CDN_HOSTS, DEFAULT_CDN_BASE_URL, DURATION_UNIT, INPUT_FIELD_TYPE, PRODUCT_TYPE, RENDER_HINT, allGalleryImages, assetUrl, generatePkce, generateState, getVariantDisplayName, isCimplifyAsset, resolveGallery, startSignIn };
@@ -1,338 +0,0 @@
1
- 'use strict';
2
-
3
- var chunkDKT62WQW_js = require('./chunk-DKT62WQW.js');
4
-
5
- // src/gallery.ts
6
- function dedupe(urls) {
7
- const seen = /* @__PURE__ */ new Set();
8
- const out = [];
9
- for (const url of urls) {
10
- if (url && !seen.has(url)) {
11
- seen.add(url);
12
- out.push(url);
13
- }
14
- }
15
- return out;
16
- }
17
- function resolveGallery(product, selectedVariantId) {
18
- const variant = selectedVariantId ? product.variants?.find((v) => v.id === selectedVariantId) : void 0;
19
- if (variant?.images?.length) return dedupe(variant.images);
20
- if (product.images?.length) return dedupe(product.images);
21
- const firstWithImages = product.variants?.find((v) => v.images?.length);
22
- if (firstWithImages?.images?.length) return dedupe(firstWithImages.images);
23
- return product.image_url ? [product.image_url] : [];
24
- }
25
- function allGalleryImages(product) {
26
- const seen = /* @__PURE__ */ new Set();
27
- const out = [];
28
- const push = (url, variantId) => {
29
- if (url && !seen.has(url)) {
30
- seen.add(url);
31
- out.push({ url, variantId });
32
- }
33
- };
34
- push(product.image_url, null);
35
- for (const url of product.images ?? []) push(url, null);
36
- for (const variant of product.variants ?? []) {
37
- for (const url of variant.images ?? []) push(url, variant.id);
38
- }
39
- return out;
40
- }
41
-
42
- // src/utils/variant.ts
43
- function stripProductPrefix(variantName, productName) {
44
- if (!variantName || !productName) return variantName || productName;
45
- const lower = variantName.toLowerCase().trim();
46
- if (lower === "default" || lower === "standard") return productName;
47
- if (lower.endsWith("-default") || lower.endsWith("-standard")) return productName;
48
- if (variantName.startsWith(productName)) {
49
- const rest = variantName.slice(productName.length);
50
- const match = rest.match(/^\s*[-–—]\s*(.*)/);
51
- if (match && match[1].length > 0) return match[1];
52
- }
53
- const lowerProduct = productName.toLowerCase().trim();
54
- if (lower.startsWith(lowerProduct)) {
55
- const rest = variantName.slice(productName.length);
56
- const match = rest.match(/^\s*[-–—]\s*(.*)/);
57
- if (match && match[1].length > 0) return match[1];
58
- }
59
- const lastDash = variantName.lastIndexOf("-");
60
- if (lastDash > 0 && lastDash < variantName.length - 1) {
61
- const prefix = variantName.slice(0, lastDash).trim();
62
- const suffix = variantName.slice(lastDash + 1).trim();
63
- if (suffix.length > 0 && prefix.length > suffix.length * 2) {
64
- return suffix;
65
- }
66
- }
67
- return variantName;
68
- }
69
- function getVariantDisplayName(variant, productName) {
70
- if (variant.display_attributes?.length) {
71
- return variant.display_attributes.map((a) => a.value_name).join(" / ");
72
- }
73
- if (variant.name) {
74
- return productName ? stripProductPrefix(variant.name, productName) : variant.name;
75
- }
76
- return productName || (variant.is_default ? "Default" : "Option");
77
- }
78
-
79
- // src/types/product.ts
80
- var PRODUCT_TYPE = {
81
- Product: "product",
82
- Service: "service",
83
- Digital: "digital",
84
- Bundle: "bundle",
85
- Composite: "composite"
86
- };
87
- var RENDER_HINT = {
88
- Food: "food",
89
- Physical: "physical",
90
- General: "general"
91
- };
92
- var DURATION_UNIT = {
93
- Minutes: "minutes",
94
- Hours: "hours",
95
- Days: "days",
96
- Nights: "nights",
97
- Weeks: "weeks",
98
- Months: "months",
99
- Years: "years"
100
- };
101
- var INPUT_FIELD_TYPE = {
102
- Text: "text",
103
- Textarea: "textarea",
104
- Number: "number",
105
- Select: "select",
106
- Radio: "radio",
107
- Checkbox: "checkbox",
108
- Color: "color",
109
- Date: "date",
110
- File: "file",
111
- Image: "image",
112
- Url: "url",
113
- Address: "address",
114
- Phone: "phone",
115
- Email: "email",
116
- DateTime: "date_time",
117
- Time: "time",
118
- Signature: "signature",
119
- MultiSelect: "multi_select",
120
- DateRange: "date_range",
121
- Location: "location"
122
- };
123
-
124
- // src/internal/pkce.ts
125
- var VERIFIER_BYTES = 64;
126
- async function generatePkce() {
127
- const random = new Uint8Array(VERIFIER_BYTES);
128
- crypto.getRandomValues(random);
129
- const verifier = base64UrlEncode(random);
130
- const digest = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(verifier));
131
- const challenge = base64UrlEncode(new Uint8Array(digest));
132
- return { verifier, challenge, method: "S256" };
133
- }
134
- function generateState(byteLength = 16) {
135
- const buf = new Uint8Array(byteLength);
136
- crypto.getRandomValues(buf);
137
- return base64UrlEncode(buf);
138
- }
139
- function base64UrlEncode(bytes) {
140
- let str = "";
141
- for (const byte of bytes) str += String.fromCharCode(byte);
142
- return btoa(str).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
143
- }
144
-
145
- // src/internal/modal-iframe.ts
146
- function openModalIframe(opts) {
147
- const overlay = document.createElement("div");
148
- overlay.dataset.cimplifyModal = "1";
149
- Object.assign(overlay.style, {
150
- position: "fixed",
151
- inset: "0",
152
- background: "rgba(15, 18, 24, 0.55)",
153
- zIndex: "2147483647",
154
- display: "grid",
155
- placeItems: "center",
156
- backdropFilter: "blur(2px)"
157
- });
158
- const card = document.createElement("div");
159
- Object.assign(card.style, {
160
- width: `${opts.width ?? 480}px`,
161
- maxWidth: "calc(100vw - 24px)",
162
- height: `${opts.height ?? 720}px`,
163
- maxHeight: "calc(100vh - 32px)"
164
- });
165
- const iframe = document.createElement("iframe");
166
- iframe.src = opts.src;
167
- iframe.style.width = "100%";
168
- iframe.style.height = "100%";
169
- iframe.style.border = "none";
170
- iframe.style.background = "transparent";
171
- iframe.setAttribute(
172
- "sandbox",
173
- opts.sandbox ?? "allow-scripts allow-same-origin allow-forms allow-popups"
174
- );
175
- iframe.setAttribute("allow", "publickey-credentials-get; publickey-credentials-create");
176
- card.appendChild(iframe);
177
- overlay.appendChild(card);
178
- document.body.appendChild(overlay);
179
- const close = () => {
180
- overlay.remove();
181
- document.removeEventListener("keydown", onKey);
182
- opts.onClose?.();
183
- };
184
- const onKey = (e) => {
185
- if (e.key === "Escape") close();
186
- };
187
- overlay.addEventListener("click", (e) => {
188
- if (e.target === overlay) close();
189
- });
190
- document.addEventListener("keydown", onKey);
191
- return { iframe, close };
192
- }
193
-
194
- // src/sign-in.ts
195
- var DEFAULT_SCOPE = "openid email phone profile";
196
- function resolveAuthorizeEndpoint(opts) {
197
- if (opts.authUrl) {
198
- return Promise.resolve(`${opts.authUrl.replace(/\/$/, "")}/oauth/authorize`);
199
- }
200
- return chunkDKT62WQW_js.getAuthorizationEndpoint(opts.issuer ?? chunkDKT62WQW_js.DEFAULT_ISSUER);
201
- }
202
- async function startSignIn(opts) {
203
- const callbackUri = opts.callbackUri ?? "/auth/callback";
204
- const pkce = await generatePkce();
205
- const state = generateState();
206
- const authorizeEndpoint = await resolveAuthorizeEndpoint(opts);
207
- if ((opts.mode ?? "redirect") === "redirect") {
208
- startRedirectSignIn(opts, authorizeEndpoint, pkce, state);
209
- return;
210
- }
211
- const params = new URLSearchParams({
212
- response_type: "code",
213
- response_mode: "web_message",
214
- client_id: opts.clientId,
215
- redirect_uri: opts.redirectUri,
216
- scope: opts.scope ?? DEFAULT_SCOPE,
217
- state,
218
- code_challenge: pkce.challenge,
219
- code_challenge_method: pkce.method
220
- });
221
- if (opts.loginHint) params.set("login_hint", opts.loginHint);
222
- if (opts.prompt) params.set("prompt", opts.prompt);
223
- const src = `${authorizeEndpoint}?${params.toString()}`;
224
- const expectedOrigin = new URL(authorizeEndpoint).origin;
225
- const modal = openModalIframe({
226
- src,
227
- onClose: () => {
228
- window.removeEventListener("message", handler);
229
- }
230
- });
231
- const handler = async (event) => {
232
- if (event.origin !== expectedOrigin) return;
233
- const data = event.data;
234
- if (!data || typeof data !== "object" || data.type !== "authorization_response") return;
235
- const response = data.response;
236
- if (response.error) {
237
- modal.close();
238
- opts.onError?.({ error: response.error, description: response.error_description });
239
- return;
240
- }
241
- if (!response.code) return;
242
- if (response.state !== state) {
243
- modal.close();
244
- opts.onError?.({ error: "state_mismatch" });
245
- return;
246
- }
247
- try {
248
- const res = await fetch(callbackUri, {
249
- method: "POST",
250
- credentials: "include",
251
- headers: { "Content-Type": "application/json" },
252
- body: JSON.stringify({ code: response.code, codeVerifier: pkce.verifier, state })
253
- });
254
- if (!res.ok) {
255
- const body = await res.text().catch(() => "");
256
- opts.onError?.({ error: "callback_failed", description: body });
257
- modal.close();
258
- return;
259
- }
260
- modal.close();
261
- opts.onSuccess?.();
262
- } catch (e) {
263
- opts.onError?.({ error: "callback_exception", description: String(e) });
264
- modal.close();
265
- }
266
- };
267
- window.addEventListener("message", handler);
268
- }
269
- function startRedirectSignIn(opts, authorizeEndpoint, pkce, state) {
270
- const returnTo = opts.returnTo ?? window.location.pathname + window.location.search;
271
- const cookieValue = chunkDKT62WQW_js.encodePkceState({ verifier: pkce.verifier, state, returnTo });
272
- const secure = window.location.protocol === "https:" ? "; Secure" : "";
273
- document.cookie = `${chunkDKT62WQW_js.PKCE_COOKIE}=${cookieValue}; Path=${chunkDKT62WQW_js.PKCE_COOKIE_PATH}; Max-Age=${chunkDKT62WQW_js.PKCE_COOKIE_MAX_AGE_SECONDS}; SameSite=Lax${secure}`;
274
- const params = new URLSearchParams({
275
- response_type: "code",
276
- response_mode: "query",
277
- client_id: opts.clientId,
278
- redirect_uri: opts.redirectUri,
279
- scope: opts.scope ?? DEFAULT_SCOPE,
280
- state,
281
- code_challenge: pkce.challenge,
282
- code_challenge_method: pkce.method
283
- });
284
- if (opts.loginHint) params.set("login_hint", opts.loginHint);
285
- if (opts.prompt) params.set("prompt", opts.prompt);
286
- window.location.assign(`${authorizeEndpoint}?${params.toString()}`);
287
- }
288
-
289
- // src/assets/url.ts
290
- var DEFAULT_CDN_BASE_URL = "https://storefrontassetscdn.cimplify.io";
291
- var CIMPLIFY_CDN_HOSTS = [
292
- "storefrontassetscdn.cimplify.io",
293
- "cdn.cimplify.io",
294
- "static-tmp.cimplify.io"
295
- ];
296
- var ABSOLUTE_URL_RE = /^https?:\/\//i;
297
- var MOCK_PASSTHROUGH_RE = /^\/(img|elements|_mock)\//;
298
- function assetUrl(path, opts = {}) {
299
- if (!path) return path;
300
- if (ABSOLUTE_URL_RE.test(path)) return appendTransform(path, opts);
301
- if (MOCK_PASSTHROUGH_RE.test(path)) return appendTransform(path, opts);
302
- const base = (opts.base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
303
- const normalized = path.replace(/^\/+/, "");
304
- return appendTransform(`${base}/${normalized}`, opts);
305
- }
306
- function isCimplifyAsset(src, base) {
307
- if (!src) return false;
308
- if (!ABSOLUTE_URL_RE.test(src)) return true;
309
- if (MOCK_PASSTHROUGH_RE.test(src)) return true;
310
- const resolvedBase = (base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
311
- if (resolvedBase && src.startsWith(resolvedBase)) return true;
312
- return CIMPLIFY_CDN_HOSTS.some((host) => src.startsWith(`https://${host}/`));
313
- }
314
- function appendTransform(url, t) {
315
- const params = new URLSearchParams();
316
- if (t.w != null) params.set("w", String(t.w));
317
- if (t.h != null) params.set("h", String(t.h));
318
- if (t.quality != null) params.set("quality", String(t.quality));
319
- if (t.format != null) params.set("format", t.format);
320
- const query = params.toString();
321
- if (!query) return url;
322
- return `${url}${url.includes("?") ? "&" : "?"}${query}`;
323
- }
324
-
325
- exports.CIMPLIFY_CDN_HOSTS = CIMPLIFY_CDN_HOSTS;
326
- exports.DEFAULT_CDN_BASE_URL = DEFAULT_CDN_BASE_URL;
327
- exports.DURATION_UNIT = DURATION_UNIT;
328
- exports.INPUT_FIELD_TYPE = INPUT_FIELD_TYPE;
329
- exports.PRODUCT_TYPE = PRODUCT_TYPE;
330
- exports.RENDER_HINT = RENDER_HINT;
331
- exports.allGalleryImages = allGalleryImages;
332
- exports.assetUrl = assetUrl;
333
- exports.generatePkce = generatePkce;
334
- exports.generateState = generateState;
335
- exports.getVariantDisplayName = getVariantDisplayName;
336
- exports.isCimplifyAsset = isCimplifyAsset;
337
- exports.resolveGallery = resolveGallery;
338
- exports.startSignIn = startSignIn;