@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,11 +1,11 @@
|
|
|
1
1
|
import type { FormulaNode } from "@opendash/ruleset-core";
|
|
2
2
|
import type { Service_FormConfig } from "../../../types/index.js";
|
|
3
3
|
/**
|
|
4
|
-
* The
|
|
4
|
+
* The names a priority formula may read, e.g.
|
|
5
5
|
* `max(downtime, restriction) * 0.7 + frequency * 0.3`. Mirrors
|
|
6
|
-
* `
|
|
6
|
+
* `PRIORITY_FORMULA_INPUTS` in `@opendash/plugin-openservice-ticket`.
|
|
7
7
|
*/
|
|
8
|
-
export declare const PRIORITY_FORMULA_INPUTS: readonly ["downtime", "restriction", "frequency"];
|
|
8
|
+
export declare const PRIORITY_FORMULA_INPUTS: readonly ["downtime", "restriction", "frequency", "criticality"];
|
|
9
9
|
interface PriorityFormula {
|
|
10
10
|
expression: FormulaNode;
|
|
11
11
|
names: string[];
|
|
@@ -21,28 +21,35 @@ export declare function priorityFormulaOf(config: Service_FormConfig | undefined
|
|
|
21
21
|
* The priority for a ticket's values, or `undefined` when there is nothing to
|
|
22
22
|
* compute from. Mirrors `computePriority` of the frontend:
|
|
23
23
|
*
|
|
24
|
-
* - None of the
|
|
25
|
-
* nobody has assessed keeps its priority.
|
|
24
|
+
* - None of the scale fields the formula reads is set: `undefined`, so a
|
|
25
|
+
* ticket nobody has assessed keeps its priority. The equipment's
|
|
26
|
+
* criticality does not count here — it is known for every ticket on
|
|
27
|
+
* classified equipment, assessed or not.
|
|
26
28
|
* - Some are set: the rest count as 0, the lowest level.
|
|
27
29
|
* - Clamped to 0–100 and rounded; no number at all (division by zero) is
|
|
28
30
|
* `undefined` as well.
|
|
29
31
|
*/
|
|
30
32
|
export declare function computePriority(formula: PriorityFormula, values: (key: string) => unknown): number | undefined;
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
+
/**
|
|
34
|
+
* Whether this save changes one of the inputs a priority formula reads: a
|
|
35
|
+
* scale field, or the equipment — whose class the formula reads under
|
|
36
|
+
* `criticality`. Without `formula`, whether it may: the equipment counts
|
|
37
|
+
* whenever a formula could read it.
|
|
38
|
+
*/
|
|
39
|
+
export declare function changesPriorityInputs(object: Parse.Object, original: Parse.Object | undefined, formula?: PriorityFormula): boolean;
|
|
33
40
|
/**
|
|
34
41
|
* Sets the computed priority on a ticket being saved, under `config` — the
|
|
35
42
|
* form config that applies to the user saving (see `applicableFormConfig`).
|
|
36
43
|
*
|
|
37
44
|
* Only when this save changes one of the inputs — a ticket the save does not
|
|
38
|
-
* reassess keeps its priority, also when the formula has changed since
|
|
39
|
-
* only when the caller does not set the priority
|
|
40
|
-
* import keeps the priority its file states.
|
|
45
|
+
* reassess keeps its priority, also when the formula has changed since, or the
|
|
46
|
+
* class of its equipment — and only when the caller does not set the priority
|
|
47
|
+
* itself in the same save: an import keeps the priority its file states.
|
|
41
48
|
*
|
|
42
49
|
* "Changes" and "sets" are judged against `original`. The admin table sends
|
|
43
50
|
* every field of its form, the unchanged priority included; counting that as
|
|
44
51
|
* set by hand would leave the old priority after every factor edit there —
|
|
45
52
|
* which is the case this exists for.
|
|
46
53
|
*/
|
|
47
|
-
export declare function applyComputedPriority(object: Parse.Object, original: Parse.Object | undefined, config: Service_FormConfig | undefined): void
|
|
54
|
+
export declare function applyComputedPriority(object: Parse.Object, original: Parse.Object | undefined, config: Service_FormConfig | undefined): Promise<void>;
|
|
48
55
|
export {};
|
|
@@ -6,15 +6,26 @@ exports.computePriority = computePriority;
|
|
|
6
6
|
exports.changesPriorityInputs = changesPriorityInputs;
|
|
7
7
|
exports.applyComputedPriority = applyComputedPriority;
|
|
8
8
|
const ruleset_core_1 = require("@opendash/ruleset-core");
|
|
9
|
+
const criticality_js_1 = require("../equipment/criticality.js");
|
|
9
10
|
/**
|
|
10
|
-
* The
|
|
11
|
+
* The ticket's own assessment: the scale fields. Mirrors `SCALE_FIELD_KEYS` in
|
|
12
|
+
* `@opendash/plugin-openservice-ticket`.
|
|
13
|
+
*/
|
|
14
|
+
const ASSESSMENT_INPUTS = ["downtime", "restriction", "frequency"];
|
|
15
|
+
/**
|
|
16
|
+
* The equipment's class (A 100, B 50, C or none 0), inherited down the tree —
|
|
17
|
+
* see `criticality.ts`. Context, not an assessment: it alone never makes a
|
|
18
|
+
* ticket "assessed" (see {@link computePriority}).
|
|
19
|
+
*/
|
|
20
|
+
const CRITICALITY_INPUT = "criticality";
|
|
21
|
+
/**
|
|
22
|
+
* The names a priority formula may read, e.g.
|
|
11
23
|
* `max(downtime, restriction) * 0.7 + frequency * 0.3`. Mirrors
|
|
12
|
-
* `
|
|
24
|
+
* `PRIORITY_FORMULA_INPUTS` in `@opendash/plugin-openservice-ticket`.
|
|
13
25
|
*/
|
|
14
26
|
exports.PRIORITY_FORMULA_INPUTS = [
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
"frequency",
|
|
27
|
+
...ASSESSMENT_INPUTS,
|
|
28
|
+
CRITICALITY_INPUT,
|
|
18
29
|
];
|
|
19
30
|
/**
|
|
20
31
|
* The formula a config's priority entry asks for, or `undefined` when the
|
|
@@ -49,8 +60,10 @@ function asNumber(value) {
|
|
|
49
60
|
* The priority for a ticket's values, or `undefined` when there is nothing to
|
|
50
61
|
* compute from. Mirrors `computePriority` of the frontend:
|
|
51
62
|
*
|
|
52
|
-
* - None of the
|
|
53
|
-
* nobody has assessed keeps its priority.
|
|
63
|
+
* - None of the scale fields the formula reads is set: `undefined`, so a
|
|
64
|
+
* ticket nobody has assessed keeps its priority. The equipment's
|
|
65
|
+
* criticality does not count here — it is known for every ticket on
|
|
66
|
+
* classified equipment, assessed or not.
|
|
54
67
|
* - Some are set: the rest count as 0, the lowest level.
|
|
55
68
|
* - Clamped to 0–100 and rounded; no number at all (division by zero) is
|
|
56
69
|
* `undefined` as well.
|
|
@@ -60,7 +73,7 @@ function computePriority(formula, values) {
|
|
|
60
73
|
let anySet = false;
|
|
61
74
|
for (const name of formula.names) {
|
|
62
75
|
const value = asNumber(values(name));
|
|
63
|
-
if (value !== undefined)
|
|
76
|
+
if (value !== undefined && name !== CRITICALITY_INPUT)
|
|
64
77
|
anySet = true;
|
|
65
78
|
scope[name] = value ?? 0;
|
|
66
79
|
}
|
|
@@ -77,33 +90,54 @@ function changes(object, original, key) {
|
|
|
77
90
|
? object.get(key) !== original.get(key)
|
|
78
91
|
: object.get(key) != null;
|
|
79
92
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
93
|
+
/**
|
|
94
|
+
* Whether this save moves the ticket to other equipment. Compared by id: a
|
|
95
|
+
* pointer comes back as a new object on every read.
|
|
96
|
+
*/
|
|
97
|
+
function changesEquipment(object, original) {
|
|
98
|
+
const id = (o) => o?.get("equipment")?.id;
|
|
99
|
+
return original ? id(object) !== id(original) : id(object) != null;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Whether this save changes one of the inputs a priority formula reads: a
|
|
103
|
+
* scale field, or the equipment — whose class the formula reads under
|
|
104
|
+
* `criticality`. Without `formula`, whether it may: the equipment counts
|
|
105
|
+
* whenever a formula could read it.
|
|
106
|
+
*/
|
|
107
|
+
function changesPriorityInputs(object, original, formula) {
|
|
108
|
+
if (ASSESSMENT_INPUTS.some((key) => changes(object, original, key)))
|
|
109
|
+
return true;
|
|
110
|
+
const readsCriticality = formula
|
|
111
|
+
? formula.names.includes(CRITICALITY_INPUT)
|
|
112
|
+
: true;
|
|
113
|
+
return readsCriticality && changesEquipment(object, original);
|
|
83
114
|
}
|
|
84
115
|
/**
|
|
85
116
|
* Sets the computed priority on a ticket being saved, under `config` — the
|
|
86
117
|
* form config that applies to the user saving (see `applicableFormConfig`).
|
|
87
118
|
*
|
|
88
119
|
* Only when this save changes one of the inputs — a ticket the save does not
|
|
89
|
-
* reassess keeps its priority, also when the formula has changed since
|
|
90
|
-
* only when the caller does not set the priority
|
|
91
|
-
* import keeps the priority its file states.
|
|
120
|
+
* reassess keeps its priority, also when the formula has changed since, or the
|
|
121
|
+
* class of its equipment — and only when the caller does not set the priority
|
|
122
|
+
* itself in the same save: an import keeps the priority its file states.
|
|
92
123
|
*
|
|
93
124
|
* "Changes" and "sets" are judged against `original`. The admin table sends
|
|
94
125
|
* every field of its form, the unchanged priority included; counting that as
|
|
95
126
|
* set by hand would leave the old priority after every factor edit there —
|
|
96
127
|
* which is the case this exists for.
|
|
97
128
|
*/
|
|
98
|
-
function applyComputedPriority(object, original, config) {
|
|
99
|
-
if (!changesPriorityInputs(object, original))
|
|
100
|
-
return;
|
|
101
|
-
if (changes(object, original, "priority"))
|
|
102
|
-
return;
|
|
129
|
+
async function applyComputedPriority(object, original, config) {
|
|
103
130
|
const formula = priorityFormulaOf(config);
|
|
104
131
|
if (!formula)
|
|
105
132
|
return;
|
|
106
|
-
|
|
133
|
+
if (!changesPriorityInputs(object, original, formula))
|
|
134
|
+
return;
|
|
135
|
+
if (changes(object, original, "priority"))
|
|
136
|
+
return;
|
|
137
|
+
const criticality = formula.names.includes(CRITICALITY_INPUT)
|
|
138
|
+
? (0, criticality_js_1.criticalityValue)(await (0, criticality_js_1.effectiveCriticality)(object.get("equipment")))
|
|
139
|
+
: undefined;
|
|
140
|
+
const priority = computePriority(formula, (key) => key === CRITICALITY_INPUT ? criticality : object.get(key));
|
|
107
141
|
if (priority !== undefined)
|
|
108
142
|
object.set("priority", priority);
|
|
109
143
|
}
|
|
@@ -227,7 +227,7 @@ async function applyFormConfigRules(object, original, user, { master, sessionTok
|
|
|
227
227
|
master,
|
|
228
228
|
sessionToken,
|
|
229
229
|
})) ?? (await (0, ticketFormConfig_js_1.applicableFormConfig)(tenant, user));
|
|
230
|
-
(0, ticketPriority_js_1.applyComputedPriority)(object, original, config);
|
|
230
|
+
await (0, ticketPriority_js_1.applyComputedPriority)(object, original, config);
|
|
231
231
|
if (!runRules || !config)
|
|
232
232
|
return;
|
|
233
233
|
applyValueRules(parseJson(config.fields), object, original, new Date());
|
|
@@ -189,8 +189,17 @@ exports.INDEXES = [
|
|
|
189
189
|
// Work orders of an order plan (MES order view).
|
|
190
190
|
od_orderPlan: ["orderPlan"],
|
|
191
191
|
}),
|
|
192
|
+
// Reasons of a tenant, and the unique-key check of their hook.
|
|
193
|
+
defineIndexes(index_js_1.BDE_DisruptionReason, {
|
|
194
|
+
od_tenant_key: ["tenant", "key"],
|
|
195
|
+
}),
|
|
192
196
|
defineIndexes(index_js_1.BDE_Article, {
|
|
193
197
|
od_articleNumber: ["articleNumber"],
|
|
198
|
+
// Spare parts of an equipment subtree (`equipment` contained in the ids):
|
|
199
|
+
// the material picker and the equipment page.
|
|
200
|
+
od_equipment: ["equipment"],
|
|
201
|
+
// "Meldebestand erreicht": the article list filters on it.
|
|
202
|
+
od_stockAlert: ["stockAlert"],
|
|
194
203
|
}),
|
|
195
204
|
// --- MES ---
|
|
196
205
|
// A cron job reads the last day's orders every minute.
|
|
@@ -6,18 +6,16 @@
|
|
|
6
6
|
* alarm's data and the settings somebody filled into the action's form — above
|
|
7
7
|
* all the maintenance template to use.
|
|
8
8
|
*
|
|
9
|
-
* **Authentication** —
|
|
9
|
+
* **Authentication and payload** — see `readAlarmCall`:
|
|
10
10
|
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* - **open.WARE** posts `{ alarm }` through the action's `OD3_AlarmWebhook`
|
|
12
|
+
* row (`ensureOpenwareWebhook`) with the webhook token; the tenant is the
|
|
13
|
+
* alarm owner's.
|
|
14
|
+
* - Called directly: `{ event, params?, secret?, tenantId? }` with the master
|
|
15
|
+
* key and a `tenantId`, or a tenant's shared secret.
|
|
16
16
|
*
|
|
17
|
-
* A logged-in user is deliberately *not* enough: this is a machine endpoint
|
|
18
|
-
* and a browser session should not be able to fabricate maintenance plans.
|
|
17
|
+
* A logged-in user is deliberately *not* enough: this is a machine endpoint.
|
|
19
18
|
*
|
|
20
|
-
* Params: `{ event, params?, secret?, tenantId? }`.
|
|
21
19
|
* Returns `{ scheduleId, created, origin, due, equipmentId?, templateId? }` —
|
|
22
20
|
* `created: false` means an unperformed appointment for this alarm already
|
|
23
21
|
* existed (see `createAlarmSchedule`).
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const index_js_1 = require("../features/openservice/alarms/index.js");
|
|
9
|
-
const index_js_2 = require("../types/index.js");
|
|
10
9
|
/**
|
|
11
10
|
* Schedule a one-off maintenance appointment for a fired alarm.
|
|
12
11
|
*
|
|
@@ -15,49 +14,30 @@ const index_js_2 = require("../types/index.js");
|
|
|
15
14
|
* alarm's data and the settings somebody filled into the action's form — above
|
|
16
15
|
* all the maintenance template to use.
|
|
17
16
|
*
|
|
18
|
-
* **Authentication** —
|
|
17
|
+
* **Authentication and payload** — see `readAlarmCall`:
|
|
19
18
|
*
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* - **open.WARE** posts `{ alarm }` through the action's `OD3_AlarmWebhook`
|
|
20
|
+
* row (`ensureOpenwareWebhook`) with the webhook token; the tenant is the
|
|
21
|
+
* alarm owner's.
|
|
22
|
+
* - Called directly: `{ event, params?, secret?, tenantId? }` with the master
|
|
23
|
+
* key and a `tenantId`, or a tenant's shared secret.
|
|
25
24
|
*
|
|
26
|
-
* A logged-in user is deliberately *not* enough: this is a machine endpoint
|
|
27
|
-
* and a browser session should not be able to fabricate maintenance plans.
|
|
25
|
+
* A logged-in user is deliberately *not* enough: this is a machine endpoint.
|
|
28
26
|
*
|
|
29
|
-
* Params: `{ event, params?, secret?, tenantId? }`.
|
|
30
27
|
* Returns `{ scheduleId, created, origin, due, equipmentId?, templateId? }` —
|
|
31
28
|
* `created: false` means an unperformed appointment for this alarm already
|
|
32
29
|
* existed (see `createAlarmSchedule`).
|
|
33
30
|
*/
|
|
34
31
|
async function init(name) {
|
|
35
32
|
node_1.default.Cloud.define(name, async (request) => {
|
|
36
|
-
const { event, params
|
|
37
|
-
|
|
38
|
-
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name} needs an "event" object describing the alarm`);
|
|
39
|
-
}
|
|
40
|
-
const tenant = request.master
|
|
41
|
-
? await tenantById(tenantId)
|
|
42
|
-
: await (0, index_js_1.tenantForAlarmSchedule)(typeof secret === "string" ? secret : "");
|
|
43
|
-
if (!tenant) {
|
|
44
|
-
// Same answer for "wrong secret" and "no such tenant": a caller
|
|
45
|
-
// guessing secrets learns nothing from the difference.
|
|
46
|
-
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `${name}: unknown tenant or invalid secret`);
|
|
47
|
-
}
|
|
48
|
-
const result = await (0, index_js_1.createAlarmSchedule)(tenant, event, params ?? {});
|
|
33
|
+
const { tenant, event, params } = await (0, index_js_1.readAlarmCall)(name, request, index_js_1.tenantForAlarmSchedule);
|
|
34
|
+
const result = await (0, index_js_1.createAlarmSchedule)(tenant, event, params);
|
|
49
35
|
console.log(`[${name}] ${result.created ? "created" : "reused"} schedule ` +
|
|
50
36
|
`${result.scheduleId} for ${result.origin}, due ${result.due}` +
|
|
51
37
|
(result.equipmentId ? ` (machine ${result.equipmentId})` : ""));
|
|
52
38
|
return result;
|
|
53
39
|
},
|
|
54
|
-
// No `requireUser`: the callers are machines, authenticated
|
|
40
|
+
// No `requireUser`: the callers are machines, authenticated in
|
|
41
|
+
// `readAlarmCall`.
|
|
55
42
|
{});
|
|
56
43
|
}
|
|
57
|
-
async function tenantById(tenantId) {
|
|
58
|
-
if (!tenantId)
|
|
59
|
-
return undefined;
|
|
60
|
-
return ((await new node_1.default.Query(index_js_2.Tenant)
|
|
61
|
-
.equalTo("objectId", tenantId)
|
|
62
|
-
.first({ useMasterKey: true })) ?? undefined);
|
|
63
|
-
}
|
|
@@ -6,18 +6,16 @@
|
|
|
6
6
|
* this with the alarm's data and the settings someone filled into the action's
|
|
7
7
|
* form.
|
|
8
8
|
*
|
|
9
|
-
* **Authentication** —
|
|
9
|
+
* **Authentication and payload** — see `readAlarmCall`:
|
|
10
10
|
*
|
|
11
|
-
* -
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
11
|
+
* - **open.WARE** posts `{ alarm }` through the action's `OD3_AlarmWebhook`
|
|
12
|
+
* row (`ensureOpenwareWebhook`) with the webhook token; the tenant is the
|
|
13
|
+
* alarm owner's.
|
|
14
|
+
* - Called directly: `{ event, params?, secret?, tenantId? }` with the master
|
|
15
|
+
* key and a `tenantId`, or a tenant's shared secret.
|
|
16
16
|
*
|
|
17
|
-
* A logged-in user is deliberately *not* enough: this is a machine endpoint
|
|
18
|
-
* and a browser session should not be able to fabricate alarm tickets.
|
|
17
|
+
* A logged-in user is deliberately *not* enough: this is a machine endpoint.
|
|
19
18
|
*
|
|
20
|
-
* Params: `{ event, params?, secret?, tenantId? }`.
|
|
21
19
|
* Returns `{ ticketId, created, origin, equipmentId? }` — `created: false`
|
|
22
20
|
* means an open ticket for this alarm already existed (see
|
|
23
21
|
* `createAlarmTicket`).
|
|
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const index_js_1 = require("../features/openservice/alarms/index.js");
|
|
9
|
-
const index_js_2 = require("../types/index.js");
|
|
10
9
|
/**
|
|
11
10
|
* Raise an open.SERVICE ticket for a fired alarm.
|
|
12
11
|
*
|
|
@@ -15,49 +14,30 @@ const index_js_2 = require("../types/index.js");
|
|
|
15
14
|
* this with the alarm's data and the settings someone filled into the action's
|
|
16
15
|
* form.
|
|
17
16
|
*
|
|
18
|
-
* **Authentication** —
|
|
17
|
+
* **Authentication and payload** — see `readAlarmCall`:
|
|
19
18
|
*
|
|
20
|
-
* -
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
19
|
+
* - **open.WARE** posts `{ alarm }` through the action's `OD3_AlarmWebhook`
|
|
20
|
+
* row (`ensureOpenwareWebhook`) with the webhook token; the tenant is the
|
|
21
|
+
* alarm owner's.
|
|
22
|
+
* - Called directly: `{ event, params?, secret?, tenantId? }` with the master
|
|
23
|
+
* key and a `tenantId`, or a tenant's shared secret.
|
|
25
24
|
*
|
|
26
|
-
* A logged-in user is deliberately *not* enough: this is a machine endpoint
|
|
27
|
-
* and a browser session should not be able to fabricate alarm tickets.
|
|
25
|
+
* A logged-in user is deliberately *not* enough: this is a machine endpoint.
|
|
28
26
|
*
|
|
29
|
-
* Params: `{ event, params?, secret?, tenantId? }`.
|
|
30
27
|
* Returns `{ ticketId, created, origin, equipmentId? }` — `created: false`
|
|
31
28
|
* means an open ticket for this alarm already existed (see
|
|
32
29
|
* `createAlarmTicket`).
|
|
33
30
|
*/
|
|
34
31
|
async function init(name) {
|
|
35
32
|
node_1.default.Cloud.define(name, async (request) => {
|
|
36
|
-
const { event, params
|
|
37
|
-
|
|
38
|
-
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name} needs an "event" object describing the alarm`);
|
|
39
|
-
}
|
|
40
|
-
const tenant = request.master
|
|
41
|
-
? await tenantById(tenantId)
|
|
42
|
-
: await (0, index_js_1.tenantForAlarmTicket)(typeof secret === "string" ? secret : "");
|
|
43
|
-
if (!tenant) {
|
|
44
|
-
// Same answer for "wrong secret" and "no such tenant": a caller
|
|
45
|
-
// guessing secrets learns nothing from the difference.
|
|
46
|
-
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `${name}: unknown tenant or invalid secret`);
|
|
47
|
-
}
|
|
48
|
-
const result = await (0, index_js_1.createAlarmTicket)(tenant, event, params ?? {});
|
|
33
|
+
const { tenant, event, params } = await (0, index_js_1.readAlarmCall)(name, request, index_js_1.tenantForAlarmTicket);
|
|
34
|
+
const result = await (0, index_js_1.createAlarmTicket)(tenant, event, params);
|
|
49
35
|
console.log(`[${name}] ${result.created ? "created" : "reused"} ticket ` +
|
|
50
36
|
`${result.ticketId} for ${result.origin}` +
|
|
51
37
|
(result.equipmentId ? ` (machine ${result.equipmentId})` : ""));
|
|
52
38
|
return result;
|
|
53
39
|
},
|
|
54
|
-
// No `requireUser`: the callers are machines, authenticated
|
|
40
|
+
// No `requireUser`: the callers are machines, authenticated in
|
|
41
|
+
// `readAlarmCall`.
|
|
55
42
|
{});
|
|
56
43
|
}
|
|
57
|
-
async function tenantById(tenantId) {
|
|
58
|
-
if (!tenantId)
|
|
59
|
-
return undefined;
|
|
60
|
-
return ((await new node_1.default.Query(index_js_2.Tenant)
|
|
61
|
-
.equalTo("objectId", tenantId)
|
|
62
|
-
.first({ useMasterKey: true })) ?? undefined);
|
|
63
|
-
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.init = init;
|
|
4
4
|
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
+
const articleEquipment_js_1 = require("../features/openservice/articles/articleEquipment.js");
|
|
6
|
+
const articleStock_js_1 = require("../features/openservice/articles/articleStock.js");
|
|
5
7
|
const index_js_2 = require("../types/index.js");
|
|
6
8
|
async function init() {
|
|
7
9
|
// Soft delete: articles are referenced from a ticket's `material` list and
|
|
@@ -35,7 +37,9 @@ async function init() {
|
|
|
35
37
|
allowCustomACL: true,
|
|
36
38
|
allowTenantUserWrite: true,
|
|
37
39
|
});
|
|
38
|
-
//
|
|
40
|
+
// After `defaultHandler`, which settles the tenant the check compares with.
|
|
41
|
+
await (0, articleEquipment_js_1.assertArticleEquipment)(object);
|
|
42
|
+
(0, articleStock_js_1.applyStockAlert)(object);
|
|
39
43
|
});
|
|
40
44
|
(0, index_js_1.afterSaveHook)(index_js_2.BDE_Article, async (request) => {
|
|
41
45
|
const { object, original, user } = request;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function init(): Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
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/schema/index.js");
|
|
9
|
+
const index_js_2 = require("../types/index.js");
|
|
10
|
+
/** Longest key accepted — it is stored on every disruption booking. */
|
|
11
|
+
const MAX_KEY_LENGTH = 64;
|
|
12
|
+
async function init() {
|
|
13
|
+
// The reasons a BDE disruption is reported with. A reported disruption
|
|
14
|
+
// stores the reason's `key` in `OD3_BDE_WorkTime.comment`, and instances map
|
|
15
|
+
// it on — Künne sends `externalCode` to ABAS as `sgrund`. So the key is
|
|
16
|
+
// fixed once saved, unique per tenant, and a reason in use is deactivated
|
|
17
|
+
// (`active: false`) rather than deleted.
|
|
18
|
+
//
|
|
19
|
+
// Read by every user of the tenant (the disruption dialog offers them),
|
|
20
|
+
// written by the creator and tenant admins; further editors are granted in
|
|
21
|
+
// the BDE admin's permission dialog, so a custom ACL is kept.
|
|
22
|
+
(0, index_js_1.beforeSaveHook)(index_js_2.BDE_DisruptionReason, async (request) => {
|
|
23
|
+
const { object, original, master } = request;
|
|
24
|
+
await (0, index_js_1.defaultHandler)(request);
|
|
25
|
+
await (0, index_js_1.defaultAclHandler)(request, { allowCustomACL: true });
|
|
26
|
+
const key = String(object.get("key") ?? "").trim();
|
|
27
|
+
if (!key || key.length > MAX_KEY_LENGTH || /\s/.test(key)) {
|
|
28
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `A disruption reason needs a key of 1–${MAX_KEY_LENGTH} characters ` +
|
|
29
|
+
`without spaces.`);
|
|
30
|
+
}
|
|
31
|
+
if (original && original.get("key") !== key && !master) {
|
|
32
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "The key of a disruption reason cannot be changed: bookings store it.");
|
|
33
|
+
}
|
|
34
|
+
object.set("key", key);
|
|
35
|
+
const label = String(object.get("label") ?? "").trim();
|
|
36
|
+
if (!label) {
|
|
37
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "A disruption reason needs a label.");
|
|
38
|
+
}
|
|
39
|
+
object.set("label", label);
|
|
40
|
+
if (!object.isNew() && !object.dirty("key"))
|
|
41
|
+
return;
|
|
42
|
+
const duplicate = new node_1.default.Query(index_js_2.BDE_DisruptionReason).equalTo("key", key);
|
|
43
|
+
const tenant = object.get("tenant");
|
|
44
|
+
if (tenant)
|
|
45
|
+
duplicate.equalTo("tenant", tenant);
|
|
46
|
+
else
|
|
47
|
+
duplicate.doesNotExist("tenant");
|
|
48
|
+
if (object.id)
|
|
49
|
+
duplicate.notEqualTo("objectId", object.id);
|
|
50
|
+
if (await duplicate.first({ useMasterKey: true })) {
|
|
51
|
+
throw new node_1.default.Error(node_1.default.Error.DUPLICATE_VALUE, `There is already a disruption reason with the key "${key}".`);
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
(0, index_js_1.beforeDeleteHook)(index_js_2.BDE_DisruptionReason, async (request) => {
|
|
55
|
+
const { object } = request;
|
|
56
|
+
const key = object.get("key");
|
|
57
|
+
if (!key)
|
|
58
|
+
return;
|
|
59
|
+
const inUse = new node_1.default.Query(index_js_2.BDE_WorkTime)
|
|
60
|
+
.equalTo("status", "disrupted")
|
|
61
|
+
.equalTo("comment", key);
|
|
62
|
+
const tenant = object.get("tenant");
|
|
63
|
+
if (tenant)
|
|
64
|
+
inUse.equalTo("tenant", tenant);
|
|
65
|
+
if (await inUse.first({ useMasterKey: true })) {
|
|
66
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, `The disruption reason "${key}" is used by bookings — deactivate it ` +
|
|
67
|
+
`instead of deleting it.`);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -7,6 +7,7 @@ exports.init = init;
|
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
8
|
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
9
9
|
const index_js_1 = require("../features/schema/index.js");
|
|
10
|
+
const criticality_js_1 = require("../features/openservice/equipment/criticality.js");
|
|
10
11
|
const index_js_2 = require("../features/permissions/index.js");
|
|
11
12
|
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
12
13
|
const ticketSortKeys_js_1 = require("../helper/ticketSortKeys.js");
|
|
@@ -37,6 +38,8 @@ async function init() {
|
|
|
37
38
|
Boolean(object.get("deleted")) !== Boolean(original.get("deleted"))) {
|
|
38
39
|
await (0, index_js_2.requirePermission)(request, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "archive equipment");
|
|
39
40
|
}
|
|
41
|
+
// A, B, C or unset (inherits from the parent) — see `criticality.ts`.
|
|
42
|
+
(0, criticality_js_1.normalizeCriticality)(object);
|
|
40
43
|
await (0, index_js_1.defaultHandler)(request);
|
|
41
44
|
await (0, index_js_1.defaultAclHandler)(request);
|
|
42
45
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
7
|
+
const articleStock_js_1 = require("../features/openservice/articles/articleStock.js");
|
|
8
|
+
const index_js_1 = require("../types/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* One-off backfill for `OD3_BDE_Article.stockAlert`.
|
|
11
|
+
*
|
|
12
|
+
* From here on the article hook keeps the flag in step with `stock` and
|
|
13
|
+
* `minimumStock`, but it only sees writes — an article saved before the flag
|
|
14
|
+
* existed is missing from the "Meldebestand erreicht" filter until someone
|
|
15
|
+
* touches it. This sets the flag where it is wrong or missing.
|
|
16
|
+
*
|
|
17
|
+
* PARSE_URL=… PARSE_APP_ID=… PARSE_MASTER_KEY=… \
|
|
18
|
+
* node dist/scripts/backfill-stock-alert.js [--dry-run]
|
|
19
|
+
*
|
|
20
|
+
* Reads every article, but writes only the ones whose flag differs. The re-save
|
|
21
|
+
* writes no changelog entry (`skipChangelog`) — the flag is derived, not an
|
|
22
|
+
* edit. Safe to re-run.
|
|
23
|
+
*/
|
|
24
|
+
const BATCH_SIZE = 500;
|
|
25
|
+
function requireEnv(name) {
|
|
26
|
+
const value = process.env[name];
|
|
27
|
+
if (!value) {
|
|
28
|
+
console.error(`Missing required environment variable ${name}.`);
|
|
29
|
+
process.exit(1);
|
|
30
|
+
}
|
|
31
|
+
return value;
|
|
32
|
+
}
|
|
33
|
+
/** Iterate the articles in `createdAt` order, page by page. */
|
|
34
|
+
async function* pages() {
|
|
35
|
+
let after;
|
|
36
|
+
for (;;) {
|
|
37
|
+
const query = new node_1.default.Query(index_js_1.BDE_Article)
|
|
38
|
+
.select("stock", "minimumStock", "stockAlert")
|
|
39
|
+
.ascending("createdAt")
|
|
40
|
+
.limit(BATCH_SIZE);
|
|
41
|
+
// `createdAt` is not part of the generic attribute map, hence the cast.
|
|
42
|
+
if (after)
|
|
43
|
+
query.greaterThan("createdAt", after);
|
|
44
|
+
// Archived articles too, so un-archiving brings back a right flag. A query
|
|
45
|
+
// that constrains `isDeleted` gets past `hideSoftDeleted`.
|
|
46
|
+
query.containedIn("isDeleted", [true, false]);
|
|
47
|
+
const results = await query.find({ useMasterKey: true });
|
|
48
|
+
if (results.length === 0)
|
|
49
|
+
return;
|
|
50
|
+
yield results;
|
|
51
|
+
after = results[results.length - 1].createdAt;
|
|
52
|
+
if (results.length < BATCH_SIZE)
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function main() {
|
|
57
|
+
const dryRun = process.argv.includes("--dry-run");
|
|
58
|
+
node_1.default.initialize(requireEnv("PARSE_APP_ID"), undefined, requireEnv("PARSE_MASTER_KEY"));
|
|
59
|
+
node_1.default.serverURL =
|
|
60
|
+
process.env.PARSE_URL ?? "http://localhost:1337/parse";
|
|
61
|
+
let scanned = 0;
|
|
62
|
+
let changed = 0;
|
|
63
|
+
let alerts = 0;
|
|
64
|
+
for await (const page of pages()) {
|
|
65
|
+
for (const article of page) {
|
|
66
|
+
scanned++;
|
|
67
|
+
const expected = (0, articleStock_js_1.stockAlertOf)(article.get("stock"), article.get("minimumStock"));
|
|
68
|
+
if (expected)
|
|
69
|
+
alerts++;
|
|
70
|
+
if (article.get("stockAlert") === expected)
|
|
71
|
+
continue;
|
|
72
|
+
changed++;
|
|
73
|
+
if (dryRun)
|
|
74
|
+
continue;
|
|
75
|
+
article.set("stockAlert", expected);
|
|
76
|
+
await article.save(null, {
|
|
77
|
+
useMasterKey: true,
|
|
78
|
+
context: { skipChangelog: true },
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
console.log(`${dryRun ? "[dry run] " : ""}scanned ${scanned} articles, ` +
|
|
83
|
+
`${changed} flag(s) ${dryRun ? "to set" : "set"}, ` +
|
|
84
|
+
`${alerts} at or below the reorder point`);
|
|
85
|
+
}
|
|
86
|
+
main().catch((error) => {
|
|
87
|
+
console.error(error);
|
|
88
|
+
process.exit(1);
|
|
89
|
+
});
|
|
@@ -14,8 +14,12 @@ import type { MigrationConfig } from "./env.js";
|
|
|
14
14
|
* Pass 05 therefore writes those to the columns now, and only what still has no
|
|
15
15
|
* home stays here: v1's `category` — deliberately never given a column, since
|
|
16
16
|
* tags and `type` already classify and a third such field goes stale — v1's
|
|
17
|
-
* `description` (the label column is taken by v1's `name`)
|
|
18
|
-
*
|
|
17
|
+
* `description` (the label column is taken by v1's `name`).
|
|
18
|
+
*
|
|
19
|
+
* **Equipment moved to a column on 2026-11-17.** The links behind
|
|
20
|
+
* `Item.sources` became `OD3_BDE_Article.equipment`, which the material picker
|
|
21
|
+
* and the equipment page read. Pass 05 writes them there and strips the old
|
|
22
|
+
* meta key.
|
|
19
23
|
*
|
|
20
24
|
* ⚠️ The ABAS sync still owns the columns it writes and replaces them on every
|
|
21
25
|
* run. It does not touch the stock-keeping ones today — if that changes, they
|
|
@@ -42,7 +46,7 @@ export declare const ARTICLE_META_CONTEXT: string[];
|
|
|
42
46
|
* once in the article form, once under *Kopfdaten*. Listed here rather than in
|
|
43
47
|
* the pass because it is a statement about this context's history.
|
|
44
48
|
*/
|
|
45
|
-
export declare const META_KEYS_NOW_COLUMNS: readonly ["price", "stock", "stockAlarmAt", "stockUnit", "storageLocation", "supplier", "orderNumber"];
|
|
49
|
+
export declare const META_KEYS_NOW_COLUMNS: readonly ["price", "stock", "stockAlarmAt", "stockUnit", "storageLocation", "supplier", "orderNumber", "equipment"];
|
|
46
50
|
/**
|
|
47
51
|
* The field definitions written to the shared `Meta_Config`.
|
|
48
52
|
*
|