@openinc/parse-server-opendash 4.38.2 → 4.40.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/features/config/helper/customOptions.js +9 -0
- package/dist/features/openservice/alarms/alarmIdentity.d.ts +2 -0
- package/dist/features/openservice/alarms/alarmIdentity.js +4 -1
- package/dist/features/openservice/alarms/index.d.ts +5 -2
- package/dist/features/openservice/alarms/index.js +6 -5
- package/dist/features/openservice/alarms/schedule/AlarmScheduleTypes.d.ts +4 -19
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.d.ts +6 -6
- package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +36 -139
- package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +2 -2
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.d.ts +7 -4
- package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +42 -161
- package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.js +2 -2
- package/dist/features/openservice/automation/automationCall.d.ts +56 -0
- package/dist/features/openservice/automation/automationCall.js +61 -0
- package/dist/features/openservice/automation/createSchedule.d.ts +124 -0
- package/dist/features/openservice/automation/createSchedule.js +247 -0
- package/dist/features/openservice/automation/createTicket.d.ts +121 -0
- package/dist/features/openservice/automation/createTicket.js +212 -0
- package/dist/features/openservice/automation/index.d.ts +32 -0
- package/dist/features/openservice/automation/index.js +56 -0
- package/dist/features/openservice/{alarms/actionParams.d.ts → automation/params.d.ts} +15 -1
- package/dist/features/openservice/{alarms/actionParams.js → automation/params.js} +58 -1
- package/dist/features/openservice/automation/recordExecution.d.ts +61 -0
- package/dist/features/openservice/automation/recordExecution.js +111 -0
- package/dist/features/openservice/automation/resolveEquipment.d.ts +16 -0
- package/dist/features/openservice/automation/resolveEquipment.js +43 -0
- package/dist/features/openservice/automation/resolveStatus.d.ts +20 -0
- package/dist/features/openservice/automation/resolveStatus.js +57 -0
- package/dist/features/openservice/automation/resolveTenantUser.d.ts +16 -0
- package/dist/features/openservice/automation/resolveTenantUser.js +35 -0
- package/dist/features/openservice/automation/ticketDefaults.d.ts +34 -0
- package/dist/features/openservice/{alarms/ticket/alarmTicketDefaults.js → automation/ticketDefaults.js} +8 -8
- package/dist/features/openservice/automation/updateTicket.d.ts +65 -0
- package/dist/features/openservice/automation/updateTicket.js +141 -0
- package/dist/features/openservice/index.d.ts +2 -0
- package/dist/features/openservice/index.js +2 -0
- package/dist/functions/openinc-openservice-create-schedule.d.ts +20 -0
- package/dist/functions/openinc-openservice-create-schedule.js +41 -0
- package/dist/functions/openinc-openservice-create-ticket.d.ts +24 -0
- package/dist/functions/openinc-openservice-create-ticket.js +48 -0
- package/dist/functions/openinc-openservice-record-execution.d.ts +17 -0
- package/dist/functions/openinc-openservice-record-execution.js +38 -0
- package/dist/functions/openinc-openservice-update-ticket.d.ts +16 -0
- package/dist/functions/openinc-openservice-update-ticket.js +37 -0
- package/dist/hooks/Service_Schedule.js +5 -0
- package/dist/hooks/Tenant.js +68 -10
- package/package.json +11 -11
- package/pnpm-workspace.yaml +1 -1
- package/dist/features/openservice/alarms/resolveAlarmUser.d.ts +0 -16
- package/dist/features/openservice/alarms/resolveAlarmUser.js +0 -35
- package/dist/features/openservice/alarms/resolveEquipment.d.ts +0 -17
- package/dist/features/openservice/alarms/resolveEquipment.js +0 -45
- package/dist/features/openservice/alarms/ticket/alarmTicketDefaults.d.ts +0 -34
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.init = init;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../features/openservice/automation/index.js");
|
|
9
|
+
/**
|
|
10
|
+
* Change an open.SERVICE ticket from outside the frontend: move its status,
|
|
11
|
+
* reassign it, record the failure window, comment on it.
|
|
12
|
+
*
|
|
13
|
+
* **Authentication** — see `readAutomationCall`: master key with `tenantId`
|
|
14
|
+
* (and optionally `actingUserId`, the comment's author), or the session of a
|
|
15
|
+
* (technical) user, whose write the ticket's ACL then decides — exactly as
|
|
16
|
+
* on the detail page.
|
|
17
|
+
*
|
|
18
|
+
* **Parameters** — `TicketUpdateParams`: the ticket by `ticketId`, or by
|
|
19
|
+
* `origin` (the newest open ticket of it); then only the fields to change, a
|
|
20
|
+
* status by id or by category, and/or a `comment`.
|
|
21
|
+
*
|
|
22
|
+
* Returns `{ ticketId, changed, commentId?, statusId? }`.
|
|
23
|
+
*/
|
|
24
|
+
async function init(name) {
|
|
25
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
26
|
+
const { tenant, auth, actor, params } = await (0, index_js_1.readAutomationCall)(name, request);
|
|
27
|
+
const result = await (0, index_js_1.updateTicket)(tenant, params, {
|
|
28
|
+
auth,
|
|
29
|
+
actor,
|
|
30
|
+
logPrefix: `[${name}]`,
|
|
31
|
+
});
|
|
32
|
+
console.log(`[${name}] ticket ${result.ticketId}: ` +
|
|
33
|
+
(result.changed.length ? result.changed.join(", ") : "no fields") +
|
|
34
|
+
(result.commentId ? " + comment" : ""));
|
|
35
|
+
return result;
|
|
36
|
+
}, {});
|
|
37
|
+
}
|
|
@@ -10,6 +10,7 @@ const Permissions_js_1 = require("../features/permissions/types/Permissions.js")
|
|
|
10
10
|
const index_js_2 = require("../features/permissions/index.js");
|
|
11
11
|
const assignmentAcl_js_1 = require("../features/openservice/serviceSchedules/assignmentAcl.js");
|
|
12
12
|
const demoSeed_js_1 = require("../features/openservice/demoSeed/demoSeed.js");
|
|
13
|
+
const createSchedule_js_1 = require("../features/openservice/automation/createSchedule.js");
|
|
13
14
|
const index_js_3 = require("../features/openservice/serviceSchedules/calendarSync/index.js");
|
|
14
15
|
const index_js_4 = require("../types/index.js");
|
|
15
16
|
async function init() {
|
|
@@ -84,6 +85,10 @@ async function init() {
|
|
|
84
85
|
// Demo data belongs to a demo tenant, not in anybody's calendar.
|
|
85
86
|
if (context?.[demoSeed_js_1.DEMO_SEED_CONTEXT_FLAG])
|
|
86
87
|
return;
|
|
88
|
+
// A plan created from outside that asked to stay out of every calendar
|
|
89
|
+
// (`calendarSync: false` of the automation endpoint — demo data above all).
|
|
90
|
+
if (context?.[createSchedule_js_1.NO_CALENDAR_SYNC_CONTEXT_FLAG])
|
|
91
|
+
return;
|
|
87
92
|
if (!original || calendarRelevantChange(object, original)) {
|
|
88
93
|
// Deliberately not awaited: the calendar is a downstream system, and a
|
|
89
94
|
// Graph round trip (token + write) would otherwise be part of every save
|
package/dist/hooks/Tenant.js
CHANGED
|
@@ -5,14 +5,15 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.init = init;
|
|
7
7
|
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
-
const index_js_1 = require("../features/
|
|
8
|
+
const index_js_1 = require("../features/config/index.js");
|
|
9
|
+
const index_js_2 = require("../features/schema/index.js");
|
|
9
10
|
const openinc_rmq_create_tenant_js_1 = require("../functions/openinc-rmq-create-tenant.js");
|
|
10
|
-
const
|
|
11
|
+
const index_js_3 = require("../types/index.js");
|
|
11
12
|
async function init() {
|
|
12
|
-
(0,
|
|
13
|
+
(0, index_js_2.beforeSaveHook)(index_js_3.Tenant, async (request) => {
|
|
13
14
|
const { object, original, user } = request;
|
|
14
|
-
await (0,
|
|
15
|
-
await (0,
|
|
15
|
+
await (0, index_js_2.defaultHandler)(request);
|
|
16
|
+
await (0, index_js_2.immutableField)(request, "tagPrefix", "opendash:tenant:change-tag-prefix");
|
|
16
17
|
if (object.id) {
|
|
17
18
|
object.setACL(new node_1.default.ACL({
|
|
18
19
|
[`role:od-tenant-user-${object.id}`]: {
|
|
@@ -34,10 +35,10 @@ async function init() {
|
|
|
34
35
|
}
|
|
35
36
|
}
|
|
36
37
|
});
|
|
37
|
-
(0,
|
|
38
|
+
(0, index_js_2.afterSaveHook)(index_js_3.Tenant, async ({ object, original, user }) => {
|
|
38
39
|
// Handle Data Source
|
|
39
40
|
if (object.id && !original?.get("dataSource")) {
|
|
40
|
-
const rootSource = await new node_1.default.Query(
|
|
41
|
+
const rootSource = await new node_1.default.Query(index_js_3.Source)
|
|
41
42
|
.equalTo("tag", "tenant-root-source")
|
|
42
43
|
.first({ useMasterKey: true });
|
|
43
44
|
const sourceACL = new node_1.default.ACL({
|
|
@@ -47,7 +48,7 @@ async function init() {
|
|
|
47
48
|
});
|
|
48
49
|
let dataSource = object.get("dataSource");
|
|
49
50
|
if (!dataSource) {
|
|
50
|
-
dataSource = new
|
|
51
|
+
dataSource = new index_js_3.Source();
|
|
51
52
|
}
|
|
52
53
|
dataSource.setACL(sourceACL);
|
|
53
54
|
if (rootSource) {
|
|
@@ -60,10 +61,10 @@ async function init() {
|
|
|
60
61
|
object.set("dataSource", dataSource);
|
|
61
62
|
await object.save(null, { useMasterKey: true });
|
|
62
63
|
}
|
|
63
|
-
await (0,
|
|
64
|
+
await (0, index_js_2.ensureRole)(`od-tenant-admin-${object.id}`, {
|
|
64
65
|
label: `${object.get("label")} (Admin)`,
|
|
65
66
|
});
|
|
66
|
-
await (0,
|
|
67
|
+
await (0, index_js_2.ensureRole)(`od-tenant-user-${object.id}`, {
|
|
67
68
|
label: object.get("label"),
|
|
68
69
|
acl: new node_1.default.ACL({
|
|
69
70
|
[`role:od-tenant-user-${object.id}`]: {
|
|
@@ -71,6 +72,10 @@ async function init() {
|
|
|
71
72
|
},
|
|
72
73
|
}),
|
|
73
74
|
});
|
|
75
|
+
if (object.id &&
|
|
76
|
+
index_js_1.ConfigInstance.getInstance().getBoolean("TENANT_ACCESS_PERMISSION_ENABLE")) {
|
|
77
|
+
await ensureTenantAccessPermission(object);
|
|
78
|
+
}
|
|
74
79
|
if (!original && object.id && process.env.OPENINC_PARSE_CLOUD_RMQ_HOST) {
|
|
75
80
|
try {
|
|
76
81
|
await (0, openinc_rmq_create_tenant_js_1.createRabbitMQTenant)(object.id);
|
|
@@ -87,4 +92,57 @@ async function init() {
|
|
|
87
92
|
});
|
|
88
93
|
}
|
|
89
94
|
});
|
|
95
|
+
(0, index_js_2.beforeDeleteHook)(index_js_3.Tenant, async ({ object }) => {
|
|
96
|
+
try {
|
|
97
|
+
const permissions = await new node_1.default.Query(ACCESS_PERMISSIONS)
|
|
98
|
+
.equalTo("tenant", object)
|
|
99
|
+
.find({ useMasterKey: true });
|
|
100
|
+
await node_1.default.Object.destroyAll(permissions, { useMasterKey: true });
|
|
101
|
+
}
|
|
102
|
+
catch (error) {
|
|
103
|
+
console.error(`[@openinc/parse-server-opendash][Tenant] Could not delete open.WARE AccessPermissions of tenant ${object.id}:`, error);
|
|
104
|
+
}
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
/** open.WARE class, not an OD3_* class — there is no generated type for it. */
|
|
108
|
+
const ACCESS_PERMISSIONS = "AccessPermissions";
|
|
109
|
+
function escapeRegex(value) {
|
|
110
|
+
return value.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Keeps one open.WARE `AccessPermissions` row per tenant that gives the tenant
|
|
114
|
+
* admin role read/write/delete on every data source whose tag starts with the
|
|
115
|
+
* tenant's tag prefix (`ownerGroup: true`, `owner` is a regex).
|
|
116
|
+
*
|
|
117
|
+
* The row is found again by its `tenant` pointer, so repeated saves update it
|
|
118
|
+
* instead of adding a new one — e.g. when the tag prefix is set after creation.
|
|
119
|
+
* Visible to od-admin (read/write); the tenant admin role reads it, which is
|
|
120
|
+
* what grants the access in open.WARE.
|
|
121
|
+
*/
|
|
122
|
+
async function ensureTenantAccessPermission(tenant) {
|
|
123
|
+
try {
|
|
124
|
+
const prefix = tenant.get("tagPrefix") || `tenant-${tenant.id}-`;
|
|
125
|
+
const permission = (await new node_1.default.Query(ACCESS_PERMISSIONS)
|
|
126
|
+
.equalTo("tenant", tenant)
|
|
127
|
+
.first({ useMasterKey: true })) ?? new node_1.default.Object(ACCESS_PERMISSIONS);
|
|
128
|
+
permission.set("tenant", tenant);
|
|
129
|
+
permission.set("owner", `^${escapeRegex(prefix)}.*`);
|
|
130
|
+
permission.set("ownerGroup", true);
|
|
131
|
+
permission.set("read", ".*");
|
|
132
|
+
permission.set("write", ".*");
|
|
133
|
+
permission.set("delete", ".*");
|
|
134
|
+
permission.setACL(new node_1.default.ACL({
|
|
135
|
+
[`role:od-tenant-admin-${tenant.id}`]: {
|
|
136
|
+
read: true,
|
|
137
|
+
},
|
|
138
|
+
[`role:od-admin`]: {
|
|
139
|
+
read: true,
|
|
140
|
+
write: true,
|
|
141
|
+
},
|
|
142
|
+
}));
|
|
143
|
+
await permission.save(null, { useMasterKey: true });
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error(`[@openinc/parse-server-opendash][Tenant] open.WARE AccessPermissions for tenant ${tenant.id} were not saved:`, error);
|
|
147
|
+
}
|
|
90
148
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@openinc/parse-server-opendash",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.40.0",
|
|
4
4
|
"description": "Parse Server Cloud Code for open.INC Stack.",
|
|
5
|
-
"packageManager": "pnpm@12.
|
|
5
|
+
"packageManager": "pnpm@12.21.0",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"parse",
|
|
8
8
|
"opendash"
|
|
@@ -75,26 +75,26 @@
|
|
|
75
75
|
"seed:v1": "node dist/scripts/seed-v1-testdata.js"
|
|
76
76
|
},
|
|
77
77
|
"dependencies": {
|
|
78
|
-
"@opendash/openservice-shared": "0.2.0-nightly.
|
|
78
|
+
"@opendash/openservice-shared": "0.2.0-nightly.7",
|
|
79
79
|
"@opendash/ruleset-core": "nightly",
|
|
80
80
|
"@opendash/schedule": "1.2.0-nightly.24",
|
|
81
81
|
"@openinc/parse-server-schema": "^4.1.8",
|
|
82
82
|
"amqplib": "^0.10.9",
|
|
83
83
|
"cron": "^4.4.0",
|
|
84
84
|
"dayjs": "^1.11.23",
|
|
85
|
-
"dotenv": "^18.0.
|
|
86
|
-
"fast-equals": "^6.
|
|
87
|
-
"i18next": "^26.7.
|
|
88
|
-
"i18next-fs-backend": "^2.
|
|
85
|
+
"dotenv": "^18.0.10",
|
|
86
|
+
"fast-equals": "^6.4.0",
|
|
87
|
+
"i18next": "^26.7.2",
|
|
88
|
+
"i18next-fs-backend": "^2.7.0",
|
|
89
89
|
"jsonwebtoken": "^9.0.3",
|
|
90
90
|
"jwks-rsa": "^4.1.0",
|
|
91
|
-
"nodemailer": "^10.
|
|
91
|
+
"nodemailer": "^10.6.0",
|
|
92
92
|
"nunjucks": "^3.2.4",
|
|
93
93
|
"parse": "8.6.2",
|
|
94
94
|
"parse-server": "9.10.7",
|
|
95
95
|
"pdf-img-convert": "2.0.0",
|
|
96
96
|
"rimraf": "^6.1.4",
|
|
97
|
-
"table": "^6.
|
|
97
|
+
"table": "^6.10.1",
|
|
98
98
|
"web-push": "^3.6.7",
|
|
99
99
|
"winston": "^3.19.0"
|
|
100
100
|
},
|
|
@@ -105,8 +105,8 @@
|
|
|
105
105
|
"@types/nunjucks": "^3.2.6",
|
|
106
106
|
"@types/safe-timers": "^1.1.2",
|
|
107
107
|
"@types/web-push": "^3.6.4",
|
|
108
|
-
"concurrently": "^10.0.
|
|
109
|
-
"prettier": "^3.
|
|
108
|
+
"concurrently": "^10.0.7",
|
|
109
|
+
"prettier": "^3.10.1",
|
|
110
110
|
"prettier-plugin-organize-imports": "^4.3.0",
|
|
111
111
|
"ts-node": "^10.9.2",
|
|
112
112
|
"typedoc": "^0.28.20",
|
package/pnpm-workspace.yaml
CHANGED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { type _User, Tenant } from "../../../types/index.js";
|
|
2
|
-
/**
|
|
3
|
-
* The person who configured a fired alarm (`event.userId`, `OD3_Alarm.user`),
|
|
4
|
-
* if they are a user of the alarm's tenant.
|
|
5
|
-
*
|
|
6
|
-
* What the actions make of them grants access: a ticket's `createdBy` and a
|
|
7
|
-
* plan's `user` both get read/write in the ACL. The tenant is established by
|
|
8
|
-
* the caller's secret, the user id is just a value in the payload — so a user
|
|
9
|
-
* of another tenant is dropped rather than handed write access to this
|
|
10
|
-
* tenant's record. Neither action needs an owner, so dropping one is a
|
|
11
|
-
* warning, not an error.
|
|
12
|
-
*
|
|
13
|
-
* An executor that does not fill the placeholder posts `"{{alarm.user}}"`
|
|
14
|
-
* literally; that matches no user and ends up the same way.
|
|
15
|
-
*/
|
|
16
|
-
export declare function resolveAlarmUser(tenant: Tenant, userId: unknown, logPrefix: string): Promise<_User | undefined>;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveAlarmUser = resolveAlarmUser;
|
|
7
|
-
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
-
const actionParams_js_1 = require("./actionParams.js");
|
|
9
|
-
/**
|
|
10
|
-
* The person who configured a fired alarm (`event.userId`, `OD3_Alarm.user`),
|
|
11
|
-
* if they are a user of the alarm's tenant.
|
|
12
|
-
*
|
|
13
|
-
* What the actions make of them grants access: a ticket's `createdBy` and a
|
|
14
|
-
* plan's `user` both get read/write in the ACL. The tenant is established by
|
|
15
|
-
* the caller's secret, the user id is just a value in the payload — so a user
|
|
16
|
-
* of another tenant is dropped rather than handed write access to this
|
|
17
|
-
* tenant's record. Neither action needs an owner, so dropping one is a
|
|
18
|
-
* warning, not an error.
|
|
19
|
-
*
|
|
20
|
-
* An executor that does not fill the placeholder posts `"{{alarm.user}}"`
|
|
21
|
-
* literally; that matches no user and ends up the same way.
|
|
22
|
-
*/
|
|
23
|
-
async function resolveAlarmUser(tenant, userId, logPrefix) {
|
|
24
|
-
const id = (0, actionParams_js_1.paramId)(userId);
|
|
25
|
-
if (!id)
|
|
26
|
-
return undefined;
|
|
27
|
-
const user = await new node_1.default.Query(node_1.default.User)
|
|
28
|
-
.equalTo("objectId", id)
|
|
29
|
-
.equalTo("tenant", tenant)
|
|
30
|
-
.first({ useMasterKey: true });
|
|
31
|
-
if (!user) {
|
|
32
|
-
console.warn(`${logPrefix} Alarm owner ${id} is not a user of this tenant — creating without one`);
|
|
33
|
-
}
|
|
34
|
-
return user ?? undefined;
|
|
35
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { Service_Equipment, Tenant } from "../../../types/index.js";
|
|
2
|
-
import type { AlarmEvent } from "./AlarmEvent.js";
|
|
3
|
-
/**
|
|
4
|
-
* The machine a fired alarm concerns.
|
|
5
|
-
*
|
|
6
|
-
* 1. what was configured on the alarm — the only reliable source, because
|
|
7
|
-
* **nothing in the data model links a sensor to a machine**;
|
|
8
|
-
* 2. otherwise a machine whose `sourceTags` name the sensor or its source.
|
|
9
|
-
* That is a convention, not a relation, so it is a fallback: `sourceTags`
|
|
10
|
-
* was meant for source scoping, and a site-level tag can match several
|
|
11
|
-
* machines — the first one wins, which is a guess.
|
|
12
|
-
*
|
|
13
|
-
* No machine is not an error for a ticket (`equipment` is optional there). A
|
|
14
|
-
* caller that *needs* one — a maintenance plan is about a machine — checks the
|
|
15
|
-
* `undefined` itself.
|
|
16
|
-
*/
|
|
17
|
-
export declare function resolveEquipment(tenant: Tenant, event: AlarmEvent, equipmentId: string | undefined, logPrefix: string): Promise<Service_Equipment | undefined>;
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.resolveEquipment = resolveEquipment;
|
|
7
|
-
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
-
const index_js_1 = require("../../../types/index.js");
|
|
9
|
-
/**
|
|
10
|
-
* The machine a fired alarm concerns.
|
|
11
|
-
*
|
|
12
|
-
* 1. what was configured on the alarm — the only reliable source, because
|
|
13
|
-
* **nothing in the data model links a sensor to a machine**;
|
|
14
|
-
* 2. otherwise a machine whose `sourceTags` name the sensor or its source.
|
|
15
|
-
* That is a convention, not a relation, so it is a fallback: `sourceTags`
|
|
16
|
-
* was meant for source scoping, and a site-level tag can match several
|
|
17
|
-
* machines — the first one wins, which is a guess.
|
|
18
|
-
*
|
|
19
|
-
* No machine is not an error for a ticket (`equipment` is optional there). A
|
|
20
|
-
* caller that *needs* one — a maintenance plan is about a machine — checks the
|
|
21
|
-
* `undefined` itself.
|
|
22
|
-
*/
|
|
23
|
-
async function resolveEquipment(tenant, event, equipmentId, logPrefix) {
|
|
24
|
-
if (equipmentId) {
|
|
25
|
-
// Master key reads every tenant: the alarm's tenant (from its secret) must
|
|
26
|
-
// own the machine, or a plan would point at another tenant's machine.
|
|
27
|
-
const explicit = await new node_1.default.Query(index_js_1.Service_Equipment)
|
|
28
|
-
.equalTo("objectId", equipmentId)
|
|
29
|
-
.equalTo("tenant", tenant)
|
|
30
|
-
.first({ useMasterKey: true });
|
|
31
|
-
if (explicit)
|
|
32
|
-
return explicit;
|
|
33
|
-
console.warn(`${logPrefix} Configured machine ${equipmentId} does not exist for this tenant`);
|
|
34
|
-
}
|
|
35
|
-
const candidates = [event.item_id, event.item_source].filter((value) => !!value);
|
|
36
|
-
if (candidates.length === 0)
|
|
37
|
-
return undefined;
|
|
38
|
-
const query = new node_1.default.Query(index_js_1.Service_Equipment)
|
|
39
|
-
.equalTo("tenant", tenant)
|
|
40
|
-
.notEqualTo("deleted", true)
|
|
41
|
-
// `sourceTags` is an Array column: Mongo reads "contained in" as "the array
|
|
42
|
-
// holds one of these". The generated type only knows `any[]`, hence the cast.
|
|
43
|
-
.containedIn("sourceTags", candidates);
|
|
44
|
-
return (await query.first({ useMasterKey: true })) ?? undefined;
|
|
45
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Values the ticket an alarm creates starts out with — the alarm's template
|
|
3
|
-
* (the ticket form in template mode) or what its form config pre-fills
|
|
4
|
-
* (`defaultValue` of its fields). Both in the form's edit shape: field values
|
|
5
|
-
* keyed by ticket field, references as ids.
|
|
6
|
-
*
|
|
7
|
-
* Read here into exactly the fields a default may set. Dates are left out (a
|
|
8
|
-
* fixed date makes no sense for an alarm that fires later; the config's
|
|
9
|
-
* relative value rules still apply on save), and so are the fields the server
|
|
10
|
-
* owns (tenant, number, origin, closedAt …). Title and description come back
|
|
11
|
-
* apart: the alarm's own title wins over them, and the alarm's details are
|
|
12
|
-
* appended to the description (`alarmTicketFields`). Whether a referenced row
|
|
13
|
-
* belongs to the tenant is the `Service_Ticket` hook's call, as on every write
|
|
14
|
-
* path.
|
|
15
|
-
*/
|
|
16
|
-
export interface AlarmTicketDefaults {
|
|
17
|
-
title?: string;
|
|
18
|
-
description?: string;
|
|
19
|
-
status?: string;
|
|
20
|
-
equipment?: string;
|
|
21
|
-
project?: string;
|
|
22
|
-
/** The remaining fields, ready for `ticket.set`. */
|
|
23
|
-
values: Record<string, unknown>;
|
|
24
|
-
}
|
|
25
|
-
/**
|
|
26
|
-
* The defaults of a form config's `fields` (its JSON column). Hidden fields
|
|
27
|
-
* count: the create form keeps them as hidden inputs and saves their default.
|
|
28
|
-
*
|
|
29
|
-
* shortcut: `visibleWhen` is not evaluated — a default of a field hidden by
|
|
30
|
-
* condition is applied anyway; read it with the ticket's values if a config
|
|
31
|
-
* ever relies on that.
|
|
32
|
-
*/
|
|
33
|
-
export declare function formConfigDefaults(fields: string | undefined): AlarmTicketDefaults;
|
|
34
|
-
export declare function readTicketDefaults(raw: unknown): AlarmTicketDefaults;
|