@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/dist/index.mjs CHANGED
@@ -5335,7 +5335,8 @@ var SUBSCRIPTION_END_GRACE_DAYS = Number(
5335
5335
  process.env.SUBSCRIPTION_END_GRACE_DAYS ?? 7
5336
5336
  );
5337
5337
  var SUBSCRIPTION_AUTO_SUSPEND_ENABLED = process.env.SUBSCRIPTION_AUTO_SUSPEND_ENABLED === "true";
5338
- var ROBOT_CLOUD_BASE_URL = process.env.ROBOT_CLOUD_BASE_URL ?? "";
5338
+ var OUNITECH_DEFAULT_API_BASE = "https://app.frankfurt.robotcloud.top";
5339
+ var ROBOT_CLOUD_BASE_URL = process.env.OUNITECH_API_BASE || process.env.ROBOT_CLOUD_BASE_URL || OUNITECH_DEFAULT_API_BASE;
5339
5340
  var ROBOT_CLOUD_TIMEOUT_MS = Number(
5340
5341
  process.env.ROBOT_CLOUD_TIMEOUT_MS ?? 15e3
5341
5342
  );
@@ -61495,6 +61496,40 @@ function useRobotRepo() {
61495
61496
  site: { _id: site, name: String(s?.name ?? "") }
61496
61497
  };
61497
61498
  }
61499
+ async function clientSiteIds(site) {
61500
+ if (!ObjectId108.isValid(site))
61501
+ return [];
61502
+ const s = await db2.collection("sites").findOne({ _id: new ObjectId108(site) }, { projection: { orgId: 1, org: 1 } });
61503
+ const owner = String(s?.orgId ?? s?.org ?? "");
61504
+ if (!ObjectId108.isValid(owner))
61505
+ return [new ObjectId108(site), site];
61506
+ const ownerIds = [new ObjectId108(owner), owner];
61507
+ const rows = await db2.collection("sites").find({ $or: [{ orgId: { $in: ownerIds } }, { org: { $in: ownerIds } }] }, { projection: { _id: 1 } }).toArray();
61508
+ return rows.flatMap((r) => [r._id, String(r._id)]);
61509
+ }
61510
+ async function getClientCloudCredentials(site, brand) {
61511
+ const sites = await clientSiteIds(site);
61512
+ if (!sites.length || !brand)
61513
+ return null;
61514
+ const row = await collection.findOne(
61515
+ {
61516
+ "metadata.siteId": { $in: sites },
61517
+ brand,
61518
+ appKey: { $type: "string", $ne: "" },
61519
+ appToken: { $type: "string", $ne: "" },
61520
+ ...NOT_DELETED
61521
+ },
61522
+ { sort: { updatedAt: -1, createdAt: -1 }, projection: { appKey: 1, appToken: 1 } }
61523
+ );
61524
+ return row ? { appKey: String(row.appKey), appToken: String(row.appToken) } : null;
61525
+ }
61526
+ async function getClientSerials(site, serials) {
61527
+ const sites = await clientSiteIds(site);
61528
+ if (!sites.length || !serials.length)
61529
+ return /* @__PURE__ */ new Set();
61530
+ const rows = await collection.find({ "metadata.siteId": { $in: sites }, robotSn: { $in: serials }, ...NOT_DELETED }, { projection: { robotSn: 1 } }).toArray();
61531
+ return new Set(rows.map((r) => String(r.robotSn)));
61532
+ }
61498
61533
  async function maxDemoSerial(letter) {
61499
61534
  const rows = await collection.find({ robotSn: { $regex: `^DEMO-${letter}-[0-9]+$` } }, { projection: { robotSn: 1 } }).toArray();
61500
61535
  return rows.reduce((max, r) => Math.max(max, Number(String(r.robotSn).split("-")[2]) || 0), 0);
@@ -61541,6 +61576,8 @@ function useRobotRepo() {
61541
61576
  getNetworkRobots,
61542
61577
  getSiteSummary,
61543
61578
  getSiteNames,
61579
+ getClientCloudCredentials,
61580
+ getClientSerials,
61544
61581
  maxDemoSerial,
61545
61582
  getDemoRobotsAtSite,
61546
61583
  getNetworkSummary,
@@ -62034,14 +62071,11 @@ function planDayFromJsDay(jsDay) {
62034
62071
  return jsDay === 0 ? 7 : jsDay;
62035
62072
  }
62036
62073
  var ROBOT_CLOUD_DOC_CONFIRMATIONS = [
62037
- // The document's examples for get-map-list and get-file-url show the SAME
62038
- // `sign` with the same appid and timestamp but DIFFERENT url paths, which the
62039
- // spec's own formula makes impossible. One of the two examples is a
62040
- // copy-paste. Confirm the exact signed `url` string for every endpoint.
62041
- "Exact signed `url` string per endpoint (the doc's own examples contradict the formula).",
62042
- // `timestamp` has no timezone. This module emits UTC; if the cloud reads it as
62043
- // Asia/Singapore every request is 8 hours out and rejected.
62044
- "Timestamp timezone (this module emits UTC) and the accepted clock-skew window.",
62074
+ // ANSWERED 2026-09-26 (Ounitech Part 1): base URL, one appid/secret per
62075
+ // company, sign = the formula with url = each endpoint's own path (the doc's
62076
+ // examples were a copy-paste), timestamp in UTC+0. Removed from this list.
62077
+ // Still open: the accepted clock-skew window.
62078
+ "Accepted clock-skew window for `timestamp` (UTC+0 confirmed; the window is not stated).",
62045
62079
  // pixelToMetres assumes the image y-origin is top-left.
62046
62080
  "Pixel y-origin: top-left (assumed) or bottom-left.",
62047
62081
  // The doc labels modeFlag "1 vacuum / 2 washing / 3 dry dust mop" on the
@@ -63952,8 +63986,10 @@ function useRobotController() {
63952
63986
  await requireSiteReach(req, site);
63953
63987
  }
63954
63988
  async function createRobot(req, res, next) {
63955
- const payload = { ...req.body, createdBy: callerId(req) };
63956
- const { error } = robotSchema.validate(payload);
63989
+ const { useClientCredentials, ...body } = req.body ?? {};
63990
+ const payload = { ...body, createdBy: callerId(req) };
63991
+ const shape = useClientCredentials === true ? { ...payload, appKey: "saved", appToken: "saved" } : payload;
63992
+ const { error } = robotSchema.validate(shape);
63957
63993
  if (error) {
63958
63994
  logger107.log({ level: "error", message: error.message });
63959
63995
  next(new BadRequestError135(error.message));
@@ -63967,6 +64003,19 @@ function useRobotController() {
63967
64003
  }
63968
64004
  try {
63969
64005
  await requireRobotReach(req, payload.metadata.siteId);
64006
+ if (useClientCredentials === true) {
64007
+ if (!String(payload.robotSn ?? "").trim()) {
64008
+ throw new BadRequestError135("Pick the robot's serial - the saved credentials cover more than one robot.");
64009
+ }
64010
+ const saved = await useRobotRepo().getClientCloudCredentials(
64011
+ String(payload.metadata.siteId),
64012
+ String(payload.brand || "ounitech")
64013
+ );
64014
+ if (!saved) {
64015
+ throw new BadRequestError135("This client has no saved credentials for this brand yet - enter them once.");
64016
+ }
64017
+ Object.assign(payload, saved);
64018
+ }
63970
64019
  const id = await _createRobot(payload);
63971
64020
  await recordConsoleAction({
63972
64021
  action: "robot.added" /* ROBOT_ADDED */,
@@ -66090,7 +66139,54 @@ function useRobotFleetController(deps) {
66090
66139
  fail(next, error);
66091
66140
  }
66092
66141
  }
66093
- return { getState, getMaps, getMapImages, getPlans, getPatrolRoutes, sendCommand: sendCommand2, trackRobot, getBrands };
66142
+ async function discoverRobots(req, res, next) {
66143
+ try {
66144
+ const { error, value } = Joi76.object({
66145
+ robot: Joi76.string().hex().length(24),
66146
+ site: Joi76.string().hex().length(24).when("robot", { is: Joi76.exist(), then: Joi76.optional(), otherwise: Joi76.required() }),
66147
+ brand: Joi76.string().trim().max(60).allow("").default("ounitech"),
66148
+ appKey: Joi76.string().trim().max(500).allow(""),
66149
+ appToken: Joi76.string().trim().max(500).allow("")
66150
+ }).validate(req.body ?? {});
66151
+ if (error)
66152
+ throw new BadRequestError136(error.message);
66153
+ if (!!value.appKey !== !!value.appToken)
66154
+ throw new BadRequestError136("Enter both the AppID and the Secret.");
66155
+ const own = value.robot ? await entitleRobot(req, value.robot) : null;
66156
+ if (own)
66157
+ value.site = String(own.metadata?.siteId ?? "");
66158
+ else
66159
+ await requireSiteReach(req, value.site);
66160
+ const brand = own ? String(own.brand ?? "") : value.brand || "ounitech";
66161
+ if (!robotBrandFor(brand))
66162
+ throw new BadRequestError136(`Unknown robot brand "${brand}".`);
66163
+ const pair = own ? { appKey: own.appKey, appToken: own.appToken } : value.appKey ? { appKey: value.appKey, appToken: value.appToken } : await getRepo().getClientCloudCredentials(value.site, brand);
66164
+ if (!pair)
66165
+ throw new BadRequestError136("This client has no saved credentials for this brand yet - enter them once.");
66166
+ let fleet2;
66167
+ try {
66168
+ fleet2 = await adapterForRobot({ brand, ...pair, name: "discovery" }).listRobots();
66169
+ } catch (e) {
66170
+ if (e instanceof RobotCloudError)
66171
+ throw new BadRequestError136(e.message);
66172
+ throw e;
66173
+ }
66174
+ const serials = fleet2.map((r) => String(r.robotSn ?? "")).filter(Boolean);
66175
+ const added = await getRepo().getClientSerials(value.site, serials);
66176
+ res.json({
66177
+ items: fleet2.filter((r) => r.robotSn).map((r) => ({
66178
+ robotSn: r.robotSn,
66179
+ name: r.name ?? "",
66180
+ online: r.online,
66181
+ statusName: r.statusName ?? "",
66182
+ added: added.has(String(r.robotSn))
66183
+ }))
66184
+ });
66185
+ } catch (error) {
66186
+ fail(next, error);
66187
+ }
66188
+ }
66189
+ return { getState, getMaps, getMapImages, getPlans, getPatrolRoutes, sendCommand: sendCommand2, trackRobot, getBrands, discoverRobots };
66094
66190
  }
66095
66191
 
66096
66192
  // src/models/robot-building-map.model.ts