@7365admin1/core 3.113.0 → 3.114.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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @iservice365/core
2
2
 
3
+ ## 3.114.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 043ab69: 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.
8
+
3
9
  ## 3.113.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.d.ts CHANGED
@@ -6947,6 +6947,11 @@ declare function useRobotRepo(): {
6947
6947
  name: string;
6948
6948
  };
6949
6949
  }>;
6950
+ getClientCloudCredentials: (site: string, brand: string) => Promise<{
6951
+ appKey: string;
6952
+ appToken: string;
6953
+ } | null>;
6954
+ getClientSerials: (site: string, serials: string[]) => Promise<Set<string>>;
6950
6955
  maxDemoSerial: (letter: "C" | "S") => Promise<number>;
6951
6956
  getDemoRobotsAtSite: (site: string) => Promise<mongodb.WithId<bson.Document>[]>;
6952
6957
  getNetworkSummary: () => Promise<{
@@ -7033,7 +7038,7 @@ declare function useRobotController(): {
7033
7038
  * file owns the request signature, the status vocabulary and the two coordinate
7034
7039
  * conversions the cloud's own documentation leaves the caller to do.
7035
7040
  *
7036
- * Source: "Robot Cloud API Document (2025.05.27)". The cloud is ours, so where
7041
+ * Source: "Robot Cloud API Document (2025.05.27)" (Ounitech's cloud). Where
7037
7042
  * the document is ambiguous the ambiguity is recorded here rather than guessed
7038
7043
  * away - see ROBOT_CLOUD_DOC_CONFIRMATIONS at the bottom.
7039
7044
  */
@@ -7043,14 +7048,28 @@ declare function useRobotController(): {
7043
7048
  * appid=[appid],timestamp=[timestamp],url=[path],secret=[secret]
7044
7049
  *
7045
7050
  * `path` is the request path as the document writes it, leading slash included
7046
- * (e.g. `/portal/robots/get-robot-list`). It is part of the hash, so a trailing
7047
- * slash or a missing one produces a different - rejected - signature.
7051
+ * (e.g. `/portal/robots/get-robot-list`) - the endpoint being called, so every
7052
+ * endpoint has its own sign. It is part of the hash, so a trailing slash or a
7053
+ * missing one produces a different - rejected - signature. Never the base URL.
7054
+ *
7055
+ * Ounitech confirmed on 2026-09-26 (Part 1, Q3) that the document's example
7056
+ * sign/timestamp values are a copy-paste error and the formula is authoritative.
7048
7057
  *
7049
7058
  * Exported for the tests: the assertion that matters is the string's shape, and
7050
7059
  * the shape is invisible once it has been hashed.
7051
7060
  */
7052
7061
  declare function robotCloudSigningString(appid: string, timestamp: string, path: string, secret: string): string;
7053
- /** `yyyyMMddHHmmss`, the only format the cloud accepts. */
7062
+ /**
7063
+ * `yyyyMMddHHmmss` in **UTC+0**, to the second.
7064
+ *
7065
+ * - Format and unit: the API document's auth section gives `timestamp` as
7066
+ * `yyyyMMddHHmmss` (a 14-digit calendar string, one-second resolution) - not
7067
+ * Unix seconds or milliseconds.
7068
+ * - Timezone: Ounitech's answer of 2026-09-26 (Part 1, Q4): "You must use the
7069
+ * UTC+0 time zone. If incorrect content is sent, the API will respond
7070
+ * immediately." Read with `getUTC*`, never the server's local clock - the
7071
+ * staging box and a developer laptop in Singapore would be 8 hours out.
7072
+ */
7054
7073
  declare function robotCloudTimestamp(now?: Date): string;
7055
7074
  /**
7056
7075
  * SHA-1 of the signing string, lower-case hex.
@@ -9831,6 +9850,7 @@ declare function useRobotFleetController(deps?: {
9831
9850
  sendCommand: (req: Request, res: Response, next: NextFunction) => Promise<void>;
9832
9851
  trackRobot: (req: Request, res: Response, next: NextFunction) => Promise<void>;
9833
9852
  getBrands: (_req: Request, res: Response, next: NextFunction) => Promise<void>;
9853
+ discoverRobots: (req: Request, res: Response, next: NextFunction) => Promise<void>;
9834
9854
  };
9835
9855
 
9836
9856
  /**
package/dist/index.js CHANGED
@@ -6328,7 +6328,8 @@ var SUBSCRIPTION_END_GRACE_DAYS = Number(
6328
6328
  process.env.SUBSCRIPTION_END_GRACE_DAYS ?? 7
6329
6329
  );
6330
6330
  var SUBSCRIPTION_AUTO_SUSPEND_ENABLED = process.env.SUBSCRIPTION_AUTO_SUSPEND_ENABLED === "true";
6331
- var ROBOT_CLOUD_BASE_URL = process.env.ROBOT_CLOUD_BASE_URL ?? "";
6331
+ var OUNITECH_DEFAULT_API_BASE = "https://app.frankfurt.robotcloud.top";
6332
+ var ROBOT_CLOUD_BASE_URL = process.env.OUNITECH_API_BASE || process.env.ROBOT_CLOUD_BASE_URL || OUNITECH_DEFAULT_API_BASE;
6332
6333
  var ROBOT_CLOUD_TIMEOUT_MS = Number(
6333
6334
  process.env.ROBOT_CLOUD_TIMEOUT_MS ?? 15e3
6334
6335
  );
@@ -62056,6 +62057,40 @@ function useRobotRepo() {
62056
62057
  site: { _id: site, name: String(s?.name ?? "") }
62057
62058
  };
62058
62059
  }
62060
+ async function clientSiteIds(site) {
62061
+ if (!import_mongodb108.ObjectId.isValid(site))
62062
+ return [];
62063
+ const s = await db2.collection("sites").findOne({ _id: new import_mongodb108.ObjectId(site) }, { projection: { orgId: 1, org: 1 } });
62064
+ const owner = String(s?.orgId ?? s?.org ?? "");
62065
+ if (!import_mongodb108.ObjectId.isValid(owner))
62066
+ return [new import_mongodb108.ObjectId(site), site];
62067
+ const ownerIds = [new import_mongodb108.ObjectId(owner), owner];
62068
+ const rows = await db2.collection("sites").find({ $or: [{ orgId: { $in: ownerIds } }, { org: { $in: ownerIds } }] }, { projection: { _id: 1 } }).toArray();
62069
+ return rows.flatMap((r) => [r._id, String(r._id)]);
62070
+ }
62071
+ async function getClientCloudCredentials(site, brand) {
62072
+ const sites = await clientSiteIds(site);
62073
+ if (!sites.length || !brand)
62074
+ return null;
62075
+ const row = await collection.findOne(
62076
+ {
62077
+ "metadata.siteId": { $in: sites },
62078
+ brand,
62079
+ appKey: { $type: "string", $ne: "" },
62080
+ appToken: { $type: "string", $ne: "" },
62081
+ ...NOT_DELETED
62082
+ },
62083
+ { sort: { updatedAt: -1, createdAt: -1 }, projection: { appKey: 1, appToken: 1 } }
62084
+ );
62085
+ return row ? { appKey: String(row.appKey), appToken: String(row.appToken) } : null;
62086
+ }
62087
+ async function getClientSerials(site, serials) {
62088
+ const sites = await clientSiteIds(site);
62089
+ if (!sites.length || !serials.length)
62090
+ return /* @__PURE__ */ new Set();
62091
+ const rows = await collection.find({ "metadata.siteId": { $in: sites }, robotSn: { $in: serials }, ...NOT_DELETED }, { projection: { robotSn: 1 } }).toArray();
62092
+ return new Set(rows.map((r) => String(r.robotSn)));
62093
+ }
62059
62094
  async function maxDemoSerial(letter) {
62060
62095
  const rows = await collection.find({ robotSn: { $regex: `^DEMO-${letter}-[0-9]+$` } }, { projection: { robotSn: 1 } }).toArray();
62061
62096
  return rows.reduce((max, r) => Math.max(max, Number(String(r.robotSn).split("-")[2]) || 0), 0);
@@ -62102,6 +62137,8 @@ function useRobotRepo() {
62102
62137
  getNetworkRobots,
62103
62138
  getSiteSummary,
62104
62139
  getSiteNames,
62140
+ getClientCloudCredentials,
62141
+ getClientSerials,
62105
62142
  maxDemoSerial,
62106
62143
  getDemoRobotsAtSite,
62107
62144
  getNetworkSummary,
@@ -62595,14 +62632,11 @@ function planDayFromJsDay(jsDay) {
62595
62632
  return jsDay === 0 ? 7 : jsDay;
62596
62633
  }
62597
62634
  var ROBOT_CLOUD_DOC_CONFIRMATIONS = [
62598
- // The document's examples for get-map-list and get-file-url show the SAME
62599
- // `sign` with the same appid and timestamp but DIFFERENT url paths, which the
62600
- // spec's own formula makes impossible. One of the two examples is a
62601
- // copy-paste. Confirm the exact signed `url` string for every endpoint.
62602
- "Exact signed `url` string per endpoint (the doc's own examples contradict the formula).",
62603
- // `timestamp` has no timezone. This module emits UTC; if the cloud reads it as
62604
- // Asia/Singapore every request is 8 hours out and rejected.
62605
- "Timestamp timezone (this module emits UTC) and the accepted clock-skew window.",
62635
+ // ANSWERED 2026-09-26 (Ounitech Part 1): base URL, one appid/secret per
62636
+ // company, sign = the formula with url = each endpoint's own path (the doc's
62637
+ // examples were a copy-paste), timestamp in UTC+0. Removed from this list.
62638
+ // Still open: the accepted clock-skew window.
62639
+ "Accepted clock-skew window for `timestamp` (UTC+0 confirmed; the window is not stated).",
62606
62640
  // pixelToMetres assumes the image y-origin is top-left.
62607
62641
  "Pixel y-origin: top-left (assumed) or bottom-left.",
62608
62642
  // The doc labels modeFlag "1 vacuum / 2 washing / 3 dry dust mop" on the
@@ -64513,8 +64547,10 @@ function useRobotController() {
64513
64547
  await requireSiteReach(req, site);
64514
64548
  }
64515
64549
  async function createRobot(req, res, next) {
64516
- const payload = { ...req.body, createdBy: callerId(req) };
64517
- const { error } = robotSchema.validate(payload);
64550
+ const { useClientCredentials, ...body } = req.body ?? {};
64551
+ const payload = { ...body, createdBy: callerId(req) };
64552
+ const shape = useClientCredentials === true ? { ...payload, appKey: "saved", appToken: "saved" } : payload;
64553
+ const { error } = robotSchema.validate(shape);
64518
64554
  if (error) {
64519
64555
  import_node_server_utils161.logger.log({ level: "error", message: error.message });
64520
64556
  next(new import_node_server_utils161.BadRequestError(error.message));
@@ -64528,6 +64564,19 @@ function useRobotController() {
64528
64564
  }
64529
64565
  try {
64530
64566
  await requireRobotReach(req, payload.metadata.siteId);
64567
+ if (useClientCredentials === true) {
64568
+ if (!String(payload.robotSn ?? "").trim()) {
64569
+ throw new import_node_server_utils161.BadRequestError("Pick the robot's serial - the saved credentials cover more than one robot.");
64570
+ }
64571
+ const saved = await useRobotRepo().getClientCloudCredentials(
64572
+ String(payload.metadata.siteId),
64573
+ String(payload.brand || "ounitech")
64574
+ );
64575
+ if (!saved) {
64576
+ throw new import_node_server_utils161.BadRequestError("This client has no saved credentials for this brand yet - enter them once.");
64577
+ }
64578
+ Object.assign(payload, saved);
64579
+ }
64531
64580
  const id = await _createRobot(payload);
64532
64581
  await recordConsoleAction({
64533
64582
  action: "robot.added" /* ROBOT_ADDED */,
@@ -66651,7 +66700,54 @@ function useRobotFleetController(deps) {
66651
66700
  fail(next, error);
66652
66701
  }
66653
66702
  }
66654
- return { getState, getMaps, getMapImages, getPlans, getPatrolRoutes, sendCommand: sendCommand2, trackRobot, getBrands };
66703
+ async function discoverRobots(req, res, next) {
66704
+ try {
66705
+ const { error, value } = import_joi76.default.object({
66706
+ robot: import_joi76.default.string().hex().length(24),
66707
+ 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() }),
66708
+ brand: import_joi76.default.string().trim().max(60).allow("").default("ounitech"),
66709
+ appKey: import_joi76.default.string().trim().max(500).allow(""),
66710
+ appToken: import_joi76.default.string().trim().max(500).allow("")
66711
+ }).validate(req.body ?? {});
66712
+ if (error)
66713
+ throw new import_node_server_utils164.BadRequestError(error.message);
66714
+ if (!!value.appKey !== !!value.appToken)
66715
+ throw new import_node_server_utils164.BadRequestError("Enter both the AppID and the Secret.");
66716
+ const own = value.robot ? await entitleRobot(req, value.robot) : null;
66717
+ if (own)
66718
+ value.site = String(own.metadata?.siteId ?? "");
66719
+ else
66720
+ await requireSiteReach(req, value.site);
66721
+ const brand = own ? String(own.brand ?? "") : value.brand || "ounitech";
66722
+ if (!robotBrandFor(brand))
66723
+ throw new import_node_server_utils164.BadRequestError(`Unknown robot brand "${brand}".`);
66724
+ const pair = own ? { appKey: own.appKey, appToken: own.appToken } : value.appKey ? { appKey: value.appKey, appToken: value.appToken } : await getRepo().getClientCloudCredentials(value.site, brand);
66725
+ if (!pair)
66726
+ throw new import_node_server_utils164.BadRequestError("This client has no saved credentials for this brand yet - enter them once.");
66727
+ let fleet2;
66728
+ try {
66729
+ fleet2 = await adapterForRobot({ brand, ...pair, name: "discovery" }).listRobots();
66730
+ } catch (e) {
66731
+ if (e instanceof RobotCloudError)
66732
+ throw new import_node_server_utils164.BadRequestError(e.message);
66733
+ throw e;
66734
+ }
66735
+ const serials = fleet2.map((r) => String(r.robotSn ?? "")).filter(Boolean);
66736
+ const added = await getRepo().getClientSerials(value.site, serials);
66737
+ res.json({
66738
+ items: fleet2.filter((r) => r.robotSn).map((r) => ({
66739
+ robotSn: r.robotSn,
66740
+ name: r.name ?? "",
66741
+ online: r.online,
66742
+ statusName: r.statusName ?? "",
66743
+ added: added.has(String(r.robotSn))
66744
+ }))
66745
+ });
66746
+ } catch (error) {
66747
+ fail(next, error);
66748
+ }
66749
+ }
66750
+ return { getState, getMaps, getMapImages, getPlans, getPatrolRoutes, sendCommand: sendCommand2, trackRobot, getBrands, discoverRobots };
66655
66751
  }
66656
66752
 
66657
66753
  // src/models/robot-building-map.model.ts