@zssz-soft/firebase-functions-shared 1.4.1 → 1.5.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.
package/lib/index.d.ts CHANGED
@@ -15,4 +15,5 @@ export * from './modules/booking';
15
15
  export * from './modules/events';
16
16
  export * from './modules/error-reporting';
17
17
  export * from './modules/health';
18
+ export * from './modules/audit';
18
19
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,cAAc,UAAU,CAAC;AACzB,cAAc,qBAAqB,CAAC;AACpC,cAAc,iBAAiB,CAAC;AAChC,cAAc,mBAAmB,CAAC;AAClC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,eAAe,CAAC;AAC9B,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,cAAc,2BAA2B,CAAC;AAC1C,cAAc,kBAAkB,CAAC;AACjC,cAAc,iBAAiB,CAAC"}
package/lib/index.js CHANGED
@@ -31,4 +31,5 @@ __exportStar(require("./modules/booking"), exports);
31
31
  __exportStar(require("./modules/events"), exports);
32
32
  __exportStar(require("./modules/error-reporting"), exports);
33
33
  __exportStar(require("./modules/health"), exports);
34
+ __exportStar(require("./modules/audit"), exports);
34
35
  //# sourceMappingURL=index.js.map
package/lib/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,iDAA+B;AAC/B,qDAAmC;AACnC,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,4DAA0C;AAC1C,mDAAiC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,sDAAoC;AACpC,kDAAgC;AAChC,oDAAkC;AAClC,iDAA+B;AAC/B,qDAAmC;AACnC,gDAA8B;AAC9B,oDAAkC;AAClC,mDAAiC;AACjC,4DAA0C;AAC1C,mDAAiC;AACjC,kDAAgC"}
@@ -0,0 +1,158 @@
1
+ /**
2
+ * Server-Side Audit Models
3
+ *
4
+ * Extends the core audit models with server-specific types and metadata.
5
+ * These models are used by Firebase Cloud Functions to track operations.
6
+ */
7
+ /**
8
+ * Server-specific audit metadata
9
+ * Extends the base AuditMetadata with Cloud Functions context
10
+ */
11
+ export interface ServerAuditMetadata {
12
+ /** Cloud Function name */
13
+ functionName: string;
14
+ /** Cloud Function execution ID */
15
+ executionId?: string;
16
+ /** Cloud Function region */
17
+ region?: string;
18
+ /** Function revision/version */
19
+ revision?: string;
20
+ /** Trigger type (http, firestore, pubsub, eventarc, etc.) */
21
+ triggerType?: 'http' | 'firestore' | 'pubsub' | 'eventarc' | 'scheduler' | 'storage' | 'auth';
22
+ /** Document path for Firestore triggers */
23
+ documentPath?: string;
24
+ /** Event type for event-driven triggers */
25
+ eventType?: string;
26
+ /** Request information (for HTTP triggers) */
27
+ request?: {
28
+ method?: string;
29
+ url?: string;
30
+ ip?: string;
31
+ userAgent?: string;
32
+ origin?: string;
33
+ };
34
+ /** Performance metrics */
35
+ performance?: {
36
+ /** Duration in milliseconds */
37
+ durationMs?: number;
38
+ /** Memory usage in MB */
39
+ memoryMb?: number;
40
+ };
41
+ /** Additional custom metadata */
42
+ [key: string]: unknown;
43
+ }
44
+ /**
45
+ * Server-side audit log entry
46
+ */
47
+ export interface ServerAuditLog {
48
+ /** Unique audit log ID (auto-generated) */
49
+ id?: string;
50
+ /** User ID who triggered the action (or 'system' for automated tasks) */
51
+ userId: string;
52
+ /** Action performed */
53
+ action: ServerAuditAction;
54
+ /** Resource affected by the action */
55
+ resource: ServerAuditResource;
56
+ /** Timestamp when action occurred (ISO string for Firestore) */
57
+ timestamp: string;
58
+ /** Server metadata */
59
+ metadata: ServerAuditMetadata;
60
+ /** Action result */
61
+ result: ServerAuditResult;
62
+ /** Additional context data */
63
+ context?: Record<string, unknown>;
64
+ }
65
+ /**
66
+ * Types of server-side actions that can be audited
67
+ */
68
+ export type ServerAuditAction = 'data.create' | 'data.read' | 'data.update' | 'data.delete' | 'data.batch_create' | 'data.batch_update' | 'data.batch_delete' | 'email.send' | 'email.send_batch' | 'email.template_render' | 'user.create' | 'user.update' | 'user.delete' | 'user.role_change' | 'user.password_reset' | 'auth.user_created' | 'auth.user_deleted' | 'auth.user_disabled' | 'auth.email_verified' | 'booking.created' | 'booking.updated' | 'booking.status_changed' | 'booking.cancelled' | 'booking.confirmed' | 'booking.completed' | 'workflow.transition' | 'workflow.state_change' | 'event.published' | 'event.received' | 'event.processed' | 'system.bootstrap' | 'system.cleanup' | 'system.migration' | 'system.backup' | 'security.permission_denied' | 'security.unauthorized_access' | 'security.rate_limited' | 'storage.upload' | 'storage.delete' | 'storage.thumbnail_generated' | string;
69
+ /**
70
+ * Resource types that can be audited on the server
71
+ */
72
+ export interface ServerAuditResource {
73
+ /** Type of resource (e.g., 'booking', 'user', 'apartment') */
74
+ type: string;
75
+ /** Resource identifier */
76
+ id?: string;
77
+ /** Firestore collection path */
78
+ collection?: string;
79
+ /** Parent resource if applicable */
80
+ parent?: {
81
+ type: string;
82
+ id: string;
83
+ };
84
+ /** Additional resource metadata */
85
+ metadata?: Record<string, unknown>;
86
+ }
87
+ /**
88
+ * Result of an audited action
89
+ */
90
+ export interface ServerAuditResult {
91
+ /** Whether the action was successful */
92
+ success: boolean;
93
+ /** Status code or error code */
94
+ code?: string | number;
95
+ /** Human-readable message */
96
+ message?: string;
97
+ /** Error details if action failed */
98
+ error?: {
99
+ type: string;
100
+ message: string;
101
+ stack?: string;
102
+ };
103
+ /** Changes made (for update actions) */
104
+ changes?: {
105
+ before?: unknown;
106
+ after?: unknown;
107
+ fields?: string[];
108
+ };
109
+ /** Additional result data */
110
+ data?: unknown;
111
+ }
112
+ /**
113
+ * Configuration for the audit service
114
+ */
115
+ export interface AuditConfig {
116
+ /** Firestore collection name for audit logs */
117
+ collection?: string;
118
+ /** Whether to enable audit logging (default: true) */
119
+ enabled?: boolean;
120
+ /** Default function name to use if not provided */
121
+ defaultFunctionName?: string;
122
+ /** Cloud Functions region */
123
+ region?: string;
124
+ /** Actions to skip (not audit) */
125
+ skipActions?: ServerAuditAction[];
126
+ /** Resource types to skip (not audit) */
127
+ skipResourceTypes?: string[];
128
+ /** Whether to include full error stack traces (default: false in production) */
129
+ includeStackTraces?: boolean;
130
+ }
131
+ /**
132
+ * Default audit configuration
133
+ */
134
+ export declare const DEFAULT_AUDIT_CONFIG: Required<AuditConfig>;
135
+ /**
136
+ * Options for creating an audit log entry
137
+ */
138
+ export interface AuditLogOptions {
139
+ /** User ID (defaults to 'system') */
140
+ userId?: string;
141
+ /** Action performed */
142
+ action: ServerAuditAction;
143
+ /** Resource being acted upon */
144
+ resource: ServerAuditResource;
145
+ /** Whether the action was successful */
146
+ success: boolean;
147
+ /** Optional result message */
148
+ message?: string;
149
+ /** Error if action failed */
150
+ error?: Error;
151
+ /** Changes made */
152
+ changes?: ServerAuditResult['changes'];
153
+ /** Additional context */
154
+ context?: Record<string, unknown>;
155
+ /** Performance timing */
156
+ durationMs?: number;
157
+ }
158
+ //# sourceMappingURL=audit.models.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.models.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/audit.models.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IAClC,0BAA0B;IAC1B,YAAY,EAAE,MAAM,CAAC;IAErB,kCAAkC;IAClC,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,4BAA4B;IAC5B,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,gCAAgC;IAChC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,6DAA6D;IAC7D,WAAW,CAAC,EAAE,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,UAAU,GAAG,WAAW,GAAG,SAAS,GAAG,MAAM,CAAC;IAE9F,2CAA2C;IAC3C,YAAY,CAAC,EAAE,MAAM,CAAC;IAEtB,2CAA2C;IAC3C,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,8CAA8C;IAC9C,OAAO,CAAC,EAAE;QACR,MAAM,CAAC,EAAE,MAAM,CAAC;QAChB,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,EAAE,CAAC,EAAE,MAAM,CAAC;QACZ,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,MAAM,CAAC,EAAE,MAAM,CAAC;KACjB,CAAC;IAEF,0BAA0B;IAC1B,WAAW,CAAC,EAAE;QACZ,+BAA+B;QAC/B,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,yBAAyB;QACzB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;IAEF,iCAAiC;IACjC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,2CAA2C;IAC3C,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ,yEAAyE;IACzE,MAAM,EAAE,M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,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB,uBAAuB;IACvB,MAAM,EAAE,iBAAiB,CAAC;IAE1B,gCAAgC;IAChC,QAAQ,EAAE,mBAAmB,CAAC;IAE9B,wCAAwC;IACxC,OAAO,EAAE,OAAO,CAAC;IAEjB,8BAA8B;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAC;IAEjB,6BAA6B;IAC7B,KAAK,CAAC,EAAE,KAAK,CAAC;IAEd,mBAAmB;IACnB,OAAO,CAAC,EAAE,iBAAiB,CAAC,SAAS,CAAC,CAAC;IAEvC,yBAAyB;IACzB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAElC,yBAAyB;IACzB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB"}
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ /**
3
+ * Server-Side Audit Models
4
+ *
5
+ * Extends the core audit models with server-specific types and metadata.
6
+ * These models are used by Firebase Cloud Functions to track operations.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.DEFAULT_AUDIT_CONFIG = void 0;
10
+ /**
11
+ * Default audit configuration
12
+ */
13
+ exports.DEFAULT_AUDIT_CONFIG = {
14
+ collection: 'audit_logs',
15
+ enabled: true,
16
+ defaultFunctionName: 'unknown',
17
+ region: 'europe-west1',
18
+ skipActions: [],
19
+ skipResourceTypes: [],
20
+ includeStackTraces: process.env.NODE_ENV !== 'production',
21
+ };
22
+ //# sourceMappingURL=audit.models.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.models.js","sourceRoot":"","sources":["../../../src/modules/audit/audit.models.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAiOH;;GAEG;AACU,QAAA,oBAAoB,GAA0B;IACzD,UAAU,EAAE,YAAY;IACxB,OAAO,EAAE,IAAI;IACb,mBAAmB,EAAE,SAAS;IAC9B,MAAM,EAAE,cAAc;IACtB,WAAW,EAAE,EAAE;IACf,iBAAiB,EAAE,EAAE;IACrB,kBAAkB,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;CAC1D,CAAC"}
@@ -0,0 +1,126 @@
1
+ /**
2
+ * Server-Side Audit Service
3
+ *
4
+ * Provides audit logging for Firebase Cloud Functions.
5
+ * Writes audit logs to Firestore with server-specific metadata.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * const auditor = new ServerAuditService({ functionName: 'onBookingCreated' });
10
+ *
11
+ * // Log a successful operation
12
+ * await auditor.logSuccess({
13
+ * action: 'booking.created',
14
+ * resource: { type: 'booking', id: bookingId },
15
+ * userId: userId,
16
+ * });
17
+ *
18
+ * // Log a failed operation
19
+ * await auditor.logFailure({
20
+ * action: 'email.send',
21
+ * resource: { type: 'email', id: emailId },
22
+ * error: new Error('SMTP connection failed'),
23
+ * });
24
+ * ```
25
+ */
26
+ import { ServerAuditMetadata, AuditConfig, AuditLogOptions } from './audit.models';
27
+ /**
28
+ * Server-side audit service for Cloud Functions
29
+ */
30
+ export declare class ServerAuditService {
31
+ private config;
32
+ private db;
33
+ private metadata;
34
+ constructor(options: {
35
+ functionName: string;
36
+ triggerType?: ServerAuditMetadata['triggerType'];
37
+ documentPath?: string;
38
+ eventType?: string;
39
+ config?: Partial<AuditConfig>;
40
+ });
41
+ /**
42
+ * Log a successful operation
43
+ */
44
+ logSuccess(options: Omit<AuditLogOptions, 'success'>): Promise<string | null>;
45
+ /**
46
+ * Log a failed operation
47
+ */
48
+ logFailure(options: Omit<AuditLogOptions, 'success'> & {
49
+ error: Error;
50
+ }): Promise<string | null>;
51
+ /**
52
+ * Log an audit entry
53
+ */
54
+ log(options: AuditLogOptions): Promise<string | null>;
55
+ /**
56
+ * Log with HTTP request context
57
+ */
58
+ withRequest(request: {
59
+ method?: string;
60
+ url?: string;
61
+ ip?: string;
62
+ userAgent?: string;
63
+ origin?: string;
64
+ }): ServerAuditService;
65
+ /**
66
+ * Add performance timing
67
+ */
68
+ withPerformance(performance: {
69
+ durationMs?: number;
70
+ memoryMb?: number;
71
+ }): ServerAuditService;
72
+ /**
73
+ * Create the audit log object
74
+ */
75
+ private createAuditLog;
76
+ }
77
+ /**
78
+ * Create an audit service for a specific function
79
+ *
80
+ * @param functionName - Name of the Cloud Function
81
+ * @param options - Additional options
82
+ * @returns ServerAuditService instance
83
+ */
84
+ export declare function createAuditService(functionName: string, options?: {
85
+ triggerType?: ServerAuditMetadata['triggerType'];
86
+ documentPath?: string;
87
+ eventType?: string;
88
+ config?: Partial<AuditConfig>;
89
+ }): ServerAuditService;
90
+ /**
91
+ * Wrap an async function with automatic audit logging
92
+ *
93
+ * @param functionName - Name of the Cloud Function
94
+ * @param action - The action being performed
95
+ * @param resource - The resource being acted upon
96
+ * @param fn - The async function to wrap
97
+ * @returns Wrapped function with automatic audit logging
98
+ */
99
+ export declare function withAuditLogging<T extends (...args: unknown[]) => Promise<unknown>>(functionName: string, action: AuditLogOptions['action'], resource: AuditLogOptions['resource'], fn: T, options?: {
100
+ userId?: string;
101
+ config?: Partial<AuditConfig>;
102
+ }): T;
103
+ /**
104
+ * Audit decorator for Firestore triggers
105
+ *
106
+ * Helper to create audit context from Firestore event data
107
+ */
108
+ export declare function createFirestoreAuditContext(event: {
109
+ params: Record<string, string>;
110
+ data?: {
111
+ before?: {
112
+ data(): Record<string, unknown> | undefined;
113
+ };
114
+ after?: {
115
+ data(): Record<string, unknown> | undefined;
116
+ };
117
+ data(): Record<string, unknown> | undefined;
118
+ };
119
+ }): {
120
+ documentPath: string;
121
+ changes?: {
122
+ before?: Record<string, unknown>;
123
+ after?: Record<string, unknown>;
124
+ };
125
+ };
126
+ //# sourceMappingURL=audit.service.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.service.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/audit.service.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAIH,OAAO,EAEL,mBAAmB,EACnB,WAAW,EACX,eAA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QACjC,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;KACjC,CAAC;CACH,CAkBA"}
@@ -0,0 +1,221 @@
1
+ "use strict";
2
+ /**
3
+ * Server-Side Audit Service
4
+ *
5
+ * Provides audit logging for Firebase Cloud Functions.
6
+ * Writes audit logs to Firestore with server-specific metadata.
7
+ *
8
+ * Usage:
9
+ * ```typescript
10
+ * const auditor = new ServerAuditService({ functionName: 'onBookingCreated' });
11
+ *
12
+ * // Log a successful operation
13
+ * await auditor.logSuccess({
14
+ * action: 'booking.created',
15
+ * resource: { type: 'booking', id: bookingId },
16
+ * userId: userId,
17
+ * });
18
+ *
19
+ * // Log a failed operation
20
+ * await auditor.logFailure({
21
+ * action: 'email.send',
22
+ * resource: { type: 'email', id: emailId },
23
+ * error: new Error('SMTP connection failed'),
24
+ * });
25
+ * ```
26
+ */
27
+ Object.defineProperty(exports, "__esModule", { value: true });
28
+ exports.ServerAuditService = void 0;
29
+ exports.createAuditService = createAuditService;
30
+ exports.withAuditLogging = withAuditLogging;
31
+ exports.createFirestoreAuditContext = createFirestoreAuditContext;
32
+ const firestore_1 = require("firebase-admin/firestore");
33
+ const firebase_functions_1 = require("firebase-functions");
34
+ const audit_models_1 = require("./audit.models");
35
+ /**
36
+ * Server-side audit service for Cloud Functions
37
+ */
38
+ class ServerAuditService {
39
+ constructor(options) {
40
+ this.config = Object.assign(Object.assign({}, audit_models_1.DEFAULT_AUDIT_CONFIG), options.config);
41
+ this.db = (0, firestore_1.getFirestore)();
42
+ // Build base metadata from Cloud Functions environment
43
+ this.metadata = {
44
+ functionName: options.functionName,
45
+ executionId: process.env.FUNCTION_SIGNATURE_TYPE
46
+ ? `${Date.now()}-${Math.random().toString(36).substr(2, 9)}`
47
+ : undefined,
48
+ region: this.config.region || process.env.FUNCTION_REGION,
49
+ revision: process.env.K_REVISION,
50
+ triggerType: options.triggerType,
51
+ documentPath: options.documentPath,
52
+ eventType: options.eventType,
53
+ };
54
+ }
55
+ /**
56
+ * Log a successful operation
57
+ */
58
+ async logSuccess(options) {
59
+ return this.log(Object.assign(Object.assign({}, options), { success: true }));
60
+ }
61
+ /**
62
+ * Log a failed operation
63
+ */
64
+ async logFailure(options) {
65
+ return this.log(Object.assign(Object.assign({}, options), { success: false }));
66
+ }
67
+ /**
68
+ * Log an audit entry
69
+ */
70
+ async log(options) {
71
+ if (!this.config.enabled) {
72
+ return null;
73
+ }
74
+ // Check if action or resource type should be skipped
75
+ if (this.config.skipActions.includes(options.action)) {
76
+ return null;
77
+ }
78
+ if (this.config.skipResourceTypes.includes(options.resource.type)) {
79
+ return null;
80
+ }
81
+ try {
82
+ const auditLog = this.createAuditLog(options);
83
+ const docRef = await this.db.collection(this.config.collection).add(Object.assign(Object.assign({}, auditLog), { createdAt: firestore_1.FieldValue.serverTimestamp() }));
84
+ firebase_functions_1.logger.debug(`[Audit] Logged ${options.action} for ${options.resource.type}`, {
85
+ auditId: docRef.id,
86
+ action: options.action,
87
+ resourceType: options.resource.type,
88
+ resourceId: options.resource.id,
89
+ success: options.success,
90
+ });
91
+ return docRef.id;
92
+ }
93
+ catch (error) {
94
+ // Don't let audit failures break the main operation
95
+ firebase_functions_1.logger.error('[Audit] Failed to write audit log', {
96
+ error: error instanceof Error ? error.message : String(error),
97
+ action: options.action,
98
+ resource: options.resource,
99
+ });
100
+ return null;
101
+ }
102
+ }
103
+ /**
104
+ * Log with HTTP request context
105
+ */
106
+ withRequest(request) {
107
+ this.metadata.request = request;
108
+ return this;
109
+ }
110
+ /**
111
+ * Add performance timing
112
+ */
113
+ withPerformance(performance) {
114
+ this.metadata.performance = performance;
115
+ return this;
116
+ }
117
+ /**
118
+ * Create the audit log object
119
+ */
120
+ createAuditLog(options) {
121
+ const now = new Date().toISOString();
122
+ const auditLog = {
123
+ userId: options.userId || 'system',
124
+ action: options.action,
125
+ resource: options.resource,
126
+ timestamp: now,
127
+ metadata: Object.assign(Object.assign({}, this.metadata), (options.durationMs && {
128
+ performance: Object.assign(Object.assign({}, this.metadata.performance), { durationMs: options.durationMs }),
129
+ })),
130
+ result: {
131
+ success: options.success,
132
+ message: options.message,
133
+ },
134
+ };
135
+ // Add error details if present
136
+ if (options.error) {
137
+ auditLog.result.error = Object.assign({ type: options.error.name || 'Error', message: options.error.message }, (this.config.includeStackTraces && { stack: options.error.stack }));
138
+ }
139
+ // Add changes if present
140
+ if (options.changes) {
141
+ auditLog.result.changes = options.changes;
142
+ }
143
+ // Add context if present
144
+ if (options.context) {
145
+ auditLog.context = options.context;
146
+ }
147
+ return auditLog;
148
+ }
149
+ }
150
+ exports.ServerAuditService = ServerAuditService;
151
+ /**
152
+ * Create an audit service for a specific function
153
+ *
154
+ * @param functionName - Name of the Cloud Function
155
+ * @param options - Additional options
156
+ * @returns ServerAuditService instance
157
+ */
158
+ function createAuditService(functionName, options) {
159
+ return new ServerAuditService(Object.assign({ functionName }, options));
160
+ }
161
+ /**
162
+ * Wrap an async function with automatic audit logging
163
+ *
164
+ * @param functionName - Name of the Cloud Function
165
+ * @param action - The action being performed
166
+ * @param resource - The resource being acted upon
167
+ * @param fn - The async function to wrap
168
+ * @returns Wrapped function with automatic audit logging
169
+ */
170
+ function withAuditLogging(functionName, action, resource, fn, options) {
171
+ const auditor = createAuditService(functionName, { config: options === null || options === void 0 ? void 0 : options.config });
172
+ return (async (...args) => {
173
+ const startTime = Date.now();
174
+ try {
175
+ const result = await fn(...args);
176
+ const durationMs = Date.now() - startTime;
177
+ await auditor.logSuccess({
178
+ action,
179
+ resource,
180
+ userId: options === null || options === void 0 ? void 0 : options.userId,
181
+ durationMs,
182
+ context: { resultType: typeof result },
183
+ });
184
+ return result;
185
+ }
186
+ catch (error) {
187
+ const durationMs = Date.now() - startTime;
188
+ await auditor.logFailure({
189
+ action,
190
+ resource,
191
+ userId: options === null || options === void 0 ? void 0 : options.userId,
192
+ error: error instanceof Error ? error : new Error(String(error)),
193
+ durationMs,
194
+ });
195
+ throw error;
196
+ }
197
+ });
198
+ }
199
+ /**
200
+ * Audit decorator for Firestore triggers
201
+ *
202
+ * Helper to create audit context from Firestore event data
203
+ */
204
+ function createFirestoreAuditContext(event) {
205
+ var _a, _b;
206
+ const pathParts = Object.entries(event.params)
207
+ .map(([key, value]) => `${key}/${value}`)
208
+ .join('/');
209
+ const context = {
210
+ documentPath: pathParts,
211
+ };
212
+ // Extract before/after for update events
213
+ if (((_a = event.data) === null || _a === void 0 ? void 0 : _a.before) && ((_b = event.data) === null || _b === void 0 ? void 0 : _b.after)) {
214
+ context.changes = {
215
+ before: event.data.before.data(),
216
+ after: event.data.after.data(),
217
+ };
218
+ }
219
+ return context;
220
+ }
221
+ //# sourceMappingURL=audit.service.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"audit.service.js","sourceRoot":"","sources":["../../../src/modules/audit/audit.service.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;;;AAqLH,gDAaC;AAWD,4CA0CC;AAOD,kEA+BC;AA3RD,wDAA+E;AAC/E,2DAA4C;AAC5C,iDAMwB;AAExB;;GAEG;AACH,MAAa,kBAAkB;IAK7B,YAAY,OAMX;QACC,IAAI,CAAC,MAAM,mCAAQ,mCAAoB,GAAK,OAAO,CAAC,MAAM,CAAE,CAAC;QAC7D,IAAI,CAAC,EAAE,GAAG,IAAA,wBAAY,GAAE,CAAC;QAEzB,uDAAuD;QACvD,IAAI,CAAC,QAAQ,GAAG;YACd,YAAY,EAAE,OAAO,CAAC,YAAY;YAClC,WAAW,EAAE,OAAO,CAAC,GAAG,CAAC,uBAAuB;gBAC9C,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;gBAC5D,CAAC,CAAC,SAAS;YACb,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,OAAO,CAAC,G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,KAAK,EAAE,CAAC;SACxC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEb,MAAM,OAAO,GAAmD;QAC9D,YAAY,EAAE,SAAS;KACxB,CAAC;IAEF,yCAAyC;IACzC,IAAI,CAAA,MAAA,KAAK,CAAC,IAAI,0CAAE,MAAM,MAAI,MAAA,KAAK,CAAC,IAAI,0CAAE,KAAK,CAAA,EAAE,CAAC;QAC5C,OAAO,CAAC,OAAO,GAAG;YAChB,MAAM,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE;YAChC,KAAK,EAAE,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE;SAC/B,CAAC;IACJ,CAAC;IAED,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Server-Side Audit Module
3
+ *
4
+ * Provides audit logging capabilities for Firebase Cloud Functions.
5
+ * Tracks operations, errors, and user actions in Firestore.
6
+ *
7
+ * Usage:
8
+ * ```typescript
9
+ * import { createAuditService, withAuditLogging } from '@zssz-soft/firebase-functions-shared';
10
+ *
11
+ * // Create an audit service for a function
12
+ * const auditor = createAuditService('onBookingCreated', {
13
+ * triggerType: 'firestore',
14
+ * documentPath: 'booking/{bookingId}',
15
+ * });
16
+ *
17
+ * // Log operations
18
+ * await auditor.logSuccess({
19
+ * action: 'booking.created',
20
+ * resource: { type: 'booking', id: bookingId },
21
+ * userId: userId,
22
+ * });
23
+ *
24
+ * // Or use the wrapper for automatic logging
25
+ * const wrappedFn = withAuditLogging('processBooking', 'booking.created', { type: 'booking' }, myAsyncFn);
26
+ * ```
27
+ */
28
+ export * from './audit.models';
29
+ export * from './audit.service';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/modules/audit/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,cAAc,gBAAgB,CAAC;AAC/B,cAAc,iBAAiB,CAAC"}
@@ -0,0 +1,46 @@
1
+ "use strict";
2
+ /**
3
+ * Server-Side Audit Module
4
+ *
5
+ * Provides audit logging capabilities for Firebase Cloud Functions.
6
+ * Tracks operations, errors, and user actions in Firestore.
7
+ *
8
+ * Usage:
9
+ * ```typescript
10
+ * import { createAuditService, withAuditLogging } from '@zssz-soft/firebase-functions-shared';
11
+ *
12
+ * // Create an audit service for a function
13
+ * const auditor = createAuditService('onBookingCreated', {
14
+ * triggerType: 'firestore',
15
+ * documentPath: 'booking/{bookingId}',
16
+ * });
17
+ *
18
+ * // Log operations
19
+ * await auditor.logSuccess({
20
+ * action: 'booking.created',
21
+ * resource: { type: 'booking', id: bookingId },
22
+ * userId: userId,
23
+ * });
24
+ *
25
+ * // Or use the wrapper for automatic logging
26
+ * const wrappedFn = withAuditLogging('processBooking', 'booking.created', { type: 'booking' }, myAsyncFn);
27
+ * ```
28
+ */
29
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
30
+ if (k2 === undefined) k2 = k;
31
+ var desc = Object.getOwnPropertyDescriptor(m, k);
32
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
33
+ desc = { enumerable: true, get: function() { return m[k]; } };
34
+ }
35
+ Object.defineProperty(o, k2, desc);
36
+ }) : (function(o, m, k, k2) {
37
+ if (k2 === undefined) k2 = k;
38
+ o[k2] = m[k];
39
+ }));
40
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
41
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ __exportStar(require("./audit.models"), exports);
45
+ __exportStar(require("./audit.service"), exports);
46
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/modules/audit/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;;;;;;;;;;;;;;;;AAEH,iDAA+B;AAC/B,kDAAgC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zssz-soft/firebase-functions-shared",
3
- "version": "1.4.1",
3
+ "version": "1.5.0",
4
4
  "description": "Shared Firebase Cloud Functions modules for LodgeFlow applications",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -29,7 +29,9 @@
29
29
  "authentication",
30
30
  "permissions",
31
31
  "security",
32
- "rbac"
32
+ "rbac",
33
+ "audit",
34
+ "logging"
33
35
  ],
34
36
  "author": "ZS-Soft <contact@zs-soft.hu>",
35
37
  "license": "UNLICENSED",