From 4c4e33208f05146b13cd3b4d0c6f9917d973b5cc Mon Sep 17 00:00:00 2001 From: Maxim <102874843+maxim-01@users.noreply.github.com> Date: Tue, 28 Nov 2023 18:27:27 +0000 Subject: [PATCH 1/6] Update to match recent API changes - Updated ban-related fields in line with recent changes - Narrowed down fields in certain types for better IntelliSense - Loosened param types for methods returning API routes to accept string here applicable --- traffic/v2/index.ts | 10 +- traffic/v2/server.ts | 40 +++-- traffic/v2/traffic.ts | 62 ++++--- tsconfig.json | 3 +- web/v2/ban.ts | 14 +- web/v2/event.ts | 12 +- web/v2/index.ts | 16 +- web/v2/player.ts | 385 ++++++++++++++++++++++++++---------------- web/v2/server.ts | 4 +- 9 files changed, 349 insertions(+), 197 deletions(-) diff --git a/traffic/v2/index.ts b/traffic/v2/index.ts index cbc651c..567f9ed 100644 --- a/traffic/v2/index.ts +++ b/traffic/v2/index.ts @@ -1,9 +1,9 @@ -import type { APITrafficServerGameName } from './server'; +import type { APITrafficServerGameName } from "./server"; -export * from './server'; -export * from './traffic'; +export * from "./server"; +export * from "./traffic"; -export const APITrafficVersion = '2'; +export const APITrafficVersion = "2" as const; export const APITrafficRoutes = { /** @@ -13,7 +13,7 @@ export const APITrafficRoutes = { * @returns APIResponse */ servers() { - return '/public/servers.json' as const; + return "/public/servers.json" as const; }, /** diff --git a/traffic/v2/server.ts b/traffic/v2/server.ts index c2a4cec..db15a7a 100644 --- a/traffic/v2/server.ts +++ b/traffic/v2/server.ts @@ -1,7 +1,7 @@ /** * A short name of a game map type. */ -export type APITrafficServerGameName = 'ets2' | 'promods' | 'ats'; +export type APITrafficServerGameName = "ets2" | "promods" | "ats"; /** * Basic information of a TruckersMP server. @@ -70,16 +70,30 @@ export interface APITrafficServer { /** * Response type of the traffic servers API end-point. */ -export interface APITrafficServers { - /** - * Determines whether the service is offline. If this is the case, no servers - * and/or traffic information may be provided. - */ - offline: boolean; +export type APITrafficServers = + | { + /** + * Determines whether the service is offline. If this is the case, no servers + * and/or traffic information may be provided. + */ + offline: false; - /** - * A collection of public game servers. - * @see https://truckersmp.com/developers/api#operation/get-servers - */ - servers?: APITrafficServer[]; -} + /** + * A collection of public game servers. + * @see https://truckersmp.com/developers/api#operation/get-servers + */ + servers: APITrafficServer[]; + } + | { + /** + * Determines whether the service is offline. If this is the case, no servers + * and/or traffic information may be provided. + */ + offline: true; + + /** + * A collection of public game servers. + * @see https://truckersmp.com/developers/api#operation/get-servers + */ + servers?: never; + }; diff --git a/traffic/v2/traffic.ts b/traffic/v2/traffic.ts index a4dc4fd..45a76a3 100644 --- a/traffic/v2/traffic.ts +++ b/traffic/v2/traffic.ts @@ -1,9 +1,14 @@ -import type { APITrafficServer } from './server'; +import type { APITrafficServer } from "./server"; /** * The congestion severity of the given location. */ -export type APITrafficLocationSeverity = 'Empty' | 'Low' | 'Moderate' | 'Congested' | 'Heavy'; +export type APITrafficLocationSeverity = + | "Empty" + | "Low" + | "Moderate" + | "Congested" + | "Heavy"; /** * Information about a traffic location on the map. @@ -49,7 +54,7 @@ export interface APITrafficServerTop { * Basic information of a TruckersMP server. * @see https://truckersmp.com/developers/api#operation/get-servers */ - server?: Omit; + server?: Omit; /** * 8 busiest locations on the map (descending order). @@ -60,21 +65,40 @@ export interface APITrafficServerTop { /** * Response type for all locations on the game server. */ -export interface APITrafficServerTraffic { - /** - * Determines whether the service is offline. If this is the case, no servers - * and/or traffic information may be provided. - */ - offline: boolean; +export type APITrafficServerTraffic = + | { + /** + * Determines whether the service is offline. If this is the case, no servers + * and/or traffic information may be provided. + */ + offline: false; - /** - * Basic information of a TruckersMP server. - * @see https://truckersmp.com/developers/api#operation/get-servers - */ - server?: Omit; + /** + * Basic information of a TruckersMP server. + * @see https://truckersmp.com/developers/api#operation/get-servers + */ + server: Omit; - /** - * All locations on the map. - */ - traffic?: APITrafficLocation[]; -} + /** + * All locations on the map. + */ + traffic: APITrafficLocation[]; + } + | { + /** + * Determines whether the service is offline. If this is the case, no servers + * and/or traffic information may be provided. + */ + offline: true; + + /** + * Basic information of a TruckersMP server. + * @see https://truckersmp.com/developers/api#operation/get-servers + */ + server?: never; + + /** + * All locations on the map. + */ + traffic?: never; + }; diff --git a/tsconfig.json b/tsconfig.json index 64f0255..3454e8c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,7 +9,8 @@ "skipLibCheck": true, "sourceMap": true, "declaration": true, - "declarationMap": true + "declarationMap": true, + "strictNullChecks": true }, "exclude": ["./node_modules"] } diff --git a/web/v2/ban.ts b/web/v2/ban.ts index 31c7285..f1cd1b6 100644 --- a/web/v2/ban.ts +++ b/web/v2/ban.ts @@ -26,12 +26,18 @@ export interface APIPlayerBan { reason: string; /** - * Name of the admin that banned the user. + * @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: string; + adminName: "Game Moderator"; /** - * TruckersMP ID for the admin that banned the user. + * @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: number; + adminID: null; } + +export type APIPlayerBans = APIPlayerBan[]; diff --git a/web/v2/event.ts b/web/v2/event.ts index aefb265..cc541c8 100644 --- a/web/v2/event.ts +++ b/web/v2/event.ts @@ -61,7 +61,7 @@ export interface APIGameEventType { /** * The event's type key. */ - key: string; + key: "convoy" | "truck_show" | "truck_show_and_convoy"; /** * The event's type name. @@ -241,6 +241,11 @@ export interface APIGameEvent { */ arrive: APIGameEventLocation; + /** + * The date and time the event's meetup is scheduled at (UTC). + */ + meetup_at: string | null; + /** * The date and time the event starts at (UTC). */ @@ -298,8 +303,11 @@ export interface APIGameEvent { /** * The event's required DLCs. + * + * - Empty array when no DLCs are required; + * - Record when 1 or more DLCs are required, where the key is the Steam app ID and value is the DLC's name. */ - dlcs: Record; + dlcs: Record | []; /** * The relative URL to the event page. diff --git a/web/v2/index.ts b/web/v2/index.ts index 483eb44..4c53ff0 100644 --- a/web/v2/index.ts +++ b/web/v2/index.ts @@ -17,7 +17,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - bans(id: bigint) { + bans(id: bigint | string) { return `/bans/${id}` as const; }, @@ -64,7 +64,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyEvent(companyId: string | number, eventId: number) { + companyEvent(companyId: string | number, eventId: number | string) { return `/vtc/${companyId}/events/${eventId}` as const; }, @@ -89,7 +89,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyMember(companyId: string | number, memberId: number) { + companyMember(companyId: string | number, memberId: number | string) { return `/vtc/${companyId}/member/${memberId}` as const; }, @@ -114,7 +114,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyNewsEntry(companyId: string | number, newsId: number) { + companyNewsEntry(companyId: string | number, newsId: number | string) { return `/vtc/${companyId}/news/${newsId}` as const; }, @@ -139,7 +139,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyRole(companyId: string | number, roleId: number) { + companyRole(companyId: string | number, roleId: number | string) { return `/vtc/${companyId}/role/${roleId}` as const; }, @@ -151,7 +151,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - event(id: number) { + event(id: number | string) { return `/events/${id}` as const; }, @@ -173,7 +173,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - eventsUser(id: number) { + eventsUser(id: number | string) { return `/events/user/${id}` as const; }, @@ -185,7 +185,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - player(id: bigint) { + player(id: bigint | number | string) { return `/player/${id}` as const; }, diff --git a/web/v2/player.ts b/web/v2/player.ts index de4d2bd..5189fb5 100644 --- a/web/v2/player.ts +++ b/web/v2/player.ts @@ -1,70 +1,142 @@ /** * Information about player's Patreon status. */ -export interface APIPlayerPatreon { - /** - * If the user has donated or is currently donating via Patreon. - */ - isPatron: boolean; - - /** - * If the user has an active Patreon subscription. - */ - active: boolean; +type APIPlayerPatreon = APIPlayerPatreon.InfoHidden | APIPlayerPatreon.NonPatron | APIPlayerPatreon.Patron; +namespace APIPlayerPatreon { + /** Base interface containing property annotations */ + interface _Base { + /** + * If the user has donated or is currently donating via Patreon. + */ + isPatron: boolean | null; + + /** + * If the user has an active Patreon subscription. + */ + active: boolean | null; + + /** + * HEX code for subscribed tier. + */ + color: string | null; + + /** + * The tier ID of current pledge. + */ + tierId: number | null; + + /** + * Current pledge in cents. + */ + currentPledge: number | null; + + /** + * Lifetime pledge in cents. + */ + lifetimePledge: number | null; + + /** + * Next pledge in cents. + */ + nextPledge: number | null; + + /** + * If user has their Patreon information hidden. + */ + hidden: boolean | null; + } + + /** Properties specific to the `patreon` field when the information is public (not hidden) */ + interface _VisiblePartial { + lifetimePledge: number | null; + hidden: false | null; + } + + /** Properties specific to the `patreon` field when the user is an inactive patron */ + interface _InactivePartial extends _VisiblePartial { + active: false; + color: null; + tierId: null; + currentPledge: null; + nextPledge: null; + } + + /** Properties specific to the `patreon` field when the user is an active patron */ + interface _ActivePartial extends _VisiblePartial { + active: true; + color: string; + tierId: number; + currentPledge: number; + nextPledge: number | null; + } + + /** `patreon` field when the user has their Patreon information hidden */ + export interface InfoHidden extends _Base { + isPatron: false | null; + active: null; + color: null; + tierId: null; + currentPledge: null; + lifetimePledge: null; + nextPledge: null; + hidden: true; + } + + /** `patreon` field when the user is a patron (active or not) */ + export type Patron = _Base & ({ isPatron: true } & (_InactivePartial | _ActivePartial)); + + /** `patreon` field when the user is not a patron (ie. has never donated) */ + export interface NonPatron extends _InactivePartial { isPatron: false }; +} +export { APIPlayerPatreon }; +export interface APIPlayerPermissions { /** - * HEX code for subscribed tier. + * If the user is a TruckersMP staff member. */ - color: string | null; + isStaff: boolean; /** - * The tier ID of current pledge. + * If the user is part of upper staff within the TruckersMP team. */ - tierId: number | null; + isUpperStaff: boolean; /** - * Current pledge in cents. + * If the user has Game Moderator permissions. */ - currentPledge: number | null; + isGameAdmin: boolean; +} +/** + * Information about player's membership in a virtual trucking company. + */ +export type APIPlayerCompanyMember = { /** - * Lifetime pledge in cents. + * ID of the company the user belongs to or 0 if not in a company. */ - lifetimePledge: number | null; + id: 0; /** - * Next pledge in cents. + * Name of the company the user belongs to or empty if not in a company. */ - nextPledge: number | null; + name: ""; /** - * If user has their Patreon information hidden. + * Tag of the company the user belongs to or empty if not in a company. */ - hidden: boolean | null; -} + tag: ""; -export interface APIPlayerPermissions { /** - * If the user is a TruckersMP staff member. - */ - isStaff: boolean; - - /** - * If the user is part of upper staff within the TruckersMP team. + * If the user is in a company. */ - isUpperStaff: boolean; + inVTC: false; /** - * If the user has Game Moderator permissions. + * Company member ID or 0 if not in a company. */ - isGameAdmin: boolean; -} - -/** - * Information about player's membership in a virtual trucking company. - */ -export interface APIPlayerCompanyMember { - /** + memberID: 0; +} | { + /** * ID of the company the user belongs to or 0 if not in a company. */ id: number; @@ -82,7 +154,7 @@ export interface APIPlayerCompanyMember { /** * If the user is in a company. */ - inVTC: boolean; + inVTC: true; /** * Company member ID or 0 if not in a company. @@ -124,106 +196,133 @@ export interface APIPlayerCompanyHistory { * Information about a TruckersMP player. * @see https://truckersmp.com/developers/api#operation/get-player-id */ -export interface APIPlayer { - /** - * The ID of the requested user. - */ - id: number; - - /** - * The name of the user. - */ - name: string; - - /** - * URL to the avatar used on the website. - */ - avatar: string; - - /** - * URL to the avatar used on the website (32px x 32px). - */ - smallAvatar: string; - - /** - * The date and time the user registered (UTC). - */ - joinDate: string; - - /** - * The SteamID64 of the user. - */ - steamID64: bigint; - - /** - * The SteamID64 of the user. - */ - steamID: string; - - /** - * The Discord account linked to the user or `null` if not linked or private. - */ - discordSnowflake: string | null; - - /** - * If the user's company history is visible. - */ - displayVTCHistory: boolean; - - /** - * The name of the group the user belongs to. - */ - groupName: string; - - /** - * The color of the group. - */ - groupColor: string; - - /** - * The ID of the group the user belongs to. - */ - groupID: number; - - /** - * If the user is currently banned. - */ - banned: boolean; - - /** - * The date and time the ban will expire (UTC) or `null` if not banned or ban is permanent. - */ - bannedUntil: string | null; - - /** - * The number of active bans a user has or `null` if private. - */ - bansCount: number | null; - - /** - * If the user has their bans hidden. - */ - displayBans: boolean; - - /** - * Data of the player's Patreon status. - */ - patreon: APIPlayerPatreon; - - /** - * Permissions that the player has. - */ - permissions: APIPlayerPermissions; - - /** - * Information about player's membership in a virtual trucking company. - */ - vtc: APIPlayerCompanyMember; - - /** - * Entries with brief information of a company the player was in. - * - * If the user does not allow to see their company history, `null` will be returned instead. - */ - vtcHistory: APIPlayerCompanyHistory[] | null; +export type APIPlayer = APIPlayer.Player; +namespace APIPlayer { + /** Base interface containing property annotations */ + interface _Base { + /** + * The ID of the requested user. + */ + id: number; + + /** + * The name of the user. + */ + name: string; + + /** + * URL to the avatar used on the website. + */ + avatar: string; + + /** + * URL to the avatar used on the website (32px x 32px). + */ + smallAvatar: string; + + /** + * The date and time the user registered (UTC). + */ + joinDate: string; + + /** + * The SteamID64 of the user. + */ + steamID64: bigint; + + /** + * The SteamID64 of the user. + */ + steamID: string; + + /** + * The Discord account linked to the user or `null` if not linked or private. + */ + discordSnowflake: string | null; + + /** + * If the user's company history is visible. + */ + displayVTCHistory: boolean; + + /** + * The name of the group the user belongs to. + */ + groupName: string; + + /** + * The color of the group. + */ + groupColor: string; + + /** + * The ID of the group the user belongs to. + */ + groupID: number; + + /** + * If the user is currently banned. + */ + banned: boolean; + + /** + * @deprecated + * This field is no longer available and will be returned as `null`. + */ + bannedUntil: null; + + /** + * The number of active bans a user has or `null` if private. + */ + bansCount: number | null; + + /** + * If the user has their bans hidden. + */ + displayBans: boolean; + + /** + * Data of the player's Patreon status. + */ + patreon: APIPlayerPatreon; + + /** + * Permissions that the player has. + */ + permissions: APIPlayerPermissions; + + /** + * Information about player's membership in a virtual trucking company. + */ + vtc: APIPlayerCompanyMember; + + /** + * Entries with brief information of a company the player was in. + * + * If the user does not allow to see their company history, `null` will be returned instead. + */ + vtcHistory: APIPlayerCompanyHistory[] | null; + } + + interface _VTCHistoryHidden extends Pick<_Base, "displayVTCHistory" | "vtcHistory"> { + displayVTCHistory: false; + vtcHistory: null; + } + interface _VTCHistoryPublic extends Pick<_Base, "displayVTCHistory" | "vtcHistory"> { + displayVTCHistory: true; + vtcHistory: APIPlayerCompanyHistory[]; + } + type _VTCHistory = _VTCHistoryHidden | _VTCHistoryPublic; + + interface _BansHidden extends Pick<_Base, "displayBans" | "bansCount"> { + displayBans: false; + bansCount: null; + } + interface _BansPublic extends Pick<_Base, "displayBans" | "bansCount"> { + displayBans: true; + bansCount: number; + } + type _BanData = _BansHidden | _BansPublic; + + export type Player = _Base & _VTCHistory & _BanData; } diff --git a/web/v2/server.ts b/web/v2/server.ts index 4265eae..2d264ba 100644 --- a/web/v2/server.ts +++ b/web/v2/server.ts @@ -74,9 +74,9 @@ export interface APIGameServer { displayorder: number; /** - * If the speed limiter is enabled on the server (110 kmh for ETS2 and 80 mph for ATS). + * Whether or not the speed limiter is enabled on the server (110 kmh for ETS2 and 80 mph for ATS). */ - speedlimiter: number; + speedlimiter: 0 | 1; /** * If server wide collisions is enabled. From dee53a749f58f36dbbb4c83158a797e687063c48 Mon Sep 17 00:00:00 2001 From: Maxim <102874843+maxim-01@users.noreply.github.com> Date: Tue, 28 Nov 2023 21:27:04 +0000 Subject: [PATCH 2/6] Fix ESLint violations --- traffic/v2/index.ts | 10 +- traffic/v2/server.ts | 2 +- traffic/v2/traffic.ts | 16 +- web/v2/ban.ts | 2 +- web/v2/event.ts | 4 +- web/v2/player.ts | 328 --------------------------------------- web/v2/player/index.ts | 246 +++++++++++++++++++++++++++++ web/v2/player/patreon.ts | 90 +++++++++++ 8 files changed, 353 insertions(+), 345 deletions(-) delete mode 100644 web/v2/player.ts create mode 100644 web/v2/player/index.ts create mode 100644 web/v2/player/patreon.ts diff --git a/traffic/v2/index.ts b/traffic/v2/index.ts index 567f9ed..1f02d88 100644 --- a/traffic/v2/index.ts +++ b/traffic/v2/index.ts @@ -1,9 +1,9 @@ -import type { APITrafficServerGameName } from "./server"; +import type { APITrafficServerGameName } from './server'; -export * from "./server"; -export * from "./traffic"; +export * from './server'; +export * from './traffic'; -export const APITrafficVersion = "2" as const; +export const APITrafficVersion = '2' as const; export const APITrafficRoutes = { /** @@ -13,7 +13,7 @@ export const APITrafficRoutes = { * @returns APIResponse */ servers() { - return "/public/servers.json" as const; + return '/public/servers.json' as const; }, /** diff --git a/traffic/v2/server.ts b/traffic/v2/server.ts index db15a7a..1d0af95 100644 --- a/traffic/v2/server.ts +++ b/traffic/v2/server.ts @@ -1,7 +1,7 @@ /** * A short name of a game map type. */ -export type APITrafficServerGameName = "ets2" | "promods" | "ats"; +export type APITrafficServerGameName = 'ets2' | 'promods' | 'ats'; /** * Basic information of a TruckersMP server. diff --git a/traffic/v2/traffic.ts b/traffic/v2/traffic.ts index 45a76a3..d14a912 100644 --- a/traffic/v2/traffic.ts +++ b/traffic/v2/traffic.ts @@ -1,14 +1,14 @@ -import type { APITrafficServer } from "./server"; +import type { APITrafficServer } from './server'; /** * The congestion severity of the given location. */ export type APITrafficLocationSeverity = - | "Empty" - | "Low" - | "Moderate" - | "Congested" - | "Heavy"; + | 'Empty' + | 'Low' + | 'Moderate' + | 'Congested' + | 'Heavy'; /** * Information about a traffic location on the map. @@ -54,7 +54,7 @@ export interface APITrafficServerTop { * Basic information of a TruckersMP server. * @see https://truckersmp.com/developers/api#operation/get-servers */ - server?: Omit; + server?: Omit; /** * 8 busiest locations on the map (descending order). @@ -77,7 +77,7 @@ export type APITrafficServerTraffic = * Basic information of a TruckersMP server. * @see https://truckersmp.com/developers/api#operation/get-servers */ - server: Omit; + server: Omit; /** * All locations on the map. diff --git a/web/v2/ban.ts b/web/v2/ban.ts index f1cd1b6..59d7b57 100644 --- a/web/v2/ban.ts +++ b/web/v2/ban.ts @@ -30,7 +30,7 @@ export interface APIPlayerBan { * 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"; + adminName: 'Game Moderator'; /** * @deprecated - v2.21.1.0 diff --git a/web/v2/event.ts b/web/v2/event.ts index cc541c8..c18b806 100644 --- a/web/v2/event.ts +++ b/web/v2/event.ts @@ -61,7 +61,7 @@ export interface APIGameEventType { /** * The event's type key. */ - key: "convoy" | "truck_show" | "truck_show_and_convoy"; + key: 'convoy' | 'truck_show' | 'truck_show_and_convoy'; /** * The event's type name. @@ -305,7 +305,7 @@ export interface APIGameEvent { * The event's required DLCs. * * - Empty array when no DLCs are required; - * - Record when 1 or more DLCs are required, where the key is the Steam app ID and value is the DLC's name. + * - Record when DLCs are required, where the key is the Steam app ID and value is the DLC's name. */ dlcs: Record | []; diff --git a/web/v2/player.ts b/web/v2/player.ts deleted file mode 100644 index 5189fb5..0000000 --- a/web/v2/player.ts +++ /dev/null @@ -1,328 +0,0 @@ -/** - * Information about player's Patreon status. - */ -type APIPlayerPatreon = APIPlayerPatreon.InfoHidden | APIPlayerPatreon.NonPatron | APIPlayerPatreon.Patron; -namespace APIPlayerPatreon { - /** Base interface containing property annotations */ - interface _Base { - /** - * If the user has donated or is currently donating via Patreon. - */ - isPatron: boolean | null; - - /** - * If the user has an active Patreon subscription. - */ - active: boolean | null; - - /** - * HEX code for subscribed tier. - */ - color: string | null; - - /** - * The tier ID of current pledge. - */ - tierId: number | null; - - /** - * Current pledge in cents. - */ - currentPledge: number | null; - - /** - * Lifetime pledge in cents. - */ - lifetimePledge: number | null; - - /** - * Next pledge in cents. - */ - nextPledge: number | null; - - /** - * If user has their Patreon information hidden. - */ - hidden: boolean | null; - } - - /** Properties specific to the `patreon` field when the information is public (not hidden) */ - interface _VisiblePartial { - lifetimePledge: number | null; - hidden: false | null; - } - - /** Properties specific to the `patreon` field when the user is an inactive patron */ - interface _InactivePartial extends _VisiblePartial { - active: false; - color: null; - tierId: null; - currentPledge: null; - nextPledge: null; - } - - /** Properties specific to the `patreon` field when the user is an active patron */ - interface _ActivePartial extends _VisiblePartial { - active: true; - color: string; - tierId: number; - currentPledge: number; - nextPledge: number | null; - } - - /** `patreon` field when the user has their Patreon information hidden */ - export interface InfoHidden extends _Base { - isPatron: false | null; - active: null; - color: null; - tierId: null; - currentPledge: null; - lifetimePledge: null; - nextPledge: null; - hidden: true; - } - - /** `patreon` field when the user is a patron (active or not) */ - export type Patron = _Base & ({ isPatron: true } & (_InactivePartial | _ActivePartial)); - - /** `patreon` field when the user is not a patron (ie. has never donated) */ - export interface NonPatron extends _InactivePartial { isPatron: false }; -} -export { APIPlayerPatreon }; - -export interface APIPlayerPermissions { - /** - * If the user is a TruckersMP staff member. - */ - isStaff: boolean; - - /** - * If the user is part of upper staff within the TruckersMP team. - */ - isUpperStaff: boolean; - - /** - * If the user has Game Moderator permissions. - */ - isGameAdmin: boolean; -} - -/** - * Information about player's membership in a virtual trucking company. - */ -export type APIPlayerCompanyMember = { - /** - * ID of the company the user belongs to or 0 if not in a company. - */ - id: 0; - - /** - * Name of the company the user belongs to or empty if not in a company. - */ - name: ""; - - /** - * Tag of the company the user belongs to or empty if not in a company. - */ - tag: ""; - - /** - * If the user is in a company. - */ - inVTC: false; - - /** - * Company member ID or 0 if not in a company. - */ - memberID: 0; -} | { - /** - * ID of the company the user belongs to or 0 if not in a company. - */ - id: number; - - /** - * Name of the company the user belongs to or empty if not in a company. - */ - name: string; - - /** - * Tag of the company the user belongs to or empty if not in a company. - */ - tag: string; - - /** - * If the user is in a company. - */ - inVTC: true; - - /** - * Company member ID or 0 if not in a company. - */ - memberID: number; -} - -/** - * Entry with brief information of the company the player was previously in. - */ -export interface APIPlayerCompanyHistory { - /** - * ID of the company. - */ - id: number; - - /** - * Name of the company. - */ - name: string; - - /** - * If the company is verified. - */ - verified: boolean; - - /** - * Date and time the user joined the company (UTC). - */ - joinDate: string; - - /** - * Date and time the user left the company (UTC). - */ - leftDate: string; -} - -/** - * Information about a TruckersMP player. - * @see https://truckersmp.com/developers/api#operation/get-player-id - */ -export type APIPlayer = APIPlayer.Player; -namespace APIPlayer { - /** Base interface containing property annotations */ - interface _Base { - /** - * The ID of the requested user. - */ - id: number; - - /** - * The name of the user. - */ - name: string; - - /** - * URL to the avatar used on the website. - */ - avatar: string; - - /** - * URL to the avatar used on the website (32px x 32px). - */ - smallAvatar: string; - - /** - * The date and time the user registered (UTC). - */ - joinDate: string; - - /** - * The SteamID64 of the user. - */ - steamID64: bigint; - - /** - * The SteamID64 of the user. - */ - steamID: string; - - /** - * The Discord account linked to the user or `null` if not linked or private. - */ - discordSnowflake: string | null; - - /** - * If the user's company history is visible. - */ - displayVTCHistory: boolean; - - /** - * The name of the group the user belongs to. - */ - groupName: string; - - /** - * The color of the group. - */ - groupColor: string; - - /** - * The ID of the group the user belongs to. - */ - groupID: number; - - /** - * If the user is currently banned. - */ - banned: boolean; - - /** - * @deprecated - * This field is no longer available and will be returned as `null`. - */ - bannedUntil: null; - - /** - * The number of active bans a user has or `null` if private. - */ - bansCount: number | null; - - /** - * If the user has their bans hidden. - */ - displayBans: boolean; - - /** - * Data of the player's Patreon status. - */ - patreon: APIPlayerPatreon; - - /** - * Permissions that the player has. - */ - permissions: APIPlayerPermissions; - - /** - * Information about player's membership in a virtual trucking company. - */ - vtc: APIPlayerCompanyMember; - - /** - * Entries with brief information of a company the player was in. - * - * If the user does not allow to see their company history, `null` will be returned instead. - */ - vtcHistory: APIPlayerCompanyHistory[] | null; - } - - interface _VTCHistoryHidden extends Pick<_Base, "displayVTCHistory" | "vtcHistory"> { - displayVTCHistory: false; - vtcHistory: null; - } - interface _VTCHistoryPublic extends Pick<_Base, "displayVTCHistory" | "vtcHistory"> { - displayVTCHistory: true; - vtcHistory: APIPlayerCompanyHistory[]; - } - type _VTCHistory = _VTCHistoryHidden | _VTCHistoryPublic; - - interface _BansHidden extends Pick<_Base, "displayBans" | "bansCount"> { - displayBans: false; - bansCount: null; - } - interface _BansPublic extends Pick<_Base, "displayBans" | "bansCount"> { - displayBans: true; - bansCount: number; - } - type _BanData = _BansHidden | _BansPublic; - - export type Player = _Base & _VTCHistory & _BanData; -} diff --git a/web/v2/player/index.ts b/web/v2/player/index.ts new file mode 100644 index 0000000..5d94ea8 --- /dev/null +++ b/web/v2/player/index.ts @@ -0,0 +1,246 @@ +import APIPlayerPatreon from './patreon'; +export { type APIPlayerPatreon }; + +export interface APIPlayerPermissions { + /** + * If the user is a TruckersMP staff member. + */ + isStaff: boolean; + + /** + * If the user is part of upper staff within the TruckersMP team. + */ + isUpperStaff: boolean; + + /** + * If the user has Game Moderator permissions. + */ + isGameAdmin: boolean; +} + +/** + * Information about player's membership in a virtual trucking company. + */ +export type APIPlayerCompanyMember = { + /** + * ID of the company the user belongs to or 0 if not in a company. + */ + id: 0; + + /** + * Name of the company the user belongs to or empty if not in a company. + */ + name: ''; + + /** + * Tag of the company the user belongs to or empty if not in a company. + */ + tag: ''; + + /** + * If the user is in a company. + */ + inVTC: false; + + /** + * Company member ID or 0 if not in a company. + */ + memberID: 0; +} | { + /** + * ID of the company the user belongs to or 0 if not in a company. + */ + id: number; + + /** + * Name of the company the user belongs to or empty if not in a company. + */ + name: string; + + /** + * Tag of the company the user belongs to or empty if not in a company. + */ + tag: string; + + /** + * If the user is in a company. + */ + inVTC: true; + + /** + * Company member ID or 0 if not in a company. + */ + memberID: number; +} + +/** + * Entry with brief information of the company the player was previously in. + */ +export interface APIPlayerCompanyHistory { + /** + * ID of the company. + */ + id: number; + + /** + * Name of the company. + */ + name: string; + + /** + * If the company is verified. + */ + verified: boolean; + + /** + * Date and time the user joined the company (UTC). + */ + joinDate: string; + + /** + * Date and time the user left the company (UTC). + */ + leftDate: string; +} + +/** + * Information about a TruckersMP player. + * @see https://truckersmp.com/developers/api#operation/get-player-id + */ +export type APIPlayer = _Base & _VTCHistory & _BanData; + +// #region APIPlayer + +/** Base interface containing property annotations */ +interface _Base { + /** + * The ID of the requested user. + */ + id: number; + + /** + * The name of the user. + */ + name: string; + + /** + * URL to the avatar used on the website. + */ + avatar: string; + + /** + * URL to the avatar used on the website (32px x 32px). + */ + smallAvatar: string; + + /** + * The date and time the user registered (UTC). + */ + joinDate: string; + + /** + * The SteamID64 of the user. + */ + steamID64: bigint; + + /** + * The SteamID64 of the user. + */ + steamID: string; + + /** + * The Discord account linked to the user or `null` if not linked or private. + */ + discordSnowflake: string | null; + + /** + * If the user's company history is visible. + */ + displayVTCHistory: boolean; + + /** + * The name of the group the user belongs to. + */ + groupName: string; + + /** + * The color of the group. + */ + groupColor: string; + + /** + * The ID of the group the user belongs to. + */ + groupID: number; + + /** + * If the user is currently banned. + */ + banned: boolean; + + /** + * @deprecated + * This field is no longer available and will be returned as `null`. + */ + bannedUntil: null; + + /** + * The number of active bans a user has or `null` if private. + */ + bansCount: number | null; + + /** + * If the user has their bans hidden. + */ + displayBans: boolean; + + /** + * Data of the player's Patreon status. + */ + patreon: APIPlayerPatreon; + + /** + * Permissions that the player has. + */ + permissions: APIPlayerPermissions; + + /** + * Information about player's membership in a virtual trucking company. + */ + vtc: APIPlayerCompanyMember; + + /** + * Entries with brief information of a company the player was in. + * + * If the user does not allow to see their company history, `null` will be returned instead. + */ + vtcHistory: APIPlayerCompanyHistory[] | null; +} + +/** Properties specific to the player resource when VTC information is hidden */ +interface _VTCHistoryHidden extends Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> { + displayVTCHistory: false; + vtcHistory: null; +} + +/** Properties specific to the player resource when VTC information is public */ +interface _VTCHistoryPublic extends Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> { + displayVTCHistory: true; + vtcHistory: APIPlayerCompanyHistory[]; +} +type _VTCHistory = _VTCHistoryHidden | _VTCHistoryPublic; + +/** Properties specific to the player resource when ban information is hidden */ +interface _BansHidden extends Pick<_Base, 'displayBans' | 'bansCount'> { + displayBans: false; + bansCount: null; +} + +/** Properties specific to the player resource when ban information is public */ +interface _BansPublic extends Pick<_Base, 'displayBans' | 'bansCount'> { + displayBans: true; + bansCount: number; +} +type _BanData = _BansHidden | _BansPublic; + +// #endregion APIPlayer diff --git a/web/v2/player/patreon.ts b/web/v2/player/patreon.ts new file mode 100644 index 0000000..2a811e0 --- /dev/null +++ b/web/v2/player/patreon.ts @@ -0,0 +1,90 @@ +/** Base interface containing property annotations */ +interface _Base { + /** + * If the user has donated or is currently donating via Patreon. + */ + isPatron: boolean | null; + + /** + * If the user has an active Patreon subscription. + */ + active: boolean | null; + + /** + * HEX code for subscribed tier. + */ + color: string | null; + + /** + * The tier ID of current pledge. + */ + tierId: number | null; + + /** + * Current pledge in cents. + */ + currentPledge: number | null; + + /** + * Lifetime pledge in cents. + */ + lifetimePledge: number | null; + + /** + * Next pledge in cents. + */ + nextPledge: number | null; + + /** + * If user has their Patreon information hidden. + */ + hidden: boolean | null; +} + +/** Properties specific to the `patreon` field when the information is public (not hidden) */ +interface _VisiblePartial { + lifetimePledge: number | null; + hidden: false | null; +} + +/** Properties specific to the `patreon` field when the user is an inactive patron */ +interface _InactivePartial extends _VisiblePartial { + active: false; + color: null; + tierId: null; + currentPledge: null; + nextPledge: null; +} + +/** Properties specific to the `patreon` field when the user is an active patron */ +interface _ActivePartial extends _VisiblePartial { + active: true; + color: string; + tierId: number; + currentPledge: number; + nextPledge: number | null; +} + +/** `patreon` field when the user has their Patreon information hidden */ +export interface InfoHidden extends _Base { + isPatron: false | null; + active: null; + color: null; + tierId: null; + currentPledge: null; + lifetimePledge: null; + nextPledge: null; + hidden: true; +} + +/** `patreon` field when the user is a patron (active or not) */ +export type Patron = _Base & ({ isPatron: true } & (_InactivePartial | _ActivePartial)); + +/** `patreon` field when the user is not a patron (ie. has never donated) */ +export interface NonPatron extends _InactivePartial { isPatron: false } + +/** + * Information about player's Patreon status. + */ +type APIPlayerPatreon = InfoHidden | NonPatron | Patron; +export default APIPlayerPatreon; From 5c28f32ce09570482d41dffb7140bca7d09eff76 Mon Sep 17 00:00:00 2001 From: Maxim <102874843+maxim-01@users.noreply.github.com> Date: Fri, 26 Apr 2024 20:09:59 +0100 Subject: [PATCH 3/6] Make changes requested in #2 - removed exported `APIPlayerBans` type - removed string from argument types when numeric identifiers are expected - merged types that did not require separation --- web/v2/ban.ts | 2 -- web/v2/index.ts | 24 ++++++++--------- web/v2/player/index.ts | 56 +++++++++++++++++++--------------------- web/v2/player/patreon.ts | 53 ++++++++++++++++++++----------------- 4 files changed, 69 insertions(+), 66 deletions(-) diff --git a/web/v2/ban.ts b/web/v2/ban.ts index 59d7b57..71bd0c7 100644 --- a/web/v2/ban.ts +++ b/web/v2/ban.ts @@ -39,5 +39,3 @@ export interface APIPlayerBan { */ adminID: null; } - -export type APIPlayerBans = APIPlayerBan[]; diff --git a/web/v2/index.ts b/web/v2/index.ts index 4c53ff0..9418ab8 100644 --- a/web/v2/index.ts +++ b/web/v2/index.ts @@ -39,7 +39,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - company(id: string | number) { + company(id: number | string) { return `/vtc/${id}` as const; }, @@ -51,7 +51,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyEvents(companyId: string | number) { + companyEvents(companyId: number | string) { return `/vtc/${companyId}/events` as const; }, @@ -64,7 +64,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyEvent(companyId: string | number, eventId: number | string) { + companyEvent(companyId: number | string, eventId: number) { return `/vtc/${companyId}/events/${eventId}` as const; }, @@ -76,7 +76,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyMembers(companyId: string | number) { + companyMembers(companyId: number | string) { return `/vtc/${companyId}/members` as const; }, @@ -89,7 +89,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyMember(companyId: string | number, memberId: number | string) { + companyMember(companyId: number | string, memberId: number) { return `/vtc/${companyId}/member/${memberId}` as const; }, @@ -101,7 +101,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyNews(companyId: string | number) { + companyNews(companyId: number | string) { return `/vtc/${companyId}/news` as const; }, @@ -114,7 +114,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyNewsEntry(companyId: string | number, newsId: number | string) { + companyNewsEntry(companyId: number | string, newsId: number) { return `/vtc/${companyId}/news/${newsId}` as const; }, @@ -126,7 +126,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyRoles(companyId: string | number) { + companyRoles(companyId: number) { return `/vtc/${companyId}/roles` as const; }, @@ -139,7 +139,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyRole(companyId: string | number, roleId: number | string) { + companyRole(companyId: number | string, roleId: number) { return `/vtc/${companyId}/role/${roleId}` as const; }, @@ -151,7 +151,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - event(id: number | string) { + event(id: number) { return `/events/${id}` as const; }, @@ -173,7 +173,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - eventsUser(id: number | string) { + eventsUser(id: number) { return `/events/user/${id}` as const; }, @@ -185,7 +185,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - player(id: bigint | number | string) { + player(id: bigint | number) { return `/player/${id}` as const; }, diff --git a/web/v2/player/index.ts b/web/v2/player/index.ts index 5d94ea8..343c83d 100644 --- a/web/v2/player/index.ts +++ b/web/v2/player/index.ts @@ -47,7 +47,7 @@ export type APIPlayerCompanyMember = { */ memberID: 0; } | { - /** + /** * ID of the company the user belongs to or 0 if not in a company. */ id: number; @@ -107,7 +107,7 @@ export interface APIPlayerCompanyHistory { * Information about a TruckersMP player. * @see https://truckersmp.com/developers/api#operation/get-player-id */ -export type APIPlayer = _Base & _VTCHistory & _BanData; +export type APIPlayer = _Base & _APIPlayerVTCHistory & _APIPlayerBanData; // #region APIPlayer @@ -179,8 +179,8 @@ interface _Base { banned: boolean; /** - * @deprecated - * This field is no longer available and will be returned as `null`. + * @deprecated - v2.21.1.0 + * This field is no longer provided. */ bannedUntil: null; @@ -217,30 +217,28 @@ interface _Base { vtcHistory: APIPlayerCompanyHistory[] | null; } -/** Properties specific to the player resource when VTC information is hidden */ -interface _VTCHistoryHidden extends Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> { - displayVTCHistory: false; - vtcHistory: null; -} - -/** Properties specific to the player resource when VTC information is public */ -interface _VTCHistoryPublic extends Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> { - displayVTCHistory: true; - vtcHistory: APIPlayerCompanyHistory[]; -} -type _VTCHistory = _VTCHistoryHidden | _VTCHistoryPublic; - -/** Properties specific to the player resource when ban information is hidden */ -interface _BansHidden extends Pick<_Base, 'displayBans' | 'bansCount'> { - displayBans: false; - bansCount: null; -} - -/** Properties specific to the player resource when ban information is public */ -interface _BansPublic extends Pick<_Base, 'displayBans' | 'bansCount'> { - displayBans: true; - bansCount: number; -} -type _BanData = _BansHidden | _BansPublic; +type _APIPlayerVTCHistory = Pick<_Base, 'displayVTCHistory' | 'vtcHistory'> & + ( + | { + displayVTCHistory: false; + vtcHistory: null; + } + | { + displayVTCHistory: true; + vtcHistory: APIPlayerCompanyHistory[]; + } + ); + +type _APIPlayerBanData = Pick<_Base, 'displayBans' | 'bansCount'> & + ( + | { + displayBans: false; + bansCount: null; + } + | { + displayBans: true; + bansCount: number; + } + ); // #endregion APIPlayer diff --git a/web/v2/player/patreon.ts b/web/v2/player/patreon.ts index 2a811e0..53a7fb4 100644 --- a/web/v2/player/patreon.ts +++ b/web/v2/player/patreon.ts @@ -1,5 +1,5 @@ -/** Base interface containing property annotations */ -interface _Base { +/** Base interface containing property type annotations and documentation. */ +interface _APIPlayerPatreonBase { /** * If the user has donated or is currently donating via Patreon. */ @@ -11,7 +11,7 @@ interface _Base { active: boolean | null; /** - * HEX code for subscribed tier. + * Hex code for subscribed tier. */ color: string | null; @@ -41,14 +41,28 @@ interface _Base { hidden: boolean | null; } -/** Properties specific to the `patreon` field when the information is public (not hidden) */ -interface _VisiblePartial { +/** `patreon` field when the user has their Patreon information hidden */ +interface _APIPartialPlayerPatreonPrivate extends _APIPlayerPatreonBase { + isPatron: false | null; + active: null; + color: null; + tierId: null; + currentPledge: null; + lifetimePledge: null; + nextPledge: null; + hidden: true; +} + +// #region Properties specific to the `patreon` field when the information is public + +/** 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 _InactivePartial extends _VisiblePartial { +interface _APIPartialPlayerPatreonInactive extends _APIPartialPlayerPatreonPublicBase { active: false; color: null; tierId: null; @@ -57,7 +71,7 @@ interface _InactivePartial extends _VisiblePartial { } /** Properties specific to the `patreon` field when the user is an active patron */ -interface _ActivePartial extends _VisiblePartial { +interface _APIPartialPlayerPatreonActive extends _APIPartialPlayerPatreonPublicBase { active: true; color: string; tierId: number; @@ -65,26 +79,19 @@ interface _ActivePartial extends _VisiblePartial { nextPledge: number | null; } -/** `patreon` field when the user has their Patreon information hidden */ -export interface InfoHidden extends _Base { - isPatron: false | null; - active: null; - color: null; - tierId: null; - currentPledge: null; - lifetimePledge: null; - nextPledge: null; - hidden: true; -} - -/** `patreon` field when the user is a patron (active or not) */ -export type Patron = _Base & ({ isPatron: true } & (_InactivePartial | _ActivePartial)); +/** `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) */ -export interface NonPatron extends _InactivePartial { isPatron: false } +interface _APIPlayerPatreonNonPatron extends _APIPartialPlayerPatreonInactive { isPatron: false } + +// #endregion /** * Information about player's Patreon status. */ -type APIPlayerPatreon = InfoHidden | NonPatron | Patron; +type APIPlayerPatreon = _APIPartialPlayerPatreonPrivate | _APIPlayerPatreonNonPatron | _APIPlayerPatreonIsPatron; export default APIPlayerPatreon; From c3bfcebffd83b8bf328755b2de440bb3d07598a0 Mon Sep 17 00:00:00 2001 From: Maxim <102874843+maxim-01@users.noreply.github.com> Date: Sun, 28 Apr 2024 01:29:24 +0100 Subject: [PATCH 4/6] Additional general style changes requested in #2 - generalised `as const` where applicable - renamed the base interface for `APIPlayer` to align with `APIPlayerPatreon` --- web/v2/ban.ts | 82 ++++++++++++++++++++-------------------- web/v2/index.ts | 2 +- web/v2/player/index.ts | 22 ++++++----- web/v2/player/patreon.ts | 64 ++++++++++++++++++++----------- 4 files changed, 96 insertions(+), 74 deletions(-) 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 + ); From 66e69c2b9cd2e2961934e53599946c9fa62172d1 Mon Sep 17 00:00:00 2001 From: Maxim <102874843+maxim-01@users.noreply.github.com> Date: Tue, 30 Apr 2024 16:50:58 +0100 Subject: [PATCH 5/6] Fixed missed type in #5c28f32 --- web/v2/index.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/v2/index.ts b/web/v2/index.ts index 510d989..3861f5d 100644 --- a/web/v2/index.ts +++ b/web/v2/index.ts @@ -126,7 +126,7 @@ export const APIWebRoutes = { * * @returns APIResponse */ - companyRoles(companyId: number) { + companyRoles(companyId: number | string) { return `/vtc/${companyId}/roles` as const; }, From 15dd9bf8c71e7c0be8fe8a902e2443a27c562cca Mon Sep 17 00:00:00 2001 From: ShawnCZek Date: Fri, 17 May 2024 19:01:37 +0200 Subject: [PATCH 6/6] Fix line endings for web/v2/ban.ts --- web/v2/ban.ts | 82 +++++++++++++++++++++++++-------------------------- 1 file changed, 41 insertions(+), 41 deletions(-) diff --git a/web/v2/ban.ts b/web/v2/ban.ts index 7544739..71bd0c7 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; +}