@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
@@ -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
- AUTHENTICATED: "authenticated", REQUIRES_OTP: "requires_otp", ERROR: "error",
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
- TOKEN_REFRESHED: "token_refreshed", LOGOUT_COMPLETE: "logout_complete",
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) { parent.postMessage(msg, ORIGIN); }
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
- '<label>Email or phone</label>' +
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("send-otp").onclick = function () {
2704
- var contact = document.getElementById("contact").value.trim();
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("send-otp").click(); }, 50);
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
- send({ type: MSG.TOKEN_REFRESHED, token: state.token || "tok_mock_refreshed" });
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-R6363CC7.mjs';
1
+ import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-SOV4H6PQ.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
- const response = await this.resilientFetch(url, options);
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) {
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkHCZTBWU4_js = require('./chunk-HCZTBWU4.js');
4
- var chunkJ3MGY6AU_js = require('./chunk-J3MGY6AU.js');
3
+ var chunkSXGFJEME_js = require('./chunk-SXGFJEME.js');
4
+ var chunk5HAUJBOK_js = require('./chunk-5HAUJBOK.js');
5
5
  var zod = require('zod');
6
6
 
7
7
  var cimplifyRegistry = zod.z.registry();
@@ -595,7 +595,7 @@ async function toForwardedRequest(input, init) {
595
595
  };
596
596
  }
597
597
  function createTestClient(options = {}) {
598
- const mock = chunkHCZTBWU4_js.createMockApp(options);
598
+ const mock = chunkSXGFJEME_js.createMockApp(options);
599
599
  let sessionToken;
600
600
  const fetchImpl = async (input, init) => {
601
601
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
@@ -614,7 +614,7 @@ function createTestClient(options = {}) {
614
614
  if (echoed) sessionToken = echoed;
615
615
  return res;
616
616
  };
617
- const client = chunkJ3MGY6AU_js.createCimplifyClient({
617
+ const client = chunk5HAUJBOK_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.