@7365admin1/core 3.119.0 → 3.120.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/CHANGELOG.md +6 -0
- package/dist/index.d.ts +29 -1
- package/dist/index.js +64 -7
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +63 -7
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/test/ounitech-timestamp-probe.test.mjs +57 -0
package/dist/index.mjs
CHANGED
|
@@ -62404,7 +62404,7 @@ function useRobotCloudService(credentials, options = {}) {
|
|
|
62404
62404
|
credentials.secret,
|
|
62405
62405
|
path5,
|
|
62406
62406
|
params,
|
|
62407
|
-
|
|
62407
|
+
options.now?.(),
|
|
62408
62408
|
options.timestampFormat
|
|
62409
62409
|
);
|
|
62410
62410
|
const step = robotCloudStepName(path5);
|
|
@@ -65069,6 +65069,15 @@ function registerPadbotBrand() {
|
|
|
65069
65069
|
registerPadbotBrand();
|
|
65070
65070
|
|
|
65071
65071
|
// src/services/robot-fleet.service.ts
|
|
65072
|
+
var TIMESTAMP_OFFSET_CANDIDATES = [
|
|
65073
|
+
{ offsetMinutes: 120, label: "UTC+2 (Frankfurt summer time)" },
|
|
65074
|
+
{ offsetMinutes: 60, label: "UTC+1 (Frankfurt winter time)" },
|
|
65075
|
+
{ offsetMinutes: 480, label: "UTC+8 (China / Singapore)" },
|
|
65076
|
+
{ offsetMinutes: -480, label: "UTC-8" },
|
|
65077
|
+
{ offsetMinutes: 540, label: "UTC+9" },
|
|
65078
|
+
{ offsetMinutes: 1, label: "UTC +1 min drift" },
|
|
65079
|
+
{ offsetMinutes: -1, label: "UTC -1 min drift" }
|
|
65080
|
+
];
|
|
65072
65081
|
var lastTimestampProbe = /* @__PURE__ */ new Map();
|
|
65073
65082
|
var TIMESTAMP_PROBE_INTERVAL_MS = 6e4;
|
|
65074
65083
|
function cloudHost(baseUrl) {
|
|
@@ -65414,12 +65423,13 @@ function useRobotFleetService(deps) {
|
|
|
65414
65423
|
}
|
|
65415
65424
|
return out(null, "Every step worked.");
|
|
65416
65425
|
}
|
|
65417
|
-
|
|
65426
|
+
function probeGate(robot, kind) {
|
|
65418
65427
|
if (String(robot.brand ?? "").trim() !== OUNITECH_BRAND) {
|
|
65419
65428
|
throw new BadRequestError136("The timestamp probe is for Ounitech robots only.");
|
|
65420
65429
|
}
|
|
65421
65430
|
const id = robot._id ? String(robot._id) : "";
|
|
65422
|
-
const
|
|
65431
|
+
const key = `${id}:${kind}`;
|
|
65432
|
+
const last = lastTimestampProbe.get(key);
|
|
65423
65433
|
if (last && Date.now() - last < TIMESTAMP_PROBE_INTERVAL_MS) {
|
|
65424
65434
|
const wait = Math.ceil((TIMESTAMP_PROBE_INTERVAL_MS - (Date.now() - last)) / 1e3);
|
|
65425
65435
|
throw new AppError25(`The timestamp probe ran for this robot less than a minute ago - try again in ${wait} s.`, 429);
|
|
@@ -65428,7 +65438,48 @@ function useRobotFleetService(deps) {
|
|
|
65428
65438
|
if (!pair.appid || !pair.secret) {
|
|
65429
65439
|
throw new BadRequestError136("No AppID and Secret saved on this robot - run Diagnose first.");
|
|
65430
65440
|
}
|
|
65431
|
-
lastTimestampProbe.set(
|
|
65441
|
+
lastTimestampProbe.set(key, Date.now());
|
|
65442
|
+
return { id, pair };
|
|
65443
|
+
}
|
|
65444
|
+
async function probeTimestampOffset(robot) {
|
|
65445
|
+
const { id, pair } = probeGate(robot, "offset");
|
|
65446
|
+
const baseUrl = deps?.cloudOptions?.baseUrl ?? ROBOT_CLOUD_BASE_URL;
|
|
65447
|
+
let skewMs = null;
|
|
65448
|
+
const onReply = ({ date }) => {
|
|
65449
|
+
const t = date ? Date.parse(date) : NaN;
|
|
65450
|
+
if (skewMs === null && !Number.isNaN(t))
|
|
65451
|
+
skewMs = t - Date.now();
|
|
65452
|
+
};
|
|
65453
|
+
const attempts = [];
|
|
65454
|
+
let accepted = null;
|
|
65455
|
+
for (const c of [{ offsetMinutes: 0, label: "UTC (current)" }, ...TIMESTAMP_OFFSET_CANDIDATES]) {
|
|
65456
|
+
const now = () => new Date(Date.now() + (skewMs ?? 0) + c.offsetMinutes * 6e4);
|
|
65457
|
+
const sent = robotCloudTimestamp(now(), "yyyyMMddHHmmss");
|
|
65458
|
+
try {
|
|
65459
|
+
const robots = await useRobotCloudService(pair, { ...deps?.cloudOptions, timestampFormat: "yyyyMMddHHmmss", now, onReply }).getRobots();
|
|
65460
|
+
attempts.push({ ...c, sent, ok: true, detail: `Accepted. The account lists ${robots.length} robot${robots.length === 1 ? "" : "s"}.` });
|
|
65461
|
+
accepted = c.offsetMinutes;
|
|
65462
|
+
break;
|
|
65463
|
+
} catch (e) {
|
|
65464
|
+
attempts.push({ ...c, sent, ok: false, ...describeFailure(e) });
|
|
65465
|
+
if (e instanceof RobotCloudError && (e.kind === "unreachable" || e.kind === "timeout"))
|
|
65466
|
+
break;
|
|
65467
|
+
}
|
|
65468
|
+
}
|
|
65469
|
+
const skew = skewMs;
|
|
65470
|
+
const winner = attempts[attempts.length - 1];
|
|
65471
|
+
return {
|
|
65472
|
+
robotId: id,
|
|
65473
|
+
cloudHost: cloudHost(baseUrl),
|
|
65474
|
+
vendorSkewSeconds: skew === null ? null : Math.round(skew / 1e3),
|
|
65475
|
+
acceptedOffsetMinutes: accepted,
|
|
65476
|
+
attempts,
|
|
65477
|
+
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).`,
|
|
65478
|
+
checkedAt: (/* @__PURE__ */ new Date()).toISOString()
|
|
65479
|
+
};
|
|
65480
|
+
}
|
|
65481
|
+
async function probeTimestampFormat(robot) {
|
|
65482
|
+
const { id, pair } = probeGate(robot, "format");
|
|
65432
65483
|
const baseUrl = deps?.cloudOptions?.baseUrl ?? ROBOT_CLOUD_BASE_URL;
|
|
65433
65484
|
const attempts = [];
|
|
65434
65485
|
let accepted = null;
|
|
@@ -65458,6 +65509,7 @@ function useRobotFleetService(deps) {
|
|
|
65458
65509
|
return {
|
|
65459
65510
|
diagnose,
|
|
65460
65511
|
probeTimestampFormat,
|
|
65512
|
+
probeTimestampOffset,
|
|
65461
65513
|
getLiveVideo,
|
|
65462
65514
|
resolveAlerts,
|
|
65463
65515
|
getPatrolHistory,
|
|
@@ -68519,12 +68571,15 @@ function useRobotFleetController(deps) {
|
|
|
68519
68571
|
try {
|
|
68520
68572
|
await requirePlatformStaff(req, CROSS_CLIENT_GRANT);
|
|
68521
68573
|
const probe = req.query.probe;
|
|
68522
|
-
if (probe !== void 0 && probe !== "timestamp") {
|
|
68523
|
-
return fail(next, new BadRequestError139('probe must be "timestamp".'));
|
|
68574
|
+
if (probe !== void 0 && probe !== "timestamp" && probe !== "timestamp-offset") {
|
|
68575
|
+
return fail(next, new BadRequestError139('probe must be "timestamp" or "timestamp-offset".'));
|
|
68524
68576
|
}
|
|
68525
68577
|
const robot = await entitleRobot(req, req.params.id);
|
|
68526
68578
|
res.set("Cache-Control", "no-store");
|
|
68527
|
-
|
|
68579
|
+
const fleet2 = getFleet2();
|
|
68580
|
+
res.json(
|
|
68581
|
+
probe === "timestamp" ? await fleet2.probeTimestampFormat(robot) : probe === "timestamp-offset" ? await fleet2.probeTimestampOffset(robot) : await fleet2.diagnose(robot)
|
|
68582
|
+
);
|
|
68528
68583
|
} catch (error) {
|
|
68529
68584
|
fail(next, error);
|
|
68530
68585
|
}
|
|
@@ -104531,6 +104586,7 @@ export {
|
|
|
104531
104586
|
SubjectSort,
|
|
104532
104587
|
SubscriptionBillingMode,
|
|
104533
104588
|
SubscriptionType,
|
|
104589
|
+
TIMESTAMP_OFFSET_CANDIDATES,
|
|
104534
104590
|
TRACKING_BACKOFF_BASE_MS,
|
|
104535
104591
|
TRACKING_BACKOFF_CAP_MS,
|
|
104536
104592
|
TRACKING_IDLE_TIMEOUT_MS,
|