@openinc/parse-server-opendash 4.4.6 → 4.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/dist/featuremap.json +6 -7
  2. package/dist/features/config/index.d.ts +4 -1
  3. package/dist/features/config/index.js +6 -1
  4. package/dist/features/config/services/ensureConfigs.d.ts +29 -0
  5. package/dist/features/config/services/ensureConfigs.js +133 -0
  6. package/dist/features/config/types/ConfigKeys.d.ts +87 -7
  7. package/dist/features/config/types/ConfigKeys.js +112 -11
  8. package/dist/features/openservice/alarms/actionParams.d.ts +29 -0
  9. package/dist/features/openservice/alarms/actionParams.js +63 -0
  10. package/dist/features/openservice/alarms/index.d.ts +1 -1
  11. package/dist/features/openservice/alarms/index.js +2 -1
  12. package/dist/features/openservice/alarms/schedule/createAlarmSchedule.d.ts +1 -1
  13. package/dist/features/openservice/alarms/schedule/createAlarmSchedule.js +23 -1
  14. package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.d.ts +17 -0
  15. package/dist/features/openservice/alarms/schedule/ensureAlarmScheduleAction.js +83 -1
  16. package/dist/features/openservice/alarms/schedule/listAlarmTriggers.js +44 -22
  17. package/dist/features/openservice/alarms/ticket/createAlarmTicket.d.ts +1 -1
  18. package/dist/features/openservice/alarms/ticket/createAlarmTicket.js +10 -1
  19. package/dist/features/openservice/alarms/ticket/ensureAlarmTicketAction.js +18 -1
  20. package/dist/features/openservice/init.js +8 -3
  21. package/dist/features/openservice/serviceProviders/ProviderAccessTypes.d.ts +23 -0
  22. package/dist/features/openservice/serviceProviders/ProviderAccessTypes.js +17 -0
  23. package/dist/features/openservice/serviceProviders/grantProviderAccess.d.ts +35 -0
  24. package/dist/features/openservice/serviceProviders/grantProviderAccess.js +172 -0
  25. package/dist/features/openservice/serviceProviders/index.d.ts +5 -0
  26. package/dist/features/openservice/serviceProviders/index.js +12 -0
  27. package/dist/features/openservice/serviceProviders/providerRoleSetup.d.ts +63 -0
  28. package/dist/features/openservice/serviceProviders/providerRoleSetup.js +110 -0
  29. package/dist/features/openservice/setupStatus.d.ts +55 -0
  30. package/dist/features/openservice/setupStatus.js +139 -0
  31. package/dist/features/permissions/types/Permissions.d.ts +1 -0
  32. package/dist/features/permissions/types/Permissions.js +5 -0
  33. package/dist/functions/openinc-auth-login-passwordless.js +7 -2
  34. package/dist/functions/openinc-auth-validate-token.js +6 -0
  35. package/dist/functions/openinc-auth.common.js +13 -0
  36. package/dist/functions/openinc-openservice-provider-access.d.ts +22 -0
  37. package/dist/functions/openinc-openservice-provider-access.js +54 -0
  38. package/dist/functions/openinc-openservice-provider-setup.d.ts +19 -0
  39. package/dist/functions/openinc-openservice-provider-setup.js +57 -0
  40. package/dist/functions/openinc-openservice-setup.d.ts +24 -0
  41. package/dist/functions/openinc-openservice-setup.js +140 -0
  42. package/dist/hooks/Config_open_service.js +34 -10
  43. package/dist/hooks/Service_Equipment.js +6 -11
  44. package/dist/hooks/Service_Schedule_Execution.js +136 -7
  45. package/dist/scripts/migration/lib/articleMeta.d.ts +20 -7
  46. package/dist/scripts/migration/lib/articleMeta.js +20 -14
  47. package/dist/scripts/migration/passes/05-articles.d.ts +17 -8
  48. package/dist/scripts/migration/passes/05-articles.js +43 -24
  49. package/dist/types/BDE_Article.d.ts +27 -3
  50. package/dist/types/BDE_Article.js +48 -0
  51. package/dist/types/Service_MigrationMap.d.ts +26 -0
  52. package/dist/types/Service_MigrationMap.js +45 -0
  53. package/dist/types/Service_Occurrence.d.ts +31 -0
  54. package/dist/types/Service_Occurrence.js +51 -0
  55. package/dist/types/Service_Schedule_Execution.d.ts +22 -3
  56. package/dist/types/Service_Schedule_Execution.js +36 -0
  57. package/dist/types/index.d.ts +4 -4
  58. package/dist/types/index.js +5 -5
  59. package/package.json +1 -1
  60. package/schema/BDE_Article.json +41 -6
  61. package/schema/Service_FormConfig.json +10 -10
  62. package/schema/{Service_TriggerState.json → Service_Occurrence.json} +21 -9
  63. package/schema/Service_Schedule_Execution.json +27 -1
  64. package/dist/hooks/Service_TriggerState.d.ts +0 -1
  65. package/dist/hooks/Service_TriggerState.js +0 -17
  66. package/dist/types/Service_MeterReading.d.ts +0 -35
  67. package/dist/types/Service_MeterReading.js +0 -57
  68. package/dist/types/Service_TriggerState.d.ts +0 -31
  69. package/dist/types/Service_TriggerState.js +0 -51
  70. package/schema/Service_MeterReading.json +0 -54
@@ -48,11 +48,6 @@
48
48
  "OD3_Knowledge_Video": "KNOWLEDGE",
49
49
  "OD3_Language": "CORE",
50
50
  "OD3_Log": "CORE",
51
- "OD3_MES_Article": "MONITORING",
52
- "OD3_MES_Order": "MONITORING",
53
- "OD3_MES_OrderPlan": "MONITORING",
54
- "OD3_MIAAS_MDSEndpoint": "MIAAS",
55
- "OD3_ML_DataSelection": "MASCHINELEARNING",
56
51
  "OD3_MailTemplate": "MONITORING",
57
52
  "OD3_Mail_Groups": "MONITORING",
58
53
  "OD3_Maintenance_Downtime": "MAINTENANCE",
@@ -86,9 +81,14 @@
86
81
  "OD3_Maintenance_Ticket_QR_Code": "MAINTENANCE",
87
82
  "OD3_Maintenance_Ticket_Source": "MAINTENANCE",
88
83
  "OD3_Maintenance_Ticket_Title": "MAINTENANCE",
84
+ "OD3_MES_Article": "MONITORING",
85
+ "OD3_MES_Order": "MONITORING",
86
+ "OD3_MES_OrderPlan": "MONITORING",
89
87
  "OD3_Meta_Config": "CORE",
90
88
  "OD3_Meta_Context": "CORE",
91
89
  "OD3_Meta_Entry": "CORE",
90
+ "OD3_MIAAS_MDSEndpoint": "MIAAS",
91
+ "OD3_ML_DataSelection": "MASCHINELEARNING",
92
92
  "OD3_Monitoring_DataHierachies": "MONITORING",
93
93
  "OD3_Monitoring_Jobs": "MONITORING",
94
94
  "OD3_Monitoring_ParseTableSensor": "MONITORING",
@@ -111,8 +111,8 @@
111
111
  "OD3_Report": "CORE",
112
112
  "OD3_Service_Equipment": "SERVICE",
113
113
  "OD3_Service_FormConfig": "SERVICE",
114
- "OD3_Service_MeterReading": "SERVICE",
115
114
  "OD3_Service_MigrationMap": "SERVICE",
115
+ "OD3_Service_Occurrence": "SERVICE",
116
116
  "OD3_Service_Project": "SERVICE",
117
117
  "OD3_Service_Schedule": "SERVICE",
118
118
  "OD3_Service_Schedule_Execution": "SERVICE",
@@ -121,7 +121,6 @@
121
121
  "OD3_Service_Tag": "SERVICE",
122
122
  "OD3_Service_Ticket": "SERVICE",
123
123
  "OD3_Service_TicketCounter": "SERVICE",
124
- "OD3_Service_TriggerState": "SERVICE",
125
124
  "OD3_Share": "CORE",
126
125
  "OD3_Source": "CORE",
127
126
  "OD3_SourceMeta": "CORE",
@@ -1,7 +1,10 @@
1
1
  export type { CommonConfigValue, ConfigBooleanValue, ConfigMap, ConfigValue, } from "./types/configTypes.js";
2
2
  export { ConfigState } from "./states/Config.js";
3
3
  export { default as ConfigInstance } from "./services/ConfigInstance.js";
4
- export { ConfigKeys } from "./types/ConfigKeys.js";
4
+ export { ALL_CONFIG_KEYS, ConfigKeys, configKeyDefinition, OPENSERVICE_CONFIG_KEYS, } from "./types/ConfigKeys.js";
5
+ export type { ConfigKeyDefinition, ConfigScope } from "./types/ConfigKeys.js";
6
+ export { ensureConfigs } from "./services/ensureConfigs.js";
7
+ export type { EnsureConfigsResult } from "./services/ensureConfigs.js";
5
8
  export { baseoptions } from "./helper/baseOptions.js";
6
9
  export { customoptions } from "./helper/customOptions.js";
7
10
  export { getConfig, getConfigBoolean } from "./helper/getConfig.js";
@@ -3,13 +3,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.isFeatureEnabled = exports.getConfigBoolean = exports.getConfig = exports.customoptions = exports.baseoptions = exports.ConfigKeys = exports.ConfigInstance = exports.ConfigState = void 0;
6
+ exports.isFeatureEnabled = exports.getConfigBoolean = exports.getConfig = exports.customoptions = exports.baseoptions = exports.ensureConfigs = exports.OPENSERVICE_CONFIG_KEYS = exports.configKeyDefinition = exports.ConfigKeys = exports.ALL_CONFIG_KEYS = exports.ConfigInstance = exports.ConfigState = void 0;
7
7
  var Config_js_1 = require("./states/Config.js");
8
8
  Object.defineProperty(exports, "ConfigState", { enumerable: true, get: function () { return Config_js_1.ConfigState; } });
9
9
  var ConfigInstance_js_1 = require("./services/ConfigInstance.js");
10
10
  Object.defineProperty(exports, "ConfigInstance", { enumerable: true, get: function () { return __importDefault(ConfigInstance_js_1).default; } });
11
11
  var ConfigKeys_js_1 = require("./types/ConfigKeys.js");
12
+ Object.defineProperty(exports, "ALL_CONFIG_KEYS", { enumerable: true, get: function () { return ConfigKeys_js_1.ALL_CONFIG_KEYS; } });
12
13
  Object.defineProperty(exports, "ConfigKeys", { enumerable: true, get: function () { return ConfigKeys_js_1.ConfigKeys; } });
14
+ Object.defineProperty(exports, "configKeyDefinition", { enumerable: true, get: function () { return ConfigKeys_js_1.configKeyDefinition; } });
15
+ Object.defineProperty(exports, "OPENSERVICE_CONFIG_KEYS", { enumerable: true, get: function () { return ConfigKeys_js_1.OPENSERVICE_CONFIG_KEYS; } });
16
+ var ensureConfigs_js_1 = require("./services/ensureConfigs.js");
17
+ Object.defineProperty(exports, "ensureConfigs", { enumerable: true, get: function () { return ensureConfigs_js_1.ensureConfigs; } });
13
18
  var baseOptions_js_1 = require("./helper/baseOptions.js");
14
19
  Object.defineProperty(exports, "baseoptions", { enumerable: true, get: function () { return baseOptions_js_1.baseoptions; } });
15
20
  var customOptions_js_1 = require("./helper/customOptions.js");
@@ -0,0 +1,29 @@
1
+ /** What a bootstrap run did, so the log says something useful. */
2
+ export interface EnsureConfigsResult {
3
+ created: string[];
4
+ /** Catalogued, needed, and not creatable without a human. */
5
+ missing: string[];
6
+ }
7
+ /**
8
+ * Create the config rows an installation needs, for every tenant.
9
+ *
10
+ * **Why the server and not a setup page.** Setting open.SERVICE up meant
11
+ * creating rows by hand in the Parse dashboard, and forgetting one produced an
12
+ * endpoint that refuses every call with "unknown tenant or invalid secret" —
13
+ * a message that is deliberately unhelpful to an attacker and therefore
14
+ * unhelpful to the administrator too. Anything with a sensible default should
15
+ * simply exist.
16
+ *
17
+ * **Secrets are generated rather than defaulted.** A `defaultValue` of
18
+ * "changeme" is a value everybody keeps. A generated one is usable
19
+ * immediately: the endpoint works from the first boot, and the administrator
20
+ * only has to *read* the secret to paste it into the executor — which the
21
+ * setup page offers.
22
+ *
23
+ * **It only ever creates.** An existing row is never touched, not even an
24
+ * empty one: somebody may have emptied it on purpose, and a bootstrap that
25
+ * overwrites configuration is a bootstrap nobody dares to run twice.
26
+ *
27
+ * Idempotent, so it belongs in `init()` next to the other `ensure*` functions.
28
+ */
29
+ export declare function ensureConfigs(): Promise<EnsureConfigsResult>;
@@ -0,0 +1,133 @@
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.ensureConfigs = ensureConfigs;
7
+ const crypto_1 = require("crypto");
8
+ const node_1 = __importDefault(require("parse/node"));
9
+ const index_js_1 = require("../../../types/index.js");
10
+ const ConfigKeys_js_1 = require("../types/ConfigKeys.js");
11
+ /**
12
+ * Create the config rows an installation needs, for every tenant.
13
+ *
14
+ * **Why the server and not a setup page.** Setting open.SERVICE up meant
15
+ * creating rows by hand in the Parse dashboard, and forgetting one produced an
16
+ * endpoint that refuses every call with "unknown tenant or invalid secret" —
17
+ * a message that is deliberately unhelpful to an attacker and therefore
18
+ * unhelpful to the administrator too. Anything with a sensible default should
19
+ * simply exist.
20
+ *
21
+ * **Secrets are generated rather than defaulted.** A `defaultValue` of
22
+ * "changeme" is a value everybody keeps. A generated one is usable
23
+ * immediately: the endpoint works from the first boot, and the administrator
24
+ * only has to *read* the secret to paste it into the executor — which the
25
+ * setup page offers.
26
+ *
27
+ * **It only ever creates.** An existing row is never touched, not even an
28
+ * empty one: somebody may have emptied it on purpose, and a bootstrap that
29
+ * overwrites configuration is a bootstrap nobody dares to run twice.
30
+ *
31
+ * Idempotent, so it belongs in `init()` next to the other `ensure*` functions.
32
+ */
33
+ async function ensureConfigs() {
34
+ const tenants = await new node_1.default.Query(index_js_1.Tenant).findAll({
35
+ useMasterKey: true,
36
+ });
37
+ const created = [];
38
+ const missing = [];
39
+ for (const tenant of tenants) {
40
+ for (const definition of ConfigKeys_js_1.OPENSERVICE_CONFIG_KEYS) {
41
+ // Runtime state belongs to the software that writes it; creating it here
42
+ // would fake progress the worker never made.
43
+ if (definition.runtimeState)
44
+ continue;
45
+ if (definition.scope !== "tenant")
46
+ continue;
47
+ const existing = await new node_1.default.Query(index_js_1.Config)
48
+ .equalTo("key", definition.key)
49
+ .equalTo("tenant", tenant)
50
+ .first({ useMasterKey: true });
51
+ if (existing) {
52
+ // An existing row keeps its value, but a secret may still carry the
53
+ // permissive grant — from before this bootstrap existed, or from the
54
+ // `Config_open_service` hook, which applied it to every `OPENSERVICE_*`
55
+ // row regardless. That is the difference between a shared secret and a
56
+ // public one, so it is repaired on every boot rather than once.
57
+ if (definition.secret && (await tightenSecretAcl(existing, tenant))) {
58
+ console.log(`[Config] Tightened ACL of ${definition.key} for tenant ${tenant.id}`);
59
+ }
60
+ continue;
61
+ }
62
+ const value = initialValue(definition);
63
+ if (value === undefined) {
64
+ if (definition.required)
65
+ missing.push(`${definition.key}@${tenant.id}`);
66
+ continue;
67
+ }
68
+ const config = new index_js_1.Config();
69
+ config.set("key", definition.key);
70
+ config.set("value", value);
71
+ config.set("tenant", tenant);
72
+ config.set("priority", 0);
73
+ config.setACL(configAcl(definition, tenant));
74
+ await config.save(null, { useMasterKey: true });
75
+ created.push(`${definition.key}@${tenant.id}`);
76
+ }
77
+ }
78
+ if (created.length > 0) {
79
+ console.log(`[Config] Created ${created.length} row(s): ${created.join(", ")}`);
80
+ }
81
+ if (missing.length > 0) {
82
+ console.warn(`[Config] Still missing (needs manual input): ${missing.join(", ")}`);
83
+ }
84
+ return { created, missing };
85
+ }
86
+ /** The value a row starts with, or `undefined` when only a human can supply it. */
87
+ function initialValue(definition) {
88
+ if (definition.generate === "secret")
89
+ return (0, crypto_1.randomBytes)(32).toString("hex");
90
+ return definition.defaultValue;
91
+ }
92
+ /**
93
+ * Who may read a config row.
94
+ *
95
+ * `hooks/Config.ts` applies no ACL of its own — it only calls `defaultHandler`
96
+ * — so whatever is set here is what the row keeps. That matters most for
97
+ * secrets: the rows written before this existed are readable *and writable* by
98
+ * every user in the tenant, which for a shared secret means anybody in the
99
+ * tenant can both read it and hand themselves a working one.
100
+ */
101
+ function configAcl(definition, tenant) {
102
+ const acl = new node_1.default.ACL();
103
+ acl.setRoleReadAccess("od-admin", true);
104
+ acl.setRoleWriteAccess("od-admin", true);
105
+ acl.setRoleReadAccess(`od-tenant-admin-${tenant.id}`, true);
106
+ acl.setRoleWriteAccess(`od-tenant-admin-${tenant.id}`, true);
107
+ // Ordinary members read the non-secret settings — the ticket admin edits the
108
+ // notification rules, and the frontend reads them back.
109
+ if (!definition.secret) {
110
+ acl.setRoleReadAccess(`od-tenant-user-${tenant.id}`, true);
111
+ acl.setRoleWriteAccess(`od-tenant-user-${tenant.id}`, true);
112
+ }
113
+ return acl;
114
+ }
115
+ /**
116
+ * Take tenant-user access away from a secret row that still grants it.
117
+ *
118
+ * Returns whether anything was changed, so the caller only logs a real repair.
119
+ */
120
+ async function tightenSecretAcl(config, tenant) {
121
+ const acl = config.getACL();
122
+ if (!acl)
123
+ return false;
124
+ const role = `od-tenant-user-${tenant.id}`;
125
+ if (!acl.getRoleReadAccess(role) && !acl.getRoleWriteAccess(role)) {
126
+ return false;
127
+ }
128
+ acl.setRoleReadAccess(role, false);
129
+ acl.setRoleWriteAccess(role, false);
130
+ config.setACL(acl);
131
+ await config.save(null, { useMasterKey: true });
132
+ return true;
133
+ }
@@ -1,8 +1,88 @@
1
- export declare namespace ConfigKeys {
2
- enum OpenService {
3
- closedTicketsLifetime = "OPENSERVICE_CLOSED_TICKET_LIFETIME",
4
- ticketCreationForm = "OPENSERVICE_CREATE_TICKET_FORM",
5
- scheduleMetaFields = "OPENSERVICE_SCHEDULE_META_FIELDS",
6
- createTicketOnSchedule = "OPENSERVICE_CREATE_TICKET_ON_SCHEDULE"
7
- }
1
+ /**
2
+ * Every `OD3_Config` key this server knows, with what it is for and what it
3
+ * should hold when nobody has said otherwise.
4
+ *
5
+ * **Why a catalogue and not just string constants.** Setting an installation up
6
+ * used to mean creating rows by hand in the Parse dashboard, from a list that
7
+ * existed only in people's heads: the keys were spelled out inline at their
8
+ * point of use, some of them in three different files. A key nobody documented
9
+ * is a key somebody forgets, and a forgotten key is an endpoint that refuses
10
+ * every call for a reason nobody can see.
11
+ *
12
+ * Entries with a `defaultValue` (or `generate`) are created automatically at
13
+ * boot by `ensureConfigs()`. The rest need a human because they need data only
14
+ * the customer has — those are listed too, so a setup page can show what is
15
+ * still missing instead of leaving it to be discovered in production.
16
+ *
17
+ * **Never overwritten.** The bootstrap only ever creates; an existing value is
18
+ * left exactly as it is, including an empty one somebody set deliberately.
19
+ */
20
+ /** Where a config row lives. */
21
+ export type ConfigScope =
22
+ /** One row per tenant, `tenant` set. The usual case. */
23
+ "tenant"
24
+ /** A single row without `tenant` — server-wide runtime state. */
25
+ | "global";
26
+ export interface ConfigKeyDefinition {
27
+ key: string;
28
+ /** One line, shown in the setup UI. */
29
+ description: string;
30
+ scope: ConfigScope;
31
+ /**
32
+ * Holds a credential. Such a row gets a restrictive ACL and is never shown
33
+ * in full without being asked for explicitly.
34
+ */
35
+ secret?: boolean;
36
+ /**
37
+ * Written on creation when the row does not exist. Omit for a key that
38
+ * cannot be guessed — it is then reported as missing instead.
39
+ */
40
+ defaultValue?: string;
41
+ /**
42
+ * Generated on creation, for values that must be unguessable. Beats a
43
+ * `defaultValue` of "changeme", which is what everybody would keep.
44
+ */
45
+ generate?: "secret";
46
+ /**
47
+ * The feature does not work without it. A key with neither `defaultValue`
48
+ * nor `generate` and `required: true` is what a setup page complains about.
49
+ */
50
+ required?: boolean;
51
+ /**
52
+ * Written by the software itself, not by a person. Never created by the
53
+ * bootstrap and never offered for editing — deleting one of these loses
54
+ * runtime state (a watermark, a cursor).
55
+ */
56
+ runtimeState?: boolean;
8
57
  }
58
+ /**
59
+ * The open.SERVICE keys.
60
+ *
61
+ * Note the two separate alarm secrets: whoever lets alarms open tickets does
62
+ * not thereby let them write into the maintenance plan, and revoking one must
63
+ * not revoke the other.
64
+ */
65
+ export declare const OPENSERVICE_CONFIG_KEYS: ConfigKeyDefinition[];
66
+ /** Every catalogued key, across features. */
67
+ export declare const ALL_CONFIG_KEYS: ConfigKeyDefinition[];
68
+ /** Look one up by key. */
69
+ export declare function configKeyDefinition(key: string): ConfigKeyDefinition | undefined;
70
+ /**
71
+ * The key names as an enum-like object, for call sites that only need the
72
+ * string.
73
+ *
74
+ * Replaces the old `ConfigKeys` namespace, which listed four keys — three of
75
+ * which no longer existed anywhere — and omitted every key actually in use.
76
+ */
77
+ export declare const ConfigKeys: {
78
+ readonly OpenService: {
79
+ readonly alarmScheduleSecret: "OPENSERVICE_ALARM_SCHEDULE_SECRET";
80
+ readonly alarmTicketSecret: "OPENSERVICE_ALARM_TICKET_SECRET";
81
+ readonly assignmentNotifications: "OPENSERVICE_ASSIGNMENT_NOTIFICATIONS";
82
+ readonly closedTicketsLifetime: "OPENSERVICE_CLOSED_TICKET_LIFETIME";
83
+ readonly createTicketOnSchedule: "OPENSERVICE_CREATE_TICKET_ON_SCHEDULE";
84
+ readonly scheduleMetaFields: "OPENSERVICE_SCHEDULE_META_FIELDS";
85
+ readonly outlookIntegration: "OPENSERVICE_MICROSOFT_OUTLOOK_INTEGRATION";
86
+ readonly v2NotificationWatermark: "OPENSERVICE_V2_NOTIFICATION_WATERMARK";
87
+ };
88
+ };
@@ -1,13 +1,114 @@
1
1
  "use strict";
2
+ /**
3
+ * Every `OD3_Config` key this server knows, with what it is for and what it
4
+ * should hold when nobody has said otherwise.
5
+ *
6
+ * **Why a catalogue and not just string constants.** Setting an installation up
7
+ * used to mean creating rows by hand in the Parse dashboard, from a list that
8
+ * existed only in people's heads: the keys were spelled out inline at their
9
+ * point of use, some of them in three different files. A key nobody documented
10
+ * is a key somebody forgets, and a forgotten key is an endpoint that refuses
11
+ * every call for a reason nobody can see.
12
+ *
13
+ * Entries with a `defaultValue` (or `generate`) are created automatically at
14
+ * boot by `ensureConfigs()`. The rest need a human because they need data only
15
+ * the customer has — those are listed too, so a setup page can show what is
16
+ * still missing instead of leaving it to be discovered in production.
17
+ *
18
+ * **Never overwritten.** The bootstrap only ever creates; an existing value is
19
+ * left exactly as it is, including an empty one somebody set deliberately.
20
+ */
2
21
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ConfigKeys = void 0;
4
- var ConfigKeys;
5
- (function (ConfigKeys) {
6
- let OpenService;
7
- (function (OpenService) {
8
- OpenService["closedTicketsLifetime"] = "OPENSERVICE_CLOSED_TICKET_LIFETIME";
9
- OpenService["ticketCreationForm"] = "OPENSERVICE_CREATE_TICKET_FORM";
10
- OpenService["scheduleMetaFields"] = "OPENSERVICE_SCHEDULE_META_FIELDS";
11
- OpenService["createTicketOnSchedule"] = "OPENSERVICE_CREATE_TICKET_ON_SCHEDULE";
12
- })(OpenService = ConfigKeys.OpenService || (ConfigKeys.OpenService = {}));
13
- })(ConfigKeys || (exports.ConfigKeys = ConfigKeys = {}));
22
+ exports.ConfigKeys = exports.ALL_CONFIG_KEYS = exports.OPENSERVICE_CONFIG_KEYS = void 0;
23
+ exports.configKeyDefinition = configKeyDefinition;
24
+ /**
25
+ * The open.SERVICE keys.
26
+ *
27
+ * Note the two separate alarm secrets: whoever lets alarms open tickets does
28
+ * not thereby let them write into the maintenance plan, and revoking one must
29
+ * not revoke the other.
30
+ */
31
+ exports.OPENSERVICE_CONFIG_KEYS = [
32
+ {
33
+ key: "OPENSERVICE_ALARM_SCHEDULE_SECRET",
34
+ description: "Shared secret an alarm executor sends to create a maintenance plan. Establishes which tenant the call belongs to.",
35
+ scope: "tenant",
36
+ secret: true,
37
+ generate: "secret",
38
+ required: true,
39
+ },
40
+ {
41
+ key: "OPENSERVICE_ALARM_TICKET_SECRET",
42
+ description: "Shared secret an alarm executor sends to create a ticket. Deliberately separate from the schedule secret.",
43
+ scope: "tenant",
44
+ secret: true,
45
+ generate: "secret",
46
+ required: true,
47
+ },
48
+ {
49
+ key: "OPENSERVICE_ASSIGNMENT_NOTIFICATIONS",
50
+ description: "Conditional rules for who is notified about a ticket beyond its assignees. JSON array, edited in the ticket admin.",
51
+ scope: "tenant",
52
+ defaultValue: "[]",
53
+ },
54
+ {
55
+ key: "OPENSERVICE_CLOSED_TICKET_LIFETIME",
56
+ description: 'How long a finished ticket stays enabled, in milliseconds. "0" switches the cleanup off.',
57
+ scope: "tenant",
58
+ defaultValue: "604800000", // 7 days
59
+ },
60
+ {
61
+ key: "OPENSERVICE_MICROSOFT_OUTLOOK_INTEGRATION",
62
+ description: "Outlook calendar connection as JSON (tenant_id, client_id, client_secret, user_email). Needs credentials from the customer, so it cannot be seeded.",
63
+ scope: "tenant",
64
+ secret: true,
65
+ // No default: without the customer's client secret there is nothing to
66
+ // write. Not `required` either — the sync is optional, and its poller is
67
+ // currently switched off (see initServiceSchedulesFeature).
68
+ },
69
+ {
70
+ // Still read by the v1 plugin and by `Config_open_service`'s afterSave,
71
+ // which syncs the configured fields into `Maintenance_Schedule_Step`.
72
+ key: "OPENSERVICE_SCHEDULE_META_FIELDS",
73
+ description: "v1: fields a maintenance step can capture, as a JSON array. Changing it removes step values whose field is gone.",
74
+ scope: "tenant",
75
+ },
76
+ {
77
+ key: "OPENSERVICE_CREATE_TICKET_ON_SCHEDULE",
78
+ description: "v1: whether a due maintenance plan also opens a ticket. Read by the v1 notification job.",
79
+ scope: "tenant",
80
+ },
81
+ {
82
+ key: "OPENSERVICE_V2_NOTIFICATION_WATERMARK",
83
+ description: "How far the notification worker has got. Written by the scheduler; removing it re-sends or skips reminders.",
84
+ scope: "global",
85
+ runtimeState: true,
86
+ },
87
+ ];
88
+ /** Every catalogued key, across features. */
89
+ exports.ALL_CONFIG_KEYS = [
90
+ ...exports.OPENSERVICE_CONFIG_KEYS,
91
+ ];
92
+ /** Look one up by key. */
93
+ function configKeyDefinition(key) {
94
+ return exports.ALL_CONFIG_KEYS.find((definition) => definition.key === key);
95
+ }
96
+ /**
97
+ * The key names as an enum-like object, for call sites that only need the
98
+ * string.
99
+ *
100
+ * Replaces the old `ConfigKeys` namespace, which listed four keys — three of
101
+ * which no longer existed anywhere — and omitted every key actually in use.
102
+ */
103
+ exports.ConfigKeys = {
104
+ OpenService: {
105
+ alarmScheduleSecret: "OPENSERVICE_ALARM_SCHEDULE_SECRET",
106
+ alarmTicketSecret: "OPENSERVICE_ALARM_TICKET_SECRET",
107
+ assignmentNotifications: "OPENSERVICE_ASSIGNMENT_NOTIFICATIONS",
108
+ closedTicketsLifetime: "OPENSERVICE_CLOSED_TICKET_LIFETIME",
109
+ createTicketOnSchedule: "OPENSERVICE_CREATE_TICKET_ON_SCHEDULE",
110
+ scheduleMetaFields: "OPENSERVICE_SCHEDULE_META_FIELDS",
111
+ outlookIntegration: "OPENSERVICE_MICROSOFT_OUTLOOK_INTEGRATION",
112
+ v2NotificationWatermark: "OPENSERVICE_V2_NOTIFICATION_WATERMARK",
113
+ },
114
+ };
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Reading the values an alarm action's form produced.
3
+ *
4
+ * **Why this is not just `typeof value === "string"`.** The `select.parse` field
5
+ * in `FormGenerator` only stores an id when its settings name a `valueField`;
6
+ * without one it stores **the whole selected object**. The open.SERVICE action
7
+ * forms did not name one, so a picked template arrived as an object — the
8
+ * overview then reported "no template", and `createAlarmSchedule` looked up
9
+ * `objectId = [object Object]`, found nothing, and created the plan without any
10
+ * steps. Silently: a missing template is a legitimate configuration.
11
+ *
12
+ * The forms now set `valueField`, but alarms configured before that keep the
13
+ * object, and nothing rewrites a saved alarm. So the read side stays tolerant —
14
+ * which is also the right shape for a value that arrives from an external
15
+ * executor as JSON.
16
+ */
17
+ /**
18
+ * The object id behind a form value, whatever shape it arrived in: a plain id,
19
+ * a Parse pointer, a serialised object, or a live `Parse.Object`.
20
+ *
21
+ * Returns `undefined` for anything that carries no id, so a caller can treat
22
+ * "not configured" and "not readable" the same way — for these fields they mean
23
+ * the same thing in practice.
24
+ */
25
+ export declare function paramId(value: unknown): string | undefined;
26
+ /** A trimmed string, or `undefined` when the value is not usable text. */
27
+ export declare function paramString(value: unknown): string | undefined;
28
+ /** A finite number, or `undefined`. Accepts the numeric strings a form posts. */
29
+ export declare function paramNumber(value: unknown): number | undefined;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ /**
3
+ * Reading the values an alarm action's form produced.
4
+ *
5
+ * **Why this is not just `typeof value === "string"`.** The `select.parse` field
6
+ * in `FormGenerator` only stores an id when its settings name a `valueField`;
7
+ * without one it stores **the whole selected object**. The open.SERVICE action
8
+ * forms did not name one, so a picked template arrived as an object — the
9
+ * overview then reported "no template", and `createAlarmSchedule` looked up
10
+ * `objectId = [object Object]`, found nothing, and created the plan without any
11
+ * steps. Silently: a missing template is a legitimate configuration.
12
+ *
13
+ * The forms now set `valueField`, but alarms configured before that keep the
14
+ * object, and nothing rewrites a saved alarm. So the read side stays tolerant —
15
+ * which is also the right shape for a value that arrives from an external
16
+ * executor as JSON.
17
+ */
18
+ Object.defineProperty(exports, "__esModule", { value: true });
19
+ exports.paramId = paramId;
20
+ exports.paramString = paramString;
21
+ exports.paramNumber = paramNumber;
22
+ /**
23
+ * The object id behind a form value, whatever shape it arrived in: a plain id,
24
+ * a Parse pointer, a serialised object, or a live `Parse.Object`.
25
+ *
26
+ * Returns `undefined` for anything that carries no id, so a caller can treat
27
+ * "not configured" and "not readable" the same way — for these fields they mean
28
+ * the same thing in practice.
29
+ */
30
+ function paramId(value) {
31
+ if (typeof value === "string")
32
+ return value.trim() || undefined;
33
+ if (!value || typeof value !== "object")
34
+ return undefined;
35
+ const candidate = value;
36
+ if (typeof candidate.objectId === "string" && candidate.objectId) {
37
+ return candidate.objectId;
38
+ }
39
+ if (typeof candidate.id === "string" && candidate.id) {
40
+ return candidate.id;
41
+ }
42
+ if (typeof candidate.get === "function") {
43
+ const objectId = candidate.get("objectId");
44
+ if (typeof objectId === "string" && objectId)
45
+ return objectId;
46
+ }
47
+ return undefined;
48
+ }
49
+ /** A trimmed string, or `undefined` when the value is not usable text. */
50
+ function paramString(value) {
51
+ return typeof value === "string" && value.trim() ? value.trim() : undefined;
52
+ }
53
+ /** A finite number, or `undefined`. Accepts the numeric strings a form posts. */
54
+ function paramNumber(value) {
55
+ if (typeof value === "number") {
56
+ return Number.isFinite(value) ? value : undefined;
57
+ }
58
+ if (typeof value === "string" && value.trim()) {
59
+ const parsed = Number(value);
60
+ return Number.isFinite(parsed) ? parsed : undefined;
61
+ }
62
+ return undefined;
63
+ }
@@ -23,7 +23,7 @@ export { alarmScheduleFields, dueDate, } from "./schedule/alarmScheduleFields.js
23
23
  export type { AlarmScheduleFields } from "./schedule/alarmScheduleFields.js";
24
24
  export { createAlarmSchedule, tenantForAlarmSchedule, } from "./schedule/createAlarmSchedule.js";
25
25
  export type { AlarmScheduleResult } from "./schedule/createAlarmSchedule.js";
26
- export { ensureAlarmScheduleAction } from "./schedule/ensureAlarmScheduleAction.js";
26
+ export { ensureAlarmScheduleAction, ensureAlarmScheduleWebhook, } from "./schedule/ensureAlarmScheduleAction.js";
27
27
  export { listAlarmTriggers } from "./schedule/listAlarmTriggers.js";
28
28
  export type { AlarmTriggerRow } from "./schedule/listAlarmTriggers.js";
29
29
  export { ALARM_SCHEDULE_ACTION_ID, ALARM_SCHEDULE_SECRET_CONFIG_KEY, } 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.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;
13
+ exports.ALARM_SCHEDULE_SECRET_CONFIG_KEY = exports.ALARM_SCHEDULE_ACTION_ID = exports.listAlarmTriggers = exports.ensureAlarmScheduleWebhook = 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
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");
@@ -45,6 +45,7 @@ Object.defineProperty(exports, "createAlarmSchedule", { enumerable: true, get: f
45
45
  Object.defineProperty(exports, "tenantForAlarmSchedule", { enumerable: true, get: function () { return createAlarmSchedule_js_1.tenantForAlarmSchedule; } });
46
46
  var ensureAlarmScheduleAction_js_1 = require("./schedule/ensureAlarmScheduleAction.js");
47
47
  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; } });
48
49
  var listAlarmTriggers_js_1 = require("./schedule/listAlarmTriggers.js");
49
50
  Object.defineProperty(exports, "listAlarmTriggers", { enumerable: true, get: function () { return listAlarmTriggers_js_1.listAlarmTriggers; } });
50
51
  var AlarmScheduleTypes_js_1 = require("./schedule/AlarmScheduleTypes.js");
@@ -27,7 +27,7 @@ export interface AlarmScheduleResult {
27
27
  * execution runner or the notification worker has to know an alarm was
28
28
  * involved; they all read a plan.
29
29
  */
30
- export declare function createAlarmSchedule(tenant: Tenant, event: AlarmEvent, params?: AlarmScheduleParams): Promise<AlarmScheduleResult>;
30
+ export declare function createAlarmSchedule(tenant: Tenant, event: AlarmEvent, rawParams?: AlarmScheduleParams): Promise<AlarmScheduleResult>;
31
31
  /**
32
32
  * The tenant a call belongs to, identified by its shared secret.
33
33
  *
@@ -7,6 +7,7 @@ exports.createAlarmSchedule = createAlarmSchedule;
7
7
  exports.tenantForAlarmSchedule = tenantForAlarmSchedule;
8
8
  const node_1 = __importDefault(require("parse/node"));
9
9
  const index_js_1 = require("../../../../types/index.js");
10
+ const actionParams_js_1 = require("../actionParams.js");
10
11
  const alarmIdentity_js_1 = require("../alarmIdentity.js");
11
12
  const resolveEquipment_js_1 = require("../resolveEquipment.js");
12
13
  const tenantForSecret_js_1 = require("../tenantForSecret.js");
@@ -27,10 +28,15 @@ const AlarmScheduleTypes_js_1 = require("./AlarmScheduleTypes.js");
27
28
  * execution runner or the notification worker has to know an alarm was
28
29
  * involved; they all read a plan.
29
30
  */
30
- async function createAlarmSchedule(tenant, event, params = {}) {
31
+ async function createAlarmSchedule(tenant, event, rawParams = {}) {
31
32
  if (!(0, alarmIdentity_js_1.alarmKey)(event)) {
32
33
  throw new node_1.default.Error(node_1.default.Error.INVALID_QUERY, "The alarm payload identifies no alarm: pass alarmId, or item_source/item_id.");
33
34
  }
35
+ // Normalised once, at the door, rather than at each use. The reference
36
+ // fields arrive as whole objects from alarms configured before the action
37
+ // form set a `valueField` (see `actionParams.ts`), and an executor is free to
38
+ // send a pointer too — every reader downstream wants a plain id.
39
+ const params = normalizeParams(rawParams);
34
40
  const template = await resolveTemplate(tenant, params.templateId);
35
41
  const fields = (0, alarmScheduleFields_js_1.alarmScheduleFields)(event, params, template?.get("title"));
36
42
  if (!params.duplicate) {
@@ -179,3 +185,19 @@ function dueOf(schedule) {
179
185
  async function tenantForAlarmSchedule(secret) {
180
186
  return (0, tenantForSecret_js_1.tenantForSecret)(AlarmScheduleTypes_js_1.ALARM_SCHEDULE_SECRET_CONFIG_KEY, secret);
181
187
  }
188
+ /**
189
+ * The action's form values, reduced to the shapes the rest of this file
190
+ * assumes: ids as strings, `dueInDays` as a number.
191
+ *
192
+ * Keeps unknown keys untouched — the executor forwards the whole action object
193
+ * as `params`, and dropping what we do not recognise would silently discard a
194
+ * field added later.
195
+ */
196
+ function normalizeParams(params) {
197
+ return {
198
+ ...params,
199
+ templateId: (0, actionParams_js_1.paramId)(params.templateId),
200
+ equipmentId: (0, actionParams_js_1.paramId)(params.equipmentId),
201
+ dueInDays: (0, actionParams_js_1.paramNumber)(params.dueInDays),
202
+ };
203
+ }