@cimplify/sdk 0.102.0 → 0.103.0

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 (68) hide show
  1. package/dist/advanced.d.mts +3 -3
  2. package/dist/advanced.d.ts +3 -3
  3. package/dist/advanced.js +23 -22
  4. package/dist/advanced.mjs +4 -3
  5. package/dist/{chunk-DCMXUKDQ.mjs → chunk-C2JSNJUC.mjs} +404 -95
  6. package/dist/chunk-CNN7Z2IP.js +125 -0
  7. package/dist/{chunk-DKLHCZ5M.mjs → chunk-GERXZQSX.mjs} +487 -11
  8. package/dist/chunk-GOHSXBKW.mjs +105 -0
  9. package/dist/{chunk-4KNFBPV2.mjs → chunk-H7ACMHM3.mjs} +32 -14
  10. package/dist/{chunk-Z3K2D3TE.mjs → chunk-J6PNHDHL.mjs} +453 -483
  11. package/dist/{chunk-NIOUSKQQ.js → chunk-JG5CQNCB.js} +5 -0
  12. package/dist/{chunk-YER7DIOM.js → chunk-JSWJ4XDE.js} +471 -519
  13. package/dist/{chunk-DLW3RWRK.mjs → chunk-M4URVKHE.mjs} +46 -12
  14. package/dist/{chunk-WMEC5JWN.js → chunk-NNG6IFFX.js} +50 -13
  15. package/dist/{chunk-LOWSMGRT.js → chunk-QOWPGS7Z.js} +34 -16
  16. package/dist/{chunk-YDA46OZ6.js → chunk-R6OLQ33I.js} +560 -80
  17. package/dist/{chunk-EAZGA7LD.js → chunk-VIL6IQCG.js} +406 -97
  18. package/dist/{chunk-O3YUHLZL.mjs → chunk-VNPEYLB2.mjs} +5 -0
  19. package/dist/{client-B40KFazg.d.ts → client-BfpNjJ_a.d.mts} +90 -299
  20. package/dist/{client-BizGfqB7.d.mts → client-DHBwvh7U.d.ts} +90 -299
  21. package/dist/{client-BdErclfU.d.mts → client-DpqRobY9.d.mts} +2 -2
  22. package/dist/{client-nsiMwuC1.d.ts → client-Dqg2mc-7.d.ts} +2 -2
  23. package/dist/{index-DpmnI__D.d.mts → index-C8uDqLwJ.d.ts} +14 -4
  24. package/dist/{index-nEyXWIyR.d.ts → index-e2y6AK70.d.mts} +14 -4
  25. package/dist/index.d.mts +81 -8
  26. package/dist/index.d.ts +81 -8
  27. package/dist/index.js +202 -169
  28. package/dist/index.mjs +6 -5
  29. package/dist/link-cuNVYc2s.d.mts +297 -0
  30. package/dist/link-cuNVYc2s.d.ts +297 -0
  31. package/dist/mock/cli.mjs +410 -94
  32. package/dist/mock/library.js +410 -94
  33. package/dist/mock/library.mjs +410 -94
  34. package/dist/mock/msw.js +410 -94
  35. package/dist/mock/msw.mjs +410 -94
  36. package/dist/{product-Byf0unSy.d.mts → payment-H5LoIvXU.d.mts} +189 -7
  37. package/dist/{product-Byf0unSy.d.ts → payment-H5LoIvXU.d.ts} +189 -7
  38. package/dist/{price-CS4E5zLS.d.mts → price-BvePgDXe.d.mts} +1 -1
  39. package/dist/{price-BstChV9a.d.ts → price-C2RqscMY.d.ts} +1 -1
  40. package/dist/react.d.mts +4 -4
  41. package/dist/react.d.ts +4 -4
  42. package/dist/react.js +141 -140
  43. package/dist/react.mjs +5 -4
  44. package/dist/{server-DqbZh8Bk.d.mts → server-C7FyLdrz.d.mts} +11 -9
  45. package/dist/{server-Cj40R2ZD.d.ts → server-DoXIpSd7.d.ts} +11 -9
  46. package/dist/server.d.mts +4 -4
  47. package/dist/server.d.ts +4 -4
  48. package/dist/server.js +11 -10
  49. package/dist/server.mjs +5 -4
  50. package/dist/testing/msw.d.mts +2 -2
  51. package/dist/testing/msw.d.ts +2 -2
  52. package/dist/testing/msw.js +4 -3
  53. package/dist/testing/msw.mjs +3 -2
  54. package/dist/testing/suite.d.mts +6 -6
  55. package/dist/testing/suite.d.ts +6 -6
  56. package/dist/testing/suite.js +26 -25
  57. package/dist/testing/suite.mjs +7 -6
  58. package/dist/testing.d.mts +154 -55
  59. package/dist/testing.d.ts +154 -55
  60. package/dist/testing.js +83 -82
  61. package/dist/testing.mjs +8 -7
  62. package/dist/utils.d.mts +4 -4
  63. package/dist/utils.d.ts +4 -4
  64. package/dist/utils.js +37 -29
  65. package/dist/utils.mjs +2 -2
  66. package/package.json +7 -1
  67. package/dist/payment-l0rkieEQ.d.mts +0 -113
  68. package/dist/payment-vzNnIi1n.d.ts +0 -113
@@ -1,4 +1,4 @@
1
- import { moneyFromNumber, money } from './chunk-O3YUHLZL.mjs';
1
+ import { moneyFromNumber, money } from './chunk-VNPEYLB2.mjs';
2
2
 
3
3
  // src/utils/price.ts
4
4
  var CURRENCY_SYMBOLS = {
@@ -378,21 +378,22 @@ var PAYMENT_SUCCESS_STATUSES = /* @__PURE__ */ new Set([
378
378
  "paid",
379
379
  "captured",
380
380
  "completed",
381
- "authorized",
382
381
  "not_required"
383
382
  ]);
384
- var PAYMENT_FAILURE_STATUSES = /* @__PURE__ */ new Set([
383
+ var PAYMENT_TERMINAL_FAILURE_STATUSES = [
385
384
  "failed",
386
- "declined",
387
385
  "cancelled",
388
386
  "voided",
389
- "error",
390
- "abandoned"
391
- ]);
387
+ "abandoned",
388
+ "refunded",
389
+ "refund_pending",
390
+ "reversed",
391
+ "disputed"
392
+ ];
393
+ var PAYMENT_FAILURE_STATUSES = new Set(PAYMENT_TERMINAL_FAILURE_STATUSES);
392
394
  var PAYMENT_REQUIRES_ACTION_STATUSES = /* @__PURE__ */ new Set([
393
395
  "requires_action",
394
- "requires_payment_method",
395
- "requires_capture"
396
+ "requires_payment_method"
396
397
  ]);
397
398
  var PAYMENT_STATUS_ALIAS_MAP = {
398
399
  ok: "captured",
@@ -474,7 +475,7 @@ function normalizeStatusResponse(response) {
474
475
  const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
475
476
  const normalizedAmount = typeof res.amount === "string" ? money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? moneyFromNumber(res.amount) : moneyFromNumber(0);
476
477
  const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? res.currency : "";
477
- const paidValue = res.paid === true;
478
+ const paidValue = res.paid === true && normalizedStatus !== "authorized" && !PAYMENT_REQUIRES_ACTION_STATUSES.has(normalizedStatus) && !PAYMENT_FAILURE_STATUSES.has(normalizedStatus);
478
479
  const derivedPaid = paidValue || PAYMENT_SUCCESS_STATUSES.has(normalizedStatus);
479
480
  return {
480
481
  status: normalizedStatus,
@@ -486,10 +487,43 @@ function normalizeStatusResponse(response) {
486
487
  };
487
488
  }
488
489
  var MOBILE_MONEY_PROVIDERS = {
489
- mtn: { name: "MTN Mobile Money", prefix: ["024", "025", "053", "054", "055", "059"] },
490
+ mtn: {
491
+ name: "MTN Mobile Money",
492
+ prefix: ["024", "025", "053", "054", "055", "059"]
493
+ },
490
494
  vodafone: { name: "Telecel Cash", prefix: ["020", "050"] },
491
495
  airtel: { name: "AirtelTigo Money", prefix: ["026", "027", "056", "057"] }
492
496
  };
497
+ var MOBILE_MONEY_PROVIDER_ALIASES = {
498
+ mtn: "mtn",
499
+ mtnmomo: "mtn",
500
+ vod: "telecel",
501
+ vodafone: "telecel",
502
+ telecel: "telecel",
503
+ atl: "airteltigo",
504
+ airtel: "airteltigo",
505
+ tigo: "airteltigo",
506
+ airteltigo: "airteltigo",
507
+ mpesa: "mpesa"
508
+ };
509
+ function canonicalMobileMoneyProvider(provider) {
510
+ if (typeof provider !== "string") return null;
511
+ const normalized = provider.trim().toLowerCase().replace(/[\s_-]+/g, "");
512
+ return MOBILE_MONEY_PROVIDER_ALIASES[normalized] ?? null;
513
+ }
514
+ var LOOPBACK_AUTHORIZATION_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
515
+ function paymentAuthorizationUrl(value) {
516
+ if (typeof value !== "string" || !value.trim()) return null;
517
+ try {
518
+ const url = new URL(value);
519
+ if (url.protocol === "https:") return url.toString();
520
+ if (url.protocol === "http:" && LOOPBACK_AUTHORIZATION_HOSTS.has(url.hostname)) {
521
+ return url.toString();
522
+ }
523
+ } catch {
524
+ }
525
+ return null;
526
+ }
493
527
  function detectMobileMoneyProvider(phoneNumber) {
494
528
  const cleaned = phoneNumber.replace(/\D/g, "");
495
529
  const networkCode = cleaned.slice(-9, -7);
@@ -501,4 +535,4 @@ function detectMobileMoneyProvider(phoneNumber) {
501
535
  return null;
502
536
  }
503
537
 
504
- export { CURRENCY_SYMBOLS, MOBILE_MONEY_PROVIDERS, categorizePaymentError, detectMobileMoneyProvider, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatPriceRange, formatPriceWithTax, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getPriceRange, getProductCurrency, getTaxAmount, getUnitPriceAtQuantity, getVariantUnitPrice, hasTaxInfo, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isTaxInclusive, normalizePaymentResponse, normalizeStatusResponse, parsePrice };
538
+ export { CURRENCY_SYMBOLS, MOBILE_MONEY_PROVIDERS, PAYMENT_TERMINAL_FAILURE_STATUSES, canonicalMobileMoneyProvider, categorizePaymentError, detectMobileMoneyProvider, formatMoney, formatNumberCompact, formatPrice, formatPriceAdjustment, formatPriceCompact, formatPriceRange, formatPriceWithTax, formatProductPrice, getBasePrice, getCurrencySymbol, getDiscountPercentage, getDisplayPrice, getMarkupPercentage, getPriceRange, getProductCurrency, getTaxAmount, getUnitPriceAtQuantity, getVariantUnitPrice, hasTaxInfo, isOnSale, isPaymentStatusFailure, isPaymentStatusRequiresAction, isPaymentStatusSuccess, isTaxInclusive, normalizePaymentResponse, normalizeStatusResponse, parsePrice, paymentAuthorizationUrl };
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var chunkNIOUSKQQ_js = require('./chunk-NIOUSKQQ.js');
3
+ var chunkJG5CQNCB_js = require('./chunk-JG5CQNCB.js');
4
4
 
5
5
  // src/utils/price.ts
6
6
  var CURRENCY_SYMBOLS = {
@@ -380,21 +380,22 @@ var PAYMENT_SUCCESS_STATUSES = /* @__PURE__ */ new Set([
380
380
  "paid",
381
381
  "captured",
382
382
  "completed",
383
- "authorized",
384
383
  "not_required"
385
384
  ]);
386
- var PAYMENT_FAILURE_STATUSES = /* @__PURE__ */ new Set([
385
+ var PAYMENT_TERMINAL_FAILURE_STATUSES = [
387
386
  "failed",
388
- "declined",
389
387
  "cancelled",
390
388
  "voided",
391
- "error",
392
- "abandoned"
393
- ]);
389
+ "abandoned",
390
+ "refunded",
391
+ "refund_pending",
392
+ "reversed",
393
+ "disputed"
394
+ ];
395
+ var PAYMENT_FAILURE_STATUSES = new Set(PAYMENT_TERMINAL_FAILURE_STATUSES);
394
396
  var PAYMENT_REQUIRES_ACTION_STATUSES = /* @__PURE__ */ new Set([
395
397
  "requires_action",
396
- "requires_payment_method",
397
- "requires_capture"
398
+ "requires_payment_method"
398
399
  ]);
399
400
  var PAYMENT_STATUS_ALIAS_MAP = {
400
401
  ok: "captured",
@@ -467,16 +468,16 @@ function normalizeStatusResponse(response) {
467
468
  return {
468
469
  status: "pending",
469
470
  paid: false,
470
- amount: chunkNIOUSKQQ_js.moneyFromNumber(0),
471
+ amount: chunkJG5CQNCB_js.moneyFromNumber(0),
471
472
  currency: "",
472
473
  message: "No status available"
473
474
  };
474
475
  }
475
476
  const res = response;
476
477
  const normalizedStatus = normalizePaymentStatusValue(res.status ?? void 0);
477
- const normalizedAmount = typeof res.amount === "string" ? chunkNIOUSKQQ_js.money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? chunkNIOUSKQQ_js.moneyFromNumber(res.amount) : chunkNIOUSKQQ_js.moneyFromNumber(0);
478
+ const normalizedAmount = typeof res.amount === "string" ? chunkJG5CQNCB_js.money(res.amount) : typeof res.amount === "number" && Number.isFinite(res.amount) ? chunkJG5CQNCB_js.moneyFromNumber(res.amount) : chunkJG5CQNCB_js.moneyFromNumber(0);
478
479
  const normalizedCurrency = typeof res.currency === "string" && res.currency.trim().length > 0 ? res.currency : "";
479
- const paidValue = res.paid === true;
480
+ const paidValue = res.paid === true && normalizedStatus !== "authorized" && !PAYMENT_REQUIRES_ACTION_STATUSES.has(normalizedStatus) && !PAYMENT_FAILURE_STATUSES.has(normalizedStatus);
480
481
  const derivedPaid = paidValue || PAYMENT_SUCCESS_STATUSES.has(normalizedStatus);
481
482
  return {
482
483
  status: normalizedStatus,
@@ -488,10 +489,43 @@ function normalizeStatusResponse(response) {
488
489
  };
489
490
  }
490
491
  var MOBILE_MONEY_PROVIDERS = {
491
- mtn: { name: "MTN Mobile Money", prefix: ["024", "025", "053", "054", "055", "059"] },
492
+ mtn: {
493
+ name: "MTN Mobile Money",
494
+ prefix: ["024", "025", "053", "054", "055", "059"]
495
+ },
492
496
  vodafone: { name: "Telecel Cash", prefix: ["020", "050"] },
493
497
  airtel: { name: "AirtelTigo Money", prefix: ["026", "027", "056", "057"] }
494
498
  };
499
+ var MOBILE_MONEY_PROVIDER_ALIASES = {
500
+ mtn: "mtn",
501
+ mtnmomo: "mtn",
502
+ vod: "telecel",
503
+ vodafone: "telecel",
504
+ telecel: "telecel",
505
+ atl: "airteltigo",
506
+ airtel: "airteltigo",
507
+ tigo: "airteltigo",
508
+ airteltigo: "airteltigo",
509
+ mpesa: "mpesa"
510
+ };
511
+ function canonicalMobileMoneyProvider(provider) {
512
+ if (typeof provider !== "string") return null;
513
+ const normalized = provider.trim().toLowerCase().replace(/[\s_-]+/g, "");
514
+ return MOBILE_MONEY_PROVIDER_ALIASES[normalized] ?? null;
515
+ }
516
+ var LOOPBACK_AUTHORIZATION_HOSTS = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
517
+ function paymentAuthorizationUrl(value) {
518
+ if (typeof value !== "string" || !value.trim()) return null;
519
+ try {
520
+ const url = new URL(value);
521
+ if (url.protocol === "https:") return url.toString();
522
+ if (url.protocol === "http:" && LOOPBACK_AUTHORIZATION_HOSTS.has(url.hostname)) {
523
+ return url.toString();
524
+ }
525
+ } catch {
526
+ }
527
+ return null;
528
+ }
495
529
  function detectMobileMoneyProvider(phoneNumber) {
496
530
  const cleaned = phoneNumber.replace(/\D/g, "");
497
531
  const networkCode = cleaned.slice(-9, -7);
@@ -505,6 +539,8 @@ function detectMobileMoneyProvider(phoneNumber) {
505
539
 
506
540
  exports.CURRENCY_SYMBOLS = CURRENCY_SYMBOLS;
507
541
  exports.MOBILE_MONEY_PROVIDERS = MOBILE_MONEY_PROVIDERS;
542
+ exports.PAYMENT_TERMINAL_FAILURE_STATUSES = PAYMENT_TERMINAL_FAILURE_STATUSES;
543
+ exports.canonicalMobileMoneyProvider = canonicalMobileMoneyProvider;
508
544
  exports.categorizePaymentError = categorizePaymentError;
509
545
  exports.detectMobileMoneyProvider = detectMobileMoneyProvider;
510
546
  exports.formatMoney = formatMoney;
@@ -534,3 +570,4 @@ exports.isTaxInclusive = isTaxInclusive;
534
570
  exports.normalizePaymentResponse = normalizePaymentResponse;
535
571
  exports.normalizeStatusResponse = normalizeStatusResponse;
536
572
  exports.parsePrice = parsePrice;
573
+ exports.paymentAuthorizationUrl = paymentAuthorizationUrl;
@@ -1,7 +1,7 @@
1
1
  'use strict';
2
2
 
3
- var chunkEAZGA7LD_js = require('./chunk-EAZGA7LD.js');
4
- var chunkYDA46OZ6_js = require('./chunk-YDA46OZ6.js');
3
+ var chunkVIL6IQCG_js = require('./chunk-VIL6IQCG.js');
4
+ var chunkR6OLQ33I_js = require('./chunk-R6OLQ33I.js');
5
5
  var zod = require('zod');
6
6
 
7
7
  var cimplifyRegistry = zod.z.registry();
@@ -556,31 +556,49 @@ var CheckoutBodySchema = registerSchema(
556
556
  }
557
557
  );
558
558
  var assertCheckoutBody = makeAssertion(CheckoutBodySchema, "checkoutBody");
559
- var AuthorizationTypeSchema = zod.z.enum(["otp", "pin", "phone", "birthday", "address"]);
559
+ var AuthorizationTypeSchema = zod.z.union([
560
+ zod.z.enum(["otp", "pin", "phone", "birthday"]),
561
+ zod.z.object({
562
+ address: zod.z.object({
563
+ address: zod.z.string(),
564
+ city: zod.z.string(),
565
+ state: zod.z.string(),
566
+ zip_code: zod.z.string()
567
+ })
568
+ })
569
+ ]);
560
570
  var NextActionSchema = zod.z.discriminatedUnion("type", [
561
571
  zod.z.object({ type: zod.z.literal("none") }),
572
+ zod.z.object({
573
+ type: zod.z.literal("card_popup"),
574
+ provider: zod.z.string().min(1),
575
+ client_secret: zod.z.string().min(1),
576
+ public_key: zod.z.string().min(1)
577
+ }),
562
578
  zod.z.object({ type: zod.z.literal("redirect"), authorization_url: zod.z.string() }),
563
579
  zod.z.object({
564
580
  type: zod.z.literal("authorization"),
565
- authorization_type: zod.z.string(),
566
- display_text: zod.z.string().optional()
567
- })
581
+ authorization_type: AuthorizationTypeSchema,
582
+ display_text: zod.z.string().nullish()
583
+ }),
584
+ zod.z.object({ type: zod.z.literal("poll") })
568
585
  ]);
569
586
  var CheckoutResponseSchema = registerSchema(
570
587
  zod.z.looseObject({
571
588
  order_id: zod.z.string().min(1),
572
589
  order_number: zod.z.string().min(1),
590
+ payment_id: zod.z.string().nullish(),
573
591
  payment_status: zod.z.string().min(1),
574
- payment_reference: zod.z.string().optional(),
592
+ payment_reference: zod.z.string().nullish(),
575
593
  requires_authorization: zod.z.boolean(),
576
- authorization_type: AuthorizationTypeSchema.optional(),
594
+ authorization_type: AuthorizationTypeSchema.nullish(),
577
595
  next_action: NextActionSchema,
578
- provider: zod.z.string().optional(),
579
- authorization_url: zod.z.string().optional(),
580
- display_text: zod.z.string().optional(),
581
- bill_token: zod.z.string().optional(),
582
- client_secret: zod.z.string().optional(),
583
- public_key: zod.z.string().optional()
596
+ provider: zod.z.string().nullish(),
597
+ authorization_url: zod.z.string().nullish(),
598
+ display_text: zod.z.string().nullish(),
599
+ bill_token: zod.z.string().nullish(),
600
+ client_secret: zod.z.string().nullish(),
601
+ public_key: zod.z.string().nullish()
584
602
  }),
585
603
  {
586
604
  id: "CheckoutResponse",
@@ -607,7 +625,7 @@ async function toForwardedRequest(input, init) {
607
625
  };
608
626
  }
609
627
  function createTestClient(options = {}) {
610
- const mock = chunkEAZGA7LD_js.createMockApp(options);
628
+ const mock = chunkVIL6IQCG_js.createMockApp(options);
611
629
  let sessionToken;
612
630
  const fetchImpl = async (input, init) => {
613
631
  const url = typeof input === "string" ? input : input instanceof URL ? input.toString() : input.url;
@@ -626,7 +644,7 @@ function createTestClient(options = {}) {
626
644
  if (echoed) sessionToken = echoed;
627
645
  return res;
628
646
  };
629
- const client = chunkYDA46OZ6_js.createCimplifyClient({
647
+ const client = chunkR6OLQ33I_js.createCimplifyClient({
630
648
  baseUrl: TEST_BASE_URL,
631
649
  // Link mock lives at /v1/link on the same Hono app, so point the SDK's
632
650
  // separate Link transport at the same TEST_BASE_URL.