@cimplify/sdk 0.46.0 → 0.46.1
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 +22 -22
- package/dist/advanced.mjs +3 -3
- package/dist/{chunk-XPXAZXF2.mjs → chunk-3HXYEK5K.mjs} +2 -2
- package/dist/{chunk-K6FCVLZA.js → chunk-4KNCSWE4.js} +234 -234
- package/dist/{chunk-RQ3ILHUQ.mjs → chunk-5LZNTG4V.mjs} +1 -1
- package/dist/{chunk-GVLWRI5I.js → chunk-6V67MAWO.js} +49 -25
- package/dist/{chunk-RR3ZJQW5.mjs → chunk-7H2DYO4T.mjs} +4 -4
- package/dist/{chunk-NRT6PVW5.mjs → chunk-7RRVM2X2.mjs} +1 -1
- package/dist/{chunk-IF22UYTT.mjs → chunk-AUS4B7PA.mjs} +2 -2
- package/dist/{chunk-QBQCMQ4F.js → chunk-DETRNWHF.js} +2 -2
- package/dist/{chunk-LLZZMHSU.js → chunk-HNPVZGTO.js} +62 -62
- package/dist/{chunk-ZH6ZST5T.js → chunk-NKZ5YN5D.js} +4 -4
- package/dist/{chunk-AIXUFSA6.mjs → chunk-UJ5BBLKL.mjs} +29 -5
- package/dist/{chunk-BN2CXGMO.js → chunk-Z3CHDA24.js} +3 -3
- package/dist/{client-aZInadOY.d.ts → client-B9r5rH3O.d.ts} +3 -0
- package/dist/{client-MUD63aYS.d.mts → client-BScRT1Rz.d.mts} +1 -1
- package/dist/{client-BDYBB-ME.d.ts → client-D7nI2XmP.d.ts} +1 -1
- package/dist/{client-CDUY-6nC.d.mts → client-DyrpQRza.d.mts} +3 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +107 -107
- package/dist/index.mjs +4 -4
- package/dist/react.d.mts +1 -1
- package/dist/react.d.ts +1 -1
- package/dist/react.js +85 -85
- package/dist/react.mjs +4 -4
- package/dist/server.d.mts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +6 -6
- package/dist/server.mjs +4 -4
- package/dist/testing/msw.js +3 -3
- package/dist/testing/msw.mjs +2 -2
- package/dist/testing/suite.d.mts +2 -2
- package/dist/testing/suite.d.ts +2 -2
- package/dist/testing/suite.js +25 -25
- package/dist/testing/suite.mjs +6 -6
- package/dist/testing.d.mts +2 -2
- package/dist/testing.d.ts +2 -2
- package/dist/testing.js +81 -81
- package/dist/testing.mjs +7 -7
- package/dist/utils.js +29 -29
- package/dist/utils.mjs +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { __publicField, __privateAdd, __privateSet, __privateGet, __privateMethod, ErrorCode, __privateWrapper } from './chunk-
|
|
1
|
+
import { __publicField, __privateAdd, __privateSet, __privateGet, __privateMethod, ErrorCode, __privateWrapper } from './chunk-3HXYEK5K.mjs';
|
|
2
2
|
|
|
3
3
|
// ../node_modules/.bun/hono@4.12.16/node_modules/hono/dist/compose.js
|
|
4
4
|
var compose = (middleware, onError, onNotFound) => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunkZ3CHDA24_js = require('./chunk-Z3CHDA24.js');
|
|
4
|
+
var chunkDETRNWHF_js = require('./chunk-DETRNWHF.js');
|
|
5
5
|
|
|
6
6
|
// src/types/result.ts
|
|
7
7
|
function ok(value) {
|
|
@@ -85,11 +85,11 @@ function generateIdempotencyKey(prefix = "idem") {
|
|
|
85
85
|
|
|
86
86
|
// src/internal/safe.ts
|
|
87
87
|
function toCimplifyError(error) {
|
|
88
|
-
if (error instanceof
|
|
88
|
+
if (error instanceof chunkDETRNWHF_js.CimplifyError) return chunkDETRNWHF_js.enrichError(error);
|
|
89
89
|
if (error instanceof Error) {
|
|
90
|
-
return
|
|
90
|
+
return chunkDETRNWHF_js.enrichError(new chunkDETRNWHF_js.CimplifyError(chunkDETRNWHF_js.ErrorCode.UNKNOWN_ERROR, error.message, false));
|
|
91
91
|
}
|
|
92
|
-
return
|
|
92
|
+
return chunkDETRNWHF_js.enrichError(new chunkDETRNWHF_js.CimplifyError(chunkDETRNWHF_js.ErrorCode.UNKNOWN_ERROR, String(error), false));
|
|
93
93
|
}
|
|
94
94
|
async function safe(promise) {
|
|
95
95
|
try {
|
|
@@ -648,7 +648,7 @@ var CartOperations = class {
|
|
|
648
648
|
if (typeof updates.quantity !== "number") {
|
|
649
649
|
return {
|
|
650
650
|
ok: false,
|
|
651
|
-
error: new
|
|
651
|
+
error: new chunkDETRNWHF_js.CimplifyError(
|
|
652
652
|
"VALIDATION_ERROR",
|
|
653
653
|
"updateItem requires a quantity; richer mid-cart edits are not supported"
|
|
654
654
|
)
|
|
@@ -1093,7 +1093,7 @@ var CheckoutResolver = class {
|
|
|
1093
1093
|
}
|
|
1094
1094
|
}
|
|
1095
1095
|
}
|
|
1096
|
-
if (checkoutResult.requires_authorization ||
|
|
1096
|
+
if (checkoutResult.requires_authorization || chunkZ3CHDA24_js.isPaymentStatusRequiresAction(checkoutResult.payment_status)) {
|
|
1097
1097
|
const authorization = await this.handleAuthorization({
|
|
1098
1098
|
authorizationType,
|
|
1099
1099
|
paymentReference,
|
|
@@ -1267,18 +1267,18 @@ var CheckoutResolver = class {
|
|
|
1267
1267
|
if (statusResult.value.reference) {
|
|
1268
1268
|
paymentReference = statusResult.value.reference;
|
|
1269
1269
|
}
|
|
1270
|
-
const normalized =
|
|
1271
|
-
if (normalized.paid ||
|
|
1270
|
+
const normalized = chunkZ3CHDA24_js.normalizeStatusResponse(statusResult.value);
|
|
1271
|
+
if (normalized.paid || chunkZ3CHDA24_js.isPaymentStatusSuccess(normalized.status)) {
|
|
1272
1272
|
return this.finalizeSuccess(latestCheckoutResult);
|
|
1273
1273
|
}
|
|
1274
|
-
if (
|
|
1274
|
+
if (chunkZ3CHDA24_js.isPaymentStatusFailure(normalized.status)) {
|
|
1275
1275
|
return this.fail(
|
|
1276
1276
|
normalized.status ? normalized.status.toUpperCase() : "PAYMENT_FAILED",
|
|
1277
1277
|
normalized.message || "Payment failed during confirmation.",
|
|
1278
1278
|
false
|
|
1279
1279
|
);
|
|
1280
1280
|
}
|
|
1281
|
-
if (
|
|
1281
|
+
if (chunkZ3CHDA24_js.isPaymentStatusRequiresAction(normalized.status)) {
|
|
1282
1282
|
const authorization = await this.handleAuthorization({
|
|
1283
1283
|
authorizationType,
|
|
1284
1284
|
paymentReference,
|
|
@@ -1309,8 +1309,8 @@ var CheckoutResolver = class {
|
|
|
1309
1309
|
try {
|
|
1310
1310
|
const finalResult = await this.client.checkout.pollPaymentStatus(input.orderId);
|
|
1311
1311
|
if (finalResult.ok) {
|
|
1312
|
-
const normalized =
|
|
1313
|
-
if (normalized.paid ||
|
|
1312
|
+
const normalized = chunkZ3CHDA24_js.normalizeStatusResponse(finalResult.value);
|
|
1313
|
+
if (normalized.paid || chunkZ3CHDA24_js.isPaymentStatusSuccess(normalized.status)) {
|
|
1314
1314
|
return this.finalizeSuccess(latestCheckoutResult);
|
|
1315
1315
|
}
|
|
1316
1316
|
}
|
|
@@ -1506,12 +1506,12 @@ var CheckoutResolver = class {
|
|
|
1506
1506
|
};
|
|
1507
1507
|
}
|
|
1508
1508
|
isSuccessfulStatus(status) {
|
|
1509
|
-
const normalized =
|
|
1510
|
-
return normalized.paid ||
|
|
1509
|
+
const normalized = chunkZ3CHDA24_js.normalizeStatusResponse({ status, paid: false });
|
|
1510
|
+
return normalized.paid || chunkZ3CHDA24_js.isPaymentStatusSuccess(normalized.status);
|
|
1511
1511
|
}
|
|
1512
1512
|
isFailureStatus(status) {
|
|
1513
|
-
const normalized =
|
|
1514
|
-
return
|
|
1513
|
+
const normalized = chunkZ3CHDA24_js.normalizeStatusResponse({ status, paid: false });
|
|
1514
|
+
return chunkZ3CHDA24_js.isPaymentStatusFailure(normalized.status);
|
|
1515
1515
|
}
|
|
1516
1516
|
ensureNotAborted() {
|
|
1517
1517
|
if (this.signal?.aborted) {
|
|
@@ -1570,7 +1570,7 @@ var CheckoutService = class {
|
|
|
1570
1570
|
}
|
|
1571
1571
|
async initializePayment(_orderId, _method) {
|
|
1572
1572
|
return err(
|
|
1573
|
-
new
|
|
1573
|
+
new chunkDETRNWHF_js.CimplifyError(
|
|
1574
1574
|
"NOT_IMPLEMENTED",
|
|
1575
1575
|
"initializePayment is not available in REST mode.",
|
|
1576
1576
|
false
|
|
@@ -1642,11 +1642,11 @@ var CheckoutService = class {
|
|
|
1642
1642
|
pay_currency: data.pay_currency,
|
|
1643
1643
|
fx_quote_id: data.fx_quote_id
|
|
1644
1644
|
};
|
|
1645
|
-
const baseCurrency =
|
|
1645
|
+
const baseCurrency = chunkDETRNWHF_js.currencyCode(
|
|
1646
1646
|
(cart.pricing.currency || checkoutData.pay_currency || "GHS").toUpperCase()
|
|
1647
1647
|
);
|
|
1648
1648
|
const payCurrency = data.pay_currency?.trim().toUpperCase();
|
|
1649
|
-
const payCurrencyCode = payCurrency ?
|
|
1649
|
+
const payCurrencyCode = payCurrency ? chunkDETRNWHF_js.currencyCode(payCurrency) : void 0;
|
|
1650
1650
|
const cartTotalAmount = typeof cart.pricing.total_price === "number" ? cart.pricing.total_price : Number.parseFloat(cart.pricing.total_price || "0");
|
|
1651
1651
|
if (payCurrencyCode && payCurrencyCode !== baseCurrency && !checkoutData.fx_quote_id && Number.isFinite(cartTotalAmount) && cartTotalAmount > 0) {
|
|
1652
1652
|
const fxQuoteResult = await this.client.fx.lockQuote({
|
|
@@ -1979,7 +1979,7 @@ var BusinessService = class {
|
|
|
1979
1979
|
if (!result.ok) return err(result.error);
|
|
1980
1980
|
const location = result.value.find((item) => item.id === locationId);
|
|
1981
1981
|
if (!location) {
|
|
1982
|
-
return err(new
|
|
1982
|
+
return err(new chunkDETRNWHF_js.CimplifyError(chunkDETRNWHF_js.ErrorCode.NOT_FOUND, `Location not found: ${locationId}`, false));
|
|
1983
1983
|
}
|
|
1984
1984
|
return ok(location);
|
|
1985
1985
|
}
|
|
@@ -2266,7 +2266,7 @@ var EVENT_TYPES = {
|
|
|
2266
2266
|
|
|
2267
2267
|
// src/elements.ts
|
|
2268
2268
|
function toCheckoutError(code, message, recoverable) {
|
|
2269
|
-
const hint =
|
|
2269
|
+
const hint = chunkDETRNWHF_js.getErrorHint(code);
|
|
2270
2270
|
return {
|
|
2271
2271
|
success: false,
|
|
2272
2272
|
error: {
|
|
@@ -2732,6 +2732,8 @@ var CimplifyElement = class {
|
|
|
2732
2732
|
this.iframe = null;
|
|
2733
2733
|
this.container = null;
|
|
2734
2734
|
this.mounted = false;
|
|
2735
|
+
this.ready = false;
|
|
2736
|
+
this.pendingMessages = [];
|
|
2735
2737
|
this.pendingInit = null;
|
|
2736
2738
|
this.eventHandlers = /* @__PURE__ */ new Map();
|
|
2737
2739
|
this.resolvers = /* @__PURE__ */ new Map();
|
|
@@ -2773,6 +2775,8 @@ var CimplifyElement = class {
|
|
|
2773
2775
|
}
|
|
2774
2776
|
this.container = null;
|
|
2775
2777
|
this.mounted = false;
|
|
2778
|
+
this.ready = false;
|
|
2779
|
+
this.pendingMessages = [];
|
|
2776
2780
|
this.eventHandlers.clear();
|
|
2777
2781
|
this.resolvers.forEach((entry) => clearTimeout(entry.timeoutId));
|
|
2778
2782
|
this.resolvers.clear();
|
|
@@ -2813,10 +2817,28 @@ var CimplifyElement = class {
|
|
|
2813
2817
|
this.sendMessage({ type: MESSAGE_TYPES.SET_CART, cart });
|
|
2814
2818
|
}
|
|
2815
2819
|
sendMessage(message) {
|
|
2816
|
-
|
|
2820
|
+
const iframe = this.iframe;
|
|
2821
|
+
if (!iframe || !iframe.isConnected) {
|
|
2822
|
+
if (iframe && !iframe.isConnected) {
|
|
2823
|
+
console.warn(
|
|
2824
|
+
"[cimplify:checkout] sendMessage DROPPED \u2014 iframe detached",
|
|
2825
|
+
{ type: message.type }
|
|
2826
|
+
);
|
|
2827
|
+
}
|
|
2828
|
+
return;
|
|
2829
|
+
}
|
|
2830
|
+
if (!this.ready || !iframe.contentWindow) {
|
|
2831
|
+
this.pendingMessages.push(message);
|
|
2832
|
+
return;
|
|
2833
|
+
}
|
|
2834
|
+
iframe.contentWindow.postMessage(message, this.linkUrl);
|
|
2835
|
+
}
|
|
2836
|
+
flushPending() {
|
|
2837
|
+
if (!this.ready || !this.iframe?.contentWindow) return;
|
|
2838
|
+
const queue = this.pendingMessages;
|
|
2839
|
+
this.pendingMessages = [];
|
|
2840
|
+
for (const message of queue) {
|
|
2817
2841
|
this.iframe.contentWindow.postMessage(message, this.linkUrl);
|
|
2818
|
-
} else {
|
|
2819
|
-
console.warn("[cimplify:checkout] sendMessage DROPPED \u2014 no contentWindow", { type: message.type, hasIframe: !!this.iframe, isConnected: this.iframe?.isConnected });
|
|
2820
2842
|
}
|
|
2821
2843
|
}
|
|
2822
2844
|
getContentWindow() {
|
|
@@ -2881,6 +2903,7 @@ var CimplifyElement = class {
|
|
|
2881
2903
|
if (!message) return;
|
|
2882
2904
|
switch (message.type) {
|
|
2883
2905
|
case MESSAGE_TYPES.READY:
|
|
2906
|
+
this.ready = true;
|
|
2884
2907
|
if (this.iframe && message.height) this.iframe.style.height = `${message.height}px`;
|
|
2885
2908
|
if (this.pendingInit) {
|
|
2886
2909
|
const { publicKey } = this.pendingInit;
|
|
@@ -2902,6 +2925,7 @@ var CimplifyElement = class {
|
|
|
2902
2925
|
}
|
|
2903
2926
|
this.pendingInit = null;
|
|
2904
2927
|
}
|
|
2928
|
+
this.flushPending();
|
|
2905
2929
|
this.emit(EVENT_TYPES.READY, { height: message.height });
|
|
2906
2930
|
break;
|
|
2907
2931
|
case MESSAGE_TYPES.HEIGHT_CHANGE:
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-
|
|
2
|
-
import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-
|
|
1
|
+
import { safe, generateIdempotencyKey, CatalogueQueries, CartOperations, CheckoutService, OrderQueries, LinkService, AuthService, BusinessService, InventoryService, SchedulingService, LiteService, FxService, createElements } from './chunk-UJ5BBLKL.mjs';
|
|
2
|
+
import { CimplifyError, ErrorCode, IdempotencyMismatchError, enrichError } from './chunk-3HXYEK5K.mjs';
|
|
3
3
|
|
|
4
4
|
// src/activity.ts
|
|
5
5
|
var ActivityService = class {
|
|
@@ -396,7 +396,7 @@ var CimplifyClient = class {
|
|
|
396
396
|
this.sessionToken = this.loadSessionToken();
|
|
397
397
|
if (!this.publicKey && !config.suppressPublicKeyWarning) {
|
|
398
398
|
console.warn(
|
|
399
|
-
'[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "
|
|
399
|
+
'[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "cpk_..." } to createCimplifyClient().'
|
|
400
400
|
);
|
|
401
401
|
}
|
|
402
402
|
}
|
|
@@ -414,7 +414,7 @@ var CimplifyClient = class {
|
|
|
414
414
|
return this.publicKey;
|
|
415
415
|
}
|
|
416
416
|
isTestMode() {
|
|
417
|
-
return this.publicKey.trim().startsWith("
|
|
417
|
+
return this.publicKey.trim().startsWith("cpk_test_");
|
|
418
418
|
}
|
|
419
419
|
setAccessToken(token) {
|
|
420
420
|
const previous = this.accessToken;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { createCimplifyClient } from './chunk-
|
|
2
|
-
import { createMockApp } from './chunk-
|
|
1
|
+
import { createCimplifyClient } from './chunk-7H2DYO4T.mjs';
|
|
2
|
+
import { createMockApp } from './chunk-5LZNTG4V.mjs';
|
|
3
3
|
import { z } from 'zod';
|
|
4
4
|
|
|
5
5
|
var cimplifyRegistry = z.registry();
|
|
@@ -229,10 +229,10 @@ function enrichError(error, options = {}) {
|
|
|
229
229
|
const docsUrl = error.docs_url || hint?.docs_url || docsUrlForCode(error.code || ErrorCode.UNKNOWN_ERROR);
|
|
230
230
|
const suggestion = error.suggestion || hint?.suggestion;
|
|
231
231
|
let message = error.message;
|
|
232
|
-
if (options.isTestMode && !message.includes("
|
|
232
|
+
if (options.isTestMode && !message.includes("cpk_test_")) {
|
|
233
233
|
message = `${message}
|
|
234
234
|
|
|
235
|
-
\u2139 Your API key is a test-mode key (
|
|
235
|
+
\u2139 Your API key is a test-mode key (cpk_test_...). Verify test data/session before retrying.`;
|
|
236
236
|
}
|
|
237
237
|
const enriched = new CimplifyError(error.code, message, error.retryable, docsUrl, suggestion);
|
|
238
238
|
enriched.stack = error.stack;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
4
|
-
var
|
|
3
|
+
var chunk6V67MAWO_js = require('./chunk-6V67MAWO.js');
|
|
4
|
+
var chunkDETRNWHF_js = require('./chunk-DETRNWHF.js');
|
|
5
5
|
|
|
6
6
|
// src/activity.ts
|
|
7
7
|
var ActivityService = class {
|
|
@@ -29,7 +29,7 @@ var ActivityService = class {
|
|
|
29
29
|
this.sendEvents([event]);
|
|
30
30
|
}
|
|
31
31
|
async getState() {
|
|
32
|
-
return
|
|
32
|
+
return chunk6V67MAWO_js.safe(this.client.get("/api/v1/activity/state"));
|
|
33
33
|
}
|
|
34
34
|
async getRecommendations(options) {
|
|
35
35
|
const params = new URLSearchParams();
|
|
@@ -37,10 +37,10 @@ var ActivityService = class {
|
|
|
37
37
|
if (options?.limit) params.set("limit", String(options.limit));
|
|
38
38
|
const query = params.toString();
|
|
39
39
|
const path = query ? `/api/v1/activity/recommendations?${query}` : "/api/v1/activity/recommendations";
|
|
40
|
-
return
|
|
40
|
+
return chunk6V67MAWO_js.safe(this.client.get(path));
|
|
41
41
|
}
|
|
42
42
|
async dismissMessage(code) {
|
|
43
|
-
return
|
|
43
|
+
return chunk6V67MAWO_js.safe(
|
|
44
44
|
this.client.post("/api/v1/activity/messages/dismiss", { code })
|
|
45
45
|
);
|
|
46
46
|
}
|
|
@@ -62,16 +62,16 @@ var SubscriptionService = class {
|
|
|
62
62
|
this.client = client;
|
|
63
63
|
}
|
|
64
64
|
async list() {
|
|
65
|
-
return
|
|
65
|
+
return chunk6V67MAWO_js.safe(this.client.get("/api/v1/subscriptions"));
|
|
66
66
|
}
|
|
67
67
|
async get(id) {
|
|
68
68
|
const encodedId = encodeURIComponent(id);
|
|
69
|
-
return
|
|
69
|
+
return chunk6V67MAWO_js.safe(this.client.get(`/api/v1/subscriptions/${encodedId}`));
|
|
70
70
|
}
|
|
71
71
|
async cancel(id, reason, opts) {
|
|
72
72
|
const encodedId = encodeURIComponent(id);
|
|
73
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
74
|
-
return
|
|
73
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunk6V67MAWO_js.generateIdempotencyKey();
|
|
74
|
+
return chunk6V67MAWO_js.safe(
|
|
75
75
|
this.client.post(
|
|
76
76
|
`/api/v1/subscriptions/${encodedId}/cancel`,
|
|
77
77
|
{ reason },
|
|
@@ -81,20 +81,20 @@ var SubscriptionService = class {
|
|
|
81
81
|
}
|
|
82
82
|
async pause(id) {
|
|
83
83
|
const encodedId = encodeURIComponent(id);
|
|
84
|
-
return
|
|
84
|
+
return chunk6V67MAWO_js.safe(
|
|
85
85
|
this.client.post(`/api/v1/subscriptions/${encodedId}/pause`)
|
|
86
86
|
);
|
|
87
87
|
}
|
|
88
88
|
async resume(id) {
|
|
89
89
|
const encodedId = encodeURIComponent(id);
|
|
90
|
-
return
|
|
90
|
+
return chunk6V67MAWO_js.safe(
|
|
91
91
|
this.client.post(`/api/v1/subscriptions/${encodedId}/resume`)
|
|
92
92
|
);
|
|
93
93
|
}
|
|
94
94
|
async skipNextRenewal(id, opts) {
|
|
95
95
|
const encodedId = encodeURIComponent(id);
|
|
96
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
97
|
-
return
|
|
96
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunk6V67MAWO_js.generateIdempotencyKey();
|
|
97
|
+
return chunk6V67MAWO_js.safe(
|
|
98
98
|
this.client.post(
|
|
99
99
|
`/api/v1/subscriptions/${encodedId}/skip`,
|
|
100
100
|
void 0,
|
|
@@ -110,8 +110,8 @@ var UploadService = class {
|
|
|
110
110
|
this.client = client;
|
|
111
111
|
}
|
|
112
112
|
async init(filename, contentType, sizeBytes, opts) {
|
|
113
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
114
|
-
return
|
|
113
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunk6V67MAWO_js.generateIdempotencyKey();
|
|
114
|
+
return chunk6V67MAWO_js.safe(
|
|
115
115
|
this.client.post(
|
|
116
116
|
"/api/v1/uploads/init",
|
|
117
117
|
{
|
|
@@ -124,7 +124,7 @@ var UploadService = class {
|
|
|
124
124
|
);
|
|
125
125
|
}
|
|
126
126
|
async confirm(uploadId) {
|
|
127
|
-
return
|
|
127
|
+
return chunk6V67MAWO_js.safe(
|
|
128
128
|
this.client.post("/api/v1/uploads/confirm", {
|
|
129
129
|
upload_id: uploadId
|
|
130
130
|
})
|
|
@@ -143,7 +143,7 @@ var UploadService = class {
|
|
|
143
143
|
if (!uploadResponse.ok) {
|
|
144
144
|
return {
|
|
145
145
|
ok: false,
|
|
146
|
-
error: new
|
|
146
|
+
error: new chunkDETRNWHF_js.CimplifyError(
|
|
147
147
|
"UPLOAD_FAILED",
|
|
148
148
|
`Upload failed with status ${uploadResponse.status}`,
|
|
149
149
|
true
|
|
@@ -153,7 +153,7 @@ var UploadService = class {
|
|
|
153
153
|
} catch (error) {
|
|
154
154
|
return {
|
|
155
155
|
ok: false,
|
|
156
|
-
error: new
|
|
156
|
+
error: new chunkDETRNWHF_js.CimplifyError(
|
|
157
157
|
"UPLOAD_FAILED",
|
|
158
158
|
error instanceof Error ? error.message : "Upload failed",
|
|
159
159
|
true
|
|
@@ -170,7 +170,7 @@ var PlacesService = class {
|
|
|
170
170
|
this.client = client;
|
|
171
171
|
}
|
|
172
172
|
async autocomplete(input, sessionToken) {
|
|
173
|
-
return
|
|
173
|
+
return chunk6V67MAWO_js.safe(
|
|
174
174
|
this.client.post("/api/v1/places/autocomplete", {
|
|
175
175
|
input,
|
|
176
176
|
sessionToken
|
|
@@ -178,7 +178,7 @@ var PlacesService = class {
|
|
|
178
178
|
);
|
|
179
179
|
}
|
|
180
180
|
async details(placeId, sessionToken) {
|
|
181
|
-
return
|
|
181
|
+
return chunk6V67MAWO_js.safe(
|
|
182
182
|
this.client.post("/api/v1/places/details", {
|
|
183
183
|
place_id: placeId,
|
|
184
184
|
sessionToken
|
|
@@ -197,7 +197,7 @@ var DeliveryService = class {
|
|
|
197
197
|
params.set("dropoff_lat", String(dropoffLat));
|
|
198
198
|
params.set("dropoff_lng", String(dropoffLng));
|
|
199
199
|
if (country) params.set("country", country);
|
|
200
|
-
return
|
|
200
|
+
return chunk6V67MAWO_js.safe(
|
|
201
201
|
this.client.get(`/api/v1/delivery/fee?${params.toString()}`)
|
|
202
202
|
);
|
|
203
203
|
}
|
|
@@ -210,8 +210,8 @@ var SupportService = class {
|
|
|
210
210
|
}
|
|
211
211
|
/** Open (or resume) the customer's widget conversation. */
|
|
212
212
|
async openConversation(opts) {
|
|
213
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
214
|
-
return
|
|
213
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunk6V67MAWO_js.generateIdempotencyKey();
|
|
214
|
+
return chunk6V67MAWO_js.safe(
|
|
215
215
|
this.client.post("/api/v1/support/conversation", void 0, {
|
|
216
216
|
idempotencyKey
|
|
217
217
|
})
|
|
@@ -219,8 +219,8 @@ var SupportService = class {
|
|
|
219
219
|
}
|
|
220
220
|
/** Send a message in the active conversation. */
|
|
221
221
|
async sendMessage(content, opts) {
|
|
222
|
-
const idempotencyKey = opts?.idempotencyKey ??
|
|
223
|
-
return
|
|
222
|
+
const idempotencyKey = opts?.idempotencyKey ?? chunk6V67MAWO_js.generateIdempotencyKey();
|
|
223
|
+
return chunk6V67MAWO_js.safe(
|
|
224
224
|
this.client.post(
|
|
225
225
|
"/api/v1/support/conversation/messages",
|
|
226
226
|
{ content },
|
|
@@ -235,7 +235,7 @@ var SupportService = class {
|
|
|
235
235
|
if (options.limit) params.set("limit", String(options.limit));
|
|
236
236
|
const query = params.toString();
|
|
237
237
|
const path = query ? `/api/v1/support/conversation/messages?${query}` : "/api/v1/support/conversation/messages";
|
|
238
|
-
return
|
|
238
|
+
return chunk6V67MAWO_js.safe(this.client.get(path));
|
|
239
239
|
}
|
|
240
240
|
};
|
|
241
241
|
|
|
@@ -304,16 +304,16 @@ function isRetryable(error) {
|
|
|
304
304
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
305
305
|
return true;
|
|
306
306
|
}
|
|
307
|
-
if (error instanceof
|
|
307
|
+
if (error instanceof chunkDETRNWHF_js.CimplifyError) {
|
|
308
308
|
return error.retryable;
|
|
309
309
|
}
|
|
310
310
|
return false;
|
|
311
311
|
}
|
|
312
312
|
function toNetworkError(error, isTestMode) {
|
|
313
313
|
if (error instanceof DOMException && error.name === "AbortError") {
|
|
314
|
-
return
|
|
315
|
-
new
|
|
316
|
-
|
|
314
|
+
return chunkDETRNWHF_js.enrichError(
|
|
315
|
+
new chunkDETRNWHF_js.CimplifyError(
|
|
316
|
+
chunkDETRNWHF_js.ErrorCode.TIMEOUT,
|
|
317
317
|
"Request timed out. Please check your connection and try again.",
|
|
318
318
|
true
|
|
319
319
|
),
|
|
@@ -321,21 +321,21 @@ function toNetworkError(error, isTestMode) {
|
|
|
321
321
|
);
|
|
322
322
|
}
|
|
323
323
|
if (error instanceof TypeError && error.message.includes("fetch")) {
|
|
324
|
-
return
|
|
325
|
-
new
|
|
326
|
-
|
|
324
|
+
return chunkDETRNWHF_js.enrichError(
|
|
325
|
+
new chunkDETRNWHF_js.CimplifyError(
|
|
326
|
+
chunkDETRNWHF_js.ErrorCode.NETWORK_ERROR,
|
|
327
327
|
"Network error. Please check your internet connection.",
|
|
328
328
|
true
|
|
329
329
|
),
|
|
330
330
|
{ isTestMode }
|
|
331
331
|
);
|
|
332
332
|
}
|
|
333
|
-
if (error instanceof
|
|
334
|
-
return
|
|
333
|
+
if (error instanceof chunkDETRNWHF_js.CimplifyError) {
|
|
334
|
+
return chunkDETRNWHF_js.enrichError(error, { isTestMode });
|
|
335
335
|
}
|
|
336
|
-
return
|
|
337
|
-
new
|
|
338
|
-
|
|
336
|
+
return chunkDETRNWHF_js.enrichError(
|
|
337
|
+
new chunkDETRNWHF_js.CimplifyError(
|
|
338
|
+
chunkDETRNWHF_js.ErrorCode.UNKNOWN_ERROR,
|
|
339
339
|
error instanceof Error ? error.message : "An unknown error occurred",
|
|
340
340
|
false
|
|
341
341
|
),
|
|
@@ -398,7 +398,7 @@ var CimplifyClient = class {
|
|
|
398
398
|
this.sessionToken = this.loadSessionToken();
|
|
399
399
|
if (!this.publicKey && !config.suppressPublicKeyWarning) {
|
|
400
400
|
console.warn(
|
|
401
|
-
'[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "
|
|
401
|
+
'[Cimplify] No public key found. Set NEXT_PUBLIC_CIMPLIFY_PUBLIC_KEY in your environment, or pass { publicKey: "cpk_..." } to createCimplifyClient().'
|
|
402
402
|
);
|
|
403
403
|
}
|
|
404
404
|
}
|
|
@@ -416,7 +416,7 @@ var CimplifyClient = class {
|
|
|
416
416
|
return this.publicKey;
|
|
417
417
|
}
|
|
418
418
|
isTestMode() {
|
|
419
|
-
return this.publicKey.trim().startsWith("
|
|
419
|
+
return this.publicKey.trim().startsWith("cpk_test_");
|
|
420
420
|
}
|
|
421
421
|
setAccessToken(token) {
|
|
422
422
|
const previous = this.accessToken;
|
|
@@ -510,8 +510,8 @@ var CimplifyClient = class {
|
|
|
510
510
|
this.businessIdResolvePromise = (async () => {
|
|
511
511
|
const result = await this.business.getInfo();
|
|
512
512
|
if (!result.ok || !result.value?.id) {
|
|
513
|
-
throw new
|
|
514
|
-
|
|
513
|
+
throw new chunkDETRNWHF_js.CimplifyError(
|
|
514
|
+
chunkDETRNWHF_js.ErrorCode.NOT_FOUND,
|
|
515
515
|
"Unable to resolve business ID from the current public key.",
|
|
516
516
|
true
|
|
517
517
|
);
|
|
@@ -628,7 +628,7 @@ var CimplifyClient = class {
|
|
|
628
628
|
if (response.status >= 400 && response.status < 500) {
|
|
629
629
|
this.hooks.onRequestError?.({
|
|
630
630
|
...context,
|
|
631
|
-
error: new
|
|
631
|
+
error: new chunkDETRNWHF_js.CimplifyError(
|
|
632
632
|
`HTTP_${response.status}`,
|
|
633
633
|
`Request failed with status ${response.status}`,
|
|
634
634
|
false
|
|
@@ -654,7 +654,7 @@ var CimplifyClient = class {
|
|
|
654
654
|
}
|
|
655
655
|
this.hooks.onRequestError?.({
|
|
656
656
|
...context,
|
|
657
|
-
error: new
|
|
657
|
+
error: new chunkDETRNWHF_js.CimplifyError(
|
|
658
658
|
"SERVER_ERROR",
|
|
659
659
|
`Server error ${response.status} after ${retryCount} retries`,
|
|
660
660
|
false
|
|
@@ -787,17 +787,17 @@ var CimplifyClient = class {
|
|
|
787
787
|
const retryable = typeof json.error === "object" && typeof json.error?.retryable === "boolean" ? json.error.retryable : false;
|
|
788
788
|
if (errorCode === "IDEMPOTENCY_MISMATCH") {
|
|
789
789
|
const originalCreatedAt = typeof json.error === "object" && json.error?.original_created_at || "";
|
|
790
|
-
throw new
|
|
790
|
+
throw new chunkDETRNWHF_js.IdempotencyMismatchError(errorMessage, originalCreatedAt);
|
|
791
791
|
}
|
|
792
|
-
const error =
|
|
793
|
-
new
|
|
792
|
+
const error = chunkDETRNWHF_js.enrichError(
|
|
793
|
+
new chunkDETRNWHF_js.CimplifyError(
|
|
794
794
|
errorCode,
|
|
795
795
|
errorMessage,
|
|
796
796
|
retryable
|
|
797
797
|
),
|
|
798
798
|
{ isTestMode: this.isTestMode() }
|
|
799
799
|
);
|
|
800
|
-
if ((response.status === 401 || error.code ===
|
|
800
|
+
if ((response.status === 401 || error.code === chunkDETRNWHF_js.ErrorCode.UNAUTHORIZED) && this.accessToken) {
|
|
801
801
|
console.warn(
|
|
802
802
|
"[Cimplify] Received 401 Unauthorized. Access token may be missing/expired. Refresh authentication and retry the request."
|
|
803
803
|
);
|
|
@@ -805,8 +805,8 @@ var CimplifyClient = class {
|
|
|
805
805
|
throw error;
|
|
806
806
|
}
|
|
807
807
|
if (json?.success === false || json?.error?.code || json?.error?.message) {
|
|
808
|
-
const error =
|
|
809
|
-
new
|
|
808
|
+
const error = chunkDETRNWHF_js.enrichError(
|
|
809
|
+
new chunkDETRNWHF_js.CimplifyError(
|
|
810
810
|
json.error?.code || "API_ERROR",
|
|
811
811
|
json.error?.message || "An error occurred",
|
|
812
812
|
json.error?.retryable || false
|
|
@@ -822,25 +822,25 @@ var CimplifyClient = class {
|
|
|
822
822
|
}
|
|
823
823
|
get catalogue() {
|
|
824
824
|
if (!this._catalogue) {
|
|
825
|
-
this._catalogue = new
|
|
825
|
+
this._catalogue = new chunk6V67MAWO_js.CatalogueQueries(this);
|
|
826
826
|
}
|
|
827
827
|
return this._catalogue;
|
|
828
828
|
}
|
|
829
829
|
get cart() {
|
|
830
830
|
if (!this._cart) {
|
|
831
|
-
this._cart = new
|
|
831
|
+
this._cart = new chunk6V67MAWO_js.CartOperations(this);
|
|
832
832
|
}
|
|
833
833
|
return this._cart;
|
|
834
834
|
}
|
|
835
835
|
get checkout() {
|
|
836
836
|
if (!this._checkout) {
|
|
837
|
-
this._checkout = new
|
|
837
|
+
this._checkout = new chunk6V67MAWO_js.CheckoutService(this);
|
|
838
838
|
}
|
|
839
839
|
return this._checkout;
|
|
840
840
|
}
|
|
841
841
|
get orders() {
|
|
842
842
|
if (!this._orders) {
|
|
843
|
-
this._orders = new
|
|
843
|
+
this._orders = new chunk6V67MAWO_js.OrderQueries(this);
|
|
844
844
|
}
|
|
845
845
|
return this._orders;
|
|
846
846
|
}
|
|
@@ -864,43 +864,43 @@ var CimplifyClient = class {
|
|
|
864
864
|
}
|
|
865
865
|
get link() {
|
|
866
866
|
if (!this._link) {
|
|
867
|
-
this._link = new
|
|
867
|
+
this._link = new chunk6V67MAWO_js.LinkService(this);
|
|
868
868
|
}
|
|
869
869
|
return this._link;
|
|
870
870
|
}
|
|
871
871
|
get auth() {
|
|
872
872
|
if (!this._auth) {
|
|
873
|
-
this._auth = new
|
|
873
|
+
this._auth = new chunk6V67MAWO_js.AuthService(this);
|
|
874
874
|
}
|
|
875
875
|
return this._auth;
|
|
876
876
|
}
|
|
877
877
|
get business() {
|
|
878
878
|
if (!this._business) {
|
|
879
|
-
this._business = new
|
|
879
|
+
this._business = new chunk6V67MAWO_js.BusinessService(this);
|
|
880
880
|
}
|
|
881
881
|
return this._business;
|
|
882
882
|
}
|
|
883
883
|
get inventory() {
|
|
884
884
|
if (!this._inventory) {
|
|
885
|
-
this._inventory = new
|
|
885
|
+
this._inventory = new chunk6V67MAWO_js.InventoryService(this);
|
|
886
886
|
}
|
|
887
887
|
return this._inventory;
|
|
888
888
|
}
|
|
889
889
|
get scheduling() {
|
|
890
890
|
if (!this._scheduling) {
|
|
891
|
-
this._scheduling = new
|
|
891
|
+
this._scheduling = new chunk6V67MAWO_js.SchedulingService(this);
|
|
892
892
|
}
|
|
893
893
|
return this._scheduling;
|
|
894
894
|
}
|
|
895
895
|
get lite() {
|
|
896
896
|
if (!this._lite) {
|
|
897
|
-
this._lite = new
|
|
897
|
+
this._lite = new chunk6V67MAWO_js.LiteService(this);
|
|
898
898
|
}
|
|
899
899
|
return this._lite;
|
|
900
900
|
}
|
|
901
901
|
get fx() {
|
|
902
902
|
if (!this._fx) {
|
|
903
|
-
this._fx = new
|
|
903
|
+
this._fx = new chunk6V67MAWO_js.FxService(this);
|
|
904
904
|
}
|
|
905
905
|
return this._fx;
|
|
906
906
|
}
|
|
@@ -935,7 +935,7 @@ var CimplifyClient = class {
|
|
|
935
935
|
if (businessId) {
|
|
936
936
|
this.setBusinessId(businessId);
|
|
937
937
|
}
|
|
938
|
-
return
|
|
938
|
+
return chunk6V67MAWO_js.createElements(this, businessId ?? this.businessId ?? void 0, options);
|
|
939
939
|
}
|
|
940
940
|
};
|
|
941
941
|
function createCimplifyClient(config = {}) {
|