@xbg.solutions/utils-logger 1.0.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 ADDED
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Logger utility barrel export
3
+ */
4
+ export * from './logger';
5
+ export * from './logger-types';
6
+ import { Logger } from './logger';
7
+ /**
8
+ * Default logger instance for use outside request context
9
+ * For request-scoped logging, use the logger from req.logger
10
+ */
11
+ export declare const logger: Logger;
12
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,UAAU,CAAC;AACzB,cAAc,gBAAgB,CAAC;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC;;;GAGG;AACH,eAAO,MAAM,MAAM,QAAoD,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.logger = void 0;
18
+ /**
19
+ * Logger utility barrel export
20
+ */
21
+ __exportStar(require("./logger"), exports);
22
+ __exportStar(require("./logger-types"), exports);
23
+ const logger_1 = require("./logger");
24
+ /**
25
+ * Default logger instance for use outside request context
26
+ * For request-scoped logging, use the logger from req.logger
27
+ */
28
+ exports.logger = new logger_1.Logger('system', { service: 'wishlist-api' });
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA;;GAEG;AACH,2CAAyB;AACzB,iDAA+B;AAE/B,qCAAkC;AAElC;;;GAGG;AACU,QAAA,MAAM,GAAG,IAAI,eAAM,CAAC,QAAQ,EAAE,EAAE,OAAO,EAAE,cAAc,EAAE,CAAC,CAAC"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Logger type definitions
3
+ */
4
+ /**
5
+ * Base log context interface
6
+ * Represents metadata that can be attached to log messages
7
+ */
8
+ export interface LogContext {
9
+ [key: string]: unknown;
10
+ }
11
+ /**
12
+ * Common context fields used across the application
13
+ */
14
+ export interface BaseLogContext extends LogContext {
15
+ operation?: string;
16
+ userId?: string;
17
+ accountUID?: string;
18
+ listUID?: string;
19
+ itemUID?: string;
20
+ contactUID?: string;
21
+ metadata?: Record<string, unknown>;
22
+ }
23
+ /**
24
+ * Log level enum (re-export for convenience)
25
+ */
26
+ export declare enum LogLevel {
27
+ DEBUG = "debug",
28
+ INFO = "info",
29
+ WARN = "warn",
30
+ ERROR = "error"
31
+ }
32
+ //# sourceMappingURL=logger-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-types.d.ts","sourceRoot":"","sources":["../src/logger-types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH;;;GAGG;AACH,MAAM,WAAW,UAAU;IACzB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IAChD,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;GAEG;AACH,oBAAY,QAAQ;IAClB,KAAK,UAAU;IACf,IAAI,SAAS;IACb,IAAI,SAAS;IACb,KAAK,UAAU;CAChB"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ /**
3
+ * Logger type definitions
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LogLevel = void 0;
7
+ /**
8
+ * Log level enum (re-export for convenience)
9
+ */
10
+ var LogLevel;
11
+ (function (LogLevel) {
12
+ LogLevel["DEBUG"] = "debug";
13
+ LogLevel["INFO"] = "info";
14
+ LogLevel["WARN"] = "warn";
15
+ LogLevel["ERROR"] = "error";
16
+ })(LogLevel || (exports.LogLevel = LogLevel = {}));
17
+ //# sourceMappingURL=logger-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger-types.js","sourceRoot":"","sources":["../src/logger-types.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAuBH;;GAEG;AACH,IAAY,QAKX;AALD,WAAY,QAAQ;IAClB,2BAAe,CAAA;IACf,yBAAa,CAAA;IACb,yBAAa,CAAA;IACb,2BAAe,CAAA;AACjB,CAAC,EALW,QAAQ,wBAAR,QAAQ,QAKnB"}
@@ -0,0 +1,42 @@
1
+ /**
2
+ * Structured Logger with Correlation IDs
3
+ *
4
+ * Integrates with Firebase Functions logging (GCP Cloud Logging)
5
+ * Never logs PII in plaintext - sanitizes metadata
6
+ */
7
+ import { LogContext } from './logger-types';
8
+ export { LogLevel } from './logger-types';
9
+ export declare class Logger {
10
+ private readonly correlationId;
11
+ private readonly context;
12
+ constructor(correlationId: string, context?: LogContext);
13
+ /**
14
+ * Sanitize metadata to remove sensitive fields
15
+ */
16
+ private sanitizeMetadata;
17
+ /**
18
+ * Build log data structure
19
+ */
20
+ private buildLogData;
21
+ /**
22
+ * Log debug message (development only)
23
+ */
24
+ debug(message: string, meta?: LogContext): void;
25
+ /**
26
+ * Log info message
27
+ */
28
+ info(message: string, meta?: LogContext): void;
29
+ /**
30
+ * Log warning message
31
+ */
32
+ warn(message: string, meta?: LogContext): void;
33
+ /**
34
+ * Log error message with error object
35
+ */
36
+ error(message: string, error: Error, meta?: LogContext): void;
37
+ /**
38
+ * Create child logger with additional context
39
+ */
40
+ child(additionalContext: LogContext): Logger;
41
+ }
42
+ //# sourceMappingURL=logger.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAY,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAmC1C,qBAAa,MAAM;IAEf,OAAO,CAAC,QAAQ,CAAC,aAAa;IAC9B,OAAO,CAAC,QAAQ,CAAC,OAAO;gBADP,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,UAAe;IAG3C;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAuBxB;;OAEG;IACH,OAAO,CAAC,YAAY;IAiBpB;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAOnD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAKlD;;OAEG;IACH,IAAI,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAKlD;;OAEG;IACH,KAAK,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,IAAI,GAAE,UAAe,GAAG,IAAI;IAYjE;;OAEG;IACH,KAAK,CAAC,iBAAiB,EAAE,UAAU,GAAG,MAAM;CAM7C"}
package/lib/logger.js ADDED
@@ -0,0 +1,123 @@
1
+ "use strict";
2
+ /**
3
+ * Structured Logger with Correlation IDs
4
+ *
5
+ * Integrates with Firebase Functions logging (GCP Cloud Logging)
6
+ * Never logs PII in plaintext - sanitizes metadata
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.Logger = exports.LogLevel = void 0;
10
+ const firebase_functions_1 = require("firebase-functions");
11
+ const logger_types_1 = require("./logger-types");
12
+ var logger_types_2 = require("./logger-types");
13
+ Object.defineProperty(exports, "LogLevel", { enumerable: true, get: function () { return logger_types_2.LogLevel; } });
14
+ /**
15
+ * Sensitive field names that should never be logged
16
+ */
17
+ const SENSITIVE_FIELDS = [
18
+ 'password',
19
+ 'token',
20
+ 'secret',
21
+ 'key',
22
+ 'apiKey',
23
+ 'api_key',
24
+ 'accessToken',
25
+ 'access_token',
26
+ 'refreshToken',
27
+ 'refresh_token',
28
+ 'email',
29
+ 'phoneNumber',
30
+ 'phone',
31
+ 'address',
32
+ 'addressLine1',
33
+ 'addressLine2',
34
+ 'city',
35
+ 'state',
36
+ 'postalCode',
37
+ 'postal_code',
38
+ 'ssn',
39
+ 'creditCard',
40
+ 'credit_card',
41
+ 'cardNumber',
42
+ 'card_number',
43
+ 'cvv',
44
+ 'authorization',
45
+ ];
46
+ class Logger {
47
+ constructor(correlationId, context = {}) {
48
+ this.correlationId = correlationId;
49
+ this.context = context;
50
+ }
51
+ /**
52
+ * Sanitize metadata to remove sensitive fields
53
+ */
54
+ sanitizeMetadata(meta) {
55
+ const sanitized = {};
56
+ for (const [key, value] of Object.entries(meta)) {
57
+ // Check if field name is sensitive
58
+ const lowerKey = key.toLowerCase();
59
+ const isSensitive = SENSITIVE_FIELDS.some((field) => lowerKey.includes(field.toLowerCase()));
60
+ if (isSensitive) {
61
+ sanitized[key] = '[REDACTED]';
62
+ }
63
+ else if (value && typeof value === 'object' && !Array.isArray(value)) {
64
+ // Recursively sanitize nested objects
65
+ sanitized[key] = this.sanitizeMetadata(value);
66
+ }
67
+ else {
68
+ sanitized[key] = value;
69
+ }
70
+ }
71
+ return sanitized;
72
+ }
73
+ /**
74
+ * Build log data structure
75
+ */
76
+ buildLogData(level, message, meta = {}) {
77
+ const sanitizedMeta = this.sanitizeMetadata(meta);
78
+ return Object.assign({ correlationId: this.correlationId, timestamp: new Date().toISOString(), level,
79
+ message, context: this.context }, sanitizedMeta);
80
+ }
81
+ /**
82
+ * Log debug message (development only)
83
+ */
84
+ debug(message, meta = {}) {
85
+ if (process.env.LOG_LEVEL === 'debug' || process.env.NODE_ENV === 'development') {
86
+ const logData = this.buildLogData(logger_types_1.LogLevel.DEBUG, message, meta);
87
+ firebase_functions_1.logger.debug(logData);
88
+ }
89
+ }
90
+ /**
91
+ * Log info message
92
+ */
93
+ info(message, meta = {}) {
94
+ const logData = this.buildLogData(logger_types_1.LogLevel.INFO, message, meta);
95
+ firebase_functions_1.logger.info(logData);
96
+ }
97
+ /**
98
+ * Log warning message
99
+ */
100
+ warn(message, meta = {}) {
101
+ const logData = this.buildLogData(logger_types_1.LogLevel.WARN, message, meta);
102
+ firebase_functions_1.logger.warn(logData);
103
+ }
104
+ /**
105
+ * Log error message with error object
106
+ */
107
+ error(message, error, meta = {}) {
108
+ const logData = this.buildLogData(logger_types_1.LogLevel.ERROR, message, Object.assign({ error: {
109
+ name: error.name,
110
+ message: error.message,
111
+ stack: error.stack,
112
+ } }, meta));
113
+ firebase_functions_1.logger.error(logData);
114
+ }
115
+ /**
116
+ * Create child logger with additional context
117
+ */
118
+ child(additionalContext) {
119
+ return new Logger(this.correlationId, Object.assign(Object.assign({}, this.context), additionalContext));
120
+ }
121
+ }
122
+ exports.Logger = Logger;
123
+ //# sourceMappingURL=logger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,2DAAyD;AACzD,iDAAsD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AAC;IAED;;OAEG;IACH,KAAK,CAAC,OAAe,EAAE,KAAY,EAAE,OAAmB,EAAE;QACxD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,uBAAQ,CAAC,KAAK,EAAE,OAAO,kBACvD,KAAK,EAAE;gBACL,IAAI,EAAE,KAAK,CAAC,IAAI;gBAChB,OAAO,EAAE,KAAK,CAAC,OAAO;gBACtB,KAAK,EAAE,KAAK,CAAC,KAAK;aACnB,IACE,IAAI,EACP,CAAC;QACH,2BAAS,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC3B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,iBAA6B;QACjC,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,aAAa,kCAC/B,IAAI,CAAC,OAAO,GACZ,iBAAiB,EACpB,CAAC;IACL,CAAC;CACF;AAtGD,wBAsGC"}
package/package.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "name": "@xbg.solutions/utils-logger",
3
+ "version": "1.0.0",
4
+ "description": "Structured logging with PII sanitization and GCP Cloud Logging",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "files": ["lib"],
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "build:watch": "tsc --watch",
11
+ "clean": "rm -rf lib",
12
+ "prepublishOnly": "npm run build"
13
+ },
14
+ "dependencies": {"uuid": "^9.0.1"},
15
+ "devDependencies": {"@types/uuid": "^9.0.7", "@types/node": "^20.11.0", "typescript": "^5.3.3"},
16
+ "engines": {
17
+ "node": "22"
18
+ },
19
+ "publishConfig": {
20
+ "access": "public"
21
+ }
22
+ }