@mitumba/sdk 5.0.0 → 5.2.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,120 @@ 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
+ * Fetch the OpenID Connect discovery document.
756
+ *
757
+ * A relying party reads this to learn the provider's endpoints and capabilities (issuer, the
758
+ * authorize/token/userinfo/jwks URLs, supported scopes, signing algorithms) rather than hard-
759
+ * coding them. Public — no session required.
760
+ *
761
+ * @param options - Optional per-request options (abort signal, extra headers)
762
+ * @returns The discovery metadata
763
+ */
764
+ async discover(options) {
765
+ return this.client.get("/auth/oauth/openid-configuration", void 0, options);
766
+ }
767
+ /**
768
+ * Fetch the JWKS — the public keys that verify provider-issued id_token signatures.
769
+ *
770
+ * A relying party uses these (matched by the id_token header `kid`) to verify an id_token without
771
+ * a shared secret. Public — no session required. Serves public key parameters only.
772
+ *
773
+ * @param options - Optional per-request options (abort signal, extra headers)
774
+ * @returns The JWKS document
775
+ */
776
+ async getJwks(options) {
777
+ return this.client.get("/auth/oauth/jwks.json", void 0, options);
778
+ }
779
+ /**
780
+ * Fetch the userinfo claim set for the current session.
781
+ *
782
+ * Returns `sub` plus the identity claims the session's granted scopes allow. Requires an
783
+ * authenticated session — the SDK attaches the bearer token automatically.
784
+ *
785
+ * @param options - Optional per-request options (abort signal, extra headers)
786
+ * @returns The userinfo claims
787
+ */
788
+ async userinfo(options) {
789
+ return this.client.get("/auth/oauth/userinfo", void 0, options);
790
+ }
791
+ };
792
+
679
793
  // src/modules/listings.ts
680
794
  var ListingsModule = class {
681
795
  constructor(client) {
@@ -2471,6 +2585,7 @@ function baleShareUrl(baleId, options = {}) {
2471
2585
  var MitumbaClient = class {
2472
2586
  api;
2473
2587
  auth;
2588
+ oauth;
2474
2589
  listings;
2475
2590
  search;
2476
2591
  orders;
@@ -2493,6 +2608,7 @@ var MitumbaClient = class {
2493
2608
  constructor(config) {
2494
2609
  this.api = new APIClient(config);
2495
2610
  this.auth = new AuthModule(this.api);
2611
+ this.oauth = new OAuthModule(this.api);
2496
2612
  this.listings = new ListingsModule(this.api);
2497
2613
  this.search = new SearchModule(this.api);
2498
2614
  this.orders = new OrdersModule(this.api);
@@ -2552,6 +2668,6 @@ var MitumbaClient = class {
2552
2668
  }
2553
2669
  };
2554
2670
 
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 };
2671
+ 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
2672
  //# sourceMappingURL=index.mjs.map
2557
2673
  //# sourceMappingURL=index.mjs.map