@gw2me/client
Version:
gw2.me client library
194 lines (193 loc) • 5.54 kB
text/typescript
import { a as Scope, i as Options, n as DPoPCallback, r as DPoPParams, t as ClientInfo } from "./types-cXKOlCJ4.mjs";
//#region src/api.d.ts
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>;
}
//#endregion
//#region src/fed-cm.d.ts
interface FedCMRequestOptions {
scopes: Scope[];
mediation?: CredentialMediationRequirement;
mode?: 'passive' | 'active';
signal?: AbortSignal;
code_challenge: string;
code_challenge_method: 'S256';
/** @default true */
include_granted_scopes?: boolean;
}
declare class Gw2MeFedCM {
#private;
constructor(configUrl: URL, clientId: string);
isSupported(): boolean;
request({
scopes,
mediation,
signal,
mode,
code_challenge,
code_challenge_method,
include_granted_scopes
}: FedCMRequestOptions): Promise<null | {
token: string;
type: "identity";
}>;
}
//#endregion
//#region src/client.d.ts
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;
}
//#endregion
//#region src/error.d.ts
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);
}
//#endregion
export { AccountsResponse, ApiOptions, AuthTokenParams, AuthorizationUrlParams, AuthorizationUrlRequestUriParams, ClientInfo, DPoPCallback, DPoPParams, FedCMRequestOptions, Gw2MeApi, Gw2MeClient, Gw2MeError, Gw2MeFedCM, Gw2MeOAuthError, IntrospectTokenParams, IntrospectTokenResponse, Options, PushedAuthorizationRequestParams, PushedAuthorizationRequestResponse, RefreshTokenParams, RevokeTokenParams, Scope, SubtokenOptions, SubtokenResponse, TokenResponse, TokenType, UserResponse };
//# sourceMappingURL=index.d.mts.map