@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/dist/index.mjs CHANGED
@@ -61893,7 +61893,8 @@ function normalisePatrolPlan(raw) {
61893
61893
  floorNo: Number.isInteger(route.floorNo) ? route.floorNo : null,
61894
61894
  checkpoints: drawn,
61895
61895
  currentCheckpoint: Number.isInteger(cur) && cur >= 0 && cur < drawn.length ? cur : null,
61896
- ...stops.length ? { stops } : {}
61896
+ ...stops.length ? { stops } : {},
61897
+ ...plainText(route.mapId, 80) ? { mapId: plainText(route.mapId, 80) } : {}
61897
61898
  });
61898
61899
  }
61899
61900
  const schedule = [];
@@ -62404,7 +62405,7 @@ function useRobotCloudService(credentials, options = {}) {
62404
62405
  credentials.secret,
62405
62406
  path5,
62406
62407
  params,
62407
- void 0,
62408
+ options.now?.(),
62408
62409
  options.timestampFormat
62409
62410
  );
62410
62411
  const step = robotCloudStepName(path5);
@@ -64591,6 +64592,19 @@ function padbotPlanShare(frame2, x, y) {
64591
64592
  return null;
64592
64593
  return { x: Math.round(sx * 100) / 100, y: Math.round(sy * 100) / 100 };
64593
64594
  }
64595
+ function padbotCanReachMap(maps, fromMapId, toMapId) {
64596
+ if (typeof toMapId !== "string" || !toMapId || typeof fromMapId !== "string" || !fromMapId)
64597
+ return false;
64598
+ if (fromMapId === toMapId)
64599
+ return true;
64600
+ const list = Array.isArray(maps) ? maps : [];
64601
+ const group = (id) => {
64602
+ const g = list.find((m) => m?.mapId === id)?.mapGroup;
64603
+ return typeof g === "string" ? g.trim() : "";
64604
+ };
64605
+ return group(fromMapId) !== "" && group(fromMapId) === group(toMapId);
64606
+ }
64607
+ var PADBOT_OTHER_MAP_TEXT = "The robot must be on this map first.";
64594
64608
  function padbotAlarmFault(alarm) {
64595
64609
  if (!alarm?.alarmType)
64596
64610
  return null;
@@ -64643,21 +64657,19 @@ function padbotPatrolPlan(paths, maps, states = {}) {
64643
64657
  checkpoints: placed,
64644
64658
  currentCheckpoint: null,
64645
64659
  stops: placed.map((c) => c.name).filter(Boolean),
64646
- _mapId: p?.mapId,
64660
+ ...typeof p?.mapId === "string" && p.mapId ? { mapId: p.mapId } : {},
64647
64661
  _default: !!p?.isDefault
64648
64662
  };
64649
64663
  });
64650
64664
  const next = walking ? nav.nextTargetPointName : null;
64651
- const candidates = next ? routes.filter((r) => r._mapId === currentMap && r.checkpoints.some((c) => c.name === next)) : [];
64665
+ const candidates = next ? routes.filter((r) => r.mapId === currentMap && r.checkpoints.some((c) => c.name === next)) : [];
64652
64666
  if (candidates.length === 1) {
64653
64667
  const r = candidates[0];
64654
64668
  r.currentCheckpoint = r.checkpoints.findIndex((c) => c.name === next);
64655
64669
  }
64656
64670
  routes.sort((a, b) => Number(b.currentCheckpoint !== null) - Number(a.currentCheckpoint !== null) || Number(b._default) - Number(a._default));
64657
- for (const r of routes) {
64658
- delete r._mapId;
64671
+ for (const r of routes)
64659
64672
  delete r._default;
64660
- }
64661
64673
  return { routes, schedule: [], scheduleShared: false };
64662
64674
  }
64663
64675
  function padbotPatrolRecord(r) {
@@ -64871,6 +64883,7 @@ function createPadbotAdapter(credentials, options = {}) {
64871
64883
  batteryPercent: battery,
64872
64884
  floorNo: Number.isInteger(floor) ? floor : null,
64873
64885
  floorKnown: Number.isInteger(floor),
64886
+ mapId: typeof st["1007"]?.mapId === "string" && st["1007"].mapId ? st["1007"].mapId : null,
64874
64887
  position: null,
64875
64888
  planPosition: null,
64876
64889
  fault: null
@@ -64891,6 +64904,8 @@ function createPadbotAdapter(credentials, options = {}) {
64891
64904
  const ly = num(loc?.worldY ?? loc?.y);
64892
64905
  if (lx !== null && ly !== null) {
64893
64906
  robot.position = { x: lx, y: ly, theta: (num(loc.yaw ?? loc.r) ?? 0) * Math.PI / 180 };
64907
+ if (typeof loc.mapId === "string" && loc.mapId)
64908
+ robot.mapId = loc.mapId;
64894
64909
  const map = await maps(robotSn).then((all) => (all ?? []).find((m) => m.mapId === (loc.mapId ?? st["1007"]?.mapId))).catch(() => null);
64895
64910
  robot.planPosition = padbotPlanShare(map, lx, ly);
64896
64911
  }
@@ -64950,9 +64965,13 @@ function createPadbotAdapter(credentials, options = {}) {
64950
64965
  case "relocalize":
64951
64966
  await call2(PADBOT_PATHS.relocate, { ...sn, worldX: command.x, worldY: command.y });
64952
64967
  return;
64953
- case "go-to-point":
64968
+ case "go-to-point": {
64969
+ const [st, all] = await Promise.all([states(robotSn), maps(robotSn).catch(() => [])]);
64970
+ if (!padbotCanReachMap(all, st?.["1007"]?.mapId, command.mapId))
64971
+ throw new BadRequestError135(PADBOT_OTHER_MAP_TEXT);
64954
64972
  await call2(PADBOT_PATHS.navigateTarget, { ...sn, mapId: command.mapId, targetPointId: command.targetPointId });
64955
64973
  return;
64974
+ }
64956
64975
  default:
64957
64976
  throw new BadRequestError135(`PadBot robots cannot "${command.kind}" through the PadBot API.`);
64958
64977
  }
@@ -65069,6 +65088,15 @@ function registerPadbotBrand() {
65069
65088
  registerPadbotBrand();
65070
65089
 
65071
65090
  // src/services/robot-fleet.service.ts
65091
+ var TIMESTAMP_OFFSET_CANDIDATES = [
65092
+ { offsetMinutes: 120, label: "UTC+2 (Frankfurt summer time)" },
65093
+ { offsetMinutes: 60, label: "UTC+1 (Frankfurt winter time)" },
65094
+ { offsetMinutes: 480, label: "UTC+8 (China / Singapore)" },
65095
+ { offsetMinutes: -480, label: "UTC-8" },
65096
+ { offsetMinutes: 540, label: "UTC+9" },
65097
+ { offsetMinutes: 1, label: "UTC +1 min drift" },
65098
+ { offsetMinutes: -1, label: "UTC -1 min drift" }
65099
+ ];
65072
65100
  var lastTimestampProbe = /* @__PURE__ */ new Map();
65073
65101
  var TIMESTAMP_PROBE_INTERVAL_MS = 6e4;
65074
65102
  function cloudHost(baseUrl) {
@@ -65142,6 +65170,7 @@ function useRobotFleetService(deps) {
65142
65170
  batteryPercent: null,
65143
65171
  floorNo: null,
65144
65172
  floorKnown: false,
65173
+ mapId: null,
65145
65174
  position: null,
65146
65175
  planPosition: null,
65147
65176
  fault: null,
@@ -65173,6 +65202,7 @@ function useRobotFleetService(deps) {
65173
65202
  batteryPercent: found.batteryPercent ?? null,
65174
65203
  floorNo: found.floorNo ?? null,
65175
65204
  floorKnown: found.floorKnown === true,
65205
+ mapId: typeof found.mapId === "string" && found.mapId ? found.mapId : null,
65176
65206
  position: found.position ?? null,
65177
65207
  planPosition: found.planPosition ?? null,
65178
65208
  fault,
@@ -65414,12 +65444,13 @@ function useRobotFleetService(deps) {
65414
65444
  }
65415
65445
  return out(null, "Every step worked.");
65416
65446
  }
65417
- async function probeTimestampFormat(robot) {
65447
+ function probeGate(robot, kind) {
65418
65448
  if (String(robot.brand ?? "").trim() !== OUNITECH_BRAND) {
65419
65449
  throw new BadRequestError136("The timestamp probe is for Ounitech robots only.");
65420
65450
  }
65421
65451
  const id = robot._id ? String(robot._id) : "";
65422
- const last = lastTimestampProbe.get(id);
65452
+ const key = `${id}:${kind}`;
65453
+ const last = lastTimestampProbe.get(key);
65423
65454
  if (last && Date.now() - last < TIMESTAMP_PROBE_INTERVAL_MS) {
65424
65455
  const wait = Math.ceil((TIMESTAMP_PROBE_INTERVAL_MS - (Date.now() - last)) / 1e3);
65425
65456
  throw new AppError25(`The timestamp probe ran for this robot less than a minute ago - try again in ${wait} s.`, 429);
@@ -65428,7 +65459,48 @@ function useRobotFleetService(deps) {
65428
65459
  if (!pair.appid || !pair.secret) {
65429
65460
  throw new BadRequestError136("No AppID and Secret saved on this robot - run Diagnose first.");
65430
65461
  }
65431
- lastTimestampProbe.set(id, Date.now());
65462
+ lastTimestampProbe.set(key, Date.now());
65463
+ return { id, pair };
65464
+ }
65465
+ async function probeTimestampOffset(robot) {
65466
+ const { id, pair } = probeGate(robot, "offset");
65467
+ const baseUrl = deps?.cloudOptions?.baseUrl ?? ROBOT_CLOUD_BASE_URL;
65468
+ let skewMs = null;
65469
+ const onReply = ({ date }) => {
65470
+ const t = date ? Date.parse(date) : NaN;
65471
+ if (skewMs === null && !Number.isNaN(t))
65472
+ skewMs = t - Date.now();
65473
+ };
65474
+ const attempts = [];
65475
+ let accepted = null;
65476
+ for (const c of [{ offsetMinutes: 0, label: "UTC (current)" }, ...TIMESTAMP_OFFSET_CANDIDATES]) {
65477
+ const now = () => new Date(Date.now() + (skewMs ?? 0) + c.offsetMinutes * 6e4);
65478
+ const sent = robotCloudTimestamp(now(), "yyyyMMddHHmmss");
65479
+ try {
65480
+ const robots = await useRobotCloudService(pair, { ...deps?.cloudOptions, timestampFormat: "yyyyMMddHHmmss", now, onReply }).getRobots();
65481
+ attempts.push({ ...c, sent, ok: true, detail: `Accepted. The account lists ${robots.length} robot${robots.length === 1 ? "" : "s"}.` });
65482
+ accepted = c.offsetMinutes;
65483
+ break;
65484
+ } catch (e) {
65485
+ attempts.push({ ...c, sent, ok: false, ...describeFailure(e) });
65486
+ if (e instanceof RobotCloudError && (e.kind === "unreachable" || e.kind === "timeout"))
65487
+ break;
65488
+ }
65489
+ }
65490
+ const skew = skewMs;
65491
+ const winner = attempts[attempts.length - 1];
65492
+ return {
65493
+ robotId: id,
65494
+ cloudHost: cloudHost(baseUrl),
65495
+ vendorSkewSeconds: skew === null ? null : Math.round(skew / 1e3),
65496
+ acceptedOffsetMinutes: accepted,
65497
+ attempts,
65498
+ summary: accepted === null ? "Ounitech accepted none of the offsets tried - ask Ounitech for an exact example timestamp." : accepted === 0 ? "Ounitech accepts plain UTC now - the earlier refusal was not the offset." : `Ounitech accepts yyyyMMddHHmmss at ${winner.label} (${accepted > 0 ? "+" : ""}${accepted} min from UTC).`,
65499
+ checkedAt: (/* @__PURE__ */ new Date()).toISOString()
65500
+ };
65501
+ }
65502
+ async function probeTimestampFormat(robot) {
65503
+ const { id, pair } = probeGate(robot, "format");
65432
65504
  const baseUrl = deps?.cloudOptions?.baseUrl ?? ROBOT_CLOUD_BASE_URL;
65433
65505
  const attempts = [];
65434
65506
  let accepted = null;
@@ -65458,6 +65530,7 @@ function useRobotFleetService(deps) {
65458
65530
  return {
65459
65531
  diagnose,
65460
65532
  probeTimestampFormat,
65533
+ probeTimestampOffset,
65461
65534
  getLiveVideo,
65462
65535
  resolveAlerts,
65463
65536
  getPatrolHistory,
@@ -68367,7 +68440,7 @@ function useRobotFleetController(deps) {
68367
68440
  return;
68368
68441
  heardAt = Date.now();
68369
68442
  void Promise.resolve(adapter.getMaps?.(robotSn) ?? []).then((maps) => padbotPlanShare((maps ?? []).find((m) => m?.mapId === e.mapId), e.x, e.y)).catch(() => null).then(
68370
- (planPosition) => send2({ type: "pose", pose: { x: e.x, y: e.y, theta: (e.yawDeg ?? 0) * Math.PI / 180 }, planPosition, at: Date.now() })
68443
+ (planPosition) => send2({ type: "pose", pose: { x: e.x, y: e.y, theta: (e.yawDeg ?? 0) * Math.PI / 180 }, planPosition, mapId: e.mapId ?? null, at: Date.now() })
68371
68444
  );
68372
68445
  });
68373
68446
  }
@@ -68519,12 +68592,15 @@ function useRobotFleetController(deps) {
68519
68592
  try {
68520
68593
  await requirePlatformStaff(req, CROSS_CLIENT_GRANT);
68521
68594
  const probe = req.query.probe;
68522
- if (probe !== void 0 && probe !== "timestamp") {
68523
- return fail(next, new BadRequestError139('probe must be "timestamp".'));
68595
+ if (probe !== void 0 && probe !== "timestamp" && probe !== "timestamp-offset") {
68596
+ return fail(next, new BadRequestError139('probe must be "timestamp" or "timestamp-offset".'));
68524
68597
  }
68525
68598
  const robot = await entitleRobot(req, req.params.id);
68526
68599
  res.set("Cache-Control", "no-store");
68527
- res.json(probe === "timestamp" ? await getFleet2().probeTimestampFormat(robot) : await getFleet2().diagnose(robot));
68600
+ const fleet2 = getFleet2();
68601
+ res.json(
68602
+ probe === "timestamp" ? await fleet2.probeTimestampFormat(robot) : probe === "timestamp-offset" ? await fleet2.probeTimestampOffset(robot) : await fleet2.diagnose(robot)
68603
+ );
68528
68604
  } catch (error) {
68529
68605
  fail(next, error);
68530
68606
  }
@@ -104468,6 +104544,7 @@ export {
104468
104544
  PADBOT_MOTION,
104469
104545
  PADBOT_MQTT_SYNC_MS,
104470
104546
  PADBOT_ONLINE_WINDOW_MS,
104547
+ PADBOT_OTHER_MAP_TEXT,
104471
104548
  PADBOT_PATHS,
104472
104549
  PATROL_CCTV_CAMERA_FILTER,
104473
104550
  PATROL_EMAIL_MAX_LOGS,
@@ -104531,6 +104608,7 @@ export {
104531
104608
  SubjectSort,
104532
104609
  SubscriptionBillingMode,
104533
104610
  SubscriptionType,
104611
+ TIMESTAMP_OFFSET_CANDIDATES,
104534
104612
  TRACKING_BACKOFF_BASE_MS,
104535
104613
  TRACKING_BACKOFF_CAP_MS,
104536
104614
  TRACKING_IDLE_TIMEOUT_MS,
@@ -104802,6 +104880,7 @@ export {
104802
104880
  padbotAlarmPlace,
104803
104881
  padbotAlarmPollEnabled,
104804
104882
  padbotBaseUrl,
104883
+ padbotCanReachMap,
104805
104884
  padbotCheckpointVisit,
104806
104885
  padbotCommandLog,
104807
104886
  padbotDriveBlock,