erlc-v2 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,381 +1,609 @@
1
- # erlc-v2
2
-
3
- JavaScript client for the ER:LC API v2.
4
-
5
- Built for Node 18+.
6
-
7
- ## Beta Notice
8
-
9
- This wrapper is in beta (`1.0.0-beta.x`) and is not guaranteed to work 100% in all environments or API states.
10
-
11
- ## Responsibility and API Safety
12
-
13
- You are responsible for how you use this wrapper and API key(s). If you use it recklessly (for example, aggressive request spam, ignoring rate limits, or abusive automation) and get rate-limited, blocked, or banned by PRC/Cloudflare, that is on you.
14
-
15
- This project is provided as-is. Always monitor your integration and respect PRC API rules and headers.
16
-
17
- ## Install
18
-
19
- ```bash
20
- npm install erlc-v2
21
- ```
22
-
23
- ## Quick Start (CommonJS)
24
-
25
- ```js
26
- const { Client } = require("erlc-v2");
27
-
28
- const client = new Client({
29
- serverKey: "YOUR_SERVER_KEY",
30
- // globalKey: "YOUR_GLOBAL_KEY", // optional
31
- });
32
-
33
- client.on("disconnect", ({ reason, error }) => {
34
- console.error("Disconnected:", reason, error?.message);
35
- });
36
-
37
- async function main() {
38
- const snapshot = await client.server.fetch({
39
- players: true,
40
- staff: true,
41
- queue: true,
42
- });
43
-
44
- console.log("Server:", snapshot.name);
45
- console.log("Players:", `${snapshot.currentPlayers}/${snapshot.maxPlayers}`);
46
- console.log("Players payload:", snapshot.players.length);
47
- }
48
-
49
- main()
50
- .catch(console.error)
51
- .finally(() => client.destroy());
52
- ```
53
-
54
- ## Quick Start (ESM)
55
-
56
- ```js
57
- import { Client } from "erlc-v2";
58
-
59
- const client = new Client({
60
- serverKey: "YOUR_SERVER_KEY",
61
- });
62
- ```
63
-
64
- ## Options
65
-
66
- ```ts
67
- new Client({
68
- serverKey: string, // required
69
- globalKey?: string, // optional
70
- logging?: boolean, // default: false
71
- logger?: { info, warn, error, debug },
72
- cache?: {
73
- enabled?: boolean, // default: true
74
- ttlMs?: number, // default: 1500
75
- maxSize?: number, // default: 500
76
- provider?: "memory" | "redis", // default: auto (redis if redis config is present)
77
- redisUrl?: string, // optional (requires `npm i redis`)
78
- redisPrefix?: string, // default: "erlc-v2:cache"
79
- redisClient?: object, // optional pre-configured Redis client
80
- },
81
- rateLimit?: {
82
- enabled?: boolean, // default: true
83
- strictSerial?: boolean, // default: true (global one-at-a-time queue)
84
- bucketLimit?: number, // default: 1
85
- totalLimit?: number, // default: 1
86
- unauthLimit?: number, // default: 3
87
- },
88
- polling?: {
89
- enabled?: boolean, // default: true
90
- intervalMs?: number, // default: 2500 (min enforced: 250)
91
- bypassCache?: boolean, // default: true
92
- },
93
- });
94
- ```
95
-
96
- Legacy aliases (`perBucketConcurrency`, `globalConcurrency`, `unauthorizedThreshold`) are still accepted.
97
-
98
- ## Redis Cache (Optional)
99
-
100
- You can use Redis instead of in-memory cache by passing either `cache.redisUrl` or `cache.redisClient`.
101
-
102
- If you use `redisUrl`, install the Redis client package:
103
-
104
- ```bash
105
- npm i redis
106
- ```
107
-
108
- Example with connection URL:
109
-
110
- ```js
111
- const { Client } = require("erlc-v2");
112
-
113
- const client = new Client({
114
- serverKey: "YOUR_SERVER_KEY",
115
- cache: {
116
- provider: "redis",
117
- redisUrl: "redis://localhost:6379",
118
- redisPrefix: "myapp:erlc",
119
- ttlMs: 2000,
120
- },
121
- });
122
- ```
123
-
124
- Example with your own Redis client instance:
125
-
126
- ```js
127
- const { createClient } = require("redis");
128
- const { Client } = require("erlc-v2");
129
-
130
- (async () => {
131
- const redis = createClient({ url: process.env.REDIS_URL });
132
- await redis.connect();
133
-
134
- const client = new Client({
135
- serverKey: "YOUR_SERVER_KEY",
136
- cache: {
137
- redisClient: redis,
138
- redisPrefix: "myapp:erlc",
139
- },
140
- });
141
- })();
142
- ```
143
-
144
- ## API
145
-
146
- Core:
147
-
148
- - `await client.server.fetch(flags, requestOptions?)`
149
- - `client.destroy()`
150
- - `client.cache.clear()`
151
-
152
- Convenience methods:
153
-
154
- - `await client.players.list()`
155
- - `await client.map.render(options?)`
156
- - `await client.map.renderUser(userId, options?)`
157
- - `await client.staff.list()`
158
- - `await client.logs.kills()`
159
- - `await client.logs.joins()`
160
- - `await client.logs.commands()`
161
- - `await client.logs.modCalls()`
162
- - `await client.vehicles.list()`
163
- - `await client.queue.get()`
164
- - `await client.commands.execute(":h Hey everyone!")` (v1 endpoint)
165
-
166
- ### Fetch Flags
167
-
168
- - `players` -> `Players`
169
- - `staff` -> `Staff`
170
- - `joinLogs` -> `JoinLogs`
171
- - `queue` -> `Queue`
172
- - `killLogs` -> `KillLogs`
173
- - `commandLogs` -> `CommandLogs`
174
- - `modCalls` -> `ModCalls`
175
- - `vehicles` -> `Vehicles`
176
-
177
- ### Request Options
178
-
179
- - `bypassCache?: boolean`
180
- - `cacheTtlMs?: number`
181
- - `dedupe?: boolean`
182
-
183
- ### Command Execution (v1)
184
-
185
- `client.commands.execute(command)` sends a POST request to `/v1/server/command`.
186
- Command execution is FIFO-queued client-side, so commands run one-at-a-time in order.
187
-
188
- Blocked by client policy (request will be rejected before hitting the API):
189
-
190
- - `:view`
191
- - `:to`
192
- - `:tocar`
193
- - `:toatv`
194
- - `:logs`
195
- - `:mods`
196
- - `:admins`
197
- - `helpers` / `:helpers`
198
- - `:administrators`
199
- - `:moderators`
200
- - `:killlogs`
201
- - `:kl`
202
- - `:cmds`
203
- - `:commands`
204
-
205
- Example:
206
-
207
- ```js
208
- await client.commands.execute(":h Hey everyone!");
209
- await client.commands.execute(":log recentban He was trolling!");
210
- ```
211
-
212
- ## Map Rendering
213
-
214
- Render an ER:LC map (`3121x3121`) with player markers that use Roblox avatars.
215
-
216
- ```js
217
- const result = await client.map.render();
218
-
219
- // png buffer
220
- console.log(result.buffer);
221
- console.log(result.players.length);
222
- ```
223
-
224
- `client.map.render()` renders the full map with all players currently in the server.
225
-
226
- Render an official season/type map preset:
227
-
228
- ```js
229
- const fallBlank = await client.map.render({
230
- season: "fall",
231
- type: "blank",
232
- });
233
-
234
- const fallPostals = await client.map.render({
235
- season: "fall",
236
- type: "postals",
237
- });
238
-
239
- const winterBlank = await client.map.render({
240
- season: "winter", // alias: "snow"
241
- type: "blank",
242
- });
243
-
244
- const winterPostals = await client.map.render({
245
- season: "winter",
246
- type: "postals",
247
- });
248
- ```
249
-
250
- Use your own map image URL:
251
-
252
- ```js
253
- const customMap = await client.map.render({
254
- mapUrl: "https://example.com/my-map.png", // mainly used in cases where we fail to add the most recent map when its released (sizing should be 3121x3121)
255
- });
256
- ```
257
-
258
- Render only one player by Roblox user ID:
259
-
260
- ```js
261
- const single = await client.map.renderUser(123456789, {
262
- season: "winter",
263
- type: "postals",
264
- });
265
- ```
266
-
267
- Options:
268
-
269
- - `userId?: number | string`
270
- - `userIds?: Array<number | string>`
271
- - `players?: any[]` (use your own pre-fetched player payload)
272
- - `mapUrl?: string` (custom map URL; if set, this overrides `season`/`type`)
273
- - `season?: string` (`"fall"` or `"winter"`/`"snow"` for official presets)
274
- - `type?: string` (`"blank"` or `"postals"` for official presets)
275
- - `mapSeason?: string` (alias of `season`)
276
- - `mapType?: string` (alias of `type`)
277
- - `coordinateBounds?: { minX, maxX, minY, maxY, invertY? }`
278
- - `clampToMap?: boolean` (default: `true`)
279
- - `robloxHeadshotSize?: string` (default: `"150x150"`)
280
- - `marker?: { outerRadius, innerRadius, tipLength, tipWidth, fillColor, shadow }`
281
-
282
- Map size is fixed to `3121x3121`.
283
-
284
- Result shape:
285
-
286
- - `buffer` (`image/png`)
287
- - `map` (`{ url, season, type, width, height }`)
288
- - `players` (rendered marker metadata)
289
- - `skipped` (players skipped because coordinates were unavailable/invalid)
290
- - `requestedUserIds` (IDs requested via `userId` / `userIds`)
291
- - `unmatchedUserIds` (requested IDs not found in current player payload)
292
-
293
- ## Events
294
-
295
- - `ready`
296
- - `playerJoin`
297
- - `playerLeave`
298
- - `kill`
299
- - `vehicleSpawn`
300
- - `vehicleDespawn`
301
- - `queueUpdate`
302
- - `staffUpdate`
303
- - `modCall`
304
- - `commandLog`
305
- - `logCommand` (only when command starts with `:log`)
306
- - `serverUpdate`
307
- - `error`
308
- - `disconnect` (`{ reason, error }`)
309
-
310
- Alias event names are also supported with `client.on(...)`:
311
-
312
- - `onReady`
313
- - `onJoin`
314
- - `onLeave`
315
- - `onKill`
316
- - `onVehicleSpawn`
317
- - `onVehicleDespawn`
318
- - `onQueueUpdate`
319
- - `onStaffUpdate`
320
- - `onModCall`
321
- - `onCommandLog`
322
- - `onLogCommand`
323
- - `onServerUpdate`
324
- - `onError`
325
- - `onDisconnect`
326
-
327
- Shortcut methods are available too:
328
-
329
- ```js
330
- client.onJoin((payload) => console.log("join", payload));
331
- client.onLeave((payload) => console.log("leave", payload));
332
- client.onVehicleSpawn((payload) => console.log("spawn", payload));
333
- client.onLogCommand(({ command, parsed }) => {
334
- console.log("raw command:", command.Command);
335
- console.log("keyword:", parsed.keyword);
336
- console.log("args:", parsed.args);
337
- });
338
- ```
339
-
340
- `logCommand` / `onLogCommand` fires when a command starts with `:log`.
341
-
342
- Events are deduped per poll cycle so the same log entry is not emitted repeatedly.
343
-
344
- ## Rate Limits
345
-
346
- Requests are automatically bucketed using API response headers:
347
-
348
- - `X-RateLimit-Bucket`
349
- - `X-RateLimit-Limit`
350
- - `X-RateLimit-Remaining`
351
- - `X-RateLimit-Reset`
352
-
353
- On `429`, the client blocks the affected bucket until retry time/reset.
354
-
355
- By default, requests are strictly serialized (`strictSerial: true`) so this client does not send parallel requests.
356
- This is intentionally conservative for anti-abuse/rate-limit safety.
357
-
358
- ## Errors
359
-
360
- The client normalizes errors into classes:
361
-
362
- - `ERLCError`
363
- - `ERLCHttpError`
364
- - `ERLCAPIError`
365
- - `RateLimitError`
366
- - `KeyExpiredError` (`2002`)
367
- - `KeyBannedError` (`2004`)
368
- - `InvalidGlobalKeyError` (`2003`)
369
- - `ServerOfflineError` (`3002`)
370
- - `RestrictedError` (`9998`)
371
- - `ModuleOutOfDateError` (`9999`)
372
-
373
- Terminal key errors (`2002`, `2004`) trigger disconnect and stop polling.
374
-
375
- Repeated `403` responses can also trigger disconnect (reason: `"unauthorized"`).
376
-
377
- ## Notes
378
-
379
- - API base URL: `https://api.policeroleplay.community`
380
- - `Server-Key` is required for requests
1
+ # erlc-v2
2
+
3
+ JavaScript client for the ER:LC API v2.
4
+
5
+ Built for Node 18+.
6
+
7
+ Quick note: sorry this update took a while. There is a lot in this version, and I did not have a ton of time to get to it, so it ended up taking longer than I wanted.
8
+
9
+ ## New Features
10
+
11
+ - `client.commands.execute()` now uses `/v2/server/command`
12
+ - emergency calls are supported
13
+ - vehicle lookup helpers are built in
14
+ - you can start a small local API with `api: { port: 3001 }`
15
+ - event webhooks are supported and signature-checked before they fire events
16
+
17
+ ## Stable Release
18
+
19
+ This wrapper is on a stable release track (`1.0.0+`).
20
+
21
+ ## Responsibility and API Safety
22
+
23
+ Use your keys like a normal person. If you spam requests, ignore rate limits, or build dumb abuse tools and PRC or Cloudflare blocks you, that is on you.
24
+
25
+ This project is provided as-is. Keep an eye on your own integration and follow the PRC API rules.
26
+
27
+ ## Install
28
+
29
+ ```bash
30
+ npm install erlc-v2
31
+ ```
32
+
33
+ ## Quick Start (CommonJS)
34
+
35
+ ```js
36
+ const { Client } = require("erlc-v2");
37
+
38
+ const client = new Client({
39
+ serverKey: "YOUR_SERVER_KEY",
40
+ polling: {
41
+ enabled: true,
42
+ },
43
+ });
44
+
45
+ client.on("disconnect", ({ reason, error }) => {
46
+ console.error("Disconnected:", reason, error?.message);
47
+ });
48
+
49
+ async function main() {
50
+ const snapshot = await client.server.fetch({
51
+ players: true,
52
+ staff: true,
53
+ queue: true,
54
+ vehicles: true,
55
+ emergencyCalls: true,
56
+ });
57
+
58
+ console.log("Server:", snapshot.name);
59
+ console.log("Players:", `${snapshot.currentPlayers}/${snapshot.maxPlayers}`);
60
+ console.log("Vehicles:", snapshot.vehicles.length);
61
+ console.log("Emergency calls:", snapshot.emergencyCalls.length);
62
+ }
63
+
64
+ main()
65
+ .catch(console.error)
66
+ .finally(() => client.destroy());
67
+ ```
68
+
69
+ ## Quick Start (ESM)
70
+
71
+ ```js
72
+ import { Client } from "erlc-v2";
73
+
74
+ const client = new Client({
75
+ serverKey: "YOUR_SERVER_KEY",
76
+ });
77
+ ```
78
+
79
+ ## Options
80
+
81
+ ```ts
82
+ new Client({
83
+ serverKey: string, // required
84
+ globalKey?: string, // optional
85
+ logging?: boolean, // default: false
86
+ logger?: { info, warn, error, debug },
87
+ cache?: {
88
+ enabled?: boolean, // default: true
89
+ ttlMs?: number, // default: 1500
90
+ maxSize?: number, // default: 500
91
+ provider?: "memory" | "redis", // default: auto
92
+ redisUrl?: string,
93
+ redisPrefix?: string, // default: "erlc-v2:cache"
94
+ redisClient?: object,
95
+ },
96
+ rateLimit?: {
97
+ enabled?: boolean, // default: true
98
+ strictSerial?: boolean, // default: true
99
+ bucketLimit?: number, // default: 1
100
+ totalLimit?: number, // default: 1
101
+ unauthLimit?: number, // default: 3
102
+ },
103
+ polling?: {
104
+ enabled?: boolean, // default: true
105
+ intervalMs?: number, // default: 2500
106
+ bypassCache?: boolean, // default: true
107
+ },
108
+ api?: {
109
+ enabled?: boolean, // default: false unless port is set
110
+ host?: string, // default: "127.0.0.1"
111
+ port?: number, // required if you want the local API server
112
+ path?: string, // default: "/erlc"
113
+ webhookPath?: string, // default: `${path}/events`
114
+ publicUrl?: string, // optional, used to build webhookUrl in client.api.info()
115
+ token?: string, // optional bearer token for built-in routes
116
+ logRequests?: boolean, // default: true, logs route/webhook hits to the console
117
+ },
118
+ });
119
+ ```
120
+
121
+ Legacy aliases (`perBucketConcurrency`, `globalConcurrency`, `unauthorizedThreshold`) are still accepted.
122
+
123
+ ## Redis Cache (Optional)
124
+
125
+ You can use Redis instead of in-memory cache by passing either `cache.redisUrl` or `cache.redisClient`.
126
+
127
+ If you use `redisUrl`, install the Redis client package:
128
+
129
+ ```bash
130
+ npm i redis
131
+ ```
132
+
133
+ Example with connection URL:
134
+
135
+ ```js
136
+ const { Client } = require("erlc-v2");
137
+
138
+ const client = new Client({
139
+ serverKey: "YOUR_SERVER_KEY",
140
+ cache: {
141
+ provider: "redis",
142
+ redisUrl: "redis://localhost:6379",
143
+ redisPrefix: "myapp:erlc",
144
+ ttlMs: 2000,
145
+ },
146
+ });
147
+ ```
148
+
149
+ Example with your own Redis client instance:
150
+
151
+ ```js
152
+ const { createClient } = require("redis");
153
+ const { Client } = require("erlc-v2");
154
+
155
+ (async () => {
156
+ const redis = createClient({ url: process.env.REDIS_URL });
157
+ await redis.connect();
158
+
159
+ const client = new Client({
160
+ serverKey: "YOUR_SERVER_KEY",
161
+ cache: {
162
+ redisClient: redis,
163
+ redisPrefix: "myapp:erlc",
164
+ },
165
+ });
166
+ })();
167
+ ```
168
+
169
+ ## API
170
+
171
+ Core:
172
+
173
+ - `await client.server.fetch(flags, requestOptions?)`
174
+ - `await client.commands.execute(command)`
175
+ - `client.destroy()`
176
+ - `client.cache.clear()`
177
+
178
+ Convenience methods:
179
+
180
+ - `await client.players.list()`
181
+ - `await client.map.render(options?)`
182
+ - `await client.map.renderUser(userId, options?)`
183
+ - `await client.staff.list()`
184
+ - `await client.logs.kills()`
185
+ - `await client.logs.joins()`
186
+ - `await client.logs.commands()`
187
+ - `await client.logs.modCalls()`
188
+ - `await client.logs.emergencyCalls()`
189
+ - `await client.vehicles.list()`
190
+ - `await client.vehicles.search(filters)`
191
+ - `await client.vehicles.findByPlate(plate)`
192
+ - `await client.vehicles.findByOwner(owner)`
193
+ - `await client.vehicles.findOne(filters)`
194
+ - `await client.queue.get()`
195
+
196
+ ### Fetch Flags
197
+
198
+ - `players` -> `Players`
199
+ - `staff` -> `Staff`
200
+ - `joinLogs` -> `JoinLogs`
201
+ - `queue` -> `Queue`
202
+ - `killLogs` -> `KillLogs`
203
+ - `commandLogs` -> `CommandLogs`
204
+ - `modCalls` -> `ModCalls`
205
+ - `emergencyCalls` -> `EmergencyCalls`
206
+ - `vehicles` -> `Vehicles`
207
+
208
+ ### Request Options
209
+
210
+ - `bypassCache?: boolean`
211
+ - `cacheTtlMs?: number`
212
+ - `dedupe?: boolean`
213
+
214
+ ## Vehicle Search Helpers
215
+
216
+ Find one exact plate:
217
+
218
+ ```js
219
+ const car = await client.vehicles.findByPlate("LINCOLN7");
220
+
221
+ if (car) {
222
+ console.log(car.Owner, car.Name, car.Plate);
223
+ }
224
+ ```
225
+
226
+ Search across plate, owner, name, color, and texture:
227
+
228
+ ```js
229
+ const matches = await client.vehicles.search({
230
+ query: "lincoln",
231
+ });
232
+
233
+ const ownerCars = await client.vehicles.findByOwner("lando");
234
+
235
+ const blackTahoes = await client.vehicles.search({
236
+ name: "tahoe",
237
+ color: "black",
238
+ });
239
+ ```
240
+
241
+ Exact matching is supported too:
242
+
243
+ ```js
244
+ const exact = await client.vehicles.findOne({
245
+ plate: "A12BCD",
246
+ owner: "SomePlayer",
247
+ exact: true,
248
+ });
249
+ ```
250
+
251
+ ## Emergency Calls
252
+
253
+ ```js
254
+ const calls = await client.logs.emergencyCalls();
255
+
256
+ for (const call of calls) {
257
+ console.log(call.CallNumber, call.Team, call.Description);
258
+ }
259
+
260
+ client.on("emergencyCall", ({ emergencyCall }) => {
261
+ console.log("New emergency call:", emergencyCall.Description);
262
+ });
263
+ ```
264
+
265
+ ## Command Execution
266
+
267
+ `client.commands.execute(command)` sends a POST request to `/v2/server/command`.
268
+ Command execution is FIFO-queued client-side, so commands run one-at-a-time in order.
269
+
270
+ Blocked by client policy:
271
+
272
+ - `:view`
273
+ - `:to`
274
+ - `:tocar`
275
+ - `:toatv`
276
+ - `:logs`
277
+ - `:mods`
278
+ - `:admins`
279
+ - `helpers` / `:helpers`
280
+ - `:administrators`
281
+ - `:moderators`
282
+ - `:killlogs`
283
+ - `:kl`
284
+ - `:cmds`
285
+ - `:commands`
286
+
287
+ Example:
288
+
289
+ ```js
290
+ const result = await client.commands.execute(":h Hey everyone!");
291
+ console.log(result.message);
292
+ ```
293
+
294
+ ## Built-in Local API Server
295
+
296
+ If you want the wrapper to expose a small HTTP server, it can do that too.
297
+
298
+ ```js
299
+ const client = new Client({
300
+ serverKey: process.env.ERLC_SERVER_KEY,
301
+ api: {
302
+ port: 3001,
303
+ host: "127.0.0.1",
304
+ path: "/erlc",
305
+ publicUrl: "https://hooks.example.com",
306
+ token: process.env.ERLC_LOCAL_API_TOKEN,
307
+ },
308
+ });
309
+
310
+ client.api.info();
311
+ ```
312
+
313
+ If `api.port` is set, the local API auto-starts with the client. You can also call `await client.api.start()` yourself.
314
+
315
+ By default it logs incoming route hits and verified webhook payloads to the console.
316
+
317
+ If you want to react to ER:LC webhooks in your own code, use:
318
+
319
+ - `client.onWebhook(...)`
320
+ - `client.onWebhookCommand(...)`
321
+ - `client.onWebhookEmergencyCall(...)`
322
+
323
+ Those only fire after the webhook signature checks out.
324
+
325
+ Built-in routes:
326
+
327
+ - `GET /erlc`
328
+ - `GET /erlc/health`
329
+ - `GET /erlc/server`
330
+ - `GET /erlc/players`
331
+ - `GET /erlc/vehicles`
332
+ - `GET /erlc/vehicles/:plate`
333
+ - `GET /erlc/emergency-calls`
334
+ - `POST /erlc/command`
335
+ - `POST /erlc/events`
336
+
337
+ `/erlc/vehicles` accepts query params like `search`, `plate`, `owner`, `name`, `color`, `texture`, `exact`, and `limit`.
338
+
339
+ If you set `api.token`, send either:
340
+
341
+ - `Authorization: Bearer YOUR_TOKEN`
342
+ - `X-API-Token: YOUR_TOKEN`
343
+
344
+ ## Event Webhook Support
345
+
346
+ The built-in API can take ER:LC event webhooks and verify the signatures for you.
347
+
348
+ ```js
349
+ const client = new Client({
350
+ serverKey: process.env.ERLC_SERVER_KEY,
351
+ api: {
352
+ port: 3001,
353
+ publicUrl: "https://hooks.example.com",
354
+ },
355
+ });
356
+
357
+ client.onWebhook((payload) => {
358
+ console.log("Webhook type:", payload.type);
359
+ console.log("Event name:", payload.event);
360
+ });
361
+
362
+ client.onWebhookCommand((payload) => {
363
+ console.log("Command:", payload.command);
364
+ console.log("Args:", payload.args);
365
+ console.log("Origin:", payload.origin);
366
+ // react to in-game ; commands here
367
+ });
368
+
369
+ client.onWebhookEmergencyCall((payload) => {
370
+ console.log("Event:", payload.event);
371
+ console.log("Origin:", payload.origin);
372
+ console.log("Data:", payload.data);
373
+ // react to emergency calls here
374
+ });
375
+ ```
376
+
377
+ Useful flattened webhook fields:
378
+
379
+ - `payload.type`
380
+ - `payload.event`
381
+ - `payload.origin`
382
+ - `payload.server`
383
+ - `payload.eventTimestamp`
384
+ - `payload.data`
385
+ - `payload.command`
386
+ - `payload.args`
387
+ - `payload.argument`
388
+ - `payload.entry`
389
+ - `payload.events`
390
+
391
+ For in-game custom commands, `onWebhookCommand(...)` is usually the one you want. Most of the time `payload.command`, `payload.args`, and `payload.origin` are enough.
392
+
393
+ If your public URL is `https://hooks.example.com` and your API path is the default, set this in your ER:LC server settings:
394
+
395
+ ```txt
396
+ https://hooks.example.com/erlc/events
397
+ ```
398
+
399
+ If you want the longer request shape with type information, use:
400
+
401
+ ```txt
402
+ https://hooks.example.com/erlc/events?long=true
403
+ ```
404
+
405
+ ## Domain, Hosting, and Reverse Proxy Notes
406
+
407
+ The event webhook has to hit a public HTTPS URL. A local port by itself is not enough.
408
+
409
+ Important:
410
+
411
+ - Most Discord bot hosts are bad for this because they do not let you expose your own API cleanly.
412
+ - If your host does not allow inbound HTTP traffic, PRC will never reach your webhook.
413
+ - You need something public in front of your wrapper.
414
+
415
+ Common setups:
416
+
417
+ - Buy a domain and point it at a VPS.
418
+ - Run the wrapper on a VPS and put NGINX or Caddy in front of it.
419
+ - Run it somewhere private and use Cloudflare Tunnel.
420
+
421
+ Common places people use for domains:
422
+
423
+ - Cloudflare Registrar: `https://www.cloudflare.com/products/registrar/`
424
+ - Namecheap: `https://www.namecheap.com/`
425
+ - Porkbun: `https://porkbun.com/`
426
+
427
+ Common places people use for public hosting or a VPS:
428
+
429
+ - DigitalOcean: `https://www.digitalocean.com/`
430
+ - Hetzner: `https://www.hetzner.com/`
431
+ - Railway: `https://railway.com/`
432
+ - Render: `https://render.com/`
433
+ - Fly.io: `https://fly.io/`
434
+
435
+ Common reverse proxy or edge options:
436
+
437
+ - NGINX: `https://nginx.org/`
438
+ - Caddy: `https://caddyserver.com/`
439
+ - Cloudflare Tunnel: `https://www.cloudflare.com/products/tunnel/`
440
+
441
+ Those are just examples. Use whatever actually gives you inbound HTTPS and a process you control.
442
+
443
+ ## Map Rendering
444
+
445
+ Render an ER:LC map (`3121x3121`) with player markers that use Roblox avatars.
446
+
447
+ ```js
448
+ const result = await client.map.render();
449
+
450
+ console.log(result.buffer);
451
+ console.log(result.players.length);
452
+ ```
453
+
454
+ `client.map.render()` renders the full map with all players currently in the server.
455
+
456
+ Render an official season/type map preset:
457
+
458
+ ```js
459
+ const fallBlank = await client.map.render({
460
+ season: "fall",
461
+ type: "blank",
462
+ });
463
+
464
+ const winterPostals = await client.map.render({
465
+ season: "winter",
466
+ type: "postals",
467
+ });
468
+ ```
469
+
470
+ Use your own map image URL:
471
+
472
+ ```js
473
+ const customMap = await client.map.render({
474
+ mapUrl: "https://example.com/my-map.png",
475
+ });
476
+ ```
477
+
478
+ Render only one player by Roblox user ID:
479
+
480
+ ```js
481
+ const single = await client.map.renderUser(123456789, {
482
+ season: "winter",
483
+ type: "postals",
484
+ });
485
+ ```
486
+
487
+ Options:
488
+
489
+ - `userId?: number | string`
490
+ - `userIds?: Array<number | string>`
491
+ - `players?: any[]`
492
+ - `mapUrl?: string`
493
+ - `season?: string`
494
+ - `type?: string`
495
+ - `mapSeason?: string`
496
+ - `mapType?: string`
497
+ - `coordinateBounds?: { minX, maxX, minY, maxY, invertY? }`
498
+ - `clampToMap?: boolean`
499
+ - `robloxHeadshotSize?: string`
500
+ - `marker?: { outerRadius, innerRadius, tipLength, tipWidth, fillColor, shadow }`
501
+
502
+ Map size is fixed to `3121x3121`.
503
+
504
+ Result shape:
505
+
506
+ - `buffer` (`image/png`)
507
+ - `map` (`{ url, season, type, width, height }`)
508
+ - `players`
509
+ - `skipped`
510
+ - `requestedUserIds`
511
+ - `unmatchedUserIds`
512
+
513
+ ## Events
514
+
515
+ - `ready`
516
+ - `playerJoin`
517
+ - `playerLeave`
518
+ - `kill`
519
+ - `vehicleSpawn`
520
+ - `vehicleDespawn`
521
+ - `queueUpdate`
522
+ - `staffUpdate`
523
+ - `modCall`
524
+ - `emergencyCall`
525
+ - `commandLog`
526
+ - `logCommand`
527
+ - `serverUpdate`
528
+ - `webhook`
529
+ - `webhookCommand`
530
+ - `webhookEmergencyCall`
531
+ - `error`
532
+ - `disconnect`
533
+
534
+ Alias event names are also supported with `client.on(...)`:
535
+
536
+ - `onReady`
537
+ - `onJoin`
538
+ - `onLeave`
539
+ - `onKill`
540
+ - `onVehicleSpawn`
541
+ - `onVehicleDespawn`
542
+ - `onQueueUpdate`
543
+ - `onStaffUpdate`
544
+ - `onModCall`
545
+ - `onEmergencyCall`
546
+ - `onCommandLog`
547
+ - `onLogCommand`
548
+ - `onServerUpdate`
549
+ - `onApiRequest`
550
+ - `onWebhook`
551
+ - `onWebhookCommand`
552
+ - `onWebhookEmergencyCall`
553
+ - `onError`
554
+ - `onDisconnect`
555
+
556
+ Shortcut methods are available too:
557
+
558
+ ```js
559
+ client.onJoin((payload) => console.log("join", payload));
560
+ client.onLeave((payload) => console.log("leave", payload));
561
+ client.onVehicleSpawn((payload) => console.log("spawn", payload));
562
+ client.onLogCommand(({ command, parsed }) => {
563
+ console.log("raw command:", command.Command);
564
+ console.log("keyword:", parsed.keyword);
565
+ console.log("args:", parsed.args);
566
+ });
567
+ ```
568
+
569
+ `logCommand` / `onLogCommand` fires when a command starts with `:log`.
570
+
571
+ Events are deduped per poll cycle so the same log entry is not emitted repeatedly.
572
+
573
+ ## Rate Limits
574
+
575
+ Requests are automatically bucketed using API response headers:
576
+
577
+ - `X-RateLimit-Bucket`
578
+ - `X-RateLimit-Limit`
579
+ - `X-RateLimit-Remaining`
580
+ - `X-RateLimit-Reset`
581
+
582
+ On `429`, the client blocks the affected bucket until retry time or reset.
583
+
584
+ By default, requests are serialized (`strictSerial: true`) so this client does not spray parallel requests at the API.
585
+
586
+ ## Errors
587
+
588
+ The client normalizes errors into classes:
589
+
590
+ - `ERLCError`
591
+ - `ERLCHttpError`
592
+ - `ERLCAPIError`
593
+ - `RateLimitError`
594
+ - `KeyExpiredError` (`2002`)
595
+ - `KeyBannedError` (`2004`)
596
+ - `InvalidGlobalKeyError` (`2003`)
597
+ - `ServerOfflineError` (`3002`)
598
+ - `RestrictedError` (`9998`)
599
+ - `ModuleOutOfDateError` (`9999`)
600
+
601
+ Terminal key errors (`2002`, `2004`) trigger disconnect and stop polling.
602
+
603
+ Repeated `403` responses can also trigger disconnect (`reason: "unauthorized"`).
604
+
605
+ ## Notes
606
+
607
+ - API base URL: `https://api.policeroleplay.community`
608
+ - `server-key` is required for requests
381
609
  - `Authorization` is optional (`globalKey`)