@openinc/parse-server-opendash 3.14.9 → 3.14.11

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.
@@ -31,6 +31,7 @@ async function init(name) {
31
31
  };
32
32
  }
33
33
  catch (error) {
34
+ console.error(error);
34
35
  throw new Parse.Error(Parse.Error.OBJECT_NOT_FOUND, "t:AUTH_INVALID");
35
36
  }
36
37
  }
@@ -6,8 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.init = init;
7
7
  const bree_1 = __importDefault(require("bree"));
8
8
  const __1 = require("..");
9
- const cron_1 = __importDefault(require("../features/cron"));
10
- const initScheduling_1 = require("../features/openservice/schedules/initScheduling");
11
9
  const types_1 = require("../types");
12
10
  bree_1.default.extend(require("@breejs/ts-worker"));
13
11
  async function init() {
@@ -18,22 +16,11 @@ async function init() {
18
16
  });
19
17
  (0, __1.afterSaveHook)(types_1.Maintenance_Schedule_Template, async (request) => {
20
18
  const { object, original, user } = request;
21
- await (0, initScheduling_1.addJobToBree)([object]);
22
19
  });
23
20
  (0, __1.beforeDeleteHook)(types_1.Maintenance_Schedule_Template, async (request) => {
24
21
  const { object, original, user } = request;
25
- try {
26
- //Check if a prenotification is scheduled
27
- const notifyBeforeDue = object.get("notifyBeforeDue");
28
- // If the notifyBeforeDue field is set, we will schedule a job to run before the due date
29
- if (notifyBeforeDue && notifyBeforeDue.value > 0) {
30
- await cron_1.default.removeJob(cron_1.default.constructJobName(object.id, "Maintenance_Schedule_Notification_Before_Due"));
31
- }
32
- await cron_1.default.removeJob(cron_1.default.constructJobName(object.id, "Maintenance_Schedule"));
33
- }
34
- catch (error) {
35
- console.error("Error removing jobs:", error);
36
- }
37
22
  });
38
- (0, __1.afterDeleteHook)(types_1.Maintenance_Schedule_Template, async (request) => { });
23
+ (0, __1.afterDeleteHook)(types_1.Maintenance_Schedule_Template, async (request) => {
24
+ const { object, original, user } = request;
25
+ });
39
26
  }
package/dist/index.js CHANGED
@@ -39,7 +39,6 @@ const notifications_1 = require("./features/notifications");
39
39
  const permissions_1 = require("./features/permissions");
40
40
  const settings_1 = require("./features/user/settings");
41
41
  const Core_Email_1 = require("./hooks/Core_Email");
42
- const cron_1 = require("./features/cron");
43
42
  const openservice_1 = require("./features/openservice");
44
43
  const _init_1 = require("./functions/_init");
45
44
  const _init_2 = require("./hooks/_init");
@@ -83,7 +82,6 @@ async function init() {
83
82
  catch (error) { }
84
83
  config = config_1.ConfigInstance.getInstance();
85
84
  await config.init(true);
86
- await (0, cron_1.init)();
87
85
  await initTranslations();
88
86
  await (0, Core_Email_1.initEmailTransport)();
89
87
  await initWebPush();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@openinc/parse-server-opendash",
3
- "version": "3.14.9",
3
+ "version": "3.14.11",
4
4
  "description": "Parse Server Cloud Code for open.INC Stack.",
5
5
  "packageManager": "pnpm@10.13.1",
6
6
  "keywords": [
@@ -6,7 +6,7 @@
6
6
  },
7
7
  "cron": {
8
8
  "type": "Object",
9
- "required": false
9
+ "required": true
10
10
  },
11
11
  "description": {
12
12
  "type": "String",
@@ -39,7 +39,7 @@
39
39
  },
40
40
  "title": {
41
41
  "type": "String",
42
- "required": false
42
+ "required": true
43
43
  }
44
44
  },
45
45
  "classLevelPermissions": {
@@ -1,5 +0,0 @@
1
- export { ScheduleCronObjectType, ScheduleType } from "./types/CRON_Types";
2
- export { JobTypes } from "./types/jobTypes";
3
- export { TimespanFieldType, TimeUnit } from "./types/notifyBeforeDue";
4
- export { init } from "./services/initBree";
5
- export { default } from "./states/BreeInstance";
@@ -1,12 +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
- exports.default = exports.init = exports.TimeUnit = void 0;
7
- var notifyBeforeDue_1 = require("./types/notifyBeforeDue");
8
- Object.defineProperty(exports, "TimeUnit", { enumerable: true, get: function () { return notifyBeforeDue_1.TimeUnit; } });
9
- var initBree_1 = require("./services/initBree");
10
- Object.defineProperty(exports, "init", { enumerable: true, get: function () { return initBree_1.init; } });
11
- var BreeInstance_1 = require("./states/BreeInstance");
12
- Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(BreeInstance_1).default; } });
@@ -1 +0,0 @@
1
- export declare function init(): Promise<void>;
@@ -1,19 +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
- exports.init = init;
7
- const __1 = __importDefault(require(".."));
8
- async function init() {
9
- const bree = __1.default.getBree();
10
- //Start bree object
11
- // const graceful = new Graceful({ brees: [bree] });
12
- // graceful.listen();
13
- (async () => {
14
- console.log("[@openinc/parse-server-opendash] Starting bree");
15
- await bree.start();
16
- const jobs = __1.default.getAllJobs();
17
- console.log("[@openinc/parse-server-opendash] Number of Bree jobs in initialization:", jobs.length);
18
- })();
19
- }
@@ -1,32 +0,0 @@
1
- import Bree from "bree";
2
- import { JobTypes, TimespanFieldType } from "..";
3
- export default class BreeInstance {
4
- private static instance;
5
- private static jobs;
6
- private constructor();
7
- static getBree(): Bree;
8
- static getAllJobs(): Bree.Job[];
9
- /**
10
- * Converts a cron-like string into a human-readable format.
11
- *
12
- * @param value - The cron-like string to convert.
13
- * @returns A human-readable string representing the cron-like schedule.
14
- */
15
- static createHumanReadableFormat(value: string): string;
16
- /**
17
- * Calculates how much earlier a job should be scheduled based on the user input.
18
- * Users can set an offset like "2 weeks" or "3 days" to schedule the job earlier.
19
- * This function will substract the offset from startdate and return a new date.
20
- */
21
- static calculateOffsetToExecution(startdate: Date, notifyBeforeDue: TimespanFieldType): Date;
22
- static addJob(newjob: Bree.Job | Omit<Bree.Job, "timeout"> | undefined): Promise<void>;
23
- static removeJob(jobName: string): Promise<void>;
24
- static getJobByName(jobName: string): Bree.Job | undefined;
25
- /**
26
- * Constructs a job name based on the schedule ID and job type.
27
- * @param id - The ID of the schedule.
28
- * @param jobType - The type of the job (e.g., "notification before due").
29
- * @returns A string representing the constructed job name.
30
- */
31
- static constructJobName(id: string, jobType: JobTypes): string;
32
- }
@@ -1,133 +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
- const bree_1 = __importDefault(require("bree"));
7
- const dayjs_1 = __importDefault(require("dayjs"));
8
- const duration_1 = __importDefault(require("dayjs/plugin/duration"));
9
- dayjs_1.default.extend(duration_1.default);
10
- class BreeInstance {
11
- constructor() { }
12
- static getBree() {
13
- if (this.instance === null) {
14
- // Create a new instance of Bree
15
- this.instance = new bree_1.default({
16
- // Bree configuration options
17
- errorHandler: (error, workerMetadata) => {
18
- console.error(`An error occurred in worker ${workerMetadata.name} with the following error: ${error}`);
19
- },
20
- workerMessageHandler: (message) => {
21
- console.log(`Worker ${message.name} sent the following message: ${message.message}`);
22
- },
23
- root: false, //path.join(__dirname, "..", "jobs")
24
- jobs: this.jobs,
25
- acceptedExtensions: ["js"],
26
- defaultExtension: "js",
27
- outputWorkerMetadata: false,
28
- });
29
- }
30
- return this.instance;
31
- }
32
- static getAllJobs() {
33
- return this.jobs;
34
- }
35
- /**
36
- * Converts a cron-like string into a human-readable format.
37
- *
38
- * @param value - The cron-like string to convert.
39
- * @returns A human-readable string representing the cron-like schedule.
40
- */
41
- static createHumanReadableFormat(value) {
42
- //value looks like this: "1 1 1 1 1 1 1"
43
- //1. seconds
44
- //2. minutes
45
- //3. hours
46
- //4. days
47
- //5. weeks
48
- //6. months
49
- //7. years
50
- const valueArray = value.split(" ");
51
- //Should be in the format: "every 1 second" when second is 1
52
- //If any value is 0, it should be ignored
53
- //Values should be separated by a comma
54
- const returnArray = [];
55
- if (valueArray[0] !== "0") {
56
- returnArray.push(`every ${valueArray[0]} seconds`);
57
- }
58
- if (valueArray[1] !== "0") {
59
- returnArray.push(`every ${valueArray[1]} minutes`);
60
- }
61
- if (valueArray[2] !== "0") {
62
- returnArray.push(`every ${valueArray[2]} hours`);
63
- }
64
- if (valueArray[3] !== "0") {
65
- returnArray.push(`every ${valueArray[3]} days`);
66
- }
67
- if (valueArray[4] !== "0") {
68
- returnArray.push(`every ${valueArray[4]} weeks`);
69
- }
70
- if (valueArray[5] !== "0") {
71
- returnArray.push(`every ${valueArray[5]} months`);
72
- }
73
- if (valueArray[6] !== "0") {
74
- returnArray.push(`every ${valueArray[6]} years`);
75
- }
76
- return returnArray.join(", ");
77
- }
78
- /**
79
- * Calculates how much earlier a job should be scheduled based on the user input.
80
- * Users can set an offset like "2 weeks" or "3 days" to schedule the job earlier.
81
- * This function will substract the offset from startdate and return a new date.
82
- */
83
- static calculateOffsetToExecution(startdate, notifyBeforeDue) {
84
- const result = (0, dayjs_1.default)(startdate).subtract(dayjs_1.default.duration({ days: notifyBeforeDue.value }));
85
- return result.toDate();
86
- }
87
- static async addJob(newjob) {
88
- if (newjob === undefined) {
89
- console.error("newjob is undefined");
90
- return;
91
- }
92
- //Get all jobs from bree and check whether the job already exists
93
- const jobs = BreeInstance.getAllJobs();
94
- let jobExists = false;
95
- for (const job of jobs) {
96
- if (job.name === newjob.name) {
97
- jobExists = true;
98
- break;
99
- }
100
- }
101
- if (jobExists) {
102
- console.log(`Job with name ${newjob.name} already exists`);
103
- return;
104
- }
105
- console.log(`Adding job with jobname ${newjob.name}`);
106
- return await BreeInstance.getBree().add(newjob);
107
- }
108
- static async removeJob(jobName) {
109
- console.log(`Removing job with jobname ${jobName}`);
110
- return BreeInstance.getBree().remove(jobName);
111
- }
112
- static getJobByName(jobName) {
113
- const jobs = BreeInstance.getAllJobs();
114
- for (const job of jobs) {
115
- if (job.name === jobName) {
116
- return job;
117
- }
118
- }
119
- return undefined;
120
- }
121
- /**
122
- * Constructs a job name based on the schedule ID and job type.
123
- * @param id - The ID of the schedule.
124
- * @param jobType - The type of the job (e.g., "notification before due").
125
- * @returns A string representing the constructed job name.
126
- */
127
- static constructJobName(id, jobType) {
128
- return `${id}_${jobType}`;
129
- }
130
- }
131
- BreeInstance.instance = null;
132
- BreeInstance.jobs = [];
133
- exports.default = BreeInstance;
@@ -1,10 +0,0 @@
1
- export type ScheduleType = "quartz" | "human";
2
- export type ScheduleCronObjectType = {
3
- scheduletype: ScheduleType;
4
- run_cron: string;
5
- run_startdate: Date;
6
- run_enddate: Date;
7
- is_week: boolean;
8
- week_interval: number;
9
- is_one_time: boolean;
10
- };
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,5 +0,0 @@
1
- /**
2
- * @description
3
- * This file contains the types for the job types used in the cron jobs.
4
- */
5
- export type JobTypes = "Maintenance_Schedule" | "Maintenance_Schedule_Notification_Before_Due";
@@ -1,2 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,14 +0,0 @@
1
- export declare enum TimeUnit {
2
- milliseconds = "milliseconds",
3
- seconds = "seconds",
4
- minutes = "minutes",
5
- hours = "hours",
6
- days = "days",
7
- weeks = "weeks",
8
- months = "months",
9
- years = "years"
10
- }
11
- export type TimespanFieldType = {
12
- value: number;
13
- unit: TimeUnit;
14
- };
@@ -1,14 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.TimeUnit = void 0;
4
- var TimeUnit;
5
- (function (TimeUnit) {
6
- TimeUnit["milliseconds"] = "milliseconds";
7
- TimeUnit["seconds"] = "seconds";
8
- TimeUnit["minutes"] = "minutes";
9
- TimeUnit["hours"] = "hours";
10
- TimeUnit["days"] = "days";
11
- TimeUnit["weeks"] = "weeks";
12
- TimeUnit["months"] = "months";
13
- TimeUnit["years"] = "years";
14
- })(TimeUnit || (exports.TimeUnit = TimeUnit = {}));
@@ -1,6 +0,0 @@
1
- import { Maintenance_Schedule_Template } from "../../../types";
2
- /**
3
- * This function is called upon initialization and uses bree to schedule all jobs.
4
- */
5
- export declare function initScheduling(): Promise<void>;
6
- export declare function addJobToBree(query: Maintenance_Schedule_Template[]): Promise<void>;
@@ -1,123 +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
- exports.initScheduling = initScheduling;
7
- exports.addJobToBree = addJobToBree;
8
- const path_1 = __importDefault(require("path"));
9
- const catchError_1 = require("../../../helper/catchError");
10
- const types_1 = require("../../../types");
11
- const cron_1 = __importDefault(require("../../cron"));
12
- /**
13
- * This function is called upon initialization and uses bree to schedule all jobs.
14
- */
15
- async function initScheduling() {
16
- console.log("Init scheduling Maintenance_Schedule_Template jobs");
17
- //Get all Maintenance_Schedule_Template objects
18
- const [queryError, query] = await (0, catchError_1.catchError)(new Parse.Query(types_1.Maintenance_Schedule_Template).find({
19
- useMasterKey: true,
20
- }));
21
- //Create an new bree object for all Maintenance_Schedule_Template objects that have cron.is_one_time = false
22
- if (queryError) {
23
- console.error("Error while querying Maintenance_Schedule_Template objects", queryError);
24
- return;
25
- }
26
- await addJobToBree(query);
27
- }
28
- async function addJobToBree(query) {
29
- for (const schedule of query) {
30
- const cron = schedule.get("cron");
31
- const notifyBeforeDue = schedule.get("notifyBeforeDue");
32
- // If the notifyBeforeDue field is set, we will schedule a job to run before the due date
33
- if (notifyBeforeDue && notifyBeforeDue.value > 0) {
34
- // Calculate the offset from the start date
35
- const startdate = cron_1.default.calculateOffsetToExecution(schedule.get("cron").run_startdate, notifyBeforeDue);
36
- //Add a job to bree to run at the calculated date
37
- const newjob = {
38
- name: cron_1.default.constructJobName(schedule.id, "Maintenance_Schedule_Notification_Before_Due"),
39
- path: path_1.default.join(__dirname, "..", "jobs", "open_service_notifyBeforeSchedule.js"),
40
- date: startdate,
41
- interval: cron.is_one_time
42
- ? 0
43
- : cron_1.default.createHumanReadableFormat(cron.run_cron),
44
- hasSeconds: true,
45
- worker: {
46
- workerData: {
47
- scheduleId: schedule.id,
48
- ParseAppId: Parse.applicationId,
49
- ParseJSKey: Parse.javaScriptKey,
50
- ParseMasterKey: Parse.masterKey,
51
- ParseServerURL: Parse.serverURL,
52
- },
53
- },
54
- };
55
- await cron_1.default.addJob(newjob);
56
- }
57
- try {
58
- let newjob = undefined;
59
- if (cron.is_one_time === false) {
60
- if (cron.scheduletype === "human") {
61
- newjob = {
62
- name: cron_1.default.constructJobName(schedule.id, "Maintenance_Schedule"),
63
- date: cron.run_startdate,
64
- path: path_1.default.join(__dirname, "..", "jobs", "open_service_notifyOnSchedule.js"),
65
- interval: cron_1.default.createHumanReadableFormat(cron.run_cron),
66
- hasSeconds: true,
67
- worker: {
68
- workerData: {
69
- scheduleId: schedule.id,
70
- ParseAppId: Parse.applicationId,
71
- ParseJSKey: Parse.javaScriptKey,
72
- ParseMasterKey: Parse.masterKey,
73
- ParseServerURL: Parse.serverURL,
74
- },
75
- },
76
- };
77
- }
78
- else if (cron.scheduletype === "quartz") {
79
- newjob = {
80
- name: cron_1.default.constructJobName(schedule.id, "Maintenance_Schedule"),
81
- cron: cron.run_cron,
82
- path: path_1.default.join(__dirname, "..", "jobs", "open_service_notifyOnSchedule.js"),
83
- timeout: 0,
84
- interval: 0,
85
- hasSeconds: true,
86
- worker: {
87
- workerData: {
88
- scheduleId: schedule.id,
89
- ParseAppId: Parse.applicationId,
90
- ParseJSKey: Parse.javaScriptKey,
91
- ParseMasterKey: Parse.masterKey,
92
- ParseServerURL: Parse.serverURL,
93
- },
94
- },
95
- };
96
- }
97
- }
98
- else {
99
- // If the job is a one time job, we will schedule it to run once
100
- newjob = {
101
- name: cron_1.default.constructJobName(schedule.id, "Maintenance_Schedule"),
102
- date: cron.run_startdate,
103
- path: path_1.default.join(__dirname, "..", "jobs", "open_service_notifyOnSchedule.js"),
104
- interval: 0,
105
- hasSeconds: true,
106
- worker: {
107
- workerData: {
108
- scheduleId: schedule.id,
109
- ParseAppId: Parse.applicationId,
110
- ParseJSKey: Parse.javaScriptKey,
111
- ParseMasterKey: Parse.masterKey,
112
- ParseServerURL: Parse.serverURL,
113
- },
114
- },
115
- };
116
- }
117
- await cron_1.default.addJob(newjob);
118
- }
119
- catch (error) {
120
- console.warn(`Error while adding job for schedule ${schedule.id}`, error);
121
- }
122
- }
123
- }