UNPKG

@bn2me/client

Version:
167 lines (161 loc) 5.58 kB
import { O as Options, a as DPoPCallback, S as Scope, C as ClientInfo } from './types-DhWGU22V.js'; export { D as DPoPParams } from './types-DhWGU22V.js'; interface UserResponse { sub: string; user: { id: string; name: string; email?: string; emailVerified?: boolean; }; settings?: unknown; } interface AccountsResponse { accounts: { id: string; name: string; verified?: boolean; displayName?: string | null; }[]; } interface SubtokenOptions { permissions?: string[]; } interface SubtokenResponse { subtoken: string; expiresAt: string; } interface ApiOptions extends Options { dpop?: DPoPCallback; } declare class Bn2MeApi { #private; private access_token; private options?; constructor(access_token: string, options?: Partial<ApiOptions> | undefined); user(): Promise<UserResponse>; saveSettings(settings: unknown): Promise<void>; accounts(): Promise<AccountsResponse>; subtoken(accountId: string, options?: SubtokenOptions): Promise<SubtokenResponse>; } interface FedCMRequestOptions { scopes: Scope[]; mediation?: CredentialMediationRequirement; mode?: 'passive' | 'active'; signal?: AbortSignal; code_challenge: string; code_challenge_method: 'S256'; } declare class Bn2MeFedCM { #private; constructor(configUrl: URL, clientId: string); isSupported(): boolean; request({ scopes, mediation, signal, mode, code_challenge, code_challenge_method }: FedCMRequestOptions): Promise<null | { token: string; type: "identity"; }>; } interface AuthorizationUrlParams { redirect_uri: string; scopes: Scope[]; state?: string; code_challenge?: string; code_challenge_method?: 'S256'; dpop_jkt?: string; prompt?: 'none' | 'consent'; include_granted_scopes?: boolean; verified_accounts_only?: boolean; } interface PushedAuthorizationRequestParams extends AuthorizationUrlParams { dpop?: DPoPCallback; } interface AuthorizationUrlRequestUriParams { request_uri: string; } type TokenType = 'Bearer' | 'DPoP'; interface AuthTokenParams { code: string; token_type?: TokenType; redirect_uri: string; code_verifier?: string; dpop?: DPoPCallback; } interface RefreshTokenParams { refresh_token: string; refresh_token_type?: TokenType; dpop?: DPoPCallback; } interface TokenResponse { access_token: string; issued_token_type: 'urn:ietf:params:oauth:token-type:access_token'; token_type: TokenType; expires_in: number; refresh_token?: string; scope: string; } interface RevokeTokenParams { token: string; } interface IntrospectTokenParams { token: string; } declare namespace IntrospectTokenResponse { interface Inactive { active: false; } namespace Active { interface Common { active: true; scope: string; client_id: string; exp?: number; } interface Bearer extends Common { token_type: 'Bearer'; } interface DPoP extends Common { token_type: 'DPoP'; cnf: { jkt: string; }; } } type Active = Active.Bearer | Active.DPoP; } type IntrospectTokenResponse = IntrospectTokenResponse.Inactive | IntrospectTokenResponse.Active; interface PushedAuthorizationRequestResponse { request_uri: string; expires_in: number; } declare class Bn2MeClient { #private; private options?; constructor(client: ClientInfo, options?: Partial<Options> | undefined); getAuthorizationUrl(params: AuthorizationUrlParams | AuthorizationUrlRequestUriParams): string; pushAuthorizationRequest(params: PushedAuthorizationRequestParams): Promise<PushedAuthorizationRequestResponse>; getAccessToken({ code, token_type, redirect_uri, code_verifier, dpop }: AuthTokenParams): Promise<TokenResponse>; refreshToken({ refresh_token, refresh_token_type, dpop }: RefreshTokenParams): Promise<TokenResponse>; revokeToken({ token }: RevokeTokenParams): Promise<void>; introspectToken({ token }: IntrospectTokenParams): Promise<IntrospectTokenResponse>; /** * Parses the search params received from bn2.me on the redirect url (code and state). * If bn2.me returned an error response, this will throw an error. * * @returns The code and optional state. */ parseAuthorizationResponseSearchParams(searchParams: URLSearchParams): { code: string; state: string | undefined; }; api(access_token: string, options?: Partial<Omit<ApiOptions, keyof Options>>): Bn2MeApi; get fedCM(): Bn2MeFedCM; } declare class Bn2MeError extends Error { } declare class Bn2MeOAuthError extends Bn2MeError { error: string; error_description?: string | undefined; error_uri?: string | undefined; constructor(error: string, error_description?: string | undefined, error_uri?: string | undefined); } export { type AccountsResponse, type ApiOptions, type AuthTokenParams, type AuthorizationUrlParams, type AuthorizationUrlRequestUriParams, Bn2MeApi, Bn2MeClient, Bn2MeError, Bn2MeFedCM, Bn2MeOAuthError, ClientInfo, DPoPCallback, type FedCMRequestOptions, type IntrospectTokenParams, IntrospectTokenResponse, Options, type PushedAuthorizationRequestParams, type PushedAuthorizationRequestResponse, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenOptions, type SubtokenResponse, type TokenResponse, type TokenType, type UserResponse };