@7365admin1/core 3.122.5 → 3.123.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 +12 -0
- package/dist/index.d.ts +168 -3
- package/dist/index.js +169 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +164 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/e2e/dashboard-inventory-low-stock.e2e.test.mjs +40 -1
- package/test/padbot-command-readiness.test.mjs +103 -0
- package/test/padbot-mqtt.test.mjs +2 -2
- package/test/padbot-real-data.test.mjs +4 -2
- package/test/padbot.test.mjs +6 -1
package/package.json
CHANGED
|
@@ -18,7 +18,26 @@ describe("dashboard supply tile", { concurrency: 1 }, () => {
|
|
|
18
18
|
before(async () => {
|
|
19
19
|
h = await startHarness();
|
|
20
20
|
const store = new ObjectId();
|
|
21
|
-
|
|
21
|
+
const cleaner = new ObjectId();
|
|
22
|
+
const guards = new ObjectId();
|
|
23
|
+
const manager = new ObjectId();
|
|
24
|
+
await h.db.collection("organizations").insertMany([
|
|
25
|
+
{ _id: cleaner, name: "Cleaner", nature: "cleaning_services" },
|
|
26
|
+
{ _id: guards, name: "Guards", nature: "security_agency" },
|
|
27
|
+
{ _id: manager, name: "Manager", nature: "property_management_agency" },
|
|
28
|
+
]);
|
|
29
|
+
await h.db.collection("inventory.stores").insertOne({ _id: store, org: cleaner, ownerType: "service_provider", name: "Main", sites: [withStore], status: "active" });
|
|
30
|
+
// Two more organisations keep their own stores at the same site.
|
|
31
|
+
const guardStore = new ObjectId();
|
|
32
|
+
const propertyStore = new ObjectId();
|
|
33
|
+
await h.db.collection("inventory.stores").insertMany([
|
|
34
|
+
{ _id: guardStore, org: guards, ownerType: "service_provider", name: "Guard room", sites: [withStore], status: "active" },
|
|
35
|
+
{ _id: propertyStore, org: manager, ownerType: "property", name: "Property store", sites: [withStore], status: "active" },
|
|
36
|
+
]);
|
|
37
|
+
await h.db.collection("inventory.items").insertMany([
|
|
38
|
+
{ store: guardStore, name: "Guard torch battery", onHand: 1, reorderLevel: 5, status: "active" },
|
|
39
|
+
{ store: propertyStore, name: "Property LED", onHand: 2, reorderLevel: 10, status: "active" },
|
|
40
|
+
]);
|
|
22
41
|
await h.db.collection("inventory.items").insertMany([
|
|
23
42
|
{ store, name: "Tube 18W", onHand: 3, reorderLevel: 10, status: "active" },
|
|
24
43
|
{ store, name: "Holder", onHand: 0, reorderLevel: 5, status: "active" },
|
|
@@ -50,6 +69,26 @@ describe("dashboard supply tile", { concurrency: 1 }, () => {
|
|
|
50
69
|
assert.equal(supply.thresholdUnavailableReason, undefined);
|
|
51
70
|
});
|
|
52
71
|
|
|
72
|
+
it("another organisation's store at the same site never appears on this app's tile", async () => {
|
|
73
|
+
const supply = await tile(withStore);
|
|
74
|
+
assert.ok(!supply.items.some((i) => i.name === "Guard torch battery" || i.name === "Property LED"));
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it("the property and security dashboards show Low Stock from their own organisation's store only", async () => {
|
|
78
|
+
const repo = h.core.useNewDashboardRepo();
|
|
79
|
+
const pm = await repo.getPropertyManagementDashboard(withStore.toString());
|
|
80
|
+
assert.equal(pm.supplyAlert.basis, "below-alert-level");
|
|
81
|
+
assert.deepEqual(pm.supplyAlert.items, [{ name: "Property LED", qty: 2 }]);
|
|
82
|
+
const sec = await repo.getSecurityDashboard({ siteId: withStore.toString() });
|
|
83
|
+
assert.deepEqual(sec.supplyAlert.items, [{ name: "Guard torch battery", qty: 1 }]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("the property and security dashboards carry no supply tile where they have no store", async () => {
|
|
87
|
+
const repo = h.core.useNewDashboardRepo();
|
|
88
|
+
assert.equal((await repo.getPropertyManagementDashboard(withoutStore.toString())).supplyAlert, undefined);
|
|
89
|
+
assert.equal((await repo.getSecurityDashboard({ siteId: withoutStore.toString() })).supplyAlert, undefined);
|
|
90
|
+
});
|
|
91
|
+
|
|
53
92
|
it("a site without a store keeps the old lowest-quantity list", async () => {
|
|
54
93
|
const supply = await tile(withoutStore);
|
|
55
94
|
assert.equal(supply.basis, "lowest-quantity");
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
// Owner, prod 2026-09-26 22:36 SGT: "I click the function but it's not moving".
|
|
2
|
+
// Go to point P4 (Lvl3, robot on Lvl3) and Return to charger were both answered
|
|
3
|
+
// code 0 "success" by PadBot; the robot stayed idle at its charger. Recorded
|
|
4
|
+
// states (Diagnose 14:43Z): 1002 chargingState 2, 1006 wheelLockState 1,
|
|
5
|
+
// e-stop 0, battery 100, 1003 idle. PadBot's own 20:00 schedule also did not
|
|
6
|
+
// run that day. These tests pin what we now do before and after sending.
|
|
7
|
+
|
|
8
|
+
import assert from "node:assert/strict";
|
|
9
|
+
import { test } from "node:test";
|
|
10
|
+
|
|
11
|
+
import {
|
|
12
|
+
PADBOT_PATHS, clearPadbotCache, createPadbotAdapter, padbotCommandBlock, padbotReadiness, padbotCommandLog, padbotAccountKey,
|
|
13
|
+
} from "./.build/services/padbot.adapter.mjs";
|
|
14
|
+
|
|
15
|
+
const CREDS = { appid: "ak-real-id", secret: "sk-real-secret-never-shown" };
|
|
16
|
+
const NOW = Date.parse("2026-09-26T14:43:10.000Z");
|
|
17
|
+
const L3 = "40f18c40a12ee2f3c0b20b38dc7a5b0f";
|
|
18
|
+
const st = (over = {}) => ({
|
|
19
|
+
"1000": { updatedAt: "2026-09-26T14:43:05.807Z" },
|
|
20
|
+
"1001": { batteryPercent: 100 },
|
|
21
|
+
"1002": { chargingState: 2 },
|
|
22
|
+
"1003": { actionType: 0, actionState: 0, message: null },
|
|
23
|
+
"1006": { emergencyStopState: 0, wheelLockState: 1 },
|
|
24
|
+
"1007": { mapId: L3, floor: 3, mapDisplayName: "Lvl3 Office" },
|
|
25
|
+
"1010": { workState: 0, taskType: 0 },
|
|
26
|
+
...over,
|
|
27
|
+
});
|
|
28
|
+
const asEntry = (s) => [{ serialNumber: "PS8517", states: Object.entries(s).map(([stateType, data]) => ({ stateType, data })) }];
|
|
29
|
+
|
|
30
|
+
test("blocks: e-stop, low battery, offline, Return while docked; cancel never", () => {
|
|
31
|
+
assert.match(padbotCommandBlock(st({ "1006": { emergencyStopState: 1 } }), "area", NOW), /emergency stop button is pressed/);
|
|
32
|
+
assert.match(padbotCommandBlock(st({ "1001": { batteryPercent: 8 } }), "go-to-point", NOW), /battery is at 8%/);
|
|
33
|
+
assert.equal(padbotCommandBlock(st({ "1001": { batteryPercent: 8 } }), "return", NOW), "The robot is already on its charger.");
|
|
34
|
+
assert.match(padbotCommandBlock(st({ "1000": { updatedAt: "2026-09-26T14:00:00Z" } }), "full", NOW), /not reporting/);
|
|
35
|
+
assert.equal(padbotCommandBlock(st(), "return", NOW), "The robot is already on its charger.");
|
|
36
|
+
assert.equal(padbotCommandBlock(st({ "1006": { emergencyStopState: 1 } }), "cancel", NOW), null);
|
|
37
|
+
// The recorded prod state: nothing PadBot documents as blocking a Go to point.
|
|
38
|
+
assert.equal(padbotCommandBlock(st(), "go-to-point", NOW), null);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
test("readiness shows the raw wheel lock and charging state 2 with plain notes", () => {
|
|
42
|
+
const r = padbotReadiness(st(), NOW);
|
|
43
|
+
assert.equal(r.online, true);
|
|
44
|
+
assert.equal(r.wheelLockState, 1);
|
|
45
|
+
assert.equal(r.chargingState, 2);
|
|
46
|
+
assert.equal(r.blocker, null);
|
|
47
|
+
assert.equal(r.notes.length, 2);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
function fake(sequence) {
|
|
51
|
+
const calls = [];
|
|
52
|
+
let reads = 0;
|
|
53
|
+
const fetch = async (url, init) => {
|
|
54
|
+
const path = new URL(url).pathname;
|
|
55
|
+
const body = JSON.parse(init.body);
|
|
56
|
+
calls.push({ path, body });
|
|
57
|
+
let data = null;
|
|
58
|
+
if (path === PADBOT_PATHS.states) data = asEntry(sequence[Math.min(reads++, sequence.length - 1)]);
|
|
59
|
+
if (path === PADBOT_PATHS.maps) data = [{ mapId: L3, mapDisplayName: "Lvl3 Office", floor: 3, mapGroup: "", targetPoints: [] }];
|
|
60
|
+
if (path === PADBOT_PATHS.location) data = { mapId: L3, worldX: null, worldY: null, yaw: -93 };
|
|
61
|
+
if (path === PADBOT_PATHS.robots) data = [];
|
|
62
|
+
return { status: 200, text: async () => JSON.stringify({ code: 0, message: "success", requestId: "rid-1", data }) };
|
|
63
|
+
};
|
|
64
|
+
const adapter = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch, now: () => NOW, watch: { everyMs: 1, forMs: 10 }, sleep: () => Promise.resolve() });
|
|
65
|
+
return { calls, adapter };
|
|
66
|
+
}
|
|
67
|
+
const settle = () => new Promise((r) => setTimeout(r, 20));
|
|
68
|
+
|
|
69
|
+
test("Return while docked is refused in words; nothing is sent", async () => {
|
|
70
|
+
clearPadbotCache();
|
|
71
|
+
const { calls, adapter } = fake([st()]);
|
|
72
|
+
await assert.rejects(adapter.sendCommand("PS8517", { kind: "return" }), (e) => e.statusCode === 400 && e.message === "The robot is already on its charger.");
|
|
73
|
+
assert.equal(calls.filter((c) => c.path === PADBOT_PATHS.charge).length, 0);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test("after an accepted Go to point the robot's own failure is kept and shown on the status line", async () => {
|
|
77
|
+
clearPadbotCache();
|
|
78
|
+
const failed = st({ "1003": { actionType: 11, actionState: 6, finalTargetPointName: "P4", message: "wheel locked" } });
|
|
79
|
+
// reads: the pre-send check, the map check, then the trace.
|
|
80
|
+
const { adapter } = fake([st(), st(), st({ "1003": { actionType: 11, actionState: 1, finalTargetPointName: "P4" } }), failed, failed]);
|
|
81
|
+
await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: "07828d" });
|
|
82
|
+
await settle();
|
|
83
|
+
const [entry] = padbotCommandLog(padbotAccountKey(CREDS), "PS8517");
|
|
84
|
+
assert.equal(entry.vendorMessage, "success");
|
|
85
|
+
assert.equal(entry.requestId, "rid-1");
|
|
86
|
+
assert.equal(entry.reaction.watching, false);
|
|
87
|
+
assert.equal(entry.reaction.moved, true);
|
|
88
|
+
assert.equal(entry.reaction.failure, "Could not reach P4 (wheel locked)");
|
|
89
|
+
assert.ok(entry.reaction.points.length >= 2);
|
|
90
|
+
const robot = await adapter.getRobot("PS8517");
|
|
91
|
+
assert.match(robot.statusName, /^Could not reach P4 \(wheel locked\) · /);
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
test("no reaction at all is recorded as such (robot never moved)", async () => {
|
|
95
|
+
clearPadbotCache();
|
|
96
|
+
const { adapter } = fake([st()]);
|
|
97
|
+
await adapter.sendCommand("PS8517", { kind: "go-to-point", mapId: L3, targetPointId: "07828d" });
|
|
98
|
+
await settle();
|
|
99
|
+
const [entry] = padbotCommandLog(padbotAccountKey(CREDS), "PS8517");
|
|
100
|
+
assert.equal(entry.reaction.moved, false);
|
|
101
|
+
assert.equal(entry.reaction.failure, null);
|
|
102
|
+
assert.equal(entry.reaction.points.length, 1);
|
|
103
|
+
});
|
|
@@ -351,10 +351,10 @@ test("go-to-point: parsed strictly; needs navigateToPoint; PadBot sends §5.7 wi
|
|
|
351
351
|
calls.push({ path, body: JSON.parse(init.body) });
|
|
352
352
|
const code = path === PADBOT_PATHS.stop ? 1009 : 0;
|
|
353
353
|
// The robot reports map m1 (§4.2 1007), so a point on m1 is reachable.
|
|
354
|
-
const data = path === PADBOT_PATHS.states ? [{ serialNumber: "PS1", states: [{ stateType: "1007", data: { mapId: "m1" } }] }] : null;
|
|
354
|
+
const data = path === PADBOT_PATHS.states ? [{ serialNumber: "PS1", states: [{ stateType: "1000", data: { updatedAt: new Date().toISOString() } }, { stateType: "1007", data: { mapId: "m1" } }] }] : null;
|
|
355
355
|
return { status: 200, text: async () => JSON.stringify({ code, message: code ? "robot busy" : "success", data }) };
|
|
356
356
|
};
|
|
357
|
-
const a = createPadbotAdapter(creds, { baseUrl: "https://pb.test", fetch });
|
|
357
|
+
const a = createPadbotAdapter(creds, { baseUrl: "https://pb.test", fetch, watch: false });
|
|
358
358
|
await a.sendCommand("PS1", { kind: "go-to-point", mapId: "m1", targetPointId: "t2" });
|
|
359
359
|
assert.deepEqual(calls.at(-1), { path: "/api/v1/robots/actions/navigate-to-target", body: { serialNumber: "PS1", mapId: "m1", targetPointId: "t2" } });
|
|
360
360
|
await assert.rejects(a.sendCommand("PS1", { kind: "cancel" }), (e) => e.vendorCode === 1009 && e.vendorMessage === "robot busy");
|
|
@@ -141,7 +141,9 @@ test("diagnose: PadBot's raw answers per read (code, message, data); maps summar
|
|
|
141
141
|
[PADBOT_PATHS.records]: () => ({ items: [], totalItems: 0 }),
|
|
142
142
|
});
|
|
143
143
|
const steps = await createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW }).diagnose("PS8517");
|
|
144
|
-
assert.deepEqual(steps.map((s) => s.step), ["states (4.2)", "location (4.3)", "maps (5.1)", "patrol routes (6.1)", "alarms (6.4)", "patrol records (6.7)", "recent commands (this server)"]);
|
|
144
|
+
assert.deepEqual(steps.map((s) => s.step), ["states (4.2)", "location (4.3)", "maps (5.1)", "patrol routes (6.1)", "alarms (6.4)", "patrol records (6.7)", "recent commands (this server)", "can it move now? (from 4.2)"]);
|
|
145
|
+
assert.equal(steps.at(-1).data.online, true);
|
|
146
|
+
assert.equal(steps.at(-1).data.blocker, null);
|
|
145
147
|
const loc = steps[1];
|
|
146
148
|
assert.equal(loc.code, 1008);
|
|
147
149
|
assert.equal(loc.message, "Failed to retrieve data");
|
|
@@ -203,7 +205,7 @@ test("go to point on another map: only inside one map group, else 'The robot mus
|
|
|
203
205
|
|
|
204
206
|
clearPadbotCache();
|
|
205
207
|
const f = fake({
|
|
206
|
-
[PADBOT_PATHS.states]: () => [{ serialNumber: "PS8517", states: [{ stateType: "1007", data: { mapId: "m1" } }] }],
|
|
208
|
+
[PADBOT_PATHS.states]: () => [{ serialNumber: "PS8517", states: [{ stateType: "1000", data: { updatedAt: fresh } }, { stateType: "1007", data: { mapId: "m1" } }] }],
|
|
207
209
|
[PADBOT_PATHS.maps]: () => [{ mapId: "m1", mapGroup: "" }, { mapId: "m2", mapGroup: "" }],
|
|
208
210
|
[PADBOT_PATHS.navigateTarget]: () => null,
|
|
209
211
|
});
|
package/test/padbot.test.mjs
CHANGED
|
@@ -488,6 +488,8 @@ test("adapter getRobot: e-stop outranks alarms; unknown serial = null; offline s
|
|
|
488
488
|
test("adapter commands: each of ours becomes the documented PadBot call", async () => {
|
|
489
489
|
const f = fakePadbot({
|
|
490
490
|
...Object.fromEntries(Object.values(PADBOT_PATHS).map((p) => [p, () => null])),
|
|
491
|
+
// Reporting, off its charger: every moving command passes the pre-send check.
|
|
492
|
+
[PADBOT_PATHS.states]: (b) => (b.serialNumbers ?? []).map((serialNumber) => ({ serialNumber, states: [{ stateType: "1000", data: { updatedAt: fresh } }] })),
|
|
491
493
|
[PADBOT_PATHS.patrolRoutes]: () => [{ pathId: "p1", pathName: "Loop", mapId: null, isDefault: false, pointNames: [] }],
|
|
492
494
|
});
|
|
493
495
|
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
|
|
@@ -516,7 +518,10 @@ test("adapter commands: each of ours becomes the documented PadBot call", async
|
|
|
516
518
|
|
|
517
519
|
test("adapter errors: business codes, HTTP 401/403/5xx and timeouts are plain words; the secret never appears", async () => {
|
|
518
520
|
const err = async (answer) => {
|
|
519
|
-
const f = fakePadbot({
|
|
521
|
+
const f = fakePadbot({
|
|
522
|
+
[PADBOT_PATHS.patrolResume]: () => answer,
|
|
523
|
+
[PADBOT_PATHS.states]: () => (answer?.__status ? answer : [{ serialNumber: "PS1", states: [{ stateType: "1000", data: { updatedAt: fresh } }] }]),
|
|
524
|
+
});
|
|
520
525
|
const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: f.now });
|
|
521
526
|
try {
|
|
522
527
|
await a.sendCommand("PS1", { kind: "patrol-resume" });
|