@7365admin1/core 3.119.0 → 3.121.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.119.0",
4
+ "version": "3.121.0",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -110,3 +110,60 @@ test("probe: refuses non-Ounitech robots and robots with no credentials, without
110
110
  await assert.rejects(fleetFor("none").probeTimestampFormat({ ...robotRow("a4"), appKey: "", appToken: "" }), (e) => e.statusCode === 400);
111
111
  assert.equal(calls.length, 0);
112
112
  });
113
+
114
+ /* ------------------------------------------------------- the offset probe */
115
+
116
+ // A mock Ounitech whose clock runs 30 s ahead and which accepts yyyyMMddHHmmss
117
+ // only at its own clock + 8 h (within 2 s), checking the sign server-side.
118
+ let offServer;
119
+ let offBase;
120
+ const offCalls = [];
121
+ const SKEW_MS = 30_000;
122
+ const parseCompact = (t) =>
123
+ Date.UTC(+t.slice(0, 4), +t.slice(4, 6) - 1, +t.slice(6, 8), +t.slice(8, 10), +t.slice(10, 12), +t.slice(12, 14));
124
+
125
+ before(async () => {
126
+ offServer = http.createServer((req, res) => {
127
+ let raw = "";
128
+ req.on("data", (c) => (raw += c));
129
+ req.on("end", () => {
130
+ const [, mode, ...rest] = req.url.split("/");
131
+ const path = "/" + rest.join("/");
132
+ const body = JSON.parse(raw);
133
+ offCalls.push({ path, body });
134
+ const vendorNow = Date.now() + SKEW_MS;
135
+ const signOk = body.sign === sha1(`appid=${body.appid},timestamp=${body.timestamp},url=${path},secret=${SECRET}`);
136
+ const want = mode === "plus8" ? vendorNow + 8 * 3600_000 : NaN;
137
+ const ok = signOk && /^\d{14}$/.test(body.timestamp) && Math.abs(parseCompact(body.timestamp) - want) < 2000;
138
+ res.writeHead(200, { "content-type": "application/json", date: new Date(vendorNow).toUTCString() });
139
+ res.end(JSON.stringify(ok ? { robotList: [] } : { ok: false, msg: "bad timestamp" }));
140
+ });
141
+ });
142
+ offServer.listen(0, "127.0.0.1");
143
+ await once(offServer, "listening");
144
+ offBase = `http://127.0.0.1:${offServer.address().port}`;
145
+ });
146
+ after(() => offServer.close());
147
+
148
+ const offFleet = (mode) => useRobotFleetService({ cloudOptions: { baseUrl: `${offBase}/${mode}`, timeoutMs: 1000 } });
149
+
150
+ test("offset probe: learns the vendor clock, tries offsets in order, stops at the first accepted (+8 h)", async () => {
151
+ offCalls.length = 0;
152
+ const r = await offFleet("plus8").probeTimestampOffset(robotRow("o1"));
153
+ assert.equal(r.acceptedOffsetMinutes, 480);
154
+ assert.deepEqual(r.attempts.map((a) => a.offsetMinutes), [0, 120, 60, 480]);
155
+ assert.ok(Math.abs(r.vendorSkewSeconds - 30) <= 1);
156
+ assert.ok(offCalls.every((c) => c.path === PATH), "only the robot list is called");
157
+ assert.ok(r.attempts.every((a) => /^\d{14}$/.test(a.sent)));
158
+ const text = JSON.stringify(r);
159
+ assert.equal(text.includes(SECRET) || text.includes(APPID), false);
160
+ assert.equal(/"sign"|[0-9a-f]{40}/.test(text), false);
161
+ });
162
+
163
+ test("offset probe: none accepted tries all 8; its own once-a-minute limit, separate from the format probe", async () => {
164
+ const fleet = offFleet("none");
165
+ const r = await fleet.probeTimestampOffset(robotRow("o2"));
166
+ assert.equal(r.acceptedOffsetMinutes, null);
167
+ assert.equal(r.attempts.length, 8);
168
+ await assert.rejects(fleet.probeTimestampOffset(robotRow("o2")), (e) => e.statusCode === 429);
169
+ });
@@ -346,7 +346,9 @@ test("go-to-point: parsed strictly; needs navigateToPoint; PadBot sends §5.7 wi
346
346
  const path = new URL(url).pathname;
347
347
  calls.push({ path, body: JSON.parse(init.body) });
348
348
  const code = path === PADBOT_PATHS.stop ? 1009 : 0;
349
- return { status: 200, text: async () => JSON.stringify({ code, message: code ? "robot busy" : "success", data: null }) };
349
+ // The robot reports map m1 (§4.2 1007), so a point on m1 is reachable.
350
+ const data = path === PADBOT_PATHS.states ? [{ serialNumber: "PS1", states: [{ stateType: "1007", data: { mapId: "m1" } }] }] : null;
351
+ return { status: 200, text: async () => JSON.stringify({ code, message: code ? "robot busy" : "success", data }) };
350
352
  };
351
353
  const a = createPadbotAdapter(creds, { baseUrl: "https://pb.test", fetch });
352
354
  await a.sendCommand("PS1", { kind: "go-to-point", mapId: "m1", targetPointId: "t2" });
@@ -13,6 +13,8 @@ import {
13
13
  clearPadbotCache,
14
14
  createPadbotAdapter,
15
15
  networkText,
16
+ PADBOT_OTHER_MAP_TEXT,
17
+ padbotCanReachMap,
16
18
  padbotPatrolPlan,
17
19
  } from "./.build/services/padbot.adapter.mjs";
18
20
  import { normalisePatrolPlan } from "./.build/utils/robot-adapter.util.mjs";
@@ -163,3 +165,51 @@ test("live video: HD asks PadBot for quality 1, default smooth for quality 2", a
163
165
  await a.getLiveVideo("PS8517");
164
166
  assert.deepEqual(f.calls.map((c) => c.body.quality), [1, 2]);
165
167
  });
168
+
169
+ /* ---------------------------- multi-map robots (owner report 2026-09-26: 2 maps, no choice) */
170
+
171
+ test("maps: the robot's current map comes from §4.2 1007 (and §4.3 when it names one)", async () => {
172
+ clearPadbotCache();
173
+ const f = fake({
174
+ [PADBOT_PATHS.states]: () => [{ serialNumber: "PS8517", states: [
175
+ { stateType: "1000", data: { updatedAt: fresh } },
176
+ { stateType: "1007", data: { mapId: "20260528172106098_5ecd8fa9", floor: -1, updatedAt: fresh } },
177
+ ] }],
178
+ [PADBOT_PATHS.location]: () => ({ mapId: "772df9dc808b45a5_20260924185244234", worldX: 1, worldY: 1, yaw: 0 }),
179
+ [PADBOT_PATHS.maps]: () => [],
180
+ [PADBOT_PATHS.alarms]: () => ({ items: [] }),
181
+ });
182
+ const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW });
183
+ const r = await a.getRobot("PS8517");
184
+ assert.equal(r.mapId, "772df9dc808b45a5_20260924185244234", "the location read's map wins (it is the newest)");
185
+ });
186
+
187
+ test("routes: each route keeps the id of the map it belongs to", () => {
188
+ const maps = [{ mapId: "mB1", floor: -1 }, { mapId: "mL3", floor: 3 }];
189
+ const paths = [
190
+ { pathId: "p1", pathName: "B1", mapId: "mB1", isDefault: true, pointNames: ["Gate", "Lobby"] },
191
+ { pathId: "p2", pathName: "Patrolling Lvl3", mapId: "mL3", pointNames: ["Lift", "Store"] },
192
+ ];
193
+ const plan = normalisePatrolPlan(padbotPatrolPlan(paths, maps, {}));
194
+ assert.deepEqual(plan.routes.map((r) => [r.name, r.mapId, r.floorNo]), [["B1 (default)", "mB1", -1], ["Patrolling Lvl3", "mL3", 3]]);
195
+ });
196
+
197
+ test("go to point on another map: only inside one map group, else 'The robot must be on this map first.'", async () => {
198
+ assert.equal(padbotCanReachMap([], "m1", "m1"), true);
199
+ assert.equal(padbotCanReachMap([{ mapId: "m1", mapGroup: "" }, { mapId: "m2", mapGroup: "" }], "m1", "m2"), false);
200
+ assert.equal(padbotCanReachMap([{ mapId: "m1", mapGroup: "tower" }, { mapId: "m2", mapGroup: "tower" }], "m1", "m2"), true);
201
+ assert.equal(padbotCanReachMap([{ mapId: "m1", mapGroup: "a" }, { mapId: "m2", mapGroup: "b" }], "m1", "m2"), false);
202
+ assert.equal(padbotCanReachMap([], null, "m1"), false, "unknown current map: refused, never guessed");
203
+
204
+ clearPadbotCache();
205
+ const f = fake({
206
+ [PADBOT_PATHS.states]: () => [{ serialNumber: "PS8517", states: [{ stateType: "1007", data: { mapId: "m1" } }] }],
207
+ [PADBOT_PATHS.maps]: () => [{ mapId: "m1", mapGroup: "" }, { mapId: "m2", mapGroup: "" }],
208
+ [PADBOT_PATHS.navigateTarget]: () => null,
209
+ });
210
+ const a = createPadbotAdapter(CREDS, { baseUrl: "https://pb.test", fetch: f.fetch, now: () => NOW });
211
+ await assert.rejects(a.sendCommand("PS8517", { kind: "go-to-point", mapId: "m2", targetPointId: "t9" }), (e) => e.message === PADBOT_OTHER_MAP_TEXT);
212
+ assert.ok(!f.calls.some((c) => c.path === PADBOT_PATHS.navigateTarget), "nothing sent to the robot");
213
+ await a.sendCommand("PS8517", { kind: "go-to-point", mapId: "m1", targetPointId: "t1" });
214
+ assert.equal(f.calls.at(-1).path, PADBOT_PATHS.navigateTarget);
215
+ });