@payfit/audit-log 3.17.3 → 3.17.5
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/index.js +1 -1
- package/dist/index.mjs +9 -9
- package/package.json +9 -9
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var w=Object.defineProperty;var f=(s,e,t)=>e in s?w(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>f(s,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const v=require("uuid"),o=require("winston"),S=require("hot-shots"),h=require("@aws-sdk/client-sqs"),E=require("zlib"),y="audit-logs",_="@payfit/audit-log",q=()=>{const s=process.env.LOG_LEVEL;return s&&s.trim()!==""?s.trim():"info"},L=(s,e)=>o.createLogger({level:q(),silent:process.env.NODE_ENV==="test",exitOnError:!1,defaultMeta:{namespace:y,sdk:_,service:s,environment:e},format:o.format.combine(o.format.timestamp(),o.format.errors({stack:!0}),o.format.json()),transports:[new o.transports.Console]}),M="payfit.audit_logs.",p=s=>Object.entries(s).filter(([,e])=>e!==void 0&&e!=="").map(([e,t])=>`${e}:${String(t)}`);class b{constructor(){i(this,"client");this.client=new S.StatsD({prefix:M,errorHandler:()=>{},cacheDns:!0})}increment(e,t){this.client.increment(e,1,p(t))}histogram(e,t,n){this.client.histogram(e,t,p(n))}async close(){await new Promise(e=>{this.client.close(()=>e())})}}const A=()=>new b;function U(s){return E.brotliCompressSync(new TextEncoder().encode(s)).toString("base64")}function C(s){return s instanceof Error&&s.message.includes("Message must be shorter than")}const O="eu-west-3",z={dev:"https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",staging:"https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",prod:"https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"},D={working:"staging",production:"prod",development:"dev"};class N{constructor(e,t){i(this,"environment");i(this,"logger");i(this,"client");i(this,"queueUrl");this.environment=e,this.logger=t;const n=D[e]??e;if(this.queueUrl=z[n],!this.queueUrl){t==null||t.warn("audit-logs SDK: no SQS queue URL configured for this environment, audit logs are disabled",{environment:e});return}this.client=new h.SQSClient({region:O})}async create(e){var n;if(!this.client||!this.queueUrl)return{compressed:!1};const t=JSON.stringify(e);try{return await this.send(t),{compressed:!1}}catch(c){if(!C(c))throw c;return(n=this.logger)==null||n.info("audit-log payload exceeds the SQS size limit, retrying with Brotli compression",{id:e.id,namespace:e.namespace}),await this.send(U(t)),{compressed:!0}}}async send(e){await this.client.send(new h.SendMessageCommand({QueueUrl:this.queueUrl,MessageBody:e}))}}class T{constructor(e,t={}){i(this,"params");i(this,"transport");i(this,"logger");i(this,"metrics");this.params=e,this.logger=t.logger??L(e.service,e.environment),this.transport=t.transport??new N(e.environment,this.logger),this.metrics=t.metrics??A()}async log({scope:e,account:t,...n}){const c=v.v4(),{environment:g,service:d}=this.params,r={...n,...t,service:d,id:c,environment:g,...e&&{scope:e}},a={service:d,environment:g,namespace:r.namespace,event:r.event,target:r.target},u=Date.now();try{const{compressed:l}=await this.transport.create(r);this.metrics.increment("sent",{...a,compressed:String(l)}),this.metrics.histogram("send_duration_ms",Date.now()-u,a),this.logger.debug("audit-log sent",{id:r.id,event:r.event,target:r.target})}catch(l){this.metrics.increment("send_failed",a),this.metrics.histogram("send_duration_ms",Date.now()-u,a);const m=l.message;try{this.logger.error("audit-log write failed",{audit_log:r,error:m})}catch{this.metrics.increment("serialization_failed",a);try{this.logger.error("audit-log write failed (serialization failed)",{audit_log_meta:{id:r.id,service:r.service,environment:r.environment,namespace:r.namespace,event:r.event,target:r.target},error:m})}catch{}}}}}exports.AuditLogger=T;
|
package/dist/index.mjs
CHANGED
|
@@ -47,29 +47,29 @@ class b {
|
|
|
47
47
|
}
|
|
48
48
|
const D = () => new b();
|
|
49
49
|
function N(s) {
|
|
50
|
-
return L(
|
|
50
|
+
return L(new TextEncoder().encode(s)).toString("base64");
|
|
51
51
|
}
|
|
52
52
|
function O(s) {
|
|
53
53
|
return s instanceof Error && s.message.includes("Message must be shorter than");
|
|
54
54
|
}
|
|
55
|
-
const z = "eu-west-3",
|
|
55
|
+
const z = "eu-west-3", x = {
|
|
56
56
|
dev: "https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",
|
|
57
57
|
staging: "https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",
|
|
58
58
|
prod: "https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"
|
|
59
|
-
},
|
|
59
|
+
}, Q = {
|
|
60
60
|
working: "staging",
|
|
61
61
|
production: "prod",
|
|
62
62
|
development: "dev"
|
|
63
63
|
};
|
|
64
|
-
class
|
|
64
|
+
class R {
|
|
65
65
|
constructor(e, t) {
|
|
66
66
|
i(this, "environment");
|
|
67
67
|
i(this, "logger");
|
|
68
68
|
i(this, "client");
|
|
69
69
|
i(this, "queueUrl");
|
|
70
70
|
this.environment = e, this.logger = t;
|
|
71
|
-
const n =
|
|
72
|
-
if (this.queueUrl =
|
|
71
|
+
const n = Q[e] ?? e;
|
|
72
|
+
if (this.queueUrl = x[n], !this.queueUrl) {
|
|
73
73
|
t == null || t.warn("audit-logs SDK: no SQS queue URL configured for this environment, audit logs are disabled", { environment: e });
|
|
74
74
|
return;
|
|
75
75
|
}
|
|
@@ -95,13 +95,13 @@ class k {
|
|
|
95
95
|
}));
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
|
-
class
|
|
98
|
+
class j {
|
|
99
99
|
constructor(e, t = {}) {
|
|
100
100
|
i(this, "params");
|
|
101
101
|
i(this, "transport");
|
|
102
102
|
i(this, "logger");
|
|
103
103
|
i(this, "metrics");
|
|
104
|
-
this.params = e, this.logger = t.logger ?? q(e.service, e.environment), this.transport = t.transport ?? new
|
|
104
|
+
this.params = e, this.logger = t.logger ?? q(e.service, e.environment), this.transport = t.transport ?? new R(e.environment, this.logger), this.metrics = t.metrics ?? D();
|
|
105
105
|
}
|
|
106
106
|
async log({ scope: e, account: t, ...n }) {
|
|
107
107
|
const a = w(), { environment: l, service: g } = this.params, r = {
|
|
@@ -157,5 +157,5 @@ class V {
|
|
|
157
157
|
}
|
|
158
158
|
}
|
|
159
159
|
export {
|
|
160
|
-
|
|
160
|
+
j as AuditLogger
|
|
161
161
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payfit/audit-log",
|
|
3
|
-
"version": "3.17.
|
|
3
|
+
"version": "3.17.5",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/PayFit/audit-logs.git",
|
|
@@ -31,22 +31,22 @@
|
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|
|
33
33
|
"@payfit/eslint-config-node": "1.1.0",
|
|
34
|
-
"@rollup/plugin-typescript": "11.1.
|
|
35
|
-
"@tsconfig/node18": "18.2.2",
|
|
34
|
+
"@rollup/plugin-typescript": "11.1.6",
|
|
36
35
|
"@tsconfig/strictest": "2.0.2",
|
|
37
36
|
"@types/lodash": "4.14.202",
|
|
38
37
|
"@types/node": "20.10.6",
|
|
39
38
|
"@types/uuid": "9.0.7",
|
|
40
|
-
"@typescript-eslint/eslint-plugin": "
|
|
41
|
-
"@typescript-eslint/parser": "
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "8.70.0",
|
|
40
|
+
"@typescript-eslint/parser": "8.70.0",
|
|
41
|
+
"@typescript/native": "npm:typescript@^7.0.2",
|
|
42
42
|
"builtin-modules": "3.3.0",
|
|
43
|
-
"eslint": "8.
|
|
43
|
+
"eslint": "8.57.0",
|
|
44
44
|
"prettier": "3.1.1",
|
|
45
|
-
"rimraf": "5.0.
|
|
45
|
+
"rimraf": "5.0.10",
|
|
46
46
|
"ts-node": "10.9.2",
|
|
47
|
-
"typescript": "
|
|
47
|
+
"typescript": "npm:@typescript/typescript6@^6.0.2",
|
|
48
48
|
"vite": "^6.0.0",
|
|
49
|
-
"vitest": "4.1.
|
|
49
|
+
"vitest": "4.1.11"
|
|
50
50
|
},
|
|
51
51
|
"publishConfig": {
|
|
52
52
|
"registry": "https://registry.npmjs.org/",
|