@modular-rest/server 1.11.14 → 1.11.15

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 (79) hide show
  1. package/dist/application.d.ts +29 -0
  2. package/dist/application.js +217 -0
  3. package/dist/class/cms_trigger.d.ts +52 -0
  4. package/dist/class/cms_trigger.js +47 -0
  5. package/dist/class/collection_definition.d.ts +112 -0
  6. package/dist/class/collection_definition.js +87 -0
  7. package/dist/class/combinator.d.ts +43 -0
  8. package/dist/class/combinator.js +174 -0
  9. package/dist/class/database_trigger.d.ts +90 -0
  10. package/dist/class/database_trigger.js +64 -0
  11. package/dist/class/db_schemas.d.ts +25 -0
  12. package/dist/class/db_schemas.js +28 -0
  13. package/dist/class/directory.d.ts +20 -0
  14. package/dist/class/directory.js +87 -0
  15. package/dist/class/paginator.d.ts +31 -0
  16. package/dist/class/paginator.js +43 -0
  17. package/dist/class/reply.d.ts +29 -0
  18. package/dist/class/reply.js +44 -0
  19. package/dist/class/security.d.ts +186 -0
  20. package/dist/class/security.js +178 -0
  21. package/dist/class/trigger_operator.d.ts +92 -0
  22. package/dist/class/trigger_operator.js +99 -0
  23. package/dist/class/user.d.ts +81 -0
  24. package/dist/class/user.js +151 -0
  25. package/dist/class/validator.d.ts +19 -0
  26. package/dist/class/validator.js +101 -0
  27. package/dist/config.d.ts +113 -0
  28. package/dist/config.js +26 -0
  29. package/dist/defult-permissions.d.ts +2 -0
  30. package/dist/defult-permissions.js +31 -0
  31. package/dist/events.d.ts +23 -0
  32. package/dist/events.js +47 -0
  33. package/dist/helper/data_insertion.d.ts +38 -0
  34. package/dist/helper/data_insertion.js +110 -0
  35. package/dist/helper/presetup_services.d.ts +60 -0
  36. package/dist/helper/presetup_services.js +108 -0
  37. package/dist/index.d.ts +118 -0
  38. package/dist/middlewares.d.ts +53 -0
  39. package/dist/middlewares.js +106 -0
  40. package/dist/play-test.d.ts +1 -0
  41. package/dist/play-test.js +9 -0
  42. package/dist/services/data_provider/router.d.ts +4 -0
  43. package/dist/services/data_provider/router.js +412 -0
  44. package/dist/services/data_provider/service.d.ts +132 -0
  45. package/dist/services/data_provider/service.js +253 -0
  46. package/dist/services/data_provider/typeCasters.d.ts +9 -0
  47. package/dist/services/data_provider/typeCasters.js +18 -0
  48. package/dist/services/file/db.d.ts +1 -0
  49. package/dist/services/file/db.js +31 -0
  50. package/dist/services/file/router.d.ts +4 -0
  51. package/dist/services/file/router.js +115 -0
  52. package/dist/services/file/service.d.ts +204 -0
  53. package/dist/services/file/service.js +341 -0
  54. package/dist/services/functions/router.d.ts +4 -0
  55. package/dist/services/functions/router.js +68 -0
  56. package/dist/services/functions/service.d.ts +132 -0
  57. package/dist/services/functions/service.js +159 -0
  58. package/dist/services/jwt/router.d.ts +4 -0
  59. package/dist/services/jwt/router.js +99 -0
  60. package/dist/services/jwt/service.d.ts +97 -0
  61. package/dist/services/jwt/service.js +135 -0
  62. package/dist/services/user_manager/db.d.ts +1 -0
  63. package/dist/services/user_manager/db.js +75 -0
  64. package/dist/services/user_manager/permissionManager.d.ts +19 -0
  65. package/dist/services/user_manager/permissionManager.js +42 -0
  66. package/dist/services/user_manager/router.d.ts +4 -0
  67. package/dist/services/user_manager/router.js +195 -0
  68. package/dist/services/user_manager/service.d.ts +317 -0
  69. package/dist/services/user_manager/service.js +632 -0
  70. package/package.json +3 -3
  71. package/src/application.ts +1 -1
  72. package/src/class/cms_trigger.ts +8 -14
  73. package/src/class/database_trigger.ts +10 -4
  74. package/src/class/user.ts +1 -1
  75. package/src/services/data_provider/router.ts +293 -0
  76. package/src/services/data_provider/service.ts +2 -1
  77. package/src/services/functions/router.ts +3 -2
  78. package/src/services/user_manager/db.ts +5 -5
  79. package/src/services/user_manager/service.ts +20 -15
@@ -0,0 +1,186 @@
1
+ /**
2
+ * Permission type string literal type that defines various access levels and capabilities
3
+
4
+ * @inline
5
+ */
6
+ export type AccessType = 'god_access' | 'user_access' | 'upload_file_access' | 'remove_file_access' | 'anonymous_access' | 'advanced_settings' | string;
7
+ /**
8
+ * Defines access control for a specific database collection
9
+ *
10
+ * @internal
11
+ */
12
+ export declare class AccessDefinition {
13
+ /** @hidden */
14
+ database: string;
15
+ /** @hidden */
16
+ collection: string;
17
+ /** @hidden */
18
+ permissionList: Permission[];
19
+ /**
20
+ * Creates a new AccessDefinition instance
21
+ * @param {Object} options - Configuration options
22
+ * @param {string} options.database - The name of the database
23
+ * @param {string} options.collection - The name of the collection
24
+ * @param {Permission[]} options.permissionList - List of permissions
25
+ */
26
+ constructor({ database, collection, permissionList, }: {
27
+ database: string;
28
+ collection: string;
29
+ permissionList: Permission[];
30
+ });
31
+ }
32
+ /**
33
+ * Defines a permission for accessing data within the system. This class is a fundamental component used in both the {@link defineCollection} method and {@link CollectionDefinition} class
34
+ * by specifying which permission types can interact with them. The permission system matches a user's assigned permission types against
35
+ * the collection's permissions to determine access levels. For example, a collection can allow read access for 'user_access' while
36
+ * restricting writes to 'advanced_settings' permissions.
37
+ *
38
+ * @remark
39
+ * {@include ../../docs/system-access-type.md}
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * import { Permission } from '@modular-rest/server';
44
+ *
45
+ * const permission = new Permission({
46
+ * type: 'user_access',
47
+ * read: true,
48
+ * write: true,
49
+ * onlyOwnData: true,
50
+ * ownerIdField: 'userId'
51
+ * });
52
+ * ```
53
+ */
54
+ export declare class Permission {
55
+ /** @hidden */
56
+ accessType: AccessType;
57
+ /** @hidden */
58
+ read: boolean;
59
+ /** @hidden */
60
+ write: boolean;
61
+ /** @hidden */
62
+ onlyOwnData: boolean;
63
+ /** @hidden */
64
+ ownerIdField: string;
65
+ /**
66
+ * Creates a new Permission instance
67
+ * @param {Object} options - Configuration options
68
+ *
69
+ * @param {AccessType} options.type - The type of permission,system defined or custom. check the **Remarks section** for more information.
70
+ *
71
+ * @param {boolean} [options.read=false] - Whether read access is granted
72
+ * @param {boolean} [options.write=false] - Whether write access is granted
73
+ * @param {boolean} [options.onlyOwnData=false] - Whether access is limited to own data
74
+ * @param {string} [options.ownerIdField='refId'] - Field name for owner identification
75
+ */
76
+ constructor({ accessType: type, read, write, onlyOwnData, ownerIdField, }: {
77
+ accessType: AccessType;
78
+ read?: boolean;
79
+ write?: boolean;
80
+ onlyOwnData?: boolean;
81
+ ownerIdField?: string;
82
+ });
83
+ }
84
+ /**
85
+ * A comprehensive access control mechanism that manages user permissions through grouped access types.
86
+ *
87
+ * Permission groups are a fundamental security concept that define and enforce what actions users
88
+ * can perform within the system. They provide a flexible and maintainable way to handle authorization
89
+ * by grouping related access types together.
90
+ *
91
+ * These groups enable users to:
92
+ * 1. Read and write data from collections that match their access types, allowing granular control
93
+ * over database operations
94
+ * 2. Execute specific functions that require matching access types, ensuring that sensitive
95
+ * operations are only performed by authorized users
96
+ * 3. Perform custom developer-defined actions by validating against the user's access types,
97
+ * enabling extensible permission-based features
98
+ *
99
+ * Permission groups can be configured as default groups for new users or anonymous groups for
100
+ * unauthenticated access, providing a complete authorization framework.
101
+ *
102
+ * @class PermissionGroup
103
+ * @property {string} title - The title of the permission group
104
+ * @property {boolean} isDefault - This is a default group, on `true` this permission group will be given to any new user automatically.
105
+ * @property {boolean} isAnonymous - This is a anonymous group, on `true` will be used for anonymous users.
106
+ * @property {AccessType[]} allowedAccessTypes - List of valid access types.
107
+ * @example
108
+ * ```typescript
109
+ * const group = new PermissionGroup({
110
+ * title: 'Admin',
111
+ * isDefault: true,
112
+ * allowedAccessTypes: ['god_access', 'advanced_settings']
113
+ * });
114
+ * ```
115
+ */
116
+ export declare class PermissionGroup {
117
+ /** @hidden */
118
+ title: string;
119
+ /** @hidden */
120
+ isDefault: boolean;
121
+ /** @hidden */
122
+ isAnonymous: boolean;
123
+ /** @hidden */
124
+ allowedAccessTypes: AccessType[];
125
+ /**
126
+ * Creates a new PermissionGroup instance
127
+ * @param {Object} options - Configuration options
128
+ * @param {string} options.title - The title of the group
129
+ * @param {boolean} [options.isDefault=false] - Whether this is a default group
130
+ * @param {boolean} [options.isAnonymous=false] - Whether this group is for anonymous users
131
+ * @param {AccessType[]} [options.allowedAccessTypes=[]] - List of valid permission types
132
+ */
133
+ constructor({ title, isDefault, isAnonymous, allowedAccessTypes, }: {
134
+ title: string;
135
+ isDefault?: boolean;
136
+ isAnonymous?: boolean;
137
+ allowedAccessTypes?: AccessType[];
138
+ });
139
+ }
140
+ /**
141
+ * Provides static access to access type constants
142
+ * @class AccessTypes
143
+ */
144
+ export declare class AccessTypes {
145
+ /**
146
+ * Get the string representing read access type
147
+ * @returns {string} The read access type
148
+ */
149
+ static get read(): string;
150
+ /**
151
+ * Get the string representing write access type
152
+ * @returns {string} The write access type
153
+ */
154
+ static get write(): string;
155
+ }
156
+ /**
157
+ * Provides static access to permission type constants
158
+ * @class PermissionTypes
159
+ */
160
+ export declare class PermissionTypes {
161
+ /**
162
+ * Get the string representing god access permission type
163
+ * @returns {string} The god access permission type
164
+ */
165
+ static get god_access(): AccessType;
166
+ /**
167
+ * Get the string representing advanced settings permission type
168
+ * @returns {string} The advanced settings permission type
169
+ */
170
+ static get advanced_settings(): AccessType;
171
+ /**
172
+ * Get the string representing user access permission type
173
+ * @returns {string} The user access permission type
174
+ */
175
+ static get user_access(): AccessType;
176
+ /**
177
+ * Get the string representing upload file access permission type
178
+ * @returns {string} The upload file access permission type
179
+ */
180
+ static get upload_file_access(): AccessType;
181
+ /**
182
+ * Get the string representing remove file access permission type
183
+ * @returns {string} The remove file access permission type
184
+ */
185
+ static get remove_file_access(): AccessType;
186
+ }
@@ -0,0 +1,178 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PermissionTypes = exports.AccessTypes = exports.PermissionGroup = exports.Permission = exports.AccessDefinition = void 0;
4
+ /**
5
+ * Defines access control for a specific database collection
6
+ *
7
+ * @internal
8
+ */
9
+ class AccessDefinition {
10
+ /**
11
+ * Creates a new AccessDefinition instance
12
+ * @param {Object} options - Configuration options
13
+ * @param {string} options.database - The name of the database
14
+ * @param {string} options.collection - The name of the collection
15
+ * @param {Permission[]} options.permissionList - List of permissions
16
+ */
17
+ constructor({ database, collection, permissionList, }) {
18
+ this.database = database;
19
+ this.collection = collection;
20
+ this.permissionList = permissionList;
21
+ }
22
+ }
23
+ exports.AccessDefinition = AccessDefinition;
24
+ /**
25
+ * Defines a permission for accessing data within the system. This class is a fundamental component used in both the {@link defineCollection} method and {@link CollectionDefinition} class
26
+ * by specifying which permission types can interact with them. The permission system matches a user's assigned permission types against
27
+ * the collection's permissions to determine access levels. For example, a collection can allow read access for 'user_access' while
28
+ * restricting writes to 'advanced_settings' permissions.
29
+ *
30
+ * @remark
31
+ * {@include ../../docs/system-access-type.md}
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { Permission } from '@modular-rest/server';
36
+ *
37
+ * const permission = new Permission({
38
+ * type: 'user_access',
39
+ * read: true,
40
+ * write: true,
41
+ * onlyOwnData: true,
42
+ * ownerIdField: 'userId'
43
+ * });
44
+ * ```
45
+ */
46
+ class Permission {
47
+ /**
48
+ * Creates a new Permission instance
49
+ * @param {Object} options - Configuration options
50
+ *
51
+ * @param {AccessType} options.type - The type of permission,system defined or custom. check the **Remarks section** for more information.
52
+ *
53
+ * @param {boolean} [options.read=false] - Whether read access is granted
54
+ * @param {boolean} [options.write=false] - Whether write access is granted
55
+ * @param {boolean} [options.onlyOwnData=false] - Whether access is limited to own data
56
+ * @param {string} [options.ownerIdField='refId'] - Field name for owner identification
57
+ */
58
+ constructor({ accessType: type, read = false, write = false, onlyOwnData = false, ownerIdField = 'refId', }) {
59
+ this.accessType = type;
60
+ this.read = read;
61
+ this.write = write;
62
+ this.onlyOwnData = onlyOwnData;
63
+ this.ownerIdField = ownerIdField;
64
+ }
65
+ }
66
+ exports.Permission = Permission;
67
+ /**
68
+ * A comprehensive access control mechanism that manages user permissions through grouped access types.
69
+ *
70
+ * Permission groups are a fundamental security concept that define and enforce what actions users
71
+ * can perform within the system. They provide a flexible and maintainable way to handle authorization
72
+ * by grouping related access types together.
73
+ *
74
+ * These groups enable users to:
75
+ * 1. Read and write data from collections that match their access types, allowing granular control
76
+ * over database operations
77
+ * 2. Execute specific functions that require matching access types, ensuring that sensitive
78
+ * operations are only performed by authorized users
79
+ * 3. Perform custom developer-defined actions by validating against the user's access types,
80
+ * enabling extensible permission-based features
81
+ *
82
+ * Permission groups can be configured as default groups for new users or anonymous groups for
83
+ * unauthenticated access, providing a complete authorization framework.
84
+ *
85
+ * @class PermissionGroup
86
+ * @property {string} title - The title of the permission group
87
+ * @property {boolean} isDefault - This is a default group, on `true` this permission group will be given to any new user automatically.
88
+ * @property {boolean} isAnonymous - This is a anonymous group, on `true` will be used for anonymous users.
89
+ * @property {AccessType[]} allowedAccessTypes - List of valid access types.
90
+ * @example
91
+ * ```typescript
92
+ * const group = new PermissionGroup({
93
+ * title: 'Admin',
94
+ * isDefault: true,
95
+ * allowedAccessTypes: ['god_access', 'advanced_settings']
96
+ * });
97
+ * ```
98
+ */
99
+ class PermissionGroup {
100
+ /**
101
+ * Creates a new PermissionGroup instance
102
+ * @param {Object} options - Configuration options
103
+ * @param {string} options.title - The title of the group
104
+ * @param {boolean} [options.isDefault=false] - Whether this is a default group
105
+ * @param {boolean} [options.isAnonymous=false] - Whether this group is for anonymous users
106
+ * @param {AccessType[]} [options.allowedAccessTypes=[]] - List of valid permission types
107
+ */
108
+ constructor({ title, isDefault = false, isAnonymous = false, allowedAccessTypes = [], }) {
109
+ this.title = title;
110
+ this.isDefault = isDefault;
111
+ this.isAnonymous = isAnonymous;
112
+ this.allowedAccessTypes = allowedAccessTypes;
113
+ }
114
+ }
115
+ exports.PermissionGroup = PermissionGroup;
116
+ /**
117
+ * Provides static access to access type constants
118
+ * @class AccessTypes
119
+ */
120
+ class AccessTypes {
121
+ /**
122
+ * Get the string representing read access type
123
+ * @returns {string} The read access type
124
+ */
125
+ static get read() {
126
+ return 'read';
127
+ }
128
+ /**
129
+ * Get the string representing write access type
130
+ * @returns {string} The write access type
131
+ */
132
+ static get write() {
133
+ return 'write';
134
+ }
135
+ }
136
+ exports.AccessTypes = AccessTypes;
137
+ /**
138
+ * Provides static access to permission type constants
139
+ * @class PermissionTypes
140
+ */
141
+ class PermissionTypes {
142
+ /**
143
+ * Get the string representing god access permission type
144
+ * @returns {string} The god access permission type
145
+ */
146
+ static get god_access() {
147
+ return 'god_access';
148
+ }
149
+ /**
150
+ * Get the string representing advanced settings permission type
151
+ * @returns {string} The advanced settings permission type
152
+ */
153
+ static get advanced_settings() {
154
+ return 'advanced_settings';
155
+ }
156
+ /**
157
+ * Get the string representing user access permission type
158
+ * @returns {string} The user access permission type
159
+ */
160
+ static get user_access() {
161
+ return 'user_access';
162
+ }
163
+ /**
164
+ * Get the string representing upload file access permission type
165
+ * @returns {string} The upload file access permission type
166
+ */
167
+ static get upload_file_access() {
168
+ return 'upload_file_access';
169
+ }
170
+ /**
171
+ * Get the string representing remove file access permission type
172
+ * @returns {string} The remove file access permission type
173
+ */
174
+ static get remove_file_access() {
175
+ return 'remove_file_access';
176
+ }
177
+ }
178
+ exports.PermissionTypes = PermissionTypes;
@@ -0,0 +1,92 @@
1
+ import { DatabaseOperation } from './database_trigger';
2
+ /**
3
+ * Interface defining a database trigger
4
+ * @interface Trigger
5
+ * @property {DatabaseOperation} operation - The database operation that triggers this callback
6
+ * @property {string} database - The database name to monitor
7
+ * @property {string} collection - The collection name to monitor
8
+ * @property {(data: any) => void} callback - Function to execute when trigger conditions are met
9
+ * @example
10
+ * ```typescript
11
+ * const trigger: Trigger = {
12
+ * operation: 'insert',
13
+ * database: 'myDB',
14
+ * collection: 'users',
15
+ * callback: (data) => {
16
+ * console.log('New user inserted:', data);
17
+ * }
18
+ * };
19
+ * ```
20
+ */
21
+ interface Trigger {
22
+ operation: DatabaseOperation;
23
+ database: string;
24
+ collection: string;
25
+ callback: (data: any) => void;
26
+ }
27
+ /**
28
+ * Singleton class for managing database triggers
29
+ * Provides functionality to add and execute triggers based on database operations
30
+ * @class TriggerOperator
31
+ * @example
32
+ * ```typescript
33
+ * // Add a trigger for user insertions
34
+ * TriggerOperator.instance.addTrigger({
35
+ * operation: 'insert',
36
+ * database: 'myDB',
37
+ * collection: 'users',
38
+ * callback: (data) => {
39
+ * console.log('New user inserted:', data);
40
+ * }
41
+ * });
42
+ * ```
43
+ */
44
+ declare class TriggerOperator {
45
+ private triggers;
46
+ private static _instance;
47
+ private constructor();
48
+ /**
49
+ * Gets the singleton instance of TriggerOperator
50
+ * @static
51
+ * @returns {TriggerOperator} The singleton instance
52
+ */
53
+ static get instance(): TriggerOperator;
54
+ /**
55
+ * Adds a new trigger to the registry
56
+ * @param {Trigger} trigger - The trigger configuration to add
57
+ * @throws {Error} If trigger is invalid or already exists
58
+ * @example
59
+ * ```typescript
60
+ * // Add a trigger for document updates
61
+ * TriggerOperator.instance.addTrigger({
62
+ * operation: 'update',
63
+ * database: 'myDB',
64
+ * collection: 'documents',
65
+ * callback: (data) => {
66
+ * console.log('Document updated:', data);
67
+ * }
68
+ * });
69
+ * ```
70
+ */
71
+ addTrigger(trigger: Trigger): void;
72
+ /**
73
+ * Executes all matching triggers for a given database operation
74
+ * @param {DatabaseOperation} operation - The database operation that occurred
75
+ * @param {string} database - The database where the operation occurred
76
+ * @param {string} collection - The collection where the operation occurred
77
+ * @param {any} data - The data associated with the operation
78
+ * @example
79
+ * ```typescript
80
+ * // This would typically be called by the database layer
81
+ * TriggerOperator.instance.call(
82
+ * 'insert',
83
+ * 'myDB',
84
+ * 'users',
85
+ * { id: 1, name: 'John' }
86
+ * );
87
+ * ```
88
+ */
89
+ call(operation: DatabaseOperation, database: string, collection: string, data: any): void;
90
+ }
91
+ declare const _default: TriggerOperator;
92
+ export = _default;
@@ -0,0 +1,99 @@
1
+ "use strict";
2
+ /**
3
+ * Singleton class for managing database triggers
4
+ * Provides functionality to add and execute triggers based on database operations
5
+ * @class TriggerOperator
6
+ * @example
7
+ * ```typescript
8
+ * // Add a trigger for user insertions
9
+ * TriggerOperator.instance.addTrigger({
10
+ * operation: 'insert',
11
+ * database: 'myDB',
12
+ * collection: 'users',
13
+ * callback: (data) => {
14
+ * console.log('New user inserted:', data);
15
+ * }
16
+ * });
17
+ * ```
18
+ */
19
+ class TriggerOperator {
20
+ constructor() {
21
+ this.triggers = [];
22
+ }
23
+ /**
24
+ * Gets the singleton instance of TriggerOperator
25
+ * @static
26
+ * @returns {TriggerOperator} The singleton instance
27
+ */
28
+ static get instance() {
29
+ if (!TriggerOperator._instance) {
30
+ TriggerOperator._instance = new TriggerOperator();
31
+ }
32
+ return TriggerOperator._instance;
33
+ }
34
+ /**
35
+ * Adds a new trigger to the registry
36
+ * @param {Trigger} trigger - The trigger configuration to add
37
+ * @throws {Error} If trigger is invalid or already exists
38
+ * @example
39
+ * ```typescript
40
+ * // Add a trigger for document updates
41
+ * TriggerOperator.instance.addTrigger({
42
+ * operation: 'update',
43
+ * database: 'myDB',
44
+ * collection: 'documents',
45
+ * callback: (data) => {
46
+ * console.log('Document updated:', data);
47
+ * }
48
+ * });
49
+ * ```
50
+ */
51
+ addTrigger(trigger) {
52
+ // Validate trigger
53
+ if (!trigger.operation || !trigger.database || !trigger.collection || !trigger.callback) {
54
+ throw new Error('Invalid trigger configuration');
55
+ }
56
+ // Check for duplicate triggers
57
+ const exists = this.triggers.some(t => t.operation === trigger.operation &&
58
+ t.database === trigger.database &&
59
+ t.collection === trigger.collection);
60
+ if (exists) {
61
+ throw new Error(`Trigger already exists for operation ${trigger.operation} on ${trigger.database}.${trigger.collection}`);
62
+ }
63
+ this.triggers.push(trigger);
64
+ }
65
+ /**
66
+ * Executes all matching triggers for a given database operation
67
+ * @param {DatabaseOperation} operation - The database operation that occurred
68
+ * @param {string} database - The database where the operation occurred
69
+ * @param {string} collection - The collection where the operation occurred
70
+ * @param {any} data - The data associated with the operation
71
+ * @example
72
+ * ```typescript
73
+ * // This would typically be called by the database layer
74
+ * TriggerOperator.instance.call(
75
+ * 'insert',
76
+ * 'myDB',
77
+ * 'users',
78
+ * { id: 1, name: 'John' }
79
+ * );
80
+ * ```
81
+ */
82
+ call(operation, database, collection, data) {
83
+ this.triggers.forEach(trigger => {
84
+ if (operation === trigger.operation &&
85
+ database === trigger.database &&
86
+ collection === trigger.collection &&
87
+ trigger.callback) {
88
+ try {
89
+ trigger.callback(data);
90
+ }
91
+ catch (error) {
92
+ console.error(`Error executing trigger for ${operation} on ${database}.${collection}:`, error);
93
+ }
94
+ }
95
+ });
96
+ }
97
+ }
98
+ TriggerOperator._instance = null;
99
+ module.exports = TriggerOperator.instance;
@@ -0,0 +1,81 @@
1
+ import { PermissionGroup } from './security';
2
+ import { Model } from 'mongoose';
3
+ /**
4
+ * User detail interface
5
+ */
6
+ interface UserDetail {
7
+ permissionGroup?: string | PermissionGroup;
8
+ phone?: string;
9
+ email?: string;
10
+ password?: string;
11
+ fullname?: string;
12
+ type?: string;
13
+ [key: string]: any;
14
+ }
15
+ /**
16
+ * User class representing a user in the system
17
+ *
18
+ * @public
19
+ */
20
+ export declare class User {
21
+ id: string;
22
+ permissionGroup: string;
23
+ phone: string;
24
+ email: string;
25
+ password: string;
26
+ type: string;
27
+ dbModel: any;
28
+ /**
29
+ * Create a user
30
+ * @param id - User ID
31
+ * @param permissionGroup - Permission group name
32
+ * @param phone - User phone
33
+ * @param email - User email
34
+ * @param password - User password
35
+ * @param type - User type
36
+ * @param model - Database model
37
+ *
38
+ * @hidden
39
+ */
40
+ constructor(id: string, permissionGroup: string, phone: string, email: string, password: string, type: 'user' | 'anonymous', model: any);
41
+ /**
42
+ * Get brief user information
43
+ * @returns Brief user info object
44
+ */
45
+ getBrief(): UserDetail;
46
+ /**
47
+ * Update user details
48
+ * @param detail - Object containing user details to update
49
+ */
50
+ setNewDetail(detail: UserDetail): void;
51
+ /**
52
+ * Check if user has a specific permission
53
+ * @param accessType - Permission to check
54
+ * @returns True if user has permission, false otherwise
55
+ */
56
+ hasPermission(accessType: string): boolean;
57
+ /**
58
+ * Save user to database
59
+ */
60
+ save(): Promise<void>;
61
+ /**
62
+ * Load user from database model
63
+ * @param model - Database model
64
+ * @returns Promise resolving to User instance
65
+ */
66
+ static loadFromModel(model: any): Promise<User>;
67
+ /**
68
+ * Create user from model and details
69
+ * @param model - Mongoose model
70
+ * @param detail - User details
71
+ * @returns Promise resolving to User instance
72
+ */
73
+ static createFromModel(model: Model<any>, detail: UserDetail): Promise<User>;
74
+ /**
75
+ * Create error for invalid user
76
+ * @param object - Invalid user object
77
+ * @returns Error message
78
+ */
79
+ static notValid(object: any): string;
80
+ }
81
+ export default User;