@mitumba/sdk 5.3.0 → 5.4.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
@@ -831,6 +831,50 @@ var OAuthModule = class {
831
831
  async listConsents(options) {
832
832
  return this.client.get("/auth/oauth/consents", void 0, options);
833
833
  }
834
+ /**
835
+ * Attempt a silent (`prompt=none`) authorization — the "sign in once, every app knows you" path.
836
+ *
837
+ * Sends the authorize request with `prompt=none`, meaning: mint a code only if it can be done with
838
+ * no interaction, otherwise tell me why so I can fall back. Unlike {@link OAuthModule.authorize},
839
+ * the expected non-success outcomes are RETURNED (discriminated on `ok`), not thrown, so a caller
840
+ * can branch cleanly without a try/catch:
841
+ *
842
+ * - `{ ok: true, code, state }` — redirect to `redirect_uri?code=..&state=..` as usual.
843
+ * - `{ ok: false, reason: 'login_required' }` — no usable session, or this client is not
844
+ * authorized for silent auth. Fall back to a visible sign-in (or stay logged out).
845
+ * - `{ ok: false, reason: 'interaction_required' }` — consent needed; fall back to a visible flow.
846
+ * - `{ ok: false, reason: 'unauthenticated' }` — no session reached the server (HTTP 401).
847
+ *
848
+ * Only genuinely unexpected errors (network failure, 5xx, an unrecognised error code) throw.
849
+ * `code_challenge_method` is fixed to `'S256'` and `prompt` to `'none'` by the SDK. This is a
850
+ * top-level/first-party call carrying the session the SDK holds; the server never mints for a
851
+ * client that lacks the silent-auth privilege (it returns `login_required`).
852
+ *
853
+ * @param input - The authorize request (client, redirect URI, state, PKCE challenge, scope)
854
+ * @param options - Optional per-request options (abort signal, extra headers)
855
+ * @returns A discriminated success-or-fallback result
856
+ * @throws {APIError} Only on unexpected failures (network, 5xx, unknown error code)
857
+ */
858
+ async silentAuthorize(input, options) {
859
+ try {
860
+ const result = await this.client.post(
861
+ "/auth/oauth/authorize",
862
+ { ...input, code_challenge_method: "S256", prompt: "none" },
863
+ options
864
+ );
865
+ if (isConsentRequired(result)) return { ok: false, reason: "interaction_required" };
866
+ return { ok: true, code: result.code, state: result.state };
867
+ } catch (err) {
868
+ if (err instanceof APIError) {
869
+ if (err.status === 401) return { ok: false, reason: "unauthenticated" };
870
+ if (err.code === "login_required") return { ok: false, reason: "login_required" };
871
+ if (err.code === "interaction_required" || err.code === "consent_required") {
872
+ return { ok: false, reason: "interaction_required" };
873
+ }
874
+ }
875
+ throw err;
876
+ }
877
+ }
834
878
  };
835
879
 
836
880
  // src/modules/listings.ts