@golemio/audit-logs 1.0.0-dev.1590464100

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.
Files changed (33) hide show
  1. package/LICENSE +11 -0
  2. package/README.md +85 -0
  3. package/dist/helpers/AuditLogger.d.ts +9 -0
  4. package/dist/helpers/AuditLogger.js +49 -0
  5. package/dist/helpers/AuditLogger.js.map +1 -0
  6. package/dist/index.d.ts +5 -0
  7. package/dist/index.js +10 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/interfaces/IAuditLog.d.ts +6 -0
  10. package/dist/interfaces/IAuditLog.js +3 -0
  11. package/dist/interfaces/IAuditLog.js.map +1 -0
  12. package/dist/interfaces/IAuditLogsConfig.d.ts +3 -0
  13. package/dist/interfaces/IAuditLogsConfig.js +3 -0
  14. package/dist/interfaces/IAuditLogsConfig.js.map +1 -0
  15. package/dist/ioc/AuditLogsContainerToken.d.ts +7 -0
  16. package/dist/ioc/AuditLogsContainerToken.js +15 -0
  17. package/dist/ioc/AuditLogsContainerToken.js.map +1 -0
  18. package/dist/ioc/Di.d.ts +3 -0
  19. package/dist/ioc/Di.js +25 -0
  20. package/dist/ioc/Di.js.map +1 -0
  21. package/dist/models/AuditLogsModel.d.ts +14 -0
  22. package/dist/models/AuditLogsModel.js +56 -0
  23. package/dist/models/AuditLogsModel.js.map +1 -0
  24. package/dist/models/interfaces/IAuditLog.d.ts +6 -0
  25. package/dist/models/interfaces/IAuditLog.js +3 -0
  26. package/dist/models/interfaces/IAuditLog.js.map +1 -0
  27. package/dist/repositories/AuditLogsRepository.d.ts +18 -0
  28. package/dist/repositories/AuditLogsRepository.js +71 -0
  29. package/dist/repositories/AuditLogsRepository.js.map +1 -0
  30. package/dist/transformations/AuditLogTransformation.d.ts +10 -0
  31. package/dist/transformations/AuditLogTransformation.js +22 -0
  32. package/dist/transformations/AuditLogTransformation.js.map +1 -0
  33. package/package.json +75 -0
package/LICENSE ADDED
@@ -0,0 +1,11 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Operátor ICT, a.s.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
10
+
11
+ Source: http://opensource.org/licenses/MIT
package/README.md ADDED
@@ -0,0 +1,85 @@
1
+ <div align="center">
2
+ <p>
3
+ <a href="https://operatorict.cz">
4
+ <img src="https://gitlab.com/operator-ict/golemio/code/modules/core/-/raw/development/.assets/oict_logo.png" alt="oict" width="100px" height="100px" />
5
+ </a>
6
+ <a href="https://golemio.cz">
7
+ <img src="https://gitlab.com/operator-ict/golemio/code/modules/core/-/raw/development/.assets/golemio_logo.png" alt="golemio" width="100px" height="100px" />
8
+ </a>
9
+ </p>
10
+
11
+ <h1>@golemio/audit-logs</h1>
12
+
13
+ <p>
14
+ <a href="https://gitlab.com/operator-ict/golemio/code/modules/audit-logs/commits/master">
15
+ <img src="https://gitlab.com/operator-ict/golemio/code/modules/audit-logs/badges/master/pipeline.svg" alt="pipeline">
16
+ </a>
17
+ <a href="https://gitlab.com/operator-ict/golemio/code/modules/audit-logs/commits/master">
18
+ <img src="https://gitlab.com/operator-ict/golemio/code/modules/audit-logs/badges/master/coverage.svg" alt="coverage">
19
+ </a>
20
+ <a href="./LICENSE">
21
+ <img src="https://img.shields.io/npm/l/@golemio/audit-logs" alt="license">
22
+ </a>
23
+ </p>
24
+
25
+ <p>
26
+ <a href="#installation">Installation</a> · <a href="./docs">Documentation</a> · <a href="https://operator-ict.gitlab.io/golemio/code/modules/audit-logs">TypeDoc</a>
27
+ </p>
28
+ </div>
29
+
30
+ This module is intended for use with Golemio services. Refer [here](https://gitlab.com/operator-ict/golemio/code/modules/core/-/blob/master/README.md) for further information on usage, local development and more.
31
+
32
+ ## Installation
33
+
34
+ The APIs may be unstable. Therefore, we recommend to install this module as an exact version.
35
+
36
+ ```bash
37
+ # Latest version
38
+ npm install --save-exact @golemio/audit-logs@latest
39
+
40
+ # Development version
41
+ npm install --save-exact @golemio/audit-logs@dev
42
+ ```
43
+
44
+ ## Setup
45
+
46
+ For local integration tests, run database migrations with the `audit_logs` schema.
47
+
48
+ ```bash
49
+ npx golemio migrate-db up --postgres --schema audit_logs
50
+ ```
51
+
52
+ ## Usage
53
+
54
+ For information on how to use this module with default module schema migrations, see [golemio-cli docs](https://gitlab.com/operator-ict/golemio/code/golemio-cli/-/blob/release/docs/migrations.md?ref_type=heads#default-module-schema-migrations).
55
+
56
+ Configuring the database schema to use for audit logging using dependency injection:
57
+ ```ts
58
+ // Di.ts
59
+ import { AuditLogsContainer, AuditLogsContainerToken, AuditLogger, IAuditLogsConfig } from "@golemio/audit-logs";
60
+
61
+ const YourModuleContainer: DependencyContainer = SomeOtherContainer.createChildContainer();
62
+
63
+ const config: IAuditLogsConfig = { schema: "your_module_schema" };
64
+ const YourAuditLogsContainer: DependencyContainer = AuditLogsContainer.createChildContainer();
65
+ YourAuditLogsContainer.register(AuditLogsContainerToken.AuditLogsConfig, { useValue: config });
66
+ YourModuleContainer.registerInstance(
67
+ "your_audit_logs_token", YourAuditLogsContainer.resolve<AuditLogger>(AuditLogsContainerToken.AuditLogger)
68
+ );
69
+ ```
70
+
71
+ The audit logger can then be used as follows:
72
+ ```ts
73
+ // YourClass.ts
74
+ import { inject } from "@golemio/core/dist/shared/tsyringe";
75
+ import { AuditLogger } from "@golemio/audit-logs";
76
+
77
+ export class YourClass {
78
+ constructor(@inject("your_audit_logs_token") private auditLogger: AuditLogger) {}
79
+
80
+ someMethod() {
81
+ this.auditLogger.log({ action: "test-action", entity: "test-entity", userId: "test-user-id" /*, data: {...} */ });
82
+ // .then(...).catch(...)
83
+ }
84
+ }
85
+ ```
@@ -0,0 +1,9 @@
1
+ import { IAuditLog } from "../interfaces/IAuditLog";
2
+ import { AuditLogsRepository } from "../repositories/AuditLogsRepository";
3
+ import { AuditLogTransformation } from "../transformations/AuditLogTransformation";
4
+ export declare class AuditLogger {
5
+ private auditLogsRepository;
6
+ private auditLogTransformation;
7
+ constructor(auditLogsRepository: AuditLogsRepository, auditLogTransformation: AuditLogTransformation);
8
+ log(auditLog: IAuditLog): Promise<void>;
9
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.AuditLogger = void 0;
25
+ const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
26
+ const AuditLogsContainerToken_1 = require("../ioc/AuditLogsContainerToken");
27
+ const AuditLogsRepository_1 = require("../repositories/AuditLogsRepository");
28
+ const AuditLogTransformation_1 = require("../transformations/AuditLogTransformation");
29
+ let AuditLogger = exports.AuditLogger = class AuditLogger {
30
+ constructor(auditLogsRepository, auditLogTransformation) {
31
+ this.auditLogsRepository = auditLogsRepository;
32
+ this.auditLogTransformation = auditLogTransformation;
33
+ // do nothing
34
+ }
35
+ log(auditLog) {
36
+ return __awaiter(this, void 0, void 0, function* () {
37
+ const transformedAuditLog = this.auditLogTransformation.transformElement(auditLog);
38
+ yield this.auditLogsRepository.insert(transformedAuditLog);
39
+ });
40
+ }
41
+ };
42
+ exports.AuditLogger = AuditLogger = __decorate([
43
+ (0, tsyringe_1.injectable)(),
44
+ __param(0, (0, tsyringe_1.inject)(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogsRepository)),
45
+ __param(1, (0, tsyringe_1.inject)(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogTransformation)),
46
+ __metadata("design:paramtypes", [AuditLogsRepository_1.AuditLogsRepository,
47
+ AuditLogTransformation_1.AuditLogTransformation])
48
+ ], AuditLogger);
49
+ //# sourceMappingURL=AuditLogger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditLogger.js","sourceRoot":"","sources":["../../src/helpers/AuditLogger.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAAA,iEAAwE;AAExE,4EAAyE;AACzE,6EAA0E;AAC1E,sFAAmF;AAG5E,IAAM,WAAW,yBAAjB,MAAM,WAAW;IACpB,YACiE,mBAAwC,EACrC,sBAA8C;QADjD,wBAAmB,GAAnB,mBAAmB,CAAqB;QACrC,2BAAsB,GAAtB,sBAAsB,CAAwB;QAE9G,aAAa;IACjB,CAAC;IAEY,GAAG,CAAC,QAAmB;;YAChC,MAAM,mBAAmB,GAAG,IAAI,CAAC,sBAAsB,CAAC,gBAAgB,CAAC,QAAQ,CAAC,CAAC;YACnF,MAAM,IAAI,CAAC,mBAAmB,CAAC,MAAM,CAAC,mBAAmB,CAAC,CAAC;QAC/D,CAAC;KAAA;CACJ,CAAA;sBAZY,WAAW;IADvB,IAAA,qBAAU,GAAE;IAGJ,WAAA,IAAA,iBAAM,EAAC,iDAAuB,CAAC,mBAAmB,CAAC,CAAA;IACnD,WAAA,IAAA,iBAAM,EAAC,iDAAuB,CAAC,sBAAsB,CAAC,CAAA;qCAD2B,yCAAmB;QACb,+CAAsB;GAHzG,WAAW,CAYvB"}
@@ -0,0 +1,5 @@
1
+ export { AuditLogger } from "./helpers/AuditLogger";
2
+ export { IAuditLog } from "./interfaces/IAuditLog";
3
+ export { IAuditLogsConfig } from "./interfaces/IAuditLogsConfig";
4
+ export { AuditLogsContainerToken } from "./ioc/AuditLogsContainerToken";
5
+ export { AuditLogsContainer } from "./ioc/Di";
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuditLogsContainer = exports.AuditLogsContainerToken = exports.AuditLogger = void 0;
4
+ var AuditLogger_1 = require("./helpers/AuditLogger");
5
+ Object.defineProperty(exports, "AuditLogger", { enumerable: true, get: function () { return AuditLogger_1.AuditLogger; } });
6
+ var AuditLogsContainerToken_1 = require("./ioc/AuditLogsContainerToken");
7
+ Object.defineProperty(exports, "AuditLogsContainerToken", { enumerable: true, get: function () { return AuditLogsContainerToken_1.AuditLogsContainerToken; } });
8
+ var Di_1 = require("./ioc/Di");
9
+ Object.defineProperty(exports, "AuditLogsContainer", { enumerable: true, get: function () { return Di_1.AuditLogsContainer; } });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAAA,qDAAoD;AAA3C,0GAAA,WAAW,OAAA;AAGpB,yEAAwE;AAA/D,kIAAA,uBAAuB,OAAA;AAChC,+BAA8C;AAArC,wGAAA,kBAAkB,OAAA"}
@@ -0,0 +1,6 @@
1
+ export interface IAuditLog {
2
+ action: string;
3
+ entity: string;
4
+ userId: string;
5
+ data?: object;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAuditLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAuditLog.js","sourceRoot":"","sources":["../../src/interfaces/IAuditLog.ts"],"names":[],"mappings":""}
@@ -0,0 +1,3 @@
1
+ export interface IAuditLogsConfig {
2
+ schema: string;
3
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAuditLogsConfig.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAuditLogsConfig.js","sourceRoot":"","sources":["../../src/interfaces/IAuditLogsConfig.ts"],"names":[],"mappings":""}
@@ -0,0 +1,7 @@
1
+ declare const AuditLogsContainerToken: {
2
+ AuditLogsConfig: symbol;
3
+ AuditLogger: symbol;
4
+ AuditLogsRepository: symbol;
5
+ AuditLogTransformation: symbol;
6
+ };
7
+ export { AuditLogsContainerToken };
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuditLogsContainerToken = void 0;
4
+ const AuditLogsContainerToken = {
5
+ /* Config */
6
+ AuditLogsConfig: Symbol("AuditLogsConfig"),
7
+ /* Helpers */
8
+ AuditLogger: Symbol("AuditLogger"),
9
+ /* Repositories */
10
+ AuditLogsRepository: Symbol("AuditLogsRepository"),
11
+ /* Transformations */
12
+ AuditLogTransformation: Symbol("AuditLogTransformation"),
13
+ };
14
+ exports.AuditLogsContainerToken = AuditLogsContainerToken;
15
+ //# sourceMappingURL=AuditLogsContainerToken.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditLogsContainerToken.js","sourceRoot":"","sources":["../../src/ioc/AuditLogsContainerToken.ts"],"names":[],"mappings":";;;AAAA,MAAM,uBAAuB,GAAG;IAC5B,YAAY;IACZ,eAAe,EAAE,MAAM,CAAC,iBAAiB,CAAC;IAC1C,aAAa;IACb,WAAW,EAAE,MAAM,CAAC,aAAa,CAAC;IAClC,kBAAkB;IAClB,mBAAmB,EAAE,MAAM,CAAC,qBAAqB,CAAC;IAClD,qBAAqB;IACrB,sBAAsB,EAAE,MAAM,CAAC,wBAAwB,CAAC;CAC3D,CAAC;AAEO,0DAAuB"}
@@ -0,0 +1,3 @@
1
+ import { DependencyContainer } from "@golemio/core/dist/shared/tsyringe";
2
+ declare const AuditLogsContainer: DependencyContainer;
3
+ export { AuditLogsContainer };
package/dist/ioc/Di.js ADDED
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuditLogsContainer = void 0;
4
+ const Di_1 = require("@golemio/core/dist/integration-engine/ioc/Di");
5
+ const AuditLogger_1 = require("../helpers/AuditLogger");
6
+ const AuditLogsRepository_1 = require("../repositories/AuditLogsRepository");
7
+ const AuditLogTransformation_1 = require("../transformations/AuditLogTransformation");
8
+ const AuditLogsContainerToken_1 = require("./AuditLogsContainerToken");
9
+ //#region Initialization
10
+ const AuditLogsContainer = Di_1.IntegrationEngineContainer.createChildContainer();
11
+ exports.AuditLogsContainer = AuditLogsContainer;
12
+ //#endregion
13
+ //#region Config
14
+ const config = { schema: "audit_logs" };
15
+ AuditLogsContainer.register(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogsConfig, { useValue: config });
16
+ //#endregion
17
+ //#region Helpers
18
+ AuditLogsContainer.register(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogger, AuditLogger_1.AuditLogger);
19
+ //#endregion
20
+ //#region Repositories
21
+ AuditLogsContainer.register(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogsRepository, AuditLogsRepository_1.AuditLogsRepository);
22
+ //#endregion
23
+ //#region Transformations
24
+ AuditLogsContainer.register(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogTransformation, AuditLogTransformation_1.AuditLogTransformation);
25
+ //# sourceMappingURL=Di.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Di.js","sourceRoot":"","sources":["../../src/ioc/Di.ts"],"names":[],"mappings":";;;AAAA,qEAA0F;AAE1F,wDAAqD;AAErD,6EAA0E;AAC1E,sFAAmF;AACnF,uEAAoE;AAEpE,wBAAwB;AACxB,MAAM,kBAAkB,GAAwB,+BAA0B,CAAC,oBAAoB,EAAE,CAAC;AAoBzF,gDAAkB;AAnB3B,YAAY;AAEZ,gBAAgB;AAChB,MAAM,MAAM,GAAqB,EAAE,MAAM,EAAE,YAAY,EAAE,CAAC;AAC1D,kBAAkB,CAAC,QAAQ,CAAC,iDAAuB,CAAC,eAAe,EAAE,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC;AAC3F,YAAY;AAEZ,iBAAiB;AACjB,kBAAkB,CAAC,QAAQ,CAAC,iDAAuB,CAAC,WAAW,EAAE,yBAAW,CAAC,CAAC;AAC9E,YAAY;AAEZ,sBAAsB;AACtB,kBAAkB,CAAC,QAAQ,CAAC,iDAAuB,CAAC,mBAAmB,EAAE,yCAAmB,CAAC,CAAC;AAC9F,YAAY;AAEZ,yBAAyB;AACzB,kBAAkB,CAAC,QAAQ,CAAC,iDAAuB,CAAC,sBAAsB,EAAE,+CAAsB,CAAC,CAAC"}
@@ -0,0 +1,14 @@
1
+ import { JSONSchemaType } from "@golemio/core/dist/shared/ajv";
2
+ import { CreationOptional, InferAttributes, InferCreationAttributes, Model, ModelAttributes } from "@golemio/core/dist/shared/sequelize";
3
+ import { IAuditLog } from "./interfaces/IAuditLog";
4
+ export declare class AuditLogsModel extends Model<InferAttributes<AuditLogsModel>, InferCreationAttributes<AuditLogsModel>> implements IAuditLog {
5
+ static tableName: string;
6
+ id: CreationOptional<string>;
7
+ action: string;
8
+ entity: string;
9
+ user_id: string;
10
+ data?: object | null;
11
+ created_at: CreationOptional<Date>;
12
+ static attributeModel: ModelAttributes<AuditLogsModel>;
13
+ static jsonSchema: JSONSchemaType<IAuditLog[]>;
14
+ }
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AuditLogsModel = void 0;
4
+ const sequelize_1 = require("@golemio/core/dist/shared/sequelize");
5
+ class AuditLogsModel extends sequelize_1.Model {
6
+ }
7
+ exports.AuditLogsModel = AuditLogsModel;
8
+ AuditLogsModel.tableName = "audit_logs";
9
+ AuditLogsModel.attributeModel = {
10
+ id: {
11
+ primaryKey: true,
12
+ type: sequelize_1.DataTypes.UUID,
13
+ allowNull: false,
14
+ defaultValue: sequelize_1.DataTypes.UUIDV4,
15
+ },
16
+ action: {
17
+ type: sequelize_1.DataTypes.TEXT,
18
+ allowNull: false,
19
+ },
20
+ entity: {
21
+ type: sequelize_1.DataTypes.TEXT,
22
+ allowNull: false,
23
+ },
24
+ user_id: {
25
+ type: sequelize_1.DataTypes.TEXT,
26
+ allowNull: false,
27
+ },
28
+ data: {
29
+ type: sequelize_1.DataTypes.JSONB,
30
+ allowNull: true,
31
+ },
32
+ created_at: {
33
+ type: sequelize_1.DataTypes.DATE,
34
+ allowNull: false,
35
+ defaultValue: sequelize_1.DataTypes.NOW,
36
+ },
37
+ };
38
+ AuditLogsModel.jsonSchema = {
39
+ type: "array",
40
+ items: {
41
+ type: "object",
42
+ properties: {
43
+ action: { type: "string" },
44
+ entity: { type: "string" },
45
+ user_id: { type: "string" },
46
+ data: {
47
+ type: "object",
48
+ additionalProperties: true,
49
+ nullable: true,
50
+ },
51
+ },
52
+ additionalProperties: false,
53
+ required: ["action", "entity", "user_id"],
54
+ },
55
+ };
56
+ //# sourceMappingURL=AuditLogsModel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditLogsModel.js","sourceRoot":"","sources":["../../src/models/AuditLogsModel.ts"],"names":[],"mappings":";;;AACA,mEAO6C;AAG7C,MAAa,cACT,SAAQ,iBAA+E;;AAD3F,wCA6DC;AAzDiB,wBAAS,GAAG,YAAY,CAAC;AASzB,6BAAc,GAAoC;IAC5D,EAAE,EAAE;QACA,UAAU,EAAE,IAAI;QAChB,IAAI,EAAE,qBAAS,CAAC,IAAI;QACpB,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,qBAAS,CAAC,MAAM;KACjC;IACD,MAAM,EAAE;QACJ,IAAI,EAAE,qBAAS,CAAC,IAAI;QACpB,SAAS,EAAE,KAAK;KACnB;IACD,MAAM,EAAE;QACJ,IAAI,EAAE,qBAAS,CAAC,IAAI;QACpB,SAAS,EAAE,KAAK;KACnB;IACD,OAAO,EAAE;QACL,IAAI,EAAE,qBAAS,CAAC,IAAI;QACpB,SAAS,EAAE,KAAK;KACnB;IACD,IAAI,EAAE;QACF,IAAI,EAAE,qBAAS,CAAC,KAAK;QACrB,SAAS,EAAE,IAAI;KAClB;IACD,UAAU,EAAE;QACR,IAAI,EAAE,qBAAS,CAAC,IAAI;QACpB,SAAS,EAAE,KAAK;QAChB,YAAY,EAAE,qBAAS,CAAC,GAAG;KAC9B;CACJ,CAAC;AAEY,yBAAU,GAAgC;IACpD,IAAI,EAAE,OAAO;IACb,KAAK,EAAE;QACH,IAAI,EAAE,QAAQ;QACd,UAAU,EAAE;YACR,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B,MAAM,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC1B,OAAO,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE;YAC3B,IAAI,EAAE;gBACF,IAAI,EAAE,QAAQ;gBACd,oBAAoB,EAAE,IAAI;gBAC1B,QAAQ,EAAE,IAAI;aACjB;SACJ;QACD,oBAAoB,EAAE,KAAK;QAC3B,QAAQ,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,CAAC;KAC5C;CACJ,CAAC"}
@@ -0,0 +1,6 @@
1
+ export interface IAuditLog {
2
+ action: string;
3
+ entity: string;
4
+ user_id: string;
5
+ data?: object | null;
6
+ }
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=IAuditLog.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IAuditLog.js","sourceRoot":"","sources":["../../../src/models/interfaces/IAuditLog.ts"],"names":[],"mappings":""}
@@ -0,0 +1,18 @@
1
+ import { ILogger } from "@golemio/core/dist/helpers";
2
+ import { IDatabaseConnector } from "@golemio/core/dist/helpers/data-access/postgres/IDatabaseConnector";
3
+ import { AbstractValidatableRepository } from "@golemio/core/dist/helpers/data-access/postgres/repositories/AbstractValidatableRepository";
4
+ import { JSONSchemaValidator } from "@golemio/core/dist/shared/golemio-validator";
5
+ import { ModelStatic } from "@golemio/core/dist/shared/sequelize";
6
+ import { IAuditLogsConfig } from "../interfaces/IAuditLogsConfig";
7
+ import { AuditLogsModel } from "../models/AuditLogsModel";
8
+ import { IAuditLog } from "../models/interfaces/IAuditLog";
9
+ export declare class AuditLogsRepository extends AbstractValidatableRepository {
10
+ private logger;
11
+ private config;
12
+ validator: JSONSchemaValidator;
13
+ tableName: string;
14
+ schema: string;
15
+ private sequelizeModel;
16
+ constructor(connector: IDatabaseConnector, logger: ILogger, config: IAuditLogsConfig);
17
+ insert(data: IAuditLog): Promise<ReturnType<ModelStatic<AuditLogsModel>["create"]>>;
18
+ }
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ var __metadata = (this && this.__metadata) || function (k, v) {
9
+ if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
+ };
11
+ var __param = (this && this.__param) || function (paramIndex, decorator) {
12
+ return function (target, key) { decorator(target, key, paramIndex); }
13
+ };
14
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
15
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
16
+ return new (P || (P = Promise))(function (resolve, reject) {
17
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
18
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
19
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
20
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
21
+ });
22
+ };
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.AuditLogsRepository = void 0;
25
+ const AbstractValidatableRepository_1 = require("@golemio/core/dist/helpers/data-access/postgres/repositories/AbstractValidatableRepository");
26
+ const CoreToken_1 = require("@golemio/core/dist/helpers/ioc/CoreToken");
27
+ const golemio_errors_1 = require("@golemio/core/dist/shared/golemio-errors");
28
+ const golemio_validator_1 = require("@golemio/core/dist/shared/golemio-validator");
29
+ const sequelize_1 = require("@golemio/core/dist/shared/sequelize");
30
+ const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
31
+ const AuditLogsContainerToken_1 = require("../ioc/AuditLogsContainerToken");
32
+ const AuditLogsModel_1 = require("../models/AuditLogsModel");
33
+ let AuditLogsRepository = exports.AuditLogsRepository = class AuditLogsRepository extends AbstractValidatableRepository_1.AbstractValidatableRepository {
34
+ constructor(connector, logger, config) {
35
+ super(connector, logger);
36
+ this.logger = logger;
37
+ this.config = config;
38
+ this.tableName = AuditLogsModel_1.AuditLogsModel.tableName;
39
+ this.schema = this.config.schema;
40
+ this.validator = new golemio_validator_1.JSONSchemaValidator("AuditLogsRepository", AuditLogsModel_1.AuditLogsModel.jsonSchema);
41
+ this.sequelizeModel = connector
42
+ .getConnection()
43
+ .define(this.tableName, AuditLogsModel_1.AuditLogsModel.attributeModel, { schema: this.schema, updatedAt: false });
44
+ }
45
+ insert(data) {
46
+ var _a;
47
+ return __awaiter(this, void 0, void 0, function* () {
48
+ try {
49
+ return yield this.sequelizeModel.create(data);
50
+ }
51
+ catch (err) {
52
+ if (err instanceof sequelize_1.ValidationError && ((_a = err.errors) === null || _a === void 0 ? void 0 : _a.length) > 0) {
53
+ const mappedErrors = err.errors.map((e) => `${e.message} (${e.value})`).join(", ");
54
+ throw new golemio_errors_1.ValidationError(`Validation error in insert: ${mappedErrors}`, this.constructor.name, err);
55
+ }
56
+ if (err instanceof sequelize_1.DatabaseError) {
57
+ throw new golemio_errors_1.GeneralError(`Error in insert: ${err.parent}`, this.constructor.name, err);
58
+ }
59
+ throw new golemio_errors_1.GeneralError("Error in insert", this.constructor.name, err);
60
+ }
61
+ });
62
+ }
63
+ };
64
+ exports.AuditLogsRepository = AuditLogsRepository = __decorate([
65
+ (0, tsyringe_1.injectable)(),
66
+ __param(0, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.PostgresConnector)),
67
+ __param(1, (0, tsyringe_1.inject)(CoreToken_1.CoreToken.Logger)),
68
+ __param(2, (0, tsyringe_1.inject)(AuditLogsContainerToken_1.AuditLogsContainerToken.AuditLogsConfig)),
69
+ __metadata("design:paramtypes", [Object, Object, Object])
70
+ ], AuditLogsRepository);
71
+ //# sourceMappingURL=AuditLogsRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditLogsRepository.js","sourceRoot":"","sources":["../../src/repositories/AuditLogsRepository.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAEA,8IAA2I;AAC3I,wEAAqE;AACrE,6EAAyF;AACzF,mFAAkF;AAClF,mEAI6C;AAC7C,iEAAwE;AAExE,4EAAyE;AACzE,6DAA0D;AAInD,IAAM,mBAAmB,iCAAzB,MAAM,mBAAoB,SAAQ,6DAA6B;IAOlE,YACyC,SAA6B,EACxC,MAAuB,EACA,MAAgC;QAEjF,KAAK,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;QAHS,WAAM,GAAN,MAAM,CAAS;QACQ,WAAM,GAAN,MAAM,CAAkB;QAR9E,cAAS,GAAG,+BAAc,CAAC,SAAS,CAAC;QAWxC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QACjC,IAAI,CAAC,SAAS,GAAG,IAAI,uCAAmB,CAAC,qBAAqB,EAAE,+BAAc,CAAC,UAAU,CAAC,CAAC;QAC3F,IAAI,CAAC,cAAc,GAAG,SAAS;aAC1B,aAAa,EAAE;aACf,MAAM,CAAC,IAAI,CAAC,SAAS,EAAE,+BAAc,CAAC,cAAc,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,CAAC;IAC1G,CAAC;IAEY,MAAM,CAAC,IAAe;;;YAC/B,IAAI;gBACA,OAAO,MAAM,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;aACjD;YAAC,OAAO,GAAG,EAAE;gBACV,IAAI,GAAG,YAAY,2BAAwB,IAAI,CAAA,MAAA,GAAG,CAAC,MAAM,0CAAE,MAAM,IAAG,CAAC,EAAE;oBACnE,MAAM,YAAY,GAAG,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,KAAK,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;oBACnF,MAAM,IAAI,gCAAe,CAAC,+BAA+B,YAAY,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;iBACxG;gBACD,IAAI,GAAG,YAAY,yBAAsB,EAAE;oBACvC,MAAM,IAAI,6BAAY,CAAC,oBAAoB,GAAG,CAAC,MAAM,EAAE,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;iBACxF;gBACD,MAAM,IAAI,6BAAY,CAAC,iBAAiB,EAAE,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;aACzE;;KACJ;CACJ,CAAA;8BAlCY,mBAAmB;IAD/B,IAAA,qBAAU,GAAE;IASJ,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,iBAAiB,CAAC,CAAA;IACnC,WAAA,IAAA,iBAAM,EAAC,qBAAS,CAAC,MAAM,CAAC,CAAA;IACxB,WAAA,IAAA,iBAAM,EAAC,iDAAuB,CAAC,eAAe,CAAC,CAAA;;GAV3C,mBAAmB,CAkC/B"}
@@ -0,0 +1,10 @@
1
+ import { AbstractTransformation } from "@golemio/core/dist/helpers/transformation/AbstractTransformation";
2
+ import { IAuditLog } from "../interfaces/IAuditLog";
3
+ import { IAuditLog as IAuditLogModel } from "../models/interfaces/IAuditLog";
4
+ type TransformIn = IAuditLog;
5
+ type TransformOut = IAuditLogModel;
6
+ export declare class AuditLogTransformation extends AbstractTransformation<TransformIn, TransformOut> {
7
+ name: string;
8
+ protected transformInternal: (auditLog: TransformIn) => TransformOut;
9
+ }
10
+ export {};
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
+ var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
+ if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
+ else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
+ return c > 3 && r && Object.defineProperty(target, key, r), r;
7
+ };
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.AuditLogTransformation = void 0;
10
+ const AbstractTransformation_1 = require("@golemio/core/dist/helpers/transformation/AbstractTransformation");
11
+ const tsyringe_1 = require("@golemio/core/dist/shared/tsyringe");
12
+ let AuditLogTransformation = exports.AuditLogTransformation = class AuditLogTransformation extends AbstractTransformation_1.AbstractTransformation {
13
+ constructor() {
14
+ super(...arguments);
15
+ this.name = "AuditLogTransformation";
16
+ this.transformInternal = (auditLog) => (Object.assign({ action: auditLog.action, entity: auditLog.entity, user_id: auditLog.userId }, (auditLog.data ? { data: auditLog.data } : {})));
17
+ }
18
+ };
19
+ exports.AuditLogTransformation = AuditLogTransformation = __decorate([
20
+ (0, tsyringe_1.injectable)()
21
+ ], AuditLogTransformation);
22
+ //# sourceMappingURL=AuditLogTransformation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AuditLogTransformation.js","sourceRoot":"","sources":["../../src/transformations/AuditLogTransformation.ts"],"names":[],"mappings":";;;;;;;;;AAAA,6GAA0G;AAC1G,iEAAgE;AAQzD,IAAM,sBAAsB,oCAA5B,MAAM,sBAAuB,SAAQ,+CAAiD;IAAtF;;QACI,SAAI,GAAG,wBAAwB,CAAC;QAE7B,sBAAiB,GAAG,CAAC,QAAqB,EAAgB,EAAE,CAAC,iBACnE,MAAM,EAAE,QAAQ,CAAC,MAAM,EACvB,MAAM,EAAE,QAAQ,CAAC,MAAM,EACvB,OAAO,EAAE,QAAQ,CAAC,MAAM,IACrB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EACnD,CAAC;IACP,CAAC;CAAA,CAAA;iCATY,sBAAsB;IADlC,IAAA,qBAAU,GAAE;GACA,sBAAsB,CASlC"}
package/package.json ADDED
@@ -0,0 +1,75 @@
1
+ {
2
+ "name": "@golemio/audit-logs",
3
+ "version": "1.0.0-dev.1590464100",
4
+ "description": "Golemio Audit Logs Module",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "directories": {
8
+ "doc": "docs"
9
+ },
10
+ "scripts": {
11
+ "build": "rimraf ./dist && tspc -p ./tsconfig.build.json",
12
+ "build-minimal": "run-s 'build -- --sourceMap false --declaration false'",
13
+ "build-watch": "run-s 'build -- --watch --preserveWatchOutput'",
14
+ "pretest": "golemio import-db-data",
15
+ "test": "cross-env NODE_ENV='test' TZ='UTC' mocha --exit --check-leaks --timeout 120000 --reporter-option maxDiffSize=0 -r ts-node/register -r tsconfig-paths/register --file 'test/setup.ts' -r dotenv/config 'test/**/*.test.ts'",
16
+ "test-debug": "run-s 'test -- --inspect-brk=9230'",
17
+ "code-coverage": "nyc run-s 'test -- -r source-map-support/register'",
18
+ "generate-docs": "typedoc --out docs/typedoc src",
19
+ "lint": "eslint --cache \"{src,test}/**/*.ts\""
20
+ },
21
+ "keywords": [
22
+ "golemio"
23
+ ],
24
+ "author": "Operator ICT, a.s.",
25
+ "license": "MIT",
26
+ "repository": {
27
+ "type": "git",
28
+ "url": "https://gitlab.com/operator-ict/golemio/code/modules/audit-logs"
29
+ },
30
+ "engines": {
31
+ "node": ">=20.0.0",
32
+ "npm": ">=8.0.0"
33
+ },
34
+ "devDependencies": {
35
+ "@commitlint/cli": "^11.0.0",
36
+ "@commitlint/config-conventional": "^11.0.0",
37
+ "@golemio/cli": "1.7.4-dev.1586271916",
38
+ "@golemio/core": "1.17.1",
39
+ "@golemio/eslint-config": "1.1.2",
40
+ "@types/amqplib": "^0.5.17",
41
+ "@types/chai": "4.2.3",
42
+ "@types/chai-as-promised": "7.1.2",
43
+ "@types/mocha": "^9.1.1",
44
+ "@types/node": "^20.12.7",
45
+ "@types/pg-copy-streams": "^1.2.1",
46
+ "@types/sinon": "^9.0.10",
47
+ "@types/supertest": "^2.0.10",
48
+ "body-parser": "^1.19.0",
49
+ "body-parser-xml": "^2.0.0",
50
+ "chai": "4.2.0",
51
+ "chai-as-promised": "7.1.1",
52
+ "cross-env": "^7.0.3",
53
+ "dotenv": "^8.2.0",
54
+ "eslint": "^8.1.1",
55
+ "husky": "^4.3.7",
56
+ "mocha": "^10.0.0",
57
+ "npm-run-all": "^4.1.5",
58
+ "nyc": "^15.1.0",
59
+ "prettier": "^2.5.1",
60
+ "pretty-quick": "^3.1.0",
61
+ "rimraf": "^3.0.2",
62
+ "sinon": "^9.2.3",
63
+ "source-map-support": "0.5.21",
64
+ "supertest": "^6.0.1",
65
+ "ts-node": "^10.9.1",
66
+ "ts-patch": "3.0.0-beta3",
67
+ "tsconfig-paths": "^4.2.0",
68
+ "typedoc": "^0.24.8",
69
+ "typescript": "5.1.3",
70
+ "typescript-transform-paths": "^3.4.6"
71
+ },
72
+ "peerDependencies": {
73
+ "@golemio/core": ">=1.17.0"
74
+ }
75
+ }