Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ export * from './structures/Currency';
export * from './structures/CurrencyCache';
export * from './structures/CurrencyFormatting';
export * from './structures/ExchangeRate';
export * from './structures/RequestHandler';
export * from './structures/TipccClient';
export * from './structures/Transaction';
export * from './structures/User';
Expand Down
4 changes: 4 additions & 0 deletions src/structures/Amount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import type { APICoin, APIMonetary } from '@tipccjs/tipcc-api-types';

/**
* A class for storing an API amount. This can be used for either fiats or cryptocurrencies.
*
* @category Currency
*/
export class Amount {
/** The raw API BigNumber */
public valueRaw: BigNumber;

/** The currency code */
public currency: string;

/**
Expand Down
12 changes: 12 additions & 0 deletions src/structures/Currency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ import type {

/**
* A class for storing an API cryptocurrency.
*
* @category Currency
*/
export class CryptoCurrency {
/** The currency code */
public code: string;

/** The currency name */
public name: string;

/** The currency icon link */
public icon: string;

/** The currency explorer link */
public explorer: string;

/** An instance of {@link CurrencyFormat} for this currency */
public format: CurrencyFormat;

/**
Expand Down Expand Up @@ -50,12 +57,17 @@ export class CryptoCurrency {

/**
* A class for storing an API fiat currency.
*
* @category Currency
*/
export class FiatCurrency {
/** The currency code */
public code: string;

/** The currency name */
public name: string;

/** An instance of {@link CurrencyFormat} for this currency */
public format: CurrencyFormat;

/**
Expand Down
10 changes: 10 additions & 0 deletions src/structures/CurrencyCache.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
/**
* A class extending Array holding a cache of objects with type T.
*
* @category Client utilities
* @typeParam T - The object type this {@link CurrencyCache} will hold
*/
export class CurrencyCache<T> extends Array {
private refreshFunction: () => T[] | Promise<T[]>;

/**
* Create a CurrencyCache.
* @param refreshFunction The refresh function which returns new values to insert to this cache
*/
constructor(refreshFunction: () => T[] | Promise<T[]>) {
super();

Expand Down
4 changes: 4 additions & 0 deletions src/structures/CurrencyFormatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import type {

/**
* A class for storing an API cryptocurrency unit.
*
* @category Currency
*/
export class CurrencyUnit {
public singular: string;
Expand Down Expand Up @@ -46,6 +48,8 @@ export class CurrencyUnit {

/**
* A class for storing an API cryptocurrency format.
*
* @category Currency
*/
export class CurrencyFormat {
public scale: number;
Expand Down
5 changes: 5 additions & 0 deletions src/structures/ExchangeRate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,17 @@ import type { APIExchangeRate } from '@tipccjs/tipcc-api-types';

/**
* A class for storing an API exchange rate for a cryptocurrency.
*
* @category API Classes
*/
export class ExchangeRate {
/** The currency code */
public code: string;

/** The currency name */
public name: string;

/** The USD value of {@link ExchangeRate.code currency} */
public usdValue?: Amount;

/**
Expand Down
13 changes: 12 additions & 1 deletion src/structures/RequestHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Bucket } from '../utils/Bucket';

/**
* A handler used for HTTP requests.
*
* @category Utilities
*/
export class RequestHandler {
private _apiBaseUrl: string;
Expand All @@ -18,7 +20,8 @@ export class RequestHandler {
/**
* Create a RequestHandler.
* @param apiKey The tip.cc API key
* @param payload Optional: options for requests
* @param payload The options for requests
* @param payload.apiBaseUrl The base URL to use
*/
constructor(
apiKey: string,
Expand Down Expand Up @@ -95,6 +98,14 @@ export class RequestHandler {
return this.request('POST', route, payload, requestOptions);
}

/**
* Send a HTTP request
* @param method The HTTP method
* @param route The route to request
* @param payload The data to send with the request
* @param requestOptions Optional additional configuration for Axios
* @returns
*/
public request(
method: 'POST' | 'GET',
route: string,
Expand Down
14 changes: 13 additions & 1 deletion src/structures/TipccClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,29 @@ interface Events {

/**
* A tip.cc client to interact with the API.
*
* @category Client
*/
export class TipccClient extends EventEmitter {
/** The tip.cc API token this client uses */
public token: string;

/** The {@link RequestHandler} this client uses */
public REST: RequestHandler;

/** The {@link CurrencyCache} for cryptocurrencies */
public cryptos = new CurrencyCache<CryptoCurrency>(this._refreshCryptos);

/** The {@link CurrencyCache} for fiat currencies */
public fiats = new CurrencyCache<FiatCurrency>(this._refreshFiats);

/** A boolean indicating whether the client is ready */
public isReady = false;

/** The number of milliseconds between each API poll */
public pollingInterval = 10000;

/** The max number of retries to poll the API, after which an error will be thrown */
public maxRetries = 5;

private polling = new Set();
Expand All @@ -52,7 +61,10 @@ export class TipccClient extends EventEmitter {
/**
* Create a tip.cc client.
* @param token The tip.cc API token to use
* @param options Optional options
* @param options The options to use
* @param options.baseUrl The base URL for requests
* @param options.pollingInterval The number of milliseconds between each API poll. Defaults to `10000`.
* @param options.maxRetries The max number of retries to poll the API, after which an error will be thrown. Defaults to `5`.
*/
constructor(
token: string,
Expand Down
13 changes: 13 additions & 0 deletions src/structures/Transaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,41 @@ import type { APITransaction } from '@tipccjs/tipcc-api-types';

/**
* A class for storing an API transaction.
*
* @category API Classes
*/
export class Transaction {
/** The transaction id */
public id: string;

/** The type of transaction */
public type: 'tip' | 'withdrawal' | 'deposit' = 'tip';

/** An instance of {@link Amount} for this transaction */
public amount: Amount;

/** An instance of {@link Amount} for the fee of this transaction */
public fee: Amount | null = null;

/** An instance of {@link Amount} for the USD value of this transaction */
public usdValue: Amount | null = null;

/** The service in which this transaction took place */
public service = 'discord' as const;

/** The chat (guild) id where this transaction took place */
public chatId: string;

/** The subchat (channel) id where this transaction took place */
public subchatId: string;

/** The id of the sender */
public sender: User;

/** The id of the recipient */
public recipient: User;

/** The Date when this transaction was created */
public created: Date;

/**
Expand Down
6 changes: 6 additions & 0 deletions src/structures/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,20 @@ import type { APIConnection } from '@tipccjs/tipcc-api-types';

/**
* A class for storing an API user.
*
* @category API Classes
*/
export class User {
/** The identifier (id) of this user */
public identifier: string;

/** The user's username */
public username: string | null;

/** The user's avatar URL */
public avatarUrl: string | null;

/** The service where this user is registered */
public service: 'discord';

/**
Expand Down
6 changes: 6 additions & 0 deletions src/structures/Wallet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,20 @@ import type { APIWallet } from '@tipccjs/tipcc-api-types';

/**
* A class for storing an API wallet.
*
* @category API Classes
*/
export class Wallet {
/** The currency code */
public code: string;

/** The currency name */
public name: string;

/** The balance of this wallet */
public balance: Amount;

/** The USD value of this wallet's balance */
public usdValue: Amount | null = null;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/utils/Bucket.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import type { AxiosRequestConfig } from 'axios';

/**
* @category Utilities
*/
export class Bucket extends Array {
public processing: ReturnType<typeof setTimeout> | boolean = false;

Expand Down
8 changes: 6 additions & 2 deletions typedoc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"entryPoints": ["./src/**/*.ts"],
"$schema": "https://typedoc.org/schema.json",
"entryPoints": ["./src/index.ts"],
"out": "docs",
"name": "tipcc.js Documentation",
"cname": "tipccjs.org",
Expand All @@ -8,7 +9,10 @@
"GitHub": "https://github.com/tipccjs/tipcc.js"
},
"defaultCategory": "Classes",
"categorizeByGroup": true,
"categorizeByGroup": false,
"categoryOrder": [
"Client", "Client utilities", "*", "Utilities"
],
"customCss": "./docs.css",
"githubPages": false
}