Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reflect recent API changes in event and player endpoints #2

Merged
merged 6 commits into from
May 17, 2024
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
2 changes: 1 addition & 1 deletion traffic/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { APITrafficServerGameName } from './server';
export * from './server';
export * from './traffic';

export const APITrafficVersion = '2';
export const APITrafficVersion = '2' as const;
maxim-01 marked this conversation as resolved.
Show resolved Hide resolved

export const APITrafficRoutes = {
/**
Expand Down
38 changes: 26 additions & 12 deletions traffic/v2/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
58 changes: 41 additions & 17 deletions traffic/v2/traffic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ 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.
Expand Down Expand Up @@ -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<APITrafficServer, 'urls'>;
/**
* Basic information of a TruckersMP server.
* @see https://truckersmp.com/developers/api#operation/get-servers
*/
server: Omit<APITrafficServer, 'urls'>;

/**
* 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;
};
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"skipLibCheck": true,
"sourceMap": true,
"declaration": true,
"declarationMap": true
"declarationMap": true,
"strictNullChecks": true
},
"exclude": ["./node_modules"]
}
12 changes: 8 additions & 4 deletions web/v2/ban.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,16 @@ 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;
}
12 changes: 10 additions & 2 deletions web/v2/event.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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).
*/
Expand Down Expand Up @@ -298,8 +303,11 @@ export interface APIGameEvent {

/**
* The event's required DLCs.
*
* - Empty array when no DLCs are required;
* - Record<string, string> when DLCs are required, where the key is the Steam app ID and value is the DLC's name.
*/
dlcs: Record<string, string>;
dlcs: Record<string, string> | [];

/**
* The relative URL to the event page.
Expand Down
24 changes: 12 additions & 12 deletions web/v2/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
/**
Expand All @@ -17,7 +17,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APIBan[]>
*/
bans(id: bigint) {
bans(id: bigint | string) {
return `/bans/${id}` as const;
},

Expand All @@ -39,7 +39,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompany>
*/
company(id: string | number) {
company(id: number | string) {
return `/vtc/${id}` as const;
},

Expand All @@ -51,7 +51,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APIGameEventSimple[]>
*/
companyEvents(companyId: string | number) {
companyEvents(companyId: number | string) {
return `/vtc/${companyId}/events` as const;
},

Expand All @@ -64,7 +64,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APIGameEvent>
*/
companyEvent(companyId: string | number, eventId: number) {
companyEvent(companyId: number | string, eventId: number) {
return `/vtc/${companyId}/events/${eventId}` as const;
},

Expand All @@ -76,7 +76,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompanyMembers>
*/
companyMembers(companyId: string | number) {
companyMembers(companyId: number | string) {
return `/vtc/${companyId}/members` as const;
},

Expand All @@ -89,7 +89,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompanyMember>
*/
companyMember(companyId: string | number, memberId: number) {
companyMember(companyId: number | string, memberId: number) {
return `/vtc/${companyId}/member/${memberId}` as const;
},

Expand All @@ -101,7 +101,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompanyNews>
*/
companyNews(companyId: string | number) {
companyNews(companyId: number | string) {
return `/vtc/${companyId}/news` as const;
},

Expand All @@ -114,7 +114,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompanyNewsEntry>
*/
companyNewsEntry(companyId: string | number, newsId: number) {
companyNewsEntry(companyId: number | string, newsId: number) {
return `/vtc/${companyId}/news/${newsId}` as const;
},

Expand All @@ -126,7 +126,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompanyRoles>
*/
companyRoles(companyId: string | number) {
companyRoles(companyId: number | string) {
return `/vtc/${companyId}/roles` as const;
},

Expand All @@ -139,7 +139,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APICompanyRoleEntry>
*/
companyRole(companyId: string | number, roleId: number) {
companyRole(companyId: number | string, roleId: number) {
return `/vtc/${companyId}/role/${roleId}` as const;
},

Expand Down Expand Up @@ -185,7 +185,7 @@ export const APIWebRoutes = {
*
* @returns APIResponse<APIPlayer>
*/
player(id: bigint) {
player(id: bigint | number) {
return `/player/${id}` as const;
},

Expand Down
Loading
Loading