@alanszp/audit 4.0.2 → 4.0.5

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/audit.d.ts CHANGED
@@ -1,10 +1,9 @@
1
1
  import { ILogger } from "@alanszp/logger";
2
2
  import { AuditBody } from ".";
3
+ import { AuditWithState } from "./auditWithState";
3
4
  export declare class Audit {
4
5
  logger: ILogger;
5
- additions: Partial<AuditBody>;
6
6
  constructor(logger: ILogger);
7
- log(body: Partial<AuditBody>): void;
8
- add(body: Partial<AuditBody>): void;
9
- merge(body: Partial<AuditBody>): Partial<AuditBody>;
7
+ log(body: AuditBody): void;
8
+ withState(): AuditWithState;
10
9
  }
package/dist/audit.js CHANGED
@@ -4,27 +4,21 @@ exports.Audit = void 0;
4
4
  const logger_1 = require("@alanszp/logger");
5
5
  const lodash_1 = require("lodash");
6
6
  const _1 = require(".");
7
+ const auditWithState_1 = require("./auditWithState");
7
8
  const MissingAuditFieldsError_1 = require("./errors/MissingAuditFieldsError");
8
9
  class Audit {
9
10
  constructor(logger) {
10
11
  this.logger = logger;
11
- this.additions = {};
12
12
  }
13
13
  log(body) {
14
- const completeBody = this.merge(body);
15
- const missingFields = (0, lodash_1.difference)(_1.REQUIRED_FIELDS, Object.keys(completeBody));
14
+ const missingFields = (0, lodash_1.difference)(_1.REQUIRED_FIELDS, Object.keys(body));
16
15
  if (missingFields.length > 0) {
17
16
  throw new MissingAuditFieldsError_1.MissingAuditFieldsError(missingFields);
18
17
  }
19
- const action = completeBody.action;
20
- delete completeBody.action;
21
- this.logger.info(action, Object.assign({ log_type: logger_1.LogType.AUDIT }, completeBody));
18
+ this.logger.info(body.action, Object.assign(Object.assign({ log_type: logger_1.LogType.AUDIT }, body), { action: undefined }));
22
19
  }
23
- add(body) {
24
- this.additions = this.merge(body);
25
- }
26
- merge(body) {
27
- return (0, lodash_1.merge)(this.additions, body);
20
+ withState() {
21
+ return new auditWithState_1.AuditWithState(this);
28
22
  }
29
23
  }
30
24
  exports.Audit = Audit;
package/dist/audit.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":";;;AAAA,4CAAmD;AACnD,mCAA2C;AAC3C,wBAA+C;AAC/C,8EAA2E;AAE3E,MAAa,KAAK;IAKhB,YAAY,MAAe;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAEM,GAAG,CAAC,IAAwB;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAEtC,MAAM,aAAa,GAAG,IAAA,mBAAU,EAC9B,kBAAe,EACf,MAAM,CAAC,IAAI,CAAC,YAAY,CAAC,CAC1B,CAAC;QAEF,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,iDAAuB,CAAC,aAAa,CAAC,CAAC;SAClD;QAED,MAAM,MAAM,GAAG,YAAY,CAAC,MAAgB,CAAC;QAC7C,OAAO,YAAY,CAAC,MAAM,CAAC;QAE3B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,kBAAI,QAAQ,EAAE,gBAAO,CAAC,KAAK,IAAK,YAAY,EAAG,CAAC;IACzE,CAAC;IAEM,GAAG,CAAC,IAAwB;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,IAAwB;QACnC,OAAO,IAAA,cAAK,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;CACF;AAnCD,sBAmCC"}
1
+ {"version":3,"file":"audit.js","sourceRoot":"","sources":["../src/audit.ts"],"names":[],"mappings":";;;AAAA,4CAAmD;AACnD,mCAAoC;AACpC,wBAA+C;AAC/C,qDAAkD;AAClD,8EAA2E;AAE3E,MAAa,KAAK;IAGhB,YAAY,MAAe;QACzB,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAEM,GAAG,CAAC,IAAe;QACxB,MAAM,aAAa,GAAG,IAAA,mBAAU,EAAC,kBAAe,EAAE,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAErE,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,IAAI,iDAAuB,CAAC,aAAa,CAAC,CAAC;SAClD;QAED,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,gCAC1B,QAAQ,EAAE,gBAAO,CAAC,KAAK,IACpB,IAAI,KACP,MAAM,EAAE,SAAS,IACjB,CAAC;IACL,CAAC;IAEM,SAAS;QACd,OAAO,IAAI,+BAAc,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF;AAxBD,sBAwBC"}
@@ -0,0 +1,10 @@
1
+ import { AuditBody } from "./interfaces";
2
+ import { Audit } from "./audit";
3
+ export declare class AuditWithState {
4
+ audit: Audit;
5
+ additions: Partial<AuditBody>;
6
+ constructor(audit: Audit);
7
+ log(body: Partial<AuditBody>): void;
8
+ add(body: Partial<AuditBody>): void;
9
+ merge(body: Partial<AuditBody>): Partial<AuditBody>;
10
+ }
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuditWithState = void 0;
4
+ const lodash_1 = require("lodash");
5
+ class AuditWithState {
6
+ constructor(audit) {
7
+ this.audit = audit;
8
+ this.additions = {};
9
+ }
10
+ log(body) {
11
+ const completeBody = this.merge(body);
12
+ this.audit.log(completeBody);
13
+ }
14
+ add(body) {
15
+ this.additions = this.merge(body);
16
+ }
17
+ merge(body) {
18
+ return (0, lodash_1.merge)(this.additions, body);
19
+ }
20
+ }
21
+ exports.AuditWithState = AuditWithState;
22
+ //# sourceMappingURL=auditWithState.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auditWithState.js","sourceRoot":"","sources":["../src/auditWithState.ts"],"names":[],"mappings":";;;AAAA,mCAA+B;AAI/B,MAAa,cAAc;IAKzB,YAAY,KAAY;QACtB,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,SAAS,GAAG,EAAE,CAAC;IACtB,CAAC;IAEM,GAAG,CAAC,IAAwB;QACjC,MAAM,YAAY,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAc,CAAC;QACnD,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;IAC/B,CAAC;IAEM,GAAG,CAAC,IAAwB;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IACpC,CAAC;IAEM,KAAK,CAAC,IAAwB;QACnC,OAAO,IAAA,cAAK,EAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;IACrC,CAAC;CACF;AAtBD,wCAsBC"}
package/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./factory";
2
2
  export * from "./audit";
3
+ export * from "./auditWithState";
3
4
  export * from "./interfaces";
4
5
  export * from "./errors";
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
13
  __exportStar(require("./factory"), exports);
14
14
  __exportStar(require("./audit"), exports);
15
+ __exportStar(require("./auditWithState"), exports);
15
16
  __exportStar(require("./interfaces"), exports);
16
17
  __exportStar(require("./errors"), exports);
17
18
  //# 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,4CAA0B;AAC1B,0CAAwB;AACxB,+CAA6B;AAC7B,2CAAyB"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,4CAA0B;AAC1B,0CAAwB;AACxB,mDAAiC;AACjC,+CAA6B;AAC7B,2CAAyB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alanszp/audit",
3
- "version": "4.0.2",
3
+ "version": "4.0.5",
4
4
  "description": "Alan's audit util.",
5
5
  "main": "dist/index.js",
6
6
  "typings": "dist/index.d.ts",
@@ -15,12 +15,13 @@
15
15
  "compile": "rm -rf ./dist && tsc --declaration",
16
16
  "compile-watch": "tsc -w",
17
17
  "build": "yarn run compile",
18
- "prepack": "yarn run build"
18
+ "prepack": "yarn run build",
19
+ "yalc-publish": "yarn run yalc publish"
19
20
  },
20
21
  "dependencies": {
21
- "@alanszp/errors": "^4.0.0",
22
- "@alanszp/logger": "^4.0.2",
22
+ "@alanszp/errors": "^4.0.5",
23
+ "@alanszp/logger": "^4.0.5",
23
24
  "lodash": "^4.17.21"
24
25
  },
25
- "gitHead": "c983be912daf7999c18052e7bcef490f3df9f863"
26
+ "gitHead": "dd71920ed2c565d81bab8de3fafadbea0fff9ad9"
26
27
  }
package/src/audit.ts CHANGED
@@ -1,41 +1,31 @@
1
1
  import { ILogger, LogType } from "@alanszp/logger";
2
- import { difference, merge } from "lodash";
2
+ import { difference } from "lodash";
3
3
  import { AuditBody, REQUIRED_FIELDS } from ".";
4
+ import { AuditWithState } from "./auditWithState";
4
5
  import { MissingAuditFieldsError } from "./errors/MissingAuditFieldsError";
5
6
 
6
7
  export class Audit {
7
8
  public logger: ILogger;
8
9
 
9
- public additions: Partial<AuditBody>;
10
-
11
10
  constructor(logger: ILogger) {
12
11
  this.logger = logger;
13
- this.additions = {};
14
12
  }
15
13
 
16
- public log(body: Partial<AuditBody>): void {
17
- const completeBody = this.merge(body);
18
-
19
- const missingFields = difference(
20
- REQUIRED_FIELDS,
21
- Object.keys(completeBody)
22
- );
14
+ public log(body: AuditBody): void {
15
+ const missingFields = difference(REQUIRED_FIELDS, Object.keys(body));
23
16
 
24
17
  if (missingFields.length > 0) {
25
18
  throw new MissingAuditFieldsError(missingFields);
26
19
  }
27
20
 
28
- const action = completeBody.action as string;
29
- delete completeBody.action;
30
-
31
- this.logger.info(action, { log_type: LogType.AUDIT, ...completeBody });
32
- }
33
-
34
- public add(body: Partial<AuditBody>): void {
35
- this.additions = this.merge(body);
21
+ this.logger.info(body.action, {
22
+ log_type: LogType.AUDIT,
23
+ ...body,
24
+ action: undefined,
25
+ });
36
26
  }
37
27
 
38
- public merge(body: Partial<AuditBody>): Partial<AuditBody> {
39
- return merge(this.additions, body);
28
+ public withState(): AuditWithState {
29
+ return new AuditWithState(this);
40
30
  }
41
31
  }
@@ -0,0 +1,27 @@
1
+ import { merge } from "lodash";
2
+ import { AuditBody } from "./interfaces";
3
+ import { Audit } from "./audit";
4
+
5
+ export class AuditWithState {
6
+ public audit: Audit;
7
+
8
+ public additions: Partial<AuditBody>;
9
+
10
+ constructor(audit: Audit) {
11
+ this.audit = audit;
12
+ this.additions = {};
13
+ }
14
+
15
+ public log(body: Partial<AuditBody>): void {
16
+ const completeBody = this.merge(body) as AuditBody;
17
+ this.audit.log(completeBody);
18
+ }
19
+
20
+ public add(body: Partial<AuditBody>): void {
21
+ this.additions = this.merge(body);
22
+ }
23
+
24
+ public merge(body: Partial<AuditBody>): Partial<AuditBody> {
25
+ return merge(this.additions, body);
26
+ }
27
+ }
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export * from "./factory";
2
2
  export * from "./audit";
3
+ export * from "./auditWithState";
3
4
  export * from "./interfaces";
4
5
  export * from "./errors";