@payfit/audit-log 1.0.2 → 1.0.3

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
@@ -81,5 +81,5 @@ export declare class AuditLogger implements IAuditLogger {
81
81
  protected params: IAuditLoggerInitialization;
82
82
  private transport;
83
83
  constructor(params: IAuditLoggerInitialization);
84
- log(data: IAuditLogData): Promise<void>;
84
+ log({ scope, account, ...data }: IAuditLogData): Promise<void>;
85
85
  }
package/dist/index.js CHANGED
@@ -7,6 +7,17 @@ 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 __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
10
21
  Object.defineProperty(exports, "__esModule", { value: true });
11
22
  const uuid_1 = require("uuid");
12
23
  const implementation_1 = require("./transport/implementation");
@@ -15,13 +26,14 @@ class AuditLogger {
15
26
  this.params = params;
16
27
  this.transport = new implementation_1.Transport(params.apiUrl);
17
28
  }
18
- log(data) {
29
+ log(_a) {
30
+ var { scope, account } = _a, data = __rest(_a, ["scope", "account"]);
19
31
  return __awaiter(this, void 0, void 0, function* () {
20
32
  const uuid = uuid_1.v4();
21
33
  const { environment, service } = this.params;
22
34
  const timestamp = new Date().getTime();
23
- const log = Object.assign({}, data, { service, id: uuid, environment,
24
- timestamp });
35
+ const log = Object.assign({}, data, account, { service, id: uuid, environment,
36
+ timestamp }, (scope && { scope }));
25
37
  yield this.transport.create(log);
26
38
  });
27
39
  }
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,+BAAmC;AAEnC,+DAAsD;AAqGtD,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,IAAmB;;YAC3B,MAAM,IAAI,GAAG,SAAM,EAAE,CAAA;YACrB,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;YAC5C,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;YAEtC,MAAM,GAAG,qBACJ,IAAI,IACP,OAAO,EACP,EAAE,EAAE,IAAI,EACR,WAAW;gBACX,SAAS,GACV,CAAA;YAED,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;QAClC,CAAC;KAAA;CACF;AAtBD,kCAsBC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+BAAmC;AAEnC,+DAAsD;AAqGtD,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,EAA0C;YAA1C,EAAE,KAAK,EAAE,OAAO,OAA0B,EAAxB,uCAAO;;YACjC,MAAM,IAAI,GAAG,SAAM,EAAE,CAAA;YACrB,MAAM,EAAE,WAAW,EAAE,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,CAAA;YAC5C,MAAM,SAAS,GAAG,IAAI,IAAI,EAAE,CAAC,OAAO,EAAE,CAAA;YAEtC,MAAM,GAAG,qBACJ,IAAI,EACJ,OAAO,IACV,OAAO,EACP,EAAE,EAAE,IAAI,EACR,WAAW;gBACX,SAAS,IACN,CAAC,KAAK,IAAI,EAAE,KAAK,EAAE,CAAC,CACxB,CAAA;YAED,MAAM,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;;KACjC;CACF;AAxBD,kCAwBC"}
@@ -123,4 +123,10 @@ export interface InlineObject {
123
123
  * @memberof InlineObject
124
124
  */
125
125
  email?: string;
126
+ /**
127
+ * Audit log event scope
128
+ * @type {object}
129
+ * @memberof InlineObject
130
+ */
131
+ scope?: object;
126
132
  }
@@ -1,8 +1,9 @@
1
1
  import { DefaultApi } from './generated';
2
- import { IAuditLogTransport, IAuditLogCreationData } from './interface';
2
+ import { InlineObject } from './generated/model';
3
+ import { IAuditLogTransport } from './interface';
3
4
  export declare class Transport implements IAuditLogTransport {
4
5
  protected apiUrl: string;
5
6
  api: DefaultApi;
6
7
  constructor(apiUrl: string);
7
- create(auditLogData: IAuditLogCreationData): Promise<void>;
8
+ create(auditLogData: InlineObject): Promise<void>;
8
9
  }
@@ -7,17 +7,6 @@ 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 __rest = (this && this.__rest) || function (s, e) {
11
- var t = {};
12
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
- t[p] = s[p];
14
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
- t[p[i]] = s[p[i]];
18
- }
19
- return t;
20
- };
21
10
  Object.defineProperty(exports, "__esModule", { value: true });
22
11
  const generated_1 = require("./generated");
23
12
  class Transport {
@@ -29,9 +18,7 @@ class Transport {
29
18
  }
30
19
  create(auditLogData) {
31
20
  return __awaiter(this, void 0, void 0, function* () {
32
- const { account } = auditLogData, logDataWithoutAccount = __rest(auditLogData, ["account"]);
33
- const dataToSend = Object.assign({}, logDataWithoutAccount, account);
34
- yield this.api.v1LogPost(dataToSend);
21
+ yield this.api.v1LogPost(auditLogData);
35
22
  });
36
23
  }
37
24
  }
@@ -1 +1 @@
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,KAA+B,YAAY,EAAzC,yDAAyC,CAAA;YAE1D,MAAM,UAAU,qBACX,qBAAqB,EACrB,OAAO,CACX,CAAA;YAED,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,UAAU,CAAC,CAAA;QACtC,CAAC;KAAA;CACF;AAnBD,8BAmBC"}
1
+ {"version":3,"file":"implementation.js","sourceRoot":"","sources":["../../src/transport/implementation.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,2CAAwC;AAKxC,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,YAA0B;;YACrC,MAAM,IAAI,CAAC,GAAG,CAAC,SAAS,CAAC,YAAY,CAAC,CAAA;QACxC,CAAC;KAAA;CACF;AAZD,8BAYC"}
@@ -1,9 +1,24 @@
1
- import { IAuditLogData } from '..';
2
- export declare type IAuditLogCreationData = IAuditLogData & {
1
+ export declare type IAuditLogCreationData = {
3
2
  id: string;
4
3
  timestamp: number;
5
4
  environment: string;
6
5
  service: string;
6
+ scope?: object;
7
+ countryCode?: string;
8
+ payload?: object;
9
+ internalId?: string;
10
+ isSystem?: boolean;
11
+ namespace: string;
12
+ event: string;
13
+ target: string;
14
+ holdingId?: string;
15
+ companyId?: string;
16
+ employeeId?: string;
17
+ individualId?: string;
18
+ roleId?: string;
19
+ userIp?: string;
20
+ specialRole?: string;
21
+ email?: string;
7
22
  };
8
23
  export interface IAuditLogTransport {
9
24
  create: (data: IAuditLogCreationData) => Promise<void>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payfit/audit-log",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "Library to handle audit logs at Payfit",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/index.ts CHANGED
@@ -108,17 +108,19 @@ export class AuditLogger implements IAuditLogger {
108
108
  this.transport = new Transport(params.apiUrl)
109
109
  }
110
110
 
111
- async log(data: IAuditLogData) {
111
+ async log({ scope, account, ...data }: IAuditLogData) {
112
112
  const uuid = uuidV4()
113
113
  const { environment, service } = this.params
114
114
  const timestamp = new Date().getTime()
115
115
 
116
116
  const log = {
117
117
  ...data,
118
+ ...account,
118
119
  service,
119
120
  id: uuid,
120
121
  environment,
121
122
  timestamp,
123
+ ...(scope && { scope }),
122
124
  }
123
125
 
124
126
  await this.transport.create(log)
@@ -127,6 +127,12 @@ export interface InlineObject {
127
127
  * @memberof InlineObject
128
128
  */
129
129
  email?: string;
130
+ /**
131
+ * Audit log event scope
132
+ * @type {object}
133
+ * @memberof InlineObject
134
+ */
135
+ scope?: object;
130
136
  }
131
137
 
132
138
 
@@ -1,5 +1,7 @@
1
1
  import { DefaultApi } from './generated'
2
- import { IAuditLogTransport, IAuditLogCreationData } from './interface'
2
+ import { InlineObject } from './generated/model'
3
+
4
+ import { IAuditLogTransport } from './interface'
3
5
 
4
6
  export class Transport implements IAuditLogTransport {
5
7
  api: DefaultApi
@@ -10,14 +12,7 @@ export class Transport implements IAuditLogTransport {
10
12
  })
11
13
  }
12
14
 
13
- async create(auditLogData: IAuditLogCreationData) {
14
- const { account, ...logDataWithoutAccount } = auditLogData
15
-
16
- const dataToSend = {
17
- ...logDataWithoutAccount,
18
- ...account,
19
- }
20
-
21
- await this.api.v1LogPost(dataToSend)
15
+ async create(auditLogData: InlineObject) {
16
+ await this.api.v1LogPost(auditLogData)
22
17
  }
23
18
  }
@@ -1,10 +1,26 @@
1
1
  import { IAuditLogData } from '..'
2
2
 
3
- export type IAuditLogCreationData = IAuditLogData & {
3
+ export type IAuditLogCreationData = {
4
4
  id: string
5
5
  timestamp: number
6
6
  environment: string
7
7
  service: string
8
+ scope?: object
9
+ countryCode?: string
10
+ payload?: object
11
+ internalId?: string
12
+ isSystem?: boolean
13
+ namespace: string
14
+ event: string
15
+ target: string
16
+ holdingId?: string
17
+ companyId?: string
18
+ employeeId?: string
19
+ individualId?: string
20
+ roleId?: string
21
+ userIp?: string
22
+ specialRole?: string
23
+ email?: string
8
24
  }
9
25
 
10
26
  export interface IAuditLogTransport {