@openinc/parse-server-opendash 4.35.0 → 4.37.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/featuremap.json +1 -0
- package/dist/features/openservice/alarms/ensureAlarmActionRow.d.ts +32 -0
- package/dist/features/openservice/alarms/ensureAlarmActionRow.js +67 -0
- package/dist/features/openservice/alarms/ensureOpenwareWebhook.d.ts +22 -0
- package/dist/features/openservice/alarms/ensureOpenwareWebhook.js +81 -0
- package/dist/features/openservice/alarms/index.d.ts +9 -1
- package/dist/features/openservice/alarms/index.js +17 -2
- package/dist/features/openservice/alarms/openwareAlarm.d.ts +76 -0
- package/dist/features/openservice/alarms/openwareAlarm.js +96 -0
- package/dist/features/openservice/alarms/readAlarmCall.d.ts +26 -0
- package/dist/features/openservice/alarms/readAlarmCall.js +67 -0
- package/dist/features/openservice/alarms/resolveAlarmUser.d.ts +16 -0
- package/dist/features/openservice/alarms/resolveAlarmUser.js +35 -0
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +2 -8
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.d.ts +3 -36
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +12 -140
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +6 -0
- package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.d.ts +3 -19
- package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.js +12 -70
- package/dist/features/openservice/articles/articleEquipment.d.ts +19 -0
- package/dist/features/openservice/articles/articleEquipment.js +53 -0
- package/dist/features/openservice/articles/articleStock.d.ts +19 -0
- package/dist/features/openservice/articles/articleStock.js +31 -0
- package/dist/features/openservice/equipment/criticality.d.ts +29 -0
- package/dist/features/openservice/equipment/criticality.js +85 -0
- package/dist/features/openservice/init.js +11 -3
- package/dist/features/openservice/tickets/ticketPriority.d.ts +18 -11
- package/dist/features/openservice/tickets/ticketPriority.js +54 -20
- package/dist/features/openservice/tickets/ticketRules.js +1 -1
- package/dist/features/schema/indexes.js +9 -0
- package/dist/functions/openinc-openservice-alarm-create-schedule.d.ts +7 -9
- package/dist/functions/openinc-openservice-alarm-create-schedule.js +11 -31
- package/dist/functions/openinc-openservice-alarm-create-ticket.d.ts +7 -9
- package/dist/functions/openinc-openservice-alarm-create-ticket.js +11 -31
- package/dist/hooks/BDE_Article.js +5 -1
- package/dist/hooks/BDE_DisruptionReason.d.ts +1 -0
- package/dist/hooks/BDE_DisruptionReason.js +70 -0
- package/dist/hooks/Service_Equipment.js +3 -0
- package/dist/scripts/backfill-stock-alert.d.ts +1 -0
- package/dist/scripts/backfill-stock-alert.js +89 -0
- package/dist/scripts/migration/lib/articleMeta.d.ts +7 -3
- package/dist/scripts/migration/lib/articleMeta.js +8 -10
- package/dist/scripts/migration/passes/05-articles.d.ts +8 -4
- package/dist/scripts/migration/passes/05-articles.js +29 -12
- package/dist/types/BDE_Article.d.ts +6 -0
- package/dist/types/BDE_Article.js +12 -0
- package/dist/types/BDE_DisruptionReason.d.ts +43 -0
- package/dist/types/BDE_DisruptionReason.js +72 -0
- package/dist/types/Service_Equipment.d.ts +3 -0
- package/dist/types/Service_Equipment.js +6 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/index.js +5 -3
- package/package.json +2 -1
- package/schema/BDE_Article.json +9 -0
- package/schema/BDE_DisruptionReason.json +73 -0
- package/schema/Service_Equipment.json +3 -0
|
@@ -1,39 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
* `
|
|
5
|
-
* than calling anything itself. That row used to be created by hand — and a
|
|
6
|
-
* hand-made one is how an installation ends up with `payload: "{}"`, which
|
|
7
|
-
* reaches the endpoint carrying neither secret nor event, so nothing happens
|
|
8
|
-
* and nothing says why.
|
|
9
|
-
*
|
|
10
|
-
* Found again by `url`, not by name: the url is what makes two rows the same
|
|
11
|
-
* webhook, a name is free text somebody renames.
|
|
12
|
-
*
|
|
13
|
-
* ⚠️ **The url is relative.** That is what the existing hand-made rows use and
|
|
14
|
-
* what this server answers, but whether the executor resolves it against the
|
|
15
|
-
* Parse base or needs an absolute address is open.WARE's business. If a fired
|
|
16
|
-
* alarm never arrives, check this first.
|
|
17
|
-
*/
|
|
18
|
-
export declare function ensureAlarmScheduleWebhook(): Promise<void>;
|
|
19
|
-
/**
|
|
20
|
-
* Make "schedule a maintenance appointment" selectable in the alarm dialog.
|
|
21
|
-
*
|
|
22
|
-
* Alarm actions are **data**, not code: `OD3_AlarmAction` rows that the
|
|
23
|
-
* monitoring adapter loads into the frontend, where the chosen row's
|
|
24
|
-
* `formFields` are rendered as the action's settings form (see
|
|
25
|
-
* `plugins/monitoring/src/components/AlarmCreate.tsx`). There is no plugin-side
|
|
26
|
-
* `registerAlarmAction`, so the row is seeded here — find-or-create by `topic`,
|
|
27
|
-
* like the ticket action and the other open.SERVICE bootstraps.
|
|
28
|
-
*
|
|
29
|
-
* The row is **global** (no tenant): the action makes sense for every tenant,
|
|
30
|
-
* and the tenant of a fired alarm is established by its secret, not by this row.
|
|
31
|
-
*
|
|
32
|
-
* **How it is carried out.** `type: "webhook"` means the executor runs an
|
|
33
|
-
* `OD3_AlarmWebhook` row, which POSTs to a URL. That row is created by hand for
|
|
34
|
-
* now (an admin UI can come later) and must point at
|
|
35
|
-
* `/parse/functions/openinc-openservice-alarm-create-schedule` with the payload
|
|
36
|
-
* below. The `target` here names the same path so the two are readable side by
|
|
37
|
-
* side, and so a webhook-less executor that reads `target` directly still works.
|
|
2
|
+
* Make "schedule a maintenance appointment" selectable in the alarm dialog and
|
|
3
|
+
* executable by open.WARE: the `OD3_AlarmAction` row and the
|
|
4
|
+
* `OD3_AlarmWebhook` row it targets (see `ensureAlarmActionRow`).
|
|
38
5
|
*/
|
|
39
6
|
export declare function ensureAlarmScheduleAction(): Promise<void>;
|
|
@@ -1,150 +1,22 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.ensureAlarmScheduleWebhook = ensureAlarmScheduleWebhook;
|
|
7
3
|
exports.ensureAlarmScheduleAction = ensureAlarmScheduleAction;
|
|
8
|
-
const
|
|
9
|
-
const index_js_1 = require("../../../../types/index.js");
|
|
4
|
+
const ensureAlarmActionRow_js_1 = require("../ensureAlarmActionRow.js");
|
|
10
5
|
const AlarmScheduleTypes_js_1 = require("./AlarmScheduleTypes.js");
|
|
11
|
-
/** Name of the webhook row. Free text — the url is what identifies it. */
|
|
12
|
-
const WEBHOOK_NAME = "open.SERVICE: Wartungstermin anlegen";
|
|
13
6
|
/**
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
* contract written down twice, and a difference between them is a bug waiting
|
|
18
|
-
* for whichever one the executor happens to read.
|
|
19
|
-
*/
|
|
20
|
-
const WEBHOOK_PAYLOAD = JSON.stringify({
|
|
21
|
-
secret: "{{secret}}",
|
|
22
|
-
event: {
|
|
23
|
-
alarmId: "{{alarm.id}}",
|
|
24
|
-
name: "{{alarm.name}}",
|
|
25
|
-
userId: "{{alarm.user}}",
|
|
26
|
-
item_id: "{{item.id}}",
|
|
27
|
-
item_source: "{{item.source}}",
|
|
28
|
-
item_dimension: "{{item.dimension}}",
|
|
29
|
-
value: "{{value}}",
|
|
30
|
-
condition: "{{condition}}",
|
|
31
|
-
firedAt: "{{timestamp}}",
|
|
32
|
-
},
|
|
33
|
-
params: "{{action}}",
|
|
34
|
-
});
|
|
35
|
-
/**
|
|
36
|
-
* The HTTP call that carries the action out.
|
|
37
|
-
*
|
|
38
|
-
* `type: "webhook"` means the executor runs an `OD3_AlarmWebhook` row rather
|
|
39
|
-
* than calling anything itself. That row used to be created by hand — and a
|
|
40
|
-
* hand-made one is how an installation ends up with `payload: "{}"`, which
|
|
41
|
-
* reaches the endpoint carrying neither secret nor event, so nothing happens
|
|
42
|
-
* and nothing says why.
|
|
43
|
-
*
|
|
44
|
-
* Found again by `url`, not by name: the url is what makes two rows the same
|
|
45
|
-
* webhook, a name is free text somebody renames.
|
|
46
|
-
*
|
|
47
|
-
* ⚠️ **The url is relative.** That is what the existing hand-made rows use and
|
|
48
|
-
* what this server answers, but whether the executor resolves it against the
|
|
49
|
-
* Parse base or needs an absolute address is open.WARE's business. If a fired
|
|
50
|
-
* alarm never arrives, check this first.
|
|
51
|
-
*/
|
|
52
|
-
async function ensureAlarmScheduleWebhook() {
|
|
53
|
-
const url = "/parse/functions/openinc-openservice-alarm-create-schedule";
|
|
54
|
-
const existing = await new node_1.default.Query(index_js_1.AlarmWebhook)
|
|
55
|
-
.equalTo("url", url)
|
|
56
|
-
.first({ useMasterKey: true });
|
|
57
|
-
if (existing) {
|
|
58
|
-
// An empty payload is the failure this function exists to prevent, so it
|
|
59
|
-
// is repaired. One somebody deliberately customised is left alone.
|
|
60
|
-
const payload = existing.get("payload");
|
|
61
|
-
if (!payload || payload.trim() === "" || payload.trim() === "{}") {
|
|
62
|
-
existing.set("payload", WEBHOOK_PAYLOAD);
|
|
63
|
-
await existing.save(null, { useMasterKey: true });
|
|
64
|
-
console.log(`[AlarmSchedule] Filled in the empty payload of "${url}"`);
|
|
65
|
-
}
|
|
66
|
-
return;
|
|
67
|
-
}
|
|
68
|
-
const webhook = new index_js_1.AlarmWebhook();
|
|
69
|
-
webhook.set("name", WEBHOOK_NAME);
|
|
70
|
-
webhook.set("url", url);
|
|
71
|
-
webhook.set("method", "POST");
|
|
72
|
-
webhook.set("payload", WEBHOOK_PAYLOAD);
|
|
73
|
-
webhook.set("header", { "Content-Type": "application/json" });
|
|
74
|
-
webhook.set("extraOptions", {});
|
|
75
|
-
await webhook.save(null, { useMasterKey: true });
|
|
76
|
-
console.log(`[AlarmSchedule] Registered webhook "${WEBHOOK_NAME}"`);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Make "schedule a maintenance appointment" selectable in the alarm dialog.
|
|
80
|
-
*
|
|
81
|
-
* Alarm actions are **data**, not code: `OD3_AlarmAction` rows that the
|
|
82
|
-
* monitoring adapter loads into the frontend, where the chosen row's
|
|
83
|
-
* `formFields` are rendered as the action's settings form (see
|
|
84
|
-
* `plugins/monitoring/src/components/AlarmCreate.tsx`). There is no plugin-side
|
|
85
|
-
* `registerAlarmAction`, so the row is seeded here — find-or-create by `topic`,
|
|
86
|
-
* like the ticket action and the other open.SERVICE bootstraps.
|
|
87
|
-
*
|
|
88
|
-
* The row is **global** (no tenant): the action makes sense for every tenant,
|
|
89
|
-
* and the tenant of a fired alarm is established by its secret, not by this row.
|
|
90
|
-
*
|
|
91
|
-
* **How it is carried out.** `type: "webhook"` means the executor runs an
|
|
92
|
-
* `OD3_AlarmWebhook` row, which POSTs to a URL. That row is created by hand for
|
|
93
|
-
* now (an admin UI can come later) and must point at
|
|
94
|
-
* `/parse/functions/openinc-openservice-alarm-create-schedule` with the payload
|
|
95
|
-
* below. The `target` here names the same path so the two are readable side by
|
|
96
|
-
* side, and so a webhook-less executor that reads `target` directly still works.
|
|
7
|
+
* Make "schedule a maintenance appointment" selectable in the alarm dialog and
|
|
8
|
+
* executable by open.WARE: the `OD3_AlarmAction` row and the
|
|
9
|
+
* `OD3_AlarmWebhook` row it targets (see `ensureAlarmActionRow`).
|
|
97
10
|
*/
|
|
98
11
|
async function ensureAlarmScheduleAction() {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
// store whole objects instead of ids.
|
|
108
|
-
if (JSON.stringify(existing.get("formFields")) !== JSON.stringify(FORM_FIELDS)) {
|
|
109
|
-
existing.set("formFields", FORM_FIELDS);
|
|
110
|
-
await existing.save(null, { useMasterKey: true });
|
|
111
|
-
console.log(`[AlarmSchedule] Updated form fields of "${AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID}"`);
|
|
112
|
-
}
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
const action = new index_js_1.AlarmAction();
|
|
116
|
-
action.set("label", "Wartungstermin anlegen (open.SERVICE)");
|
|
117
|
-
action.set("type", "webhook");
|
|
118
|
-
action.set("topic", AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID);
|
|
119
|
-
action.set("target", "/parse/functions/openinc-openservice-alarm-create-schedule");
|
|
120
|
-
action.set("templateType", "json");
|
|
121
|
-
action.set("payload", JSON.stringify({
|
|
122
|
-
secret: "{{secret}}",
|
|
123
|
-
event: {
|
|
124
|
-
alarmId: "{{alarm.id}}",
|
|
125
|
-
name: "{{alarm.name}}",
|
|
126
|
-
userId: "{{alarm.user}}",
|
|
127
|
-
item_id: "{{item.id}}",
|
|
128
|
-
item_source: "{{item.source}}",
|
|
129
|
-
item_dimension: "{{item.dimension}}",
|
|
130
|
-
value: "{{value}}",
|
|
131
|
-
condition: "{{condition}}",
|
|
132
|
-
firedAt: "{{timestamp}}",
|
|
133
|
-
},
|
|
134
|
-
params: "{{action}}",
|
|
135
|
-
}));
|
|
136
|
-
// Wear is not only a number: a boolean "filter clogged" or a string state
|
|
137
|
-
// code is just as good a reason to schedule maintenance.
|
|
138
|
-
action.set("supportedTypes", [
|
|
139
|
-
"Number",
|
|
140
|
-
"String",
|
|
141
|
-
"Boolean",
|
|
142
|
-
"Geo",
|
|
143
|
-
"Object",
|
|
144
|
-
]);
|
|
145
|
-
action.set("formFields", FORM_FIELDS);
|
|
146
|
-
await action.save(null, { useMasterKey: true });
|
|
147
|
-
console.log(`[AlarmSchedule] Registered alarm action "${AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID}"`);
|
|
12
|
+
await (0, ensureAlarmActionRow_js_1.ensureAlarmActionRow)({
|
|
13
|
+
topic: AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID,
|
|
14
|
+
label: "Wartungstermin anlegen (open.SERVICE)",
|
|
15
|
+
functionName: "openinc-openservice-alarm-create-schedule",
|
|
16
|
+
webhookName: "open.SERVICE: Wartungstermin anlegen",
|
|
17
|
+
webhookComment: "Von open.SERVICE angelegt und gepflegt — Änderungen werden beim Serverstart überschrieben.",
|
|
18
|
+
formFields: FORM_FIELDS,
|
|
19
|
+
});
|
|
148
20
|
}
|
|
149
21
|
/**
|
|
150
22
|
* What the person configuring an alarm gets to fill in.
|
|
@@ -11,6 +11,7 @@ const index_js_1 = require("../../../../types/index.js");
|
|
|
11
11
|
const ticketFormConfig_js_1 = require("../../tickets/ticketFormConfig.js");
|
|
12
12
|
const actionParams_js_1 = require("../actionParams.js");
|
|
13
13
|
const alarmIdentity_js_1 = require("../alarmIdentity.js");
|
|
14
|
+
const resolveAlarmUser_js_1 = require("../resolveAlarmUser.js");
|
|
14
15
|
const resolveEquipment_js_1 = require("../resolveEquipment.js");
|
|
15
16
|
const tenantForSecret_js_1 = require("../tenantForSecret.js");
|
|
16
17
|
const alarmTicketFields_js_1 = require("./alarmTicketFields.js");
|
|
@@ -83,6 +84,11 @@ async function createAlarmTicket(tenant, event, rawParams = {}) {
|
|
|
83
84
|
ticket.set("startDate", (0, alarmIdentity_js_1.firedAt)(event));
|
|
84
85
|
if (equipment)
|
|
85
86
|
ticket.set("equipment", equipment);
|
|
87
|
+
// The alarm's owner is the ticket's creator: it shows up as such, and the
|
|
88
|
+
// ACL gives them write access to what their alarm raised.
|
|
89
|
+
const creator = await (0, resolveAlarmUser_js_1.resolveAlarmUser)(tenant, event.userId, `[${AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID}]`);
|
|
90
|
+
if (creator)
|
|
91
|
+
ticket.set("createdBy", creator);
|
|
86
92
|
// The config's remaining defaults first: the flat fields below and the
|
|
87
93
|
// template after them override them.
|
|
88
94
|
for (const [key, value] of Object.entries(defaults.values)) {
|
|
@@ -1,22 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Make "create a ticket" selectable in the alarm dialog
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* monitoring adapter loads into the frontend, where the chosen row's
|
|
6
|
-
* `formFields` are rendered as the action's settings form (see
|
|
7
|
-
* `plugins/monitoring/src/components/AlarmCreate.tsx`). There is no plugin-side
|
|
8
|
-
* `registerAlarmAction`, so the row is seeded here — find-or-create by `topic`,
|
|
9
|
-
* like the other open.SERVICE bootstraps.
|
|
10
|
-
*
|
|
11
|
-
* The row is **global** (no tenant): the action makes sense for every tenant,
|
|
12
|
-
* and the tenant of a fired alarm is established by its secret, not by this
|
|
13
|
-
* row.
|
|
14
|
-
*
|
|
15
|
-
* ⚠️ `type` / `target` / `payload` are the executor's half of the contract —
|
|
16
|
-
* the component that evaluates alarms lives outside this server. The values
|
|
17
|
-
* below assume a webhook-style executor that POSTs `payload` (placeholders
|
|
18
|
-
* filled from the alarm) to `target`. If the executor expects something else,
|
|
19
|
-
* this row is where it is corrected; the receiving endpoint accepts any caller
|
|
20
|
-
* that brings the secret.
|
|
2
|
+
* Make "create a ticket" selectable in the alarm dialog and executable by
|
|
3
|
+
* open.WARE: the `OD3_AlarmAction` row and the `OD3_AlarmWebhook` row it
|
|
4
|
+
* targets (see `ensureAlarmActionRow`).
|
|
21
5
|
*/
|
|
22
6
|
export declare function ensureAlarmTicketAction(): Promise<void>;
|
|
@@ -1,81 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.ensureAlarmTicketAction = ensureAlarmTicketAction;
|
|
7
|
-
const node_1 = __importDefault(require("parse/node"));
|
|
8
4
|
const index_js_1 = require("../../../../types/index.js");
|
|
5
|
+
const ensureAlarmActionRow_js_1 = require("../ensureAlarmActionRow.js");
|
|
9
6
|
const AlarmTicketTypes_js_1 = require("./AlarmTicketTypes.js");
|
|
10
7
|
/**
|
|
11
|
-
* Make "create a ticket" selectable in the alarm dialog
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
* monitoring adapter loads into the frontend, where the chosen row's
|
|
15
|
-
* `formFields` are rendered as the action's settings form (see
|
|
16
|
-
* `plugins/monitoring/src/components/AlarmCreate.tsx`). There is no plugin-side
|
|
17
|
-
* `registerAlarmAction`, so the row is seeded here — find-or-create by `topic`,
|
|
18
|
-
* like the other open.SERVICE bootstraps.
|
|
19
|
-
*
|
|
20
|
-
* The row is **global** (no tenant): the action makes sense for every tenant,
|
|
21
|
-
* and the tenant of a fired alarm is established by its secret, not by this
|
|
22
|
-
* row.
|
|
23
|
-
*
|
|
24
|
-
* ⚠️ `type` / `target` / `payload` are the executor's half of the contract —
|
|
25
|
-
* the component that evaluates alarms lives outside this server. The values
|
|
26
|
-
* below assume a webhook-style executor that POSTs `payload` (placeholders
|
|
27
|
-
* filled from the alarm) to `target`. If the executor expects something else,
|
|
28
|
-
* this row is where it is corrected; the receiving endpoint accepts any caller
|
|
29
|
-
* that brings the secret.
|
|
8
|
+
* Make "create a ticket" selectable in the alarm dialog and executable by
|
|
9
|
+
* open.WARE: the `OD3_AlarmAction` row and the `OD3_AlarmWebhook` row it
|
|
10
|
+
* targets (see `ensureAlarmActionRow`).
|
|
30
11
|
*/
|
|
31
12
|
async function ensureAlarmTicketAction() {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
// store whole objects instead of ids.
|
|
41
|
-
if (JSON.stringify(existing.get("formFields")) !== JSON.stringify(FORM_FIELDS)) {
|
|
42
|
-
existing.set("formFields", FORM_FIELDS);
|
|
43
|
-
await existing.save(null, { useMasterKey: true });
|
|
44
|
-
console.log(`[AlarmTicket] Updated form fields of "${AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID}"`);
|
|
45
|
-
}
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const action = new index_js_1.AlarmAction();
|
|
49
|
-
action.set("label", "Ticket erstellen (open.SERVICE)");
|
|
50
|
-
action.set("type", "webhook");
|
|
51
|
-
action.set("topic", AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID);
|
|
52
|
-
action.set("target", "/parse/functions/openinc-openservice-alarm-create-ticket");
|
|
53
|
-
action.set("templateType", "json");
|
|
54
|
-
action.set("payload", JSON.stringify({
|
|
55
|
-
secret: "{{secret}}",
|
|
56
|
-
event: {
|
|
57
|
-
alarmId: "{{alarm.id}}",
|
|
58
|
-
name: "{{alarm.name}}",
|
|
59
|
-
item_id: "{{item.id}}",
|
|
60
|
-
item_source: "{{item.source}}",
|
|
61
|
-
item_dimension: "{{item.dimension}}",
|
|
62
|
-
value: "{{value}}",
|
|
63
|
-
condition: "{{condition}}",
|
|
64
|
-
firedAt: "{{timestamp}}",
|
|
65
|
-
},
|
|
66
|
-
params: "{{action}}",
|
|
67
|
-
}));
|
|
68
|
-
// Every value type can breach a rule, so every type may raise a ticket.
|
|
69
|
-
action.set("supportedTypes", [
|
|
70
|
-
"Number",
|
|
71
|
-
"String",
|
|
72
|
-
"Boolean",
|
|
73
|
-
"Geo",
|
|
74
|
-
"Object",
|
|
75
|
-
]);
|
|
76
|
-
action.set("formFields", FORM_FIELDS);
|
|
77
|
-
await action.save(null, { useMasterKey: true });
|
|
78
|
-
console.log(`[AlarmTicket] Registered alarm action "${AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID}"`);
|
|
13
|
+
await (0, ensureAlarmActionRow_js_1.ensureAlarmActionRow)({
|
|
14
|
+
topic: AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID,
|
|
15
|
+
label: "Ticket erstellen (open.SERVICE)",
|
|
16
|
+
functionName: "openinc-openservice-alarm-create-ticket",
|
|
17
|
+
webhookName: "open.SERVICE: Ticket erstellen",
|
|
18
|
+
webhookComment: "Von open.SERVICE angelegt und gepflegt — Änderungen werden beim Serverstart überschrieben.",
|
|
19
|
+
formFields: FORM_FIELDS,
|
|
20
|
+
});
|
|
79
21
|
}
|
|
80
22
|
/**
|
|
81
23
|
* What the person configuring an alarm gets to fill in.
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Normalises `equipment` and rejects equipment of another tenant.
|
|
3
|
+
*
|
|
4
|
+
* The column holds plain equipment ids, written directly: an article belongs to
|
|
5
|
+
* the equipment it is assigned to, and the frontend adds the descendants when
|
|
6
|
+
* it asks for "the parts of this machine" (a part of the gearbox is a part of
|
|
7
|
+
* the machine too). Nothing is stored for the ancestors, so moving equipment in
|
|
8
|
+
* the hierarchy needs no rewrite here.
|
|
9
|
+
*
|
|
10
|
+
* Only a changed column is judged, so an article that already carries a bad id
|
|
11
|
+
* stays saveable — the ABAS sync re-saves the whole catalogue and must not stop
|
|
12
|
+
* on it. Ids that match no equipment pass: they show as nothing and harm
|
|
13
|
+
* nothing, while refusing them would block every save after equipment is
|
|
14
|
+
* deleted for good.
|
|
15
|
+
*
|
|
16
|
+
* Articles without a tenant are shared catalogue entries; they may reference
|
|
17
|
+
* any equipment, like shared master data on a ticket.
|
|
18
|
+
*/
|
|
19
|
+
export declare function assertArticleEquipment(object: Parse.Object): Promise<void>;
|
|
@@ -0,0 +1,53 @@
|
|
|
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.assertArticleEquipment = assertArticleEquipment;
|
|
7
|
+
// The equipment an article is a spare part of (`OD3_BDE_Article.equipment`).
|
|
8
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
9
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
10
|
+
const index_js_1 = require("../../../types/index.js");
|
|
11
|
+
/**
|
|
12
|
+
* Normalises `equipment` and rejects equipment of another tenant.
|
|
13
|
+
*
|
|
14
|
+
* The column holds plain equipment ids, written directly: an article belongs to
|
|
15
|
+
* the equipment it is assigned to, and the frontend adds the descendants when
|
|
16
|
+
* it asks for "the parts of this machine" (a part of the gearbox is a part of
|
|
17
|
+
* the machine too). Nothing is stored for the ancestors, so moving equipment in
|
|
18
|
+
* the hierarchy needs no rewrite here.
|
|
19
|
+
*
|
|
20
|
+
* Only a changed column is judged, so an article that already carries a bad id
|
|
21
|
+
* stays saveable — the ABAS sync re-saves the whole catalogue and must not stop
|
|
22
|
+
* on it. Ids that match no equipment pass: they show as nothing and harm
|
|
23
|
+
* nothing, while refusing them would block every save after equipment is
|
|
24
|
+
* deleted for good.
|
|
25
|
+
*
|
|
26
|
+
* Articles without a tenant are shared catalogue entries; they may reference
|
|
27
|
+
* any equipment, like shared master data on a ticket.
|
|
28
|
+
*/
|
|
29
|
+
async function assertArticleEquipment(object) {
|
|
30
|
+
if (!object.dirty("equipment"))
|
|
31
|
+
return;
|
|
32
|
+
const ids = [...new Set((0, openservice_shared_1.refIds)(object.get("equipment")))];
|
|
33
|
+
if (ids.length === 0) {
|
|
34
|
+
object.unset("equipment");
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
object.set("equipment", ids);
|
|
38
|
+
const tenantId = object.get("tenant")?.id;
|
|
39
|
+
if (!tenantId)
|
|
40
|
+
return;
|
|
41
|
+
const rows = await new node_1.default.Query(index_js_1.Service_Equipment)
|
|
42
|
+
.containedIn("objectId", ids)
|
|
43
|
+
.select("tenant")
|
|
44
|
+
.limit(ids.length)
|
|
45
|
+
.find({ useMasterKey: true });
|
|
46
|
+
for (const row of rows) {
|
|
47
|
+
const refTenantId = row.get("tenant")?.id;
|
|
48
|
+
if (!refTenantId || refTenantId === tenantId)
|
|
49
|
+
continue;
|
|
50
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `Cannot assign equipment ${row.id} of tenant ${refTenantId} to an ` +
|
|
51
|
+
`article of tenant ${tenantId}.`);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Whether stock has reached the reorder point: `stock <= minimumStock`.
|
|
3
|
+
*
|
|
4
|
+
* No reorder point (unset or 0) means no alert — every ABAS article carries
|
|
5
|
+
* `minimumStock: 0` from the schema default, and none of them is "running out".
|
|
6
|
+
* Uncounted stock reads as 0: a part with a reorder point and no count is one
|
|
7
|
+
* to look at.
|
|
8
|
+
*/
|
|
9
|
+
export declare function stockAlertOf(stock: unknown, minimumStock: unknown): boolean;
|
|
10
|
+
/**
|
|
11
|
+
* Keeps `stockAlert` in step with `stock` and `minimumStock` on every save.
|
|
12
|
+
*
|
|
13
|
+
* A stored flag because a query cannot compare two columns: the article list
|
|
14
|
+
* filters on it ("Meldebestand erreicht"), and the reorder notification of
|
|
15
|
+
* "Lager light" will need it to fire once on the edge rather than on every
|
|
16
|
+
* save. Stock is still counted by hand — nothing books consumption yet — so
|
|
17
|
+
* the flag is as good as the last count.
|
|
18
|
+
*/
|
|
19
|
+
export declare function applyStockAlert(object: Parse.Object): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stockAlertOf = stockAlertOf;
|
|
4
|
+
exports.applyStockAlert = applyStockAlert;
|
|
5
|
+
/**
|
|
6
|
+
* Whether stock has reached the reorder point: `stock <= minimumStock`.
|
|
7
|
+
*
|
|
8
|
+
* No reorder point (unset or 0) means no alert — every ABAS article carries
|
|
9
|
+
* `minimumStock: 0` from the schema default, and none of them is "running out".
|
|
10
|
+
* Uncounted stock reads as 0: a part with a reorder point and no count is one
|
|
11
|
+
* to look at.
|
|
12
|
+
*/
|
|
13
|
+
function stockAlertOf(stock, minimumStock) {
|
|
14
|
+
if (typeof minimumStock !== "number" || minimumStock <= 0)
|
|
15
|
+
return false;
|
|
16
|
+
return (typeof stock === "number" ? stock : 0) <= minimumStock;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Keeps `stockAlert` in step with `stock` and `minimumStock` on every save.
|
|
20
|
+
*
|
|
21
|
+
* A stored flag because a query cannot compare two columns: the article list
|
|
22
|
+
* filters on it ("Meldebestand erreicht"), and the reorder notification of
|
|
23
|
+
* "Lager light" will need it to fire once on the edge rather than on every
|
|
24
|
+
* save. Stock is still counted by hand — nothing books consumption yet — so
|
|
25
|
+
* the flag is as good as the last count.
|
|
26
|
+
*/
|
|
27
|
+
function applyStockAlert(object) {
|
|
28
|
+
const alert = stockAlertOf(object.get("stock"), object.get("minimumStock"));
|
|
29
|
+
if (object.get("stockAlert") !== alert)
|
|
30
|
+
object.set("stockAlert", alert);
|
|
31
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The classes, most critical first. Mirrors `CRITICALITY_LEVELS` in
|
|
3
|
+
* `@opendash/plugin-openservice-core`.
|
|
4
|
+
*/
|
|
5
|
+
export declare const CRITICALITY_LEVELS: readonly ["A", "B", "C"];
|
|
6
|
+
export type Criticality = (typeof CRITICALITY_LEVELS)[number];
|
|
7
|
+
/**
|
|
8
|
+
* What the priority formula reads under `criticality`: the classes on the
|
|
9
|
+
* 0–100 scale of the ticket's factors. Unclassified equipment, and a ticket
|
|
10
|
+
* without equipment, read 0 like class C — the factors' rule for an empty
|
|
11
|
+
* input. Mirrors `CRITICALITY_VALUES` of the core plugin.
|
|
12
|
+
*/
|
|
13
|
+
export declare const CRITICALITY_VALUES: Record<Criticality, number>;
|
|
14
|
+
export declare function isCriticality(value: unknown): value is Criticality;
|
|
15
|
+
/**
|
|
16
|
+
* Normalises `criticality` on an equipment being saved: trimmed and
|
|
17
|
+
* upper-cased, empty unsets it (the equipment inherits again). Anything but
|
|
18
|
+
* A, B or C is refused.
|
|
19
|
+
*/
|
|
20
|
+
export declare function normalizeCriticality(object: Parse.Object): void;
|
|
21
|
+
/**
|
|
22
|
+
* The class an equipment counts as: its own, else the nearest ancestor's;
|
|
23
|
+
* `undefined` when nobody up the tree classified it. Reads one row per level
|
|
24
|
+
* with the master key — the caller decides whose equipment it asks about.
|
|
25
|
+
* Guarded against a cycle in `parent`, which migrated data has had.
|
|
26
|
+
*/
|
|
27
|
+
export declare function effectiveCriticality(equipment: Parse.Object | undefined): Promise<Criticality | undefined>;
|
|
28
|
+
/** The number the priority formula reads for a class. */
|
|
29
|
+
export declare function criticalityValue(criticality: Criticality | undefined): number;
|
|
@@ -0,0 +1,85 @@
|
|
|
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.CRITICALITY_VALUES = exports.CRITICALITY_LEVELS = void 0;
|
|
7
|
+
exports.isCriticality = isCriticality;
|
|
8
|
+
exports.normalizeCriticality = normalizeCriticality;
|
|
9
|
+
exports.effectiveCriticality = effectiveCriticality;
|
|
10
|
+
exports.criticalityValue = criticalityValue;
|
|
11
|
+
// How critical a piece of equipment is for production: A (stops it), B
|
|
12
|
+
// (hampers it), C (neither). Set where somebody classified it and inherited
|
|
13
|
+
// downwards: a gearbox without its own class counts as its machine does.
|
|
14
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
15
|
+
const index_js_1 = require("../../../types/index.js");
|
|
16
|
+
/**
|
|
17
|
+
* The classes, most critical first. Mirrors `CRITICALITY_LEVELS` in
|
|
18
|
+
* `@opendash/plugin-openservice-core`.
|
|
19
|
+
*/
|
|
20
|
+
exports.CRITICALITY_LEVELS = ["A", "B", "C"];
|
|
21
|
+
/**
|
|
22
|
+
* What the priority formula reads under `criticality`: the classes on the
|
|
23
|
+
* 0–100 scale of the ticket's factors. Unclassified equipment, and a ticket
|
|
24
|
+
* without equipment, read 0 like class C — the factors' rule for an empty
|
|
25
|
+
* input. Mirrors `CRITICALITY_VALUES` of the core plugin.
|
|
26
|
+
*/
|
|
27
|
+
exports.CRITICALITY_VALUES = {
|
|
28
|
+
A: 100,
|
|
29
|
+
B: 50,
|
|
30
|
+
C: 0,
|
|
31
|
+
};
|
|
32
|
+
/** Further up than any real hierarchy; stops a walk through broken data. */
|
|
33
|
+
const MAX_DEPTH = 50;
|
|
34
|
+
function isCriticality(value) {
|
|
35
|
+
return (typeof value === "string" &&
|
|
36
|
+
exports.CRITICALITY_LEVELS.includes(value));
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Normalises `criticality` on an equipment being saved: trimmed and
|
|
40
|
+
* upper-cased, empty unsets it (the equipment inherits again). Anything but
|
|
41
|
+
* A, B or C is refused.
|
|
42
|
+
*/
|
|
43
|
+
function normalizeCriticality(object) {
|
|
44
|
+
const raw = object.get("criticality");
|
|
45
|
+
if (raw == null)
|
|
46
|
+
return;
|
|
47
|
+
const value = typeof raw === "string" ? raw.trim().toUpperCase() : raw;
|
|
48
|
+
if (value === "") {
|
|
49
|
+
object.unset("criticality");
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!isCriticality(value)) {
|
|
53
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `criticality must be one of ${exports.CRITICALITY_LEVELS.join(", ")}`);
|
|
54
|
+
}
|
|
55
|
+
if (value !== raw)
|
|
56
|
+
object.set("criticality", value);
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* The class an equipment counts as: its own, else the nearest ancestor's;
|
|
60
|
+
* `undefined` when nobody up the tree classified it. Reads one row per level
|
|
61
|
+
* with the master key — the caller decides whose equipment it asks about.
|
|
62
|
+
* Guarded against a cycle in `parent`, which migrated data has had.
|
|
63
|
+
*/
|
|
64
|
+
async function effectiveCriticality(equipment) {
|
|
65
|
+
const seen = new Set();
|
|
66
|
+
let id = equipment?.id;
|
|
67
|
+
while (id && !seen.has(id) && seen.size < MAX_DEPTH) {
|
|
68
|
+
seen.add(id);
|
|
69
|
+
const row = await new node_1.default.Query(index_js_1.Service_Equipment)
|
|
70
|
+
.select("criticality", "parent")
|
|
71
|
+
.equalTo("objectId", id)
|
|
72
|
+
.first({ useMasterKey: true });
|
|
73
|
+
if (!row)
|
|
74
|
+
return undefined;
|
|
75
|
+
const own = row.get("criticality");
|
|
76
|
+
if (isCriticality(own))
|
|
77
|
+
return own;
|
|
78
|
+
id = row.get("parent")?.id;
|
|
79
|
+
}
|
|
80
|
+
return undefined;
|
|
81
|
+
}
|
|
82
|
+
/** The number the priority formula reads for a class. */
|
|
83
|
+
function criticalityValue(criticality) {
|
|
84
|
+
return criticality ? exports.CRITICALITY_VALUES[criticality] : 0;
|
|
85
|
+
}
|
|
@@ -43,9 +43,17 @@ async function init(generations) {
|
|
|
43
43
|
if (generations.v2) {
|
|
44
44
|
await (0, initServiceSchedulesFeature_js_1.initServiceSchedulesFeature)();
|
|
45
45
|
await (0, initKpiFeature_js_1.initKpiFeature)();
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
// The alarm classes exist only with MONITORING (featuremap). A failure
|
|
47
|
+
// here must not stop the rest of open.SERVICE from coming up.
|
|
48
|
+
if ((0, index_js_1.isFeatureEnabled)("MONITORING")) {
|
|
49
|
+
try {
|
|
50
|
+
await (0, index_js_2.ensureAlarmTicketAction)();
|
|
51
|
+
await (0, index_js_2.ensureAlarmScheduleAction)();
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
console.error("[open.SERVICE] Alarm actions not set up:", error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
49
57
|
}
|
|
50
58
|
// Last, so the rows it reports as missing are the ones a human still has to
|
|
51
59
|
// supply rather than ones a later bootstrap would have created anyway. The
|