@7365admin1/core 3.121.0 → 3.122.1

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.121.0",
4
+ "version": "3.122.1",
5
5
  "author": "7365admin1",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.mjs",
@@ -190,6 +190,9 @@ describe("robot faults - stored, deduped, network-wide", { concurrency: 1 }, ()
190
190
  assert.equal(demo.ok, true);
191
191
  assert.equal(typeof demo.online, "boolean");
192
192
  assert.ok(demo.capabilities);
193
+ // Model-aware manifest: the demo robot's model resolves (brand defaults + model), with its plain-words profile.
194
+ assert.equal(typeof demo.profile?.modelKnown, "boolean");
195
+ assert.ok(Array.isArray(demo.profile.makerAppOnly));
193
196
  assert.deepEqual(res.body.items.find((i) => i.id === String(id.noInterface)), {
194
197
  id: String(id.noInterface), ok: false, monitorable: false,
195
198
  });
@@ -2,7 +2,7 @@
2
2
  // - requests go to OUNITECH_API_BASE + the endpoint path (Q1),
3
3
  // - sign = sha1("appid=..,timestamp=..,url=<that path>,secret=..") (Q3),
4
4
  // verified SERVER-SIDE by a mock that recomputes it,
5
- // - timestamp is UTC+0 now (Q4),
5
+ // - timestamp is Asia/Shanghai now (they said UTC+0; production proved UTC+8),
6
6
  // - one AppID/Secret per company (Q2): entered once, discovered robots picked
7
7
  // by serial, reused for the client's next robot without re-entry.
8
8
  //
@@ -37,7 +37,8 @@ async function startMockOunitech() {
37
37
  const sent = /^\d{14}$/.test(t)
38
38
  ? 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))
39
39
  : NaN;
40
- const utcNow = Math.abs(Date.now() - sent) < 30_000;
40
+ // Ounitech's proven zone: Asia/Shanghai (UTC+8).
41
+ const utcNow = Math.abs(Date.now() + 8 * 3600_000 - sent) < 30_000;
41
42
  const signOk = body.appid === APPID && body.sign === sha1(`appid=${APPID},timestamp=${t},url=${req.url},secret=${SECRET}`);
42
43
  calls.push({ path: req.url, signOk, utcNow, leakedSecret: raw.includes(SECRET) });
43
44
  res.setHeader("content-type", "application/json");
@@ -58,7 +59,7 @@ async function startMockOunitech() {
58
59
  return { server, calls, url: `http://127.0.0.1:${server.address().port}/` };
59
60
  }
60
61
 
61
- describe("Ounitech: base URL, server-verified sign, UTC timestamp, one credential per company", { concurrency: 1 }, () => {
62
+ describe("Ounitech: base URL, server-verified sign, Shanghai-time timestamp, one credential per company", { concurrency: 1 }, () => {
62
63
  let h;
63
64
  let mock;
64
65
  let managerSid;
@@ -97,7 +98,7 @@ describe("Ounitech: base URL, server-verified sign, UTC timestamp, one credentia
97
98
  assert.equal(lastCall().signOk, false);
98
99
  });
99
100
 
100
- it("typed company credentials list the company's robots; request is signed for its own path in UTC", async () => {
101
+ it("typed company credentials list the company's robots; request is signed for its own path in Shanghai time", async () => {
101
102
  const res = await h.api("/robots/discover", {
102
103
  method: "POST",
103
104
  sid: managerSid,
@@ -17,7 +17,7 @@ import { createOunitechAdapter } from "./.build/services/ounitech.adapter.mjs";
17
17
  * Q1 base URL https://app.frankfurt.robotcloud.top
18
18
  * Q3 sign sha1("appid=..,timestamp=..,url=..,secret=..") with url = THAT
19
19
  * endpoint's path; the document's example values are wrong
20
- * Q4 timestamp UTC+0 (format yyyyMMddHHmmss from the document)
20
+ * Q4 timestamp: they said UTC+0; production proved Asia/Shanghai (UTC+8), 2026-09-26
21
21
  * Fake credentials only - nothing here reaches Ounitech.
22
22
  * ----------------------------------------------------------------------- */
23
23
 
@@ -34,15 +34,16 @@ test("the default base URL is the one Ounitech gave (Part 1, Q1)", () => {
34
34
  }
35
35
  });
36
36
 
37
- test("timestamp is UTC+0, not the server's local time (Part 1, Q4)", () => {
38
- assert.equal(robotCloudTimestamp(CLOCK), "20260926013005");
37
+ test("timestamp is Asia/Shanghai wall clock (proven in production), not the server's local time", () => {
38
+ assert.equal(robotCloudTimestamp(CLOCK), "20260926093005");
39
+ assert.equal(robotCloudTimestamp(CLOCK, "yyyyMMddHHmmss", "UTC"), "20260926013005");
39
40
  });
40
41
 
41
42
  for (const [name, path] of Object.entries(ROBOT_CLOUD_PATHS)) {
42
43
  test(`sign for ${name} hashes exactly its own path ${path}`, () => {
43
44
  const body = robotCloudBody(APPID, SECRET, path, { robotSn: "SN1" }, CLOCK);
44
- const expected = sha1(`appid=${APPID},timestamp=20260926013005,url=${path},secret=${SECRET}`);
45
- assert.equal(body.timestamp, "20260926013005");
45
+ const expected = sha1(`appid=${APPID},timestamp=20260926093005,url=${path},secret=${SECRET}`);
46
+ assert.equal(body.timestamp, "20260926093005");
46
47
  assert.equal(body.sign, expected);
47
48
  assert.equal(body.appid, APPID);
48
49
  assert.equal(JSON.stringify(body).includes(SECRET), false);
@@ -54,7 +55,7 @@ test("every endpoint has a different sign at the same instant (Part 1, Q3)", ()
54
55
  assert.equal(new Set(signs).size, signs.length);
55
56
  });
56
57
 
57
- test("the adapter posts to base + path, signed for that path, stamped in UTC now", async () => {
58
+ test("the adapter posts to base + path, signed for that path, stamped in Shanghai time now", async () => {
58
59
  const seen = [];
59
60
  const server = http.createServer((req, res) => {
60
61
  let raw = "";
@@ -83,7 +84,7 @@ test("the adapter posts to base + path, signed for that path, stamped in UTC now
83
84
  assert.match(body.timestamp, /^\d{14}$/);
84
85
  const t = body.timestamp;
85
86
  const sent = 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));
86
- assert.ok(Math.abs(Date.now() - sent) < 10_000, `timestamp ${t} is not UTC now`);
87
+ assert.ok(Math.abs(Date.now() + 8 * 3600_000 - sent) < 10_000, `timestamp ${t} is not Shanghai now`);
87
88
  }
88
89
  } finally {
89
90
  server.close();
@@ -6,6 +6,7 @@ import { after, before, test } from "node:test";
6
6
 
7
7
  import {
8
8
  OUNITECH_TIMESTAMP_FORMAT,
9
+ OUNITECH_TIMESTAMP_ZONE,
9
10
  ROBOT_CLOUD_PATHS,
10
11
  ROBOT_CLOUD_TIMESTAMP_FORMATS,
11
12
  robotCloudBody,
@@ -22,23 +23,24 @@ const sha1 = (s) => createHash("sha1").update(s).digest("hex");
22
23
  const PATH = ROBOT_CLOUD_PATHS.robotList;
23
24
 
24
25
  const EXPECTED = {
25
- yyyyMMddHHmmss: "20260926013005",
26
+ yyyyMMddHHmmss: "20260926093005",
26
27
  "unix-s": "1790386205",
27
28
  "unix-ms": "1790386205123",
28
- "yyyy-MM-dd HH:mm:ss": "2026-09-26 01:30:05",
29
+ "yyyy-MM-dd HH:mm:ss": "2026-09-26 09:30:05",
29
30
  iso8601: "2026-09-26T01:30:05Z",
30
31
  "unix-s-number": "1790386205",
31
32
  "unix-ms-number": "1790386205123",
32
33
  };
33
34
 
34
- test("default format is unchanged until the probe proves another", () => {
35
+ test("Ounitech: yyyyMMddHHmmss in Asia/Shanghai, both proven in production", () => {
35
36
  assert.equal(OUNITECH_TIMESTAMP_FORMAT, "yyyyMMddHHmmss");
37
+ assert.equal(OUNITECH_TIMESTAMP_ZONE, "Asia/Shanghai");
36
38
  assert.equal(robotCloudTimestamp(CLOCK), EXPECTED.yyyyMMddHHmmss);
37
39
  assert.deepEqual([...ROBOT_CLOUD_TIMESTAMP_FORMATS].sort(), Object.keys(EXPECTED).sort());
38
40
  });
39
41
 
40
42
  for (const [format, text] of Object.entries(EXPECTED)) {
41
- test(`format ${format}: UTC+0 text and a sign recomputed over that exact text`, () => {
43
+ test(`format ${format}: brand-zone text and a sign recomputed over that exact text`, () => {
42
44
  assert.equal(robotCloudTimestamp(CLOCK, format), text);
43
45
  const body = robotCloudBody(APPID, SECRET, PATH, {}, CLOCK, format);
44
46
  assert.equal(body.sign, sha1(`appid=${APPID},timestamp=${text},url=${PATH},secret=${SECRET}`));
@@ -47,6 +49,14 @@ for (const [format, text] of Object.entries(EXPECTED)) {
47
49
  });
48
50
  }
49
51
 
52
+ test("the zone is a NAMED zone: one with summer time follows it", () => {
53
+ assert.equal(robotCloudTimestamp(new Date("2026-07-01T00:00:00Z"), "yyyyMMddHHmmss", "Europe/Berlin"), "20260701020000");
54
+ assert.equal(robotCloudTimestamp(new Date("2026-01-01T00:00:00Z"), "yyyyMMddHHmmss", "Europe/Berlin"), "20260101010000");
55
+ // Shanghai has none: +8 in both seasons.
56
+ assert.equal(robotCloudTimestamp(new Date("2026-07-01T00:00:00Z")), "20260701080000");
57
+ assert.equal(robotCloudTimestamp(new Date("2026-01-01T00:00:00Z")), "20260101080000");
58
+ });
59
+
50
60
  /* -------------------------------------------------------------- the probe */
51
61
 
52
62
  // A mock Ounitech that accepts only one format, checking the sign server-side.
@@ -167,3 +177,53 @@ test("offset probe: none accepted tries all 8; its own once-a-minute limit, sepa
167
177
  assert.equal(r.attempts.length, 8);
168
178
  await assert.rejects(fleet.probeTimestampOffset(robotRow("o2")), (e) => e.statusCode === 429);
169
179
  });
180
+
181
+ /* ------------------------------------------------------- the region probe */
182
+
183
+ // Three mock "regions": one with the robot, one empty, one refusing.
184
+ let regServer;
185
+ let regBase;
186
+ const regCalls = [];
187
+ before(async () => {
188
+ regServer = http.createServer((req, res) => {
189
+ let raw = "";
190
+ req.on("data", (c) => (raw += c));
191
+ req.on("end", () => {
192
+ const [, region, ...rest] = req.url.split("/");
193
+ const path = "/" + rest.join("/");
194
+ regCalls.push({ region, path });
195
+ res.writeHead(200, { "content-type": "application/json" });
196
+ if (region === "sg") return res.end(JSON.stringify({ robotList: [{ robotSn: "Q3G-001", robotName: "Lobby", ownerName: "Owner", ownerPhone: "+6599999999", statusName: "Idle", onlineFlag: true }] }));
197
+ if (region === "fra") return res.end(JSON.stringify({ robotList: [] }));
198
+ return res.end(JSON.stringify({ ok: false, msg: "invalid appid" }));
199
+ });
200
+ });
201
+ regServer.listen(0, "127.0.0.1");
202
+ await once(regServer, "listening");
203
+ regBase = `http://127.0.0.1:${regServer.address().port}`;
204
+ });
205
+ after(() => regServer.close());
206
+
207
+ test("region probe: asks every region's robot list, shows shape and robots, no owner phone or secret", async () => {
208
+ regCalls.length = 0;
209
+ const fleet = useRobotFleetService({
210
+ cloudOptions: { baseUrl: `${regBase}/fra`, timeoutMs: 1000 },
211
+ regionBaseUrls: [`${regBase}/fra`, `${regBase}/sg`, `${regBase}/cn`],
212
+ });
213
+ const r = await fleet.probeRegions(robotRow("r1"));
214
+ assert.deepEqual(r.hosts.map((h) => h.ok), [true, true, false]);
215
+ assert.deepEqual(r.hosts[0].replyShape, { robotList: "list of 0" });
216
+ assert.deepEqual(r.hosts[1].robots, [{ robotSn: "Q3G-001", robotName: "Lobby", online: true, statusName: "Idle" }]);
217
+ assert.equal(r.hosts[2].vendorMessage, "invalid appid");
218
+ assert.match(r.summary, /Robots found on .*\(1\)/);
219
+ assert.ok(regCalls.every((c) => c.path === PATH), "only the robot list is called");
220
+ const text = JSON.stringify(r);
221
+ assert.equal(text.includes(SECRET) || text.includes(APPID) || text.includes("+6599999999"), false);
222
+ await assert.rejects(fleet.probeRegions(robotRow("r1")), (e) => e.statusCode === 429);
223
+ });
224
+
225
+ test("region probe: every region empty says Ounitech must bind the robot", async () => {
226
+ const fleet = useRobotFleetService({ cloudOptions: { timeoutMs: 1000 }, regionBaseUrls: [`${regBase}/fra`] });
227
+ const r = await fleet.probeRegions(robotRow("r2"));
228
+ assert.match(r.summary, /must bind the robot/);
229
+ });
@@ -33,8 +33,9 @@ import {
33
33
  } from "./.build/utils/padbot-mqtt.util.mjs";
34
34
  import { floorWord, robotFaultText } from "./.build/utils/robot-fault.util.mjs";
35
35
  import { parseRobotCommand } from "./.build/utils/robot-cloud.util.mjs";
36
- import { commandSupported } from "./.build/utils/robot-adapter.util.mjs";
36
+ import { commandSupported, registerRobotBrand, robotManifest } from "./.build/utils/robot-adapter.util.mjs";
37
37
  import {
38
+ PADBOT_BRAND_DEFINITION,
38
39
  PADBOT_CAPABILITIES,
39
40
  PADBOT_PATHS,
40
41
  clearPadbotCache,
@@ -185,9 +186,12 @@ test("flags: MQTT and alarm poll default on; manual drive default OFF (only the
185
186
  assert.equal(padbotManualDriveEnabled({ PADBOT_MANUAL_DRIVE: " On " }), true);
186
187
  const env = process.env.PADBOT_MANUAL_DRIVE;
187
188
  delete process.env.PADBOT_MANUAL_DRIVE;
188
- assert.equal(PADBOT_CAPABILITIES.manualDrive, false, "the capability follows the flag");
189
+ registerRobotBrand(PADBOT_BRAND_DEFINITION);
190
+ assert.equal(robotManifest("padbot", "S2").capabilities.manualDrive, false, "the capability follows the flag");
189
191
  process.env.PADBOT_MANUAL_DRIVE = "on";
190
- assert.equal({ ...PADBOT_CAPABILITIES }.manualDrive, true);
192
+ assert.equal(robotManifest("padbot", "S2").capabilities.manualDrive, true);
193
+ assert.equal(PADBOT_CAPABILITIES.manualDrive, false, "S2 only: the drive limits are the S2's head range");
194
+ assert.equal(robotManifest("padbot", "P3").capabilities.manualDrive, false, "another model: no manual control");
191
195
  if (env === undefined) delete process.env.PADBOT_MANUAL_DRIVE;
192
196
  else process.env.PADBOT_MANUAL_DRIVE = env;
193
197
  });
@@ -73,14 +73,15 @@ test("missing credentials throw instead of signing an empty secret", () => {
73
73
  assert.throws(() => robotCloudSign("a", "20250520200000", "/p", ""), /secret/);
74
74
  });
75
75
 
76
- test("the timestamp is yyyyMMddHHmmss, zero-padded", () => {
76
+ test("the timestamp is yyyyMMddHHmmss, zero-padded, Shanghai wall clock", () => {
77
+ // 20:00 UTC is 04:00 the next day in Shanghai (UTC+8).
77
78
  assert.equal(
78
79
  robotCloudTimestamp(new Date(Date.UTC(2025, 4, 20, 20, 0, 0))),
79
- "20250520200000"
80
+ "20250521040000"
80
81
  );
81
82
  // Single-digit month, day, hour, minute and second all pad.
82
83
  assert.equal(
83
- robotCloudTimestamp(new Date(Date.UTC(2025, 0, 2, 3, 4, 5))),
84
+ robotCloudTimestamp(new Date(Date.UTC(2025, 0, 2, 3, 4, 5)), "yyyyMMddHHmmss", "UTC"),
84
85
  "20250102030405"
85
86
  );
86
87
  });
@@ -0,0 +1,83 @@
1
+ // Capabilities per brand AND model: brand defaults + the model's differences;
2
+ // an unknown model gets the brand's defaults, an unknown brand gets nothing.
3
+ import assert from "node:assert/strict";
4
+ import { test } from "node:test";
5
+
6
+ import { commandSupported, registerRobotBrand, registeredRobotBrands, robotManifest, robotTier } from "./.build/utils/robot-adapter.util.mjs";
7
+ import { PADBOT_BRAND_DEFINITION } from "./.build/services/padbot.adapter.mjs";
8
+ import { OUNITECH_BRAND_DEFINITION } from "./.build/services/ounitech.adapter.mjs";
9
+ import { DEMO_BRAND_DEFINITION } from "./.build/services/demo.adapter.mjs";
10
+
11
+ // Each test bundle carries its own registry: register the adapters' exact definitions here.
12
+ for (const b of [PADBOT_BRAND_DEFINITION, OUNITECH_BRAND_DEFINITION, DEMO_BRAND_DEFINITION]) registerRobotBrand(b);
13
+
14
+ test("PadBot S2: the full security set, heat camera, S2 alarms and maker-app list", () => {
15
+ for (const reported of ["PadBot S2", "S2", "padbot s2", " PADBOT-S2 "]) {
16
+ const m = robotManifest("padbot", reported);
17
+ assert.equal(m.profile.model, "PadBot S2", reported);
18
+ assert.equal(m.profile.modelKnown, true, reported);
19
+ }
20
+ const { capabilities: c, profile } = robotManifest("padbot", "PadBot S2");
21
+ for (const k of ["patrolControl", "liveVideo", "patrolHistory", "resolveAlerts", "battery", "floorReporting", "readLocation", "sendToDock", "relocalize", "navigateToPoint", "thermalCamera"]) {
22
+ assert.equal(c[k], true, k);
23
+ }
24
+ for (const k of ["pauseResume", "spotClean", "multiFloor", "pathAndEta"]) assert.equal(c[k], false, k);
25
+ assert.equal(commandSupported(c, "pause"), false, "PadBot has no pause");
26
+ assert.equal(commandSupported(c, "cancel"), true);
27
+ assert.ok(profile.alarms.includes("smoke") && profile.alarms.includes("high temperature"));
28
+ assert.equal(profile.makerApp, "the PadBot app");
29
+ assert.ok(profile.makerAppOnly.includes("patrol schedules"));
30
+ assert.equal(Object.getOwnPropertyDescriptor(c, "manualDrive").get, undefined, "a plain object, getters read");
31
+ });
32
+
33
+ test("PadBot unknown model: the brand defaults (API-wide), no S2 extras", () => {
34
+ const { capabilities: c, profile } = robotManifest("padbot", "PadBot P3");
35
+ assert.equal(profile.modelKnown, false);
36
+ assert.equal(profile.model, "PadBot P3", "the reported name is kept");
37
+ assert.equal(c.patrolControl, true);
38
+ assert.equal(c.thermalCamera, false);
39
+ assert.equal(c.manualDrive, false);
40
+ assert.equal(profile.makerAppOnly.includes("live thermal view"), false, "heat camera is the S2's");
41
+ assert.ok(robotManifest("padbot", "S2").profile.makerAppOnly.includes("live thermal view"));
42
+ assert.equal(robotManifest("padbot").profile.model, "");
43
+ });
44
+
45
+ test("Ounitech: no model reported, one manifest for Q3-G and Q3-W; Basic control", () => {
46
+ const { capabilities: c, profile } = robotManifest("ounitech", "");
47
+ assert.equal(profile.modelKnown, false);
48
+ assert.equal(c.startProcess, true);
49
+ assert.equal(c.sendToDock, true);
50
+ for (const k of ["battery", "floorReporting", "pauseResume", "pauseProcess", "spotClean", "liveVideo", "patrolControl"]) assert.notEqual(c[k], true, k);
51
+ assert.equal(profile.makerApp, "the Ounitech app");
52
+ assert.deepEqual(profile.alarms, []);
53
+ });
54
+
55
+ test("Demo: models differ - S1 and SP-1 full, CX-1 no point commands", () => {
56
+ const s1 = robotManifest("demo", "Demo S1").capabilities;
57
+ const cx = robotManifest("demo", "Demo CX-1");
58
+ const sp = robotManifest("demo", "Demo SP-1").capabilities;
59
+ assert.equal(robotTier(s1), "full-control");
60
+ assert.equal(s1.spotClean, true);
61
+ assert.equal(cx.profile.modelKnown, true);
62
+ assert.equal(cx.capabilities.navigateToPoint, false);
63
+ assert.equal(commandSupported(cx.capabilities, "relocalize"), false);
64
+ assert.equal(commandSupported(cx.capabilities, "full"), true);
65
+ assert.equal(robotTier(sp), "full-control", "the demo patroller keeps its Full control badge");
66
+ });
67
+
68
+ test("unknown brand: nothing claimed", () => {
69
+ const m = robotManifest("acme", "Z9");
70
+ assert.deepEqual(m.capabilities, {});
71
+ assert.equal(m.profile.model, "Z9");
72
+ assert.equal(m.profile.modelKnown, false);
73
+ assert.equal(robotManifest(undefined).profile.model, "");
74
+ });
75
+
76
+ test("brand list carries each model's resolved manifest", () => {
77
+ const padbot = registeredRobotBrands().find((b) => b.brand === "padbot");
78
+ assert.deepEqual(padbot.models.map((m) => m.name), ["PadBot S2"]);
79
+ assert.equal(padbot.models[0].capabilities.thermalCamera, true);
80
+ assert.equal(padbot.capabilities.thermalCamera, false);
81
+ const demo = registeredRobotBrands().find((b) => b.brand === "demo");
82
+ assert.deepEqual(demo.models.map((m) => m.name), ["Demo CX-1"]);
83
+ });