@mitumba/sdk 5.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.mjs CHANGED
@@ -676,6 +676,83 @@ var AuthModule = class {
676
676
  }
677
677
  };
678
678
 
679
+ // src/modules/oauth.ts
680
+ var OAuthModule = class {
681
+ constructor(client) {
682
+ this.client = client;
683
+ }
684
+ client;
685
+ /**
686
+ * Mint a one-time authorization code for the relying party.
687
+ *
688
+ * This is the authenticated mint step the accounts app calls after the user is signed in. It
689
+ * returns a one-time code (plus the echoed `state`) that the app then redirects back to the
690
+ * relying party's `redirect_uri`. The PKCE method is fixed to `'S256'` by the SDK, so callers
691
+ * cannot supply a weaker value. The returned code is not a session — this method does not
692
+ * persist anything.
693
+ *
694
+ * @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
695
+ * @param options - Optional per-request options (abort signal, extra headers)
696
+ * @returns The one-time authorization code and the echoed `state`
697
+ * @throws {APIError} On `400` (`invalid_redirect_uri`, `invalid_client`, `invalid_scope`) or other errors
698
+ *
699
+ * @example
700
+ * ```typescript
701
+ * const { code, state } = await sdk.oauth.authorize({
702
+ * client_id: 'rp_abc',
703
+ * redirect_uri: 'https://app.example.com/callback',
704
+ * scope: 'profile email',
705
+ * state: csrfState,
706
+ * code_challenge: challenge,
707
+ * })
708
+ * ```
709
+ */
710
+ async authorize(input, options) {
711
+ return this.client.post(
712
+ "/auth/oauth/authorize",
713
+ { ...input, code_challenge_method: "S256" },
714
+ options
715
+ );
716
+ }
717
+ /**
718
+ * Exchange a one-time authorization code for a token pair.
719
+ *
720
+ * The relying party calls this server-to-server (or from its own origin) with the PKCE verifier
721
+ * that matches the earlier challenge. The authorization code is single-use — a reused, expired,
722
+ * or tampered code is rejected with `400 invalid_grant`. On success the returned tokens are
723
+ * persisted into the client session via `setSession`, so the relying party is logged in
724
+ * immediately after the exchange. `grant_type` is set to `'authorization_code'` by the SDK.
725
+ *
726
+ * @param input - The token exchange request (code, redirect URI, client, PKCE verifier, optional secret)
727
+ * @param options - Optional per-request options (abort signal, extra headers)
728
+ * @returns The access/refresh token pair and granted scope
729
+ * @throws {APIError} On `400 invalid_grant` (bad/expired/replayed code) or `401 invalid_client` (wrong secret)
730
+ *
731
+ * @example
732
+ * ```typescript
733
+ * const tokens = await sdk.oauth.exchangeCode({
734
+ * code,
735
+ * redirect_uri: 'https://app.example.com/callback',
736
+ * client_id: 'rp_abc',
737
+ * code_verifier: verifier,
738
+ * })
739
+ * // sdk is now authenticated as the exchanged session
740
+ * ```
741
+ */
742
+ async exchangeCode(input, options) {
743
+ const result = await this.client.post(
744
+ "/auth/oauth/token",
745
+ { ...input, grant_type: "authorization_code" },
746
+ options
747
+ );
748
+ await this.client.setSession({
749
+ access_token: result.access_token,
750
+ refresh_token: result.refresh_token
751
+ });
752
+ return result;
753
+ }
754
+ };
755
+
679
756
  // src/modules/listings.ts
680
757
  var ListingsModule = class {
681
758
  constructor(client) {
@@ -2471,6 +2548,7 @@ function baleShareUrl(baleId, options = {}) {
2471
2548
  var MitumbaClient = class {
2472
2549
  api;
2473
2550
  auth;
2551
+ oauth;
2474
2552
  listings;
2475
2553
  search;
2476
2554
  orders;
@@ -2493,6 +2571,7 @@ var MitumbaClient = class {
2493
2571
  constructor(config) {
2494
2572
  this.api = new APIClient(config);
2495
2573
  this.auth = new AuthModule(this.api);
2574
+ this.oauth = new OAuthModule(this.api);
2496
2575
  this.listings = new ListingsModule(this.api);
2497
2576
  this.search = new SearchModule(this.api);
2498
2577
  this.orders = new OrdersModule(this.api);
@@ -2552,6 +2631,6 @@ var MitumbaClient = class {
2552
2631
  }
2553
2632
  };
2554
2633
 
2555
- export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
2634
+ export { APIClient, APIError, AdminModule, AuthModule, BALE_ORDER_STATUSES, BusinessesModule, CONDITIONS, CartModule, DEFAULT_SHARE_ORIGIN, DESIRED_RESOLUTIONS, DISPUTE_REASONS, DISPUTE_STATUSES, DisputesModule, IDBTokenStore, LISTING_STATUSES, ListingsModule, MailerModule, MemoryTokenStore, MessagesModule, MitumbaClient, NotificationsModule, OAuthModule, ORDER_STATUSES, OrdersModule, PAYMENT_STATUSES, PayModule, RealtimeProtocolError, RealtimeUnavailableError, ReportsModule, ReviewsModule, SearchModule, SettingsModule, StoresModule, TWO_FACTOR_METHOD_TYPES, UploadsModule, VaziModule, WholesaleModule, WishlistsModule, baleShareUrl, createTokenStore, isMessagingAPIError, listingShareUrl, storeShareUrl };
2556
2635
  //# sourceMappingURL=index.mjs.map
2557
2636
  //# sourceMappingURL=index.mjs.map