UNPKG

biketag

Version:

The Javascript client API for BikeTag Games

117 lines (115 loc) 9.85 kB
import { Game, Tag, Player, Ambassador, Setting, Achievement } from './common/schema'; import { Credentials, BikeTagApiResponse, ImgurCredentials, SanityCredentials, RequireAtLeastOne, BikeTagCredentials, BikeTagConfiguration, PartialBikeTagConfiguration, ApiOptions } from './common/types'; import { AvailableApis, DataTypes } from './common/enums'; import { getTagPayload, getTagsPayload, updateTagPayload, updateGamePayload, getGamePayload, uploadTagImagePayload, deleteTagPayload, deleteTagsPayload, importTagPayload, getPlayersPayload, getPlayerPayload, getSettingPayload, getAmbassadorPayload, getAmbassadorsPayload, getSettingsPayload, getQueuePayload, queueTagPayload, archiveTagPayload, getAchievementsPayload } from './common/payloads'; import { ImgurClient } from 'imgur'; import { SanityClient } from '@sanity/client'; import { AxiosInstance, AxiosResponse, AxiosRequestConfig } from 'axios'; import { EventEmitter } from 'events'; import * as BikeTagExpressions from './common/expressions'; import * as BikeTagGetters from './common/getters'; export declare class BikeTagClient extends EventEmitter { readonly configuration: Credentials | BikeTagConfiguration; static expressions: typeof BikeTagExpressions; static getters: typeof BikeTagGetters; static createGameObject: (gameData?: any) => Game; static createTagObject: (tagData?: any, foundTagData?: any) => Tag; static createPlayerObject: (playerData?: any) => Player; protected fetcher: AxiosInstance; protected plainFetcher: AxiosInstance; protected cachedFetcher: AxiosInstance; protected imgurClient?: ImgurClient; protected sanityClient?: SanityClient; protected sanityConfig?: SanityCredentials; protected imgurConfig?: ImgurCredentials; protected biketagConfig?: BikeTagCredentials; constructor(configuration: Credentials | BikeTagConfiguration); /** * Returns a normalized object of the payload and options for the API request from a variety of input types. * * @param opts - The options passed in from the request * @param source - The source type to use for the request * @param method - The method requested of the BikeTag API * @returns The API options payload object */ protected getInitialPayload(opts: any, source?: AvailableApis | string, method?: string): ApiOptions; protected getDefaultOptions(options: ApiOptions, dataType?: DataTypes, overrides?: any, method?: string): ApiOptions; protected getClientAdapter(payload: any, overrides?: any, dataType?: DataTypes, method?: string): any; protected getMostAvailableClient(method?: string): AvailableApis; protected getPassthroughApiMethod(method: any, client: ImgurClient | BikeTagClient | SanityClient, dataType?: DataTypes, binding?: any): any; protected getConfig(config?: BikeTagConfiguration): BikeTagConfiguration; protected initializeClients(config?: BikeTagConfiguration): BikeTagConfiguration; options(opts?: any, dataType?: DataTypes, overrides?: any, method?: string): ApiOptions; config(config?: Credentials | BikeTagConfiguration | PartialBikeTagConfiguration, overwrite?: boolean, reInitialize?: boolean): BikeTagConfiguration; plainRequest(options?: AxiosRequestConfig): Promise<AxiosResponse<any>>; cachedRequest(options?: AxiosRequestConfig): Promise<AxiosResponse<any>>; request(options?: AxiosRequestConfig): Promise<AxiosResponse<string>>; fetchCredentials(authorization?: string): Promise<Partial<BikeTagCredentials>>; /** * Retrieves BikeTag `Game` data based on the provided payload and options * * @param payload - The getGamePayload for retrieving BikeTag `Game` data * @param opts - Credentials and other options for retrieving BikeTag `Game` data * @returns A promise that resolves to a BikeTag `Game` object */ game(payload?: RequireAtLeastOne<getGamePayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Game> | Game>; getGame(payload?: RequireAtLeastOne<getGamePayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Game>>; updateGame(payload: RequireAtLeastOne<updateGamePayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean>>; /** * Retrieves BikeTag `Tag` from the queue for a given game * * @param payload - The getQueuePayload for retrieving BikeTag `Tag` data * @param opts - Credentials and other options for retrieving BikeTag `Tag` data * @returns A promise that resolves to a BikeTag `Tag` object */ queue(payload?: RequireAtLeastOne<getQueuePayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag[]> | Tag[]>; getQueue(payload?: RequireAtLeastOne<getQueuePayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag[]>>; queueTag(payload?: RequireAtLeastOne<queueTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag>>; submitQueuedTag(payload?: RequireAtLeastOne<queueTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag>>; /** * Retrieves BikeTags based on the provided payload and options for a given game * * @param payload - The getTagPayload for retrieving tags * @param opts - Credentials and other options for retrieving tags * @returns A promise that resolves to an array of tags */ tags(payload?: RequireAtLeastOne<getTagPayload> | RequireAtLeastOne<getTagsPayload> | number | number[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag[]> | Tag[]>; /** * Retrieves a single BikeTag for a given game * * @param payload - The getTagPayload for retrieving a tag * @param opts - Credentials and other options for retrieving a tag * @returns A promise that resolves to a `BikeTagApiResponse` object containing the tag data. */ getTag(payload?: RequireAtLeastOne<getTagPayload> | number, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag>>; /** * Retrieves BikeTags based on the provided payload and options for a given game * * @param payload - The getTagsPayload for retrieving tags * @param opts - Credentials and other options for retrieving tags * @returns A promise that resolves to an array of tags */ getTags(payload?: RequireAtLeastOne<getTagsPayload> | number[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag[]>>; uploadTagImage(payload: RequireAtLeastOne<uploadTagImagePayload> | RequireAtLeastOne<uploadTagImagePayload>[], opts?: Credentials): Promise<BikeTagApiResponse<any | any[]>>; updateTag(payload: RequireAtLeastOne<updateTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean>>; archiveTag(payload: RequireAtLeastOne<archiveTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean>>; importTag(payload: RequireAtLeastOne<importTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag>>; deleteTag(payload: RequireAtLeastOne<deleteTagPayload> | number, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<any>>; deleteTags(payload: RequireAtLeastOne<deleteTagsPayload> | number[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean[]>>; players(payload?: RequireAtLeastOne<getPlayerPayload> | RequireAtLeastOne<getPlayersPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player[]> | Player[]>; getPlayer(payload: RequireAtLeastOne<getPlayerPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player>>; getPlayers(payload?: RequireAtLeastOne<getPlayersPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player[]>>; updatePlayer(payload?: RequireAtLeastOne<getPlayersPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player[]>>; ambassadors(payload?: RequireAtLeastOne<getAmbassadorPayload> | RequireAtLeastOne<getAmbassadorsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Ambassador[]> | Ambassador[]>; getAmbassador(payload: RequireAtLeastOne<getAmbassadorPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Ambassador>>; getAmbassadors(payload?: RequireAtLeastOne<getAmbassadorsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Ambassador[]>>; settings(payload?: RequireAtLeastOne<getSettingPayload> | RequireAtLeastOne<getSettingsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Setting[]> | Setting[]>; getSetting(payload: RequireAtLeastOne<getSettingPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Setting>>; getSettings(payload?: RequireAtLeastOne<getSettingsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Setting[]>>; achievements(payload?: RequireAtLeastOne<getAchievementsPayload> | RequireAtLeastOne<getAchievementsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Achievement[]> | Achievement[]>; getAchievement(payload: RequireAtLeastOne<getAchievementsPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Achievement>>; getAchievements(payload?: RequireAtLeastOne<getAchievementsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Achievement[]>>; content(opts?: any): SanityClient; images(opts?: any): ImgurClient; } export type { BikeTagCredentials, BikeTagConfiguration };