screeps-connectivity 0.3.0 → 0.5.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/CHANGELOG.md CHANGED
@@ -1,5 +1,19 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 1e7161f: Add `http.game.roomHistory(room, time, shard?)` to `GameEndpoints` — handles both official server (path-based URL) and private server (query-param URL) automatically. `HistoryPlayer` in `screeps-client` is refactored to use this endpoint instead of a raw `fetch()` with manual token injection.
8
+
9
+ ## 0.4.0
10
+
11
+ ### Minor Changes
12
+
13
+ - de4fd47: Add memory watch panel with live WebSocket subscriptions, persistent watchlist, temp creep watch, and inline editing.
14
+
15
+ `screeps-connectivity` gains `UserStore.subscribeMemory(path, shard?)` and a new `user:memory` event on `UserStoreEvents`. `screeps-client` adds a full Memory pane to the bottom bar: a persistent watchlist, a temporary per-creep watch triggered from the Eye button on the selection panel, a recursive type-aware `MemoryTree` with expand/collapse, insert-to-console, and inline leaf editing.
16
+
3
17
  ## 0.3.0
4
18
 
5
19
  ### Minor Changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "screeps-connectivity",
3
- "version": "0.3.0",
3
+ "version": "0.5.0",
4
4
  "license": "ISC",
5
5
  "type": "module",
6
6
  "repository": {
@@ -13,6 +13,7 @@ import type {
13
13
  ApiGenUniqueObjectNameResponse,
14
14
  ApiCheckUniqueObjectNameResponse,
15
15
  ApiGameTickResponse,
16
+ RoomHistoryChunk,
16
17
  } from '../../types/api.js'
17
18
  import { createPowerCreepsEndpoints, type PowerCreepsEndpoints } from './power-creeps.js'
18
19
 
@@ -39,6 +40,8 @@ export interface GameEndpoints {
39
40
  removeConstructionSite(room: string, ids: string[], shard?: string | null): Promise<{ ok: number }>
40
41
  addObjectIntent(id: string, room: string, name: string, intent: unknown, shard?: string | null): Promise<{ ok: number }>
41
42
  addGlobalIntent(name: string, intent: unknown): Promise<{ ok: number }>
43
+ /** Fetch a room history chunk. Pass shard for official multi-shard servers; omit for private servers. */
44
+ roomHistory(room: string, time: number, shard?: string | null): Promise<RoomHistoryChunk>
42
45
  setNotifyWhenAttacked(id: string, enabled: boolean): Promise<{ ok: number }>
43
46
  createInvader(room: string, x: number, y: number, size: number, type: string, boosted?: boolean): Promise<{ ok: number }>
44
47
  removeInvader(id: string): Promise<{ ok: number }>
@@ -85,6 +88,10 @@ export function createGameEndpoints(http: HttpClient): GameEndpoints {
85
88
  removeConstructionSite: (room, ids, shard) => http.request('POST', '/api/game/add-object-intent', withShard({ _id: 'room', room, name: 'removeConstructionSite', intent: ids.map(id => ({ id, roomName: room })) }, shard)),
86
89
  addObjectIntent: (id, room, name, intent, shard) => http.request('POST', '/api/game/add-object-intent', withShard({ _id: id, room, name, intent }, shard)),
87
90
  addGlobalIntent: (name, intent) => http.request('POST', '/api/game/add-global-intent', { name, intent }),
91
+ roomHistory: (room, time, shard) =>
92
+ shard
93
+ ? http.request('GET', `/room-history/${encodeURIComponent(shard)}/${encodeURIComponent(room)}/${time}.json`)
94
+ : http.request('GET', '/room-history', { room, time }),
88
95
  setNotifyWhenAttacked: (id, enabled) => http.request('POST', '/api/game/set-notify-when-attacked', { _id: id, enabled }),
89
96
  createInvader: (room, x, y, size, type, boosted) => http.request('POST', '/api/game/create-invader', { room, x, y, size, type, ...(boosted != null ? { boosted } : {}) }),
90
97
  removeInvader: (id) => http.request('POST', '/api/game/remove-invader', { _id: id }),
package/src/index.ts CHANGED
@@ -39,6 +39,7 @@ export type {
39
39
 
40
40
  export { fetchServerVersion, fetchAuthModInfo, checkUsername, checkEmail, registerUser, getServerFeature, getScreepsmodAuth } from './http/fetchServerVersion.js'
41
41
  export type { ApiAuthModInfoResponse } from './http/fetchServerVersion.js'
42
+ export type { RoomHistoryChunk } from './types/api.js'
42
43
 
43
44
  export { badgeToSvg } from './badge/index.js'
44
45
  export { BadgeColors } from './badge/colors.js'
package/src/types/api.ts CHANGED
@@ -2,6 +2,13 @@ export interface ApiOkResponse {
2
2
  ok: number
3
3
  }
4
4
 
5
+ export interface RoomHistoryChunk {
6
+ timestamp: number
7
+ room: string
8
+ base: number
9
+ ticks: Record<string, import('./game.js').RoomObjectDiff>
10
+ }
11
+
5
12
  export interface ApiAuthSigninResponse {
6
13
  ok: number
7
14
  token: string
@@ -207,4 +207,32 @@ describe('game endpoints', () => {
207
207
  expect(url).toContain('/api/game/tick')
208
208
  expect(res.tick).toBe(500)
209
209
  })
210
+
211
+ it('roomHistory uses path URL for official server (shard provided)', async () => {
212
+ const chunk = { timestamp: 1000, room: 'W1N1', base: 1000, ticks: {} }
213
+ fetchMock.mockResolvedValue(mockResponse(chunk))
214
+ const http = new HttpClient({ url: 'http://test.local', auth: new TokenAuth({ token: 't' }) })
215
+
216
+ const res = await http.game.roomHistory('W1N1', 1000, 'shard0')
217
+
218
+ const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit]
219
+ expect(init.method).toBe('GET')
220
+ expect(url).toBe('http://test.local/room-history/shard0/W1N1/1000.json')
221
+ expect(res.base).toBe(1000)
222
+ })
223
+
224
+ it('roomHistory uses query params for private server (no shard)', async () => {
225
+ const chunk = { timestamp: 1000, room: 'W1N1', base: 1000, ticks: {} }
226
+ fetchMock.mockResolvedValue(mockResponse(chunk))
227
+ const http = new HttpClient({ url: 'http://test.local', auth: new TokenAuth({ token: 't' }) })
228
+
229
+ const res = await http.game.roomHistory('W1N1', 1000)
230
+
231
+ const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit]
232
+ expect(init.method).toBe('GET')
233
+ expect(url).toMatch(/\/room-history/)
234
+ expect(url).toContain('room=W1N1')
235
+ expect(url).toContain('time=1000')
236
+ expect(res.base).toBe(1000)
237
+ })
210
238
  })