@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/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-6HYKWYUF.mjs → chunk-24FK7VFL.mjs} +1 -1
- package/dist/{chunk-Z2MLAIID.js → chunk-CYGLTD7D.js} +35 -35
- package/dist/{chunk-TW4OFRWV.js → chunk-D22UVSFN.js} +2 -2
- package/dist/{chunk-7ZACMER7.js → chunk-DR4UPU6P.js} +0 -1
- package/dist/{chunk-WUIERJ6J.mjs → chunk-MBR2DBEN.mjs} +1 -1
- package/dist/{chunk-CKRMA5F7.mjs → chunk-OFNVLUH4.mjs} +0 -1
- package/dist/{client-QVINYu1X.d.ts → client-B8tJnOde.d.ts} +0 -1
- package/dist/{client-G2WCoxv2.d.mts → client-BZZK1txR.d.mts} +0 -1
- package/dist/{client-B76ZNW5r.d.ts → client-BdbvMtOU.d.ts} +1 -1
- package/dist/{client-CT9NwIDX.d.mts → client-BqCAm5vI.d.mts} +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +61 -61
- package/dist/index.mjs +2 -2
- package/dist/react.d.mts +2 -5
- package/dist/react.d.ts +2 -5
- package/dist/react.js +51 -195
- package/dist/react.mjs +37 -181
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +3 -3
- package/dist/server.mjs +2 -2
- package/dist/testing/suite.d.mts +2 -2
- package/dist/testing/suite.d.ts +2 -2
- package/dist/testing/suite.js +22 -22
- package/dist/testing/suite.mjs +3 -3
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +78 -78
- package/dist/testing.mjs +4 -4
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
4
|
var chunkMN4PNKJA_js = require('./chunk-MN4PNKJA.js');
|
|
5
|
-
var
|
|
6
|
-
var
|
|
5
|
+
var chunkCYGLTD7D_js = require('./chunk-CYGLTD7D.js');
|
|
6
|
+
var chunkDR4UPU6P_js = require('./chunk-DR4UPU6P.js');
|
|
7
7
|
var chunk6RP6OPYO_js = require('./chunk-6RP6OPYO.js');
|
|
8
8
|
var chunkTKOTACKZ_js = require('./chunk-TKOTACKZ.js');
|
|
9
9
|
var React10 = require('react');
|
|
@@ -626,7 +626,8 @@ function useCollectionStore(collection) {
|
|
|
626
626
|
}
|
|
627
627
|
|
|
628
628
|
// src/react/hooks/use-cart.ts
|
|
629
|
-
var
|
|
629
|
+
var LEGACY_CART_STORAGE_PREFIX = "cimplify:cart:v3";
|
|
630
|
+
var legacyCachesPurged = false;
|
|
630
631
|
var cartStores = /* @__PURE__ */ new Map();
|
|
631
632
|
var ROLLBACK_VISIBLE_DELAY_MS = 3e3;
|
|
632
633
|
function clearAllCartStores() {
|
|
@@ -636,34 +637,35 @@ function clearAllCartStores() {
|
|
|
636
637
|
clearTimeout(handle);
|
|
637
638
|
}
|
|
638
639
|
entry.failedOpRemovers.clear();
|
|
639
|
-
if (entry.persistTimer) {
|
|
640
|
-
clearTimeout(entry.persistTimer);
|
|
641
|
-
entry.persistTimer = null;
|
|
642
|
-
}
|
|
643
640
|
}
|
|
644
641
|
cartStores.clear();
|
|
645
642
|
}
|
|
646
643
|
function emptyBase(currency, isLoading = true) {
|
|
647
644
|
return { items: [], subtotal: 0, tax: 0, total: 0, currency, isLoading };
|
|
648
645
|
}
|
|
649
|
-
function
|
|
650
|
-
const current = entry.collection.getBase() ?? emptyBase(entry.currency, false);
|
|
651
|
-
entry.collection.setBase({ ...applyCartPatch(current, patch), isLoading: false });
|
|
652
|
-
persistBase(entry);
|
|
653
|
-
}
|
|
654
|
-
function buildStoreKey(client, locationId, isDemoMode) {
|
|
646
|
+
function buildStoreKey(client, locationId) {
|
|
655
647
|
return [
|
|
656
|
-
client.getPublicKey() || "
|
|
657
|
-
locationId || "__no_location__"
|
|
658
|
-
isDemoMode ? "demo" : "live"
|
|
648
|
+
client.getPublicKey() || "__no_public_key__",
|
|
649
|
+
locationId || "__no_location__"
|
|
659
650
|
].join(":");
|
|
660
651
|
}
|
|
661
|
-
function
|
|
662
|
-
return
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
652
|
+
function purgeLegacyCartCachesOnce() {
|
|
653
|
+
if (legacyCachesPurged) return;
|
|
654
|
+
legacyCachesPurged = true;
|
|
655
|
+
if (typeof window === "undefined" || !window.localStorage) return;
|
|
656
|
+
try {
|
|
657
|
+
const keys = [];
|
|
658
|
+
for (let i = 0; i < window.localStorage.length; i += 1) {
|
|
659
|
+
const key = window.localStorage.key(i);
|
|
660
|
+
if (key && key.startsWith(LEGACY_CART_STORAGE_PREFIX)) {
|
|
661
|
+
keys.push(key);
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
for (const key of keys) {
|
|
665
|
+
window.localStorage.removeItem(key);
|
|
666
|
+
}
|
|
667
|
+
} catch {
|
|
668
|
+
}
|
|
667
669
|
}
|
|
668
670
|
function toProductFromServerItem(item, businessId) {
|
|
669
671
|
return {
|
|
@@ -758,69 +760,13 @@ function deriveView(base, ops) {
|
|
|
758
760
|
pendingOpCount: ops.length
|
|
759
761
|
};
|
|
760
762
|
}
|
|
761
|
-
function persistBase(entry) {
|
|
762
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
763
|
-
if (!entry.isDemoMode) return;
|
|
764
|
-
if (entry.persistTimer) return;
|
|
765
|
-
entry.persistTimer = setTimeout(() => {
|
|
766
|
-
entry.persistTimer = null;
|
|
767
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
768
|
-
const base = entry.collection.getBase();
|
|
769
|
-
if (!base) return;
|
|
770
|
-
try {
|
|
771
|
-
window.localStorage.setItem(
|
|
772
|
-
entry.storageKey,
|
|
773
|
-
JSON.stringify({
|
|
774
|
-
items: base.items.map((item) => stripInternalItemMetadata(item)),
|
|
775
|
-
subtotal: base.subtotal,
|
|
776
|
-
tax: base.tax,
|
|
777
|
-
total: base.total,
|
|
778
|
-
currency: base.currency
|
|
779
|
-
})
|
|
780
|
-
);
|
|
781
|
-
} catch {
|
|
782
|
-
}
|
|
783
|
-
}, 100);
|
|
784
|
-
}
|
|
785
|
-
function hydrateFromStorage(entry) {
|
|
786
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
787
|
-
if (!entry.isDemoMode) {
|
|
788
|
-
try {
|
|
789
|
-
window.localStorage.removeItem(entry.storageKey);
|
|
790
|
-
} catch {
|
|
791
|
-
}
|
|
792
|
-
return;
|
|
793
|
-
}
|
|
794
|
-
try {
|
|
795
|
-
const raw = window.localStorage.getItem(entry.storageKey);
|
|
796
|
-
if (!raw) return;
|
|
797
|
-
const parsed = JSON.parse(raw);
|
|
798
|
-
if (!parsed || !Array.isArray(parsed.items)) return;
|
|
799
|
-
const items = parsed.items.map((item) => attachInternalItemMetadata(item));
|
|
800
|
-
entry.collection.setBase({
|
|
801
|
-
items,
|
|
802
|
-
subtotal: toNumber(parsed.subtotal),
|
|
803
|
-
tax: toNumber(parsed.tax),
|
|
804
|
-
total: toNumber(parsed.total),
|
|
805
|
-
currency: typeof parsed.currency === "string" && parsed.currency ? parsed.currency : entry.currency,
|
|
806
|
-
isLoading: !entry.isDemoMode
|
|
807
|
-
});
|
|
808
|
-
} catch {
|
|
809
|
-
}
|
|
810
|
-
}
|
|
811
763
|
async function syncFromServer(entry) {
|
|
812
|
-
if (entry.isDemoMode) {
|
|
813
|
-
const base = entry.collection.getBase() ?? emptyBase(entry.currency);
|
|
814
|
-
entry.collection.setBase({ ...base, isLoading: false });
|
|
815
|
-
return;
|
|
816
|
-
}
|
|
817
764
|
if (entry.syncing) return;
|
|
818
765
|
entry.syncing = true;
|
|
819
766
|
try {
|
|
820
767
|
const result = await entry.client.cart.get();
|
|
821
768
|
if (!result.ok) throw result.error;
|
|
822
769
|
entry.collection.setBase(mapServerCart(result.value, entry.currency));
|
|
823
|
-
persistBase(entry);
|
|
824
770
|
} finally {
|
|
825
771
|
entry.syncing = false;
|
|
826
772
|
}
|
|
@@ -842,8 +788,9 @@ function scheduleFailedOpRemoval(entry, opId) {
|
|
|
842
788
|
entry.failedOpRemovers.add(handle);
|
|
843
789
|
}
|
|
844
790
|
function getOrCreateStore(params) {
|
|
845
|
-
const { client, locationId,
|
|
846
|
-
|
|
791
|
+
const { client, locationId, currency, optimisticEnabled } = params;
|
|
792
|
+
purgeLegacyCartCachesOnce();
|
|
793
|
+
const storeKey = buildStoreKey(client, locationId);
|
|
847
794
|
const existing = cartStores.get(storeKey);
|
|
848
795
|
if (existing) {
|
|
849
796
|
existing.optimisticEnabled = optimisticEnabled;
|
|
@@ -857,14 +804,11 @@ function getOrCreateStore(params) {
|
|
|
857
804
|
const entry = {
|
|
858
805
|
collection,
|
|
859
806
|
client,
|
|
860
|
-
storageKey: buildStorageKey(storeKey),
|
|
861
807
|
locationId,
|
|
862
808
|
currency,
|
|
863
|
-
isDemoMode,
|
|
864
809
|
optimisticEnabled,
|
|
865
810
|
initialized: false,
|
|
866
811
|
initializePromise: null,
|
|
867
|
-
persistTimer: null,
|
|
868
812
|
syncing: false,
|
|
869
813
|
failedOpRemovers: /* @__PURE__ */ new Set()
|
|
870
814
|
};
|
|
@@ -877,12 +821,6 @@ async function ensureInitialized(entry) {
|
|
|
877
821
|
return;
|
|
878
822
|
}
|
|
879
823
|
entry.initialized = true;
|
|
880
|
-
hydrateFromStorage(entry);
|
|
881
|
-
if (entry.isDemoMode) {
|
|
882
|
-
const base = entry.collection.getBase() ?? emptyBase(entry.currency);
|
|
883
|
-
entry.collection.setBase({ ...base, isLoading: false });
|
|
884
|
-
return;
|
|
885
|
-
}
|
|
886
824
|
entry.initializePromise = syncFromServer(entry).catch(() => {
|
|
887
825
|
const base = entry.collection.getBase() ?? emptyBase(entry.currency);
|
|
888
826
|
entry.collection.setBase({ ...base, isLoading: false });
|
|
@@ -896,7 +834,7 @@ async function maybeResolveQuoteId(entry, product, quantity, options) {
|
|
|
896
834
|
const requiresQuote = Boolean(
|
|
897
835
|
options.variantId || addOnOptionIds && addOnOptionIds.length > 0 || options.bundleSelections && options.bundleSelections.length > 0 || options.compositeSelections && options.compositeSelections.length > 0
|
|
898
836
|
);
|
|
899
|
-
if (!requiresQuote
|
|
837
|
+
if (!requiresQuote) return void 0;
|
|
900
838
|
const quoteResult = await entry.client.catalogue.fetchQuote({
|
|
901
839
|
product_id: product.id,
|
|
902
840
|
quantity,
|
|
@@ -936,10 +874,6 @@ async function performAddItem(entry, product, quantity, options) {
|
|
|
936
874
|
});
|
|
937
875
|
const idempotencyKey = `idem_${typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}_${Math.random().toString(36).slice(2, 10)}`}`;
|
|
938
876
|
const patch = { kind: "add_item", tempItem, lineKey };
|
|
939
|
-
if (entry.isDemoMode) {
|
|
940
|
-
advanceBaseWithPatch(entry, patch);
|
|
941
|
-
return;
|
|
942
|
-
}
|
|
943
877
|
const useOptimistic = entry.optimisticEnabled;
|
|
944
878
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
945
879
|
try {
|
|
@@ -978,10 +912,6 @@ async function performAddItem(entry, product, quantity, options) {
|
|
|
978
912
|
async function performRemoveItem(entry, itemId) {
|
|
979
913
|
const idempotencyKey = "";
|
|
980
914
|
const patch = { kind: "remove_item", itemId };
|
|
981
|
-
if (entry.isDemoMode) {
|
|
982
|
-
advanceBaseWithPatch(entry, patch);
|
|
983
|
-
return;
|
|
984
|
-
}
|
|
985
915
|
const useOptimistic = entry.optimisticEnabled;
|
|
986
916
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
987
917
|
try {
|
|
@@ -1006,10 +936,6 @@ async function performUpdateQuantity(entry, itemId, quantity) {
|
|
|
1006
936
|
const resolved = clampQuantity(quantity);
|
|
1007
937
|
const idempotencyKey = "";
|
|
1008
938
|
const patch = { kind: "set_quantity", itemId, quantity: resolved };
|
|
1009
|
-
if (entry.isDemoMode) {
|
|
1010
|
-
advanceBaseWithPatch(entry, patch);
|
|
1011
|
-
return;
|
|
1012
|
-
}
|
|
1013
939
|
const useOptimistic = entry.optimisticEnabled;
|
|
1014
940
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
1015
941
|
try {
|
|
@@ -1030,10 +956,6 @@ async function performUpdateQuantity(entry, itemId, quantity) {
|
|
|
1030
956
|
async function performClear(entry) {
|
|
1031
957
|
const idempotencyKey = "";
|
|
1032
958
|
const patch = { kind: "clear" };
|
|
1033
|
-
if (entry.isDemoMode) {
|
|
1034
|
-
advanceBaseWithPatch(entry, patch);
|
|
1035
|
-
return;
|
|
1036
|
-
}
|
|
1037
959
|
const useOptimistic = entry.optimisticEnabled;
|
|
1038
960
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
1039
961
|
try {
|
|
@@ -1064,18 +986,16 @@ function useCart(options = {}) {
|
|
|
1064
986
|
throw new Error("useCart must be used within CimplifyProvider or passed { client }.");
|
|
1065
987
|
}
|
|
1066
988
|
const locationId = options.locationId ?? client.getLocationId();
|
|
1067
|
-
const isDemoMode = options.demoMode ?? context?.isDemoMode ?? client.getPublicKey().trim().length === 0;
|
|
1068
989
|
const currency = options.currency ?? context?.currency ?? "USD";
|
|
1069
990
|
const optimisticEnabled = context?.optimistic ?? true;
|
|
1070
991
|
const entry = React10.useMemo(
|
|
1071
992
|
() => getOrCreateStore({
|
|
1072
993
|
client,
|
|
1073
994
|
locationId,
|
|
1074
|
-
isDemoMode,
|
|
1075
995
|
currency,
|
|
1076
996
|
optimisticEnabled
|
|
1077
997
|
}),
|
|
1078
|
-
[client, currency,
|
|
998
|
+
[client, currency, locationId, optimisticEnabled]
|
|
1079
999
|
);
|
|
1080
1000
|
const view = useCollectionStore(entry.collection);
|
|
1081
1001
|
React10.useEffect(() => {
|
|
@@ -1161,7 +1081,7 @@ var DEFAULT_COUNTRY = "US";
|
|
|
1161
1081
|
function createDefaultClient() {
|
|
1162
1082
|
const processRef = globalThis.process;
|
|
1163
1083
|
const envPublicKey = processRef?.env?.NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY || "";
|
|
1164
|
-
return
|
|
1084
|
+
return chunkCYGLTD7D_js.createCimplifyClient({ publicKey: envPublicKey });
|
|
1165
1085
|
}
|
|
1166
1086
|
function getStoredLocationId() {
|
|
1167
1087
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
@@ -1235,7 +1155,6 @@ function CimplifyProvider({
|
|
|
1235
1155
|
React10.useEffect(() => {
|
|
1236
1156
|
onLocationChangeRef.current = onLocationChange;
|
|
1237
1157
|
}, [onLocationChange]);
|
|
1238
|
-
const isDemoMode = resolvedClient.getPublicKey().trim().length === 0;
|
|
1239
1158
|
const baseCurrency = business?.default_currency || DEFAULT_CURRENCY;
|
|
1240
1159
|
const [displayCurrencyOverride, setDisplayCurrencyOverride] = React10.useState(
|
|
1241
1160
|
() => getStoredDisplayCurrency()
|
|
@@ -1257,7 +1176,7 @@ function CimplifyProvider({
|
|
|
1257
1176
|
[baseCurrency]
|
|
1258
1177
|
);
|
|
1259
1178
|
React10.useEffect(() => {
|
|
1260
|
-
if (displayCurrency === baseCurrency
|
|
1179
|
+
if (displayCurrency === baseCurrency) {
|
|
1261
1180
|
setFxRate(null);
|
|
1262
1181
|
return;
|
|
1263
1182
|
}
|
|
@@ -1280,7 +1199,7 @@ function CimplifyProvider({
|
|
|
1280
1199
|
cancelled = true;
|
|
1281
1200
|
clearInterval(intervalId);
|
|
1282
1201
|
};
|
|
1283
|
-
}, [resolvedClient, baseCurrency, displayCurrency
|
|
1202
|
+
}, [resolvedClient, baseCurrency, displayCurrency]);
|
|
1284
1203
|
const convertPrice = React10.useCallback(
|
|
1285
1204
|
(amount) => {
|
|
1286
1205
|
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
@@ -1307,17 +1226,6 @@ function CimplifyProvider({
|
|
|
1307
1226
|
let cancelled = false;
|
|
1308
1227
|
async function bootstrap() {
|
|
1309
1228
|
setIsReady(false);
|
|
1310
|
-
if (isDemoMode) {
|
|
1311
|
-
if (!cancelled) {
|
|
1312
|
-
setBusiness(null);
|
|
1313
|
-
setLocations([]);
|
|
1314
|
-
setCurrentLocationState(null);
|
|
1315
|
-
resolvedClient.setLocationId(null);
|
|
1316
|
-
setStoredLocationId(null);
|
|
1317
|
-
setIsReady(true);
|
|
1318
|
-
}
|
|
1319
|
-
return;
|
|
1320
|
-
}
|
|
1321
1229
|
const [businessResult, locationsResult] = await Promise.all([
|
|
1322
1230
|
resolvedClient.business.getInfo(),
|
|
1323
1231
|
resolvedClient.business.getLocations()
|
|
@@ -1358,7 +1266,7 @@ function CimplifyProvider({
|
|
|
1358
1266
|
return () => {
|
|
1359
1267
|
cancelled = true;
|
|
1360
1268
|
};
|
|
1361
|
-
}, [resolvedClient
|
|
1269
|
+
}, [resolvedClient]);
|
|
1362
1270
|
const clientContextValue = React10.useMemo(
|
|
1363
1271
|
() => ({
|
|
1364
1272
|
client: resolvedClient,
|
|
@@ -1367,7 +1275,6 @@ function CimplifyProvider({
|
|
|
1367
1275
|
country: business?.country_code || DEFAULT_COUNTRY,
|
|
1368
1276
|
locations,
|
|
1369
1277
|
isReady,
|
|
1370
|
-
isDemoMode,
|
|
1371
1278
|
baseCurrency,
|
|
1372
1279
|
optimistic
|
|
1373
1280
|
}),
|
|
@@ -1377,7 +1284,6 @@ function CimplifyProvider({
|
|
|
1377
1284
|
baseCurrency,
|
|
1378
1285
|
locations,
|
|
1379
1286
|
isReady,
|
|
1380
|
-
isDemoMode,
|
|
1381
1287
|
optimistic
|
|
1382
1288
|
]
|
|
1383
1289
|
);
|
|
@@ -1485,7 +1391,6 @@ function CimplifyCheckout({
|
|
|
1485
1391
|
onError,
|
|
1486
1392
|
onStatusChange,
|
|
1487
1393
|
appearance,
|
|
1488
|
-
demoMode,
|
|
1489
1394
|
className
|
|
1490
1395
|
}) {
|
|
1491
1396
|
const resolvedOrderTypes = React10.useMemo(
|
|
@@ -1513,8 +1418,6 @@ function CimplifyCheckout({
|
|
|
1513
1418
|
const initialAppearanceRef = React10.useRef(appearance);
|
|
1514
1419
|
const hasWarnedInlineAppearanceRef = React10.useRef(false);
|
|
1515
1420
|
const isMountedRef = React10.useRef(true);
|
|
1516
|
-
const demoRunRef = React10.useRef(0);
|
|
1517
|
-
const isDemoCheckout = demoMode ?? client.getPublicKey().trim().length === 0;
|
|
1518
1421
|
const isTestMode = client.isTestMode();
|
|
1519
1422
|
const cimplifyCtx = useOptionalCimplify();
|
|
1520
1423
|
const fxOptions = React10.useMemo(() => {
|
|
@@ -1559,15 +1462,6 @@ function CimplifyCheckout({
|
|
|
1559
1462
|
React10.useEffect(() => {
|
|
1560
1463
|
let cancelled = false;
|
|
1561
1464
|
async function bootstrap() {
|
|
1562
|
-
if (isDemoCheckout) {
|
|
1563
|
-
if (!cancelled) {
|
|
1564
|
-
setResolvedBusinessId(businessId ?? null);
|
|
1565
|
-
setResolvedCartId(cartId ?? "cart_demo");
|
|
1566
|
-
setIsInitializing(false);
|
|
1567
|
-
setErrorMessage(null);
|
|
1568
|
-
}
|
|
1569
|
-
return;
|
|
1570
|
-
}
|
|
1571
1465
|
const needsBusinessResolve = !businessId;
|
|
1572
1466
|
const needsCartResolve = !cartId;
|
|
1573
1467
|
if (!needsBusinessResolve && !needsCartResolve) {
|
|
@@ -1635,11 +1529,10 @@ function CimplifyCheckout({
|
|
|
1635
1529
|
return () => {
|
|
1636
1530
|
cancelled = true;
|
|
1637
1531
|
};
|
|
1638
|
-
}, [businessId, cartId, client
|
|
1532
|
+
}, [businessId, cartId, client]);
|
|
1639
1533
|
React10.useEffect(() => {
|
|
1640
1534
|
return () => {
|
|
1641
1535
|
isMountedRef.current = false;
|
|
1642
|
-
demoRunRef.current += 1;
|
|
1643
1536
|
activeCheckoutRef.current?.abort();
|
|
1644
1537
|
activeCheckoutRef.current = null;
|
|
1645
1538
|
};
|
|
@@ -1656,42 +1549,6 @@ function CimplifyCheckout({
|
|
|
1656
1549
|
setErrorMessage(null);
|
|
1657
1550
|
setIsSubmitting(true);
|
|
1658
1551
|
emitStatus("preparing", { display_text: statusToLabel("preparing") });
|
|
1659
|
-
if (isDemoCheckout) {
|
|
1660
|
-
const runId = demoRunRef.current + 1;
|
|
1661
|
-
demoRunRef.current = runId;
|
|
1662
|
-
const wait = async (ms) => {
|
|
1663
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
1664
|
-
return isMountedRef.current && runId === demoRunRef.current;
|
|
1665
|
-
};
|
|
1666
|
-
try {
|
|
1667
|
-
if (!await wait(400)) return;
|
|
1668
|
-
emitStatus("processing", { display_text: statusToLabel("processing") });
|
|
1669
|
-
if (!await wait(900)) return;
|
|
1670
|
-
emitStatus("polling", { display_text: statusToLabel("polling") });
|
|
1671
|
-
if (!await wait(1200)) return;
|
|
1672
|
-
const result = {
|
|
1673
|
-
success: true,
|
|
1674
|
-
order: {
|
|
1675
|
-
id: `ord_demo_${Date.now()}`,
|
|
1676
|
-
order_number: `DEMO-${Math.random().toString(36).slice(2, 8).toUpperCase()}`,
|
|
1677
|
-
status: "confirmed",
|
|
1678
|
-
total: "0.00",
|
|
1679
|
-
currency: "USD"
|
|
1680
|
-
}
|
|
1681
|
-
};
|
|
1682
|
-
emitStatus("success", {
|
|
1683
|
-
order_id: result.order?.id,
|
|
1684
|
-
order_number: result.order?.order_number,
|
|
1685
|
-
display_text: statusToLabel("success")
|
|
1686
|
-
});
|
|
1687
|
-
onComplete(result);
|
|
1688
|
-
} finally {
|
|
1689
|
-
if (isMountedRef.current && runId === demoRunRef.current) {
|
|
1690
|
-
setIsSubmitting(false);
|
|
1691
|
-
}
|
|
1692
|
-
}
|
|
1693
|
-
return;
|
|
1694
|
-
}
|
|
1695
1552
|
if (!elementsRef.current) {
|
|
1696
1553
|
const message = "Checkout is still initializing. Please try again.";
|
|
1697
1554
|
setErrorMessage(message);
|
|
@@ -1726,7 +1583,7 @@ function CimplifyCheckout({
|
|
|
1726
1583
|
}
|
|
1727
1584
|
});
|
|
1728
1585
|
React10.useEffect(() => {
|
|
1729
|
-
if (
|
|
1586
|
+
if (!resolvedBusinessId) {
|
|
1730
1587
|
elementsRef.current = null;
|
|
1731
1588
|
return;
|
|
1732
1589
|
}
|
|
@@ -1767,7 +1624,6 @@ function CimplifyCheckout({
|
|
|
1767
1624
|
}, [
|
|
1768
1625
|
client,
|
|
1769
1626
|
resolvedBusinessId,
|
|
1770
|
-
isDemoCheckout,
|
|
1771
1627
|
resolvedOrderTypes,
|
|
1772
1628
|
resolvedDefaultOrderType,
|
|
1773
1629
|
submitLabel
|
|
@@ -1783,11 +1639,11 @@ function CimplifyCheckout({
|
|
|
1783
1639
|
if (isInitializing) {
|
|
1784
1640
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-cimplify-checkout": "", children: /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-status": "", style: { fontSize: 13, color: colors.textSecondary }, children: "Preparing checkout..." }) });
|
|
1785
1641
|
}
|
|
1786
|
-
if (!
|
|
1642
|
+
if (!resolvedBusinessId || !resolvedCartId) {
|
|
1787
1643
|
return /* @__PURE__ */ jsxRuntime.jsx("div", { className, "data-cimplify-checkout": "", children: /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-error": "", style: { fontSize: 13, color: colors.error }, children: errorMessage || "Unable to initialize checkout. Please refresh and try again." }) });
|
|
1788
1644
|
}
|
|
1789
1645
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, "data-cimplify-checkout": "", children: [
|
|
1790
|
-
isTestMode &&
|
|
1646
|
+
isTestMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1791
1647
|
"p",
|
|
1792
1648
|
{
|
|
1793
1649
|
"data-cimplify-test-mode": "",
|
|
@@ -1800,7 +1656,7 @@ function CimplifyCheckout({
|
|
|
1800
1656
|
children: "Test mode - no real charges"
|
|
1801
1657
|
}
|
|
1802
1658
|
),
|
|
1803
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { "data-cimplify-section": "checkout", children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref:
|
|
1659
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { "data-cimplify-section": "checkout", children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: checkoutMountRef }) }),
|
|
1804
1660
|
status && /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-status": "", style: { marginTop: SPACE.sm, fontSize: 13, color: colors.textSecondary }, children: statusText || statusToLabel(status) }),
|
|
1805
1661
|
errorMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-error": "", style: { marginTop: SPACE.sm, fontSize: 13, color: colors.error }, children: errorMessage })
|
|
1806
1662
|
] });
|
|
@@ -3667,19 +3523,19 @@ function AuthElement({
|
|
|
3667
3523
|
}, [onReady, onAuthenticated, onRequiresOtp, onError]);
|
|
3668
3524
|
React10.useEffect(() => {
|
|
3669
3525
|
if (!elements || !containerRef.current) return;
|
|
3670
|
-
const element = elements.create(
|
|
3526
|
+
const element = elements.create(chunkDR4UPU6P_js.ELEMENT_TYPES.AUTH, { prefillEmail });
|
|
3671
3527
|
elementRef.current = element;
|
|
3672
|
-
element.on(
|
|
3528
|
+
element.on(chunkDR4UPU6P_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
|
|
3673
3529
|
element.on(
|
|
3674
|
-
|
|
3530
|
+
chunkDR4UPU6P_js.EVENT_TYPES.AUTHENTICATED,
|
|
3675
3531
|
(data) => onAuthenticatedRef.current?.(data)
|
|
3676
3532
|
);
|
|
3677
3533
|
element.on(
|
|
3678
|
-
|
|
3534
|
+
chunkDR4UPU6P_js.EVENT_TYPES.REQUIRES_OTP,
|
|
3679
3535
|
(data) => onRequiresOtpRef.current?.(data)
|
|
3680
3536
|
);
|
|
3681
3537
|
element.on(
|
|
3682
|
-
|
|
3538
|
+
chunkDR4UPU6P_js.EVENT_TYPES.ERROR,
|
|
3683
3539
|
(data) => onErrorRef.current?.(data)
|
|
3684
3540
|
);
|
|
3685
3541
|
element.mount(containerRef.current);
|
|
@@ -3708,15 +3564,15 @@ function AddressElement({
|
|
|
3708
3564
|
}, [onReady, onChange, onError]);
|
|
3709
3565
|
React10.useEffect(() => {
|
|
3710
3566
|
if (!elements || !containerRef.current) return;
|
|
3711
|
-
const element = elements.create(
|
|
3567
|
+
const element = elements.create(chunkDR4UPU6P_js.ELEMENT_TYPES.ADDRESS, { mode });
|
|
3712
3568
|
elementRef.current = element;
|
|
3713
|
-
element.on(
|
|
3569
|
+
element.on(chunkDR4UPU6P_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
|
|
3714
3570
|
element.on(
|
|
3715
|
-
|
|
3571
|
+
chunkDR4UPU6P_js.EVENT_TYPES.CHANGE,
|
|
3716
3572
|
(data) => onChangeRef.current?.(data)
|
|
3717
3573
|
);
|
|
3718
3574
|
element.on(
|
|
3719
|
-
|
|
3575
|
+
chunkDR4UPU6P_js.EVENT_TYPES.ERROR,
|
|
3720
3576
|
(data) => onErrorRef.current?.(data)
|
|
3721
3577
|
);
|
|
3722
3578
|
element.mount(containerRef.current);
|
|
@@ -3746,15 +3602,15 @@ function PaymentElement({
|
|
|
3746
3602
|
}, [onReady, onChange, onError]);
|
|
3747
3603
|
React10.useEffect(() => {
|
|
3748
3604
|
if (!elements || !containerRef.current) return;
|
|
3749
|
-
const element = elements.create(
|
|
3605
|
+
const element = elements.create(chunkDR4UPU6P_js.ELEMENT_TYPES.PAYMENT, { amount, currency });
|
|
3750
3606
|
elementRef.current = element;
|
|
3751
|
-
element.on(
|
|
3607
|
+
element.on(chunkDR4UPU6P_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
|
|
3752
3608
|
element.on(
|
|
3753
|
-
|
|
3609
|
+
chunkDR4UPU6P_js.EVENT_TYPES.CHANGE,
|
|
3754
3610
|
(data) => onChangeRef.current?.(data)
|
|
3755
3611
|
);
|
|
3756
3612
|
element.on(
|
|
3757
|
-
|
|
3613
|
+
chunkDR4UPU6P_js.EVENT_TYPES.ERROR,
|
|
3758
3614
|
(data) => onErrorRef.current?.(data)
|
|
3759
3615
|
);
|
|
3760
3616
|
element.mount(containerRef.current);
|