erlc-v2 1.1.0 → 1.1.1

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