@7365admin1/core 3.94.0 → 3.95.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.94.0",
4
+ "version": "3.95.0",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -13,7 +13,7 @@
13
13
  "build": "tsup src/index.ts --format cjs,esm --dts && shx cp -r src/public dist && shx cp -r src/utils/handlebars dist",
14
14
  "release": "yarn run build && changeset publish",
15
15
  "lint": "tsc",
16
- "test": "tsup src/config.ts src/utils/building-map.util.ts src/utils/robot-cloud.util.ts src/utils/robot-adapter.util.ts src/utils/png-encoder.util.ts src/services/demo.adapter.ts src/services/ounitech.adapter.ts src/utils/robot-fault.util.ts src/utils/robot-tracking.util.ts src/utils/robot-apps.util.ts src/utils/robot-permission.util.ts src/utils/robot-network.util.ts src/utils/lift-contract.util.ts src/models/robot-building-map.model.ts src/utils/anpr-revoke.util.ts src/utils/anpr-plate.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/utils/camera-playback.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/occurrence-book-create.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts src/utils/console-permission.util.ts src/utils/role-scope.util.ts src/utils/org-default-roles.util.ts src/utils/org-modules.util.ts src/utils/site-modules.util.ts src/utils/resident-app-modules.util.ts src/utils/resident-default-role.util.ts src/utils/invite-role-scope.util.ts src/models/personal-emergency-chain.model.ts src/utils/self-signup-files.util.ts src/models/person.model.ts src/utils/module-gate.util.ts src/utils/member-lookup.util.ts src/utils/notification-access.util.ts src/utils/module-access.util.ts src/services/module-gate.service.ts src/controllers/site.controller.ts src/controllers/organization.controller.ts src/controllers/member.controller.ts src/utils/org-owner-repair.util.ts src/utils/socket-session.util.ts src/utils/people-create-gate.util.ts src/utils/service-app-type.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
16
+ "test": "tsup src/config.ts src/utils/building-map.util.ts src/utils/robot-cloud.util.ts src/utils/robot-adapter.util.ts src/utils/png-encoder.util.ts src/services/demo.adapter.ts src/services/ounitech.adapter.ts src/services/open-rmf.adapter.ts src/utils/door-contract.util.ts src/utils/robot-fault.util.ts src/utils/robot-tracking.util.ts src/utils/robot-apps.util.ts src/utils/robot-permission.util.ts src/utils/robot-network.util.ts src/utils/lift-contract.util.ts src/models/robot-building-map.model.ts src/utils/anpr-revoke.util.ts src/utils/anpr-plate.util.ts src/utils/vehicle-request.util.ts src/utils/camera-view.util.ts src/utils/camera-bulk-import.util.ts src/utils/dashboard-metrics.util.ts src/utils/camera-capability.util.ts src/utils/camera-playback.util.ts src/services/camera-device-http.service.ts src/utils/camera-alert.util.ts src/utils/dahua-protocol.util.ts src/utils/site-name.util.ts src/utils/service-provider-invite.util.ts src/utils/notification-category.util.ts src/utils/hid-card.util.ts src/utils/hid-json.util.ts src/utils/hid-access.util.ts src/models/customer-site.model.ts src/models/site-camera.model.ts src/models/member.model.ts src/models/subscription.model.ts src/utils/session-id.util.ts src/utils/occurrence-query.util.ts src/utils/occurrence-book-create.util.ts src/utils/update-result.util.ts src/utils/hid-amico-authz.util.ts src/utils/promo-code-currency.util.ts src/utils/console-audit.util.ts src/utils/org-suspension.util.ts src/utils/session-revoke.util.ts src/models/hid-amico.model.ts src/models/patrol-email.model.ts src/utils/patrol-email-pdf.util.ts src/utils/visitor-status.util.ts src/utils/self-service-email.util.ts src/utils/hid-secret.util.ts src/models/visitor-invite.model.ts src/models/guard-invite.model.ts src/utils/site-timezone.util.ts src/utils/bulletin-service-apps.util.ts src/models/bulletin-board.model.ts src/utils/vehicle-import.util.ts src/utils/expired-vehicle-sweep.util.ts src/models/vehicle.model.ts src/controllers/chat.controller.ts src/utils/file-owner.util.ts src/utils/console-permission.util.ts src/utils/role-scope.util.ts src/utils/org-default-roles.util.ts src/utils/org-modules.util.ts src/utils/site-modules.util.ts src/utils/resident-app-modules.util.ts src/utils/resident-default-role.util.ts src/utils/invite-role-scope.util.ts src/models/personal-emergency-chain.model.ts src/utils/self-signup-files.util.ts src/models/person.model.ts src/utils/module-gate.util.ts src/utils/member-lookup.util.ts src/utils/notification-access.util.ts src/utils/module-access.util.ts src/services/module-gate.service.ts src/controllers/site.controller.ts src/controllers/organization.controller.ts src/controllers/member.controller.ts src/utils/org-owner-repair.util.ts src/utils/socket-session.util.ts src/utils/people-create-gate.util.ts src/utils/service-app-type.util.ts --format esm --out-dir test/.build --no-dts --silent && node --test test/*.test.mjs",
17
17
  "test:camera": "yarn test",
18
18
  "test:e2e": "yarn build && node --test --test-concurrency=1 --test-timeout=600000 \"test/e2e/*.test.mjs\""
19
19
  },
@@ -905,6 +905,7 @@ function buildApp(nsu, core) {
905
905
  const m = core.useRobotMapController();
906
906
  const MAP = "/building-maps/:mapId([0-9a-fA-F]{24})";
907
907
  const SESSION = "/lift-sessions/:sessionId([0-9a-fA-F]{24})";
908
+ robots.get("/fleet-core/building", requireAuth, m.getOpenRmfBuilding);
908
909
  robots.get("/building-maps", requireAuth, m.listMaps);
909
910
  robots.post("/building-maps", requireAuth, m.createMap);
910
911
  robots.get(MAP, requireAuth, m.getMap);
@@ -0,0 +1,185 @@
1
+ // End-to-end proof for the Open-RMF bridge, against a local stub that answers
2
+ // with responses recorded from a real Open-RMF server (test/fixtures/open-rmf).
3
+ //
4
+ // 1. Without OPEN_RMF_API_URL the building read-through is 404 and nothing is
5
+ // called - the state of production, where the variable is not set.
6
+ // 2. The read-through is estate-gated like a site map read, and stores nothing.
7
+ // 3. An `open-rmf` robot's state is read from RMF's fleet state, and a command
8
+ // becomes an RMF robot task - the stub sees the exact request.
9
+ //
10
+ // In-process MongoDB, loopback Redis and mail sink, loopback stub only.
11
+ //
12
+ // Run with: yarn test:e2e
13
+
14
+ import { after, before, describe, it } from "node:test";
15
+ import assert from "node:assert/strict";
16
+ import { createServer } from "node:http";
17
+ import { readFileSync } from "node:fs";
18
+ import { ObjectId } from "mongodb";
19
+
20
+ import { startHarness } from "./harness.mjs";
21
+
22
+ const PASSWORD = "Robot-Passw0rd!";
23
+ const OUTSIDER = "rmf-outsider@e2e.example.com";
24
+ const MANAGER = "rmf-manager@e2e.example.com";
25
+ const fx = (n) => JSON.parse(readFileSync(new URL(`../fixtures/open-rmf/${n}.json`, import.meta.url), "utf8"));
26
+
27
+ function startStub() {
28
+ const seen = [];
29
+ const routes = {
30
+ "GET /fleets": () => fx("fleets"),
31
+ "GET /building_map": () => fx("building_map"),
32
+ "POST /tasks/robot_task": () => fx("robot_task_response"),
33
+ };
34
+ const server = createServer((req, res) => {
35
+ let raw = "";
36
+ req.on("data", (c) => (raw += c));
37
+ req.on("end", () => {
38
+ seen.push({ method: req.method, url: req.url, auth: req.headers.authorization, body: raw ? JSON.parse(raw) : null });
39
+ const key = `${req.method} ${req.url}`;
40
+ const name = decodeURIComponent(req.url.split("/")[2] ?? "");
41
+ let body = routes[key]?.();
42
+ if (!body && /^GET \/doors\/[^/]+\/state$/.test(key)) body = { ...fx("door_state"), door_name: name };
43
+ if (!body && /^GET \/lifts\/[^/]+\/state$/.test(key)) body = { ...fx("lift_state"), lift_name: name };
44
+ if (!body && /^GET \/tasks\/[^/]+\/state$/.test(key)) body = fx("task_state_patrol");
45
+ res.writeHead(body ? 200 : 404, { "Content-Type": "application/json" });
46
+ res.end(JSON.stringify(body ?? { detail: "Not Found" }));
47
+ });
48
+ });
49
+ return new Promise((resolve) =>
50
+ server.listen(0, "127.0.0.1", () => resolve({ server, seen, url: `http://127.0.0.1:${server.address().port}` })),
51
+ );
52
+ }
53
+
54
+ describe("Open-RMF bridge", { concurrency: 1 }, () => {
55
+ let h;
56
+ let stub;
57
+ const id = {};
58
+ let outsiderSid;
59
+ let managerSid;
60
+
61
+ before(async () => {
62
+ delete process.env.OPEN_RMF_API_URL;
63
+ h = await startHarness();
64
+ stub = await startStub();
65
+ Object.assign(id, await seed(h));
66
+ outsiderSid = await h.login(OUTSIDER, PASSWORD);
67
+ managerSid = await h.login(MANAGER, PASSWORD);
68
+ }, { timeout: 300000 });
69
+
70
+ after(async () => {
71
+ delete process.env.OPEN_RMF_API_URL;
72
+ delete process.env.OPEN_RMF_TOKEN;
73
+ stub?.server.close();
74
+ if (h) await h.stop();
75
+ });
76
+
77
+ it("unauthenticated is 401", async () => {
78
+ assert.equal((await h.api(`/robots/fleet-core/building?site=${id.siteB}`)).status, 401);
79
+ });
80
+
81
+ it("without OPEN_RMF_API_URL: 404 and the RMF server is never called", async () => {
82
+ const res = await h.api(`/robots/fleet-core/building?site=${id.siteB}`, { sid: managerSid });
83
+ assert.equal(res.status, 404);
84
+ assert.match(res.body.message, /not configured/);
85
+ assert.equal(stub.seen.length, 0);
86
+ assert.equal(h.core.robotBrandFor("fleet-core"), null, "the brand is not registered on a server without Open-RMF");
87
+ });
88
+
89
+ it("configured: a caller at another estate gets 404, and RMF is not called", async () => {
90
+ process.env.OPEN_RMF_API_URL = stub.url;
91
+ process.env.OPEN_RMF_TOKEN = "e2e-token";
92
+ const res = await h.api(`/robots/fleet-core/building?site=${id.siteB}`, { sid: outsiderSid });
93
+ assert.equal(res.status, 404);
94
+ assert.equal(stub.seen.length, 0);
95
+ });
96
+
97
+ it("configured: the estate's manager reads the RMF building through, with live doors and lifts, nothing stored", async () => {
98
+ const res = await h.api(`/robots/fleet-core/building?site=${id.siteB}`, { sid: managerSid });
99
+ assert.equal(res.status, 200, JSON.stringify(res.body));
100
+ assert.equal(res.body.source, "fleet-core");
101
+ assert.doesNotMatch(JSON.stringify(res.body), /open-?rmf/i, "no upstream name in a client-visible reply");
102
+ assert.equal(res.body.readOnly, true);
103
+ assert.deepEqual(res.body.levels.map((l) => l.name), ["L1", "L2", "L3"]);
104
+ assert.equal(res.body.doors.length, 19);
105
+ assert.equal(res.body.lifts.length, 2);
106
+ assert.equal(res.body.doorStates.length, 19);
107
+ assert.deepEqual(res.body.liftStates.map((l) => l.liftName), ["Lift1", "Lift2"]);
108
+ assert.ok(stub.seen.every((c) => c.auth === "Bearer e2e-token"));
109
+ assert.equal(await h.db.collection("robot-building-maps").countDocuments(), 0);
110
+ });
111
+
112
+ it("an open-rmf robot's state comes from RMF, and a command becomes an RMF robot task", async () => {
113
+ assert.equal(h.core.registerOpenRmfBrand(process.env), true);
114
+ const state = await h.api(`/robots/${id.rmfRobot}/state`, { sid: managerSid });
115
+ assert.equal(state.status, 200, JSON.stringify(state.body));
116
+ const robot = state.body.data ?? state.body;
117
+ assert.equal(robot.brand, "fleet-core");
118
+ assert.doesNotMatch(JSON.stringify(state.body), /open-?rmf/i, "no upstream name in a client-visible reply");
119
+ assert.equal(robot.robotSn, "tinyRobot/tinyBot_1");
120
+ assert.equal(robot.floorNo, 1);
121
+ assert.equal(robot.online, true);
122
+
123
+ // "full" goes through only when the platform itself finds the robot free.
124
+ const full = await h.api(`/robots/${id.rmfRobot}/command`, { method: "POST", sid: managerSid, body: { kind: "full" } });
125
+ if (robot.dispatchable) {
126
+ assert.equal(full.status, 202, JSON.stringify(full.body));
127
+ const task = stub.seen.find((c) => c.url === "/tasks/robot_task");
128
+ assert.deepEqual([task.body.fleet, task.body.robot, task.body.request.category], ["tinyRobot", "tinyBot_1", "patrol"]);
129
+ } else {
130
+ assert.equal(full.status, 400);
131
+ assert.equal(stub.seen.filter((c) => c.url === "/tasks/robot_task").length, 0);
132
+ }
133
+ // "return" is how an operator recovers a busy robot, so it always goes through.
134
+ const ret = await h.api(`/robots/${id.rmfRobot}/command`, { method: "POST", sid: managerSid, body: { kind: "return" } });
135
+ assert.equal(ret.status, 202, JSON.stringify(ret.body));
136
+ const task = stub.seen.filter((c) => c.url === "/tasks/robot_task").at(-1);
137
+ assert.equal(task.body.request.description.phases[0].activity.description.activities[0].description, "tinybot_charger");
138
+ });
139
+ });
140
+
141
+ async function seed(h) {
142
+ const now = new Date().toISOString();
143
+ const orgA = new ObjectId();
144
+ const orgB = new ObjectId();
145
+ const siteA = new ObjectId();
146
+ const siteB = new ObjectId();
147
+ const roleA = new ObjectId();
148
+ const roleB = new ObjectId();
149
+ await h.db.collection("organizations").insertMany([
150
+ { _id: orgA, name: "RMF Org A", email: "rmfa@e2e.example.com", type: "org", nature: "property_management_agency", status: "active", createdAt: now },
151
+ { _id: orgB, name: "RMF Org B", email: "rmfb@e2e.example.com", type: "org", nature: "property_management_agency", status: "active", createdAt: now },
152
+ ]);
153
+ await h.db.collection("sites").insertMany([
154
+ { _id: siteA, name: "RMF Site A", org: orgA, orgId: orgA, status: "active" },
155
+ { _id: siteB, name: "RMF Site B", org: orgB, orgId: orgB, status: "active" },
156
+ ]);
157
+ await h.db.collection("roles").insertMany([
158
+ { _id: roleA, name: "Manager A", org: orgA, permissions: ["*"], status: "active" },
159
+ { _id: roleB, name: "Manager B", org: orgB, permissions: ["*"], status: "active" },
160
+ ]);
161
+ const emails = [OUTSIDER, MANAGER];
162
+ const users = await h.db.collection("users").insertMany(emails.map((email) => ({ email, name: email.split("@")[0], status: "active", createdAt: now })));
163
+ const hashed = await h.hashPassword(PASSWORD);
164
+ await h.db.collection("users").updateMany({ email: { $in: emails } }, { $set: { password: hashed } });
165
+ const [outsider, manager] = [0, 1].map((i) => users.insertedIds[i]);
166
+ await h.db.collection("members").insertMany([
167
+ { user: outsider, org: orgA, siteId: siteA, type: "organization", role: roleA, status: "active" },
168
+ { user: manager, org: orgB, type: "organization", role: roleB, status: "active" },
169
+ ]);
170
+ const r = await h.db.collection("robots").insertOne({
171
+ name: "Fleet Core tinyBot_1",
172
+ brand: "fleet-core",
173
+ type: "security",
174
+ robotSn: "tinyRobot/tinyBot_1",
175
+ appKey: "fleet-core",
176
+ appToken: "server-env",
177
+ createdBy: manager,
178
+ createdByName: "rmf-manager",
179
+ metadata: { orgId: orgB, siteId: siteB, administratorId: "" },
180
+ status: "",
181
+ deletedAt: "",
182
+ createdAt: new Date(),
183
+ });
184
+ return { orgA, orgB, siteA, siteB, rmfRobot: r.insertedId };
185
+ }