@openinc/parse-server-opendash 4.4.6 → 4.6.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 +6 -7
- package/dist/features/config/index.d.ts +4 -1
- package/dist/features/config/index.js +6 -1
- package/dist/features/config/services/ensureConfigs.d.ts +29 -0
- package/dist/features/config/services/ensureConfigs.js +133 -0
- package/dist/features/config/types/ConfigKeys.d.ts +87 -7
- package/dist/features/config/types/ConfigKeys.js +112 -11
- package/dist/features/openservice/alarms/actionParams.d.ts +29 -0
- package/dist/features/openservice/alarms/actionParams.js +63 -0
- package/dist/features/openservice/alarms/index.d.ts +1 -1
- package/dist/features/openservice/alarms/index.js +2 -1
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.d.ts +1 -1
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +23 -1
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.d.ts +17 -0
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +83 -1
- package/dist/features/openservice/alarms/schedule/listAlarmTriggers.js +44 -22
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.d.ts +1 -1
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +10 -1
- package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.js +18 -1
- package/dist/features/openservice/init.js +8 -3
- package/dist/features/openservice/serviceProviders/ProviderAccessTypes.d.ts +23 -0
- package/dist/features/openservice/serviceProviders/ProviderAccessTypes.js +17 -0
- package/dist/features/openservice/serviceProviders/grantProviderAccess.d.ts +35 -0
- package/dist/features/openservice/serviceProviders/grantProviderAccess.js +172 -0
- package/dist/features/openservice/serviceProviders/index.d.ts +5 -0
- package/dist/features/openservice/serviceProviders/index.js +12 -0
- package/dist/features/openservice/serviceProviders/providerRoleSetup.d.ts +63 -0
- package/dist/features/openservice/serviceProviders/providerRoleSetup.js +110 -0
- package/dist/features/openservice/setupStatus.d.ts +55 -0
- package/dist/features/openservice/setupStatus.js +139 -0
- package/dist/features/permissions/types/Permissions.d.ts +1 -0
- package/dist/features/permissions/types/Permissions.js +5 -0
- package/dist/functions/openinc-auth-login-passwordless.js +7 -2
- package/dist/functions/openinc-auth-validate-token.js +6 -0
- package/dist/functions/openinc-auth.common.js +13 -0
- package/dist/functions/openinc-openservice-provider-access.d.ts +22 -0
- package/dist/functions/openinc-openservice-provider-access.js +54 -0
- package/dist/functions/openinc-openservice-provider-setup.d.ts +19 -0
- package/dist/functions/openinc-openservice-provider-setup.js +57 -0
- package/dist/functions/openinc-openservice-setup.d.ts +24 -0
- package/dist/functions/openinc-openservice-setup.js +140 -0
- package/dist/hooks/Config_open_service.js +34 -10
- package/dist/hooks/Service_Equipment.js +6 -11
- package/dist/hooks/Service_Schedule_Execution.js +136 -7
- package/dist/scripts/migration/lib/articleMeta.d.ts +20 -7
- package/dist/scripts/migration/lib/articleMeta.js +20 -14
- package/dist/scripts/migration/passes/05-articles.d.ts +17 -8
- package/dist/scripts/migration/passes/05-articles.js +43 -24
- package/dist/types/BDE_Article.d.ts +27 -3
- package/dist/types/BDE_Article.js +48 -0
- package/dist/types/Service_MigrationMap.d.ts +26 -0
- package/dist/types/Service_MigrationMap.js +45 -0
- package/dist/types/Service_Occurrence.d.ts +31 -0
- package/dist/types/Service_Occurrence.js +51 -0
- package/dist/types/Service_Schedule_Execution.d.ts +22 -3
- package/dist/types/Service_Schedule_Execution.js +36 -0
- package/dist/types/index.d.ts +4 -4
- package/dist/types/index.js +5 -5
- package/package.json +1 -1
- package/schema/BDE_Article.json +41 -6
- package/schema/Service_FormConfig.json +10 -10
- package/schema/{Service_TriggerState.json → Service_Occurrence.json} +21 -9
- package/schema/Service_Schedule_Execution.json +27 -1
- package/dist/hooks/Service_TriggerState.d.ts +0 -1
- package/dist/hooks/Service_TriggerState.js +0 -17
- package/dist/types/Service_MeterReading.d.ts +0 -35
- package/dist/types/Service_MeterReading.js +0 -57
- package/dist/types/Service_TriggerState.d.ts +0 -31
- package/dist/types/Service_TriggerState.js +0 -51
- package/schema/Service_MeterReading.json +0 -54
|
@@ -0,0 +1,140 @@
|
|
|
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 crypto_1 = require("crypto");
|
|
9
|
+
const index_js_1 = require("../types/index.js");
|
|
10
|
+
const index_js_2 = require("../features/config/index.js");
|
|
11
|
+
const setupStatus_js_1 = require("../features/openservice/setupStatus.js");
|
|
12
|
+
const index_js_3 = require("../features/permissions/index.js");
|
|
13
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
14
|
+
/**
|
|
15
|
+
* Inspect and complete the open.SERVICE setup of the caller's tenant.
|
|
16
|
+
*
|
|
17
|
+
* Actions:
|
|
18
|
+
* - `status` (default) — what is in place and what is not. Never returns a
|
|
19
|
+
* secret's value.
|
|
20
|
+
* - `reveal` — the value of one secret config row, so it can be pasted into
|
|
21
|
+
* the alarm executor. The one call that hands a credential out, which is why
|
|
22
|
+
* it is a separate action rather than a field on `status`: a page rendering
|
|
23
|
+
* the overview should not be carrying secrets it does not display.
|
|
24
|
+
* - `regenerate` — replace a secret with a fresh one. Invalidates the old one
|
|
25
|
+
* immediately, so every executor holding it stops working until it is
|
|
26
|
+
* updated. The caller is expected to have said so out loud first.
|
|
27
|
+
* - `set` — write a config row a human has to supply (the Outlook
|
|
28
|
+
* credentials). Refuses keys the catalogue marks as generated, because
|
|
29
|
+
* pasting a secret by hand defeats generating one.
|
|
30
|
+
*
|
|
31
|
+
* Gated on `masterdata_manage`: this is tenant administration, a step above
|
|
32
|
+
* working with plans and tickets.
|
|
33
|
+
*
|
|
34
|
+
* **The tenant comes from the session, never from a parameter** — otherwise
|
|
35
|
+
* reading a secret would become a way to read another customer's.
|
|
36
|
+
*/
|
|
37
|
+
async function init(name) {
|
|
38
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
39
|
+
const user = request.user;
|
|
40
|
+
if (!user) {
|
|
41
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_SESSION_TOKEN, `${name} requires a logged-in user`);
|
|
42
|
+
}
|
|
43
|
+
await (0, index_js_3.requirePermission)({
|
|
44
|
+
sessionToken: user.getSessionToken(),
|
|
45
|
+
master: request.master,
|
|
46
|
+
}, Permissions_js_1.Permissions.SERVICE.masterdata_manage, "inspect or change the open.SERVICE setup");
|
|
47
|
+
const tenant = user.get("tenant");
|
|
48
|
+
if (!tenant?.id) {
|
|
49
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: the calling user has no tenant`);
|
|
50
|
+
}
|
|
51
|
+
const { action, key, value } = request.params;
|
|
52
|
+
switch (action ?? "status") {
|
|
53
|
+
case "status":
|
|
54
|
+
return (0, setupStatus_js_1.openServiceSetupStatus)(tenant);
|
|
55
|
+
case "reveal":
|
|
56
|
+
return { key: requireKey(key), value: await reveal(tenant, key) };
|
|
57
|
+
case "regenerate":
|
|
58
|
+
return {
|
|
59
|
+
key: requireKey(key),
|
|
60
|
+
value: await regenerate(tenant, key),
|
|
61
|
+
};
|
|
62
|
+
case "set":
|
|
63
|
+
await setValue(tenant, requireKey(key), value ?? "");
|
|
64
|
+
return (0, setupStatus_js_1.openServiceSetupStatus)(tenant);
|
|
65
|
+
default:
|
|
66
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name}: unknown action "${action}"`);
|
|
67
|
+
}
|
|
68
|
+
}, { requireUser: true });
|
|
69
|
+
}
|
|
70
|
+
/** A key the catalogue knows. Anything else is refused rather than created. */
|
|
71
|
+
function requireKey(key) {
|
|
72
|
+
if (!key || !(0, index_js_2.configKeyDefinition)(key)) {
|
|
73
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `Not a known configuration key: ${key ?? "(none)"}`);
|
|
74
|
+
}
|
|
75
|
+
return key;
|
|
76
|
+
}
|
|
77
|
+
async function reveal(tenant, key) {
|
|
78
|
+
const definition = (0, index_js_2.configKeyDefinition)(key);
|
|
79
|
+
if (!definition.secret) {
|
|
80
|
+
// Non-secret values are readable through the ordinary config query; there
|
|
81
|
+
// is no reason for a privileged path to duplicate that.
|
|
82
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${key} is not a secret — read it through the config query.`);
|
|
83
|
+
}
|
|
84
|
+
const row = await findRow(tenant, key);
|
|
85
|
+
if (!row) {
|
|
86
|
+
throw new node_1.default.Error(node_1.default.Error.OBJECT_NOT_FOUND, `${key} does not exist for this tenant yet. It is created at server start.`);
|
|
87
|
+
}
|
|
88
|
+
return row.get("value") ?? "";
|
|
89
|
+
}
|
|
90
|
+
async function regenerate(tenant, key) {
|
|
91
|
+
const definition = (0, index_js_2.configKeyDefinition)(key);
|
|
92
|
+
if (definition.generate !== "secret") {
|
|
93
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${key} is not a generated secret.`);
|
|
94
|
+
}
|
|
95
|
+
const row = (await findRow(tenant, key)) ?? newRow(tenant, key);
|
|
96
|
+
const value = (0, crypto_1.randomBytes)(32).toString("hex");
|
|
97
|
+
row.set("value", value);
|
|
98
|
+
await row.save(null, { useMasterKey: true });
|
|
99
|
+
return value;
|
|
100
|
+
}
|
|
101
|
+
async function setValue(tenant, key, value) {
|
|
102
|
+
const definition = (0, index_js_2.configKeyDefinition)(key);
|
|
103
|
+
if (definition.generate === "secret") {
|
|
104
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${key} is generated — use "regenerate" rather than pasting a value.`);
|
|
105
|
+
}
|
|
106
|
+
if (definition.runtimeState) {
|
|
107
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${key} is runtime state and must not be set by hand.`);
|
|
108
|
+
}
|
|
109
|
+
const row = (await findRow(tenant, key)) ?? newRow(tenant, key);
|
|
110
|
+
row.set("value", value);
|
|
111
|
+
await row.save(null, { useMasterKey: true });
|
|
112
|
+
}
|
|
113
|
+
function findRow(tenant, key) {
|
|
114
|
+
return new node_1.default.Query(index_js_1.Config)
|
|
115
|
+
.equalTo("key", key)
|
|
116
|
+
.equalTo("tenant", tenant)
|
|
117
|
+
.first({ useMasterKey: true });
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* A new row, carrying the same restrictive ACL the bootstrap applies — a row
|
|
121
|
+
* created here must not be more readable than one created at boot.
|
|
122
|
+
*/
|
|
123
|
+
function newRow(tenant, key) {
|
|
124
|
+
const definition = (0, index_js_2.configKeyDefinition)(key);
|
|
125
|
+
const row = new index_js_1.Config();
|
|
126
|
+
row.set("key", key);
|
|
127
|
+
row.set("tenant", tenant);
|
|
128
|
+
row.set("priority", 0);
|
|
129
|
+
const acl = new node_1.default.ACL();
|
|
130
|
+
acl.setRoleReadAccess("od-admin", true);
|
|
131
|
+
acl.setRoleWriteAccess("od-admin", true);
|
|
132
|
+
acl.setRoleReadAccess(`od-tenant-admin-${tenant.id}`, true);
|
|
133
|
+
acl.setRoleWriteAccess(`od-tenant-admin-${tenant.id}`, true);
|
|
134
|
+
if (!definition.secret) {
|
|
135
|
+
acl.setRoleReadAccess(`od-tenant-user-${tenant.id}`, true);
|
|
136
|
+
acl.setRoleWriteAccess(`od-tenant-user-${tenant.id}`, true);
|
|
137
|
+
}
|
|
138
|
+
row.setACL(acl);
|
|
139
|
+
return row;
|
|
140
|
+
}
|
|
@@ -6,21 +6,30 @@ 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/schema/index.js");
|
|
9
|
+
const index_js_2 = require("../features/config/index.js");
|
|
9
10
|
const catchError_js_1 = require("../helper/catchError.js");
|
|
10
|
-
const
|
|
11
|
+
const index_js_3 = require("../types/index.js");
|
|
11
12
|
/**
|
|
12
13
|
* This handles all config changes for a key starting with 'OPENSERVICE_' in class OD3_Config
|
|
13
14
|
*/
|
|
14
15
|
async function init() {
|
|
15
|
-
(0, index_js_1.beforeSaveHook)(
|
|
16
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Config, async (request) => {
|
|
16
17
|
const { object, original, user } = request;
|
|
17
18
|
await (0, index_js_1.defaultHandler)(request);
|
|
18
|
-
//
|
|
19
|
-
//
|
|
20
|
-
//
|
|
19
|
+
// The ACL of every `OPENSERVICE_*` row, rebuilt on each save so a row can
|
|
20
|
+
// never keep a grant it should not have.
|
|
21
|
+
//
|
|
22
|
+
// Ordinary tenant members read and write the settings — the ticket admin
|
|
23
|
+
// edits the notification rules from the browser. **Except a secret.** A
|
|
24
|
+
// shared secret readable by every member is a secret every member can use
|
|
25
|
+
// to call the alarm endpoints as that tenant, which is the whole
|
|
26
|
+
// authorisation of those endpoints. The catalogue says which keys those
|
|
27
|
+
// are; anything it does not know keeps the permissive default, because an
|
|
28
|
+
// unknown key is a settings row somebody added for the frontend to read.
|
|
21
29
|
if (object.get("key").startsWith("OPENSERVICE_")) {
|
|
22
30
|
let acl = object.getACL();
|
|
23
31
|
const tenant = object.get("tenant");
|
|
32
|
+
const isSecret = !!(0, index_js_2.configKeyDefinition)(object.get("key"))?.secret;
|
|
24
33
|
if (!acl) {
|
|
25
34
|
acl = new node_1.default.ACL();
|
|
26
35
|
}
|
|
@@ -31,23 +40,38 @@ async function init() {
|
|
|
31
40
|
acl.setPublicWriteAccess(false);
|
|
32
41
|
acl.setRoleReadAccess(`od-tenant-admin-${tenant?.id}`, true);
|
|
33
42
|
acl.setRoleWriteAccess(`od-tenant-admin-${tenant?.id}`, true);
|
|
34
|
-
|
|
35
|
-
|
|
43
|
+
// Set explicitly either way: a secret row written before this existed
|
|
44
|
+
// carries the grant, and only revoking it actively takes it back.
|
|
45
|
+
acl.setRoleReadAccess(`od-tenant-user-${tenant?.id}`, !isSecret);
|
|
46
|
+
acl.setRoleWriteAccess(`od-tenant-user-${tenant?.id}`, !isSecret);
|
|
36
47
|
}
|
|
37
48
|
object.setACL(acl);
|
|
38
49
|
}
|
|
39
50
|
});
|
|
40
|
-
(0, index_js_1.afterSaveHook)(
|
|
51
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Config, async ({ object, original, user }) => {
|
|
41
52
|
if (object.get("key").startsWith("OPENSERVICE_")) {
|
|
42
53
|
console.log("Config changed: ", object.get("key"));
|
|
43
54
|
console.log("Check Meta Fields in Maintenance_Schedule_Step...");
|
|
44
55
|
//Get all Entries in OD3_Maintenance_Step and remove all entries in field "fields" (type: array) that are not in the config
|
|
45
56
|
//object.value can look like this: [{"label":"PSA","allowedValues":[],"required":false},{"label":"Typ","allowedValues":[],"required":false,"onlyOneAllowedValue":false},{"label":"Material","allowedValues":["@OD3_Maintenance_Item"],"required":false,"onlyOneAllowedValue":false},{"label":"Dienstleister","allowedValues":["@OD3_COMPANY","@OD3_CONTACT"],"required":false,"onlyOneAllowedValue":false}]
|
|
46
57
|
//fields in Maintenance_Step can look like this: [{"value":"Handschuhe","metafield":{"label":"PSA","allowedValues":[],"required":false}},{"value":"Auffüllen","metafield":{"label":"Typ","allowedValues":[],"required":false,"onlyOneAllowedValue":false}}]
|
|
47
|
-
|
|
58
|
+
// Only this one key carries the meta-field list. It used to run for
|
|
59
|
+
// every `OPENSERVICE_*` key and parse the value blindly — which throws
|
|
60
|
+
// on anything that is not JSON, and a generated hex secret is not JSON.
|
|
61
|
+
if (object.get("key") !== index_js_2.ConfigKeys.OpenService.scheduleMetaFields) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
let metafieldsconfig;
|
|
65
|
+
try {
|
|
66
|
+
metafieldsconfig = JSON.parse(object.get("value"));
|
|
67
|
+
}
|
|
68
|
+
catch {
|
|
69
|
+
console.warn(`[Config] ${object.get("key")} does not hold JSON — skipping the meta field sync`);
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
48
72
|
if (!Array.isArray(metafieldsconfig))
|
|
49
73
|
return;
|
|
50
|
-
const [maintenanceStepQueryError, maintenanceStepQuery] = await (0, catchError_js_1.catchError)(new node_1.default.Query(
|
|
74
|
+
const [maintenanceStepQueryError, maintenanceStepQuery] = await (0, catchError_js_1.catchError)(new node_1.default.Query(index_js_3.Maintenance_Schedule_Step).find({
|
|
51
75
|
useMasterKey: true,
|
|
52
76
|
}));
|
|
53
77
|
if (maintenanceStepQueryError) {
|
|
@@ -26,17 +26,12 @@ async function init() {
|
|
|
26
26
|
// active tickets, and meter readings (whose `equipment` pointer is required,
|
|
27
27
|
// so orphaning it would break them).
|
|
28
28
|
(0, index_js_1.beforeDeleteHook)(index_js_2.Service_Equipment, async ({ object }) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
new node_1.default.
|
|
35
|
-
.equalTo("equipment", object)
|
|
36
|
-
.count({ useMasterKey: true }),
|
|
37
|
-
]);
|
|
38
|
-
if (tickets > 0 || readings > 0) {
|
|
39
|
-
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `Cannot delete equipment: referenced by ${tickets} active ticket(s) and ${readings} meter reading(s).`);
|
|
29
|
+
const tickets = await new node_1.default.Query(index_js_2.Service_Ticket)
|
|
30
|
+
.equalTo("equipment", object)
|
|
31
|
+
.notEqualTo("deleted", true)
|
|
32
|
+
.count({ useMasterKey: true });
|
|
33
|
+
if (tickets > 0) {
|
|
34
|
+
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `Cannot delete equipment: referenced by ${tickets} active ticket(s).`);
|
|
40
35
|
}
|
|
41
36
|
});
|
|
42
37
|
}
|
|
@@ -1,17 +1,146 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
6
|
exports.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
4
8
|
const index_js_1 = require("../features/schema/index.js");
|
|
5
|
-
const index_js_2 = require("../
|
|
9
|
+
const index_js_2 = require("../features/permissions/index.js");
|
|
10
|
+
const Permissions_js_1 = require("../features/permissions/types/Permissions.js");
|
|
11
|
+
const index_js_3 = require("../types/index.js");
|
|
12
|
+
/**
|
|
13
|
+
* Fields a completed execution may still change.
|
|
14
|
+
*
|
|
15
|
+
* A protocol is evidence: once signed off, what was done, by whom and with
|
|
16
|
+
* which results must not move.
|
|
17
|
+
*
|
|
18
|
+
* `coverageOrigin` is listed as a concession, not because anything writes it
|
|
19
|
+
* today — the sign-off sets it when it *creates* a coverage record, never on an
|
|
20
|
+
* existing one. It is here so that recording "a later maintenance covered this"
|
|
21
|
+
* stays possible without reopening the protocol, which is the one addition that
|
|
22
|
+
* does not contradict what was performed.
|
|
23
|
+
*/
|
|
24
|
+
const EDITABLE_AFTER_COMPLETION = new Set(["coverageOrigin", "updatedAt"]);
|
|
6
25
|
async function init() {
|
|
7
|
-
(0, index_js_1.beforeSaveHook)(
|
|
26
|
+
(0, index_js_1.beforeSaveHook)(index_js_3.Service_Schedule_Execution, async (request) => {
|
|
8
27
|
const { object, original, user } = request;
|
|
9
28
|
await (0, index_js_1.defaultHandler)(request);
|
|
10
|
-
|
|
11
|
-
//
|
|
29
|
+
// Read stays tenant-wide: a protocol is the evidence that maintenance
|
|
30
|
+
// happened, and the people who need to see it — the planner, the auditor,
|
|
31
|
+
// the colleague on the next shift — are not necessarily the person who
|
|
32
|
+
// carried it out. Write is what gets restricted, below and by Parse.
|
|
33
|
+
await (0, index_js_1.defaultAclHandler)(request, { allowCustomACL: true });
|
|
34
|
+
// Freeze the plan's work steps onto the execution as it is created.
|
|
35
|
+
//
|
|
36
|
+
// Deliberately **before** the migration/master escape below: this is not an
|
|
37
|
+
// authorisation question but a data one. A protocol written by the seed
|
|
38
|
+
// script, an import or a future schedule migration needs its snapshot just
|
|
39
|
+
// as much as one a technician creates — arguably more, since nobody is
|
|
40
|
+
// watching.
|
|
41
|
+
//
|
|
42
|
+
// Without it a protocol shows whatever the plan says *now*: renaming a step
|
|
43
|
+
// rewrites every protocol that referenced it, deleting one turns its
|
|
44
|
+
// results into numbered orphans (GRENZEN §5).
|
|
45
|
+
//
|
|
46
|
+
// A direct maintenance (no plan) brings its own steps and is left alone.
|
|
47
|
+
if (object.isNew() && !object.get("steps")) {
|
|
48
|
+
await freezeSteps(object);
|
|
49
|
+
}
|
|
50
|
+
// A protocol has to be about something: the plan it performs, or — for a
|
|
51
|
+
// direct maintenance — the machine it was done on. With neither, no view
|
|
52
|
+
// can place it. A data rule like the snapshot above, so it holds for
|
|
53
|
+
// migrations and master-key writes too.
|
|
54
|
+
if (!object.get("schedule") && !object.get("equipment")) {
|
|
55
|
+
throw new node_1.default.Error(node_1.default.Error.VALIDATION_ERROR, "An execution needs a schedule, or an equipment for a direct maintenance.");
|
|
56
|
+
}
|
|
57
|
+
// A migration replays historical protocols; it must not be refused for
|
|
58
|
+
// lacking a capability, and it supplies `performedBy` itself.
|
|
59
|
+
if ((0, index_js_1.isMigrationMode)() || request.master)
|
|
60
|
+
return;
|
|
61
|
+
// Creating an execution *is* performing maintenance — the capability that
|
|
62
|
+
// gates the button in the UI now gates the write as well. Until this,
|
|
63
|
+
// `can-perform-execution` only hid a button: anyone who could reach the
|
|
64
|
+
// Parse class could sign a protocol.
|
|
65
|
+
if (object.isNew()) {
|
|
66
|
+
await (0, index_js_2.requirePermission)({
|
|
67
|
+
sessionToken: user?.getSessionToken(),
|
|
68
|
+
master: request.master,
|
|
69
|
+
}, Permissions_js_1.Permissions.SERVICE.execution_perform, "perform a maintenance execution");
|
|
70
|
+
}
|
|
71
|
+
// Who performed it is established by the server from the session, not
|
|
72
|
+
// accepted from the client. A protocol that names somebody else is worth
|
|
73
|
+
// less than no protocol at all.
|
|
74
|
+
if (object.dirty("performedBy") && user) {
|
|
75
|
+
const claimed = object.get("performedBy");
|
|
76
|
+
if (claimed?.id && claimed.id !== user.id) {
|
|
77
|
+
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, "performedBy must be the acting user.");
|
|
78
|
+
}
|
|
79
|
+
// Set it explicitly rather than trusting an absent value: the sign-off
|
|
80
|
+
// sends it, but nothing else should have to.
|
|
81
|
+
object.set("performedBy", user);
|
|
82
|
+
}
|
|
83
|
+
// A signed-off protocol is closed. `original` exists on every update, and
|
|
84
|
+
// its `completedAt` is what the record looked like *before* this save —
|
|
85
|
+
// so this refuses edits to something that was already complete, while
|
|
86
|
+
// still allowing the sign-off itself.
|
|
87
|
+
const completedAt = original?.get("completedAt");
|
|
88
|
+
if (completedAt) {
|
|
89
|
+
const changed = object
|
|
90
|
+
.dirtyKeys()
|
|
91
|
+
.filter((key) => !EDITABLE_AFTER_COMPLETION.has(key));
|
|
92
|
+
if (changed.length > 0) {
|
|
93
|
+
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `This execution was completed on ${completedAt.toISOString()} ` +
|
|
94
|
+
`and cannot be changed (${changed.join(", ")}).`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
12
97
|
});
|
|
13
|
-
(0, index_js_1.
|
|
14
|
-
|
|
15
|
-
//
|
|
98
|
+
(0, index_js_1.beforeDeleteHook)(index_js_3.Service_Schedule_Execution, async (request) => {
|
|
99
|
+
// Making a protocol unmodifiable but deletable protects nothing: the
|
|
100
|
+
// simplest way around "you may not change what this says" is to remove it
|
|
101
|
+
// and write a new one. A completed protocol is evidence that maintenance
|
|
102
|
+
// happened, and evidence does not get tidied away.
|
|
103
|
+
//
|
|
104
|
+
// An *incomplete* one is not evidence yet — it is a run somebody started
|
|
105
|
+
// and abandoned. Removing that is housekeeping, gated on the same
|
|
106
|
+
// capability as performing maintenance.
|
|
107
|
+
if ((0, index_js_1.isMigrationMode)() || request.master)
|
|
108
|
+
return;
|
|
109
|
+
if (request.object.get("completedAt")) {
|
|
110
|
+
throw new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, "A completed maintenance protocol cannot be deleted.");
|
|
111
|
+
}
|
|
112
|
+
await (0, index_js_2.requirePermission)({
|
|
113
|
+
sessionToken: request.user?.getSessionToken(),
|
|
114
|
+
master: request.master,
|
|
115
|
+
}, Permissions_js_1.Permissions.SERVICE.execution_perform, "delete an unfinished maintenance execution");
|
|
116
|
+
});
|
|
117
|
+
(0, index_js_1.afterSaveHook)(index_js_3.Service_Schedule_Execution, async () => {
|
|
118
|
+
// Nothing to do. Kept as the documented place for it: the obvious
|
|
119
|
+
// candidate — notifying on completion — belongs to the scheduler, which
|
|
120
|
+
// already owns notification timing and recipients.
|
|
16
121
|
});
|
|
17
122
|
}
|
|
123
|
+
/**
|
|
124
|
+
* Copy the plan's steps onto the execution.
|
|
125
|
+
*
|
|
126
|
+
* Failure is logged, not thrown: a missing snapshot degrades the protocol to
|
|
127
|
+
* what it was before this existed — readable, just not frozen — while throwing
|
|
128
|
+
* would stop somebody from recording maintenance they actually performed.
|
|
129
|
+
*/
|
|
130
|
+
async function freezeSteps(execution) {
|
|
131
|
+
const schedule = execution.get("schedule");
|
|
132
|
+
if (!schedule?.id)
|
|
133
|
+
return;
|
|
134
|
+
try {
|
|
135
|
+
const plan = await new node_1.default.Query(index_js_3.Service_Schedule)
|
|
136
|
+
.equalTo("objectId", schedule.id)
|
|
137
|
+
.first({ useMasterKey: true });
|
|
138
|
+
const steps = plan?.get("steps");
|
|
139
|
+
if (Array.isArray(steps) && steps.length > 0) {
|
|
140
|
+
execution.set("steps", steps);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
catch (error) {
|
|
144
|
+
console.error(`[ServiceScheduleExecution] Could not snapshot steps of plan ${schedule.id}:`, error);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -2,14 +2,18 @@ import { Meta_Entry } from "../../../types/index.js";
|
|
|
2
2
|
import type { MetaFieldConfig } from "../../../types/custom/MetaField.js";
|
|
3
3
|
import type { MigrationConfig } from "./env.js";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* The article data that has no column of its own.
|
|
6
6
|
*
|
|
7
|
-
* v1's
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
*
|
|
7
|
+
* Until 2026-09-18 this held all of v1's stock keeping, because `OD3_BDE_Article`
|
|
8
|
+
* is **shared with BDE and its ABAS sync** and was not ours to widen. The class
|
|
9
|
+
* has since gained those columns and pass 05 writes them directly; what is left
|
|
10
|
+
* here is the category and the equipment links.
|
|
11
11
|
*
|
|
12
|
-
*
|
|
12
|
+
* ⚠️ The ABAS sync still owns the columns it writes and replaces them on every
|
|
13
|
+
* run. It does not touch the stock-keeping ones today — if that changes, they
|
|
14
|
+
* are the collision to watch.
|
|
15
|
+
*
|
|
16
|
+
* The data lands in a `Meta_Entry` under the same
|
|
13
17
|
* `["service", <entity>, "meta"]` context every other core master-data entity
|
|
14
18
|
* uses (`constants.metaContext`). That makes it editable through the article
|
|
15
19
|
* admin view in `openservice-core` with no extra machinery.
|
|
@@ -22,7 +26,16 @@ import type { MigrationConfig } from "./env.js";
|
|
|
22
26
|
* would have its values clobbered on the next sync.
|
|
23
27
|
*/
|
|
24
28
|
export declare const ARTICLE_META_CONTEXT: string[];
|
|
25
|
-
/**
|
|
29
|
+
/**
|
|
30
|
+
* The field definitions written to the shared `Meta_Config`.
|
|
31
|
+
*
|
|
32
|
+
* **Shrunk on 2026-09-18**, when the class gained proper columns for price,
|
|
33
|
+
* stock, reorder level, storage location, supplier and order number. Leaving
|
|
34
|
+
* them here would have shown every article twice — once as an empty meta field,
|
|
35
|
+
* once as the column that actually holds the value.
|
|
36
|
+
*
|
|
37
|
+
* What remains is what has no column: the category, and the equipment links.
|
|
38
|
+
*/
|
|
26
39
|
export declare const ARTICLE_META_FIELDS: MetaFieldConfig[];
|
|
27
40
|
/**
|
|
28
41
|
* v1 stores `price` as a String, and these are German-language instances.
|
|
@@ -14,14 +14,18 @@ const acl_js_1 = require("./acl.js");
|
|
|
14
14
|
const ptr_js_1 = require("./ptr.js");
|
|
15
15
|
const pass_js_1 = require("./pass.js");
|
|
16
16
|
/**
|
|
17
|
-
*
|
|
17
|
+
* The article data that has no column of its own.
|
|
18
18
|
*
|
|
19
|
-
* v1's
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
19
|
+
* Until 2026-09-18 this held all of v1's stock keeping, because `OD3_BDE_Article`
|
|
20
|
+
* is **shared with BDE and its ABAS sync** and was not ours to widen. The class
|
|
21
|
+
* has since gained those columns and pass 05 writes them directly; what is left
|
|
22
|
+
* here is the category and the equipment links.
|
|
23
23
|
*
|
|
24
|
-
*
|
|
24
|
+
* ⚠️ The ABAS sync still owns the columns it writes and replaces them on every
|
|
25
|
+
* run. It does not touch the stock-keeping ones today — if that changes, they
|
|
26
|
+
* are the collision to watch.
|
|
27
|
+
*
|
|
28
|
+
* The data lands in a `Meta_Entry` under the same
|
|
25
29
|
* `["service", <entity>, "meta"]` context every other core master-data entity
|
|
26
30
|
* uses (`constants.metaContext`). That makes it editable through the article
|
|
27
31
|
* admin view in `openservice-core` with no extra machinery.
|
|
@@ -34,16 +38,18 @@ const pass_js_1 = require("./pass.js");
|
|
|
34
38
|
* would have its values clobbered on the next sync.
|
|
35
39
|
*/
|
|
36
40
|
exports.ARTICLE_META_CONTEXT = ["service", "article", "meta"];
|
|
37
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The field definitions written to the shared `Meta_Config`.
|
|
43
|
+
*
|
|
44
|
+
* **Shrunk on 2026-09-18**, when the class gained proper columns for price,
|
|
45
|
+
* stock, reorder level, storage location, supplier and order number. Leaving
|
|
46
|
+
* them here would have shown every article twice — once as an empty meta field,
|
|
47
|
+
* once as the column that actually holds the value.
|
|
48
|
+
*
|
|
49
|
+
* What remains is what has no column: the category, and the equipment links.
|
|
50
|
+
*/
|
|
38
51
|
exports.ARTICLE_META_FIELDS = [
|
|
39
|
-
{ type: "number", name: "price", label: "Preis" },
|
|
40
|
-
{ type: "number", name: "stock", label: "Bestand" },
|
|
41
|
-
{ type: "number", name: "stockAlarmAt", label: "Meldebestand" },
|
|
42
|
-
{ type: "string", name: "stockUnit", label: "Lagereinheit" },
|
|
43
|
-
{ type: "string", name: "storageLocation", label: "Lagerort" },
|
|
44
|
-
{ type: "string", name: "supplier", label: "Lieferant" },
|
|
45
52
|
{ type: "string", name: "category", label: "Kategorie" },
|
|
46
|
-
{ type: "string", name: "orderNumber", label: "Bestellnummer" },
|
|
47
53
|
{
|
|
48
54
|
type: "select_parse",
|
|
49
55
|
name: "equipment",
|
|
@@ -6,14 +6,23 @@ import { type Pass } from "../lib/pass.js";
|
|
|
6
6
|
* retired and material now references the shared article catalogue instead, so
|
|
7
7
|
* the same v1 rows land in `OD3_BDE_Article` with `type: "spare_part"`.
|
|
8
8
|
*
|
|
9
|
-
* **
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
9
|
+
* **Stock keeping lands in columns (since 2026-09-18).** `BDE_Article` used to
|
|
10
|
+
* be a lean catalogue that was shared with BDE and therefore not ours to
|
|
11
|
+
* widen, so v1's stock fields went to a `Meta_Entry` instead. The class has
|
|
12
|
+
* since gained `stock`, `minimumStock`, `storageLocation`, `supplier`,
|
|
13
|
+
* `orderNumber`, `price`, `priceCurrency` and `packageSize`, and this pass
|
|
14
|
+
* writes them there.
|
|
15
|
+
*
|
|
16
|
+
* What still goes to meta under `["service","article","meta"]`: `category`,
|
|
17
|
+
* which deliberately got no column (tags and `type` already classify), and the
|
|
18
|
+
* equipment links. Nothing is dropped. See `lib/articleMeta.ts` for why that
|
|
19
|
+
* context and not the ABAS one.
|
|
20
|
+
*
|
|
21
|
+
* ⚠️ **Installations migrated before this change keep their values in meta.**
|
|
22
|
+
* There is no repair pass: few installations track material at all, so
|
|
23
|
+
* re-entering the handful of articles was judged cheaper than a script running
|
|
24
|
+
* against customer data. Such an installation shows the values in the meta
|
|
25
|
+
* block of the article admin view while the columns sit empty.
|
|
17
26
|
*
|
|
18
27
|
* Two naming traps, both inherited from BDE: the label column is `description`,
|
|
19
28
|
* not `name`; and the soft-delete flag is `isDeleted`, not `deleted`.
|
|
@@ -28,14 +28,23 @@ const ARTICLE_TYPE_SPARE_PART = "spare_part";
|
|
|
28
28
|
* retired and material now references the shared article catalogue instead, so
|
|
29
29
|
* the same v1 rows land in `OD3_BDE_Article` with `type: "spare_part"`.
|
|
30
30
|
*
|
|
31
|
-
* **
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
31
|
+
* **Stock keeping lands in columns (since 2026-09-18).** `BDE_Article` used to
|
|
32
|
+
* be a lean catalogue that was shared with BDE and therefore not ours to
|
|
33
|
+
* widen, so v1's stock fields went to a `Meta_Entry` instead. The class has
|
|
34
|
+
* since gained `stock`, `minimumStock`, `storageLocation`, `supplier`,
|
|
35
|
+
* `orderNumber`, `price`, `priceCurrency` and `packageSize`, and this pass
|
|
36
|
+
* writes them there.
|
|
37
|
+
*
|
|
38
|
+
* What still goes to meta under `["service","article","meta"]`: `category`,
|
|
39
|
+
* which deliberately got no column (tags and `type` already classify), and the
|
|
40
|
+
* equipment links. Nothing is dropped. See `lib/articleMeta.ts` for why that
|
|
41
|
+
* context and not the ABAS one.
|
|
42
|
+
*
|
|
43
|
+
* ⚠️ **Installations migrated before this change keep their values in meta.**
|
|
44
|
+
* There is no repair pass: few installations track material at all, so
|
|
45
|
+
* re-entering the handful of articles was judged cheaper than a script running
|
|
46
|
+
* against customer data. Such an installation shows the values in the meta
|
|
47
|
+
* block of the article admin view while the columns sit empty.
|
|
39
48
|
*
|
|
40
49
|
* Two naming traps, both inherited from BDE: the label column is `description`,
|
|
41
50
|
* not `name`; and the soft-delete flag is `isDeleted`, not `deleted`.
|
|
@@ -81,36 +90,46 @@ exports.pass05 = {
|
|
|
81
90
|
}
|
|
82
91
|
if (item.get("stockUnit"))
|
|
83
92
|
target.set("unit", item.get("stockUnit"));
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
|
|
87
|
-
for (const
|
|
88
|
-
"storageLocation",
|
|
89
|
-
"supplier",
|
|
90
|
-
"
|
|
91
|
-
"orderNumber",
|
|
92
|
-
"stockUnit",
|
|
93
|
+
// Stock keeping goes onto the class. It used to go to meta because
|
|
94
|
+
// `BDE_Article` was shared with BDE and not ours to widen; the columns
|
|
95
|
+
// were added on 2026-09-18, so the values belong in them.
|
|
96
|
+
for (const [from, to] of [
|
|
97
|
+
["storageLocation", "storageLocation"],
|
|
98
|
+
["supplier", "supplier"],
|
|
99
|
+
["orderNumber", "orderNumber"],
|
|
93
100
|
]) {
|
|
94
|
-
const value = item.get(
|
|
101
|
+
const value = item.get(from);
|
|
95
102
|
if (typeof value === "string" && value.trim()) {
|
|
96
|
-
|
|
103
|
+
target.set(to, value.trim());
|
|
97
104
|
}
|
|
98
105
|
}
|
|
99
|
-
|
|
100
|
-
|
|
106
|
+
// v1's `stockAlarmAt` is the reorder level; renamed because it raises no
|
|
107
|
+
// alarm.
|
|
108
|
+
for (const [from, to] of [
|
|
109
|
+
["stock", "stock"],
|
|
110
|
+
["stockAlarmAt", "minimumStock"],
|
|
111
|
+
]) {
|
|
112
|
+
const value = item.get(from);
|
|
101
113
|
if (typeof value === "number")
|
|
102
|
-
|
|
114
|
+
target.set(to, value);
|
|
115
|
+
}
|
|
116
|
+
// Only what still has no column. `category` was deliberately not added —
|
|
117
|
+
// tags and `type` already classify, and a third such field goes stale.
|
|
118
|
+
const metaValues = {};
|
|
119
|
+
const category = item.get("category");
|
|
120
|
+
if (typeof category === "string" && category.trim()) {
|
|
121
|
+
metaValues.category = category.trim();
|
|
103
122
|
}
|
|
104
123
|
// v1 stored price as a free-form string; keep the number, report the rest
|
|
105
124
|
// rather than silently discarding it.
|
|
106
125
|
const rawPrice = item.get("price");
|
|
107
126
|
const price = (0, articleMeta_js_1.parsePrice)(rawPrice);
|
|
108
127
|
if (price !== undefined)
|
|
109
|
-
|
|
128
|
+
target.set("price", price);
|
|
110
129
|
else if (rawPrice) {
|
|
111
130
|
unparseablePrices += 1;
|
|
112
131
|
report.warn(entry, `item ${sourceId} ("${item.get("name")}") price "${String(rawPrice)}" ` +
|
|
113
|
-
`is not a number — left unset on the
|
|
132
|
+
`is not a number — left unset on the article`);
|
|
114
133
|
}
|
|
115
134
|
// `Item.sources` (Relation<Source>) -> the migrated Equipment ids.
|
|
116
135
|
const equipmentIds = [];
|