@payfit/audit-log 3.5.0-rc.3 → 3.5.0-rc.31
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/compression.d.ts +2 -0
- package/dist/compression.test.d.ts +1 -0
- package/dist/index.d.ts +16 -5
- package/dist/index.js +1 -1
- package/dist/index.mjs +144 -132
- package/dist/index.test.d.ts +1 -0
- package/dist/logger.d.ts +2 -0
- package/dist/logger.test.d.ts +1 -0
- package/dist/metrics.d.ts +16 -0
- package/dist/metrics.test.d.ts +1 -0
- package/dist/transport/implementation.d.ts +9 -6
- package/dist/transport/implementation.test.d.ts +1 -0
- package/dist/transport/interface.d.ts +4 -2
- package/package.json +11 -5
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
|
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
import type { Logger } from 'winston';
|
|
2
|
+
import { type IMetricsClient } from './metrics';
|
|
3
|
+
import { IAuditLogTransport } from './transport/interface';
|
|
1
4
|
/**
|
|
2
5
|
* The allowed Namespaces for the AuditLog
|
|
3
6
|
*/
|
|
4
|
-
export type AuditNamespaces = 'employee' | 'company' | 'permissions' | 'absence' | 'expense' | 'payments' | 'auth' | 'billing' | 'modules' | 'integrations' | 'partnerApi' | 'donation' | 'notificationSettings' | 'people' | 'subscriptions' | 'organization' | 'declarations' | 'pricing' | 'payroll' | 'jetlang' | 'files' | 'versioner';
|
|
7
|
+
export type AuditNamespaces = 'employee' | 'company' | 'permissions' | 'absence' | 'expense' | 'payments' | 'auth' | 'billing' | 'modules' | 'integrations' | 'partnerApi' | 'donation' | 'notificationSettings' | 'people' | 'subscriptions' | 'organization' | 'declarations' | 'pricing' | 'payroll' | 'jetlang' | 'files' | 'versioner' | 'live-timing';
|
|
5
8
|
/**
|
|
6
9
|
* The allowed targets for the AuditLog
|
|
7
10
|
*/
|
|
@@ -9,7 +12,7 @@ export type AuditTargets = 'reporting' | 'employee' | 'employee.settings' | 'emp
|
|
|
9
12
|
/**
|
|
10
13
|
* The allowed Events for the AuditLog
|
|
11
14
|
*/
|
|
12
|
-
export type AuditEvents = 'create' | 'update' | 'share' | 'delete' | 'view' | 'sign' | 'signin' | 'signinFail' | 'signinAs' | 'logout' | 'updateCurrentAccount' | 'merge' | 'disable' | 'sendResetPasswordLink' | 'enable' | 'verify' | 'read' | 'write' | 'subscribe' | 'consume' | 'setup' | 'deleteAllAdmins' | 'import';
|
|
15
|
+
export type AuditEvents = 'create' | 'update' | 'share' | 'delete' | 'view' | 'sign' | 'signin' | 'signinFail' | 'signinAs' | 'logout' | 'updateCurrentAccount' | 'merge' | 'disable' | 'sendResetPasswordLink' | 'enable' | 'verify' | 'read' | 'write' | 'subscribe' | 'consume' | 'setup' | 'deleteAllAdmins' | 'import' | 'useAccount';
|
|
13
16
|
/**
|
|
14
17
|
* Data to audit log.
|
|
15
18
|
*/
|
|
@@ -92,13 +95,21 @@ export interface IAuditLogger {
|
|
|
92
95
|
log: (data: IAuditLogData) => Promise<void>;
|
|
93
96
|
}
|
|
94
97
|
export interface IAuditLoggerInitialization {
|
|
95
|
-
|
|
98
|
+
/** @deprecated No longer used. The library routes via SQS based on `environment`. Kept for backward compatibility. */
|
|
99
|
+
apiUrl?: string;
|
|
96
100
|
environment: string;
|
|
97
101
|
service: string;
|
|
98
102
|
}
|
|
103
|
+
export interface IAuditLoggerDependencies {
|
|
104
|
+
transport?: IAuditLogTransport;
|
|
105
|
+
logger?: Logger;
|
|
106
|
+
metrics?: IMetricsClient;
|
|
107
|
+
}
|
|
99
108
|
export declare class AuditLogger implements IAuditLogger {
|
|
100
109
|
protected params: IAuditLoggerInitialization;
|
|
101
|
-
private transport;
|
|
102
|
-
|
|
110
|
+
private readonly transport;
|
|
111
|
+
private readonly logger;
|
|
112
|
+
private readonly metrics;
|
|
113
|
+
constructor(params: IAuditLoggerInitialization, deps?: IAuditLoggerDependencies);
|
|
103
114
|
log({ scope, account, ...data }: IAuditLogData): Promise<void>;
|
|
104
115
|
}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var f=Object.defineProperty;var w=(s,e,t)=>e in s?f(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var i=(s,e,t)=>(w(s,typeof e!="symbol"?e+"":e,t),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"),y=require("zlib"),E="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:E,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 y.brotliCompressSync(Buffer.from(s,"utf8")).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 Q{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:u}=this.params,r={...n,...t,service:u,id:c,environment:g,...e&&{scope:e}},a={service:u,environment:g,namespace:r.namespace,event:r.event,target:r.target},m=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()-m,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()-m,a);const d=l.message;try{this.logger.error("audit-log write failed",{audit_log:r,error:d})}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:d})}catch{}}}}}exports.AuditLogger=Q;
|
package/dist/index.mjs
CHANGED
|
@@ -1,149 +1,161 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import { v4 as
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var p = Object.defineProperty;
|
|
2
|
+
var f = (s, e, t) => e in s ? p(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
|
|
3
|
+
var i = (s, e, t) => (f(s, typeof e != "symbol" ? e + "" : e, t), t);
|
|
4
|
+
import { v4 as w } from "uuid";
|
|
5
|
+
import { createLogger as v, format as c, transports as S } from "winston";
|
|
6
|
+
import { StatsD as E } from "hot-shots";
|
|
7
|
+
import { SQSClient as _, SendMessageCommand as y } from "@aws-sdk/client-sqs";
|
|
8
|
+
import { brotliCompressSync as L } from "zlib";
|
|
9
|
+
const M = "audit-logs", A = "@payfit/audit-log", U = () => {
|
|
10
|
+
const s = process.env.LOG_LEVEL;
|
|
11
|
+
return s && s.trim() !== "" ? s.trim() : "info";
|
|
12
|
+
}, q = (s, e) => v({
|
|
13
|
+
level: U(),
|
|
14
|
+
silent: process.env.NODE_ENV === "test",
|
|
15
|
+
exitOnError: !1,
|
|
16
|
+
defaultMeta: {
|
|
17
|
+
namespace: M,
|
|
18
|
+
sdk: A,
|
|
19
|
+
service: s,
|
|
20
|
+
environment: e
|
|
21
|
+
},
|
|
22
|
+
format: c.combine(c.timestamp(), c.errors({ stack: !0 }), c.json()),
|
|
23
|
+
transports: [new S.Console()]
|
|
24
|
+
}), C = "payfit.audit_logs.", h = (s) => Object.entries(s).filter(([, e]) => e !== void 0 && e !== "").map(([e, t]) => `${e}:${String(t)}`);
|
|
25
|
+
class b {
|
|
26
|
+
constructor() {
|
|
27
|
+
i(this, "client");
|
|
28
|
+
this.client = new E({
|
|
29
|
+
prefix: C,
|
|
30
|
+
// Loss of metrics never breaks the caller — DogStatsD UDP is best-effort by design.
|
|
31
|
+
errorHandler: () => {
|
|
32
|
+
},
|
|
33
|
+
cacheDns: !0
|
|
34
|
+
});
|
|
13
35
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
constructor(t, o) {
|
|
17
|
-
super(o);
|
|
18
|
-
n(this, "field");
|
|
19
|
-
n(this, "name", "RequiredError");
|
|
20
|
-
this.field = t;
|
|
36
|
+
increment(e, t) {
|
|
37
|
+
this.client.increment(e, 1, h(t));
|
|
21
38
|
}
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
};
|
|
85
|
-
};
|
|
86
|
-
class v extends f {
|
|
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));
|
|
39
|
+
histogram(e, t, n) {
|
|
40
|
+
this.client.histogram(e, t, h(n));
|
|
97
41
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
constructor(e) {
|
|
102
|
-
n(this, "apiUrl");
|
|
103
|
-
n(this, "api");
|
|
104
|
-
this.apiUrl = e, this.api = new v({
|
|
105
|
-
basePath: this.apiUrl,
|
|
106
|
-
isJsonMime(t) {
|
|
107
|
-
const o = new RegExp(
|
|
108
|
-
// eslint-disable-next-line no-control-regex
|
|
109
|
-
"^(application/json|[^;/ ]+/[^;/ ]+[+]json)[ ]*(;.*)?$",
|
|
110
|
-
"i"
|
|
111
|
-
);
|
|
112
|
-
return t !== null && (o.test(t) || t.toLowerCase() === "application/json-patch+json");
|
|
113
|
-
}
|
|
42
|
+
async close() {
|
|
43
|
+
await new Promise((e) => {
|
|
44
|
+
this.client.close(() => e());
|
|
114
45
|
});
|
|
115
46
|
}
|
|
47
|
+
}
|
|
48
|
+
const D = () => new b();
|
|
49
|
+
function N(s) {
|
|
50
|
+
return L(Buffer.from(s, "utf8")).toString("base64");
|
|
51
|
+
}
|
|
52
|
+
function O(s) {
|
|
53
|
+
return s instanceof Error && s.message.includes("Message must be shorter than");
|
|
54
|
+
}
|
|
55
|
+
const z = "eu-west-3", Q = {
|
|
56
|
+
dev: "https://sqs.eu-west-3.amazonaws.com/533547282673/audit-logs-ingest",
|
|
57
|
+
staging: "https://sqs.eu-west-3.amazonaws.com/589883667243/audit-logs-ingest",
|
|
58
|
+
prod: "https://sqs.eu-west-3.amazonaws.com/614948436281/audit-logs-ingest"
|
|
59
|
+
}, R = {
|
|
60
|
+
working: "staging",
|
|
61
|
+
production: "prod",
|
|
62
|
+
development: "dev"
|
|
63
|
+
};
|
|
64
|
+
class k {
|
|
65
|
+
constructor(e, t) {
|
|
66
|
+
i(this, "environment");
|
|
67
|
+
i(this, "logger");
|
|
68
|
+
i(this, "client");
|
|
69
|
+
i(this, "queueUrl");
|
|
70
|
+
this.environment = e, this.logger = t;
|
|
71
|
+
const n = R[e] ?? e;
|
|
72
|
+
if (this.queueUrl = Q[n], !this.queueUrl) {
|
|
73
|
+
t == null || t.warn("audit-logs SDK: no SQS queue URL configured for this environment, audit logs are disabled", { environment: e });
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.client = new _({ region: z });
|
|
77
|
+
}
|
|
116
78
|
async create(e) {
|
|
117
|
-
var
|
|
79
|
+
var n;
|
|
80
|
+
if (!this.client || !this.queueUrl)
|
|
81
|
+
return { compressed: !1 };
|
|
82
|
+
const t = JSON.stringify(e);
|
|
118
83
|
try {
|
|
119
|
-
await this.
|
|
120
|
-
} catch (
|
|
121
|
-
if (!
|
|
122
|
-
throw
|
|
123
|
-
|
|
124
|
-
throw new Error(r);
|
|
84
|
+
return await this.send(t), { compressed: !1 };
|
|
85
|
+
} catch (a) {
|
|
86
|
+
if (!O(a))
|
|
87
|
+
throw a;
|
|
88
|
+
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(N(t)), { compressed: !0 };
|
|
125
89
|
}
|
|
126
90
|
}
|
|
91
|
+
async send(e) {
|
|
92
|
+
await this.client.send(new y({
|
|
93
|
+
QueueUrl: this.queueUrl,
|
|
94
|
+
MessageBody: e
|
|
95
|
+
}));
|
|
96
|
+
}
|
|
127
97
|
}
|
|
128
|
-
class
|
|
129
|
-
constructor(e) {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
this
|
|
98
|
+
class V {
|
|
99
|
+
constructor(e, t = {}) {
|
|
100
|
+
i(this, "params");
|
|
101
|
+
i(this, "transport");
|
|
102
|
+
i(this, "logger");
|
|
103
|
+
i(this, "metrics");
|
|
104
|
+
this.params = e, this.logger = t.logger ?? q(e.service, e.environment), this.transport = t.transport ?? new k(e.environment, this.logger), this.metrics = t.metrics ?? D();
|
|
133
105
|
}
|
|
134
|
-
async log({ scope: e, account: t, ...
|
|
135
|
-
const
|
|
136
|
-
...
|
|
106
|
+
async log({ scope: e, account: t, ...n }) {
|
|
107
|
+
const a = w(), { environment: l, service: g } = this.params, r = {
|
|
108
|
+
...n,
|
|
137
109
|
...t,
|
|
138
|
-
service:
|
|
139
|
-
id:
|
|
140
|
-
environment:
|
|
141
|
-
timestamp: c,
|
|
110
|
+
service: g,
|
|
111
|
+
id: a,
|
|
112
|
+
environment: l,
|
|
142
113
|
...e && { scope: e }
|
|
143
|
-
}
|
|
144
|
-
|
|
114
|
+
}, o = {
|
|
115
|
+
service: g,
|
|
116
|
+
environment: l,
|
|
117
|
+
namespace: r.namespace,
|
|
118
|
+
event: r.event,
|
|
119
|
+
target: r.target
|
|
120
|
+
}, d = Date.now();
|
|
121
|
+
try {
|
|
122
|
+
const { compressed: m } = await this.transport.create(r);
|
|
123
|
+
this.metrics.increment("sent", {
|
|
124
|
+
...o,
|
|
125
|
+
compressed: String(m)
|
|
126
|
+
}), this.metrics.histogram("send_duration_ms", Date.now() - d, o), this.logger.debug("audit-log sent", {
|
|
127
|
+
id: r.id,
|
|
128
|
+
event: r.event,
|
|
129
|
+
target: r.target
|
|
130
|
+
});
|
|
131
|
+
} catch (m) {
|
|
132
|
+
this.metrics.increment("send_failed", o), this.metrics.histogram("send_duration_ms", Date.now() - d, o);
|
|
133
|
+
const u = m.message;
|
|
134
|
+
try {
|
|
135
|
+
this.logger.error("audit-log write failed", {
|
|
136
|
+
audit_log: r,
|
|
137
|
+
error: u
|
|
138
|
+
});
|
|
139
|
+
} catch {
|
|
140
|
+
this.metrics.increment("serialization_failed", o);
|
|
141
|
+
try {
|
|
142
|
+
this.logger.error("audit-log write failed (serialization failed)", {
|
|
143
|
+
audit_log_meta: {
|
|
144
|
+
id: r.id,
|
|
145
|
+
service: r.service,
|
|
146
|
+
environment: r.environment,
|
|
147
|
+
namespace: r.namespace,
|
|
148
|
+
event: r.event,
|
|
149
|
+
target: r.target
|
|
150
|
+
},
|
|
151
|
+
error: u
|
|
152
|
+
});
|
|
153
|
+
} catch {
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
145
157
|
}
|
|
146
158
|
}
|
|
147
159
|
export {
|
|
148
|
-
|
|
160
|
+
V as AuditLogger
|
|
149
161
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const METRIC_PREFIX = "payfit.audit_logs.";
|
|
2
|
+
export type MetricName = 'sent' | 'send_failed' | 'serialization_failed' | 'send_duration_ms';
|
|
3
|
+
export interface MetricTags {
|
|
4
|
+
service: string;
|
|
5
|
+
environment: string;
|
|
6
|
+
namespace?: string;
|
|
7
|
+
event?: string;
|
|
8
|
+
target?: string;
|
|
9
|
+
compressed?: string;
|
|
10
|
+
}
|
|
11
|
+
export interface IMetricsClient {
|
|
12
|
+
increment(name: MetricName, tags: MetricTags): void;
|
|
13
|
+
histogram(name: MetricName, value: number, tags: MetricTags): void;
|
|
14
|
+
close(): Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
export declare const createMetricsClient: () => IMetricsClient;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { IAuditLogTransport } from './interface';
|
|
1
|
+
import type { Logger } from 'winston';
|
|
2
|
+
import { IAuditLogCreationData, IAuditLogCreationResult, IAuditLogTransport } from './interface';
|
|
3
3
|
export declare class Transport implements IAuditLogTransport {
|
|
4
|
-
protected
|
|
5
|
-
private
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
protected environment: string;
|
|
5
|
+
private logger?;
|
|
6
|
+
private readonly client;
|
|
7
|
+
private readonly queueUrl;
|
|
8
|
+
constructor(environment: string, logger?: Logger | undefined);
|
|
9
|
+
create(auditLogData: IAuditLogCreationData): Promise<IAuditLogCreationResult>;
|
|
10
|
+
private send;
|
|
8
11
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
export interface IAuditLogCreationData {
|
|
2
2
|
id: string;
|
|
3
|
-
timestamp: number;
|
|
4
3
|
environment: string;
|
|
5
4
|
service: string;
|
|
6
5
|
scope?: Record<string, unknown>;
|
|
@@ -21,6 +20,9 @@ export interface IAuditLogCreationData {
|
|
|
21
20
|
specialRole?: string;
|
|
22
21
|
email?: string;
|
|
23
22
|
}
|
|
23
|
+
export interface IAuditLogCreationResult {
|
|
24
|
+
compressed: boolean;
|
|
25
|
+
}
|
|
24
26
|
export interface IAuditLogTransport {
|
|
25
|
-
create: (data: IAuditLogCreationData) => Promise<
|
|
27
|
+
create: (data: IAuditLogCreationData) => Promise<IAuditLogCreationResult>;
|
|
26
28
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payfit/audit-log",
|
|
3
|
-
"version": "3.5.0-rc.
|
|
3
|
+
"version": "3.5.0-rc.31",
|
|
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,9 +25,12 @@
|
|
|
23
25
|
"author": "",
|
|
24
26
|
"license": "ISC",
|
|
25
27
|
"dependencies": {
|
|
28
|
+
"@aws-sdk/client-sqs": "^3.600.0",
|
|
26
29
|
"axios": "^1.0.0",
|
|
30
|
+
"hot-shots": "^11.0.0",
|
|
27
31
|
"lodash": "^4.17.20",
|
|
28
|
-
"uuid": "^9.0.0"
|
|
32
|
+
"uuid": "^9.0.0",
|
|
33
|
+
"winston": "^3.13.0"
|
|
29
34
|
},
|
|
30
35
|
"devDependencies": {
|
|
31
36
|
"@openapitools/openapi-generator-cli": "2.7.0",
|
|
@@ -46,13 +51,14 @@
|
|
|
46
51
|
"semantic-release": "22.0.12",
|
|
47
52
|
"ts-node": "10.9.2",
|
|
48
53
|
"typescript": "5.3.3",
|
|
49
|
-
"vite": "4.5.1"
|
|
54
|
+
"vite": "4.5.1",
|
|
55
|
+
"vitest": "4.1.4"
|
|
50
56
|
},
|
|
51
|
-
"peerDependencies": {},
|
|
52
57
|
"publishConfig": {
|
|
53
58
|
"registry": "https://registry.npmjs.org/"
|
|
54
59
|
},
|
|
55
60
|
"files": [
|
|
56
61
|
"dist"
|
|
57
|
-
]
|
|
62
|
+
],
|
|
63
|
+
"packageManager": "yarn@4.14.1+sha512.64df448055b2d37ba269d7db535a469b8da93f8ef1140c25fd7a83c00a8fbaacb214ca0e02553b92a2c54cef78bb67d0b4817fab02001df0e24fac0faccc3b42"
|
|
58
64
|
}
|