@openinc/parse-server-opendash 3.14.6 → 3.14.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "3.14.6",
3
+ "version": "3.14.7",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "keywords": [
File without changes
@@ -1,2 +0,0 @@
1
- "use strict";
2
- (async () => { })();
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- // import {
7
- // changeLanguage,
8
- // getCurrentLanguageSync,
9
- // useTranslation,
10
- // } from "@opendash/i18n";
11
- const node_process_1 = __importDefault(require("node:process"));
12
- const node_worker_threads_1 = require("node:worker_threads");
13
- const node_js_1 = __importDefault(require("parse/node.js"));
14
- const index_js_1 = require("../../../features/config/index.js");
15
- const index_js_2 = require("../../../features/notifications/index.js");
16
- const openinc_openservice_save_ticket_data_js_1 = require("../../../functions/openinc-openservice-save-ticket-data.js");
17
- const catchError_js_1 = require("../../../helper/catchError.js");
18
- const Config_js_1 = require("../../../types/Config.js");
19
- const Maintenance_Schedule_Template_js_1 = require("../../../types/Maintenance_Schedule_Template.js");
20
- const Notification_js_1 = require("../../../types/Notification.js");
21
- const Notification_Setting_js_1 = require("../../../types/Notification_Setting.js");
22
- function l(message) {
23
- if (node_worker_threads_1.parentPort) {
24
- node_worker_threads_1.parentPort.postMessage(message);
25
- }
26
- }
27
- (async () => {
28
- l("Initializing Parse with worker data: " + JSON.stringify(node_worker_threads_1.workerData));
29
- node_js_1.default.initialize(node_worker_threads_1.workerData.ParseAppId, node_worker_threads_1.workerData.ParseJSKey !== "unused" ? node_worker_threads_1.workerData.ParseJSKey : undefined, node_worker_threads_1.workerData.ParseMasterKey);
30
- node_js_1.default.serverURL = node_worker_threads_1.workerData.ParseServerURL;
31
- l("Schedule is due.");
32
- // Check OD3_Config class for key ConfigKeys.OpenService.createTicketOnSchedule. If value is true, proceed with ticket creation
33
- const [configError, config] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Config_js_1.Config.className)
34
- .equalTo("key", index_js_1.ConfigKeys.OpenService.createTicketOnSchedule)
35
- .first({ useMasterKey: true }));
36
- //Get schedule object from worker data
37
- const [scheduleError, schedule] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Maintenance_Schedule_Template_js_1.Maintenance_Schedule_Template.className).get(node_worker_threads_1.workerData.scheduleId, { useMasterKey: true }));
38
- if (configError) {
39
- l("Error while querying OD3_Config for 'createTicketOnSchedule' key: " +
40
- configError);
41
- return;
42
- }
43
- if (scheduleError || schedule === undefined) {
44
- l("Error while querying Maintenance_Schedule_Template object: " +
45
- scheduleError);
46
- return;
47
- }
48
- if (config === undefined || !/true/.test(config.get("value"))) {
49
- l("Config 'createTicketOnSchedule' not set or false, skipping ticket creation for schedule.");
50
- }
51
- else {
52
- //Get all sources from schedule object
53
- const [sourcesError, sources] = await (0, catchError_js_1.catchError)(schedule
54
- .relation("sources")
55
- .query()
56
- .find({ useMasterKey: true }));
57
- if (sourcesError) {
58
- l("Error while querying sources from Maintenance_Schedule_Template object: " +
59
- sourcesError);
60
- return;
61
- }
62
- for await (const source of sources) {
63
- //Create a new ticket
64
- await (0, openinc_openservice_save_ticket_data_js_1.saveTicketData)({
65
- title: "",
66
- source: source.id,
67
- });
68
- }
69
- }
70
- l("Config 'createTicketOnSchedule' is true, creating new ticket object");
71
- const [notificationSettingsError, notificationSettings] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Notification_Setting_js_1.Notification_Setting)
72
- .equalTo("key", index_js_2.Notifications.OpenService.schedule_due)
73
- .find({ useMasterKey: true }));
74
- if (notificationSettingsError) {
75
- l("Error while querying Notification_Setting for 'Notifications.OpenService.schedule_due' key: " +
76
- notificationSettingsError);
77
- return;
78
- }
79
- const recipients = [];
80
- const users = notificationSettings.map((setting) => setting
81
- .relation("users")
82
- .query()
83
- .include("settings")
84
- .find({ useMasterKey: true }));
85
- for await (const user of users) {
86
- recipients.push(...user);
87
- }
88
- const rolesPromises = notificationSettings.map((setting) => setting.relation("roles").query().find({ useMasterKey: true }));
89
- for await (const roles of rolesPromises) {
90
- const usersFromRoles = roles.map((role) => role
91
- .relation("users")
92
- .query()
93
- .include("settings")
94
- .find({ useMasterKey: true }));
95
- for await (const usersFromRole of usersFromRoles) {
96
- recipients.push(...usersFromRole);
97
- }
98
- }
99
- //Filter out duplicates
100
- recipients.filter((user, index, self) => {
101
- return (index ===
102
- self.findIndex((t) => t.id === user.id && t.className === user.className));
103
- });
104
- l("Recipients for notification: " + JSON.stringify(recipients));
105
- //TODO: When available as ESM, use i18n module to get the correct language for the user
106
- for await (const recipient of recipients) {
107
- l("Creating new notification object for user: " + recipient.id);
108
- //Get preferred_language from user object
109
- const language = recipient.get("settings")
110
- ? recipient.get("settings").get("preferred_language")
111
- : "deu";
112
- // if (getCurrentLanguageSync() !== language) {
113
- // changeLanguage(language);
114
- // }
115
- //Get the correct notification title and description based on the user's preferred language
116
- // const t = useTranslation();
117
- const findtitle = require(`../i18n/${language}.json`)["maintenance.schedule.notification.title"];
118
- const finddescription = require(`../i18n/${language}.json`)["maintenance.schedule.notification.description"];
119
- //Create a new notification object in the database, class name: OD3_Notification
120
- const notificationObject = new node_js_1.default.Object(Notification_js_1.Notification.className);
121
- notificationObject.set("title",
122
- // t("server:maintenance.schedule.notification.title")
123
- findtitle);
124
- notificationObject.set("description",
125
- // t("server:maintenance.schedule.notification.description", {
126
- // schedule:
127
- // schedule.get("title") !== undefined ? schedule.get("title")! : "",
128
- // })
129
- finddescription);
130
- notificationObject.set("user", recipient);
131
- await notificationObject.save(null, { useMasterKey: true });
132
- }
133
- // signal to parent that the job is done
134
- if (node_worker_threads_1.parentPort) {
135
- l("done");
136
- }
137
- else {
138
- node_process_1.default.exit(0);
139
- }
140
- })();
@@ -1,140 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- // import {
7
- // changeLanguage,
8
- // getCurrentLanguageSync,
9
- // useTranslation,
10
- // } from "@opendash/i18n";
11
- const node_process_1 = __importDefault(require("node:process"));
12
- const node_worker_threads_1 = require("node:worker_threads");
13
- const node_js_1 = __importDefault(require("parse/node.js"));
14
- const index_js_1 = require("../../../features/config/index.js");
15
- const index_js_2 = require("../../../features/notifications/index.js");
16
- const openinc_openservice_save_ticket_data_js_1 = require("../../../functions/openinc-openservice-save-ticket-data.js");
17
- const catchError_js_1 = require("../../../helper/catchError.js");
18
- const Config_js_1 = require("../../../types/Config.js");
19
- const Maintenance_Schedule_Template_js_1 = require("../../../types/Maintenance_Schedule_Template.js");
20
- const Notification_js_1 = require("../../../types/Notification.js");
21
- const Notification_Setting_js_1 = require("../../../types/Notification_Setting.js");
22
- function l(message) {
23
- if (node_worker_threads_1.parentPort) {
24
- node_worker_threads_1.parentPort.postMessage(message);
25
- }
26
- }
27
- (async () => {
28
- l("Initializing Parse with worker data: " + JSON.stringify(node_worker_threads_1.workerData));
29
- node_js_1.default.initialize(node_worker_threads_1.workerData.ParseAppId, node_worker_threads_1.workerData.ParseJSKey !== "unused" ? node_worker_threads_1.workerData.ParseJSKey : undefined, node_worker_threads_1.workerData.ParseMasterKey);
30
- node_js_1.default.serverURL = node_worker_threads_1.workerData.ParseServerURL;
31
- l("Schedule is due.");
32
- // Check OD3_Config class for key ConfigKeys.OpenService.createTicketOnSchedule. If value is true, proceed with ticket creation
33
- const [configError, config] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Config_js_1.Config.className)
34
- .equalTo("key", index_js_1.ConfigKeys.OpenService.createTicketOnSchedule)
35
- .first({ useMasterKey: true }));
36
- //Get schedule object from worker data
37
- const [scheduleError, schedule] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Maintenance_Schedule_Template_js_1.Maintenance_Schedule_Template.className).get(node_worker_threads_1.workerData.scheduleId, { useMasterKey: true }));
38
- if (configError) {
39
- l("Error while querying OD3_Config for 'createTicketOnSchedule' key: " +
40
- configError);
41
- return;
42
- }
43
- if (scheduleError || schedule === undefined) {
44
- l("Error while querying Maintenance_Schedule_Template object: " +
45
- scheduleError);
46
- return;
47
- }
48
- if (config === undefined || !/true/.test(config.get("value"))) {
49
- l("Config 'createTicketOnSchedule' not set or false, skipping ticket creation for schedule.");
50
- }
51
- else {
52
- //Get all sources from schedule object
53
- const [sourcesError, sources] = await (0, catchError_js_1.catchError)(schedule
54
- .relation("sources")
55
- .query()
56
- .find({ useMasterKey: true }));
57
- if (sourcesError) {
58
- l("Error while querying sources from Maintenance_Schedule_Template object: " +
59
- sourcesError);
60
- return;
61
- }
62
- for await (const source of sources) {
63
- //Create a new ticket
64
- await (0, openinc_openservice_save_ticket_data_js_1.saveTicketData)({
65
- title: "",
66
- source: source.id,
67
- });
68
- }
69
- }
70
- l("Config 'createTicketOnSchedule' is true, creating new ticket object");
71
- const [notificationSettingsError, notificationSettings] = await (0, catchError_js_1.catchError)(new node_js_1.default.Query(Notification_Setting_js_1.Notification_Setting)
72
- .equalTo("key", index_js_2.Notifications.OpenService.schedule_due)
73
- .find({ useMasterKey: true }));
74
- if (notificationSettingsError) {
75
- l("Error while querying Notification_Setting for 'Notifications.OpenService.schedule_due' key: " +
76
- notificationSettingsError);
77
- return;
78
- }
79
- const recipients = [];
80
- const users = notificationSettings.map((setting) => setting
81
- .relation("users")
82
- .query()
83
- .include("settings")
84
- .find({ useMasterKey: true }));
85
- for await (const user of users) {
86
- recipients.push(...user);
87
- }
88
- const rolesPromises = notificationSettings.map((setting) => setting.relation("roles").query().find({ useMasterKey: true }));
89
- for await (const roles of rolesPromises) {
90
- const usersFromRoles = roles.map((role) => role
91
- .relation("users")
92
- .query()
93
- .include("settings")
94
- .find({ useMasterKey: true }));
95
- for await (const usersFromRole of usersFromRoles) {
96
- recipients.push(...usersFromRole);
97
- }
98
- }
99
- //Filter out duplicates
100
- recipients.filter((user, index, self) => {
101
- return (index ===
102
- self.findIndex((t) => t.id === user.id && t.className === user.className));
103
- });
104
- l("Recipients for notification: " + JSON.stringify(recipients));
105
- //TODO: When available as ESM, use i18n module to get the correct language for the user
106
- for await (const recipient of recipients) {
107
- l("Creating new notification object for user: " + recipient.id);
108
- //Get preferred_language from user object
109
- const language = recipient.get("settings")
110
- ? recipient.get("settings").get("preferred_language")
111
- : "deu";
112
- // if (getCurrentLanguageSync() !== language) {
113
- // changeLanguage(language);
114
- // }
115
- //Get the correct notification title and description based on the user's preferred language
116
- // const t = useTranslation();
117
- const findtitle = require(`../i18n/${language}.json`)["maintenance.schedule.notification.title"];
118
- const finddescription = require(`../i18n/${language}.json`)["maintenance.schedule.notification.description"];
119
- //Create a new notification object in the database, class name: OD3_Notification
120
- const notificationObject = new node_js_1.default.Object(Notification_js_1.Notification.className);
121
- notificationObject.set("title",
122
- // t("server:maintenance.schedule.notification.title")
123
- findtitle);
124
- notificationObject.set("description",
125
- // t("server:maintenance.schedule.notification.description", {
126
- // schedule:
127
- // schedule.get("title") !== undefined ? schedule.get("title")! : "",
128
- // })
129
- finddescription);
130
- notificationObject.set("user", recipient);
131
- await notificationObject.save(null, { useMasterKey: true });
132
- }
133
- // signal to parent that the job is done
134
- if (node_worker_threads_1.parentPort) {
135
- l("done");
136
- }
137
- else {
138
- node_process_1.default.exit(0);
139
- }
140
- })();