@openinc/parse-server-opendash 4.31.5 → 4.32.1

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 (53) hide show
  1. package/dist/featuremap.json +4 -0
  2. package/dist/features/bde/shifts/shiftValidation.d.ts +13 -0
  3. package/dist/features/bde/shifts/shiftValidation.js +96 -0
  4. package/dist/features/openservice/alarms/index.d.ts +0 -2
  5. package/dist/features/openservice/alarms/index.js +1 -3
  6. package/dist/features/openservice/init.js +2 -0
  7. package/dist/features/openservice/kpis/initKpiFeature.d.ts +13 -0
  8. package/dist/features/openservice/kpis/initKpiFeature.js +41 -0
  9. package/dist/features/openservice/kpis/kpiJob.d.ts +46 -0
  10. package/dist/features/openservice/kpis/kpiJob.js +273 -0
  11. package/dist/features/openservice/kpis/kpiMaths.d.ts +51 -0
  12. package/dist/features/openservice/kpis/kpiMaths.js +62 -0
  13. package/dist/features/openservice/tickets/ticketFailure.d.ts +37 -0
  14. package/dist/features/openservice/tickets/ticketFailure.js +99 -0
  15. package/dist/features/openservice/tickets/ticketRules.d.ts +8 -0
  16. package/dist/features/openservice/tickets/ticketRules.js +10 -0
  17. package/dist/features/permissions/types/Permissions.d.ts +3 -1
  18. package/dist/features/permissions/types/Permissions.js +5 -0
  19. package/dist/functions/openinc-openservice-kpi-recompute.d.ts +16 -0
  20. package/dist/functions/openinc-openservice-kpi-recompute.js +44 -0
  21. package/dist/hooks/BDE_ShiftException.d.ts +1 -0
  22. package/dist/hooks/BDE_ShiftException.js +22 -0
  23. package/dist/hooks/BDE_ShiftModel.d.ts +1 -0
  24. package/dist/hooks/BDE_ShiftModel.js +24 -0
  25. package/dist/hooks/BDE_WorkTime.js +4 -1
  26. package/dist/hooks/Service_EquipmentAnnotation.d.ts +1 -0
  27. package/dist/hooks/Service_EquipmentAnnotation.js +15 -0
  28. package/dist/hooks/Service_KpiDefinition.d.ts +1 -0
  29. package/dist/hooks/Service_KpiDefinition.js +65 -0
  30. package/dist/hooks/Service_Ticket.js +8 -0
  31. package/dist/types/BDE_ShiftException.d.ts +34 -0
  32. package/dist/types/BDE_ShiftException.js +57 -0
  33. package/dist/types/BDE_ShiftModel.d.ts +34 -0
  34. package/dist/types/BDE_ShiftModel.js +57 -0
  35. package/dist/types/Service_EquipmentAnnotation.d.ts +35 -0
  36. package/dist/types/Service_EquipmentAnnotation.js +57 -0
  37. package/dist/types/Service_KpiDefinition.d.ts +34 -0
  38. package/dist/types/Service_KpiDefinition.js +57 -0
  39. package/dist/types/Service_Ticket.d.ts +9 -0
  40. package/dist/types/Service_Ticket.js +18 -0
  41. package/dist/types/index.d.ts +8 -0
  42. package/dist/types/index.js +11 -3
  43. package/package.json +15 -14
  44. package/pnpm-workspace.yaml +3 -0
  45. package/schema/BDE_ShiftException.json +57 -0
  46. package/schema/BDE_ShiftModel.json +58 -0
  47. package/schema/Service_EquipmentAnnotation.json +57 -0
  48. package/schema/Service_KpiDefinition.json +56 -0
  49. package/schema/Service_Ticket.json +9 -0
  50. package/dist/features/openservice/alarms/schedule/listAlarmTriggers.d.ts +0 -41
  51. package/dist/features/openservice/alarms/schedule/listAlarmTriggers.js +0 -159
  52. package/dist/functions/openinc-openservice-alarm-triggers.d.ts +0 -13
  53. package/dist/functions/openinc-openservice-alarm-triggers.js +0 -29
@@ -1,159 +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.listAlarmTriggers = listAlarmTriggers;
7
- const node_1 = __importDefault(require("parse/node"));
8
- const index_js_1 = require("../../../../types/index.js");
9
- const actionParams_js_1 = require("../actionParams.js");
10
- const AlarmScheduleTypes_js_1 = require("./AlarmScheduleTypes.js");
11
- /**
12
- * Every alarm in this tenant whose action creates a maintenance plan.
13
- *
14
- * **Why the server has to answer this.** `Alarm.beforeSave` applies
15
- * `denyTenantUserRead`, so alarms are private to the user who configured them.
16
- * A maintenance manager asking "what triggers maintenance in this plant" would
17
- * otherwise see only their own — which is the one answer that is never useful.
18
- * The query therefore runs with the master key and is scoped to the caller's
19
- * tenant by the server, never by a parameter.
20
- *
21
- * Read-only and deliberately narrow: it returns what the overview renders and
22
- * nothing that would let a caller walk into another tenant's alarms.
23
- */
24
- async function listAlarmTriggers(user) {
25
- const tenant = user.get("tenant");
26
- if (!tenant)
27
- return [];
28
- // Which `OD3_AlarmAction` row is ours. Needed as an id because that is what
29
- // an alarm stores to point at it.
30
- const actionRow = await new node_1.default.Query(index_js_1.AlarmAction)
31
- .equalTo("topic", AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID)
32
- .first({ useMasterKey: true });
33
- // Two spellings, because an alarm's `action` object carries both and neither
34
- // is guaranteed:
35
- //
36
- // - `topic` is the stable name (`"openservice-create-schedule"`). It gets
37
- // into the alarm by being spread in from the action row
38
- // (`mapAlarmActionsReverse`), so it is missing if that row had not loaded
39
- // yet when the alarm was saved.
40
- // - `actionId` is the **objectId** of the action row, written by
41
- // `AlarmCreate`. Always present, but it says nothing about which action it
42
- // is without resolving the row first.
43
- //
44
- // Matching on `actionId` against the topic string — which is what this did —
45
- // compares an objectId with `"openservice-create-schedule"` and therefore
46
- // never matches anything: the overview was always empty.
47
- const byTopic = new node_1.default.Query(index_js_1.Alarm)
48
- .equalTo("tenant", tenant)
49
- // `action` is an Object column; Mongo reads the dotted path into it. The
50
- // generated type only knows `any`, hence the cast.
51
- .equalTo("action.topic", AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID);
52
- const queries = [byTopic];
53
- if (actionRow?.id) {
54
- queries.push(new node_1.default.Query(index_js_1.Alarm)
55
- .equalTo("tenant", tenant)
56
- .equalTo("action.actionId", actionRow.id));
57
- }
58
- // The tenant constraint sits inside each branch rather than on the combined
59
- // query, so no `or` semantics can widen it past the caller's own tenant.
60
- const alarms = await (queries.length > 1 ? node_1.default.Query.or(...queries) : byTopic)
61
- .include("user")
62
- .limit(500)
63
- .find({ useMasterKey: true });
64
- if (alarms.length === 0)
65
- return [];
66
- const plansByOrigin = await schedulesByOrigin(tenant, alarms);
67
- const templateTitles = await titlesFor(alarms
68
- .map((alarm) => templateIdOf(alarm, actionRow?.id))
69
- .filter((id) => !!id));
70
- return alarms.map((alarm) => {
71
- const action = (alarm.get("action") ?? {});
72
- const templateId = templateIdOf(alarm, actionRow?.id);
73
- const source = alarm.get("item_source");
74
- const id = alarm.get("item_id");
75
- const dimension = alarm.get("item_dimension");
76
- return {
77
- alarmId: alarm.id,
78
- name: alarm.get("name"),
79
- sensor: sensorLabel(source, id, dimension),
80
- item_source: source,
81
- item_id: id,
82
- item_dimension: dimension,
83
- owner: alarm.get("user")?.get("username"),
84
- templateId,
85
- templateTitle: templateId ? templateTitles.get(templateId) : undefined,
86
- equipmentId: (0, actionParams_js_1.paramId)(action["equipmentId"]),
87
- dueInDays: (0, actionParams_js_1.paramNumber)(action["dueInDays"]),
88
- schedules: plansByOrigin.get(`alarm:${alarm.id}`) ?? [],
89
- };
90
- });
91
- }
92
- /**
93
- * Plans grouped by their `origin` marker.
94
- *
95
- * One query for all alarms rather than one per alarm: a plant with fifty
96
- * triggers would otherwise open fifty round trips to render one table.
97
- */
98
- async function schedulesByOrigin(tenant, alarms) {
99
- const origins = alarms.map((alarm) => `alarm:${alarm.id}`);
100
- const schedules = await new node_1.default.Query(index_js_1.Service_Schedule)
101
- .equalTo("tenant", tenant)
102
- .containedIn("origin", origins)
103
- .doesNotExist("deletedAt")
104
- .descending("createdAt")
105
- .limit(1000)
106
- .find({ useMasterKey: true });
107
- const byOrigin = new Map();
108
- for (const schedule of schedules) {
109
- const origin = schedule.get("origin");
110
- if (!origin)
111
- continue;
112
- const cadence = schedule.get("cadence");
113
- const asset = schedule.get("asset");
114
- const rows = byOrigin.get(origin) ?? [];
115
- rows.push({
116
- id: schedule.id,
117
- title: schedule.get("title"),
118
- due: cadence?.dtstart,
119
- firedAt: asset?.alarm?.firedAt,
120
- });
121
- byOrigin.set(origin, rows);
122
- }
123
- return byOrigin;
124
- }
125
- /** Titles of the referenced templates, so the table can name them. */
126
- async function titlesFor(templateIds) {
127
- const unique = [...new Set(templateIds)];
128
- if (unique.length === 0)
129
- return new Map();
130
- const templates = await new node_1.default.Query("OD3_Service_Schedule_Template")
131
- .containedIn("objectId", unique)
132
- .limit(unique.length)
133
- .find({ useMasterKey: true });
134
- return new Map(templates.map((template) => [
135
- template.id,
136
- template.get("title"),
137
- ]));
138
- }
139
- /**
140
- * The template id out of the alarm's action settings.
141
- *
142
- * `AlarmCreate` prefixes its *form state* with the action row's objectId
143
- * (`<objectId>__<key>`) but writes the value back under the plain key, so
144
- * `templateId` is the spelling that reaches the database. The prefixed variant
145
- * is still accepted as a fallback — with the objectId, which is what the prefix
146
- * is actually built from. The previous fallback used the topic string and could
147
- * therefore never match.
148
- */
149
- function templateIdOf(alarm, actionRowId) {
150
- const action = (alarm.get("action") ?? {});
151
- return ((0, actionParams_js_1.paramId)(action["templateId"]) ??
152
- (actionRowId ? (0, actionParams_js_1.paramId)(action[`${actionRowId}__templateId`]) : undefined));
153
- }
154
- function sensorLabel(source, id, dimension) {
155
- const sensor = [source, id].filter(Boolean).join("/");
156
- if (!sensor)
157
- return undefined;
158
- return dimension != null ? `${sensor} [${dimension}]` : sensor;
159
- }
@@ -1,13 +0,0 @@
1
- /**
2
- * List the alarms in the caller's tenant that create maintenance plans.
3
- *
4
- * Unlike the two alarm endpoints next to it, this one is for a **person**:
5
- * `requireUser`, and the tenant comes from their account rather than from a
6
- * secret — a browser session must never be able to name a tenant it does not
7
- * belong to.
8
- *
9
- * It needs the master key internally because `Alarm.beforeSave` makes alarms
10
- * private per user (`denyTenantUserRead`); see `listAlarmTriggers` for why the
11
- * plant-wide view is the only useful one.
12
- */
13
- export declare function init(name: string): Promise<void>;
@@ -1,29 +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.init = init;
7
- const node_1 = __importDefault(require("parse/node"));
8
- const index_js_1 = require("../features/openservice/alarms/index.js");
9
- /**
10
- * List the alarms in the caller's tenant that create maintenance plans.
11
- *
12
- * Unlike the two alarm endpoints next to it, this one is for a **person**:
13
- * `requireUser`, and the tenant comes from their account rather than from a
14
- * secret — a browser session must never be able to name a tenant it does not
15
- * belong to.
16
- *
17
- * It needs the master key internally because `Alarm.beforeSave` makes alarms
18
- * private per user (`denyTenantUserRead`); see `listAlarmTriggers` for why the
19
- * plant-wide view is the only useful one.
20
- */
21
- async function init(name) {
22
- node_1.default.Cloud.define(name, async (request) => {
23
- const user = request.user;
24
- if (!user) {
25
- throw new node_1.default.Error(node_1.default.Error.INVALID_SESSION_TOKEN, `${name} requires a logged-in user`);
26
- }
27
- return (0, index_js_1.listAlarmTriggers)(user);
28
- }, { requireUser: true });
29
- }