@7365admin1/core 3.116.0 → 3.117.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/dist/index.mjs CHANGED
@@ -9970,12 +9970,16 @@ function planFaultChanges(open, reading) {
9970
9970
  want.push({ code: fault.code, message: fault.message || fault.code, since: fault.since });
9971
9971
  const clear = [];
9972
9972
  const toOpen = [];
9973
+ const refresh = [];
9973
9974
  for (const w of want) {
9974
9975
  const existing = byCode.get(w.code);
9975
9976
  if (!existing) {
9976
9977
  toOpen.push(w);
9977
9978
  continue;
9978
9979
  }
9980
+ if (w.code === OFFLINE_FAULT_CODE && typeof existing.message === "string" && existing.message !== w.message) {
9981
+ refresh.push({ id: existing._id, message: w.message });
9982
+ }
9979
9983
  const newOccurrence = typeof w.since === "number" && Math.abs(new Date(existing.since).getTime() - w.since) > SAME_OCCURRENCE_MS;
9980
9984
  if (newOccurrence) {
9981
9985
  clear.push(existing._id);
@@ -9990,7 +9994,7 @@ function planFaultChanges(open, reading) {
9990
9994
  continue;
9991
9995
  clear.push(r._id);
9992
9996
  }
9993
- return { open: toOpen, clear };
9997
+ return { open: toOpen, clear, refresh };
9994
9998
  }
9995
9999
  function robotFaultSweepConfig(env2 = process.env) {
9996
10000
  const num3 = (v, def, min, max) => {
@@ -61834,15 +61838,18 @@ function normalisePatrolPlan(raw) {
61834
61838
  if (!id || !name || routes.some((x) => x.id === id))
61835
61839
  continue;
61836
61840
  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)
61841
+ const stops = (Array.isArray(route.stops) ? route.stops.slice(0, 100) : []).map((s) => plainText(s)).filter(Boolean);
61842
+ if (checkpoints.length < 2 && !stops.length)
61838
61843
  continue;
61844
+ const drawn = checkpoints.length >= 2 ? checkpoints : [];
61839
61845
  const cur = route.currentCheckpoint;
61840
61846
  routes.push({
61841
61847
  id,
61842
61848
  name,
61843
61849
  floorNo: Number.isInteger(route.floorNo) ? route.floorNo : null,
61844
- checkpoints,
61845
- currentCheckpoint: Number.isInteger(cur) && cur >= 0 && cur < checkpoints.length ? cur : null
61850
+ checkpoints: drawn,
61851
+ currentCheckpoint: Number.isInteger(cur) && cur >= 0 && cur < drawn.length ? cur : null,
61852
+ ...stops.length ? { stops } : {}
61846
61853
  });
61847
61854
  }
61848
61855
  const schedule = [];
@@ -61865,7 +61872,7 @@ function normalisePatrolPlan(raw) {
61865
61872
  continue;
61866
61873
  schedule.push({ routeId, days, startTime, endTime, rounds: Math.min(row.rounds, 99) });
61867
61874
  }
61868
- return { routes, schedule };
61875
+ return { routes, schedule, ...r.scheduleShared === false ? { scheduleShared: false } : {} };
61869
61876
  }
61870
61877
  var COMMAND_NEEDS = {
61871
61878
  full: "startProcess",
@@ -64078,11 +64085,12 @@ function padbotMode(states, now = Date.now()) {
64078
64085
  return { online: true, mode, statusName: `${base}${networkText(states["1107"])}` };
64079
64086
  }
64080
64087
  function networkText(net) {
64088
+ const say = (label2, v) => v < 0 ? ` \xB7 ${label2} ${v} dBm` : ` \xB7 ${label2} signal ${v}`;
64081
64089
  const wifi = num(net?.wifi?.signalStrength);
64082
64090
  if (wifi !== null)
64083
- return ` \xB7 Wi-Fi ${wifi} dBm`;
64091
+ return say("Wi-Fi", wifi);
64084
64092
  const cell = num(net?.cellular?.signalStrength);
64085
- return cell !== null ? ` \xB7 Mobile ${cell} dBm` : "";
64093
+ return cell !== null ? say("Mobile", cell) : "";
64086
64094
  }
64087
64095
  function padbotPlanShare(frame2, x, y) {
64088
64096
  const w = num(frame2?.width), h = num(frame2?.height), r = num(frame2?.resolution);
@@ -64110,26 +64118,41 @@ function padbotAlarmFault(alarm) {
64110
64118
  };
64111
64119
  }
64112
64120
  function padbotPatrolPlan(paths, maps, states = {}) {
64113
- const mapById = new Map((maps ?? []).map((m) => [m.mapId, m]));
64121
+ const allMaps = Array.isArray(maps) ? maps : [];
64122
+ const mapById = new Map(allMaps.map((m) => [m?.mapId, m]));
64114
64123
  const nav = states["1003"] ?? {};
64115
64124
  const walking = states["1010"]?.workState === 1 && states["1010"]?.taskType === 2;
64116
64125
  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 };
64126
+ const findPoint = (mapId, id, name) => {
64127
+ const order = [mapById.get(mapId), ...allMaps.filter((m) => m?.mapId !== mapId)].filter(Boolean);
64128
+ for (const by of ["id", "name"]) {
64129
+ for (const map of order) {
64130
+ const tp = (map.targetPoints ?? []).find(
64131
+ (t) => by === "id" ? id && t?.targetPointId === id : name && t?.name === name
64132
+ );
64133
+ if (tp)
64134
+ return { map, tp };
64135
+ }
64136
+ }
64137
+ return null;
64138
+ };
64139
+ const routes = (Array.isArray(paths) ? paths : []).map((p) => {
64140
+ const map = mapById.get(p?.mapId);
64141
+ 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 }));
64142
+ const placed = raw.map((pt) => {
64143
+ const hit = findPoint(pt.mapId, pt.id, pt.name);
64144
+ const share = hit ? padbotPlanShare(hit.map, hit.tp?.worldX, hit.tp?.worldY) : null;
64145
+ return { name: String(pt.name ?? hit?.tp?.name ?? ""), x: share?.x, y: share?.y };
64124
64146
  });
64125
64147
  return {
64126
- id: String(p.pathId ?? ""),
64127
- name: `${p.pathName ?? "Route"}${p.isDefault ? " (default)" : ""}`,
64148
+ id: String(p?.pathId ?? ""),
64149
+ name: `${p?.pathName || "Route"}${p?.isDefault ? " (default)" : ""}`,
64128
64150
  floorNo: Number.isInteger(map?.floor) ? map.floor : null,
64129
- checkpoints,
64151
+ checkpoints: placed,
64130
64152
  currentCheckpoint: null,
64131
- _mapId: p.mapId,
64132
- _default: !!p.isDefault
64153
+ stops: placed.map((c) => c.name).filter(Boolean),
64154
+ _mapId: p?.mapId,
64155
+ _default: !!p?.isDefault
64133
64156
  };
64134
64157
  });
64135
64158
  const next = walking ? nav.nextTargetPointName : null;
@@ -64143,7 +64166,7 @@ function padbotPatrolPlan(paths, maps, states = {}) {
64143
64166
  delete r._mapId;
64144
64167
  delete r._default;
64145
64168
  }
64146
- return { routes, schedule: [] };
64169
+ return { routes, schedule: [], scheduleShared: false };
64147
64170
  }
64148
64171
  function padbotPatrolRecord(r) {
64149
64172
  return {
@@ -64168,6 +64191,7 @@ function padbotCheckpointVisit(d) {
64168
64191
  maxTempC: num(d?.maxTemperature)
64169
64192
  };
64170
64193
  }
64194
+ 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
64195
  var page = (data, map) => ({
64172
64196
  items: (Array.isArray(data?.items) ? data.items : []).map(map),
64173
64197
  total: num(data?.totalItems) ?? 0,
@@ -64201,7 +64225,56 @@ function createPadbotClient(credentials, options = {}) {
64201
64225
  throw new BadRequestError135(padbotErrorText(Number(json?.code)));
64202
64226
  return json.data;
64203
64227
  }
64204
- return { call, baseUrl };
64228
+ async function raw(path5, body = {}) {
64229
+ const t0 = Date.now();
64230
+ const req = padbotSignedRequest({ path: path5, body, accessKeyId: credentials.appid, accessKeySecret: credentials.secret, now: options.now });
64231
+ try {
64232
+ const res = await doFetch(`${baseUrl}${path5}`, { method: "POST", headers: req.headers, body: req.body, signal: AbortSignal.timeout(timeoutMs) });
64233
+ const text2 = await res.text();
64234
+ let json = null;
64235
+ try {
64236
+ json = JSON.parse(text2);
64237
+ } catch {
64238
+ }
64239
+ return {
64240
+ httpStatus: res.status,
64241
+ code: typeof json?.code === "number" ? json.code : null,
64242
+ message: typeof json?.message === "string" ? json.message.slice(0, 300) : json ? "" : `not JSON (${text2.length} bytes)`,
64243
+ data: json?.data ?? null,
64244
+ ms: Date.now() - t0
64245
+ };
64246
+ } catch (error) {
64247
+ return { httpStatus: null, code: null, message: error?.name === "TimeoutError" ? "timed out" : "unreachable", data: null, ms: Date.now() - t0 };
64248
+ }
64249
+ }
64250
+ return { call, raw, baseUrl };
64251
+ }
64252
+ function mapSummary(m) {
64253
+ const count = (v) => Array.isArray(v) ? v.length : 0;
64254
+ return {
64255
+ mapId: m?.mapId,
64256
+ mapName: m?.mapName,
64257
+ mapDisplayName: m?.mapDisplayName,
64258
+ building: m?.building,
64259
+ floor: m?.floor,
64260
+ isDefault: m?.isDefault,
64261
+ width: m?.width,
64262
+ height: m?.height,
64263
+ resolution: m?.resolution,
64264
+ originX: m?.originX,
64265
+ originY: m?.originY,
64266
+ targetPoints: (Array.isArray(m?.targetPoints) ? m.targetPoints : []).slice(0, 200).map((t) => ({
64267
+ targetPointId: t?.targetPointId,
64268
+ mapId: t?.mapId,
64269
+ name: t?.name,
64270
+ worldX: t?.worldX,
64271
+ worldY: t?.worldY,
64272
+ yaw: t?.yaw,
64273
+ targetPointType: t?.targetPointType
64274
+ })),
64275
+ counts: { targetPoints: count(m?.targetPoints), restrictedAreas: count(m?.restrictedAreas), speedLimitAreas: count(m?.speedLimitAreas), passableAreas: count(m?.passableAreas), virtualTracks: count(m?.virtualTracks) },
64276
+ otherKeys: Object.keys(m ?? {}).filter((k) => !["targetPoints", "restrictedAreas", "speedLimitAreas", "passableAreas", "virtualTracks", "imageUrl", "mapFileUrl"].includes(k))
64277
+ };
64205
64278
  }
64206
64279
  var CACHE_TTL_MS = 5 * 6e4;
64207
64280
  var cache2 = /* @__PURE__ */ new Map();
@@ -64220,11 +64293,11 @@ function clearPadbotCache() {
64220
64293
  cache2.clear();
64221
64294
  }
64222
64295
  function createPadbotAdapter(credentials, options = {}) {
64223
- const { call } = createPadbotClient(credentials, options);
64296
+ const { call, raw } = createPadbotClient(credentials, options);
64224
64297
  const now = options.now ?? Date.now;
64225
64298
  const ns = `${credentials.appid}@${options.baseUrl ?? padbotBaseUrl()}`;
64226
64299
  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 }));
64300
+ const maps = (sn) => cached2(`${ns}:maps:${sn}`, () => call(PADBOT_PATHS.maps, { serialNumber: sn }).then(asList));
64228
64301
  const states = async (sn) => {
64229
64302
  const list = await call(PADBOT_PATHS.states, { serialNumbers: [sn] });
64230
64303
  const entry = (list ?? []).find((e) => e?.serialNumber === sn);
@@ -64262,11 +64335,15 @@ function createPadbotAdapter(credentials, options = {}) {
64262
64335
  call(PADBOT_PATHS.location, { serialNumber: robotSn }).catch(() => null),
64263
64336
  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
64337
  ]);
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
- }
64338
+ const lx = num(loc?.worldX ?? loc?.x);
64339
+ const ly = num(loc?.worldY ?? loc?.y);
64340
+ if (lx !== null && ly !== null) {
64341
+ robot.position = { x: lx, y: ly, theta: (num(loc.yaw ?? loc.r) ?? 0) * Math.PI / 180 };
64342
+ const map = await maps(robotSn).then((all) => (all ?? []).find((m) => m.mapId === (loc.mapId ?? st["1007"]?.mapId))).catch(() => null);
64343
+ robot.planPosition = padbotPlanShare(map, lx, ly);
64344
+ }
64345
+ if (!robot.position)
64346
+ robot.statusName = `${robot.statusName} \xB7 Position not reported`;
64270
64347
  if (alarm)
64271
64348
  robot.fault = padbotAlarmFault(alarm);
64272
64349
  return robot;
@@ -64335,16 +64412,38 @@ function createPadbotAdapter(credentials, options = {}) {
64335
64412
  async getMaps(robotSn) {
64336
64413
  return await maps(robotSn) ?? [];
64337
64414
  },
64415
+ /**
64416
+ * Staff Diagnose: PadBot's raw answers (code, message, data) for the reads
64417
+ * behind the robot screen - states, location, maps (summarised), patrol
64418
+ * routes, newest alarm, newest patrol record. Read-only; no credential,
64419
+ * no MQTT credential, ever.
64420
+ */
64421
+ async diagnose(robotSn) {
64422
+ const sn = { serialNumber: robotSn };
64423
+ const steps = [];
64424
+ const run = async (step, path5, body, shape = (d) => d) => {
64425
+ const r = await raw(path5, body);
64426
+ 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 });
64427
+ };
64428
+ await run("states (4.2)", PADBOT_PATHS.states, { serialNumbers: [robotSn] });
64429
+ await run("location (4.3)", PADBOT_PATHS.location, sn);
64430
+ await run("maps (5.1)", PADBOT_PATHS.maps, sn, (d) => Array.isArray(d) ? d.slice(0, 100).map(mapSummary) : d);
64431
+ await run("patrol routes (6.1)", PADBOT_PATHS.patrolRoutes, sn, (d) => Array.isArray(d) ? d.slice(0, 50) : d);
64432
+ await run("alarms (6.4)", PADBOT_PATHS.alarms, { serialNumbers: [robotSn], pageNumber: 1, pageSize: 3 });
64433
+ await run("patrol records (6.7)", PADBOT_PATHS.records, { serialNumbers: [robotSn], pageNumber: 1, pageSize: 3 });
64434
+ return steps;
64435
+ },
64338
64436
  async getPatrolRoutes(robotSn) {
64339
64437
  const [paths, allMaps, st] = await Promise.all([
64340
- call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }),
64438
+ call(PADBOT_PATHS.patrolRoutes, { serialNumber: robotSn }).then(asList),
64341
64439
  maps(robotSn).catch(() => []),
64342
64440
  states(robotSn).catch(() => null)
64343
64441
  ]);
64344
64442
  return padbotPatrolPlan(paths ?? [], allMaps ?? [], st ?? {});
64345
64443
  },
64346
- async getLiveVideo(robotSn) {
64347
- const d = await call(PADBOT_PATHS.video, { serialNumber: robotSn, quality: 2 });
64444
+ // §6.5: the robot's current surveillance stream; 1 = HD main stream, 2 = smooth sub stream (default here).
64445
+ async getLiveVideo(robotSn, quality) {
64446
+ const d = await call(PADBOT_PATHS.video, { serialNumber: robotSn, quality: quality === "hd" ? 1 : 2 });
64348
64447
  if (!d?.playbackUrl)
64349
64448
  throw new BadRequestError135("PadBot has no video for this robot right now.");
64350
64449
  return { url: String(d.playbackUrl), expiresAt: d.expiresAt ?? null };
@@ -64575,9 +64674,9 @@ function useRobotFleetService(deps) {
64575
64674
  }
64576
64675
  return { adapter, fn: fn.bind(adapter) };
64577
64676
  }
64578
- async function getLiveVideo(robot) {
64677
+ async function getLiveVideo(robot, quality) {
64579
64678
  const { fn } = extra(robot, "getLiveVideo", "liveVideo", "live video");
64580
- return fn(await resolveRobotSn(robot));
64679
+ return fn(await resolveRobotSn(robot), quality);
64581
64680
  }
64582
64681
  async function resolveAlerts(robot, code) {
64583
64682
  const { fn } = extra(robot, "resolveAlerts", "resolveAlerts", "resolving alerts");
@@ -64717,6 +64816,25 @@ function useRobotFleetService(deps) {
64717
64816
  return out("maps", describeFailure(e).detail);
64718
64817
  }
64719
64818
  }
64819
+ if (adapter.diagnose) {
64820
+ try {
64821
+ for (const r of await adapter.diagnose(serial)) {
64822
+ const ok = r.code === 0;
64823
+ steps.push({
64824
+ step: String(r.step),
64825
+ ok,
64826
+ ms: r.ms,
64827
+ detail: ok ? "Answered." : `Vendor answered ${r.httpStatus ?? "nothing"}${r.code !== null && r.code !== void 0 ? `, code ${r.code}` : ""}${r.message ? `: ${r.message}` : ""}.`,
64828
+ ...r.httpStatus ? { httpStatus: r.httpStatus } : {},
64829
+ ...r.code !== null && r.code !== void 0 ? { vendorCode: String(r.code) } : {},
64830
+ ...r.message ? { vendorMessage: r.message } : {},
64831
+ raw: { path: r.path, body: r.body, data: r.data }
64832
+ });
64833
+ }
64834
+ } catch (e) {
64835
+ steps.push({ step: "vendor reads", ok: false, ...describeFailure(e) });
64836
+ }
64837
+ }
64720
64838
  return out(null, "Every step worked.");
64721
64839
  }
64722
64840
  return {
@@ -66553,7 +66671,7 @@ function useRobotFaultRepo() {
66553
66671
  }
66554
66672
  }
66555
66673
  async function getOpenFaults() {
66556
- return collection.find({ clearedAt: null }, { projection: { robotId: 1, code: 1, since: 1 } }).toArray();
66674
+ return collection.find({ clearedAt: null }, { projection: { robotId: 1, code: 1, since: 1, message: 1 } }).toArray();
66557
66675
  }
66558
66676
  async function getOpenFault(robotId, code) {
66559
66677
  return collection.findOne({ robotId: toId3(robotId), code, clearedAt: null });
@@ -66614,6 +66732,9 @@ function useRobotFaultRepo() {
66614
66732
  async function markNotified(id, at2) {
66615
66733
  await collection.updateOne({ _id: toId3(id), notifiedAt: null }, { $set: { notifiedAt: at2 } });
66616
66734
  }
66735
+ async function setFaultMessage(id, message) {
66736
+ await collection.updateOne({ _id: toId3(id), clearedAt: null }, { $set: { message } });
66737
+ }
66617
66738
  async function clearFault(id) {
66618
66739
  await collection.updateOne(
66619
66740
  { _id: toId3(id), clearedAt: null },
@@ -66643,6 +66764,7 @@ function useRobotFaultRepo() {
66643
66764
  findNotifiedOccurrence,
66644
66765
  markNotified,
66645
66766
  clearFault,
66767
+ setFaultMessage,
66646
66768
  listNetworkFaults,
66647
66769
  countNetworkFaults
66648
66770
  };
@@ -66797,6 +66919,8 @@ function useRobotFaultSweep(deps) {
66797
66919
  await repo.clearFault(id);
66798
66920
  out.cleared++;
66799
66921
  }
66922
+ for (const r of plan.refresh)
66923
+ await repo.setFaultMessage(r.id, r.message);
66800
66924
  if (offlineRec) {
66801
66925
  const online = plan.clear.includes(offlineRec._id);
66802
66926
  if (await alertConnection(robot, offlineRec._id, online, cfg.offlineAlertMinutes, deps?.connectionNotifyFn))
@@ -67038,8 +67162,9 @@ function useRobotFleetController(deps) {
67038
67162
  async function getLiveVideo(req, res, next) {
67039
67163
  try {
67040
67164
  const robot = await entitleRobot(req, req.params.id);
67165
+ const quality = req.body?.quality === "hd" ? "hd" : "smooth";
67041
67166
  res.set("Cache-Control", "no-store");
67042
- res.json(await getFleet2().getLiveVideo(robot));
67167
+ res.json(await getFleet2().getLiveVideo(robot, quality));
67043
67168
  } catch (error) {
67044
67169
  fail(next, error);
67045
67170
  }
@@ -103102,6 +103227,7 @@ export {
103102
103227
  allowsRobotListing,
103103
103228
  applyTrackingFrame,
103104
103229
  areaColourToHex,
103230
+ asList,
103105
103231
  attendanceSchema,
103106
103232
  attendanceSettingsSchema,
103107
103233
  buildSelfServiceEmailContext,
@@ -103275,6 +103401,7 @@ export {
103275
103401
  moduleGateMode,
103276
103402
  moduleImpact,
103277
103403
  moduleListGateOn,
103404
+ networkText,
103278
103405
  newCode,
103279
103406
  newSecret,
103280
103407
  nfcPatrolSettingsSchema,