@avss-tech/logger 1.0.0 → 1.0.1
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/dist/constants.d.ts +38 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +41 -0
- package/dist/constants.js.map +1 -0
- package/dist/http-client.d.ts +27 -0
- package/dist/http-client.d.ts.map +1 -0
- package/dist/http-client.js +89 -0
- package/dist/http-client.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +25 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +22 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +218 -0
- package/dist/logger.js.map +1 -0
- package/dist/queue.d.ts +20 -0
- package/dist/queue.d.ts.map +1 -0
- package/dist/queue.js +93 -0
- package/dist/queue.js.map +1 -0
- package/dist/retry.d.ts +10 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +52 -0
- package/dist/retry.js.map +1 -0
- package/dist/types.d.ts +99 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/validators.d.ts +14 -0
- package/dist/validators.d.ts.map +1 -0
- package/dist/validators.js +114 -0
- package/dist/validators.js.map +1 -0
- package/package.json +12 -9
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
export declare const DEFAULT_CONFIG: {
|
|
2
|
+
readonly endpoint: "http://localhost:4000/logs";
|
|
3
|
+
readonly timeout: 5000;
|
|
4
|
+
readonly maxRetries: 3;
|
|
5
|
+
readonly initialRetryDelay: 100;
|
|
6
|
+
readonly batchSize: 50;
|
|
7
|
+
readonly batchTimeout: 5000;
|
|
8
|
+
readonly debug: false;
|
|
9
|
+
};
|
|
10
|
+
export declare const RETRY_CONFIG: {
|
|
11
|
+
readonly maxAttempts: 3;
|
|
12
|
+
readonly initialDelayMs: 100;
|
|
13
|
+
readonly multiplier: 2;
|
|
14
|
+
readonly maxDelayMs: 10000;
|
|
15
|
+
readonly retryableStatusCodes: readonly [408, 429, 500, 502, 503, 504];
|
|
16
|
+
};
|
|
17
|
+
export declare const API_ENDPOINTS: {
|
|
18
|
+
readonly LOG: "/logs";
|
|
19
|
+
readonly AUDIT: "/logs/audit";
|
|
20
|
+
readonly ACCESS: "/logs/access";
|
|
21
|
+
readonly ERROR: "/logs/error";
|
|
22
|
+
};
|
|
23
|
+
export declare const LOG_LEVELS: {
|
|
24
|
+
readonly DEBUG: "debug";
|
|
25
|
+
readonly INFO: "info";
|
|
26
|
+
readonly WARN: "warn";
|
|
27
|
+
readonly ERROR: "error";
|
|
28
|
+
};
|
|
29
|
+
export declare const ERROR_MESSAGES: {
|
|
30
|
+
readonly MISSING_PROJECT: "Project name is required";
|
|
31
|
+
readonly MISSING_API_KEY: "API key is required";
|
|
32
|
+
readonly INVALID_ENDPOINT: "Invalid endpoint URL";
|
|
33
|
+
readonly NETWORK_ERROR: "Network error occurred";
|
|
34
|
+
readonly TIMEOUT: "Request timeout";
|
|
35
|
+
readonly INVALID_LOG: "Invalid log data";
|
|
36
|
+
readonly MAX_RETRIES_EXCEEDED: "Max retries exceeded";
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,cAAc;;;;;;;;CAQjB,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;CAMf,CAAC;AAEX,eAAO,MAAM,aAAa;;;;;CAKhB,CAAC;AAEX,eAAO,MAAM,UAAU;;;;;CAKb,CAAC;AAEX,eAAO,MAAM,cAAc;;;;;;;;CAQjB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ERROR_MESSAGES = exports.LOG_LEVELS = exports.API_ENDPOINTS = exports.RETRY_CONFIG = exports.DEFAULT_CONFIG = void 0;
|
|
4
|
+
exports.DEFAULT_CONFIG = {
|
|
5
|
+
endpoint: 'http://localhost:4000/logs',
|
|
6
|
+
timeout: 5000,
|
|
7
|
+
maxRetries: 3,
|
|
8
|
+
initialRetryDelay: 100,
|
|
9
|
+
batchSize: 50,
|
|
10
|
+
batchTimeout: 5000,
|
|
11
|
+
debug: false,
|
|
12
|
+
};
|
|
13
|
+
exports.RETRY_CONFIG = {
|
|
14
|
+
maxAttempts: 3,
|
|
15
|
+
initialDelayMs: 100,
|
|
16
|
+
multiplier: 2,
|
|
17
|
+
maxDelayMs: 10000,
|
|
18
|
+
retryableStatusCodes: [408, 429, 500, 502, 503, 504],
|
|
19
|
+
};
|
|
20
|
+
exports.API_ENDPOINTS = {
|
|
21
|
+
LOG: '/logs',
|
|
22
|
+
AUDIT: '/logs/audit',
|
|
23
|
+
ACCESS: '/logs/access',
|
|
24
|
+
ERROR: '/logs/error',
|
|
25
|
+
};
|
|
26
|
+
exports.LOG_LEVELS = {
|
|
27
|
+
DEBUG: 'debug',
|
|
28
|
+
INFO: 'info',
|
|
29
|
+
WARN: 'warn',
|
|
30
|
+
ERROR: 'error',
|
|
31
|
+
};
|
|
32
|
+
exports.ERROR_MESSAGES = {
|
|
33
|
+
MISSING_PROJECT: 'Project name is required',
|
|
34
|
+
MISSING_API_KEY: 'API key is required',
|
|
35
|
+
INVALID_ENDPOINT: 'Invalid endpoint URL',
|
|
36
|
+
NETWORK_ERROR: 'Network error occurred',
|
|
37
|
+
TIMEOUT: 'Request timeout',
|
|
38
|
+
INVALID_LOG: 'Invalid log data',
|
|
39
|
+
MAX_RETRIES_EXCEEDED: 'Max retries exceeded',
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":";;;AAIa,QAAA,cAAc,GAAG;IAC5B,QAAQ,EAAE,4BAA4B;IACtC,OAAO,EAAE,IAAI;IACb,UAAU,EAAE,CAAC;IACb,iBAAiB,EAAE,GAAG;IACtB,SAAS,EAAE,EAAE;IACb,YAAY,EAAE,IAAI;IAClB,KAAK,EAAE,KAAK;CACJ,CAAC;AAEE,QAAA,YAAY,GAAG;IAC1B,WAAW,EAAE,CAAC;IACd,cAAc,EAAE,GAAG;IACnB,UAAU,EAAE,CAAC;IACb,UAAU,EAAE,KAAK;IACjB,oBAAoB,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC;CAC5C,CAAC;AAEE,QAAA,aAAa,GAAG;IAC3B,GAAG,EAAE,OAAO;IACZ,KAAK,EAAE,aAAa;IACpB,MAAM,EAAE,cAAc;IACtB,KAAK,EAAE,aAAa;CACZ,CAAC;AAEE,QAAA,UAAU,GAAG;IACxB,KAAK,EAAE,OAAO;IACd,IAAI,EAAE,MAAM;IACZ,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,OAAO;CACN,CAAC;AAEE,QAAA,cAAc,GAAG;IAC5B,eAAe,EAAE,0BAA0B;IAC3C,eAAe,EAAE,qBAAqB;IACtC,gBAAgB,EAAE,sBAAsB;IACxC,aAAa,EAAE,wBAAwB;IACvC,OAAO,EAAE,iBAAiB;IAC1B,WAAW,EAAE,kBAAkB;IAC/B,oBAAoB,EAAE,sBAAsB;CACpC,CAAC"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { AVSLoggerConfig } from './types';
|
|
2
|
+
export interface HttpRequest {
|
|
3
|
+
method: 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH';
|
|
4
|
+
endpoint: string;
|
|
5
|
+
headers?: Record<string, string>;
|
|
6
|
+
body?: any;
|
|
7
|
+
timeout?: number;
|
|
8
|
+
}
|
|
9
|
+
export interface HttpResponse {
|
|
10
|
+
status: number;
|
|
11
|
+
data: any;
|
|
12
|
+
headers: Record<string, string>;
|
|
13
|
+
}
|
|
14
|
+
export declare class HttpClient {
|
|
15
|
+
private baseUrl;
|
|
16
|
+
private headers;
|
|
17
|
+
private timeout;
|
|
18
|
+
private retryManager;
|
|
19
|
+
private debug;
|
|
20
|
+
constructor(config: AVSLoggerConfig);
|
|
21
|
+
request(req: HttpRequest): Promise<HttpResponse>;
|
|
22
|
+
private makeRequest;
|
|
23
|
+
private parseResponse;
|
|
24
|
+
post(endpoint: string, body: any, headers?: Record<string, string>): Promise<any>;
|
|
25
|
+
get(endpoint: string, headers?: Record<string, string>): Promise<any>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=http-client.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.d.ts","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAE1C,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,GAAG,OAAO,CAAC;IACpD,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,GAAG,CAAC;IACV,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACjC;AAED,qBAAa,UAAU;IACrB,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,YAAY,CAAe;IACnC,OAAO,CAAC,KAAK,CAAU;gBAEX,MAAM,EAAE,eAAe;IAoB7B,OAAO,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,YAAY,CAAC;YAkBxC,WAAW;YA0CX,aAAa;IAiBrB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;IAajF,GAAG,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,GAAG,CAAC;CAQ5E"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HttpClient = void 0;
|
|
4
|
+
const retry_1 = require("./retry");
|
|
5
|
+
class HttpClient {
|
|
6
|
+
constructor(config) {
|
|
7
|
+
this.baseUrl = config.endpoint || 'http://localhost:4000/logs';
|
|
8
|
+
this.timeout = config.timeout || 5000;
|
|
9
|
+
this.debug = config.debug || false;
|
|
10
|
+
this.headers = {
|
|
11
|
+
'Content-Type': 'application/json',
|
|
12
|
+
'x-api-key': config.apiKey,
|
|
13
|
+
...config.customHeaders,
|
|
14
|
+
};
|
|
15
|
+
this.retryManager = new retry_1.RetryManager({
|
|
16
|
+
maxAttempts: config.maxRetries || 3,
|
|
17
|
+
initialDelayMs: config.initialRetryDelay || 100,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async request(req) {
|
|
21
|
+
const url = `${this.baseUrl}${req.endpoint}`;
|
|
22
|
+
return this.retryManager.executeWithRetry(() => this.makeRequest(url, req), (attempt, error, nextDelay) => {
|
|
23
|
+
if (this.debug) {
|
|
24
|
+
console.log(`[HttpClient] Retry attempt ${attempt} in ${Math.round(nextDelay)}ms: ${error.message}`);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
async makeRequest(url, req) {
|
|
29
|
+
const controller = new AbortController();
|
|
30
|
+
const timeoutId = setTimeout(() => controller.abort(), req.timeout || this.timeout);
|
|
31
|
+
try {
|
|
32
|
+
const response = await fetch(url, {
|
|
33
|
+
method: req.method,
|
|
34
|
+
headers: { ...this.headers, ...req.headers },
|
|
35
|
+
body: req.body ? JSON.stringify(req.body) : undefined,
|
|
36
|
+
signal: controller.signal,
|
|
37
|
+
});
|
|
38
|
+
clearTimeout(timeoutId);
|
|
39
|
+
const data = await this.parseResponse(response);
|
|
40
|
+
if (!response.ok) {
|
|
41
|
+
const error = new Error(`HTTP ${response.status}: ${data?.message || response.statusText}`);
|
|
42
|
+
error.status = response.status;
|
|
43
|
+
error.response = { status: response.status, data };
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
status: response.status,
|
|
48
|
+
data,
|
|
49
|
+
headers: Object.fromEntries(response.headers.entries()),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
clearTimeout(timeoutId);
|
|
54
|
+
if (error instanceof Error && error.name === 'AbortError') {
|
|
55
|
+
throw new Error('Request timeout');
|
|
56
|
+
}
|
|
57
|
+
throw error;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
async parseResponse(response) {
|
|
61
|
+
const contentType = response.headers.get('content-type');
|
|
62
|
+
if (!contentType) {
|
|
63
|
+
return null;
|
|
64
|
+
}
|
|
65
|
+
if (contentType.includes('application/json')) {
|
|
66
|
+
return response.json().catch(() => null);
|
|
67
|
+
}
|
|
68
|
+
return response.text();
|
|
69
|
+
}
|
|
70
|
+
async post(endpoint, body, headers) {
|
|
71
|
+
const response = await this.request({
|
|
72
|
+
method: 'POST',
|
|
73
|
+
endpoint,
|
|
74
|
+
headers,
|
|
75
|
+
body,
|
|
76
|
+
});
|
|
77
|
+
return response.data;
|
|
78
|
+
}
|
|
79
|
+
async get(endpoint, headers) {
|
|
80
|
+
const response = await this.request({
|
|
81
|
+
method: 'GET',
|
|
82
|
+
endpoint,
|
|
83
|
+
headers,
|
|
84
|
+
});
|
|
85
|
+
return response.data;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.HttpClient = HttpClient;
|
|
89
|
+
//# sourceMappingURL=http-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-client.js","sourceRoot":"","sources":["../src/http-client.ts"],"names":[],"mappings":";;;AAIA,mCAAuC;AAiBvC,MAAa,UAAU;IAOrB,YAAY,MAAuB;QACjC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,QAAQ,IAAI,4BAA4B,CAAC;QAC/D,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,IAAI,IAAI,CAAC;QACtC,IAAI,CAAC,KAAK,GAAG,MAAM,CAAC,KAAK,IAAI,KAAK,CAAC;QAEnC,IAAI,CAAC,OAAO,GAAG;YACb,cAAc,EAAE,kBAAkB;YAClC,WAAW,EAAE,MAAM,CAAC,MAAM;YAC1B,GAAG,MAAM,CAAC,aAAa;SACxB,CAAC;QAEF,IAAI,CAAC,YAAY,GAAG,IAAI,oBAAY,CAAC;YACnC,WAAW,EAAE,MAAM,CAAC,UAAU,IAAI,CAAC;YACnC,cAAc,EAAE,MAAM,CAAC,iBAAiB,IAAI,GAAG;SAChD,CAAC,CAAC;IACL,CAAC;IAKD,KAAK,CAAC,OAAO,CAAC,GAAgB;QAC5B,MAAM,GAAG,GAAG,GAAG,IAAI,CAAC,OAAO,GAAG,GAAG,CAAC,QAAQ,EAAE,CAAC;QAE7C,OAAO,IAAI,CAAC,YAAY,CAAC,gBAAgB,CACvC,GAAG,EAAE,CAAC,IAAI,CAAC,WAAW,CAAC,GAAG,EAAE,GAAG,CAAC,EAChC,CAAC,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE;YAC5B,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,GAAG,CACT,8BAA8B,OAAO,OAAO,IA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AC,CAAC;QACH,OAAO,QAAQ,CAAC,IAAI,CAAC;IACvB,CAAC;CACF;AA7HD,gCA6HC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { AVSLogger, default } from './logger';
|
|
2
|
+
export type { Actor, Entity, GenericLog, AuditLog, AccessLog, ErrorLog, LogLevel, AVSLoggerConfig, LogResponse, LogResult, RetryPolicy, QueueItem, SDKStatistics, } from './types';
|
|
3
|
+
export { Validators, ValidationError } from './validators';
|
|
4
|
+
export { RetryManager } from './retry';
|
|
5
|
+
export { Queue } from './queue';
|
|
6
|
+
export { HttpClient } from './http-client';
|
|
7
|
+
export { DEFAULT_CONFIG, RETRY_CONFIG, API_ENDPOINTS, LOG_LEVELS, ERROR_MESSAGES } from './constants';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EACV,KAAK,EACL,MAAM,EACN,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,QAAQ,EACR,eAAe,EACf,WAAW,EACX,SAAS,EACT,WAAW,EACX,SAAS,EACT,aAAa,GACd,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAC3D,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAChC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAG3C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,aAAa,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ERROR_MESSAGES = exports.LOG_LEVELS = exports.API_ENDPOINTS = exports.RETRY_CONFIG = exports.DEFAULT_CONFIG = exports.HttpClient = exports.Queue = exports.RetryManager = exports.ValidationError = exports.Validators = exports.default = exports.AVSLogger = void 0;
|
|
7
|
+
var logger_1 = require("./logger");
|
|
8
|
+
Object.defineProperty(exports, "AVSLogger", { enumerable: true, get: function () { return logger_1.AVSLogger; } });
|
|
9
|
+
Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(logger_1).default; } });
|
|
10
|
+
var validators_1 = require("./validators");
|
|
11
|
+
Object.defineProperty(exports, "Validators", { enumerable: true, get: function () { return validators_1.Validators; } });
|
|
12
|
+
Object.defineProperty(exports, "ValidationError", { enumerable: true, get: function () { return validators_1.ValidationError; } });
|
|
13
|
+
var retry_1 = require("./retry");
|
|
14
|
+
Object.defineProperty(exports, "RetryManager", { enumerable: true, get: function () { return retry_1.RetryManager; } });
|
|
15
|
+
var queue_1 = require("./queue");
|
|
16
|
+
Object.defineProperty(exports, "Queue", { enumerable: true, get: function () { return queue_1.Queue; } });
|
|
17
|
+
var http_client_1 = require("./http-client");
|
|
18
|
+
Object.defineProperty(exports, "HttpClient", { enumerable: true, get: function () { return http_client_1.HttpClient; } });
|
|
19
|
+
var constants_1 = require("./constants");
|
|
20
|
+
Object.defineProperty(exports, "DEFAULT_CONFIG", { enumerable: true, get: function () { return constants_1.DEFAULT_CONFIG; } });
|
|
21
|
+
Object.defineProperty(exports, "RETRY_CONFIG", { enumerable: true, get: function () { return constants_1.RETRY_CONFIG; } });
|
|
22
|
+
Object.defineProperty(exports, "API_ENDPOINTS", { enumerable: true, get: function () { return constants_1.API_ENDPOINTS; } });
|
|
23
|
+
Object.defineProperty(exports, "LOG_LEVELS", { enumerable: true, get: function () { return constants_1.LOG_LEVELS; } });
|
|
24
|
+
Object.defineProperty(exports, "ERROR_MESSAGES", { enumerable: true, get: function () { return constants_1.ERROR_MESSAGES; } });
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;AAKA,mCAA8C;AAArC,mGAAA,SAAS,OAAA;AAAE,kHAAA,OAAO,OAAA;AAoB3B,2CAA2D;AAAlD,wGAAA,UAAU,OAAA;AAAE,6GAAA,eAAe,OAAA;AACpC,iCAAuC;AAA9B,qGAAA,YAAY,OAAA;AACrB,iCAAgC;AAAvB,8FAAA,KAAK,OAAA;AACd,6CAA2C;AAAlC,yGAAA,UAAU,OAAA;AAGnB,yCAAsG;AAA7F,2GAAA,cAAc,OAAA;AAAE,yGAAA,YAAY,OAAA;AAAE,0GAAA,aAAa,OAAA;AAAE,uGAAA,UAAU,OAAA;AAAE,2GAAA,cAAc,OAAA"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { AVSLoggerConfig, GenericLog, AuditLog, AccessLog, ErrorLog, LogResult, SDKStatistics } from './types';
|
|
2
|
+
export declare class AVSLogger {
|
|
3
|
+
private config;
|
|
4
|
+
private httpClient;
|
|
5
|
+
private queue;
|
|
6
|
+
private statistics;
|
|
7
|
+
constructor(config: AVSLoggerConfig);
|
|
8
|
+
log(logData: Partial<GenericLog>): Promise<LogResult>;
|
|
9
|
+
audit(auditData: Partial<AuditLog>): Promise<LogResult>;
|
|
10
|
+
access(accessData: Partial<AccessLog>): Promise<LogResult>;
|
|
11
|
+
error(errorData: Partial<ErrorLog>): Promise<LogResult>;
|
|
12
|
+
private sendLog;
|
|
13
|
+
private handleError;
|
|
14
|
+
private flushQueueItems;
|
|
15
|
+
private getEndpointForType;
|
|
16
|
+
flush(): Promise<void>;
|
|
17
|
+
getStatistics(): SDKStatistics;
|
|
18
|
+
resetStatistics(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
export default AVSLogger;
|
|
22
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,eAAe,EACf,UAAU,EACV,QAAQ,EACR,SAAS,EACT,QAAQ,EACR,SAAS,EACT,aAAa,EACd,MAAM,SAAS,CAAC;AAMjB,qBAAa,SAAS;IACpB,OAAO,CAAC,MAAM,CAA4B;IAC1C,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,UAAU,CAMhB;gBAEU,MAAM,EAAE,eAAe;IAqC7B,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAoBrD,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAmBvD,MAAM,CAAC,UAAU,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;IAmB1D,KAAK,CAAC,SAAS,EAAE,OAAO,CAAC,QAAQ,CAAC,GAAG,OAAO,CAAC,SAAS,CAAC;YAmB/C,OAAO;IA2CrB,OAAO,CAAC,WAAW;YAoBL,eAAe;IAgC7B,OAAO,CAAC,kBAAkB;IAgBpB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAS5B,aAAa,IAAI,aAAa;IAiB9B,eAAe,IAAI,IAAI;IAavB,OAAO,IAAI,IAAI;CAUhB;AAGD,eAAe,SAAS,CAAC"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AVSLogger = void 0;
|
|
4
|
+
const http_client_1 = require("./http-client");
|
|
5
|
+
const validators_1 = require("./validators");
|
|
6
|
+
const queue_1 = require("./queue");
|
|
7
|
+
const constants_1 = require("./constants");
|
|
8
|
+
class AVSLogger {
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.queue = null;
|
|
11
|
+
this.statistics = {
|
|
12
|
+
totalLogsAttempted: 0,
|
|
13
|
+
successfulLogs: 0,
|
|
14
|
+
failedLogs: 0,
|
|
15
|
+
retriedLogs: 0,
|
|
16
|
+
totalResponseTimeMs: 0,
|
|
17
|
+
};
|
|
18
|
+
validators_1.Validators.validateConfig(config);
|
|
19
|
+
this.config = {
|
|
20
|
+
project: config.project,
|
|
21
|
+
apiKey: config.apiKey,
|
|
22
|
+
endpoint: config.endpoint || constants_1.DEFAULT_CONFIG.endpoint,
|
|
23
|
+
timeout: config.timeout || constants_1.DEFAULT_CONFIG.timeout,
|
|
24
|
+
enableQueue: config.enableQueue ?? false,
|
|
25
|
+
batchSize: config.batchSize || constants_1.DEFAULT_CONFIG.batchSize,
|
|
26
|
+
batchTimeout: config.batchTimeout || constants_1.DEFAULT_CONFIG.batchTimeout,
|
|
27
|
+
maxRetries: config.maxRetries || constants_1.DEFAULT_CONFIG.maxRetries,
|
|
28
|
+
initialRetryDelay: config.initialRetryDelay || constants_1.DEFAULT_CONFIG.initialRetryDelay,
|
|
29
|
+
debug: config.debug || constants_1.DEFAULT_CONFIG.debug,
|
|
30
|
+
customHeaders: config.customHeaders || {},
|
|
31
|
+
onFatalError: config.onFatalError,
|
|
32
|
+
};
|
|
33
|
+
this.httpClient = new http_client_1.HttpClient(this.config);
|
|
34
|
+
if (this.config.enableQueue) {
|
|
35
|
+
this.queue = new queue_1.Queue(this.config.batchSize, this.config.batchTimeout);
|
|
36
|
+
this.queue.setOnFlush((items) => this.flushQueueItems(items));
|
|
37
|
+
}
|
|
38
|
+
if (this.config.debug) {
|
|
39
|
+
console.log('[AVSLogger] Initialized', { project: this.config.project });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async log(logData) {
|
|
43
|
+
try {
|
|
44
|
+
const log = {
|
|
45
|
+
project: this.config.project,
|
|
46
|
+
level: 'info',
|
|
47
|
+
...logData,
|
|
48
|
+
timestamp: new Date().toISOString(),
|
|
49
|
+
};
|
|
50
|
+
validators_1.Validators.validateGenericLog(log);
|
|
51
|
+
return this.sendLog(constants_1.API_ENDPOINTS.LOG, log);
|
|
52
|
+
}
|
|
53
|
+
catch (error) {
|
|
54
|
+
return this.handleError('log', error);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
async audit(auditData) {
|
|
58
|
+
try {
|
|
59
|
+
const log = {
|
|
60
|
+
project: this.config.project,
|
|
61
|
+
...auditData,
|
|
62
|
+
timestamp: new Date().toISOString(),
|
|
63
|
+
};
|
|
64
|
+
validators_1.Validators.validateAuditLog(log);
|
|
65
|
+
return this.sendLog(constants_1.API_ENDPOINTS.AUDIT, log);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
return this.handleError('audit', error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
async access(accessData) {
|
|
72
|
+
try {
|
|
73
|
+
const log = {
|
|
74
|
+
project: this.config.project,
|
|
75
|
+
...accessData,
|
|
76
|
+
timestamp: new Date().toISOString(),
|
|
77
|
+
};
|
|
78
|
+
validators_1.Validators.validateAccessLog(log);
|
|
79
|
+
return this.sendLog(constants_1.API_ENDPOINTS.ACCESS, log);
|
|
80
|
+
}
|
|
81
|
+
catch (error) {
|
|
82
|
+
return this.handleError('access', error);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
async error(errorData) {
|
|
86
|
+
try {
|
|
87
|
+
const log = {
|
|
88
|
+
project: this.config.project,
|
|
89
|
+
...errorData,
|
|
90
|
+
timestamp: new Date().toISOString(),
|
|
91
|
+
};
|
|
92
|
+
validators_1.Validators.validateErrorLog(log);
|
|
93
|
+
return this.sendLog(constants_1.API_ENDPOINTS.ERROR, log);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
return this.handleError('error', error);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
async sendLog(endpoint, log) {
|
|
100
|
+
this.statistics.totalLogsAttempted++;
|
|
101
|
+
try {
|
|
102
|
+
const startTime = Date.now();
|
|
103
|
+
if (this.config.enableQueue && this.queue) {
|
|
104
|
+
const id = await this.queue.add({
|
|
105
|
+
type: endpoint === constants_1.API_ENDPOINTS.LOG ? 'log' : endpoint === constants_1.API_ENDPOINTS.AUDIT ? 'audit' : endpoint === constants_1.API_ENDPOINTS.ACCESS ? 'access' : 'error',
|
|
106
|
+
data: log,
|
|
107
|
+
});
|
|
108
|
+
return {
|
|
109
|
+
success: true,
|
|
110
|
+
message: 'Log queued for processing',
|
|
111
|
+
id,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
const response = await this.httpClient.post(endpoint, log);
|
|
115
|
+
const duration = Date.now() - startTime;
|
|
116
|
+
this.statistics.successfulLogs++;
|
|
117
|
+
this.statistics.totalResponseTimeMs += duration;
|
|
118
|
+
if (this.config.debug) {
|
|
119
|
+
console.log(`[AVSLogger] Log sent successfully in ${duration}ms`);
|
|
120
|
+
}
|
|
121
|
+
return {
|
|
122
|
+
success: true,
|
|
123
|
+
message: response.message || 'Log processed successfully',
|
|
124
|
+
id: response.id,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
this.statistics.failedLogs++;
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
handleError(type, error) {
|
|
133
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
134
|
+
if (this.config.debug) {
|
|
135
|
+
console.error(`[AVSLogger] ${type} failed:`, error);
|
|
136
|
+
}
|
|
137
|
+
if (this.config.onFatalError && error instanceof Error) {
|
|
138
|
+
this.config.onFatalError(error);
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
success: false,
|
|
142
|
+
message: `Failed to send ${type}: ${errorMessage}`,
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
async flushQueueItems(items) {
|
|
146
|
+
const promises = items.map(async (item) => {
|
|
147
|
+
try {
|
|
148
|
+
if (!this.queue)
|
|
149
|
+
return;
|
|
150
|
+
await this.httpClient.post(this.getEndpointForType(item.type), item.data);
|
|
151
|
+
this.queue?.removeItem(item.id);
|
|
152
|
+
this.statistics.successfulLogs++;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
if (!this.queue)
|
|
156
|
+
return;
|
|
157
|
+
item.retries++;
|
|
158
|
+
this.queue.updateItem(item.id, { ...item });
|
|
159
|
+
if (item.retries >= this.config.maxRetries) {
|
|
160
|
+
this.queue.removeItem(item.id);
|
|
161
|
+
this.statistics.failedLogs++;
|
|
162
|
+
this.statistics.retriedLogs++;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
await Promise.all(promises);
|
|
167
|
+
}
|
|
168
|
+
getEndpointForType(type) {
|
|
169
|
+
switch (type) {
|
|
170
|
+
case 'audit':
|
|
171
|
+
return constants_1.API_ENDPOINTS.AUDIT;
|
|
172
|
+
case 'access':
|
|
173
|
+
return constants_1.API_ENDPOINTS.ACCESS;
|
|
174
|
+
case 'error':
|
|
175
|
+
return constants_1.API_ENDPOINTS.ERROR;
|
|
176
|
+
default:
|
|
177
|
+
return constants_1.API_ENDPOINTS.LOG;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
async flush() {
|
|
181
|
+
if (this.queue) {
|
|
182
|
+
await this.queue.flush();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
getStatistics() {
|
|
186
|
+
return {
|
|
187
|
+
totalLogsAttempted: this.statistics.totalLogsAttempted,
|
|
188
|
+
successfulLogs: this.statistics.successfulLogs,
|
|
189
|
+
failedLogs: this.statistics.failedLogs,
|
|
190
|
+
retriedLogs: this.statistics.retriedLogs,
|
|
191
|
+
averageResponseTimeMs: this.statistics.successfulLogs > 0
|
|
192
|
+
? Math.round(this.statistics.totalResponseTimeMs / this.statistics.successfulLogs)
|
|
193
|
+
: 0,
|
|
194
|
+
queueLength: this.queue?.getLength() || 0,
|
|
195
|
+
};
|
|
196
|
+
}
|
|
197
|
+
resetStatistics() {
|
|
198
|
+
this.statistics = {
|
|
199
|
+
totalLogsAttempted: 0,
|
|
200
|
+
successfulLogs: 0,
|
|
201
|
+
failedLogs: 0,
|
|
202
|
+
retriedLogs: 0,
|
|
203
|
+
totalResponseTimeMs: 0,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
destroy() {
|
|
207
|
+
if (this.queue) {
|
|
208
|
+
this.queue.destroy();
|
|
209
|
+
this.queue = null;
|
|
210
|
+
}
|
|
211
|
+
if (this.config.debug) {
|
|
212
|
+
console.log('[AVSLogger] Destroyed');
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
exports.AVSLogger = AVSLogger;
|
|
217
|
+
exports.default = AVSLogger;
|
|
218
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":";;;AAcA,+CAA2C;AAC3C,6CAAyC;AACzC,mCAAgC;AAChC,2CAA4D;AAE5D,MAAa,SAAS;IAYpB,YAAY,MAAuB;QAT3B,UAAK,GAAiB,IAAI,CAAC;QAC3B,eAAU,GAAG;YACnB,kBAAkB,EAAE,CAAC;YACrB,cAAc,EAAE,CAAC;YACjB,UAAU,EAAE,CAAC;YACb,WAAW,EAAE,CAAC;YACd,mBAAmB,EAAE,CAAC;SACvB,CAAC;QAIA,uBAAU,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;QAGlC,IAAI,CAAC,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAC,OAAO;YACvB,MAAM,EAAE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AG,IAAI,CAAC;QACpB,CAAC;QAED,IAAI,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAC;QACvC,CAAC;IACH,CAAC;CACF;AA9RD,8BA8RC;AAGD,kBAAe,SAAS,CAAC"}
|
package/dist/queue.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { QueueItem } from './types';
|
|
2
|
+
export declare class Queue<T = any> {
|
|
3
|
+
private items;
|
|
4
|
+
private flushTimeout;
|
|
5
|
+
private maxSize;
|
|
6
|
+
private flushIntervalMs;
|
|
7
|
+
private onFlush?;
|
|
8
|
+
constructor(maxSize?: number, flushIntervalMs?: number);
|
|
9
|
+
add(item: Omit<QueueItem<T>, 'id' | 'timestamp' | 'retries'>): Promise<string>;
|
|
10
|
+
getItems(): QueueItem<T>[];
|
|
11
|
+
getLength(): number;
|
|
12
|
+
removeItem(id: string): boolean;
|
|
13
|
+
updateItem(id: string, updates: Partial<QueueItem<T>>): boolean;
|
|
14
|
+
setOnFlush(callback: (items: QueueItem<T>[]) => Promise<void>): void;
|
|
15
|
+
private scheduleFlush;
|
|
16
|
+
flush(): Promise<void>;
|
|
17
|
+
clear(): void;
|
|
18
|
+
destroy(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=queue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.d.ts","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAGpC,qBAAa,KAAK,CAAC,CAAC,GAAG,GAAG;IACxB,OAAO,CAAC,KAAK,CAAsB;IACnC,OAAO,CAAC,YAAY,CAA+B;IACnD,OAAO,CAAC,OAAO,CAAS;IACxB,OAAO,CAAC,eAAe,CAAS;IAChC,OAAO,CAAC,OAAO,CAAC,CAA2C;gBAE/C,OAAO,GAAE,MAAW,EAAE,eAAe,GAAE,MAAa;IAQ1D,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,IAAI,GAAG,WAAW,GAAG,SAAS,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC;IAuBpF,QAAQ,IAAI,SAAS,CAAC,CAAC,CAAC,EAAE;IAO1B,SAAS,IAAI,MAAM;IAOnB,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO;IAY/B,UAAU,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO;IAY/D,UAAU,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI;IAOpE,OAAO,CAAC,aAAa;IAef,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAyB5B,KAAK,IAAI,IAAI;IAWb,OAAO,IAAI,IAAI;CAGhB"}
|
package/dist/queue.js
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Queue = void 0;
|
|
4
|
+
const uuid_1 = require("uuid");
|
|
5
|
+
class Queue {
|
|
6
|
+
constructor(maxSize = 50, flushIntervalMs = 5000) {
|
|
7
|
+
this.items = [];
|
|
8
|
+
this.flushTimeout = null;
|
|
9
|
+
this.maxSize = maxSize;
|
|
10
|
+
this.flushIntervalMs = flushIntervalMs;
|
|
11
|
+
}
|
|
12
|
+
async add(item) {
|
|
13
|
+
const queueItem = {
|
|
14
|
+
...item,
|
|
15
|
+
id: (0, uuid_1.v4)(),
|
|
16
|
+
timestamp: Date.now(),
|
|
17
|
+
retries: 0,
|
|
18
|
+
};
|
|
19
|
+
this.items.push(queueItem);
|
|
20
|
+
if (this.items.length >= this.maxSize) {
|
|
21
|
+
await this.flush();
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
this.scheduleFlush();
|
|
25
|
+
}
|
|
26
|
+
return queueItem.id;
|
|
27
|
+
}
|
|
28
|
+
getItems() {
|
|
29
|
+
return [...this.items];
|
|
30
|
+
}
|
|
31
|
+
getLength() {
|
|
32
|
+
return this.items.length;
|
|
33
|
+
}
|
|
34
|
+
removeItem(id) {
|
|
35
|
+
const index = this.items.findIndex((item) => item.id === id);
|
|
36
|
+
if (index >= 0) {
|
|
37
|
+
this.items.splice(index, 1);
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
updateItem(id, updates) {
|
|
43
|
+
const item = this.items.find((i) => i.id === id);
|
|
44
|
+
if (item) {
|
|
45
|
+
Object.assign(item, updates);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
setOnFlush(callback) {
|
|
51
|
+
this.onFlush = callback;
|
|
52
|
+
}
|
|
53
|
+
scheduleFlush() {
|
|
54
|
+
if (this.flushTimeout) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
this.flushTimeout = setTimeout(() => {
|
|
58
|
+
this.flush().catch((error) => {
|
|
59
|
+
console.error('Queue flush failed:', error);
|
|
60
|
+
});
|
|
61
|
+
}, this.flushIntervalMs);
|
|
62
|
+
}
|
|
63
|
+
async flush() {
|
|
64
|
+
if (this.flushTimeout) {
|
|
65
|
+
clearTimeout(this.flushTimeout);
|
|
66
|
+
this.flushTimeout = null;
|
|
67
|
+
}
|
|
68
|
+
if (this.items.length === 0 || !this.onFlush) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
const itemsToFlush = [...this.items];
|
|
72
|
+
this.items = [];
|
|
73
|
+
try {
|
|
74
|
+
await this.onFlush(itemsToFlush);
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
this.items = itemsToFlush.concat(this.items);
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
clear() {
|
|
82
|
+
this.items = [];
|
|
83
|
+
if (this.flushTimeout) {
|
|
84
|
+
clearTimeout(this.flushTimeout);
|
|
85
|
+
this.flushTimeout = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
destroy() {
|
|
89
|
+
this.clear();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.Queue = Queue;
|
|
93
|
+
//# sourceMappingURL=queue.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"queue.js","sourceRoot":"","sources":["../src/queue.ts"],"names":[],"mappings":";;;AAKA,+BAAoC;AAEpC,MAAa,KAAK;IAOhB,YAAY,UAAkB,EAAE,EAAE,kBAA0B,IAAI;QANxD,UAAK,GAAmB,EAAE,CAAC;QAC3B,iBAAY,GAA0B,IAAI,CAAC;QAMjD,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;QACvB,IAAI,CAAC,eAAe,GAAG,eAAe,CAAC;IACzC,CAAC;IAKD,KAAK,CAAC,GAAG,CAAC,IAAwD;QAChE,MAAM,SAAS,GAAiB;YAC9B,GAAG,IAAI;YACP,EAAE,EAAE,IAAA,SAAM,GAAE;YACZ,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE;YACrB,OAAO,EAAE,CAAC;SACX,CAAC;QAEF,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QAG3B,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;YACtC,MAAM,IAAI,CAAC,KAAK,EAAE,CAAC;QACrB,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,aAAa,EAAE,CAAC;QACvB,CAAC;QAED,OAAO,SAAS,CAAC,EAAE,CAAC;IACtB,CAAC;IAKD,QAAQ;QACN,OAAO,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;IACzB,CAAC;I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E,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;QAED,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YAC7C,OAAO;QACT,CAAC;QAED,MAAM,YAAY,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAEhB,IAAI,CAAC;YACH,MAAM,IAAI,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;QACnC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YAEf,IAAI,CAAC,KAAK,GAAG,YAAY,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;YAC7C,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;IAKD,KAAK;QACH,IAAI,CAAC,KAAK,GAAG,EAAE,CAAC;QAChB,IAAI,IAAI,CAAC,YAAY,EAAE,CAAC;YACtB,YAAY,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;YAChC,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC;QAC3B,CAAC;IACH,CAAC;IAKD,OAAO;QACL,IAAI,CAAC,KAAK,EAAE,CAAC;IACf,CAAC;CACF;AAzID,sBAyIC"}
|
package/dist/retry.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { RetryPolicy } from './types';
|
|
2
|
+
export declare class RetryManager {
|
|
3
|
+
private policy;
|
|
4
|
+
constructor(policy?: Partial<RetryPolicy>);
|
|
5
|
+
getBackoffDelay(attempt: number): number;
|
|
6
|
+
isRetryable(error: any, statusCode?: number): boolean;
|
|
7
|
+
shouldRetry(attempt: number): boolean;
|
|
8
|
+
executeWithRetry<T>(fn: () => Promise<T>, onRetry?: (attempt: number, error: Error, nextDelay: number) => void): Promise<T>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAGtC,qBAAa,YAAY;IACvB,OAAO,CAAC,MAAM,CAAc;gBAEhB,MAAM,GAAE,OAAO,CAAC,WAAW,CAAM;IAU7C,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM;IAgBxC,WAAW,CAAC,KAAK,EAAE,GAAG,EAAE,UAAU,CAAC,EAAE,MAAM,GAAG,OAAO;IAiBrD,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO;IAO/B,gBAAgB,CAAC,CAAC,EACtB,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EACpB,OAAO,CAAC,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,KAAK,IAAI,GACnE,OAAO,CAAC,CAAC,CAAC;CA0Bd"}
|
package/dist/retry.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.RetryManager = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
class RetryManager {
|
|
6
|
+
constructor(policy = {}) {
|
|
7
|
+
this.policy = {
|
|
8
|
+
...constants_1.RETRY_CONFIG,
|
|
9
|
+
...policy,
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
getBackoffDelay(attempt) {
|
|
13
|
+
const exponentialDelay = this.policy.initialDelayMs * Math.pow(this.policy.multiplier, attempt);
|
|
14
|
+
const cappedDelay = Math.min(exponentialDelay, this.policy.maxDelayMs);
|
|
15
|
+
const jitter = cappedDelay * 0.1 * (Math.random() - 0.5) * 2;
|
|
16
|
+
return Math.max(1, cappedDelay + jitter);
|
|
17
|
+
}
|
|
18
|
+
isRetryable(error, statusCode) {
|
|
19
|
+
if (!error.response) {
|
|
20
|
+
return true;
|
|
21
|
+
}
|
|
22
|
+
if (statusCode) {
|
|
23
|
+
return this.policy.retryableStatusCodes.includes(statusCode);
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
shouldRetry(attempt) {
|
|
28
|
+
return attempt < this.policy.maxAttempts;
|
|
29
|
+
}
|
|
30
|
+
async executeWithRetry(fn, onRetry) {
|
|
31
|
+
let lastError;
|
|
32
|
+
for (let attempt = 0; attempt < this.policy.maxAttempts; attempt++) {
|
|
33
|
+
try {
|
|
34
|
+
return await fn();
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
38
|
+
if (!this.isRetryable(error) || !this.shouldRetry(attempt + 1)) {
|
|
39
|
+
throw error;
|
|
40
|
+
}
|
|
41
|
+
const delay = this.getBackoffDelay(attempt);
|
|
42
|
+
if (onRetry) {
|
|
43
|
+
onRetry(attempt + 1, lastError, delay);
|
|
44
|
+
}
|
|
45
|
+
await new Promise((resolve) => setTimeout(resolve, delay));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw lastError || new Error('Failed after all retry attempts');
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
exports.RetryManager = RetryManager;
|
|
52
|
+
//# sourceMappingURL=retry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.js","sourceRoot":"","sources":["../src/retry.ts"],"names":[],"mappings":";;;AAKA,2CAA2C;AAE3C,MAAa,YAAY;IAGvB,YAAY,SAA+B,EAAE;QAC3C,IAAI,CAAC,MAAM,GAAG;YACZ,GAAG,wBAAY;YACf,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAKD,eAAe,CAAC,OAAe;QAE7B,MAAM,gBAAgB,GAAG,IAAI,CAAC,MAAM,CAAC,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CAAC,WAAW,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC;oBAC/D,MAAM,KAAK,CAAC;gBACd,CAAC;gBAED,MAAM,KAAK,GAAG,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,CAAC;gBAE5C,IAAI,OAAO,EAAE,CAAC;oBACZ,OAAO,CAAC,OAAO,GAAG,CAAC,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;gBACzC,CAAC;gBAGD,MAAM,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC,CAAC;YAC7D,CAAC;QACH,CAAC;QAED,MAAM,SAAS,IAAI,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAC;IAClE,CAAC;CACF;AAlFD,oCAkFC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
export interface Actor {
|
|
2
|
+
userId?: string;
|
|
3
|
+
email?: string;
|
|
4
|
+
username?: string;
|
|
5
|
+
ipAddress?: string;
|
|
6
|
+
userAgent?: string;
|
|
7
|
+
[key: string]: string | undefined;
|
|
8
|
+
}
|
|
9
|
+
export interface Entity {
|
|
10
|
+
type: string;
|
|
11
|
+
id: string;
|
|
12
|
+
[key: string]: string;
|
|
13
|
+
}
|
|
14
|
+
export type LogLevel = 'debug' | 'info' | 'warn' | 'error';
|
|
15
|
+
export interface GenericLog {
|
|
16
|
+
project: string;
|
|
17
|
+
message?: string;
|
|
18
|
+
level: LogLevel;
|
|
19
|
+
userId?: string;
|
|
20
|
+
meta?: Record<string, any>;
|
|
21
|
+
timestamp?: string;
|
|
22
|
+
}
|
|
23
|
+
export interface AuditLog {
|
|
24
|
+
project: string;
|
|
25
|
+
actor: Actor;
|
|
26
|
+
action: string;
|
|
27
|
+
entity: Entity;
|
|
28
|
+
metadata?: Record<string, any>;
|
|
29
|
+
timestamp?: string;
|
|
30
|
+
}
|
|
31
|
+
export interface AccessLog {
|
|
32
|
+
project: string;
|
|
33
|
+
endpoint: string;
|
|
34
|
+
method: string;
|
|
35
|
+
statusCode: number;
|
|
36
|
+
ip: string;
|
|
37
|
+
responseTimeMs: number;
|
|
38
|
+
userId?: string;
|
|
39
|
+
timestamp?: string;
|
|
40
|
+
userAgent?: string;
|
|
41
|
+
}
|
|
42
|
+
export interface ErrorLog {
|
|
43
|
+
project: string;
|
|
44
|
+
message: string;
|
|
45
|
+
stack?: string;
|
|
46
|
+
context?: Record<string, any>;
|
|
47
|
+
userId?: string;
|
|
48
|
+
ip?: string;
|
|
49
|
+
timestamp?: string;
|
|
50
|
+
}
|
|
51
|
+
export interface AVSLoggerConfig {
|
|
52
|
+
project: string;
|
|
53
|
+
apiKey: string;
|
|
54
|
+
endpoint?: string;
|
|
55
|
+
timeout?: number;
|
|
56
|
+
enableQueue?: boolean;
|
|
57
|
+
batchSize?: number;
|
|
58
|
+
batchTimeout?: number;
|
|
59
|
+
maxRetries?: number;
|
|
60
|
+
initialRetryDelay?: number;
|
|
61
|
+
debug?: boolean;
|
|
62
|
+
customHeaders?: Record<string, string>;
|
|
63
|
+
onFatalError: (error: Error) => void;
|
|
64
|
+
}
|
|
65
|
+
export interface LogResponse {
|
|
66
|
+
status: 'queued' | 'processed' | 'error';
|
|
67
|
+
message: string;
|
|
68
|
+
id?: string;
|
|
69
|
+
error?: string;
|
|
70
|
+
}
|
|
71
|
+
export interface RetryPolicy {
|
|
72
|
+
maxAttempts: number;
|
|
73
|
+
initialDelayMs: number;
|
|
74
|
+
multiplier: number;
|
|
75
|
+
maxDelayMs: number;
|
|
76
|
+
retryableStatusCodes: readonly number[];
|
|
77
|
+
}
|
|
78
|
+
export interface QueueItem<T = any> {
|
|
79
|
+
id: string;
|
|
80
|
+
type: 'log' | 'audit' | 'access' | 'error';
|
|
81
|
+
data: T;
|
|
82
|
+
timestamp: number;
|
|
83
|
+
retries: number;
|
|
84
|
+
error?: string;
|
|
85
|
+
}
|
|
86
|
+
export interface LogResult {
|
|
87
|
+
success: boolean;
|
|
88
|
+
message: string;
|
|
89
|
+
id?: string;
|
|
90
|
+
}
|
|
91
|
+
export interface SDKStatistics {
|
|
92
|
+
totalLogsAttempted: number;
|
|
93
|
+
successfulLogs: number;
|
|
94
|
+
failedLogs: number;
|
|
95
|
+
retriedLogs: number;
|
|
96
|
+
averageResponseTimeMs: number;
|
|
97
|
+
queueLength: number;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,KAAK;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC;CACnC;AAMD,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;CACvB;AAMD,MAAM,MAAM,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC;AAE3D,MAAM,WAAW,UAAU;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,QAAQ,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC3B,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,QAAQ;IACvB,OAA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":[],"mappings":""}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { GenericLog, AuditLog, AccessLog, ErrorLog, AVSLoggerConfig } from './types';
|
|
2
|
+
export declare class ValidationError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class Validators {
|
|
6
|
+
static validateConfig(config: AVSLoggerConfig): void;
|
|
7
|
+
static validateGenericLog(log: GenericLog): void;
|
|
8
|
+
static validateAuditLog(log: AuditLog): void;
|
|
9
|
+
static validateAccessLog(log: AccessLog): void;
|
|
10
|
+
static validateErrorLog(log: ErrorLog): void;
|
|
11
|
+
static isValidUrl(url: string): boolean;
|
|
12
|
+
static sanitizeObject(obj: any, sensitiveFields?: string[]): any;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=validators.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.ts","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,QAAQ,EAAE,SAAS,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAGrF,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,UAAU;IAIrB,MAAM,CAAC,cAAc,CAAC,MAAM,EAAE,eAAe,GAAG,IAAI;IAyBpD,MAAM,CAAC,kBAAkB,CAAC,GAAG,EAAE,UAAU,GAAG,IAAI;IAiBhD,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IA6B5C,MAAM,CAAC,iBAAiB,CAAC,GAAG,EAAE,SAAS,GAAG,IAAI;IA6B9C,MAAM,CAAC,gBAAgB,CAAC,GAAG,EAAE,QAAQ,GAAG,IAAI;IAa5C,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAYvC,MAAM,CAAC,cAAc,CAAC,GAAG,EAAE,GAAG,EAAE,eAAe,GAAE,MAAM,EAAO,GAAG,GAAG;CAkBrE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Validators = exports.ValidationError = void 0;
|
|
4
|
+
const constants_1 = require("./constants");
|
|
5
|
+
class ValidationError extends Error {
|
|
6
|
+
constructor(message) {
|
|
7
|
+
super(message);
|
|
8
|
+
this.name = 'ValidationError';
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.ValidationError = ValidationError;
|
|
12
|
+
class Validators {
|
|
13
|
+
static validateConfig(config) {
|
|
14
|
+
if (!config.project || config.project.trim() === '') {
|
|
15
|
+
throw new ValidationError(constants_1.ERROR_MESSAGES.MISSING_PROJECT);
|
|
16
|
+
}
|
|
17
|
+
if (!config.apiKey || config.apiKey.trim() === '') {
|
|
18
|
+
throw new ValidationError(constants_1.ERROR_MESSAGES.MISSING_API_KEY);
|
|
19
|
+
}
|
|
20
|
+
if (config.endpoint && !Validators.isValidUrl(config.endpoint)) {
|
|
21
|
+
throw new ValidationError(constants_1.ERROR_MESSAGES.INVALID_ENDPOINT);
|
|
22
|
+
}
|
|
23
|
+
if (config.timeout && config.timeout < 0) {
|
|
24
|
+
throw new ValidationError('Timeout must be a positive number');
|
|
25
|
+
}
|
|
26
|
+
if (config.maxRetries && config.maxRetries < 0) {
|
|
27
|
+
throw new ValidationError('Max retries must be a non-negative number');
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
static validateGenericLog(log) {
|
|
31
|
+
if (!log.project || log.project.trim() === '') {
|
|
32
|
+
throw new ValidationError('Log project is required');
|
|
33
|
+
}
|
|
34
|
+
if (!log.message || log.message.trim() === '') {
|
|
35
|
+
throw new ValidationError('Log message is required');
|
|
36
|
+
}
|
|
37
|
+
if (!['debug', 'info', 'warn', 'error'].includes(log.level)) {
|
|
38
|
+
throw new ValidationError('Invalid log level');
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
static validateAuditLog(log) {
|
|
42
|
+
if (!log.project || log.project.trim() === '') {
|
|
43
|
+
throw new ValidationError('Project is required');
|
|
44
|
+
}
|
|
45
|
+
if (!log.actor || typeof log.actor !== 'object') {
|
|
46
|
+
throw new ValidationError('Actor is required and must be an object');
|
|
47
|
+
}
|
|
48
|
+
if (!log.action || log.action.trim() === '') {
|
|
49
|
+
throw new ValidationError('Action is required');
|
|
50
|
+
}
|
|
51
|
+
if (!log.entity || typeof log.entity !== 'object') {
|
|
52
|
+
throw new ValidationError('Entity is required and must be an object');
|
|
53
|
+
}
|
|
54
|
+
if (!log.entity.type || log.entity.type.trim() === '') {
|
|
55
|
+
throw new ValidationError('Entity type is required');
|
|
56
|
+
}
|
|
57
|
+
if (!log.entity.id || log.entity.id.toString().trim() === '') {
|
|
58
|
+
throw new ValidationError('Entity ID is required');
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
static validateAccessLog(log) {
|
|
62
|
+
if (!log.project || log.project.trim() === '') {
|
|
63
|
+
throw new ValidationError('Project is required');
|
|
64
|
+
}
|
|
65
|
+
if (!log.endpoint || log.endpoint.trim() === '') {
|
|
66
|
+
throw new ValidationError('Endpoint is required');
|
|
67
|
+
}
|
|
68
|
+
if (!log.method || log.method.trim() === '') {
|
|
69
|
+
throw new ValidationError('Method is required');
|
|
70
|
+
}
|
|
71
|
+
if (!Number.isInteger(log.statusCode) || log.statusCode < 100 || log.statusCode >= 600) {
|
|
72
|
+
throw new ValidationError('Status code must be a valid HTTP status code');
|
|
73
|
+
}
|
|
74
|
+
if (!log.ip || log.ip.trim() === '') {
|
|
75
|
+
throw new ValidationError('IP address is required');
|
|
76
|
+
}
|
|
77
|
+
if (typeof log.responseTimeMs !== 'number' || log.responseTimeMs < 0) {
|
|
78
|
+
throw new ValidationError('Response time must be a non-negative number');
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
static validateErrorLog(log) {
|
|
82
|
+
if (!log.project || log.project.trim() === '') {
|
|
83
|
+
throw new ValidationError('Project is required');
|
|
84
|
+
}
|
|
85
|
+
if (!log.message || log.message.trim() === '') {
|
|
86
|
+
throw new ValidationError('Error message is required');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
static isValidUrl(url) {
|
|
90
|
+
try {
|
|
91
|
+
new URL(url);
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
static sanitizeObject(obj, sensitiveFields = []) {
|
|
99
|
+
if (!obj || typeof obj !== 'object') {
|
|
100
|
+
return obj;
|
|
101
|
+
}
|
|
102
|
+
const sensitiveDefaults = ['password', 'token', 'secret', 'apiKey', 'creditCard', 'ssn'];
|
|
103
|
+
const allSensitiveFields = [...sensitiveDefaults, ...sensitiveFields];
|
|
104
|
+
const sanitized = { ...obj };
|
|
105
|
+
for (const field of allSensitiveFields) {
|
|
106
|
+
if (field in sanitized && sanitized[field]) {
|
|
107
|
+
sanitized[field] = '***REDACTED***';
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
return sanitized;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
exports.Validators = Validators;
|
|
114
|
+
//# sourceMappingURL=validators.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.js","sourceRoot":"","sources":["../src/validators.ts"],"names":[],"mappings":";;;AAKA,2CAA6C;AAE7C,MAAa,eAAgB,SAAQ,KAAK;IACxC,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AALD,0CAKC;AAED,MAAa,UAAU;IAIrB,MAAM,CAAC,cAAc,CAAC,MAAuB;QAC3C,IAAI,CAAC,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC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AAI,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,KAAK,EAAE,EAAE,CAAC;YAC9C,MAAM,IAAI,eAAe,CAAC,2BAA2B,CAAC,CAAC;QACzD,CAAC;IACH,CAAC;IAKD,MAAM,CAAC,UAAU,CAAC,GAAW;QAC3B,IAAI,CAAC;YACH,IAAI,GAAG,CAAC,GAAG,CAAC,CAAC;YACb,OAAO,IAAI,CAAC;QACd,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAKD,MAAM,CAAC,cAAc,CAAC,GAAQ,EAAE,kBAA4B,EAAE;QAC5D,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;YACpC,OAAO,GAAG,CAAC;QACb,CAAC;QAED,MAAM,iBAAiB,GAAG,CAAC,UAAU,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,YAAY,EAAE,KAAK,CAAC,CAAC;QACzF,MAAM,kBAAkB,GAAG,CAAC,GAAG,iBAAiB,EAAE,GAAG,eAAe,CAAC,CAAC;QAEtE,MAAM,SAAS,GAAG,EAAE,GAAG,GAAG,EAAE,CAAC;QAE7B,KAAK,MAAM,KAAK,IAAI,kBAAkB,EAAE,CAAC;YACvC,IAAI,KAAK,IAAI,SAAS,IAAI,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC;gBAC3C,SAAS,CAAC,KAAK,CAAC,GAAG,gBAAgB,CAAC;YACtC,CAAC;QACH,CAAC;QAED,OAAO,SAAS,CAAC;IACnB,CAAC;CACF;AAnJD,gCAmJC"}
|
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@avss-tech/logger",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
4
4
|
"description": "TypeScript client SDK for AVS Centralized Logging Platform",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
|
-
"files": [
|
|
7
|
+
"files": [
|
|
8
|
+
"dist"
|
|
9
|
+
],
|
|
8
10
|
"scripts": {
|
|
9
11
|
"build": "tsc",
|
|
10
12
|
"watch": "tsc --watch",
|
|
11
|
-
"clean": "
|
|
13
|
+
"clean": "rimraf dist",
|
|
12
14
|
"prebuild": "npm run clean",
|
|
13
15
|
"test": "jest",
|
|
14
16
|
"test:watch": "jest --watch",
|
|
@@ -26,20 +28,21 @@
|
|
|
26
28
|
"author": "Your Organization",
|
|
27
29
|
"license": "MIT",
|
|
28
30
|
"dependencies": {
|
|
29
|
-
"uuid": "^9.0.
|
|
31
|
+
"uuid": "^9.0.1"
|
|
30
32
|
},
|
|
31
33
|
"devDependencies": {
|
|
34
|
+
"@types/jest": "^29.0.0",
|
|
32
35
|
"@types/node": "^20.0.0",
|
|
33
|
-
"
|
|
36
|
+
"@types/uuid": "^10.0.0",
|
|
34
37
|
"@typescript-eslint/eslint-plugin": "^6.0.0",
|
|
35
38
|
"@typescript-eslint/parser": "^6.0.0",
|
|
36
39
|
"eslint": "^8.0.0",
|
|
37
|
-
"prettier": "^3.0.0",
|
|
38
40
|
"jest": "^29.0.0",
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
+
"prettier": "^3.0.0",
|
|
42
|
+
"rimraf": "^6.1.2",
|
|
43
|
+
"ts-jest": "^29.0.0",
|
|
44
|
+
"typescript": "^5.0.0"
|
|
41
45
|
},
|
|
42
|
-
"peerDependencies": {},
|
|
43
46
|
"engines": {
|
|
44
47
|
"node": ">=16.0.0"
|
|
45
48
|
},
|