@cimplify/sdk 0.46.2 → 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 -187
- package/dist/react.mjs +37 -173
- 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,61 +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.persistTimer) return;
|
|
764
|
-
entry.persistTimer = setTimeout(() => {
|
|
765
|
-
entry.persistTimer = null;
|
|
766
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
767
|
-
const base = entry.collection.getBase();
|
|
768
|
-
if (!base) return;
|
|
769
|
-
try {
|
|
770
|
-
window.localStorage.setItem(
|
|
771
|
-
entry.storageKey,
|
|
772
|
-
JSON.stringify({
|
|
773
|
-
items: base.items.map((item) => stripInternalItemMetadata(item)),
|
|
774
|
-
subtotal: base.subtotal,
|
|
775
|
-
tax: base.tax,
|
|
776
|
-
total: base.total,
|
|
777
|
-
currency: base.currency
|
|
778
|
-
})
|
|
779
|
-
);
|
|
780
|
-
} catch {
|
|
781
|
-
}
|
|
782
|
-
}, 100);
|
|
783
|
-
}
|
|
784
|
-
function hydrateFromStorage(entry) {
|
|
785
|
-
if (typeof window === "undefined" || !window.localStorage) return;
|
|
786
|
-
try {
|
|
787
|
-
const raw = window.localStorage.getItem(entry.storageKey);
|
|
788
|
-
if (!raw) return;
|
|
789
|
-
const parsed = JSON.parse(raw);
|
|
790
|
-
if (!parsed || !Array.isArray(parsed.items)) return;
|
|
791
|
-
const items = parsed.items.map((item) => attachInternalItemMetadata(item));
|
|
792
|
-
entry.collection.setBase({
|
|
793
|
-
items,
|
|
794
|
-
subtotal: toNumber(parsed.subtotal),
|
|
795
|
-
tax: toNumber(parsed.tax),
|
|
796
|
-
total: toNumber(parsed.total),
|
|
797
|
-
currency: typeof parsed.currency === "string" && parsed.currency ? parsed.currency : entry.currency,
|
|
798
|
-
isLoading: !entry.isDemoMode
|
|
799
|
-
});
|
|
800
|
-
} catch {
|
|
801
|
-
}
|
|
802
|
-
}
|
|
803
763
|
async function syncFromServer(entry) {
|
|
804
|
-
if (entry.isDemoMode) {
|
|
805
|
-
const base = entry.collection.getBase() ?? emptyBase(entry.currency);
|
|
806
|
-
entry.collection.setBase({ ...base, isLoading: false });
|
|
807
|
-
return;
|
|
808
|
-
}
|
|
809
764
|
if (entry.syncing) return;
|
|
810
765
|
entry.syncing = true;
|
|
811
766
|
try {
|
|
812
767
|
const result = await entry.client.cart.get();
|
|
813
768
|
if (!result.ok) throw result.error;
|
|
814
769
|
entry.collection.setBase(mapServerCart(result.value, entry.currency));
|
|
815
|
-
persistBase(entry);
|
|
816
770
|
} finally {
|
|
817
771
|
entry.syncing = false;
|
|
818
772
|
}
|
|
@@ -834,8 +788,9 @@ function scheduleFailedOpRemoval(entry, opId) {
|
|
|
834
788
|
entry.failedOpRemovers.add(handle);
|
|
835
789
|
}
|
|
836
790
|
function getOrCreateStore(params) {
|
|
837
|
-
const { client, locationId,
|
|
838
|
-
|
|
791
|
+
const { client, locationId, currency, optimisticEnabled } = params;
|
|
792
|
+
purgeLegacyCartCachesOnce();
|
|
793
|
+
const storeKey = buildStoreKey(client, locationId);
|
|
839
794
|
const existing = cartStores.get(storeKey);
|
|
840
795
|
if (existing) {
|
|
841
796
|
existing.optimisticEnabled = optimisticEnabled;
|
|
@@ -849,14 +804,11 @@ function getOrCreateStore(params) {
|
|
|
849
804
|
const entry = {
|
|
850
805
|
collection,
|
|
851
806
|
client,
|
|
852
|
-
storageKey: buildStorageKey(storeKey),
|
|
853
807
|
locationId,
|
|
854
808
|
currency,
|
|
855
|
-
isDemoMode,
|
|
856
809
|
optimisticEnabled,
|
|
857
810
|
initialized: false,
|
|
858
811
|
initializePromise: null,
|
|
859
|
-
persistTimer: null,
|
|
860
812
|
syncing: false,
|
|
861
813
|
failedOpRemovers: /* @__PURE__ */ new Set()
|
|
862
814
|
};
|
|
@@ -869,12 +821,6 @@ async function ensureInitialized(entry) {
|
|
|
869
821
|
return;
|
|
870
822
|
}
|
|
871
823
|
entry.initialized = true;
|
|
872
|
-
hydrateFromStorage(entry);
|
|
873
|
-
if (entry.isDemoMode) {
|
|
874
|
-
const base = entry.collection.getBase() ?? emptyBase(entry.currency);
|
|
875
|
-
entry.collection.setBase({ ...base, isLoading: false });
|
|
876
|
-
return;
|
|
877
|
-
}
|
|
878
824
|
entry.initializePromise = syncFromServer(entry).catch(() => {
|
|
879
825
|
const base = entry.collection.getBase() ?? emptyBase(entry.currency);
|
|
880
826
|
entry.collection.setBase({ ...base, isLoading: false });
|
|
@@ -888,7 +834,7 @@ async function maybeResolveQuoteId(entry, product, quantity, options) {
|
|
|
888
834
|
const requiresQuote = Boolean(
|
|
889
835
|
options.variantId || addOnOptionIds && addOnOptionIds.length > 0 || options.bundleSelections && options.bundleSelections.length > 0 || options.compositeSelections && options.compositeSelections.length > 0
|
|
890
836
|
);
|
|
891
|
-
if (!requiresQuote
|
|
837
|
+
if (!requiresQuote) return void 0;
|
|
892
838
|
const quoteResult = await entry.client.catalogue.fetchQuote({
|
|
893
839
|
product_id: product.id,
|
|
894
840
|
quantity,
|
|
@@ -928,10 +874,6 @@ async function performAddItem(entry, product, quantity, options) {
|
|
|
928
874
|
});
|
|
929
875
|
const idempotencyKey = `idem_${typeof crypto !== "undefined" && crypto.randomUUID ? crypto.randomUUID() : `${Date.now()}_${Math.random().toString(36).slice(2, 10)}`}`;
|
|
930
876
|
const patch = { kind: "add_item", tempItem, lineKey };
|
|
931
|
-
if (entry.isDemoMode) {
|
|
932
|
-
advanceBaseWithPatch(entry, patch);
|
|
933
|
-
return;
|
|
934
|
-
}
|
|
935
877
|
const useOptimistic = entry.optimisticEnabled;
|
|
936
878
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
937
879
|
try {
|
|
@@ -970,10 +912,6 @@ async function performAddItem(entry, product, quantity, options) {
|
|
|
970
912
|
async function performRemoveItem(entry, itemId) {
|
|
971
913
|
const idempotencyKey = "";
|
|
972
914
|
const patch = { kind: "remove_item", itemId };
|
|
973
|
-
if (entry.isDemoMode) {
|
|
974
|
-
advanceBaseWithPatch(entry, patch);
|
|
975
|
-
return;
|
|
976
|
-
}
|
|
977
915
|
const useOptimistic = entry.optimisticEnabled;
|
|
978
916
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
979
917
|
try {
|
|
@@ -998,10 +936,6 @@ async function performUpdateQuantity(entry, itemId, quantity) {
|
|
|
998
936
|
const resolved = clampQuantity(quantity);
|
|
999
937
|
const idempotencyKey = "";
|
|
1000
938
|
const patch = { kind: "set_quantity", itemId, quantity: resolved };
|
|
1001
|
-
if (entry.isDemoMode) {
|
|
1002
|
-
advanceBaseWithPatch(entry, patch);
|
|
1003
|
-
return;
|
|
1004
|
-
}
|
|
1005
939
|
const useOptimistic = entry.optimisticEnabled;
|
|
1006
940
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
1007
941
|
try {
|
|
@@ -1022,10 +956,6 @@ async function performUpdateQuantity(entry, itemId, quantity) {
|
|
|
1022
956
|
async function performClear(entry) {
|
|
1023
957
|
const idempotencyKey = "";
|
|
1024
958
|
const patch = { kind: "clear" };
|
|
1025
|
-
if (entry.isDemoMode) {
|
|
1026
|
-
advanceBaseWithPatch(entry, patch);
|
|
1027
|
-
return;
|
|
1028
|
-
}
|
|
1029
959
|
const useOptimistic = entry.optimisticEnabled;
|
|
1030
960
|
const opId = useOptimistic ? entry.collection.enqueue(patch, idempotencyKey) : null;
|
|
1031
961
|
try {
|
|
@@ -1056,18 +986,16 @@ function useCart(options = {}) {
|
|
|
1056
986
|
throw new Error("useCart must be used within CimplifyProvider or passed { client }.");
|
|
1057
987
|
}
|
|
1058
988
|
const locationId = options.locationId ?? client.getLocationId();
|
|
1059
|
-
const isDemoMode = options.demoMode ?? context?.isDemoMode ?? client.getPublicKey().trim().length === 0;
|
|
1060
989
|
const currency = options.currency ?? context?.currency ?? "USD";
|
|
1061
990
|
const optimisticEnabled = context?.optimistic ?? true;
|
|
1062
991
|
const entry = React10.useMemo(
|
|
1063
992
|
() => getOrCreateStore({
|
|
1064
993
|
client,
|
|
1065
994
|
locationId,
|
|
1066
|
-
isDemoMode,
|
|
1067
995
|
currency,
|
|
1068
996
|
optimisticEnabled
|
|
1069
997
|
}),
|
|
1070
|
-
[client, currency,
|
|
998
|
+
[client, currency, locationId, optimisticEnabled]
|
|
1071
999
|
);
|
|
1072
1000
|
const view = useCollectionStore(entry.collection);
|
|
1073
1001
|
React10.useEffect(() => {
|
|
@@ -1153,7 +1081,7 @@ var DEFAULT_COUNTRY = "US";
|
|
|
1153
1081
|
function createDefaultClient() {
|
|
1154
1082
|
const processRef = globalThis.process;
|
|
1155
1083
|
const envPublicKey = processRef?.env?.NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY || "";
|
|
1156
|
-
return
|
|
1084
|
+
return chunkCYGLTD7D_js.createCimplifyClient({ publicKey: envPublicKey });
|
|
1157
1085
|
}
|
|
1158
1086
|
function getStoredLocationId() {
|
|
1159
1087
|
if (typeof window === "undefined" || !window.localStorage) {
|
|
@@ -1227,7 +1155,6 @@ function CimplifyProvider({
|
|
|
1227
1155
|
React10.useEffect(() => {
|
|
1228
1156
|
onLocationChangeRef.current = onLocationChange;
|
|
1229
1157
|
}, [onLocationChange]);
|
|
1230
|
-
const isDemoMode = resolvedClient.getPublicKey().trim().length === 0;
|
|
1231
1158
|
const baseCurrency = business?.default_currency || DEFAULT_CURRENCY;
|
|
1232
1159
|
const [displayCurrencyOverride, setDisplayCurrencyOverride] = React10.useState(
|
|
1233
1160
|
() => getStoredDisplayCurrency()
|
|
@@ -1249,7 +1176,7 @@ function CimplifyProvider({
|
|
|
1249
1176
|
[baseCurrency]
|
|
1250
1177
|
);
|
|
1251
1178
|
React10.useEffect(() => {
|
|
1252
|
-
if (displayCurrency === baseCurrency
|
|
1179
|
+
if (displayCurrency === baseCurrency) {
|
|
1253
1180
|
setFxRate(null);
|
|
1254
1181
|
return;
|
|
1255
1182
|
}
|
|
@@ -1272,7 +1199,7 @@ function CimplifyProvider({
|
|
|
1272
1199
|
cancelled = true;
|
|
1273
1200
|
clearInterval(intervalId);
|
|
1274
1201
|
};
|
|
1275
|
-
}, [resolvedClient, baseCurrency, displayCurrency
|
|
1202
|
+
}, [resolvedClient, baseCurrency, displayCurrency]);
|
|
1276
1203
|
const convertPrice = React10.useCallback(
|
|
1277
1204
|
(amount) => {
|
|
1278
1205
|
const num = typeof amount === "string" ? parseFloat(amount) : amount;
|
|
@@ -1299,17 +1226,6 @@ function CimplifyProvider({
|
|
|
1299
1226
|
let cancelled = false;
|
|
1300
1227
|
async function bootstrap() {
|
|
1301
1228
|
setIsReady(false);
|
|
1302
|
-
if (isDemoMode) {
|
|
1303
|
-
if (!cancelled) {
|
|
1304
|
-
setBusiness(null);
|
|
1305
|
-
setLocations([]);
|
|
1306
|
-
setCurrentLocationState(null);
|
|
1307
|
-
resolvedClient.setLocationId(null);
|
|
1308
|
-
setStoredLocationId(null);
|
|
1309
|
-
setIsReady(true);
|
|
1310
|
-
}
|
|
1311
|
-
return;
|
|
1312
|
-
}
|
|
1313
1229
|
const [businessResult, locationsResult] = await Promise.all([
|
|
1314
1230
|
resolvedClient.business.getInfo(),
|
|
1315
1231
|
resolvedClient.business.getLocations()
|
|
@@ -1350,7 +1266,7 @@ function CimplifyProvider({
|
|
|
1350
1266
|
return () => {
|
|
1351
1267
|
cancelled = true;
|
|
1352
1268
|
};
|
|
1353
|
-
}, [resolvedClient
|
|
1269
|
+
}, [resolvedClient]);
|
|
1354
1270
|
const clientContextValue = React10.useMemo(
|
|
1355
1271
|
() => ({
|
|
1356
1272
|
client: resolvedClient,
|
|
@@ -1359,7 +1275,6 @@ function CimplifyProvider({
|
|
|
1359
1275
|
country: business?.country_code || DEFAULT_COUNTRY,
|
|
1360
1276
|
locations,
|
|
1361
1277
|
isReady,
|
|
1362
|
-
isDemoMode,
|
|
1363
1278
|
baseCurrency,
|
|
1364
1279
|
optimistic
|
|
1365
1280
|
}),
|
|
@@ -1369,7 +1284,6 @@ function CimplifyProvider({
|
|
|
1369
1284
|
baseCurrency,
|
|
1370
1285
|
locations,
|
|
1371
1286
|
isReady,
|
|
1372
|
-
isDemoMode,
|
|
1373
1287
|
optimistic
|
|
1374
1288
|
]
|
|
1375
1289
|
);
|
|
@@ -1477,7 +1391,6 @@ function CimplifyCheckout({
|
|
|
1477
1391
|
onError,
|
|
1478
1392
|
onStatusChange,
|
|
1479
1393
|
appearance,
|
|
1480
|
-
demoMode,
|
|
1481
1394
|
className
|
|
1482
1395
|
}) {
|
|
1483
1396
|
const resolvedOrderTypes = React10.useMemo(
|
|
@@ -1505,8 +1418,6 @@ function CimplifyCheckout({
|
|
|
1505
1418
|
const initialAppearanceRef = React10.useRef(appearance);
|
|
1506
1419
|
const hasWarnedInlineAppearanceRef = React10.useRef(false);
|
|
1507
1420
|
const isMountedRef = React10.useRef(true);
|
|
1508
|
-
const demoRunRef = React10.useRef(0);
|
|
1509
|
-
const isDemoCheckout = demoMode ?? client.getPublicKey().trim().length === 0;
|
|
1510
1421
|
const isTestMode = client.isTestMode();
|
|
1511
1422
|
const cimplifyCtx = useOptionalCimplify();
|
|
1512
1423
|
const fxOptions = React10.useMemo(() => {
|
|
@@ -1551,15 +1462,6 @@ function CimplifyCheckout({
|
|
|
1551
1462
|
React10.useEffect(() => {
|
|
1552
1463
|
let cancelled = false;
|
|
1553
1464
|
async function bootstrap() {
|
|
1554
|
-
if (isDemoCheckout) {
|
|
1555
|
-
if (!cancelled) {
|
|
1556
|
-
setResolvedBusinessId(businessId ?? null);
|
|
1557
|
-
setResolvedCartId(cartId ?? "cart_demo");
|
|
1558
|
-
setIsInitializing(false);
|
|
1559
|
-
setErrorMessage(null);
|
|
1560
|
-
}
|
|
1561
|
-
return;
|
|
1562
|
-
}
|
|
1563
1465
|
const needsBusinessResolve = !businessId;
|
|
1564
1466
|
const needsCartResolve = !cartId;
|
|
1565
1467
|
if (!needsBusinessResolve && !needsCartResolve) {
|
|
@@ -1627,11 +1529,10 @@ function CimplifyCheckout({
|
|
|
1627
1529
|
return () => {
|
|
1628
1530
|
cancelled = true;
|
|
1629
1531
|
};
|
|
1630
|
-
}, [businessId, cartId, client
|
|
1532
|
+
}, [businessId, cartId, client]);
|
|
1631
1533
|
React10.useEffect(() => {
|
|
1632
1534
|
return () => {
|
|
1633
1535
|
isMountedRef.current = false;
|
|
1634
|
-
demoRunRef.current += 1;
|
|
1635
1536
|
activeCheckoutRef.current?.abort();
|
|
1636
1537
|
activeCheckoutRef.current = null;
|
|
1637
1538
|
};
|
|
@@ -1648,42 +1549,6 @@ function CimplifyCheckout({
|
|
|
1648
1549
|
setErrorMessage(null);
|
|
1649
1550
|
setIsSubmitting(true);
|
|
1650
1551
|
emitStatus("preparing", { display_text: statusToLabel("preparing") });
|
|
1651
|
-
if (isDemoCheckout) {
|
|
1652
|
-
const runId = demoRunRef.current + 1;
|
|
1653
|
-
demoRunRef.current = runId;
|
|
1654
|
-
const wait = async (ms) => {
|
|
1655
|
-
await new Promise((resolve) => setTimeout(resolve, ms));
|
|
1656
|
-
return isMountedRef.current && runId === demoRunRef.current;
|
|
1657
|
-
};
|
|
1658
|
-
try {
|
|
1659
|
-
if (!await wait(400)) return;
|
|
1660
|
-
emitStatus("processing", { display_text: statusToLabel("processing") });
|
|
1661
|
-
if (!await wait(900)) return;
|
|
1662
|
-
emitStatus("polling", { display_text: statusToLabel("polling") });
|
|
1663
|
-
if (!await wait(1200)) return;
|
|
1664
|
-
const result = {
|
|
1665
|
-
success: true,
|
|
1666
|
-
order: {
|
|
1667
|
-
id: `ord_demo_${Date.now()}`,
|
|
1668
|
-
order_number: `DEMO-${Math.random().toString(36).slice(2, 8).toUpperCase()}`,
|
|
1669
|
-
status: "confirmed",
|
|
1670
|
-
total: "0.00",
|
|
1671
|
-
currency: "USD"
|
|
1672
|
-
}
|
|
1673
|
-
};
|
|
1674
|
-
emitStatus("success", {
|
|
1675
|
-
order_id: result.order?.id,
|
|
1676
|
-
order_number: result.order?.order_number,
|
|
1677
|
-
display_text: statusToLabel("success")
|
|
1678
|
-
});
|
|
1679
|
-
onComplete(result);
|
|
1680
|
-
} finally {
|
|
1681
|
-
if (isMountedRef.current && runId === demoRunRef.current) {
|
|
1682
|
-
setIsSubmitting(false);
|
|
1683
|
-
}
|
|
1684
|
-
}
|
|
1685
|
-
return;
|
|
1686
|
-
}
|
|
1687
1552
|
if (!elementsRef.current) {
|
|
1688
1553
|
const message = "Checkout is still initializing. Please try again.";
|
|
1689
1554
|
setErrorMessage(message);
|
|
@@ -1718,7 +1583,7 @@ function CimplifyCheckout({
|
|
|
1718
1583
|
}
|
|
1719
1584
|
});
|
|
1720
1585
|
React10.useEffect(() => {
|
|
1721
|
-
if (
|
|
1586
|
+
if (!resolvedBusinessId) {
|
|
1722
1587
|
elementsRef.current = null;
|
|
1723
1588
|
return;
|
|
1724
1589
|
}
|
|
@@ -1759,7 +1624,6 @@ function CimplifyCheckout({
|
|
|
1759
1624
|
}, [
|
|
1760
1625
|
client,
|
|
1761
1626
|
resolvedBusinessId,
|
|
1762
|
-
isDemoCheckout,
|
|
1763
1627
|
resolvedOrderTypes,
|
|
1764
1628
|
resolvedDefaultOrderType,
|
|
1765
1629
|
submitLabel
|
|
@@ -1775,11 +1639,11 @@ function CimplifyCheckout({
|
|
|
1775
1639
|
if (isInitializing) {
|
|
1776
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..." }) });
|
|
1777
1641
|
}
|
|
1778
|
-
if (!
|
|
1642
|
+
if (!resolvedBusinessId || !resolvedCartId) {
|
|
1779
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." }) });
|
|
1780
1644
|
}
|
|
1781
1645
|
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className, "data-cimplify-checkout": "", children: [
|
|
1782
|
-
isTestMode &&
|
|
1646
|
+
isTestMode && /* @__PURE__ */ jsxRuntime.jsx(
|
|
1783
1647
|
"p",
|
|
1784
1648
|
{
|
|
1785
1649
|
"data-cimplify-test-mode": "",
|
|
@@ -1792,7 +1656,7 @@ function CimplifyCheckout({
|
|
|
1792
1656
|
children: "Test mode - no real charges"
|
|
1793
1657
|
}
|
|
1794
1658
|
),
|
|
1795
|
-
/* @__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 }) }),
|
|
1796
1660
|
status && /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-status": "", style: { marginTop: SPACE.sm, fontSize: 13, color: colors.textSecondary }, children: statusText || statusToLabel(status) }),
|
|
1797
1661
|
errorMessage && /* @__PURE__ */ jsxRuntime.jsx("p", { "data-cimplify-error": "", style: { marginTop: SPACE.sm, fontSize: 13, color: colors.error }, children: errorMessage })
|
|
1798
1662
|
] });
|
|
@@ -3659,19 +3523,19 @@ function AuthElement({
|
|
|
3659
3523
|
}, [onReady, onAuthenticated, onRequiresOtp, onError]);
|
|
3660
3524
|
React10.useEffect(() => {
|
|
3661
3525
|
if (!elements || !containerRef.current) return;
|
|
3662
|
-
const element = elements.create(
|
|
3526
|
+
const element = elements.create(chunkDR4UPU6P_js.ELEMENT_TYPES.AUTH, { prefillEmail });
|
|
3663
3527
|
elementRef.current = element;
|
|
3664
|
-
element.on(
|
|
3528
|
+
element.on(chunkDR4UPU6P_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
|
|
3665
3529
|
element.on(
|
|
3666
|
-
|
|
3530
|
+
chunkDR4UPU6P_js.EVENT_TYPES.AUTHENTICATED,
|
|
3667
3531
|
(data) => onAuthenticatedRef.current?.(data)
|
|
3668
3532
|
);
|
|
3669
3533
|
element.on(
|
|
3670
|
-
|
|
3534
|
+
chunkDR4UPU6P_js.EVENT_TYPES.REQUIRES_OTP,
|
|
3671
3535
|
(data) => onRequiresOtpRef.current?.(data)
|
|
3672
3536
|
);
|
|
3673
3537
|
element.on(
|
|
3674
|
-
|
|
3538
|
+
chunkDR4UPU6P_js.EVENT_TYPES.ERROR,
|
|
3675
3539
|
(data) => onErrorRef.current?.(data)
|
|
3676
3540
|
);
|
|
3677
3541
|
element.mount(containerRef.current);
|
|
@@ -3700,15 +3564,15 @@ function AddressElement({
|
|
|
3700
3564
|
}, [onReady, onChange, onError]);
|
|
3701
3565
|
React10.useEffect(() => {
|
|
3702
3566
|
if (!elements || !containerRef.current) return;
|
|
3703
|
-
const element = elements.create(
|
|
3567
|
+
const element = elements.create(chunkDR4UPU6P_js.ELEMENT_TYPES.ADDRESS, { mode });
|
|
3704
3568
|
elementRef.current = element;
|
|
3705
|
-
element.on(
|
|
3569
|
+
element.on(chunkDR4UPU6P_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
|
|
3706
3570
|
element.on(
|
|
3707
|
-
|
|
3571
|
+
chunkDR4UPU6P_js.EVENT_TYPES.CHANGE,
|
|
3708
3572
|
(data) => onChangeRef.current?.(data)
|
|
3709
3573
|
);
|
|
3710
3574
|
element.on(
|
|
3711
|
-
|
|
3575
|
+
chunkDR4UPU6P_js.EVENT_TYPES.ERROR,
|
|
3712
3576
|
(data) => onErrorRef.current?.(data)
|
|
3713
3577
|
);
|
|
3714
3578
|
element.mount(containerRef.current);
|
|
@@ -3738,15 +3602,15 @@ function PaymentElement({
|
|
|
3738
3602
|
}, [onReady, onChange, onError]);
|
|
3739
3603
|
React10.useEffect(() => {
|
|
3740
3604
|
if (!elements || !containerRef.current) return;
|
|
3741
|
-
const element = elements.create(
|
|
3605
|
+
const element = elements.create(chunkDR4UPU6P_js.ELEMENT_TYPES.PAYMENT, { amount, currency });
|
|
3742
3606
|
elementRef.current = element;
|
|
3743
|
-
element.on(
|
|
3607
|
+
element.on(chunkDR4UPU6P_js.EVENT_TYPES.READY, () => onReadyRef.current?.());
|
|
3744
3608
|
element.on(
|
|
3745
|
-
|
|
3609
|
+
chunkDR4UPU6P_js.EVENT_TYPES.CHANGE,
|
|
3746
3610
|
(data) => onChangeRef.current?.(data)
|
|
3747
3611
|
);
|
|
3748
3612
|
element.on(
|
|
3749
|
-
|
|
3613
|
+
chunkDR4UPU6P_js.EVENT_TYPES.ERROR,
|
|
3750
3614
|
(data) => onErrorRef.current?.(data)
|
|
3751
3615
|
);
|
|
3752
3616
|
element.mount(containerRef.current);
|