@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
@@ -0,0 +1,271 @@
1
+ 'use strict';
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
+ }
251
+
252
+ exports.CimplifyError = CimplifyError;
253
+ exports.ERROR_HINTS = ERROR_HINTS;
254
+ exports.ErrorCode = ErrorCode;
255
+ exports.IdempotencyMismatchError = IdempotencyMismatchError;
256
+ exports.ZERO = ZERO;
257
+ exports.__privateAdd = __privateAdd;
258
+ exports.__privateGet = __privateGet;
259
+ exports.__privateMethod = __privateMethod;
260
+ exports.__privateSet = __privateSet;
261
+ exports.__privateWrapper = __privateWrapper;
262
+ exports.__publicField = __publicField;
263
+ exports.currencyCode = currencyCode;
264
+ exports.enrichError = enrichError;
265
+ exports.getErrorHint = getErrorHint;
266
+ exports.isCimplifyError = isCimplifyError;
267
+ exports.isIdempotencyMismatchError = isIdempotencyMismatchError;
268
+ exports.isRetryableError = isRetryableError;
269
+ exports.isSupportedCurrency = isSupportedCurrency;
270
+ exports.money = money;
271
+ exports.moneyFromNumber = moneyFromNumber;
@@ -0,0 +1,250 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __typeError = (msg) => {
3
+ throw TypeError(msg);
4
+ };
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
7
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
8
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
9
+ 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);
10
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
11
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
12
+ var __privateWrapper = (obj, member, setter, getter) => ({
13
+ set _(value) {
14
+ __privateSet(obj, member, value, setter);
15
+ },
16
+ get _() {
17
+ return __privateGet(obj, member, getter);
18
+ }
19
+ });
20
+
21
+ // src/types/common.ts
22
+ function money(value) {
23
+ return typeof value === "string" ? parseFloat(value) || 0 : value;
24
+ }
25
+ function moneyFromNumber(value) {
26
+ return value;
27
+ }
28
+ var ZERO = 0;
29
+ var SUPPORTED_CURRENCY_CODES = /* @__PURE__ */ new Set([
30
+ "USD",
31
+ "EUR",
32
+ "GBP",
33
+ "JPY",
34
+ "CNY",
35
+ "CHF",
36
+ "CAD",
37
+ "AUD",
38
+ "GHS",
39
+ "NGN",
40
+ "KES",
41
+ "ZAR",
42
+ "XOF",
43
+ "XAF",
44
+ "EGP",
45
+ "TZS",
46
+ "UGX",
47
+ "RWF",
48
+ "ETB",
49
+ "ZMW",
50
+ "BWP",
51
+ "MUR",
52
+ "NAD",
53
+ "MWK",
54
+ "AOA",
55
+ "CDF",
56
+ "GMD",
57
+ "GNF",
58
+ "LRD",
59
+ "SLL",
60
+ "MZN",
61
+ "BIF",
62
+ "INR",
63
+ "BRL",
64
+ "MXN",
65
+ "KRW",
66
+ "TRY",
67
+ "THB",
68
+ "MYR",
69
+ "PHP",
70
+ "IDR",
71
+ "VND",
72
+ "SGD",
73
+ "HKD",
74
+ "TWD",
75
+ "AED",
76
+ "SAR",
77
+ "ILS"
78
+ ]);
79
+ function isSupportedCurrency(code) {
80
+ return SUPPORTED_CURRENCY_CODES.has(code);
81
+ }
82
+ var warnedCurrencies = /* @__PURE__ */ new Set();
83
+ function currencyCode(value) {
84
+ const normalized = value.trim().toUpperCase();
85
+ if (!isSupportedCurrency(normalized) && !warnedCurrencies.has(normalized)) {
86
+ warnedCurrencies.add(normalized);
87
+ console.warn(
88
+ `[Cimplify] Unrecognized currency code "${normalized}". It may not format correctly.`
89
+ );
90
+ }
91
+ return normalized;
92
+ }
93
+ var ErrorCode = {
94
+ UNKNOWN_ERROR: "UNKNOWN_ERROR",
95
+ NETWORK_ERROR: "NETWORK_ERROR",
96
+ TIMEOUT: "TIMEOUT",
97
+ UNAUTHORIZED: "UNAUTHORIZED",
98
+ FORBIDDEN: "FORBIDDEN",
99
+ NOT_FOUND: "NOT_FOUND",
100
+ VALIDATION_ERROR: "VALIDATION_ERROR",
101
+ CART_EMPTY: "CART_EMPTY",
102
+ CART_EXPIRED: "CART_EXPIRED",
103
+ CART_NOT_FOUND: "CART_NOT_FOUND",
104
+ ITEM_UNAVAILABLE: "ITEM_UNAVAILABLE",
105
+ VARIANT_NOT_FOUND: "VARIANT_NOT_FOUND",
106
+ VARIANT_OUT_OF_STOCK: "VARIANT_OUT_OF_STOCK",
107
+ ADDON_REQUIRED: "ADDON_REQUIRED",
108
+ ADDON_MAX_EXCEEDED: "ADDON_MAX_EXCEEDED",
109
+ CHECKOUT_VALIDATION_FAILED: "CHECKOUT_VALIDATION_FAILED",
110
+ DELIVERY_ADDRESS_REQUIRED: "DELIVERY_ADDRESS_REQUIRED",
111
+ CUSTOMER_INFO_REQUIRED: "CUSTOMER_INFO_REQUIRED",
112
+ QUOTE_NOT_FOUND: "QUOTE_NOT_FOUND",
113
+ QUOTE_EXPIRED: "QUOTE_EXPIRED",
114
+ QUOTE_CONSUMED: "QUOTE_CONSUMED",
115
+ QUOTE_STORAGE_UNAVAILABLE: "QUOTE_STORAGE_UNAVAILABLE",
116
+ PAYMENT_FAILED: "PAYMENT_FAILED",
117
+ PAYMENT_CANCELLED: "PAYMENT_CANCELLED",
118
+ INSUFFICIENT_FUNDS: "INSUFFICIENT_FUNDS",
119
+ CARD_DECLINED: "CARD_DECLINED",
120
+ INVALID_OTP: "INVALID_OTP",
121
+ OTP_EXPIRED: "OTP_EXPIRED",
122
+ AUTHORIZATION_FAILED: "AUTHORIZATION_FAILED",
123
+ PAYMENT_ACTION_NOT_COMPLETED: "PAYMENT_ACTION_NOT_COMPLETED",
124
+ SLOT_UNAVAILABLE: "SLOT_UNAVAILABLE",
125
+ BOOKING_CONFLICT: "BOOKING_CONFLICT",
126
+ SERVICE_NOT_FOUND: "SERVICE_NOT_FOUND",
127
+ OUT_OF_STOCK: "OUT_OF_STOCK",
128
+ INSUFFICIENT_QUANTITY: "INSUFFICIENT_QUANTITY"
129
+ };
130
+ var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
131
+ function docsUrlForCode(code) {
132
+ return `${DOCS_ERROR_BASE_URL}#${code.toLowerCase().replace(/_/g, "-")}`;
133
+ }
134
+ var ERROR_SUGGESTIONS = {
135
+ UNKNOWN_ERROR: "An unexpected error occurred. Capture the request/response payload and retry with exponential backoff.",
136
+ NETWORK_ERROR: "Check the shopper's connection and retry. If this persists, inspect CORS, DNS, and API reachability.",
137
+ TIMEOUT: "The request exceeded the timeout. Retry once, then poll order status before charging again.",
138
+ UNAUTHORIZED: "Authentication is missing or expired. Ensure a valid access token is set and refresh the session if needed.",
139
+ FORBIDDEN: "The key/session lacks permission for this resource. Verify business ownership and API key scope.",
140
+ NOT_FOUND: "The requested resource does not exist or is not visible in this environment.",
141
+ VALIDATION_ERROR: "One or more fields are invalid. Validate required fields and enum values before retrying.",
142
+ CART_EMPTY: "The cart has no items. Redirect back to menu/catalogue and require at least one line item.",
143
+ CART_EXPIRED: "This cart is no longer active. Recreate a new cart and re-add shopper selections.",
144
+ CART_NOT_FOUND: "Cart could not be located. It may have expired or belongs to a different key/location.",
145
+ ITEM_UNAVAILABLE: "The selected item is unavailable at this location/time. Prompt the shopper to pick an alternative.",
146
+ VARIANT_NOT_FOUND: "The requested variant no longer exists. Refresh product data and require re-selection.",
147
+ VARIANT_OUT_OF_STOCK: "The selected variant is out of stock. Show in-stock variants and block checkout for this line.",
148
+ ADDON_REQUIRED: "A required add-on is missing. Ensure required modifier groups are completed before add-to-cart.",
149
+ ADDON_MAX_EXCEEDED: "Too many add-ons were selected. Enforce max selections client-side before submission.",
150
+ CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
151
+ DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
152
+ CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
153
+ QUOTE_NOT_FOUND: "Quote could not be found. Refresh pricing and create a new quote before checkout.",
154
+ QUOTE_EXPIRED: "Quote has expired. Re-fetch pricing to generate a new quote with a valid expiry window.",
155
+ QUOTE_CONSUMED: "Quote has already been used. Request a fresh quote to prevent duplicate checkout attempts.",
156
+ QUOTE_STORAGE_UNAVAILABLE: "Quote storage is temporarily unavailable. Retry shortly and avoid charging until quote fetch succeeds.",
157
+ PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
158
+ PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
159
+ INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
160
+ CARD_DECLINED: "Card was declined. Ask shopper to retry or switch payment method.",
161
+ INVALID_OTP: "Authorization code is invalid. Let shopper re-enter OTP/PIN and retry.",
162
+ OTP_EXPIRED: "Authorization code expired. Request a new OTP and re-submit authorization.",
163
+ AUTHORIZATION_FAILED: "Additional payment authorization failed. Retry authorization or change payment method.",
164
+ PAYMENT_ACTION_NOT_COMPLETED: "Required payment action was not completed. Resume provider flow and poll for status.",
165
+ SLOT_UNAVAILABLE: "Selected schedule slot is unavailable. Refresh available slots and ask shopper to reselect.",
166
+ BOOKING_CONFLICT: "The requested booking conflicts with an existing reservation. Pick another slot/resource.",
167
+ SERVICE_NOT_FOUND: "Requested service no longer exists. Refresh service catalogue and retry selection.",
168
+ OUT_OF_STOCK: "Inventory is depleted for this item. Remove it or reduce quantity before checkout.",
169
+ INSUFFICIENT_QUANTITY: "Requested quantity exceeds available inventory. Reduce quantity and retry.",
170
+ BUSINESS_ID_REQUIRED: "Business context could not be resolved. Verify the public key and business bootstrap call.",
171
+ INVALID_CART: "Cart is invalid for checkout. Sync cart state, ensure items exist, then retry.",
172
+ ORDER_TYPE_REQUIRED: "Order type is required. Provide one of delivery, pickup, or dine_in before checkout.",
173
+ NO_PAYMENT_ELEMENT: "PaymentElement is required for processCheckout(). Mount it before triggering checkout.",
174
+ PAYMENT_NOT_MOUNTED: "PaymentElement iframe is not mounted. Mount it in the DOM before processCheckout().",
175
+ AUTH_INCOMPLETE: "AuthElement has not completed authentication. Wait for AUTHENTICATED before checkout.",
176
+ AUTH_LOST: "Session was cleared during checkout. Re-authenticate and restart checkout safely.",
177
+ ALREADY_PROCESSING: "Checkout is already in progress. Disable duplicate submits until completion.",
178
+ CHECKOUT_NOT_READY: "Checkout elements are still initializing. Wait for readiness before submit.",
179
+ CANCELLED: "Checkout was cancelled. Preserve cart state and allow shopper to retry.",
180
+ REQUEST_TIMEOUT: "Provider call timed out. Poll payment/order status before issuing another charge attempt.",
181
+ POPUP_BLOCKED: "Browser blocked provider popup. Ask shopper to enable popups and retry.",
182
+ FX_QUOTE_FAILED: "Failed to lock FX quote. Retry currency quote or fallback to base currency."
183
+ };
184
+ var ERROR_HINTS = Object.fromEntries(
185
+ Object.entries(ERROR_SUGGESTIONS).map(([code, suggestion]) => [
186
+ code,
187
+ {
188
+ docs_url: docsUrlForCode(code),
189
+ suggestion
190
+ }
191
+ ])
192
+ );
193
+ var CimplifyError = class extends Error {
194
+ constructor(code, message, retryable = false, docs_url, suggestion) {
195
+ super(message);
196
+ this.code = code;
197
+ this.retryable = retryable;
198
+ this.docs_url = docs_url;
199
+ this.suggestion = suggestion;
200
+ this.name = "CimplifyError";
201
+ }
202
+ get userMessage() {
203
+ return this.message;
204
+ }
205
+ };
206
+ var IdempotencyMismatchError = class extends CimplifyError {
207
+ constructor(message, originalCreatedAt) {
208
+ super("IDEMPOTENCY_MISMATCH", message, false);
209
+ this.originalCreatedAt = originalCreatedAt;
210
+ this.name = "IdempotencyMismatchError";
211
+ }
212
+ };
213
+ function isCimplifyError(error) {
214
+ return error instanceof CimplifyError;
215
+ }
216
+ function isIdempotencyMismatchError(error) {
217
+ return error instanceof IdempotencyMismatchError;
218
+ }
219
+ function getErrorHint(code) {
220
+ return ERROR_HINTS[code];
221
+ }
222
+ function enrichError(error, options = {}) {
223
+ if (error instanceof IdempotencyMismatchError) {
224
+ return error;
225
+ }
226
+ const hint = getErrorHint(error.code);
227
+ const docsUrl = error.docs_url || hint?.docs_url || docsUrlForCode(error.code || ErrorCode.UNKNOWN_ERROR);
228
+ const suggestion = error.suggestion || hint?.suggestion;
229
+ let message = error.message;
230
+ if (options.isTestMode && !message.includes("pk_test_")) {
231
+ message = `${message}
232
+
233
+ \u2139 Your API key is a test-mode key (pk_test_...). Verify test data/session before retrying.`;
234
+ }
235
+ const enriched = new CimplifyError(error.code, message, error.retryable, docsUrl, suggestion);
236
+ enriched.stack = error.stack;
237
+ return enriched;
238
+ }
239
+ function isRetryableError(error) {
240
+ if (isCimplifyError(error)) {
241
+ return error.retryable;
242
+ }
243
+ if (error instanceof Error) {
244
+ const msg = error.message.toLowerCase();
245
+ return msg.includes("network") || msg.includes("timeout") || msg.includes("fetch");
246
+ }
247
+ return false;
248
+ }
249
+
250
+ export { CimplifyError, ERROR_HINTS, ErrorCode, IdempotencyMismatchError, ZERO, __privateAdd, __privateGet, __privateMethod, __privateSet, __privateWrapper, __publicField, currencyCode, enrichError, getErrorHint, isCimplifyError, isIdempotencyMismatchError, isRetryableError, isSupportedCurrency, money, moneyFromNumber };
@@ -1,4 +1,5 @@
1
- import { CimplifyError, currencyCode, ErrorCode, enrichError, isPaymentStatusRequiresAction, normalizeStatusResponse, isPaymentStatusSuccess, isPaymentStatusFailure, getErrorHint } from './chunk-6AZZ6AOF.mjs';
1
+ import { isPaymentStatusRequiresAction, normalizeStatusResponse, isPaymentStatusSuccess, isPaymentStatusFailure } from './chunk-NRT6PVW5.mjs';
2
+ import { CimplifyError, currencyCode, ErrorCode, enrichError, getErrorHint } from './chunk-XPXAZXF2.mjs';
2
3
 
3
4
  // src/types/result.ts
4
5
  function ok(value) {
@@ -0,0 +1,86 @@
1
+ import { C as CimplifyClient } from './client-Dh-bHyhU.mjs';
2
+ import { C as CreateAppOptions, A as AppHandle } from './server-CWpUlLOQ.mjs';
3
+
4
+ /**
5
+ * Test client + fixtures.
6
+ *
7
+ * Spins up an in-process Hono mock and a typed SDK client wired to it
8
+ * via the SDK's first-class `fetch` injection — no global mutation,
9
+ * no port, no MSW. Tests in the same module run in parallel safely.
10
+ *
11
+ * import { createTestClient, fixtures } from "@cimplify/sdk/testing";
12
+ *
13
+ * const handle = createTestClient({ seed: "fashion" });
14
+ * try {
15
+ * const item = await fixtures.addFirstProduct(handle.client);
16
+ * expect(item.product.name).toBeTruthy();
17
+ * } finally {
18
+ * handle.dispose();
19
+ * }
20
+ */
21
+
22
+ interface TestClientHandle {
23
+ /** Typed SDK client routed to the in-process mock. */
24
+ client: CimplifyClient;
25
+ /** Direct access to the mock — registry, deps, request shortcut. */
26
+ mock: AppHandle;
27
+ /** Reset all in-memory state (cart, orders, sessions). Token persists. */
28
+ reset: () => void;
29
+ /** Drop all state + session. Always safe to call multiple times. */
30
+ dispose: () => void;
31
+ }
32
+ /**
33
+ * Create an in-process mock + a typed SDK client wired to it.
34
+ *
35
+ * Each call gets its OWN session token — tests in the same module
36
+ * run safely in parallel because there's no shared global state.
37
+ */
38
+ declare function createTestClient(options?: CreateAppOptions): TestClientHandle;
39
+ interface ProductSummary {
40
+ id: string;
41
+ name: string;
42
+ slug: string;
43
+ type?: string;
44
+ }
45
+ interface AddFirstProductOptions {
46
+ /** Pick a specific product by slug instead of "first". */
47
+ slug?: string;
48
+ /** Auto-pick the first available variant if the product has variants. Default true. */
49
+ withVariant?: boolean;
50
+ }
51
+ interface AddFirstProductResult {
52
+ product: ProductSummary;
53
+ variantId?: string;
54
+ }
55
+ /**
56
+ * Pre-baked fixture functions for common test setup. Use these to keep
57
+ * tests focused on the assertion you care about, not on plumbing.
58
+ */
59
+ declare const fixtures: {
60
+ /**
61
+ * Add the first available product (or a named one) to the cart.
62
+ * Picks the first variant if the product has variants.
63
+ */
64
+ addFirstProduct(client: CimplifyClient, opts?: AddFirstProductOptions): Promise<AddFirstProductResult>;
65
+ /** A minimal valid customer object for checkout. */
66
+ customer(overrides?: Partial<{
67
+ name: string;
68
+ email: string;
69
+ phone: string;
70
+ }>): {
71
+ name: string;
72
+ email: string;
73
+ phone: string;
74
+ };
75
+ /**
76
+ * Run the full guest auth flow (request OTP → verify) and return
77
+ * the new session token. The mock's permissive auth mode echoes
78
+ * the code in `request_otp`, so we don't need to read it.
79
+ */
80
+ authenticate(client: CimplifyClient, contact?: string, code?: string): Promise<{
81
+ token: string;
82
+ customerId: string;
83
+ }>;
84
+ };
85
+
86
+ export { type AddFirstProductOptions as A, type ProductSummary as P, type TestClientHandle as T, type AddFirstProductResult as a, createTestClient as c, fixtures as f };