@flusys/nestjs-shared 3.0.0 → 4.0.0-lts

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 (103) hide show
  1. package/README.md +160 -80
  2. package/cjs/classes/api-controller.class.js +26 -8
  3. package/cjs/classes/api-service.class.js +100 -17
  4. package/cjs/classes/winston-logger-adapter.class.js +15 -20
  5. package/cjs/classes/winston.logger.class.js +103 -70
  6. package/cjs/constants/index.js +1 -0
  7. package/cjs/constants/message-keys.js +80 -0
  8. package/cjs/constants/permissions.js +65 -11
  9. package/cjs/decorators/index.js +1 -0
  10. package/cjs/decorators/log-action.decorator.js +149 -0
  11. package/cjs/dtos/response-payload.dto.js +72 -0
  12. package/cjs/enums/index.js +20 -0
  13. package/cjs/enums/notification-type.enum.js +17 -0
  14. package/cjs/enums/participant-status.enum.js +17 -0
  15. package/cjs/enums/recurrence-type.enum.js +18 -0
  16. package/cjs/exceptions/base-app.exception.js +145 -0
  17. package/cjs/exceptions/index.js +1 -0
  18. package/cjs/exceptions/permission.exception.js +12 -8
  19. package/cjs/filters/global-exception.filter.js +167 -0
  20. package/cjs/filters/index.js +18 -0
  21. package/cjs/guards/jwt-auth.guard.js +4 -1
  22. package/cjs/guards/permission.guard.js +6 -13
  23. package/cjs/index.js +2 -0
  24. package/cjs/interceptors/idempotency.interceptor.js +1 -1
  25. package/cjs/interceptors/index.js +0 -1
  26. package/cjs/interfaces/event-manager-adapter.interface.js +11 -0
  27. package/cjs/interfaces/index.js +2 -0
  28. package/cjs/interfaces/logger.interface.js +1 -4
  29. package/cjs/interfaces/notification-adapter.interface.js +11 -0
  30. package/cjs/middlewares/logger.middleware.js +83 -26
  31. package/cjs/modules/datasource/multi-tenant-datasource.service.js +33 -11
  32. package/cjs/modules/utils/utils.service.js +4 -20
  33. package/cjs/utils/index.js +0 -1
  34. package/cjs/utils/query-helpers.util.js +8 -1
  35. package/classes/api-controller.class.d.ts +1 -0
  36. package/classes/api-service.class.d.ts +5 -10
  37. package/classes/winston-logger-adapter.class.d.ts +12 -11
  38. package/classes/winston.logger.class.d.ts +1 -0
  39. package/constants/index.d.ts +1 -0
  40. package/constants/message-keys.d.ts +81 -0
  41. package/constants/permissions.d.ts +72 -0
  42. package/decorators/index.d.ts +1 -0
  43. package/decorators/log-action.decorator.d.ts +8 -0
  44. package/dtos/response-payload.dto.d.ts +8 -0
  45. package/enums/index.d.ts +3 -0
  46. package/enums/notification-type.enum.d.ts +6 -0
  47. package/enums/participant-status.enum.d.ts +6 -0
  48. package/enums/recurrence-type.enum.d.ts +7 -0
  49. package/exceptions/base-app.exception.d.ts +41 -0
  50. package/exceptions/index.d.ts +1 -0
  51. package/exceptions/permission.exception.d.ts +1 -1
  52. package/fesm/classes/api-controller.class.js +26 -8
  53. package/fesm/classes/api-service.class.js +101 -18
  54. package/fesm/classes/winston-logger-adapter.class.js +18 -44
  55. package/fesm/classes/winston.logger.class.js +100 -68
  56. package/fesm/constants/index.js +2 -0
  57. package/fesm/constants/message-keys.js +59 -0
  58. package/fesm/constants/permissions.js +51 -14
  59. package/fesm/decorators/index.js +1 -0
  60. package/fesm/decorators/log-action.decorator.js +139 -0
  61. package/fesm/dtos/response-payload.dto.js +72 -0
  62. package/fesm/enums/index.js +3 -0
  63. package/fesm/enums/notification-type.enum.js +7 -0
  64. package/fesm/enums/participant-status.enum.js +7 -0
  65. package/fesm/enums/recurrence-type.enum.js +8 -0
  66. package/fesm/exceptions/base-app.exception.js +109 -0
  67. package/fesm/exceptions/index.js +1 -0
  68. package/fesm/exceptions/permission.exception.js +15 -17
  69. package/fesm/filters/global-exception.filter.js +157 -0
  70. package/fesm/filters/index.js +1 -0
  71. package/fesm/guards/jwt-auth.guard.js +5 -2
  72. package/fesm/guards/permission.guard.js +8 -15
  73. package/fesm/index.js +2 -0
  74. package/fesm/interceptors/idempotency.interceptor.js +2 -2
  75. package/fesm/interceptors/index.js +0 -1
  76. package/fesm/interfaces/event-manager-adapter.interface.js +1 -0
  77. package/fesm/interfaces/index.js +2 -0
  78. package/fesm/interfaces/logger.interface.js +1 -4
  79. package/fesm/interfaces/notification-adapter.interface.js +1 -0
  80. package/fesm/middlewares/logger.middleware.js +83 -26
  81. package/fesm/modules/datasource/multi-tenant-datasource.service.js +34 -12
  82. package/fesm/modules/utils/utils.service.js +5 -21
  83. package/fesm/utils/index.js +0 -1
  84. package/fesm/utils/query-helpers.util.js +8 -1
  85. package/filters/global-exception.filter.d.ts +10 -0
  86. package/filters/index.d.ts +1 -0
  87. package/guards/permission.guard.d.ts +1 -3
  88. package/index.d.ts +2 -0
  89. package/interceptors/index.d.ts +0 -1
  90. package/interfaces/event-manager-adapter.interface.d.ts +43 -0
  91. package/interfaces/index.d.ts +2 -0
  92. package/interfaces/logger.interface.d.ts +5 -5
  93. package/interfaces/notification-adapter.interface.d.ts +22 -0
  94. package/modules/datasource/multi-tenant-datasource.service.d.ts +1 -2
  95. package/modules/utils/utils.service.d.ts +0 -1
  96. package/package.json +10 -3
  97. package/utils/index.d.ts +0 -1
  98. package/cjs/interceptors/query-performance.interceptor.js +0 -66
  99. package/cjs/utils/error-handler.util.js +0 -90
  100. package/fesm/interceptors/query-performance.interceptor.js +0 -56
  101. package/fesm/utils/error-handler.util.js +0 -82
  102. package/interceptors/query-performance.interceptor.d.ts +0 -8
  103. package/utils/error-handler.util.d.ts +0 -19
@@ -2,9 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- Object.defineProperty(exports, "instance", {
6
- enumerable: true,
7
- get: function() {
5
+ function _export(target, all) {
6
+ for(var name in all)Object.defineProperty(target, name, {
7
+ enumerable: true,
8
+ get: Object.getOwnPropertyDescriptor(all, name).get
9
+ });
10
+ }
11
+ _export(exports, {
12
+ get createModuleLogger () {
13
+ return createModuleLogger;
14
+ },
15
+ get instance () {
8
16
  return instance;
9
17
  }
10
18
  });
@@ -12,8 +20,8 @@ const _config = require("@flusys/nestjs-core/config");
12
20
  const _fs = require("fs");
13
21
  const _path = require("path");
14
22
  const _winston = require("winston");
15
- const _winstontransport = /*#__PURE__*/ _interop_require_wildcard(require("winston-transport"));
16
23
  const _winstondailyrotatefile = /*#__PURE__*/ _interop_require_wildcard(require("winston-daily-rotate-file"));
24
+ const _winstontransport = /*#__PURE__*/ _interop_require_wildcard(require("winston-transport"));
17
25
  function _define_property(obj, key, value) {
18
26
  if (key in obj) {
19
27
  Object.defineProperty(obj, key, {
@@ -85,33 +93,48 @@ if (!(0, _fs.existsSync)(LOG_DIR)) {
85
93
  }
86
94
  // Custom Formats
87
95
  /**
88
- * Custom format for structured logging
89
- * Includes: timestamp, level, context, requestId, userId, message, metadata
90
- */ const structuredFormat = _winston.format.printf(({ timestamp, level, message, context, requestId, userId, stack, ...metadata })=>{
91
- const logEntry = {
92
- timestamp,
93
- level: level.toUpperCase(),
94
- context: context || 'App',
95
- message
96
- };
97
- if (requestId) logEntry.requestId = requestId;
98
- if (userId) logEntry.userId = userId;
99
- if (Object.keys(metadata).length > 0) logEntry.metadata = metadata;
100
- if (stack) logEntry.stack = stack;
101
- return JSON.stringify(logEntry);
102
- });
103
- /**
104
- * Custom format for development console output
105
- * Human-readable format with colors
106
- */ const devConsoleFormat = _winston.format.printf(({ timestamp, level, message, context, requestId, userId, method, url, path, statusCode, duration, stack })=>{
107
- const ctx = context || 'App';
108
- const reqId = requestId ? ` [${requestId}]` : '';
109
- const user = userId ? ` (user:${userId})` : '';
110
- const endpoint = method && (path || url) ? ` [${method} ${path || url}]` : '';
111
- const status = statusCode ? ` [${statusCode}]` : '';
112
- const time = duration ? ` (${duration})` : '';
113
- const stackTrace = stack ? `\n${stack}` : '';
114
- return `${timestamp} [${level.toUpperCase().padEnd(7)}] [${ctx}]${endpoint}${status}${time}${reqId}${user} ${message}${stackTrace}`;
96
+ * Custom format for structured logging (production)
97
+ * Multi-line format:
98
+ * - Line 1: Timestamp
99
+ * - Line 2: Log Level
100
+ * - Line 3: [RequestId]
101
+ * - Line 4: Empty
102
+ * - Line 5+: Message with context
103
+ */ const LEVEL_MAP = {
104
+ error: 'Error',
105
+ warn: 'Warning',
106
+ info: 'Information',
107
+ debug: 'Debug',
108
+ verbose: 'Verbose'
109
+ };
110
+ const LOG_SEPARATOR = '─'.repeat(80);
111
+ const structuredFormat = _winston.format.printf(({ timestamp, level, message, context, requestId, userId, tenantId, companyId, method, url, path, statusCode, duration, stack, ...metadata })=>{
112
+ const reqId = requestId || 'no-request-id';
113
+ const levelFormatted = LEVEL_MAP[level] || level.charAt(0).toUpperCase() + level.slice(1);
114
+ const contextParts = [];
115
+ if (context) contextParts.push(`Context: ${context}`);
116
+ if (method && (path || url)) contextParts.push(`Endpoint: ${method} ${path || url}`);
117
+ if (statusCode) contextParts.push(`Status: ${statusCode}`);
118
+ if (duration) contextParts.push(`Duration: ${duration}`);
119
+ if (userId) contextParts.push(`UserId: ${userId}`);
120
+ if (tenantId) contextParts.push(`TenantId: ${tenantId}`);
121
+ if (companyId) contextParts.push(`CompanyId: ${companyId}`);
122
+ let content = message;
123
+ if (contextParts.length > 0) {
124
+ content = `${contextParts.join(' | ')}\n${message}`;
125
+ }
126
+ const metaKeys = Object.keys(metadata).filter((k)=>k !== 'splat');
127
+ if (metaKeys.length > 0) {
128
+ const metaStr = JSON.stringify(metaKeys.reduce((acc, k)=>({
129
+ ...acc,
130
+ [k]: metadata[k]
131
+ }), {}));
132
+ content += `\nMetadata: ${metaStr}`;
133
+ }
134
+ if (stack) {
135
+ content += `\nStack: ${stack}`;
136
+ }
137
+ return `${LOG_SEPARATOR}\n${timestamp} | ${levelFormatted} | [${reqId}]\n${content}`;
115
138
  });
116
139
  // Transports
117
140
  /**
@@ -134,63 +157,44 @@ if (!(0, _fs.existsSync)(LOG_DIR)) {
134
157
  maxFiles: LOG_MAX_FILES,
135
158
  level: 'error'
136
159
  });
137
- // Tenant-Aware Transport
138
- /**
139
- * Cache for tenant-specific transports
140
- * Avoids creating new transport instances for each log entry
141
- */ const tenantTransportCache = new Map();
142
- /**
143
- * Get or create a tenant-specific transport
144
- * Creates logs in: logs/{tenantId}/combined-YYYY-MM-DD.log
145
- */ function getTenantTransport(tenantId) {
146
- if (tenantTransportCache.has(tenantId)) {
147
- return tenantTransportCache.get(tenantId);
148
- }
149
- const tenantLogDir = (0, _path.join)(LOG_DIR, tenantId);
150
- if (!(0, _fs.existsSync)(tenantLogDir)) {
151
- (0, _fs.mkdirSync)(tenantLogDir, {
160
+ // Transport Caches
161
+ const moduleTransportCache = new Map();
162
+ const tenantTransportCache = new Map();
163
+ function getCachedTransport(cache, name) {
164
+ const cached = cache.get(name);
165
+ if (cached) return cached;
166
+ const logDir = (0, _path.join)(LOG_DIR, name);
167
+ if (!(0, _fs.existsSync)(logDir)) {
168
+ (0, _fs.mkdirSync)(logDir, {
152
169
  recursive: true
153
170
  });
154
171
  }
155
172
  const transport = new DailyRotateFile({
156
- filename: `${tenantLogDir}/combined-%DATE%.log`,
173
+ filename: `${logDir}/combined-%DATE%.log`,
157
174
  datePattern: 'YYYY-MM-DD',
158
175
  zippedArchive: true,
159
176
  maxSize: LOG_MAX_SIZE,
160
177
  maxFiles: LOG_MAX_FILES,
161
178
  level: LOG_LEVEL
162
179
  });
163
- tenantTransportCache.set(tenantId, transport);
180
+ cache.set(name, transport);
164
181
  return transport;
165
182
  }
166
- /**
167
- * Tenant-aware transport wrapper
168
- * Routes logs to tenant-specific folders when tenantId is present
169
- */ let TenantAwareTransport = class TenantAwareTransport extends Transport {
183
+ const getModuleTransport = (name)=>getCachedTransport(moduleTransportCache, name);
184
+ const getTenantTransport = (name)=>getCachedTransport(tenantTransportCache, name);
185
+ let TenantAwareTransport = class TenantAwareTransport extends Transport {
170
186
  log(info, callback) {
171
187
  setImmediate(()=>this.emit('logged', info));
172
188
  const tenantId = info.tenantId || info.metadata?.tenantId;
173
- if (USE_TENANT_MODE && tenantId) {
174
- // Write to tenant-specific folder
175
- const tenantTransport = getTenantTransport(tenantId);
176
- tenantTransport.log(info, callback);
177
- } else {
178
- // Write to default log folder
179
- this.defaultTransport.log(info, callback);
180
- }
189
+ const transport = USE_TENANT_MODE && tenantId ? getTenantTransport(tenantId) : this.defaultTransport;
190
+ transport.log(info, callback);
181
191
  }
182
192
  constructor(defaultTransport){
183
- super(), _define_property(this, "defaultTransport", void 0);
184
- this.defaultTransport = defaultTransport;
193
+ super(), _define_property(this, "defaultTransport", void 0), this.defaultTransport = defaultTransport;
185
194
  }
186
195
  };
187
- /**
188
- * Tenant-aware combined transport
189
- * When USE_TENANT_MODE=true, routes to tenant folders (like database mode)
190
- */ const tenantAwareCombinedTransport = new TenantAwareTransport(combinedRotateTransport);
191
- /**
192
- * Console transport for development
193
- */ const consoleTransport = new _winston.transports.Console({
196
+ const tenantAwareCombinedTransport = new TenantAwareTransport(combinedRotateTransport);
197
+ const consoleTransport = new _winston.transports.Console({
194
198
  level: LOG_LEVEL,
195
199
  format: _winston.format.combine(_winston.format.colorize({
196
200
  all: true
@@ -198,7 +202,7 @@ if (!(0, _fs.existsSync)(LOG_DIR)) {
198
202
  format: 'YYYY-MM-DD HH:mm:ss'
199
203
  }), _winston.format.errors({
200
204
  stack: true
201
- }), devConsoleFormat)
205
+ }), structuredFormat)
202
206
  });
203
207
  // Logger Instances
204
208
  /**
@@ -239,3 +243,32 @@ if (!(0, _fs.existsSync)(LOG_DIR)) {
239
243
  exitOnError: false
240
244
  });
241
245
  const instance = _config.envConfig.isProduction() ? prodLogger : devLogger;
246
+ /**
247
+ * Module logger cache to avoid creating multiple loggers for the same module
248
+ */ const moduleLoggerCache = new Map();
249
+ function createModuleLogger(moduleName) {
250
+ // In dev mode, use global console logger
251
+ if (!_config.envConfig.isProduction()) {
252
+ return devLogger;
253
+ }
254
+ // Check cache first
255
+ if (moduleLoggerCache.has(moduleName)) {
256
+ return moduleLoggerCache.get(moduleName);
257
+ }
258
+ // Create module-specific logger for production
259
+ const moduleLogger = (0, _winston.createLogger)({
260
+ level: LOG_LEVEL,
261
+ format: _winston.format.combine(_winston.format.timestamp({
262
+ format: 'YYYY-MM-DD HH:mm:ss.SSS'
263
+ }), _winston.format.errors({
264
+ stack: true
265
+ }), structuredFormat),
266
+ transports: [
267
+ getModuleTransport(moduleName),
268
+ errorRotateTransport
269
+ ],
270
+ exitOnError: false
271
+ });
272
+ moduleLoggerCache.set(moduleName, moduleLogger);
273
+ return moduleLogger;
274
+ }
@@ -42,6 +42,7 @@ _export(exports, {
42
42
  }
43
43
  });
44
44
  _export_star(require("./permissions"), exports);
45
+ _export_star(require("./message-keys"), exports);
45
46
  function _export_star(from, to) {
46
47
  Object.keys(from).forEach(function(k) {
47
48
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) {
@@ -0,0 +1,80 @@
1
+ // ==================== SHARED/SYSTEM MESSAGE KEYS ====================
2
+ // Package-specific messages are now in their respective packages:
3
+ // - nestjs-auth/src/config/message-keys.ts
4
+ // - nestjs-iam/src/config/message-keys.ts
5
+ // - nestjs-storage/src/config/message-keys.ts
6
+ // - nestjs-email/src/config/message-keys.ts
7
+ // - nestjs-form-builder/src/config/message-keys.ts
8
+ // - nestjs-event-manager/src/config/message-keys.ts
9
+ // - nestjs-notification/src/config/message-keys.ts
10
+ // - nestjs-localization/src/config/message-keys.ts
11
+ // ==================== AUTH (Shared across guards/interceptors) ====================
12
+ // These are duplicated in nestjs-auth but needed here to avoid circular dependencies
13
+ "use strict";
14
+ Object.defineProperty(exports, "__esModule", {
15
+ value: true
16
+ });
17
+ function _export(target, all) {
18
+ for(var name in all)Object.defineProperty(target, name, {
19
+ enumerable: true,
20
+ get: Object.getOwnPropertyDescriptor(all, name).get
21
+ });
22
+ }
23
+ _export(exports, {
24
+ get AUTH_MESSAGES () {
25
+ return AUTH_MESSAGES;
26
+ },
27
+ get ERROR_MESSAGES () {
28
+ return ERROR_MESSAGES;
29
+ },
30
+ get MESSAGE_KEYS () {
31
+ return MESSAGE_KEYS;
32
+ },
33
+ get SYSTEM_MESSAGES () {
34
+ return SYSTEM_MESSAGES;
35
+ }
36
+ });
37
+ const AUTH_MESSAGES = {
38
+ TOKEN_REQUIRED: 'auth.token.required',
39
+ TOKEN_INVALID: 'auth.token.invalid',
40
+ TOKEN_EXPIRED: 'auth.token.expired',
41
+ COMPANY_NO_ACCESS: 'auth.company.no.access'
42
+ };
43
+ const ERROR_MESSAGES = {
44
+ NOT_FOUND: 'error.not.found',
45
+ VALIDATION: 'error.validation',
46
+ UNAUTHORIZED: 'error.unauthorized',
47
+ FORBIDDEN: 'error.forbidden',
48
+ CONFLICT: 'error.conflict',
49
+ INTERNAL: 'error.internal',
50
+ SERVICE_UNAVAILABLE: 'error.service.unavailable',
51
+ UNKNOWN: 'error.unknown',
52
+ HTTP: 'error.http',
53
+ GENERIC: 'error.generic',
54
+ PERMISSION_SYSTEM_UNAVAILABLE: 'error.permission.system.unavailable',
55
+ INSUFFICIENT_PERMISSIONS: 'error.insufficient.permissions',
56
+ INSUFFICIENT_PERMISSIONS_OR: 'error.insufficient.permissions.or',
57
+ NO_PERMISSIONS_FOUND: 'error.no.permissions.found'
58
+ };
59
+ const SYSTEM_MESSAGES = {
60
+ REPOSITORY_NOT_AVAILABLE: 'system.repository.not.available',
61
+ DATASOURCE_NOT_AVAILABLE: 'system.datasource.not.available',
62
+ DATABASE_CONFIG_NOT_AVAILABLE: 'system.database.config.not.available',
63
+ SERVICE_NOT_AVAILABLE: 'system.service.not.available',
64
+ CONFIG_REQUIRED: 'system.config.required',
65
+ INTERNAL_ERROR: 'system.internal.error',
66
+ NOT_FOUND: 'system.not.found',
67
+ DUPLICATE_REQUEST: 'system.duplicate.request',
68
+ INVALID_TENANT_ID: 'system.invalid.tenant.id',
69
+ TENANT_NOT_FOUND: 'system.tenant.not.found',
70
+ TENANT_HEADER_REQUIRED: 'system.tenant.header.required',
71
+ MISSING_PARAMETER: 'system.missing.parameter',
72
+ SDK_NOT_INSTALLED: 'system.sdk.not.installed',
73
+ PATH_TRAVERSAL_DETECTED: 'system.path.traversal.detected',
74
+ INVALID_FILE_KEY: 'system.invalid.file.key'
75
+ };
76
+ const MESSAGE_KEYS = {
77
+ AUTH: AUTH_MESSAGES,
78
+ ERROR: ERROR_MESSAGES,
79
+ SYSTEM: SYSTEM_MESSAGES
80
+ };
@@ -1,13 +1,4 @@
1
- /**
2
- * Centralized Permission Codes
3
- *
4
- * Single source of truth for all permission codes used across the application.
5
- * Use these constants instead of hardcoded strings to prevent typos and enable easy refactoring.
6
- *
7
- * Naming Convention: <entity>.<action>
8
- * - entity: The resource being accessed (e.g., user, role, company)
9
- * - action: The operation being performed (create, read, update, delete, assign)
10
- */ // ==================== AUTH MODULE ====================
1
+ // ==================== AUTH MODULE ====================
11
2
  "use strict";
12
3
  Object.defineProperty(exports, "__esModule", {
13
4
  value: true
@@ -37,6 +28,12 @@ _export(exports, {
37
28
  get EMAIL_TEMPLATE_PERMISSIONS () {
38
29
  return EMAIL_TEMPLATE_PERMISSIONS;
39
30
  },
31
+ get EVENT_PARTICIPANT_PERMISSIONS () {
32
+ return EVENT_PARTICIPANT_PERMISSIONS;
33
+ },
34
+ get EVENT_PERMISSIONS () {
35
+ return EVENT_PERMISSIONS;
36
+ },
40
37
  get FILE_PERMISSIONS () {
41
38
  return FILE_PERMISSIONS;
42
39
  },
@@ -49,6 +46,12 @@ _export(exports, {
49
46
  get FORM_RESULT_PERMISSIONS () {
50
47
  return FORM_RESULT_PERMISSIONS;
51
48
  },
49
+ get LANGUAGE_PERMISSIONS () {
50
+ return LANGUAGE_PERMISSIONS;
51
+ },
52
+ get NOTIFICATION_PERMISSIONS () {
53
+ return NOTIFICATION_PERMISSIONS;
54
+ },
52
55
  get PERMISSIONS () {
53
56
  return PERMISSIONS;
54
57
  },
@@ -61,6 +64,12 @@ _export(exports, {
61
64
  get STORAGE_CONFIG_PERMISSIONS () {
62
65
  return STORAGE_CONFIG_PERMISSIONS;
63
66
  },
67
+ get TRANSLATION_KEY_PERMISSIONS () {
68
+ return TRANSLATION_KEY_PERMISSIONS;
69
+ },
70
+ get TRANSLATION_PERMISSIONS () {
71
+ return TRANSLATION_PERMISSIONS;
72
+ },
64
73
  get USER_ACTION_PERMISSIONS () {
65
74
  return USER_ACTION_PERMISSIONS;
66
75
  },
@@ -159,6 +168,42 @@ const FORM_RESULT_PERMISSIONS = {
159
168
  UPDATE: 'form-result.update',
160
169
  DELETE: 'form-result.delete'
161
170
  };
171
+ const EVENT_PERMISSIONS = {
172
+ CREATE: 'event.create',
173
+ READ: 'event.read',
174
+ UPDATE: 'event.update',
175
+ DELETE: 'event.delete'
176
+ };
177
+ const EVENT_PARTICIPANT_PERMISSIONS = {
178
+ CREATE: 'event-participant.create',
179
+ READ: 'event-participant.read',
180
+ UPDATE: 'event-participant.update',
181
+ DELETE: 'event-participant.delete'
182
+ };
183
+ const NOTIFICATION_PERMISSIONS = {
184
+ CREATE: 'notification.create',
185
+ READ: 'notification.read',
186
+ UPDATE: 'notification.update',
187
+ DELETE: 'notification.delete'
188
+ };
189
+ const LANGUAGE_PERMISSIONS = {
190
+ CREATE: 'language.create',
191
+ READ: 'language.read',
192
+ UPDATE: 'language.update',
193
+ DELETE: 'language.delete'
194
+ };
195
+ const TRANSLATION_KEY_PERMISSIONS = {
196
+ CREATE: 'translation-key.create',
197
+ READ: 'translation-key.read',
198
+ UPDATE: 'translation-key.update',
199
+ DELETE: 'translation-key.delete'
200
+ };
201
+ const TRANSLATION_PERMISSIONS = {
202
+ CREATE: 'translation.create',
203
+ READ: 'translation.read',
204
+ UPDATE: 'translation.update',
205
+ DELETE: 'translation.delete'
206
+ };
162
207
  const PERMISSIONS = {
163
208
  // Auth
164
209
  USER: USER_PERMISSIONS,
@@ -180,5 +225,14 @@ const PERMISSIONS = {
180
225
  EMAIL_TEMPLATE: EMAIL_TEMPLATE_PERMISSIONS,
181
226
  // Form Builder
182
227
  FORM: FORM_PERMISSIONS,
183
- FORM_RESULT: FORM_RESULT_PERMISSIONS
228
+ FORM_RESULT: FORM_RESULT_PERMISSIONS,
229
+ // Event Manager
230
+ EVENT: EVENT_PERMISSIONS,
231
+ EVENT_PARTICIPANT: EVENT_PARTICIPANT_PERMISSIONS,
232
+ // Notification
233
+ NOTIFICATION: NOTIFICATION_PERMISSIONS,
234
+ // Localization
235
+ LANGUAGE: LANGUAGE_PERMISSIONS,
236
+ TRANSLATION_KEY: TRANSLATION_KEY_PERMISSIONS,
237
+ TRANSLATION: TRANSLATION_PERMISSIONS
184
238
  };
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  });
5
5
  _export_star(require("./api-response.decorator"), exports);
6
6
  _export_star(require("./current-user.decorator"), exports);
7
+ _export_star(require("./log-action.decorator"), exports);
7
8
  _export_star(require("./public.decorator"), exports);
8
9
  _export_star(require("./require-permission.decorator"), exports);
9
10
  _export_star(require("./sanitize-html.decorator"), exports);
@@ -0,0 +1,149 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ Object.defineProperty(exports, "LogAction", {
6
+ enumerable: true,
7
+ get: function() {
8
+ return LogAction;
9
+ }
10
+ });
11
+ const _common = require("@nestjs/common");
12
+ const _winstonloggerclass = require("../classes/winston.logger.class");
13
+ const _loggermiddleware = require("../middlewares/logger.middleware");
14
+ function createLoggerAdapter(className, moduleName) {
15
+ if (moduleName) {
16
+ const winstonLogger = (0, _winstonloggerclass.createModuleLogger)(moduleName);
17
+ return {
18
+ log: (level, message, meta)=>{
19
+ winstonLogger.log(level, message, {
20
+ context: className,
21
+ ...meta
22
+ });
23
+ },
24
+ error: (message, stack, meta)=>{
25
+ winstonLogger.error(message, {
26
+ context: className,
27
+ stack,
28
+ ...meta
29
+ });
30
+ }
31
+ };
32
+ }
33
+ const nestLogger = new _common.Logger(className);
34
+ return {
35
+ log: (level, message, meta)=>{
36
+ nestLogger[level](message, meta);
37
+ },
38
+ error: (message, stack, meta)=>{
39
+ nestLogger.error(message, stack, meta);
40
+ }
41
+ };
42
+ }
43
+ function LogAction(options = {}) {
44
+ return function(target, propertyKey, descriptor) {
45
+ const originalMethod = descriptor.value;
46
+ const className = target.constructor.name;
47
+ const methodName = String(propertyKey);
48
+ descriptor.value = async function(...args) {
49
+ const startTime = Date.now();
50
+ // Resolve module: decorator option > instance property > undefined
51
+ const moduleName = options.module || this.moduleName;
52
+ const logger = createLoggerAdapter(className, moduleName);
53
+ const action = options.action || `${this.entityName || className}.${methodName}`;
54
+ const logLevel = options.logLevel || 'debug';
55
+ const context = {
56
+ requestId: (0, _loggermiddleware.getRequestId)(),
57
+ userId: (0, _loggermiddleware.getUserId)(),
58
+ tenantId: (0, _loggermiddleware.getTenantId)(),
59
+ companyId: (0, _loggermiddleware.getCompanyId)(),
60
+ method: methodName,
61
+ module: moduleName
62
+ };
63
+ const startMessage = `Executing action method "${action}"`;
64
+ const startContext = options.includeParams ? {
65
+ ...context,
66
+ params: sanitizeParams(args)
67
+ } : context;
68
+ logger.log(logLevel, startMessage, startContext);
69
+ try {
70
+ const result = await originalMethod.apply(this, args);
71
+ const duration = Date.now() - startTime;
72
+ const resultType = getResultType(result);
73
+ const successMessage = `Executed action method "${action}", returned result "${resultType}" in ${duration.toFixed(2)}ms.`;
74
+ const successContext = options.includeResult && result ? {
75
+ ...context,
76
+ duration: `${duration}ms`,
77
+ resultType,
78
+ resultPreview: getResultPreview(result)
79
+ } : {
80
+ ...context,
81
+ duration: `${duration}ms`,
82
+ resultType
83
+ };
84
+ logger.log(logLevel, successMessage, successContext);
85
+ return result;
86
+ } catch (error) {
87
+ const duration = Date.now() - startTime;
88
+ const errorMessage = error instanceof Error ? error.message : 'Unknown error';
89
+ logger.error(`Failed action method "${action}" after ${duration.toFixed(2)}ms: ${errorMessage}`, error instanceof Error ? error.stack : undefined, {
90
+ ...context,
91
+ duration: `${duration}ms`,
92
+ error: errorMessage
93
+ });
94
+ throw error;
95
+ }
96
+ };
97
+ return descriptor;
98
+ };
99
+ }
100
+ function sanitizeParams(args) {
101
+ return args.map((arg)=>{
102
+ if (arg === null || arg === undefined) return arg;
103
+ if (typeof arg === 'object') {
104
+ const sanitized = {
105
+ ...arg
106
+ };
107
+ const sensitiveKeys = [
108
+ 'password',
109
+ 'secret',
110
+ 'token',
111
+ 'apiKey',
112
+ 'authorization'
113
+ ];
114
+ for (const key of Object.keys(sanitized)){
115
+ if (sensitiveKeys.some((sk)=>key.toLowerCase().includes(sk))) {
116
+ sanitized[key] = '[REDACTED]';
117
+ }
118
+ }
119
+ return sanitized;
120
+ }
121
+ return arg;
122
+ });
123
+ }
124
+ function getResultType(result) {
125
+ if (result === null) return 'null';
126
+ if (result === undefined) return 'undefined';
127
+ if (Array.isArray(result)) return `Array<${result.length} items>`;
128
+ if (typeof result === 'object') {
129
+ const name = result.constructor?.name;
130
+ return name && name !== 'Object' ? name : 'Object';
131
+ }
132
+ return typeof result;
133
+ }
134
+ function getResultPreview(result) {
135
+ if (Array.isArray(result)) {
136
+ return {
137
+ count: result.length,
138
+ sample: result.slice(0, 2)
139
+ };
140
+ }
141
+ if (typeof result === 'object' && result !== null) {
142
+ const keys = Object.keys(result).slice(0, 5);
143
+ return {
144
+ keys,
145
+ hasMore: Object.keys(result).length > 5
146
+ };
147
+ }
148
+ return result;
149
+ }