@cimplify/sdk 0.46.3 → 0.47.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/react.mjs CHANGED
@@ -1,8 +1,8 @@
1
1
  "use client";
2
2
  import { DURATION_UNIT, getVariantDisplayName, INPUT_FIELD_TYPE, PRODUCT_TYPE, RENDER_HINT } from './chunk-NRDRVZ62.mjs';
3
3
  export { getVariantDisplayName } from './chunk-NRDRVZ62.mjs';
4
- import { createCimplifyClient } from './chunk-WUIERJ6J.mjs';
5
- import { ELEMENT_TYPES, EVENT_TYPES } from './chunk-CKRMA5F7.mjs';
4
+ import { createCimplifyClient } from './chunk-MBR2DBEN.mjs';
5
+ import { ELEMENT_TYPES, EVENT_TYPES } from './chunk-OFNVLUH4.mjs';
6
6
  import { formatPrice, parsePrice, getUnitPriceAtQuantity, isOnSale, getDiscountPercentage, getBasePrice, getPriceRange, formatPriceRange } from './chunk-XY2DFX5K.mjs';
7
7
  import { isSupportedCurrency } from './chunk-Z2AYLZDF.mjs';
8
8
  import React10, { createContext, useRef, useState, useCallback, useEffect, useContext, useMemo, useId, useSyncExternalStore } from 'react';
@@ -621,7 +621,8 @@ function useCollectionStore(collection) {
621
621
  }
622
622
 
623
623
  // src/react/hooks/use-cart.ts
624
- var CART_STORAGE_PREFIX = "cimplify:cart:v3";
624
+ var LEGACY_CART_STORAGE_PREFIX = "cimplify:cart:v3";
625
+ var legacyCachesPurged = false;
625
626
  var cartStores = /* @__PURE__ */ new Map();
626
627
  var ROLLBACK_VISIBLE_DELAY_MS = 3e3;
627
628
  function clearAllCartStores() {
@@ -631,34 +632,35 @@ function clearAllCartStores() {
631
632
  clearTimeout(handle);
632
633
  }
633
634
  entry.failedOpRemovers.clear();
634
- if (entry.persistTimer) {
635
- clearTimeout(entry.persistTimer);
636
- entry.persistTimer = null;
637
- }
638
635
  }
639
636
  cartStores.clear();
640
637
  }
641
638
  function emptyBase(currency, isLoading = true) {
642
639
  return { items: [], subtotal: 0, tax: 0, total: 0, currency, isLoading };
643
640
  }
644
- function advanceBaseWithPatch(entry, patch) {
645
- const current = entry.collection.getBase() ?? emptyBase(entry.currency, false);
646
- entry.collection.setBase({ ...applyCartPatch(current, patch), isLoading: false });
647
- persistBase(entry);
648
- }
649
- function buildStoreKey(client, locationId, isDemoMode) {
641
+ function buildStoreKey(client, locationId) {
650
642
  return [
651
- client.getPublicKey() || "__demo__",
652
- locationId || "__no_location__",
653
- isDemoMode ? "demo" : "live"
643
+ client.getPublicKey() || "__no_public_key__",
644
+ locationId || "__no_location__"
654
645
  ].join(":");
655
646
  }
656
- function buildStorageKey(storeKey) {
657
- return `${CART_STORAGE_PREFIX}:${storeKey}`;
658
- }
659
- function stripInternalItemMetadata(item) {
660
- const { _lineKey, isOptimistic, ...rest } = item;
661
- return rest;
647
+ function purgeLegacyCartCachesOnce() {
648
+ if (legacyCachesPurged) return;
649
+ legacyCachesPurged = true;
650
+ if (typeof window === "undefined" || !window.localStorage) return;
651
+ try {
652
+ const keys = [];
653
+ for (let i = 0; i < window.localStorage.length; i += 1) {
654
+ const key = window.localStorage.key(i);
655
+ if (key && key.startsWith(LEGACY_CART_STORAGE_PREFIX)) {
656
+ keys.push(key);
657
+ }
658
+ }
659
+ for (const key of keys) {
660
+ window.localStorage.removeItem(key);
661
+ }
662
+ } catch {
663
+ }
662
664
  }
663
665
  function toProductFromServerItem(item, businessId) {
664
666
  return {
@@ -753,69 +755,13 @@ function deriveView(base, ops) {
753
755
  pendingOpCount: ops.length
754
756
  };
755
757
  }
756
- function persistBase(entry) {
757
- if (typeof window === "undefined" || !window.localStorage) return;
758
- if (!entry.isDemoMode) return;
759
- if (entry.persistTimer) return;
760
- entry.persistTimer = setTimeout(() => {
761
- entry.persistTimer = null;
762
- if (typeof window === "undefined" || !window.localStorage) return;
763
- const base = entry.collection.getBase();
764
- if (!base) return;
765
- try {
766
- window.localStorage.setItem(
767
- entry.storageKey,
768
- JSON.stringify({
769
- items: base.items.map((item) => stripInternalItemMetadata(item)),
770
- subtotal: base.subtotal,
771
- tax: base.tax,
772
- total: base.total,
773
- currency: base.currency
774
- })
775
- );
776
- } catch {
777
- }
778
- }, 100);
779
- }
780
- function hydrateFromStorage(entry) {
781
- if (typeof window === "undefined" || !window.localStorage) return;
782
- if (!entry.isDemoMode) {
783
- try {
784
- window.localStorage.removeItem(entry.storageKey);
785
- } catch {
786
- }
787
- return;
788
- }
789
- try {
790
- const raw = window.localStorage.getItem(entry.storageKey);
791
- if (!raw) return;
792
- const parsed = JSON.parse(raw);
793
- if (!parsed || !Array.isArray(parsed.items)) return;
794
- const items = parsed.items.map((item) => attachInternalItemMetadata(item));
795
- entry.collection.setBase({
796
- items,
797
- subtotal: toNumber(parsed.subtotal),
798
- tax: toNumber(parsed.tax),
799
- total: toNumber(parsed.total),
800
- currency: typeof parsed.currency === "string" && parsed.currency ? parsed.currency : entry.currency,
801
- isLoading: !entry.isDemoMode
802
- });
803
- } catch {
804
- }
805
- }
806
758
  async function syncFromServer(entry) {
807
- if (entry.isDemoMode) {
808
- const base = entry.collection.getBase() ?? emptyBase(entry.currency);
809
- entry.collection.setBase({ ...base, isLoading: false });
810
- return;
811
- }
812
759
  if (entry.syncing) return;
813
760
  entry.syncing = true;
814
761
  try {
815
762
  const result = await entry.client.cart.get();
816
763
  if (!result.ok) throw result.error;
817
764
  entry.collection.setBase(mapServerCart(result.value, entry.currency));
818
- persistBase(entry);
819
765
  } finally {
820
766
  entry.syncing = false;
821
767
  }
@@ -837,8 +783,9 @@ function scheduleFailedOpRemoval(entry, opId) {
837
783
  entry.failedOpRemovers.add(handle);
838
784
  }
839
785
  function getOrCreateStore(params) {
840
- const { client, locationId, isDemoMode, currency, optimisticEnabled } = params;
841
- const storeKey = buildStoreKey(client, locationId, isDemoMode);
786
+ const { client, locationId, currency, optimisticEnabled } = params;
787
+ purgeLegacyCartCachesOnce();
788
+ const storeKey = buildStoreKey(client, locationId);
842
789
  const existing = cartStores.get(storeKey);
843
790
  if (existing) {
844
791
  existing.optimisticEnabled = optimisticEnabled;
@@ -852,14 +799,11 @@ function getOrCreateStore(params) {
852
799
  const entry = {
853
800
  collection,
854
801
  client,
855
- storageKey: buildStorageKey(storeKey),
856
802
  locationId,
857
803
  currency,
858
- isDemoMode,
859
804
  optimisticEnabled,
860
805
  initialized: false,
861
806
  initializePromise: null,
862
- persistTimer: null,
863
807
  syncing: false,
864
808
  failedOpRemovers: /* @__PURE__ */ new Set()
865
809
  };
@@ -872,12 +816,6 @@ async function ensureInitialized(entry) {
872
816
  return;
873
817
  }
874
818
  entry.initialized = true;
875
- hydrateFromStorage(entry);
876
- if (entry.isDemoMode) {
877
- const base = entry.collection.getBase() ?? emptyBase(entry.currency);
878
- entry.collection.setBase({ ...base, isLoading: false });
879
- return;
880
- }
881
819
  entry.initializePromise = syncFromServer(entry).catch(() => {
882
820
  const base = entry.collection.getBase() ?? emptyBase(entry.currency);
883
821
  entry.collection.setBase({ ...base, isLoading: false });
@@ -891,7 +829,7 @@ async function maybeResolveQuoteId(entry, product, quantity, options) {
891
829
  const requiresQuote = Boolean(
892
830
  options.variantId || addOnOptionIds && addOnOptionIds.length > 0 || options.bundleSelections && options.bundleSelections.length > 0 || options.compositeSelections && options.compositeSelections.length > 0
893
831
  );
894
- if (!requiresQuote || entry.isDemoMode) return void 0;
832
+ if (!requiresQuote) return void 0;
895
833
  const quoteResult = await entry.client.catalogue.fetchQuote({
896
834
  product_id: product.id,
897
835
  quantity,
@@ -931,10 +869,6 @@ async function performAddItem(entry, product, quantity, options) {
931
869
  });
932
870
  const idempotencyKey = `idem_${typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}_${Math.random().toString(36).slice(2, 10)}`}`;
933
871
  const patch = { kind: "add_item", tempItem, lineKey };
934
- if (entry.isDemoMode) {
935
- advanceBaseWithPatch(entry, patch);
936
- return;
937
- }
938
872
  const useOptimistic = entry.optimisticEnabled;
939
873
  const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
940
874
  try {
@@ -973,10 +907,6 @@ async function performAddItem(entry, product, quantity, options) {
973
907
  async function performRemoveItem(entry, itemId) {
974
908
  const idempotencyKey = "";
975
909
  const patch = { kind: "remove_item", itemId };
976
- if (entry.isDemoMode) {
977
- advanceBaseWithPatch(entry, patch);
978
- return;
979
- }
980
910
  const useOptimistic = entry.optimisticEnabled;
981
911
  const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
982
912
  try {
@@ -1001,10 +931,6 @@ async function performUpdateQuantity(entry, itemId, quantity) {
1001
931
  const resolved = clampQuantity(quantity);
1002
932
  const idempotencyKey = "";
1003
933
  const patch = { kind: "set_quantity", itemId, quantity: resolved };
1004
- if (entry.isDemoMode) {
1005
- advanceBaseWithPatch(entry, patch);
1006
- return;
1007
- }
1008
934
  const useOptimistic = entry.optimisticEnabled;
1009
935
  const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
1010
936
  try {
@@ -1025,10 +951,6 @@ async function performUpdateQuantity(entry, itemId, quantity) {
1025
951
  async function performClear(entry) {
1026
952
  const idempotencyKey = "";
1027
953
  const patch = { kind: "clear" };
1028
- if (entry.isDemoMode) {
1029
- advanceBaseWithPatch(entry, patch);
1030
- return;
1031
- }
1032
954
  const useOptimistic = entry.optimisticEnabled;
1033
955
  const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
1034
956
  try {
@@ -1059,18 +981,16 @@ function useCart(options = {}) {
1059
981
  throw new Error("useCart must be used within CimplifyProvider or passed { client }.");
1060
982
  }
1061
983
  const locationId = options.locationId ?? client.getLocationId();
1062
- const isDemoMode = options.demoMode ?? context?.isDemoMode ?? client.getPublicKey().trim().length === 0;
1063
984
  const currency = options.currency ?? context?.currency ?? "USD";
1064
985
  const optimisticEnabled = context?.optimistic ?? true;
1065
986
  const entry = useMemo(
1066
987
  () => getOrCreateStore({
1067
988
  client,
1068
989
  locationId,
1069
- isDemoMode,
1070
990
  currency,
1071
991
  optimisticEnabled
1072
992
  }),
1073
- [client, currency, isDemoMode, locationId, optimisticEnabled]
993
+ [client, currency, locationId, optimisticEnabled]
1074
994
  );
1075
995
  const view = useCollectionStore(entry.collection);
1076
996
  useEffect(() => {
@@ -1230,7 +1150,6 @@ function CimplifyProvider({
1230
1150
  useEffect(() => {
1231
1151
  onLocationChangeRef.current = onLocationChange;
1232
1152
  }, [onLocationChange]);
1233
- const isDemoMode = resolvedClient.getPublicKey().trim().length === 0;
1234
1153
  const baseCurrency = business?.default_currency || DEFAULT_CURRENCY;
1235
1154
  const [displayCurrencyOverride, setDisplayCurrencyOverride] = useState(
1236
1155
  () => getStoredDisplayCurrency()
@@ -1252,7 +1171,7 @@ function CimplifyProvider({
1252
1171
  [baseCurrency]
1253
1172
  );
1254
1173
  useEffect(() => {
1255
- if (displayCurrency === baseCurrency || isDemoMode) {
1174
+ if (displayCurrency === baseCurrency) {
1256
1175
  setFxRate(null);
1257
1176
  return;
1258
1177
  }
@@ -1275,7 +1194,7 @@ function CimplifyProvider({
1275
1194
  cancelled = true;
1276
1195
  clearInterval(intervalId);
1277
1196
  };
1278
- }, [resolvedClient, baseCurrency, displayCurrency, isDemoMode]);
1197
+ }, [resolvedClient, baseCurrency, displayCurrency]);
1279
1198
  const convertPrice = useCallback(
1280
1199
  (amount) => {
1281
1200
  const num = typeof amount === "string" ? parseFloat(amount) : amount;
@@ -1302,17 +1221,6 @@ function CimplifyProvider({
1302
1221
  let cancelled = false;
1303
1222
  async function bootstrap() {
1304
1223
  setIsReady(false);
1305
- if (isDemoMode) {
1306
- if (!cancelled) {
1307
- setBusiness(null);
1308
- setLocations([]);
1309
- setCurrentLocationState(null);
1310
- resolvedClient.setLocationId(null);
1311
- setStoredLocationId(null);
1312
- setIsReady(true);
1313
- }
1314
- return;
1315
- }
1316
1224
  const [businessResult, locationsResult] = await Promise.all([
1317
1225
  resolvedClient.business.getInfo(),
1318
1226
  resolvedClient.business.getLocations()
@@ -1353,7 +1261,7 @@ function CimplifyProvider({
1353
1261
  return () => {
1354
1262
  cancelled = true;
1355
1263
  };
1356
- }, [resolvedClient, isDemoMode]);
1264
+ }, [resolvedClient]);
1357
1265
  const clientContextValue = useMemo(
1358
1266
  () => ({
1359
1267
  client: resolvedClient,
@@ -1362,7 +1270,6 @@ function CimplifyProvider({
1362
1270
  country: business?.country_code || DEFAULT_COUNTRY,
1363
1271
  locations,
1364
1272
  isReady,
1365
- isDemoMode,
1366
1273
  baseCurrency,
1367
1274
  optimistic
1368
1275
  }),
@@ -1372,7 +1279,6 @@ function CimplifyProvider({
1372
1279
  baseCurrency,
1373
1280
  locations,
1374
1281
  isReady,
1375
- isDemoMode,
1376
1282
  optimistic
1377
1283
  ]
1378
1284
  );
@@ -1480,7 +1386,6 @@ function CimplifyCheckout({
1480
1386
  onError,
1481
1387
  onStatusChange,
1482
1388
  appearance,
1483
- demoMode,
1484
1389
  className
1485
1390
  }) {
1486
1391
  const resolvedOrderTypes = useMemo(
@@ -1508,8 +1413,6 @@ function CimplifyCheckout({
1508
1413
  const initialAppearanceRef = useRef(appearance);
1509
1414
  const hasWarnedInlineAppearanceRef = useRef(false);
1510
1415
  const isMountedRef = useRef(true);
1511
- const demoRunRef = useRef(0);
1512
- const isDemoCheckout = demoMode ?? client.getPublicKey().trim().length === 0;
1513
1416
  const isTestMode = client.isTestMode();
1514
1417
  const cimplifyCtx = useOptionalCimplify();
1515
1418
  const fxOptions = useMemo(() => {
@@ -1554,15 +1457,6 @@ function CimplifyCheckout({
1554
1457
  useEffect(() => {
1555
1458
  let cancelled = false;
1556
1459
  async function bootstrap() {
1557
- if (isDemoCheckout) {
1558
- if (!cancelled) {
1559
- setResolvedBusinessId(businessId ?? null);
1560
- setResolvedCartId(cartId ?? "cart_demo");
1561
- setIsInitializing(false);
1562
- setErrorMessage(null);
1563
- }
1564
- return;
1565
- }
1566
1460
  const needsBusinessResolve = !businessId;
1567
1461
  const needsCartResolve = !cartId;
1568
1462
  if (!needsBusinessResolve && !needsCartResolve) {
@@ -1630,11 +1524,10 @@ function CimplifyCheckout({
1630
1524
  return () => {
1631
1525
  cancelled = true;
1632
1526
  };
1633
- }, [businessId, cartId, client, isDemoCheckout]);
1527
+ }, [businessId, cartId, client]);
1634
1528
  useEffect(() => {
1635
1529
  return () => {
1636
1530
  isMountedRef.current = false;
1637
- demoRunRef.current += 1;
1638
1531
  activeCheckoutRef.current?.abort();
1639
1532
  activeCheckoutRef.current = null;
1640
1533
  };
@@ -1651,42 +1544,6 @@ function CimplifyCheckout({
1651
1544
  setErrorMessage(null);
1652
1545
  setIsSubmitting(true);
1653
1546
  emitStatus("preparing", { display_text: statusToLabel("preparing") });
1654
- if (isDemoCheckout) {
1655
- const runId = demoRunRef.current + 1;
1656
- demoRunRef.current = runId;
1657
- const wait = async (ms) => {
1658
- await new Promise((resolve) => setTimeout(resolve, ms));
1659
- return isMountedRef.current && runId === demoRunRef.current;
1660
- };
1661
- try {
1662
- if (!await wait(400)) return;
1663
- emitStatus("processing", { display_text: statusToLabel("processing") });
1664
- if (!await wait(900)) return;
1665
- emitStatus("polling", { display_text: statusToLabel("polling") });
1666
- if (!await wait(1200)) return;
1667
- const result = {
1668
- success: true,
1669
- order: {
1670
- id: `ord_demo_${Date.now()}`,
1671
- order_number: `DEMO-${Math.random().toString(36).slice(2, 8).toUpperCase()}`,
1672
- status: "confirmed",
1673
- total: "0.00",
1674
- currency: "USD"
1675
- }
1676
- };
1677
- emitStatus("success", {
1678
- order_id: result.order?.id,
1679
- order_number: result.order?.order_number,
1680
- display_text: statusToLabel("success")
1681
- });
1682
- onComplete(result);
1683
- } finally {
1684
- if (isMountedRef.current && runId === demoRunRef.current) {
1685
- setIsSubmitting(false);
1686
- }
1687
- }
1688
- return;
1689
- }
1690
1547
  if (!elementsRef.current) {
1691
1548
  const message = "Checkout is still initializing. Please try again.";
1692
1549
  setErrorMessage(message);
@@ -1721,7 +1578,7 @@ function CimplifyCheckout({
1721
1578
  }
1722
1579
  });
1723
1580
  useEffect(() => {
1724
- if (isDemoCheckout || !resolvedBusinessId) {
1581
+ if (!resolvedBusinessId) {
1725
1582
  elementsRef.current = null;
1726
1583
  return;
1727
1584
  }
@@ -1762,7 +1619,6 @@ function CimplifyCheckout({
1762
1619
  }, [
1763
1620
  client,
1764
1621
  resolvedBusinessId,
1765
- isDemoCheckout,
1766
1622
  resolvedOrderTypes,
1767
1623
  resolvedDefaultOrderType,
1768
1624
  submitLabel
@@ -1778,11 +1634,11 @@ function CimplifyCheckout({
1778
1634
  if (isInitializing) {
1779
1635
  return /* @__PURE__ */ jsx("div", { className, "data-cimplify-checkout": "", children: /* @__PURE__ */ jsx("p", { "data-cimplify-status": "", style: { fontSize: 13, color: colors.textSecondary }, children: "Preparing checkout..." }) });
1780
1636
  }
1781
- if (!isDemoCheckout && (!resolvedBusinessId || !resolvedCartId)) {
1637
+ if (!resolvedBusinessId || !resolvedCartId) {
1782
1638
  return /* @__PURE__ */ jsx("div", { className, "data-cimplify-checkout": "", children: /* @__PURE__ */ jsx("p", { "data-cimplify-error": "", style: { fontSize: 13, color: colors.error }, children: errorMessage || "Unable to initialize checkout. Please refresh and try again." }) });
1783
1639
  }
1784
1640
  return /* @__PURE__ */ jsxs("div", { className, "data-cimplify-checkout": "", children: [
1785
- isTestMode && !isDemoCheckout && /* @__PURE__ */ jsx(
1641
+ isTestMode && /* @__PURE__ */ jsx(
1786
1642
  "p",
1787
1643
  {
1788
1644
  "data-cimplify-test-mode": "",
@@ -1795,7 +1651,7 @@ function CimplifyCheckout({
1795
1651
  children: "Test mode - no real charges"
1796
1652
  }
1797
1653
  ),
1798
- /* @__PURE__ */ jsx("div", { "data-cimplify-section": "checkout", children: /* @__PURE__ */ jsx("div", { ref: isDemoCheckout ? void 0 : checkoutMountRef }) }),
1654
+ /* @__PURE__ */ jsx("div", { "data-cimplify-section": "checkout", children: /* @__PURE__ */ jsx("div", { ref: checkoutMountRef }) }),
1799
1655
  status && /* @__PURE__ */ jsx("p", { "data-cimplify-status": "", style: { marginTop: SPACE.sm, fontSize: 13, color: colors.textSecondary }, children: statusText || statusToLabel(status) }),
1800
1656
  errorMessage && /* @__PURE__ */ jsx("p", { "data-cimplify-error": "", style: { marginTop: SPACE.sm, fontSize: 13, color: colors.error }, children: errorMessage })
1801
1657
  ] });
package/dist/server.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CimplifyClient } from './client-G2WCoxv2.mjs';
2
- export { aN as Result } from './client-G2WCoxv2.mjs';
1
+ import { C as CimplifyClient } from './client-BZZK1txR.mjs';
2
+ export { aN as Result } from './client-BZZK1txR.mjs';
3
3
  export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.mjs';
4
4
  import './payment-9L_-GWqQ.mjs';
5
5
 
package/dist/server.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { C as CimplifyClient } from './client-QVINYu1X.js';
2
- export { aN as Result } from './client-QVINYu1X.js';
1
+ import { C as CimplifyClient } from './client-B8tJnOde.js';
2
+ export { aN as Result } from './client-B8tJnOde.js';
3
3
  export { ap as Category, h as CimplifyError, ar as Collection, X as Product, aa as ProductWithDetails } from './product-C-xLzh7Q.js';
4
4
  import './payment-_e99nSRj.js';
5
5
 
package/dist/server.js CHANGED
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkZ2MLAIID_js = require('./chunk-Z2MLAIID.js');
4
- require('./chunk-7ZACMER7.js');
3
+ var chunkCYGLTD7D_js = require('./chunk-CYGLTD7D.js');
4
+ require('./chunk-DR4UPU6P.js');
5
5
  require('./chunk-6RP6OPYO.js');
6
6
  var chunkTKOTACKZ_js = require('./chunk-TKOTACKZ.js');
7
7
  var react = require('react');
@@ -19,7 +19,7 @@ function readEnv(...keys) {
19
19
  var getServerClient = react.cache((opts = {}) => {
20
20
  const baseUrl = opts.apiUrl ?? readEnv("CIMPLIFY_API_URL", "NEXT_PUBLIC_CIMPLIFY_API_URL") ?? DEFAULT_DEV_URL;
21
21
  const publicKey = opts.secretKey ?? readEnv("CIMPLIFY_SECRET_KEY", "NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY") ?? "mock-dev";
22
- const client = chunkZ2MLAIID_js.createCimplifyClient({
22
+ const client = chunkCYGLTD7D_js.createCimplifyClient({
23
23
  baseUrl,
24
24
  publicKey,
25
25
  suppressPublicKeyWarning: true
package/dist/server.mjs CHANGED
@@ -1,5 +1,5 @@
1
- import { createCimplifyClient } from './chunk-WUIERJ6J.mjs';
2
- import './chunk-CKRMA5F7.mjs';
1
+ import { createCimplifyClient } from './chunk-MBR2DBEN.mjs';
2
+ import './chunk-OFNVLUH4.mjs';
3
3
  import './chunk-XY2DFX5K.mjs';
4
4
  export { CimplifyError } from './chunk-Z2AYLZDF.mjs';
5
5
  import { cache } from 'react';
@@ -1,8 +1,8 @@
1
1
  import { TestAPI } from 'vitest';
2
- import { T as TestClientHandle } from '../client-CT9NwIDX.mjs';
2
+ import { T as TestClientHandle } from '../client-BqCAm5vI.mjs';
3
3
  import { C as CreateAppOptions } from '../server-BgccqOLT.mjs';
4
4
  export { S as SeedName } from '../server-BgccqOLT.mjs';
5
- import '../client-G2WCoxv2.mjs';
5
+ import '../client-BZZK1txR.mjs';
6
6
  import '../product-C-xLzh7Q.mjs';
7
7
  import '../payment-9L_-GWqQ.mjs';
8
8
  import 'hono';
@@ -1,8 +1,8 @@
1
1
  import { TestAPI } from 'vitest';
2
- import { T as TestClientHandle } from '../client-B76ZNW5r.js';
2
+ import { T as TestClientHandle } from '../client-BdbvMtOU.js';
3
3
  import { C as CreateAppOptions } from '../server-72rzvJ4Y.js';
4
4
  export { S as SeedName } from '../server-72rzvJ4Y.js';
5
- import '../client-QVINYu1X.js';
5
+ import '../client-B8tJnOde.js';
6
6
  import '../product-C-xLzh7Q.js';
7
7
  import '../payment-_e99nSRj.js';
8
8
  import 'hono';
@@ -1,8 +1,8 @@
1
1
  'use strict';
2
2
 
3
- var chunkTW4OFRWV_js = require('../chunk-TW4OFRWV.js');
4
- require('../chunk-Z2MLAIID.js');
5
- require('../chunk-7ZACMER7.js');
3
+ var chunkD22UVSFN_js = require('../chunk-D22UVSFN.js');
4
+ require('../chunk-CYGLTD7D.js');
5
+ require('../chunk-DR4UPU6P.js');
6
6
  require('../chunk-6RP6OPYO.js');
7
7
  require('../chunk-GEWFWQYK.js');
8
8
  require('../chunk-TKOTACKZ.js');
@@ -19,11 +19,11 @@ var PLACEHOLDER_PHRASES = [
19
19
  function createBrandSuite(opts) {
20
20
  vitest.describe(opts.label ?? "brand schema", () => {
21
21
  vitest.it("conforms to the Cimplify brand contract", () => {
22
- vitest.expect(() => chunkTW4OFRWV_js.assertBrand(opts.brand)).not.toThrow();
22
+ vitest.expect(() => chunkD22UVSFN_js.assertBrand(opts.brand)).not.toThrow();
23
23
  });
24
24
  vitest.it("declares a known mock seed", () => {
25
25
  const b = opts.brand;
26
- vitest.expect(chunkTW4OFRWV_js.SeedNameSchema.safeParse(b.mock?.seed).success).toBe(true);
26
+ vitest.expect(chunkD22UVSFN_js.SeedNameSchema.safeParse(b.mock?.seed).success).toBe(true);
27
27
  });
28
28
  vitest.it("has no placeholder copy left in", () => {
29
29
  const offenders = [];
@@ -55,7 +55,7 @@ ${msg}`);
55
55
  vitest.expect(b.mock?.businessId).toMatch(/^bus_/);
56
56
  });
57
57
  vitest.it("zod-parses cleanly", () => {
58
- const result = chunkTW4OFRWV_js.BrandSchema.safeParse(opts.brand);
58
+ const result = chunkD22UVSFN_js.BrandSchema.safeParse(opts.brand);
59
59
  if (!result.success) {
60
60
  throw new Error(
61
61
  "Brand schema violations:\n" + result.error.issues.map((i) => ` \u2022 brand.${i.path.join(".")}: ${i.message}`).join("\n")
@@ -70,23 +70,23 @@ function createCartFlowSuite(opts = {}) {
70
70
  vitest.describe(opts.label ?? "cart flow against in-process mock", () => {
71
71
  let h;
72
72
  vitest.beforeEach(() => {
73
- h = chunkTW4OFRWV_js.createTestClient(opts);
73
+ h = chunkD22UVSFN_js.createTestClient(opts);
74
74
  });
75
75
  vitest.afterEach(() => h.dispose());
76
76
  vitest.it("starts with an empty cart matching the canonical shape", async () => {
77
77
  const res = await h.client.cart.get();
78
78
  vitest.expect(res.ok).toBe(true);
79
79
  if (!res.ok) return;
80
- vitest.expect(() => chunkTW4OFRWV_js.assertCart(res.value)).not.toThrow();
80
+ vitest.expect(() => chunkD22UVSFN_js.assertCart(res.value)).not.toThrow();
81
81
  vitest.expect(res.value.items).toHaveLength(0);
82
82
  });
83
83
  vitest.it("adds the first product, persists it, and returns a shape-valid cart", async () => {
84
- const { product, variantId } = await chunkTW4OFRWV_js.fixtures.addFirstProduct(h.client);
84
+ const { product, variantId } = await chunkD22UVSFN_js.fixtures.addFirstProduct(h.client);
85
85
  vitest.expect(product.id).toBeTruthy();
86
86
  const get = await h.client.cart.get();
87
87
  vitest.expect(get.ok).toBe(true);
88
88
  if (!get.ok) return;
89
- vitest.expect(() => chunkTW4OFRWV_js.assertCart(get.value)).not.toThrow();
89
+ vitest.expect(() => chunkD22UVSFN_js.assertCart(get.value)).not.toThrow();
90
90
  vitest.expect(get.value.items).toHaveLength(1);
91
91
  vitest.expect(get.value.items[0]?.item_id).toBe(product.id);
92
92
  if (variantId) {
@@ -97,8 +97,8 @@ function createCartFlowSuite(opts = {}) {
97
97
  vitest.expect(parseFloat(String(get.value.pricing.subtotal))).toBeGreaterThan(0);
98
98
  });
99
99
  vitest.it("dedupes by line_key when adding the same product twice", async () => {
100
- await chunkTW4OFRWV_js.fixtures.addFirstProduct(h.client);
101
- await chunkTW4OFRWV_js.fixtures.addFirstProduct(h.client);
100
+ await chunkD22UVSFN_js.fixtures.addFirstProduct(h.client);
101
+ await chunkD22UVSFN_js.fixtures.addFirstProduct(h.client);
102
102
  const res = await h.client.cart.get();
103
103
  vitest.expect(res.ok).toBe(true);
104
104
  if (!res.ok) return;
@@ -106,7 +106,7 @@ function createCartFlowSuite(opts = {}) {
106
106
  vitest.expect(res.value.items[0]?.quantity).toBe(2);
107
107
  });
108
108
  vitest.it("removes items and zeroes the subtotal", async () => {
109
- await chunkTW4OFRWV_js.fixtures.addFirstProduct(h.client);
109
+ await chunkD22UVSFN_js.fixtures.addFirstProduct(h.client);
110
110
  const before = await h.client.cart.get();
111
111
  if (!before.ok) throw before.error;
112
112
  const itemId = before.value.items[0]?.id;
@@ -132,28 +132,28 @@ function createContractSuite(opts = {}) {
132
132
  vitest.describe(opts.label ?? "SDK \u2194 mock contract", () => {
133
133
  let h;
134
134
  vitest.beforeEach(() => {
135
- h = chunkTW4OFRWV_js.createTestClient(opts);
135
+ h = chunkD22UVSFN_js.createTestClient(opts);
136
136
  });
137
137
  vitest.afterEach(() => h.dispose());
138
138
  vitest.it("AddItemPayload schema accepts a minimal valid body", () => {
139
- const result = chunkTW4OFRWV_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: 1 });
139
+ const result = chunkD22UVSFN_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: 1 });
140
140
  vitest.expect(result.success).toBe(true);
141
141
  });
142
142
  vitest.it("AddItemPayload schema rejects negative quantity", () => {
143
- const result = chunkTW4OFRWV_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: -1 });
143
+ const result = chunkD22UVSFN_js.AddItemPayloadSchema.safeParse({ item_id: "prod_x", quantity: -1 });
144
144
  vitest.expect(result.success).toBe(false);
145
145
  });
146
146
  vitest.it("AddItemPayload schema rejects empty item_id", () => {
147
- const result = chunkTW4OFRWV_js.AddItemPayloadSchema.safeParse({ item_id: "", quantity: 1 });
147
+ const result = chunkD22UVSFN_js.AddItemPayloadSchema.safeParse({ item_id: "", quantity: 1 });
148
148
  vitest.expect(result.success).toBe(false);
149
149
  });
150
150
  vitest.it("Cart line items returned by the mock match CartItemSchema", async () => {
151
- const { product } = await chunkTW4OFRWV_js.fixtures.addFirstProduct(h.client);
151
+ const { product } = await chunkD22UVSFN_js.fixtures.addFirstProduct(h.client);
152
152
  const get = await h.client.cart.get();
153
153
  if (!get.ok) throw get.error;
154
154
  vitest.expect(get.value.items.length).toBeGreaterThan(0);
155
155
  for (const item of get.value.items) {
156
- const result = chunkTW4OFRWV_js.CartItemSchema.safeParse(item);
156
+ const result = chunkD22UVSFN_js.CartItemSchema.safeParse(item);
157
157
  if (!result.success) {
158
158
  const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
159
159
  throw new Error(`Cart item shape mismatch for ${product.name}:
@@ -163,19 +163,19 @@ ${issues}`);
163
163
  }
164
164
  });
165
165
  vitest.it("CheckoutResponse from the mock includes bill_token", async () => {
166
- await chunkTW4OFRWV_js.fixtures.addFirstProduct(h.client);
166
+ await chunkD22UVSFN_js.fixtures.addFirstProduct(h.client);
167
167
  const cartRes = await h.client.cart.get();
168
168
  if (!cartRes.ok) throw cartRes.error;
169
169
  const checkout = await h.client.checkout.process({
170
170
  cart_id: cartRes.value.id,
171
- customer: chunkTW4OFRWV_js.fixtures.customer(),
171
+ customer: chunkD22UVSFN_js.fixtures.customer(),
172
172
  order_type: "delivery",
173
173
  payment_method: "mobile_money",
174
174
  mobile_money_details: { phone_number: "+233244000000", provider: "mtn" }
175
175
  });
176
176
  vitest.expect(checkout.ok).toBe(true);
177
177
  if (!checkout.ok) return;
178
- const result = chunkTW4OFRWV_js.CheckoutResponseSchema.safeParse(checkout.value);
178
+ const result = chunkD22UVSFN_js.CheckoutResponseSchema.safeParse(checkout.value);
179
179
  if (!result.success) {
180
180
  const issues = result.error.issues.map((i) => ` \u2022 ${i.path.join(".")}: ${i.message}`).join("\n");
181
181
  throw new Error(`CheckoutResponse shape mismatch:
@@ -1,6 +1,6 @@
1
- import { assertBrand, SeedNameSchema, BrandSchema, createTestClient, assertCart, fixtures, AddItemPayloadSchema, CartItemSchema, CheckoutResponseSchema } from '../chunk-6HYKWYUF.mjs';
2
- import '../chunk-WUIERJ6J.mjs';
3
- import '../chunk-CKRMA5F7.mjs';
1
+ import { assertBrand, SeedNameSchema, BrandSchema, createTestClient, assertCart, fixtures, AddItemPayloadSchema, CartItemSchema, CheckoutResponseSchema } from '../chunk-24FK7VFL.mjs';
2
+ import '../chunk-MBR2DBEN.mjs';
3
+ import '../chunk-OFNVLUH4.mjs';
4
4
  import '../chunk-XY2DFX5K.mjs';
5
5
  import '../chunk-632JEJUS.mjs';
6
6
  import '../chunk-Z2AYLZDF.mjs';