@7365admin1/core 3.75.1 → 3.76.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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@7365admin1/core",
3
3
  "license": "MIT",
4
- "version": "3.75.1",
4
+ "version": "3.76.0",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -0,0 +1,163 @@
1
+ /**
2
+ * The server signs the LIVE view link, the same way it already signs recorded
3
+ * footage — and hands it out WITHOUT touching `camera.host`.
4
+ *
5
+ * Both halves are asserted here, and they are different claims:
6
+ *
7
+ * 1. `signLiveLink` produces exactly the string the relay's `playback.js`
8
+ * verifies (the expected signature is recomputed here by hand, not taken
9
+ * from the function under test).
10
+ * 2. The camera payloads this estate actually returns CARRY it — proved
11
+ * through `withLiveLink(publicCameraFields(...))`, the wrapper the wall,
12
+ * the health sweep and the single-camera view all go through.
13
+ */
14
+ import assert from "node:assert/strict";
15
+ import { createHmac } from "node:crypto";
16
+ import { readFileSync } from "node:fs";
17
+ import test from "node:test";
18
+ import { fileURLToPath } from "node:url";
19
+
20
+ import {
21
+ PLAYBACK_LINK_SECONDS,
22
+ signLiveLink,
23
+ signPlaybackLink,
24
+ withLiveLink,
25
+ } from "./.build/utils/camera-playback.util.mjs";
26
+ import {
27
+ isRelayPlayerUrl,
28
+ } from "./.build/utils/camera-capability.util.mjs";
29
+ import { publicCameraFields } from "./.build/utils/camera-view.util.mjs";
30
+
31
+ const KEY = "k".repeat(40);
32
+ const RELAY = "the-loft.example.net";
33
+ const RELAYS = { [RELAY]: KEY };
34
+ const NOW = new Date("2026-09-16T08:00:00Z");
35
+ const EXP = Math.floor(NOW.getTime() / 1000) + PLAYBACK_LINK_SECONDS;
36
+
37
+ /** What the relay computes. Written out here so the test is not the code twice. */
38
+ const expectedSig = (channel, exp = EXP, key = KEY) =>
39
+ createHmac("sha256", key).update(`${channel}|${exp}`).digest("hex");
40
+
41
+ test("a live link is signed over channel|exp with the relay's key", () => {
42
+ const link = signLiveLink(`https://${RELAY}/7`, { relays: RELAYS, now: NOW });
43
+
44
+ assert.equal(link.liveAuth, `exp=${EXP}&sig=${expectedSig("7")}`);
45
+ assert.equal(link.liveUrl, `https://${RELAY}/7?${link.liveAuth}`);
46
+ assert.equal(link.liveExpiresAt, new Date(EXP * 1000).toISOString());
47
+ });
48
+
49
+ test("the live link and the recorded-footage link sign DIFFERENT messages", () => {
50
+ const start = new Date("2026-09-16T07:00:00Z");
51
+ const end = new Date("2026-09-16T07:10:00Z");
52
+ const recorded = signPlaybackLink({
53
+ host: `https://${RELAY}/7`,
54
+ key: KEY,
55
+ start,
56
+ end,
57
+ now: NOW,
58
+ });
59
+ const live = signLiveLink(`https://${RELAY}/7`, { relays: RELAYS, now: NOW });
60
+
61
+ // Same key, same expiry, different signature - so a recording link cannot be
62
+ // replayed as a live link, which is what the relay's tests assert from the
63
+ // other side.
64
+ assert.equal(new URL(recorded.playerUrl).searchParams.get("exp"), String(EXP));
65
+ assert.notEqual(
66
+ new URL(recorded.playerUrl).searchParams.get("sig"),
67
+ new URL(live.liveUrl).searchParams.get("sig"),
68
+ );
69
+ });
70
+
71
+ test("the link lives as long as a recorded-footage link, and no longer", () => {
72
+ assert.equal(PLAYBACK_LINK_SECONDS, 120);
73
+ const link = signLiveLink(`https://${RELAY}/7`, { relays: RELAYS, now: NOW });
74
+ const exp = Number(new URLSearchParams(link.liveAuth).get("exp"));
75
+ assert.equal(exp - Math.floor(NOW.getTime() / 1000), PLAYBACK_LINK_SECONDS);
76
+ });
77
+
78
+ test("no relay configured for that address means NOTHING changes", () => {
79
+ // The estate has cameras on hosts nobody has configured. They must keep their
80
+ // plain link rather than get a signature no relay can check.
81
+ assert.equal(signLiveLink(`https://other.example.net/7`, { relays: RELAYS, now: NOW }), null);
82
+ assert.equal(signLiveLink(`https://${RELAY}/7`, { relays: {}, now: NOW }), null);
83
+ // A host with no channel is genuinely unresolvable, not channel 1.
84
+ assert.equal(signLiveLink(`https://${RELAY}/lobby`, { relays: RELAYS, now: NOW }), null);
85
+ assert.equal(signLiveLink(undefined, { relays: RELAYS, now: NOW }), null);
86
+ assert.equal(signLiveLink("", { relays: RELAYS, now: NOW }), null);
87
+ });
88
+
89
+ test("one signature serves the page, the socket, the still and the clip", () => {
90
+ // It covers the CHANNEL, not the path - which is why appending it to
91
+ // /screenshot/<ch> and /record/<ch>/duration/<n> works, and why the clients
92
+ // that splice `screenshot` into the path are unaffected.
93
+ const { liveAuth } = signLiveLink(`https://${RELAY}/7`, { relays: RELAYS, now: NOW });
94
+ for (const path of ["/7", "/api/stream/7", "/screenshot/7", "/record/7/duration/10"]) {
95
+ const url = new URL(`https://${RELAY}${path}?${liveAuth}`);
96
+ assert.equal(url.searchParams.get("sig"), expectedSig("7"));
97
+ }
98
+ });
99
+
100
+ test("the camera payloads the estate returns carry the signed link", () => {
101
+ const camera = { _id: "c1", name: "Lobby", type: "ip", status: "active", host: `https://${RELAY}/7` };
102
+ const fields = withLiveLink(publicCameraFields(camera), { relays: RELAYS, now: NOW });
103
+
104
+ assert.equal(fields.liveUrl, `https://${RELAY}/7?exp=${EXP}&sig=${expectedSig("7")}`);
105
+ assert.equal(fields.liveAuth, `exp=${EXP}&sig=${expectedSig("7")}`);
106
+ });
107
+
108
+ test("the stored host is handed back UNCHANGED, and stays a relay player URL", () => {
109
+ const host = `https://${RELAY}/7`;
110
+ const fields = withLiveLink(publicCameraFields({ _id: "c1", type: "ip", status: "active", host }), {
111
+ relays: RELAYS,
112
+ now: NOW,
113
+ });
114
+
115
+ // If `host` ever carried the signature, `isRelayPlayerUrl` would refuse it
116
+ // (it rejects any query), the liveVideo capability would switch off for both
117
+ // mobile apps and the web wall, and the patrol-route form would freeze an
118
+ // expiring signature into the route document. So this is load-bearing.
119
+ assert.equal(fields.host, host);
120
+ assert.equal(isRelayPlayerUrl(fields.host), true);
121
+ });
122
+
123
+ /**
124
+ * The WIRING, asserted on the service source — the same reason and the same
125
+ * method as `camera-entitlement-wiring.test.mjs`: constructing the service needs
126
+ * a live Atlas connection, so the only way to prove the service actually calls
127
+ * this is to assert the source.
128
+ *
129
+ * Without this, every assertion above could pass while the wall still handed out
130
+ * unsigned links — a helper nobody called.
131
+ */
132
+ test("EVERY camera payload the service returns goes through withLiveLink", () => {
133
+ const source = readFileSync(
134
+ fileURLToPath(new URL("../src/services/camera-view.service.ts", import.meta.url)),
135
+ "utf8",
136
+ );
137
+
138
+ const uses = [...source.matchAll(/publicCameraFields\(/g)];
139
+ // The import line names it too; the call sites are what matter.
140
+ const callSites = uses.filter((m) => !/import|from/.test(source.slice(Math.max(0, m.index - 80), m.index)));
141
+ assert.ok(callSites.length >= 3, `expected the wall, the health sweep and the single view, found ${callSites.length}`);
142
+
143
+ for (const match of callSites) {
144
+ const before = source.slice(Math.max(0, match.index - 60), match.index);
145
+ assert.match(
146
+ before,
147
+ /withLiveLink\(\s*$/,
148
+ `a camera payload at offset ${match.index} is handed out without a signed live link`,
149
+ );
150
+ }
151
+ });
152
+
153
+ test("an ANPR camera gets no host and therefore no live link", () => {
154
+ // `publicCameraFields` already withholds `host` for ANPR; nothing may put one
155
+ // back. ANPR belongs to visitor and vehicle management, not to CCTV.
156
+ const fields = withLiveLink(
157
+ publicCameraFields({ _id: "c2", type: "anpr", status: "active", host: `https://${RELAY}/7` }),
158
+ { relays: RELAYS, now: NOW },
159
+ );
160
+ assert.equal(fields.host, undefined);
161
+ assert.equal(fields.liveUrl, undefined);
162
+ assert.equal(fields.liveAuth, undefined);
163
+ });