@payfit/audit-log 1.0.0-alpha4 → 1.0.0-alpha6

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.d.ts CHANGED
@@ -1,18 +1,84 @@
1
- export interface AuditLogData {
2
- countryCode: string;
1
+ /**
2
+ * Data to audit log.
3
+ */
4
+ export interface IAuditLogData {
5
+ /**
6
+ * The data specific to the audit log.
7
+ * For example, if we add a bonus to an employee, it could contain the amount, the impacted employeeId, etc...
8
+ */
3
9
  payload?: object;
4
- isImpersonated?: boolean;
5
- isSystem?: boolean;
10
+ /**
11
+ * The buisness domain impacted.
12
+ * e.g documents, authentication, ...
13
+ */
6
14
  namespace: string;
15
+ /**
16
+ * The service name (tech).
17
+ * e.g files, payroll-api-v2, auth, ...
18
+ */
7
19
  service: string;
20
+ /**
21
+ * The name of the event.
22
+ * e.g. signIn, passwordUpdated, bonusAdded, ...
23
+ */
8
24
  event: string;
25
+ /**
26
+ * The data that describes who did perform the logged action.
27
+ */
28
+ account: IAuditLogAuthData;
29
+ /**
30
+ * The scope of the audit log
31
+ */
32
+ scope: IAuditLogScope;
33
+ }
34
+ /**
35
+ * Data used to indentify who performed an action
36
+ */
37
+ export declare type IAuditLogAuthData = {
38
+ /**
39
+ * Tells if the action has been made during a siginAs
40
+ */
41
+ isImpersonated?: boolean;
9
42
  holdingId?: string;
10
43
  companyId?: string;
11
44
  employeeId?: string;
12
- individualId?: string;
45
+ individualId: string;
13
46
  roleId?: string;
47
+ /**
48
+ *
49
+ */
50
+ countryCode?: string;
51
+ /**
52
+ * The IP address of the user
53
+ */
14
54
  userIp?: string;
15
- specialRole?: string;
55
+ /**
56
+ * The email address of the user
57
+ */
16
58
  email?: string;
59
+ } | {
60
+ isSystem: true;
61
+ };
62
+ /**
63
+ * Data used to "scope" the audit log.
64
+ * Might be useful to retrieve all actions performed in a holding, a company, or on an employee.
65
+ */
66
+ export declare type IAuditLogScope = {
67
+ holdingId: string;
68
+ } | {
69
+ companyId: string;
70
+ employeeId?: string;
71
+ } | null;
72
+ export interface IAuditLogger {
73
+ log: (data: IAuditLogData) => Promise<void>;
74
+ }
75
+ export interface IAuditLoggerInitialization {
76
+ apiUrl: string;
77
+ environment: string;
78
+ }
79
+ export declare class AuditLogger implements IAuditLogger {
80
+ protected params: IAuditLoggerInitialization;
81
+ private transport;
82
+ constructor(params: IAuditLoggerInitialization);
83
+ log(params: IAuditLogData): Promise<void>;
17
84
  }
18
- export declare function auditLog(params: AuditLogData): Promise<void>;
package/dist/index.js CHANGED
@@ -7,25 +7,24 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
7
7
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
8
  });
9
9
  };
10
- var __importStar = (this && this.__importStar) || function (mod) {
11
- if (mod && mod.__esModule) return mod;
12
- var result = {};
13
- if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
14
- result["default"] = mod;
15
- return result;
16
- };
17
10
  Object.defineProperty(exports, "__esModule", { value: true });
18
11
  const uuid_1 = require("uuid");
19
- const transport = __importStar(require("./transport/implementation"));
20
- function auditLog(params) {
21
- return __awaiter(this, void 0, void 0, function* () {
22
- const uuid = uuid_1.v4();
23
- const environment = process.env.ENVIRONMENT;
24
- const timestamp = new Date().getTime();
25
- const log = Object.assign({}, params, { id: uuid, environment,
26
- timestamp });
27
- yield transport.auditLog(log);
28
- });
12
+ const implementation_1 = require("./transport/implementation");
13
+ class AuditLogger {
14
+ constructor(params) {
15
+ this.params = params;
16
+ this.transport = new implementation_1.Transport(params.apiUrl);
17
+ }
18
+ log(params) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ const uuid = uuid_1.v4();
21
+ const environment = this.params.environment;
22
+ const timestamp = new Date().getTime();
23
+ const log = Object.assign({}, params, { id: uuid, environment,
24
+ timestamp });
25
+ yield this.transport.create(log);
26
+ });
27
+ }
29
28
  }
30
- exports.auditLog = auditLog;
29
+ exports.AuditLogger = AuditLogger;
31
30
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAAmC;AACnC,sEAAuD;AAoBvD,SAAsB,QAAQ,CAAC,MAAoB;;QACjD,MAAM,IAAI,GAAG,SAAM,EAAE,CAAA;QACrB,MAAM,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC,WAAW,CAAA;QAC3C,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;QAEtC,MAAM,GAAG,qBACJ,MAAM,IACT,EAAE,EAAE,IAAI,EACR,WAAW;YACX,SAAS,GACV,CAAA;QAED,MAAM,SAAS,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAA;IAC/B,CAAC;CAAA;AAbD,4BAaC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+BAAmC;AAEnC,+DAAsD;AAoGtD,MAAa,WAAW;IAGtB,YAAsB,MAAkC;QAAlC,WAAM,GAAN,MAAM,CAA4B;QACtD,IAAI,CAAC,SAAS,GAAG,IAAI,0BAAS,CAAC,MAAM,CAAC,MAAM,CAAC,CAAA;IAC/C,CAAC;IAEK,GAAG,CAAC,MAAqB;;YAC7B,MAAM,IAAI,GAAG,SAAM,EAAE,CAAA;YACrB,MAAM,WAAW,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAA;YAC3C,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;YAEtC,MAAM,GAAG,qBACJ,MAAM,IACT,EAAE,EAAE,IAAI,EACR,WAAW;gBACX,SAAS,GACV,CAAA;YAED,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClC,CAAC;KAAA;CACF;AArBD,kCAqBC"}
@@ -1,7 +1,3 @@
1
1
  "use strict";
2
- function __export(m) {
3
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
- }
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
- __export(require("./inline-object"));
7
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/transport/generated/model/index.ts"],"names":[],"mappings":";;;;;AAAA,qCAAgC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/transport/generated/model/index.ts"],"names":[],"mappings":""}
@@ -26,7 +26,7 @@ export interface InlineObject {
26
26
  * @type {string}
27
27
  * @memberof InlineObject
28
28
  */
29
- countryCode: CountryCodeEnum;
29
+ countryCode?: string;
30
30
  /**
31
31
  * Audit log event payload
32
32
  * @type {object}
@@ -118,14 +118,3 @@ export interface InlineObject {
118
118
  */
119
119
  email?: string;
120
120
  }
121
- /**
122
- * @export
123
- * @enum {string}
124
- */
125
- export declare enum CountryCodeEnum {
126
- FR = "fr",
127
- DE = "de",
128
- IT = "it",
129
- ES = "es",
130
- GB = "gb"
131
- }
@@ -12,16 +12,4 @@
12
12
  * Do not edit the class manually.
13
13
  */
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
- /**
16
- * @export
17
- * @enum {string}
18
- */
19
- var CountryCodeEnum;
20
- (function (CountryCodeEnum) {
21
- CountryCodeEnum["FR"] = "fr";
22
- CountryCodeEnum["DE"] = "de";
23
- CountryCodeEnum["IT"] = "it";
24
- CountryCodeEnum["ES"] = "es";
25
- CountryCodeEnum["GB"] = "gb";
26
- })(CountryCodeEnum = exports.CountryCodeEnum || (exports.CountryCodeEnum = {}));
27
15
  //# sourceMappingURL=inline-object.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inline-object.js","sourceRoot":"","sources":["../../../../src/transport/generated/model/inline-object.ts"],"names":[],"mappings":";AAAA,iBAAiB;AACjB;;;;;;;;;;GAUG;;AAkHH;;;MAGM;AACN,IAAY,eAMX;AAND,WAAY,eAAe;IACvB,4BAAS,CAAA;IACT,4BAAS,CAAA;IACT,4BAAS,CAAA;IACT,4BAAS,CAAA;IACT,4BAAS,CAAA;AACb,CAAC,EANW,eAAe,GAAf,uBAAe,KAAf,uBAAe,QAM1B"}
1
+ {"version":3,"file":"inline-object.js","sourceRoot":"","sources":["../../../../src/transport/generated/model/inline-object.ts"],"names":[],"mappings":";AAAA,iBAAiB;AACjB;;;;;;;;;;GAUG"}
@@ -1,2 +1,8 @@
1
- import { AuditLogCreationData } from './interface';
2
- export declare function auditLog(auditLogData: AuditLogCreationData): Promise<import("axios").AxiosResponse<void>>;
1
+ import { DefaultApi } from './generated';
2
+ import { IAuditLogTransport, IAuditLogCreationData } from './interface';
3
+ export declare class Transport implements IAuditLogTransport {
4
+ protected apiUrl: string;
5
+ api: DefaultApi;
6
+ constructor(apiUrl: string);
7
+ create(auditLogData: IAuditLogCreationData): Promise<void>;
8
+ }
@@ -20,15 +20,20 @@ var __rest = (this && this.__rest) || function (s, e) {
20
20
  };
21
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
22
  const generated_1 = require("./generated");
23
- const api = new generated_1.DefaultApi({
24
- basePath: process.env.AUDIT_LOG_API_URL,
25
- });
26
- function auditLog(auditLogData) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const { countryCode, payload } = auditLogData, data = __rest(auditLogData, ["countryCode", "payload"]);
29
- const dataToSend = Object.assign({}, data, { countryCode: countryCode, payload });
30
- return api.v1LogPost(dataToSend);
31
- });
23
+ class Transport {
24
+ constructor(apiUrl) {
25
+ this.apiUrl = apiUrl;
26
+ this.api = new generated_1.DefaultApi({
27
+ basePath: this.apiUrl,
28
+ });
29
+ }
30
+ create(auditLogData) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const { payload } = auditLogData, data = __rest(auditLogData, ["payload"]);
33
+ const dataToSend = Object.assign({}, data, { payload });
34
+ yield this.api.v1LogPost(dataToSend);
35
+ });
36
+ }
32
37
  }
33
- exports.auditLog = auditLog;
38
+ exports.Transport = Transport;
34
39
  //# sourceMappingURL=implementation.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/transport/implementation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwC;AAIxC,MAAM,GAAG,GAAG,IAAI,sBAAU,CAAC;IACzB,QAAQ,EAAE,OAAO,CAAC,GAAG,CAAC,iBAAiB;CACxC,CAAC,CAAA;AAEF,SAAsB,QAAQ,CAAC,YAAkC;;QAC/D,MAAM,EAAE,WAAW,EAAE,OAAO,KAAc,YAAY,EAAxB,uDAAwB,CAAA;QAEtD,MAAM,UAAU,qBACX,IAAI,IACP,WAAW,EAAE,WAA8B,EAC3C,OAAO,GACR,CAAA;QAED,OAAO,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;CAAA;AAVD,4BAUC"}
1
+ {"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/transport/implementation.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,2CAAwC;AAGxC,MAAa,SAAS;IAGpB,YAAsB,MAAc;QAAd,WAAM,GAAN,MAAM,CAAQ;QAClC,IAAI,CAAC,GAAG,GAAG,IAAI,sBAAU,CAAC;YACxB,QAAQ,EAAE,IAAI,CAAC,MAAM;SACtB,CAAC,CAAA;IACJ,CAAC;IAEK,MAAM,CAAC,YAAmC;;YAC9C,MAAM,EAAE,OAAO,KAAc,YAAY,EAAxB,wCAAwB,CAAA;YAEzC,MAAM,UAAU,qBACX,IAAI,IACP,OAAO,GACR,CAAA;YAED,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACtC,CAAC;KAAA;CACF;AAnBD,8BAmBC"}
@@ -1,5 +1,8 @@
1
- import { AuditLogData } from '..';
2
- export declare type AuditLogCreationData = AuditLogData & {
1
+ import { IAuditLogData } from '..';
2
+ export declare type IAuditLogCreationData = IAuditLogData & {
3
3
  id: string;
4
4
  timestamp: number;
5
5
  };
6
+ export interface IAuditLogTransport {
7
+ create: (data: IAuditLogCreationData) => Promise<void>;
8
+ }
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@payfit/audit-log",
3
- "version": "1.0.0-alpha4",
3
+ "version": "1.0.0-alpha6",
4
4
  "description": "Library to handle audit logs at Payfit",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "test": "echo \"Error: no test specified\" && exit 1",
8
+ "type:check": "tsc --noEmit",
8
9
  "build": "rimraf dist && tsc",
9
10
  "prepublish": "npm run build"
10
11
  },
@@ -0,0 +1,22 @@
1
+ import { AuditLogger } from '../src'
2
+
3
+ const logger = new AuditLogger({
4
+ apiUrl: 'http://localhost:8090',
5
+ environment: 'TEST-env',
6
+ })
7
+
8
+ async function main() {
9
+ await logger.log({
10
+ countryCode: 'fr',
11
+ event: 'signin',
12
+ namespace: 'auth',
13
+ service: 'auth',
14
+ payload: {
15
+ isTest: true,
16
+ },
17
+ })
18
+ }
19
+
20
+ main().catch(err => {
21
+ console.log('Error:', err)
22
+ })
package/src/index.ts CHANGED
@@ -1,35 +1,124 @@
1
1
  import { v4 as uuidV4 } from 'uuid'
2
- import * as transport from './transport/implementation'
2
+ import { IAuditLogTransport } from './transport/interface'
3
+ import { Transport } from './transport/implementation'
3
4
 
4
- export interface AuditLogData {
5
- countryCode: string
5
+ /**
6
+ * Data to audit log.
7
+ */
8
+ export interface IAuditLogData {
9
+ /**
10
+ * The data specific to the audit log.
11
+ * For example, if we add a bonus to an employee, it could contain the amount, the impacted employeeId, etc...
12
+ */
6
13
  payload?: object
7
- isImpersonated?: boolean
8
- isSystem?: boolean
14
+
15
+ /**
16
+ * The buisness domain impacted.
17
+ * e.g documents, authentication, ...
18
+ */
9
19
  namespace: string
20
+
21
+ /**
22
+ * The service name (tech).
23
+ * e.g files, payroll-api-v2, auth, ...
24
+ */
10
25
  service: string
26
+
27
+ /**
28
+ * The name of the event.
29
+ * e.g. signIn, passwordUpdated, bonusAdded, ...
30
+ */
11
31
  event: string
12
- holdingId?: string
13
- companyId?: string
14
- employeeId?: string
15
- individualId?: string
16
- roleId?: string
17
- userIp?: string
18
- specialRole?: string
19
- email?: string
32
+
33
+ /**
34
+ * The data that describes who did perform the logged action.
35
+ */
36
+ account: IAuditLogAuthData
37
+
38
+ /**
39
+ * The scope of the audit log
40
+ */
41
+ scope: IAuditLogScope
42
+ }
43
+
44
+ /**
45
+ * Data used to indentify who performed an action
46
+ */
47
+ export type IAuditLogAuthData =
48
+ | {
49
+ /**
50
+ * Tells if the action has been made during a siginAs
51
+ */
52
+ isImpersonated?: boolean
53
+
54
+ // the "account" infos
55
+ holdingId?: string
56
+ companyId?: string
57
+ employeeId?: string
58
+ individualId: string
59
+ roleId?: string
60
+
61
+ /**
62
+ *
63
+ */
64
+ countryCode?: string
65
+ /**
66
+ * The IP address of the user
67
+ */
68
+ userIp?: string
69
+ /**
70
+ * The email address of the user
71
+ */
72
+ email?: string
73
+ }
74
+ | {
75
+ /* Indicates that the action has been performed by the system */
76
+ isSystem: true
77
+ }
78
+
79
+ /**
80
+ * Data used to "scope" the audit log.
81
+ * Might be useful to retrieve all actions performed in a holding, a company, or on an employee.
82
+ */
83
+ export type IAuditLogScope =
84
+ | {
85
+ holdingId: string
86
+ }
87
+ | {
88
+ companyId: string
89
+ employeeId?: string
90
+ }
91
+ | null
92
+
93
+ // warning: modifying this interface means probably make a breaking change to the SDK
94
+ export interface IAuditLogger {
95
+ log: (data: IAuditLogData) => Promise<void>
96
+ }
97
+
98
+ export interface IAuditLoggerInitialization {
99
+ apiUrl: string
100
+ environment: string
20
101
  }
21
102
 
22
- export async function auditLog(params: AuditLogData): Promise<void> {
23
- const uuid = uuidV4()
24
- const environment = process.env.ENVIRONMENT
25
- const timestamp = new Date().getTime()
103
+ export class AuditLogger implements IAuditLogger {
104
+ private transport: IAuditLogTransport
26
105
 
27
- const log = {
28
- ...params,
29
- id: uuid,
30
- environment,
31
- timestamp,
106
+ constructor(protected params: IAuditLoggerInitialization) {
107
+ this.transport = new Transport(params.apiUrl)
32
108
  }
33
109
 
34
- await transport.auditLog(log)
110
+ async log(params: IAuditLogData) {
111
+ const uuid = uuidV4()
112
+ const environment = this.params.environment
113
+ const timestamp = new Date().getTime()
114
+
115
+ const log = {
116
+ ...params,
117
+ id: uuid,
118
+ environment,
119
+ timestamp,
120
+ }
121
+
122
+ await this.transport.create(log)
123
+ }
35
124
  }
@@ -30,7 +30,7 @@ export interface InlineObject {
30
30
  * @type {string}
31
31
  * @memberof InlineObject
32
32
  */
33
- countryCode: CountryCodeEnum;
33
+ countryCode?: string;
34
34
  /**
35
35
  * Audit log event payload
36
36
  * @type {object}
@@ -123,17 +123,4 @@ export interface InlineObject {
123
123
  email?: string;
124
124
  }
125
125
 
126
- /**
127
- * @export
128
- * @enum {string}
129
- */
130
- export enum CountryCodeEnum {
131
- FR = 'fr',
132
- DE = 'de',
133
- IT = 'it',
134
- ES = 'es',
135
- GB = 'gb'
136
- }
137
-
138
-
139
126
 
@@ -1,19 +1,23 @@
1
1
  import { DefaultApi } from './generated'
2
- import { CountryCodeEnum } from './generated/model'
3
- import { AuditLogCreationData } from './interface'
2
+ import { IAuditLogTransport, IAuditLogCreationData } from './interface'
4
3
 
5
- const api = new DefaultApi({
6
- basePath: process.env.AUDIT_LOG_API_URL,
7
- })
4
+ export class Transport implements IAuditLogTransport {
5
+ api: DefaultApi
8
6
 
9
- export async function auditLog(auditLogData: AuditLogCreationData) {
10
- const { countryCode, payload, ...data } = auditLogData
11
-
12
- const dataToSend = {
13
- ...data,
14
- countryCode: countryCode as CountryCodeEnum,
15
- payload,
7
+ constructor(protected apiUrl: string) {
8
+ this.api = new DefaultApi({
9
+ basePath: this.apiUrl,
10
+ })
16
11
  }
17
12
 
18
- return api.v1LogPost(dataToSend)
13
+ async create(auditLogData: IAuditLogCreationData) {
14
+ const { payload, ...data } = auditLogData
15
+
16
+ const dataToSend = {
17
+ ...data,
18
+ payload,
19
+ }
20
+
21
+ await this.api.v1LogPost(dataToSend)
22
+ }
19
23
  }
@@ -1,6 +1,10 @@
1
- import { AuditLogData } from '..'
1
+ import { IAuditLogData } from '..'
2
2
 
3
- export type AuditLogCreationData = AuditLogData & {
3
+ export type IAuditLogCreationData = IAuditLogData & {
4
4
  id: string
5
5
  timestamp: number
6
6
  }
7
+
8
+ export interface IAuditLogTransport {
9
+ create: (data: IAuditLogCreationData) => Promise<void>
10
+ }