@openinc/parse-server-opendash 4.38.1 → 4.39.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/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 -2
- 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/Service_Schedule_Execution.js +35 -0
- package/package.json +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,57 @@
|
|
|
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.statusById = statusById;
|
|
7
|
+
exports.isStatusCategory = isStatusCategory;
|
|
8
|
+
exports.statusByCategory = statusByCategory;
|
|
9
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
10
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
11
|
+
const index_js_1 = require("../../../types/index.js");
|
|
12
|
+
/**
|
|
13
|
+
* Which status a ticket created or moved from outside gets.
|
|
14
|
+
*
|
|
15
|
+
* A caller rarely knows a tenant's status ids — they are master data, named
|
|
16
|
+
* however the tenant likes. The **category** is the contract (`inbox`,
|
|
17
|
+
* `active`, `pending`, `done`, `cancelled`), so a caller may name that
|
|
18
|
+
* instead and gets the tenant's first status of it.
|
|
19
|
+
*
|
|
20
|
+
* Always the tenant's own or a global one — never another tenant's.
|
|
21
|
+
*/
|
|
22
|
+
/** A status by id, if it is the tenant's or a global one and not archived. */
|
|
23
|
+
async function statusById(tenant, statusId, logPrefix) {
|
|
24
|
+
if (!statusId)
|
|
25
|
+
return undefined;
|
|
26
|
+
const status = await tenantOrGlobal(tenant)
|
|
27
|
+
.equalTo("objectId", statusId)
|
|
28
|
+
.equalTo("deleted", false)
|
|
29
|
+
.first({ useMasterKey: true });
|
|
30
|
+
if (!status) {
|
|
31
|
+
console.warn(`${logPrefix} Status ${statusId} is not available here`);
|
|
32
|
+
}
|
|
33
|
+
return status;
|
|
34
|
+
}
|
|
35
|
+
/** Whether `value` names a status category. */
|
|
36
|
+
function isStatusCategory(value) {
|
|
37
|
+
return (typeof value === "string" &&
|
|
38
|
+
openservice_shared_1.STATUS_CATEGORIES.includes(value));
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* The tenant's first status (by `order`) of a category, else a global one.
|
|
42
|
+
* Without a category: the inbox — where a new ticket lands.
|
|
43
|
+
*/
|
|
44
|
+
async function statusByCategory(tenant, category = openservice_shared_1.DEFAULT_STATUS_CATEGORY) {
|
|
45
|
+
// Only this tenant's and the global ones: across all tenants a plain `find`
|
|
46
|
+
// stopped at the default limit (100) and could miss the tenant's own inbox.
|
|
47
|
+
const statuses = await tenantOrGlobal(tenant)
|
|
48
|
+
.equalTo("category", category)
|
|
49
|
+
.equalTo("deleted", false)
|
|
50
|
+
.ascending("order")
|
|
51
|
+
.limit(1000)
|
|
52
|
+
.find({ useMasterKey: true });
|
|
53
|
+
return (statuses.find((status) => status.get("tenant")?.id === tenant.id) ?? statuses.find((status) => !status.get("tenant")));
|
|
54
|
+
}
|
|
55
|
+
function tenantOrGlobal(tenant) {
|
|
56
|
+
return node_1.default.Query.or(new node_1.default.Query(index_js_1.Service_Status).equalTo("tenant", tenant), new node_1.default.Query(index_js_1.Service_Status).doesNotExist("tenant"));
|
|
57
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type _User, Tenant } from "../../../types/index.js";
|
|
2
|
+
/**
|
|
3
|
+
* A user of `tenant`, looked up by id — `undefined` for anything else.
|
|
4
|
+
*
|
|
5
|
+
* Used wherever a caller *names* a person the server then writes into a record
|
|
6
|
+
* that grants access: a ticket's `createdBy`, a plan's `user`, a protocol's
|
|
7
|
+
* `performedBy`, a comment's `author`. The tenant is established by the
|
|
8
|
+
* caller's credentials, 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. None of those fields is required, so dropping one is a
|
|
11
|
+
* warning, not an error.
|
|
12
|
+
*
|
|
13
|
+
* An alarm executor that does not fill its placeholder posts
|
|
14
|
+
* `"{{alarm.user}}"` literally; that matches no user and ends up the same way.
|
|
15
|
+
*/
|
|
16
|
+
export declare function resolveTenantUser(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.resolveTenantUser = resolveTenantUser;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const params_js_1 = require("./params.js");
|
|
9
|
+
/**
|
|
10
|
+
* A user of `tenant`, looked up by id — `undefined` for anything else.
|
|
11
|
+
*
|
|
12
|
+
* Used wherever a caller *names* a person the server then writes into a record
|
|
13
|
+
* that grants access: a ticket's `createdBy`, a plan's `user`, a protocol's
|
|
14
|
+
* `performedBy`, a comment's `author`. The tenant is established by the
|
|
15
|
+
* caller's credentials, 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. None of those fields is required, so dropping one is a
|
|
18
|
+
* warning, not an error.
|
|
19
|
+
*
|
|
20
|
+
* An alarm executor that does not fill its placeholder posts
|
|
21
|
+
* `"{{alarm.user}}"` literally; that matches no user and ends up the same way.
|
|
22
|
+
*/
|
|
23
|
+
async function resolveTenantUser(tenant, userId, logPrefix) {
|
|
24
|
+
const id = (0, params_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} User ${id} is not a user of this tenant — writing without one`);
|
|
33
|
+
}
|
|
34
|
+
return user ?? undefined;
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Values a ticket created from outside starts out with — the caller's template
|
|
3
|
+
* (the ticket form in template mode: an alarm's, a Node-RED node's) or what a
|
|
4
|
+
* form config pre-fills (`defaultValue` of its fields). Both in the form's edit
|
|
5
|
+
* shape: field values 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 a template that is applied later; the config's
|
|
9
|
+
* relative value rules still apply on save, and `createTicket` takes explicit
|
|
10
|
+
* dates as their own parameters), and so are the fields the server owns
|
|
11
|
+
* (tenant, number, origin, closedAt …). Title and description come back apart:
|
|
12
|
+
* a caller's own title wins over them, and an alarm appends its details to the
|
|
13
|
+
* description (`alarmTicketFields`). Whether a referenced row belongs to the
|
|
14
|
+
* tenant is the `Service_Ticket` hook's call, as on every write path.
|
|
15
|
+
*/
|
|
16
|
+
export interface TicketDefaults {
|
|
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): TicketDefaults;
|
|
34
|
+
export declare function readTicketDefaults(raw: unknown): TicketDefaults;
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.formConfigDefaults = formConfigDefaults;
|
|
4
4
|
exports.readTicketDefaults = readTicketDefaults;
|
|
5
|
-
const
|
|
5
|
+
const params_js_1 = require("./params.js");
|
|
6
6
|
/** Arrays of ids — the schema stores them as plain id strings. */
|
|
7
7
|
const ID_LISTS = ["tags", "assignedUsers", "assignedRoles"];
|
|
8
8
|
const NUMBERS = [
|
|
@@ -51,13 +51,13 @@ function readTicketDefaults(raw) {
|
|
|
51
51
|
for (const key of ID_LISTS) {
|
|
52
52
|
const list = Array.isArray(source[key]) ? source[key] : [];
|
|
53
53
|
const ids = list
|
|
54
|
-
.map(
|
|
54
|
+
.map(params_js_1.paramId)
|
|
55
55
|
.filter((id) => id !== undefined);
|
|
56
56
|
if (ids.length > 0)
|
|
57
57
|
values[key] = ids;
|
|
58
58
|
}
|
|
59
59
|
for (const key of NUMBERS) {
|
|
60
|
-
const value = (0,
|
|
60
|
+
const value = (0, params_js_1.paramNumber)(source[key]);
|
|
61
61
|
if (value !== undefined)
|
|
62
62
|
values[key] = value;
|
|
63
63
|
}
|
|
@@ -70,11 +70,11 @@ function readTicketDefaults(raw) {
|
|
|
70
70
|
values[key] = source[key];
|
|
71
71
|
}
|
|
72
72
|
return {
|
|
73
|
-
title: (0,
|
|
74
|
-
description: (0,
|
|
75
|
-
status: (0,
|
|
76
|
-
equipment: (0,
|
|
77
|
-
project: (0,
|
|
73
|
+
title: (0, params_js_1.paramString)(source.title),
|
|
74
|
+
description: (0, params_js_1.paramString)(source.description),
|
|
75
|
+
status: (0, params_js_1.paramId)(source.status),
|
|
76
|
+
equipment: (0, params_js_1.paramId)(source.equipment),
|
|
77
|
+
project: (0, params_js_1.paramId)(source.project),
|
|
78
78
|
values,
|
|
79
79
|
};
|
|
80
80
|
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { Tenant, type _User } from "../../../types/index.js";
|
|
2
|
+
import { type WriteAuth } from "./automationCall.js";
|
|
3
|
+
/**
|
|
4
|
+
* What a caller may change on an existing ticket.
|
|
5
|
+
*
|
|
6
|
+
* Only what is passed is touched. Lists (`assignedUserIds`, …) replace the
|
|
7
|
+
* ticket's list; `null` clears a field. The ticket is named by `ticketId`, or
|
|
8
|
+
* by `origin` — then the newest unfinished ticket of that origin, which is how
|
|
9
|
+
* an integration that created it with `unique` finds it again without keeping
|
|
10
|
+
* ids.
|
|
11
|
+
*/
|
|
12
|
+
export interface TicketUpdateParams {
|
|
13
|
+
ticketId?: unknown;
|
|
14
|
+
origin?: unknown;
|
|
15
|
+
title?: unknown;
|
|
16
|
+
description?: unknown;
|
|
17
|
+
/** Appended to the description as a new paragraph. */
|
|
18
|
+
appendDescription?: unknown;
|
|
19
|
+
statusId?: unknown;
|
|
20
|
+
/** The tenant's first status of this category — see `resolveStatus.ts`. */
|
|
21
|
+
statusCategory?: unknown;
|
|
22
|
+
priority?: unknown;
|
|
23
|
+
projectId?: unknown;
|
|
24
|
+
equipmentId?: unknown;
|
|
25
|
+
assignedUserIds?: unknown;
|
|
26
|
+
assignedRoleIds?: unknown;
|
|
27
|
+
tagIds?: unknown;
|
|
28
|
+
startDate?: unknown;
|
|
29
|
+
dueDate?: unknown;
|
|
30
|
+
failureStart?: unknown;
|
|
31
|
+
failureEnd?: unknown;
|
|
32
|
+
downtime?: unknown;
|
|
33
|
+
estimatedDuration?: unknown;
|
|
34
|
+
actualDuration?: unknown;
|
|
35
|
+
/**
|
|
36
|
+
* A comment in the ticket's chat (`OD3_Chat_Message`), written as the
|
|
37
|
+
* actor. Can be the only thing a call does.
|
|
38
|
+
*/
|
|
39
|
+
comment?: unknown;
|
|
40
|
+
/** Name shown on the comment when there is no actor. */
|
|
41
|
+
authorName?: unknown;
|
|
42
|
+
/** Form config whose save-time rules apply, as on create. */
|
|
43
|
+
formConfigId?: unknown;
|
|
44
|
+
}
|
|
45
|
+
export interface TicketUpdateOptions {
|
|
46
|
+
auth: WriteAuth;
|
|
47
|
+
actor?: _User;
|
|
48
|
+
logPrefix: string;
|
|
49
|
+
}
|
|
50
|
+
export interface TicketUpdateResult {
|
|
51
|
+
ticketId: string;
|
|
52
|
+
/** The fields the call changed — empty when it only commented. */
|
|
53
|
+
changed: string[];
|
|
54
|
+
commentId?: string;
|
|
55
|
+
/** Status after the call. */
|
|
56
|
+
statusId?: string;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Change a ticket the way the detail page does — one save, every hook applies.
|
|
60
|
+
*
|
|
61
|
+
* With a session, the ticket's ACL decides whether the actor may write it,
|
|
62
|
+
* exactly as in the frontend (creator, assignees, their roles). With the master
|
|
63
|
+
* key the call is the server's own and only the tenant is checked.
|
|
64
|
+
*/
|
|
65
|
+
export declare function updateTicket(tenant: Tenant, params: TicketUpdateParams, { auth, actor, logPrefix }: TicketUpdateOptions): Promise<TicketUpdateResult>;
|
|
@@ -0,0 +1,141 @@
|
|
|
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.updateTicket = updateTicket;
|
|
7
|
+
const node_1 = __importDefault(require("parse/node"));
|
|
8
|
+
const openservice_shared_1 = require("@opendash/openservice-shared");
|
|
9
|
+
const index_js_1 = require("../../../types/index.js");
|
|
10
|
+
const automationCall_js_1 = require("./automationCall.js");
|
|
11
|
+
const createTicket_js_1 = require("./createTicket.js");
|
|
12
|
+
const params_js_1 = require("./params.js");
|
|
13
|
+
const resolveStatus_js_1 = require("./resolveStatus.js");
|
|
14
|
+
/**
|
|
15
|
+
* Change a ticket the way the detail page does — one save, every hook applies.
|
|
16
|
+
*
|
|
17
|
+
* With a session, the ticket's ACL decides whether the actor may write it,
|
|
18
|
+
* exactly as in the frontend (creator, assignees, their roles). With the master
|
|
19
|
+
* key the call is the server's own and only the tenant is checked.
|
|
20
|
+
*/
|
|
21
|
+
async function updateTicket(tenant, params, { auth, actor, logPrefix }) {
|
|
22
|
+
const ticket = await findTicket(tenant, params, logPrefix);
|
|
23
|
+
const title = (0, params_js_1.paramString)(params.title);
|
|
24
|
+
if (title)
|
|
25
|
+
ticket.set("title", title);
|
|
26
|
+
if (params.description === null)
|
|
27
|
+
ticket.unset("description");
|
|
28
|
+
const description = (0, params_js_1.paramString)(params.description);
|
|
29
|
+
if (description !== undefined)
|
|
30
|
+
ticket.set("description", description);
|
|
31
|
+
const appended = (0, params_js_1.paramString)(params.appendDescription);
|
|
32
|
+
if (appended) {
|
|
33
|
+
const current = ticket.get("description")?.trim();
|
|
34
|
+
ticket.set("description", current ? `${current}\n\n${appended}` : appended);
|
|
35
|
+
}
|
|
36
|
+
const status = (await (0, resolveStatus_js_1.statusById)(tenant, (0, params_js_1.paramId)(params.statusId), logPrefix)) ??
|
|
37
|
+
((0, resolveStatus_js_1.isStatusCategory)(params.statusCategory)
|
|
38
|
+
? await (0, resolveStatus_js_1.statusByCategory)(tenant, params.statusCategory)
|
|
39
|
+
: undefined);
|
|
40
|
+
if ((params.statusId || params.statusCategory) && !status) {
|
|
41
|
+
throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, `${logPrefix} No such status for this tenant: ${String(params.statusId ?? params.statusCategory)}`);
|
|
42
|
+
}
|
|
43
|
+
if (status)
|
|
44
|
+
ticket.set("status", status);
|
|
45
|
+
if (params.priority === null)
|
|
46
|
+
ticket.unset("priority");
|
|
47
|
+
const priority = (0, params_js_1.paramNumber)(params.priority);
|
|
48
|
+
if (priority != null)
|
|
49
|
+
ticket.set("priority", priority);
|
|
50
|
+
if (params.projectId === null)
|
|
51
|
+
ticket.unset("project");
|
|
52
|
+
const projectId = (0, params_js_1.paramId)(params.projectId);
|
|
53
|
+
if (projectId) {
|
|
54
|
+
ticket.set("project", index_js_1.Service_Project.createWithoutData(projectId));
|
|
55
|
+
}
|
|
56
|
+
if (params.equipmentId === null)
|
|
57
|
+
ticket.unset("equipment");
|
|
58
|
+
const equipmentId = (0, params_js_1.paramId)(params.equipmentId);
|
|
59
|
+
if (equipmentId) {
|
|
60
|
+
ticket.set("equipment", index_js_1.Service_Equipment.createWithoutData(equipmentId));
|
|
61
|
+
}
|
|
62
|
+
for (const [param, field] of [
|
|
63
|
+
["assignedUserIds", "assignedUsers"],
|
|
64
|
+
["assignedRoleIds", "assignedRoles"],
|
|
65
|
+
["tagIds", "tags"],
|
|
66
|
+
]) {
|
|
67
|
+
const ids = (0, params_js_1.paramIds)(params[param]);
|
|
68
|
+
if (ids)
|
|
69
|
+
ticket.set(field, ids);
|
|
70
|
+
else if (params[param] === null)
|
|
71
|
+
ticket.unset(field);
|
|
72
|
+
}
|
|
73
|
+
(0, createTicket_js_1.applyTicketTimes)(ticket, params);
|
|
74
|
+
const changed = ticket.dirtyKeys();
|
|
75
|
+
if (changed.length > 0) {
|
|
76
|
+
// The hook checks master data against the tenant, runs the config's rules,
|
|
77
|
+
// stamps `closedAt` and notifies — as for a save from the detail page.
|
|
78
|
+
await ticket.save(null, {
|
|
79
|
+
...(0, automationCall_js_1.writeOptions)(auth),
|
|
80
|
+
context: { formConfig: (0, params_js_1.paramId)(params.formConfigId) },
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
const comment = (0, params_js_1.paramString)(params.comment);
|
|
84
|
+
const commentId = comment
|
|
85
|
+
? await writeComment(tenant, ticket, comment, {
|
|
86
|
+
auth,
|
|
87
|
+
actor,
|
|
88
|
+
authorName: (0, params_js_1.paramString)(params.authorName),
|
|
89
|
+
})
|
|
90
|
+
: undefined;
|
|
91
|
+
return {
|
|
92
|
+
ticketId: ticket.id,
|
|
93
|
+
changed,
|
|
94
|
+
commentId,
|
|
95
|
+
statusId: ticket.get("status")?.id,
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/** The ticket a call names — by id or by origin, always within the tenant. */
|
|
99
|
+
async function findTicket(tenant, params, logPrefix) {
|
|
100
|
+
const ticketId = (0, params_js_1.paramId)(params.ticketId);
|
|
101
|
+
const origin = (0, params_js_1.paramString)(params.origin);
|
|
102
|
+
const ticket = ticketId
|
|
103
|
+
? await new node_1.default.Query(index_js_1.Service_Ticket)
|
|
104
|
+
.equalTo("objectId", ticketId)
|
|
105
|
+
.equalTo("tenant", tenant)
|
|
106
|
+
.first({ useMasterKey: true })
|
|
107
|
+
: origin
|
|
108
|
+
? await (0, createTicket_js_1.findOpenTicket)(tenant, origin)
|
|
109
|
+
: undefined;
|
|
110
|
+
if (!ticket) {
|
|
111
|
+
throw new node_1.default.Error(node_1.default.Error.OBJECT_NOT_FOUND, ticketId || origin
|
|
112
|
+
? `${logPrefix} No ticket ${ticketId ?? `open for origin "${origin}"`} in this tenant`
|
|
113
|
+
: `${logPrefix} Name the ticket: pass "ticketId" or "origin"`);
|
|
114
|
+
}
|
|
115
|
+
return ticket;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* A comment in the ticket's chat — the same row the detail page writes, so it
|
|
119
|
+
* shows up there, notifies mentions and is indexed for similar cases.
|
|
120
|
+
*/
|
|
121
|
+
async function writeComment(tenant, ticket, text, { auth, actor, authorName, }) {
|
|
122
|
+
const message = new index_js_1.Chat_Message();
|
|
123
|
+
message.set("context", (0, openservice_shared_1.ticketContextKey)(ticket.id));
|
|
124
|
+
message.set("text", text);
|
|
125
|
+
message.set("deleted", false);
|
|
126
|
+
message.set("tenant", tenant);
|
|
127
|
+
if (actor)
|
|
128
|
+
message.set("author", actor);
|
|
129
|
+
message.set("authorName", authorName ?? displayName(actor) ?? "open.SERVICE");
|
|
130
|
+
await message.save(null, (0, automationCall_js_1.writeOptions)(auth));
|
|
131
|
+
return message.id;
|
|
132
|
+
}
|
|
133
|
+
function displayName(user) {
|
|
134
|
+
if (!user)
|
|
135
|
+
return undefined;
|
|
136
|
+
const first = user.get("firstname");
|
|
137
|
+
const last = user.get("lastname");
|
|
138
|
+
if (first && last)
|
|
139
|
+
return `${first} ${last}`;
|
|
140
|
+
return (user.get("name") || user.getUsername() || undefined);
|
|
141
|
+
}
|
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* **v2 does not go through this barrel.** Its parts are imported from the
|
|
10
10
|
* folder that owns them, so a v1 import is visible as one at the call site:
|
|
11
11
|
*
|
|
12
|
+
* - `automation/` — creating and changing tickets, plans and executions from
|
|
13
|
+
* outside the frontend (Node-RED, scripts); the alarm actions build on it
|
|
12
14
|
* - `alarms/` — alarm actions (ticket and maintenance plan)
|
|
13
15
|
* - `serviceSchedules/` — `OD3_Service_Schedule`: ACL, Outlook sync
|
|
14
16
|
* - `serviceProviders/` — external service provider access
|
|
@@ -10,6 +10,8 @@
|
|
|
10
10
|
* **v2 does not go through this barrel.** Its parts are imported from the
|
|
11
11
|
* folder that owns them, so a v1 import is visible as one at the call site:
|
|
12
12
|
*
|
|
13
|
+
* - `automation/` — creating and changing tickets, plans and executions from
|
|
14
|
+
* outside the frontend (Node-RED, scripts); the alarm actions build on it
|
|
13
15
|
* - `alarms/` — alarm actions (ticket and maintenance plan)
|
|
14
16
|
* - `serviceSchedules/` — `OD3_Service_Schedule`: ACL, Outlook sync
|
|
15
17
|
* - `serviceProviders/` — external service provider access
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an open.SERVICE maintenance plan from outside the frontend —
|
|
3
|
+
* recurring (a cadence, or a template's cadence from `startAt`) or a single
|
|
4
|
+
* appointment (`due` / `dueInDays`).
|
|
5
|
+
*
|
|
6
|
+
* **Authentication** — see `readAutomationCall`: master key with `tenantId`
|
|
7
|
+
* (and optionally `actingUserId`, the plan's owner), or the session of a
|
|
8
|
+
* (technical) user, for whom the `Service_Schedule` hook checks
|
|
9
|
+
* `schedule_create`.
|
|
10
|
+
*
|
|
11
|
+
* **Parameters** — `ScheduleCreateParams`: a template, title, machine, when,
|
|
12
|
+
* steps, tolerances, assignments, `origin` / `unique`, and `calendarSync:
|
|
13
|
+
* false` to keep the plan out of the Outlook sync.
|
|
14
|
+
*
|
|
15
|
+
* Returns `{ scheduleId, created, origin?, due?, equipmentId?, templateId? }`.
|
|
16
|
+
*
|
|
17
|
+
* The alarm action (`openinc-openservice-alarm-create-schedule`) creates its
|
|
18
|
+
* appointments through the same `createSchedule`.
|
|
19
|
+
*/
|
|
20
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,41 @@
|
|
|
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
|
+
* Create an open.SERVICE maintenance plan from outside the frontend —
|
|
11
|
+
* recurring (a cadence, or a template's cadence from `startAt`) or a single
|
|
12
|
+
* appointment (`due` / `dueInDays`).
|
|
13
|
+
*
|
|
14
|
+
* **Authentication** — see `readAutomationCall`: master key with `tenantId`
|
|
15
|
+
* (and optionally `actingUserId`, the plan's owner), or the session of a
|
|
16
|
+
* (technical) user, for whom the `Service_Schedule` hook checks
|
|
17
|
+
* `schedule_create`.
|
|
18
|
+
*
|
|
19
|
+
* **Parameters** — `ScheduleCreateParams`: a template, title, machine, when,
|
|
20
|
+
* steps, tolerances, assignments, `origin` / `unique`, and `calendarSync:
|
|
21
|
+
* false` to keep the plan out of the Outlook sync.
|
|
22
|
+
*
|
|
23
|
+
* Returns `{ scheduleId, created, origin?, due?, equipmentId?, templateId? }`.
|
|
24
|
+
*
|
|
25
|
+
* The alarm action (`openinc-openservice-alarm-create-schedule`) creates its
|
|
26
|
+
* appointments through the same `createSchedule`.
|
|
27
|
+
*/
|
|
28
|
+
async function init(name) {
|
|
29
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
30
|
+
const { tenant, auth, actor, params } = await (0, index_js_1.readAutomationCall)(name, request);
|
|
31
|
+
const result = await (0, index_js_1.createSchedule)(tenant, params, {
|
|
32
|
+
auth,
|
|
33
|
+
actor,
|
|
34
|
+
logPrefix: `[${name}]`,
|
|
35
|
+
});
|
|
36
|
+
console.log(`[${name}] ${result.created ? "created" : "reused"} plan ` +
|
|
37
|
+
`${result.scheduleId} in tenant ${tenant.id}` +
|
|
38
|
+
(result.origin ? ` (${result.origin})` : ""));
|
|
39
|
+
return result;
|
|
40
|
+
}, {});
|
|
41
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an open.SERVICE ticket from outside the frontend — an integration
|
|
3
|
+
* such as `@openinc/node-red-contrib-openservice`, an import, a script.
|
|
4
|
+
*
|
|
5
|
+
* **Authentication** — see `readAutomationCall`:
|
|
6
|
+
*
|
|
7
|
+
* - **master key** with `tenantId` (and optionally `actingUserId`, recorded as
|
|
8
|
+
* creator): the server's own write.
|
|
9
|
+
* - **session** of a (technical) user: the ticket lands in the user's tenant,
|
|
10
|
+
* and the `Service_Ticket` hook checks `ticket_create` as for the create
|
|
11
|
+
* form.
|
|
12
|
+
*
|
|
13
|
+
* **Parameters** — `TicketCreateParams`: a form config, a template in the
|
|
14
|
+
* ticket form's shape, flat fields (title, description, equipmentId,
|
|
15
|
+
* projectId, statusId / statusCategory, priority, assignments, tags, dates,
|
|
16
|
+
* durations), `origin` and `unique` (return the open ticket of that origin
|
|
17
|
+
* instead of a second one).
|
|
18
|
+
*
|
|
19
|
+
* Returns `{ ticketId, created, origin?, equipmentId?, number? }`.
|
|
20
|
+
*
|
|
21
|
+
* The alarm action (`openinc-openservice-alarm-create-ticket`) creates its
|
|
22
|
+
* tickets through the same `createTicket`.
|
|
23
|
+
*/
|
|
24
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,48 @@
|
|
|
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
|
+
* Create an open.SERVICE ticket from outside the frontend — an integration
|
|
11
|
+
* such as `@openinc/node-red-contrib-openservice`, an import, a script.
|
|
12
|
+
*
|
|
13
|
+
* **Authentication** — see `readAutomationCall`:
|
|
14
|
+
*
|
|
15
|
+
* - **master key** with `tenantId` (and optionally `actingUserId`, recorded as
|
|
16
|
+
* creator): the server's own write.
|
|
17
|
+
* - **session** of a (technical) user: the ticket lands in the user's tenant,
|
|
18
|
+
* and the `Service_Ticket` hook checks `ticket_create` as for the create
|
|
19
|
+
* form.
|
|
20
|
+
*
|
|
21
|
+
* **Parameters** — `TicketCreateParams`: a form config, a template in the
|
|
22
|
+
* ticket form's shape, flat fields (title, description, equipmentId,
|
|
23
|
+
* projectId, statusId / statusCategory, priority, assignments, tags, dates,
|
|
24
|
+
* durations), `origin` and `unique` (return the open ticket of that origin
|
|
25
|
+
* instead of a second one).
|
|
26
|
+
*
|
|
27
|
+
* Returns `{ ticketId, created, origin?, equipmentId?, number? }`.
|
|
28
|
+
*
|
|
29
|
+
* The alarm action (`openinc-openservice-alarm-create-ticket`) creates its
|
|
30
|
+
* tickets through the same `createTicket`.
|
|
31
|
+
*/
|
|
32
|
+
async function init(name) {
|
|
33
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
34
|
+
const { tenant, auth, actor, params } = await (0, index_js_1.readAutomationCall)(name, request);
|
|
35
|
+
const result = await (0, index_js_1.createTicket)(tenant, params, {
|
|
36
|
+
auth,
|
|
37
|
+
actor,
|
|
38
|
+
logPrefix: `[${name}]`,
|
|
39
|
+
});
|
|
40
|
+
console.log(`[${name}] ${result.created ? "created" : "reused"} ticket ` +
|
|
41
|
+
`${result.ticketId} in tenant ${tenant.id}` +
|
|
42
|
+
(result.origin ? ` (${result.origin})` : ""));
|
|
43
|
+
return result;
|
|
44
|
+
},
|
|
45
|
+
// No `requireUser`: the master key is a valid caller too. Authenticated in
|
|
46
|
+
// `readAutomationCall`.
|
|
47
|
+
{});
|
|
48
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Record a maintenance as performed from outside the frontend — the protocol
|
|
3
|
+
* the execution runner writes when a technician signs off.
|
|
4
|
+
*
|
|
5
|
+
* **Authentication** — see `readAutomationCall`: master key with `tenantId`
|
|
6
|
+
* (and optionally `actingUserId`, recorded as performer), or the session of a
|
|
7
|
+
* (technical) user, for whom the execution hook checks `execution_perform`
|
|
8
|
+
* and that the plan is readable — and records that user as performer.
|
|
9
|
+
*
|
|
10
|
+
* **Parameters** — `ExecutionRecordParams`: the plan by `scheduleId` or
|
|
11
|
+
* `scheduleOrigin` (or `equipmentId` + `title` for a direct maintenance), the
|
|
12
|
+
* `occurrence` it settles, `completedAt`, `stepResults` (default: every step
|
|
13
|
+
* done), `complete: false` to open it without signing off.
|
|
14
|
+
*
|
|
15
|
+
* Returns `{ executionId, scheduleId?, completedAt? }`.
|
|
16
|
+
*/
|
|
17
|
+
export declare function init(name: string): Promise<void>;
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
* Record a maintenance as performed from outside the frontend — the protocol
|
|
11
|
+
* the execution runner writes when a technician signs off.
|
|
12
|
+
*
|
|
13
|
+
* **Authentication** — see `readAutomationCall`: master key with `tenantId`
|
|
14
|
+
* (and optionally `actingUserId`, recorded as performer), or the session of a
|
|
15
|
+
* (technical) user, for whom the execution hook checks `execution_perform`
|
|
16
|
+
* and that the plan is readable — and records that user as performer.
|
|
17
|
+
*
|
|
18
|
+
* **Parameters** — `ExecutionRecordParams`: the plan by `scheduleId` or
|
|
19
|
+
* `scheduleOrigin` (or `equipmentId` + `title` for a direct maintenance), the
|
|
20
|
+
* `occurrence` it settles, `completedAt`, `stepResults` (default: every step
|
|
21
|
+
* done), `complete: false` to open it without signing off.
|
|
22
|
+
*
|
|
23
|
+
* Returns `{ executionId, scheduleId?, completedAt? }`.
|
|
24
|
+
*/
|
|
25
|
+
async function init(name) {
|
|
26
|
+
node_1.default.Cloud.define(name, async (request) => {
|
|
27
|
+
const { tenant, auth, actor, params } = await (0, index_js_1.readAutomationCall)(name, request);
|
|
28
|
+
const result = await (0, index_js_1.recordExecution)(tenant, params, {
|
|
29
|
+
auth,
|
|
30
|
+
actor,
|
|
31
|
+
logPrefix: `[${name}]`,
|
|
32
|
+
});
|
|
33
|
+
console.log(`[${name}] execution ${result.executionId}` +
|
|
34
|
+
(result.scheduleId ? ` of plan ${result.scheduleId}` : "") +
|
|
35
|
+
(result.completedAt ? ` completed ${result.completedAt}` : " opened"));
|
|
36
|
+
return result;
|
|
37
|
+
}, {});
|
|
38
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Change an open.SERVICE ticket from outside the frontend: move its status,
|
|
3
|
+
* reassign it, record the failure window, comment on it.
|
|
4
|
+
*
|
|
5
|
+
* **Authentication** — see `readAutomationCall`: master key with `tenantId`
|
|
6
|
+
* (and optionally `actingUserId`, the comment's author), or the session of a
|
|
7
|
+
* (technical) user, whose write the ticket's ACL then decides — exactly as
|
|
8
|
+
* on the detail page.
|
|
9
|
+
*
|
|
10
|
+
* **Parameters** — `TicketUpdateParams`: the ticket by `ticketId`, or by
|
|
11
|
+
* `origin` (the newest open ticket of it); then only the fields to change, a
|
|
12
|
+
* status by id or by category, and/or a `comment`.
|
|
13
|
+
*
|
|
14
|
+
* Returns `{ ticketId, changed, commentId?, statusId? }`.
|
|
15
|
+
*/
|
|
16
|
+
export declare function init(name: string): Promise<void>;
|