@thoughts-on-things/beacon-protocol 0.0.0-stage → 0.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.
- package/LICENSE +201 -0
- package/README.md +27 -2
- package/dist/beacon-management.d.ts +203 -0
- package/dist/beacon-management.d.ts.map +1 -0
- package/dist/beacon-management.js +94 -0
- package/dist/beacon-management.js.map +1 -0
- package/dist/directory.d.ts +100 -0
- package/dist/directory.d.ts.map +1 -0
- package/dist/directory.js +12 -0
- package/dist/directory.js.map +1 -0
- package/dist/fixtures.d.ts +141 -0
- package/dist/fixtures.d.ts.map +1 -0
- package/dist/fixtures.js +141 -0
- package/dist/fixtures.js.map +1 -0
- package/dist/index.d.ts +430 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +455 -0
- package/dist/index.js.map +1 -0
- package/dist/mod-relay.d.ts +26 -0
- package/dist/mod-relay.d.ts.map +1 -0
- package/dist/mod-relay.js +79 -0
- package/dist/mod-relay.js.map +1 -0
- package/dist/play.d.ts +57 -0
- package/dist/play.d.ts.map +1 -0
- package/dist/play.js +122 -0
- package/dist/play.js.map +1 -0
- package/dist/publish.d.ts +117 -0
- package/dist/publish.d.ts.map +1 -0
- package/dist/publish.js +133 -0
- package/dist/publish.js.map +1 -0
- package/package.json +66 -3
- package/src/beacon-management.ts +210 -0
- package/src/directory.ts +115 -0
- package/src/fixtures.ts +169 -0
- package/src/index.ts +538 -0
- package/src/mod-relay.ts +125 -0
- package/src/play.ts +152 -0
- package/src/publish.ts +237 -0
package/dist/play.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
// The `beacon://play` deep-link contract.
|
|
2
|
+
//
|
|
3
|
+
// A beacon's "Play" button encodes a loadout *and the beacon's own origin* so
|
|
4
|
+
// the launcher (or `beacon play`) knows which beacon to fetch the loadout
|
|
5
|
+
// manifest from — loadouts live on each beacon's web app, not on Atlas. This
|
|
6
|
+
// is a bilateral wire contract: apps/web builds the link, the launcher/CLI
|
|
7
|
+
// parse it. It lives in `@thoughts-on-things/beacon-protocol` (not the launch engine) so the web
|
|
8
|
+
// side can build links without depending on the launcher.
|
|
9
|
+
//
|
|
10
|
+
// Format: `beacon://play/<loadoutId>?host=<url-encoded beacon origin>`
|
|
11
|
+
// e.g. `beacon://play/lo_8fa2c1?host=https%3A%2F%2Fplay.example`
|
|
12
|
+
//
|
|
13
|
+
// The link carries NO credential. Member-only access is authorized by the
|
|
14
|
+
// launcher's own first-party Beacon session — a silent, Atlas-brokered link the
|
|
15
|
+
// launcher establishes per beacon (see apps/launcher/src/lib/beacon-session.ts
|
|
16
|
+
// and apps/web/src/app/auth/launcher/*) and presents as `Authorization: Bearer`
|
|
17
|
+
// on the manifest fetch. So the same link works whether or not the loadout is
|
|
18
|
+
// public, and a stale link can never carry a dead token.
|
|
19
|
+
/**
|
|
20
|
+
* Validate an untrusted `GET /api/play` payload into an {@link ActivePlayTarget},
|
|
21
|
+
* or null if it isn't one. Mirrors the defensive parsing the launcher applies to
|
|
22
|
+
* any beacon-served JSON.
|
|
23
|
+
*/
|
|
24
|
+
export function parseActivePlayTarget(data) {
|
|
25
|
+
if (typeof data !== "object" || data === null)
|
|
26
|
+
return null;
|
|
27
|
+
const raw = data;
|
|
28
|
+
if (typeof raw.loadoutId !== "string" || !raw.loadoutId)
|
|
29
|
+
return null;
|
|
30
|
+
if (typeof raw.name !== "string")
|
|
31
|
+
return null;
|
|
32
|
+
if (typeof raw.loader !== "string")
|
|
33
|
+
return null;
|
|
34
|
+
if (typeof raw.mcVersion !== "string")
|
|
35
|
+
return null;
|
|
36
|
+
if (typeof raw.launchable !== "boolean")
|
|
37
|
+
return null;
|
|
38
|
+
if (typeof raw.shared !== "boolean")
|
|
39
|
+
return null;
|
|
40
|
+
return {
|
|
41
|
+
loadoutId: raw.loadoutId,
|
|
42
|
+
name: raw.name,
|
|
43
|
+
summary: typeof raw.summary === "string" ? raw.summary : null,
|
|
44
|
+
loader: raw.loader,
|
|
45
|
+
mcVersion: raw.mcVersion,
|
|
46
|
+
launchable: raw.launchable,
|
|
47
|
+
shared: raw.shared,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/** The `play` action segment — `beacon://play/...`. */
|
|
51
|
+
const PLAY_ACTION = "play";
|
|
52
|
+
/**
|
|
53
|
+
* Build a `beacon://play` deep link. Throws if `beaconOrigin` is not a valid
|
|
54
|
+
* http(s) origin or `loadoutId` is empty — both are programming errors at the
|
|
55
|
+
* call site (the web Play button always has a real origin + id).
|
|
56
|
+
*/
|
|
57
|
+
export function buildPlayUri(target) {
|
|
58
|
+
const origin = normalizeOrigin(target.beaconOrigin);
|
|
59
|
+
if (!origin) {
|
|
60
|
+
throw new Error(`buildPlayUri: invalid beacon origin "${target.beaconOrigin}"`);
|
|
61
|
+
}
|
|
62
|
+
const id = target.loadoutId.trim();
|
|
63
|
+
if (!id)
|
|
64
|
+
throw new Error("buildPlayUri: loadoutId is required");
|
|
65
|
+
const params = new URLSearchParams({ host: origin });
|
|
66
|
+
return `beacon://${PLAY_ACTION}/${encodeURIComponent(id)}?${params.toString()}`;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Parse a `beacon://play` deep link. Returns null for anything that isn't a
|
|
70
|
+
* well-formed play link carrying a loadout id and a valid http(s) `host`
|
|
71
|
+
* origin — a malformed or hostile link simply doesn't resolve.
|
|
72
|
+
*/
|
|
73
|
+
export function parsePlayUri(uri) {
|
|
74
|
+
let url;
|
|
75
|
+
try {
|
|
76
|
+
url = new URL(uri);
|
|
77
|
+
}
|
|
78
|
+
catch {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
if (url.protocol !== "beacon:")
|
|
82
|
+
return null;
|
|
83
|
+
// `beacon://play/<id>` parses with hostname === "play".
|
|
84
|
+
if (url.hostname !== PLAY_ACTION)
|
|
85
|
+
return null;
|
|
86
|
+
const firstSegment = url.pathname.split("/").filter(Boolean)[0];
|
|
87
|
+
if (!firstSegment)
|
|
88
|
+
return null;
|
|
89
|
+
const loadoutId = safeDecode(firstSegment);
|
|
90
|
+
if (!loadoutId)
|
|
91
|
+
return null;
|
|
92
|
+
const host = url.searchParams.get("host");
|
|
93
|
+
if (!host)
|
|
94
|
+
return null;
|
|
95
|
+
const beaconOrigin = normalizeOrigin(host);
|
|
96
|
+
if (!beaconOrigin)
|
|
97
|
+
return null;
|
|
98
|
+
return { beaconOrigin, loadoutId };
|
|
99
|
+
}
|
|
100
|
+
/** Validate + normalize an http(s) origin (drops any path/query/fragment).
|
|
101
|
+
* Returns null for anything that isn't http or https. */
|
|
102
|
+
function normalizeOrigin(value) {
|
|
103
|
+
let url;
|
|
104
|
+
try {
|
|
105
|
+
url = new URL(value);
|
|
106
|
+
}
|
|
107
|
+
catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
111
|
+
return null;
|
|
112
|
+
return url.origin;
|
|
113
|
+
}
|
|
114
|
+
function safeDecode(value) {
|
|
115
|
+
try {
|
|
116
|
+
return decodeURIComponent(value);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return "";
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
//# sourceMappingURL=play.js.map
|
package/dist/play.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"play.js","sourceRoot":"","sources":["../src/play.ts"],"names":[],"mappings":"AAAA,0CAA0C;AAC1C,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,6EAA6E;AAC7E,2EAA2E;AAC3E,iGAAiG;AACjG,0DAA0D;AAC1D,EAAE;AACF,uEAAuE;AACvE,oEAAoE;AACpE,EAAE;AACF,0EAA0E;AAC1E,gFAAgF;AAChF,+EAA+E;AAC/E,gFAAgF;AAChF,8EAA8E;AAC9E,yDAAyD;AA0CzD;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,IAAa;IACjD,IAAI,OAAO,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AAY,EAAE,SAAS,EAAE,CAAC;AACrC,CAAC;AAED;0DAC0D;AAC1D,SAAS,eAAe,CAAC,KAAa;IACpC,IAAI,GAAQ,CAAC;IACb,IAAI,CAAC;QACH,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;IACD,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,QAAQ;QAAE,OAAO,IAAI,CAAC;IACvE,OAAO,GAAG,CAAC,MAAM,CAAC;AACpB,CAAC;AAED,SAAS,UAAU,CAAC,KAAa;IAC/B,IAAI,CAAC;QACH,OAAO,kBAAkB,CAAC,KAAK,CAAC,CAAC;IACnC,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,EAAE,CAAC;IACZ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { type Heartbeat, type Loader, type RosterEntry, type ActivityEntry, type VantageStream } from "./index.js";
|
|
2
|
+
/** The `settings` table key the beacon stores its Atlas listing config under. */
|
|
3
|
+
export declare const ATLAS_LISTING_KEY = "atlas_listing";
|
|
4
|
+
/** The project-owned public Atlas a new beacon offers by default. */
|
|
5
|
+
export declare const CANONICAL_ATLAS_URL = "https://beacon-mc.io";
|
|
6
|
+
/**
|
|
7
|
+
* What the beacon stores LOCALLY about its Atlas listing. Identity, credentials,
|
|
8
|
+
* and every profile field live elsewhere: the single `client_id`/`client_secret`
|
|
9
|
+
* (env) is the beacon's identity for login, heartbeat, AND directory management,
|
|
10
|
+
* and Atlas is the authoritative source of profile content and visibility. So
|
|
11
|
+
* the beacon only needs two local facts: whether listing is on (the publisher's
|
|
12
|
+
* no-op gate) and the slug Atlas minted (for the `/b/<slug>` deep-link).
|
|
13
|
+
*/
|
|
14
|
+
export interface AtlasListingSettings {
|
|
15
|
+
/** Operator opt-in to public listing. The publisher skips while false. */
|
|
16
|
+
enabled: boolean;
|
|
17
|
+
/** The public slug Atlas minted, for the `/b/<slug>` deep-link. Empty until known. */
|
|
18
|
+
slug: string;
|
|
19
|
+
/**
|
|
20
|
+
* Explicit opt-in to serving this world through the public Atlas profile.
|
|
21
|
+
* The stream stays on the Beacon; Atlas stores only the capability advertised
|
|
22
|
+
* in the heartbeat. Off by default because explored terrain is sensitive.
|
|
23
|
+
*/
|
|
24
|
+
publishMap: boolean;
|
|
25
|
+
}
|
|
26
|
+
export declare const DEFAULT_ATLAS_LISTING: AtlasListingSettings;
|
|
27
|
+
/**
|
|
28
|
+
* Server-derived facts and live state the publisher gathers, passed to
|
|
29
|
+
* {@link projectHeartbeat}. Nothing here is operator-typed: it is read
|
|
30
|
+
* from the running server itself.
|
|
31
|
+
*
|
|
32
|
+
* `peak7d` and `uptimePct` are deliberately *not* here: rolling history is
|
|
33
|
+
* computed Atlas-side from the heartbeat stream so there is a single source
|
|
34
|
+
* of truth for the public profile's time-series panels. Vantage publishes only
|
|
35
|
+
* a tiny capability here; manifests, textures, and tiles stay on the Beacon.
|
|
36
|
+
*/
|
|
37
|
+
export interface ProjectionInputs {
|
|
38
|
+
beaconId: string;
|
|
39
|
+
server: {
|
|
40
|
+
/** Minecraft version string. */
|
|
41
|
+
mcVersion: string;
|
|
42
|
+
/** Mod loader / server software. */
|
|
43
|
+
loader: Loader;
|
|
44
|
+
/** Installed mod / plugin names. */
|
|
45
|
+
mods: string[];
|
|
46
|
+
/** Server render distance, in chunks, when known. */
|
|
47
|
+
renderDistance?: number;
|
|
48
|
+
/** How long the current world has existed, in days, when known. */
|
|
49
|
+
worldAgeDays?: number;
|
|
50
|
+
/** On-disk world size, in mebibytes, when known. */
|
|
51
|
+
worldSizeMib?: number;
|
|
52
|
+
/** Federated Vantage stream, present only while public streaming is live.
|
|
53
|
+
* Typed off the wire schema so a new capability field lands here without
|
|
54
|
+
* a second declaration to keep in step — the allowlist stays by
|
|
55
|
+
* construction, it just names one shape instead of restating it. */
|
|
56
|
+
vantage?: VantageStream;
|
|
57
|
+
};
|
|
58
|
+
status: {
|
|
59
|
+
online: boolean;
|
|
60
|
+
playersOnline: number;
|
|
61
|
+
playersMax: number;
|
|
62
|
+
/** Ticks per second, when RCON answered. */
|
|
63
|
+
tps?: number;
|
|
64
|
+
/** Seconds since the Minecraft process started, when known. */
|
|
65
|
+
uptimeSeconds?: number;
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* Optional opt-in player data. Always forwarded when present; the Atlas
|
|
69
|
+
* applies the `consent_roster` / `consent_activity` listing toggles as a
|
|
70
|
+
* defense-in-depth filter so the publisher need only know whether it has
|
|
71
|
+
* data to send, not what the operator marked consent-wise on the Atlas
|
|
72
|
+
* dashboard. (A future beacon-side opt-in toggle is a separate change.)
|
|
73
|
+
*/
|
|
74
|
+
consent?: {
|
|
75
|
+
roster?: RosterEntry[];
|
|
76
|
+
activity?: ActivityEntry[];
|
|
77
|
+
};
|
|
78
|
+
/** When the status was sampled. */
|
|
79
|
+
sampledAt: Date;
|
|
80
|
+
}
|
|
81
|
+
export type ProjectionResult = {
|
|
82
|
+
ok: true;
|
|
83
|
+
heartbeat: Heartbeat;
|
|
84
|
+
} | {
|
|
85
|
+
ok: false;
|
|
86
|
+
error: string;
|
|
87
|
+
};
|
|
88
|
+
/**
|
|
89
|
+
* Project the beacon's runtime state into a validated {@link Heartbeat}.
|
|
90
|
+
*
|
|
91
|
+
* The result is run through `heartbeatSchema` before it is returned, so the
|
|
92
|
+
* heartbeat is sanitized and length-checked exactly as the Atlas will check
|
|
93
|
+
* it: a preview rendered from this is byte-identical to what the publisher
|
|
94
|
+
* sends, and a runtime value that violates the contract surfaces as an
|
|
95
|
+
* `ok: false` error the settings card can show: not a rejected POST later.
|
|
96
|
+
*/
|
|
97
|
+
export declare function projectHeartbeat(inputs: ProjectionInputs): ProjectionResult;
|
|
98
|
+
/**
|
|
99
|
+
* Coerce an untrusted `settings` JSON blob into a well-formed
|
|
100
|
+
* {@link AtlasListingSettings}. Every field defaults, so a partial or corrupt
|
|
101
|
+
* row never throws.
|
|
102
|
+
*/
|
|
103
|
+
export declare function normalizeAtlasListing(input: unknown): AtlasListingSettings;
|
|
104
|
+
/**
|
|
105
|
+
* Whether the beacon should advertise its public Vantage stream: the listing
|
|
106
|
+
* must be enabled (publishing at all) and the operator must have opted the map
|
|
107
|
+
* in. Atlas applies `privacy.coords` as the final display gate.
|
|
108
|
+
*/
|
|
109
|
+
export declare function shouldPublishMap(listing: AtlasListingSettings): boolean;
|
|
110
|
+
/**
|
|
111
|
+
* Whether the operator opted into public listing. Local settings-level gate
|
|
112
|
+
* only; the publisher and dashboard additionally require the client credentials
|
|
113
|
+
* in env (a beacon with none can't authenticate to Atlas). Atlas's own `listed`
|
|
114
|
+
* flag is the authoritative directory-visibility source.
|
|
115
|
+
*/
|
|
116
|
+
export declare function isPublishable(listing: AtlasListingSettings): boolean;
|
|
117
|
+
//# sourceMappingURL=publish.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.d.ts","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAgBA,OAAO,EAGL,KAAK,SAAS,EACd,KAAK,MAAM,EACX,KAAK,WAAW,EAChB,KAAK,aAAa,EAClB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,eAAO,MAAM,iBAAiB,kBAAkB,CAAC;AAEjD,qEAAqE;AACrE,eAAO,MAAM,mBAAmB,yBAAyB,CAAC;AAE1D;;;;;;;GAOG;AACH,MAAM,WAAW,oBAAoB;IACnC,0EAA0E;IAC1E,OAAO,EAAE,OAAO,CAAC;IACjB,sFAAsF;IACtF,IAAI,EAAE,MAAM,CAAC;IACb;;;;OAIG;IACH,UAAU,EAAE,OAAO,CAAC;CACrB;AAED,eAAO,MAAM,qBAAqB,EAAE,oBAInC,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,E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;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,OAAO,CAEpE"}
|
package/dist/publish.js
ADDED
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
// Beacon-side publishing: the projector that turns a beacon's runtime state
|
|
2
|
+
// into a wire {@link Heartbeat}.
|
|
3
|
+
//
|
|
4
|
+
// This module is the *single* place a beacon decides what to publish about
|
|
5
|
+
// itself. The field allowlist is enforced by construction: `projectHeartbeat`
|
|
6
|
+
// reads only the explicit fields below, so a coordinate, an invite code, an
|
|
7
|
+
// operator account, or any operator-typed identity field simply has no path
|
|
8
|
+
// onto the wire — there is no field to carry it. Atlas owns every operator-
|
|
9
|
+
// typed identity (name, addresses, locations, profile copy, privacy, …); the
|
|
10
|
+
// beacon publishes only what its running server measures.
|
|
11
|
+
//
|
|
12
|
+
// Both sides of the beacon use this module: the `apps/web` settings card runs
|
|
13
|
+
// it to render the "what the world sees" preview, and the `apps/admin-rpc`
|
|
14
|
+
// publisher job runs it to build the heartbeat it POSTs. Because it is one
|
|
15
|
+
// pure function, the preview is byte-identical to what is published.
|
|
16
|
+
import { buildHeartbeat, heartbeatSchema, } from "./index.js";
|
|
17
|
+
/** The `settings` table key the beacon stores its Atlas listing config under. */
|
|
18
|
+
export const ATLAS_LISTING_KEY = "atlas_listing";
|
|
19
|
+
/** The project-owned public Atlas a new beacon offers by default. */
|
|
20
|
+
export const CANONICAL_ATLAS_URL = "https://beacon-mc.io";
|
|
21
|
+
export const DEFAULT_ATLAS_LISTING = {
|
|
22
|
+
enabled: false,
|
|
23
|
+
slug: "",
|
|
24
|
+
publishMap: false,
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Project the beacon's runtime state into a validated {@link Heartbeat}.
|
|
28
|
+
*
|
|
29
|
+
* The result is run through `heartbeatSchema` before it is returned, so the
|
|
30
|
+
* heartbeat is sanitized and length-checked exactly as the Atlas will check
|
|
31
|
+
* it: a preview rendered from this is byte-identical to what the publisher
|
|
32
|
+
* sends, and a runtime value that violates the contract surfaces as an
|
|
33
|
+
* `ok: false` error the settings card can show: not a rejected POST later.
|
|
34
|
+
*/
|
|
35
|
+
export function projectHeartbeat(inputs) {
|
|
36
|
+
const { server, status, consent } = inputs;
|
|
37
|
+
const manifest = {
|
|
38
|
+
mcVersion: server.mcVersion,
|
|
39
|
+
loader: server.loader,
|
|
40
|
+
mods: server.mods,
|
|
41
|
+
...(server.renderDistance !== undefined
|
|
42
|
+
? { renderDistance: server.renderDistance }
|
|
43
|
+
: {}),
|
|
44
|
+
...(server.worldAgeDays !== undefined
|
|
45
|
+
? { worldAgeDays: server.worldAgeDays }
|
|
46
|
+
: {}),
|
|
47
|
+
...(server.worldSizeMib !== undefined
|
|
48
|
+
? { worldSizeMib: server.worldSizeMib }
|
|
49
|
+
: {}),
|
|
50
|
+
...(server.vantage !== undefined ? { vantage: server.vantage } : {}),
|
|
51
|
+
};
|
|
52
|
+
const profile = consent && (consent.roster?.length || consent.activity?.length)
|
|
53
|
+
? {
|
|
54
|
+
...(consent.roster?.length ? { roster: consent.roster } : {}),
|
|
55
|
+
...(consent.activity?.length ? { activity: consent.activity } : {}),
|
|
56
|
+
}
|
|
57
|
+
: undefined;
|
|
58
|
+
const built = buildHeartbeat(inputs.beaconId, manifest, {
|
|
59
|
+
online: status.online,
|
|
60
|
+
playersOnline: status.playersOnline,
|
|
61
|
+
playersMax: status.playersMax,
|
|
62
|
+
...(status.tps !== undefined ? { tps: status.tps } : {}),
|
|
63
|
+
...(status.uptimeSeconds !== undefined
|
|
64
|
+
? { uptimeSeconds: status.uptimeSeconds }
|
|
65
|
+
: {}),
|
|
66
|
+
sampledAt: inputs.sampledAt.toISOString(),
|
|
67
|
+
}, profile);
|
|
68
|
+
const parsed = heartbeatSchema.safeParse(built);
|
|
69
|
+
if (!parsed.success) {
|
|
70
|
+
const error = parsed.error.issues
|
|
71
|
+
.map((issue) => `${issue.path.join(".") || "(root)"}: ${issue.message}`)
|
|
72
|
+
.join("; ");
|
|
73
|
+
return { ok: false, error };
|
|
74
|
+
}
|
|
75
|
+
return { ok: true, heartbeat: parsed.data };
|
|
76
|
+
}
|
|
77
|
+
// ---------------------------------------------------------------------------
|
|
78
|
+
// Settings normalization
|
|
79
|
+
// ---------------------------------------------------------------------------
|
|
80
|
+
/**
|
|
81
|
+
* Coerce an untrusted `settings` JSON blob into a well-formed
|
|
82
|
+
* {@link AtlasListingSettings}. Every field defaults, so a partial or corrupt
|
|
83
|
+
* row never throws.
|
|
84
|
+
*/
|
|
85
|
+
export function normalizeAtlasListing(input) {
|
|
86
|
+
const r = isRecord(input) ? input : {};
|
|
87
|
+
return {
|
|
88
|
+
enabled: parseBool(r.enabled, false),
|
|
89
|
+
slug: cleanString(r.slug, "", 64),
|
|
90
|
+
publishMap: parseBool(r.publishMap, false),
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Whether the beacon should advertise its public Vantage stream: the listing
|
|
95
|
+
* must be enabled (publishing at all) and the operator must have opted the map
|
|
96
|
+
* in. Atlas applies `privacy.coords` as the final display gate.
|
|
97
|
+
*/
|
|
98
|
+
export function shouldPublishMap(listing) {
|
|
99
|
+
return listing.enabled && listing.publishMap;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Whether the operator opted into public listing. Local settings-level gate
|
|
103
|
+
* only; the publisher and dashboard additionally require the client credentials
|
|
104
|
+
* in env (a beacon with none can't authenticate to Atlas). Atlas's own `listed`
|
|
105
|
+
* flag is the authoritative directory-visibility source.
|
|
106
|
+
*/
|
|
107
|
+
export function isPublishable(listing) {
|
|
108
|
+
return listing.enabled;
|
|
109
|
+
}
|
|
110
|
+
function isRecord(value) {
|
|
111
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
112
|
+
}
|
|
113
|
+
function parseBool(value, fallback) {
|
|
114
|
+
if (typeof value === "boolean")
|
|
115
|
+
return value;
|
|
116
|
+
if (typeof value === "string") {
|
|
117
|
+
const v = value.trim().toLowerCase();
|
|
118
|
+
if (["on", "true", "1", "yes"].includes(v))
|
|
119
|
+
return true;
|
|
120
|
+
if (["off", "false", "0", "no", ""].includes(v))
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
if (value === null || value === undefined)
|
|
124
|
+
return fallback;
|
|
125
|
+
return Boolean(value);
|
|
126
|
+
}
|
|
127
|
+
function cleanString(value, fallback, max) {
|
|
128
|
+
if (typeof value !== "string")
|
|
129
|
+
return fallback;
|
|
130
|
+
const t = value.normalize("NFC").replace(/\s+/g, " ").trim();
|
|
131
|
+
return t.length > max ? t.slice(0, max) : t;
|
|
132
|
+
}
|
|
133
|
+
//# sourceMappingURL=publish.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish.js","sourceRoot":"","sources":["../src/publish.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,iCAAiC;AACjC,EAAE;AACF,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,4EAA4E;AAC5E,4EAA4E;AAC5E,6EAA6E;AAC7E,0DAA0D;AAC1D,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,2EAA2E;AAC3E,qEAAqE;AAErE,OAAO,EACL,cAAc,EACd,eAAe,GAMhB,MAAM,YAAY,CAAC;AAEpB,iFAAiF;AACjF,MAAM,CAAC,MAAM,iBAAiB,GAAG,eAAe,CAAC;AAEjD,qEAAqE;AACrE,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAuB1D,MAAM,CAAC,MAAM,qBAAqB,GAAyB;IACzD,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,EAAE;IACR,UAAU,EAAE,KAAK;CAClB,CAAC;AA6DF;;;;;;;;GAQG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAwB;IACvD,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,CAAC;IAE3C,MAAM,QAAQ,GAAG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AE,GAAW;IAChE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,QAAQ,CAAC;IAC/C,MAAM,CAAC,GAAG,KAAK,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7D,OAAO,CAAC,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,69 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thoughts-on-things/beacon-protocol",
|
|
3
|
-
"version": "0.0.0
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Wire contract between a Beacon server and Beacon Atlas: Zod schemas and types for heartbeats, listings, play links and the mod relay.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://beacon-mc.io",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/thoughts-on-things/beacon-mc.git",
|
|
10
|
+
"directory": "packages/beacon-protocol"
|
|
11
|
+
},
|
|
12
|
+
"bugs": "https://github.com/thoughts-on-things/beacon-mc/issues",
|
|
13
|
+
"type": "module",
|
|
14
|
+
"main": "./dist/index.js",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"exports": {
|
|
17
|
+
".": {
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"default": "./dist/index.js"
|
|
20
|
+
},
|
|
21
|
+
"./fixtures": {
|
|
22
|
+
"types": "./dist/fixtures.d.ts",
|
|
23
|
+
"default": "./dist/fixtures.js"
|
|
24
|
+
},
|
|
25
|
+
"./publish": {
|
|
26
|
+
"types": "./dist/publish.d.ts",
|
|
27
|
+
"default": "./dist/publish.js"
|
|
28
|
+
},
|
|
29
|
+
"./management": {
|
|
30
|
+
"types": "./dist/beacon-management.d.ts",
|
|
31
|
+
"default": "./dist/beacon-management.js"
|
|
32
|
+
},
|
|
33
|
+
"./directory": {
|
|
34
|
+
"types": "./dist/directory.d.ts",
|
|
35
|
+
"default": "./dist/directory.js"
|
|
36
|
+
},
|
|
37
|
+
"./play": {
|
|
38
|
+
"types": "./dist/play.d.ts",
|
|
39
|
+
"default": "./dist/play.js"
|
|
40
|
+
},
|
|
41
|
+
"./mod-relay": {
|
|
42
|
+
"types": "./dist/mod-relay.d.ts",
|
|
43
|
+
"default": "./dist/mod-relay.js"
|
|
44
|
+
}
|
|
45
|
+
},
|
|
46
|
+
"dependencies": {
|
|
47
|
+
"zod": "^4.6.7"
|
|
48
|
+
},
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@types/node": "^26.6.11",
|
|
51
|
+
"tsx": "^4.23.15",
|
|
52
|
+
"typescript": "^6.0.3"
|
|
53
|
+
},
|
|
54
|
+
"files": [
|
|
55
|
+
"dist",
|
|
56
|
+
"src",
|
|
57
|
+
"!**/*.test.*",
|
|
58
|
+
"!**/*.tsbuildinfo"
|
|
59
|
+
],
|
|
60
|
+
"publishConfig": {
|
|
61
|
+
"access": "public"
|
|
62
|
+
},
|
|
63
|
+
"scripts": {
|
|
64
|
+
"build": "tsc",
|
|
65
|
+
"typecheck": "tsc --noEmit",
|
|
66
|
+
"test": "tsx --test src/*.test.ts",
|
|
67
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo"
|
|
68
|
+
}
|
|
6
69
|
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// The beacon management contract: what an operator can edit on their beacon's
|
|
2
|
+
// Atlas record, and the shape Atlas returns describing it. Single definition so
|
|
3
|
+
// `apps/web` (dashboard) and Beacon Atlas (endpoint) bind to one contract and
|
|
4
|
+
// can't drift. This is the authenticated control plane the operator drives by
|
|
5
|
+
// hand, separate from the per-tick wire heartbeat (`./publish`, `./index`).
|
|
6
|
+
|
|
7
|
+
import { z } from "zod";
|
|
8
|
+
import {
|
|
9
|
+
communityLocationSchema,
|
|
10
|
+
difficultySchema,
|
|
11
|
+
eventEntrySchema,
|
|
12
|
+
joinPolicySchema,
|
|
13
|
+
privacySchema,
|
|
14
|
+
sanitizeText,
|
|
15
|
+
serverLocationSchema,
|
|
16
|
+
type CommunityLocation,
|
|
17
|
+
type Difficulty,
|
|
18
|
+
type EventEntry,
|
|
19
|
+
type JoinPolicy,
|
|
20
|
+
type ProfilePrivacy,
|
|
21
|
+
type ServerLocation,
|
|
22
|
+
} from "./index.js";
|
|
23
|
+
|
|
24
|
+
// ── Domain enums ─────────────────────────────────────────────────────────────
|
|
25
|
+
// Defined here (not in the Atlas schema) so table, endpoint, and dashboard all
|
|
26
|
+
// import one definition.
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Lifecycle of a beacon's directory presence. Staleness is NOT a value here: it
|
|
30
|
+
* is derived from the latest heartbeat timestamp at read time so it can't drift
|
|
31
|
+
* from a stored flag. `suspended` is the only non-`active` value written after
|
|
32
|
+
* first heartbeat (moderation).
|
|
33
|
+
*/
|
|
34
|
+
export const BEACON_STATUSES = [
|
|
35
|
+
"pending_verification",
|
|
36
|
+
"active",
|
|
37
|
+
"suspended",
|
|
38
|
+
] as const;
|
|
39
|
+
export type BeaconStatus = (typeof BEACON_STATUSES)[number];
|
|
40
|
+
|
|
41
|
+
/** Triage state of a public report filed against a beacon. */
|
|
42
|
+
export const REPORT_STATUSES = ["open", "reviewed", "dismissed"] as const;
|
|
43
|
+
export type ReportStatus = (typeof REPORT_STATUSES)[number];
|
|
44
|
+
|
|
45
|
+
// ── Field validators ────────────────────────────────────────────────────────
|
|
46
|
+
//
|
|
47
|
+
// A "single line" field collapses whitespace and strips control chars
|
|
48
|
+
// (`sanitizeText`) before length is measured. The host note stays multiline so
|
|
49
|
+
// paragraphs survive. These are the authoritative server-side checks; a form's
|
|
50
|
+
// `maxLength`/`<select>` attributes are only UX hints.
|
|
51
|
+
|
|
52
|
+
const singleLineText = (min: number, max: number) =>
|
|
53
|
+
z.string().transform(sanitizeText).pipe(z.string().min(min).max(max));
|
|
54
|
+
|
|
55
|
+
const optionalSingleLineText = (max: number) =>
|
|
56
|
+
z.union([z.null(), singleLineText(1, max)]).optional();
|
|
57
|
+
|
|
58
|
+
function isHttpsUrl(value: string): boolean {
|
|
59
|
+
try {
|
|
60
|
+
return new URL(value).protocol === "https:";
|
|
61
|
+
} catch {
|
|
62
|
+
return false;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const optionalHttpsUrl = (max: number) =>
|
|
67
|
+
z
|
|
68
|
+
.union([
|
|
69
|
+
z.null(),
|
|
70
|
+
z
|
|
71
|
+
.string()
|
|
72
|
+
.transform((v) => v.trim())
|
|
73
|
+
.pipe(
|
|
74
|
+
z
|
|
75
|
+
.string()
|
|
76
|
+
.min(1)
|
|
77
|
+
.max(max)
|
|
78
|
+
.refine(isHttpsUrl, { message: "must be a valid https:// URL" }),
|
|
79
|
+
),
|
|
80
|
+
])
|
|
81
|
+
.optional();
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Validation contract for every operator-editable field, run on both sides
|
|
85
|
+
* (dashboard before sending, Atlas endpoint before writing). All fields are
|
|
86
|
+
* optional: the editor submits one section at a time, so a partial patch is
|
|
87
|
+
* normal and only the fields sent are written. `status` is deliberately absent:
|
|
88
|
+
* a beacon can flip its own `listed` visibility but cannot self-suspend —
|
|
89
|
+
* moderation is Atlas-internal.
|
|
90
|
+
*/
|
|
91
|
+
export const beaconProfilePatchSchema = z.object({
|
|
92
|
+
// Operator-controlled visibility. The primary public/private toggle.
|
|
93
|
+
listed: z.boolean().optional(),
|
|
94
|
+
|
|
95
|
+
// Directory identity.
|
|
96
|
+
name: singleLineText(3, 48).optional(),
|
|
97
|
+
description: z
|
|
98
|
+
.string()
|
|
99
|
+
.transform(sanitizeText)
|
|
100
|
+
.pipe(z.string().max(160))
|
|
101
|
+
.optional(),
|
|
102
|
+
mcAddress: optionalSingleLineText(120),
|
|
103
|
+
publicUrl: optionalHttpsUrl(200),
|
|
104
|
+
iconUrl: optionalHttpsUrl(300),
|
|
105
|
+
serverLocation: serverLocationSchema.optional(),
|
|
106
|
+
communityLocation: communityLocationSchema.optional(),
|
|
107
|
+
language: singleLineText(1, 16).optional(),
|
|
108
|
+
joinPolicy: joinPolicySchema.optional(),
|
|
109
|
+
tags: z.array(singleLineText(1, 40)).max(20).optional(),
|
|
110
|
+
modpack: optionalSingleLineText(80),
|
|
111
|
+
|
|
112
|
+
// Profile content.
|
|
113
|
+
profileEnabled: z.boolean().optional(),
|
|
114
|
+
hostName: optionalSingleLineText(48),
|
|
115
|
+
vibe: optionalSingleLineText(48),
|
|
116
|
+
difficulty: difficultySchema.nullable().optional(),
|
|
117
|
+
discordUrl: optionalHttpsUrl(200),
|
|
118
|
+
rules: z.array(singleLineText(1, 160)).max(40).optional(),
|
|
119
|
+
noteBody: z.union([z.null(), z.string().max(600)]).optional(),
|
|
120
|
+
events: z.array(eventEntrySchema).max(20).optional(),
|
|
121
|
+
privacy: privacySchema.optional(),
|
|
122
|
+
|
|
123
|
+
// Consent toggles for opt-in player-identity data the beacon may publish.
|
|
124
|
+
consentRoster: z.boolean().optional(),
|
|
125
|
+
consentActivity: z.boolean().optional(),
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
/** A partial edit to a beacon's management record. */
|
|
129
|
+
export type BeaconProfilePatch = z.infer<typeof beaconProfilePatchSchema>;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The fully-resolved profile content (JSON columns parsed, optional structures
|
|
133
|
+
* defaulted) the dashboard renders for editing and host-preview. No value is
|
|
134
|
+
* ever undefined.
|
|
135
|
+
*/
|
|
136
|
+
export interface BeaconProfile {
|
|
137
|
+
name: string;
|
|
138
|
+
description: string;
|
|
139
|
+
mcAddress: string | null;
|
|
140
|
+
publicUrl: string | null;
|
|
141
|
+
iconUrl: string | null;
|
|
142
|
+
serverLocation: ServerLocation;
|
|
143
|
+
communityLocation: CommunityLocation;
|
|
144
|
+
language: string;
|
|
145
|
+
joinPolicy: JoinPolicy;
|
|
146
|
+
tags: string[];
|
|
147
|
+
modpack: string | null;
|
|
148
|
+
profileEnabled: boolean;
|
|
149
|
+
hostName: string | null;
|
|
150
|
+
vibe: string | null;
|
|
151
|
+
difficulty: Difficulty | null;
|
|
152
|
+
discordUrl: string | null;
|
|
153
|
+
rules: string[];
|
|
154
|
+
noteBody: string | null;
|
|
155
|
+
events: EventEntry[];
|
|
156
|
+
privacy: ProfilePrivacy;
|
|
157
|
+
consentRoster: boolean;
|
|
158
|
+
consentActivity: boolean;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/** The latest heartbeat summary, surfaced so the dashboard can show liveness. */
|
|
162
|
+
export interface ManagementSnapshot {
|
|
163
|
+
/** Epoch ms of the last heartbeat, or null if the beacon has never sent one. */
|
|
164
|
+
lastHeartbeatAt: number | null;
|
|
165
|
+
online: boolean;
|
|
166
|
+
playersOnline: number;
|
|
167
|
+
playersMax: number;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/** A public report filed against this beacon, surfaced read-only to the host. */
|
|
171
|
+
export interface ManagementReport {
|
|
172
|
+
id: string;
|
|
173
|
+
reason: string;
|
|
174
|
+
detail: string | null;
|
|
175
|
+
status: ReportStatus;
|
|
176
|
+
/** Epoch ms. */
|
|
177
|
+
createdAt: number;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* The full management view of a beacon, returned by `GET /api/auth/beacon/me`:
|
|
182
|
+
* identity + visibility + parsed profile (unredacted — the host's own view) +
|
|
183
|
+
* latest liveness + reports. The dashboard renders entirely from this.
|
|
184
|
+
*/
|
|
185
|
+
export interface ManagementView {
|
|
186
|
+
/** The `client_id`: the beacon's single identity. */
|
|
187
|
+
id: string;
|
|
188
|
+
/** Display name (also the registration name). */
|
|
189
|
+
name: string;
|
|
190
|
+
/** Public directory slug; the `/b/<slug>` profile lives here when listed. */
|
|
191
|
+
slug: string;
|
|
192
|
+
/** Absolute `<issuer>/b/<slug>` deep-link to the public profile. */
|
|
193
|
+
profileUrl: string;
|
|
194
|
+
/** Registered OAuth redirect URIs. */
|
|
195
|
+
redirectUris: string[];
|
|
196
|
+
/** Directory lifecycle. */
|
|
197
|
+
status: BeaconStatus;
|
|
198
|
+
/** Whether the operator has opted into public directory listing. */
|
|
199
|
+
listed: boolean;
|
|
200
|
+
/** Epoch ms. */
|
|
201
|
+
createdAt: number;
|
|
202
|
+
/** Epoch ms of the last secret rotation, or null. */
|
|
203
|
+
rotatedAt: number | null;
|
|
204
|
+
/** The parsed, editable profile content (host's unredacted view). */
|
|
205
|
+
profile: BeaconProfile;
|
|
206
|
+
/** Latest heartbeat summary, or null if never seen. */
|
|
207
|
+
snapshot: ManagementSnapshot | null;
|
|
208
|
+
/** Public reports filed against this beacon, newest first. */
|
|
209
|
+
reports: ManagementReport[];
|
|
210
|
+
}
|