@tachybase/plugin-audit-logs 0.23.8
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/.turbo/turbo-build.log +14 -0
- package/LICENSE +201 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/AuditLogsBlockInitializer.d.ts +2 -0
- package/dist/client/AuditLogsBlockProvider.d.ts +5 -0
- package/dist/client/AuditLogsProvider.d.ts +2 -0
- package/dist/client/collections.d.ts +167 -0
- package/dist/client/components/AuditLogsField.d.ts +2 -0
- package/dist/client/components/AuditLogsValue.d.ts +2 -0
- package/dist/client/components/AuditLogsViewActionInitializer.d.ts +2 -0
- package/dist/client/deplicated/AuditLogs.d.ts +1 -0
- package/dist/client/deplicated/AuditLogsDesigner.d.ts +2 -0
- package/dist/client/index.d.ts +7 -0
- package/dist/client/index.js +1 -0
- package/dist/client/initializers/AuditLogsTableActionColumnInitializer.d.ts +2 -0
- package/dist/client/initializers/AuditLogsTableActionColumnInitializers.d.ts +2 -0
- package/dist/client/initializers/AuditLogsTableActionInitializers.d.ts +3 -0
- package/dist/client/initializers/AuditLogsTableColumnInitializers.d.ts +2 -0
- package/dist/client/locale/index.d.ts +4 -0
- package/dist/client/utils.d.ts +363 -0
- package/dist/externalVersion.js +11 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +44 -0
- package/dist/locale/zh-CN.json +44 -0
- package/dist/server/collections/auditChanges.d.ts +2 -0
- package/dist/server/collections/auditChanges.js +55 -0
- package/dist/server/collections/auditLogs.d.ts +2 -0
- package/dist/server/collections/auditLogs.js +72 -0
- package/dist/server/constants.d.ts +3 -0
- package/dist/server/constants.js +33 -0
- package/dist/server/hooks/after-create.d.ts +1 -0
- package/dist/server/hooks/after-create.js +70 -0
- package/dist/server/hooks/after-destroy.d.ts +1 -0
- package/dist/server/hooks/after-destroy.js +63 -0
- package/dist/server/hooks/after-update.d.ts +1 -0
- package/dist/server/hooks/after-update.js +72 -0
- package/dist/server/hooks/index.d.ts +3 -0
- package/dist/server/hooks/index.js +25 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/server/index.js +52 -0
- package/package.json +30 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var constants_exports = {};
|
|
19
|
+
__export(constants_exports, {
|
|
20
|
+
LOG_TYPE_CREATE: () => LOG_TYPE_CREATE,
|
|
21
|
+
LOG_TYPE_DESTROY: () => LOG_TYPE_DESTROY,
|
|
22
|
+
LOG_TYPE_UPDATE: () => LOG_TYPE_UPDATE
|
|
23
|
+
});
|
|
24
|
+
module.exports = __toCommonJS(constants_exports);
|
|
25
|
+
const LOG_TYPE_CREATE = "create";
|
|
26
|
+
const LOG_TYPE_UPDATE = "update";
|
|
27
|
+
const LOG_TYPE_DESTROY = "destroy";
|
|
28
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
29
|
+
0 && (module.exports = {
|
|
30
|
+
LOG_TYPE_CREATE,
|
|
31
|
+
LOG_TYPE_DESTROY,
|
|
32
|
+
LOG_TYPE_UPDATE
|
|
33
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function afterCreate(model: any, options: any): Promise<void>;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var after_create_exports = {};
|
|
19
|
+
__export(after_create_exports, {
|
|
20
|
+
afterCreate: () => afterCreate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(after_create_exports);
|
|
23
|
+
var import_constants = require("../constants");
|
|
24
|
+
async function afterCreate(model, options) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
if (options.logging === false) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const { collection } = model.constructor;
|
|
30
|
+
if (!collection || !collection.options.logging) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const transaction = options.transaction;
|
|
34
|
+
const AuditLog = model.constructor.database.getCollection("auditLogs");
|
|
35
|
+
const currentUserId = (_c = (_b = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.state) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.id;
|
|
36
|
+
try {
|
|
37
|
+
const changes = [];
|
|
38
|
+
const changed = model.changed();
|
|
39
|
+
if (changed) {
|
|
40
|
+
changed.forEach((key) => {
|
|
41
|
+
const field = collection.findField((field2) => {
|
|
42
|
+
return field2.name === key || field2.options.field === key;
|
|
43
|
+
});
|
|
44
|
+
if (field && !field.options.hidden) {
|
|
45
|
+
changes.push({
|
|
46
|
+
field: field.options,
|
|
47
|
+
after: model.get(key)
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
await AuditLog.repository.create({
|
|
53
|
+
values: {
|
|
54
|
+
type: import_constants.LOG_TYPE_CREATE,
|
|
55
|
+
collectionName: model.constructor.name,
|
|
56
|
+
recordId: model.get(model.constructor.primaryKeyAttribute),
|
|
57
|
+
createdAt: model.get("createdAt"),
|
|
58
|
+
userId: currentUserId,
|
|
59
|
+
changes
|
|
60
|
+
},
|
|
61
|
+
transaction,
|
|
62
|
+
hooks: false
|
|
63
|
+
});
|
|
64
|
+
} catch (error) {
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
68
|
+
0 && (module.exports = {
|
|
69
|
+
afterCreate
|
|
70
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function afterDestroy(model: any, options: any): Promise<void>;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var after_destroy_exports = {};
|
|
19
|
+
__export(after_destroy_exports, {
|
|
20
|
+
afterDestroy: () => afterDestroy
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(after_destroy_exports);
|
|
23
|
+
var import_constants = require("../constants");
|
|
24
|
+
async function afterDestroy(model, options) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const { collection } = model.constructor;
|
|
27
|
+
if (!collection || !collection.options.logging) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const transaction = options.transaction;
|
|
31
|
+
const AuditLog = model.constructor.database.getCollection("auditLogs");
|
|
32
|
+
const currentUserId = (_c = (_b = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.state) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.id;
|
|
33
|
+
try {
|
|
34
|
+
const changes = [];
|
|
35
|
+
Object.keys(model.get()).forEach((key) => {
|
|
36
|
+
const field = collection.findField((field2) => {
|
|
37
|
+
return field2.name === key || field2.options.field === key;
|
|
38
|
+
});
|
|
39
|
+
if (field) {
|
|
40
|
+
changes.push({
|
|
41
|
+
field: field.options,
|
|
42
|
+
before: model.get(key)
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
await AuditLog.repository.create({
|
|
47
|
+
values: {
|
|
48
|
+
type: import_constants.LOG_TYPE_DESTROY,
|
|
49
|
+
collectionName: model.constructor.name,
|
|
50
|
+
recordId: model.get(model.constructor.primaryKeyAttribute),
|
|
51
|
+
userId: currentUserId,
|
|
52
|
+
changes
|
|
53
|
+
},
|
|
54
|
+
transaction,
|
|
55
|
+
hooks: false
|
|
56
|
+
});
|
|
57
|
+
} catch (error) {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
61
|
+
0 && (module.exports = {
|
|
62
|
+
afterDestroy
|
|
63
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function afterUpdate(model: any, options: any): Promise<void>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __export = (target, all) => {
|
|
6
|
+
for (var name in all)
|
|
7
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
8
|
+
};
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
18
|
+
var after_update_exports = {};
|
|
19
|
+
__export(after_update_exports, {
|
|
20
|
+
afterUpdate: () => afterUpdate
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(after_update_exports);
|
|
23
|
+
var import_constants = require("../constants");
|
|
24
|
+
async function afterUpdate(model, options) {
|
|
25
|
+
var _a, _b, _c;
|
|
26
|
+
const { collection } = model.constructor;
|
|
27
|
+
if (!collection || !collection.options.logging) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const changed = model.changed();
|
|
31
|
+
if (!changed) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const transaction = options.transaction;
|
|
35
|
+
const AuditLog = model.constructor.database.getCollection("auditLogs");
|
|
36
|
+
const currentUserId = (_c = (_b = (_a = options == null ? void 0 : options.context) == null ? void 0 : _a.state) == null ? void 0 : _b.currentUser) == null ? void 0 : _c.id;
|
|
37
|
+
const changes = [];
|
|
38
|
+
changed.forEach((key) => {
|
|
39
|
+
const field = collection.findField((field2) => {
|
|
40
|
+
return field2.name === key || field2.options.field === key;
|
|
41
|
+
});
|
|
42
|
+
if (field && !field.options.hidden) {
|
|
43
|
+
changes.push({
|
|
44
|
+
field: field.options,
|
|
45
|
+
after: model.get(key),
|
|
46
|
+
before: model.previous(key)
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
if (!changes.length) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
await AuditLog.repository.create({
|
|
55
|
+
values: {
|
|
56
|
+
type: import_constants.LOG_TYPE_UPDATE,
|
|
57
|
+
collectionName: model.constructor.name,
|
|
58
|
+
recordId: model.get(model.constructor.primaryKeyAttribute),
|
|
59
|
+
createdAt: model.get("updatedAt"),
|
|
60
|
+
userId: currentUserId,
|
|
61
|
+
changes
|
|
62
|
+
},
|
|
63
|
+
transaction,
|
|
64
|
+
hooks: false
|
|
65
|
+
});
|
|
66
|
+
} catch (error) {
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
70
|
+
0 && (module.exports = {
|
|
71
|
+
afterUpdate
|
|
72
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
|
+
var __copyProps = (to, from, except, desc) => {
|
|
6
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
|
+
for (let key of __getOwnPropNames(from))
|
|
8
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
9
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
10
|
+
}
|
|
11
|
+
return to;
|
|
12
|
+
};
|
|
13
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
var hooks_exports = {};
|
|
16
|
+
module.exports = __toCommonJS(hooks_exports);
|
|
17
|
+
__reExport(hooks_exports, require("./after-create"), module.exports);
|
|
18
|
+
__reExport(hooks_exports, require("./after-update"), module.exports);
|
|
19
|
+
__reExport(hooks_exports, require("./after-destroy"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./after-create"),
|
|
23
|
+
...require("./after-update"),
|
|
24
|
+
...require("./after-destroy")
|
|
25
|
+
});
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
20
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
21
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
22
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
23
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
24
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
25
|
+
mod
|
|
26
|
+
));
|
|
27
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
28
|
+
var server_exports = {};
|
|
29
|
+
__export(server_exports, {
|
|
30
|
+
default: () => PluginActionLogs
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(server_exports);
|
|
33
|
+
var import_path = __toESM(require("path"));
|
|
34
|
+
var import_server = require("@tachybase/server");
|
|
35
|
+
var import_hooks = require("./hooks");
|
|
36
|
+
class PluginActionLogs extends import_server.Plugin {
|
|
37
|
+
async beforeLoad() {
|
|
38
|
+
this.db.on("afterCreate", import_hooks.afterCreate);
|
|
39
|
+
this.db.on("afterUpdate", import_hooks.afterUpdate);
|
|
40
|
+
this.db.on("afterDestroy", import_hooks.afterDestroy);
|
|
41
|
+
}
|
|
42
|
+
async load() {
|
|
43
|
+
await this.importCollections(import_path.default.resolve(__dirname, "collections"));
|
|
44
|
+
this.db.addMigrations({
|
|
45
|
+
namespace: "audit-logs",
|
|
46
|
+
directory: import_path.default.resolve(__dirname, "./migrations"),
|
|
47
|
+
context: {
|
|
48
|
+
plugin: this
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tachybase/plugin-audit-logs",
|
|
3
|
+
"displayName": "Audit logs",
|
|
4
|
+
"version": "0.23.8",
|
|
5
|
+
"description": "Audit logs.",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"System management"
|
|
8
|
+
],
|
|
9
|
+
"main": "dist/server/index.js",
|
|
10
|
+
"devDependencies": {
|
|
11
|
+
"@ant-design/icons": "~5.3.7",
|
|
12
|
+
"antd": "5.22.5",
|
|
13
|
+
"react": "^18.3.1",
|
|
14
|
+
"react-i18next": "^15.2.0",
|
|
15
|
+
"@tachybase/components": "0.23.8"
|
|
16
|
+
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"@tachybase/client": "0.23.8",
|
|
19
|
+
"@tachybase/database": "0.23.8",
|
|
20
|
+
"@tachybase/server": "0.23.8",
|
|
21
|
+
"@tachybase/schema": "0.23.8",
|
|
22
|
+
"@tachybase/test": "0.23.8",
|
|
23
|
+
"@tachybase/utils": "0.23.8"
|
|
24
|
+
},
|
|
25
|
+
"description.zh-CN": "审计日志。",
|
|
26
|
+
"displayName.zh-CN": "审计日志",
|
|
27
|
+
"scripts": {
|
|
28
|
+
"build": "tachybase-build --no-dts @tachybase/plugin-audit-logs"
|
|
29
|
+
}
|
|
30
|
+
}
|
package/server.d.ts
ADDED
package/server.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./dist/server/index.js');
|