@mitumba/sdk 5.19.0 → 5.21.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
@@ -132,12 +132,15 @@ var APIError = class extends Error {
132
132
  code;
133
133
  status;
134
134
  details;
135
- constructor(status, data) {
135
+ /** The decoded error body as the server sent it, for errors whose details are top-level fields. */
136
+ body;
137
+ constructor(status, data, body) {
136
138
  super(data.message || data.error);
137
139
  this.name = "APIError";
138
140
  this.code = data.error;
139
141
  this.status = status;
140
142
  this.details = data.details;
143
+ this.body = body;
141
144
  }
142
145
  };
143
146
  function isExpiringSoon(token, thresholdSeconds) {
@@ -383,7 +386,7 @@ var APIClient = class {
383
386
  } catch {
384
387
  decoded = null;
385
388
  }
386
- throw new APIError(response.status, normalizeAPIErrorResponse(decoded, response.statusText));
389
+ throw new APIError(response.status, normalizeAPIErrorResponse(decoded, response.statusText), decoded ?? void 0);
387
390
  }
388
391
  return response;
389
392
  }
@@ -2102,12 +2105,57 @@ var CartModule = class {
2102
2105
  }
2103
2106
  /**
2104
2107
  * Checkout the cart — creates orders grouped by store and clears the cart.
2108
+ * @deprecated Use `sdk.checkouts.create`: checkout needs an address, an idempotency key and a
2109
+ * delivery quote per shop, and returns the checkout with its totals.
2105
2110
  */
2106
2111
  async checkout(options) {
2107
2112
  return this.client.post("/orders/checkout", void 0, options);
2108
2113
  }
2109
2114
  };
2110
2115
 
2116
+ // src/modules/checkouts.ts
2117
+ var REFUSAL_CODES = /* @__PURE__ */ new Set([
2118
+ "invalid_input",
2119
+ "empty_cart",
2120
+ "cannot_buy_own",
2121
+ "invalid_deliveries",
2122
+ "address_not_found",
2123
+ "idempotency_conflict",
2124
+ "listing_unavailable",
2125
+ "mixed_market_cart",
2126
+ "market_not_active",
2127
+ "checkout_payment_in_progress",
2128
+ "delivery_quote_rejected",
2129
+ "address_region_invalid",
2130
+ "delivery_required",
2131
+ "delivery_quotes_unavailable"
2132
+ ]);
2133
+ function checkoutRefusal(error) {
2134
+ if (!(error instanceof APIError)) return null;
2135
+ const body = error.body;
2136
+ if (typeof body !== "object" || body === null) return null;
2137
+ const code = body.error;
2138
+ if (typeof code !== "string" || !REFUSAL_CODES.has(code)) return null;
2139
+ return body;
2140
+ }
2141
+ var CheckoutsModule = class {
2142
+ constructor(client) {
2143
+ this.client = client;
2144
+ }
2145
+ /**
2146
+ * Create a checkout from the buyer's cart: one order per shop, each at the delivery quote picked
2147
+ * for it, held until the checkout's due-by. A retry with the same `idempotency_key` returns the
2148
+ * same checkout. A refusal throws an `APIError`; read it with `checkoutRefusal(error)`.
2149
+ */
2150
+ async create(input, options) {
2151
+ return this.client.post("/orders/checkout", input, options);
2152
+ }
2153
+ /** Read one of the buyer's checkouts. Anyone else gets a 404. */
2154
+ async get(checkoutId, options) {
2155
+ return this.client.get(`/orders/checkouts/${encodeURIComponent(checkoutId)}`, void 0, options);
2156
+ }
2157
+ };
2158
+
2111
2159
  // src/modules/settings.ts
2112
2160
  var SettingsModule = class {
2113
2161
  constructor(client) {
@@ -3037,6 +3085,29 @@ var DISPUTE_STATUSES = ["open", "seller_responded", "under_review", "resolved_re
3037
3085
  // src/types/wholesale.ts
3038
3086
  var BALE_ORDER_STATUSES = ["pending_payment", "paid", "confirmed", "in_transit", "delivered", "completed", "cancelled"];
3039
3087
 
3088
+ // src/modules/cart-availability.ts
3089
+ function cartLineAvailability(item) {
3090
+ if (item.status === "sold") return "sold";
3091
+ if (item.status !== "active") return "unavailable";
3092
+ if (item.available_quantity <= 0) return "reserved";
3093
+ if (item.available_quantity < item.quantity) return "limited";
3094
+ return "available";
3095
+ }
3096
+ function isCartLineBuyable(item) {
3097
+ const availability = cartLineAvailability(item);
3098
+ return availability === "available" || availability === "limited";
3099
+ }
3100
+ function partitionCart(items) {
3101
+ const partition = { buyable: [], limited: [], unavailable: [] };
3102
+ for (const item of items) {
3103
+ const availability = cartLineAvailability(item);
3104
+ if (availability === "available") partition.buyable.push(item);
3105
+ else if (availability === "limited") partition.limited.push(item);
3106
+ else partition.unavailable.push(item);
3107
+ }
3108
+ return partition;
3109
+ }
3110
+
3040
3111
  // src/markets.ts
3041
3112
  var GAP = " ";
3042
3113
  function group(value, locale) {
@@ -3196,6 +3267,7 @@ var MitumbaClient = class {
3196
3267
  reviews;
3197
3268
  wishlists;
3198
3269
  cart;
3270
+ checkouts;
3199
3271
  settings;
3200
3272
  mailer;
3201
3273
  businesses;
@@ -3221,6 +3293,7 @@ var MitumbaClient = class {
3221
3293
  this.reviews = new ReviewsModule(this.api);
3222
3294
  this.wishlists = new WishlistsModule(this.api);
3223
3295
  this.cart = new CartModule(this.api);
3296
+ this.checkouts = new CheckoutsModule(this.api);
3224
3297
  this.settings = new SettingsModule(this.api);
3225
3298
  this.mailer = new MailerModule(this.api);
3226
3299
  this.businesses = new BusinessesModule(this.api);
@@ -3271,6 +3344,6 @@ var MitumbaClient = class {
3271
3344
  }
3272
3345
  };
3273
3346
 
3274
- 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, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, regionById, storeShareUrl };
3347
+ export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, CheckoutsModule, 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, cartLineAvailability, checkoutRefusal, createTokenStore, findMarket, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isCartLineBuyable, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, partitionCart, regionById, storeShareUrl };
3275
3348
  //# sourceMappingURL=index.mjs.map
3276
3349
  //# sourceMappingURL=index.mjs.map