@7365admin1/core 3.116.0 → 3.117.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/dist/index.mjs CHANGED
@@ -61834,15 +61834,18 @@ function normalisePatrolPlan(raw) {
61834
61834
  if (!id || !name || routes.some((x) => x.id === id))
61835
61835
  continue;
61836
61836
  const checkpoints = (Array.isArray(route.checkpoints) ? route.checkpoints.slice(0, 100) : []).map((c) => ({ name: plainText(c?.name), x: planPct(c?.x), y: planPct(c?.y) })).filter((c) => c.name && c.x !== null && c.y !== null);
61837
- if (checkpoints.length < 2)
61837
+ const stops = (Array.isArray(route.stops) ? route.stops.slice(0, 100) : []).map((s) => plainText(s)).filter(Boolean);
61838
+ if (checkpoints.length < 2 && !stops.length)
61838
61839
  continue;
61840
+ const drawn = checkpoints.length >= 2 ? checkpoints : [];
61839
61841
  const cur = route.currentCheckpoint;
61840
61842
  routes.push({
61841
61843
  id,
61842
61844
  name,
61843
61845
  floorNo: Number.isInteger(route.floorNo) ? route.floorNo : null,
61844
- checkpoints,
61845
- currentCheckpoint: Number.isInteger(cur) && cur >= 0 && cur < checkpoints.length ? cur : null
61846
+ checkpoints: drawn,
61847
+ currentCheckpoint: Number.isInteger(cur) && cur >= 0 && cur < drawn.length ? cur : null,
61848
+ ...stops.length ? { stops } : {}
61846
61849
  });
61847
61850
  }
61848
61851
  const schedule = [];
@@ -61865,7 +61868,7 @@ function normalisePatrolPlan(raw) {
61865
61868
  continue;
61866
61869
  schedule.push({ routeId, days, startTime, endTime, rounds: Math.min(row.rounds, 99) });
61867
61870
  }
61868
- return { routes, schedule };
61871
+ return { routes, schedule, ...r.scheduleShared === false ? { scheduleShared: false } : {} };
61869
61872
  }
61870
61873
  var COMMAND_NEEDS = {
61871
61874
  full: "startProcess",
@@ -64078,11 +64081,12 @@ function padbotMode(states, now = Date.now()) {
64078
64081
  return { online: true, mode, statusName: `${base}${networkText(states["1107"])}` };
64079
64082
  }
64080
64083
  function networkText(net) {
64084
+ const say = (label2, v) => v < 0 ? ` \xB7 ${label2} ${v} dBm` : ` \xB7 ${label2} signal ${v}`;
64081
64085
  const wifi = num(net?.wifi?.signalStrength);
64082
64086
  if (wifi !== null)
64083
- return ` \xB7 Wi-Fi ${wifi} dBm`;
64087
+ return say("Wi-Fi", wifi);
64084
64088
  const cell = num(net?.cellular?.signalStrength);
64085
- return cell !== null ? ` \xB7 Mobile ${cell} dBm` : "";
64089
+ return cell !== null ? say("Mobile", cell) : "";
64086
64090
  }
64087
64091
  function padbotPlanShare(frame2, x, y) {
64088
64092
  const w = num(frame2?.width), h = num(frame2?.height), r = num(frame2?.resolution);
@@ -64110,26 +64114,41 @@ function padbotAlarmFault(alarm) {
64110
64114
  };
64111
64115
  }
64112
64116
  function padbotPatrolPlan(paths, maps, states = {}) {
64113
- const mapById = new Map((maps ?? []).map((m) => [m.mapId, m]));
64117
+ const allMaps = Array.isArray(maps) ? maps : [];
64118
+ const mapById = new Map(allMaps.map((m) => [m?.mapId, m]));
64114
64119
  const nav = states["1003"] ?? {};
64115
64120
  const walking = states["1010"]?.workState === 1 && states["1010"]?.taskType === 2;
64116
64121
  const currentMap = states["1007"]?.mapId;
64117
- const routes = (paths ?? []).map((p) => {
64118
- const map = mapById.get(p.mapId);
64119
- const points = map?.targetPoints ?? [];
64120
- const checkpoints = [...p.points ?? []].sort((a, b) => (a.pointIndex ?? 0) - (b.pointIndex ?? 0)).map((pt) => {
64121
- const tp = points.find((t) => t.targetPointId === pt.targetPointId) ?? points.find((t) => t.name === pt.targetPointName);
64122
- const share = padbotPlanShare(map, tp?.worldX, tp?.worldY);
64123
- return { name: String(pt.targetPointName ?? tp?.name ?? ""), x: share?.x, y: share?.y };
64122
+ const findPoint = (mapId, id, name) => {
64123
+ const order = [mapById.get(mapId), ...allMaps.filter((m) => m?.mapId !== mapId)].filter(Boolean);
64124
+ for (const by of ["id", "name"]) {
64125
+ for (const map of order) {
64126
+ const tp = (map.targetPoints ?? []).find(
64127
+ (t) => by === "id" ? id && t?.targetPointId === id : name && t?.name === name
64128
+ );
64129
+ if (tp)
64130
+ return { map, tp };
64131
+ }
64132
+ }
64133
+ return null;
64134
+ };
64135
+ const routes = (Array.isArray(paths) ? paths : []).map((p) => {
64136
+ const map = mapById.get(p?.mapId);
64137
+ const raw = Array.isArray(p?.points) && p.points.length ? [...p.points].sort((a, b) => (a?.pointIndex ?? 0) - (b?.pointIndex ?? 0)).map((pt) => ({ id: pt?.targetPointId, name: pt?.targetPointName, mapId: pt?.mapId ?? p?.mapId })) : (Array.isArray(p?.pointNames) ? p.pointNames : []).map((n) => ({ name: n, mapId: p?.mapId }));
64138
+ const placed = raw.map((pt) => {
64139
+ const hit = findPoint(pt.mapId, pt.id, pt.name);
64140
+ const share = hit ? padbotPlanShare(hit.map, hit.tp?.worldX, hit.tp?.worldY) : null;
64141
+ return { name: String(pt.name ?? hit?.tp?.name ?? ""), x: share?.x, y: share?.y };
64124
64142
  });
64125
64143
  return {
64126
- id: String(p.pathId ?? ""),
64127
- name: `${p.pathName ?? "Route"}${p.isDefault ? " (default)" : ""}`,
64144
+ id: String(p?.pathId ?? ""),
64145
+ name: `${p?.pathName || "Route"}${p?.isDefault ? " (default)" : ""}`,
64128
64146
  floorNo: Number.isInteger(map?.floor) ? map.floor : null,
64129
- checkpoints,
64147
+ checkpoints: placed,
64130
64148
  currentCheckpoint: null,
64131
- _mapId: p.mapId,
64132
- _default: !!p.isDefault
64149
+ stops: placed.map((c) => c.name).filter(Boolean),
64150
+ _mapId: p?.mapId,
64151
+ _default: !!p?.isDefault
64133
64152
  };
64134
64153
  });
64135
64154
  const next = walking ? nav.nextTargetPointName : null;
@@ -64143,7 +64162,7 @@ function padbotPatrolPlan(paths, maps, states = {}) {
64143
64162
  delete r._mapId;
64144
64163
  delete r._default;
64145
64164
  }
64146
- return { routes, schedule: [] };
64165
+ return { routes, schedule: [], scheduleShared: false };
64147
64166
  }
64148
64167
  function padbotPatrolRecord(r) {
64149
64168
  return {
@@ -64168,6 +64187,7 @@ function padbotCheckpointVisit(d) {
64168
64187
  maxTempC: num(d?.maxTemperature)
64169
64188
  };
64170
64189
  }
64190
+ var asList = (d) => Array.isArray(d) ? d : Array.isArray(d?.items) ? d.items : Array.isArray(d?.list) ? d.list : Array.isArray(d?.records) ? d.records : [];
64171
64191
  var page = (data, map) => ({
64172
64192
  items: (Array.isArray(data?.items) ? data.items : []).map(map),
64173
64193
  total: num(data?.totalItems) ?? 0,
@@ -64201,7 +64221,56 @@ function createPadbotClient(credentials, options = {}) {
64201
64221
  throw new BadRequestError135(padbotErrorText(Number(json?.code)));
64202
64222
  return json.data;
64203
64223
  }
64204
- return { call, baseUrl };
64224
+ async function raw(path5, body = {}) {
64225
+ const t0 = Date.now();
64226
+ const req = padbotSignedRequest({ path: path5, body, accessKeyId: credentials.appid, accessKeySecret: credentials.secret, now: options.now });
64227
+ try {
64228
+ const res = await doFetch(`${baseUrl}${path5}`, { method: "POST", headers: req.headers, body: req.body, signal: AbortSignal.timeout(timeoutMs) });
64229
+ const text2 = await res.text();
64230
+ let json = null;
64231
+ try {
64232
+ json = JSON.parse(text2);
64233
+ } catch {
64234
+ }
64235
+ return {
64236
+ httpStatus: res.status,
64237
+ code: typeof json?.code === "number" ? json.code : null,
64238
+ message: typeof json?.message === "string" ? json.message.slice(0, 300) : json ? "" : `not JSON (${text2.length} bytes)`,
64239
+ data: json?.data ?? null,
64240
+ ms: Date.now() - t0
64241
+ };
64242
+ } catch (error) {
64243
+ return { httpStatus: null, code: null, message: error?.name === "TimeoutError" ? "timed out" : "unreachable", data: null, ms: Date.now() - t0 };
64244
+ }
64245
+ }
64246
+ return { call, raw, baseUrl };
64247
+ }
64248
+ function mapSummary(m) {
64249
+ const count = (v) => Array.isArray(v) ? v.length : 0;
64250
+ return {
64251
+ mapId: m?.mapId,
64252
+ mapName: m?.mapName,
64253
+ mapDisplayName: m?.mapDisplayName,
64254
+ building: m?.building,
64255
+ floor: m?.floor,
64256
+ isDefault: m?.isDefault,
64257
+ width: m?.width,
64258
+ height: m?.height,
64259
+ resolution: m?.resolution,
64260
+ originX: m?.originX,
64261
+ originY: m?.originY,
64262
+ targetPoints: (Array.isArray(m?.targetPoints) ? m.targetPoints : []).slice(0, 200).map((t) => ({
64263
+ targetPointId: t?.targetPointId,
64264
+ mapId: t?.mapId,
64265
+ name: t?.name,
64266
+ worldX: t?.worldX,
64267
+ worldY: t?.worldY,
64268
+ yaw: t?.yaw,
64269
+ targetPointType: t?.targetPointType
64270
+ })),
64271
+ counts: { targetPoints: count(m?.targetPoints), restrictedAreas: count(m?.restrictedAreas), speedLimitAreas: count(m?.speedLimitAreas), passableAreas: count(m?.passableAreas), virtualTracks: count(m?.virtualTracks) },
64272
+ otherKeys: Object.keys(m ?? {}).filter((k) => !["targetPoints", "restrictedAreas", "speedLimitAreas", "passableAreas", "virtualTracks", "imageUrl", "mapFileUrl"].includes(k))
64273
+ };
64205
64274
  }
64206
64275
  var CACHE_TTL_MS = 5 * 6e4;
64207
64276
  var cache2 = /* @__PURE__ */ new Map();
@@ -64220,11 +64289,11 @@ function clearPadbotCache() {
64220
64289
  cache2.clear();
64221
64290
  }
64222
64291
  function createPadbotAdapter(credentials, options = {}) {
64223
- const { call } = createPadbotClient(credentials, options);
64292
+ const { call, raw } = createPadbotClient(credentials, options);
64224
64293
  const now = options.now ?? Date.now;
64225
64294
  const ns = `${credentials.appid}@${options.baseUrl ?? padbotBaseUrl()}`;
64226
64295
  const roster = () => cached2(`${ns}:robots`, () => call(PADBOT_PATHS.robots, { robotTypes: ["PATROL"] }));
64227
- const maps = (sn) => cached2(`${ns}:maps:${sn}`, () => call(PADBOT_PATHS.maps, { serialNumber: sn }));
64296
+ const maps = (sn) => cached2(`${ns}:maps:${sn}`, () => call(PADBOT_PATHS.maps, { serialNumber: sn }).then(asList));
64228
64297
  const states = async (sn) => {
64229
64298
  const list = await call(PADBOT_PATHS.states, { serialNumbers: [sn] });
64230
64299
  const entry = (list ?? []).find((e) => e?.serialNumber === sn);
@@ -64262,11 +64331,15 @@ function createPadbotAdapter(credentials, options = {}) {
64262
64331
  call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null),
64263
64332
  robot.fault ? Promise.resolve(null) : call(PADBOT_PATHS.alarms, { serialNumbers: [robotSn], resolved: false, pageNumber: 1, pageSize: 1 }).then((d) => d?.items?.[0] ?? null).catch(() => null)
64264
64333
  ]);
64265
- if (loc && num(loc.worldX) !== null && num(loc.worldY) !== null) {
64266
- robot.position = { x: loc.worldX, y: loc.worldY, theta: (num(loc.yaw) ?? 0) * Math.PI / 180 };
64267
- const map = await maps(robotSn).then((all) => (all ?? []).find((m) => m.mapId === loc.mapId)).catch(() => null);
64268
- robot.planPosition = padbotPlanShare(map, loc.worldX, loc.worldY);
64269
- }
64334
+ const lx = num(loc?.worldX ?? loc?.x);
64335
+ const ly = num(loc?.worldY ?? loc?.y);
64336
+ if (lx !== null && ly !== null) {
64337
+ robot.position = { x: lx, y: ly, theta: (num(loc.yaw ?? loc.r) ?? 0) * Math.PI / 180 };
64338
+ const map = await maps(robotSn).then((all) => (all ?? []).find((m) => m.mapId === (loc.mapId ?? st["1007"]?.mapId))).catch(() => null);
64339
+ robot.planPosition = padbotPlanShare(map, lx, ly);
64340
+ }
64341
+ if (!robot.position)
64342
+ robot.statusName = `${robot.statusName} \xB7 Position not reported`;
64270
64343
  if (alarm)
64271
64344
  robot.fault = padbotAlarmFault(alarm);
64272
64345
  return robot;
@@ -64335,16 +64408,38 @@ function createPadbotAdapter(credentials, options = {}) {
64335
64408
  async getMaps(robotSn) {
64336
64409
  return await maps(robotSn) ?? [];
64337
64410
  },
64411
+ /**
64412
+ * Staff Diagnose: PadBot's raw answers (code, message, data) for the reads
64413
+ * behind the robot screen - states, location, maps (summarised), patrol
64414
+ * routes, newest alarm, newest patrol record. Read-only; no credential,
64415
+ * no MQTT credential, ever.
64416
+ */
64417
+ async diagnose(robotSn) {
64418
+ const sn = { serialNumber: robotSn };
64419
+ const steps = [];
64420
+ const run = async (step, path5, body, shape = (d) => d) => {
64421
+ const r = await raw(path5, body);
64422
+ steps.push({ step, path: path5, body, httpStatus: r.httpStatus, code: r.code, message: r.message, ms: r.ms, data: r.code === 0 ? shape(r.data) : r.data });
64423
+ };
64424
+ await run("states (4.2)", PADBOT_PATHS.states, { serialNumbers: [robotSn] });
64425
+ await run("location (4.3)", PADBOT_PATHS.location, sn);
64426
+ await run("maps (5.1)", PADBOT_PATHS.maps, sn, (d) => Array.isArray(d) ? d.slice(0, 100).map(mapSummary) : d);
64427
+ await run("patrol routes (6.1)", PADBOT_PATHS.patrolRoutes, sn, (d) => Array.isArray(d) ? d.slice(0, 50) : d);
64428
+ await run("alarms (6.4)", PADBOT_PATHS.alarms, { serialNumbers: [robotSn], pageNumber: 1, pageSize: 3 });
64429
+ await run("patrol records (6.7)", PADBOT_PATHS.records, { serialNumbers: [robotSn], pageNumber: 1, pageSize: 3 });
64430
+ return steps;
64431
+ },
64338
64432
  async getPatrolRoutes(robotSn) {
64339
64433
  const [paths, allMaps, st] = await Promise.all([
64340
- call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }),
64434
+ call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }).then(asList),
64341
64435
  maps(robotSn).catch(() => []),
64342
64436
  states(robotSn).catch(() => null)
64343
64437
  ]);
64344
64438
  return padbotPatrolPlan(paths ?? [], allMaps ?? [], st ?? {});
64345
64439
  },
64346
- async getLiveVideo(robotSn) {
64347
- const d = await call(PADBOT_PATHS.video, { serialNumber: robotSn, quality: 2 });
64440
+ // §6.5: the robot's current surveillance stream; 1 = HD main stream, 2 = smooth sub stream (default here).
64441
+ async getLiveVideo(robotSn, quality) {
64442
+ const d = await call(PADBOT_PATHS.video, { serialNumber: robotSn, quality: quality === "hd" ? 1 : 2 });
64348
64443
  if (!d?.playbackUrl)
64349
64444
  throw new BadRequestError135("PadBot has no video for this robot right now.");
64350
64445
  return { url: String(d.playbackUrl), expiresAt: d.expiresAt ?? null };
@@ -64575,9 +64670,9 @@ function useRobotFleetService(deps) {
64575
64670
  }
64576
64671
  return { adapter, fn: fn.bind(adapter) };
64577
64672
  }
64578
- async function getLiveVideo(robot) {
64673
+ async function getLiveVideo(robot, quality) {
64579
64674
  const { fn } = extra(robot, "getLiveVideo", "liveVideo", "live video");
64580
- return fn(await resolveRobotSn(robot));
64675
+ return fn(await resolveRobotSn(robot), quality);
64581
64676
  }
64582
64677
  async function resolveAlerts(robot, code) {
64583
64678
  const { fn } = extra(robot, "resolveAlerts", "resolveAlerts", "resolving alerts");
@@ -64717,6 +64812,25 @@ function useRobotFleetService(deps) {
64717
64812
  return out("maps", describeFailure(e).detail);
64718
64813
  }
64719
64814
  }
64815
+ if (adapter.diagnose) {
64816
+ try {
64817
+ for (const r of await adapter.diagnose(serial)) {
64818
+ const ok = r.code === 0;
64819
+ steps.push({
64820
+ step: String(r.step),
64821
+ ok,
64822
+ ms: r.ms,
64823
+ detail: ok ? "Answered." : `Vendor answered ${r.httpStatus ?? "nothing"}${r.code !== null && r.code !== void 0 ? `, code ${r.code}` : ""}${r.message ? `: ${r.message}` : ""}.`,
64824
+ ...r.httpStatus ? { httpStatus: r.httpStatus } : {},
64825
+ ...r.code !== null && r.code !== void 0 ? { vendorCode: String(r.code) } : {},
64826
+ ...r.message ? { vendorMessage: r.message } : {},
64827
+ raw: { path: r.path, body: r.body, data: r.data }
64828
+ });
64829
+ }
64830
+ } catch (e) {
64831
+ steps.push({ step: "vendor reads", ok: false, ...describeFailure(e) });
64832
+ }
64833
+ }
64720
64834
  return out(null, "Every step worked.");
64721
64835
  }
64722
64836
  return {
@@ -67038,8 +67152,9 @@ function useRobotFleetController(deps) {
67038
67152
  async function getLiveVideo(req, res, next) {
67039
67153
  try {
67040
67154
  const robot = await entitleRobot(req, req.params.id);
67155
+ const quality = req.body?.quality === "hd" ? "hd" : "smooth";
67041
67156
  res.set("Cache-Control", "no-store");
67042
- res.json(await getFleet2().getLiveVideo(robot));
67157
+ res.json(await getFleet2().getLiveVideo(robot, quality));
67043
67158
  } catch (error) {
67044
67159
  fail(next, error);
67045
67160
  }
@@ -103102,6 +103217,7 @@ export {
103102
103217
  allowsRobotListing,
103103
103218
  applyTrackingFrame,
103104
103219
  areaColourToHex,
103220
+ asList,
103105
103221
  attendanceSchema,
103106
103222
  attendanceSettingsSchema,
103107
103223
  buildSelfServiceEmailContext,
@@ -103275,6 +103391,7 @@ export {
103275
103391
  moduleGateMode,
103276
103392
  moduleImpact,
103277
103393
  moduleListGateOn,
103394
+ networkText,
103278
103395
  newCode,
103279
103396
  newSecret,
103280
103397
  nfcPatrolSettingsSchema,