@mitumba/sdk 5.5.0 → 5.7.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
@@ -2686,6 +2686,20 @@ var IamModule = class {
2686
2686
  async finishPasskeyEnrollment(methodId, credential, options) {
2687
2687
  return this.client.post(`/auth/iam/2fa/methods/${encodeURIComponent(methodId)}/passkey/finish`, credential, options);
2688
2688
  }
2689
+ /**
2690
+ * Replace this IAM principal's recovery codes after re-proving the password. The previous set
2691
+ * stops working immediately; the returned codes are shown once and never retrievable again.
2692
+ */
2693
+ async regenerateBackupCodes(password, options) {
2694
+ return this.client.post("/auth/iam/2fa/backup-codes/regenerate", { password }, options);
2695
+ }
2696
+ /**
2697
+ * Remove one of this principal's own second-factor methods after re-proving the password.
2698
+ * Refused with `last_factor` (409) when it is the only verified factor left.
2699
+ */
2700
+ async deleteMethod(methodId, password, options) {
2701
+ return this.client.delete(`/auth/iam/2fa/methods/${encodeURIComponent(methodId)}`, { password }, options);
2702
+ }
2689
2703
  /** List organizations the current root/global operator may administer. */
2690
2704
  async listOrganizations(options) {
2691
2705
  return this.client.get("/auth/orgs", void 0, options);
@@ -2740,6 +2754,25 @@ var IamModule = class {
2740
2754
  }
2741
2755
  };
2742
2756
 
2757
+ // src/modules/markets.ts
2758
+ var MarketsModule = class {
2759
+ constructor(client) {
2760
+ this.client = client;
2761
+ }
2762
+ client;
2763
+ /**
2764
+ * List the platform's markets: the countries Mitumba operates in or plans to, with each
2765
+ * market's currency, locale, phone rules, region naming and payment rails.
2766
+ *
2767
+ * Public (no sign-in needed) and cacheable for a few minutes. Read this at runtime instead of
2768
+ * hardcoding a country, and pair it with the helpers exported from the package root
2769
+ * (`formatMoney`, `normalizePhone`, `findMarket`, ...).
2770
+ */
2771
+ async list(options) {
2772
+ return this.client.get("/markets", void 0, options);
2773
+ }
2774
+ };
2775
+
2743
2776
  // src/types/auth.ts
2744
2777
  var TWO_FACTOR_METHOD_TYPES = ["totp", "sms", "email", "passkey"];
2745
2778
 
@@ -2771,6 +2804,103 @@ var DISPUTE_STATUSES = ["open", "seller_responded", "under_review", "resolved_re
2771
2804
  // src/types/wholesale.ts
2772
2805
  var BALE_ORDER_STATUSES = ["pending_payment", "paid", "confirmed", "in_transit", "delivered", "completed", "cancelled"];
2773
2806
 
2807
+ // src/markets.ts
2808
+ var GAP = " ";
2809
+ function group(value, locale) {
2810
+ const rounded = Math.round(Math.abs(value));
2811
+ try {
2812
+ return new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }).format(rounded);
2813
+ } catch {
2814
+ return String(rounded).replace(/\B(?=(\d{3})+(?!\d))/g, ",");
2815
+ }
2816
+ }
2817
+ function formatMoney(amount, market) {
2818
+ const { code, locale } = market.currency;
2819
+ if (!Number.isFinite(amount)) return `${code}${GAP}\u2014`;
2820
+ return `${amount < 0 ? "-" : ""}${code}${GAP}${group(amount, locale)}`;
2821
+ }
2822
+ function formatAmount(amount, market) {
2823
+ if (!Number.isFinite(amount)) return "\u2014";
2824
+ return `${amount < 0 ? "-" : ""}${group(amount, market.currency.locale)}`;
2825
+ }
2826
+ function formatMoneyCompact(amount, market) {
2827
+ const absolute = Math.abs(amount);
2828
+ if (!Number.isFinite(amount) || absolute < 1e4) return formatMoney(amount, market);
2829
+ const { code } = market.currency;
2830
+ const sign = amount < 0 ? "-" : "";
2831
+ const trim = (n) => n.toFixed(1).replace(/\.0$/, "");
2832
+ if (absolute < 1e6) {
2833
+ const thousands = absolute / 1e3;
2834
+ if (Math.round(thousands) < 1e3) {
2835
+ return `${sign}${code}${GAP}${thousands < 100 ? trim(thousands) : String(Math.round(thousands))}K`;
2836
+ }
2837
+ }
2838
+ return `${sign}${code}${GAP}${trim(absolute / 1e6)}M`;
2839
+ }
2840
+ function digitsOnly(value) {
2841
+ return value.replace(/\D/g, "");
2842
+ }
2843
+ function normalizePhone(input, market) {
2844
+ const { calling_code, national_length } = market.phone;
2845
+ const callingDigits = digitsOnly(calling_code);
2846
+ const trimmed = input.trim();
2847
+ const digits = digitsOnly(trimmed);
2848
+ if (digits.length === 0) return null;
2849
+ const fits = (national) => national_length.includes(national.length) && !national.startsWith("0");
2850
+ const afterCallingCode = (rest) => {
2851
+ if (fits(rest)) return rest;
2852
+ if (rest.startsWith("0") && fits(rest.slice(1))) return rest.slice(1);
2853
+ return null;
2854
+ };
2855
+ if (trimmed.startsWith("+")) {
2856
+ if (!digits.startsWith(callingDigits)) return null;
2857
+ const national = afterCallingCode(digits.slice(callingDigits.length));
2858
+ return national === null ? null : `+${callingDigits}${national}`;
2859
+ }
2860
+ if (digits.startsWith("0") && fits(digits.slice(1))) return `+${callingDigits}${digits.slice(1)}`;
2861
+ if (digits.startsWith(callingDigits)) {
2862
+ const national = afterCallingCode(digits.slice(callingDigits.length));
2863
+ if (national !== null) return `+${callingDigits}${national}`;
2864
+ }
2865
+ if (fits(digits)) return `+${callingDigits}${digits}`;
2866
+ return null;
2867
+ }
2868
+ function isValidPhone(input, market) {
2869
+ return normalizePhone(input, market) !== null;
2870
+ }
2871
+ function splitNational(e164, market) {
2872
+ const calling = market.phone.calling_code;
2873
+ if (!e164.startsWith(calling)) return null;
2874
+ const national = e164.slice(calling.length);
2875
+ if (!/^\d+$/.test(national) || !market.phone.national_length.includes(national.length)) return null;
2876
+ return { calling, national };
2877
+ }
2878
+ function formatPhone(value, market) {
2879
+ const compact = value.replace(/[^\d+]/g, "");
2880
+ const parts = splitNational(compact, market);
2881
+ if (!parts) return value;
2882
+ const groups = parts.national.match(/\d{1,3}/g) ?? [];
2883
+ if (groups.length > 1 && groups[groups.length - 1].length === 1) {
2884
+ const last = groups.pop();
2885
+ groups[groups.length - 1] += last;
2886
+ }
2887
+ return `${parts.calling}${GAP}${groups.join(GAP)}`;
2888
+ }
2889
+ function maskPhone(value, market) {
2890
+ const compact = value.replace(/[^\d+]/g, "");
2891
+ const parts = splitNational(compact, market);
2892
+ if (!parts || parts.national.length < 7) return value;
2893
+ const head = parts.national.slice(0, 3);
2894
+ const tail = parts.national.slice(-3);
2895
+ return `${parts.calling}${GAP}${head}${GAP}\u2022\u2022\u2022${GAP}${tail}`;
2896
+ }
2897
+ function findMarket(markets, code) {
2898
+ return markets.find((market) => market.code === code);
2899
+ }
2900
+ function activeMarkets(markets) {
2901
+ return markets.filter((market) => market.status === "active");
2902
+ }
2903
+
2774
2904
  // src/share.ts
2775
2905
  var DEFAULT_SHARE_ORIGIN = "https://go.mitumba.africa";
2776
2906
  var ID_PATTERN = /^[0-9a-f]{32}$/;
@@ -2834,6 +2964,7 @@ var MitumbaClient = class {
2834
2964
  reports;
2835
2965
  wholesale;
2836
2966
  iam;
2967
+ markets;
2837
2968
  constructor(config) {
2838
2969
  this.api = new APIClient(config);
2839
2970
  this.auth = new AuthModule(this.api);
@@ -2858,6 +2989,7 @@ var MitumbaClient = class {
2858
2989
  this.reports = new ReportsModule(this.api);
2859
2990
  this.wholesale = new WholesaleModule(this.api);
2860
2991
  this.iam = new IamModule(this.api);
2992
+ this.markets = new MarketsModule(this.api);
2861
2993
  }
2862
2994
  /**
2863
2995
  * Set the access token for authenticated requests.
@@ -2898,6 +3030,6 @@ var MitumbaClient = class {
2898
3030
  }
2899
3031
  };
2900
3032
 
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 };
3033
+ 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
3034
  //# sourceMappingURL=index.mjs.map
2903
3035
  //# sourceMappingURL=index.mjs.map