UNPKG

cactive

Version:

Link in to the vast and epic CactiveNetwork ecosystem.

128 lines 4.16 kB
/// <reference types="node" /> import User, { PartialUser, ProjectData } from "./user"; import EventEmitter from "events"; declare type ConnectionOpts = { base_url: string; socket_url: string; verbose: boolean; socket_keepalive: number; }; declare interface Connections { on(event: "ready", handler: () => void): this; } declare class Connections extends EventEmitter { options: ConnectionOpts; private _token; private _socket; private _socket_store; private _timer; /** * Creates a client * @param token Authorization token * @param options Client options */ constructor(token: string, options?: ConnectionOpts | { [key: string]: any; }); /** * Makes a request to the API * @param endpoint Endpoint to target * @param method Method to use * @param data Outgoing data * @returns Response promise */ private request; /** * Sends an event and data to the server * @param event Event name * @param data Event data */ private socketEmit; /** * Fetches a refresh token based on Identification token from an OAuth gateway * @param identifier_token Identifier token provided by the oauth gateway * @param client_id Project Client Id * @param client_secret Project Client Secret * @param redirect_uri Used Redirect URI * @param scopes Used Scopes * @returns Refresh token */ oauthIdentify(identifier_token: string, client_id: string, client_secret: string, redirect_uri: string, scopes: string[]): Promise<string>; /** * Creates an Access Token from a Refresh Token * @param refresh_token Refresh token * @returns Access token */ refreshToken(refresh_token: string): Promise<string>; getUserByAccessToken(access_token: string): Promise<PartialUser>; /** * Fetches a User by their ID * @param id User ID * @returns User */ getUser(id: string): Promise<User>; /** * Changes the instance's display name * @param display_name New display name * @returns Resolution result */ changeName(display_name: string): Promise<void>; /** * Fetches the instance's User object * @returns Own User */ getSelf(): Promise<User>; /** * Updates a User's role * * Requires access to the 'MODIFY_ROLES' permission. * @param target Target User's ID * @param role New role * @returns Updated User */ setRole(target: string, role: User['api_level']): Promise<User>; /** * Registers or updates your Service's default data structure * * Requires access to the 'CREATE_SERVICE' permission. * @param name Service name, must be unique * @param structure Default fields for your service * @returns Resolution result */ registerService(name: string, structure: { [key: string]: any; }): Promise<void>; /** * Updates an owned service's data for a user * @param name Service name, must be owned * @param target Target User's ID * @param data Updated service structure * @returns Resolution result */ setService(name: string, target: string, data: { [key: string]: any; }): Promise<void>; /** * Registers an intent for a user to pay for a service * @param price The price to pay, must be less that 9999 and greater than 0 * @param currency Three digit ISO country code * @param purchase_handler Function to handle payments once made * @returns Promise of Gateway URL */ registerPayment(price: number, currency: string, purchase_handler: () => void): Promise<string>; /** * Creates a new Project * * Requires access to the 'CREATE_PROJECT' permission. * * Max of 25 * @returns Resolution result */ createProject(): Promise<ProjectData & { token: string; }>; /** * Fetches an owned project by ID * @param id Project ID * @returns Project */ fetchProject(id: string): Promise<User>; } export { Connections as Client }; //# sourceMappingURL=index.d.ts.map