@cimplify/sdk 0.44.14 → 0.44.18

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 (85) hide show
  1. package/dist/advanced.d.mts +1 -1
  2. package/dist/advanced.d.ts +1 -1
  3. package/dist/advanced.js +22 -21
  4. package/dist/advanced.mjs +3 -2
  5. package/dist/{chunk-OMAP327U.js → chunk-3FS3ZDKX.js} +62 -61
  6. package/dist/chunk-53J2WE4S.js +657 -0
  7. package/dist/{chunk-3WD6U5RD.mjs → chunk-5OK3YDZC.mjs} +4 -3
  8. package/dist/{chunk-V2O5AO7I.js → chunk-BN2CXGMO.js} +5 -246
  9. package/dist/chunk-CCSONJCO.js +8824 -0
  10. package/dist/{chunk-BAWKQRIB.js → chunk-HBRCVJL4.js} +22 -21
  11. package/dist/chunk-MJBSVUHO.mjs +8822 -0
  12. package/dist/{chunk-6TVQQYQ5.mjs → chunk-NRT6PVW5.mjs} +4 -231
  13. package/dist/chunk-QBQCMQ4F.js +271 -0
  14. package/dist/chunk-VDH3O7UB.mjs +604 -0
  15. package/dist/chunk-XPXAZXF2.mjs +250 -0
  16. package/dist/{chunk-EZK2FXTM.mjs → chunk-XZPO5GEM.mjs} +2 -1
  17. package/dist/cli/commands/deploy.mjs +9 -1
  18. package/dist/client-B_Ei3ENB.d.mts +86 -0
  19. package/dist/client-Bep2FooI.d.ts +86 -0
  20. package/dist/{client-lvLvB1_K.d.ts → client-D6ZisKco.d.ts} +7 -0
  21. package/dist/{client-CkGlXZRd.d.mts → client-Dh-bHyhU.d.mts} +7 -0
  22. package/dist/index.d.mts +1 -1
  23. package/dist/index.d.ts +1 -1
  24. package/dist/index.js +145 -144
  25. package/dist/index.mjs +4 -3
  26. package/dist/mock/cli.mjs +2 -1
  27. package/dist/mock/library.js +2 -1
  28. package/dist/mock/library.mjs +2 -1
  29. package/dist/mock/msw.js +2 -1
  30. package/dist/mock/msw.mjs +2 -1
  31. package/dist/react.d.mts +1 -1
  32. package/dist/react.d.ts +1 -1
  33. package/dist/react.js +81 -80
  34. package/dist/react.mjs +4 -3
  35. package/dist/server-CWpUlLOQ.d.mts +1003 -0
  36. package/dist/server-CWpUlLOQ.d.ts +1003 -0
  37. package/dist/server.d.mts +2 -2
  38. package/dist/server.d.ts +2 -2
  39. package/dist/server.js +6 -5
  40. package/dist/server.mjs +4 -3
  41. package/dist/testing/msw.d.mts +17 -0
  42. package/dist/testing/msw.d.ts +17 -0
  43. package/dist/testing/msw.js +42 -0
  44. package/dist/testing/msw.mjs +40 -0
  45. package/dist/testing/suite.d.mts +85 -0
  46. package/dist/testing/suite.d.ts +85 -0
  47. package/dist/testing/suite.js +174 -0
  48. package/dist/testing/suite.mjs +170 -0
  49. package/dist/testing.d.mts +1885 -0
  50. package/dist/testing.d.ts +1885 -0
  51. package/dist/testing.js +261 -0
  52. package/dist/testing.mjs +51 -0
  53. package/dist/utils.js +29 -28
  54. package/dist/utils.mjs +2 -1
  55. package/package.json +28 -4
  56. package/templates/storefront-bakery/__tests__/brand.test.ts +4 -0
  57. package/templates/storefront-bakery/__tests__/cart-flow.test.ts +4 -0
  58. package/templates/storefront-bakery/__tests__/contract.test.ts +4 -0
  59. package/templates/storefront-bakery/package.json +11 -3
  60. package/templates/storefront-bakery/vitest.config.ts +9 -0
  61. package/templates/storefront-fashion/__tests__/brand.test.ts +4 -0
  62. package/templates/storefront-fashion/__tests__/cart-flow.test.ts +4 -0
  63. package/templates/storefront-fashion/__tests__/contract.test.ts +4 -0
  64. package/templates/storefront-fashion/package.json +11 -3
  65. package/templates/storefront-fashion/vitest.config.ts +9 -0
  66. package/templates/storefront-grocery/__tests__/brand.test.ts +4 -0
  67. package/templates/storefront-grocery/__tests__/cart-flow.test.ts +4 -0
  68. package/templates/storefront-grocery/__tests__/contract.test.ts +4 -0
  69. package/templates/storefront-grocery/package.json +11 -3
  70. package/templates/storefront-grocery/vitest.config.ts +9 -0
  71. package/templates/storefront-restaurant/__tests__/brand.test.ts +4 -0
  72. package/templates/storefront-restaurant/__tests__/cart-flow.test.ts +4 -0
  73. package/templates/storefront-restaurant/__tests__/contract.test.ts +4 -0
  74. package/templates/storefront-restaurant/package.json +11 -3
  75. package/templates/storefront-restaurant/vitest.config.ts +9 -0
  76. package/templates/storefront-retail/__tests__/brand.test.ts +4 -0
  77. package/templates/storefront-retail/__tests__/cart-flow.test.ts +4 -0
  78. package/templates/storefront-retail/__tests__/contract.test.ts +4 -0
  79. package/templates/storefront-retail/package.json +11 -3
  80. package/templates/storefront-retail/vitest.config.ts +9 -0
  81. package/templates/storefront-services/__tests__/brand.test.ts +4 -0
  82. package/templates/storefront-services/__tests__/cart-flow.test.ts +4 -0
  83. package/templates/storefront-services/__tests__/contract.test.ts +4 -0
  84. package/templates/storefront-services/package.json +11 -3
  85. package/templates/storefront-services/vitest.config.ts +9 -0
@@ -1,233 +1,6 @@
1
1
  'use strict';
2
2
 
3
- // src/types/common.ts
4
- function money(value) {
5
- return typeof value === "string" ? parseFloat(value) || 0 : value;
6
- }
7
- function moneyFromNumber(value) {
8
- return value;
9
- }
10
- var ZERO = 0;
11
- var SUPPORTED_CURRENCY_CODES = /* @__PURE__ */ new Set([
12
- "USD",
13
- "EUR",
14
- "GBP",
15
- "JPY",
16
- "CNY",
17
- "CHF",
18
- "CAD",
19
- "AUD",
20
- "GHS",
21
- "NGN",
22
- "KES",
23
- "ZAR",
24
- "XOF",
25
- "XAF",
26
- "EGP",
27
- "TZS",
28
- "UGX",
29
- "RWF",
30
- "ETB",
31
- "ZMW",
32
- "BWP",
33
- "MUR",
34
- "NAD",
35
- "MWK",
36
- "AOA",
37
- "CDF",
38
- "GMD",
39
- "GNF",
40
- "LRD",
41
- "SLL",
42
- "MZN",
43
- "BIF",
44
- "INR",
45
- "BRL",
46
- "MXN",
47
- "KRW",
48
- "TRY",
49
- "THB",
50
- "MYR",
51
- "PHP",
52
- "IDR",
53
- "VND",
54
- "SGD",
55
- "HKD",
56
- "TWD",
57
- "AED",
58
- "SAR",
59
- "ILS"
60
- ]);
61
- function isSupportedCurrency(code) {
62
- return SUPPORTED_CURRENCY_CODES.has(code);
63
- }
64
- var warnedCurrencies = /* @__PURE__ */ new Set();
65
- function currencyCode(value) {
66
- const normalized = value.trim().toUpperCase();
67
- if (!isSupportedCurrency(normalized) && !warnedCurrencies.has(normalized)) {
68
- warnedCurrencies.add(normalized);
69
- console.warn(
70
- `[Cimplify] Unrecognized currency code "${normalized}". It may not format correctly.`
71
- );
72
- }
73
- return normalized;
74
- }
75
- var ErrorCode = {
76
- UNKNOWN_ERROR: "UNKNOWN_ERROR",
77
- NETWORK_ERROR: "NETWORK_ERROR",
78
- TIMEOUT: "TIMEOUT",
79
- UNAUTHORIZED: "UNAUTHORIZED",
80
- FORBIDDEN: "FORBIDDEN",
81
- NOT_FOUND: "NOT_FOUND",
82
- VALIDATION_ERROR: "VALIDATION_ERROR",
83
- CART_EMPTY: "CART_EMPTY",
84
- CART_EXPIRED: "CART_EXPIRED",
85
- CART_NOT_FOUND: "CART_NOT_FOUND",
86
- ITEM_UNAVAILABLE: "ITEM_UNAVAILABLE",
87
- VARIANT_NOT_FOUND: "VARIANT_NOT_FOUND",
88
- VARIANT_OUT_OF_STOCK: "VARIANT_OUT_OF_STOCK",
89
- ADDON_REQUIRED: "ADDON_REQUIRED",
90
- ADDON_MAX_EXCEEDED: "ADDON_MAX_EXCEEDED",
91
- CHECKOUT_VALIDATION_FAILED: "CHECKOUT_VALIDATION_FAILED",
92
- DELIVERY_ADDRESS_REQUIRED: "DELIVERY_ADDRESS_REQUIRED",
93
- CUSTOMER_INFO_REQUIRED: "CUSTOMER_INFO_REQUIRED",
94
- QUOTE_NOT_FOUND: "QUOTE_NOT_FOUND",
95
- QUOTE_EXPIRED: "QUOTE_EXPIRED",
96
- QUOTE_CONSUMED: "QUOTE_CONSUMED",
97
- QUOTE_STORAGE_UNAVAILABLE: "QUOTE_STORAGE_UNAVAILABLE",
98
- PAYMENT_FAILED: "PAYMENT_FAILED",
99
- PAYMENT_CANCELLED: "PAYMENT_CANCELLED",
100
- INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS",
101
- CARD_DECLINED: "CARD_DECLINED",
102
- INVALID_OTP: "INVALID_OTP",
103
- OTP_EXPIRED: "OTP_EXPIRED",
104
- AUTHORIZATION_FAILED: "AUTHORIZATION_FAILED",
105
- PAYMENT_ACTION_NOT_COMPLETED: "PAYMENT_ACTION_NOT_COMPLETED",
106
- SLOT_UNAVAILABLE: "SLOT_UNAVAILABLE",
107
- BOOKING_CONFLICT: "BOOKING_CONFLICT",
108
- SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND",
109
- OUT_OF_STOCK: "OUT_OF_STOCK",
110
- INSUFFICIENT_QUANTITY: "INSUFFICIENT_QUANTITY"
111
- };
112
- var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
113
- function docsUrlForCode(code) {
114
- return `${DOCS_ERROR_BASE_URL}#${code.toLowerCase().replace(/_/g, "-")}`;
115
- }
116
- var ERROR_SUGGESTIONS = {
117
- UNKNOWN_ERROR: "An unexpected error occurred. Capture the request/response payload and retry with exponential backoff.",
118
- NETWORK_ERROR: "Check the shopper's connection and retry. If this persists, inspect CORS, DNS, and API reachability.",
119
- TIMEOUT: "The request exceeded the timeout. Retry once, then poll order status before charging again.",
120
- UNAUTHORIZED: "Authentication is missing or expired. Ensure a valid access token is set and refresh the session if needed.",
121
- FORBIDDEN: "The key/session lacks permission for this resource. Verify business ownership and API key scope.",
122
- NOT_FOUND: "The requested resource does not exist or is not visible in this environment.",
123
- VALIDATION_ERROR: "One or more fields are invalid. Validate required fields and enum values before retrying.",
124
- CART_EMPTY: "The cart has no items. Redirect back to menu/catalogue and require at least one line item.",
125
- CART_EXPIRED: "This cart is no longer active. Recreate a new cart and re-add shopper selections.",
126
- CART_NOT_FOUND: "Cart could not be located. It may have expired or belongs to a different key/location.",
127
- ITEM_UNAVAILABLE: "The selected item is unavailable at this location/time. Prompt the shopper to pick an alternative.",
128
- VARIANT_NOT_FOUND: "The requested variant no longer exists. Refresh product data and require re-selection.",
129
- VARIANT_OUT_OF_STOCK: "The selected variant is out of stock. Show in-stock variants and block checkout for this line.",
130
- ADDON_REQUIRED: "A required add-on is missing. Ensure required modifier groups are completed before add-to-cart.",
131
- ADDON_MAX_EXCEEDED: "Too many add-ons were selected. Enforce max selections client-side before submission.",
132
- CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
133
- DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
134
- CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
135
- QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
136
- QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
137
- QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
138
- QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
139
- PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
140
- PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
141
- INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
142
- CARD_DECLINED: "Card was declined. Ask shopper to retry or switch payment method.",
143
- INVALID_OTP: "Authorization code is invalid. Let shopper re-enter OTP/PIN and retry.",
144
- OTP_EXPIRED: "Authorization code expired. Request a new OTP and re-submit authorization.",
145
- AUTHORIZATION_FAILED: "Additional payment authorization failed. Retry authorization or change payment method.",
146
- PAYMENT_ACTION_NOT_COMPLETED: "Required payment action was not completed. Resume provider flow and poll for status.",
147
- SLOT_UNAVAILABLE: "Selected schedule slot is unavailable. Refresh available slots and ask shopper to reselect.",
148
- BOOKING_CONFLICT: "The requested booking conflicts with an existing reservation. Pick another slot/resource.",
149
- SERVICE_NOT_FOUND: "Requested service no longer exists. Refresh service catalogue and retry selection.",
150
- OUT_OF_STOCK: "Inventory is depleted for this item. Remove it or reduce quantity before checkout.",
151
- INSUFFICIENT_QUANTITY: "Requested quantity exceeds available inventory. Reduce quantity and retry.",
152
- BUSINESS_ID_REQUIRED: "Business context could not be resolved. Verify the public key and business bootstrap call.",
153
- INVALID_CART: "Cart is invalid for checkout. Sync cart state, ensure items exist, then retry.",
154
- ORDER_TYPE_REQUIRED: "Order type is required. Provide one of delivery, pickup, or dine_in before checkout.",
155
- NO_PAYMENT_ELEMENT: "PaymentElement is required for processCheckout(). Mount it before triggering checkout.",
156
- PAYMENT_NOT_MOUNTED: "PaymentElement iframe is not mounted. Mount it in the DOM before processCheckout().",
157
- AUTH_INCOMPLETE: "AuthElement has not completed authentication. Wait for AUTHENTICATED before checkout.",
158
- AUTH_LOST: "Session was cleared during checkout. Re-authenticate and restart checkout safely.",
159
- ALREADY_PROCESSING: "Checkout is already in progress. Disable duplicate submits until completion.",
160
- CHECKOUT_NOT_READY: "Checkout elements are still initializing. Wait for readiness before submit.",
161
- CANCELLED: "Checkout was cancelled. Preserve cart state and allow shopper to retry.",
162
- REQUEST_TIMEOUT: "Provider call timed out. Poll payment/order status before issuing another charge attempt.",
163
- POPUP_BLOCKED: "Browser blocked provider popup. Ask shopper to enable popups and retry.",
164
- FX_QUOTE_FAILED: "Failed to lock FX quote. Retry currency quote or fallback to base currency."
165
- };
166
- var ERROR_HINTS = Object.fromEntries(
167
- Object.entries(ERROR_SUGGESTIONS).map(([code, suggestion]) => [
168
- code,
169
- {
170
- docs_url: docsUrlForCode(code),
171
- suggestion
172
- }
173
- ])
174
- );
175
- var CimplifyError = class extends Error {
176
- constructor(code, message, retryable = false, docs_url, suggestion) {
177
- super(message);
178
- this.code = code;
179
- this.retryable = retryable;
180
- this.docs_url = docs_url;
181
- this.suggestion = suggestion;
182
- this.name = "CimplifyError";
183
- }
184
- get userMessage() {
185
- return this.message;
186
- }
187
- };
188
- var IdempotencyMismatchError = class extends CimplifyError {
189
- constructor(message, originalCreatedAt) {
190
- super("IDEMPOTENCY_MISMATCH", message, false);
191
- this.originalCreatedAt = originalCreatedAt;
192
- this.name = "IdempotencyMismatchError";
193
- }
194
- };
195
- function isCimplifyError(error) {
196
- return error instanceof CimplifyError;
197
- }
198
- function isIdempotencyMismatchError(error) {
199
- return error instanceof IdempotencyMismatchError;
200
- }
201
- function getErrorHint(code) {
202
- return ERROR_HINTS[code];
203
- }
204
- function enrichError(error, options = {}) {
205
- if (error instanceof IdempotencyMismatchError) {
206
- return error;
207
- }
208
- const hint = getErrorHint(error.code);
209
- const docsUrl = error.docs_url || hint?.docs_url || docsUrlForCode(error.code || ErrorCode.UNKNOWN_ERROR);
210
- const suggestion = error.suggestion || hint?.suggestion;
211
- let message = error.message;
212
- if (options.isTestMode && !message.includes("pk_test_")) {
213
- message = `${message}
214
-
215
- \u2139 Your API key is a test-mode key (pk_test_...). Verify test data/session before retrying.`;
216
- }
217
- const enriched = new CimplifyError(error.code, message, error.retryable, docsUrl, suggestion);
218
- enriched.stack = error.stack;
219
- return enriched;
220
- }
221
- function isRetryableError(error) {
222
- if (isCimplifyError(error)) {
223
- return error.retryable;
224
- }
225
- if (error instanceof Error) {
226
- const msg = error.message.toLowerCase();
227
- return msg.includes("network") || msg.includes("timeout") || msg.includes("fetch");
228
- }
229
- return false;
230
- }
3
+ var chunkQBQCMQ4F_js = require('./chunk-QBQCMQ4F.js');
231
4
 
232
5
  // src/utils/price.ts
233
6
  var CURRENCY_SYMBOLS = {
@@ -300,8 +73,8 @@ var CURRENCY_SYMBOLS = {
300
73
  KMF: "CF",
301
74
  BIF: "FBu"
302
75
  };
303
- function getCurrencySymbol(currencyCode3) {
304
- return CURRENCY_SYMBOLS[currencyCode3.toUpperCase()] || currencyCode3;
76
+ function getCurrencySymbol(currencyCode2) {
77
+ return CURRENCY_SYMBOLS[currencyCode2.toUpperCase()] || currencyCode2;
305
78
  }
306
79
  function formatNumberCompact(value, decimals = 1) {
307
80
  const absValue = Math.abs(value);
@@ -667,14 +440,14 @@ function normalizeStatusResponse(response) {
667
440
  return {
668
441
  status: "pending",
669
442
  paid: false,
670
- amount: moneyFromNumber(0),
443
+ amount: chunkQBQCMQ4F_js.moneyFromNumber(0),
671
444
  currency: "",
672
445
  message: "No status available"
673
446
  };
674
447
  }
675
448
  const res = response;
676
449
  const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
677
- 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);
678
451
  const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? res.currency : "";
679
452
  const paidValue = res.paid === true;
680
453
  const derivedPaid = paidValue || [
@@ -711,16 +484,9 @@ function detectMobileMoneyProvider(phoneNumber) {
711
484
  }
712
485
 
713
486
  exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
714
- exports.CimplifyError = CimplifyError;
715
- exports.ERROR_HINTS = ERROR_HINTS;
716
- exports.ErrorCode = ErrorCode;
717
- exports.IdempotencyMismatchError = IdempotencyMismatchError;
718
487
  exports.MOBILE_MONEY_PROVIDERS = MOBILE_MONEY_PROVIDERS;
719
- exports.ZERO = ZERO;
720
488
  exports.categorizePaymentError = categorizePaymentError;
721
- exports.currencyCode = currencyCode;
722
489
  exports.detectMobileMoneyProvider = detectMobileMoneyProvider;
723
- exports.enrichError = enrichError;
724
490
  exports.formatMoney = formatMoney;
725
491
  exports.formatNumberCompact = formatNumberCompact;
726
492
  exports.formatPrice = formatPrice;
@@ -733,24 +499,17 @@ exports.getBasePrice = getBasePrice;
733
499
  exports.getCurrencySymbol = getCurrencySymbol;
734
500
  exports.getDiscountPercentage = getDiscountPercentage;
735
501
  exports.getDisplayPrice = getDisplayPrice;
736
- exports.getErrorHint = getErrorHint;
737
502
  exports.getMarkupPercentage = getMarkupPercentage;
738
503
  exports.getPriceRange = getPriceRange;
739
504
  exports.getProductCurrency = getProductCurrency;
740
505
  exports.getTaxAmount = getTaxAmount;
741
506
  exports.getUnitPriceAtQuantity = getUnitPriceAtQuantity;
742
507
  exports.hasTaxInfo = hasTaxInfo;
743
- exports.isCimplifyError = isCimplifyError;
744
- exports.isIdempotencyMismatchError = isIdempotencyMismatchError;
745
508
  exports.isOnSale = isOnSale;
746
509
  exports.isPaymentStatusFailure = isPaymentStatusFailure;
747
510
  exports.isPaymentStatusRequiresAction = isPaymentStatusRequiresAction;
748
511
  exports.isPaymentStatusSuccess = isPaymentStatusSuccess;
749
- exports.isRetryableError = isRetryableError;
750
- exports.isSupportedCurrency = isSupportedCurrency;
751
512
  exports.isTaxInclusive = isTaxInclusive;
752
- exports.money = money;
753
- exports.moneyFromNumber = moneyFromNumber;
754
513
  exports.normalizePaymentResponse = normalizePaymentResponse;
755
514
  exports.normalizeStatusResponse = normalizeStatusResponse;
756
515
  exports.parsePrice = parsePrice;