npm package: @korabi-dev/erlc-api
Description: Unofficial ER:LC API wrapper for Node.js/TypeScript
Author: Korabi
Latest version: 1.0.0

# ERLC API

This project provides an ER:LC API Wrapper built with TypeScript. Below are the main details and usage instructions.

## Getting Started

### Prerequisites
- [Node.js](https://nodejs.org/) or [Bun](https://bun.sh/)
- npm or bun (for package management)


## Usage

### TypeScript
```typescript
import ErlcClient from '@korabi-dev/erlc-api';

const client = new ErlcClient({ serverKey: 'YOUR_SERVER_KEY' });

// Fetch server status
const status = await client.fetchServerStatus();
if (!status.error) {
	console.log('Server status:', status.data);
}

// Fetch all players
const players = await client.fetchPlayers();
if (!players.error) {
	console.log('Players:', players.data);
}

// Send a message to the server
const result = await client.sendMessage('Hello, ER:LC!');
if (result.error) {
	console.error('Failed to send message:', result.message);
}
```

### JavaScript (CommonJS)
```javascript
const ErlcClient = require('@korabi-dev/erlc-api').default;

const client = new ErlcClient({ serverKey: 'YOUR_SERVER_KEY' });

(async () => {
	// Fetch server status
	const status = await client.fetchServerStatus();
	if (!status.error) {
		console.log('Server status:', status.data);
	}

	// Fetch all players
	const players = await client.fetchPlayers();
	if (!players.error) {
		console.log('Players:', players.data);
	}

	// Send a message to the server
	const result = await client.sendMessage('Hello, ER:LC!');
	if (result.error) {
		console.error('Failed to send message:', result.message);
	}
})();
```

## API Reference

All methods are asynchronous and return an object with at least:
- `error`: boolean
- `message`: string (if error)
- `data`: varies by method

### Methods

#### fetchServerStatus()
Returns server status info:
```ts
{
	error: boolean,
	message?: string,
	data?: {
		Name: string,
		OwnerId: number,
		CoOwnerIds: number[],
		CurrentPlayers: number,
		MaxPlayers: number,
		JoinKey: string,
		AccVerifiedReq: "Disabled" | "Email" | "Phone/ID",
		TeamBalance: boolean
	}
}
```

#### fetchPlayers()
Returns array of players:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{
		UserId: number,
		Username: string,
		Permission: "Normal" | "Server Administrator" | "Server Owner" | "Server Moderator",
		Callsign?: string,
		Team: string
	}>
}
```

#### fetchJoinLogs()
Returns array of join logs:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{
		Join: boolean, // this indicates a join or leave event, Join=true means the user joined, Join=false means the user left
		Timestamp: number,
		Username: string,
		UserId: number
	}>
}
```

#### fetchPlayerQueue()
Returns array of user IDs in queue:
```ts
{
	error: boolean,
	message?: string,
	data?: Number[] // this is an array of roblox userIDs
}
```

#### fetchKillLogs()
Returns array of kill logs:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{
		KillerUsername: string,
		KillerUserId: number,
		VictimUsername: string,
		VictimUserId: number,
		Timestamp: number
	}>
}
```

#### fetchCommandLogs()
Returns array of command logs:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{
		Username: string,
		UserId: number,
		Command: string,
		Timestamp: number
	}>
}
```

#### fetchModCalls()
Returns array of mod calls:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{
		CallerUsername: string,
		CallerUserId: number,
		ModeratorUsername?: string,
		ModeratorUserId?: number,
		Timestamp: number
	}>
}
```

#### fetchBans()
Returns array of banned player IDs:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{ PlayerId: string }>
}
```

#### fetchSpawnedVehicles()
Returns array of vehicles:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{ Name: string, Texture: string, Owner: string }>
}
```

#### fetchStaff()
Returns array of staff players:
```ts
{
	error: boolean,
	message?: string,
	data?: Array<{ UserId: number, Username: string, Permission: string }>
}
```

#### fetchFilteredModCalls(options)
Returns filtered mod calls (see `fetchModCalls` for structure).

#### fetchFilteredKillLogs(options)
Returns filtered kill logs (see `fetchKillLogs` for structure).

#### fetchFilteredJoinLogs(options)
Returns filtered join logs (see `fetchJoinLogs` for structure).

#### fetchFilteredCommandLogs(options)
Returns filtered command logs (see `fetchCommandLogs` for structure).

#### fetchPlayer(options)
Returns a single player object (see `fetchPlayers` for structure).

#### isBanned(userId)
Returns banned status:
```ts
{
	error: boolean,
	message?: string,
	data?: { banned: boolean }
}
```

#### sendMessage(message)
Sends a message to the server. Returns error/message only.

#### sendHint(message)
Sends a hint to the server. Returns error/message only.

#### banPlayer(options)
Ban a player by userid or username. Returns error/message only.

#### kickPlayer(options)
Kick a player by userid or username. Returns error/message only.

### Options Objects

Some methods accept an `options` object to filter or specify parameters. Here are the details for each:

#### fetchFilteredModCalls(options)
`options` can include:
- `timeframe` (number, ms): Only calls within this time window (from now)
- `modid` (number): Moderator's user ID
- `modusername` (string): Moderator's username
- `callerid` (string): Caller user ID
- `callerusername` (string): Caller username
At least one must be provided.

#### fetchFilteredKillLogs(options)
`options` can include:
- `timeframe` (number, ms): Only logs within this time window
- `killerid` (number): Killer's user ID
- `killerusername` (string): Killer's username
- `victimid` (number): Victim's user ID
- `victimusername` (string): Victim's username
At least one must be provided.

#### fetchFilteredJoinLogs(options)
`options` can include:
- `timeframe` (number, ms): Only logs within this time window
- `userid` (number): User ID
- `username` (string): Username
At least one must be provided.

#### fetchFilteredCommandLogs(options)
`options` can include:
- `timeframe` (number, ms): Only logs within this time window
- `userid` (number): User ID
- `username` (string): Username
At least one must be provided.

#### fetchPlayer(options)
`options` must include either:
- `userid` (number): User ID
- `username` (string): Username
Only one should be provided.

#### banPlayer(options)
`options` must include:
- `userid` (number): User ID, or
- `username` (string): Username
Only one should be provided.
- `reason` (string): Reason for ban (required)
- `strict` (boolean): If true, checks if ban succeeded (optional)

#### kickPlayer(options)
`options` must include:
- `userid` (number): User ID, or
- `username` (string): Username
Only one should be provided.
- `reason` (string): Reason for kick (required)
- `strict` (boolean): If true, checks if kick succeeded (optional)