@cimplify/sdk 0.66.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.
- package/dist/advanced.d.mts +1 -1
- package/dist/advanced.d.ts +1 -1
- package/dist/advanced.js +20 -20
- package/dist/advanced.mjs +1 -1
- package/dist/{chunk-AVQL3TSJ.js → chunk-3QSW33RG.js} +389 -78
- package/dist/chunk-E6T5VJMG.mjs +156 -0
- package/dist/{chunk-MWI5GAUF.mjs → chunk-FNK6UZOE.mjs} +2 -2
- package/dist/{chunk-3G4QCENX.mjs → chunk-FVGVJ4TC.mjs} +12 -50
- package/dist/chunk-IQLJJW2H.js +168 -0
- package/dist/{chunk-227XTAEB.mjs → chunk-JAPCAZN4.mjs} +2 -48
- package/dist/{chunk-R6363CC7.mjs → chunk-QQMDEGAK.mjs} +382 -79
- package/dist/{chunk-H6DBPHMZ.js → chunk-SH6HJW4A.js} +4 -4
- package/dist/{chunk-J3MGY6AU.js → chunk-SSLFZPAI.js} +36 -82
- package/dist/{chunk-HCZTBWU4.js → chunk-SXGFJEME.js} +12 -50
- package/dist/{client-Dka2cGhu.d.mts → client-ByI_3jfL.d.mts} +32 -20
- package/dist/{client-DasPHOJh.d.ts → client-CQlEWH5j.d.ts} +1 -1
- package/dist/{client-Bo5rujc2.d.ts → client-DVFQoDtI.d.ts} +32 -20
- package/dist/{client-CUrA1uQ0.d.mts → client-Dd82KQ_G.d.mts} +1 -1
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +80 -81
- package/dist/index.mjs +4 -5
- package/dist/mock/cli.mjs +12 -50
- package/dist/mock/library.js +12 -50
- package/dist/mock/library.mjs +12 -50
- package/dist/mock/msw.js +12 -50
- package/dist/mock/msw.mjs +12 -50
- package/dist/react.d.mts +4 -7
- package/dist/react.d.ts +4 -7
- package/dist/react.js +63 -71
- package/dist/react.mjs +5 -13
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +16 -9
- package/dist/server.mjs +11 -4
- package/dist/{sign-in-dr7m09nm.d.ts → sign-in-RFuWZOgF.d.mts} +6 -1
- package/dist/{sign-in-dr7m09nm.d.mts → sign-in-RFuWZOgF.d.ts} +6 -1
- package/dist/testing/msw.js +2 -2
- package/dist/testing/msw.mjs +1 -1
- package/dist/testing/suite.d.mts +2 -2
- package/dist/testing/suite.d.ts +2 -2
- package/dist/testing/suite.js +23 -23
- package/dist/testing/suite.mjs +4 -4
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +79 -79
- package/dist/testing.mjs +5 -5
- package/package.json +1 -1
- package/dist/chunk-3Z3FQH7X.mjs +0 -323
- package/dist/chunk-7BKKBJQM.mjs +0 -52
- package/dist/chunk-GDAGM26J.js +0 -338
- package/dist/chunk-KWYI2TTA.js +0 -60
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// src/gallery.ts
|
|
2
|
+
function dedupe(urls) {
|
|
3
|
+
const seen = /* @__PURE__ */ new Set();
|
|
4
|
+
const out = [];
|
|
5
|
+
for (const url of urls) {
|
|
6
|
+
if (url && !seen.has(url)) {
|
|
7
|
+
seen.add(url);
|
|
8
|
+
out.push(url);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
return out;
|
|
12
|
+
}
|
|
13
|
+
function resolveGallery(product, selectedVariantId) {
|
|
14
|
+
const variant = selectedVariantId ? product.variants?.find((v) => v.id === selectedVariantId) : void 0;
|
|
15
|
+
if (variant?.images?.length) return dedupe(variant.images);
|
|
16
|
+
if (product.images?.length) return dedupe(product.images);
|
|
17
|
+
const firstWithImages = product.variants?.find((v) => v.images?.length);
|
|
18
|
+
if (firstWithImages?.images?.length) return dedupe(firstWithImages.images);
|
|
19
|
+
return product.image_url ? [product.image_url] : [];
|
|
20
|
+
}
|
|
21
|
+
function allGalleryImages(product) {
|
|
22
|
+
const seen = /* @__PURE__ */ new Set();
|
|
23
|
+
const out = [];
|
|
24
|
+
const push = (url, variantId) => {
|
|
25
|
+
if (url && !seen.has(url)) {
|
|
26
|
+
seen.add(url);
|
|
27
|
+
out.push({ url, variantId });
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
push(product.image_url, null);
|
|
31
|
+
for (const url of product.images ?? []) push(url, null);
|
|
32
|
+
for (const variant of product.variants ?? []) {
|
|
33
|
+
for (const url of variant.images ?? []) push(url, variant.id);
|
|
34
|
+
}
|
|
35
|
+
return out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// src/utils/variant.ts
|
|
39
|
+
function stripProductPrefix(variantName, productName) {
|
|
40
|
+
if (!variantName || !productName) return variantName || productName;
|
|
41
|
+
const lower = variantName.toLowerCase().trim();
|
|
42
|
+
if (lower === "default" || lower === "standard") return productName;
|
|
43
|
+
if (lower.endsWith("-default") || lower.endsWith("-standard")) return productName;
|
|
44
|
+
if (variantName.startsWith(productName)) {
|
|
45
|
+
const rest = variantName.slice(productName.length);
|
|
46
|
+
const match = rest.match(/^\s*[-–—]\s*(.*)/);
|
|
47
|
+
if (match && match[1].length > 0) return match[1];
|
|
48
|
+
}
|
|
49
|
+
const lowerProduct = productName.toLowerCase().trim();
|
|
50
|
+
if (lower.startsWith(lowerProduct)) {
|
|
51
|
+
const rest = variantName.slice(productName.length);
|
|
52
|
+
const match = rest.match(/^\s*[-–—]\s*(.*)/);
|
|
53
|
+
if (match && match[1].length > 0) return match[1];
|
|
54
|
+
}
|
|
55
|
+
const lastDash = variantName.lastIndexOf("-");
|
|
56
|
+
if (lastDash > 0 && lastDash < variantName.length - 1) {
|
|
57
|
+
const prefix = variantName.slice(0, lastDash).trim();
|
|
58
|
+
const suffix = variantName.slice(lastDash + 1).trim();
|
|
59
|
+
if (suffix.length > 0 && prefix.length > suffix.length * 2) {
|
|
60
|
+
return suffix;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return variantName;
|
|
64
|
+
}
|
|
65
|
+
function getVariantDisplayName(variant, productName) {
|
|
66
|
+
if (variant.display_attributes?.length) {
|
|
67
|
+
return variant.display_attributes.map((a) => a.value_name).join(" / ");
|
|
68
|
+
}
|
|
69
|
+
if (variant.name) {
|
|
70
|
+
return productName ? stripProductPrefix(variant.name, productName) : variant.name;
|
|
71
|
+
}
|
|
72
|
+
return productName || (variant.is_default ? "Default" : "Option");
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// src/types/product.ts
|
|
76
|
+
var PRODUCT_TYPE = {
|
|
77
|
+
Product: "product",
|
|
78
|
+
Service: "service",
|
|
79
|
+
Digital: "digital",
|
|
80
|
+
Bundle: "bundle",
|
|
81
|
+
Composite: "composite"
|
|
82
|
+
};
|
|
83
|
+
var RENDER_HINT = {
|
|
84
|
+
Food: "food",
|
|
85
|
+
Physical: "physical",
|
|
86
|
+
General: "general"
|
|
87
|
+
};
|
|
88
|
+
var DURATION_UNIT = {
|
|
89
|
+
Minutes: "minutes",
|
|
90
|
+
Hours: "hours",
|
|
91
|
+
Days: "days",
|
|
92
|
+
Nights: "nights",
|
|
93
|
+
Weeks: "weeks",
|
|
94
|
+
Months: "months",
|
|
95
|
+
Years: "years"
|
|
96
|
+
};
|
|
97
|
+
var INPUT_FIELD_TYPE = {
|
|
98
|
+
Text: "text",
|
|
99
|
+
Textarea: "textarea",
|
|
100
|
+
Number: "number",
|
|
101
|
+
Select: "select",
|
|
102
|
+
Radio: "radio",
|
|
103
|
+
Checkbox: "checkbox",
|
|
104
|
+
Color: "color",
|
|
105
|
+
Date: "date",
|
|
106
|
+
File: "file",
|
|
107
|
+
Image: "image",
|
|
108
|
+
Url: "url",
|
|
109
|
+
Address: "address",
|
|
110
|
+
Phone: "phone",
|
|
111
|
+
Email: "email",
|
|
112
|
+
DateTime: "date_time",
|
|
113
|
+
Time: "time",
|
|
114
|
+
Signature: "signature",
|
|
115
|
+
MultiSelect: "multi_select",
|
|
116
|
+
DateRange: "date_range",
|
|
117
|
+
Location: "location"
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/assets/url.ts
|
|
121
|
+
var DEFAULT_CDN_BASE_URL = "https://storefrontassetscdn.cimplify.io";
|
|
122
|
+
var CIMPLIFY_CDN_HOSTS = [
|
|
123
|
+
"storefrontassetscdn.cimplify.io",
|
|
124
|
+
"cdn.cimplify.io",
|
|
125
|
+
"static-tmp.cimplify.io"
|
|
126
|
+
];
|
|
127
|
+
var ABSOLUTE_URL_RE = /^https?:\/\//i;
|
|
128
|
+
var MOCK_PASSTHROUGH_RE = /^\/(img|elements|_mock)\//;
|
|
129
|
+
function assetUrl(path, opts = {}) {
|
|
130
|
+
if (!path) return path;
|
|
131
|
+
if (ABSOLUTE_URL_RE.test(path)) return appendTransform(path, opts);
|
|
132
|
+
if (MOCK_PASSTHROUGH_RE.test(path)) return appendTransform(path, opts);
|
|
133
|
+
const base = (opts.base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
|
|
134
|
+
const normalized = path.replace(/^\/+/, "");
|
|
135
|
+
return appendTransform(`${base}/${normalized}`, opts);
|
|
136
|
+
}
|
|
137
|
+
function isCimplifyAsset(src, base) {
|
|
138
|
+
if (!src) return false;
|
|
139
|
+
if (!ABSOLUTE_URL_RE.test(src)) return true;
|
|
140
|
+
if (MOCK_PASSTHROUGH_RE.test(src)) return true;
|
|
141
|
+
const resolvedBase = (base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
|
|
142
|
+
if (resolvedBase && src.startsWith(resolvedBase)) return true;
|
|
143
|
+
return CIMPLIFY_CDN_HOSTS.some((host) => src.startsWith(`https://${host}/`));
|
|
144
|
+
}
|
|
145
|
+
function appendTransform(url, t) {
|
|
146
|
+
const params = new URLSearchParams();
|
|
147
|
+
if (t.w != null) params.set("w", String(t.w));
|
|
148
|
+
if (t.h != null) params.set("h", String(t.h));
|
|
149
|
+
if (t.quality != null) params.set("quality", String(t.quality));
|
|
150
|
+
if (t.format != null) params.set("format", t.format);
|
|
151
|
+
const query = params.toString();
|
|
152
|
+
if (!query) return url;
|
|
153
|
+
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
export { CIMPLIFY_CDN_HOSTS, DEFAULT_CDN_BASE_URL, DURATION_UNIT, INPUT_FIELD_TYPE, PRODUCT_TYPE, RENDER_HINT, allGalleryImages, assetUrl, getVariantDisplayName, isCimplifyAsset, resolveGallery };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createMockApp } from './chunk-
|
|
2
|
-
import { createCimplifyClient } from './chunk-
|
|
1
|
+
import { createMockApp } from './chunk-FVGVJ4TC.mjs';
|
|
2
|
+
import { createCimplifyClient } from './chunk-JAPCAZN4.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
var cimplifyRegistry = z.registry();
|
|
@@ -2645,10 +2645,10 @@ var ELEMENT_HANDLER_JS = `/* eslint-disable */
|
|
|
2645
2645
|
REFRESH_TOKEN: "refresh_token", LOGOUT: "logout",
|
|
2646
2646
|
PROCESS_CHECKOUT: "process_checkout", ABORT_CHECKOUT: "abort_checkout",
|
|
2647
2647
|
READY: "ready", HEIGHT_CHANGE: "height_change",
|
|
2648
|
-
|
|
2648
|
+
AUTH_REQUESTED: "auth_requested", ERROR: "error",
|
|
2649
2649
|
ADDRESS_CHANGED: "address_changed", ADDRESS_SELECTED: "address_selected",
|
|
2650
2650
|
PAYMENT_METHOD_SELECTED: "payment_method_selected",
|
|
2651
|
-
|
|
2651
|
+
LOGOUT_COMPLETE: "logout_complete",
|
|
2652
2652
|
CONTACT_PROVIDED: "contact_provided",
|
|
2653
2653
|
CHECKOUT_STATUS: "checkout_status", CHECKOUT_COMPLETE: "checkout_complete",
|
|
2654
2654
|
ORDER_TYPE_CHANGED: "order_type_changed", REQUEST_SUBMIT: "request_submit"
|
|
@@ -2657,6 +2657,7 @@ var ELEMENT_HANDLER_JS = `/* eslint-disable */
|
|
|
2657
2657
|
var AUTO = qs.get("auto") === "true";
|
|
2658
2658
|
var DEMO_OTP = qs.get("otp") || "123456";
|
|
2659
2659
|
var ORIGIN = qs.get("origin") || "*";
|
|
2660
|
+
var NONCE = qs.get("nonce");
|
|
2660
2661
|
var state = {
|
|
2661
2662
|
businessId: DEFAULT_BUSINESS,
|
|
2662
2663
|
token: null,
|
|
@@ -2671,7 +2672,10 @@ var ELEMENT_HANDLER_JS = `/* eslint-disable */
|
|
|
2671
2672
|
var content = document.getElementById("content");
|
|
2672
2673
|
var title = document.getElementById("title");
|
|
2673
2674
|
|
|
2674
|
-
function send(msg) {
|
|
2675
|
+
function send(msg) {
|
|
2676
|
+
if (NONCE) msg.nonce = NONCE;
|
|
2677
|
+
parent.postMessage(msg, ORIGIN);
|
|
2678
|
+
}
|
|
2675
2679
|
function reportHeight() { send({ type: MSG.HEIGHT_CHANGE, height: document.documentElement.scrollHeight }); }
|
|
2676
2680
|
function ready() { send({ type: MSG.READY, height: document.documentElement.scrollHeight }); }
|
|
2677
2681
|
|
|
@@ -2691,54 +2695,13 @@ var ELEMENT_HANDLER_JS = `/* eslint-disable */
|
|
|
2691
2695
|
function renderAuth() {
|
|
2692
2696
|
title.textContent = "Sign in";
|
|
2693
2697
|
content.innerHTML =
|
|
2694
|
-
'<
|
|
2695
|
-
'<input id="contact" placeholder="you@example.com or +233..." value="' + (qs.get("contact") || "") + '">' +
|
|
2696
|
-
'<button id="send-otp">Send code</button>' +
|
|
2697
|
-
'<div id="otp-box" style="display:none">' +
|
|
2698
|
-
' <label>Verification code (mock: ' + DEMO_OTP + ')</label>' +
|
|
2699
|
-
' <input id="otp" maxlength="6" value="' + DEMO_OTP + '">' +
|
|
2700
|
-
' <button id="verify-otp">Verify</button>' +
|
|
2701
|
-
'</div>' +
|
|
2698
|
+
'<button id="start-auth">Continue with Cimplify</button>' +
|
|
2702
2699
|
'<div class="err" id="err"></div>';
|
|
2703
|
-
document.getElementById("
|
|
2704
|
-
|
|
2705
|
-
if (!contact) { document.getElementById("err").textContent = "Enter contact"; return; }
|
|
2706
|
-
state.contact = contact;
|
|
2707
|
-
var contactType = contact.indexOf("@") >= 0 ? "email" : "phone";
|
|
2708
|
-
send({ type: MSG.CONTACT_PROVIDED, contact: contact, contactType: contactType });
|
|
2709
|
-
send({ type: MSG.REQUIRES_OTP, contactMasked: contact.slice(0, 3) + "***" });
|
|
2710
|
-
document.getElementById("otp-box").style.display = "block";
|
|
2711
|
-
reportHeight();
|
|
2712
|
-
};
|
|
2713
|
-
document.getElementById("verify-otp").onclick = function () {
|
|
2714
|
-
var code = document.getElementById("otp").value.trim();
|
|
2715
|
-
if (code !== DEMO_OTP) { document.getElementById("err").textContent = "Invalid code"; return; }
|
|
2716
|
-
fetch("/api/v1/auth/verify-otp", {
|
|
2717
|
-
method: "POST",
|
|
2718
|
-
headers: { "content-type": "application/json" },
|
|
2719
|
-
body: JSON.stringify({ contact: state.contact, code: code })
|
|
2720
|
-
}).then(function (r) { return r.json(); }).then(function (body) {
|
|
2721
|
-
var session = body.session || {};
|
|
2722
|
-
state.token = session.token || body.token;
|
|
2723
|
-
state.customer = {
|
|
2724
|
-
name: session.customer_name || "Customer",
|
|
2725
|
-
email: session.customer_email || (state.contact && state.contact.indexOf("@") >= 0 ? state.contact : null),
|
|
2726
|
-
phone: session.customer_phone || (state.contact && state.contact.indexOf("@") < 0 ? state.contact : null)
|
|
2727
|
-
};
|
|
2728
|
-
send({
|
|
2729
|
-
type: MSG.AUTHENTICATED,
|
|
2730
|
-
accountId: "acct_mock_" + (session.id || "x"),
|
|
2731
|
-
customerId: session.customer_id || "cust_mock",
|
|
2732
|
-
token: state.token,
|
|
2733
|
-
customer: state.customer
|
|
2734
|
-
});
|
|
2735
|
-
}).catch(function (e) {
|
|
2736
|
-
send({ type: MSG.ERROR, code: "AUTH_FAILED", message: String(e) });
|
|
2737
|
-
});
|
|
2700
|
+
document.getElementById("start-auth").onclick = function () {
|
|
2701
|
+
send({ type: MSG.AUTH_REQUESTED });
|
|
2738
2702
|
};
|
|
2739
2703
|
if (AUTO) {
|
|
2740
|
-
setTimeout(function () { document.getElementById("
|
|
2741
|
-
setTimeout(function () { document.getElementById("verify-otp").click(); }, 150);
|
|
2704
|
+
setTimeout(function () { document.getElementById("start-auth").click(); }, 50);
|
|
2742
2705
|
}
|
|
2743
2706
|
}
|
|
2744
2707
|
|
|
@@ -2915,7 +2878,6 @@ var ELEMENT_HANDLER_JS = `/* eslint-disable */
|
|
|
2915
2878
|
break;
|
|
2916
2879
|
case MSG.SET_TOKEN:
|
|
2917
2880
|
state.token = msg.token;
|
|
2918
|
-
send({ type: MSG.TOKEN_REFRESHED, token: state.token });
|
|
2919
2881
|
break;
|
|
2920
2882
|
case MSG.SET_CART:
|
|
2921
2883
|
state.cart = msg.cart;
|
|
@@ -2927,7 +2889,7 @@ var ELEMENT_HANDLER_JS = `/* eslint-disable */
|
|
|
2927
2889
|
send({ type: MSG.HEIGHT_CHANGE, height: document.documentElement.scrollHeight });
|
|
2928
2890
|
break;
|
|
2929
2891
|
case MSG.REFRESH_TOKEN:
|
|
2930
|
-
|
|
2892
|
+
reportHeight();
|
|
2931
2893
|
break;
|
|
2932
2894
|
case MSG.LOGOUT:
|
|
2933
2895
|
state.token = null;
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
'use strict';
|
|
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/assets/url.ts
|
|
123
|
+
var DEFAULT_CDN_BASE_URL = "https://storefrontassetscdn.cimplify.io";
|
|
124
|
+
var CIMPLIFY_CDN_HOSTS = [
|
|
125
|
+
"storefrontassetscdn.cimplify.io",
|
|
126
|
+
"cdn.cimplify.io",
|
|
127
|
+
"static-tmp.cimplify.io"
|
|
128
|
+
];
|
|
129
|
+
var ABSOLUTE_URL_RE = /^https?:\/\//i;
|
|
130
|
+
var MOCK_PASSTHROUGH_RE = /^\/(img|elements|_mock)\//;
|
|
131
|
+
function assetUrl(path, opts = {}) {
|
|
132
|
+
if (!path) return path;
|
|
133
|
+
if (ABSOLUTE_URL_RE.test(path)) return appendTransform(path, opts);
|
|
134
|
+
if (MOCK_PASSTHROUGH_RE.test(path)) return appendTransform(path, opts);
|
|
135
|
+
const base = (opts.base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
|
|
136
|
+
const normalized = path.replace(/^\/+/, "");
|
|
137
|
+
return appendTransform(`${base}/${normalized}`, opts);
|
|
138
|
+
}
|
|
139
|
+
function isCimplifyAsset(src, base) {
|
|
140
|
+
if (!src) return false;
|
|
141
|
+
if (!ABSOLUTE_URL_RE.test(src)) return true;
|
|
142
|
+
if (MOCK_PASSTHROUGH_RE.test(src)) return true;
|
|
143
|
+
const resolvedBase = (base ?? DEFAULT_CDN_BASE_URL).replace(/\/+$/, "");
|
|
144
|
+
if (resolvedBase && src.startsWith(resolvedBase)) return true;
|
|
145
|
+
return CIMPLIFY_CDN_HOSTS.some((host) => src.startsWith(`https://${host}/`));
|
|
146
|
+
}
|
|
147
|
+
function appendTransform(url, t) {
|
|
148
|
+
const params = new URLSearchParams();
|
|
149
|
+
if (t.w != null) params.set("w", String(t.w));
|
|
150
|
+
if (t.h != null) params.set("h", String(t.h));
|
|
151
|
+
if (t.quality != null) params.set("quality", String(t.quality));
|
|
152
|
+
if (t.format != null) params.set("format", t.format);
|
|
153
|
+
const query = params.toString();
|
|
154
|
+
if (!query) return url;
|
|
155
|
+
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
exports.CIMPLIFY_CDN_HOSTS = CIMPLIFY_CDN_HOSTS;
|
|
159
|
+
exports.DEFAULT_CDN_BASE_URL = DEFAULT_CDN_BASE_URL;
|
|
160
|
+
exports.DURATION_UNIT = DURATION_UNIT;
|
|
161
|
+
exports.INPUT_FIELD_TYPE = INPUT_FIELD_TYPE;
|
|
162
|
+
exports.PRODUCT_TYPE = PRODUCT_TYPE;
|
|
163
|
+
exports.RENDER_HINT = RENDER_HINT;
|
|
164
|
+
exports.allGalleryImages = allGalleryImages;
|
|
165
|
+
exports.assetUrl = assetUrl;
|
|
166
|
+
exports.getVariantDisplayName = getVariantDisplayName;
|
|
167
|
+
exports.isCimplifyAsset = isCimplifyAsset;
|
|
168
|
+
exports.resolveGallery = resolveGallery;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-
|
|
1
|
+
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-QQMDEGAK.mjs';
|
|
2
2
|
import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-AMZXALF6.mjs';
|
|
3
3
|
|
|
4
4
|
// src/activity.ts
|
|
@@ -274,7 +274,6 @@ function createClientEvents() {
|
|
|
274
274
|
var SESSION_TOKEN_STORAGE_KEY = "cimplify_session_token";
|
|
275
275
|
var ORDER_TOKEN_PREFIX = "cimplify_ot_";
|
|
276
276
|
var SESSION_TOKEN_HEADER = "x-session-token";
|
|
277
|
-
var REFRESH_ENDPOINT = "/v1/link/elements/refresh";
|
|
278
277
|
var ORDER_TOKEN_TTL_MS = 24 * 60 * 60 * 1e3;
|
|
279
278
|
var DEFAULT_TIMEOUT_MS = 5e3;
|
|
280
279
|
var DEFAULT_MAX_RETRIES = 3;
|
|
@@ -382,7 +381,6 @@ var CimplifyClient = class {
|
|
|
382
381
|
this.context = {};
|
|
383
382
|
this.businessId = null;
|
|
384
383
|
this.businessIdResolvePromise = null;
|
|
385
|
-
this.refreshInflight = null;
|
|
386
384
|
this.inflightRequests = /* @__PURE__ */ new Map();
|
|
387
385
|
/**
|
|
388
386
|
* App-level event channel. Subscribe to surface mutation rollbacks, outbox
|
|
@@ -529,52 +527,8 @@ var CimplifyClient = class {
|
|
|
529
527
|
this.businessIdResolvePromise = null;
|
|
530
528
|
}
|
|
531
529
|
}
|
|
532
|
-
// Browser-only (the server is handed a token directly). Concurrent 401s share
|
|
533
|
-
// one in-flight refresh so the rotating cookie rotates once, not N times.
|
|
534
|
-
async refreshAccessToken() {
|
|
535
|
-
if (typeof window === "undefined") return false;
|
|
536
|
-
if (this.refreshInflight) return this.refreshInflight;
|
|
537
|
-
this.refreshInflight = (async () => {
|
|
538
|
-
try {
|
|
539
|
-
const headers = { "Content-Type": "application/json" };
|
|
540
|
-
const trimmedPublicKey = this.publicKey.trim();
|
|
541
|
-
if (trimmedPublicKey) headers["X-API-Key"] = trimmedPublicKey;
|
|
542
|
-
const res = await this.fetchImpl(`${this.linkApiUrl}${REFRESH_ENDPOINT}`, {
|
|
543
|
-
method: "POST",
|
|
544
|
-
credentials: this.credentials,
|
|
545
|
-
headers,
|
|
546
|
-
body: "{}"
|
|
547
|
-
});
|
|
548
|
-
if (!res.ok) return false;
|
|
549
|
-
const json = await res.json();
|
|
550
|
-
const token = json?.data?.token ?? json?.token;
|
|
551
|
-
if (typeof token === "string" && token.length > 0) {
|
|
552
|
-
this.setAccessToken(token);
|
|
553
|
-
return true;
|
|
554
|
-
}
|
|
555
|
-
return false;
|
|
556
|
-
} catch {
|
|
557
|
-
return false;
|
|
558
|
-
} finally {
|
|
559
|
-
this.refreshInflight = null;
|
|
560
|
-
}
|
|
561
|
-
})();
|
|
562
|
-
return this.refreshInflight;
|
|
563
|
-
}
|
|
564
|
-
// On 401, refresh from the session cookie once and retry — re-establishes a
|
|
565
|
-
// session after a reload without persisting any token.
|
|
566
530
|
async authedFetch(url, options) {
|
|
567
|
-
|
|
568
|
-
if (response.status !== 401 || typeof window === "undefined" || url.includes(REFRESH_ENDPOINT)) {
|
|
569
|
-
return response;
|
|
570
|
-
}
|
|
571
|
-
const refreshed = await this.refreshAccessToken();
|
|
572
|
-
if (!refreshed) return response;
|
|
573
|
-
const retryHeaders = {
|
|
574
|
-
...options.headers,
|
|
575
|
-
Authorization: `Bearer ${this.accessToken}`
|
|
576
|
-
};
|
|
577
|
-
return this.resilientFetch(url, { ...options, headers: retryHeaders });
|
|
531
|
+
return this.resilientFetch(url, options);
|
|
578
532
|
}
|
|
579
533
|
loadSessionToken() {
|
|
580
534
|
if (typeof window !== "undefined" && window.localStorage) {
|