app-tracker 2.2.2 → 3.1.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/index.js CHANGED
@@ -1,8 +1,9 @@
1
- "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./main"));
7
- __export(require("./app-tracker.service"));
8
- __export(require("./log"));
1
+ "use strict";
2
+ function __export(m) {
3
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ __export(require("./main"));
7
+ __export(require("./app-tracker.service"));
8
+ __export(require("./log"));
9
+ __export(require("./version"));
@@ -0,0 +1,2 @@
1
+ export declare function sanitizeLogText(value: string): string;
2
+ export declare function sanitizeLogValue(value: any, depth?: number, seen?: WeakSet<object>): any;
package/log-privacy.js ADDED
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const REDACTED = '[REDACTED]';
4
+ const SENSITIVE_KEYS = new Set(['authorization', 'cookie', 'password', 'passwd', 'secret', 'token', 'apikey', 'email', 'emailaddress', 'phone', 'mobile', 'firstname', 'lastname', 'fullname', 'address', 'street', 'postcode', 'postalcode', 'ip', 'ipaddress', 'hostname', 'ident', 'userid', 'customerid', 'paymentid', 'sessionid', 'refreshtoken', 'accesstoken', 'recipient', 'recipients', 'username', 'displayname', 'birthdate', 'dateofbirth', 'dob', 'iban', 'bic', 'accountnumber', 'creditcard', 'cardnumber', 'coordinates', 'latitude', 'longitude']);
5
+ const SECRET_KEY_PARTS = ['authorization', 'cookie', 'password', 'passwd', 'secret', 'token', 'apikey', 'credential', 'privatekey'];
6
+ function isSensitiveKey(key) {
7
+ const normalizedKey = key.replace(/[^a-z0-9]/gi, '').toLowerCase();
8
+ return SENSITIVE_KEYS.has(normalizedKey) || SECRET_KEY_PARTS.some(part => normalizedKey.indexOf(part) >= 0);
9
+ }
10
+ function sanitizeLogUrl(value) {
11
+ let sanitizedUrl = '[REDACTED URL]';
12
+ try {
13
+ const url = new URL(value);
14
+ const identityRoutes = new Set(['users', 'customers', 'accounts', 'sessions', 'payments']);
15
+ const segments = url.pathname.split('/').map((segment, index, allSegments) => {
16
+ const followsIdentityRoute = index > 0 && identityRoutes.has(allSegments[index - 1].toLowerCase());
17
+ const isIdentifier = /^[0-9a-f]{24}$/i.test(segment) || /^[0-9a-f]{8}-[0-9a-f-]{27}$/i.test(segment) || /^(?:cus|pi|pm|seti|sub|cs|price|in|ch)_[A-Za-z0-9_]+$/.test(segment) || /^\d{6,}$/.test(segment);
18
+ return followsIdentityRoute || isIdentifier ? ':id' : segment;
19
+ });
20
+ sanitizedUrl = `${url.protocol}//${url.host}${segments.join('/')}`;
21
+ }
22
+ catch (_error) {
23
+ // Keep the privacy-safe fallback.
24
+ }
25
+ return sanitizedUrl;
26
+ }
27
+ function sanitizeLogText(value) {
28
+ return value
29
+ .replace(/https?:\/\/[^\s"'<>]+/gi, (url) => sanitizeLogUrl(url))
30
+ .replace(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, REDACTED)
31
+ .replace(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g, REDACTED)
32
+ .replace(/\b[A-Z]{2}\d{2}[A-Z0-9]{11,30}\b/g, REDACTED)
33
+ .replace(/\+\d[\d\s().-]{7,}\d/g, REDACTED)
34
+ .replace(/[A-Z]:\\Users\\[^\\\s]+/gi, REDACTED)
35
+ .replace(/\/home\/[^/\s]+/g, REDACTED)
36
+ .replace(/\b(?:Bearer|Basic)\s+[A-Za-z0-9._~+\/-]+=*/gi, REDACTED)
37
+ .replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, REDACTED);
38
+ }
39
+ exports.sanitizeLogText = sanitizeLogText;
40
+ function sanitizeLogValue(value, depth = 0, seen = new WeakSet()) {
41
+ if (typeof value === 'string')
42
+ return sanitizeLogText(value);
43
+ if (value === null || typeof value === 'undefined' || typeof value === 'number' || typeof value === 'boolean' || typeof value === 'bigint')
44
+ return value;
45
+ if (depth >= 6)
46
+ return '[TRUNCATED]';
47
+ if (value instanceof Date)
48
+ return value.toISOString();
49
+ if (value instanceof Error)
50
+ return Object.assign({ name: sanitizeLogText(value.name), message: sanitizeLogText(value.message) }, (typeof value.stack === 'string' ? { stack: sanitizeLogText(value.stack) } : {}));
51
+ if (typeof value === 'object') {
52
+ if (seen.has(value))
53
+ return '[Circular]';
54
+ seen.add(value);
55
+ if (Array.isArray(value))
56
+ return value.map(item => sanitizeLogValue(item, depth + 1, seen));
57
+ const result = {};
58
+ Object.keys(value).forEach(key => result[key] = isSensitiveKey(key) ? REDACTED : sanitizeLogValue(value[key], depth + 1, seen));
59
+ return result;
60
+ }
61
+ return `[${typeof value}]`;
62
+ }
63
+ exports.sanitizeLogValue = sanitizeLogValue;
package/log.d.ts CHANGED
@@ -1,32 +1,31 @@
1
- export declare class AppTrackerConfig {
2
- /** Should logs in the development environment be sent to the server. For Node enviroment process.env.NODE_ENV must be set to 'development' */
3
- sendLogsInDevelopment?: boolean;
4
- logInConsole?: boolean;
5
- endpointUrl?: string;
6
- maxSendTries?: number;
7
- maxLogsCount?: number;
8
- /** Defines which log types should be sent to the server */
9
- logLevel?: LogType[];
10
- sendLogsByTypesImmediately?: LogType[];
11
- /**
12
- * Please pass:
13
- * Web -> navigator.userAgent,
14
- * Node -> os (from require('os'))
15
- */
16
- userAgentOrOs: any;
17
- }
18
- export declare class Log {
19
- logType: LogType;
20
- message: any;
21
- optionalParams: any[];
22
- createdAt: Date;
23
- ident: string;
24
- }
25
- export declare enum LogType {
26
- debug = 0,
27
- info = 1,
28
- log = 2,
29
- warn = 3,
30
- error = 4,
31
- critical = 5
32
- }
1
+ export declare class AppTrackerConfig {
2
+ /** Should logs in the development environment be sent to the server. For Node enviroment process.env.NODE_ENV must be set to 'development' */
3
+ sendLogsInDevelopment?: boolean;
4
+ logInConsole?: boolean;
5
+ endpointUrl?: string;
6
+ maxSendTries?: number;
7
+ /** Delay between send attempts. */
8
+ retryDelayMs?: number;
9
+ /** Maximum duration of a single request before it is aborted. */
10
+ requestTimeoutMs?: number;
11
+ maxLogsCount?: number;
12
+ /** Defines which log types should be sent to the server */
13
+ logLevel?: LogType[];
14
+ sendLogsByTypesImmediately?: LogType[];
15
+ /** Used only to derive coarse browser/OS categories; raw values are not transmitted. */
16
+ userAgentOrOs?: any;
17
+ }
18
+ export declare class Log {
19
+ logType: LogType;
20
+ message: any;
21
+ optionalParams: any[];
22
+ createdAt: Date;
23
+ }
24
+ export declare enum LogType {
25
+ debug = 0,
26
+ info = 1,
27
+ log = 2,
28
+ warn = 3,
29
+ error = 4,
30
+ critical = 5
31
+ }
package/log.js CHANGED
@@ -1,27 +1,30 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- class AppTrackerConfig {
4
- constructor() {
5
- this.maxLogsCount = 5;
6
- this.sendLogsByTypesImmediately = [LogType.error];
7
- }
8
- }
9
- exports.AppTrackerConfig = AppTrackerConfig;
10
- class Log {
11
- constructor() {
12
- this.logType = LogType.log;
13
- this.optionalParams = [];
14
- this.createdAt = new Date();
15
- this.ident = '';
16
- }
17
- }
18
- exports.Log = Log;
19
- var LogType;
20
- (function (LogType) {
21
- LogType[LogType["debug"] = 0] = "debug";
22
- LogType[LogType["info"] = 1] = "info";
23
- LogType[LogType["log"] = 2] = "log";
24
- LogType[LogType["warn"] = 3] = "warn";
25
- LogType[LogType["error"] = 4] = "error";
26
- LogType[LogType["critical"] = 5] = "critical";
27
- })(LogType = exports.LogType || (exports.LogType = {}));
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class AppTrackerConfig {
4
+ constructor() {
5
+ /** Delay between send attempts. */
6
+ this.retryDelayMs = 10000;
7
+ /** Maximum duration of a single request before it is aborted. */
8
+ this.requestTimeoutMs = 10000;
9
+ this.maxLogsCount = 5;
10
+ this.sendLogsByTypesImmediately = [LogType.error];
11
+ }
12
+ }
13
+ exports.AppTrackerConfig = AppTrackerConfig;
14
+ class Log {
15
+ constructor() {
16
+ this.logType = LogType.log;
17
+ this.optionalParams = [];
18
+ this.createdAt = new Date();
19
+ }
20
+ }
21
+ exports.Log = Log;
22
+ var LogType;
23
+ (function (LogType) {
24
+ LogType[LogType["debug"] = 0] = "debug";
25
+ LogType[LogType["info"] = 1] = "info";
26
+ LogType[LogType["log"] = 2] = "log";
27
+ LogType[LogType["warn"] = 3] = "warn";
28
+ LogType[LogType["error"] = 4] = "error";
29
+ LogType[LogType["critical"] = 5] = "critical";
30
+ })(LogType = exports.LogType || (exports.LogType = {}));
package/main.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { AppTrackerService } from './app-tracker.service';
2
- import { AppTrackerConfig } from './log';
3
- export declare class AppTracker {
4
- private static _service;
5
- private static get service();
6
- static init(apiKey: string, config?: AppTrackerConfig): AppTrackerService;
7
- static getService(): AppTrackerService;
8
- }
1
+ import { AppTrackerService } from './app-tracker.service';
2
+ import { AppTrackerConfig } from './log';
3
+ export declare class AppTracker {
4
+ private static _service;
5
+ private static get service();
6
+ static init(apiKey: string, config?: AppTrackerConfig): AppTrackerService;
7
+ static getService(): AppTrackerService;
8
+ }
package/main.js CHANGED
@@ -1,19 +1,19 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const app_tracker_service_1 = require("./app-tracker.service");
4
- class AppTracker {
5
- static get service() {
6
- if (!this._service)
7
- this._service = new app_tracker_service_1.AppTrackerService();
8
- return this._service;
9
- }
10
- static init(apiKey, config) {
11
- AppTracker.service.init(apiKey, config);
12
- return AppTracker.service;
13
- }
14
- static getService() {
15
- return AppTracker.service;
16
- }
17
- }
18
- exports.AppTracker = AppTracker;
19
- AppTracker._service = null;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const app_tracker_service_1 = require("./app-tracker.service");
4
+ class AppTracker {
5
+ static get service() {
6
+ if (!this._service)
7
+ this._service = new app_tracker_service_1.AppTrackerService();
8
+ return this._service;
9
+ }
10
+ static init(apiKey, config) {
11
+ AppTracker.service.init(apiKey, config);
12
+ return AppTracker.service;
13
+ }
14
+ static getService() {
15
+ return AppTracker.service;
16
+ }
17
+ }
18
+ exports.AppTracker = AppTracker;
19
+ AppTracker._service = null;
package/package.json CHANGED
@@ -1,46 +1,54 @@
1
- {
2
- "name": "app-tracker",
3
- "version": "2.2.2",
4
- "description": "App Tracker for Web-Applications",
5
- "main": "index.js",
6
- "scripts": {
7
- "build": "tsc && npm run copyFile",
8
- "copyFile": "xcopy package.json lib && xcopy README.md lib",
9
- "terser": "terser lib/main.js -c -m -o lib/main.js && terser lib/log.js -c -m -o lib/log.js && terser lib/app-tracker.service.js -c -m -o lib/app-tracker.service.js",
10
- "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
11
- "lint": "tslint -p tsconfig.json"
12
- },
13
- "keywords": [
14
- "logging",
15
- "protocol",
16
- "event logging",
17
- "monitoring",
18
- "tracking",
19
- "recording",
20
- "debugging",
21
- "iroubleshooting",
22
- "user activity",
23
- "data analysis",
24
- "system events",
25
- "performance monitoring",
26
- "processing",
27
- "archiving",
28
- "alerting",
29
- "notification",
30
- "integration",
31
- "interfaces"
32
- ],
33
- "author": "Wigtertainment Ltd",
34
- "license": "ISC",
35
- "devDependencies": {
36
- "@types/node": "^17.0.10",
37
- "parcel": "^2.7.0",
38
- "prettier": "^1.19.1",
39
- "tslint": "^5.20.1",
40
- "tslint-config-prettier": "^1.18.0",
41
- "typescript": "^3.7.3"
42
- },
43
- "dependencies": {
44
- "cross-fetch": "^3.1.5"
45
- }
46
- }
1
+ {
2
+ "name": "app-tracker",
3
+ "version": "3.1.0",
4
+ "description": "App Tracker for Web-Applications",
5
+ "main": "index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/Wigtertainment-Ltd/App-Tracker-PKG.git"
9
+ },
10
+ "scripts": {
11
+ "build": "tsc && npm run copyFile",
12
+ "copyFile": "node scripts/copy-package-files.js",
13
+ "terser": "terser lib/main.js -c -m -o lib/main.js && terser lib/log.js -c -m -o lib/log.js && terser lib/app-tracker.service.js -c -m -o lib/app-tracker.service.js",
14
+ "format": "prettier --write \"src/**/*.ts\" \"src/**/*.js\"",
15
+ "lint": "tslint -p tsconfig.json",
16
+ "test": "npm run build && node test/logging.integration.js && node test/browser-build.js"
17
+ },
18
+ "keywords": [
19
+ "logging",
20
+ "protocol",
21
+ "event logging",
22
+ "monitoring",
23
+ "tracking",
24
+ "recording",
25
+ "debugging",
26
+ "iroubleshooting",
27
+ "user activity",
28
+ "data analysis",
29
+ "system events",
30
+ "performance monitoring",
31
+ "processing",
32
+ "archiving",
33
+ "alerting",
34
+ "notification",
35
+ "integration",
36
+ "interfaces"
37
+ ],
38
+ "author": "Wigtertainment Ltd",
39
+ "license": "ISC",
40
+ "engines": {
41
+ "node": ">=16"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^17.0.10",
45
+ "parcel": "^2.7.0",
46
+ "prettier": "^1.19.1",
47
+ "tslint": "^5.20.1",
48
+ "tslint-config-prettier": "^1.18.0",
49
+ "typescript": "^3.7.3"
50
+ },
51
+ "dependencies": {
52
+ "cross-fetch": "^3.1.5"
53
+ }
54
+ }
package/version.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ /** Replaced with the package.json version by the build script. */
2
+ export declare const APP_TRACKER_VERSION: string;
package/version.js ADDED
@@ -0,0 +1,4 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ /** Replaced with the package.json version by the build script. */
4
+ exports.APP_TRACKER_VERSION = '3.1.0';