From 46ea33d61d064a1a22617f5599668e2d380d58a5 Mon Sep 17 00:00:00 2001 From: ZeroWave022 <36341766+ZeroWave022@users.noreply.github.com> Date: Sat, 22 Apr 2023 22:24:42 +0200 Subject: [PATCH 1/3] docs: Add categories --- src/structures/Amount.ts | 2 ++ src/structures/Currency.ts | 4 ++++ src/structures/CurrencyCache.ts | 3 +++ src/structures/CurrencyFormatting.ts | 4 ++++ src/structures/ExchangeRate.ts | 2 ++ src/structures/RequestHandler.ts | 2 ++ src/structures/TipccClient.ts | 2 ++ src/structures/Transaction.ts | 2 ++ src/structures/User.ts | 2 ++ src/structures/Wallet.ts | 2 ++ src/utils/Bucket.ts | 3 +++ typedoc.json | 8 ++++++-- 12 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/structures/Amount.ts b/src/structures/Amount.ts index 8911cf2..359100c 100644 --- a/src/structures/Amount.ts +++ b/src/structures/Amount.ts @@ -3,6 +3,8 @@ 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 { public valueRaw: BigNumber; diff --git a/src/structures/Currency.ts b/src/structures/Currency.ts index cff4124..c19c83d 100644 --- a/src/structures/Currency.ts +++ b/src/structures/Currency.ts @@ -7,6 +7,8 @@ import type { /** * A class for storing an API cryptocurrency. + * + * @category Currency */ export class CryptoCurrency { public code: string; @@ -50,6 +52,8 @@ export class CryptoCurrency { /** * A class for storing an API fiat currency. + * + * @category Currency */ export class FiatCurrency { public code: string; diff --git a/src/structures/CurrencyCache.ts b/src/structures/CurrencyCache.ts index 97e74fa..c41e037 100644 --- a/src/structures/CurrencyCache.ts +++ b/src/structures/CurrencyCache.ts @@ -1,3 +1,6 @@ +/** + * @category Client utilities + */ export class CurrencyCache extends Array { private refreshFunction: () => T[] | Promise; diff --git a/src/structures/CurrencyFormatting.ts b/src/structures/CurrencyFormatting.ts index 7771017..f782ab5 100644 --- a/src/structures/CurrencyFormatting.ts +++ b/src/structures/CurrencyFormatting.ts @@ -7,6 +7,8 @@ import type { /** * A class for storing an API cryptocurrency unit. + * + * @category Currency */ export class CurrencyUnit { public singular: string; @@ -46,6 +48,8 @@ export class CurrencyUnit { /** * A class for storing an API cryptocurrency format. + * + * @category Currency */ export class CurrencyFormat { public scale: number; diff --git a/src/structures/ExchangeRate.ts b/src/structures/ExchangeRate.ts index 269b49a..f14cef6 100644 --- a/src/structures/ExchangeRate.ts +++ b/src/structures/ExchangeRate.ts @@ -3,6 +3,8 @@ 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 { public code: string; diff --git a/src/structures/RequestHandler.ts b/src/structures/RequestHandler.ts index 890787e..5a62948 100644 --- a/src/structures/RequestHandler.ts +++ b/src/structures/RequestHandler.ts @@ -3,6 +3,8 @@ import { Bucket } from '../utils/Bucket'; /** * A handler used for HTTP requests. + * + * @category Utilities */ export class RequestHandler { private _apiBaseUrl: string; diff --git a/src/structures/TipccClient.ts b/src/structures/TipccClient.ts index ea19a81..62896ed 100644 --- a/src/structures/TipccClient.ts +++ b/src/structures/TipccClient.ts @@ -25,6 +25,8 @@ interface Events { /** * A tip.cc client to interact with the API. + * + * @category Client */ export class TipccClient extends EventEmitter { public token: string; diff --git a/src/structures/Transaction.ts b/src/structures/Transaction.ts index 253e769..8a2a32a 100644 --- a/src/structures/Transaction.ts +++ b/src/structures/Transaction.ts @@ -4,6 +4,8 @@ import type { APITransaction } from '@tipccjs/tipcc-api-types'; /** * A class for storing an API transaction. + * + * @category API Classes */ export class Transaction { public id: string; diff --git a/src/structures/User.ts b/src/structures/User.ts index 8b13894..13727d1 100644 --- a/src/structures/User.ts +++ b/src/structures/User.ts @@ -2,6 +2,8 @@ import type { APIConnection } from '@tipccjs/tipcc-api-types'; /** * A class for storing an API user. + * + * @category API Classes */ export class User { public identifier: string; diff --git a/src/structures/Wallet.ts b/src/structures/Wallet.ts index 8910839..fcf19ac 100644 --- a/src/structures/Wallet.ts +++ b/src/structures/Wallet.ts @@ -3,6 +3,8 @@ import type { APIWallet } from '@tipccjs/tipcc-api-types'; /** * A class for storing an API wallet. + * + * @category API Classes */ export class Wallet { public code: string; diff --git a/src/utils/Bucket.ts b/src/utils/Bucket.ts index 6066d76..46aa283 100644 --- a/src/utils/Bucket.ts +++ b/src/utils/Bucket.ts @@ -1,5 +1,8 @@ import type { AxiosRequestConfig } from 'axios'; +/** + * @category Utilities + */ export class Bucket extends Array { public processing: ReturnType | boolean = false; diff --git a/typedoc.json b/typedoc.json index 944d5cf..df4e0f9 100644 --- a/typedoc.json +++ b/typedoc.json @@ -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", @@ -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 } From fee4f858c7c0660d068e70b12d1cbfe97ec71528 Mon Sep 17 00:00:00 2001 From: ZeroWave022 <36341766+ZeroWave022@users.noreply.github.com> Date: Sat, 22 Apr 2023 23:11:52 +0200 Subject: [PATCH 2/3] fix: Export RequestHandler --- src/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/index.ts b/src/index.ts index 400348d..3f7a333 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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'; From f51525182530ed58048855a89c476738654a1884 Mon Sep 17 00:00:00 2001 From: ZeroWave022 <36341766+ZeroWave022@users.noreply.github.com> Date: Sat, 22 Apr 2023 23:16:48 +0200 Subject: [PATCH 3/3] docs: Document multiple class properties --- src/structures/Amount.ts | 2 ++ src/structures/Currency.ts | 8 ++++++++ src/structures/CurrencyCache.ts | 7 +++++++ src/structures/ExchangeRate.ts | 3 +++ src/structures/RequestHandler.ts | 11 ++++++++++- src/structures/TipccClient.ts | 12 +++++++++++- src/structures/Transaction.ts | 11 +++++++++++ src/structures/User.ts | 4 ++++ src/structures/Wallet.ts | 4 ++++ 9 files changed, 60 insertions(+), 2 deletions(-) diff --git a/src/structures/Amount.ts b/src/structures/Amount.ts index 359100c..4236bf6 100644 --- a/src/structures/Amount.ts +++ b/src/structures/Amount.ts @@ -7,8 +7,10 @@ import type { APICoin, APIMonetary } from '@tipccjs/tipcc-api-types'; * @category Currency */ export class Amount { + /** The raw API BigNumber */ public valueRaw: BigNumber; + /** The currency code */ public currency: string; /** diff --git a/src/structures/Currency.ts b/src/structures/Currency.ts index c19c83d..7ca3b66 100644 --- a/src/structures/Currency.ts +++ b/src/structures/Currency.ts @@ -11,14 +11,19 @@ import type { * @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; /** @@ -56,10 +61,13 @@ export class CryptoCurrency { * @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; /** diff --git a/src/structures/CurrencyCache.ts b/src/structures/CurrencyCache.ts index c41e037..61aeb7a 100644 --- a/src/structures/CurrencyCache.ts +++ b/src/structures/CurrencyCache.ts @@ -1,9 +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 extends Array { private refreshFunction: () => T[] | Promise; + /** + * Create a CurrencyCache. + * @param refreshFunction The refresh function which returns new values to insert to this cache + */ constructor(refreshFunction: () => T[] | Promise) { super(); diff --git a/src/structures/ExchangeRate.ts b/src/structures/ExchangeRate.ts index f14cef6..ce28b79 100644 --- a/src/structures/ExchangeRate.ts +++ b/src/structures/ExchangeRate.ts @@ -7,10 +7,13 @@ import type { APIExchangeRate } from '@tipccjs/tipcc-api-types'; * @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; /** diff --git a/src/structures/RequestHandler.ts b/src/structures/RequestHandler.ts index 5a62948..b4a6228 100644 --- a/src/structures/RequestHandler.ts +++ b/src/structures/RequestHandler.ts @@ -20,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, @@ -97,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, diff --git a/src/structures/TipccClient.ts b/src/structures/TipccClient.ts index 62896ed..305ea55 100644 --- a/src/structures/TipccClient.ts +++ b/src/structures/TipccClient.ts @@ -29,18 +29,25 @@ interface Events { * @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(this._refreshCryptos); + /** The {@link CurrencyCache} for fiat currencies */ public fiats = new CurrencyCache(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(); @@ -54,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, diff --git a/src/structures/Transaction.ts b/src/structures/Transaction.ts index 8a2a32a..9fc91f1 100644 --- a/src/structures/Transaction.ts +++ b/src/structures/Transaction.ts @@ -8,26 +8,37 @@ import type { APITransaction } from '@tipccjs/tipcc-api-types'; * @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; /** diff --git a/src/structures/User.ts b/src/structures/User.ts index 13727d1..92dd9dd 100644 --- a/src/structures/User.ts +++ b/src/structures/User.ts @@ -6,12 +6,16 @@ import type { APIConnection } from '@tipccjs/tipcc-api-types'; * @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'; /** diff --git a/src/structures/Wallet.ts b/src/structures/Wallet.ts index fcf19ac..bc5f51a 100644 --- a/src/structures/Wallet.ts +++ b/src/structures/Wallet.ts @@ -7,12 +7,16 @@ import type { APIWallet } from '@tipccjs/tipcc-api-types'; * @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; /**