@meistrari/audit-sdk 0.0.0 → 0.2.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/dist/client.d.ts +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +15 -10
- package/dist/index.d.ts.map +1 -1
- package/package.json +29 -28
package/dist/client.d.ts
CHANGED
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,QAAQ,GAAG,IAAI,CAAA;AAEjD,MAAM,WAAW,UAAU;IACvB,MAAM,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,MAAM,CAAA;IACnB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,MAAM,EAAE,WAAW,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IAC1C,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACrC;AAED,MAAM,WAAW,iBAAiB;IAC9B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,MAAM,CAAA;CACtB;AAED,qBAAa,WAAW;IACpB,OAAO,CAAC,OAAO,CAAQ;IACvB,OAAO,CAAC,SAAS,CAAQ;IACzB,OAAO,CAAC,UAAU,CAAQ;gBAEd,MAAM,EAAE,iBAAiB;IAY/B,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,KAAK,EAAE,UAAU;IAI1C,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,UAAU,EAAE;IA6CvD,OAAO,CAAC,UAAU;YAaJ,KAAK;CAGtB;AAED,qBAAa,UAAW,SAAQ,KAAK;IACG,OAAO,CAAC,EAAE,OAAO;gBAAzC,OAAO,EAAE,MAAM,EAAS,OAAO,CAAC,EAAE,OAAO,YAAA;CAIxD"}
|
package/dist/client.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import process from 'node:process';
|
|
2
|
+
import pino from '@meistrari/logger';
|
|
3
|
+
const logger = pino();
|
|
1
4
|
export class AuditClient {
|
|
2
5
|
constructor(config) {
|
|
3
|
-
|
|
6
|
+
const baseUrl = config.baseUrl || process.env.AUDIT_API_BASE_URL;
|
|
7
|
+
if (!baseUrl) {
|
|
8
|
+
throw new Error('AuditClient requires a baseUrl');
|
|
9
|
+
}
|
|
10
|
+
this.baseUrl = baseUrl.replace(/\/$/, '');
|
|
4
11
|
this.timeoutMs = config.timeoutMs ?? 5000;
|
|
5
12
|
this.maxRetries = config.maxRetries ?? 3;
|
|
6
13
|
}
|
|
@@ -14,7 +21,7 @@ export class AuditClient {
|
|
|
14
21
|
const response = await fetch(`${this.baseUrl}/v1/events`, {
|
|
15
22
|
method: 'POST',
|
|
16
23
|
headers: {
|
|
17
|
-
Authorization: `Bearer ${dataToken}`,
|
|
24
|
+
'Authorization': `Bearer ${dataToken}`,
|
|
18
25
|
'Content-Type': 'application/json',
|
|
19
26
|
},
|
|
20
27
|
body: JSON.stringify({ events }),
|
|
@@ -40,7 +47,7 @@ export class AuditClient {
|
|
|
40
47
|
}
|
|
41
48
|
lastError = error;
|
|
42
49
|
}
|
|
43
|
-
await this.sleep(
|
|
50
|
+
await this.sleep(2 ** attempt * 1000);
|
|
44
51
|
}
|
|
45
52
|
this.logFailure(events, lastError);
|
|
46
53
|
}
|
|
@@ -50,15 +57,13 @@ export class AuditClient {
|
|
|
50
57
|
service: 'audit-sdk',
|
|
51
58
|
message: 'Failed to send audit events after retries',
|
|
52
59
|
event_count: events.length,
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
error: error?.message,
|
|
56
|
-
timestamp: new Date().toISOString(),
|
|
60
|
+
events,
|
|
61
|
+
error,
|
|
57
62
|
};
|
|
58
|
-
|
|
63
|
+
logger.error(payload);
|
|
59
64
|
}
|
|
60
|
-
sleep(ms) {
|
|
61
|
-
|
|
65
|
+
async sleep(ms) {
|
|
66
|
+
await new Promise(resolve => setTimeout(resolve, ms));
|
|
62
67
|
}
|
|
63
68
|
}
|
|
64
69
|
export class AuditError extends Error {
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,30 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
2
|
+
"name": "@meistrari/audit-sdk",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"description": "",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "git+https://github.com/meistrari/audit-service.git"
|
|
10
|
+
},
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
|
+
"files": [
|
|
13
|
+
"dist"
|
|
14
|
+
],
|
|
15
|
+
"scripts": {
|
|
16
|
+
"build": "tsc -p tsconfig.json",
|
|
17
|
+
"postinstall": "mise-en-place postinstall",
|
|
18
|
+
"clean": "rm -rf dist"
|
|
19
|
+
},
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=18"
|
|
22
|
+
},
|
|
23
|
+
"devDependencies": {
|
|
24
|
+
"@meistrari/mise-en-place": "^2.10.2",
|
|
25
|
+
"@types/node": "^25.2.3",
|
|
26
|
+
"typescript": "^5.3.3"
|
|
27
|
+
},
|
|
28
|
+
"dependencies": {
|
|
29
|
+
"@meistrari/logger": "^2.1.3"
|
|
30
|
+
}
|
|
30
31
|
}
|