@cimplify/sdk 0.44.16 → 0.44.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/advanced.js +22 -21
  2. package/dist/advanced.mjs +3 -2
  3. package/dist/{chunk-MBGQP6FZ.js → chunk-3FS3ZDKX.js} +60 -60
  4. package/dist/{chunk-UXLQ7WXI.mjs → chunk-5OK3YDZC.mjs} +2 -2
  5. package/dist/{chunk-MNIKXG7W.js → chunk-BN2CXGMO.js} +5 -272
  6. package/dist/chunk-GLOO4HUN.mjs +676 -0
  7. package/dist/{chunk-CFD4J32N.js → chunk-HBRCVJL4.js} +22 -21
  8. package/dist/{chunk-ZLEFMQC6.mjs → chunk-KSKZAXG2.mjs} +4 -498
  9. package/dist/{chunk-6AZZ6AOF.mjs → chunk-NRT6PVW5.mjs} +4 -251
  10. package/dist/{chunk-XL4CX75J.js → chunk-PGSM3NQ2.js} +237 -781
  11. package/dist/chunk-Q4I7JRGO.js +733 -0
  12. package/dist/chunk-QBQCMQ4F.js +271 -0
  13. package/dist/chunk-XPXAZXF2.mjs +250 -0
  14. package/dist/{chunk-7NML226B.mjs → chunk-XZPO5GEM.mjs} +2 -1
  15. package/dist/client-B_Ei3ENB.d.mts +86 -0
  16. package/dist/client-Bep2FooI.d.ts +86 -0
  17. package/dist/index.js +145 -144
  18. package/dist/index.mjs +4 -3
  19. package/dist/mock/cli.mjs +2 -0
  20. package/dist/mock/library.js +2 -0
  21. package/dist/mock/library.mjs +2 -0
  22. package/dist/mock/msw.js +2 -0
  23. package/dist/mock/msw.mjs +2 -0
  24. package/dist/react.js +81 -80
  25. package/dist/react.mjs +4 -3
  26. package/dist/server.js +6 -5
  27. package/dist/server.mjs +4 -3
  28. package/dist/testing/msw.d.mts +17 -0
  29. package/dist/testing/msw.d.ts +17 -0
  30. package/dist/testing/msw.js +42 -0
  31. package/dist/testing/msw.mjs +40 -0
  32. package/dist/testing/suite.d.mts +25 -0
  33. package/dist/testing/suite.d.ts +25 -0
  34. package/dist/testing/suite.js +28 -23
  35. package/dist/testing/suite.mjs +9 -4
  36. package/dist/testing.d.mts +963 -135
  37. package/dist/testing.d.ts +963 -135
  38. package/dist/testing.js +123 -59
  39. package/dist/testing.mjs +51 -4
  40. package/dist/utils.js +29 -28
  41. package/dist/utils.mjs +2 -1
  42. package/package.json +11 -2
@@ -1,253 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var __defProp = Object.defineProperty;
4
- var __typeError = (msg) => {
5
- throw TypeError(msg);
6
- };
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
9
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
10
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
11
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
12
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
13
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
14
- var __privateWrapper = (obj, member, setter, getter) => ({
15
- set _(value) {
16
- __privateSet(obj, member, value, setter);
17
- },
18
- get _() {
19
- return __privateGet(obj, member, getter);
20
- }
21
- });
22
-
23
- // src/types/common.ts
24
- function money(value) {
25
- return typeof value === "string" ? parseFloat(value) || 0 : value;
26
- }
27
- function moneyFromNumber(value) {
28
- return value;
29
- }
30
- var ZERO = 0;
31
- var SUPPORTED_CURRENCY_CODES = /* @__PURE__ */ new Set([
32
- "USD",
33
- "EUR",
34
- "GBP",
35
- "JPY",
36
- "CNY",
37
- "CHF",
38
- "CAD",
39
- "AUD",
40
- "GHS",
41
- "NGN",
42
- "KES",
43
- "ZAR",
44
- "XOF",
45
- "XAF",
46
- "EGP",
47
- "TZS",
48
- "UGX",
49
- "RWF",
50
- "ETB",
51
- "ZMW",
52
- "BWP",
53
- "MUR",
54
- "NAD",
55
- "MWK",
56
- "AOA",
57
- "CDF",
58
- "GMD",
59
- "GNF",
60
- "LRD",
61
- "SLL",
62
- "MZN",
63
- "BIF",
64
- "INR",
65
- "BRL",
66
- "MXN",
67
- "KRW",
68
- "TRY",
69
- "THB",
70
- "MYR",
71
- "PHP",
72
- "IDR",
73
- "VND",
74
- "SGD",
75
- "HKD",
76
- "TWD",
77
- "AED",
78
- "SAR",
79
- "ILS"
80
- ]);
81
- function isSupportedCurrency(code) {
82
- return SUPPORTED_CURRENCY_CODES.has(code);
83
- }
84
- var warnedCurrencies = /* @__PURE__ */ new Set();
85
- function currencyCode(value) {
86
- const normalized = value.trim().toUpperCase();
87
- if (!isSupportedCurrency(normalized) && !warnedCurrencies.has(normalized)) {
88
- warnedCurrencies.add(normalized);
89
- console.warn(
90
- `[Cimplify] Unrecognized currency code "${normalized}". It may not format correctly.`
91
- );
92
- }
93
- return normalized;
94
- }
95
- var ErrorCode = {
96
- UNKNOWN_ERROR: "UNKNOWN_ERROR",
97
- NETWORK_ERROR: "NETWORK_ERROR",
98
- TIMEOUT: "TIMEOUT",
99
- UNAUTHORIZED: "UNAUTHORIZED",
100
- FORBIDDEN: "FORBIDDEN",
101
- NOT_FOUND: "NOT_FOUND",
102
- VALIDATION_ERROR: "VALIDATION_ERROR",
103
- CART_EMPTY: "CART_EMPTY",
104
- CART_EXPIRED: "CART_EXPIRED",
105
- CART_NOT_FOUND: "CART_NOT_FOUND",
106
- ITEM_UNAVAILABLE: "ITEM_UNAVAILABLE",
107
- VARIANT_NOT_FOUND: "VARIANT_NOT_FOUND",
108
- VARIANT_OUT_OF_STOCK: "VARIANT_OUT_OF_STOCK",
109
- ADDON_REQUIRED: "ADDON_REQUIRED",
110
- ADDON_MAX_EXCEEDED: "ADDON_MAX_EXCEEDED",
111
- CHECKOUT_VALIDATION_FAILED: "CHECKOUT_VALIDATION_FAILED",
112
- DELIVERY_ADDRESS_REQUIRED: "DELIVERY_ADDRESS_REQUIRED",
113
- CUSTOMER_INFO_REQUIRED: "CUSTOMER_INFO_REQUIRED",
114
- QUOTE_NOT_FOUND: "QUOTE_NOT_FOUND",
115
- QUOTE_EXPIRED: "QUOTE_EXPIRED",
116
- QUOTE_CONSUMED: "QUOTE_CONSUMED",
117
- QUOTE_STORAGE_UNAVAILABLE: "QUOTE_STORAGE_UNAVAILABLE",
118
- PAYMENT_FAILED: "PAYMENT_FAILED",
119
- PAYMENT_CANCELLED: "PAYMENT_CANCELLED",
120
- INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS",
121
- CARD_DECLINED: "CARD_DECLINED",
122
- INVALID_OTP: "INVALID_OTP",
123
- OTP_EXPIRED: "OTP_EXPIRED",
124
- AUTHORIZATION_FAILED: "AUTHORIZATION_FAILED",
125
- PAYMENT_ACTION_NOT_COMPLETED: "PAYMENT_ACTION_NOT_COMPLETED",
126
- SLOT_UNAVAILABLE: "SLOT_UNAVAILABLE",
127
- BOOKING_CONFLICT: "BOOKING_CONFLICT",
128
- SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND",
129
- OUT_OF_STOCK: "OUT_OF_STOCK",
130
- INSUFFICIENT_QUANTITY: "INSUFFICIENT_QUANTITY"
131
- };
132
- var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
133
- function docsUrlForCode(code) {
134
- return `${DOCS_ERROR_BASE_URL}#${code.toLowerCase().replace(/_/g, "-")}`;
135
- }
136
- var ERROR_SUGGESTIONS = {
137
- UNKNOWN_ERROR: "An unexpected error occurred. Capture the request/response payload and retry with exponential backoff.",
138
- NETWORK_ERROR: "Check the shopper's connection and retry. If this persists, inspect CORS, DNS, and API reachability.",
139
- TIMEOUT: "The request exceeded the timeout. Retry once, then poll order status before charging again.",
140
- UNAUTHORIZED: "Authentication is missing or expired. Ensure a valid access token is set and refresh the session if needed.",
141
- FORBIDDEN: "The key/session lacks permission for this resource. Verify business ownership and API key scope.",
142
- NOT_FOUND: "The requested resource does not exist or is not visible in this environment.",
143
- VALIDATION_ERROR: "One or more fields are invalid. Validate required fields and enum values before retrying.",
144
- CART_EMPTY: "The cart has no items. Redirect back to menu/catalogue and require at least one line item.",
145
- CART_EXPIRED: "This cart is no longer active. Recreate a new cart and re-add shopper selections.",
146
- CART_NOT_FOUND: "Cart could not be located. It may have expired or belongs to a different key/location.",
147
- ITEM_UNAVAILABLE: "The selected item is unavailable at this location/time. Prompt the shopper to pick an alternative.",
148
- VARIANT_NOT_FOUND: "The requested variant no longer exists. Refresh product data and require re-selection.",
149
- VARIANT_OUT_OF_STOCK: "The selected variant is out of stock. Show in-stock variants and block checkout for this line.",
150
- ADDON_REQUIRED: "A required add-on is missing. Ensure required modifier groups are completed before add-to-cart.",
151
- ADDON_MAX_EXCEEDED: "Too many add-ons were selected. Enforce max selections client-side before submission.",
152
- CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
153
- DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
154
- CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
155
- QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
156
- QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
157
- QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
158
- QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
159
- PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
160
- PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
161
- INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
162
- CARD_DECLINED: "Card was declined. Ask shopper to retry or switch payment method.",
163
- INVALID_OTP: "Authorization code is invalid. Let shopper re-enter OTP/PIN and retry.",
164
- OTP_EXPIRED: "Authorization code expired. Request a new OTP and re-submit authorization.",
165
- AUTHORIZATION_FAILED: "Additional payment authorization failed. Retry authorization or change payment method.",
166
- PAYMENT_ACTION_NOT_COMPLETED: "Required payment action was not completed. Resume provider flow and poll for status.",
167
- SLOT_UNAVAILABLE: "Selected schedule slot is unavailable. Refresh available slots and ask shopper to reselect.",
168
- BOOKING_CONFLICT: "The requested booking conflicts with an existing reservation. Pick another slot/resource.",
169
- SERVICE_NOT_FOUND: "Requested service no longer exists. Refresh service catalogue and retry selection.",
170
- OUT_OF_STOCK: "Inventory is depleted for this item. Remove it or reduce quantity before checkout.",
171
- INSUFFICIENT_QUANTITY: "Requested quantity exceeds available inventory. Reduce quantity and retry.",
172
- BUSINESS_ID_REQUIRED: "Business context could not be resolved. Verify the public key and business bootstrap call.",
173
- INVALID_CART: "Cart is invalid for checkout. Sync cart state, ensure items exist, then retry.",
174
- ORDER_TYPE_REQUIRED: "Order type is required. Provide one of delivery, pickup, or dine_in before checkout.",
175
- NO_PAYMENT_ELEMENT: "PaymentElement is required for processCheckout(). Mount it before triggering checkout.",
176
- PAYMENT_NOT_MOUNTED: "PaymentElement iframe is not mounted. Mount it in the DOM before processCheckout().",
177
- AUTH_INCOMPLETE: "AuthElement has not completed authentication. Wait for AUTHENTICATED before checkout.",
178
- AUTH_LOST: "Session was cleared during checkout. Re-authenticate and restart checkout safely.",
179
- ALREADY_PROCESSING: "Checkout is already in progress. Disable duplicate submits until completion.",
180
- CHECKOUT_NOT_READY: "Checkout elements are still initializing. Wait for readiness before submit.",
181
- CANCELLED: "Checkout was cancelled. Preserve cart state and allow shopper to retry.",
182
- REQUEST_TIMEOUT: "Provider call timed out. Poll payment/order status before issuing another charge attempt.",
183
- POPUP_BLOCKED: "Browser blocked provider popup. Ask shopper to enable popups and retry.",
184
- FX_QUOTE_FAILED: "Failed to lock FX quote. Retry currency quote or fallback to base currency."
185
- };
186
- var ERROR_HINTS = Object.fromEntries(
187
- Object.entries(ERROR_SUGGESTIONS).map(([code, suggestion]) => [
188
- code,
189
- {
190
- docs_url: docsUrlForCode(code),
191
- suggestion
192
- }
193
- ])
194
- );
195
- var CimplifyError = class extends Error {
196
- constructor(code, message, retryable = false, docs_url, suggestion) {
197
- super(message);
198
- this.code = code;
199
- this.retryable = retryable;
200
- this.docs_url = docs_url;
201
- this.suggestion = suggestion;
202
- this.name = "CimplifyError";
203
- }
204
- get userMessage() {
205
- return this.message;
206
- }
207
- };
208
- var IdempotencyMismatchError = class extends CimplifyError {
209
- constructor(message, originalCreatedAt) {
210
- super("IDEMPOTENCY_MISMATCH", message, false);
211
- this.originalCreatedAt = originalCreatedAt;
212
- this.name = "IdempotencyMismatchError";
213
- }
214
- };
215
- function isCimplifyError(error) {
216
- return error instanceof CimplifyError;
217
- }
218
- function isIdempotencyMismatchError(error) {
219
- return error instanceof IdempotencyMismatchError;
220
- }
221
- function getErrorHint(code) {
222
- return ERROR_HINTS[code];
223
- }
224
- function enrichError(error, options = {}) {
225
- if (error instanceof IdempotencyMismatchError) {
226
- return error;
227
- }
228
- const hint = getErrorHint(error.code);
229
- const docsUrl = error.docs_url || hint?.docs_url || docsUrlForCode(error.code || ErrorCode.UNKNOWN_ERROR);
230
- const suggestion = error.suggestion || hint?.suggestion;
231
- let message = error.message;
232
- if (options.isTestMode && !message.includes("pk_test_")) {
233
- message = `${message}
234
-
235
- \u2139 Your API key is a test-mode key (pk_test_...). Verify test data/session before retrying.`;
236
- }
237
- const enriched = new CimplifyError(error.code, message, error.retryable, docsUrl, suggestion);
238
- enriched.stack = error.stack;
239
- return enriched;
240
- }
241
- function isRetryableError(error) {
242
- if (isCimplifyError(error)) {
243
- return error.retryable;
244
- }
245
- if (error instanceof Error) {
246
- const msg = error.message.toLowerCase();
247
- return msg.includes("network") || msg.includes("timeout") || msg.includes("fetch");
248
- }
249
- return false;
250
- }
3
+ var chunkQBQCMQ4F_js = require('./chunk-QBQCMQ4F.js');
251
4
 
252
5
  // src/utils/price.ts
253
6
  var CURRENCY_SYMBOLS = {
@@ -320,8 +73,8 @@ var CURRENCY_SYMBOLS = {
320
73
  KMF: "CF",
321
74
  BIF: "FBu"
322
75
  };
323
- function getCurrencySymbol(currencyCode3) {
324
- return CURRENCY_SYMBOLS[currencyCode3.toUpperCase()] || currencyCode3;
76
+ function getCurrencySymbol(currencyCode2) {
77
+ return CURRENCY_SYMBOLS[currencyCode2.toUpperCase()] || currencyCode2;
325
78
  }
326
79
  function formatNumberCompact(value, decimals = 1) {
327
80
  const absValue = Math.abs(value);
@@ -687,14 +440,14 @@ function normalizeStatusResponse(response) {
687
440
  return {
688
441
  status: "pending",
689
442
  paid: false,
690
- amount: moneyFromNumber(0),
443
+ amount: chunkQBQCMQ4F_js.moneyFromNumber(0),
691
444
  currency: "",
692
445
  message: "No status available"
693
446
  };
694
447
  }
695
448
  const res = response;
696
449
  const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
697
- const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : moneyFromNumber(0);
450
+ const normalizedAmount = typeof res.amount === "string" ? chunkQBQCMQ4F_js.money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? chunkQBQCMQ4F_js.moneyFromNumber(res.amount) : chunkQBQCMQ4F_js.moneyFromNumber(0);
698
451
  const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? res.currency : "";
699
452
  const paidValue = res.paid === true;
700
453
  const derivedPaid = paidValue || [
@@ -731,22 +484,9 @@ function detectMobileMoneyProvider(phoneNumber) {
731
484
  }
732
485
 
733
486
  exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
734
- exports.CimplifyError = CimplifyError;
735
- exports.ERROR_HINTS = ERROR_HINTS;
736
- exports.ErrorCode = ErrorCode;
737
- exports.IdempotencyMismatchError = IdempotencyMismatchError;
738
487
  exports.MOBILE_MONEY_PROVIDERS = MOBILE_MONEY_PROVIDERS;
739
- exports.ZERO = ZERO;
740
- exports.__privateAdd = __privateAdd;
741
- exports.__privateGet = __privateGet;
742
- exports.__privateMethod = __privateMethod;
743
- exports.__privateSet = __privateSet;
744
- exports.__privateWrapper = __privateWrapper;
745
- exports.__publicField = __publicField;
746
488
  exports.categorizePaymentError = categorizePaymentError;
747
- exports.currencyCode = currencyCode;
748
489
  exports.detectMobileMoneyProvider = detectMobileMoneyProvider;
749
- exports.enrichError = enrichError;
750
490
  exports.formatMoney = formatMoney;
751
491
  exports.formatNumberCompact = formatNumberCompact;
752
492
  exports.formatPrice = formatPrice;
@@ -759,24 +499,17 @@ exports.getBasePrice = getBasePrice;
759
499
  exports.getCurrencySymbol = getCurrencySymbol;
760
500
  exports.getDiscountPercentage = getDiscountPercentage;
761
501
  exports.getDisplayPrice = getDisplayPrice;
762
- exports.getErrorHint = getErrorHint;
763
502
  exports.getMarkupPercentage = getMarkupPercentage;
764
503
  exports.getPriceRange = getPriceRange;
765
504
  exports.getProductCurrency = getProductCurrency;
766
505
  exports.getTaxAmount = getTaxAmount;
767
506
  exports.getUnitPriceAtQuantity = getUnitPriceAtQuantity;
768
507
  exports.hasTaxInfo = hasTaxInfo;
769
- exports.isCimplifyError = isCimplifyError;
770
- exports.isIdempotencyMismatchError = isIdempotencyMismatchError;
771
508
  exports.isOnSale = isOnSale;
772
509
  exports.isPaymentStatusFailure = isPaymentStatusFailure;
773
510
  exports.isPaymentStatusRequiresAction = isPaymentStatusRequiresAction;
774
511
  exports.isPaymentStatusSuccess = isPaymentStatusSuccess;
775
- exports.isRetryableError = isRetryableError;
776
- exports.isSupportedCurrency = isSupportedCurrency;
777
512
  exports.isTaxInclusive = isTaxInclusive;
778
- exports.money = money;
779
- exports.moneyFromNumber = moneyFromNumber;
780
513
  exports.normalizePaymentResponse = normalizePaymentResponse;
781
514
  exports.normalizeStatusResponse = normalizeStatusResponse;
782
515
  exports.parsePrice = parsePrice;