biketag
Version:
The Javascript client API for BikeTag Games
436 lines (435 loc) • 22.2 kB
TypeScript
import { Game, Tag, Player, Ambassador, Setting, Achievement, Stat } from './common/schema';
import { Credentials, BikeTagApiResponse, ImgurCredentials, AWSCredentials, SanityCredentials, RequireAtLeastOne, BikeTagCredentials, BikeTagConfiguration, PartialBikeTagConfiguration, ApiOptions } from './common/types';
import { AvailableApis, DataTypes } from './common/enums';
import { getTagPayload, getTagsPayload, updateTagPayload, updateGamePayload, getGamePayload, uploadTagImagePayload, deleteTagPayload, deleteTagsPayload, getPlayersPayload, getPlayerPayload, getSettingPayload, getAmbassadorPayload, getAmbassadorsPayload, getSettingsPayload, getQueuePayload, queueTagPayload, archiveTagPayload, getAchievementsPayload, getStatPayload, getStatsPayload, updateStatPayload, fetchSignedUrlPayload } from './common/payloads';
import { S3Client } from '@aws-sdk/client-s3';
import { ImgurClient } from 'imgur';
import { SanityClient } from '@sanity/client';
import { AxiosInstance, AxiosResponse, AxiosRequestConfig } from 'axios';
import { AxiosCacheInstance } from 'axios-cache-interceptor';
import * as BikeTagExpressions from './common/expressions';
import * as BikeTagGetters from './common/getters';
export declare class BikeTagClient {
readonly configuration: Credentials | PartialBikeTagConfiguration;
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: AxiosCacheInstance;
protected imgurClient?: ImgurClient;
protected sanityClient?: SanityClient;
protected awsClient?: S3Client;
protected awsConfig?: AWSCredentials;
protected sanityConfig?: SanityCredentials;
protected imgurConfig?: ImgurCredentials;
protected biketagConfig?: BikeTagCredentials;
constructor(configuration: Credentials | PartialBikeTagConfiguration);
/**
* 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;
/**
* Applies defaults and overrides to an API options object based on the data
* type being requested.
*
* @param options - Existing API options
* @param dataType - The type of data the request is for
* @param overrides - Optional values that override configuration defaults
* @param method - Name of the method requesting options
* @returns Normalized API options
*/
protected getDefaultOptions(options: ApiOptions, dataType?: DataTypes, overrides?: Partial<Pick<ApiOptions, 'source' | 'region' | 'host' | 'cached' | 'concise'>>, method?: string): ApiOptions;
/**
* Determines which API client and adapter should handle a request based on
* provided options.
*
* @param payload - Incoming payload or options
* @param overrides - Optional configuration overrides
* @param dataType - Type of data being requested
* @param method - Name of the method being invoked
* @returns Client, api adapter and normalized options
*/
protected getClientAdapter(payload: any, overrides?: any, dataType?: DataTypes, method?: string): any;
/**
* Determines which API is currently capable of handling a particular method.
*
* @param method - Method name to check for availability
* @returns The most appropriate API source or null if none are available
*/
protected getMostAvailableClient(method?: string): AvailableApis;
/**
* Creates a wrapper that forwards a call to another API method while
* normalizing payload and options for that method.
*
* @param method - Method to invoke on the underlying API
* @param client - Client instance used to execute the method
* @param dataType - Data type of the request
* @param binding - Optional binding context for the method
* @returns A callable function that forwards arguments to the target method
*/
protected getPassthroughApiMethod(method: any, client: ImgurClient | BikeTagClient | SanityClient | S3Client, dataType?: DataTypes, binding?: any): any;
/**
* Retrieves the current configuration with any supplied overrides and a list
* of available API clients.
*
* @param config - Optional partial configuration to merge with defaults
* @returns Complete configuration information
*/
protected getConfig(config?: BikeTagConfiguration): BikeTagConfiguration;
/**
* Instantiates API client wrappers based on the provided configuration.
*
* @param config - Configuration describing credentials for each API
* @returns The configuration used to initialize the clients
*/
protected initializeClients(config?: BikeTagConfiguration): BikeTagConfiguration;
/**
* Helper for generating normalized API options from arbitrary input.
*
* @param opts - Incoming payload or options
* @param dataType - Optional data type the request targets
* @param overrides - Optional overrides for configuration values
* @param method - Name of the calling method
* @returns Normalized API options
*/
options(opts?: any, dataType?: DataTypes, overrides?: any, method?: string): ApiOptions;
/**
* Updates the client configuration and optionally reinitializes API clients.
*
* @param config - Partial configuration or credentials to merge
* @param overwrite - When true, new values overwrite existing ones
* @param reInitialize - Recreate underlying API clients when true
* @returns The resulting configuration
*/
config(config?: Partial<Credentials> | Partial<BikeTagConfiguration> | PartialBikeTagConfiguration, overwrite?: boolean, reInitialize?: boolean): BikeTagConfiguration;
/**
* Performs a request using an Axios instance without authentication or cache.
*
* @param options - Axios request options
* @returns The Axios response promise
*/
plainRequest(options?: AxiosRequestConfig): Promise<AxiosResponse<any>>;
/**
* Performs a request using the caching Axios instance.
*
* @param options - Axios request options
* @returns The Axios response promise
*/
cachedRequest(options?: AxiosRequestConfig): Promise<AxiosResponse<any>>;
/**
* Performs an authenticated request using the main Axios instance.
* Normalizes GET requests so payload data becomes query parameters.
*
* @param options - Axios request options
* @returns The Axios response promise
*/
request(options?: AxiosRequestConfig): Promise<AxiosResponse<string>>;
/**
* Requests a signed URL from the configured API for direct uploads.
*
* @param payload - Data describing the object to upload
* @param opts - Optional credentials overriding default configuration
*/
fetchSignedUrl(payload: fetchSignedUrlPayload, opts?: RequireAtLeastOne<Credentials>): any;
/**
* Retrieves credential claims using an authorization header.
*
* @param authorization - Optional bearer token to decode
* @returns Decoded credential claims
*/
fetchCredentials(authorization?: string): Promise<PartialBikeTagConfiguration | Record<string, never>>;
/**
* 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>;
/**
* Retrieves a single BikeTag `Game` from the configured API.
*
* @param payload - Options identifying the game
* @param opts - Optional credentials for the request
* @returns A response containing the game data
*/
getGame(payload?: RequireAtLeastOne<getGamePayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Game>>;
/**
* Retrieves all BikeTag `Game` entries regardless of game name provided.
*
* @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 an array of `Game` objects
*/
getAllGames(payload?: RequireAtLeastOne<getGamePayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Game[]>>;
/**
* Updates BikeTag `Game` data based on the provided payload.
*
* @param payload - The updateGamePayload containing new game data
* @param opts - Credentials and other options for updating the game
* @returns A promise that resolves to success status
*/
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[]>;
/**
* Retrieves the current queue of tags awaiting approval.
*
* @param payload - Options for retrieving queued tags
* @param opts - Credentials for the request
* @returns A response containing queued tags
*/
getQueue(payload?: RequireAtLeastOne<getQueuePayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Tag[]>>;
/**
* Queues a new tag image to be approved by game moderators.
*
* @param payload - Tag information and image data to queue
* @param opts - Credentials for the request
* @returns A response containing the queued tag
*/
queueTag(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[]>>;
/**
* Uploads a tag image (mystery or found) for a game.
*
* @param payload - The uploadTagImagePayload or array of payloads
* @param opts - Credentials for image upload
* @returns A promise that resolves when upload completes
*/
uploadTagImage(payload: RequireAtLeastOne<uploadTagImagePayload> | RequireAtLeastOne<uploadTagImagePayload>[], opts?: Credentials): Promise<BikeTagApiResponse<any | any[]>>;
/**
* Updates an existing tag for a game.
*
* @param payload - The updateTagPayload containing updates
* @param opts - Credentials and other options for update
* @returns A promise that resolves to success status
*/
updateTag(payload: RequireAtLeastOne<updateTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean>>;
/**
* Archives a tag in a game.
*
* @param payload - The archiveTagPayload identifying the tag
* @param opts - Credentials for archiving
* @returns A promise that resolves to success status
*/
archiveTag(payload: RequireAtLeastOne<archiveTagPayload>, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean>>;
/**
* Deletes a single tag for a game.
*
* @param payload - The deleteTagPayload identifying the tag
* @param opts - Credentials for deletion
* @returns A promise that resolves when deletion completes
*/
deleteTag(payload: RequireAtLeastOne<deleteTagPayload> | number, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<any>>;
/**
* Deletes multiple tags for a game.
*
* @param payload - The deleteTagsPayload identifying tags
* @param opts - Credentials for deletion
* @returns A promise that resolves when deletions complete
*/
deleteTags(payload: RequireAtLeastOne<deleteTagsPayload> | number[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<boolean[]>>;
/**
* Retrieves BikeTag `Player` records for a game.
*
* @param payload - The getPlayerPayload or getPlayersPayload
* @param opts - Credentials and other options for player retrieval
* @returns A promise that resolves to array of players
*/
players(payload?: RequireAtLeastOne<getPlayerPayload> | RequireAtLeastOne<getPlayersPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player[]> | Player[]>;
/**
* Retrieves a single player from the configured API.
*
* @param payload - Player identifier
* @param opts - Credentials for the request
* @returns The player information
*/
getPlayer(payload: RequireAtLeastOne<getPlayerPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player>>;
/**
* Retrieves multiple players from the configured API.
*
* @param payload - Filtering options or player names
* @param opts - Credentials for the request
* @returns A response containing player data
*/
getPlayers(payload?: RequireAtLeastOne<getPlayersPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player[]>>;
/**
* Updates a player record for a game.
*
* @param payload - The getPlayersPayload or player names
* @param opts - Credentials and other options for update
* @returns A promise that resolves to array of updated players
*/
updatePlayer(payload?: RequireAtLeastOne<getPlayersPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Player[]>>;
/**
* Retrieves BikeTag `Ambassador` records for a game.
*
* @param payload - The getAmbassadorPayload or getAmbassadorsPayload
* @param opts - Credentials and other options for retrieval
* @returns A promise that resolves to array of ambassadors
*/
ambassadors(payload?: RequireAtLeastOne<getAmbassadorPayload> | RequireAtLeastOne<getAmbassadorsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Ambassador[]> | Ambassador[]>;
/**
* Retrieves a single ambassador.
*
* @param payload - Ambassador identifier
* @param opts - Credentials for the request
* @returns Ambassador information
*/
getAmbassador(payload: RequireAtLeastOne<getAmbassadorPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Ambassador>>;
/**
* Retrieves multiple ambassadors.
*
* @param payload - Ambassador filter or identifiers
* @param opts - Credentials for the request
* @returns A response containing ambassadors
*/
getAmbassadors(payload?: RequireAtLeastOne<getAmbassadorsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Ambassador[]>>;
/**
* Retrieves BikeTag `Setting` records for a game.
*
* @param payload - The getSettingPayload or getSettingsPayload
* @param opts - Credentials and other options for retrieval
* @returns A promise that resolves to array of settings
*/
settings(payload?: RequireAtLeastOne<getSettingPayload> | RequireAtLeastOne<getSettingsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Setting[]> | Setting[]>;
/**
* Retrieves a single application setting.
*
* @param payload - Setting identifier
* @param opts - Credentials for the request
* @returns The requested setting
*/
getSetting(payload: RequireAtLeastOne<getSettingPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Setting>>;
/**
* Retrieves multiple application settings.
*
* @param payload - Setting identifiers or filters
* @param opts - Credentials for the request
* @returns A response containing settings
*/
getSettings(payload?: RequireAtLeastOne<getSettingsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Setting[]>>;
/**
* Retrieves BikeTag `Stat` records for a game.
*
* @param payload - The getStatPayload or getStatsPayload
* @param opts - Credentials and other options for retrieval
* @returns A promise that resolves to array of stats
*/
stats(payload?: RequireAtLeastOne<getStatPayload> | RequireAtLeastOne<getStatsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Stat[]> | Stat[]>;
/**
* Retrieves a single stat entry.
*
* @param payload - Stat identifier
* @param opts - Credentials for the request
* @returns The stat data
*/
getStat(payload: RequireAtLeastOne<getStatPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Stat>>;
/**
* Retrieves multiple stat entries from the API.
*
* @param payload - Stat identifiers or filters
* @param opts - Credentials for the request
* @returns A response containing stats
*/
getStats(payload?: RequireAtLeastOne<getStatsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Stat[]>>;
/**
* Updates a single stat entry.
*
* @param payload - Stat update data
* @param opts - Credentials for the request
* @returns Updated stat information
*/
updateStat(payload?: RequireAtLeastOne<updateStatPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Stat[]>>;
/**
* Updates one or more `Stat` records for a game.
*
* @param payload - The updateStatPayload or array of payloads
* @param opts - Credentials for updating stats
* @returns A promise that resolves to array of updated stats
*/
updateStats(payload?: RequireAtLeastOne<updateStatPayload[]> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Stat[]>>;
/**
* Retrieves BikeTag `Achievement` records for a game.
*
* @param payload - The getAchievementsPayload or achievement names
* @param opts - Credentials and other options for retrieval
* @returns A promise that resolves to array of achievements
*/
achievements(payload?: RequireAtLeastOne<getAchievementsPayload> | RequireAtLeastOne<getAchievementsPayload> | string | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Achievement[]> | Achievement[]>;
/**
* Retrieves a single achievement.
*
* @param payload - Achievement identifier
* @param opts - Credentials for the request
* @returns The achievement data
*/
getAchievement(payload: RequireAtLeastOne<getAchievementsPayload> | string, opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Achievement>>;
/**
* Retrieves multiple achievements.
*
* @param payload - Achievement identifiers or filters
* @param opts - Credentials for the request
* @returns A response containing achievements
*/
getAchievements(payload?: RequireAtLeastOne<getAchievementsPayload> | string[], opts?: RequireAtLeastOne<Credentials>): Promise<BikeTagApiResponse<Achievement[]>>;
/**
* Instantiates and returns a configured S3Client instance.
*
* @param opts - Configuration or credentials for the S3 client
* @returns A S3Client instance
*/
objects(opts?: any): S3Client;
/**
* Instantiates and returns a configured SanityClient instance.
*
* @param opts - Configuration or credentials for the Sanity client
* @returns A SanityClient instance
*/
content(opts?: any): SanityClient;
/**
* Instantiates and returns a configured ImgurClient instance.
*
* @param opts - Configuration or credentials for the Imgur client
* @returns An ImgurClient instance
*/
images(opts?: any): ImgurClient;
}
export type { BikeTagCredentials, BikeTagConfiguration };