import { Locales, Origins, Resource, getBlizzardApi } from "@blizzard-api/core"; import { Options } from "ky"; //#region src/client/types.d.ts /** * An access token response from the Blizzard API. * @see https://develop.battle.net/documentation/guides/using-oauth * @see https://develop.battle.net/documentation/guides/using-oauth/client-credentials-flow¨ * @example * const response: AccessToken = { * access_token: 'access-token', * token_type: 'bearer', * expires_in: 86399, * sub: 'client-id', * }; */ interface AccessToken { access_token: string; expires_in: number; sub?: string; token_type: 'bearer'; } /** * An access token request. * @see https://develop.battle.net/documentation/guides/using-oauth/client-credentials-flow * @example * const request: AccessTokenRequestArguments = { * origin: 'eu', * key: 'client', * secret: 'secret' * }; */ interface AccessTokenRequestArguments { key?: string; origin?: Origins; secret?: string; } /** * A client configuration object. * @example * const options: ClientOptions = { * key: 'client', * kyOptions: { ... }, * secret: 'secret', * origin: 'eu', * locale: 'en_GB', * token: 'access' * }; */ interface ClientOptions { key: string; kyOptions?: Options; locale?: Locales; maxAttempts?: number; origin: Origins; retryOnRateLimit?: boolean; secret: string; token?: string; } /** * Validate an access token. * @see https://develop.battle.net/documentation/guides/using-oauth/client-credentials-flow * @example * const request: ValidateAccessTokenArguments = { * origin: 'eu', * token: 'access' * }; */ interface ValidateAccessTokenArguments { origin?: Origins; token?: string; } /** * A response from validating an access token. * @see https://develop.battle.net/documentation/guides/using-oauth/client-credentials-flow * @example * const response: ValidateAccessTokenResponse = { * scope: ['wow.profile'], * account_authorities: [], * exp: 1617000000, * client_authorities: [], * authorities: ['wow.profile'], * client_id: 'client' * }; */ interface ValidateAccessTokenResponse { account_authorities: Array; authorities: Array; client_authorities: Array; client_id: string; exp: number; scope: Array; } //#endregion //#region src/client/client.d.ts /** * A Blizzard API client. * @classdesc A client to interact with the Blizzard API. * @example * const client = new BlizzardApiClient({ * key: 'client', * secret: 'secret', * origin: 'eu', * locale: 'en_GB', * token: 'access' * }); */ declare class BlizzardApiClient { defaults: { key: string; locale: Locales; maxAttempts: number; origin: Origins; retryOnRateLimit: boolean; secret: string; token?: string; }; private ky; constructor(options: ClientOptions); /** * Get an access token. * @param options The access token request arguments. See {@link AccessTokenRequestArguments}. * @returns The access token. See {@link AccessToken}. * @example * const response = await client.getAccessToken(); * const { access_token, token_type, expires_in, sub } = response; * console.log(access_token, token_type, expires_in, sub); * // => 'access' * // => 'bearer' * // => 86399 * // => 'client-id' */ getAccessToken: (options?: AccessTokenRequestArguments) => Promise; /** * Get the request configuration. * @param resource The resource to fetch. See {@link Resource}. * @param options Client options. See {@link ClientOptions}. * @returns The request configuration. */ getRequestConfig(resource: Resource, options?: Partial): { headers: Record & { Authorization: `Bearer ${string}`; 'Battlenet-Namespace'?: string; 'Content-Type': 'application/json'; }; searchParams: Record & { locale: ReturnType['locale']; }; }; /** * Get the request URL. * @param resource The resource to fetch. See {@link Resource}. * @param options Client options. See {@link ClientOptions}. * @returns The request URL. */ getRequestUrl(resource: Resource, options?: Partial): string; /** * Refresh the access token. * @param options The access token request arguments. See {@link AccessTokenRequestArguments}. * @returns The access token. See {@link AccessToken}. * @example * const response = await client.refreshAccessToken(); * const { access_token, token_type, expires_in, sub } = response; * console.log(access_token, token_type, expires_in, sub); * // => 'access' * // => 'bearer' * // => 86399 * // => 'client-id' */ refreshAccessToken: (options?: AccessTokenRequestArguments) => Promise; /** * Send a request to the Blizzard API. * @param resource The resource to fetch. See {@link Resource}. * @param options Client options. See {@link ClientOptions}. * @returns The response from the Blizzard API. */ sendRequest(resource: Resource, options?: Partial): Promise; /** * Set the access token. * @param token The access token. */ setAccessToken: (token: string) => void; /** * Validate an access token. * @param options The validate access token arguments. See {@link ValidateAccessTokenArguments}. * @returns The response from the Blizzard API. See {@link ValidateAccessTokenResponse}. * @example * const response = await client.validateAccessToken({ token: 'access' }); * console.log(response.client_id); * // => 'client-id' */ validateAccessToken: (options?: ValidateAccessTokenArguments) => Promise; } //#endregion //#region src/client/create-client.d.ts /** * Create a new Blizzard API client. * @param options Client options, see {@link ClientOptions} & https://develop.battle.net/documentation/guides/getting-started * @param onTokenRefresh Callback function to handle token refresh. If set to `true`, the client will automatically refresh the token. If set to `false`, the client will not refresh the token. If set to a function, the function will be called with the new token. * @returns A new Blizzard API client. */ declare const createBlizzardApiClient: (options: ClientOptions, onTokenRefresh?: ((token: AccessToken) => void) | boolean) => Promise; //#endregion export { type AccessToken, type AccessTokenRequestArguments, type ClientOptions, type ValidateAccessTokenArguments, type ValidateAccessTokenResponse, createBlizzardApiClient, createBlizzardApiClient as default }; //# sourceMappingURL=index.d.ts.map