@cimplify/sdk 0.6.6 → 0.6.8
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/README.md +19 -0
- package/dist/advanced.d.mts +2 -2
- package/dist/advanced.d.ts +2 -2
- package/dist/advanced.js +228 -101
- package/dist/advanced.mjs +228 -101
- package/dist/{client-CUFdFugo.d.mts → client-D4vA6FY_.d.ts} +40 -34
- package/dist/{client-CjqNbEM6.d.ts → client-FQUyv41r.d.mts} +40 -34
- package/dist/{index-CJ9GkIXf.d.mts → index-DaKJxoEh.d.mts} +13 -12
- package/dist/{index-B5Bj-Ikg.d.ts → index-pztT_bcJ.d.ts} +13 -12
- package/dist/index.d.mts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +315 -131
- package/dist/index.mjs +309 -132
- package/dist/{payment-D-u3asA8.d.mts → payment-Cu75tmUc.d.mts} +34 -8
- package/dist/{payment-D-u3asA8.d.ts → payment-Cu75tmUc.d.ts} +34 -8
- package/dist/react.d.mts +225 -4
- package/dist/react.d.ts +225 -4
- package/dist/react.js +2097 -63
- package/dist/react.mjs +2086 -65
- package/dist/utils.d.mts +2 -2
- package/dist/utils.d.ts +2 -2
- package/dist/utils.js +76 -4
- package/dist/utils.mjs +76 -4
- package/package.json +1 -1
package/dist/utils.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS, n as categorizePaymentError, u as detectMobileMoneyProvider, c as formatMoney, d as formatNumberCompact, f as formatPrice, a as formatPriceAdjustment, b as formatPriceCompact, e as formatProductPrice, i as getBasePrice, g as getCurrencySymbol, k as getDiscountPercentage, h as getDisplayPrice, l as getMarkupPercentage, m as getProductCurrency, j as isOnSale, r as isPaymentStatusFailure, s as isPaymentStatusRequiresAction, t as isPaymentStatusSuccess, o as normalizePaymentResponse, q as normalizeStatusResponse, p as parsePrice } from './index-
|
|
2
|
-
import './payment-
|
|
1
|
+
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS, n as categorizePaymentError, u as detectMobileMoneyProvider, c as formatMoney, d as formatNumberCompact, f as formatPrice, a as formatPriceAdjustment, b as formatPriceCompact, e as formatProductPrice, i as getBasePrice, g as getCurrencySymbol, k as getDiscountPercentage, h as getDisplayPrice, l as getMarkupPercentage, m as getProductCurrency, j as isOnSale, r as isPaymentStatusFailure, s as isPaymentStatusRequiresAction, t as isPaymentStatusSuccess, o as normalizePaymentResponse, q as normalizeStatusResponse, p as parsePrice } from './index-DaKJxoEh.mjs';
|
|
2
|
+
import './payment-Cu75tmUc.mjs';
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS, n as categorizePaymentError, u as detectMobileMoneyProvider, c as formatMoney, d as formatNumberCompact, f as formatPrice, a as formatPriceAdjustment, b as formatPriceCompact, e as formatProductPrice, i as getBasePrice, g as getCurrencySymbol, k as getDiscountPercentage, h as getDisplayPrice, l as getMarkupPercentage, m as getProductCurrency, j as isOnSale, r as isPaymentStatusFailure, s as isPaymentStatusRequiresAction, t as isPaymentStatusSuccess, o as normalizePaymentResponse, q as normalizeStatusResponse, p as parsePrice } from './index-
|
|
2
|
-
import './payment-
|
|
1
|
+
export { C as CURRENCY_SYMBOLS, M as MOBILE_MONEY_PROVIDERS, n as categorizePaymentError, u as detectMobileMoneyProvider, c as formatMoney, d as formatNumberCompact, f as formatPrice, a as formatPriceAdjustment, b as formatPriceCompact, e as formatProductPrice, i as getBasePrice, g as getCurrencySymbol, k as getDiscountPercentage, h as getDisplayPrice, l as getMarkupPercentage, m as getProductCurrency, j as isOnSale, r as isPaymentStatusFailure, s as isPaymentStatusRequiresAction, t as isPaymentStatusSuccess, o as normalizePaymentResponse, q as normalizeStatusResponse, p as parsePrice } from './index-pztT_bcJ.js';
|
|
2
|
+
import './payment-Cu75tmUc.js';
|
package/dist/utils.js
CHANGED
|
@@ -73,8 +73,8 @@ var CURRENCY_SYMBOLS = {
|
|
|
73
73
|
KMF: "CF",
|
|
74
74
|
BIF: "FBu"
|
|
75
75
|
};
|
|
76
|
-
function getCurrencySymbol(
|
|
77
|
-
return CURRENCY_SYMBOLS[
|
|
76
|
+
function getCurrencySymbol(currencyCode2) {
|
|
77
|
+
return CURRENCY_SYMBOLS[currencyCode2.toUpperCase()] || currencyCode2;
|
|
78
78
|
}
|
|
79
79
|
function formatNumberCompact(value, decimals = 1) {
|
|
80
80
|
const absValue = Math.abs(value);
|
|
@@ -205,6 +205,76 @@ function formatProductPrice(product, locale = "en-US") {
|
|
|
205
205
|
return formatPrice(price, currency, locale);
|
|
206
206
|
}
|
|
207
207
|
|
|
208
|
+
// src/types/common.ts
|
|
209
|
+
function money(value) {
|
|
210
|
+
return value;
|
|
211
|
+
}
|
|
212
|
+
function moneyFromNumber(value) {
|
|
213
|
+
return value.toFixed(2);
|
|
214
|
+
}
|
|
215
|
+
function currencyCode(value) {
|
|
216
|
+
return value;
|
|
217
|
+
}
|
|
218
|
+
var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
|
|
219
|
+
function docsUrlForCode(code) {
|
|
220
|
+
return `${DOCS_ERROR_BASE_URL}#${code.toLowerCase().replace(/_/g, "-")}`;
|
|
221
|
+
}
|
|
222
|
+
var ERROR_SUGGESTIONS = {
|
|
223
|
+
UNKNOWN_ERROR: "An unexpected error occurred. Capture the request/response payload and retry with exponential backoff.",
|
|
224
|
+
NETWORK_ERROR: "Check the shopper's connection and retry. If this persists, inspect CORS, DNS, and API reachability.",
|
|
225
|
+
TIMEOUT: "The request exceeded the timeout. Retry once, then poll order status before charging again.",
|
|
226
|
+
UNAUTHORIZED: "Authentication is missing or expired. Ensure a valid access token is set and refresh the session if needed.",
|
|
227
|
+
FORBIDDEN: "The key/session lacks permission for this resource. Verify business ownership and API key scope.",
|
|
228
|
+
NOT_FOUND: "The requested resource does not exist or is not visible in this environment.",
|
|
229
|
+
VALIDATION_ERROR: "One or more fields are invalid. Validate required fields and enum values before retrying.",
|
|
230
|
+
CART_EMPTY: "The cart has no items. Redirect back to menu/catalogue and require at least one line item.",
|
|
231
|
+
CART_EXPIRED: "This cart is no longer active. Recreate a new cart and re-add shopper selections.",
|
|
232
|
+
CART_NOT_FOUND: "Cart could not be located. It may have expired or belongs to a different key/location.",
|
|
233
|
+
ITEM_UNAVAILABLE: "The selected item is unavailable at this location/time. Prompt the shopper to pick an alternative.",
|
|
234
|
+
VARIANT_NOT_FOUND: "The requested variant no longer exists. Refresh product data and require re-selection.",
|
|
235
|
+
VARIANT_OUT_OF_STOCK: "The selected variant is out of stock. Show in-stock variants and block checkout for this line.",
|
|
236
|
+
ADDON_REQUIRED: "A required add-on is missing. Ensure required modifier groups are completed before add-to-cart.",
|
|
237
|
+
ADDON_MAX_EXCEEDED: "Too many add-ons were selected. Enforce max selections client-side before submission.",
|
|
238
|
+
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
239
|
+
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
240
|
+
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
241
|
+
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
242
|
+
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
243
|
+
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
244
|
+
CARD_DECLINED: "Card was declined. Ask shopper to retry or switch payment method.",
|
|
245
|
+
INVALID_OTP: "Authorization code is invalid. Let shopper re-enter OTP/PIN and retry.",
|
|
246
|
+
OTP_EXPIRED: "Authorization code expired. Request a new OTP and re-submit authorization.",
|
|
247
|
+
AUTHORIZATION_FAILED: "Additional payment authorization failed. Retry authorization or change payment method.",
|
|
248
|
+
PAYMENT_ACTION_NOT_COMPLETED: "Required payment action was not completed. Resume provider flow and poll for status.",
|
|
249
|
+
SLOT_UNAVAILABLE: "Selected schedule slot is unavailable. Refresh available slots and ask shopper to reselect.",
|
|
250
|
+
BOOKING_CONFLICT: "The requested booking conflicts with an existing reservation. Pick another slot/resource.",
|
|
251
|
+
SERVICE_NOT_FOUND: "Requested service no longer exists. Refresh service catalogue and retry selection.",
|
|
252
|
+
OUT_OF_STOCK: "Inventory is depleted for this item. Remove it or reduce quantity before checkout.",
|
|
253
|
+
INSUFFICIENT_QUANTITY: "Requested quantity exceeds available inventory. Reduce quantity and retry.",
|
|
254
|
+
BUSINESS_ID_REQUIRED: "Business context could not be resolved. Verify the public key and business bootstrap call.",
|
|
255
|
+
INVALID_CART: "Cart is invalid for checkout. Sync cart state, ensure items exist, then retry.",
|
|
256
|
+
ORDER_TYPE_REQUIRED: "Order type is required. Provide one of delivery, pickup, or dine_in before checkout.",
|
|
257
|
+
NO_PAYMENT_ELEMENT: "PaymentElement is required for processCheckout(). Mount it before triggering checkout.",
|
|
258
|
+
PAYMENT_NOT_MOUNTED: "PaymentElement iframe is not mounted. Mount it in the DOM before processCheckout().",
|
|
259
|
+
AUTH_INCOMPLETE: "AuthElement has not completed authentication. Wait for AUTHENTICATED before checkout.",
|
|
260
|
+
AUTH_LOST: "Session was cleared during checkout. Re-authenticate and restart checkout safely.",
|
|
261
|
+
ALREADY_PROCESSING: "Checkout is already in progress. Disable duplicate submits until completion.",
|
|
262
|
+
CHECKOUT_NOT_READY: "Checkout elements are still initializing. Wait for readiness before submit.",
|
|
263
|
+
CANCELLED: "Checkout was cancelled. Preserve cart state and allow shopper to retry.",
|
|
264
|
+
REQUEST_TIMEOUT: "Provider call timed out. Poll payment/order status before issuing another charge attempt.",
|
|
265
|
+
POPUP_BLOCKED: "Browser blocked provider popup. Ask shopper to enable popups and retry.",
|
|
266
|
+
FX_QUOTE_FAILED: "Failed to lock FX quote. Retry currency quote or fallback to base currency."
|
|
267
|
+
};
|
|
268
|
+
Object.fromEntries(
|
|
269
|
+
Object.entries(ERROR_SUGGESTIONS).map(([code, suggestion]) => [
|
|
270
|
+
code,
|
|
271
|
+
{
|
|
272
|
+
docs_url: docsUrlForCode(code),
|
|
273
|
+
suggestion
|
|
274
|
+
}
|
|
275
|
+
])
|
|
276
|
+
);
|
|
277
|
+
|
|
208
278
|
// src/utils/payment.ts
|
|
209
279
|
function categorizePaymentError(error, errorCode) {
|
|
210
280
|
let message = "An unexpected error occurred during payment processing. Please try again or contact support.";
|
|
@@ -398,6 +468,8 @@ function normalizeStatusResponse(response) {
|
|
|
398
468
|
}
|
|
399
469
|
const res = response;
|
|
400
470
|
const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
|
|
471
|
+
const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : void 0;
|
|
472
|
+
const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? currencyCode(res.currency) : void 0;
|
|
401
473
|
const paidValue = res.paid === true;
|
|
402
474
|
const derivedPaid = paidValue || [
|
|
403
475
|
"success",
|
|
@@ -410,8 +482,8 @@ function normalizeStatusResponse(response) {
|
|
|
410
482
|
return {
|
|
411
483
|
status: normalizedStatus,
|
|
412
484
|
paid: derivedPaid,
|
|
413
|
-
amount:
|
|
414
|
-
currency:
|
|
485
|
+
amount: normalizedAmount,
|
|
486
|
+
currency: normalizedCurrency,
|
|
415
487
|
reference: res.reference,
|
|
416
488
|
message: res.message || ""
|
|
417
489
|
};
|
package/dist/utils.mjs
CHANGED
|
@@ -71,8 +71,8 @@ var CURRENCY_SYMBOLS = {
|
|
|
71
71
|
KMF: "CF",
|
|
72
72
|
BIF: "FBu"
|
|
73
73
|
};
|
|
74
|
-
function getCurrencySymbol(
|
|
75
|
-
return CURRENCY_SYMBOLS[
|
|
74
|
+
function getCurrencySymbol(currencyCode2) {
|
|
75
|
+
return CURRENCY_SYMBOLS[currencyCode2.toUpperCase()] || currencyCode2;
|
|
76
76
|
}
|
|
77
77
|
function formatNumberCompact(value, decimals = 1) {
|
|
78
78
|
const absValue = Math.abs(value);
|
|
@@ -203,6 +203,76 @@ function formatProductPrice(product, locale = "en-US") {
|
|
|
203
203
|
return formatPrice(price, currency, locale);
|
|
204
204
|
}
|
|
205
205
|
|
|
206
|
+
// src/types/common.ts
|
|
207
|
+
function money(value) {
|
|
208
|
+
return value;
|
|
209
|
+
}
|
|
210
|
+
function moneyFromNumber(value) {
|
|
211
|
+
return value.toFixed(2);
|
|
212
|
+
}
|
|
213
|
+
function currencyCode(value) {
|
|
214
|
+
return value;
|
|
215
|
+
}
|
|
216
|
+
var DOCS_ERROR_BASE_URL = "https://docs.cimplify.io/reference/error-codes";
|
|
217
|
+
function docsUrlForCode(code) {
|
|
218
|
+
return `${DOCS_ERROR_BASE_URL}#${code.toLowerCase().replace(/_/g, "-")}`;
|
|
219
|
+
}
|
|
220
|
+
var ERROR_SUGGESTIONS = {
|
|
221
|
+
UNKNOWN_ERROR: "An unexpected error occurred. Capture the request/response payload and retry with exponential backoff.",
|
|
222
|
+
NETWORK_ERROR: "Check the shopper's connection and retry. If this persists, inspect CORS, DNS, and API reachability.",
|
|
223
|
+
TIMEOUT: "The request exceeded the timeout. Retry once, then poll order status before charging again.",
|
|
224
|
+
UNAUTHORIZED: "Authentication is missing or expired. Ensure a valid access token is set and refresh the session if needed.",
|
|
225
|
+
FORBIDDEN: "The key/session lacks permission for this resource. Verify business ownership and API key scope.",
|
|
226
|
+
NOT_FOUND: "The requested resource does not exist or is not visible in this environment.",
|
|
227
|
+
VALIDATION_ERROR: "One or more fields are invalid. Validate required fields and enum values before retrying.",
|
|
228
|
+
CART_EMPTY: "The cart has no items. Redirect back to menu/catalogue and require at least one line item.",
|
|
229
|
+
CART_EXPIRED: "This cart is no longer active. Recreate a new cart and re-add shopper selections.",
|
|
230
|
+
CART_NOT_FOUND: "Cart could not be located. It may have expired or belongs to a different key/location.",
|
|
231
|
+
ITEM_UNAVAILABLE: "The selected item is unavailable at this location/time. Prompt the shopper to pick an alternative.",
|
|
232
|
+
VARIANT_NOT_FOUND: "The requested variant no longer exists. Refresh product data and require re-selection.",
|
|
233
|
+
VARIANT_OUT_OF_STOCK: "The selected variant is out of stock. Show in-stock variants and block checkout for this line.",
|
|
234
|
+
ADDON_REQUIRED: "A required add-on is missing. Ensure required modifier groups are completed before add-to-cart.",
|
|
235
|
+
ADDON_MAX_EXCEEDED: "Too many add-ons were selected. Enforce max selections client-side before submission.",
|
|
236
|
+
CHECKOUT_VALIDATION_FAILED: "Checkout payload failed validation. Verify customer, order type, and address fields are complete.",
|
|
237
|
+
DELIVERY_ADDRESS_REQUIRED: "Delivery orders require an address. Collect and pass address info before processing checkout.",
|
|
238
|
+
CUSTOMER_INFO_REQUIRED: "Customer details are required. Ensure name/email/phone are available before checkout.",
|
|
239
|
+
PAYMENT_FAILED: "Payment provider rejected or failed processing. Show retry/change-method options to the shopper.",
|
|
240
|
+
PAYMENT_CANCELLED: "Payment was cancelled by the shopper or provider flow. Allow a safe retry path.",
|
|
241
|
+
INSUFFICIENT_FUNDS: "Payment method has insufficient funds. Prompt shopper to use another method.",
|
|
242
|
+
CARD_DECLINED: "Card was declined. Ask shopper to retry or switch payment method.",
|
|
243
|
+
INVALID_OTP: "Authorization code is invalid. Let shopper re-enter OTP/PIN and retry.",
|
|
244
|
+
OTP_EXPIRED: "Authorization code expired. Request a new OTP and re-submit authorization.",
|
|
245
|
+
AUTHORIZATION_FAILED: "Additional payment authorization failed. Retry authorization or change payment method.",
|
|
246
|
+
PAYMENT_ACTION_NOT_COMPLETED: "Required payment action was not completed. Resume provider flow and poll for status.",
|
|
247
|
+
SLOT_UNAVAILABLE: "Selected schedule slot is unavailable. Refresh available slots and ask shopper to reselect.",
|
|
248
|
+
BOOKING_CONFLICT: "The requested booking conflicts with an existing reservation. Pick another slot/resource.",
|
|
249
|
+
SERVICE_NOT_FOUND: "Requested service no longer exists. Refresh service catalogue and retry selection.",
|
|
250
|
+
OUT_OF_STOCK: "Inventory is depleted for this item. Remove it or reduce quantity before checkout.",
|
|
251
|
+
INSUFFICIENT_QUANTITY: "Requested quantity exceeds available inventory. Reduce quantity and retry.",
|
|
252
|
+
BUSINESS_ID_REQUIRED: "Business context could not be resolved. Verify the public key and business bootstrap call.",
|
|
253
|
+
INVALID_CART: "Cart is invalid for checkout. Sync cart state, ensure items exist, then retry.",
|
|
254
|
+
ORDER_TYPE_REQUIRED: "Order type is required. Provide one of delivery, pickup, or dine_in before checkout.",
|
|
255
|
+
NO_PAYMENT_ELEMENT: "PaymentElement is required for processCheckout(). Mount it before triggering checkout.",
|
|
256
|
+
PAYMENT_NOT_MOUNTED: "PaymentElement iframe is not mounted. Mount it in the DOM before processCheckout().",
|
|
257
|
+
AUTH_INCOMPLETE: "AuthElement has not completed authentication. Wait for AUTHENTICATED before checkout.",
|
|
258
|
+
AUTH_LOST: "Session was cleared during checkout. Re-authenticate and restart checkout safely.",
|
|
259
|
+
ALREADY_PROCESSING: "Checkout is already in progress. Disable duplicate submits until completion.",
|
|
260
|
+
CHECKOUT_NOT_READY: "Checkout elements are still initializing. Wait for readiness before submit.",
|
|
261
|
+
CANCELLED: "Checkout was cancelled. Preserve cart state and allow shopper to retry.",
|
|
262
|
+
REQUEST_TIMEOUT: "Provider call timed out. Poll payment/order status before issuing another charge attempt.",
|
|
263
|
+
POPUP_BLOCKED: "Browser blocked provider popup. Ask shopper to enable popups and retry.",
|
|
264
|
+
FX_QUOTE_FAILED: "Failed to lock FX quote. Retry currency quote or fallback to base currency."
|
|
265
|
+
};
|
|
266
|
+
Object.fromEntries(
|
|
267
|
+
Object.entries(ERROR_SUGGESTIONS).map(([code, suggestion]) => [
|
|
268
|
+
code,
|
|
269
|
+
{
|
|
270
|
+
docs_url: docsUrlForCode(code),
|
|
271
|
+
suggestion
|
|
272
|
+
}
|
|
273
|
+
])
|
|
274
|
+
);
|
|
275
|
+
|
|
206
276
|
// src/utils/payment.ts
|
|
207
277
|
function categorizePaymentError(error, errorCode) {
|
|
208
278
|
let message = "An unexpected error occurred during payment processing. Please try again or contact support.";
|
|
@@ -396,6 +466,8 @@ function normalizeStatusResponse(response) {
|
|
|
396
466
|
}
|
|
397
467
|
const res = response;
|
|
398
468
|
const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
|
|
469
|
+
const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : void 0;
|
|
470
|
+
const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? currencyCode(res.currency) : void 0;
|
|
399
471
|
const paidValue = res.paid === true;
|
|
400
472
|
const derivedPaid = paidValue || [
|
|
401
473
|
"success",
|
|
@@ -408,8 +480,8 @@ function normalizeStatusResponse(response) {
|
|
|
408
480
|
return {
|
|
409
481
|
status: normalizedStatus,
|
|
410
482
|
paid: derivedPaid,
|
|
411
|
-
amount:
|
|
412
|
-
currency:
|
|
483
|
+
amount: normalizedAmount,
|
|
484
|
+
currency: normalizedCurrency,
|
|
413
485
|
reference: res.reference,
|
|
414
486
|
message: res.message || ""
|
|
415
487
|
};
|