@payfit/audit-log 1.0.0-alpha3 → 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.
@@ -0,0 +1,84 @@
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
+ */
9
+ payload?: object;
10
+ /**
11
+ * The buisness domain impacted.
12
+ * e.g documents, authentication, ...
13
+ */
14
+ namespace: string;
15
+ /**
16
+ * The service name (tech).
17
+ * e.g files, payroll-api-v2, auth, ...
18
+ */
19
+ service: string;
20
+ /**
21
+ * The name of the event.
22
+ * e.g. signIn, passwordUpdated, bonusAdded, ...
23
+ */
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;
42
+ holdingId?: string;
43
+ companyId?: string;
44
+ employeeId?: string;
45
+ individualId: string;
46
+ roleId?: string;
47
+ /**
48
+ *
49
+ */
50
+ countryCode?: string;
51
+ /**
52
+ * The IP address of the user
53
+ */
54
+ userIp?: string;
55
+ /**
56
+ * The email address of the user
57
+ */
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>;
84
+ }
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"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Audit Logs
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: damian.bursztyn@payfit.com
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import { AxiosPromise, AxiosInstance } from 'axios';
13
+ import { Configuration } from '../configuration';
14
+ import { RequestArgs, BaseAPI } from '../base';
15
+ import { InlineObject } from '../model';
16
+ /**
17
+ * DefaultApi - axios parameter creator
18
+ * @export
19
+ */
20
+ export declare const DefaultApiAxiosParamCreator: (configuration?: Configuration | undefined) => {
21
+ /**
22
+ *
23
+ * @summary Creates Audit Log event
24
+ * @param {InlineObject} inlineObject
25
+ * @param {*} [options] Override http request option.
26
+ * @throws {RequiredError}
27
+ */
28
+ v1LogPost(inlineObject: InlineObject, options?: any): RequestArgs;
29
+ };
30
+ /**
31
+ * DefaultApi - functional programming interface
32
+ * @export
33
+ */
34
+ export declare const DefaultApiFp: (configuration?: Configuration | undefined) => {
35
+ /**
36
+ *
37
+ * @summary Creates Audit Log event
38
+ * @param {InlineObject} inlineObject
39
+ * @param {*} [options] Override http request option.
40
+ * @throws {RequiredError}
41
+ */
42
+ v1LogPost(inlineObject: InlineObject, options?: any): (axios?: AxiosInstance | undefined, basePath?: string | undefined) => AxiosPromise<void>;
43
+ };
44
+ /**
45
+ * DefaultApi - factory interface
46
+ * @export
47
+ */
48
+ export declare const DefaultApiFactory: (configuration?: Configuration | undefined, basePath?: string | undefined, axios?: AxiosInstance | undefined) => {
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(inlineObject: InlineObject, options?: any): AxiosPromise<void>;
57
+ };
58
+ /**
59
+ * DefaultApi - object-oriented interface
60
+ * @export
61
+ * @class DefaultApi
62
+ * @extends {BaseAPI}
63
+ */
64
+ export declare class DefaultApi extends BaseAPI {
65
+ /**
66
+ *
67
+ * @summary Creates Audit Log event
68
+ * @param {InlineObject} inlineObject
69
+ * @param {*} [options] Override http request option.
70
+ * @throws {RequiredError}
71
+ * @memberof DefaultApi
72
+ */
73
+ v1LogPost(inlineObject: InlineObject, options?: any): AxiosPromise<void>;
74
+ }
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Audit Logs
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: damian.bursztyn@payfit.com
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ export * from './api/default-api';
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Audit Logs
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: damian.bursztyn@payfit.com
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ import { Configuration } from "./configuration";
13
+ import { AxiosInstance } from 'axios';
14
+ export declare const BASE_PATH: string;
15
+ /**
16
+ *
17
+ * @export
18
+ */
19
+ export declare const COLLECTION_FORMATS: {
20
+ csv: string;
21
+ ssv: string;
22
+ tsv: string;
23
+ pipes: string;
24
+ };
25
+ /**
26
+ *
27
+ * @export
28
+ * @interface RequestArgs
29
+ */
30
+ export interface RequestArgs {
31
+ url: string;
32
+ options: any;
33
+ }
34
+ /**
35
+ *
36
+ * @export
37
+ * @class BaseAPI
38
+ */
39
+ export declare class BaseAPI {
40
+ protected basePath: string;
41
+ protected axios: AxiosInstance;
42
+ protected configuration: Configuration | undefined;
43
+ constructor(configuration?: Configuration, basePath?: string, axios?: AxiosInstance);
44
+ }
45
+ /**
46
+ *
47
+ * @export
48
+ * @class RequiredError
49
+ * @extends {Error}
50
+ */
51
+ export declare class RequiredError extends Error {
52
+ field: string;
53
+ name: "RequiredError";
54
+ constructor(field: string, msg?: string);
55
+ }
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Audit Logs
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: damian.bursztyn@payfit.com
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ export interface ConfigurationParameters {
13
+ apiKey?: string | ((name: string) => string);
14
+ username?: string;
15
+ password?: string;
16
+ accessToken?: string | ((name?: string, scopes?: string[]) => string);
17
+ basePath?: string;
18
+ baseOptions?: any;
19
+ }
20
+ export declare class Configuration {
21
+ /**
22
+ * parameter for apiKey security
23
+ * @param name security name
24
+ * @memberof Configuration
25
+ */
26
+ apiKey?: string | ((name: string) => string);
27
+ /**
28
+ * parameter for basic security
29
+ *
30
+ * @type {string}
31
+ * @memberof Configuration
32
+ */
33
+ username?: string;
34
+ /**
35
+ * parameter for basic security
36
+ *
37
+ * @type {string}
38
+ * @memberof Configuration
39
+ */
40
+ password?: string;
41
+ /**
42
+ * parameter for oauth2 security
43
+ * @param name security name
44
+ * @param scopes oauth2 scope
45
+ * @memberof Configuration
46
+ */
47
+ accessToken?: string | ((name?: string, scopes?: string[]) => string);
48
+ /**
49
+ * override base path
50
+ *
51
+ * @type {string}
52
+ * @memberof Configuration
53
+ */
54
+ basePath?: string;
55
+ /**
56
+ * base options for axios calls
57
+ *
58
+ * @type {any}
59
+ * @memberof Configuration
60
+ */
61
+ baseOptions?: any;
62
+ constructor(param?: ConfigurationParameters);
63
+ }
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Audit Logs
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: damian.bursztyn@payfit.com
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ export * from "./api";
13
+ export * from "./configuration";
@@ -0,0 +1 @@
1
+ export * from './inline-object';
@@ -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":""}
@@ -0,0 +1,120 @@
1
+ /**
2
+ * Audit Logs
3
+ * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
4
+ *
5
+ * The version of the OpenAPI document: 1.0.0
6
+ * Contact: damian.bursztyn@payfit.com
7
+ *
8
+ * NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
9
+ * https://openapi-generator.tech
10
+ * Do not edit the class manually.
11
+ */
12
+ /**
13
+ *
14
+ * @export
15
+ * @interface InlineObject
16
+ */
17
+ export interface InlineObject {
18
+ /**
19
+ * Audit log event unique identifier
20
+ * @type {string}
21
+ * @memberof InlineObject
22
+ */
23
+ id: string;
24
+ /**
25
+ * Audit log event country code
26
+ * @type {string}
27
+ * @memberof InlineObject
28
+ */
29
+ countryCode?: string;
30
+ /**
31
+ * Audit log event payload
32
+ * @type {object}
33
+ * @memberof InlineObject
34
+ */
35
+ payload?: object;
36
+ /**
37
+ *
38
+ * @type {boolean}
39
+ * @memberof InlineObject
40
+ */
41
+ isImpersonated?: boolean;
42
+ /**
43
+ *
44
+ * @type {boolean}
45
+ * @memberof InlineObject
46
+ */
47
+ isSystem?: boolean;
48
+ /**
49
+ * Audit log event namespace (business related)
50
+ * @type {string}
51
+ * @memberof InlineObject
52
+ */
53
+ namespace: string;
54
+ /**
55
+ * Audit log event namespace (technical related)
56
+ * @type {string}
57
+ * @memberof InlineObject
58
+ */
59
+ service: string;
60
+ /**
61
+ * Audit log event type
62
+ * @type {string}
63
+ * @memberof InlineObject
64
+ */
65
+ event?: string;
66
+ /**
67
+ * Audit log event environment
68
+ * @type {string}
69
+ * @memberof InlineObject
70
+ */
71
+ environment?: string;
72
+ /**
73
+ * Audit log event holdingId
74
+ * @type {string}
75
+ * @memberof InlineObject
76
+ */
77
+ holdingId?: string;
78
+ /**
79
+ * Audit log event companyId
80
+ * @type {string}
81
+ * @memberof InlineObject
82
+ */
83
+ companyId?: string;
84
+ /**
85
+ * Audit log event employeeId
86
+ * @type {string}
87
+ * @memberof InlineObject
88
+ */
89
+ employeeId?: string;
90
+ /**
91
+ * Audit log event individualId
92
+ * @type {string}
93
+ * @memberof InlineObject
94
+ */
95
+ individualId?: string;
96
+ /**
97
+ * Audit log event roleId
98
+ * @type {string}
99
+ * @memberof InlineObject
100
+ */
101
+ roleId?: string;
102
+ /**
103
+ * Audit log event userIp
104
+ * @type {string}
105
+ * @memberof InlineObject
106
+ */
107
+ userIp?: string;
108
+ /**
109
+ * Audit log event specialRole
110
+ * @type {string}
111
+ * @memberof InlineObject
112
+ */
113
+ specialRole?: string;
114
+ /**
115
+ * Audit log event email
116
+ * @type {string}
117
+ * @memberof InlineObject
118
+ */
119
+ email?: string;
120
+ }
@@ -12,46 +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
- /**
28
- * @export
29
- * @enum {string}
30
- */
31
- var NamespaceEnum;
32
- (function (NamespaceEnum) {
33
- NamespaceEnum["MANAGER"] = "manager";
34
- NamespaceEnum["VERSIONER"] = "versioner";
35
- NamespaceEnum["MAILER"] = "mailer";
36
- })(NamespaceEnum = exports.NamespaceEnum || (exports.NamespaceEnum = {}));
37
- /**
38
- * @export
39
- * @enum {string}
40
- */
41
- var ServiceEnum;
42
- (function (ServiceEnum) {
43
- ServiceEnum["FILES_V2"] = "files-v2";
44
- ServiceEnum["PAYROLL_V2"] = "payroll-v2";
45
- ServiceEnum["HR_API"] = "hr-api";
46
- })(ServiceEnum = exports.ServiceEnum || (exports.ServiceEnum = {}));
47
- /**
48
- * @export
49
- * @enum {string}
50
- */
51
- var EventEnum;
52
- (function (EventEnum) {
53
- EventEnum["CREATE"] = "create";
54
- EventEnum["UPDATE"] = "update";
55
- EventEnum["DELETE"] = "delete";
56
- })(EventEnum = exports.EventEnum || (exports.EventEnum = {}));
57
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;AACD;;;MAGM;AACN,IAAY,aAIX;AAJD,WAAY,aAAa;IACrB,oCAAmB,CAAA;IACnB,wCAAuB,CAAA;IACvB,kCAAiB,CAAA;AACrB,CAAC,EAJW,aAAa,GAAb,qBAAa,KAAb,qBAAa,QAIxB;AACD;;;MAGM;AACN,IAAY,WAIX;AAJD,WAAY,WAAW;IACnB,oCAAqB,CAAA;IACrB,wCAAyB,CAAA;IACzB,gCAAiB,CAAA;AACrB,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AACD;;;MAGM;AACN,IAAY,SAIX;AAJD,WAAY,SAAS;IACjB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;IACjB,8BAAiB,CAAA;AACrB,CAAC,EAJW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAIpB"}
1
+ {"version":3,"file":"inline-object.js","sourceRoot":"","sources":["../../../../src/transport/generated/model/inline-object.ts"],"names":[],"mappings":";AAAA,iBAAiB;AACjB;;;;;;;;;;GAUG"}
@@ -0,0 +1,8 @@
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, namespace, service, event, payload } = auditLogData, data = __rest(auditLogData, ["countryCode", "namespace", "service", "event", "payload"]);
29
- const dataToSend = Object.assign({}, data, { countryCode: countryCode, namespace: namespace, service: service, event: event, 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;AASxC,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,EACJ,WAAW,EACX,SAAS,EACT,OAAO,EACP,KAAK,EACL,OAAO,KAEL,YAAY,EADd,wFACc,CAAA;QAEhB,MAAM,UAAU,qBACX,IAAI,IACP,WAAW,EAAE,WAA8B,EAC3C,SAAS,EAAE,SAA0B,EACrC,OAAO,EAAE,OAAsB,EAC/B,KAAK,EAAE,KAAkB,EACzB,OAAO,GACR,CAAA;QAED,OAAO,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;IAClC,CAAC;CAAA;AApBD,4BAoBC"}
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"}
@@ -0,0 +1,8 @@
1
+ import { IAuditLogData } from '..';
2
+ export declare type IAuditLogCreationData = IAuditLogData & {
3
+ id: string;
4
+ timestamp: number;
5
+ };
6
+ export interface IAuditLogTransport {
7
+ create: (data: IAuditLogCreationData) => Promise<void>;
8
+ }
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@payfit/audit-log",
3
- "version": "1.0.0-alpha3",
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
  },
11
- "types": "./src/index.ts",
12
12
  "author": "",
13
13
  "license": "ISC",
14
14
  "dependencies": {
15
- "axios": "^0.19.2",
16
- "lodash": "^4.17.15",
17
- "uuid": "^7.0.0"
15
+ "axios": "0.19.2",
16
+ "lodash": "4.17.15",
17
+ "uuid": "7.0.0"
18
18
  },
19
19
  "devDependencies": {
20
- "@types/lodash": "^4.14.149",
21
- "@types/uuid": "^3.4.7",
20
+ "@types/lodash": "4.14.149",
21
+ "@types/uuid": "3.4.7",
22
22
  "prettier": "1.18.2",
23
23
  "rimraf": "2.6.3",
24
24
  "ts-node": "8.3.0",
@@ -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}
@@ -54,19 +54,19 @@ export interface InlineObject {
54
54
  * @type {string}
55
55
  * @memberof InlineObject
56
56
  */
57
- namespace: NamespaceEnum;
57
+ namespace: string;
58
58
  /**
59
59
  * Audit log event namespace (technical related)
60
60
  * @type {string}
61
61
  * @memberof InlineObject
62
62
  */
63
- service: ServiceEnum;
63
+ service: string;
64
64
  /**
65
65
  * Audit log event type
66
66
  * @type {string}
67
67
  * @memberof InlineObject
68
68
  */
69
- event?: EventEnum;
69
+ event?: string;
70
70
  /**
71
71
  * Audit log event environment
72
72
  * @type {string}
@@ -123,44 +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
- * @export
139
- * @enum {string}
140
- */
141
- export enum NamespaceEnum {
142
- MANAGER = 'manager',
143
- VERSIONER = 'versioner',
144
- MAILER = 'mailer'
145
- }
146
- /**
147
- * @export
148
- * @enum {string}
149
- */
150
- export enum ServiceEnum {
151
- FILES_V2 = 'files-v2',
152
- PAYROLL_V2 = 'payroll-v2',
153
- HR_API = 'hr-api'
154
- }
155
- /**
156
- * @export
157
- * @enum {string}
158
- */
159
- export enum EventEnum {
160
- CREATE = 'create',
161
- UPDATE = 'update',
162
- DELETE = 'delete'
163
- }
164
-
165
-
166
126
 
@@ -1,34 +1,23 @@
1
1
  import { DefaultApi } from './generated'
2
- import {
3
- CountryCodeEnum,
4
- NamespaceEnum,
5
- EventEnum,
6
- ServiceEnum,
7
- } from './generated/model'
8
- import { AuditLogCreationData } from './interface'
2
+ import { IAuditLogTransport, IAuditLogCreationData } from './interface'
9
3
 
10
- const api = new DefaultApi({
11
- basePath: process.env.AUDIT_LOG_API_URL,
12
- })
4
+ export class Transport implements IAuditLogTransport {
5
+ api: DefaultApi
13
6
 
14
- export async function auditLog(auditLogData: AuditLogCreationData) {
15
- const {
16
- countryCode,
17
- namespace,
18
- service,
19
- event,
20
- payload,
21
- ...data
22
- } = auditLogData
23
-
24
- const dataToSend = {
25
- ...data,
26
- countryCode: countryCode as CountryCodeEnum,
27
- namespace: namespace as NamespaceEnum,
28
- service: service as ServiceEnum,
29
- event: event as EventEnum,
30
- payload,
7
+ constructor(protected apiUrl: string) {
8
+ this.api = new DefaultApi({
9
+ basePath: this.apiUrl,
10
+ })
31
11
  }
32
12
 
33
- 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
+ }
34
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
+ }
package/tsconfig.json CHANGED
@@ -1,5 +1,6 @@
1
1
  {
2
2
  "compilerOptions": {
3
+ "declaration": true,
3
4
  "target": "es6",
4
5
  "module": "commonjs",
5
6
  "lib": ["es7", "esnext.asynciterable", "es2017"],