diff --git a/web/v2/ban.ts b/web/v2/ban.ts index 71bd0c7..7544739 100644 --- a/web/v2/ban.ts +++ b/web/v2/ban.ts @@ -1,41 +1,41 @@ -/** - * Information about a current player's ban. - * @see https://truckersmp.com/developers/api#operation/get-bans-id - */ -export interface APIPlayerBan { - /** - * The time the ban will expire. - */ - expiration: string | null; - - /** - * The time the ban was issued. - */ - timeAdded: string; - - /** - * If the ban is still active. - * - * For the user to be banned the `expiration` date has to be passed or `active` has to be false. - */ - active: boolean; - - /** - * The reason for the ban. - */ - reason: string; - - /** - * @deprecated - v2.21.1.0 - * Name of the admin that banned the user. This field is no longer provided. - * @see https://forum.truckersmp.com/index.php?/topic/112993-website-v221-release/#comment-1111277 - */ - adminName: 'Game Moderator'; - - /** - * @deprecated - v2.21.1.0 - * TruckersMP ID for the admin that banned the user. This field is no longer provided. - * @see https://forum.truckersmp.com/index.php?/topic/112993-website-v221-release/#comment-1111277 - */ - adminID: null; -} +/** + * Information about a current player's ban. + * @see https://truckersmp.com/developers/api#operation/get-bans-id + */ +export interface APIPlayerBan { + /** + * The time the ban will expire. + */ + expiration: string | null; + + /** + * The time the ban was issued. + */ + timeAdded: string; + + /** + * If the ban is still active. + * + * For the user to be banned the `expiration` date has to be passed or `active` has to be false. + */ + active: boolean; + + /** + * The reason for the ban. + */ + reason: string; + + /** + * @deprecated - v2.21.1.0 + * Name of the admin that banned the user. This field is no longer provided. + * @see https://forum.truckersmp.com/index.php?/topic/112993-website-v221-release/#comment-1111277 + */ + adminName: 'Game Moderator'; + + /** + * @deprecated - v2.21.1.0 + * TruckersMP ID for the admin that banned the user. This field is no longer provided. + * @see https://forum.truckersmp.com/index.php?/topic/112993-website-v221-release/#comment-1111277 + */ + adminID: null; +} diff --git a/web/v2/index.ts b/web/v2/index.ts index 9418ab8..510d989 100644 --- a/web/v2/index.ts +++ b/web/v2/index.ts @@ -6,7 +6,7 @@ export * from './rules'; export * from './server'; export * from './version'; -export const APIWebVersion = '2'; +export const APIWebVersion = '2' as const; export const APIWebRoutes = { /** diff --git a/web/v2/player/index.ts b/web/v2/player/index.ts index 343c83d..a53b3b3 100644 --- a/web/v2/player/index.ts +++ b/web/v2/player/index.ts @@ -107,12 +107,12 @@ export interface APIPlayerCompanyHistory { * Information about a TruckersMP player. * @see https://truckersmp.com/developers/api#operation/get-player-id */ -export type APIPlayer = _Base & _APIPlayerVTCHistory & _APIPlayerBanData; +export type APIPlayer = _APIPlayerBase & _APIPlayerVTCHistory & _APIPlayerBanData; -// #region APIPlayer - -/** Base interface containing property annotations */ -interface _Base { +/** + * Base interface containing property annotations + */ +interface _APIPlayerBase { /** * The ID of the requested user. */ @@ -217,7 +217,10 @@ interface _Base { vtcHistory: APIPlayerCompanyHistory[] | null; } -type _APIPlayerVTCHistory = Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> & +/** + * Specific properties of the player object regarding their VTC history + */ +type _APIPlayerVTCHistory = Pick<_APIPlayerBase, 'displayVTCHistory' | 'vtcHistory'> & ( | { displayVTCHistory: false; @@ -229,7 +232,10 @@ type _APIPlayerVTCHistory = Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> & } ); -type _APIPlayerBanData = Pick<_Base, 'displayBans' | 'bansCount'> & +/** + * Specific properties of the player object regarding bans + */ +type _APIPlayerBanData = Pick<_APIPlayerBase, 'displayBans' | 'bansCount'> & ( | { displayBans: false; @@ -240,5 +246,3 @@ type _APIPlayerBanData = Pick<_Base, 'displayBans' | 'bansCount'> & bansCount: number; } ); - -// #endregion APIPlayer diff --git a/web/v2/player/patreon.ts b/web/v2/player/patreon.ts index 53a7fb4..1e2962e 100644 --- a/web/v2/player/patreon.ts +++ b/web/v2/player/patreon.ts @@ -1,4 +1,15 @@ -/** Base interface containing property type annotations and documentation. */ +/** + * Information about player's Patreon status. + */ +type APIPlayerPatreon = + | _APIPlayerPatreonPrivate + | _APIPlayerPatreonNonPatron + | _APIPlayerPatreonIsPatron; +export default APIPlayerPatreon; + +/** + * Base interface containing property type annotations and documentation. + */ interface _APIPlayerPatreonBase { /** * If the user has donated or is currently donating via Patreon. @@ -41,8 +52,10 @@ interface _APIPlayerPatreonBase { hidden: boolean | null; } -/** `patreon` field when the user has their Patreon information hidden */ -interface _APIPartialPlayerPatreonPrivate extends _APIPlayerPatreonBase { +/** + * `patreon` field when the user has their Patreon information hidden + */ +interface _APIPlayerPatreonPrivate extends _APIPlayerPatreonBase { isPatron: false | null; active: null; color: null; @@ -53,16 +66,19 @@ interface _APIPartialPlayerPatreonPrivate extends _APIPlayerPatreonBase { hidden: true; } -// #region Properties specific to the `patreon` field when the information is public - -/** Base interface for public Patreon information */ +/** + * Base interface for public Patreon information + */ interface _APIPartialPlayerPatreonPublicBase { lifetimePledge: number | null; hidden: false | null; } -/** Properties specific to the `patreon` field when the user is an inactive patron */ -interface _APIPartialPlayerPatreonInactive extends _APIPartialPlayerPatreonPublicBase { +/** + * Properties specific to the `patreon` field when the user is an inactive patron + */ +interface _APIPartialPlayerPatreonPublicInactive + extends _APIPartialPlayerPatreonPublicBase { active: false; color: null; tierId: null; @@ -70,8 +86,11 @@ interface _APIPartialPlayerPatreonInactive extends _APIPartialPlayerPatreonPubli nextPledge: null; } -/** Properties specific to the `patreon` field when the user is an active patron */ -interface _APIPartialPlayerPatreonActive extends _APIPartialPlayerPatreonPublicBase { +/** + * Properties specific to the `patreon` field when the user is an active patron + */ +interface _APIPartialPlayerPatreonPublicActive + extends _APIPartialPlayerPatreonPublicBase { active: true; color: string; tierId: number; @@ -79,19 +98,18 @@ interface _APIPartialPlayerPatreonActive extends _APIPartialPlayerPatreonPublicB nextPledge: number | null; } -/** `patreon` field when the user is a current or former patron */ -type _APIPlayerPatreonIsPatron = - & _APIPlayerPatreonBase - & { isPatron: true } - & (_APIPartialPlayerPatreonInactive | _APIPartialPlayerPatreonActive); - -/** `patreon` field when the user is not a patron (ie. has never donated) */ -interface _APIPlayerPatreonNonPatron extends _APIPartialPlayerPatreonInactive { isPatron: false } - -// #endregion +/** + * `patreon` field when the user is not a patron (ie. has never donated) + */ +interface _APIPlayerPatreonNonPatron + extends _APIPartialPlayerPatreonPublicInactive { + isPatron: false; +} /** - * Information about player's Patreon status. + * `patreon` field when the user is a current or former patron */ -type APIPlayerPatreon = _APIPartialPlayerPatreonPrivate | _APIPlayerPatreonNonPatron | _APIPlayerPatreonIsPatron; -export default APIPlayerPatreon; +type _APIPlayerPatreonIsPatron = _APIPlayerPatreonBase & { isPatron: true } & ( + | _APIPartialPlayerPatreonPublicInactive + | _APIPartialPlayerPatreonPublicActive + );