@privateaim/server-telemetry-kit 0.8.16 → 0.8.17

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/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.17](https://github.com/PrivateAIM/hub/compare/v0.8.16...v0.8.17) (2025-09-01)
4
+
5
+
6
+ ### Features
7
+
8
+ * refactor domain event publisher & register amqp ([0f98ecf](https://github.com/PrivateAIM/hub/commit/0f98ecf3c24239d9050fd4a7c2e0bd6843cb3dc8))
9
+
10
+
11
+ ### Dependencies
12
+
13
+ * The following workspace dependencies were updated
14
+ * devDependencies
15
+ * @privateaim/kit bumped from ^0.8.16 to ^0.8.17
16
+ * @privateaim/server-kit bumped from ^0.8.16 to ^0.8.17
17
+ * @privateaim/telemetry-kit bumped from ^0.8.16 to ^0.8.17
18
+ * peerDependencies
19
+ * @privateaim/kit bumped from ^0.8.16 to ^0.8.17
20
+ * @privateaim/server-kit bumped from ^0.8.16 to ^0.8.17
21
+ * @privateaim/telemetry-kit bumped from ^0.8.16 to ^0.8.17
22
+
3
23
  ## [0.8.16](https://github.com/PrivateAIM/hub/compare/v0.8.15...v0.8.16) (2025-08-26)
4
24
 
5
25
 
@@ -0,0 +1,2 @@
1
+ export * from './subscriber';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/event/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./subscriber"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/core/event/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,+CAA6B"}
@@ -0,0 +1,5 @@
1
+ import type { EntityEventHandleOptions, IEntityEventHandler } from '@privateaim/server-kit';
2
+ export declare class EntityEventHandler implements IEntityEventHandler {
3
+ handle(ctx: EntityEventHandleOptions): Promise<void>;
4
+ }
5
+ //# sourceMappingURL=subscriber.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriber.d.ts","sourceRoot":"","sources":["../../../src/core/event/subscriber.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,wBAAwB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAQ5F,qBAAa,kBAAmB,YAAW,mBAAmB;IACpD,MAAM,CAAC,GAAG,EAAE,wBAAwB,GAAG,OAAO,CAAC,IAAI,CAAC;CA0F7D"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.EntityEventHandler = void 0;
10
+ const smob_1 = require("smob");
11
+ const server_kit_1 = require("@privateaim/server-kit");
12
+ const telemetry_kit_1 = require("@privateaim/telemetry-kit");
13
+ const kit_1 = require("@privateaim/kit");
14
+ const services_1 = require("../../services");
15
+ class EntityEventHandler {
16
+ async handle(ctx) {
17
+ if (ctx.metadata.ref_type === telemetry_kit_1.DomainType.EVENT) {
18
+ return;
19
+ }
20
+ const entity = {
21
+ ref_type: ctx.metadata.ref_type,
22
+ name: ctx.metadata.event,
23
+ scope: 'entity',
24
+ expiring: true,
25
+ expires_at: new Date(Date.now() + (1000 * 60 * 60 * 24 * 7)).toISOString(),
26
+ };
27
+ if (ctx.metadata.ref_id) {
28
+ entity.ref_id = ctx.metadata.ref_id;
29
+ }
30
+ const keys = [
31
+ 'actor_id',
32
+ 'actor_type',
33
+ 'actor_name',
34
+ 'request_path',
35
+ 'request_method',
36
+ 'request_ip_address',
37
+ 'request_user_agent',
38
+ ];
39
+ for (let i = 0; i < keys.length; i++) {
40
+ if (ctx.metadata[keys[i]]) {
41
+ entity[keys[i]] = ctx.metadata[keys[i]];
42
+ }
43
+ }
44
+ if (entity.request_ip_address &&
45
+ entity.request_ip_address === '::1') {
46
+ entity.request_ip_address = '127.0.0.1';
47
+ }
48
+ const data = {};
49
+ if (
50
+ // todo: use enum
51
+ ctx.metadata.event === 'updated' &&
52
+ ctx.dataPrevious) {
53
+ const diff = {};
54
+ const keys = Object.keys(ctx.data);
55
+ for (let i = 0; i < keys.length; i++) {
56
+ const key = keys[i];
57
+ // skip date changes
58
+ if (key.endsWith('_at')) {
59
+ continue;
60
+ }
61
+ if ((0, kit_1.isObject)(diff[key]) || Array.isArray(diff[key])) {
62
+ continue;
63
+ }
64
+ if (!(0, smob_1.isEqual)(ctx.data[key], ctx.dataPrevious[key])) {
65
+ diff[key] = {
66
+ next: ctx.data[key],
67
+ previous: ctx.dataPrevious[key],
68
+ };
69
+ }
70
+ }
71
+ data.diff = diff;
72
+ }
73
+ entity.data = data;
74
+ if ((0, services_1.isEventComponentServiceUsable)()) {
75
+ const eventService = (0, services_1.useEventComponentService)();
76
+ await eventService.command({
77
+ command: 'create',
78
+ data: entity,
79
+ });
80
+ return;
81
+ }
82
+ (0, server_kit_1.useLogger)().debug('Event service is not available to publish events.');
83
+ }
84
+ }
85
+ exports.EntityEventHandler = EntityEventHandler;
86
+ //# sourceMappingURL=subscriber.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscriber.js","sourceRoot":"","sources":["../../../src/core/event/subscriber.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,+BAA+B;AAE/B,uDAAmD;AAEnD,6DAAuD;AAEvD,yCAA2C;AAC3C,6CAAyF;AAEzF,MAAa,kBAAkB;IAC3B,KAAK,CAAC,MAAM,CAAC,GAA6B;QACtC,IAAI,GAAG,CAAC,QAAQ,CAAC,QAAQ,KAAK,0BAAU,CAAC,KAAK,EAAE,CAAC;YAC7C,OAAO;QACX,CAAC;QAED,MAAM,MAAM,GAAoB;YAC5B,QAAQ,EAAE,GAAG,CAAC,QAAQ,CAAC,QAAQ;YAE/B,IAAI,EAAE,GAAG,CAAC,QAAQ,CAAC,KAAK;YACxB,KAAK,EAAE,QAAQ;YAEf,QAAQ,EAAE,IAAI;YACd,UAAU,EAAE,IAAI,IAAI,CAChB,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,CACzC,CAAC,WAAW,EAAE;SAClB,CAAC;QAEF,IAAI,GAAG,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;YACtB,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC;QACxC,CAAC;QAED,MAAM,IAAI,GAAqB;YAC3B,UAAU;YACV,YAAY;YACZ,YAAY;YACZ,cAAc;YACd,gBAAgB;YAChB,oBAAoB;YACpB,oBAAoB;SACvB,CAAC;QAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GA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,CAAC,GAAG,CAAC,GAAG;wBACR,IAAI,EAAE,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC;wBACnB,QAAQ,EAAE,GAAG,CAAC,YAAY,CAAC,GAAG,CAAC;qBAClC,CAAC;gBACN,CAAC;YACL,CAAC;YAED,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACrB,CAAC;QAED,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;QAEnB,IAAI,IAAA,wCAA6B,GAAE,EAAE,CAAC;YAClC,MAAM,YAAY,GAAG,IAAA,mCAAwB,GAAE,CAAC;YAChD,MAAM,YAAY,CAAC,OAAO,CAAC;gBACvB,OAAO,EAAE,QAAQ;gBACjB,IAAI,EAAE,MAAM;aACf,CAAC,CAAC;YAEH,OAAO;QACX,CAAC;QAED,IAAA,sBAAS,GAAE,CAAC,KAAK,CAAC,mDAAmD,CAAC,CAAC;IAC3E,CAAC;CACJ;AA3FD,gDA2FC"}
@@ -0,0 +1,2 @@
1
+ export * from './event';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":"AAOA,cAAc,SAAS,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright (c) 2025.
4
+ * Author Peter Placzek (tada5hi)
5
+ * For the full copyright and license information,
6
+ * view the LICENSE file that was distributed with this source code.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
+ };
22
+ Object.defineProperty(exports, "__esModule", { value: true });
23
+ __exportStar(require("./event"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/core/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,0CAAwB"}
package/dist/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from './components';
2
+ export * from './core';
2
3
  export * from './services';
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC"}
package/dist/index.js CHANGED
@@ -21,5 +21,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
21
21
  };
22
22
  Object.defineProperty(exports, "__esModule", { value: true });
23
23
  __exportStar(require("./components"), exports);
24
+ __exportStar(require("./core"), exports);
24
25
  __exportStar(require("./services"), exports);
25
26
  //# 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;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,6CAA2B"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,+CAA6B;AAC7B,yCAAuB;AACvB,6CAA2B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@privateaim/server-telemetry-kit",
3
- "version": "0.8.16",
3
+ "version": "0.8.17",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "author": {
@@ -11,16 +11,19 @@
11
11
  "license": "Apache-2.0",
12
12
  "description": "This package contains server side db helpers & utilities.",
13
13
  "dependencies": {
14
+ "smob": "^1.5.0",
14
15
  "winston-transport": "^4.9.0"
15
16
  },
16
17
  "devDependencies": {
17
- "@privateaim/server-kit": "^0.8.16",
18
- "@privateaim/telemetry-kit": "^0.8.16",
18
+ "@privateaim/kit": "^0.8.17",
19
+ "@privateaim/server-kit": "^0.8.17",
20
+ "@privateaim/telemetry-kit": "^0.8.17",
19
21
  "singa": "^1.1.0"
20
22
  },
21
23
  "peerDependencies": {
22
- "@privateaim/server-kit": "^0.8.16",
23
- "@privateaim/telemetry-kit": "^0.8.16",
24
+ "@privateaim/kit": "^0.8.17",
25
+ "@privateaim/server-kit": "^0.8.17",
26
+ "@privateaim/telemetry-kit": "^0.8.17",
24
27
  "singa": "^1.1.0"
25
28
  },
26
29
  "scripts": {
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './subscriber';
@@ -0,0 +1,108 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ import { isEqual } from 'smob';
9
+ import type { EntityEventHandleOptions, IEntityEventHandler } from '@privateaim/server-kit';
10
+ import { useLogger } from '@privateaim/server-kit';
11
+ import type { Event, EventData } from '@privateaim/telemetry-kit';
12
+ import { DomainType } from '@privateaim/telemetry-kit';
13
+ import type { ObjectDiff, ObjectLiteral } from '@privateaim/kit';
14
+ import { isObject } from '@privateaim/kit';
15
+ import { isEventComponentServiceUsable, useEventComponentService } from '../../services';
16
+
17
+ export class EntityEventHandler implements IEntityEventHandler {
18
+ async handle(ctx: EntityEventHandleOptions): Promise<void> {
19
+ if (ctx.metadata.ref_type === DomainType.EVENT) {
20
+ return;
21
+ }
22
+
23
+ const entity : Partial<Event> = {
24
+ ref_type: ctx.metadata.ref_type,
25
+
26
+ name: ctx.metadata.event,
27
+ scope: 'entity',
28
+
29
+ expiring: true,
30
+ expires_at: new Date(
31
+ Date.now() + (1000 * 60 * 60 * 24 * 7),
32
+ ).toISOString(),
33
+ };
34
+
35
+ if (ctx.metadata.ref_id) {
36
+ entity.ref_id = ctx.metadata.ref_id;
37
+ }
38
+
39
+ const keys : (keyof Event)[] = [
40
+ 'actor_id',
41
+ 'actor_type',
42
+ 'actor_name',
43
+ 'request_path',
44
+ 'request_method',
45
+ 'request_ip_address',
46
+ 'request_user_agent',
47
+ ];
48
+
49
+ for (let i = 0; i < keys.length; i++) {
50
+ if (ctx.metadata[keys[i]]) {
51
+ (entity as ObjectLiteral)[keys[i]] = ctx.metadata[keys[i]];
52
+ }
53
+ }
54
+
55
+ if (
56
+ entity.request_ip_address &&
57
+ entity.request_ip_address === '::1'
58
+ ) {
59
+ entity.request_ip_address = '127.0.0.1';
60
+ }
61
+
62
+ const data : EventData = {};
63
+
64
+ if (
65
+ // todo: use enum
66
+ ctx.metadata.event === 'updated' &&
67
+ ctx.dataPrevious
68
+ ) {
69
+ const diff : ObjectDiff = {};
70
+ const keys = Object.keys(ctx.data);
71
+ for (let i = 0; i < keys.length; i++) {
72
+ const key = keys[i];
73
+
74
+ // skip date changes
75
+ if (key.endsWith('_at')) {
76
+ continue;
77
+ }
78
+
79
+ if (isObject(diff[key]) || Array.isArray(diff[key])) {
80
+ continue;
81
+ }
82
+
83
+ if (!isEqual(ctx.data[key], ctx.dataPrevious[key])) {
84
+ diff[key] = {
85
+ next: ctx.data[key],
86
+ previous: ctx.dataPrevious[key],
87
+ };
88
+ }
89
+ }
90
+
91
+ data.diff = diff;
92
+ }
93
+
94
+ entity.data = data;
95
+
96
+ if (isEventComponentServiceUsable()) {
97
+ const eventService = useEventComponentService();
98
+ await eventService.command({
99
+ command: 'create',
100
+ data: entity,
101
+ });
102
+
103
+ return;
104
+ }
105
+
106
+ useLogger().debug('Event service is not available to publish events.');
107
+ }
108
+ }
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2025.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */
7
+
8
+ export * from './event';
package/src/index.ts CHANGED
@@ -6,4 +6,5 @@
6
6
  */
7
7
 
8
8
  export * from './components';
9
+ export * from './core';
9
10
  export * from './services';