@openinc/parse-server-opendash 4.3.2 → 4.4.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.
Files changed (161) hide show
  1. package/dist/features/openservice/alarms/AlarmEvent.d.ts +40 -0
  2. package/dist/features/openservice/alarms/alarmIdentity.d.ts +39 -0
  3. package/dist/features/openservice/{serviceTickets/alarmActions/functions/alarmTicketFields.js → alarms/alarmIdentity.js} +55 -57
  4. package/dist/features/openservice/alarms/index.d.ts +30 -0
  5. package/dist/features/openservice/alarms/index.js +52 -0
  6. package/dist/features/openservice/alarms/resolveEquipment.d.ts +17 -0
  7. package/dist/features/openservice/alarms/resolveEquipment.js +42 -0
  8. package/dist/features/openservice/alarms/schedule/AlarmScheduleTypes.d.ts +88 -0
  9. package/dist/features/openservice/alarms/schedule/AlarmScheduleTypes.js +29 -0
  10. package/dist/features/openservice/alarms/schedule/alarmScheduleFields.d.ts +27 -0
  11. package/dist/features/openservice/alarms/schedule/alarmScheduleFields.js +56 -0
  12. package/dist/features/openservice/alarms/schedule/createAlarmSchedule.d.ts +37 -0
  13. package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +181 -0
  14. package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.d.ts +22 -0
  15. package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +127 -0
  16. package/dist/features/openservice/alarms/schedule/listAlarmTriggers.d.ts +41 -0
  17. package/dist/features/openservice/alarms/schedule/listAlarmTriggers.js +137 -0
  18. package/dist/features/openservice/alarms/tenantForSecret.d.ts +13 -0
  19. package/dist/features/openservice/alarms/tenantForSecret.js +45 -0
  20. package/dist/features/openservice/{serviceTickets/alarmActions/types → alarms/ticket}/AlarmTicketTypes.d.ts +0 -26
  21. package/dist/features/openservice/alarms/ticket/alarmTicketFields.d.ts +18 -0
  22. package/dist/features/openservice/alarms/ticket/alarmTicketFields.js +37 -0
  23. package/dist/features/openservice/{serviceTickets/alarmActions/service → alarms/ticket}/createAlarmTicket.d.ts +7 -7
  24. package/dist/features/openservice/{serviceTickets/alarmActions/service → alarms/ticket}/createAlarmTicket.js +15 -69
  25. package/dist/features/openservice/{serviceTickets/alarmActions/service → alarms/ticket}/ensureAlarmTicketAction.js +2 -2
  26. package/dist/features/openservice/functions/assignUsersAndRoles.d.ts +5 -0
  27. package/dist/features/openservice/functions/assignUsersAndRoles.js +5 -0
  28. package/dist/features/openservice/functions/getSourceMetaMap.d.ts +4 -0
  29. package/dist/features/openservice/functions/getSourceMetaMap.js +4 -0
  30. package/dist/features/openservice/functions/getTicketObject.d.ts +5 -0
  31. package/dist/features/openservice/functions/getTicketObject.js +5 -0
  32. package/dist/features/openservice/functions/saveDescription.d.ts +5 -0
  33. package/dist/features/openservice/functions/saveDescription.js +5 -0
  34. package/dist/features/openservice/functions/saveDowntime.d.ts +5 -0
  35. package/dist/features/openservice/functions/saveDowntime.js +5 -0
  36. package/dist/features/openservice/functions/saveDuedate.d.ts +5 -0
  37. package/dist/features/openservice/functions/saveDuedate.js +5 -0
  38. package/dist/features/openservice/functions/saveFrequency.d.ts +5 -0
  39. package/dist/features/openservice/functions/saveFrequency.js +5 -0
  40. package/dist/features/openservice/functions/saveIssuecategory.d.ts +10 -0
  41. package/dist/features/openservice/functions/saveIssuecategory.js +10 -0
  42. package/dist/features/openservice/functions/saveMaterial.d.ts +5 -0
  43. package/dist/features/openservice/functions/saveMaterial.js +5 -0
  44. package/dist/features/openservice/functions/saveMessage.d.ts +5 -0
  45. package/dist/features/openservice/functions/saveMessage.js +5 -0
  46. package/dist/features/openservice/functions/savePriority.d.ts +5 -0
  47. package/dist/features/openservice/functions/savePriority.js +5 -0
  48. package/dist/features/openservice/functions/saveProject.d.ts +5 -0
  49. package/dist/features/openservice/functions/saveProject.js +5 -0
  50. package/dist/features/openservice/functions/saveRestriction.d.ts +5 -0
  51. package/dist/features/openservice/functions/saveRestriction.js +5 -0
  52. package/dist/features/openservice/functions/saveSource.d.ts +5 -0
  53. package/dist/features/openservice/functions/saveSource.js +5 -0
  54. package/dist/features/openservice/functions/saveState.d.ts +10 -0
  55. package/dist/features/openservice/functions/saveState.js +10 -0
  56. package/dist/features/openservice/functions/saveTicketMeta.d.ts +5 -0
  57. package/dist/features/openservice/functions/saveTicketMeta.js +5 -0
  58. package/dist/features/openservice/functions/saveTicketTitle.d.ts +5 -0
  59. package/dist/features/openservice/functions/saveTicketTitle.js +5 -0
  60. package/dist/features/openservice/index.d.ts +15 -0
  61. package/dist/features/openservice/index.js +15 -0
  62. package/dist/features/openservice/init.d.ts +9 -0
  63. package/dist/features/openservice/init.js +15 -3
  64. package/dist/features/openservice/issuecategory/initIssuecategory.d.ts +4 -0
  65. package/dist/features/openservice/issuecategory/initIssuecategory.js +4 -0
  66. package/dist/features/openservice/kanbanState/initKanbanStates.d.ts +10 -0
  67. package/dist/features/openservice/kanbanState/initKanbanStates.js +10 -0
  68. package/dist/features/openservice/messages/initMessages.d.ts +3 -0
  69. package/dist/features/openservice/messages/initMessages.js +3 -0
  70. package/dist/features/openservice/messages/removeLatestMessage.d.ts +2 -0
  71. package/dist/features/openservice/messages/removeLatestMessage.js +2 -0
  72. package/dist/features/openservice/schedules/calendarSync/Access.d.ts +12 -0
  73. package/dist/features/openservice/schedules/calendarSync/{service/CalendarManager.d.ts → CalendarManager.d.ts} +7 -2
  74. package/dist/features/openservice/schedules/calendarSync/{service/CalendarManager.js → CalendarManager.js} +6 -1
  75. package/dist/features/openservice/schedules/calendarSync/{service/CalendarSyncPoller.d.ts → CalendarSyncPoller.d.ts} +6 -1
  76. package/dist/features/openservice/schedules/calendarSync/{service/CalendarSyncPoller.js → CalendarSyncPoller.js} +7 -2
  77. package/dist/features/openservice/schedules/calendarSync/ConfigValues.d.ts +13 -0
  78. package/dist/features/openservice/schedules/calendarSync/{types/Event.d.ts → Event.d.ts} +7 -0
  79. package/dist/features/openservice/schedules/calendarSync/Event.js +9 -0
  80. package/dist/features/openservice/schedules/calendarSync/calendarMetaHelper.d.ts +76 -0
  81. package/dist/features/openservice/schedules/calendarSync/{service/calendarMetaHelper.js → calendarMetaHelper.js} +31 -1
  82. package/dist/features/openservice/schedules/calendarSync/eventToSchedule.d.ts +37 -0
  83. package/dist/features/openservice/schedules/calendarSync/{functions/eventToSchedule.js → eventToSchedule.js} +5 -0
  84. package/dist/features/openservice/schedules/calendarSync/scheduleToEvent.d.ts +9 -0
  85. package/dist/features/openservice/schedules/calendarSync/{functions/scheduleToEvent.js → scheduleToEvent.js} +5 -0
  86. package/dist/features/openservice/schedules/{mappings/checkStatus.d.ts → checkStatus.d.ts} +3 -0
  87. package/dist/features/openservice/schedules/{mappings/checkStatus.js → checkStatus.js} +4 -1
  88. package/dist/features/openservice/schedules/getScheduleLink.d.ts +3 -0
  89. package/dist/features/openservice/schedules/getScheduleLink.js +3 -0
  90. package/dist/features/openservice/schedules/initSchedulesFeature.d.ts +4 -0
  91. package/dist/features/openservice/schedules/initSchedulesFeature.js +5 -1
  92. package/dist/features/openservice/schedules/reassignScheduleExecutions.d.ts +5 -0
  93. package/dist/features/openservice/schedules/{mappings/reassignScheduleExecutions.js → reassignScheduleExecutions.js} +5 -1
  94. package/dist/features/openservice/serviceSchedules/calendarSync/{service/ServiceCalendarSyncPoller.d.ts → ServiceCalendarSyncPoller.d.ts} +26 -1
  95. package/dist/features/openservice/serviceSchedules/calendarSync/{service/ServiceCalendarSyncPoller.js → ServiceCalendarSyncPoller.js} +94 -20
  96. package/dist/features/openservice/serviceSchedules/calendarSync/{functions/eventToPlan.d.ts → eventToPlan.d.ts} +2 -2
  97. package/dist/features/openservice/serviceSchedules/calendarSync/index.d.ts +8 -8
  98. package/dist/features/openservice/serviceSchedules/calendarSync/index.js +7 -7
  99. package/dist/features/openservice/serviceSchedules/calendarSync/{functions/outlookRecurrence.d.ts → outlookRecurrence.d.ts} +2 -2
  100. package/dist/features/openservice/serviceSchedules/calendarSync/{functions/planToEvent.d.ts → planToEvent.d.ts} +3 -3
  101. package/dist/features/openservice/serviceSchedules/calendarSync/{service/serviceCalendarMeta.d.ts → serviceCalendarMeta.d.ts} +3 -3
  102. package/dist/features/openservice/serviceSchedules/calendarSync/{service/serviceCalendarMeta.js → serviceCalendarMeta.js} +1 -1
  103. package/dist/features/openservice/serviceSchedules/calendarSync/{service/syncPlanToCalendar.d.ts → syncPlanToCalendar.d.ts} +3 -3
  104. package/dist/features/openservice/serviceSchedules/calendarSync/{service/syncPlanToCalendar.js → syncPlanToCalendar.js} +5 -5
  105. package/dist/features/openservice/serviceSchedules/initServiceSchedulesFeature.js +2 -2
  106. package/dist/features/openservice/ticket/getTicketLink.d.ts +2 -0
  107. package/dist/features/openservice/ticket/getTicketLink.js +2 -0
  108. package/dist/features/openservice/ticket/initTicket.d.ts +2 -0
  109. package/dist/features/openservice/ticket/initTicket.js +2 -0
  110. package/dist/features/openservice/types/Material.d.ts +4 -0
  111. package/dist/features/openservice/types/MessageData.d.ts +8 -0
  112. package/dist/features/openservice/types/OpenserviceTranslationKeys.d.ts +4 -0
  113. package/dist/features/openservice/types/OpenserviceTranslationKeys.js +4 -0
  114. package/dist/features/openservice/types/SaveValues.d.ts +4 -0
  115. package/dist/features/openservice/types/ScheduleTypes.d.ts +24 -0
  116. package/dist/features/openservice/types/TicketData.d.ts +4 -0
  117. package/dist/features/openservice/types/TicketMeta.d.ts +28 -0
  118. package/dist/features/openservice/types/TicketMeta.js +4 -0
  119. package/dist/functions/openinc-openservice-alarm-create-schedule.d.ts +25 -0
  120. package/dist/functions/openinc-openservice-alarm-create-schedule.js +63 -0
  121. package/dist/functions/openinc-openservice-alarm-create-ticket.js +2 -2
  122. package/dist/functions/openinc-openservice-alarm-triggers.d.ts +13 -0
  123. package/dist/functions/openinc-openservice-alarm-triggers.js +29 -0
  124. package/dist/functions/openinc-openservice-get-sourcemeta-map.js +8 -0
  125. package/dist/functions/openinc-openservice-provider-access.d.ts +1 -0
  126. package/dist/functions/openinc-openservice-provider-access.js +79 -0
  127. package/dist/functions/openinc-openservice-save-ticket-data.js +11 -0
  128. package/dist/functions/openinc-openservice-ticket-data.js +9 -0
  129. package/dist/hooks/Maintenance_Schedule.js +3 -3
  130. package/dist/hooks/Service_Schedule.js +11 -11
  131. package/dist/hooks/Service_Schedule_Template.js +6 -6
  132. package/dist/types/Contact.d.ts +3 -0
  133. package/dist/types/Contact.js +6 -0
  134. package/dist/types/Service_Schedule.d.ts +3 -0
  135. package/dist/types/Service_Schedule.js +6 -0
  136. package/package.json +1 -1
  137. package/schema/Contact.json +5 -0
  138. package/schema/Service_Schedule.json +4 -0
  139. package/dist/features/openservice/schedules/calendarSync/functions/eventToSchedule.d.ts +0 -17
  140. package/dist/features/openservice/schedules/calendarSync/functions/scheduleToEvent.d.ts +0 -4
  141. package/dist/features/openservice/schedules/calendarSync/service/calendarMetaHelper.d.ts +0 -36
  142. package/dist/features/openservice/schedules/calendarSync/types/Access.d.ts +0 -9
  143. package/dist/features/openservice/schedules/calendarSync/types/ConfigValues.d.ts +0 -8
  144. package/dist/features/openservice/schedules/mappings/reassignScheduleExecutions.d.ts +0 -1
  145. package/dist/features/openservice/serviceSchedules/acl/index.d.ts +0 -1
  146. package/dist/features/openservice/serviceSchedules/acl/index.js +0 -6
  147. package/dist/features/openservice/serviceTickets/alarmActions/functions/alarmTicketFields.d.ts +0 -35
  148. package/dist/features/openservice/serviceTickets/alarmActions/index.d.ts +0 -7
  149. package/dist/features/openservice/serviceTickets/alarmActions/index.js +0 -16
  150. /package/dist/features/openservice/{schedules/calendarSync/types/Access.js → alarms/AlarmEvent.js} +0 -0
  151. /package/dist/features/openservice/{serviceTickets/alarmActions/types → alarms/ticket}/AlarmTicketTypes.js +0 -0
  152. /package/dist/features/openservice/{serviceTickets/alarmActions/service → alarms/ticket}/ensureAlarmTicketAction.d.ts +0 -0
  153. /package/dist/features/openservice/schedules/calendarSync/{types/ConfigValues.js → Access.js} +0 -0
  154. /package/dist/features/openservice/schedules/calendarSync/{types/Event.js → ConfigValues.js} +0 -0
  155. /package/dist/features/openservice/serviceSchedules/{acl/assignmentAcl.d.ts → assignmentAcl.d.ts} +0 -0
  156. /package/dist/features/openservice/serviceSchedules/{acl/assignmentAcl.js → assignmentAcl.js} +0 -0
  157. /package/dist/features/openservice/serviceSchedules/calendarSync/{types/ServiceSyncTypes.d.ts → ServiceSyncTypes.d.ts} +0 -0
  158. /package/dist/features/openservice/serviceSchedules/calendarSync/{types/ServiceSyncTypes.js → ServiceSyncTypes.js} +0 -0
  159. /package/dist/features/openservice/serviceSchedules/calendarSync/{functions/eventToPlan.js → eventToPlan.js} +0 -0
  160. /package/dist/features/openservice/serviceSchedules/calendarSync/{functions/outlookRecurrence.js → outlookRecurrence.js} +0 -0
  161. /package/dist/features/openservice/serviceSchedules/calendarSync/{functions/planToEvent.js → planToEvent.js} +0 -0
@@ -0,0 +1,40 @@
1
+ /**
2
+ * What an alarm executor reports about an alarm that fired.
3
+ *
4
+ * Shared by every open.SERVICE alarm action (ticket, schedule, …) so the
5
+ * payload of an `OD3_AlarmAction` row is the same shape whichever action a
6
+ * customer picks. Field names follow `OD3_Alarm`, so a payload can be assembled
7
+ * from the alarm row without renaming: `item_id` / `item_source` /
8
+ * `item_dimension` identify the sensor, the rest is context.
9
+ *
10
+ * Everything is optional except that *something* must identify the alarm — see
11
+ * {@link alarmKey}.
12
+ */
13
+ export interface AlarmEvent {
14
+ /** `OD3_Alarm.objectId`, if the executor knows it. */
15
+ alarmId?: string;
16
+ /** The alarm's name — the most recognisable label there is. */
17
+ name?: string;
18
+ /** Sensor id, e.g. `cnc04.spindle`. */
19
+ item_id?: string;
20
+ /** Source (site/tenant hierarchy) the sensor belongs to. */
21
+ item_source?: string;
22
+ /** Which dimension of the sensor tripped. */
23
+ item_dimension?: number;
24
+ /** The value that broke the rule. */
25
+ value?: number | string | boolean;
26
+ /** Human-readable rule, e.g. `> 80`. */
27
+ condition?: string;
28
+ /** When it fired (ISO). Defaults to now. */
29
+ firedAt?: string;
30
+ /**
31
+ * `OD3_Alarm.user` — who configured the alarm.
32
+ *
33
+ * Matters for anything the ACL is derived from: a record created without a
34
+ * creator is readable by administrators only (`syncAssignmentAcl`), so the
35
+ * person who set the alarm up would not see what it produced. Optional
36
+ * because the executor may not report it; the actions then fall back to
37
+ * whatever their assignments grant.
38
+ */
39
+ userId?: string;
40
+ }
@@ -0,0 +1,39 @@
1
+ import type { AlarmEvent } from "./AlarmEvent.js";
2
+ /**
3
+ * Identity and text rendering for a fired alarm — pure, so the `origin` marker
4
+ * and the wording can be checked without a database.
5
+ *
6
+ * Shared by every alarm action. The marker in particular **must** be computed
7
+ * the same way everywhere: it is what makes the actions idempotent, and two
8
+ * implementations that drift would silently start creating duplicates.
9
+ */
10
+ /**
11
+ * A stable identity for the alarm — the one thing a payload must carry.
12
+ *
13
+ * Returns `undefined` when the executor reports neither an alarm id nor a
14
+ * sensor: such a call cannot be deduplicated and is rejected rather than
15
+ * silently creating a record on every firing.
16
+ */
17
+ export declare function alarmKey(event: AlarmEvent): string | undefined;
18
+ /**
19
+ * The `origin` marker: `alarm:<key>`.
20
+ *
21
+ * A free-form, greppable string that says where a record came from and can be
22
+ * queried back (`equalTo("origin", …)`) — the same idea as the schedule
23
+ * plugin's `schedule:<id>:<occurrence>`. Stable across firings of one alarm.
24
+ */
25
+ export declare function alarmOrigin(event: AlarmEvent): string;
26
+ /** When the alarm fired — never when we happened to receive the call. */
27
+ export declare function firedAt(event: AlarmEvent): Date;
28
+ /** `source/id [dimension]` — how a sensor is named to a human. */
29
+ export declare function sensorLabel(event: AlarmEvent): string;
30
+ export declare function formatValue(value: AlarmEvent["value"]): string;
31
+ /**
32
+ * Fill `{{alarm}}`, `{{sensor}}` and `{{value}}` in a title the user configured.
33
+ *
34
+ * Returns `undefined` for an empty template, so each action can pick its own
35
+ * fallback — a ticket and a maintenance plan do not want the same default name.
36
+ */
37
+ export declare function renderTitleTemplate(template: string | undefined, event: AlarmEvent): string | undefined;
38
+ /** The lines describing what the alarm actually reported. */
39
+ export declare function alarmDetailLines(event: AlarmEvent, actionId: string): string[];
@@ -1,35 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.alarmTicketFields = alarmTicketFields;
4
- exports.alarmOrigin = alarmOrigin;
5
3
  exports.alarmKey = alarmKey;
4
+ exports.alarmOrigin = alarmOrigin;
6
5
  exports.firedAt = firedAt;
7
- const AlarmTicketTypes_js_1 = require("../types/AlarmTicketTypes.js");
8
- function alarmTicketFields(event, params = {}) {
9
- return {
10
- title: renderTitle(event, params),
11
- description: renderDescription(event, params),
12
- origin: alarmOrigin(event),
13
- };
14
- }
6
+ exports.sensorLabel = sensorLabel;
7
+ exports.formatValue = formatValue;
8
+ exports.renderTitleTemplate = renderTitleTemplate;
9
+ exports.alarmDetailLines = alarmDetailLines;
15
10
  /**
16
- * The `origin` marker: `alarm:<key>`.
11
+ * Identity and text rendering for a fired alarm — pure, so the `origin` marker
12
+ * and the wording can be checked without a database.
17
13
  *
18
- * Same idea as the schedule plugin's `schedule:<id>:<occurrence>` — a
19
- * free-form, greppable string that says where a ticket came from and can be
20
- * queried back (`equalTo("origin", …)`). The key is the alarm's id when the
21
- * executor knows it, otherwise source and sensor, which stay stable across
22
- * firings of the same alarm.
14
+ * Shared by every alarm action. The marker in particular **must** be computed
15
+ * the same way everywhere: it is what makes the actions idempotent, and two
16
+ * implementations that drift would silently start creating duplicates.
23
17
  */
24
- function alarmOrigin(event) {
25
- return `alarm:${alarmKey(event)}`;
26
- }
27
18
  /**
28
19
  * A stable identity for the alarm — the one thing a payload must carry.
29
20
  *
30
21
  * Returns `undefined` when the executor reports neither an alarm id nor a
31
22
  * sensor: such a call cannot be deduplicated and is rejected rather than
32
- * silently creating a ticket on every firing.
23
+ * silently creating a record on every firing.
33
24
  */
34
25
  function alarmKey(event) {
35
26
  if (event.alarmId)
@@ -41,47 +32,17 @@ function alarmKey(event) {
41
32
  ? `${sensor}#${event.item_dimension}`
42
33
  : sensor;
43
34
  }
44
- /** `{{alarm}}` / `{{sensor}}` / `{{value}}` in the configured title. */
45
- function renderTitle(event, params) {
46
- const template = params.title?.trim();
47
- const sensor = sensorLabel(event);
48
- if (!template) {
49
- // No template: the alarm's own name is the most recognisable thing there
50
- // is, and a ticket must have a title.
51
- return event.name || (sensor ? `Alarm: ${sensor}` : "Alarm");
52
- }
53
- return template
54
- .replace(/\{\{\s*alarm\s*\}\}/gi, event.name ?? "")
55
- .replace(/\{\{\s*sensor\s*\}\}/gi, sensor)
56
- .replace(/\{\{\s*value\s*\}\}/gi, formatValue(event.value))
57
- .replace(/\s+/g, " ")
58
- .trim();
59
- }
60
35
  /**
61
- * The configured note plus what the alarm actually reported.
36
+ * The `origin` marker: `alarm:<key>`.
62
37
  *
63
- * The details are appended rather than templated, because the person handling
64
- * the ticket needs to know which sensor, which value and when — and forgetting
65
- * a placeholder in the form should not lose that.
38
+ * A free-form, greppable string that says where a record came from and can be
39
+ * queried back (`equalTo("origin", …)`) — the same idea as the schedule
40
+ * plugin's `schedule:<id>:<occurrence>`. Stable across firings of one alarm.
66
41
  */
67
- function renderDescription(event, params) {
68
- const lines = [];
69
- const note = params.description?.trim();
70
- if (note)
71
- lines.push(note, "");
72
- const sensor = sensorLabel(event);
73
- if (event.name)
74
- lines.push(`Alarm: ${event.name}`);
75
- if (sensor)
76
- lines.push(`Sensor: ${sensor}`);
77
- if (event.value !== undefined)
78
- lines.push(`Wert: ${formatValue(event.value)}`);
79
- if (event.condition)
80
- lines.push(`Regel: ${event.condition}`);
81
- lines.push(`Ausgelöst: ${firedAt(event).toISOString()}`);
82
- lines.push(`Quelle: ${AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID}`);
83
- return lines.join("\n");
42
+ function alarmOrigin(event) {
43
+ return `alarm:${alarmKey(event)}`;
84
44
  }
45
+ /** When the alarm fired — never when we happened to receive the call. */
85
46
  function firedAt(event) {
86
47
  if (event.firedAt) {
87
48
  const parsed = new Date(event.firedAt);
@@ -90,6 +51,7 @@ function firedAt(event) {
90
51
  }
91
52
  return new Date();
92
53
  }
54
+ /** `source/id [dimension]` — how a sensor is named to a human. */
93
55
  function sensorLabel(event) {
94
56
  const sensor = [event.item_source, event.item_id].filter(Boolean).join("/");
95
57
  return event.item_dimension != null && sensor
@@ -101,3 +63,39 @@ function formatValue(value) {
101
63
  return "";
102
64
  return String(value);
103
65
  }
66
+ /**
67
+ * Fill `{{alarm}}`, `{{sensor}}` and `{{value}}` in a title the user configured.
68
+ *
69
+ * Returns `undefined` for an empty template, so each action can pick its own
70
+ * fallback — a ticket and a maintenance plan do not want the same default name.
71
+ */
72
+ function renderTitleTemplate(template, event) {
73
+ const trimmed = template?.trim();
74
+ if (!trimmed)
75
+ return undefined;
76
+ const rendered = trimmed
77
+ .replace(/\{\{\s*alarm\s*\}\}/gi, event.name ?? "")
78
+ .replace(/\{\{\s*sensor\s*\}\}/gi, sensorLabel(event))
79
+ .replace(/\{\{\s*value\s*\}\}/gi, formatValue(event.value))
80
+ .replace(/\s+/g, " ")
81
+ .trim();
82
+ // A template of nothing but placeholders that all resolved empty is not a
83
+ // title; let the caller fall back instead of writing a blank one.
84
+ return rendered || undefined;
85
+ }
86
+ /** The lines describing what the alarm actually reported. */
87
+ function alarmDetailLines(event, actionId) {
88
+ const lines = [];
89
+ const sensor = sensorLabel(event);
90
+ if (event.name)
91
+ lines.push(`Alarm: ${event.name}`);
92
+ if (sensor)
93
+ lines.push(`Sensor: ${sensor}`);
94
+ if (event.value !== undefined)
95
+ lines.push(`Wert: ${formatValue(event.value)}`);
96
+ if (event.condition)
97
+ lines.push(`Regel: ${event.condition}`);
98
+ lines.push(`Ausgelöst: ${firedAt(event).toISOString()}`);
99
+ lines.push(`Quelle: ${actionId}`);
100
+ return lines;
101
+ }
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Alarm actions of open.SERVICE — everything that turns a fired alarm into
3
+ * work somebody can carry out.
4
+ *
5
+ * One folder per action — `ticket/` and `schedule/` — over a shared base at
6
+ * this level. The two differ in *what* they create, not in how they are
7
+ * called, secured or deduplicated, and the identity helpers in that base
8
+ * (`alarmKey`, `alarmOrigin`) **must** stay a single implementation: two of
9
+ * them would silently start creating duplicates. `README.md` has the wiring.
10
+ */
11
+ export { alarmDetailLines, alarmKey, alarmOrigin, firedAt, formatValue, renderTitleTemplate, sensorLabel, } from "./alarmIdentity.js";
12
+ export { resolveEquipment } from "./resolveEquipment.js";
13
+ export { tenantForSecret } from "./tenantForSecret.js";
14
+ export type { AlarmEvent } from "./AlarmEvent.js";
15
+ export { alarmTicketFields } from "./ticket/alarmTicketFields.js";
16
+ export type { AlarmTicketFields } from "./ticket/alarmTicketFields.js";
17
+ export { createAlarmTicket, tenantForAlarmTicket, } from "./ticket/createAlarmTicket.js";
18
+ export type { AlarmTicketResult } from "./ticket/createAlarmTicket.js";
19
+ export { ensureAlarmTicketAction } from "./ticket/ensureAlarmTicketAction.js";
20
+ export { ALARM_TICKET_ACTION_ID, ALARM_TICKET_SECRET_CONFIG_KEY, } from "./ticket/AlarmTicketTypes.js";
21
+ export type { AlarmTicketParams } from "./ticket/AlarmTicketTypes.js";
22
+ export { alarmScheduleFields, dueDate, } from "./schedule/alarmScheduleFields.js";
23
+ export type { AlarmScheduleFields } from "./schedule/alarmScheduleFields.js";
24
+ export { createAlarmSchedule, tenantForAlarmSchedule, } from "./schedule/createAlarmSchedule.js";
25
+ export type { AlarmScheduleResult } from "./schedule/createAlarmSchedule.js";
26
+ export { ensureAlarmScheduleAction } from "./schedule/ensureAlarmScheduleAction.js";
27
+ export { listAlarmTriggers } from "./schedule/listAlarmTriggers.js";
28
+ export type { AlarmTriggerRow } from "./schedule/listAlarmTriggers.js";
29
+ export { ALARM_SCHEDULE_ACTION_ID, ALARM_SCHEDULE_SECRET_CONFIG_KEY, } from "./schedule/AlarmScheduleTypes.js";
30
+ export type { AlarmScheduleParams, ScheduleAlarmContext, } from "./schedule/AlarmScheduleTypes.js";
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ /**
3
+ * Alarm actions of open.SERVICE — everything that turns a fired alarm into
4
+ * work somebody can carry out.
5
+ *
6
+ * One folder per action — `ticket/` and `schedule/` — over a shared base at
7
+ * this level. The two differ in *what* they create, not in how they are
8
+ * called, secured or deduplicated, and the identity helpers in that base
9
+ * (`alarmKey`, `alarmOrigin`) **must** stay a single implementation: two of
10
+ * them would silently start creating duplicates. `README.md` has the wiring.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.ALARM_SCHEDULE_SECRET_CONFIG_KEY = exports.ALARM_SCHEDULE_ACTION_ID = exports.listAlarmTriggers = 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.sensorLabel = exports.renderTitleTemplate = exports.formatValue = exports.firedAt = exports.alarmOrigin = exports.alarmKey = exports.alarmDetailLines = void 0;
14
+ // The shared base, here at the root because both actions read it: payload
15
+ // shape, identity, and the two lookups every action needs.
16
+ var alarmIdentity_js_1 = require("./alarmIdentity.js");
17
+ Object.defineProperty(exports, "alarmDetailLines", { enumerable: true, get: function () { return alarmIdentity_js_1.alarmDetailLines; } });
18
+ Object.defineProperty(exports, "alarmKey", { enumerable: true, get: function () { return alarmIdentity_js_1.alarmKey; } });
19
+ Object.defineProperty(exports, "alarmOrigin", { enumerable: true, get: function () { return alarmIdentity_js_1.alarmOrigin; } });
20
+ Object.defineProperty(exports, "firedAt", { enumerable: true, get: function () { return alarmIdentity_js_1.firedAt; } });
21
+ Object.defineProperty(exports, "formatValue", { enumerable: true, get: function () { return alarmIdentity_js_1.formatValue; } });
22
+ Object.defineProperty(exports, "renderTitleTemplate", { enumerable: true, get: function () { return alarmIdentity_js_1.renderTitleTemplate; } });
23
+ Object.defineProperty(exports, "sensorLabel", { enumerable: true, get: function () { return alarmIdentity_js_1.sensorLabel; } });
24
+ var resolveEquipment_js_1 = require("./resolveEquipment.js");
25
+ Object.defineProperty(exports, "resolveEquipment", { enumerable: true, get: function () { return resolveEquipment_js_1.resolveEquipment; } });
26
+ var tenantForSecret_js_1 = require("./tenantForSecret.js");
27
+ Object.defineProperty(exports, "tenantForSecret", { enumerable: true, get: function () { return tenantForSecret_js_1.tenantForSecret; } });
28
+ // `ticket/` — "raise a ticket", an alarm that reports a finding.
29
+ var alarmTicketFields_js_1 = require("./ticket/alarmTicketFields.js");
30
+ Object.defineProperty(exports, "alarmTicketFields", { enumerable: true, get: function () { return alarmTicketFields_js_1.alarmTicketFields; } });
31
+ var createAlarmTicket_js_1 = require("./ticket/createAlarmTicket.js");
32
+ Object.defineProperty(exports, "createAlarmTicket", { enumerable: true, get: function () { return createAlarmTicket_js_1.createAlarmTicket; } });
33
+ Object.defineProperty(exports, "tenantForAlarmTicket", { enumerable: true, get: function () { return createAlarmTicket_js_1.tenantForAlarmTicket; } });
34
+ var ensureAlarmTicketAction_js_1 = require("./ticket/ensureAlarmTicketAction.js");
35
+ Object.defineProperty(exports, "ensureAlarmTicketAction", { enumerable: true, get: function () { return ensureAlarmTicketAction_js_1.ensureAlarmTicketAction; } });
36
+ var AlarmTicketTypes_js_1 = require("./ticket/AlarmTicketTypes.js");
37
+ Object.defineProperty(exports, "ALARM_TICKET_ACTION_ID", { enumerable: true, get: function () { return AlarmTicketTypes_js_1.ALARM_TICKET_ACTION_ID; } });
38
+ Object.defineProperty(exports, "ALARM_TICKET_SECRET_CONFIG_KEY", { enumerable: true, get: function () { return AlarmTicketTypes_js_1.ALARM_TICKET_SECRET_CONFIG_KEY; } });
39
+ // `schedule/` — "schedule maintenance", an alarm that reports wear.
40
+ var alarmScheduleFields_js_1 = require("./schedule/alarmScheduleFields.js");
41
+ Object.defineProperty(exports, "alarmScheduleFields", { enumerable: true, get: function () { return alarmScheduleFields_js_1.alarmScheduleFields; } });
42
+ Object.defineProperty(exports, "dueDate", { enumerable: true, get: function () { return alarmScheduleFields_js_1.dueDate; } });
43
+ var createAlarmSchedule_js_1 = require("./schedule/createAlarmSchedule.js");
44
+ Object.defineProperty(exports, "createAlarmSchedule", { enumerable: true, get: function () { return createAlarmSchedule_js_1.createAlarmSchedule; } });
45
+ Object.defineProperty(exports, "tenantForAlarmSchedule", { enumerable: true, get: function () { return createAlarmSchedule_js_1.tenantForAlarmSchedule; } });
46
+ var ensureAlarmScheduleAction_js_1 = require("./schedule/ensureAlarmScheduleAction.js");
47
+ Object.defineProperty(exports, "ensureAlarmScheduleAction", { enumerable: true, get: function () { return ensureAlarmScheduleAction_js_1.ensureAlarmScheduleAction; } });
48
+ var listAlarmTriggers_js_1 = require("./schedule/listAlarmTriggers.js");
49
+ Object.defineProperty(exports, "listAlarmTriggers", { enumerable: true, get: function () { return listAlarmTriggers_js_1.listAlarmTriggers; } });
50
+ var AlarmScheduleTypes_js_1 = require("./schedule/AlarmScheduleTypes.js");
51
+ Object.defineProperty(exports, "ALARM_SCHEDULE_ACTION_ID", { enumerable: true, get: function () { return AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID; } });
52
+ Object.defineProperty(exports, "ALARM_SCHEDULE_SECRET_CONFIG_KEY", { enumerable: true, get: function () { return AlarmScheduleTypes_js_1.ALARM_SCHEDULE_SECRET_CONFIG_KEY; } });
@@ -0,0 +1,17 @@
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>;
@@ -0,0 +1,42 @@
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
+ const explicit = await new node_1.default.Query(index_js_1.Service_Equipment)
26
+ .equalTo("objectId", equipmentId)
27
+ .first({ useMasterKey: true });
28
+ if (explicit)
29
+ return explicit;
30
+ console.warn(`${logPrefix} Configured machine ${equipmentId} does not exist`);
31
+ }
32
+ const candidates = [event.item_id, event.item_source].filter((value) => !!value);
33
+ if (candidates.length === 0)
34
+ return undefined;
35
+ const query = new node_1.default.Query(index_js_1.Service_Equipment)
36
+ .equalTo("tenant", tenant)
37
+ .notEqualTo("deleted", true)
38
+ // `sourceTags` is an Array column: Mongo reads "contained in" as "the array
39
+ // holds one of these". The generated type only knows `any[]`, hence the cast.
40
+ .containedIn("sourceTags", candidates);
41
+ return (await query.first({ useMasterKey: true })) ?? undefined;
42
+ }
@@ -0,0 +1,88 @@
1
+ /**
2
+ * The alarm action "create a one-off maintenance schedule".
3
+ *
4
+ * An open.DASH alarm watches a sensor value against a rule; when the rule
5
+ * breaks, its configured **action** runs. Actions are rows in `OD3_AlarmAction`
6
+ * (loaded into the frontend by the monitoring adapter); an action of
7
+ * `type: "webhook"` is carried out by an `OD3_AlarmWebhook` row, which POSTs to
8
+ * a URL. This module is the receiving end: it turns one fired alarm into a
9
+ * single appointment in the maintenance calendar.
10
+ *
11
+ * Sibling of the ticket action next to it, and deliberately shaped like it —
12
+ * the two differ in *what* they create, not in how they are called, secured or
13
+ * deduplicated. The split is the domain one: an alarm that reports a **finding**
14
+ * raises a ticket, an alarm that reports **wear** schedules maintenance.
15
+ */
16
+ /** Id of the action row, and the marker in a schedule's `origin`. */
17
+ export declare const ALARM_SCHEDULE_ACTION_ID = "openservice-create-schedule";
18
+ /**
19
+ * Config key of the shared secret an executor authenticates with.
20
+ *
21
+ * Deliberately its own key rather than sharing the ticket action's: the two
22
+ * endpoints create different things, and a tenant that wants alarm tickets does
23
+ * not automatically want alarms writing into its maintenance plan. Revoking one
24
+ * must not revoke the other.
25
+ */
26
+ export declare const ALARM_SCHEDULE_SECRET_CONFIG_KEY = "OPENSERVICE_ALARM_SCHEDULE_SECRET";
27
+ /**
28
+ * What the person configuring the alarm filled into the action's form
29
+ * (`OD3_AlarmAction.formFields`).
30
+ */
31
+ export interface AlarmScheduleParams {
32
+ /**
33
+ * Template to copy steps and settings from — the main point of the action.
34
+ *
35
+ * Without one the plan is created with no steps: still a dated entry in the
36
+ * calendar that somebody can act on, which beats refusing the alarm.
37
+ */
38
+ templateId?: string;
39
+ /** Plan title; `{{alarm}}`, `{{sensor}}` and `{{value}}` are replaced. */
40
+ title?: string;
41
+ /**
42
+ * Machine the plan belongs to.
43
+ *
44
+ * Set explicitly when configuring the alarm — that is the reliable way,
45
+ * because nothing in the data model links a sensor to a machine. Without it,
46
+ * `Equipment.sourceTags` is tried (see `resolveEquipment`).
47
+ */
48
+ equipmentId?: string;
49
+ /**
50
+ * Days between the alarm firing and the appointment. Default `0` — due now.
51
+ *
52
+ * For wear that is noticed early ("filter is getting full"), a few days of
53
+ * lead time is the difference between a planned job and an interruption.
54
+ */
55
+ dueInDays?: number;
56
+ /** Accent colour of the plan, `#rrggbb`. Unset derives one from the id. */
57
+ color?: string;
58
+ /**
59
+ * Reopen behaviour. `false` (default) keeps **one open appointment per
60
+ * alarm**: a flapping sensor does not fill the calendar, and performing the
61
+ * maintenance arms the alarm again. `true` creates one per firing.
62
+ */
63
+ duplicate?: boolean;
64
+ }
65
+ /**
66
+ * The alarm that produced a plan, recorded on `Schedule.asset.alarm`.
67
+ *
68
+ * A plan has no description field, so the context of the firing would
69
+ * otherwise be lost between the title and the `origin` marker. Structured
70
+ * rather than prose because the trigger overview reads it back — and mirrored
71
+ * in `openservice-core` (`ScheduleAlarmContext`) so the frontend has the type.
72
+ */
73
+ export interface ScheduleAlarmContext {
74
+ /** `OD3_Alarm.objectId`, when the executor reported one. */
75
+ alarmId?: string;
76
+ /** The alarm's name at the time it fired. */
77
+ name?: string;
78
+ /** `source/id [dimension]` — the sensor, as shown to a human. */
79
+ sensor?: string;
80
+ /** The value that broke the rule. */
81
+ value?: number | string | boolean;
82
+ /** Human-readable rule, e.g. `> 80`. */
83
+ condition?: string;
84
+ /** ISO timestamp of the firing. */
85
+ firedAt: string;
86
+ /** Which action row created the plan. */
87
+ actionId: string;
88
+ }
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ /**
3
+ * The alarm action "create a one-off maintenance schedule".
4
+ *
5
+ * An open.DASH alarm watches a sensor value against a rule; when the rule
6
+ * breaks, its configured **action** runs. Actions are rows in `OD3_AlarmAction`
7
+ * (loaded into the frontend by the monitoring adapter); an action of
8
+ * `type: "webhook"` is carried out by an `OD3_AlarmWebhook` row, which POSTs to
9
+ * a URL. This module is the receiving end: it turns one fired alarm into a
10
+ * single appointment in the maintenance calendar.
11
+ *
12
+ * Sibling of the ticket action next to it, and deliberately shaped like it —
13
+ * the two differ in *what* they create, not in how they are called, secured or
14
+ * deduplicated. The split is the domain one: an alarm that reports a **finding**
15
+ * raises a ticket, an alarm that reports **wear** schedules maintenance.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ALARM_SCHEDULE_SECRET_CONFIG_KEY = exports.ALARM_SCHEDULE_ACTION_ID = void 0;
19
+ /** Id of the action row, and the marker in a schedule's `origin`. */
20
+ exports.ALARM_SCHEDULE_ACTION_ID = "openservice-create-schedule";
21
+ /**
22
+ * Config key of the shared secret an executor authenticates with.
23
+ *
24
+ * Deliberately its own key rather than sharing the ticket action's: the two
25
+ * endpoints create different things, and a tenant that wants alarm tickets does
26
+ * not automatically want alarms writing into its maintenance plan. Revoking one
27
+ * must not revoke the other.
28
+ */
29
+ exports.ALARM_SCHEDULE_SECRET_CONFIG_KEY = "OPENSERVICE_ALARM_SCHEDULE_SECRET";
@@ -0,0 +1,27 @@
1
+ import type { AlarmEvent } from "../AlarmEvent.js";
2
+ import { type AlarmScheduleParams, type ScheduleAlarmContext } from "./AlarmScheduleTypes.js";
3
+ /**
4
+ * Alarm + action parameters → the fields of a one-off maintenance plan.
5
+ *
6
+ * Pure, so the wording, the due date arithmetic and — most importantly — the
7
+ * `origin` marker can be checked without a database.
8
+ */
9
+ /** Everything a fired alarm contributes to the plan it creates. */
10
+ export interface AlarmScheduleFields {
11
+ title: string;
12
+ origin: string;
13
+ /** When the appointment is due — firing time plus the configured lead. */
14
+ due: Date;
15
+ /** Structured record of the firing, stored on `Schedule.asset.alarm`. */
16
+ alarmContext: ScheduleAlarmContext;
17
+ }
18
+ export declare function alarmScheduleFields(event: AlarmEvent, params?: AlarmScheduleParams, templateTitle?: string): AlarmScheduleFields;
19
+ /**
20
+ * When the appointment lands.
21
+ *
22
+ * Measured from the **firing**, not from the call: a webhook that was queued or
23
+ * retried must not push the appointment further out. `dueInDays` is clamped at
24
+ * zero — a negative lead would date the maintenance before the alarm that asked
25
+ * for it, which no calendar can render sensibly.
26
+ */
27
+ export declare function dueDate(event: AlarmEvent, params?: AlarmScheduleParams): Date;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.alarmScheduleFields = alarmScheduleFields;
4
+ exports.dueDate = dueDate;
5
+ const alarmIdentity_js_1 = require("../alarmIdentity.js");
6
+ const AlarmScheduleTypes_js_1 = require("./AlarmScheduleTypes.js");
7
+ function alarmScheduleFields(event, params = {}, templateTitle) {
8
+ return {
9
+ title: renderTitle(event, params, templateTitle),
10
+ origin: (0, alarmIdentity_js_1.alarmOrigin)(event),
11
+ due: dueDate(event, params),
12
+ alarmContext: {
13
+ alarmId: event.alarmId,
14
+ name: event.name,
15
+ sensor: (0, alarmIdentity_js_1.sensorLabel)(event) || undefined,
16
+ value: event.value,
17
+ condition: event.condition,
18
+ firedAt: (0, alarmIdentity_js_1.firedAt)(event).toISOString(),
19
+ actionId: AlarmScheduleTypes_js_1.ALARM_SCHEDULE_ACTION_ID,
20
+ },
21
+ };
22
+ }
23
+ /**
24
+ * When the appointment lands.
25
+ *
26
+ * Measured from the **firing**, not from the call: a webhook that was queued or
27
+ * retried must not push the appointment further out. `dueInDays` is clamped at
28
+ * zero — a negative lead would date the maintenance before the alarm that asked
29
+ * for it, which no calendar can render sensibly.
30
+ */
31
+ function dueDate(event, params = {}) {
32
+ const fired = (0, alarmIdentity_js_1.firedAt)(event);
33
+ const days = Number.isFinite(params.dueInDays) ? Number(params.dueInDays) : 0;
34
+ if (days <= 0)
35
+ return fired;
36
+ return new Date(fired.getTime() + days * 24 * 60 * 60 * 1000);
37
+ }
38
+ /**
39
+ * The plan's title.
40
+ *
41
+ * Order of preference: what the user templated into the action form, then the
42
+ * template's own title (the usual case — somebody picked "Filterwechsel"), then
43
+ * the alarm's name, then the sensor. A plan must have a title; `title` is
44
+ * `required` on the class.
45
+ */
46
+ function renderTitle(event, params, templateTitle) {
47
+ const rendered = (0, alarmIdentity_js_1.renderTitleTemplate)(params.title, event);
48
+ if (rendered)
49
+ return rendered;
50
+ if (templateTitle?.trim())
51
+ return templateTitle.trim();
52
+ if (event.name?.trim())
53
+ return event.name.trim();
54
+ const sensor = (0, alarmIdentity_js_1.sensorLabel)(event);
55
+ return sensor ? `Wartung: ${sensor}` : "Wartung (Alarm)";
56
+ }
@@ -0,0 +1,37 @@
1
+ import { Tenant } from "../../../../types/index.js";
2
+ import type { AlarmEvent } from "../AlarmEvent.js";
3
+ import { type AlarmScheduleParams } from "./AlarmScheduleTypes.js";
4
+ /** Outcome of one fired alarm. */
5
+ export interface AlarmScheduleResult {
6
+ scheduleId: string;
7
+ /** `false` when an unperformed appointment for this alarm already existed. */
8
+ created: boolean;
9
+ origin: string;
10
+ /** ISO timestamp of the appointment. */
11
+ due: string;
12
+ equipmentId?: string;
13
+ templateId?: string;
14
+ }
15
+ /**
16
+ * Create the one-off appointment a fired alarm asks for — or return the one
17
+ * that is already waiting.
18
+ *
19
+ * **One open appointment per alarm** is the default (`params.duplicate` opts
20
+ * out). A sensor that crosses its threshold every few minutes would otherwise
21
+ * fill the calendar with the same job; performing the maintenance arms the
22
+ * alarm again, which is the behaviour the ticket action already establishes.
23
+ *
24
+ * The plan is a perfectly ordinary `OD3_Service_Schedule` with a `COUNT=1`
25
+ * RRULE — the spelling the frontend's `oneOffCadence()` produces and
26
+ * `isOneOff()` recognises. Nothing about the calendar, the detail page, the
27
+ * execution runner or the notification worker has to know an alarm was
28
+ * involved; they all read a plan.
29
+ */
30
+ export declare function createAlarmSchedule(tenant: Tenant, event: AlarmEvent, params?: AlarmScheduleParams): Promise<AlarmScheduleResult>;
31
+ /**
32
+ * The tenant a call belongs to, identified by its shared secret.
33
+ *
34
+ * Its own config key, deliberately: enabling alarm tickets must not also let
35
+ * alarms write into the maintenance plan.
36
+ */
37
+ export declare function tenantForAlarmSchedule(secret: string): Promise<Tenant | undefined>;