@payfit/audit-log 3.6.1 → 3.7.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/README.md +1 -2
- package/dist/index.d.ts +2 -1
- package/dist/index.js +1 -1
- package/dist/index.mjs +64 -133
- package/dist/index.test.d.ts +1 -0
- package/dist/transport/implementation.d.ts +6 -6
- package/dist/transport/implementation.test.d.ts +1 -0
- package/dist/transport/interface.d.ts +0 -1
- package/package.json +8 -4
package/README.md
CHANGED
|
@@ -16,8 +16,7 @@ Then, you must instanciate a client :
|
|
|
16
16
|
import { AuditLogger } from '@payfit/audit-log'
|
|
17
17
|
|
|
18
18
|
const logger = new AuditLogger({
|
|
19
|
-
|
|
20
|
-
environment: 'an-environment-name',
|
|
19
|
+
environment: 'dev', // must be one of: dev, staging, prod
|
|
21
20
|
service: 'the-name-of-the-service',
|
|
22
21
|
})
|
|
23
22
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -92,7 +92,8 @@ export interface IAuditLogger {
|
|
|
92
92
|
log: (data: IAuditLogData) => Promise<void>;
|
|
93
93
|
}
|
|
94
94
|
export interface IAuditLoggerInitialization {
|
|
95
|
-
|
|
95
|
+
/** @deprecated No longer used. The library routes via SQS based on `environment`. Kept for backward compatibility. */
|
|
96
|
+
apiUrl?: string;
|
|
96
97
|
environment: string;
|
|
97
98
|
service: string;
|
|
98
99
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var d=Object.defineProperty;var
|
|
1
|
+
"use strict";var d=Object.defineProperty;var m=(r,e,t)=>e in r?d(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var n=(r,e,t)=>(m(r,typeof e!="symbol"?e+"":e,t),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const w=require("uuid"),i=require("@aws-sdk/client-sqs"),p="eu-west-3",S={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"},h={working:"staging",production:"prod"};class v{constructor(e){n(this,"environment");n(this,"client");n(this,"queueUrl");this.environment=e;const t=h[e]??e,o=S[t];if(!o)throw new Error(`audit-logs SDK: no SQS queue URL configured for environment "${e}"`);this.queueUrl=o,this.client=new i.SQSClient({region:p})}async create(e){await this.client.send(new i.SendMessageCommand({QueueUrl:this.queueUrl,MessageBody:JSON.stringify(e)}))}}class q{constructor(e){n(this,"params");n(this,"transport");this.params=e,this.transport=new v(e.environment)}async log({scope:e,account:t,...o}){const c=w.v4(),{environment:u,service:g}=this.params,s={...o,...t,service:g,id:c,environment:u,...e&&{scope:e}};try{await this.transport.create(s)}catch(l){const a=l.message;try{console.error(JSON.stringify({status:"error",namespace:"audit-logs",message:"audit-log write failed",audit_log:s,error:a}))}catch{console.error(JSON.stringify({status:"error",namespace:"audit-logs",message:"audit-log write failed (serialization failed)",audit_log_meta:{id:s.id,service:s.service,environment:s.environment,namespace:s.namespace,event:s.event,target:s.target},error:a}))}}}}exports.AuditLogger=q;
|
package/dist/index.mjs
CHANGED
|
@@ -1,149 +1,80 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
1
|
+
var l = Object.defineProperty;
|
|
2
|
+
var d = (r, e, t) => e in r ? l(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t;
|
|
3
|
+
var o = (r, e, t) => (d(r, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
4
|
import { v4 as m } from "uuid";
|
|
5
|
-
import
|
|
6
|
-
const
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
}
|
|
15
|
-
class A extends Error {
|
|
16
|
-
constructor(t, o) {
|
|
17
|
-
super(o);
|
|
18
|
-
n(this, "field");
|
|
19
|
-
n(this, "name", "RequiredError");
|
|
20
|
-
this.field = t;
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
const w = "https://example.com", x = function(s, e, t) {
|
|
24
|
-
if (t == null)
|
|
25
|
-
throw new A(e, `Required parameter ${e} was null or undefined when calling ${s}.`);
|
|
26
|
-
}, g = function(s, ...e) {
|
|
27
|
-
const t = new URLSearchParams(s.search);
|
|
28
|
-
for (const o of e)
|
|
29
|
-
for (const r in o)
|
|
30
|
-
if (Array.isArray(o[r])) {
|
|
31
|
-
t.delete(r);
|
|
32
|
-
for (const a of o[r])
|
|
33
|
-
t.append(r, a);
|
|
34
|
-
} else
|
|
35
|
-
t.set(r, o[r]);
|
|
36
|
-
s.search = t.toString();
|
|
37
|
-
}, b = function(s, e, t) {
|
|
38
|
-
const o = typeof s != "string";
|
|
39
|
-
return (o && t && t.isJsonMime ? t.isJsonMime(e.headers["Content-Type"]) : o) ? JSON.stringify(s !== void 0 ? s : {}) : s || "";
|
|
40
|
-
}, y = function(s) {
|
|
41
|
-
return s.pathname + s.search + s.hash;
|
|
42
|
-
}, E = function(s, e, t, o) {
|
|
43
|
-
return (r = e, a = t) => {
|
|
44
|
-
const i = { ...s.options, url: ((o == null ? void 0 : o.basePath) || a) + s.url };
|
|
45
|
-
return r.request(i);
|
|
46
|
-
};
|
|
47
|
-
}, L = function(s) {
|
|
48
|
-
return {
|
|
49
|
-
/**
|
|
50
|
-
*
|
|
51
|
-
* @summary Creates Audit Log event
|
|
52
|
-
* @param {InlineObject} inlineObject
|
|
53
|
-
* @param {*} [options] Override http request option.
|
|
54
|
-
* @throws {RequiredError}
|
|
55
|
-
*/
|
|
56
|
-
v1LogPost: async (e, t = {}) => {
|
|
57
|
-
x("v1LogPost", "inlineObject", e);
|
|
58
|
-
const o = "/v1/log", r = new URL(o, w);
|
|
59
|
-
let a;
|
|
60
|
-
s && (a = s.baseOptions);
|
|
61
|
-
const i = { method: "POST", ...a, ...t }, c = {}, h = {};
|
|
62
|
-
c["Content-Type"] = "application/json", g(r, h);
|
|
63
|
-
let d = a && a.headers ? a.headers : {};
|
|
64
|
-
return i.headers = { ...c, ...d, ...t.headers }, i.data = b(e, i, s), {
|
|
65
|
-
url: y(r),
|
|
66
|
-
options: i
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
}, S = function(s) {
|
|
71
|
-
const e = L(s);
|
|
72
|
-
return {
|
|
73
|
-
/**
|
|
74
|
-
*
|
|
75
|
-
* @summary Creates Audit Log event
|
|
76
|
-
* @param {InlineObject} inlineObject
|
|
77
|
-
* @param {*} [options] Override http request option.
|
|
78
|
-
* @throws {RequiredError}
|
|
79
|
-
*/
|
|
80
|
-
async v1LogPost(t, o) {
|
|
81
|
-
const r = await e.v1LogPost(t, o);
|
|
82
|
-
return E(r, l, p, s);
|
|
83
|
-
}
|
|
84
|
-
};
|
|
5
|
+
import { SQSClient as p, SendMessageCommand as w } from "@aws-sdk/client-sqs";
|
|
6
|
+
const h = "eu-west-3", S = {
|
|
7
|
+
dev: "https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",
|
|
8
|
+
staging: "https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",
|
|
9
|
+
prod: "https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"
|
|
10
|
+
}, v = {
|
|
11
|
+
working: "staging",
|
|
12
|
+
production: "prod"
|
|
85
13
|
};
|
|
86
|
-
class
|
|
87
|
-
/**
|
|
88
|
-
*
|
|
89
|
-
* @summary Creates Audit Log event
|
|
90
|
-
* @param {InlineObject} inlineObject
|
|
91
|
-
* @param {*} [options] Override http request option.
|
|
92
|
-
* @throws {RequiredError}
|
|
93
|
-
* @memberof DefaultApi
|
|
94
|
-
*/
|
|
95
|
-
v1LogPost(e, t) {
|
|
96
|
-
return S(this.configuration).v1LogPost(e, t).then((o) => o(this.axios, this.basePath));
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
const R = (s) => "isAxiosError" in s && s.isAxiosError && s instanceof Error;
|
|
100
|
-
class U {
|
|
14
|
+
class f {
|
|
101
15
|
constructor(e) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
this
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
"i"
|
|
111
|
-
);
|
|
112
|
-
return t !== null && (o.test(t) || t.toLowerCase() === "application/json-patch+json");
|
|
113
|
-
}
|
|
114
|
-
});
|
|
16
|
+
o(this, "environment");
|
|
17
|
+
o(this, "client");
|
|
18
|
+
o(this, "queueUrl");
|
|
19
|
+
this.environment = e;
|
|
20
|
+
const t = v[e] ?? e, a = S[t];
|
|
21
|
+
if (!a)
|
|
22
|
+
throw new Error(`audit-logs SDK: no SQS queue URL configured for environment "${e}"`);
|
|
23
|
+
this.queueUrl = a, this.client = new p({ region: h });
|
|
115
24
|
}
|
|
116
25
|
async create(e) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
121
|
-
if (!R(o))
|
|
122
|
-
throw o;
|
|
123
|
-
const r = ((t = o.response) == null ? void 0 : t.data) || o.message;
|
|
124
|
-
throw new Error(r);
|
|
125
|
-
}
|
|
26
|
+
await this.client.send(new w({
|
|
27
|
+
QueueUrl: this.queueUrl,
|
|
28
|
+
MessageBody: JSON.stringify(e)
|
|
29
|
+
}));
|
|
126
30
|
}
|
|
127
31
|
}
|
|
128
|
-
class
|
|
32
|
+
class E {
|
|
129
33
|
constructor(e) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this.params = e, this.transport = new
|
|
34
|
+
o(this, "params");
|
|
35
|
+
o(this, "transport");
|
|
36
|
+
this.params = e, this.transport = new f(e.environment);
|
|
133
37
|
}
|
|
134
|
-
async log({ scope: e, account: t, ...
|
|
135
|
-
const
|
|
136
|
-
...
|
|
38
|
+
async log({ scope: e, account: t, ...a }) {
|
|
39
|
+
const i = m(), { environment: c, service: g } = this.params, s = {
|
|
40
|
+
...a,
|
|
137
41
|
...t,
|
|
138
|
-
service:
|
|
139
|
-
id:
|
|
140
|
-
environment:
|
|
141
|
-
timestamp: c,
|
|
42
|
+
service: g,
|
|
43
|
+
id: i,
|
|
44
|
+
environment: c,
|
|
142
45
|
...e && { scope: e }
|
|
143
46
|
};
|
|
144
|
-
|
|
47
|
+
try {
|
|
48
|
+
await this.transport.create(s);
|
|
49
|
+
} catch (u) {
|
|
50
|
+
const n = u.message;
|
|
51
|
+
try {
|
|
52
|
+
console.error(JSON.stringify({
|
|
53
|
+
status: "error",
|
|
54
|
+
namespace: "audit-logs",
|
|
55
|
+
message: "audit-log write failed",
|
|
56
|
+
audit_log: s,
|
|
57
|
+
error: n
|
|
58
|
+
}));
|
|
59
|
+
} catch {
|
|
60
|
+
console.error(JSON.stringify({
|
|
61
|
+
status: "error",
|
|
62
|
+
namespace: "audit-logs",
|
|
63
|
+
message: "audit-log write failed (serialization failed)",
|
|
64
|
+
audit_log_meta: {
|
|
65
|
+
id: s.id,
|
|
66
|
+
service: s.service,
|
|
67
|
+
environment: s.environment,
|
|
68
|
+
namespace: s.namespace,
|
|
69
|
+
event: s.event,
|
|
70
|
+
target: s.target
|
|
71
|
+
},
|
|
72
|
+
error: n
|
|
73
|
+
}));
|
|
74
|
+
}
|
|
75
|
+
}
|
|
145
76
|
}
|
|
146
77
|
}
|
|
147
78
|
export {
|
|
148
|
-
|
|
79
|
+
E as AuditLogger
|
|
149
80
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IAuditLogTransport } from './interface';
|
|
1
|
+
import { IAuditLogCreationData, IAuditLogTransport } from './interface';
|
|
3
2
|
export declare class Transport implements IAuditLogTransport {
|
|
4
|
-
protected
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
protected environment: string;
|
|
4
|
+
private client;
|
|
5
|
+
private queueUrl;
|
|
6
|
+
constructor(environment: string);
|
|
7
|
+
create(auditLogData: IAuditLogCreationData): Promise<void>;
|
|
8
8
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payfit/audit-log",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.7.1",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://github.com/PayFit/audit-logs.git",
|
|
@@ -15,6 +15,8 @@
|
|
|
15
15
|
"build": "rimraf dist && vite build",
|
|
16
16
|
"prepack": "npm run build",
|
|
17
17
|
"lint": "eslint .",
|
|
18
|
+
"test": "vitest run",
|
|
19
|
+
"test:watch": "vitest",
|
|
18
20
|
"start:playground": "ts-node src/playground.ts",
|
|
19
21
|
"format:check": "prettier --check .",
|
|
20
22
|
"format:fix": "prettier --write .",
|
|
@@ -23,6 +25,7 @@
|
|
|
23
25
|
"author": "",
|
|
24
26
|
"license": "ISC",
|
|
25
27
|
"dependencies": {
|
|
28
|
+
"@aws-sdk/client-sqs": "^3.600.0",
|
|
26
29
|
"axios": "^1.0.0",
|
|
27
30
|
"lodash": "^4.17.20",
|
|
28
31
|
"uuid": "^9.0.0"
|
|
@@ -46,13 +49,14 @@
|
|
|
46
49
|
"semantic-release": "22.0.12",
|
|
47
50
|
"ts-node": "10.9.2",
|
|
48
51
|
"typescript": "5.3.3",
|
|
49
|
-
"vite": "4.5.1"
|
|
52
|
+
"vite": "4.5.1",
|
|
53
|
+
"vitest": "4.1.4"
|
|
50
54
|
},
|
|
51
|
-
"peerDependencies": {},
|
|
52
55
|
"publishConfig": {
|
|
53
56
|
"registry": "https://registry.npmjs.org/"
|
|
54
57
|
},
|
|
55
58
|
"files": [
|
|
56
59
|
"dist"
|
|
57
|
-
]
|
|
60
|
+
],
|
|
61
|
+
"packageManager": "yarn@4.14.1+sha512.64df448055b2d37ba269d7db535a469b8da93f8ef1140c25fd7a83c00a8fbaacb214ca0e02553b92a2c54cef78bb67d0b4817fab02001df0e24fac0faccc3b42"
|
|
58
62
|
}
|