@tachybase/module-instrumentation 1.0.22
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/LICENSE +201 -0
- package/README.md +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/TrackingConfigPane.d.ts +1 -0
- package/dist/client/TrackingLogPane.d.ts +1 -0
- package/dist/client/TrackingStatisticsPane.d.ts +1 -0
- package/dist/client/collections/statisticsConfig.collection.d.ts +10 -0
- package/dist/client/collections/trackingConfig.collection.d.ts +10 -0
- package/dist/client/collections/trackingLog.collection.d.ts +17 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.js +139 -0
- package/dist/client/locale.d.ts +7 -0
- package/dist/client/plugin.d.ts +5 -0
- package/dist/client/schemas/createStatisticsConfig.d.ts +2 -0
- package/dist/client/schemas/createTrackingConfig.d.ts +2 -0
- package/dist/client/schemas/schemaStatisticsConfigs.d.ts +2 -0
- package/dist/client/schemas/schemaTrackingLog.d.ts +2 -0
- package/dist/client/schemas/schematrackingConfig.d.ts +2 -0
- package/dist/client/schemas/updateStatisticsConfig.d.ts +2 -0
- package/dist/client/schemas/updateTrackingConfig.d.ts +2 -0
- package/dist/client/schemas/viewTrackingLog.d.ts +2 -0
- package/dist/externalVersion.js +12 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +39 -0
- package/dist/locale/en-US.json +18 -0
- package/dist/locale/zh-CN.json +19 -0
- package/dist/server/ServerTrackingFilter.d.ts +19 -0
- package/dist/server/ServerTrackingFilter.js +68 -0
- package/dist/server/actions/tracking-controller.d.ts +5 -0
- package/dist/server/actions/tracking-controller.js +135 -0
- package/dist/server/collections/statistics_config.d.ts +3 -0
- package/dist/server/collections/statistics_config.js +44 -0
- package/dist/server/collections/tracking_config.d.ts +3 -0
- package/dist/server/collections/tracking_config.js +58 -0
- package/dist/server/collections/tracking_log.d.ts +3 -0
- package/dist/server/collections/tracking_log.js +50 -0
- package/dist/server/hooks/afterAction.d.ts +3 -0
- package/dist/server/hooks/afterAction.js +94 -0
- package/dist/server/hooks/filterMatch.d.ts +1 -0
- package/dist/server/hooks/filterMatch.js +81 -0
- package/dist/server/hooks/getActiveUser.d.ts +6 -0
- package/dist/server/hooks/getActiveUser.js +84 -0
- package/dist/server/hooks/getStatistics.d.ts +17 -0
- package/dist/server/hooks/getStatistics.js +208 -0
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js +33 -0
- package/dist/server/plugin.d.ts +8 -0
- package/dist/server/plugin.js +161 -0
- package/package.json +27 -0
- package/server.d.ts +2 -0
- package/server.js +1 -0
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const NAMESPACE = "@tachybase/module-instrumentation";
|
|
2
|
+
export declare function usePluginTranslation(): any;
|
|
3
|
+
export declare function useTranslation(): {
|
|
4
|
+
t: (key: string, options?: {}) => string;
|
|
5
|
+
};
|
|
6
|
+
export declare function lang(key: string, options?: {}): string;
|
|
7
|
+
export declare const tval: (key: string) => string;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
"@tachybase/client": "1.0.25",
|
|
3
|
+
"antd": "5.22.5",
|
|
4
|
+
"react": "18.3.1",
|
|
5
|
+
"lodash": "4.17.21",
|
|
6
|
+
"@tachybase/database": "1.0.25",
|
|
7
|
+
"@tachybase/actions": "1.0.25",
|
|
8
|
+
"@tachybase/server": "1.0.25",
|
|
9
|
+
"@tachybase/schema": "1.0.25",
|
|
10
|
+
"@tachybase/utils": "1.0.25",
|
|
11
|
+
"dayjs": "1.11.13"
|
|
12
|
+
};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var src_exports = {};
|
|
30
|
+
__export(src_exports, {
|
|
31
|
+
default: () => import_server.default
|
|
32
|
+
});
|
|
33
|
+
module.exports = __toCommonJS(src_exports);
|
|
34
|
+
__reExport(src_exports, require("./server"), module.exports);
|
|
35
|
+
var import_server = __toESM(require("./server"));
|
|
36
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
37
|
+
0 && (module.exports = {
|
|
38
|
+
...require("./server")
|
|
39
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Action": "API Action",
|
|
3
|
+
"All users": "Total Users",
|
|
4
|
+
"Api audit": "Enable API Audit Log",
|
|
5
|
+
"Custom Instrumentation": "Custom Tracking",
|
|
6
|
+
"Instrumentation key": "Tracking Key",
|
|
7
|
+
"Instrumentation log": "Tracking Logs",
|
|
8
|
+
"Instrumentation type": "Tracking Type",
|
|
9
|
+
"Instrumentation values": "Tracking Values",
|
|
10
|
+
"Other users": "Other Users",
|
|
11
|
+
"Resource name": "API Resource",
|
|
12
|
+
"Server tracking configuration": "Backend Tracking Configuration",
|
|
13
|
+
"Statistics options": "Data Source",
|
|
14
|
+
"Statistics title": "Chart Title",
|
|
15
|
+
"Today active": "Active Today",
|
|
16
|
+
"Tracking options": "Tracking Configuration",
|
|
17
|
+
"Tracking statistics": "Tracking Analytics"
|
|
18
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"Action": "API操作",
|
|
3
|
+
"All users": "总用户数",
|
|
4
|
+
"Api audit": "启用日志",
|
|
5
|
+
"Custom Instrumentation": "自定义埋点",
|
|
6
|
+
"Instrumentation key": "埋点键",
|
|
7
|
+
"Instrumentation log": "埋点日志",
|
|
8
|
+
"Instrumentation type": "埋点类型",
|
|
9
|
+
"Instrumentation values": "值",
|
|
10
|
+
"Other users": "其他用户",
|
|
11
|
+
"Resource name": "API资源",
|
|
12
|
+
"Server tracking configuration": "后端埋点配置",
|
|
13
|
+
"Statistics options": "数据来源",
|
|
14
|
+
"Statistics title": "数据标题",
|
|
15
|
+
"Today active": "今日活跃",
|
|
16
|
+
"Total Users": "总用户",
|
|
17
|
+
"Tracking options": "埋点配置",
|
|
18
|
+
"Tracking statistics": "埋点分析"
|
|
19
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import Database, { Transaction } from '@tachybase/database';
|
|
2
|
+
export type WhiteListItem = {
|
|
3
|
+
title: string;
|
|
4
|
+
resourceName: string;
|
|
5
|
+
action: string;
|
|
6
|
+
options: Record<string, any>;
|
|
7
|
+
};
|
|
8
|
+
export declare class ServerTrackingFilter {
|
|
9
|
+
db: Database;
|
|
10
|
+
whiteList: WhiteListItem[];
|
|
11
|
+
blackList: {
|
|
12
|
+
resourceName: string;
|
|
13
|
+
action: string;
|
|
14
|
+
}[];
|
|
15
|
+
constructor(database: Database);
|
|
16
|
+
load(transaction?: Transaction): Promise<void>;
|
|
17
|
+
addRefreshListener(): Promise<void>;
|
|
18
|
+
check(resourceName: string, actionName: string): boolean;
|
|
19
|
+
}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 ServerTrackingFilter_exports = {};
|
|
19
|
+
__export(ServerTrackingFilter_exports, {
|
|
20
|
+
ServerTrackingFilter: () => ServerTrackingFilter
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(ServerTrackingFilter_exports);
|
|
23
|
+
class ServerTrackingFilter {
|
|
24
|
+
constructor(database) {
|
|
25
|
+
this.whiteList = [];
|
|
26
|
+
this.blackList = [];
|
|
27
|
+
this.db = database;
|
|
28
|
+
this.load().catch(console.error);
|
|
29
|
+
this.addRefreshListener().catch(console.error);
|
|
30
|
+
}
|
|
31
|
+
// app.start的时候从数据库apiLogsConfig保存到whiteList和blackList
|
|
32
|
+
async load(transaction) {
|
|
33
|
+
try {
|
|
34
|
+
const apiConfigs = await this.db.getRepository("trackingConfig").find({ transaction });
|
|
35
|
+
this.whiteList = [];
|
|
36
|
+
this.blackList = [];
|
|
37
|
+
for (const item of apiConfigs) {
|
|
38
|
+
if (item.apiConfig) {
|
|
39
|
+
this.whiteList.push({
|
|
40
|
+
title: item.title,
|
|
41
|
+
resourceName: item.resourceName,
|
|
42
|
+
action: item.action,
|
|
43
|
+
options: item.trackingOptions
|
|
44
|
+
});
|
|
45
|
+
} else {
|
|
46
|
+
this.blackList.push({ resourceName: item.resourceName, action: item.action });
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
} catch (error) {
|
|
50
|
+
console.error("Failed to load API filter lists:", error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
async addRefreshListener() {
|
|
54
|
+
this.db.on("trackingConfig.afterSave", async (model, options) => {
|
|
55
|
+
await this.load(options.transaction);
|
|
56
|
+
});
|
|
57
|
+
this.db.on("trackingConfig.afterDestroy", async (model, options) => {
|
|
58
|
+
await this.load(options.transaction);
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
check(resourceName, actionName) {
|
|
62
|
+
return this.whiteList.some((item) => item.resourceName === resourceName && item.action === actionName);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
ServerTrackingFilter
|
|
68
|
+
});
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __knownSymbol = (name, symbol) => (symbol = Symbol[name]) ? symbol : Symbol.for("Symbol." + name);
|
|
7
|
+
var __typeError = (msg) => {
|
|
8
|
+
throw TypeError(msg);
|
|
9
|
+
};
|
|
10
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
11
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
12
|
+
var __export = (target, all) => {
|
|
13
|
+
for (var name in all)
|
|
14
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
15
|
+
};
|
|
16
|
+
var __copyProps = (to, from, except, desc) => {
|
|
17
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
18
|
+
for (let key of __getOwnPropNames(from))
|
|
19
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
20
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
21
|
+
}
|
|
22
|
+
return to;
|
|
23
|
+
};
|
|
24
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
25
|
+
var __decoratorStart = (base) => [, , , __create((base == null ? void 0 : base[__knownSymbol("metadata")]) ?? null)];
|
|
26
|
+
var __decoratorStrings = ["class", "method", "getter", "setter", "accessor", "field", "value", "get", "set"];
|
|
27
|
+
var __expectFn = (fn) => fn !== void 0 && typeof fn !== "function" ? __typeError("Function expected") : fn;
|
|
28
|
+
var __decoratorContext = (kind, name, done, metadata, fns) => ({ kind: __decoratorStrings[kind], name, metadata, addInitializer: (fn) => done._ ? __typeError("Already initialized") : fns.push(__expectFn(fn || null)) });
|
|
29
|
+
var __decoratorMetadata = (array, target) => __defNormalProp(target, __knownSymbol("metadata"), array[3]);
|
|
30
|
+
var __runInitializers = (array, flags, self, value) => {
|
|
31
|
+
for (var i = 0, fns = array[flags >> 1], n = fns && fns.length; i < n; i++) flags & 1 ? fns[i].call(self) : value = fns[i].call(self, value);
|
|
32
|
+
return value;
|
|
33
|
+
};
|
|
34
|
+
var __decorateElement = (array, flags, name, decorators, target, extra) => {
|
|
35
|
+
var fn, it, done, ctx, access, k = flags & 7, s = !!(flags & 8), p = !!(flags & 16);
|
|
36
|
+
var j = k > 3 ? array.length + 1 : k ? s ? 1 : 2 : 0, key = __decoratorStrings[k + 5];
|
|
37
|
+
var initializers = k > 3 && (array[j - 1] = []), extraInitializers = array[j] || (array[j] = []);
|
|
38
|
+
var desc = k && (!p && !s && (target = target.prototype), k < 5 && (k > 3 || !p) && __getOwnPropDesc(k < 4 ? target : { get [name]() {
|
|
39
|
+
return __privateGet(this, extra);
|
|
40
|
+
}, set [name](x) {
|
|
41
|
+
return __privateSet(this, extra, x);
|
|
42
|
+
} }, name));
|
|
43
|
+
k ? p && k < 4 && __name(extra, (k > 2 ? "set " : k > 1 ? "get " : "") + name) : __name(target, name);
|
|
44
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
45
|
+
ctx = __decoratorContext(k, name, done = {}, array[3], extraInitializers);
|
|
46
|
+
if (k) {
|
|
47
|
+
ctx.static = s, ctx.private = p, access = ctx.access = { has: p ? (x) => __privateIn(target, x) : (x) => name in x };
|
|
48
|
+
if (k ^ 3) access.get = p ? (x) => (k ^ 1 ? __privateGet : __privateMethod)(x, target, k ^ 4 ? extra : desc.get) : (x) => x[name];
|
|
49
|
+
if (k > 2) access.set = p ? (x, y) => __privateSet(x, target, y, k ^ 4 ? extra : desc.set) : (x, y) => x[name] = y;
|
|
50
|
+
}
|
|
51
|
+
it = (0, decorators[i])(k ? k < 4 ? p ? extra : desc[key] : k > 4 ? void 0 : { get: desc.get, set: desc.set } : target, ctx), done._ = 1;
|
|
52
|
+
if (k ^ 4 || it === void 0) __expectFn(it) && (k > 4 ? initializers.unshift(it) : k ? p ? extra = it : desc[key] = it : target = it);
|
|
53
|
+
else if (typeof it !== "object" || it === null) __typeError("Object expected");
|
|
54
|
+
else __expectFn(fn = it.get) && (desc.get = fn), __expectFn(fn = it.set) && (desc.set = fn), __expectFn(fn = it.init) && initializers.unshift(fn);
|
|
55
|
+
}
|
|
56
|
+
return k || __decoratorMetadata(array, target), desc && __defProp(target, name, desc), p ? k ^ 4 ? extra : desc : target;
|
|
57
|
+
};
|
|
58
|
+
var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
|
|
59
|
+
var __privateIn = (member, obj) => Object(obj) !== obj ? __typeError('Cannot use the "in" operator on this value') : member.has(obj);
|
|
60
|
+
var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
|
|
61
|
+
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
62
|
+
var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
|
|
63
|
+
var tracking_controller_exports = {};
|
|
64
|
+
__export(tracking_controller_exports, {
|
|
65
|
+
TrackingController: () => TrackingController
|
|
66
|
+
});
|
|
67
|
+
module.exports = __toCommonJS(tracking_controller_exports);
|
|
68
|
+
var import_utils = require("@tachybase/utils");
|
|
69
|
+
var import_getActiveUser = require("../hooks/getActiveUser");
|
|
70
|
+
var import_getStatistics = require("../hooks/getStatistics");
|
|
71
|
+
var _list_dec, _create_dec, _TrackingController_decorators, _init;
|
|
72
|
+
_TrackingController_decorators = [(0, import_utils.Controller)("instrumentation")], _create_dec = [(0, import_utils.Action)("create", { acl: "public" })], _list_dec = [(0, import_utils.Action)("list", { acl: "private" })];
|
|
73
|
+
class TrackingController {
|
|
74
|
+
constructor() {
|
|
75
|
+
__runInitializers(_init, 5, this);
|
|
76
|
+
}
|
|
77
|
+
async create(ctx, next) {
|
|
78
|
+
var _a, _b;
|
|
79
|
+
const repo = await ctx.db.getRepository("trackingEvents");
|
|
80
|
+
const version = process.env.npm_package_version;
|
|
81
|
+
const currentTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
82
|
+
const currentUserId = ((_b = (_a = ctx.auth) == null ? void 0 : _a.user) == null ? void 0 : _b.id) || null;
|
|
83
|
+
const values = ctx.action.params.values.values ? {
|
|
84
|
+
...ctx.action.params.values,
|
|
85
|
+
values: {
|
|
86
|
+
meta: {
|
|
87
|
+
userId: currentUserId,
|
|
88
|
+
createdAt: currentTime
|
|
89
|
+
},
|
|
90
|
+
payload: {
|
|
91
|
+
...ctx.action.params.values.values,
|
|
92
|
+
version
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
} : { ...ctx.action.params.values, createdAt: currentTime };
|
|
96
|
+
await repo.create({
|
|
97
|
+
values
|
|
98
|
+
});
|
|
99
|
+
return next();
|
|
100
|
+
}
|
|
101
|
+
async list(ctx, next) {
|
|
102
|
+
var _a;
|
|
103
|
+
const userCount = await ctx.db.getRepository("users").count();
|
|
104
|
+
const ActiveUsers = await (0, import_getActiveUser.getDailyActiveUser)(ctx);
|
|
105
|
+
const allData = await ctx.db.getRepository("trackingEvents").find();
|
|
106
|
+
const configs = await ctx.db.getRepository("statisticsConfig").find();
|
|
107
|
+
let customData = {};
|
|
108
|
+
let customDataByTime = {};
|
|
109
|
+
for (const config of configs) {
|
|
110
|
+
if ((_a = config.statisticsOptions) == null ? void 0 : _a.timeGroup) {
|
|
111
|
+
const grouped = (0, import_getStatistics.groupDataByTime)(allData, config.statisticsOptions);
|
|
112
|
+
customDataByTime[config.title] = grouped;
|
|
113
|
+
} else {
|
|
114
|
+
const count = (0, import_getStatistics.countDataByEventFrequency)(allData, config.statisticsOptions);
|
|
115
|
+
customData[config.title] = count;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
const result = {
|
|
119
|
+
users: { ...ActiveUsers, userCount },
|
|
120
|
+
customData,
|
|
121
|
+
customDataByTime
|
|
122
|
+
};
|
|
123
|
+
ctx.body = result;
|
|
124
|
+
return next();
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
_init = __decoratorStart(null);
|
|
128
|
+
__decorateElement(_init, 1, "create", _create_dec, TrackingController);
|
|
129
|
+
__decorateElement(_init, 1, "list", _list_dec, TrackingController);
|
|
130
|
+
TrackingController = __decorateElement(_init, 0, "TrackingController", _TrackingController_decorators, TrackingController);
|
|
131
|
+
__runInitializers(_init, 1, TrackingController);
|
|
132
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
133
|
+
0 && (module.exports = {
|
|
134
|
+
TrackingController
|
|
135
|
+
});
|
|
@@ -0,0 +1,44 @@
|
|
|
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 statistics_config_exports = {};
|
|
19
|
+
__export(statistics_config_exports, {
|
|
20
|
+
default: () => statistics_config_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(statistics_config_exports);
|
|
23
|
+
var statistics_config_default = {
|
|
24
|
+
dumpRules: {
|
|
25
|
+
group: "log"
|
|
26
|
+
},
|
|
27
|
+
name: "statisticsConfig",
|
|
28
|
+
createdBy: false,
|
|
29
|
+
updatedBy: false,
|
|
30
|
+
updatedAt: false,
|
|
31
|
+
createdAt: false,
|
|
32
|
+
shared: true,
|
|
33
|
+
model: "CollectionModel",
|
|
34
|
+
fields: [
|
|
35
|
+
{
|
|
36
|
+
type: "string",
|
|
37
|
+
name: "title"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "jsonb",
|
|
41
|
+
name: "statisticsOptions"
|
|
42
|
+
}
|
|
43
|
+
]
|
|
44
|
+
};
|
|
@@ -0,0 +1,58 @@
|
|
|
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 tracking_config_exports = {};
|
|
19
|
+
__export(tracking_config_exports, {
|
|
20
|
+
default: () => tracking_config_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(tracking_config_exports);
|
|
23
|
+
var tracking_config_default = {
|
|
24
|
+
dumpRules: {
|
|
25
|
+
group: "log"
|
|
26
|
+
},
|
|
27
|
+
name: "trackingConfig",
|
|
28
|
+
createdBy: false,
|
|
29
|
+
updatedBy: false,
|
|
30
|
+
updatedAt: false,
|
|
31
|
+
createdAt: false,
|
|
32
|
+
shared: true,
|
|
33
|
+
model: "CollectionModel",
|
|
34
|
+
fields: [
|
|
35
|
+
{
|
|
36
|
+
type: "string",
|
|
37
|
+
name: "resourceName"
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
type: "string",
|
|
41
|
+
name: "title",
|
|
42
|
+
unique: true
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
type: "string",
|
|
46
|
+
name: "action"
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: "boolean",
|
|
50
|
+
name: "apiConfig",
|
|
51
|
+
defaultValue: true
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
type: "jsonb",
|
|
55
|
+
name: "trackingOptions"
|
|
56
|
+
}
|
|
57
|
+
]
|
|
58
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
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 tracking_log_exports = {};
|
|
19
|
+
__export(tracking_log_exports, {
|
|
20
|
+
default: () => tracking_log_default
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(tracking_log_exports);
|
|
23
|
+
var tracking_log_default = {
|
|
24
|
+
dumpRules: {
|
|
25
|
+
group: "log"
|
|
26
|
+
},
|
|
27
|
+
name: "trackingEvents",
|
|
28
|
+
createdAt: true,
|
|
29
|
+
fields: [
|
|
30
|
+
{
|
|
31
|
+
name: "id",
|
|
32
|
+
autoIncrement: true,
|
|
33
|
+
primaryKey: true,
|
|
34
|
+
allowNull: false,
|
|
35
|
+
type: "bigInt"
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
type: "string",
|
|
39
|
+
name: "type"
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
type: "string",
|
|
43
|
+
name: "key"
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
type: "jsonb",
|
|
47
|
+
name: "values"
|
|
48
|
+
}
|
|
49
|
+
]
|
|
50
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
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 afterAction_exports = {};
|
|
19
|
+
__export(afterAction_exports, {
|
|
20
|
+
handleOtherAction: () => handleOtherAction
|
|
21
|
+
});
|
|
22
|
+
module.exports = __toCommonJS(afterAction_exports);
|
|
23
|
+
var import_filterMatch = require("./filterMatch");
|
|
24
|
+
async function handleOtherAction(ctx, next, whiteList) {
|
|
25
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
26
|
+
const { actionName, resourceName, params } = ctx.action;
|
|
27
|
+
const data = ((_a = ctx.response) == null ? void 0 : _a.body) || null;
|
|
28
|
+
const repo = ctx.db.getRepository("trackingEvents");
|
|
29
|
+
const allConfigs = whiteList.filter((item) => item.resourceName === resourceName && item.action === actionName);
|
|
30
|
+
function findValuesByKeys(obj, trackingOptions) {
|
|
31
|
+
const result = {};
|
|
32
|
+
const traverse = (current) => {
|
|
33
|
+
if (typeof current !== "object" || current === null) return;
|
|
34
|
+
for (const [k, v] of Object.entries(current)) {
|
|
35
|
+
if (trackingOptions.includes(k)) {
|
|
36
|
+
if (!result[k]) result[k] = [];
|
|
37
|
+
result[k].push(v);
|
|
38
|
+
}
|
|
39
|
+
traverse(v);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
traverse(obj);
|
|
43
|
+
for (const key in result) {
|
|
44
|
+
const seen = /* @__PURE__ */ new Set();
|
|
45
|
+
result[key] = result[key].filter((item) => {
|
|
46
|
+
const str = JSON.stringify(item);
|
|
47
|
+
if (seen.has(str)) return false;
|
|
48
|
+
seen.add(str);
|
|
49
|
+
return true;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return result;
|
|
53
|
+
}
|
|
54
|
+
for (const Config of allConfigs) {
|
|
55
|
+
const configTitle = (Config == null ? void 0 : Config.title) || "";
|
|
56
|
+
const configKeys = {
|
|
57
|
+
meta: ((_b = Config == null ? void 0 : Config.options) == null ? void 0 : _b.meta) || [],
|
|
58
|
+
payload: ((_c = Config == null ? void 0 : Config.options) == null ? void 0 : _c.payload) || [],
|
|
59
|
+
filter: ((_d = Config == null ? void 0 : Config.options) == null ? void 0 : _d.filter) || {}
|
|
60
|
+
};
|
|
61
|
+
const app = ctx.app;
|
|
62
|
+
const collection = app.mainDataSource.collectionManager.getCollection(ctx.action.resourceName);
|
|
63
|
+
const currentRecordId = ((_e = ctx.body) == null ? void 0 : _e[collection == null ? void 0 : collection.filterTargetKey]) || null;
|
|
64
|
+
const currentUserId = ((_g = (_f = ctx.auth) == null ? void 0 : _f.user) == null ? void 0 : _g.id) || null;
|
|
65
|
+
const currentTime = (/* @__PURE__ */ new Date()).toISOString();
|
|
66
|
+
const baseValues = {};
|
|
67
|
+
if (configKeys.meta.includes("userId")) baseValues.userId = currentUserId;
|
|
68
|
+
if (configKeys.meta.includes("recordId")) baseValues.recordId = currentRecordId;
|
|
69
|
+
if (configKeys.meta.includes("createdAt")) baseValues.createdAt = currentTime;
|
|
70
|
+
const nestedValuesMap = findValuesByKeys({ params, data }, configKeys.payload);
|
|
71
|
+
const finalValues = {
|
|
72
|
+
meta: baseValues,
|
|
73
|
+
payload: Object.fromEntries(
|
|
74
|
+
Object.entries(nestedValuesMap).map(([key, value]) => [
|
|
75
|
+
key,
|
|
76
|
+
Array.isArray(value) && value.length === 1 ? value[0] : value
|
|
77
|
+
])
|
|
78
|
+
)
|
|
79
|
+
};
|
|
80
|
+
if ((0, import_filterMatch.filterMatch)(finalValues, configKeys.filter)) {
|
|
81
|
+
await repo.create({
|
|
82
|
+
values: {
|
|
83
|
+
key: configTitle,
|
|
84
|
+
type: `${resourceName}-${actionName}`,
|
|
85
|
+
values: finalValues
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
+
0 && (module.exports = {
|
|
93
|
+
handleOtherAction
|
|
94
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function filterMatch(model: any, filter: any): any;
|