UNPKG

guildwars2-ts

Version:

GuildWars 2 API Wrapper in Typescript

51 lines (50 loc) 2.03 kB
import { type RawAxiosRequestConfig } from 'axios'; import type { z } from 'zod'; import type { Endpoint } from '../apis/endpoints'; import { type ApiParams, type UrlParams } from './apiParams'; /** * Base Api object. Implements anything needed for the requests to all endpoints */ export declare class ApiBase { private readonly _baseUrl; private readonly _apiToken?; private readonly _language; private readonly _rateLimitRetry; private readonly _inBrowser; constructor(apiParams?: ApiParams); /** * Parameters for the api response, at top level */ protected getParams(): ApiParams; /** * Generic request builder. Adds a finalized request to the concurrency queue * * @param endpoint - API Endpoint * @param apiParams - Query string * @param responseType - Type of the response * @param attempts - Previously failed retry count */ protected buildRequest<T extends z.ZodType>(endpoint: Endpoint, apiParams: UrlParams, responseType: T, attempts?: number): Promise<z.infer<T>>; /** * Retries failed requests * * @param endpoint - Endpoint to which a request was originally made * @param prevOptions - Axios request options * @param responseType - Originally requested schema * @param apiParams - Query string * @param rateLimitAttempt - Current rate-limit retry counter * @param prevError - Error that caused a retry */ protected retryRequest<T extends z.ZodType>(endpoint: Endpoint, prevOptions: RawAxiosRequestConfig, responseType: T, apiParams: UrlParams, rateLimitAttempt: number, prevError?: unknown): Promise<z.infer<T>>; /** * Builds final Api url from the endpoint and provided parameters * * @param endpoint - Api endpoint * @param urlParams - Parameters * * The following function is adapted from https://github.com/Sansossio/twisted * Copyright (c) 2021 Julio Sansossio * Licensed under MIT License */ private _getApiUrl; }