@cimplify/sdk 0.66.0 → 0.68.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 (55) 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-J3MGY6AU.js → chunk-5HAUJBOK.js} +36 -82
  6. package/dist/chunk-E6T5VJMG.mjs +156 -0
  7. package/dist/{chunk-3G4QCENX.mjs → chunk-FVGVJ4TC.mjs} +12 -50
  8. package/dist/chunk-IQLJJW2H.js +168 -0
  9. package/dist/{chunk-227XTAEB.mjs → chunk-KNPE4WCQ.mjs} +2 -48
  10. package/dist/{chunk-H6DBPHMZ.js → chunk-NGQCWFKF.js} +4 -4
  11. package/dist/{chunk-R6363CC7.mjs → chunk-SOV4H6PQ.mjs} +509 -79
  12. package/dist/{chunk-HCZTBWU4.js → chunk-SXGFJEME.js} +12 -50
  13. package/dist/{chunk-MWI5GAUF.mjs → chunk-TAKORJP4.mjs} +2 -2
  14. package/dist/{chunk-AVQL3TSJ.js → chunk-WCSAZRNC.js} +519 -78
  15. package/dist/{client-CUrA1uQ0.d.mts → client-CBE7ksYC.d.mts} +1 -1
  16. package/dist/{client-Bo5rujc2.d.ts → client-CfeQRwhl.d.ts} +55 -21
  17. package/dist/{client-DasPHOJh.d.ts → client-DlXfZy7N.d.ts} +1 -1
  18. package/dist/{client-Dka2cGhu.d.mts → client-Dyo3dvNy.d.mts} +55 -21
  19. package/dist/index.d.mts +2 -2
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +104 -88
  22. package/dist/index.mjs +16 -12
  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 +44 -44
  29. package/dist/react.d.ts +44 -44
  30. package/dist/react.js +298 -175
  31. package/dist/react.mjs +240 -117
  32. package/dist/server.d.mts +2 -2
  33. package/dist/server.d.ts +2 -2
  34. package/dist/server.js +16 -9
  35. package/dist/server.mjs +11 -4
  36. package/dist/{sign-in-dr7m09nm.d.ts → sign-in-DQlIdqsi.d.mts} +14 -1
  37. package/dist/{sign-in-dr7m09nm.d.mts → sign-in-DQlIdqsi.d.ts} +14 -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 +17 -17
  46. package/dist/testing.d.ts +17 -17
  47. package/dist/testing.js +79 -79
  48. package/dist/testing.mjs +5 -5
  49. package/package.json +1 -1
  50. package/registry/index.json +0 -9
  51. package/dist/chunk-3Z3FQH7X.mjs +0 -323
  52. package/dist/chunk-7BKKBJQM.mjs +0 -52
  53. package/dist/chunk-GDAGM26J.js +0 -338
  54. package/dist/chunk-KWYI2TTA.js +0 -60
  55. package/registry/account.json +0 -15
@@ -1,323 +0,0 @@
1
- import { encodePkceState, PKCE_COOKIE, PKCE_COOKIE_PATH, PKCE_COOKIE_MAX_AGE_SECONDS, getAuthorizationEndpoint, DEFAULT_ISSUER } from './chunk-7BKKBJQM.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,52 +0,0 @@
1
- // src/internal/pkce-cookie.ts
2
- var PKCE_COOKIE = "cimplify_pkce";
3
- var PKCE_COOKIE_PATH = "/auth";
4
- var PKCE_COOKIE_MAX_AGE_SECONDS = 600;
5
- function encodePkceState(state) {
6
- return encodeURIComponent(JSON.stringify(state));
7
- }
8
- function decodePkceState(raw) {
9
- try {
10
- const parsed = JSON.parse(decodeURIComponent(raw));
11
- if (typeof parsed?.verifier === "string" && typeof parsed.state === "string" && typeof parsed.returnTo === "string") {
12
- return { verifier: parsed.verifier, state: parsed.state, returnTo: parsed.returnTo };
13
- }
14
- } catch {
15
- }
16
- return null;
17
- }
18
-
19
- // src/internal/discovery.ts
20
- var DEFAULT_ISSUER = "https://api.cimplify.io";
21
- var DEFAULT_AUTHORIZATION_ENDPOINT = "https://auth.cimplify.io/oauth/authorize";
22
- function fallbackAuthorizationEndpoint(issuerBase) {
23
- if (issuerBase === DEFAULT_ISSUER) return DEFAULT_AUTHORIZATION_ENDPOINT;
24
- throw new Error(
25
- `OIDC discovery for "${issuerBase}" is unreachable and no fallback authorize endpoint is known for it. Make discovery reachable (enable CORS) or pass authUrl.`
26
- );
27
- }
28
- var cache = /* @__PURE__ */ new Map();
29
- function fetchDiscovery(issuer) {
30
- const base = issuer.replace(/\/$/, "");
31
- let pending = cache.get(base);
32
- if (!pending) {
33
- pending = fetch(`${base}/.well-known/openid-configuration`).then((res) => {
34
- if (!res.ok) throw new Error(`oidc discovery failed: ${res.status}`);
35
- return res.json();
36
- });
37
- pending.catch(() => cache.delete(base));
38
- cache.set(base, pending);
39
- }
40
- return pending;
41
- }
42
- async function getAuthorizationEndpoint(issuer) {
43
- const base = issuer.replace(/\/$/, "");
44
- try {
45
- const doc = await fetchDiscovery(base);
46
- if (doc.authorization_endpoint) return doc.authorization_endpoint;
47
- } catch {
48
- }
49
- return fallbackAuthorizationEndpoint(base);
50
- }
51
-
52
- export { DEFAULT_ISSUER, PKCE_COOKIE, PKCE_COOKIE_MAX_AGE_SECONDS, PKCE_COOKIE_PATH, decodePkceState, encodePkceState, getAuthorizationEndpoint };