@7365admin1/core 3.99.1-staging.390 → 3.99.1-staging.391

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.
@@ -0,0 +1,5 @@
1
+ ---
2
+ "@7365admin1/core": minor
3
+ ---
4
+
5
+ Ounitech robot cloud: default API base `https://app.frankfurt.robotcloud.top` (override `OUNITECH_API_BASE`), UTC+0 timestamp and per-endpoint sign documented against the vendor's answers; `POST /robots/discover` lists the robots a company credential covers; Add Robot can reuse the client's saved Ounitech credentials (`useClientCredentials`) with a picked serial.
package/dist/index.d.ts CHANGED
@@ -7027,6 +7027,11 @@ declare function useRobotRepo(): {
7027
7027
  name: string;
7028
7028
  };
7029
7029
  }>;
7030
+ getClientCloudCredentials: (site: string, brand: string) => Promise<{
7031
+ appKey: string;
7032
+ appToken: string;
7033
+ } | null>;
7034
+ getClientSerials: (site: string, serials: string[]) => Promise<Set<string>>;
7030
7035
  maxDemoSerial: (letter: "C" | "S") => Promise<number>;
7031
7036
  getDemoRobotsAtSite: (site: string) => Promise<mongodb.WithId<bson.Document>[]>;
7032
7037
  getNetworkSummary: () => Promise<{
@@ -7113,7 +7118,7 @@ declare function useRobotController(): {
7113
7118
  * file owns the request signature, the status vocabulary and the two coordinate
7114
7119
  * conversions the cloud's own documentation leaves the caller to do.
7115
7120
  *
7116
- * Source: "Robot Cloud API Document (2025.05.27)". The cloud is ours, so where
7121
+ * Source: "Robot Cloud API Document (2025.05.27)" (Ounitech's cloud). Where
7117
7122
  * the document is ambiguous the ambiguity is recorded here rather than guessed
7118
7123
  * away - see ROBOT_CLOUD_DOC_CONFIRMATIONS at the bottom.
7119
7124
  */
@@ -7123,14 +7128,28 @@ declare function useRobotController(): {
7123
7128
  * appid=[appid],timestamp=[timestamp],url=[path],secret=[secret]
7124
7129
  *
7125
7130
  * `path` is the request path as the document writes it, leading slash included
7126
- * (e.g. `/portal/robots/get-robot-list`). It is part of the hash, so a trailing
7127
- * slash or a missing one produces a different - rejected - signature.
7131
+ * (e.g. `/portal/robots/get-robot-list`) - the endpoint being called, so every
7132
+ * endpoint has its own sign. It is part of the hash, so a trailing slash or a
7133
+ * missing one produces a different - rejected - signature. Never the base URL.
7134
+ *
7135
+ * Ounitech confirmed on 2026-09-26 (Part 1, Q3) that the document's example
7136
+ * sign/timestamp values are a copy-paste error and the formula is authoritative.
7128
7137
  *
7129
7138
  * Exported for the tests: the assertion that matters is the string's shape, and
7130
7139
  * the shape is invisible once it has been hashed.
7131
7140
  */
7132
7141
  declare function robotCloudSigningString(appid: string, timestamp: string, path: string, secret: string): string;
7133
- /** `yyyyMMddHHmmss`, the only format the cloud accepts. */
7142
+ /**
7143
+ * `yyyyMMddHHmmss` in **UTC+0**, to the second.
7144
+ *
7145
+ * - Format and unit: the API document's auth section gives `timestamp` as
7146
+ * `yyyyMMddHHmmss` (a 14-digit calendar string, one-second resolution) - not
7147
+ * Unix seconds or milliseconds.
7148
+ * - Timezone: Ounitech's answer of 2026-09-26 (Part 1, Q4): "You must use the
7149
+ * UTC+0 time zone. If incorrect content is sent, the API will respond
7150
+ * immediately." Read with `getUTC*`, never the server's local clock - the
7151
+ * staging box and a developer laptop in Singapore would be 8 hours out.
7152
+ */
7134
7153
  declare function robotCloudTimestamp(now?: Date): string;
7135
7154
  /**
7136
7155
  * SHA-1 of the signing string, lower-case hex.
@@ -9911,6 +9930,7 @@ declare function useRobotFleetController(deps?: {
9911
9930
  sendCommand: (req: Request, res: Response, next: NextFunction) => Promise<void>;
9912
9931
  trackRobot: (req: Request, res: Response, next: NextFunction) => Promise<void>;
9913
9932
  getBrands: (_req: Request, res: Response, next: NextFunction) => Promise<void>;
9933
+ discoverRobots: (req: Request, res: Response, next: NextFunction) => Promise<void>;
9914
9934
  };
9915
9935
 
9916
9936
  /**
package/dist/index.js CHANGED
@@ -6346,7 +6346,8 @@ var SUBSCRIPTION_END_GRACE_DAYS = Number(
6346
6346
  process.env.SUBSCRIPTION_END_GRACE_DAYS ?? 7
6347
6347
  );
6348
6348
  var SUBSCRIPTION_AUTO_SUSPEND_ENABLED = process.env.SUBSCRIPTION_AUTO_SUSPEND_ENABLED === "true";
6349
- var ROBOT_CLOUD_BASE_URL = process.env.ROBOT_CLOUD_BASE_URL ?? "";
6349
+ var OUNITECH_DEFAULT_API_BASE = "https://app.frankfurt.robotcloud.top";
6350
+ var ROBOT_CLOUD_BASE_URL = process.env.OUNITECH_API_BASE || process.env.ROBOT_CLOUD_BASE_URL || OUNITECH_DEFAULT_API_BASE;
6350
6351
  var ROBOT_CLOUD_TIMEOUT_MS = Number(
6351
6352
  process.env.ROBOT_CLOUD_TIMEOUT_MS ?? 15e3
6352
6353
  );
@@ -63710,6 +63711,40 @@ function useRobotRepo() {
63710
63711
  site: { _id: site, name: String(s?.name ?? "") }
63711
63712
  };
63712
63713
  }
63714
+ async function clientSiteIds(site) {
63715
+ if (!import_mongodb108.ObjectId.isValid(site))
63716
+ return [];
63717
+ const s = await db2.collection("sites").findOne({ _id: new import_mongodb108.ObjectId(site) }, { projection: { orgId: 1, org: 1 } });
63718
+ const owner = String(s?.orgId ?? s?.org ?? "");
63719
+ if (!import_mongodb108.ObjectId.isValid(owner))
63720
+ return [new import_mongodb108.ObjectId(site), site];
63721
+ const ownerIds = [new import_mongodb108.ObjectId(owner), owner];
63722
+ const rows = await db2.collection("sites").find({ $or: [{ orgId: { $in: ownerIds } }, { org: { $in: ownerIds } }] }, { projection: { _id: 1 } }).toArray();
63723
+ return rows.flatMap((r) => [r._id, String(r._id)]);
63724
+ }
63725
+ async function getClientCloudCredentials(site, brand) {
63726
+ const sites = await clientSiteIds(site);
63727
+ if (!sites.length || !brand)
63728
+ return null;
63729
+ const row = await collection.findOne(
63730
+ {
63731
+ "metadata.siteId": { $in: sites },
63732
+ brand,
63733
+ appKey: { $type: "string", $ne: "" },
63734
+ appToken: { $type: "string", $ne: "" },
63735
+ ...NOT_DELETED
63736
+ },
63737
+ { sort: { updatedAt: -1, createdAt: -1 }, projection: { appKey: 1, appToken: 1 } }
63738
+ );
63739
+ return row ? { appKey: String(row.appKey), appToken: String(row.appToken) } : null;
63740
+ }
63741
+ async function getClientSerials(site, serials) {
63742
+ const sites = await clientSiteIds(site);
63743
+ if (!sites.length || !serials.length)
63744
+ return /* @__PURE__ */ new Set();
63745
+ const rows = await collection.find({ "metadata.siteId": { $in: sites }, robotSn: { $in: serials }, ...NOT_DELETED }, { projection: { robotSn: 1 } }).toArray();
63746
+ return new Set(rows.map((r) => String(r.robotSn)));
63747
+ }
63713
63748
  async function maxDemoSerial(letter) {
63714
63749
  const rows = await collection.find({ robotSn: { $regex: `^DEMO-${letter}-[0-9]+$` } }, { projection: { robotSn: 1 } }).toArray();
63715
63750
  return rows.reduce((max, r) => Math.max(max, Number(String(r.robotSn).split("-")[2]) || 0), 0);
@@ -63756,6 +63791,8 @@ function useRobotRepo() {
63756
63791
  getNetworkRobots,
63757
63792
  getSiteSummary,
63758
63793
  getSiteNames,
63794
+ getClientCloudCredentials,
63795
+ getClientSerials,
63759
63796
  maxDemoSerial,
63760
63797
  getDemoRobotsAtSite,
63761
63798
  getNetworkSummary,
@@ -64249,14 +64286,11 @@ function planDayFromJsDay(jsDay) {
64249
64286
  return jsDay === 0 ? 7 : jsDay;
64250
64287
  }
64251
64288
  var ROBOT_CLOUD_DOC_CONFIRMATIONS = [
64252
- // The document's examples for get-map-list and get-file-url show the SAME
64253
- // `sign` with the same appid and timestamp but DIFFERENT url paths, which the
64254
- // spec's own formula makes impossible. One of the two examples is a
64255
- // copy-paste. Confirm the exact signed `url` string for every endpoint.
64256
- "Exact signed `url` string per endpoint (the doc's own examples contradict the formula).",
64257
- // `timestamp` has no timezone. This module emits UTC; if the cloud reads it as
64258
- // Asia/Singapore every request is 8 hours out and rejected.
64259
- "Timestamp timezone (this module emits UTC) and the accepted clock-skew window.",
64289
+ // ANSWERED 2026-09-26 (Ounitech Part 1): base URL, one appid/secret per
64290
+ // company, sign = the formula with url = each endpoint's own path (the doc's
64291
+ // examples were a copy-paste), timestamp in UTC+0. Removed from this list.
64292
+ // Still open: the accepted clock-skew window.
64293
+ "Accepted clock-skew window for `timestamp` (UTC+0 confirmed; the window is not stated).",
64260
64294
  // pixelToMetres assumes the image y-origin is top-left.
64261
64295
  "Pixel y-origin: top-left (assumed) or bottom-left.",
64262
64296
  // The doc labels modeFlag "1 vacuum / 2 washing / 3 dry dust mop" on the
@@ -66167,8 +66201,10 @@ function useRobotController() {
66167
66201
  await requireSiteReach(req, site);
66168
66202
  }
66169
66203
  async function createRobot(req, res, next) {
66170
- const payload = { ...req.body, createdBy: callerId(req) };
66171
- const { error } = robotSchema.validate(payload);
66204
+ const { useClientCredentials, ...body } = req.body ?? {};
66205
+ const payload = { ...body, createdBy: callerId(req) };
66206
+ const shape = useClientCredentials === true ? { ...payload, appKey: "saved", appToken: "saved" } : payload;
66207
+ const { error } = robotSchema.validate(shape);
66172
66208
  if (error) {
66173
66209
  import_node_server_utils161.logger.log({ level: "error", message: error.message });
66174
66210
  next(new import_node_server_utils161.BadRequestError(error.message));
@@ -66182,6 +66218,19 @@ function useRobotController() {
66182
66218
  }
66183
66219
  try {
66184
66220
  await requireRobotReach(req, payload.metadata.siteId);
66221
+ if (useClientCredentials === true) {
66222
+ if (!String(payload.robotSn ?? "").trim()) {
66223
+ throw new import_node_server_utils161.BadRequestError("Pick the robot's serial - the saved credentials cover more than one robot.");
66224
+ }
66225
+ const saved = await useRobotRepo().getClientCloudCredentials(
66226
+ String(payload.metadata.siteId),
66227
+ String(payload.brand || "ounitech")
66228
+ );
66229
+ if (!saved) {
66230
+ throw new import_node_server_utils161.BadRequestError("This client has no saved credentials for this brand yet - enter them once.");
66231
+ }
66232
+ Object.assign(payload, saved);
66233
+ }
66185
66234
  const id = await _createRobot(payload);
66186
66235
  await recordConsoleAction({
66187
66236
  action: "robot.added" /* ROBOT_ADDED */,
@@ -68305,7 +68354,54 @@ function useRobotFleetController(deps) {
68305
68354
  fail(next, error);
68306
68355
  }
68307
68356
  }
68308
- return { getState, getMaps, getMapImages, getPlans, getPatrolRoutes, sendCommand: sendCommand2, trackRobot, getBrands };
68357
+ async function discoverRobots(req, res, next) {
68358
+ try {
68359
+ const { error, value } = import_joi76.default.object({
68360
+ robot: import_joi76.default.string().hex().length(24),
68361
+ site: import_joi76.default.string().hex().length(24).when("robot", { is: import_joi76.default.exist(), then: import_joi76.default.optional(), otherwise: import_joi76.default.required() }),
68362
+ brand: import_joi76.default.string().trim().max(60).allow("").default("ounitech"),
68363
+ appKey: import_joi76.default.string().trim().max(500).allow(""),
68364
+ appToken: import_joi76.default.string().trim().max(500).allow("")
68365
+ }).validate(req.body ?? {});
68366
+ if (error)
68367
+ throw new import_node_server_utils164.BadRequestError(error.message);
68368
+ if (!!value.appKey !== !!value.appToken)
68369
+ throw new import_node_server_utils164.BadRequestError("Enter both the AppID and the Secret.");
68370
+ const own = value.robot ? await entitleRobot(req, value.robot) : null;
68371
+ if (own)
68372
+ value.site = String(own.metadata?.siteId ?? "");
68373
+ else
68374
+ await requireSiteReach(req, value.site);
68375
+ const brand = own ? String(own.brand ?? "") : value.brand || "ounitech";
68376
+ if (!robotBrandFor(brand))
68377
+ throw new import_node_server_utils164.BadRequestError(`Unknown robot brand "${brand}".`);
68378
+ const pair = own ? { appKey: own.appKey, appToken: own.appToken } : value.appKey ? { appKey: value.appKey, appToken: value.appToken } : await getRepo().getClientCloudCredentials(value.site, brand);
68379
+ if (!pair)
68380
+ throw new import_node_server_utils164.BadRequestError("This client has no saved credentials for this brand yet - enter them once.");
68381
+ let fleet2;
68382
+ try {
68383
+ fleet2 = await adapterForRobot({ brand, ...pair, name: "discovery" }).listRobots();
68384
+ } catch (e) {
68385
+ if (e instanceof RobotCloudError)
68386
+ throw new import_node_server_utils164.BadRequestError(e.message);
68387
+ throw e;
68388
+ }
68389
+ const serials = fleet2.map((r) => String(r.robotSn ?? "")).filter(Boolean);
68390
+ const added = await getRepo().getClientSerials(value.site, serials);
68391
+ res.json({
68392
+ items: fleet2.filter((r) => r.robotSn).map((r) => ({
68393
+ robotSn: r.robotSn,
68394
+ name: r.name ?? "",
68395
+ online: r.online,
68396
+ statusName: r.statusName ?? "",
68397
+ added: added.has(String(r.robotSn))
68398
+ }))
68399
+ });
68400
+ } catch (error) {
68401
+ fail(next, error);
68402
+ }
68403
+ }
68404
+ return { getState, getMaps, getMapImages, getPlans, getPatrolRoutes, sendCommand: sendCommand2, trackRobot, getBrands, discoverRobots };
68309
68405
  }
68310
68406
 
68311
68407
  // src/models/robot-building-map.model.ts