@mitumba/sdk 5.19.0 → 5.20.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.d.mts +111 -2
- package/dist/index.d.ts +111 -2
- package/dist/index.js +54 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -3
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -132,12 +132,15 @@ var APIError = class extends Error {
|
|
|
132
132
|
code;
|
|
133
133
|
status;
|
|
134
134
|
details;
|
|
135
|
-
|
|
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) {
|
|
@@ -3196,6 +3244,7 @@ var MitumbaClient = class {
|
|
|
3196
3244
|
reviews;
|
|
3197
3245
|
wishlists;
|
|
3198
3246
|
cart;
|
|
3247
|
+
checkouts;
|
|
3199
3248
|
settings;
|
|
3200
3249
|
mailer;
|
|
3201
3250
|
businesses;
|
|
@@ -3221,6 +3270,7 @@ var MitumbaClient = class {
|
|
|
3221
3270
|
this.reviews = new ReviewsModule(this.api);
|
|
3222
3271
|
this.wishlists = new WishlistsModule(this.api);
|
|
3223
3272
|
this.cart = new CartModule(this.api);
|
|
3273
|
+
this.checkouts = new CheckoutsModule(this.api);
|
|
3224
3274
|
this.settings = new SettingsModule(this.api);
|
|
3225
3275
|
this.mailer = new MailerModule(this.api);
|
|
3226
3276
|
this.businesses = new BusinessesModule(this.api);
|
|
@@ -3271,6 +3321,6 @@ var MitumbaClient = class {
|
|
|
3271
3321
|
}
|
|
3272
3322
|
};
|
|
3273
3323
|
|
|
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 };
|
|
3324
|
+
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, checkoutRefusal, createTokenStore, findMarket, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, regionById, storeShareUrl };
|
|
3275
3325
|
//# sourceMappingURL=index.mjs.map
|
|
3276
3326
|
//# sourceMappingURL=index.mjs.map
|