@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.d.mts CHANGED
@@ -2811,12 +2811,119 @@ interface CartItem {
2811
2811
  price: number;
2812
2812
  condition: string;
2813
2813
  size: string | null;
2814
+ /** Units in the cart. */
2815
+ quantity: number;
2816
+ /** The listing's status now. Only an `active` listing can be bought. */
2817
+ status: ListingStatus;
2818
+ /** Units the listing has in total. */
2819
+ stock_quantity: number;
2820
+ /** Units this buyer can have now: stock less units other buyers hold or bought. 0 when not active. */
2821
+ available_quantity: number;
2814
2822
  store_id: string;
2815
2823
  store_name: string;
2816
2824
  store_slug: string;
2817
2825
  image_url: string | null;
2826
+ /**
2827
+ * @deprecated A flat legacy per-city fee, not a delivery price. Delivery is priced per shop at
2828
+ * checkout from the buyer's address (`POST /logistics/basket-quotes`).
2829
+ */
2818
2830
  delivery_fee: number;
2819
2831
  }
2832
+ /**
2833
+ * Whether a cart line can be bought, as {@link cartLineAvailability} decides it.
2834
+ *
2835
+ * - `available`: every unit in the cart can be bought.
2836
+ * - `limited`: fewer units are left than the cart holds; `available_quantity` can still be bought.
2837
+ * - `reserved`: on sale, but every unit is held by other buyers' unpaid checkouts. It may come back.
2838
+ * - `sold`: sold out for good.
2839
+ * - `unavailable`: withdrawn by the seller (removed or back in draft).
2840
+ */
2841
+ type CartLineAvailability = 'available' | 'limited' | 'reserved' | 'sold' | 'unavailable';
2842
+
2843
+ /** An amount in a currency's minor units (cents for KES). */
2844
+ interface CheckoutMoney {
2845
+ currency: string;
2846
+ minor_units: number;
2847
+ }
2848
+ interface CreateCheckoutInput {
2849
+ /** One of the buyer's saved addresses. */
2850
+ address_id: string;
2851
+ /** One per buyer intent, 8 to 128 characters. A retry with the same key returns the same checkout. */
2852
+ idempotency_key: string;
2853
+ /** Exactly one per shop in the cart: the delivery quote picked for that shop. */
2854
+ deliveries: Array<{
2855
+ store_id: string;
2856
+ quote_id: string;
2857
+ }>;
2858
+ }
2859
+ type CheckoutState = 'awaiting_payment' | 'paid' | 'expired' | 'cancelled';
2860
+ /** One shop's order within a checkout. */
2861
+ interface CheckoutShopOrder {
2862
+ order_id: string;
2863
+ store_id: string;
2864
+ items_total: CheckoutMoney;
2865
+ delivery_fee: CheckoutMoney;
2866
+ /** The buyer protection fee (BPF) on this shop's order; zero when none. */
2867
+ bpf: CheckoutMoney;
2868
+ /** What the buyer pays for this shop's order: items + delivery + BPF. */
2869
+ total: CheckoutMoney;
2870
+ }
2871
+ /** One cart submission, holding one order per shop. */
2872
+ interface Checkout {
2873
+ id: string;
2874
+ invoice_number: string;
2875
+ status: CheckoutState;
2876
+ market_code: string;
2877
+ items_total: CheckoutMoney;
2878
+ delivery_total: CheckoutMoney;
2879
+ /** The BPF across every shop's order; zero when none. */
2880
+ bpf_total: CheckoutMoney;
2881
+ /** What the buyer pays: items + delivery + BPF. */
2882
+ total: CheckoutMoney;
2883
+ /** Payment due-by (ISO 8601). */
2884
+ due_at: string;
2885
+ created_at: string;
2886
+ orders: CheckoutShopOrder[];
2887
+ }
2888
+ interface CreateCheckoutResponse {
2889
+ checkout: Checkout;
2890
+ order_ids: string[];
2891
+ count: number;
2892
+ }
2893
+ interface GetCheckoutResponse {
2894
+ checkout: Checkout;
2895
+ }
2896
+ /** Why a checkout was refused: the error body, keyed by `error`. */
2897
+ type CheckoutRefusal = {
2898
+ error: 'invalid_input' | 'empty_cart' | 'cannot_buy_own' | 'invalid_deliveries';
2899
+ } | {
2900
+ error: 'address_not_found';
2901
+ } | {
2902
+ error: 'idempotency_conflict';
2903
+ } | {
2904
+ error: 'listing_unavailable';
2905
+ listings: Array<{
2906
+ listing_id: string;
2907
+ available: number;
2908
+ }>;
2909
+ } | {
2910
+ error: 'mixed_market_cart' | 'market_not_active';
2911
+ } | {
2912
+ error: 'checkout_payment_in_progress';
2913
+ checkout_id: string;
2914
+ } | {
2915
+ error: 'delivery_quote_rejected';
2916
+ store_id: string | null;
2917
+ reason: string;
2918
+ } | {
2919
+ error: 'address_region_invalid';
2920
+ } | {
2921
+ error: 'delivery_required';
2922
+ store_ids: string[];
2923
+ } | {
2924
+ error: 'delivery_quotes_unavailable';
2925
+ };
2926
+ type CheckoutRefusalCode = CheckoutRefusal['error'];
2820
2927
 
2821
2928
  /**
2822
2929
  * Fields a user may change on their own profile via `PUT /auth/me`. Every field is optional;
@@ -3283,7 +3390,9 @@ declare class APIError extends Error {
3283
3390
  readonly code: string;
3284
3391
  readonly status: number;
3285
3392
  readonly details?: unknown;
3286
- constructor(status: number, data: APIErrorResponse);
3393
+ /** The decoded error body as the server sent it, for errors whose details are top-level fields. */
3394
+ readonly body?: unknown;
3395
+ constructor(status: number, data: APIErrorResponse, body?: unknown);
3287
3396
  }
3288
3397
  declare class APIClient {
3289
3398
  private config;
@@ -4209,6 +4318,8 @@ declare class CartModule {
4209
4318
  }>;
4210
4319
  /**
4211
4320
  * Checkout the cart — creates orders grouped by store and clears the cart.
4321
+ * @deprecated Use `sdk.checkouts.create`: checkout needs an address, an idempotency key and a
4322
+ * delivery quote per shop, and returns the checkout with its totals.
4212
4323
  */
4213
4324
  checkout(options?: RequestOptions): Promise<{
4214
4325
  order_ids: string[];
@@ -4216,6 +4327,25 @@ declare class CartModule {
4216
4327
  }>;
4217
4328
  }
4218
4329
 
4330
+ /**
4331
+ * The checkout refusal carried by an error thrown from `checkouts.create`, or null when the error is
4332
+ * not one. The body is the server's own, so the refusal's details (such as `listings` for
4333
+ * `listing_unavailable`) are present.
4334
+ */
4335
+ declare function checkoutRefusal(error: unknown): CheckoutRefusal | null;
4336
+ declare class CheckoutsModule {
4337
+ private readonly client;
4338
+ constructor(client: APIClient);
4339
+ /**
4340
+ * Create a checkout from the buyer's cart: one order per shop, each at the delivery quote picked
4341
+ * for it, held until the checkout's due-by. A retry with the same `idempotency_key` returns the
4342
+ * same checkout. A refusal throws an `APIError`; read it with `checkoutRefusal(error)`.
4343
+ */
4344
+ create(input: CreateCheckoutInput, options?: RequestOptions): Promise<CreateCheckoutResponse>;
4345
+ /** Read one of the buyer's checkouts. Anyone else gets a 404. */
4346
+ get(checkoutId: string, options?: RequestOptions): Promise<GetCheckoutResponse>;
4347
+ }
4348
+
4219
4349
  declare class SettingsModule {
4220
4350
  private readonly client;
4221
4351
  constructor(client: APIClient);
@@ -5066,6 +5196,25 @@ declare class MarketsModule {
5066
5196
  regions(code: string, options?: RequestOptions): Promise<MarketRegionsResponse>;
5067
5197
  }
5068
5198
 
5199
+ type AvailabilityFields = Pick<CartItem, 'status' | 'quantity' | 'available_quantity'>;
5200
+ /** Whether a cart line can be bought now. See {@link CartLineAvailability}. */
5201
+ declare function cartLineAvailability(item: AvailabilityFields): CartLineAvailability;
5202
+ /** True when the line can be checked out, possibly at a lower quantity (`limited`). */
5203
+ declare function isCartLineBuyable(item: AvailabilityFields): boolean;
5204
+ interface CartPartition<T extends AvailabilityFields> {
5205
+ /** Lines that can be bought exactly as they are. */
5206
+ buyable: T[];
5207
+ /** Lines with fewer units left than in the cart: lower the quantity to `available_quantity`. */
5208
+ limited: T[];
5209
+ /** Lines that cannot be bought now: sold, withdrawn, or reserved by other buyers. */
5210
+ unavailable: T[];
5211
+ }
5212
+ /**
5213
+ * Split a cart for checkout. Checkout refuses a cart holding any line it cannot sell in full, so
5214
+ * `limited` and `unavailable` lines must be fixed (lowered or removed) before checking out.
5215
+ */
5216
+ declare function partitionCart<T extends AvailabilityFields>(items: readonly T[]): CartPartition<T>;
5217
+
5069
5218
  /**
5070
5219
  * Market-aware formatting and validation. Everything here is driven by a `Market` read from
5071
5220
  * `sdk.markets.list()`: no country, currency or calling code is hardcoded, so adding a market
@@ -5162,6 +5311,7 @@ declare class MitumbaClient {
5162
5311
  readonly reviews: ReviewsModule;
5163
5312
  readonly wishlists: WishlistsModule;
5164
5313
  readonly cart: CartModule;
5314
+ readonly checkouts: CheckoutsModule;
5165
5315
  readonly settings: SettingsModule;
5166
5316
  readonly mailer: MailerModule;
5167
5317
  readonly businesses: BusinessesModule;
@@ -5203,4 +5353,4 @@ declare class MitumbaClient {
5203
5353
  isAuthenticated(): Promise<boolean>;
5204
5354
  }
5205
5355
 
5206
- export { APIClient, APIError, type APIErrorResponse, type ActivateIamUserInput, type ActivateIamUserResult, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddIamPasskeyResult, type AddIamTotpResult, type AddIamTwoFactorMethodInput, type AddPaymentMethodInput, type Address, type AdminAuditActor, type AdminAuditEntry, type AdminAuditQuery, type AdminAuthStrength, type AdminListingItem, type AdminMessageReport, type AdminMessageReportDetail, type AdminMessageReportList, type AdminMessageReportThreadMessage, AdminModule, type AdminOperator, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminPermission, type AdminPermissionDescription, type AdminRecoveryEvent, type AdminRecoveryRequest, type AdminReport, type AdminRolePreset, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, type AdminWholesalePendingStore, type ApiResponse, type AttachmentDownloadAuthorization, type AttachmentUploadAuthorization, type AttachmentUploadBody, type AttachmentUploadState, type AttachmentUploadStatus, type AuthCapabilities, AuthModule, type AuthTokens, type AuthenticationResponseJSON, BALE_ORDER_STATUSES, type Bale, type BaleDetail, type BaleFeedItem, type BaleFulfillment, type BaleGrade, type BaleImageUploadResult, type BaleOrder, type BaleOrderEvent, type BaleOrderStatus, type BaleType, type BecomeBaleSellerInput, type BecomeSellerInput, type BlockedIp, type Business, type BusinessType, BusinessesModule, type BuyerResolveThreadInput, type BuyerSummary, CONDITIONS, type CartItem, CartModule, type Category, type ChangePasswordInput, type ChangePlatformSettingInput, type ChangePlatformSettingResult, type CheckoutNextAction, type CheckoutOrder, type CheckoutPaymentMethod, type CheckoutStatus, type CheckoutStatusResponse, type City, type CompleteOnboardingInput, type CompleteRecoveryResult, type Condition, type Conversation, type ConversationId, type ConversationSummary, type CreateAttachmentUploadInput, type CreateBaleInput, type CreateBaleOrderInput, type CreateIamUserInput, type CreateIamUserResult, type CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, type CreateOrganizationInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, type CursorPage, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type FileResponse, type FinishIamPasskeyEnrollmentInput, type FinishIamPasskeyLoginInput, type FollowedStore, type ForgotPasswordInput, IDBTokenStore, type IamActivation, type IamLoginInput, type IamLoginMethod, type IamMethodsResult, IamModule, type IamPasskeyLoginOptions, type IamProfile, type IamSession, type IamSessionsResult, type IamSignIn, type IamSignInFailureReason, type IamSignInsResult, type IamTokens, type IamTwoFactorRequired, type IamUser, type IamUserStatus, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type Jwk, type Jwks, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LibraryCadence, type LibraryCompleter, type LibraryDocument, type LibraryDocumentSummary, type LibraryKind, type LibraryListing, type LibraryOccurrence, type LibraryOccurrenceRecorded, type LibraryOccurrenceStatus, type LibraryRoutineState, type LibrarySchedule, type LibraryScheduleRule, type LibrarySeason, type LibraryWeekday, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListIamUsersResult, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, type Market, type MarketCurrency, type MarketPhone, type MarketRegion, type MarketRegionsResponse, type MarketStatus, MarketsModule, type MarketsResponse, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportOutcome, type MessageReportReason, type MessageReportStatus, type MessageResponse, MessagesModule, type MessagesRealtimeConnection, type MessagesRealtimeEnvelope, type MessagesRealtimeEvent, type MessagesRealtimeOptions, type MessagesRealtimeState, type MessagesRealtimeTicket, type MessagingBlockInput, type MessagingBlockRemovedResult, type MessagingBlockResult, type MessagingCapabilities, type MessagingCursor, type MessagingErrorCode, type MessagingIdempotentRequestOptions, type MessagingInboxes, type MessagingPerspective, type MessagingSide, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, type OAuthAuthorizeInput, type OAuthAuthorizeResult, type OAuthClient, type OAuthClientSummary, type OAuthClientTrustLevel, type OAuthClientType, type OAuthConsent, type OAuthConsentInput, type OAuthConsentRequired, type OAuthConsentRevokeResult, OAuthModule, type OAuthTokenExchangeInput, type OAuthTokenResult, ORDER_STATUSES, type OidcSigningKey, type OpenIdConfiguration, type OperatorPermissionGrant, type Order, type OrderDocument, type OrderDocumentKind, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, type Organization, type OrganizationKind, type OrganizationStatus, type OrganizationSummary, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentAttemptStatus, type PaymentMethod, type PaymentMethodType, type PaymentProvider, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PendingPayoutApproval, type PhoneLoginInput, type PhoneRegisterInput, type PlatformSetting, type PlatformSettingChange, type PlatformSettingDetail, type PlatformSettingGroup, type PlatformSettingKind, type PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegenerateIamBackupCodesResult, type RegisterInput, type RegisterOAuthClientInput, type RegisteredOAuthClient, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, type ResolveMessageReportInput, type ResolveMessageReportResult, type ResolveThreadResult, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type RootSetupInput, type RootSetupResult, type SaveSearchInput, type SaveWholesaleStoreInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SellerType, type SendEmailInput, type SendMessageInput, type SendOtpInput, type SendThreadMessageInput, type SendThreadMessageResult, type Session, SettingsModule, type ShareUrlOptions, type SilentAuthorizeResult, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreResolveThreadInput, type StoreReviewsPage, type StoreSettings, type StoreStats, type StoreSummary, StoresModule, type SubscriptionTier, type SystemStats, TWO_FACTOR_METHOD_TYPES, type ThreadCard, type ThreadId, type ThreadMessage, type ThreadSubject, type ThreadSystemEvent, type ThreadTimelineItem, type ThreadTimelineItemId, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorMethod, type TwoFactorMethodType, type TwoFactorRequired, type UpdateBusinessInput, type UpdateConversationPreferencesInput, type UpdateListingInput, type UpdateOrganizationInput, type UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserInfo, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyIamMethodResult, type VerifyIamTwoFactorInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleReviewStatus, type WholesaleStore, type WishlistListing, WishlistsModule, activeMarkets, baleShareUrl, createTokenStore, findMarket, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, regionById, storeShareUrl };
5356
+ export { APIClient, APIError, type APIErrorResponse, type ActivateIamUserInput, type ActivateIamUserResult, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddIamPasskeyResult, type AddIamTotpResult, type AddIamTwoFactorMethodInput, type AddPaymentMethodInput, type Address, type AdminAuditActor, type AdminAuditEntry, type AdminAuditQuery, type AdminAuthStrength, type AdminListingItem, type AdminMessageReport, type AdminMessageReportDetail, type AdminMessageReportList, type AdminMessageReportThreadMessage, AdminModule, type AdminOperator, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminPermission, type AdminPermissionDescription, type AdminRecoveryEvent, type AdminRecoveryRequest, type AdminReport, type AdminRolePreset, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, type AdminWholesalePendingStore, type ApiResponse, type AttachmentDownloadAuthorization, type AttachmentUploadAuthorization, type AttachmentUploadBody, type AttachmentUploadState, type AttachmentUploadStatus, type AuthCapabilities, AuthModule, type AuthTokens, type AuthenticationResponseJSON, BALE_ORDER_STATUSES, type Bale, type BaleDetail, type BaleFeedItem, type BaleFulfillment, type BaleGrade, type BaleImageUploadResult, type BaleOrder, type BaleOrderEvent, type BaleOrderStatus, type BaleType, type BecomeBaleSellerInput, type BecomeSellerInput, type BlockedIp, type Business, type BusinessType, BusinessesModule, type BuyerResolveThreadInput, type BuyerSummary, CONDITIONS, type CartItem, type CartLineAvailability, CartModule, type CartPartition, type Category, type ChangePasswordInput, type ChangePlatformSettingInput, type ChangePlatformSettingResult, type Checkout, type CheckoutMoney, type CheckoutNextAction, type CheckoutOrder, type CheckoutPaymentMethod, type CheckoutRefusal, type CheckoutRefusalCode, type CheckoutShopOrder, type CheckoutState, type CheckoutStatus, type CheckoutStatusResponse, CheckoutsModule, type City, type CompleteOnboardingInput, type CompleteRecoveryResult, type Condition, type Conversation, type ConversationId, type ConversationSummary, type CreateAttachmentUploadInput, type CreateBaleInput, type CreateBaleOrderInput, type CreateCheckoutInput, type CreateCheckoutResponse, type CreateIamUserInput, type CreateIamUserResult, type CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, type CreateOrganizationInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, type CursorPage, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type FileResponse, type FinishIamPasskeyEnrollmentInput, type FinishIamPasskeyLoginInput, type FollowedStore, type ForgotPasswordInput, type GetCheckoutResponse, IDBTokenStore, type IamActivation, type IamLoginInput, type IamLoginMethod, type IamMethodsResult, IamModule, type IamPasskeyLoginOptions, type IamProfile, type IamSession, type IamSessionsResult, type IamSignIn, type IamSignInFailureReason, type IamSignInsResult, type IamTokens, type IamTwoFactorRequired, type IamUser, type IamUserStatus, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type Jwk, type Jwks, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LibraryCadence, type LibraryCompleter, type LibraryDocument, type LibraryDocumentSummary, type LibraryKind, type LibraryListing, type LibraryOccurrence, type LibraryOccurrenceRecorded, type LibraryOccurrenceStatus, type LibraryRoutineState, type LibrarySchedule, type LibraryScheduleRule, type LibrarySeason, type LibraryWeekday, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListIamUsersResult, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, type Market, type MarketCurrency, type MarketPhone, type MarketRegion, type MarketRegionsResponse, type MarketStatus, MarketsModule, type MarketsResponse, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportOutcome, type MessageReportReason, type MessageReportStatus, type MessageResponse, MessagesModule, type MessagesRealtimeConnection, type MessagesRealtimeEnvelope, type MessagesRealtimeEvent, type MessagesRealtimeOptions, type MessagesRealtimeState, type MessagesRealtimeTicket, type MessagingBlockInput, type MessagingBlockRemovedResult, type MessagingBlockResult, type MessagingCapabilities, type MessagingCursor, type MessagingErrorCode, type MessagingIdempotentRequestOptions, type MessagingInboxes, type MessagingPerspective, type MessagingSide, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, type OAuthAuthorizeInput, type OAuthAuthorizeResult, type OAuthClient, type OAuthClientSummary, type OAuthClientTrustLevel, type OAuthClientType, type OAuthConsent, type OAuthConsentInput, type OAuthConsentRequired, type OAuthConsentRevokeResult, OAuthModule, type OAuthTokenExchangeInput, type OAuthTokenResult, ORDER_STATUSES, type OidcSigningKey, type OpenIdConfiguration, type OperatorPermissionGrant, type Order, type OrderDocument, type OrderDocumentKind, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, type Organization, type OrganizationKind, type OrganizationStatus, type OrganizationSummary, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentAttemptStatus, type PaymentMethod, type PaymentMethodType, type PaymentProvider, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PendingPayoutApproval, type PhoneLoginInput, type PhoneRegisterInput, type PlatformSetting, type PlatformSettingChange, type PlatformSettingDetail, type PlatformSettingGroup, type PlatformSettingKind, type PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegenerateIamBackupCodesResult, type RegisterInput, type RegisterOAuthClientInput, type RegisteredOAuthClient, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, type ResolveMessageReportInput, type ResolveMessageReportResult, type ResolveThreadResult, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type RootSetupInput, type RootSetupResult, type SaveSearchInput, type SaveWholesaleStoreInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SellerType, type SendEmailInput, type SendMessageInput, type SendOtpInput, type SendThreadMessageInput, type SendThreadMessageResult, type Session, SettingsModule, type ShareUrlOptions, type SilentAuthorizeResult, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreResolveThreadInput, type StoreReviewsPage, type StoreSettings, type StoreStats, type StoreSummary, StoresModule, type SubscriptionTier, type SystemStats, TWO_FACTOR_METHOD_TYPES, type ThreadCard, type ThreadId, type ThreadMessage, type ThreadSubject, type ThreadSystemEvent, type ThreadTimelineItem, type ThreadTimelineItemId, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorMethod, type TwoFactorMethodType, type TwoFactorRequired, type UpdateBusinessInput, type UpdateConversationPreferencesInput, type UpdateListingInput, type UpdateOrganizationInput, type UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserInfo, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyIamMethodResult, type VerifyIamTwoFactorInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleReviewStatus, type WholesaleStore, type WishlistListing, WishlistsModule, activeMarkets, baleShareUrl, cartLineAvailability, checkoutRefusal, createTokenStore, findMarket, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isCartLineBuyable, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, partitionCart, regionById, storeShareUrl };
package/dist/index.d.ts CHANGED
@@ -2811,12 +2811,119 @@ interface CartItem {
2811
2811
  price: number;
2812
2812
  condition: string;
2813
2813
  size: string | null;
2814
+ /** Units in the cart. */
2815
+ quantity: number;
2816
+ /** The listing's status now. Only an `active` listing can be bought. */
2817
+ status: ListingStatus;
2818
+ /** Units the listing has in total. */
2819
+ stock_quantity: number;
2820
+ /** Units this buyer can have now: stock less units other buyers hold or bought. 0 when not active. */
2821
+ available_quantity: number;
2814
2822
  store_id: string;
2815
2823
  store_name: string;
2816
2824
  store_slug: string;
2817
2825
  image_url: string | null;
2826
+ /**
2827
+ * @deprecated A flat legacy per-city fee, not a delivery price. Delivery is priced per shop at
2828
+ * checkout from the buyer's address (`POST /logistics/basket-quotes`).
2829
+ */
2818
2830
  delivery_fee: number;
2819
2831
  }
2832
+ /**
2833
+ * Whether a cart line can be bought, as {@link cartLineAvailability} decides it.
2834
+ *
2835
+ * - `available`: every unit in the cart can be bought.
2836
+ * - `limited`: fewer units are left than the cart holds; `available_quantity` can still be bought.
2837
+ * - `reserved`: on sale, but every unit is held by other buyers' unpaid checkouts. It may come back.
2838
+ * - `sold`: sold out for good.
2839
+ * - `unavailable`: withdrawn by the seller (removed or back in draft).
2840
+ */
2841
+ type CartLineAvailability = 'available' | 'limited' | 'reserved' | 'sold' | 'unavailable';
2842
+
2843
+ /** An amount in a currency's minor units (cents for KES). */
2844
+ interface CheckoutMoney {
2845
+ currency: string;
2846
+ minor_units: number;
2847
+ }
2848
+ interface CreateCheckoutInput {
2849
+ /** One of the buyer's saved addresses. */
2850
+ address_id: string;
2851
+ /** One per buyer intent, 8 to 128 characters. A retry with the same key returns the same checkout. */
2852
+ idempotency_key: string;
2853
+ /** Exactly one per shop in the cart: the delivery quote picked for that shop. */
2854
+ deliveries: Array<{
2855
+ store_id: string;
2856
+ quote_id: string;
2857
+ }>;
2858
+ }
2859
+ type CheckoutState = 'awaiting_payment' | 'paid' | 'expired' | 'cancelled';
2860
+ /** One shop's order within a checkout. */
2861
+ interface CheckoutShopOrder {
2862
+ order_id: string;
2863
+ store_id: string;
2864
+ items_total: CheckoutMoney;
2865
+ delivery_fee: CheckoutMoney;
2866
+ /** The buyer protection fee (BPF) on this shop's order; zero when none. */
2867
+ bpf: CheckoutMoney;
2868
+ /** What the buyer pays for this shop's order: items + delivery + BPF. */
2869
+ total: CheckoutMoney;
2870
+ }
2871
+ /** One cart submission, holding one order per shop. */
2872
+ interface Checkout {
2873
+ id: string;
2874
+ invoice_number: string;
2875
+ status: CheckoutState;
2876
+ market_code: string;
2877
+ items_total: CheckoutMoney;
2878
+ delivery_total: CheckoutMoney;
2879
+ /** The BPF across every shop's order; zero when none. */
2880
+ bpf_total: CheckoutMoney;
2881
+ /** What the buyer pays: items + delivery + BPF. */
2882
+ total: CheckoutMoney;
2883
+ /** Payment due-by (ISO 8601). */
2884
+ due_at: string;
2885
+ created_at: string;
2886
+ orders: CheckoutShopOrder[];
2887
+ }
2888
+ interface CreateCheckoutResponse {
2889
+ checkout: Checkout;
2890
+ order_ids: string[];
2891
+ count: number;
2892
+ }
2893
+ interface GetCheckoutResponse {
2894
+ checkout: Checkout;
2895
+ }
2896
+ /** Why a checkout was refused: the error body, keyed by `error`. */
2897
+ type CheckoutRefusal = {
2898
+ error: 'invalid_input' | 'empty_cart' | 'cannot_buy_own' | 'invalid_deliveries';
2899
+ } | {
2900
+ error: 'address_not_found';
2901
+ } | {
2902
+ error: 'idempotency_conflict';
2903
+ } | {
2904
+ error: 'listing_unavailable';
2905
+ listings: Array<{
2906
+ listing_id: string;
2907
+ available: number;
2908
+ }>;
2909
+ } | {
2910
+ error: 'mixed_market_cart' | 'market_not_active';
2911
+ } | {
2912
+ error: 'checkout_payment_in_progress';
2913
+ checkout_id: string;
2914
+ } | {
2915
+ error: 'delivery_quote_rejected';
2916
+ store_id: string | null;
2917
+ reason: string;
2918
+ } | {
2919
+ error: 'address_region_invalid';
2920
+ } | {
2921
+ error: 'delivery_required';
2922
+ store_ids: string[];
2923
+ } | {
2924
+ error: 'delivery_quotes_unavailable';
2925
+ };
2926
+ type CheckoutRefusalCode = CheckoutRefusal['error'];
2820
2927
 
2821
2928
  /**
2822
2929
  * Fields a user may change on their own profile via `PUT /auth/me`. Every field is optional;
@@ -3283,7 +3390,9 @@ declare class APIError extends Error {
3283
3390
  readonly code: string;
3284
3391
  readonly status: number;
3285
3392
  readonly details?: unknown;
3286
- constructor(status: number, data: APIErrorResponse);
3393
+ /** The decoded error body as the server sent it, for errors whose details are top-level fields. */
3394
+ readonly body?: unknown;
3395
+ constructor(status: number, data: APIErrorResponse, body?: unknown);
3287
3396
  }
3288
3397
  declare class APIClient {
3289
3398
  private config;
@@ -4209,6 +4318,8 @@ declare class CartModule {
4209
4318
  }>;
4210
4319
  /**
4211
4320
  * Checkout the cart — creates orders grouped by store and clears the cart.
4321
+ * @deprecated Use `sdk.checkouts.create`: checkout needs an address, an idempotency key and a
4322
+ * delivery quote per shop, and returns the checkout with its totals.
4212
4323
  */
4213
4324
  checkout(options?: RequestOptions): Promise<{
4214
4325
  order_ids: string[];
@@ -4216,6 +4327,25 @@ declare class CartModule {
4216
4327
  }>;
4217
4328
  }
4218
4329
 
4330
+ /**
4331
+ * The checkout refusal carried by an error thrown from `checkouts.create`, or null when the error is
4332
+ * not one. The body is the server's own, so the refusal's details (such as `listings` for
4333
+ * `listing_unavailable`) are present.
4334
+ */
4335
+ declare function checkoutRefusal(error: unknown): CheckoutRefusal | null;
4336
+ declare class CheckoutsModule {
4337
+ private readonly client;
4338
+ constructor(client: APIClient);
4339
+ /**
4340
+ * Create a checkout from the buyer's cart: one order per shop, each at the delivery quote picked
4341
+ * for it, held until the checkout's due-by. A retry with the same `idempotency_key` returns the
4342
+ * same checkout. A refusal throws an `APIError`; read it with `checkoutRefusal(error)`.
4343
+ */
4344
+ create(input: CreateCheckoutInput, options?: RequestOptions): Promise<CreateCheckoutResponse>;
4345
+ /** Read one of the buyer's checkouts. Anyone else gets a 404. */
4346
+ get(checkoutId: string, options?: RequestOptions): Promise<GetCheckoutResponse>;
4347
+ }
4348
+
4219
4349
  declare class SettingsModule {
4220
4350
  private readonly client;
4221
4351
  constructor(client: APIClient);
@@ -5066,6 +5196,25 @@ declare class MarketsModule {
5066
5196
  regions(code: string, options?: RequestOptions): Promise<MarketRegionsResponse>;
5067
5197
  }
5068
5198
 
5199
+ type AvailabilityFields = Pick<CartItem, 'status' | 'quantity' | 'available_quantity'>;
5200
+ /** Whether a cart line can be bought now. See {@link CartLineAvailability}. */
5201
+ declare function cartLineAvailability(item: AvailabilityFields): CartLineAvailability;
5202
+ /** True when the line can be checked out, possibly at a lower quantity (`limited`). */
5203
+ declare function isCartLineBuyable(item: AvailabilityFields): boolean;
5204
+ interface CartPartition<T extends AvailabilityFields> {
5205
+ /** Lines that can be bought exactly as they are. */
5206
+ buyable: T[];
5207
+ /** Lines with fewer units left than in the cart: lower the quantity to `available_quantity`. */
5208
+ limited: T[];
5209
+ /** Lines that cannot be bought now: sold, withdrawn, or reserved by other buyers. */
5210
+ unavailable: T[];
5211
+ }
5212
+ /**
5213
+ * Split a cart for checkout. Checkout refuses a cart holding any line it cannot sell in full, so
5214
+ * `limited` and `unavailable` lines must be fixed (lowered or removed) before checking out.
5215
+ */
5216
+ declare function partitionCart<T extends AvailabilityFields>(items: readonly T[]): CartPartition<T>;
5217
+
5069
5218
  /**
5070
5219
  * Market-aware formatting and validation. Everything here is driven by a `Market` read from
5071
5220
  * `sdk.markets.list()`: no country, currency or calling code is hardcoded, so adding a market
@@ -5162,6 +5311,7 @@ declare class MitumbaClient {
5162
5311
  readonly reviews: ReviewsModule;
5163
5312
  readonly wishlists: WishlistsModule;
5164
5313
  readonly cart: CartModule;
5314
+ readonly checkouts: CheckoutsModule;
5165
5315
  readonly settings: SettingsModule;
5166
5316
  readonly mailer: MailerModule;
5167
5317
  readonly businesses: BusinessesModule;
@@ -5203,4 +5353,4 @@ declare class MitumbaClient {
5203
5353
  isAuthenticated(): Promise<boolean>;
5204
5354
  }
5205
5355
 
5206
- export { APIClient, APIError, type APIErrorResponse, type ActivateIamUserInput, type ActivateIamUserResult, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddIamPasskeyResult, type AddIamTotpResult, type AddIamTwoFactorMethodInput, type AddPaymentMethodInput, type Address, type AdminAuditActor, type AdminAuditEntry, type AdminAuditQuery, type AdminAuthStrength, type AdminListingItem, type AdminMessageReport, type AdminMessageReportDetail, type AdminMessageReportList, type AdminMessageReportThreadMessage, AdminModule, type AdminOperator, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminPermission, type AdminPermissionDescription, type AdminRecoveryEvent, type AdminRecoveryRequest, type AdminReport, type AdminRolePreset, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, type AdminWholesalePendingStore, type ApiResponse, type AttachmentDownloadAuthorization, type AttachmentUploadAuthorization, type AttachmentUploadBody, type AttachmentUploadState, type AttachmentUploadStatus, type AuthCapabilities, AuthModule, type AuthTokens, type AuthenticationResponseJSON, BALE_ORDER_STATUSES, type Bale, type BaleDetail, type BaleFeedItem, type BaleFulfillment, type BaleGrade, type BaleImageUploadResult, type BaleOrder, type BaleOrderEvent, type BaleOrderStatus, type BaleType, type BecomeBaleSellerInput, type BecomeSellerInput, type BlockedIp, type Business, type BusinessType, BusinessesModule, type BuyerResolveThreadInput, type BuyerSummary, CONDITIONS, type CartItem, CartModule, type Category, type ChangePasswordInput, type ChangePlatformSettingInput, type ChangePlatformSettingResult, type CheckoutNextAction, type CheckoutOrder, type CheckoutPaymentMethod, type CheckoutStatus, type CheckoutStatusResponse, type City, type CompleteOnboardingInput, type CompleteRecoveryResult, type Condition, type Conversation, type ConversationId, type ConversationSummary, type CreateAttachmentUploadInput, type CreateBaleInput, type CreateBaleOrderInput, type CreateIamUserInput, type CreateIamUserResult, type CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, type CreateOrganizationInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, type CursorPage, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type FileResponse, type FinishIamPasskeyEnrollmentInput, type FinishIamPasskeyLoginInput, type FollowedStore, type ForgotPasswordInput, IDBTokenStore, type IamActivation, type IamLoginInput, type IamLoginMethod, type IamMethodsResult, IamModule, type IamPasskeyLoginOptions, type IamProfile, type IamSession, type IamSessionsResult, type IamSignIn, type IamSignInFailureReason, type IamSignInsResult, type IamTokens, type IamTwoFactorRequired, type IamUser, type IamUserStatus, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type Jwk, type Jwks, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LibraryCadence, type LibraryCompleter, type LibraryDocument, type LibraryDocumentSummary, type LibraryKind, type LibraryListing, type LibraryOccurrence, type LibraryOccurrenceRecorded, type LibraryOccurrenceStatus, type LibraryRoutineState, type LibrarySchedule, type LibraryScheduleRule, type LibrarySeason, type LibraryWeekday, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListIamUsersResult, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, type Market, type MarketCurrency, type MarketPhone, type MarketRegion, type MarketRegionsResponse, type MarketStatus, MarketsModule, type MarketsResponse, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportOutcome, type MessageReportReason, type MessageReportStatus, type MessageResponse, MessagesModule, type MessagesRealtimeConnection, type MessagesRealtimeEnvelope, type MessagesRealtimeEvent, type MessagesRealtimeOptions, type MessagesRealtimeState, type MessagesRealtimeTicket, type MessagingBlockInput, type MessagingBlockRemovedResult, type MessagingBlockResult, type MessagingCapabilities, type MessagingCursor, type MessagingErrorCode, type MessagingIdempotentRequestOptions, type MessagingInboxes, type MessagingPerspective, type MessagingSide, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, type OAuthAuthorizeInput, type OAuthAuthorizeResult, type OAuthClient, type OAuthClientSummary, type OAuthClientTrustLevel, type OAuthClientType, type OAuthConsent, type OAuthConsentInput, type OAuthConsentRequired, type OAuthConsentRevokeResult, OAuthModule, type OAuthTokenExchangeInput, type OAuthTokenResult, ORDER_STATUSES, type OidcSigningKey, type OpenIdConfiguration, type OperatorPermissionGrant, type Order, type OrderDocument, type OrderDocumentKind, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, type Organization, type OrganizationKind, type OrganizationStatus, type OrganizationSummary, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentAttemptStatus, type PaymentMethod, type PaymentMethodType, type PaymentProvider, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PendingPayoutApproval, type PhoneLoginInput, type PhoneRegisterInput, type PlatformSetting, type PlatformSettingChange, type PlatformSettingDetail, type PlatformSettingGroup, type PlatformSettingKind, type PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegenerateIamBackupCodesResult, type RegisterInput, type RegisterOAuthClientInput, type RegisteredOAuthClient, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, type ResolveMessageReportInput, type ResolveMessageReportResult, type ResolveThreadResult, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type RootSetupInput, type RootSetupResult, type SaveSearchInput, type SaveWholesaleStoreInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SellerType, type SendEmailInput, type SendMessageInput, type SendOtpInput, type SendThreadMessageInput, type SendThreadMessageResult, type Session, SettingsModule, type ShareUrlOptions, type SilentAuthorizeResult, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreResolveThreadInput, type StoreReviewsPage, type StoreSettings, type StoreStats, type StoreSummary, StoresModule, type SubscriptionTier, type SystemStats, TWO_FACTOR_METHOD_TYPES, type ThreadCard, type ThreadId, type ThreadMessage, type ThreadSubject, type ThreadSystemEvent, type ThreadTimelineItem, type ThreadTimelineItemId, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorMethod, type TwoFactorMethodType, type TwoFactorRequired, type UpdateBusinessInput, type UpdateConversationPreferencesInput, type UpdateListingInput, type UpdateOrganizationInput, type UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserInfo, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyIamMethodResult, type VerifyIamTwoFactorInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleReviewStatus, type WholesaleStore, type WishlistListing, WishlistsModule, activeMarkets, baleShareUrl, createTokenStore, findMarket, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, regionById, storeShareUrl };
5356
+ export { APIClient, APIError, type APIErrorResponse, type ActivateIamUserInput, type ActivateIamUserResult, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddIamPasskeyResult, type AddIamTotpResult, type AddIamTwoFactorMethodInput, type AddPaymentMethodInput, type Address, type AdminAuditActor, type AdminAuditEntry, type AdminAuditQuery, type AdminAuthStrength, type AdminListingItem, type AdminMessageReport, type AdminMessageReportDetail, type AdminMessageReportList, type AdminMessageReportThreadMessage, AdminModule, type AdminOperator, type AdminOrderDetail, type AdminOrderListItem, type AdminPayoutItem, type AdminPermission, type AdminPermissionDescription, type AdminRecoveryEvent, type AdminRecoveryRequest, type AdminReport, type AdminRolePreset, type AdminStoreDetail, type AdminStoreListItem, type AdminUserDetail, type AdminUserListItem, type AdminVaziOutfit, type AdminVerificationItem, type AdminWholesalePendingStore, type ApiResponse, type AttachmentDownloadAuthorization, type AttachmentUploadAuthorization, type AttachmentUploadBody, type AttachmentUploadState, type AttachmentUploadStatus, type AuthCapabilities, AuthModule, type AuthTokens, type AuthenticationResponseJSON, BALE_ORDER_STATUSES, type Bale, type BaleDetail, type BaleFeedItem, type BaleFulfillment, type BaleGrade, type BaleImageUploadResult, type BaleOrder, type BaleOrderEvent, type BaleOrderStatus, type BaleType, type BecomeBaleSellerInput, type BecomeSellerInput, type BlockedIp, type Business, type BusinessType, BusinessesModule, type BuyerResolveThreadInput, type BuyerSummary, CONDITIONS, type CartItem, type CartLineAvailability, CartModule, type CartPartition, type Category, type ChangePasswordInput, type ChangePlatformSettingInput, type ChangePlatformSettingResult, type Checkout, type CheckoutMoney, type CheckoutNextAction, type CheckoutOrder, type CheckoutPaymentMethod, type CheckoutRefusal, type CheckoutRefusalCode, type CheckoutShopOrder, type CheckoutState, type CheckoutStatus, type CheckoutStatusResponse, CheckoutsModule, type City, type CompleteOnboardingInput, type CompleteRecoveryResult, type Condition, type Conversation, type ConversationId, type ConversationSummary, type CreateAttachmentUploadInput, type CreateBaleInput, type CreateBaleOrderInput, type CreateCheckoutInput, type CreateCheckoutResponse, type CreateIamUserInput, type CreateIamUserResult, type CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, type CreateOrganizationInput, type CreateReportInput, type CreateReviewInput, type CreateStoreInput, type CursorPage, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, type DeliveryAddress, type DesiredResolution, type Dispute, type DisputeEvent, type DisputeEvidence, type DisputeListParams, type DisputeReason, type DisputeStatus, DisputesModule, type EmailLoginInput, type EmailRegisterInput, type FileResponse, type FinishIamPasskeyEnrollmentInput, type FinishIamPasskeyLoginInput, type FollowedStore, type ForgotPasswordInput, type GetCheckoutResponse, IDBTokenStore, type IamActivation, type IamLoginInput, type IamLoginMethod, type IamMethodsResult, IamModule, type IamPasskeyLoginOptions, type IamProfile, type IamSession, type IamSessionsResult, type IamSignIn, type IamSignInFailureReason, type IamSignInsResult, type IamTokens, type IamTwoFactorRequired, type IamUser, type IamUserStatus, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type Jwk, type Jwks, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LibraryCadence, type LibraryCompleter, type LibraryDocument, type LibraryDocumentSummary, type LibraryKind, type LibraryListing, type LibraryOccurrence, type LibraryOccurrenceRecorded, type LibraryOccurrenceStatus, type LibraryRoutineState, type LibrarySchedule, type LibraryScheduleRule, type LibrarySeason, type LibraryWeekday, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListIamUsersResult, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, type Market, type MarketCurrency, type MarketPhone, type MarketRegion, type MarketRegionsResponse, type MarketStatus, MarketsModule, type MarketsResponse, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportOutcome, type MessageReportReason, type MessageReportStatus, type MessageResponse, MessagesModule, type MessagesRealtimeConnection, type MessagesRealtimeEnvelope, type MessagesRealtimeEvent, type MessagesRealtimeOptions, type MessagesRealtimeState, type MessagesRealtimeTicket, type MessagingBlockInput, type MessagingBlockRemovedResult, type MessagingBlockResult, type MessagingCapabilities, type MessagingCursor, type MessagingErrorCode, type MessagingIdempotentRequestOptions, type MessagingInboxes, type MessagingPerspective, type MessagingSide, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, type OAuthAuthorizeInput, type OAuthAuthorizeResult, type OAuthClient, type OAuthClientSummary, type OAuthClientTrustLevel, type OAuthClientType, type OAuthConsent, type OAuthConsentInput, type OAuthConsentRequired, type OAuthConsentRevokeResult, OAuthModule, type OAuthTokenExchangeInput, type OAuthTokenResult, ORDER_STATUSES, type OidcSigningKey, type OpenIdConfiguration, type OperatorPermissionGrant, type Order, type OrderDocument, type OrderDocumentKind, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, type Organization, type OrganizationKind, type OrganizationStatus, type OrganizationSummary, PAYMENT_STATUSES, type PaginatedResponse, PayModule, type PaymentAttemptStatus, type PaymentMethod, type PaymentMethodType, type PaymentProvider, type PaymentStatus, type PaymentStatusResponse, type PaystackInitResponse, type PaystackInput, type PendingPayoutApproval, type PhoneLoginInput, type PhoneRegisterInput, type PlatformSetting, type PlatformSettingChange, type PlatformSettingDetail, type PlatformSettingGroup, type PlatformSettingKind, type PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegenerateIamBackupCodesResult, type RegisterInput, type RegisterOAuthClientInput, type RegisteredOAuthClient, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, type ResolveMessageReportInput, type ResolveMessageReportResult, type ResolveThreadResult, type RespondDisputeInput, type Review, type ReviewableOrder, ReviewsModule, type RootSetupInput, type RootSetupResult, type SaveSearchInput, type SaveWholesaleStoreInput, type SearchHistoryItem, SearchModule, type SearchParams, type SearchResult, type SellerProfile, type SellerStorefront, type SellerType, type SendEmailInput, type SendMessageInput, type SendOtpInput, type SendThreadMessageInput, type SendThreadMessageResult, type Session, SettingsModule, type ShareUrlOptions, type SilentAuthorizeResult, type SimilarListing, type StiEvent, type StkPushInput, type StkPushResponse, type Store, type StoreAnalytics, type StoreResolveThreadInput, type StoreReviewsPage, type StoreSettings, type StoreStats, type StoreSummary, StoresModule, type SubscriptionTier, type SystemStats, TWO_FACTOR_METHOD_TYPES, type ThreadCard, type ThreadId, type ThreadMessage, type ThreadSubject, type ThreadSystemEvent, type ThreadTimelineItem, type ThreadTimelineItemId, type TokenStore, type TransitionOrderInput, type TrendingTerm, type TwoFactorMethod, type TwoFactorMethodType, type TwoFactorRequired, type UpdateBusinessInput, type UpdateConversationPreferencesInput, type UpdateListingInput, type UpdateOrganizationInput, type UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserInfo, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyIamMethodResult, type VerifyIamTwoFactorInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleReviewStatus, type WholesaleStore, type WishlistListing, WishlistsModule, activeMarkets, baleShareUrl, cartLineAvailability, checkoutRefusal, createTokenStore, findMarket, findRegion, formatAmount, formatMoney, formatMoneyCompact, formatPhone, isCartLineBuyable, isConsentRequired, isMessagingAPIError, isValidPhone, listingShareUrl, maskPhone, normalizePhone, partitionCart, regionById, storeShareUrl };
package/dist/index.js CHANGED
@@ -134,12 +134,15 @@ var APIError = class extends Error {
134
134
  code;
135
135
  status;
136
136
  details;
137
- constructor(status, data) {
137
+ /** The decoded error body as the server sent it, for errors whose details are top-level fields. */
138
+ body;
139
+ constructor(status, data, body) {
138
140
  super(data.message || data.error);
139
141
  this.name = "APIError";
140
142
  this.code = data.error;
141
143
  this.status = status;
142
144
  this.details = data.details;
145
+ this.body = body;
143
146
  }
144
147
  };
145
148
  function isExpiringSoon(token, thresholdSeconds) {
@@ -385,7 +388,7 @@ var APIClient = class {
385
388
  } catch {
386
389
  decoded = null;
387
390
  }
388
- throw new APIError(response.status, normalizeAPIErrorResponse(decoded, response.statusText));
391
+ throw new APIError(response.status, normalizeAPIErrorResponse(decoded, response.statusText), decoded ?? void 0);
389
392
  }
390
393
  return response;
391
394
  }
@@ -2104,12 +2107,57 @@ var CartModule = class {
2104
2107
  }
2105
2108
  /**
2106
2109
  * Checkout the cart — creates orders grouped by store and clears the cart.
2110
+ * @deprecated Use `sdk.checkouts.create`: checkout needs an address, an idempotency key and a
2111
+ * delivery quote per shop, and returns the checkout with its totals.
2107
2112
  */
2108
2113
  async checkout(options) {
2109
2114
  return this.client.post("/orders/checkout", void 0, options);
2110
2115
  }
2111
2116
  };
2112
2117
 
2118
+ // src/modules/checkouts.ts
2119
+ var REFUSAL_CODES = /* @__PURE__ */ new Set([
2120
+ "invalid_input",
2121
+ "empty_cart",
2122
+ "cannot_buy_own",
2123
+ "invalid_deliveries",
2124
+ "address_not_found",
2125
+ "idempotency_conflict",
2126
+ "listing_unavailable",
2127
+ "mixed_market_cart",
2128
+ "market_not_active",
2129
+ "checkout_payment_in_progress",
2130
+ "delivery_quote_rejected",
2131
+ "address_region_invalid",
2132
+ "delivery_required",
2133
+ "delivery_quotes_unavailable"
2134
+ ]);
2135
+ function checkoutRefusal(error) {
2136
+ if (!(error instanceof APIError)) return null;
2137
+ const body = error.body;
2138
+ if (typeof body !== "object" || body === null) return null;
2139
+ const code = body.error;
2140
+ if (typeof code !== "string" || !REFUSAL_CODES.has(code)) return null;
2141
+ return body;
2142
+ }
2143
+ var CheckoutsModule = class {
2144
+ constructor(client) {
2145
+ this.client = client;
2146
+ }
2147
+ /**
2148
+ * Create a checkout from the buyer's cart: one order per shop, each at the delivery quote picked
2149
+ * for it, held until the checkout's due-by. A retry with the same `idempotency_key` returns the
2150
+ * same checkout. A refusal throws an `APIError`; read it with `checkoutRefusal(error)`.
2151
+ */
2152
+ async create(input, options) {
2153
+ return this.client.post("/orders/checkout", input, options);
2154
+ }
2155
+ /** Read one of the buyer's checkouts. Anyone else gets a 404. */
2156
+ async get(checkoutId, options) {
2157
+ return this.client.get(`/orders/checkouts/${encodeURIComponent(checkoutId)}`, void 0, options);
2158
+ }
2159
+ };
2160
+
2113
2161
  // src/modules/settings.ts
2114
2162
  var SettingsModule = class {
2115
2163
  constructor(client) {
@@ -3039,6 +3087,29 @@ var DISPUTE_STATUSES = ["open", "seller_responded", "under_review", "resolved_re
3039
3087
  // src/types/wholesale.ts
3040
3088
  var BALE_ORDER_STATUSES = ["pending_payment", "paid", "confirmed", "in_transit", "delivered", "completed", "cancelled"];
3041
3089
 
3090
+ // src/modules/cart-availability.ts
3091
+ function cartLineAvailability(item) {
3092
+ if (item.status === "sold") return "sold";
3093
+ if (item.status !== "active") return "unavailable";
3094
+ if (item.available_quantity <= 0) return "reserved";
3095
+ if (item.available_quantity < item.quantity) return "limited";
3096
+ return "available";
3097
+ }
3098
+ function isCartLineBuyable(item) {
3099
+ const availability = cartLineAvailability(item);
3100
+ return availability === "available" || availability === "limited";
3101
+ }
3102
+ function partitionCart(items) {
3103
+ const partition = { buyable: [], limited: [], unavailable: [] };
3104
+ for (const item of items) {
3105
+ const availability = cartLineAvailability(item);
3106
+ if (availability === "available") partition.buyable.push(item);
3107
+ else if (availability === "limited") partition.limited.push(item);
3108
+ else partition.unavailable.push(item);
3109
+ }
3110
+ return partition;
3111
+ }
3112
+
3042
3113
  // src/markets.ts
3043
3114
  var GAP = " ";
3044
3115
  function group(value, locale) {
@@ -3198,6 +3269,7 @@ var MitumbaClient = class {
3198
3269
  reviews;
3199
3270
  wishlists;
3200
3271
  cart;
3272
+ checkouts;
3201
3273
  settings;
3202
3274
  mailer;
3203
3275
  businesses;
@@ -3223,6 +3295,7 @@ var MitumbaClient = class {
3223
3295
  this.reviews = new ReviewsModule(this.api);
3224
3296
  this.wishlists = new WishlistsModule(this.api);
3225
3297
  this.cart = new CartModule(this.api);
3298
+ this.checkouts = new CheckoutsModule(this.api);
3226
3299
  this.settings = new SettingsModule(this.api);
3227
3300
  this.mailer = new MailerModule(this.api);
3228
3301
  this.businesses = new BusinessesModule(this.api);
@@ -3281,6 +3354,7 @@ exports.BALE_ORDER_STATUSES = BALE_ORDER_STATUSES;
3281
3354
  exports.BusinessesModule = BusinessesModule;
3282
3355
  exports.CONDITIONS = CONDITIONS;
3283
3356
  exports.CartModule = CartModule;
3357
+ exports.CheckoutsModule = CheckoutsModule;
3284
3358
  exports.DEFAULT_SHARE_ORIGIN = DEFAULT_SHARE_ORIGIN;
3285
3359
  exports.DESIRED_RESOLUTIONS = DESIRED_RESOLUTIONS;
3286
3360
  exports.DISPUTE_REASONS = DISPUTE_REASONS;
@@ -3315,6 +3389,8 @@ exports.WholesaleModule = WholesaleModule;
3315
3389
  exports.WishlistsModule = WishlistsModule;
3316
3390
  exports.activeMarkets = activeMarkets;
3317
3391
  exports.baleShareUrl = baleShareUrl;
3392
+ exports.cartLineAvailability = cartLineAvailability;
3393
+ exports.checkoutRefusal = checkoutRefusal;
3318
3394
  exports.createTokenStore = createTokenStore;
3319
3395
  exports.findMarket = findMarket;
3320
3396
  exports.findRegion = findRegion;
@@ -3322,12 +3398,14 @@ exports.formatAmount = formatAmount;
3322
3398
  exports.formatMoney = formatMoney;
3323
3399
  exports.formatMoneyCompact = formatMoneyCompact;
3324
3400
  exports.formatPhone = formatPhone;
3401
+ exports.isCartLineBuyable = isCartLineBuyable;
3325
3402
  exports.isConsentRequired = isConsentRequired;
3326
3403
  exports.isMessagingAPIError = isMessagingAPIError;
3327
3404
  exports.isValidPhone = isValidPhone;
3328
3405
  exports.listingShareUrl = listingShareUrl;
3329
3406
  exports.maskPhone = maskPhone;
3330
3407
  exports.normalizePhone = normalizePhone;
3408
+ exports.partitionCart = partitionCart;
3331
3409
  exports.regionById = regionById;
3332
3410
  exports.storeShareUrl = storeShareUrl;
3333
3411
  //# sourceMappingURL=index.js.map