@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.js CHANGED
@@ -678,6 +678,120 @@ var AuthModule = class {
678
678
  }
679
679
  };
680
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
+ * Fetch the OpenID Connect discovery document.
758
+ *
759
+ * A relying party reads this to learn the provider's endpoints and capabilities (issuer, the
760
+ * authorize/token/userinfo/jwks URLs, supported scopes, signing algorithms) rather than hard-
761
+ * coding them. Public — no session required.
762
+ *
763
+ * @param options - Optional per-request options (abort signal, extra headers)
764
+ * @returns The discovery metadata
765
+ */
766
+ async discover(options) {
767
+ return this.client.get("/auth/oauth/openid-configuration", void 0, options);
768
+ }
769
+ /**
770
+ * Fetch the JWKS — the public keys that verify provider-issued id_token signatures.
771
+ *
772
+ * A relying party uses these (matched by the id_token header `kid`) to verify an id_token without
773
+ * a shared secret. Public — no session required. Serves public key parameters only.
774
+ *
775
+ * @param options - Optional per-request options (abort signal, extra headers)
776
+ * @returns The JWKS document
777
+ */
778
+ async getJwks(options) {
779
+ return this.client.get("/auth/oauth/jwks.json", void 0, options);
780
+ }
781
+ /**
782
+ * Fetch the userinfo claim set for the current session.
783
+ *
784
+ * Returns `sub` plus the identity claims the session's granted scopes allow. Requires an
785
+ * authenticated session — the SDK attaches the bearer token automatically.
786
+ *
787
+ * @param options - Optional per-request options (abort signal, extra headers)
788
+ * @returns The userinfo claims
789
+ */
790
+ async userinfo(options) {
791
+ return this.client.get("/auth/oauth/userinfo", void 0, options);
792
+ }
793
+ };
794
+
681
795
  // src/modules/listings.ts
682
796
  var ListingsModule = class {
683
797
  constructor(client) {
@@ -2473,6 +2587,7 @@ function baleShareUrl(baleId, options = {}) {
2473
2587
  var MitumbaClient = class {
2474
2588
  api;
2475
2589
  auth;
2590
+ oauth;
2476
2591
  listings;
2477
2592
  search;
2478
2593
  orders;
@@ -2495,6 +2610,7 @@ var MitumbaClient = class {
2495
2610
  constructor(config) {
2496
2611
  this.api = new APIClient(config);
2497
2612
  this.auth = new AuthModule(this.api);
2613
+ this.oauth = new OAuthModule(this.api);
2498
2614
  this.listings = new ListingsModule(this.api);
2499
2615
  this.search = new SearchModule(this.api);
2500
2616
  this.orders = new OrdersModule(this.api);
@@ -2575,6 +2691,7 @@ exports.MemoryTokenStore = MemoryTokenStore;
2575
2691
  exports.MessagesModule = MessagesModule;
2576
2692
  exports.MitumbaClient = MitumbaClient;
2577
2693
  exports.NotificationsModule = NotificationsModule;
2694
+ exports.OAuthModule = OAuthModule;
2578
2695
  exports.ORDER_STATUSES = ORDER_STATUSES;
2579
2696
  exports.OrdersModule = OrdersModule;
2580
2697
  exports.PAYMENT_STATUSES = PAYMENT_STATUSES;