@openinc/parse-server-opendash 4.38.1 → 4.39.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.
Files changed (49) hide show
  1. package/dist/features/openservice/alarms/index.d.ts +5 -2
  2. package/dist/features/openservice/alarms/index.js +6 -5
  3. package/dist/features/openservice/alarms/schedule/AlarmScheduleTypes.d.ts +4 -2
  4. package/dist/features/openservice/alarms/schedule/createAlarmSchedule.d.ts +6 -6
  5. package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +36 -139
  6. package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +2 -2
  7. package/dist/features/openservice/alarms/ticket/createAlarmTicket.d.ts +7 -4
  8. package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +42 -161
  9. package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.js +2 -2
  10. package/dist/features/openservice/automation/automationCall.d.ts +56 -0
  11. package/dist/features/openservice/automation/automationCall.js +61 -0
  12. package/dist/features/openservice/automation/createSchedule.d.ts +124 -0
  13. package/dist/features/openservice/automation/createSchedule.js +247 -0
  14. package/dist/features/openservice/automation/createTicket.d.ts +121 -0
  15. package/dist/features/openservice/automation/createTicket.js +212 -0
  16. package/dist/features/openservice/automation/index.d.ts +32 -0
  17. package/dist/features/openservice/automation/index.js +56 -0
  18. package/dist/features/openservice/{alarms/actionParams.d.ts → automation/params.d.ts} +15 -1
  19. package/dist/features/openservice/{alarms/actionParams.js → automation/params.js} +58 -1
  20. package/dist/features/openservice/automation/recordExecution.d.ts +61 -0
  21. package/dist/features/openservice/automation/recordExecution.js +111 -0
  22. package/dist/features/openservice/automation/resolveEquipment.d.ts +16 -0
  23. package/dist/features/openservice/automation/resolveEquipment.js +43 -0
  24. package/dist/features/openservice/automation/resolveStatus.d.ts +20 -0
  25. package/dist/features/openservice/automation/resolveStatus.js +57 -0
  26. package/dist/features/openservice/automation/resolveTenantUser.d.ts +16 -0
  27. package/dist/features/openservice/automation/resolveTenantUser.js +35 -0
  28. package/dist/features/openservice/automation/ticketDefaults.d.ts +34 -0
  29. package/dist/features/openservice/{alarms/ticket/alarmTicketDefaults.js → automation/ticketDefaults.js} +8 -8
  30. package/dist/features/openservice/automation/updateTicket.d.ts +65 -0
  31. package/dist/features/openservice/automation/updateTicket.js +141 -0
  32. package/dist/features/openservice/index.d.ts +2 -0
  33. package/dist/features/openservice/index.js +2 -0
  34. package/dist/functions/openinc-openservice-create-schedule.d.ts +20 -0
  35. package/dist/functions/openinc-openservice-create-schedule.js +41 -0
  36. package/dist/functions/openinc-openservice-create-ticket.d.ts +24 -0
  37. package/dist/functions/openinc-openservice-create-ticket.js +48 -0
  38. package/dist/functions/openinc-openservice-record-execution.d.ts +17 -0
  39. package/dist/functions/openinc-openservice-record-execution.js +38 -0
  40. package/dist/functions/openinc-openservice-update-ticket.d.ts +16 -0
  41. package/dist/functions/openinc-openservice-update-ticket.js +37 -0
  42. package/dist/hooks/Service_Schedule.js +5 -0
  43. package/dist/hooks/Service_Schedule_Execution.js +35 -0
  44. package/package.json +1 -1
  45. package/dist/features/openservice/alarms/resolveAlarmUser.d.ts +0 -16
  46. package/dist/features/openservice/alarms/resolveAlarmUser.js +0 -35
  47. package/dist/features/openservice/alarms/resolveEquipment.d.ts +0 -17
  48. package/dist/features/openservice/alarms/resolveEquipment.js +0 -45
  49. package/dist/features/openservice/alarms/ticket/alarmTicketDefaults.d.ts +0 -34
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.init = init;
7
+ const node_1 = __importDefault(require("parse/node"));
8
+ const index_js_1 = require("../features/openservice/automation/index.js");
9
+ /**
10
+ * Change an open.SERVICE ticket from outside the frontend: move its status,
11
+ * reassign it, record the failure window, comment on it.
12
+ *
13
+ * **Authentication** — see `readAutomationCall`: master key with `tenantId`
14
+ * (and optionally `actingUserId`, the comment's author), or the session of a
15
+ * (technical) user, whose write the ticket's ACL then decides — exactly as
16
+ * on the detail page.
17
+ *
18
+ * **Parameters** — `TicketUpdateParams`: the ticket by `ticketId`, or by
19
+ * `origin` (the newest open ticket of it); then only the fields to change, a
20
+ * status by id or by category, and/or a `comment`.
21
+ *
22
+ * Returns `{ ticketId, changed, commentId?, statusId? }`.
23
+ */
24
+ async function init(name) {
25
+ node_1.default.Cloud.define(name, async (request) => {
26
+ const { tenant, auth, actor, params } = await (0, index_js_1.readAutomationCall)(name, request);
27
+ const result = await (0, index_js_1.updateTicket)(tenant, params, {
28
+ auth,
29
+ actor,
30
+ logPrefix: `[${name}]`,
31
+ });
32
+ console.log(`[${name}] ticket ${result.ticketId}: ` +
33
+ (result.changed.length ? result.changed.join(", ") : "no fields") +
34
+ (result.commentId ? " + comment" : ""));
35
+ return result;
36
+ }, {});
37
+ }
@@ -10,6 +10,7 @@ const Permissions_js_1 = require("../features/permissions/types/Permissions.js")
10
10
  const index_js_2 = require("../features/permissions/index.js");
11
11
  const assignmentAcl_js_1 = require("../features/openservice/serviceSchedules/assignmentAcl.js");
12
12
  const demoSeed_js_1 = require("../features/openservice/demoSeed/demoSeed.js");
13
+ const createSchedule_js_1 = require("../features/openservice/automation/createSchedule.js");
13
14
  const index_js_3 = require("../features/openservice/serviceSchedules/calendarSync/index.js");
14
15
  const index_js_4 = require("../types/index.js");
15
16
  async function init() {
@@ -84,6 +85,10 @@ async function init() {
84
85
  // Demo data belongs to a demo tenant, not in anybody's calendar.
85
86
  if (context?.[demoSeed_js_1.DEMO_SEED_CONTEXT_FLAG])
86
87
  return;
88
+ // A plan created from outside that asked to stay out of every calendar
89
+ // (`calendarSync: false` of the automation endpoint — demo data above all).
90
+ if (context?.[createSchedule_js_1.NO_CALENDAR_SYNC_CONTEXT_FLAG])
91
+ return;
87
92
  if (!original || calendarRelevantChange(object, original)) {
88
93
  // Deliberately not awaited: the calendar is a downstream system, and a
89
94
  // Graph round trip (token + write) would otherwise be part of every save
@@ -74,6 +74,22 @@ async function init() {
74
74
  if (object.isNew()) {
75
75
  await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.execution_perform, "perform a maintenance execution");
76
76
  }
77
+ // The capability says *that* somebody may perform maintenance, not *which*
78
+ // plans. That is decided by the plan's ACL — creator and assignments — so
79
+ // the plan an execution points at has to be one the acting user can read.
80
+ //
81
+ // Without this, anyone holding `can-perform-execution` could record a run
82
+ // of a plan they were never assigned to, given its objectId (which every
83
+ // tenant-readable execution of that plan carries). It would count towards
84
+ // the plan's due dates, and `freezeSteps` above — which reads with the
85
+ // master key — would copy the private plan's steps into a record the whole
86
+ // tenant can read.
87
+ //
88
+ // Checked whenever `schedule` changes, not only on create: re-pointing an
89
+ // open execution at another plan is the same question.
90
+ if (object.dirty("schedule")) {
91
+ await requireReadableSchedule(object, request.sessionToken);
92
+ }
77
93
  // Who performed it is established by the server from the session, not
78
94
  // accepted from the client. A protocol that names somebody else is worth
79
95
  // less than no protocol at all.
@@ -126,6 +142,25 @@ async function init() {
126
142
  // already owns notification timing and recipients.
127
143
  });
128
144
  }
145
+ /**
146
+ * Refuse an execution whose plan the acting user cannot read.
147
+ *
148
+ * Queried with the user's session token, so Parse applies the plan's ACL. A
149
+ * plan the user may not read and one that does not exist look the same here,
150
+ * and both are refused the same way — telling them apart would confirm that a
151
+ * guessed id belongs to somebody else's plan.
152
+ */
153
+ async function requireReadableSchedule(execution, sessionToken) {
154
+ const schedule = execution.get("schedule");
155
+ if (!schedule?.id)
156
+ return;
157
+ const readable = await new node_1.default.Query(index_js_3.Service_Schedule)
158
+ .equalTo("objectId", schedule.id)
159
+ .first({ sessionToken: sessionToken ?? undefined });
160
+ if (!readable) {
161
+ throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, "Maintenance plan not found, or not assigned to you.");
162
+ }
163
+ }
129
164
  /**
130
165
  * Copy the plan's steps onto the execution.
131
166
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "4.38.1",
3
+ "version": "4.39.0",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@12.16.1",
6
6
  "keywords": [
@@ -1,16 +0,0 @@
1
- import { type _User, Tenant } from "../../../types/index.js";
2
- /**
3
- * The person who configured a fired alarm (`event.userId`, `OD3_Alarm.user`),
4
- * if they are a user of the alarm's tenant.
5
- *
6
- * What the actions make of them grants access: a ticket's `createdBy` and a
7
- * plan's `user` both get read/write in the ACL. The tenant is established by
8
- * the caller's secret, the user id is just a value in the payload — so a user
9
- * of another tenant is dropped rather than handed write access to this
10
- * tenant's record. Neither action needs an owner, so dropping one is a
11
- * warning, not an error.
12
- *
13
- * An executor that does not fill the placeholder posts `"{{alarm.user}}"`
14
- * literally; that matches no user and ends up the same way.
15
- */
16
- export declare function resolveAlarmUser(tenant: Tenant, userId: unknown, logPrefix: string): Promise<_User | undefined>;
@@ -1,35 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveAlarmUser = resolveAlarmUser;
7
- const node_1 = __importDefault(require("parse/node"));
8
- const actionParams_js_1 = require("./actionParams.js");
9
- /**
10
- * The person who configured a fired alarm (`event.userId`, `OD3_Alarm.user`),
11
- * if they are a user of the alarm's tenant.
12
- *
13
- * What the actions make of them grants access: a ticket's `createdBy` and a
14
- * plan's `user` both get read/write in the ACL. The tenant is established by
15
- * the caller's secret, the user id is just a value in the payload — so a user
16
- * of another tenant is dropped rather than handed write access to this
17
- * tenant's record. Neither action needs an owner, so dropping one is a
18
- * warning, not an error.
19
- *
20
- * An executor that does not fill the placeholder posts `"{{alarm.user}}"`
21
- * literally; that matches no user and ends up the same way.
22
- */
23
- async function resolveAlarmUser(tenant, userId, logPrefix) {
24
- const id = (0, actionParams_js_1.paramId)(userId);
25
- if (!id)
26
- return undefined;
27
- const user = await new node_1.default.Query(node_1.default.User)
28
- .equalTo("objectId", id)
29
- .equalTo("tenant", tenant)
30
- .first({ useMasterKey: true });
31
- if (!user) {
32
- console.warn(`${logPrefix} Alarm owner ${id} is not a user of this tenant — creating without one`);
33
- }
34
- return user ?? undefined;
35
- }
@@ -1,17 +0,0 @@
1
- import { Service_Equipment, Tenant } from "../../../types/index.js";
2
- import type { AlarmEvent } from "./AlarmEvent.js";
3
- /**
4
- * The machine a fired alarm concerns.
5
- *
6
- * 1. what was configured on the alarm — the only reliable source, because
7
- * **nothing in the data model links a sensor to a machine**;
8
- * 2. otherwise a machine whose `sourceTags` name the sensor or its source.
9
- * That is a convention, not a relation, so it is a fallback: `sourceTags`
10
- * was meant for source scoping, and a site-level tag can match several
11
- * machines — the first one wins, which is a guess.
12
- *
13
- * No machine is not an error for a ticket (`equipment` is optional there). A
14
- * caller that *needs* one — a maintenance plan is about a machine — checks the
15
- * `undefined` itself.
16
- */
17
- export declare function resolveEquipment(tenant: Tenant, event: AlarmEvent, equipmentId: string | undefined, logPrefix: string): Promise<Service_Equipment | undefined>;
@@ -1,45 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.resolveEquipment = resolveEquipment;
7
- const node_1 = __importDefault(require("parse/node"));
8
- const index_js_1 = require("../../../types/index.js");
9
- /**
10
- * The machine a fired alarm concerns.
11
- *
12
- * 1. what was configured on the alarm — the only reliable source, because
13
- * **nothing in the data model links a sensor to a machine**;
14
- * 2. otherwise a machine whose `sourceTags` name the sensor or its source.
15
- * That is a convention, not a relation, so it is a fallback: `sourceTags`
16
- * was meant for source scoping, and a site-level tag can match several
17
- * machines — the first one wins, which is a guess.
18
- *
19
- * No machine is not an error for a ticket (`equipment` is optional there). A
20
- * caller that *needs* one — a maintenance plan is about a machine — checks the
21
- * `undefined` itself.
22
- */
23
- async function resolveEquipment(tenant, event, equipmentId, logPrefix) {
24
- if (equipmentId) {
25
- // Master key reads every tenant: the alarm's tenant (from its secret) must
26
- // own the machine, or a plan would point at another tenant's machine.
27
- const explicit = await new node_1.default.Query(index_js_1.Service_Equipment)
28
- .equalTo("objectId", equipmentId)
29
- .equalTo("tenant", tenant)
30
- .first({ useMasterKey: true });
31
- if (explicit)
32
- return explicit;
33
- console.warn(`${logPrefix} Configured machine ${equipmentId} does not exist for this tenant`);
34
- }
35
- const candidates = [event.item_id, event.item_source].filter((value) => !!value);
36
- if (candidates.length === 0)
37
- return undefined;
38
- const query = new node_1.default.Query(index_js_1.Service_Equipment)
39
- .equalTo("tenant", tenant)
40
- .notEqualTo("deleted", true)
41
- // `sourceTags` is an Array column: Mongo reads "contained in" as "the array
42
- // holds one of these". The generated type only knows `any[]`, hence the cast.
43
- .containedIn("sourceTags", candidates);
44
- return (await query.first({ useMasterKey: true })) ?? undefined;
45
- }
@@ -1,34 +0,0 @@
1
- /**
2
- * Values the ticket an alarm creates starts out with — the alarm's template
3
- * (the ticket form in template mode) or what its form config pre-fills
4
- * (`defaultValue` of its fields). Both in the form's edit shape: field values
5
- * keyed by ticket field, references as ids.
6
- *
7
- * Read here into exactly the fields a default may set. Dates are left out (a
8
- * fixed date makes no sense for an alarm that fires later; the config's
9
- * relative value rules still apply on save), and so are the fields the server
10
- * owns (tenant, number, origin, closedAt …). Title and description come back
11
- * apart: the alarm's own title wins over them, and the alarm's details are
12
- * appended to the description (`alarmTicketFields`). Whether a referenced row
13
- * belongs to the tenant is the `Service_Ticket` hook's call, as on every write
14
- * path.
15
- */
16
- export interface AlarmTicketDefaults {
17
- title?: string;
18
- description?: string;
19
- status?: string;
20
- equipment?: string;
21
- project?: string;
22
- /** The remaining fields, ready for `ticket.set`. */
23
- values: Record<string, unknown>;
24
- }
25
- /**
26
- * The defaults of a form config's `fields` (its JSON column). Hidden fields
27
- * count: the create form keeps them as hidden inputs and saves their default.
28
- *
29
- * shortcut: `visibleWhen` is not evaluated — a default of a field hidden by
30
- * condition is applied anyway; read it with the ticket's values if a config
31
- * ever relies on that.
32
- */
33
- export declare function formConfigDefaults(fields: string | undefined): AlarmTicketDefaults;
34
- export declare function readTicketDefaults(raw: unknown): AlarmTicketDefaults;