@mitumba/sdk 1.30.0 → 1.31.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
@@ -1676,6 +1676,44 @@ var DISPUTE_STATUSES = ["open", "seller_responded", "under_review", "resolved_re
1676
1676
  // src/types/wholesale.ts
1677
1677
  var BALE_ORDER_STATUSES = ["pending_payment", "paid", "confirmed", "in_transit", "delivered", "completed", "cancelled"];
1678
1678
 
1679
+ // src/share.ts
1680
+ var DEFAULT_SHARE_ORIGIN = "https://go.mitumba.africa";
1681
+ var ID_PATTERN = /^[0-9a-f]{32}$/;
1682
+ var SLUG_PATTERN = /^[a-z0-9]+(?:-[a-z0-9]+)*$/;
1683
+ function resolveOrigin(origin) {
1684
+ if (origin === void 0) return DEFAULT_SHARE_ORIGIN;
1685
+ let url;
1686
+ try {
1687
+ url = new URL(origin);
1688
+ } catch {
1689
+ throw new TypeError(`Invalid share origin: ${origin}`);
1690
+ }
1691
+ const local = url.protocol === "http:" && (url.hostname === "localhost" || url.hostname === "127.0.0.1");
1692
+ if (url.protocol !== "https:" && !local || url.username || url.password) {
1693
+ throw new TypeError(`Share origin must be https:// (or http://localhost): ${origin}`);
1694
+ }
1695
+ if (url.pathname !== "/" && url.pathname !== "" || url.search || url.hash) {
1696
+ throw new TypeError(`Share origin must not include a path, query or fragment: ${origin}`);
1697
+ }
1698
+ return url.origin;
1699
+ }
1700
+ function identifier(kind, value) {
1701
+ const normalized = typeof value === "string" ? value.trim().toLowerCase() : "";
1702
+ if (!ID_PATTERN.test(normalized)) throw new TypeError(`Invalid ${kind} ID: ${String(value)}`);
1703
+ return normalized;
1704
+ }
1705
+ function listingShareUrl(listingId, options = {}) {
1706
+ return `${resolveOrigin(options.origin)}/l/${encodeURIComponent(identifier("listing", listingId))}`;
1707
+ }
1708
+ function storeShareUrl(storeSlug, options = {}) {
1709
+ const slug = typeof storeSlug === "string" ? storeSlug.trim().toLowerCase() : "";
1710
+ if (slug.length > 64 || !SLUG_PATTERN.test(slug)) throw new TypeError(`Invalid store slug: ${String(storeSlug)}`);
1711
+ return `${resolveOrigin(options.origin)}/s/${encodeURIComponent(slug)}`;
1712
+ }
1713
+ function baleShareUrl(baleId, options = {}) {
1714
+ return `${resolveOrigin(options.origin)}/b/${encodeURIComponent(identifier("bale", baleId))}`;
1715
+ }
1716
+
1679
1717
  // src/index.ts
1680
1718
  var MitumbaClient = class {
1681
1719
  api;
@@ -1761,6 +1799,6 @@ var MitumbaClient = class {
1761
1799
  }
1762
1800
  };
1763
1801
 
1764
- export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, createTokenStore };
1802
+ export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, listingShareUrl, storeShareUrl };
1765
1803
  //# sourceMappingURL=index.mjs.map
1766
1804
  //# sourceMappingURL=index.mjs.map