@mitumba/sdk 4.0.0 → 5.1.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
@@ -1356,6 +1356,66 @@ interface RootSetupResult {
1356
1356
  permissions: AdminPermission[];
1357
1357
  next_step: string;
1358
1358
  }
1359
+ /**
1360
+ * Request body for the authorize (mint) step. The accounts app calls this once the user is
1361
+ * authenticated to mint a one-time authorization code for the relying party.
1362
+ *
1363
+ * The SDK always sets `code_challenge_method: 'S256'` internally, so callers never supply it.
1364
+ */
1365
+ interface OAuthAuthorizeInput {
1366
+ /** The relying party's registered client identifier. */
1367
+ client_id: string;
1368
+ /** The registered redirect URI the one-time code is returned to. */
1369
+ redirect_uri: string;
1370
+ /** Optional space-delimited list of requested scopes. */
1371
+ scope?: string;
1372
+ /** Opaque value echoed back unchanged, used by the relying party for CSRF protection. */
1373
+ state: string;
1374
+ /** The PKCE code challenge (base64url SHA-256 of the verifier). */
1375
+ code_challenge: string;
1376
+ }
1377
+ /**
1378
+ * Result of the authorize (mint) step: a one-time authorization code plus the echoed state.
1379
+ */
1380
+ interface OAuthAuthorizeResult {
1381
+ /** One-time authorization code to redirect back to the relying party. */
1382
+ code: string;
1383
+ /** The `state` value supplied in the request, echoed back unchanged. */
1384
+ state: string;
1385
+ }
1386
+ /**
1387
+ * Request body for the token exchange step. The relying party exchanges the one-time code for a
1388
+ * token pair. `grant_type` is set to `'authorization_code'` by the SDK, so callers need not pass it.
1389
+ */
1390
+ interface OAuthTokenExchangeInput {
1391
+ /** Always `'authorization_code'`. Defaulted by the SDK; callers may omit it. */
1392
+ grant_type?: 'authorization_code';
1393
+ /** The one-time authorization code returned by the authorize step. */
1394
+ code: string;
1395
+ /** The redirect URI used in the authorize step; must match exactly. */
1396
+ redirect_uri: string;
1397
+ /** The relying party's registered client identifier. */
1398
+ client_id: string;
1399
+ /** The PKCE code verifier that matches the earlier code challenge. */
1400
+ code_verifier: string;
1401
+ /** The client secret for confidential clients. Omit for public clients. */
1402
+ client_secret?: string;
1403
+ }
1404
+ /**
1405
+ * Result of a successful token exchange: the access/refresh token pair and its metadata.
1406
+ */
1407
+ interface OAuthTokenResult {
1408
+ /** The access token (JWT) for authenticated requests. */
1409
+ access_token: string;
1410
+ /** The refresh token used to rotate the access token. */
1411
+ refresh_token: string;
1412
+ /** Lifetime of the access token in seconds. */
1413
+ expires_in: number;
1414
+ /** Always `'Bearer'`. */
1415
+ token_type: 'Bearer';
1416
+ /** Space-delimited list of scopes actually granted. */
1417
+ scope: string;
1418
+ }
1359
1419
 
1360
1420
  declare const CONDITIONS: readonly ["new", "like_new", "good", "fair"];
1361
1421
  type Condition = typeof CONDITIONS[number];
@@ -1518,6 +1578,12 @@ interface Order {
1518
1578
  listing_condition: string | null;
1519
1579
  listing_size: string | null;
1520
1580
  buyer_name: string | null;
1581
+ /**
1582
+ * The buyer's county. Not sensitive — always returned to both parties, including to the seller
1583
+ * before payment (with `buyer_name`) while `buyer_phone`/`delivery_address` are withheld.
1584
+ * (Mitumba-Ltd/mitumba#321)
1585
+ */
1586
+ buyer_county: string | null;
1521
1587
  /**
1522
1588
  * The buyer's phone. Visible to the buyer at any status. Visible to the seller **only** while
1523
1589
  * they are handing the parcel over — statuses `paid`, `seller_confirmed`, `shipped`,
@@ -2403,6 +2469,11 @@ declare class APIClient {
2403
2469
  /** Create an isomorphic WebSocket using the configured or global transport. */
2404
2470
  createWebSocket(url: string, protocols: string | string[]): WebSocketLike;
2405
2471
  clearToken(): Promise<void>;
2472
+ /**
2473
+ * The current stored refresh token, or null if none. Exposed so logout can revoke the exact
2474
+ * token the SDK holds rather than relying on the caller to supply (or guess) it.
2475
+ */
2476
+ getStoredRefreshToken(): Promise<string | null>;
2406
2477
  /**
2407
2478
  * Check if user has a stored session (access or refresh token available).
2408
2479
  */
@@ -2451,12 +2522,19 @@ declare class AuthModule {
2451
2522
  refresh_token: string;
2452
2523
  }, options?: RequestOptions): Promise<AuthTokens>;
2453
2524
  /**
2454
- * Revoke the refresh token and log out. Clears stored session.
2525
+ * Log out: revoke the current server session and clear the stored tokens.
2526
+ *
2527
+ * Reads the refresh token the SDK holds and revokes exactly that session server-side, then
2528
+ * always clears local tokens — even if the network call fails or there was no token — so the
2529
+ * device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
2530
+ *
2531
+ * @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
2532
+ * `revoked: false` means local credentials were cleared but the server session may persist
2533
+ * until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
2455
2534
  */
2456
- logout(input: {
2457
- refresh_token: string;
2458
- }, options?: RequestOptions): Promise<{
2535
+ logout(options?: RequestOptions): Promise<{
2459
2536
  ok: boolean;
2537
+ revoked: boolean;
2460
2538
  }>;
2461
2539
  /**
2462
2540
  * Request a password reset email.
@@ -2605,6 +2683,70 @@ declare class AuthModule {
2605
2683
  }>;
2606
2684
  }
2607
2685
 
2686
+ /**
2687
+ * Relying-party OAuth session hand-off.
2688
+ *
2689
+ * Wraps the authorization-code + PKCE flow: the accounts app mints a one-time code with
2690
+ * {@link OAuthModule.authorize}, redirects it back to the relying party, and the relying party
2691
+ * exchanges it for a token pair with {@link OAuthModule.exchangeCode}.
2692
+ */
2693
+ declare class OAuthModule {
2694
+ private readonly client;
2695
+ constructor(client: APIClient);
2696
+ /**
2697
+ * Mint a one-time authorization code for the relying party.
2698
+ *
2699
+ * This is the authenticated mint step the accounts app calls after the user is signed in. It
2700
+ * returns a one-time code (plus the echoed `state`) that the app then redirects back to the
2701
+ * relying party's `redirect_uri`. The PKCE method is fixed to `'S256'` by the SDK, so callers
2702
+ * cannot supply a weaker value. The returned code is not a session — this method does not
2703
+ * persist anything.
2704
+ *
2705
+ * @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
2706
+ * @param options - Optional per-request options (abort signal, extra headers)
2707
+ * @returns The one-time authorization code and the echoed `state`
2708
+ * @throws {APIError} On `400` (`invalid_redirect_uri`, `invalid_client`, `invalid_scope`) or other errors
2709
+ *
2710
+ * @example
2711
+ * ```typescript
2712
+ * const { code, state } = await sdk.oauth.authorize({
2713
+ * client_id: 'rp_abc',
2714
+ * redirect_uri: 'https://app.example.com/callback',
2715
+ * scope: 'profile email',
2716
+ * state: csrfState,
2717
+ * code_challenge: challenge,
2718
+ * })
2719
+ * ```
2720
+ */
2721
+ authorize(input: OAuthAuthorizeInput, options?: RequestOptions): Promise<OAuthAuthorizeResult>;
2722
+ /**
2723
+ * Exchange a one-time authorization code for a token pair.
2724
+ *
2725
+ * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
2726
+ * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
2727
+ * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
2728
+ * persisted into the client session via `setSession`, so the relying party is logged in
2729
+ * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
2730
+ *
2731
+ * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
2732
+ * @param options - Optional per-request options (abort signal, extra headers)
2733
+ * @returns The access/refresh token pair and granted scope
2734
+ * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
2735
+ *
2736
+ * @example
2737
+ * ```typescript
2738
+ * const tokens = await sdk.oauth.exchangeCode({
2739
+ * code,
2740
+ * redirect_uri: 'https://app.example.com/callback',
2741
+ * client_id: 'rp_abc',
2742
+ * code_verifier: verifier,
2743
+ * })
2744
+ * // sdk is now authenticated as the exchanged session
2745
+ * ```
2746
+ */
2747
+ exchangeCode(input: OAuthTokenExchangeInput, options?: RequestOptions): Promise<OAuthTokenResult>;
2748
+ }
2749
+
2608
2750
  declare class ListingsModule {
2609
2751
  private readonly client;
2610
2752
  constructor(client: APIClient);
@@ -3732,6 +3874,7 @@ declare function baleShareUrl(baleId: string, options?: ShareUrlOptions): string
3732
3874
  declare class MitumbaClient {
3733
3875
  readonly api: APIClient;
3734
3876
  readonly auth: AuthModule;
3877
+ readonly oauth: OAuthModule;
3735
3878
  readonly listings: ListingsModule;
3736
3879
  readonly search: SearchModule;
3737
3880
  readonly orders: OrdersModule;
@@ -3782,4 +3925,4 @@ declare class MitumbaClient {
3782
3925
  isAuthenticated(): Promise<boolean>;
3783
3926
  }
3784
3927
 
3785
- export { APIClient, APIError, type APIErrorResponse, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddPaymentMethodInput, type Address, type AdminAuditEntry, type AdminAuthStrength, type AdminListingItem, 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 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 CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, 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 FollowedStore, type ForgotPasswordInput, IDBTokenStore, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportReason, 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, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, ORDER_STATUSES, type OperatorPermissionGrant, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, 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 PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegisterInput, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, 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 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 UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleStore, type WishlistListing, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
3928
+ export { APIClient, APIError, type APIErrorResponse, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddPaymentMethodInput, type Address, type AdminAuditEntry, type AdminAuthStrength, type AdminListingItem, 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 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 CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, 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 FollowedStore, type ForgotPasswordInput, IDBTokenStore, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportReason, 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, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, type OAuthAuthorizeInput, type OAuthAuthorizeResult, OAuthModule, type OAuthTokenExchangeInput, type OAuthTokenResult, ORDER_STATUSES, type OperatorPermissionGrant, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, 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 PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegisterInput, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, 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 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 UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleStore, type WishlistListing, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
package/dist/index.d.ts CHANGED
@@ -1356,6 +1356,66 @@ interface RootSetupResult {
1356
1356
  permissions: AdminPermission[];
1357
1357
  next_step: string;
1358
1358
  }
1359
+ /**
1360
+ * Request body for the authorize (mint) step. The accounts app calls this once the user is
1361
+ * authenticated to mint a one-time authorization code for the relying party.
1362
+ *
1363
+ * The SDK always sets `code_challenge_method: 'S256'` internally, so callers never supply it.
1364
+ */
1365
+ interface OAuthAuthorizeInput {
1366
+ /** The relying party's registered client identifier. */
1367
+ client_id: string;
1368
+ /** The registered redirect URI the one-time code is returned to. */
1369
+ redirect_uri: string;
1370
+ /** Optional space-delimited list of requested scopes. */
1371
+ scope?: string;
1372
+ /** Opaque value echoed back unchanged, used by the relying party for CSRF protection. */
1373
+ state: string;
1374
+ /** The PKCE code challenge (base64url SHA-256 of the verifier). */
1375
+ code_challenge: string;
1376
+ }
1377
+ /**
1378
+ * Result of the authorize (mint) step: a one-time authorization code plus the echoed state.
1379
+ */
1380
+ interface OAuthAuthorizeResult {
1381
+ /** One-time authorization code to redirect back to the relying party. */
1382
+ code: string;
1383
+ /** The `state` value supplied in the request, echoed back unchanged. */
1384
+ state: string;
1385
+ }
1386
+ /**
1387
+ * Request body for the token exchange step. The relying party exchanges the one-time code for a
1388
+ * token pair. `grant_type` is set to `'authorization_code'` by the SDK, so callers need not pass it.
1389
+ */
1390
+ interface OAuthTokenExchangeInput {
1391
+ /** Always `'authorization_code'`. Defaulted by the SDK; callers may omit it. */
1392
+ grant_type?: 'authorization_code';
1393
+ /** The one-time authorization code returned by the authorize step. */
1394
+ code: string;
1395
+ /** The redirect URI used in the authorize step; must match exactly. */
1396
+ redirect_uri: string;
1397
+ /** The relying party's registered client identifier. */
1398
+ client_id: string;
1399
+ /** The PKCE code verifier that matches the earlier code challenge. */
1400
+ code_verifier: string;
1401
+ /** The client secret for confidential clients. Omit for public clients. */
1402
+ client_secret?: string;
1403
+ }
1404
+ /**
1405
+ * Result of a successful token exchange: the access/refresh token pair and its metadata.
1406
+ */
1407
+ interface OAuthTokenResult {
1408
+ /** The access token (JWT) for authenticated requests. */
1409
+ access_token: string;
1410
+ /** The refresh token used to rotate the access token. */
1411
+ refresh_token: string;
1412
+ /** Lifetime of the access token in seconds. */
1413
+ expires_in: number;
1414
+ /** Always `'Bearer'`. */
1415
+ token_type: 'Bearer';
1416
+ /** Space-delimited list of scopes actually granted. */
1417
+ scope: string;
1418
+ }
1359
1419
 
1360
1420
  declare const CONDITIONS: readonly ["new", "like_new", "good", "fair"];
1361
1421
  type Condition = typeof CONDITIONS[number];
@@ -1518,6 +1578,12 @@ interface Order {
1518
1578
  listing_condition: string | null;
1519
1579
  listing_size: string | null;
1520
1580
  buyer_name: string | null;
1581
+ /**
1582
+ * The buyer's county. Not sensitive — always returned to both parties, including to the seller
1583
+ * before payment (with `buyer_name`) while `buyer_phone`/`delivery_address` are withheld.
1584
+ * (Mitumba-Ltd/mitumba#321)
1585
+ */
1586
+ buyer_county: string | null;
1521
1587
  /**
1522
1588
  * The buyer's phone. Visible to the buyer at any status. Visible to the seller **only** while
1523
1589
  * they are handing the parcel over — statuses `paid`, `seller_confirmed`, `shipped`,
@@ -2403,6 +2469,11 @@ declare class APIClient {
2403
2469
  /** Create an isomorphic WebSocket using the configured or global transport. */
2404
2470
  createWebSocket(url: string, protocols: string | string[]): WebSocketLike;
2405
2471
  clearToken(): Promise<void>;
2472
+ /**
2473
+ * The current stored refresh token, or null if none. Exposed so logout can revoke the exact
2474
+ * token the SDK holds rather than relying on the caller to supply (or guess) it.
2475
+ */
2476
+ getStoredRefreshToken(): Promise<string | null>;
2406
2477
  /**
2407
2478
  * Check if user has a stored session (access or refresh token available).
2408
2479
  */
@@ -2451,12 +2522,19 @@ declare class AuthModule {
2451
2522
  refresh_token: string;
2452
2523
  }, options?: RequestOptions): Promise<AuthTokens>;
2453
2524
  /**
2454
- * Revoke the refresh token and log out. Clears stored session.
2525
+ * Log out: revoke the current server session and clear the stored tokens.
2526
+ *
2527
+ * Reads the refresh token the SDK holds and revokes exactly that session server-side, then
2528
+ * always clears local tokens — even if the network call fails or there was no token — so the
2529
+ * device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
2530
+ *
2531
+ * @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
2532
+ * `revoked: false` means local credentials were cleared but the server session may persist
2533
+ * until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
2455
2534
  */
2456
- logout(input: {
2457
- refresh_token: string;
2458
- }, options?: RequestOptions): Promise<{
2535
+ logout(options?: RequestOptions): Promise<{
2459
2536
  ok: boolean;
2537
+ revoked: boolean;
2460
2538
  }>;
2461
2539
  /**
2462
2540
  * Request a password reset email.
@@ -2605,6 +2683,70 @@ declare class AuthModule {
2605
2683
  }>;
2606
2684
  }
2607
2685
 
2686
+ /**
2687
+ * Relying-party OAuth session hand-off.
2688
+ *
2689
+ * Wraps the authorization-code + PKCE flow: the accounts app mints a one-time code with
2690
+ * {@link OAuthModule.authorize}, redirects it back to the relying party, and the relying party
2691
+ * exchanges it for a token pair with {@link OAuthModule.exchangeCode}.
2692
+ */
2693
+ declare class OAuthModule {
2694
+ private readonly client;
2695
+ constructor(client: APIClient);
2696
+ /**
2697
+ * Mint a one-time authorization code for the relying party.
2698
+ *
2699
+ * This is the authenticated mint step the accounts app calls after the user is signed in. It
2700
+ * returns a one-time code (plus the echoed `state`) that the app then redirects back to the
2701
+ * relying party's `redirect_uri`. The PKCE method is fixed to `'S256'` by the SDK, so callers
2702
+ * cannot supply a weaker value. The returned code is not a session — this method does not
2703
+ * persist anything.
2704
+ *
2705
+ * @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
2706
+ * @param options - Optional per-request options (abort signal, extra headers)
2707
+ * @returns The one-time authorization code and the echoed `state`
2708
+ * @throws {APIError} On `400` (`invalid_redirect_uri`, `invalid_client`, `invalid_scope`) or other errors
2709
+ *
2710
+ * @example
2711
+ * ```typescript
2712
+ * const { code, state } = await sdk.oauth.authorize({
2713
+ * client_id: 'rp_abc',
2714
+ * redirect_uri: 'https://app.example.com/callback',
2715
+ * scope: 'profile email',
2716
+ * state: csrfState,
2717
+ * code_challenge: challenge,
2718
+ * })
2719
+ * ```
2720
+ */
2721
+ authorize(input: OAuthAuthorizeInput, options?: RequestOptions): Promise<OAuthAuthorizeResult>;
2722
+ /**
2723
+ * Exchange a one-time authorization code for a token pair.
2724
+ *
2725
+ * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
2726
+ * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
2727
+ * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
2728
+ * persisted into the client session via `setSession`, so the relying party is logged in
2729
+ * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
2730
+ *
2731
+ * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
2732
+ * @param options - Optional per-request options (abort signal, extra headers)
2733
+ * @returns The access/refresh token pair and granted scope
2734
+ * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
2735
+ *
2736
+ * @example
2737
+ * ```typescript
2738
+ * const tokens = await sdk.oauth.exchangeCode({
2739
+ * code,
2740
+ * redirect_uri: 'https://app.example.com/callback',
2741
+ * client_id: 'rp_abc',
2742
+ * code_verifier: verifier,
2743
+ * })
2744
+ * // sdk is now authenticated as the exchanged session
2745
+ * ```
2746
+ */
2747
+ exchangeCode(input: OAuthTokenExchangeInput, options?: RequestOptions): Promise<OAuthTokenResult>;
2748
+ }
2749
+
2608
2750
  declare class ListingsModule {
2609
2751
  private readonly client;
2610
2752
  constructor(client: APIClient);
@@ -3732,6 +3874,7 @@ declare function baleShareUrl(baleId: string, options?: ShareUrlOptions): string
3732
3874
  declare class MitumbaClient {
3733
3875
  readonly api: APIClient;
3734
3876
  readonly auth: AuthModule;
3877
+ readonly oauth: OAuthModule;
3735
3878
  readonly listings: ListingsModule;
3736
3879
  readonly search: SearchModule;
3737
3880
  readonly orders: OrdersModule;
@@ -3782,4 +3925,4 @@ declare class MitumbaClient {
3782
3925
  isAuthenticated(): Promise<boolean>;
3783
3926
  }
3784
3927
 
3785
- export { APIClient, APIError, type APIErrorResponse, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddPaymentMethodInput, type Address, type AdminAuditEntry, type AdminAuthStrength, type AdminListingItem, 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 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 CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, 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 FollowedStore, type ForgotPasswordInput, IDBTokenStore, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportReason, 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, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, ORDER_STATUSES, type OperatorPermissionGrant, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, 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 PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegisterInput, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, 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 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 UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleStore, type WishlistListing, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
3928
+ export { APIClient, APIError, type APIErrorResponse, type Add2FAMethodInput, type Add2FAMethodResult, type AddAddressInput, type AddDepotInput, type AddPaymentMethodInput, type Address, type AdminAuditEntry, type AdminAuthStrength, type AdminListingItem, 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 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 CreateListingInput, type CreateMessageBlockInput, type CreateMessageBlockResult, type CreateMessageReportInput, type CreateMessageReportResult, type CreateOrderInput, 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 FollowedStore, type ForgotPasswordInput, IDBTokenStore, type InboxRealtimeEvent, type InitiateCheckoutInput, type InitiateCheckoutResponse, type KnownPaymentProvider, LISTING_STATUSES, type LegacyLinkResolution, type LegacyMessageArchiveSummary, type LegacyMessagePage, type LegacyMessageRecord, type LinkedAccount, type LinkedAccountProvider, type ListConversationsParams, type ListThreadMessagesParams, type ListThreadsParams, type Listing, type ListingImage, type ListingStatus, type ListingsFeedParams, ListingsModule, type LoginInput, MailerModule, type MailerTemplate, MemoryTokenStore, type Message, type MessageAttachment, type MessageAuthor, type MessageId, type MessagePage, type MessageReportReason, 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, MitumbaClient, type MitumbaClientConfig, type MpesaInput, type Notification, type NotificationPref, type NotificationType, NotificationsModule, type OAuthAuthorizeInput, type OAuthAuthorizeResult, OAuthModule, type OAuthTokenExchangeInput, type OAuthTokenResult, ORDER_STATUSES, type OperatorPermissionGrant, type Order, type OrderEvent, type OrderHistoryParams, type OrderStatus, OrdersModule, 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 PresignImageResponse, type ProviderId, type PublicKeyCredentialCreationOptionsJSON, type PublicKeyCredentialRequestOptionsJSON, type RaiseDisputeInput, type ReadCursorResult, RealtimeProtocolError, RealtimeUnavailableError, type RecoveryStatus, type RecoveryStatusResult, type RegenerateBackupCodesResult, type RegisterInput, type RegistrationResponseJSON, ReportsModule, type RequestOptions, type RequestRecoveryInput, type RequestRecoveryResult, type ResetPasswordInput, type ResolveDisputeInput, 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 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 UpdateProfileInput, type UpdateStoreInput, type UpdateThreadPreferencesInput, UploadsModule, type UserProfile, type VAZIOutfit, type VAZIOutfitDetail, type VAZIOutfitDetailItem, type VAZIOutfitItem, type VaziFeedParams, type VaziFeedResponse, VaziModule, type Verify2FAInput, type VerifyOtpInput, type WebSocketCloseEventLike, type WebSocketFactory, type WebSocketLike, type WebSocketMessageEventLike, type WholesaleAnalytics, type WholesaleDepot, type WholesaleFeedParams, WholesaleModule, type WholesaleStore, type WishlistListing, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
package/dist/index.js CHANGED
@@ -229,6 +229,13 @@ var APIClient = class {
229
229
  this.config.refreshToken = void 0;
230
230
  await this.tokenStore.clear();
231
231
  }
232
+ /**
233
+ * The current stored refresh token, or null if none. Exposed so logout can revoke the exact
234
+ * token the SDK holds rather than relying on the caller to supply (or guess) it.
235
+ */
236
+ async getStoredRefreshToken() {
237
+ return this.config.refreshToken ?? await this.tokenStore.getRefreshToken();
238
+ }
232
239
  /**
233
240
  * Check if user has a stored session (access or refresh token available).
234
241
  */
@@ -473,12 +480,28 @@ var AuthModule = class {
473
480
  return result;
474
481
  }
475
482
  /**
476
- * Revoke the refresh token and log out. Clears stored session.
483
+ * Log out: revoke the current server session and clear the stored tokens.
484
+ *
485
+ * Reads the refresh token the SDK holds and revokes exactly that session server-side, then
486
+ * always clears local tokens — even if the network call fails or there was no token — so the
487
+ * device is signed out regardless. Idempotent: a second call is a no-op that still resolves.
488
+ *
489
+ * @returns `{ ok, revoked }` where `revoked` is true only when the server confirmed revocation.
490
+ * `revoked: false` means local credentials were cleared but the server session may persist
491
+ * until expiry (offline, or already revoked) — callers should not claim remote sign-out then.
477
492
  */
478
- async logout(input, options) {
479
- const result = await this.client.post("/auth/logout", input, options);
480
- await this.client.clearToken();
481
- return result;
493
+ async logout(options) {
494
+ const refreshToken = await this.client.getStoredRefreshToken();
495
+ let revoked = false;
496
+ try {
497
+ if (refreshToken) {
498
+ await this.client.post("/auth/logout", { refresh_token: refreshToken }, options);
499
+ revoked = true;
500
+ }
501
+ } finally {
502
+ await this.client.clearToken();
503
+ }
504
+ return { ok: true, revoked };
482
505
  }
483
506
  /**
484
507
  * Request a password reset email.
@@ -655,6 +678,83 @@ var AuthModule = class {
655
678
  }
656
679
  };
657
680
 
681
+ // src/modules/oauth.ts
682
+ var OAuthModule = class {
683
+ constructor(client) {
684
+ this.client = client;
685
+ }
686
+ client;
687
+ /**
688
+ * Mint a one-time authorization code for the relying party.
689
+ *
690
+ * This is the authenticated mint step the accounts app calls after the user is signed in. It
691
+ * returns a one-time code (plus the echoed `state`) that the app then redirects back to the
692
+ * relying party's `redirect_uri`. The PKCE method is fixed to `'S256'` by the SDK, so callers
693
+ * cannot supply a weaker value. The returned code is not a session — this method does not
694
+ * persist anything.
695
+ *
696
+ * @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
697
+ * @param options - Optional per-request options (abort signal, extra headers)
698
+ * @returns The one-time authorization code and the echoed `state`
699
+ * @throws {APIError} On `400` (`invalid_redirect_uri`, `invalid_client`, `invalid_scope`) or other errors
700
+ *
701
+ * @example
702
+ * ```typescript
703
+ * const { code, state } = await sdk.oauth.authorize({
704
+ * client_id: 'rp_abc',
705
+ * redirect_uri: 'https://app.example.com/callback',
706
+ * scope: 'profile email',
707
+ * state: csrfState,
708
+ * code_challenge: challenge,
709
+ * })
710
+ * ```
711
+ */
712
+ async authorize(input, options) {
713
+ return this.client.post(
714
+ "/auth/oauth/authorize",
715
+ { ...input, code_challenge_method: "S256" },
716
+ options
717
+ );
718
+ }
719
+ /**
720
+ * Exchange a one-time authorization code for a token pair.
721
+ *
722
+ * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
723
+ * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
724
+ * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
725
+ * persisted into the client session via `setSession`, so the relying party is logged in
726
+ * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
727
+ *
728
+ * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
729
+ * @param options - Optional per-request options (abort signal, extra headers)
730
+ * @returns The access/refresh token pair and granted scope
731
+ * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
732
+ *
733
+ * @example
734
+ * ```typescript
735
+ * const tokens = await sdk.oauth.exchangeCode({
736
+ * code,
737
+ * redirect_uri: 'https://app.example.com/callback',
738
+ * client_id: 'rp_abc',
739
+ * code_verifier: verifier,
740
+ * })
741
+ * // sdk is now authenticated as the exchanged session
742
+ * ```
743
+ */
744
+ async exchangeCode(input, options) {
745
+ const result = await this.client.post(
746
+ "/auth/oauth/token",
747
+ { ...input, grant_type: "authorization_code" },
748
+ options
749
+ );
750
+ await this.client.setSession({
751
+ access_token: result.access_token,
752
+ refresh_token: result.refresh_token
753
+ });
754
+ return result;
755
+ }
756
+ };
757
+
658
758
  // src/modules/listings.ts
659
759
  var ListingsModule = class {
660
760
  constructor(client) {
@@ -2450,6 +2550,7 @@ function baleShareUrl(baleId, options = {}) {
2450
2550
  var MitumbaClient = class {
2451
2551
  api;
2452
2552
  auth;
2553
+ oauth;
2453
2554
  listings;
2454
2555
  search;
2455
2556
  orders;
@@ -2472,6 +2573,7 @@ var MitumbaClient = class {
2472
2573
  constructor(config) {
2473
2574
  this.api = new APIClient(config);
2474
2575
  this.auth = new AuthModule(this.api);
2576
+ this.oauth = new OAuthModule(this.api);
2475
2577
  this.listings = new ListingsModule(this.api);
2476
2578
  this.search = new SearchModule(this.api);
2477
2579
  this.orders = new OrdersModule(this.api);
@@ -2552,6 +2654,7 @@ exports.MemoryTokenStore = MemoryTokenStore;
2552
2654
  exports.MessagesModule = MessagesModule;
2553
2655
  exports.MitumbaClient = MitumbaClient;
2554
2656
  exports.NotificationsModule = NotificationsModule;
2657
+ exports.OAuthModule = OAuthModule;
2555
2658
  exports.ORDER_STATUSES = ORDER_STATUSES;
2556
2659
  exports.OrdersModule = OrdersModule;
2557
2660
  exports.PAYMENT_STATUSES = PAYMENT_STATUSES;