@wildshard/engine 0.1.17 → 0.1.18
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 +8 -0
- package/lint/engine-sides.json +7 -0
- package/lint/host-callback-syntax.mjs +2 -1
- package/lint/host-callbacks.mjs +3 -3
- package/lint/host-files.mjs +5 -4
- package/lint/no-base64.mjs +3 -1
- package/lint/shard-imports.mjs +6 -7
- package/lint/shard-source.d.mts +9 -0
- package/lint/shard-source.mjs +91 -0
- package/lint/shardfile-boundaries.mjs +10 -8
- package/lint/sim-closure.mjs +6 -3
- package/lint/wildshard-plugin.d.ts +4 -0
- package/lint/wildshard-plugin.js +22 -23
- package/package.json +9 -2
- package/scripts/app-build/outputProducts.d.mts +3 -0
- package/scripts/app-build/outputProducts.mjs +31 -0
- package/scripts/app-build-pipeline.mjs +3 -0
- package/scripts/check-devserver.mjs +1 -1
- package/scripts/chromium-keychain-check.mjs +4 -2
- package/scripts/chromium-keychain.mjs +3 -1
- package/scripts/cook.mjs +7 -3
- package/scripts/devices.d.mts +4 -0
- package/scripts/devices.mjs +39 -0
- package/scripts/devserver-client.d.mts +4 -2
- package/scripts/devserver-client.mjs +25 -8
- package/scripts/doctor-proof.mjs +1 -1
- package/scripts/e2e-faults.mjs +159 -0
- package/scripts/grid-crossing-walk-proof.mjs +14 -3
- package/scripts/memory-proof.mjs +158 -0
- package/scripts/offline-proof-rules.d.mts +4 -2
- package/scripts/offline-proof-rules.mjs +21 -5
- package/scripts/offline-proof.mjs +15 -6
- package/scripts/tier-textures-proof.mjs +101 -0
- package/scripts/tier-textures.mjs +60 -0
- package/scripts/tsconfig.json +1 -0
- package/scripts/vps/wildshard-config +79 -23
- package/scripts/worker-client-play.mjs +1 -0
- package/scripts/worker-client-proof.mjs +1 -1
- package/scripts/worker-client-slug.mjs +44 -0
- package/src/client/app/entry.ts +37 -10
- package/src/client/engine/boot/parsedPages.ts +127 -58
- package/src/client/engine/build.d.ts +2 -0
- package/src/client/engine/core/Game.ts +18 -0
- package/src/client/engine/core/bootstrap.ts +4 -1
- package/src/client/engine/debug/probe.ts +18 -1
- package/src/client/engine/fx/LightPool.ts +41 -1
- package/src/client/engine/pwa/sw.js +12 -3
- package/src/client/engine/render/precompile.ts +20 -14
- package/src/client/engine/telemetry/browserErrors.ts +4 -1
- package/src/client/engine/telemetry/deviceSnapshot.ts +155 -0
- package/src/client/game/boot/audio.generated.ts +0 -102
- package/src/client/game/boot/bytes.generated.ts +42 -60
- package/src/client/game/boot/versions.generated.ts +0 -2
- package/src/client/game/grid/area.ts +38 -0
- package/src/client/game/grid/live.ts +28 -2
- package/src/client/game/grid/liveSession.ts +14 -3
- package/src/client/game/grid/menu.ts +4 -0
- package/src/client/game/grid/neighbourPanels.ts +10 -1
- package/src/client/game/grid/placedCards.ts +55 -0
- package/src/client/game/grid/placedCells.ts +131 -0
- package/src/client/game/grid/regionalRuntime.ts +6 -0
- package/src/client/game/grid/regionalWorld.ts +15 -2
- package/src/client/game/grid/roadCull.ts +44 -14
- package/src/client/game/grid/roadTileBacking.ts +13 -3
- package/src/client/game/grid/session.ts +9 -0
- package/src/client/game/grid/shardfileFar.ts +9 -3
- package/src/client/game/session/finish.ts +5 -1
- package/src/client/game/shard/titleList.ts +6 -2
- package/src/client/game/shardfile/clientWorker.ts +2 -1
- package/src/client/game/titleDeck.ts +4 -3
- package/src/client/host/online/shell.ts +14 -0
- package/src/cook/game/shardCook.ts +38 -8
- package/src/cook/game/tierTextures.ts +276 -0
- package/src/e2e/smoke/game.ts +19 -14
- package/src/e2e/smoke/page-globals.d.ts +9 -8
- package/src/e2e/smoke/template2.spec.ts +8 -7
- package/src/server/host/dedicated/placementFile.ts +1 -17
- package/src/server/host/dedicated/socketTransport.ts +2 -1
- package/src/server/host/dedicated/world.ts +30 -1
- package/src/shared/engine/net/deviceWord.ts +138 -0
- package/src/shared/engine/net/socketFrames.ts +7 -4
- package/src/shared/game/grid/catalogueSlot.ts +7 -0
- package/src/shared/game/grid/placementRows.ts +33 -0
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
// DEVICE-TELEMETRY DT3/DT4 (meta docs/plans/DEVICE-TELEMETRY-PLAN.md; Jake, 2026-11-13: "start gathering metadata for every single
|
|
2
|
+
// client that connects [...] so we can kind of reverse engineer what device is up playing"): the device word a client sends once per
|
|
3
|
+
// socket, and the one shape both sides bound it to. The client cuts its snapshot with `cleanDevice` before it sends; the door reads the
|
|
4
|
+
// word as untrusted input with `readDeviceWord` and logs `deviceLine`.
|
|
5
|
+
//
|
|
6
|
+
// Privacy line: device characteristics only, the ones any page can read (Client Hints, the User-Agent, the GPU name, screen, cores,
|
|
7
|
+
// memory, locale, connection type). No IP address, no new persistent identifier, no fingerprint hash, and nothing that reads files,
|
|
8
|
+
// contacts, sensors, the camera, the microphone or location.
|
|
9
|
+
|
|
10
|
+
/** The most bytes a device word may hold; a longer one is refused whole. Under the room's 1024-byte message cap
|
|
11
|
+
* (room.ts MAX_CLIENT_MESSAGE_BYTES), past which the socket itself closes `refused`. */
|
|
12
|
+
export const DEVICE_WORD_MAX_BYTES = 1000;
|
|
13
|
+
/** The `world` word's flag that says this door reads the device word. An older door never says it, so a client never sends one there:
|
|
14
|
+
* an older door closes `refused` on a control prefix it does not know (socketTransport.ts `receive`). */
|
|
15
|
+
export const DEVICE_WORD_FLAG = 'device';
|
|
16
|
+
|
|
17
|
+
/** Whether the door's `world` word says it reads the device word. Never throws. */
|
|
18
|
+
export function worldReadsDevice(bytes: ArrayBuffer): boolean {
|
|
19
|
+
try { const said: unknown = JSON.parse(new TextDecoder().decode(bytes)); return typeof said === 'object' && said !== null && DEVICE_WORD_FLAG in said && said[DEVICE_WORD_FLAG] === 1; }
|
|
20
|
+
catch { return false; }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
type Kind = 'text' | 'long' | 'number' | 'flag' | 'list';
|
|
24
|
+
/** A device snapshot: every field optional. Nothing else crosses the wire. */
|
|
25
|
+
export interface DeviceSnapshot {
|
|
26
|
+
readonly build?: string;
|
|
27
|
+
// User-Agent Client Hints (Chromium): `model` names an Android phone ("Pixel 8", "SM-S918B")
|
|
28
|
+
readonly ua?: string; readonly model?: string; readonly platform?: string; readonly platformVersion?: string; readonly architecture?: string;
|
|
29
|
+
readonly bitness?: string; readonly wow64?: boolean; readonly mobile?: boolean;
|
|
30
|
+
readonly brands?: readonly string[]; readonly fullVersionList?: readonly string[]; readonly formFactors?: readonly string[];
|
|
31
|
+
// the game's own WebGL context
|
|
32
|
+
readonly gpu?: string; readonly gpuVendor?: string; readonly maxTexture?: number; readonly astc?: boolean; readonly etc2?: boolean; readonly bptc?: boolean;
|
|
33
|
+
readonly screenW?: number; readonly screenH?: number; readonly availW?: number; readonly availH?: number; readonly dpr?: number; readonly orientation?: string;
|
|
34
|
+
readonly cores?: number; readonly memory?: number; readonly touch?: number; readonly pointer?: string; readonly hover?: boolean;
|
|
35
|
+
readonly language?: string; readonly languages?: readonly string[]; readonly timeZone?: string;
|
|
36
|
+
readonly net?: string; readonly downlink?: number; readonly saveData?: boolean;
|
|
37
|
+
readonly display?: string;
|
|
38
|
+
}
|
|
39
|
+
type Field = keyof DeviceSnapshot;
|
|
40
|
+
/** Each field's kind, which `cleanDevice` bounds it by. */
|
|
41
|
+
const FIELDS: Readonly<Record<Field, Kind>> = {
|
|
42
|
+
build: 'text',
|
|
43
|
+
ua: 'long', model: 'text', platform: 'text', platformVersion: 'text', architecture: 'text', bitness: 'text', wow64: 'flag', mobile: 'flag',
|
|
44
|
+
brands: 'list', fullVersionList: 'list', formFactors: 'list',
|
|
45
|
+
gpu: 'text', gpuVendor: 'text', maxTexture: 'number', astc: 'flag', etc2: 'flag', bptc: 'flag',
|
|
46
|
+
screenW: 'number', screenH: 'number', availW: 'number', availH: 'number', dpr: 'number', orientation: 'text',
|
|
47
|
+
cores: 'number', memory: 'number', touch: 'number', pointer: 'text', hover: 'flag',
|
|
48
|
+
language: 'text', languages: 'list', timeZone: 'text',
|
|
49
|
+
net: 'text', downlink: 'number', saveData: 'flag',
|
|
50
|
+
display: 'text',
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const TEXT_MAX = 96, LONG_MAX = 320, LIST_ITEMS = 6, ITEM_MAX = 48;
|
|
54
|
+
// Control, format (bidi, zero-width, soft hyphen), private-use and line/paragraph separators would let a junk word reorder or hide
|
|
55
|
+
// text in a journal line
|
|
56
|
+
const UNPRINTABLE = /[\p{Cc}\p{Cf}\p{Co}\p{Zl}\p{Zp}]/gu;
|
|
57
|
+
const text = (value: unknown, max: number): string | undefined => {
|
|
58
|
+
if (typeof value !== 'string') return undefined;
|
|
59
|
+
const cut = value.replaceAll(UNPRINTABLE, '').trim().slice(0, max);
|
|
60
|
+
return cut === '' ? undefined : cut;
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
/** A snapshot cut to the known fields and their bounds: unknown fields, wrong types and non-finite numbers drop. Never throws. */
|
|
64
|
+
export function cleanDevice(raw: unknown): DeviceSnapshot {
|
|
65
|
+
const out: Record<string, unknown> = {};
|
|
66
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) return out;
|
|
67
|
+
for (const [field, kind] of Object.entries(FIELDS) as [Field, Kind][]) {
|
|
68
|
+
let value: unknown;
|
|
69
|
+
try { value = (raw as Record<string, unknown>)[field]; } catch { continue; }
|
|
70
|
+
if (kind === 'text' || kind === 'long') { const said = text(value, kind === 'long' ? LONG_MAX : TEXT_MAX); if (said !== undefined) out[field] = said; }
|
|
71
|
+
else if (kind === 'number') { if (typeof value === 'number' && Number.isFinite(value) && Math.abs(value) < 1e9) out[field] = Math.round(value * 1000) / 1000; }
|
|
72
|
+
else if (kind === 'flag') { if (typeof value === 'boolean') out[field] = value; }
|
|
73
|
+
else if (Array.isArray(value)) {
|
|
74
|
+
const items = value.slice(0, LIST_ITEMS).map(item => text(item, ITEM_MAX)).filter((item): item is string => item !== undefined);
|
|
75
|
+
if (items.length > 0) out[field] = items;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return out;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** What a word too long sheds first, in order: the least telling fields go, the model and GPU stay. */
|
|
82
|
+
const SHED: readonly Field[] = ['fullVersionList', 'languages', 'brands', 'formFactors', 'ua', 'availW', 'availH', 'downlink', 'orientation', 'timeZone', 'gpuVendor'];
|
|
83
|
+
/** The word a client sends: its cleaned snapshot as JSON, under DEVICE_WORD_MAX_BYTES (fields shed in SHED's order until it fits). */
|
|
84
|
+
export function encodeDeviceWord(snapshot: DeviceSnapshot): ArrayBuffer {
|
|
85
|
+
const encoder = new TextEncoder(), clean: Record<string, unknown> = { ...cleanDevice(snapshot) };
|
|
86
|
+
let bytes = encoder.encode(JSON.stringify(clean));
|
|
87
|
+
for (const field of SHED) {
|
|
88
|
+
if (bytes.byteLength <= DEVICE_WORD_MAX_BYTES) break;
|
|
89
|
+
delete clean[field]; bytes = encoder.encode(JSON.stringify(clean));
|
|
90
|
+
}
|
|
91
|
+
return bytes.byteLength > DEVICE_WORD_MAX_BYTES ? encoder.encode('{}').buffer : bytes.buffer;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
/** The door's read of a device word: untrusted bytes, so an oversized, non-JSON or non-object word is null. Never throws. */
|
|
95
|
+
export function readDeviceWord(bytes: ArrayBuffer): DeviceSnapshot | null {
|
|
96
|
+
if (bytes.byteLength === 0 || bytes.byteLength > DEVICE_WORD_MAX_BYTES) return null;
|
|
97
|
+
let said: unknown;
|
|
98
|
+
try { said = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes)); } catch { return null; }
|
|
99
|
+
if (typeof said !== 'object' || said === null || Array.isArray(said)) return null;
|
|
100
|
+
return cleanDevice(said);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** The browser and its major version, from the Client Hints brands, else the User-Agent. */
|
|
104
|
+
export function deviceBrowser(device: DeviceSnapshot): string | undefined {
|
|
105
|
+
const brand = [...(device.fullVersionList ?? []), ...(device.brands ?? [])].find(entry => !/not.?a.?brand|chromium/iu.test(entry));
|
|
106
|
+
if (brand !== undefined) return brand;
|
|
107
|
+
const ua = device.ua ?? '';
|
|
108
|
+
const found = /(Firefox|FxiOS|EdgA?|SamsungBrowser|OPR|CriOS|Chrome)\/(\d+)/u.exec(ua) ?? /Version\/(\d+)[^ ]* (?:Mobile\/\S+ )?Safari/u.exec(ua);
|
|
109
|
+
if (found === null) return undefined;
|
|
110
|
+
return found.length === 3 ? `${found[1] ?? ''} ${found[2] ?? ''}` : `Safari ${found[1] ?? ''}`;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/** Who a device line names: the player's Name (what everyone in the world sees) and their body id (the door's secret-keyed hash of the
|
|
114
|
+
* player id, `seats.ts` bodyId). Never the raw player id, which whoever holds it can play as, and never an address. */
|
|
115
|
+
export interface DeviceWho { readonly name: string; readonly body: string }
|
|
116
|
+
/** The door's one journal line per connect: who and what device. */
|
|
117
|
+
export function deviceLine(who: DeviceWho, device: DeviceSnapshot): Record<string, unknown> {
|
|
118
|
+
const line: Record<string, unknown> = { at: 'client.device', name: who.name, body: who.body };
|
|
119
|
+
const put = (key: string, value: unknown): void => { if (value !== undefined) line[key] = value; };
|
|
120
|
+
put('model', device.model); put('platform', device.platform); put('platformVersion', device.platformVersion);
|
|
121
|
+
put('browser', deviceBrowser(device)); put('gpu', device.gpu); put('gpuVendor', device.gpuVendor);
|
|
122
|
+
put('screen', device.screenW !== undefined && device.screenH !== undefined ? `${String(device.screenW)}x${String(device.screenH)}` : undefined);
|
|
123
|
+
put('dpr', device.dpr); put('memory', device.memory); put('cores', device.cores); put('touch', device.touch); put('mobile', device.mobile);
|
|
124
|
+
put('formFactors', device.formFactors?.join(',')); put('architecture', device.architecture); put('maxTexture', device.maxTexture);
|
|
125
|
+
put('textures', [device.astc === true ? 'astc' : '', device.etc2 === true ? 'etc2' : '', device.bptc === true ? 'bptc' : ''].filter(Boolean).join(',') || undefined);
|
|
126
|
+
put('language', device.language); put('timeZone', device.timeZone); put('net', device.net); put('display', device.display);
|
|
127
|
+
put('clientBuild', device.build); put('ua', device.ua);
|
|
128
|
+
return line;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** SENTRY: the searchable tags (`device.model:*`), each under Sentry's 200-character tag value limit. */
|
|
132
|
+
export function deviceTags(device: DeviceSnapshot): Record<string, string> {
|
|
133
|
+
const tags: Record<string, string> = {};
|
|
134
|
+
const put = (key: string, value: string | number | undefined): void => { if (value !== undefined && value !== '') tags[key] = String(value).slice(0, 200); };
|
|
135
|
+
put('device.model', device.model); put('device.gpu', device.gpu); put('device.platform', device.platform);
|
|
136
|
+
put('device.platform_version', device.platformVersion); put('device.memory', device.memory);
|
|
137
|
+
return tags;
|
|
138
|
+
}
|
|
@@ -6,13 +6,16 @@ import type { NetChannel } from './transport';
|
|
|
6
6
|
// `NET_SCHEMA_HASH` does not move.
|
|
7
7
|
|
|
8
8
|
/** The prefix byte of every message on a game socket. */
|
|
9
|
-
export const SOCKET_RELIABLE = 0, SOCKET_UNRELIABLE = 1, SOCKET_PING = 2, SOCKET_PONG = 3, SOCKET_RESUME = 4, SOCKET_READY = 5, SOCKET_COUNTDOWN = 6, SOCKET_PLAYTEST=7, SOCKET_VOICE = 8, SOCKET_WORLD = 9;
|
|
9
|
+
export const SOCKET_RELIABLE = 0, SOCKET_UNRELIABLE = 1, SOCKET_PING = 2, SOCKET_PONG = 3, SOCKET_RESUME = 4, SOCKET_READY = 5, SOCKET_COUNTDOWN = 6, SOCKET_PLAYTEST=7, SOCKET_VOICE = 8, SOCKET_WORLD = 9, SOCKET_DEVICE = 10;
|
|
10
10
|
/** The messages outside the game protocol: the server's word on where to load, the client's that it has, and the server's that a new build is coming (J174). */
|
|
11
|
-
export type SocketControl = 'resume' | 'ready' | 'countdown' | 'playtest' | 'voice' | 'world';
|
|
11
|
+
export type SocketControl = 'resume' | 'ready' | 'countdown' | 'playtest' | 'voice' | 'world' | 'device';
|
|
12
12
|
/** GO4: the door's first word on every socket, before any hello: how many grid cells it hosts and, since opus-route2, the shard each
|
|
13
13
|
* one runs, and nothing else (D7 keeps `/health` off the rooms address, so a page learns this here). A one-shard page joins only a
|
|
14
14
|
* world that names its shard. A build from before it ignores the prefix. */
|
|
15
|
-
export interface WorldWord { readonly cells: number; readonly shards: readonly string[]
|
|
15
|
+
export interface WorldWord { readonly cells: number; readonly shards: readonly string[];
|
|
16
|
+
/** DEVICE-TELEMETRY DT3: 1 when this door reads the client's `device` word (deviceWord.ts). An older door never says it, and closes
|
|
17
|
+
* `refused` on a prefix it does not know, so a client sends the word only after hearing this. */
|
|
18
|
+
readonly device?: 1 }
|
|
16
19
|
/** J218: a voice word is JSON in a few hundred bytes; an SDP travels in pieces of this many characters, under the room's 1024-byte cap. */
|
|
17
20
|
export const VOICE_PIECE_CHARS = 400;
|
|
18
21
|
/** The server sends no frame while this much is waiting (E7.1). Delta-against-ack heals, and the next frame is just bigger. */
|
|
@@ -43,7 +46,7 @@ export function closeReason(code: number): string {
|
|
|
43
46
|
/** The prefix of a game message on `channel`. */
|
|
44
47
|
export const channelPrefix = (channel: NetChannel): number => channel === 'reliable' ? SOCKET_RELIABLE : SOCKET_UNRELIABLE;
|
|
45
48
|
/** The prefix of a control message. */
|
|
46
|
-
export const controlPrefix = (control: SocketControl): number => control === 'resume' ? SOCKET_RESUME : control === 'ready' ? SOCKET_READY : control==='playtest'?SOCKET_PLAYTEST:control === 'voice' ? SOCKET_VOICE : control === 'world' ? SOCKET_WORLD : SOCKET_COUNTDOWN;
|
|
49
|
+
export const controlPrefix = (control: SocketControl): number => control === 'resume' ? SOCKET_RESUME : control === 'ready' ? SOCKET_READY : control==='playtest'?SOCKET_PLAYTEST:control === 'voice' ? SOCKET_VOICE : control === 'world' ? SOCKET_WORLD : control === 'device' ? SOCKET_DEVICE : SOCKET_COUNTDOWN;
|
|
47
50
|
/** J174: seconds until everyone moves, and the build they move to, which a client preloads. */
|
|
48
51
|
export interface Countdown { readonly seconds: number; readonly build: string }
|
|
49
52
|
/** A `countdown` word. */
|
|
@@ -16,6 +16,8 @@ export interface CatalogueDocument {
|
|
|
16
16
|
/** Parsed by `parseGridCatalogue`, which owns its shape. */
|
|
17
17
|
readonly grid: {readonly cells: readonly {readonly instance: string; readonly slug: string}[]};
|
|
18
18
|
readonly shards?: readonly CatalogueHead[];
|
|
19
|
+
/** The slugs a released page's placement file added to `grid` at runtime (SA33's file, `placedCells.ts`); never in a baked copy. */
|
|
20
|
+
readonly placed?: readonly string[];
|
|
19
21
|
}
|
|
20
22
|
|
|
21
23
|
const SLOT = Symbol.for('game.catalogue');
|
|
@@ -62,3 +64,8 @@ export function autoPlaced(row: {readonly slug: string}): boolean {
|
|
|
62
64
|
if (catalogue === undefined || catalogue.placements.some(placed => bareSlug(placed.slug) === bareSlug(row.slug))) return false;
|
|
63
65
|
return catalogue.grid.cells.some(cell => bareSlug(cell.slug) === bareSlug(row.slug));
|
|
64
66
|
}
|
|
67
|
+
/** A shard the API placed on this channel after the build (the placement file's cell, `placedCells.ts`): Shard Select cards it, an open
|
|
68
|
+
* plot or an auto-placed shard too, because with no crossing (staging's default) its card and `?chunk=` are the only ways in. */
|
|
69
|
+
export function placedByFile(row: {readonly slug: string}): boolean {
|
|
70
|
+
return installedCatalogue()?.placed?.some(slug => bareSlug(slug) === bareSlug(row.slug)) === true;
|
|
71
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// SA33's placement file, read by both ends: the box (`src/server/host/dedicated/placementFile.ts`, Node's key check) and a released page
|
|
2
|
+
// (`src/client/game/grid/placedCells.ts`, WebCrypto). Game layer, so the page's grid code may read it.
|
|
3
|
+
import * as v from 'valibot';
|
|
4
|
+
/** SA33's placement file (`releases/<channel>-placements.json`), as the API signs it under its own placement key: every cell the API
|
|
5
|
+
* placed on one channel, in its grid's order. Read by both ends, as the release file is: the box by Node's key check
|
|
6
|
+
* (`placementFile.ts`), a released page by WebCrypto (`src/client/game/grid/placedCells.ts`). */
|
|
7
|
+
export interface PlacementFile {
|
|
8
|
+
/** Which kind of signed file this is, so a body can never be read as another kind's. */
|
|
9
|
+
readonly kind: 'placement';
|
|
10
|
+
readonly channel: 'production' | 'staging';
|
|
11
|
+
/** Rises with every write; an older file is never believed (J179). */
|
|
12
|
+
readonly serial: number;
|
|
13
|
+
readonly cells: readonly { readonly instance: string; readonly slug: string; readonly cell: readonly [number, number] }[];
|
|
14
|
+
}
|
|
15
|
+
const placedId = v.pipe(v.string(), v.regex(/^_?[a-z0-9]+(?:-[a-z0-9]+)*$/u), v.maxLength(64));
|
|
16
|
+
const placedSpot = v.pipe(v.number(), v.integer());
|
|
17
|
+
/** A placement file's body, once its signature has held. The spot's bounds are `placeCell`'s. */
|
|
18
|
+
export const PlacementSchema: v.GenericSchema<PlacementFile> = v.object({ kind: v.literal('placement'), channel: v.picklist(['production', 'staging']), serial: v.pipe(v.number(), v.integer(), v.minValue(0)),
|
|
19
|
+
cells: v.pipe(v.array(v.object({ instance: placedId, slug: placedId, cell: v.tuple([placedSpot, placedSpot]) })), v.maxLength(49)) });
|
|
20
|
+
/** The file on R2: the body as signed, and its signature in hex (as the release file's, `releaseRows.ts`). */
|
|
21
|
+
export const SignedPlacementSchema: v.GenericSchema<{ readonly body: string; readonly signature: string }> = v.object({ body: v.string(), signature: v.string() });
|
|
22
|
+
/** The API's placement key (SA33a, `~/.config/wildshard/placement-signing-key.pub.pem`), SPKI DER in hex: the box's PLACEMENT_PUBLIC_KEY. */
|
|
23
|
+
export const PLACEMENT_PUBLIC_KEY = '302a300506032b65700321004afd39342aac6a4de6066cb72e9df54cbd3d4eb522e5e6e175a17954ab98f25e';
|
|
24
|
+
/** A channel's placement file beside its release file: `…/releases/staging.json` → `…/releases/staging-placements.json`. Null for
|
|
25
|
+
* any other address, and for preview, whose page bakes staging's cells at deploy instead (SA35). */
|
|
26
|
+
export function placementsURL(release: string): string | null {
|
|
27
|
+
let url: URL;
|
|
28
|
+
try { url = new URL(release); } catch { return null; }
|
|
29
|
+
const channel = /^\/releases\/(staging|production)\.json$/u.exec(url.pathname)?.[1];
|
|
30
|
+
if (channel === undefined || url.search !== '' || url.hash !== '') return null;
|
|
31
|
+
url.pathname = `/releases/${channel}-placements.json`;
|
|
32
|
+
return url.href;
|
|
33
|
+
}
|