@openinc/parse-server-opendash 3.31.26 → 3.32.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 (205) hide show
  1. package/dist/features/cloudcode/classes/CloudCodeClass.d.ts +10 -0
  2. package/dist/features/cloudcode/classes/CloudCodeClass.js +24 -0
  3. package/dist/features/cloudcode/helper/checkCloudCodeFunction.d.ts +7 -0
  4. package/dist/features/cloudcode/helper/checkCloudCodeFunction.js +14 -0
  5. package/dist/features/cloudcode/index.d.ts +3 -0
  6. package/dist/features/cloudcode/index.js +11 -0
  7. package/dist/features/cloudcode/services/loadCloudCode.d.ts +9 -0
  8. package/dist/features/cloudcode/services/loadCloudCode.js +44 -0
  9. package/dist/features/cloudcode/types/CloudCodeFunction.d.ts +7 -0
  10. package/dist/features/cloudcode/types/CloudCodeFunction.js +2 -0
  11. package/dist/features/config/helper/getConfig.d.ts +18 -0
  12. package/dist/features/config/helper/getConfig.js +36 -0
  13. package/dist/features/config/index.d.ts +1 -0
  14. package/dist/features/config/index.js +4 -1
  15. package/dist/features/permissions/helper/ensurePermission.d.ts +10 -0
  16. package/dist/features/permissions/helper/ensurePermission.js +34 -0
  17. package/dist/features/permissions/helper/hasPermission.d.ts +7 -0
  18. package/dist/features/permissions/helper/hasPermission.js +16 -0
  19. package/dist/features/permissions/helper/requirePermission.d.ts +13 -0
  20. package/dist/features/permissions/helper/requirePermission.js +28 -0
  21. package/dist/features/permissions/index.d.ts +3 -0
  22. package/dist/features/permissions/index.js +7 -1
  23. package/dist/features/schema/classes/SchemaClass.d.ts +9 -0
  24. package/dist/features/schema/classes/SchemaClass.js +24 -0
  25. package/dist/features/schema/helper/defaultHandler.d.ts +33 -0
  26. package/dist/features/schema/helper/defaultHandler.js +106 -0
  27. package/dist/features/schema/helper/ensureRole.d.ts +17 -0
  28. package/dist/features/schema/helper/ensureRole.js +68 -0
  29. package/dist/features/schema/helper/ensureUserRole.d.ts +7 -0
  30. package/dist/features/schema/helper/ensureUserRole.js +25 -0
  31. package/dist/features/schema/helper/immutableField.d.ts +16 -0
  32. package/dist/features/schema/helper/immutableField.js +26 -0
  33. package/dist/features/schema/helper/isClassEnabled.d.ts +1 -0
  34. package/dist/features/schema/helper/isClassEnabled.js +18 -0
  35. package/dist/features/schema/index.d.ts +12 -0
  36. package/dist/features/schema/index.js +41 -0
  37. package/dist/features/schema/services/afterDeleteHook.d.ts +13 -0
  38. package/dist/features/schema/services/afterDeleteHook.js +28 -0
  39. package/dist/features/schema/services/afterSaveHook.d.ts +12 -0
  40. package/dist/features/schema/services/afterSaveHook.js +27 -0
  41. package/dist/features/schema/services/beforeDeleteHook.d.ts +11 -0
  42. package/dist/features/schema/services/beforeDeleteHook.js +26 -0
  43. package/dist/features/schema/services/beforeSaveHook.d.ts +12 -0
  44. package/dist/features/schema/services/beforeSaveHook.js +27 -0
  45. package/dist/features/schema/services/initDefaultData.d.ts +1 -0
  46. package/dist/features/schema/services/initDefaultData.js +45 -0
  47. package/dist/features/schema/services/initDefaultRoles.d.ts +1 -0
  48. package/dist/features/schema/services/initDefaultRoles.js +16 -0
  49. package/dist/features/schema/services/initSchema.d.ts +1 -0
  50. package/dist/features/schema/services/initSchema.js +32 -0
  51. package/dist/features/schema/types/hookTypes.d.ts +13 -0
  52. package/dist/features/schema/types/hookTypes.js +2 -0
  53. package/dist/features/webpush/index.d.ts +1 -0
  54. package/dist/features/webpush/index.js +5 -0
  55. package/dist/features/webpush/services/initWebPush.d.ts +1 -0
  56. package/dist/features/webpush/services/initWebPush.js +20 -0
  57. package/dist/functions/getSchemaForAdmin.js +2 -2
  58. package/dist/hooks/Alarm.js +4 -4
  59. package/dist/hooks/AlarmAction.js +4 -4
  60. package/dist/hooks/AlarmWebhook.js +4 -4
  61. package/dist/hooks/Assets.js +6 -6
  62. package/dist/hooks/Attachment.js +5 -5
  63. package/dist/hooks/BDE_Form.js +3 -3
  64. package/dist/hooks/BDE_List.js +3 -3
  65. package/dist/hooks/BDE_ListEntry.js +3 -3
  66. package/dist/hooks/BDE_Page.js +4 -4
  67. package/dist/hooks/BDE_Result.js +3 -3
  68. package/dist/hooks/BDE_Unit.js +3 -3
  69. package/dist/hooks/Company.js +5 -5
  70. package/dist/hooks/Config.js +4 -4
  71. package/dist/hooks/Config_open_service.js +4 -4
  72. package/dist/hooks/Contact.js +5 -5
  73. package/dist/hooks/Core_Email.js +2 -2
  74. package/dist/hooks/Core_Token.js +2 -2
  75. package/dist/hooks/Dashboard.js +4 -4
  76. package/dist/hooks/Documentation_Category.js +5 -5
  77. package/dist/hooks/Documentation_Config.js +6 -6
  78. package/dist/hooks/Documentation_Document.js +5 -5
  79. package/dist/hooks/GTFS_Agency.js +5 -5
  80. package/dist/hooks/GTFS_Bikes_Allowed.js +5 -5
  81. package/dist/hooks/GTFS_Calendar.js +5 -5
  82. package/dist/hooks/GTFS_Direction.js +5 -5
  83. package/dist/hooks/GTFS_Level.js +5 -5
  84. package/dist/hooks/GTFS_Location_Type.js +5 -5
  85. package/dist/hooks/GTFS_Route.js +5 -5
  86. package/dist/hooks/GTFS_Route_Type.js +5 -5
  87. package/dist/hooks/GTFS_Stop.js +5 -5
  88. package/dist/hooks/GTFS_Stop_Times.js +5 -5
  89. package/dist/hooks/GTFS_Trip.js +5 -5
  90. package/dist/hooks/GTFS_Wheelchair_Accessible.js +5 -5
  91. package/dist/hooks/GTFS_Wheelchair_Boarding.js +5 -5
  92. package/dist/hooks/Knowledge_Article.js +5 -5
  93. package/dist/hooks/Knowledge_Category.js +5 -5
  94. package/dist/hooks/Knowledge_Chat.js +5 -5
  95. package/dist/hooks/Knowledge_ChatMessage.js +5 -5
  96. package/dist/hooks/Knowledge_Document.js +7 -7
  97. package/dist/hooks/Knowledge_DocumentPage.js +6 -6
  98. package/dist/hooks/Knowledge_Video.js +5 -5
  99. package/dist/hooks/Language.js +5 -5
  100. package/dist/hooks/Log.js +5 -5
  101. package/dist/hooks/MES_Article.js +5 -5
  102. package/dist/hooks/MES_Order.js +5 -5
  103. package/dist/hooks/MES_OrderPlan.js +5 -5
  104. package/dist/hooks/MIAAS_MDSEndpoint.js +5 -5
  105. package/dist/hooks/ML_DataSelection.js +5 -5
  106. package/dist/hooks/MailTemplate.js +5 -5
  107. package/dist/hooks/Maintenance_Downtime.js +5 -5
  108. package/dist/hooks/Maintenance_Duedate.js +5 -5
  109. package/dist/hooks/Maintenance_Frequency.js +5 -5
  110. package/dist/hooks/Maintenance_Issuecategory.js +5 -5
  111. package/dist/hooks/Maintenance_Item.js +5 -5
  112. package/dist/hooks/Maintenance_Kanban_State.js +5 -5
  113. package/dist/hooks/Maintenance_Media.js +5 -5
  114. package/dist/hooks/Maintenance_Message.js +5 -5
  115. package/dist/hooks/Maintenance_Order.js +5 -5
  116. package/dist/hooks/Maintenance_Priority.js +5 -5
  117. package/dist/hooks/Maintenance_Project.js +5 -5
  118. package/dist/hooks/Maintenance_Restriction.js +5 -5
  119. package/dist/hooks/Maintenance_Schedule.js +6 -6
  120. package/dist/hooks/Maintenance_Schedule_Execution.js +5 -5
  121. package/dist/hooks/Maintenance_Schedule_Execution_Step.js +5 -5
  122. package/dist/hooks/Maintenance_Schedule_Step.js +5 -5
  123. package/dist/hooks/Maintenance_Schedule_Template.js +7 -7
  124. package/dist/hooks/Maintenance_Source_File.js +5 -5
  125. package/dist/hooks/Maintenance_Ticket.js +5 -5
  126. package/dist/hooks/Maintenance_Ticket_Assignment.js +5 -5
  127. package/dist/hooks/Maintenance_Ticket_FormConfig.js +5 -5
  128. package/dist/hooks/Maintenance_Ticket_Issuecategory.js +5 -5
  129. package/dist/hooks/Maintenance_Ticket_Kanban_State.js +7 -6
  130. package/dist/hooks/Maintenance_Ticket_Kanban_State_Current.js +5 -5
  131. package/dist/hooks/Maintenance_Ticket_Material.js +5 -5
  132. package/dist/hooks/Maintenance_Ticket_Project.js +5 -5
  133. package/dist/hooks/Maintenance_Ticket_QR_Code.js +5 -5
  134. package/dist/hooks/Maintenance_Ticket_Source.js +5 -5
  135. package/dist/hooks/Maintenance_Ticket_Title.js +5 -5
  136. package/dist/hooks/Monitoring_DataHierachies.js +5 -5
  137. package/dist/hooks/Monitoring_Jobs.js +5 -5
  138. package/dist/hooks/Monitoring_ParseTableSensor.js +5 -5
  139. package/dist/hooks/Monitoring_ReportImage.js +5 -5
  140. package/dist/hooks/Monitoring_Slideshow.js +4 -4
  141. package/dist/hooks/NavigationGroup.js +4 -4
  142. package/dist/hooks/NavigationItem.js +4 -4
  143. package/dist/hooks/Notification.js +6 -6
  144. package/dist/hooks/Notification_Setting.js +5 -5
  145. package/dist/hooks/OWPlcDevice.js +3 -3
  146. package/dist/hooks/OWPlcItem.js +3 -3
  147. package/dist/hooks/Permission.js +5 -5
  148. package/dist/hooks/Push.js +4 -4
  149. package/dist/hooks/Report.js +4 -4
  150. package/dist/hooks/Share.js +4 -4
  151. package/dist/hooks/Source.js +9 -8
  152. package/dist/hooks/SourceMeta.js +4 -4
  153. package/dist/hooks/Tenant.js +7 -7
  154. package/dist/hooks/TenantMeta.js +5 -5
  155. package/dist/hooks/TenantTrustedDomain.js +4 -4
  156. package/dist/hooks/UserData.js +4 -4
  157. package/dist/hooks/User_Setting.js +5 -5
  158. package/dist/hooks/VirtualKPI.js +5 -5
  159. package/dist/hooks/WebPush.js +5 -5
  160. package/dist/hooks/Widget.js +4 -4
  161. package/dist/hooks/WidgetPreset.js +6 -5
  162. package/dist/hooks/_ChangeLog.js +6 -6
  163. package/dist/hooks/_Role.js +2 -2
  164. package/dist/hooks/_User.js +13 -13
  165. package/dist/index.d.ts +4 -186
  166. package/dist/index.js +29 -553
  167. package/dist/types/Documentation_Category.d.ts +1 -1
  168. package/dist/types/Documentation_Document.d.ts +1 -1
  169. package/dist/types/EMS_ChargePoint.d.ts +51 -0
  170. package/dist/types/EMS_ChargePoint.js +89 -0
  171. package/dist/types/Maintenance_Schedule.d.ts +2 -2
  172. package/dist/types/Maintenance_Ticket_Data.d.ts +6 -7
  173. package/dist/types/Notification.d.ts +3 -0
  174. package/dist/types/Notification.js +6 -0
  175. package/dist/types/RAG_Data.d.ts +50 -0
  176. package/dist/types/RAG_Data.js +89 -0
  177. package/dist/types/RAG_Interview.d.ts +23 -0
  178. package/dist/types/RAG_Interview.js +35 -0
  179. package/dist/types/RAG_Meta.d.ts +23 -0
  180. package/dist/types/RAG_Meta.js +35 -0
  181. package/dist/types/RAG_Prompts.d.ts +31 -0
  182. package/dist/types/RAG_Prompts.js +53 -0
  183. package/dist/types/RAG_Questions.d.ts +16 -0
  184. package/dist/types/RAG_Questions.js +23 -0
  185. package/dist/types/RAG_Request.d.ts +23 -0
  186. package/dist/types/RAG_Request.js +35 -0
  187. package/dist/types/Spreadsheet_Workbook.d.ts +34 -0
  188. package/dist/types/Spreadsheet_Workbook.js +53 -0
  189. package/dist/types/index.d.ts +22 -3
  190. package/dist/types/index.js +19 -3
  191. package/package.json +3 -2
  192. package/schema/Documentation_Category.json +6 -15
  193. package/schema/Documentation_Document.json +8 -20
  194. package/schema/EMS_ChargePoint.json +80 -0
  195. package/schema/Knowledge_Chat.json +3 -0
  196. package/schema/Maintenance_Schedule.json +1 -1
  197. package/schema/Maintenance_Ticket_Data.json +1 -1
  198. package/schema/Notification.json +5 -0
  199. package/schema/RAG_Data.json +94 -0
  200. package/schema/RAG_Interview.json +54 -0
  201. package/schema/RAG_Meta.json +54 -0
  202. package/schema/RAG_Prompts.json +57 -0
  203. package/schema/RAG_Questions.json +42 -0
  204. package/schema/RAG_Request.json +53 -0
  205. package/schema/Spreadsheet_Workbook.json +73 -0
@@ -0,0 +1,10 @@
1
+ import { CloudCodeFunction } from "../types/CloudCodeFunction";
2
+ export declare class CloudCodeClass {
3
+ private static instance;
4
+ private registeredFunctions;
5
+ private constructor();
6
+ static getInstance(): CloudCodeClass;
7
+ registerFunction(name: string, fn: CloudCodeFunction): void;
8
+ getRegisteredFunctions(): Map<string, CloudCodeFunction>;
9
+ getFunction(name: string): CloudCodeFunction | undefined;
10
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.CloudCodeClass = void 0;
4
+ class CloudCodeClass {
5
+ constructor() {
6
+ this.registeredFunctions = new Map();
7
+ }
8
+ static getInstance() {
9
+ if (!CloudCodeClass.instance) {
10
+ CloudCodeClass.instance = new CloudCodeClass();
11
+ }
12
+ return CloudCodeClass.instance;
13
+ }
14
+ registerFunction(name, fn) {
15
+ this.registeredFunctions.set(name, fn);
16
+ }
17
+ getRegisteredFunctions() {
18
+ return this.registeredFunctions;
19
+ }
20
+ getFunction(name) {
21
+ return this.registeredFunctions.get(name);
22
+ }
23
+ }
24
+ exports.CloudCodeClass = CloudCodeClass;
@@ -0,0 +1,7 @@
1
+ import { CloudCodeModule } from "..";
2
+ /**
3
+ * Type guard to validate that a loaded module has a valid init function.
4
+ * This is required because branded types are compile-time only and cannot
5
+ * enforce structure on dynamically loaded modules.
6
+ */
7
+ export declare function isCloudCodeModule(module: unknown): module is CloudCodeModule;
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isCloudCodeModule = isCloudCodeModule;
4
+ /**
5
+ * Type guard to validate that a loaded module has a valid init function.
6
+ * This is required because branded types are compile-time only and cannot
7
+ * enforce structure on dynamically loaded modules.
8
+ */
9
+ function isCloudCodeModule(module) {
10
+ return (typeof module === "object" &&
11
+ module !== null &&
12
+ "init" in module &&
13
+ typeof module.init === "function");
14
+ }
@@ -0,0 +1,3 @@
1
+ export { autoloadCloudCode, default as initAutoload, } from "./services/loadCloudCode";
2
+ export { CloudCodeClass } from "./classes/CloudCodeClass";
3
+ export { CloudCodeFunction, CloudCodeModule } from "./types/CloudCodeFunction";
@@ -0,0 +1,11 @@
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.CloudCodeClass = exports.initAutoload = exports.autoloadCloudCode = void 0;
7
+ var loadCloudCode_1 = require("./services/loadCloudCode");
8
+ Object.defineProperty(exports, "autoloadCloudCode", { enumerable: true, get: function () { return loadCloudCode_1.autoloadCloudCode; } });
9
+ Object.defineProperty(exports, "initAutoload", { enumerable: true, get: function () { return __importDefault(loadCloudCode_1).default; } });
10
+ var CloudCodeClass_1 = require("./classes/CloudCodeClass");
11
+ Object.defineProperty(exports, "CloudCodeClass", { enumerable: true, get: function () { return CloudCodeClass_1.CloudCodeClass; } });
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Autoloads cloud code files from the specified path. Each file MUST export an init() function.
3
+ *
4
+ * @param path - The path to the directory containing the cloud code files.
5
+ * @param regex - Optional regular expression to filter the file names. Defaults to /^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/.
6
+ * @returns A promise that resolves when all the cloud code files have been loaded and initialized.
7
+ */
8
+ export declare function autoloadCloudCode(path: string, regex?: RegExp): Promise<void>;
9
+ export default function initAutoload(): Promise<void>;
@@ -0,0 +1,44 @@
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.autoloadCloudCode = autoloadCloudCode;
7
+ exports.default = initAutoload;
8
+ const config_1 = require("../../config");
9
+ const fs_1 = __importDefault(require("fs"));
10
+ const path_1 = require("path");
11
+ const __1 = require("..");
12
+ const checkCloudCodeFunction_1 = require("../helper/checkCloudCodeFunction");
13
+ /**
14
+ * Autoloads cloud code files from the specified path. Each file MUST export an init() function.
15
+ *
16
+ * @param path - The path to the directory containing the cloud code files.
17
+ * @param regex - Optional regular expression to filter the file names. Defaults to /^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/.
18
+ * @returns A promise that resolves when all the cloud code files have been loaded and initialized.
19
+ */
20
+ async function autoloadCloudCode(path, regex = /^[a-zA-Z0-9]+(?:-[a-zA-Z0-9]+)*$/) {
21
+ const cloudCodeHandler = __1.CloudCodeClass.getInstance();
22
+ const fns = fs_1.default
23
+ .readdirSync(path)
24
+ .filter((filename) => filename.endsWith(".js"))
25
+ .map((filename) => filename.replace(".js", ""))
26
+ .filter((name) => regex.test(name));
27
+ for (const name of fns) {
28
+ const module = require((0, path_1.join)(path, name));
29
+ if (!(0, checkCloudCodeFunction_1.isCloudCodeModule)(module)) {
30
+ console.warn(`[@openinc/parse-server-opendash] Skipping ${name}.js - missing or invalid init function`);
31
+ continue;
32
+ }
33
+ console.log(`[@openinc/parse-server-opendash] Autoloading ${name}.js`);
34
+ cloudCodeHandler.registerFunction(name, module.init);
35
+ await module.init().catch((e) => console.error(e));
36
+ }
37
+ }
38
+ async function initAutoload() {
39
+ const config = config_1.ConfigInstance.getInstance();
40
+ const path = config.get("AUTOLOAD_DIR");
41
+ if (path) {
42
+ await autoloadCloudCode((0, path_1.resolve)(process.cwd(), path));
43
+ }
44
+ }
@@ -0,0 +1,7 @@
1
+ export type CloudCodeFunction = () => Promise<void>;
2
+ /**
3
+ * Represents a cloud code module that must export an init function.
4
+ */
5
+ export type CloudCodeModule = {
6
+ init: CloudCodeFunction;
7
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Retrieves the value of a configuration key from OD3_Config.
3
+ * @param key - The key of the configuration to retrieve.
4
+ * @returns A promise that resolves to the value of the configuration key, or undefined if not found.
5
+ */
6
+ export declare function getConfig(key: string): Promise<string | undefined>;
7
+ /**
8
+ * Retrieves the value of a configuration key from OD3_Config as a boolean
9
+ * Converts the string value to a boolean value using the following rules:
10
+ * - "true" or "1" -> true
11
+ * - "false" or "0" -> false
12
+ * - undefined/null -> false
13
+ * - Any other value -> true
14
+ *
15
+ * @param key - The key of the configuration value.
16
+ * @returns A boolean value indicating the configuration value.
17
+ */
18
+ export declare function getConfigBoolean(key: string): Promise<boolean>;
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getConfig = getConfig;
4
+ exports.getConfigBoolean = getConfigBoolean;
5
+ const types_1 = require("../../../types");
6
+ /**
7
+ * Retrieves the value of a configuration key from OD3_Config.
8
+ * @param key - The key of the configuration to retrieve.
9
+ * @returns A promise that resolves to the value of the configuration key, or undefined if not found.
10
+ */
11
+ async function getConfig(key) {
12
+ const result = await new Parse.Query(types_1.Config).equalTo("key", key).first({
13
+ useMasterKey: true,
14
+ });
15
+ const value = result?.get("value");
16
+ console.log("[@openinc/parse-server-opendash][Config]", key, value);
17
+ return value || "";
18
+ }
19
+ /**
20
+ * Retrieves the value of a configuration key from OD3_Config as a boolean
21
+ * Converts the string value to a boolean value using the following rules:
22
+ * - "true" or "1" -> true
23
+ * - "false" or "0" -> false
24
+ * - undefined/null -> false
25
+ * - Any other value -> true
26
+ *
27
+ * @param key - The key of the configuration value.
28
+ * @returns A boolean value indicating the configuration value.
29
+ */
30
+ async function getConfigBoolean(key) {
31
+ const value = await getConfig(key);
32
+ if (!value || value.toLowerCase() === "false" || value === "0") {
33
+ return false;
34
+ }
35
+ return true;
36
+ }
@@ -5,3 +5,4 @@ export { ConfigKeys } from "./types/ConfigKeys";
5
5
  export { baseoptions } from "./helper/baseOptions";
6
6
  export { customoptions } from "./helper/customOptions";
7
7
  export { isFeatureEnabled } from "./helper/isFeatureEnabled";
8
+ export { getConfig, getConfigBoolean } from "./helper/getConfig";
@@ -3,7 +3,7 @@ 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.customoptions = exports.baseoptions = exports.ConfigKeys = exports.ConfigInstance = exports.ConfigState = void 0;
6
+ exports.getConfigBoolean = exports.getConfig = exports.isFeatureEnabled = exports.customoptions = exports.baseoptions = exports.ConfigKeys = exports.ConfigInstance = exports.ConfigState = void 0;
7
7
  var Config_1 = require("./states/Config");
8
8
  Object.defineProperty(exports, "ConfigState", { enumerable: true, get: function () { return Config_1.ConfigState; } });
9
9
  var ConfigInstance_1 = require("./services/ConfigInstance");
@@ -16,3 +16,6 @@ var customOptions_1 = require("./helper/customOptions");
16
16
  Object.defineProperty(exports, "customoptions", { enumerable: true, get: function () { return customOptions_1.customoptions; } });
17
17
  var isFeatureEnabled_1 = require("./helper/isFeatureEnabled");
18
18
  Object.defineProperty(exports, "isFeatureEnabled", { enumerable: true, get: function () { return isFeatureEnabled_1.isFeatureEnabled; } });
19
+ var getConfig_1 = require("./helper/getConfig");
20
+ Object.defineProperty(exports, "getConfig", { enumerable: true, get: function () { return getConfig_1.getConfig; } });
21
+ Object.defineProperty(exports, "getConfigBoolean", { enumerable: true, get: function () { return getConfig_1.getConfigBoolean; } });
@@ -0,0 +1,10 @@
1
+ import { Permission } from "../../../types";
2
+ /**
3
+ * Ensures that a OD3_Permission with the specified key exists in the database.
4
+ * If the permission already exists, it updates the ACL if provided.
5
+ * If the permission does not exist, it creates a new permission with the specified key and ACL.
6
+ * @param key - The key of the permission.
7
+ * @param acl - The Parse.ACL to be set for the permission.
8
+ * @returns The updated or newly created permission.
9
+ */
10
+ export declare function ensurePermission(key: string, acl?: Parse.ACL): Promise<Permission>;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensurePermission = ensurePermission;
4
+ const types_1 = require("../../../types");
5
+ /**
6
+ * Ensures that a OD3_Permission with the specified key exists in the database.
7
+ * If the permission already exists, it updates the ACL if provided.
8
+ * If the permission does not exist, it creates a new permission with the specified key and ACL.
9
+ * @param key - The key of the permission.
10
+ * @param acl - The Parse.ACL to be set for the permission.
11
+ * @returns The updated or newly created permission.
12
+ */
13
+ async function ensurePermission(key, acl) {
14
+ const permission = await new Parse.Query(types_1.Permission)
15
+ .equalTo("key", key)
16
+ .first({ useMasterKey: true });
17
+ if (permission) {
18
+ if (acl) {
19
+ permission.setACL(acl);
20
+ return await permission.save(null, { useMasterKey: true });
21
+ }
22
+ return permission;
23
+ }
24
+ else {
25
+ const newPermission = new types_1.Permission({ key });
26
+ if (acl) {
27
+ newPermission.setACL(acl);
28
+ }
29
+ else {
30
+ newPermission.setACL(new Parse.ACL());
31
+ }
32
+ return await newPermission.save(null, { useMasterKey: true });
33
+ }
34
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Checks if a user has a specific permission in OD3_Permission.
3
+ * @param sessionToken - The session token of the user.
4
+ * @param key - The key of the permission to check.
5
+ * @returns A promise that resolves to a boolean indicating whether the user has the permission.
6
+ */
7
+ export declare function hasPermission(sessionToken: string, key: string): Promise<boolean>;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hasPermission = hasPermission;
4
+ const types_1 = require("../../../types");
5
+ /**
6
+ * Checks if a user has a specific permission in OD3_Permission.
7
+ * @param sessionToken - The session token of the user.
8
+ * @param key - The key of the permission to check.
9
+ * @returns A promise that resolves to a boolean indicating whether the user has the permission.
10
+ */
11
+ async function hasPermission(sessionToken, key) {
12
+ const result = await new Parse.Query(types_1.Permission)
13
+ .equalTo("key", key)
14
+ .first({ sessionToken });
15
+ return !!result;
16
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Checks if the user has the required permission to perform an operation using hasPermission().
3
+ * If the user does not have the required permission, an error is thrown.
4
+ *
5
+ * @param request - The request object containing the user's session token and masterkey status.
6
+ * @param key - The permission key required for the operation.
7
+ * @param message - The error message to be thrown if the user does not have the required permission.
8
+ * @returns A Promise that resolves if the user has the required permission, or throws an error if not.
9
+ */
10
+ export declare function requirePermission(request: {
11
+ master?: boolean;
12
+ sessionToken: string | undefined;
13
+ }, key: string | null, message: string): Promise<void>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.requirePermission = requirePermission;
4
+ const __1 = require("..");
5
+ /**
6
+ * Checks if the user has the required permission to perform an operation using hasPermission().
7
+ * If the user does not have the required permission, an error is thrown.
8
+ *
9
+ * @param request - The request object containing the user's session token and masterkey status.
10
+ * @param key - The permission key required for the operation.
11
+ * @param message - The error message to be thrown if the user does not have the required permission.
12
+ * @returns A Promise that resolves if the user has the required permission, or throws an error if not.
13
+ */
14
+ async function requirePermission(request, key, message) {
15
+ if (request.master) {
16
+ return;
17
+ }
18
+ if (!key) {
19
+ throw new Parse.Error(119, "Missing Permission (1): " + (message || key || "Master Key Only"));
20
+ }
21
+ if (!request.sessionToken) {
22
+ throw new Parse.Error(119, "Missing Permission (2): " + (message || key || "Master Key Only"));
23
+ }
24
+ const p = await (0, __1.hasPermission)(request.sessionToken, key);
25
+ if (!p) {
26
+ throw new Parse.Error(119, "Missing Permission (3): " + (message || key || "Master Key Only"));
27
+ }
28
+ }
@@ -2,3 +2,6 @@ export { FunctionKeys, PermissionInterface, PermissionMap, } from "./types/Permi
2
2
  export { Permissions } from "./types/Permissions";
3
3
  export { RegisteredPermission } from "./states/PermissionClass";
4
4
  export { getAllPermissions, default as initPermissions, } from "./services/registerPermissions";
5
+ export { ensurePermission } from "./helper/ensurePermission";
6
+ export { hasPermission } from "./helper/hasPermission";
7
+ export { requirePermission } from "./helper/requirePermission";
@@ -3,7 +3,7 @@ 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.initPermissions = exports.getAllPermissions = exports.RegisteredPermission = exports.Permissions = void 0;
6
+ exports.requirePermission = exports.hasPermission = exports.ensurePermission = exports.initPermissions = exports.getAllPermissions = exports.RegisteredPermission = exports.Permissions = void 0;
7
7
  var Permissions_1 = require("./types/Permissions");
8
8
  Object.defineProperty(exports, "Permissions", { enumerable: true, get: function () { return Permissions_1.Permissions; } });
9
9
  var PermissionClass_1 = require("./states/PermissionClass");
@@ -11,3 +11,9 @@ Object.defineProperty(exports, "RegisteredPermission", { enumerable: true, get:
11
11
  var registerPermissions_1 = require("./services/registerPermissions");
12
12
  Object.defineProperty(exports, "getAllPermissions", { enumerable: true, get: function () { return registerPermissions_1.getAllPermissions; } });
13
13
  Object.defineProperty(exports, "initPermissions", { enumerable: true, get: function () { return __importDefault(registerPermissions_1).default; } });
14
+ var ensurePermission_1 = require("./helper/ensurePermission");
15
+ Object.defineProperty(exports, "ensurePermission", { enumerable: true, get: function () { return ensurePermission_1.ensurePermission; } });
16
+ var hasPermission_1 = require("./helper/hasPermission");
17
+ Object.defineProperty(exports, "hasPermission", { enumerable: true, get: function () { return hasPermission_1.hasPermission; } });
18
+ var requirePermission_1 = require("./helper/requirePermission");
19
+ Object.defineProperty(exports, "requirePermission", { enumerable: true, get: function () { return requirePermission_1.requirePermission; } });
@@ -0,0 +1,9 @@
1
+ export declare class SchemaClass {
2
+ private static instance;
3
+ private schema;
4
+ private constructor();
5
+ static getInstance(): SchemaClass;
6
+ setSchema(schema: Record<string, any>): void;
7
+ getSchema(): Record<string, any>;
8
+ getClassSchema(className: string): any | undefined;
9
+ }
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SchemaClass = void 0;
4
+ class SchemaClass {
5
+ constructor() {
6
+ this.schema = {};
7
+ }
8
+ static getInstance() {
9
+ if (!SchemaClass.instance) {
10
+ SchemaClass.instance = new SchemaClass();
11
+ }
12
+ return SchemaClass.instance;
13
+ }
14
+ setSchema(schema) {
15
+ this.schema = schema;
16
+ }
17
+ getSchema() {
18
+ return this.schema;
19
+ }
20
+ getClassSchema(className) {
21
+ return this.schema[className];
22
+ }
23
+ }
24
+ exports.SchemaClass = SchemaClass;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * Handles the default beforeSave() logic for a Parse.Object.
3
+ *
4
+ * This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user if not provided.
5
+ * This will also mark the user and tenant fields as immutable, preventing them from being edited in the future.
6
+ *
7
+ * @param request - The Parse.Cloud.BeforeSaveRequest object.
8
+ * @returns - Returns void.
9
+ * @throws - Throws an error if the user is not provided.
10
+ */
11
+ export declare function defaultHandler(request: {
12
+ original?: Parse.Object;
13
+ object: Parse.Object;
14
+ user?: Parse.User;
15
+ master?: boolean;
16
+ sessionToken: string | undefined;
17
+ }): Promise<void>;
18
+ /**
19
+ * Handles the default Parse.ACL beforeSave() logic for a Parse.Object.
20
+ *
21
+ * This function will set the default ACL for the object based on the user and tenant fields. By default, the object will be readable and writable by the tenant role and readable by tenant users.
22
+ *
23
+ * @param request - The Parse.Cloud.BeforeSaveRequest object.
24
+ * @param options - Optional configuration options.
25
+ * @param options.allowCustomACL - Whether to allow custom ACL (default: false).
26
+ * @param options.allowTenantUserWrite - Whether to allow tenant users to write (default: false).
27
+ * @param options.denyTenantUserRead - Whether to deny tenant users from reading (default: false).
28
+ */
29
+ export declare function defaultAclHandler(request: Parse.Cloud.BeforeSaveRequest, options?: {
30
+ allowCustomACL?: boolean;
31
+ allowTenantUserWrite?: boolean;
32
+ denyTenantUserRead?: boolean;
33
+ }): Promise<void>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultHandler = defaultHandler;
4
+ exports.defaultAclHandler = defaultAclHandler;
5
+ const __1 = require("..");
6
+ const permissions_1 = require("../../permissions");
7
+ const SchemaClass_1 = require("../classes/SchemaClass");
8
+ /**
9
+ * Handles the default beforeSave() logic for a Parse.Object.
10
+ *
11
+ * This function will check if a user or tenant field is present in the schema and set the value to the current user and/or the tenant of the current user if not provided.
12
+ * This will also mark the user and tenant fields as immutable, preventing them from being edited in the future.
13
+ *
14
+ * @param request - The Parse.Cloud.BeforeSaveRequest object.
15
+ * @returns - Returns void.
16
+ * @throws - Throws an error if the user is not provided.
17
+ */
18
+ async function defaultHandler(request) {
19
+ const className = request.object.className;
20
+ if (request.master) {
21
+ console.log(`[@openinc/parse-server-opendash] Skipping default beforeSave() handler of ${className} for masterkey`);
22
+ return;
23
+ }
24
+ if (!request.user) {
25
+ throw new Error();
26
+ }
27
+ const currentSchema = SchemaClass_1.SchemaClass.getInstance().getClassSchema(className);
28
+ if (!currentSchema) {
29
+ console.warn(`[@openinc/parse-server-opendash] Skipping default beforeSave() handler, no schema found for ${className}`);
30
+ return;
31
+ }
32
+ const userField = !!currentSchema?.fields?.user;
33
+ const tenantField = !!currentSchema?.fields?.tenant;
34
+ if (userField) {
35
+ await (0, __1.immutableField)(request, "user");
36
+ }
37
+ if (tenantField) {
38
+ await (0, __1.immutableField)(request, "tenant");
39
+ }
40
+ if (!request.original) {
41
+ if (userField) {
42
+ request.object.set("user", request.user);
43
+ }
44
+ if (tenantField) {
45
+ const user = (await request.user?.fetch({
46
+ useMasterKey: true,
47
+ }));
48
+ try {
49
+ await (0, permissions_1.requirePermission)(request, "opendash:can-admin-tenants", "User is not allowed to use tag which ignores tenant prefix");
50
+ if (!request.object.get("tenant")) {
51
+ request.object.set("tenant", user.get("tenant"));
52
+ }
53
+ }
54
+ catch (error) {
55
+ request.object.set("tenant", user.get("tenant"));
56
+ }
57
+ }
58
+ }
59
+ }
60
+ /**
61
+ * Handles the default Parse.ACL beforeSave() logic for a Parse.Object.
62
+ *
63
+ * This function will set the default ACL for the object based on the user and tenant fields. By default, the object will be readable and writable by the tenant role and readable by tenant users.
64
+ *
65
+ * @param request - The Parse.Cloud.BeforeSaveRequest object.
66
+ * @param options - Optional configuration options.
67
+ * @param options.allowCustomACL - Whether to allow custom ACL (default: false).
68
+ * @param options.allowTenantUserWrite - Whether to allow tenant users to write (default: false).
69
+ * @param options.denyTenantUserRead - Whether to deny tenant users from reading (default: false).
70
+ */
71
+ async function defaultAclHandler(request, options) {
72
+ const className = request.object.className;
73
+ const currentSchema = SchemaClass_1.SchemaClass.getInstance().getClassSchema(className);
74
+ if (!currentSchema) {
75
+ console.warn(`[@openinc/parse-server-opendash] Skipping default beforeSave() ACL handler, no schema found for ${className}`);
76
+ return;
77
+ }
78
+ const userField = !!currentSchema?.fields?.user;
79
+ const tenantField = !!currentSchema?.fields?.tenant;
80
+ if (!options?.allowCustomACL || !request.object.getACL()) {
81
+ request.object.setACL(new Parse.ACL());
82
+ }
83
+ const acl = request.object.getACL();
84
+ acl.setRoleReadAccess("od-admin", true);
85
+ acl.setRoleWriteAccess("od-admin", true);
86
+ if (userField) {
87
+ const user = request.object.get("user");
88
+ if (user) {
89
+ acl.setReadAccess(user.id, true);
90
+ acl.setWriteAccess(user.id, true);
91
+ }
92
+ }
93
+ if (tenantField) {
94
+ const tenant = request.object.get("tenant");
95
+ if (tenant) {
96
+ if (!options?.denyTenantUserRead) {
97
+ acl.setRoleReadAccess(`od-tenant-user-${tenant.id}`, true);
98
+ }
99
+ if (options?.allowTenantUserWrite) {
100
+ acl.setRoleWriteAccess(`od-tenant-user-${tenant.id}`, true);
101
+ }
102
+ acl.setRoleReadAccess(`od-tenant-admin-${tenant.id}`, true);
103
+ acl.setRoleWriteAccess(`od-tenant-admin-${tenant.id}`, true);
104
+ }
105
+ }
106
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Ensures the existence of a role with the specified name.
3
+ * If the role does not exist, it creates a new role with the given name and options.
4
+ * If the role already exists, it updates the role with the provided options.
5
+ *
6
+ * @param name - The name of the role.
7
+ * @param options - Optional parameters for the role.
8
+ * @param options.label - The label for the role.
9
+ * @param options.acl - The Parse.ACL for the role.
10
+ * @param options.childRoles - An array of child role names to be associated with the role.
11
+ * @returns A Promise that resolves when the role is successfully created or updated.
12
+ */
13
+ export declare function ensureRole(name: string, options?: {
14
+ label?: string;
15
+ acl?: Parse.ACL;
16
+ childRoles?: string[];
17
+ }): Promise<void>;
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ensureRole = ensureRole;
4
+ const fast_equals_1 = require("fast-equals");
5
+ /**
6
+ * Ensures the existence of a role with the specified name.
7
+ * If the role does not exist, it creates a new role with the given name and options.
8
+ * If the role already exists, it updates the role with the provided options.
9
+ *
10
+ * @param name - The name of the role.
11
+ * @param options - Optional parameters for the role.
12
+ * @param options.label - The label for the role.
13
+ * @param options.acl - The Parse.ACL for the role.
14
+ * @param options.childRoles - An array of child role names to be associated with the role.
15
+ * @returns A Promise that resolves when the role is successfully created or updated.
16
+ */
17
+ async function ensureRole(name, options) {
18
+ const label = options?.label || undefined;
19
+ const acl = options?.acl || new Parse.ACL();
20
+ const childRoles = options?.childRoles || undefined;
21
+ console.log(`[@openinc/parse-server-opendash] ensureRole(${name})`
22
+ // JSON.stringify({ label, acl, childRoles }, null, 2)
23
+ );
24
+ let role = await new Parse.Query(Parse.Role)
25
+ .equalTo("name", name)
26
+ .first({ useMasterKey: true });
27
+ if (!role) {
28
+ role = new Parse.Role(name, acl);
29
+ role.set("label", label);
30
+ try {
31
+ await role.save(null, {
32
+ useMasterKey: true,
33
+ });
34
+ }
35
+ catch (error) {
36
+ console.error("--------> Error creating role", error);
37
+ }
38
+ }
39
+ let changed = false;
40
+ if (role.get("label") !== label) {
41
+ role.set("label", label);
42
+ changed = true;
43
+ }
44
+ if (!(0, fast_equals_1.deepEqual)(acl.toJSON(), role.getACL()?.toJSON())) {
45
+ role.setACL(acl);
46
+ changed = true;
47
+ }
48
+ if (Array.isArray(childRoles) && childRoles.length > 0) {
49
+ const relation = role.getRoles();
50
+ const currentChildRoles = await relation
51
+ .query()
52
+ .find({ useMasterKey: true });
53
+ const currentChildRoleNames = currentChildRoles.map((role) => role.get("name"));
54
+ for (const childRoleName of childRoles) {
55
+ if (currentChildRoleNames.includes(childRoleName)) {
56
+ continue;
57
+ }
58
+ const childRole = await new Parse.Query(Parse.Role)
59
+ .equalTo("name", childRoleName)
60
+ .find({ useMasterKey: true });
61
+ relation.add(childRole);
62
+ changed = true;
63
+ }
64
+ }
65
+ if (changed) {
66
+ await role.save(null, { useMasterKey: true });
67
+ }
68
+ }
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Ensures that a user has a specific role.
3
+ * @param user The user to assign the role to.
4
+ * @param roleName The name of the role.
5
+ * @param add Specifies whether to add or remove the user from the role. Default is false (remove).
6
+ */
7
+ export declare function ensureUserRole(user: Parse.User, roleName: string, add?: boolean): Promise<void>;