@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
package/dist/featuremap.json
CHANGED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/** One open.SERVICE alarm action: its row and the webhook that carries it out. */
|
|
2
|
+
export interface AlarmActionDefinition {
|
|
3
|
+
/** `OD3_AlarmAction.topic`, the action's stable id. */
|
|
4
|
+
topic: string;
|
|
5
|
+
label: string;
|
|
6
|
+
/** The cloud function the webhook calls. */
|
|
7
|
+
functionName: string;
|
|
8
|
+
/** Name of the `OD3_AlarmWebhook` row — how it is found again. */
|
|
9
|
+
webhookName: string;
|
|
10
|
+
webhookComment: string;
|
|
11
|
+
formFields: unknown[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Make an open.SERVICE alarm action selectable in the alarm dialog and
|
|
15
|
+
* executable by open.WARE.
|
|
16
|
+
*
|
|
17
|
+
* Alarm actions are **data**, not code: `OD3_AlarmAction` rows that the
|
|
18
|
+
* monitoring adapter loads into the frontend, where the chosen row's
|
|
19
|
+
* `formFields` are rendered as the action's form. The dialog stores a copy of
|
|
20
|
+
* the whole row, with the form's values, in `OD3_Alarm.action`; open.WARE
|
|
21
|
+
* reads that copy when the alarm fires. For `type: "webhook"` it runs the
|
|
22
|
+
* `OD3_AlarmWebhook` row whose objectId is `target` — see
|
|
23
|
+
* `ensureOpenwareWebhook`.
|
|
24
|
+
*
|
|
25
|
+
* Everything on the row is the server's, so it is kept as written here; a fix
|
|
26
|
+
* would otherwise only ever reach a fresh database. The row is global (no
|
|
27
|
+
* tenant): the action makes sense for every tenant.
|
|
28
|
+
*
|
|
29
|
+
* Alarms saved before a change keep their copy until they are saved again —
|
|
30
|
+
* a changed `target` reaches open.WARE only then.
|
|
31
|
+
*/
|
|
32
|
+
export declare function ensureAlarmActionRow(definition: AlarmActionDefinition): Promise<void>;
|
|
@@ -0,0 +1,67 @@
|
|
|
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.ensureAlarmActionRow = ensureAlarmActionRow;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const ensureOpenwareWebhook_js_1 = require("./ensureOpenwareWebhook.js");
|
|
10
|
+
const openwareAlarm_js_1 = require("./openwareAlarm.js");
|
|
11
|
+
/** The action row's own payload: required by the schema, unused by open.WARE. */
|
|
12
|
+
const ACTION_PAYLOAD = "siehe OD3_AlarmWebhook (target)";
|
|
13
|
+
/**
|
|
14
|
+
* Make an open.SERVICE alarm action selectable in the alarm dialog and
|
|
15
|
+
* executable by open.WARE.
|
|
16
|
+
*
|
|
17
|
+
* Alarm actions are **data**, not code: `OD3_AlarmAction` rows that the
|
|
18
|
+
* monitoring adapter loads into the frontend, where the chosen row's
|
|
19
|
+
* `formFields` are rendered as the action's form. The dialog stores a copy of
|
|
20
|
+
* the whole row, with the form's values, in `OD3_Alarm.action`; open.WARE
|
|
21
|
+
* reads that copy when the alarm fires. For `type: "webhook"` it runs the
|
|
22
|
+
* `OD3_AlarmWebhook` row whose objectId is `target` — see
|
|
23
|
+
* `ensureOpenwareWebhook`.
|
|
24
|
+
*
|
|
25
|
+
* Everything on the row is the server's, so it is kept as written here; a fix
|
|
26
|
+
* would otherwise only ever reach a fresh database. The row is global (no
|
|
27
|
+
* tenant): the action makes sense for every tenant.
|
|
28
|
+
*
|
|
29
|
+
* Alarms saved before a change keep their copy until they are saved again —
|
|
30
|
+
* a changed `target` reaches open.WARE only then.
|
|
31
|
+
*/
|
|
32
|
+
async function ensureAlarmActionRow(definition) {
|
|
33
|
+
const webhookId = await (0, ensureOpenwareWebhook_js_1.ensureOpenwareWebhook)(definition.webhookName, definition.functionName, definition.webhookComment);
|
|
34
|
+
const action = (await new node_1.default.Query(index_js_1.AlarmAction)
|
|
35
|
+
.equalTo("topic", definition.topic)
|
|
36
|
+
.first({ useMasterKey: true })) ?? new index_js_1.AlarmAction();
|
|
37
|
+
const wanted = {
|
|
38
|
+
label: definition.label,
|
|
39
|
+
type: "webhook",
|
|
40
|
+
topic: definition.topic,
|
|
41
|
+
// open.WARE takes the template engine for the webhook from the alarm's
|
|
42
|
+
// copy of this row.
|
|
43
|
+
templateType: openwareAlarm_js_1.OPENWARE_TEMPLATE_TYPE,
|
|
44
|
+
// A webhook action sends its webhook row's payload, not this one. Kept
|
|
45
|
+
// free of placeholders: the action is part of what the webhook inserts,
|
|
46
|
+
// and with JsonPath templating a placeholder in it was expanded again on
|
|
47
|
+
// every pass — open.WARE never finished.
|
|
48
|
+
payload: ACTION_PAYLOAD,
|
|
49
|
+
// Every value type can breach a rule, so every type may fire the action.
|
|
50
|
+
supportedTypes: ["Number", "String", "Boolean", "Geo", "Object"],
|
|
51
|
+
formFields: definition.formFields,
|
|
52
|
+
};
|
|
53
|
+
// Without a webhook the target stays as it is: pointing it elsewhere would
|
|
54
|
+
// not make the action work, only lose a hand-made setup.
|
|
55
|
+
if (webhookId)
|
|
56
|
+
wanted.target = webhookId;
|
|
57
|
+
const changed = Object.entries(wanted).filter(([key, value]) => JSON.stringify(action.get(key)) !== JSON.stringify(value));
|
|
58
|
+
if (changed.length === 0)
|
|
59
|
+
return;
|
|
60
|
+
for (const [key, value] of changed) {
|
|
61
|
+
action.set(key, value);
|
|
62
|
+
}
|
|
63
|
+
const created = !action.id;
|
|
64
|
+
await action.save(null, { useMasterKey: true });
|
|
65
|
+
console.log(`[AlarmAction] ${created ? "Registered" : "Updated"} "${definition.topic}" ` +
|
|
66
|
+
`(${changed.map(([key]) => key).join(", ")})`);
|
|
67
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create or update the `OD3_AlarmWebhook` row open.WARE runs for one of the
|
|
3
|
+
* open.SERVICE alarm actions, and return its id — the action's `target`.
|
|
4
|
+
*
|
|
5
|
+
* How open.WARE carries a webhook action out (`WebHookActuator`): it reads the
|
|
6
|
+
* row whose objectId is the alarm's `action.target`, fills the placeholders
|
|
7
|
+
* in its header and payload from the fired alarm (Velocity, see
|
|
8
|
+
* `OPENWARE_TEMPLATE_TYPE`), and sends the request to its
|
|
9
|
+
* `url` as given — so the url must be **absolute** and reachable from
|
|
10
|
+
* open.WARE, and Parse's application id has to be among the headers.
|
|
11
|
+
*
|
|
12
|
+
* The row is the server's own, found by its name, and kept exactly as written
|
|
13
|
+
* here: the url follows the configuration, the token follows the JWT secret.
|
|
14
|
+
* It is global (no tenant) like the actions; the tenant of a call is the
|
|
15
|
+
* alarm owner's. Only global administrators may read it, because the token is
|
|
16
|
+
* in it — open.WARE reads with the master key.
|
|
17
|
+
*
|
|
18
|
+
* Returns `undefined`, with a warning, when the server cannot authenticate
|
|
19
|
+
* open.WARE (no JWT secret) or does not know its own URL: then the action is
|
|
20
|
+
* left as it is rather than pointed at a row that cannot work.
|
|
21
|
+
*/
|
|
22
|
+
export declare function ensureOpenwareWebhook(name: string, functionName: string, comment: string): Promise<string | undefined>;
|
|
@@ -0,0 +1,81 @@
|
|
|
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.ensureOpenwareWebhook = ensureOpenwareWebhook;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const index_js_2 = require("../../config/index.js");
|
|
10
|
+
const openwareAlarm_js_1 = require("./openwareAlarm.js");
|
|
11
|
+
/**
|
|
12
|
+
* Create or update the `OD3_AlarmWebhook` row open.WARE runs for one of the
|
|
13
|
+
* open.SERVICE alarm actions, and return its id — the action's `target`.
|
|
14
|
+
*
|
|
15
|
+
* How open.WARE carries a webhook action out (`WebHookActuator`): it reads the
|
|
16
|
+
* row whose objectId is the alarm's `action.target`, fills the placeholders
|
|
17
|
+
* in its header and payload from the fired alarm (Velocity, see
|
|
18
|
+
* `OPENWARE_TEMPLATE_TYPE`), and sends the request to its
|
|
19
|
+
* `url` as given — so the url must be **absolute** and reachable from
|
|
20
|
+
* open.WARE, and Parse's application id has to be among the headers.
|
|
21
|
+
*
|
|
22
|
+
* The row is the server's own, found by its name, and kept exactly as written
|
|
23
|
+
* here: the url follows the configuration, the token follows the JWT secret.
|
|
24
|
+
* It is global (no tenant) like the actions; the tenant of a call is the
|
|
25
|
+
* alarm owner's. Only global administrators may read it, because the token is
|
|
26
|
+
* in it — open.WARE reads with the master key.
|
|
27
|
+
*
|
|
28
|
+
* Returns `undefined`, with a warning, when the server cannot authenticate
|
|
29
|
+
* open.WARE (no JWT secret) or does not know its own URL: then the action is
|
|
30
|
+
* left as it is rather than pointed at a row that cannot work.
|
|
31
|
+
*/
|
|
32
|
+
async function ensureOpenwareWebhook(name, functionName, comment) {
|
|
33
|
+
const config = index_js_2.ConfigInstance.getInstance();
|
|
34
|
+
const secret = config.get("OPENWARE_JWT_SECRET");
|
|
35
|
+
// Parse's own address inside the stack (`PARSE_SERVER_URL`) — where
|
|
36
|
+
// open.WARE, running next to it, reaches it too. The public URL only if
|
|
37
|
+
// that is unset: it works from anywhere but takes the detour through the
|
|
38
|
+
// proxy, and in a local stack it is `localhost`, which from inside the
|
|
39
|
+
// open.WARE container is open.WARE itself.
|
|
40
|
+
const baseUrl = (node_1.default.serverURL ||
|
|
41
|
+
config.get("PARSE_PUBLIC_SERVER_URL") ||
|
|
42
|
+
"").replace(/\/+$/, "");
|
|
43
|
+
if (!secret || !baseUrl) {
|
|
44
|
+
console.warn(`[AlarmWebhook] "${name}" not set up: ` +
|
|
45
|
+
(!secret
|
|
46
|
+
? "PARSE_SERVER_OPENWARE_JWT_SECRET is missing"
|
|
47
|
+
: "no URL (PARSE_SERVER_URL / PARSE_PUBLIC_SERVER_URL)"));
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
const wanted = {
|
|
51
|
+
name,
|
|
52
|
+
url: `${baseUrl}/functions/${functionName}`,
|
|
53
|
+
method: "POST",
|
|
54
|
+
header: {
|
|
55
|
+
"Content-Type": "application/json",
|
|
56
|
+
"X-Parse-Application-Id": node_1.default.applicationId,
|
|
57
|
+
[openwareAlarm_js_1.ALARM_WEBHOOK_TOKEN_HEADER]: (0, openwareAlarm_js_1.alarmWebhookToken)(secret),
|
|
58
|
+
},
|
|
59
|
+
payload: openwareAlarm_js_1.OPENWARE_WEBHOOK_PAYLOAD,
|
|
60
|
+
extraOptions: {},
|
|
61
|
+
comment,
|
|
62
|
+
};
|
|
63
|
+
const webhook = (await new node_1.default.Query(index_js_1.AlarmWebhook)
|
|
64
|
+
.equalTo("name", name)
|
|
65
|
+
.first({ useMasterKey: true })) ?? new index_js_1.AlarmWebhook();
|
|
66
|
+
const changed = Object.entries(wanted).filter(([key, value]) => JSON.stringify(webhook.get(key)) !== JSON.stringify(value));
|
|
67
|
+
if (changed.length === 0)
|
|
68
|
+
return webhook.id;
|
|
69
|
+
for (const [key, value] of changed) {
|
|
70
|
+
webhook.set(key, value);
|
|
71
|
+
}
|
|
72
|
+
const acl = new node_1.default.ACL();
|
|
73
|
+
acl.setRoleReadAccess("od-admin", true);
|
|
74
|
+
acl.setRoleWriteAccess("od-admin", true);
|
|
75
|
+
webhook.setACL(acl);
|
|
76
|
+
const created = !webhook.id;
|
|
77
|
+
await webhook.save(null, { useMasterKey: true });
|
|
78
|
+
console.log(`[AlarmWebhook] ${created ? "Registered" : "Updated"} "${name}" ` +
|
|
79
|
+
`(${changed.map(([key]) => key).join(", ")})`);
|
|
80
|
+
return webhook.id;
|
|
81
|
+
}
|
|
@@ -9,6 +9,14 @@
|
|
|
9
9
|
* them would silently start creating duplicates. `README.md` has the wiring.
|
|
10
10
|
*/
|
|
11
11
|
export { alarmDetailLines, alarmKey, alarmOrigin, firedAt, formatValue, renderTitleTemplate, sensorLabel, } from "./alarmIdentity.js";
|
|
12
|
+
export { ensureAlarmActionRow } from "./ensureAlarmActionRow.js";
|
|
13
|
+
export type { AlarmActionDefinition } from "./ensureAlarmActionRow.js";
|
|
14
|
+
export { ensureOpenwareWebhook } from "./ensureOpenwareWebhook.js";
|
|
15
|
+
export { ALARM_WEBHOOK_TOKEN_HEADER, OPENWARE_TEMPLATE_TYPE, OPENWARE_WEBHOOK_PAYLOAD, alarmWebhookToken, describeTrigger, fromOpenwareAlarm, isAlarmWebhookToken, } from "./openwareAlarm.js";
|
|
16
|
+
export type { OpenwareAlarm } from "./openwareAlarm.js";
|
|
17
|
+
export { readAlarmCall } from "./readAlarmCall.js";
|
|
18
|
+
export type { AlarmCall } from "./readAlarmCall.js";
|
|
19
|
+
export { resolveAlarmUser } from "./resolveAlarmUser.js";
|
|
12
20
|
export { resolveEquipment } from "./resolveEquipment.js";
|
|
13
21
|
export { tenantForSecret } from "./tenantForSecret.js";
|
|
14
22
|
export type { AlarmEvent } from "./AlarmEvent.js";
|
|
@@ -23,6 +31,6 @@ export { alarmScheduleFields, dueDate, } from "./schedule/alarmScheduleFields.js
|
|
|
23
31
|
export type { AlarmScheduleFields } from "./schedule/alarmScheduleFields.js";
|
|
24
32
|
export { createAlarmSchedule, tenantForAlarmSchedule, } from "./schedule/createAlarmSchedule.js";
|
|
25
33
|
export type { AlarmScheduleResult } from "./schedule/createAlarmSchedule.js";
|
|
26
|
-
export { ensureAlarmScheduleAction
|
|
34
|
+
export { ensureAlarmScheduleAction } from "./schedule/ensureAlarmScheduleAction.js";
|
|
27
35
|
export { ALARM_SCHEDULE_ACTION_ID, ALARM_SCHEDULE_SECRET_CONFIG_KEY, } from "./schedule/AlarmScheduleTypes.js";
|
|
28
36
|
export type { AlarmScheduleParams, ScheduleAlarmContext, } from "./schedule/AlarmScheduleTypes.js";
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* them would silently start creating duplicates. `README.md` has the wiring.
|
|
11
11
|
*/
|
|
12
12
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
exports.ALARM_SCHEDULE_SECRET_CONFIG_KEY = exports.ALARM_SCHEDULE_ACTION_ID = exports.
|
|
13
|
+
exports.ALARM_SCHEDULE_SECRET_CONFIG_KEY = exports.ALARM_SCHEDULE_ACTION_ID = exports.ensureAlarmScheduleAction = exports.tenantForAlarmSchedule = exports.createAlarmSchedule = exports.dueDate = exports.alarmScheduleFields = exports.ALARM_TICKET_SECRET_CONFIG_KEY = exports.ALARM_TICKET_ACTION_ID = exports.ensureAlarmTicketAction = exports.tenantForAlarmTicket = exports.createAlarmTicket = exports.alarmTicketFields = exports.tenantForSecret = exports.resolveEquipment = exports.resolveAlarmUser = exports.readAlarmCall = exports.isAlarmWebhookToken = exports.fromOpenwareAlarm = exports.describeTrigger = exports.alarmWebhookToken = exports.OPENWARE_WEBHOOK_PAYLOAD = exports.OPENWARE_TEMPLATE_TYPE = exports.ALARM_WEBHOOK_TOKEN_HEADER = exports.ensureOpenwareWebhook = exports.ensureAlarmActionRow = exports.sensorLabel = exports.renderTitleTemplate = exports.formatValue = exports.firedAt = exports.alarmOrigin = exports.alarmKey = exports.alarmDetailLines = void 0;
|
|
14
14
|
// The shared base, here at the root because both actions read it: payload
|
|
15
15
|
// shape, identity, and the two lookups every action needs.
|
|
16
16
|
var alarmIdentity_js_1 = require("./alarmIdentity.js");
|
|
@@ -21,6 +21,22 @@ Object.defineProperty(exports, "firedAt", { enumerable: true, get: function () {
|
|
|
21
21
|
Object.defineProperty(exports, "formatValue", { enumerable: true, get: function () { return alarmIdentity_js_1.formatValue; } });
|
|
22
22
|
Object.defineProperty(exports, "renderTitleTemplate", { enumerable: true, get: function () { return alarmIdentity_js_1.renderTitleTemplate; } });
|
|
23
23
|
Object.defineProperty(exports, "sensorLabel", { enumerable: true, get: function () { return alarmIdentity_js_1.sensorLabel; } });
|
|
24
|
+
var ensureAlarmActionRow_js_1 = require("./ensureAlarmActionRow.js");
|
|
25
|
+
Object.defineProperty(exports, "ensureAlarmActionRow", { enumerable: true, get: function () { return ensureAlarmActionRow_js_1.ensureAlarmActionRow; } });
|
|
26
|
+
var ensureOpenwareWebhook_js_1 = require("./ensureOpenwareWebhook.js");
|
|
27
|
+
Object.defineProperty(exports, "ensureOpenwareWebhook", { enumerable: true, get: function () { return ensureOpenwareWebhook_js_1.ensureOpenwareWebhook; } });
|
|
28
|
+
var openwareAlarm_js_1 = require("./openwareAlarm.js");
|
|
29
|
+
Object.defineProperty(exports, "ALARM_WEBHOOK_TOKEN_HEADER", { enumerable: true, get: function () { return openwareAlarm_js_1.ALARM_WEBHOOK_TOKEN_HEADER; } });
|
|
30
|
+
Object.defineProperty(exports, "OPENWARE_TEMPLATE_TYPE", { enumerable: true, get: function () { return openwareAlarm_js_1.OPENWARE_TEMPLATE_TYPE; } });
|
|
31
|
+
Object.defineProperty(exports, "OPENWARE_WEBHOOK_PAYLOAD", { enumerable: true, get: function () { return openwareAlarm_js_1.OPENWARE_WEBHOOK_PAYLOAD; } });
|
|
32
|
+
Object.defineProperty(exports, "alarmWebhookToken", { enumerable: true, get: function () { return openwareAlarm_js_1.alarmWebhookToken; } });
|
|
33
|
+
Object.defineProperty(exports, "describeTrigger", { enumerable: true, get: function () { return openwareAlarm_js_1.describeTrigger; } });
|
|
34
|
+
Object.defineProperty(exports, "fromOpenwareAlarm", { enumerable: true, get: function () { return openwareAlarm_js_1.fromOpenwareAlarm; } });
|
|
35
|
+
Object.defineProperty(exports, "isAlarmWebhookToken", { enumerable: true, get: function () { return openwareAlarm_js_1.isAlarmWebhookToken; } });
|
|
36
|
+
var readAlarmCall_js_1 = require("./readAlarmCall.js");
|
|
37
|
+
Object.defineProperty(exports, "readAlarmCall", { enumerable: true, get: function () { return readAlarmCall_js_1.readAlarmCall; } });
|
|
38
|
+
var resolveAlarmUser_js_1 = require("./resolveAlarmUser.js");
|
|
39
|
+
Object.defineProperty(exports, "resolveAlarmUser", { enumerable: true, get: function () { return resolveAlarmUser_js_1.resolveAlarmUser; } });
|
|
24
40
|
var resolveEquipment_js_1 = require("./resolveEquipment.js");
|
|
25
41
|
Object.defineProperty(exports, "resolveEquipment", { enumerable: true, get: function () { return resolveEquipment_js_1.resolveEquipment; } });
|
|
26
42
|
var tenantForSecret_js_1 = require("./tenantForSecret.js");
|
|
@@ -45,7 +61,6 @@ Object.defineProperty(exports, "createAlarmSchedule", { enumerable: true, get: f
|
|
|
45
61
|
Object.defineProperty(exports, "tenantForAlarmSchedule", { enumerable: true, get: function () { return createAlarmSchedule_js_1.tenantForAlarmSchedule; } });
|
|
46
62
|
var ensureAlarmScheduleAction_js_1 = require("./schedule/ensureAlarmScheduleAction.js");
|
|
47
63
|
Object.defineProperty(exports, "ensureAlarmScheduleAction", { enumerable: true, get: function () { return ensureAlarmScheduleAction_js_1.ensureAlarmScheduleAction; } });
|
|
48
|
-
Object.defineProperty(exports, "ensureAlarmScheduleWebhook", { enumerable: true, get: function () { return ensureAlarmScheduleAction_js_1.ensureAlarmScheduleWebhook; } });
|
|
49
64
|
var AlarmScheduleTypes_js_1 = require("./schedule/AlarmScheduleTypes.js");
|
|
50
65
|
Object.defineProperty(exports, "ALARM_SCHEDULE_ACTION_ID", { enumerable: true, get: function () { return AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID; } });
|
|
51
66
|
Object.defineProperty(exports, "ALARM_SCHEDULE_SECRET_CONFIG_KEY", { enumerable: true, get: function () { return AlarmScheduleTypes_js_1.ALARM_SCHEDULE_SECRET_CONFIG_KEY; } });
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { AlarmEvent } from "./AlarmEvent.js";
|
|
2
|
+
/**
|
|
3
|
+
* What open.WARE knows about a fired alarm — the `options` its alarm monitor
|
|
4
|
+
* (`AlarmMonitorThreadV2`) hands every actuator: the alarm's `action` as the
|
|
5
|
+
* dialog stored it, plus what fired.
|
|
6
|
+
*
|
|
7
|
+
* The webhook rows post it whole (`{"alarm":${options}}`), so nothing here
|
|
8
|
+
* depends on open.WARE's template syntax beyond that one placeholder.
|
|
9
|
+
*/
|
|
10
|
+
export interface OpenwareAlarm extends Record<string, unknown> {
|
|
11
|
+
/** The alarm's name. */
|
|
12
|
+
name?: string;
|
|
13
|
+
/** The sensor value that broke the rule. */
|
|
14
|
+
item?: {
|
|
15
|
+
id?: string;
|
|
16
|
+
source?: string;
|
|
17
|
+
dimension?: number | string;
|
|
18
|
+
value?: number | string | boolean;
|
|
19
|
+
/** Milliseconds since epoch. */
|
|
20
|
+
timestamp?: number | string;
|
|
21
|
+
};
|
|
22
|
+
/** `OD3_Alarm.trigger`, e.g. `{ type: "number_gt", value: 10 }`. */
|
|
23
|
+
trigger?: {
|
|
24
|
+
type?: string;
|
|
25
|
+
value?: unknown;
|
|
26
|
+
};
|
|
27
|
+
/** The alarm's owner as open.WARE knows them; `uid` is the Parse objectId. */
|
|
28
|
+
user?: {
|
|
29
|
+
uid?: string;
|
|
30
|
+
};
|
|
31
|
+
/** Set only if something put it into the alarm's action. */
|
|
32
|
+
alarmId?: string;
|
|
33
|
+
}
|
|
34
|
+
/** Header the webhook rows send, carrying {@link alarmWebhookToken}. */
|
|
35
|
+
export declare const ALARM_WEBHOOK_TOKEN_HEADER = "x-openservice-alarm-token";
|
|
36
|
+
/**
|
|
37
|
+
* How open.WARE fills the open.SERVICE webhooks: Velocity. Read from the
|
|
38
|
+
* alarm's action (`OD3_Alarm.action.templateType`), not from the webhook row.
|
|
39
|
+
*
|
|
40
|
+
* Not the default JsonPath templating (`{{#$.options#}}`): that writes an
|
|
41
|
+
* object as a Java map (`{type=webhook, item={…}}`), which is not JSON.
|
|
42
|
+
* Velocity is handed `options` as a JSON object and prints it as JSON.
|
|
43
|
+
*/
|
|
44
|
+
export declare const OPENWARE_TEMPLATE_TYPE = "vtl";
|
|
45
|
+
/**
|
|
46
|
+
* The payload of the open.SERVICE webhook rows: the whole
|
|
47
|
+
* {@link OpenwareAlarm}, which Velocity prints as JSON — hence no quotes
|
|
48
|
+
* around it. Velocity does not evaluate what it inserts, so a placeholder
|
|
49
|
+
* inside the alarm's own settings stays text.
|
|
50
|
+
*/
|
|
51
|
+
export declare const OPENWARE_WEBHOOK_PAYLOAD = "{\"alarm\":${options}}";
|
|
52
|
+
/**
|
|
53
|
+
* The token open.WARE's webhook calls authenticate with.
|
|
54
|
+
*
|
|
55
|
+
* Derived from the JWT secret Parse and open.WARE already share, so there is
|
|
56
|
+
* nothing extra to configure and rotating that secret rotates this too. It is
|
|
57
|
+
* an HMAC, not the secret itself and not a JWT: whoever reads it off a webhook
|
|
58
|
+
* row can neither recover the secret nor call open.WARE's API with it.
|
|
59
|
+
*/
|
|
60
|
+
export declare function alarmWebhookToken(jwtSecret: string): string;
|
|
61
|
+
/** Constant-time comparison of a received token with the expected one. */
|
|
62
|
+
export declare function isAlarmWebhookToken(received: unknown, jwtSecret: string | undefined): boolean;
|
|
63
|
+
/** A rule as a person reads it: `> 10` rather than `number_gt`. */
|
|
64
|
+
export declare function describeTrigger(trigger: OpenwareAlarm["trigger"]): string;
|
|
65
|
+
/**
|
|
66
|
+
* open.WARE's alarm as the event and action parameters the endpoints take.
|
|
67
|
+
*
|
|
68
|
+
* The parameters are the action itself — the dialog stores the action's
|
|
69
|
+
* settings on it (`ticket`, `formConfigId`, `duplicate`, …) — without what
|
|
70
|
+
* open.WARE added about the firing. In particular `user`, which carries the
|
|
71
|
+
* owner's roles and permissions and has no business in a ticket.
|
|
72
|
+
*/
|
|
73
|
+
export declare function fromOpenwareAlarm<P extends object>(alarm: OpenwareAlarm): {
|
|
74
|
+
event: AlarmEvent;
|
|
75
|
+
params: P;
|
|
76
|
+
};
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.OPENWARE_WEBHOOK_PAYLOAD = exports.OPENWARE_TEMPLATE_TYPE = exports.ALARM_WEBHOOK_TOKEN_HEADER = void 0;
|
|
4
|
+
exports.alarmWebhookToken = alarmWebhookToken;
|
|
5
|
+
exports.isAlarmWebhookToken = isAlarmWebhookToken;
|
|
6
|
+
exports.describeTrigger = describeTrigger;
|
|
7
|
+
exports.fromOpenwareAlarm = fromOpenwareAlarm;
|
|
8
|
+
const node_crypto_1 = require("node:crypto");
|
|
9
|
+
/** Header the webhook rows send, carrying {@link alarmWebhookToken}. */
|
|
10
|
+
exports.ALARM_WEBHOOK_TOKEN_HEADER = "x-openservice-alarm-token";
|
|
11
|
+
/**
|
|
12
|
+
* How open.WARE fills the open.SERVICE webhooks: Velocity. Read from the
|
|
13
|
+
* alarm's action (`OD3_Alarm.action.templateType`), not from the webhook row.
|
|
14
|
+
*
|
|
15
|
+
* Not the default JsonPath templating (`{{#$.options#}}`): that writes an
|
|
16
|
+
* object as a Java map (`{type=webhook, item={…}}`), which is not JSON.
|
|
17
|
+
* Velocity is handed `options` as a JSON object and prints it as JSON.
|
|
18
|
+
*/
|
|
19
|
+
exports.OPENWARE_TEMPLATE_TYPE = "vtl";
|
|
20
|
+
/**
|
|
21
|
+
* The payload of the open.SERVICE webhook rows: the whole
|
|
22
|
+
* {@link OpenwareAlarm}, which Velocity prints as JSON — hence no quotes
|
|
23
|
+
* around it. Velocity does not evaluate what it inserts, so a placeholder
|
|
24
|
+
* inside the alarm's own settings stays text.
|
|
25
|
+
*/
|
|
26
|
+
exports.OPENWARE_WEBHOOK_PAYLOAD = '{"alarm":${options}}';
|
|
27
|
+
/**
|
|
28
|
+
* The token open.WARE's webhook calls authenticate with.
|
|
29
|
+
*
|
|
30
|
+
* Derived from the JWT secret Parse and open.WARE already share, so there is
|
|
31
|
+
* nothing extra to configure and rotating that secret rotates this too. It is
|
|
32
|
+
* an HMAC, not the secret itself and not a JWT: whoever reads it off a webhook
|
|
33
|
+
* row can neither recover the secret nor call open.WARE's API with it.
|
|
34
|
+
*/
|
|
35
|
+
function alarmWebhookToken(jwtSecret) {
|
|
36
|
+
return (0, node_crypto_1.createHmac)("sha256", jwtSecret)
|
|
37
|
+
.update("openservice-alarm-webhook")
|
|
38
|
+
.digest("hex");
|
|
39
|
+
}
|
|
40
|
+
/** Constant-time comparison of a received token with the expected one. */
|
|
41
|
+
function isAlarmWebhookToken(received, jwtSecret) {
|
|
42
|
+
if (!jwtSecret || typeof received !== "string" || !received)
|
|
43
|
+
return false;
|
|
44
|
+
const expected = Buffer.from(alarmWebhookToken(jwtSecret));
|
|
45
|
+
const actual = Buffer.from(received);
|
|
46
|
+
return actual.length === expected.length && (0, node_crypto_1.timingSafeEqual)(actual, expected);
|
|
47
|
+
}
|
|
48
|
+
const TRIGGER_OPERATORS = {
|
|
49
|
+
number_gt: ">",
|
|
50
|
+
number_lt: "<",
|
|
51
|
+
number_equals: "=",
|
|
52
|
+
number_not_equals: "≠",
|
|
53
|
+
string_equals: "=",
|
|
54
|
+
string_not_equals: "≠",
|
|
55
|
+
boolean_true: "= wahr",
|
|
56
|
+
boolean_false: "= falsch",
|
|
57
|
+
};
|
|
58
|
+
/** A rule as a person reads it: `> 10` rather than `number_gt`. */
|
|
59
|
+
function describeTrigger(trigger) {
|
|
60
|
+
if (!trigger?.type)
|
|
61
|
+
return "";
|
|
62
|
+
const operator = TRIGGER_OPERATORS[trigger.type];
|
|
63
|
+
const value = trigger.value == null || typeof trigger.value === "object"
|
|
64
|
+
? ""
|
|
65
|
+
: String(trigger.value);
|
|
66
|
+
if (!operator)
|
|
67
|
+
return [trigger.type, value].filter(Boolean).join(" ");
|
|
68
|
+
return [operator, value].filter(Boolean).join(" ");
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* open.WARE's alarm as the event and action parameters the endpoints take.
|
|
72
|
+
*
|
|
73
|
+
* The parameters are the action itself — the dialog stores the action's
|
|
74
|
+
* settings on it (`ticket`, `formConfigId`, `duplicate`, …) — without what
|
|
75
|
+
* open.WARE added about the firing. In particular `user`, which carries the
|
|
76
|
+
* owner's roles and permissions and has no business in a ticket.
|
|
77
|
+
*/
|
|
78
|
+
function fromOpenwareAlarm(alarm) {
|
|
79
|
+
const { item, trigger, user, name, start: _start, end: _end, ...action } = alarm;
|
|
80
|
+
const timestamp = Number(item?.timestamp);
|
|
81
|
+
const dimension = Number(item?.dimension);
|
|
82
|
+
const event = {
|
|
83
|
+
alarmId: typeof alarm.alarmId === "string" ? alarm.alarmId : undefined,
|
|
84
|
+
name: typeof name === "string" ? name : undefined,
|
|
85
|
+
userId: typeof user?.uid === "string" ? user.uid : undefined,
|
|
86
|
+
item_id: item?.id,
|
|
87
|
+
item_source: item?.source,
|
|
88
|
+
item_dimension: Number.isFinite(dimension) ? dimension : undefined,
|
|
89
|
+
value: item?.value,
|
|
90
|
+
condition: describeTrigger(trigger) || undefined,
|
|
91
|
+
firedAt: Number.isFinite(timestamp)
|
|
92
|
+
? new Date(timestamp).toISOString()
|
|
93
|
+
: undefined,
|
|
94
|
+
};
|
|
95
|
+
return { event, params: action };
|
|
96
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Tenant } from "../../../types/index.js";
|
|
2
|
+
import type { AlarmEvent } from "./AlarmEvent.js";
|
|
3
|
+
/** One authenticated call of an alarm action endpoint. */
|
|
4
|
+
export interface AlarmCall<P> {
|
|
5
|
+
tenant: Tenant;
|
|
6
|
+
event: AlarmEvent;
|
|
7
|
+
params: P;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Authenticate a call of an alarm action endpoint and read what it reports.
|
|
11
|
+
*
|
|
12
|
+
* Two shapes:
|
|
13
|
+
*
|
|
14
|
+
* - **open.WARE** (`{ alarm }`, see `ensureOpenwareWebhook`): the request
|
|
15
|
+
* carries the webhook token; the tenant is the alarm owner's. open.WARE is
|
|
16
|
+
* the one that evaluated the alarm, so the owner it reports is the alarm's.
|
|
17
|
+
* - **direct** (`{ event, params, secret?, tenantId? }`): the master key with
|
|
18
|
+
* a `tenantId`, or a tenant's shared secret, which names the tenant.
|
|
19
|
+
*
|
|
20
|
+
* A logged-in user is not enough on either: these are machine endpoints, and
|
|
21
|
+
* a browser session should not be able to fabricate alarm results.
|
|
22
|
+
*
|
|
23
|
+
* Every failure to authenticate gets the same answer, so a caller guessing
|
|
24
|
+
* tokens or secrets learns nothing from the difference.
|
|
25
|
+
*/
|
|
26
|
+
export declare function readAlarmCall<P extends object>(name: string, request: Parse.Cloud.FunctionRequest, tenantForSecret: (secret: string) => Promise<Tenant | undefined>): Promise<AlarmCall<P>>;
|
|
@@ -0,0 +1,67 @@
|
|
|
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.readAlarmCall = readAlarmCall;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const index_js_1 = require("../../../types/index.js");
|
|
9
|
+
const index_js_2 = require("../../config/index.js");
|
|
10
|
+
const openwareAlarm_js_1 = require("./openwareAlarm.js");
|
|
11
|
+
/**
|
|
12
|
+
* Authenticate a call of an alarm action endpoint and read what it reports.
|
|
13
|
+
*
|
|
14
|
+
* Two shapes:
|
|
15
|
+
*
|
|
16
|
+
* - **open.WARE** (`{ alarm }`, see `ensureOpenwareWebhook`): the request
|
|
17
|
+
* carries the webhook token; the tenant is the alarm owner's. open.WARE is
|
|
18
|
+
* the one that evaluated the alarm, so the owner it reports is the alarm's.
|
|
19
|
+
* - **direct** (`{ event, params, secret?, tenantId? }`): the master key with
|
|
20
|
+
* a `tenantId`, or a tenant's shared secret, which names the tenant.
|
|
21
|
+
*
|
|
22
|
+
* A logged-in user is not enough on either: these are machine endpoints, and
|
|
23
|
+
* a browser session should not be able to fabricate alarm results.
|
|
24
|
+
*
|
|
25
|
+
* Every failure to authenticate gets the same answer, so a caller guessing
|
|
26
|
+
* tokens or secrets learns nothing from the difference.
|
|
27
|
+
*/
|
|
28
|
+
async function readAlarmCall(name, request, tenantForSecret) {
|
|
29
|
+
const body = request.params;
|
|
30
|
+
const forbidden = () => new node_1.default.Error(node_1.default.Error.OPERATION_FORBIDDEN, `${name}: unknown tenant or invalid credentials`);
|
|
31
|
+
if (body.alarm && typeof body.alarm === "object") {
|
|
32
|
+
const token = request.headers?.[openwareAlarm_js_1.ALARM_WEBHOOK_TOKEN_HEADER];
|
|
33
|
+
const secret = index_js_2.ConfigInstance.getInstance().get("OPENWARE_JWT_SECRET");
|
|
34
|
+
if (!(0, openwareAlarm_js_1.isAlarmWebhookToken)(token, secret))
|
|
35
|
+
throw forbidden();
|
|
36
|
+
const { event, params } = (0, openwareAlarm_js_1.fromOpenwareAlarm)(body.alarm);
|
|
37
|
+
const tenant = await tenantOfUser(event.userId);
|
|
38
|
+
if (!tenant)
|
|
39
|
+
throw forbidden();
|
|
40
|
+
return { tenant, event, params };
|
|
41
|
+
}
|
|
42
|
+
if (!body.event || typeof body.event !== "object") {
|
|
43
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${name} needs an "event" object describing the alarm`);
|
|
44
|
+
}
|
|
45
|
+
const tenant = request.master
|
|
46
|
+
? await tenantById(body.tenantId)
|
|
47
|
+
: await tenantForSecret(typeof body.secret === "string" ? body.secret : "");
|
|
48
|
+
if (!tenant)
|
|
49
|
+
throw forbidden();
|
|
50
|
+
return { tenant, event: body.event, params: body.params ?? {} };
|
|
51
|
+
}
|
|
52
|
+
async function tenantById(tenantId) {
|
|
53
|
+
if (!tenantId)
|
|
54
|
+
return undefined;
|
|
55
|
+
return ((await new node_1.default.Query(index_js_1.Tenant)
|
|
56
|
+
.equalTo("objectId", tenantId)
|
|
57
|
+
.first({ useMasterKey: true })) ?? undefined);
|
|
58
|
+
}
|
|
59
|
+
async function tenantOfUser(userId) {
|
|
60
|
+
if (!userId)
|
|
61
|
+
return undefined;
|
|
62
|
+
const user = await new node_1.default.Query(node_1.default.User)
|
|
63
|
+
.equalTo("objectId", userId)
|
|
64
|
+
.include("tenant")
|
|
65
|
+
.first({ useMasterKey: true });
|
|
66
|
+
return user?.get("tenant") ?? undefined;
|
|
67
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
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>;
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
}
|
|
@@ -9,6 +9,7 @@ const node_1 = __importDefault(require("parse/node"));
|
|
|
9
9
|
const index_js_1 = require("../../../../types/index.js");
|
|
10
10
|
const actionParams_js_1 = require("../actionParams.js");
|
|
11
11
|
const alarmIdentity_js_1 = require("../alarmIdentity.js");
|
|
12
|
+
const resolveAlarmUser_js_1 = require("../resolveAlarmUser.js");
|
|
12
13
|
const resolveEquipment_js_1 = require("../resolveEquipment.js");
|
|
13
14
|
const tenantForSecret_js_1 = require("../tenantForSecret.js");
|
|
14
15
|
const alarmScheduleFields_js_1 = require("./alarmScheduleFields.js");
|
|
@@ -77,7 +78,7 @@ async function createAlarmSchedule(tenant, event, rawParams = {}) {
|
|
|
77
78
|
// Who the plan belongs to. Without it `syncAssignmentAcl` grants nobody but
|
|
78
79
|
// administrators, so the person who configured the alarm would not see what
|
|
79
80
|
// it produced.
|
|
80
|
-
const owner = await
|
|
81
|
+
const owner = await (0, resolveAlarmUser_js_1.resolveAlarmUser)(tenant, event.userId, `[${AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID}]`);
|
|
81
82
|
if (owner)
|
|
82
83
|
schedule.set("user", owner);
|
|
83
84
|
await schedule.save(null, { useMasterKey: true });
|
|
@@ -164,13 +165,6 @@ async function templateRoles(template) {
|
|
|
164
165
|
.query()
|
|
165
166
|
.find({ useMasterKey: true });
|
|
166
167
|
}
|
|
167
|
-
async function resolveUser(userId) {
|
|
168
|
-
if (!userId)
|
|
169
|
-
return undefined;
|
|
170
|
-
return ((await new node_1.default.Query("_User")
|
|
171
|
-
.equalTo("objectId", userId)
|
|
172
|
-
.first({ useMasterKey: true })) ?? undefined);
|
|
173
|
-
}
|
|
174
168
|
/** The appointment date of an existing one-off, read back from its cadence. */
|
|
175
169
|
function dueOf(schedule) {
|
|
176
170
|
const cadence = schedule.get("cadence");
|