@7365admin1/core 3.48.1-staging.196 → 3.48.1-staging.197

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": patch
3
+ ---
4
+
5
+ Scope the robot routes to their estate. `POST /api/robots` and `GET /api/robots/organization/:organization/site/:site` carried `requireAuth` and nothing more and the controller held no authorization identifier, so any signed-in account on the platform could page any estate's robot list — which projects `appKey` and `appToken`, the robot's credentials — and aim a robot registration at any estate. Reach is now decided from the session, on the site named in the request. A registration naming no estate is refused rather than falling through unscoped, and `createdBy` is taken from the session rather than from the request body.
package/dist/index.js CHANGED
@@ -51619,15 +51619,25 @@ var import_joi70 = __toESM(require("joi"));
51619
51619
  var import_node_server_utils143 = require("@7365admin1/node-server-utils");
51620
51620
  function useRobotController() {
51621
51621
  const { createRobot: _createRobot, getRobots: _getRobots } = useRobotService();
51622
+ async function requireRobotReach(req, site) {
51623
+ await requireSiteReach(req, site);
51624
+ }
51622
51625
  async function createRobot(req, res, next) {
51623
- const payload = { ...req.body };
51626
+ const payload = { ...req.body, createdBy: callerId(req) };
51624
51627
  const { error } = robotSchema.validate(payload);
51625
51628
  if (error) {
51626
51629
  import_node_server_utils143.logger.log({ level: "error", message: error.message });
51627
51630
  next(new import_node_server_utils143.BadRequestError(error.message));
51628
51631
  return;
51629
51632
  }
51633
+ if (!payload.metadata?.siteId) {
51634
+ const message = "metadata.siteId is required.";
51635
+ import_node_server_utils143.logger.log({ level: "error", message });
51636
+ next(new import_node_server_utils143.BadRequestError(message));
51637
+ return;
51638
+ }
51630
51639
  try {
51640
+ await requireRobotReach(req, payload.metadata.siteId);
51631
51641
  await _createRobot(payload);
51632
51642
  res.status(201).json({ message: "Successfully created robot." });
51633
51643
  return;
@@ -51666,6 +51676,7 @@ function useRobotController() {
51666
51676
  const from = req.query.from ?? "";
51667
51677
  const to = req.query.to ?? "";
51668
51678
  try {
51679
+ await requireRobotReach(req, site);
51669
51680
  const data = await _getRobots({
51670
51681
  search,
51671
51682
  page,