UNPKG

@gw2me/client

Version:
168 lines (162 loc) 5.6 kB
import { O as Options, a as DPoPCallback, S as Scope, C as ClientInfo } from './types-yBP8cksw.js'; export { D as DPoPParams } from './types-yBP8cksw.js'; interface UserResponse { sub: string; user: { id: string; name: string; email?: string; emailVerified?: boolean; }; settings?: unknown; } interface AccountsResponse { accounts: { id: string; name: string; shared: boolean; verified?: boolean; displayName?: string | null; }[]; } interface SubtokenOptions { permissions?: string[]; } interface SubtokenResponse { subtoken: string; expiresAt: string; } interface ApiOptions extends Options { dpop?: DPoPCallback; } declare class Gw2MeApi { #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 Gw2MeFedCM { #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 Gw2MeClient { #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 gw2.me on the redirect url (code and state). * If gw2.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>>): Gw2MeApi; get fedCM(): Gw2MeFedCM; } declare class Gw2MeError extends Error { } declare class Gw2MeOAuthError extends Gw2MeError { 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, ClientInfo, DPoPCallback, type FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, type IntrospectTokenParams, IntrospectTokenResponse, Options, type PushedAuthorizationRequestParams, type PushedAuthorizationRequestResponse, type RefreshTokenParams, type RevokeTokenParams, Scope, type SubtokenOptions, type SubtokenResponse, type TokenResponse, type TokenType, type UserResponse };