@screepts/screeps-api 1.0.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.
@@ -0,0 +1,1147 @@
1
+ import { EventEmitter } from "eventemitter3";
2
+
3
+ //#region src/RawAPI.d.ts
4
+ interface RawOpts extends URL {
5
+ url: string | URL;
6
+ path: string;
7
+ token: string;
8
+ }
9
+ declare class RawAPI extends EventEmitter<{
10
+ token: [token: string];
11
+ auth: [];
12
+ rateLimit: [ReturnType<typeof RawAPI.prototype.buildRateLimit>];
13
+ response: [Response];
14
+ }> {
15
+ opts: {
16
+ url: string;
17
+ host?: string;
18
+ port?: string;
19
+ pathname?: string;
20
+ email?: string;
21
+ password?: string;
22
+ experimentalRetry429?: boolean;
23
+ } & AdditonalKeys;
24
+ token?: string;
25
+ private __authed;
26
+ constructor(opts?: Partial<RawOpts>);
27
+ readonly raw: {
28
+ token: string | undefined;
29
+ /**
30
+ * GET /api/version
31
+ */
32
+ version: () => Res<{
33
+ package: number;
34
+ protocol: number;
35
+ serverData: AtLeast<{
36
+ customObjectTypes: object;
37
+ historyChunkSize: number;
38
+ features: AtLeast<{
39
+ name: string;
40
+ version: number;
41
+ }>[];
42
+ shards: string[];
43
+ }>;
44
+ users: number;
45
+ } & Partial<{
46
+ currentSeason: string | undefined;
47
+ seasonAccessCost: string | undefined;
48
+ decorationConvertationCost: number | undefined;
49
+ decorationPixelizationCost: number | undefined;
50
+ }>>;
51
+ /**
52
+ * GET /api/authmod
53
+ */
54
+ authmod: () => Res<{
55
+ name: string;
56
+ version?: any;
57
+ }>;
58
+ /**
59
+ * Official:
60
+ * GET /room-history/${shard}/${room}/${tick}.json
61
+ * Private:
62
+ * GET /room-history
63
+ */
64
+ history: (room: string, tick: number, shard?: string) => Promise<{
65
+ /** milliseconds since the Unix epoch */timestamp: number;
66
+ room: string;
67
+ base: number;
68
+ ticks: {
69
+ [time: string]: AdditonalKeys;
70
+ };
71
+ }>;
72
+ servers: {
73
+ /**
74
+ * POST /api/servers/list
75
+ * A list of community servers
76
+ */
77
+ list: () => Res<{
78
+ servers: {
79
+ _id: string;
80
+ settings: {
81
+ host: string;
82
+ port: string;
83
+ pass: string;
84
+ };
85
+ name: string;
86
+ status: string;
87
+ likeCount: number;
88
+ }[];
89
+ }>;
90
+ };
91
+ auth: {
92
+ /**
93
+ * POST /api/auth/signin
94
+ */
95
+ signin: (email: string, password: string) => Res<{
96
+ token: string;
97
+ }>;
98
+ /**
99
+ * POST /api/auth/steam-ticket
100
+ */
101
+ steamTicket: (ticket: any, useNativeAuth?: boolean) => UndocumentedRes;
102
+ /**
103
+ * GET /api/auth/me
104
+ */
105
+ me: () => Res<Me>;
106
+ /**
107
+ * GET /api/auth/query-token
108
+ */
109
+ queryToken: (token: string) => UndocumentedRes;
110
+ };
111
+ register: {
112
+ /**
113
+ * GET /api/register/check-email
114
+ */
115
+ checkEmail: (email: string) => UndocumentedRes;
116
+ /**
117
+ * GET /api/register/check-username
118
+ */
119
+ checkUsername: (username: string) => UndocumentedRes;
120
+ /**
121
+ * POST /api/register/set-username
122
+ */
123
+ setUsername: (username: string) => UndocumentedRes;
124
+ /**
125
+ * POST /api/register/submit
126
+ */
127
+ submit: (username: string, email: string, password: string, modules: any) => UndocumentedRes;
128
+ };
129
+ userMessages: {
130
+ /**
131
+ * GET /api/user/messages/list?respondent={userId}
132
+ * @param respondent the long `_id` of the user, not the username
133
+ */
134
+ list: (respondent: string) => Res<{
135
+ messages: {
136
+ _id: string;
137
+ date: string;
138
+ type: string;
139
+ text: string;
140
+ unread: boolean;
141
+ }[];
142
+ }>;
143
+ /**
144
+ * GET /api/user/messages/index
145
+ */
146
+ index: () => Res<{
147
+ messages: {
148
+ _id: string;
149
+ message: {
150
+ _id: string;
151
+ user: string;
152
+ respondent: string;
153
+ date: string;
154
+ type: string;
155
+ text: string;
156
+ unread: boolean;
157
+ };
158
+ }[];
159
+ users: {
160
+ [userId: string]: {
161
+ _id: string;
162
+ username: string;
163
+ badge: Badge;
164
+ };
165
+ };
166
+ }>;
167
+ /**
168
+ * GET /api/user/messages/unread-count
169
+ */
170
+ unreadCount: () => Res<{
171
+ count: number;
172
+ }>;
173
+ /**
174
+ * POST /api/user/messages/send
175
+ * @param respondent the long `_id` of the user, not the username
176
+ */
177
+ send: (respondent: string, text: string) => Res<{}>;
178
+ /**
179
+ * POST /api/user/messages/mark-read
180
+ */
181
+ markRead: (id: string) => UndocumentedRes;
182
+ };
183
+ game: {
184
+ /**
185
+ * @param rooms An array of room names
186
+ * The return type is not mapped correctly
187
+ */
188
+ mapStats: (rooms: string[], statName: "owner0" | "claim0" | StatKey, shard?: string) => Res<{
189
+ stats: {
190
+ [roomName: string]: {
191
+ status: string;
192
+ novice: string;
193
+ own: {
194
+ user: string;
195
+ level: number;
196
+ };
197
+ } & { [key in StatKey]: {
198
+ user: string;
199
+ value: number;
200
+ }[] };
201
+ };
202
+ users: {
203
+ [userId: string]: {
204
+ _id: string;
205
+ username: string;
206
+ badge: Badge;
207
+ };
208
+ };
209
+ }>;
210
+ /**
211
+ * POST /api/game/gen-unique-object-name
212
+ */
213
+ genUniqueObjectName: (type: "flag" | "spawn", shard?: string) => Res<{
214
+ name: string;
215
+ }>;
216
+ /**
217
+ * POST /api/game/check-unique-object-name
218
+ */
219
+ checkUniqueObjectName: (type: string, name: string, shard?: string) => UndocumentedRes;
220
+ /**
221
+ * POST /api/game/place-spawn
222
+ */
223
+ placeSpawn: (room: string, x: number, y: number, name: string, shard?: string) => UndocumentedRes;
224
+ /**
225
+ * POST /api/game/create-flag
226
+ * - if the name is new, result.upserted[0]._id is the game id of the created flag
227
+ * - if not, this moves the flag and the response does not contain the id (but the id doesn't change)
228
+ * - `connection` looks like some internal MongoDB thing that is irrelevant to us
229
+ */
230
+ createFlag: (room: string, x: number, y: number, name: string, color?: FlagColor, secondaryColor?: FlagColor, shard?: string) => DbResponse;
231
+ /**
232
+ * POST/api/game/gen-unique-flag-name
233
+ */
234
+ genUniqueFlagName: (shard?: string) => UndocumentedRes;
235
+ /**
236
+ * POST /api/game/check-unique-flag-name
237
+ */
238
+ checkUniqueFlagName: (name: string, shard?: string) => UndocumentedRes;
239
+ /**
240
+ * POST /api/game/change-flag-color
241
+ */
242
+ changeFlagColor: (color?: FlagColor, secondaryColor?: FlagColor, shard?: string) => DbResponse;
243
+ /**
244
+ * POST /api/game/remove-flag
245
+ */
246
+ removeFlag: (room: string, name: string, shard?: string) => UndocumentedRes;
247
+ /**
248
+ * POST /api/game/add-object-intent
249
+ * [Missing parameter] _id is the game id of the object to affect (except for destroying structures), room is the name of the room it's in
250
+ * this method is used for a variety of actions, depending on the `name` and `intent` parameters
251
+ * @example remove flag: name = "remove", intent = {}
252
+ * @example destroy structure: _id = "room", name = "destroyStructure", intent = [ {id: <structure id>, roomName, <room name>, user: <user id>} ]
253
+ can destroy multiple structures at once
254
+ * @example suicide creep: name = "suicide", intent = {id: <creep id>}
255
+ * @example unclaim controller: name = "unclaim", intent = {id: <controller id>}
256
+ intent can be an empty object for suicide and unclaim, but the web interface sends the id in it, as described
257
+ * @example remove construction site: name = "remove", intent = {}
258
+ */
259
+ addObjectIntent: (room: string, name: string, intent: string, shard?: string) => DbResponse;
260
+ /**
261
+ * POST /api/game/create-construction
262
+ * @returns {{ ok, result: { ok, n }, ops: [ { type, room, x, y, structureType, user, progress, progressTotal, _id } ], insertedCount, insertedIds }}
263
+ */
264
+ createConstruction: (room: string, x: number, y: number, structureType: string, name: string, shard?: string) => DbInsertResponse<{
265
+ ops: {
266
+ type: string;
267
+ room: string;
268
+ x: number;
269
+ y: number;
270
+ structureType: string;
271
+ user: string;
272
+ progress: number;
273
+ progressTotal: number;
274
+ _id: string;
275
+ }[];
276
+ }>;
277
+ /**
278
+ * POST /api/game/set-notify-when-attacked
279
+ */
280
+ setNotifyWhenAttacked: (_id: string, enabled?: boolean, shard?: string) => DbResponse;
281
+ /**
282
+ * POST /api/game/create-invader
283
+ */
284
+ createInvader: (room: string, x: number, y: number, size: any, type: any, boosted?: boolean, shard?: string) => UndocumentedRes;
285
+ /**
286
+ * POST /api/game/remove-invader
287
+ */
288
+ removeInvader: (_id: string, shard?: string) => UndocumentedRes;
289
+ /**
290
+ * GET /api/game/time
291
+ */
292
+ time: (shard?: string) => Res<{
293
+ time: number;
294
+ }>;
295
+ /**
296
+ * GET /api/game/world-size
297
+ */
298
+ worldSize: (shard?: string) => UndocumentedRes;
299
+ /**
300
+ * GET /api/game/room-decorations
301
+ */
302
+ roomDecorations: (room: string, shard?: string) => UndocumentedRes;
303
+ /**
304
+ * GET /api/game/room-objects
305
+ */
306
+ roomObjects: (room: string, shard?: string) => UndocumentedRes;
307
+ /**
308
+ * GET /api/game/room-terrain
309
+ * terrain is a string of digits, giving the terrain left-to-right and top-to-bottom
310
+ * 0: plain, 1: wall, 2: swamp, 3: also wall
311
+ */
312
+ roomTerrain: (room: string, encoded?: number, shard?: string) => Res<{
313
+ terrain: {
314
+ room: string;
315
+ x: number;
316
+ y: number;
317
+ type: "wall" | "swamp";
318
+ }[];
319
+ }> | Res<{
320
+ terrain: {
321
+ _id: string;
322
+ room: string;
323
+ terrain: string;
324
+ type: "wall" | "swamp";
325
+ }[];
326
+ }>;
327
+ /**
328
+ * GET /api/game/room-status
329
+ * if the room is in a novice area, novice will contain the Unix timestamp of the end of the protection (otherwise it is absent)
330
+ */
331
+ roomStatus: (room: string, shard?: string) => Promise<{
332
+ _id: string;
333
+ status: "normal" | "out of borders";
334
+ novice?: string;
335
+ }>;
336
+ /**
337
+ * GET /api/game/room-overview
338
+ */
339
+ roomOverview: (room: string, interval?: number, shard?: string) => UndocumentedRes;
340
+ market: {
341
+ /**
342
+ * GET /api/game/market/orders-index
343
+ * - _id is the resource type, and there will only be one of each type.
344
+ * - `count` is the number of orders.
345
+ */
346
+ ordersIndex: (shard?: string) => Res<{
347
+ list: {
348
+ _id: string;
349
+ count: number;
350
+ }[];
351
+ }>;
352
+ /**
353
+ * GET /api/game/market/my-orders
354
+ * `resourceType` is one of the RESOURCE_* constants.
355
+ */
356
+ myOrders: () => Res<{
357
+ list: MarketOrder[];
358
+ }>;
359
+ /**
360
+ * GET /api/game/market/orders
361
+ * @param resourceType one of the RESOURCE_* constants.
362
+ * `resourceType` is one of the RESOURCE_* constants.
363
+ */
364
+ orders: (resourceType: string, shard?: string) => Res<{
365
+ list: MarketOrder[];
366
+ }>;
367
+ /**
368
+ * GET /api/game/market/stats
369
+ */
370
+ stats: (resourceType: string, shard?: string) => UndocumentedRes;
371
+ };
372
+ shards: {
373
+ /**
374
+ * GET /api/game/shards/info
375
+ */
376
+ info: () => Res<{
377
+ shards: {
378
+ name: string;
379
+ lastTicks: number[];
380
+ cpuLimit: number;
381
+ rooms: number;
382
+ users: number;
383
+ tick: number;
384
+ }[];
385
+ }>;
386
+ };
387
+ };
388
+ leaderboard: {
389
+ /**
390
+ * GET /api/leaderboard/list
391
+ */
392
+ list: (limit?: number, mode?: "world" | "power", offset?: number, season?: string) => Res<{
393
+ list: {
394
+ _id: string;
395
+ season: string;
396
+ user: string;
397
+ score: number;
398
+ rank: number;
399
+ }[];
400
+ count: number;
401
+ users: {
402
+ [userId: string]: User;
403
+ };
404
+ }>;
405
+ /**
406
+ * GET /api/leaderboard/find
407
+ * @param season An optional date in the format YYYY-MM, if not supplied all ranks in all seasons is returned.
408
+ * - `user` (not `_id`) is the user's _id, as returned by `me` and `user/find`
409
+ * - `rank` is 0-based
410
+ */
411
+ find: (username: string, mode?: string, season?: string) => Res<{
412
+ _id: string;
413
+ season: string;
414
+ user: string;
415
+ score: number;
416
+ rank: number;
417
+ }>;
418
+ /**
419
+ * GET /api/leaderboard/seasons
420
+ * The _id returned here is used for the season name in the other leaderboard calls
421
+ */
422
+ seasons: () => Res<{
423
+ seasons: {
424
+ _id: string;
425
+ name: string;
426
+ date: string;
427
+ }[];
428
+ }>;
429
+ };
430
+ user: {
431
+ /**
432
+ * POST /api/user/badge
433
+ */
434
+ badge: (badge: Badge) => Promise<{
435
+ ok?: number;
436
+ error?: string;
437
+ }>;
438
+ /**
439
+ * POST /api/user/respawn
440
+ */
441
+ respawn: () => UndocumentedRes;
442
+ /**
443
+ * POST /api/user/set-active-branch
444
+ */
445
+ setActiveBranch: (branch: string, activeName: string) => UndocumentedRes;
446
+ /**
447
+ * POST /api/user/clone-branch
448
+ */
449
+ cloneBranch: (branch: string | undefined, newName: string, defaultModules: CodeList) => UndocumentedRes;
450
+ /**
451
+ * POST /api/user/delete-branch
452
+ */
453
+ deleteBranch: (branch: string) => UndocumentedRes;
454
+ /**
455
+ * POST /api/user/notify-prefs
456
+ */
457
+ notifyPrefs: (prefs: any) => UndocumentedRes;
458
+ /**
459
+ * POST /api/user/tutorial-done
460
+ */
461
+ tutorialDone: () => UndocumentedRes;
462
+ /**
463
+ * POST /api/user/email
464
+ */
465
+ email: (email: string) => UndocumentedRes;
466
+ /**
467
+ * GET /api/user/world-start-room
468
+ */
469
+ worldStartRoom: (shard: string) => UndocumentedRes;
470
+ /**
471
+ * GET /api/user/world-status
472
+ * returns a world status
473
+ * - 'normal'
474
+ * - 'lost' when you loose all your spawns
475
+ * - 'empty' when you have respawned and not placed your spawn yet
476
+ */
477
+ worldStatus: () => Res<{
478
+ status: "normal" | "lost" | "empty";
479
+ }>;
480
+ /**
481
+ * GET /api/user/branches
482
+ */
483
+ branches: () => Res<{
484
+ list: {
485
+ _id: string;
486
+ branch: string;
487
+ activeWorld: boolean;
488
+ activeSim: boolean;
489
+ }[];
490
+ }>;
491
+ code: {
492
+ /**
493
+ * GET /api/user/code
494
+ * for pushing or pulling code, as documented at http://support.screeps.com/hc/en-us/articles/203022612
495
+ * @returns code
496
+ */
497
+ get: (branch: string) => Res<{
498
+ modules: CodeList;
499
+ }>;
500
+ /**
501
+ * POST /api/user/code
502
+ * for pushing or pulling code, as documented at http://support.screeps.com/hc/en-us/articles/203022612
503
+ */
504
+ set: (branch: string, modules: CodeList, _hash?: any) => UndocumentedRes;
505
+ };
506
+ decorations: {
507
+ /**
508
+ * GET /api/user/decorations/inventory
509
+ */
510
+ inventory: () => UndocumentedRes;
511
+ /**
512
+ * GET /api/user/decorations/themes
513
+ */
514
+ themes: () => UndocumentedRes;
515
+ /**
516
+ * POST /api/user/decorations/convert
517
+ */
518
+ convert: (decorations: number[]) => UndocumentedRes;
519
+ /**
520
+ * POST /api/user/decorations/pixelize
521
+ */
522
+ pixelize: (count: number, theme?: string) => UndocumentedRes;
523
+ /**
524
+ * POST /api/user/decorations/activate
525
+ */
526
+ activate: (_id: string, active: any) => UndocumentedRes;
527
+ /**
528
+ * POST /api/user/decorations/deactivate
529
+ */
530
+ deactivate: (decorations: string[]) => UndocumentedRes;
531
+ };
532
+ /**
533
+ * GET /api/user/respawn-prohibited-rooms
534
+ * - `rooms` is an array, but seems to always contain only one element
535
+ */
536
+ respawnProhibitedRooms: () => Res<{
537
+ rooms: string[];
538
+ }>;
539
+ memory: {
540
+ /**
541
+ * GET /api/user/memory?path={path}
542
+ * @param path the path may be empty or absent to retrieve all of Memory, Example: flags.Flag1
543
+ * @returns gz: followed by base64-encoded gzipped JSON encoding of the requested memory path
544
+ */
545
+ get: (path?: string, shard?: string) => Res<{
546
+ data: string;
547
+ }>;
548
+ /**
549
+ * POST /api/user/memory
550
+ * @param path the path may be empty or absent to retrieve all of Memory, Example: flags.Flag1
551
+ */
552
+ set: (path: string, value: any, shard?: string) => DbInsertResponse<{
553
+ ops: {
554
+ user: string;
555
+ expression: string;
556
+ hidden: boolean;
557
+ }[];
558
+ data: any;
559
+ }>;
560
+ segment: {
561
+ /**
562
+ * GET /api/user/memory-segment?segment=[0-99]
563
+ * @param segment A number from 0-99
564
+ */
565
+ get: (segment: number, shard?: string) => Res<{
566
+ data: string;
567
+ }>;
568
+ /**
569
+ * POST /api/user/memory-segment
570
+ * @param segment A number from 0-99
571
+ */
572
+ set: (segment: number, data: any, shard?: string) => UndocumentedRes;
573
+ };
574
+ };
575
+ /**
576
+ * GET /api/user/find?username={username}
577
+ */
578
+ find: (username: string) => Res<{
579
+ user: User;
580
+ }>;
581
+ /**
582
+ * GET /api/user/find?id={userId}
583
+ */
584
+ findById: (id: string) => Res<{
585
+ user: User;
586
+ }>;
587
+ /**
588
+ * GET /api/user/stats
589
+ */
590
+ stats: (interval: number) => UndocumentedRes;
591
+ /**
592
+ * GET /api/user/rooms
593
+ */
594
+ rooms: (id: string) => UndocumentedRes;
595
+ /**
596
+ * GET /api/user/overview?interval={interval}&statName={statName}
597
+ * @param statName energyControl
598
+ */
599
+ overview: (interval: number, statName: string) => UndocumentedRes;
600
+ /**
601
+ * GET /api/user/money-history
602
+ */
603
+ moneyHistory: (page?: number) => Res<{
604
+ page: number;
605
+ hasMore: boolean;
606
+ list: {
607
+ _id: string;
608
+ date: string;
609
+ tick: number;
610
+ user: string;
611
+ type: string;
612
+ balance: number;
613
+ change: number;
614
+ market: {
615
+ order: {
616
+ type: string;
617
+ resourceType: string;
618
+ price: number;
619
+ totalAmount: number;
620
+ roomName: string;
621
+ };
622
+ } | {
623
+ extendOrder: {
624
+ orderId: string;
625
+ addAmount: number;
626
+ };
627
+ } | {
628
+ resourceType: string;
629
+ roomName: string;
630
+ targetRoomName: string;
631
+ price: number;
632
+ npc: boolean;
633
+ amount: number;
634
+ } | {
635
+ changeOrderPrice: {
636
+ orderId: string;
637
+ oldPrice: number;
638
+ newPrice: number;
639
+ };
640
+ };
641
+ }[];
642
+ }>;
643
+ /**
644
+ * POST /api/user/console
645
+ */
646
+ console: (expression: any, shard?: string) => DbInsertResponse<{
647
+ ops: {
648
+ user: string;
649
+ expression: any;
650
+ _id: string;
651
+ }[];
652
+ }>;
653
+ /**
654
+ * GET /api/user/name
655
+ */
656
+ name: () => UndocumentedRes;
657
+ };
658
+ experimental: {
659
+ /**
660
+ * time is the current server tick
661
+ * _id contains the room name for each room, and lastPvpTime contains the last tick pvp occurred
662
+ * if neither a valid interval nor a valid start argument is provided, the result of the call is still ok, but with an empty rooms array.
663
+ */
664
+ pvp: (interval?: number) => Res<{
665
+ time: number;
666
+ rooms: {
667
+ _id: string;
668
+ lastPvpTime: number;
669
+ }[];
670
+ }>;
671
+ /**
672
+ * GET /api/experimental/nukes
673
+ */
674
+ nukes: () => Res<{
675
+ nukes: {
676
+ [shard: string]: {
677
+ _id: string;
678
+ type: "nuke";
679
+ room: string;
680
+ x: number;
681
+ y: number;
682
+ landTime: number;
683
+ launchRoomName: string;
684
+ };
685
+ };
686
+ }>;
687
+ };
688
+ warpath: {
689
+ /**
690
+ * GET /api/warpath/battles
691
+ */
692
+ battles: (interval?: number) => UndocumentedRes;
693
+ };
694
+ scoreboard: {
695
+ /**
696
+ * GET /api/scoreboard/list
697
+ */
698
+ list: (limit?: number, offset?: number) => UndocumentedRes;
699
+ };
700
+ };
701
+ currentSeason(): string;
702
+ isOfficialServer(): boolean;
703
+ mapToShard: <T>(res: T & {
704
+ list?: any;
705
+ rooms?: any;
706
+ shards?: any;
707
+ }) => T & {
708
+ list?: any;
709
+ rooms?: any;
710
+ shards?: any;
711
+ };
712
+ setServer(opts: Partial<RawOpts>): void;
713
+ auth(email: string, password: string, opts?: Partial<RawOpts>): Promise<{
714
+ token: string;
715
+ } & {
716
+ ok: number;
717
+ }>;
718
+ req(method: string, path: string, body?: any): UndocumentedRes;
719
+ gz(data: string): string;
720
+ inflate(data: string): any;
721
+ buildRateLimit(method: string, path: string, res: Response): {
722
+ method: string;
723
+ path: string;
724
+ limit: number;
725
+ remaining: number;
726
+ reset: number;
727
+ toReset: number;
728
+ };
729
+ }
730
+ type Res<T extends object> = Promise<T & {
731
+ ok: number;
732
+ }>;
733
+ type UndocumentedRes = Promise<any>;
734
+ type AdditonalKeys<T = any> = Partial<Record<string, T>>;
735
+ type AtLeast<T extends object> = T & AdditonalKeys;
736
+ type DbResponse = Res<{
737
+ result: {
738
+ nModified: number;
739
+ ok: number;
740
+ upserted?: {
741
+ index: number;
742
+ _id: string;
743
+ }[];
744
+ n: number;
745
+ };
746
+ connection: {
747
+ host: string;
748
+ id: string;
749
+ port: number;
750
+ };
751
+ }>;
752
+ type DbInsertResponse<T> = Res<{
753
+ result: {
754
+ ok: number;
755
+ n: number;
756
+ };
757
+ insertedCount: number;
758
+ insertedIds: string[];
759
+ } & T>;
760
+ interface Badge {
761
+ color1: string;
762
+ color2: string;
763
+ color3: string;
764
+ flip: boolean;
765
+ param: number;
766
+ type: number | {
767
+ path1: string;
768
+ path2: string;
769
+ };
770
+ }
771
+ /**
772
+ * - Red = 1,
773
+ * - Purple = 2,
774
+ * - Blue = 3,
775
+ * - Cyan = 4,
776
+ * - Green = 5,
777
+ * - Yellow = 6,
778
+ * - Orange = 7,
779
+ * - Brown = 8,
780
+ * - Grey = 9,
781
+ * - White = 10
782
+ */
783
+ type FlagColor = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10;
784
+ type StatKey = "creepsLost" | "creepsProduced" | "energyConstruction" | "energyControl" | "energyCreeps" | "energyHarvested";
785
+ interface MarketOrder {
786
+ _id: string;
787
+ created: string;
788
+ user: string;
789
+ active: boolean;
790
+ type: "buy" | "sell";
791
+ amount: number;
792
+ remainingAmount: number;
793
+ resourceType: string;
794
+ price: number;
795
+ totalAmount: number;
796
+ roomName: string;
797
+ }
798
+ interface Me extends User {
799
+ email: string;
800
+ cpu: number;
801
+ password: string;
802
+ notifyPrefs: {
803
+ sendOnline: any;
804
+ errorsInterval: any;
805
+ disabledOnMessages: any;
806
+ disabled: any;
807
+ interval: any;
808
+ };
809
+ credits: number;
810
+ lastChargeTime: any;
811
+ lastTweetTime: any;
812
+ github: {
813
+ id: any;
814
+ username: any;
815
+ };
816
+ twitter: {
817
+ username: string;
818
+ followers_count: number;
819
+ };
820
+ }
821
+ interface User {
822
+ _id: string;
823
+ username: string;
824
+ badge: Badge;
825
+ gcl: number;
826
+ }
827
+ interface BinaryModule {
828
+ /** base64 encoded binary data */
829
+ binary: string;
830
+ }
831
+ interface CodeList {
832
+ [fileName: string]: string | BinaryModule;
833
+ }
834
+ //#endregion
835
+ //#region src/Socket.d.ts
836
+ declare const DEFAULTS: {
837
+ reconnect: boolean;
838
+ resubscribe: boolean;
839
+ keepAlive: boolean;
840
+ maxRetries: number;
841
+ maxRetryDelay: number;
842
+ };
843
+ interface Message {
844
+ channel: string;
845
+ type: string;
846
+ id?: string;
847
+ data: any;
848
+ }
849
+ declare class Socket extends EventEmitter<{
850
+ connected: [];
851
+ disconnected: [];
852
+ error: [Error | (Event & {
853
+ error: Error;
854
+ })];
855
+ message: [Message];
856
+ token: [token: string];
857
+ auth: [Message & {
858
+ data: {
859
+ status: string;
860
+ token?: string;
861
+ };
862
+ }];
863
+ authed: [];
864
+ subscribe: [path: string];
865
+ unsubscribe: [path: string];
866
+ } & {
867
+ [channel: string]: [Message];
868
+ }> {
869
+ ws?: WebSocket;
870
+ api: ScreepsAPI;
871
+ opts: typeof DEFAULTS;
872
+ authed: boolean;
873
+ connected: boolean;
874
+ reconnecting: boolean;
875
+ keepAliveInter: number | NodeJS.Timeout;
876
+ __queue: string[];
877
+ __subQueue: string[];
878
+ __subs: Record<string, number>;
879
+ constructor(api: ScreepsAPI);
880
+ reset(): void;
881
+ connect(opts?: {}): Promise<unknown>;
882
+ reconnect(): Promise<void>;
883
+ disconnect(): void;
884
+ sleep(time: number): Promise<unknown>;
885
+ handleMessage(ev: MessageEvent): void;
886
+ gzip(bool: boolean): Promise<void>;
887
+ send(data: string): Promise<void>;
888
+ auth(token: string): Promise<void>;
889
+ subscribe(path: string, cb?: (...args: any[]) => void): Promise<void>;
890
+ unsubscribe(path: string): Promise<void>;
891
+ }
892
+ //#endregion
893
+ //#region src/ConfigManager.d.ts
894
+ /**
895
+ * Unified Credentials File v1.0.
896
+ * A standardized format for storing credentials and configuration for Screeps World related tools.
897
+ * @link https://github.com/screepers/screepers-standards/blob/master/SS3-Unified_Credentials_File.md
898
+ */
899
+ interface UnifiedConfig {
900
+ servers: Partial<Record<string, ServerConfig>>;
901
+ configs?: Partial<Record<string, any>>;
902
+ [metadata: string]: any;
903
+ }
904
+ interface ServerConfig {
905
+ host: string;
906
+ /** override standard TCP port */
907
+ port?: number;
908
+ /** use SSL */
909
+ secure?: boolean;
910
+ /** authorization token */
911
+ token?: string;
912
+ /** is only supported on private servers */
913
+ username?: string;
914
+ /** is only supported on private servers */
915
+ password?: string;
916
+ /** additional metadata like ptr flag */
917
+ [metadata: string]: any;
918
+ }
919
+ /**
920
+ * Utility class for loading Unified Credentials Files from disk, environment variables, or other sources.
921
+ * Only platforms without filesystem access, {@link ConfigManager.setConfig}, must be used to provide the config data directly.
922
+ */
923
+ declare class ConfigManager {
924
+ path?: string;
925
+ private _config;
926
+ /** Custom environment variables, useful for platforms without process.env */
927
+ env: Record<string, string | undefined>;
928
+ /** Custom file reading function, useful for platforms with a virtual filesystem */
929
+ readFile?: (path: string, options: {
930
+ encoding: "utf8";
931
+ }) => Promise<string>;
932
+ setConfig(data: unknown, path?: string): UnifiedConfig;
933
+ refresh(): Promise<void>;
934
+ getServers(): Promise<string[]>;
935
+ getConfig(): Promise<UnifiedConfig | null>;
936
+ loadConfig(path: string): Promise<UnifiedConfig | null>;
937
+ }
938
+ //#endregion
939
+ //#region src/ScreepsAPI.d.ts
940
+ interface RateLimit {
941
+ limit: number;
942
+ period: string;
943
+ remaining: number;
944
+ reset: number;
945
+ toReset: number;
946
+ }
947
+ declare class ScreepsAPI extends RawAPI {
948
+ socket: Socket;
949
+ appConfig: {
950
+ [metadata: string]: any;
951
+ };
952
+ rateLimits: {
953
+ global: RateLimit;
954
+ GET: {
955
+ [path: string]: RateLimit;
956
+ };
957
+ POST: {
958
+ [path: string]: RateLimit;
959
+ };
960
+ };
961
+ private _user?;
962
+ private _tokenInfo?;
963
+ static fromConfig(server?: string, config?: string | false, opts?: {}): Promise<ScreepsAPI>;
964
+ constructor(opts?: {});
965
+ getRateLimit(method: "GET" | "POST", path: string): RateLimit;
966
+ get rateLimitResetUrl(): string;
967
+ me(): Promise<(Me | User) & {
968
+ ok: number;
969
+ }>;
970
+ tokenInfo(): Promise<{
971
+ full: boolean;
972
+ }>;
973
+ userID(): Promise<string>;
974
+ readonly registerUser: (username: string, email: string, password: string, modules: any) => UndocumentedRes;
975
+ readonly history: (room: string, tick: number, shard?: string) => Promise<{
976
+ timestamp: number;
977
+ room: string;
978
+ base: number;
979
+ ticks: {
980
+ [time: string]: Partial<Record<string, any>>;
981
+ };
982
+ }>;
983
+ readonly authmod: () => Promise<{
984
+ name: string;
985
+ version?: any;
986
+ } & {
987
+ ok: number;
988
+ }>;
989
+ readonly version: () => Promise<{
990
+ package: number;
991
+ protocol: number;
992
+ serverData: {
993
+ customObjectTypes: object;
994
+ historyChunkSize: number;
995
+ features: ({
996
+ name: string;
997
+ version: number;
998
+ } & Partial<Record<string, any>>)[];
999
+ shards: string[];
1000
+ } & Partial<Record<string, any>>;
1001
+ users: number;
1002
+ } & Partial<{
1003
+ currentSeason: string | undefined;
1004
+ seasonAccessCost: string | undefined;
1005
+ decorationConvertationCost: number | undefined;
1006
+ decorationPixelizationCost: number | undefined;
1007
+ }> & {
1008
+ ok: number;
1009
+ }>;
1010
+ readonly time: (shard?: string) => Promise<{
1011
+ time: number;
1012
+ } & {
1013
+ ok: number;
1014
+ }>;
1015
+ readonly leaderboard: {
1016
+ list: (limit?: number, mode?: "world" | "power", offset?: number, season?: string) => Promise<{
1017
+ list: {
1018
+ _id: string;
1019
+ season: string;
1020
+ user: string;
1021
+ score: number;
1022
+ rank: number;
1023
+ }[];
1024
+ count: number;
1025
+ users: {
1026
+ [userId: string]: User;
1027
+ };
1028
+ } & {
1029
+ ok: number;
1030
+ }>;
1031
+ find: (username: string, mode?: string, season?: string) => Promise<{
1032
+ _id: string;
1033
+ season: string;
1034
+ user: string;
1035
+ score: number;
1036
+ rank: number;
1037
+ } & {
1038
+ ok: number;
1039
+ }>;
1040
+ seasons: () => Promise<{
1041
+ seasons: {
1042
+ _id: string;
1043
+ name: string;
1044
+ date: string;
1045
+ }[];
1046
+ } & {
1047
+ ok: number;
1048
+ }>;
1049
+ };
1050
+ readonly market: {
1051
+ ordersIndex: (shard?: string) => Promise<{
1052
+ list: {
1053
+ _id: string;
1054
+ count: number;
1055
+ }[];
1056
+ } & {
1057
+ ok: number;
1058
+ }>;
1059
+ myOrders: () => Promise<{
1060
+ list: MarketOrder[];
1061
+ } & {
1062
+ ok: number;
1063
+ }>;
1064
+ orders: (resourceType: string, shard?: string) => Promise<{
1065
+ list: MarketOrder[];
1066
+ } & {
1067
+ ok: number;
1068
+ }>;
1069
+ stats: (resourceType: string, shard?: string) => UndocumentedRes;
1070
+ };
1071
+ readonly console: (expression: any, shard?: string) => Promise<{
1072
+ result: {
1073
+ ok: number;
1074
+ n: number;
1075
+ };
1076
+ insertedCount: number;
1077
+ insertedIds: string[];
1078
+ } & {
1079
+ ops: {
1080
+ user: string;
1081
+ expression: any;
1082
+ _id: string;
1083
+ }[];
1084
+ } & {
1085
+ ok: number;
1086
+ }>;
1087
+ readonly code: {
1088
+ get: (branch: string) => Promise<{
1089
+ modules: CodeList;
1090
+ } & {
1091
+ ok: number;
1092
+ }>; /** Unlike raw.code.set, this method will create a new branch if it doesn't exist */
1093
+ set: (branch: string, code: CodeList) => UndocumentedRes;
1094
+ branches: () => Promise<{
1095
+ list: {
1096
+ _id: string;
1097
+ branch: string;
1098
+ activeWorld: boolean;
1099
+ activeSim: boolean;
1100
+ }[];
1101
+ } & {
1102
+ ok: number;
1103
+ }>;
1104
+ cloneBranch: (branch: string | undefined, newName: string, defaultModules: CodeList) => UndocumentedRes;
1105
+ deleteBranch: (branch: string) => UndocumentedRes;
1106
+ setActiveBranch: (branch: string, activeName: string) => UndocumentedRes;
1107
+ };
1108
+ readonly memory: {
1109
+ /** Unlike raw.user.memory.get, this method returns uncompressed memory */get: (path?: string, shard?: string) => Promise<string>;
1110
+ set: (path: string, value: any, shard?: string) => Promise<{
1111
+ result: {
1112
+ ok: number;
1113
+ n: number;
1114
+ };
1115
+ insertedCount: number;
1116
+ insertedIds: string[];
1117
+ } & {
1118
+ ops: {
1119
+ user: string;
1120
+ expression: string;
1121
+ hidden: boolean;
1122
+ }[];
1123
+ data: any;
1124
+ } & {
1125
+ ok: number;
1126
+ }>;
1127
+ segment: {
1128
+ get: (segment: number, shard?: string) => Promise<{
1129
+ data: string;
1130
+ } & {
1131
+ ok: number;
1132
+ }>;
1133
+ set: (segment: number, data: any, shard?: string) => UndocumentedRes;
1134
+ };
1135
+ };
1136
+ readonly segment: {
1137
+ get: (segment: number, shard?: string) => Promise<{
1138
+ data: string;
1139
+ } & {
1140
+ ok: number;
1141
+ }>;
1142
+ set: (segment: number, data: any, shard?: string) => UndocumentedRes;
1143
+ };
1144
+ }
1145
+ //#endregion
1146
+ export { type Badge, type CodeList, ConfigManager, type MarketOrder, type Me, ScreepsAPI, type UndocumentedRes, type User };
1147
+ //# sourceMappingURL=index.d.mts.map