@7365admin1/core 3.75.1 → 3.77.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 +19 -0
- package/dist/index.d.ts +66 -5
- package/dist/index.js +167 -12
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +165 -12
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/camera-live-link.test.mjs +163 -0
- package/test/e2e/dashboard-inventory-low-stock.e2e.test.mjs +59 -0
- package/test/notification-category.util.test.mjs +21 -1
package/package.json
CHANGED
|
@@ -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
|
+
});
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
// The dashboard supply tile reads Inventory where a store serves the site.
|
|
2
|
+
//
|
|
3
|
+
// With a store: the items at or below their own alert level, lowest first,
|
|
4
|
+
// basis `below-alert-level`, and nothing above its level. Without a store: the
|
|
5
|
+
// three lowest-quantity equipment supplies exactly as before, basis
|
|
6
|
+
// `lowest-quantity` with the no-threshold reason.
|
|
7
|
+
import { after, before, describe, it } from "node:test";
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { ObjectId } from "mongodb";
|
|
10
|
+
|
|
11
|
+
import { startHarness } from "./harness.mjs";
|
|
12
|
+
|
|
13
|
+
describe("dashboard supply tile", { concurrency: 1 }, () => {
|
|
14
|
+
let h;
|
|
15
|
+
const withStore = new ObjectId();
|
|
16
|
+
const withoutStore = new ObjectId();
|
|
17
|
+
|
|
18
|
+
before(async () => {
|
|
19
|
+
h = await startHarness();
|
|
20
|
+
const store = new ObjectId();
|
|
21
|
+
await h.db.collection("inventory.stores").insertOne({ _id: store, org: new ObjectId(), ownerType: "property", name: "Main", sites: [withStore], status: "active" });
|
|
22
|
+
await h.db.collection("inventory.items").insertMany([
|
|
23
|
+
{ store, name: "Tube 18W", onHand: 3, reorderLevel: 10, status: "active" },
|
|
24
|
+
{ store, name: "Holder", onHand: 0, reorderLevel: 5, status: "active" },
|
|
25
|
+
{ store, name: "Plenty", onHand: 500, reorderLevel: 10, status: "active" },
|
|
26
|
+
{ store, name: "No alert set", onHand: 0, reorderLevel: 0, status: "active" },
|
|
27
|
+
{ store, name: "Not in use", onHand: 0, reorderLevel: 10, status: "inactive" },
|
|
28
|
+
]);
|
|
29
|
+
await h.db.collection("site.supplies").insertMany([
|
|
30
|
+
{ site: withoutStore, serviceType: "cleaning_services", name: "Gloves", qty: 900, status: "active" },
|
|
31
|
+
{ site: withoutStore, serviceType: "cleaning_services", name: "Bleach", qty: 4, status: "active" },
|
|
32
|
+
{ site: withStore, serviceType: "cleaning_services", name: "Old equipment row", qty: 1, status: "active" },
|
|
33
|
+
]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
after(async () => {
|
|
37
|
+
await h?.stop();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
const tile = async (site) =>
|
|
41
|
+
(await h.core.useNewDashboardRepo().getServiceDashboard({ site, serviceType: "cleaning_services" })).supplyAlert;
|
|
42
|
+
|
|
43
|
+
it("a site with an Inventory store shows only items at or below their alert level, lowest first", async () => {
|
|
44
|
+
const supply = await tile(withStore);
|
|
45
|
+
assert.equal(supply.basis, "below-alert-level");
|
|
46
|
+
assert.deepEqual(supply.items, [
|
|
47
|
+
{ name: "Holder", qty: 0 },
|
|
48
|
+
{ name: "Tube 18W", qty: 3 },
|
|
49
|
+
]);
|
|
50
|
+
assert.equal(supply.thresholdUnavailableReason, undefined);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("a site without a store keeps the old lowest-quantity list", async () => {
|
|
54
|
+
const supply = await tile(withoutStore);
|
|
55
|
+
assert.equal(supply.basis, "lowest-quantity");
|
|
56
|
+
assert.deepEqual(supply.items.map((i) => i.name), ["Bleach", "Gloves"]);
|
|
57
|
+
assert.ok(supply.thresholdUnavailableReason);
|
|
58
|
+
});
|
|
59
|
+
});
|
|
@@ -84,6 +84,24 @@ describe("notification categories", () => {
|
|
|
84
84
|
}
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
+
it("a role holding any inventory permission is offered the Inventory switch", () => {
|
|
88
|
+
for (const permission of [
|
|
89
|
+
"inventory:view-inventory",
|
|
90
|
+
"inventory:request-stock",
|
|
91
|
+
"inventory:approve-requests",
|
|
92
|
+
"inventory:manage-inventory",
|
|
93
|
+
]) {
|
|
94
|
+
assert.deepEqual(
|
|
95
|
+
keys(categoriesForPermissions({ permissions: [permission] })),
|
|
96
|
+
["inventory"],
|
|
97
|
+
permission,
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
const inventory = NOTIFICATION_CATEGORIES.find((c) => c.key === "inventory");
|
|
101
|
+
assert.equal(inventory.rendered, true);
|
|
102
|
+
assert.equal(inventory.safety, undefined);
|
|
103
|
+
});
|
|
104
|
+
|
|
87
105
|
it("a resident is not offered any safety switch", () => {
|
|
88
106
|
const offered = keys(
|
|
89
107
|
categoriesForPermissions({ permissions: [], isResident: true }),
|
|
@@ -360,7 +378,9 @@ describe("marketplace order categories", () => {
|
|
|
360
378
|
// ---------------------------------------------------------------------------
|
|
361
379
|
|
|
362
380
|
const NEW_KEYS = ["marketplaceOrder", "marketplaceVendorOrder"];
|
|
363
|
-
|
|
381
|
+
// Categories added after this snapshot was taken; each is pinned by its own test.
|
|
382
|
+
const LATER_KEYS = ["inventory"];
|
|
383
|
+
const withoutNew = (result) => keys(result).filter((k) => !NEW_KEYS.includes(k) && !LATER_KEYS.includes(k));
|
|
364
384
|
const onlyNew = (result) => keys(result).filter((k) => NEW_KEYS.includes(k));
|
|
365
385
|
|
|
366
386
|
const BEFORE = {
|