@mitumba/sdk 5.5.0 → 5.6.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.
package/dist/index.mjs CHANGED
@@ -2740,6 +2740,25 @@ var IamModule = class {
2740
2740
  }
2741
2741
  };
2742
2742
 
2743
+ // src/modules/markets.ts
2744
+ var MarketsModule = class {
2745
+ constructor(client) {
2746
+ this.client = client;
2747
+ }
2748
+ client;
2749
+ /**
2750
+ * List the platform's markets: the countries Mitumba operates in or plans to, with each
2751
+ * market's currency, locale, phone rules, region naming and payment rails.
2752
+ *
2753
+ * Public (no sign-in needed) and cacheable for a few minutes. Read this at runtime instead of
2754
+ * hardcoding a country, and pair it with the helpers exported from the package root
2755
+ * (`formatMoney`, `normalizePhone`, `findMarket`, ...).
2756
+ */
2757
+ async list(options) {
2758
+ return this.client.get("/markets", void 0, options);
2759
+ }
2760
+ };
2761
+
2743
2762
  // src/types/auth.ts
2744
2763
  var TWO_FACTOR_METHOD_TYPES = ["totp", "sms", "email", "passkey"];
2745
2764
 
@@ -2771,6 +2790,103 @@ var DISPUTE_STATUSES = ["open", "seller_responded", "under_review", "resolved_re
2771
2790
  // src/types/wholesale.ts
2772
2791
  var BALE_ORDER_STATUSES = ["pending_payment", "paid", "confirmed", "in_transit", "delivered", "completed", "cancelled"];
2773
2792
 
2793
+ // src/markets.ts
2794
+ var GAP = " ";
2795
+ function group(value, locale) {
2796
+ const rounded = Math.round(Math.abs(value));
2797
+ try {
2798
+ return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(rounded);
2799
+ } catch {
2800
+ return String(rounded).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
2801
+ }
2802
+ }
2803
+ function formatMoney(amount, market) {
2804
+ const { code, locale } = market.currency;
2805
+ if (!Number.isFinite(amount)) return `${code}${GAP}\u2014`;
2806
+ return `${amount < 0 ? "-" : ""}${code}${GAP}${group(amount, locale)}`;
2807
+ }
2808
+ function formatAmount(amount, market) {
2809
+ if (!Number.isFinite(amount)) return "\u2014";
2810
+ return `${amount < 0 ? "-" : ""}${group(amount, market.currency.locale)}`;
2811
+ }
2812
+ function formatMoneyCompact(amount, market) {
2813
+ const absolute = Math.abs(amount);
2814
+ if (!Number.isFinite(amount) || absolute < 1e4) return formatMoney(amount, market);
2815
+ const { code } = market.currency;
2816
+ const sign = amount < 0 ? "-" : "";
2817
+ const trim = (n) => n.toFixed(1).replace(/\.0$/, "");
2818
+ if (absolute < 1e6) {
2819
+ const thousands = absolute / 1e3;
2820
+ if (Math.round(thousands) < 1e3) {
2821
+ return `${sign}${code}${GAP}${thousands < 100 ? trim(thousands) : String(Math.round(thousands))}K`;
2822
+ }
2823
+ }
2824
+ return `${sign}${code}${GAP}${trim(absolute / 1e6)}M`;
2825
+ }
2826
+ function digitsOnly(value) {
2827
+ return value.replace(/\D/g, "");
2828
+ }
2829
+ function normalizePhone(input, market) {
2830
+ const { calling_code, national_length } = market.phone;
2831
+ const callingDigits = digitsOnly(calling_code);
2832
+ const trimmed = input.trim();
2833
+ const digits = digitsOnly(trimmed);
2834
+ if (digits.length === 0) return null;
2835
+ const fits = (national) => national_length.includes(national.length) && !national.startsWith("0");
2836
+ const afterCallingCode = (rest) => {
2837
+ if (fits(rest)) return rest;
2838
+ if (rest.startsWith("0") && fits(rest.slice(1))) return rest.slice(1);
2839
+ return null;
2840
+ };
2841
+ if (trimmed.startsWith("+")) {
2842
+ if (!digits.startsWith(callingDigits)) return null;
2843
+ const national = afterCallingCode(digits.slice(callingDigits.length));
2844
+ return national === null ? null : `+${callingDigits}${national}`;
2845
+ }
2846
+ if (digits.startsWith("0") && fits(digits.slice(1))) return `+${callingDigits}${digits.slice(1)}`;
2847
+ if (digits.startsWith(callingDigits)) {
2848
+ const national = afterCallingCode(digits.slice(callingDigits.length));
2849
+ if (national !== null) return `+${callingDigits}${national}`;
2850
+ }
2851
+ if (fits(digits)) return `+${callingDigits}${digits}`;
2852
+ return null;
2853
+ }
2854
+ function isValidPhone(input, market) {
2855
+ return normalizePhone(input, market) !== null;
2856
+ }
2857
+ function splitNational(e164, market) {
2858
+ const calling = market.phone.calling_code;
2859
+ if (!e164.startsWith(calling)) return null;
2860
+ const national = e164.slice(calling.length);
2861
+ if (!/^\d+$/.test(national) || !market.phone.national_length.includes(national.length)) return null;
2862
+ return { calling, national };
2863
+ }
2864
+ function formatPhone(value, market) {
2865
+ const compact = value.replace(/[^\d+]/g, "");
2866
+ const parts = splitNational(compact, market);
2867
+ if (!parts) return value;
2868
+ const groups = parts.national.match(/\d{1,3}/g) ?? [];
2869
+ if (groups.length > 1 && groups[groups.length - 1].length === 1) {
2870
+ const last = groups.pop();
2871
+ groups[groups.length - 1] += last;
2872
+ }
2873
+ return `${parts.calling}${GAP}${groups.join(GAP)}`;
2874
+ }
2875
+ function maskPhone(value, market) {
2876
+ const compact = value.replace(/[^\d+]/g, "");
2877
+ const parts = splitNational(compact, market);
2878
+ if (!parts || parts.national.length < 7) return value;
2879
+ const head = parts.national.slice(0, 3);
2880
+ const tail = parts.national.slice(-3);
2881
+ return `${parts.calling}${GAP}${head}${GAP}\u2022\u2022\u2022${GAP}${tail}`;
2882
+ }
2883
+ function findMarket(markets, code) {
2884
+ return markets.find((market) => market.code === code);
2885
+ }
2886
+ function activeMarkets(markets) {
2887
+ return markets.filter((market) => market.status === "active");
2888
+ }
2889
+
2774
2890
  // src/share.ts
2775
2891
  var DEFAULT_SHARE_ORIGIN = "https://go.mitumba.africa";
2776
2892
  var ID_PATTERN = /^[0-9a-f]{32}$/;
@@ -2834,6 +2950,7 @@ var MitumbaClient = class {
2834
2950
  reports;
2835
2951
  wholesale;
2836
2952
  iam;
2953
+ markets;
2837
2954
  constructor(config) {
2838
2955
  this.api = new APIClient(config);
2839
2956
  this.auth = new AuthModule(this.api);
@@ -2858,6 +2975,7 @@ var MitumbaClient = class {
2858
2975
  this.reports = new ReportsModule(this.api);
2859
2976
  this.wholesale = new WholesaleModule(this.api);
2860
2977
  this.iam = new IamModule(this.api);
2978
+ this.markets = new MarketsModule(this.api);
2861
2979
  }
2862
2980
  /**
2863
2981
  * Set the access token for authenticated requests.
@@ -2898,6 +3016,6 @@ var MitumbaClient = class {
2898
3016
  }
2899
3017
  };
2900
3018
 
2901
- export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, IamModule, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, OAuthModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, isConsentRequired, isMessagingAPIError, listingShareUrl, storeShareUrl };
3019
+ export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, IamModule, LISTING_STATUSES, ListingsModule, MailerModule, MarketsModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, OAuthModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, activeMarkets, baleShareUrl, createTokenStore, findMarket, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, storeShareUrl };
2902
3020
  //# sourceMappingURL=index.mjs.map
2903
3021
  //# sourceMappingURL=index.mjs.map