@privateaim/server-telemetry-kit 0.8.16

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 (127) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/LICENSE +202 -0
  3. package/README.md +6 -0
  4. package/dist/components/event/constants.d.ts +20 -0
  5. package/dist/components/event/constants.d.ts.map +1 -0
  6. package/dist/components/event/constants.js +31 -0
  7. package/dist/components/event/constants.js.map +1 -0
  8. package/dist/components/event/handlers/create/index.d.ts +2 -0
  9. package/dist/components/event/handlers/create/index.d.ts.map +1 -0
  10. package/dist/components/event/handlers/create/index.js +24 -0
  11. package/dist/components/event/handlers/create/index.js.map +1 -0
  12. package/dist/components/event/handlers/create/types.d.ts +11 -0
  13. package/dist/components/event/handlers/create/types.d.ts.map +1 -0
  14. package/dist/components/event/handlers/create/types.js +9 -0
  15. package/dist/components/event/handlers/create/types.js.map +1 -0
  16. package/dist/components/event/handlers/index.d.ts +2 -0
  17. package/dist/components/event/handlers/index.d.ts.map +1 -0
  18. package/dist/components/event/handlers/index.js +24 -0
  19. package/dist/components/event/handlers/index.js.map +1 -0
  20. package/dist/components/event/index.d.ts +4 -0
  21. package/dist/components/event/index.d.ts.map +1 -0
  22. package/dist/components/event/index.js +26 -0
  23. package/dist/components/event/index.js.map +1 -0
  24. package/dist/components/event/types.d.ts +31 -0
  25. package/dist/components/event/types.d.ts.map +1 -0
  26. package/dist/components/event/types.js +9 -0
  27. package/dist/components/event/types.js.map +1 -0
  28. package/dist/components/index.d.ts +3 -0
  29. package/dist/components/index.d.ts.map +1 -0
  30. package/dist/components/index.js +25 -0
  31. package/dist/components/index.js.map +1 -0
  32. package/dist/components/log/constants.d.ts +19 -0
  33. package/dist/components/log/constants.d.ts.map +1 -0
  34. package/dist/components/log/constants.js +30 -0
  35. package/dist/components/log/constants.js.map +1 -0
  36. package/dist/components/log/handlers/index.d.ts +2 -0
  37. package/dist/components/log/handlers/index.d.ts.map +1 -0
  38. package/dist/components/log/handlers/index.js +24 -0
  39. package/dist/components/log/handlers/index.js.map +1 -0
  40. package/dist/components/log/handlers/write/index.d.ts +2 -0
  41. package/dist/components/log/handlers/write/index.d.ts.map +1 -0
  42. package/dist/components/log/handlers/write/index.js +24 -0
  43. package/dist/components/log/handlers/write/index.js.map +1 -0
  44. package/dist/components/log/handlers/write/types.d.ts +3 -0
  45. package/dist/components/log/handlers/write/types.d.ts.map +1 -0
  46. package/dist/components/log/handlers/write/types.js +9 -0
  47. package/dist/components/log/handlers/write/types.js.map +1 -0
  48. package/dist/components/log/index.d.ts +4 -0
  49. package/dist/components/log/index.d.ts.map +1 -0
  50. package/dist/components/log/index.js +26 -0
  51. package/dist/components/log/index.js.map +1 -0
  52. package/dist/components/log/types.d.ts +28 -0
  53. package/dist/components/log/types.d.ts.map +1 -0
  54. package/dist/components/log/types.js +9 -0
  55. package/dist/components/log/types.js.map +1 -0
  56. package/dist/index.d.ts +3 -0
  57. package/dist/index.d.ts.map +1 -0
  58. package/dist/index.js +25 -0
  59. package/dist/index.js.map +1 -0
  60. package/dist/services/event/index.d.ts +3 -0
  61. package/dist/services/event/index.d.ts.map +1 -0
  62. package/dist/services/event/index.js +25 -0
  63. package/dist/services/event/index.js.map +1 -0
  64. package/dist/services/event/module.d.ts +6 -0
  65. package/dist/services/event/module.d.ts.map +1 -0
  66. package/dist/services/event/module.js +47 -0
  67. package/dist/services/event/module.js.map +1 -0
  68. package/dist/services/event/singleton.d.ts +4 -0
  69. package/dist/services/event/singleton.d.ts.map +1 -0
  70. package/dist/services/event/singleton.js +24 -0
  71. package/dist/services/event/singleton.js.map +1 -0
  72. package/dist/services/index.d.ts +4 -0
  73. package/dist/services/index.d.ts.map +1 -0
  74. package/dist/services/index.js +26 -0
  75. package/dist/services/index.js.map +1 -0
  76. package/dist/services/log/index.d.ts +3 -0
  77. package/dist/services/log/index.d.ts.map +1 -0
  78. package/dist/services/log/index.js +25 -0
  79. package/dist/services/log/index.js.map +1 -0
  80. package/dist/services/log/module.d.ts +6 -0
  81. package/dist/services/log/module.d.ts.map +1 -0
  82. package/dist/services/log/module.js +50 -0
  83. package/dist/services/log/module.js.map +1 -0
  84. package/dist/services/log/singleton.d.ts +4 -0
  85. package/dist/services/log/singleton.d.ts.map +1 -0
  86. package/dist/services/log/singleton.js +24 -0
  87. package/dist/services/log/singleton.js.map +1 -0
  88. package/dist/services/logger/index.d.ts +3 -0
  89. package/dist/services/logger/index.d.ts.map +1 -0
  90. package/dist/services/logger/index.js +25 -0
  91. package/dist/services/logger/index.js.map +1 -0
  92. package/dist/services/logger/transport.d.ts +11 -0
  93. package/dist/services/logger/transport.d.ts.map +1 -0
  94. package/dist/services/logger/transport.js +72 -0
  95. package/dist/services/logger/transport.js.map +1 -0
  96. package/dist/services/logger/type.d.ts +8 -0
  97. package/dist/services/logger/type.d.ts.map +1 -0
  98. package/dist/services/logger/type.js +9 -0
  99. package/dist/services/logger/type.js.map +1 -0
  100. package/package.json +29 -0
  101. package/src/components/event/constants.ts +30 -0
  102. package/src/components/event/handlers/create/index.ts +8 -0
  103. package/src/components/event/handlers/create/types.ts +20 -0
  104. package/src/components/event/handlers/index.ts +8 -0
  105. package/src/components/event/index.ts +10 -0
  106. package/src/components/event/types.ts +50 -0
  107. package/src/components/index.ts +9 -0
  108. package/src/components/log/constants.ts +29 -0
  109. package/src/components/log/handlers/index.ts +8 -0
  110. package/src/components/log/handlers/write/index.ts +8 -0
  111. package/src/components/log/handlers/write/types.ts +10 -0
  112. package/src/components/log/index.ts +10 -0
  113. package/src/components/log/types.ts +45 -0
  114. package/src/index.ts +9 -0
  115. package/src/services/event/index.ts +9 -0
  116. package/src/services/event/module.ts +56 -0
  117. package/src/services/event/singleton.ts +23 -0
  118. package/src/services/index.ts +10 -0
  119. package/src/services/log/index.ts +9 -0
  120. package/src/services/log/module.ts +60 -0
  121. package/src/services/log/singleton.ts +23 -0
  122. package/src/services/logger/index.ts +9 -0
  123. package/src/services/logger/transport.ts +90 -0
  124. package/src/services/logger/type.ts +15 -0
  125. package/tsconfig.build.json +11 -0
  126. package/tsconfig.json +10 -0
  127. package/writable/.gitkeep +0 -0
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.LoggerTransport = void 0;
7
+ const telemetry_kit_1 = require("@privateaim/telemetry-kit");
8
+ const winston_transport_1 = __importDefault(require("winston-transport"));
9
+ class LoggerTransport extends winston_transport_1.default {
10
+ labels;
11
+ save;
12
+ constructor(options) {
13
+ super(options);
14
+ this.labels = options.labels || {};
15
+ this.save = options.save;
16
+ }
17
+ log(info, next) {
18
+ const payload = this.normalizeInput(info);
19
+ Promise.resolve()
20
+ .then(() => this.save(payload))
21
+ .then(() => next());
22
+ }
23
+ normalizeInput(info) {
24
+ const { message, timestamp, stack, ...data } = info;
25
+ let date;
26
+ if (typeof timestamp === 'string') {
27
+ date = new Date(`${timestamp}`);
28
+ }
29
+ else {
30
+ date = new Date();
31
+ }
32
+ const output = {
33
+ message: stack || message,
34
+ time: (BigInt(date.getTime()) * 1000000n).toString(),
35
+ labels: { ...this.labels },
36
+ level: telemetry_kit_1.LogLevel.DEBUG,
37
+ service: 'unknown',
38
+ channel: telemetry_kit_1.LogChannel.SYSTEM,
39
+ };
40
+ const flags = Object.values(telemetry_kit_1.LogFlag);
41
+ let keys = Object.keys(output.labels);
42
+ for (let i = 0; i < keys.length; i++) {
43
+ const index = flags.indexOf(keys[i]);
44
+ if (index !== -1) {
45
+ output[keys[i]] = output.labels[keys[i]];
46
+ delete output.labels[keys[i]];
47
+ }
48
+ }
49
+ keys = Object.keys(data);
50
+ for (let i = 0; i < keys.length; i++) {
51
+ if (typeof keys[i] !== 'string') {
52
+ continue;
53
+ }
54
+ const value = data[keys[i]];
55
+ if (typeof value !== 'string' &&
56
+ typeof value !== 'number' &&
57
+ typeof value !== 'boolean') {
58
+ continue;
59
+ }
60
+ const index = flags.indexOf(keys[i]);
61
+ if (index === -1) {
62
+ output.labels[keys[i]] = `${value}`;
63
+ }
64
+ else {
65
+ output[keys[i]] = `${value}`;
66
+ }
67
+ }
68
+ return output;
69
+ }
70
+ }
71
+ exports.LoggerTransport = LoggerTransport;
72
+ //# sourceMappingURL=transport.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transport.js","sourceRoot":"","sources":["../../../src/services/logger/transport.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,8 @@
1
+ import type { TransportStreamOptions } from 'winston-transport';
2
+ import type { LogInput } from '@privateaim/telemetry-kit';
3
+ export type LoggerTransportSaveFn = (value: LogInput) => Promise<void> | void;
4
+ export type LoggerTransportOptions = TransportStreamOptions & {
5
+ labels?: Record<string, string>;
6
+ save: LoggerTransportSaveFn;
7
+ };
8
+ //# sourceMappingURL=type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../../src/services/logger/type.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAChE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAE1D,MAAM,MAAM,qBAAqB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC;AAC9E,MAAM,MAAM,sBAAsB,GAAG,sBAAsB,GAAG;IAC1D,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAChC,IAAI,EAAE,qBAAqB,CAAA;CAC9B,CAAC"}
@@ -0,0 +1,9 @@
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
+ //# sourceMappingURL=type.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type.js","sourceRoot":"","sources":["../../../src/services/logger/type.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@privateaim/server-telemetry-kit",
3
+ "version": "0.8.16",
4
+ "main": "dist/index.js",
5
+ "types": "dist/index.d.ts",
6
+ "author": {
7
+ "name": "Peter Placzek",
8
+ "email": "contact@tada5hi.net",
9
+ "url": "https://tada5hi.net"
10
+ },
11
+ "license": "Apache-2.0",
12
+ "description": "This package contains server side db helpers & utilities.",
13
+ "dependencies": {
14
+ "winston-transport": "^4.9.0"
15
+ },
16
+ "devDependencies": {
17
+ "@privateaim/server-kit": "^0.8.16",
18
+ "@privateaim/telemetry-kit": "^0.8.16",
19
+ "singa": "^1.1.0"
20
+ },
21
+ "peerDependencies": {
22
+ "@privateaim/server-kit": "^0.8.16",
23
+ "@privateaim/telemetry-kit": "^0.8.16",
24
+ "singa": "^1.1.0"
25
+ },
26
+ "scripts": {
27
+ "build": "rimraf dist && tsc -p tsconfig.build.json"
28
+ }
29
+ }
@@ -0,0 +1,30 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
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 { QueueRouterRoutingType } from '@privateaim/server-kit';
9
+
10
+ export enum EventEvent {
11
+ STARTING = 'starting',
12
+ STARTED = 'started',
13
+ FINISHED = 'finished',
14
+ FAILED = 'failed',
15
+ }
16
+
17
+ export enum EventCommand {
18
+ CREATE = 'create',
19
+ CLEAN = 'clean',
20
+ }
21
+
22
+ export const EventEventQueueRouterRouting = {
23
+ type: QueueRouterRoutingType.PUB_SUB,
24
+ key: 'telemetryEventEvents',
25
+ };
26
+
27
+ export const EventTaskQueueRouterRouting = {
28
+ type: QueueRouterRoutingType.WORK,
29
+ key: 'telemetryEventTasks',
30
+ };
@@ -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 './types';
@@ -0,0 +1,20 @@
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 type EventCreateCommandPayload = {
9
+ [key: string]: any,
10
+ // todo: domain type of event :)
11
+ };
12
+
13
+ export type EventCreateFailedEventPayload = {
14
+ id: string,
15
+ error: Error
16
+ };
17
+
18
+ export type EventCreateEventPayload = {
19
+ [key: string]: any,
20
+ };
@@ -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 './create';
@@ -0,0 +1,10 @@
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 './handlers';
9
+ export * from './constants';
10
+ export * from './types';
@@ -0,0 +1,50 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
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 type { EventCommand, EventEvent } from './constants';
9
+ import type {
10
+ EventCreateCommandPayload,
11
+ EventCreateEventPayload,
12
+ EventCreateFailedEventPayload,
13
+ } from './handlers';
14
+
15
+ //-----------------------------------------------------------------------
16
+
17
+ type TelemetryEventCommandMapRaw = {
18
+ [EventCommand.CREATE]: EventCreateCommandPayload,
19
+ [EventCommand.CLEAN]: EventCreateCommandPayload,
20
+ };
21
+
22
+ export type EventCommandMap = {
23
+ [K in keyof TelemetryEventCommandMapRaw as `${K}`]: TelemetryEventCommandMapRaw[K]
24
+ };
25
+
26
+ export type EventCommandContext = {
27
+ [K in keyof EventCommandMap]: {
28
+ command: K,
29
+ data: EventCommandMap[K]
30
+ }
31
+ }[keyof EventCommandMap];
32
+
33
+ //-----------------------------------------------------------------------
34
+
35
+ type EventEventMapRaw = {
36
+ [EventEvent.STARTING]: EventCreateEventPayload,
37
+ [EventEvent.STARTED]: EventCreateEventPayload,
38
+ [EventEvent.FAILED]: EventCreateFailedEventPayload,
39
+ };
40
+
41
+ export type EventEventMap = {
42
+ [K in keyof EventEventMapRaw as `${K}`]: EventEventMapRaw[K]
43
+ };
44
+
45
+ export type EventEventContext = {
46
+ [K in keyof EventEventMap]: {
47
+ event: K,
48
+ data: EventEventMap[K]
49
+ }
50
+ }[keyof EventEventMap];
@@ -0,0 +1,9 @@
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';
9
+ export * from './log';
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
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 { QueueRouterRoutingType } from '@privateaim/server-kit';
9
+
10
+ export enum LogEvent {
11
+ STARTING = 'starting',
12
+ STARTED = 'started',
13
+ FINISHED = 'finished',
14
+ FAILED = 'failed',
15
+ }
16
+
17
+ export enum LogCommand {
18
+ WRITE = 'write',
19
+ }
20
+
21
+ export const LogEventQueueRouterRouting = {
22
+ type: QueueRouterRoutingType.PUB_SUB,
23
+ key: 'telemetryLogEvents',
24
+ };
25
+
26
+ export const LogTaskQueueRouterRouting = {
27
+ type: QueueRouterRoutingType.WORK,
28
+ key: 'telemetryLogTasks',
29
+ };
@@ -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 './write';
@@ -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 './types';
@@ -0,0 +1,10 @@
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 type { Log } from '@privateaim/telemetry-kit';
9
+
10
+ export type LogWriteCommandPayload = Partial<Log>;
@@ -0,0 +1,10 @@
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 './handlers';
9
+ export * from './constants';
10
+ export * from './types';
@@ -0,0 +1,45 @@
1
+ /*
2
+ * Copyright (c) 2023-2024.
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 type { LogCommand } from './constants';
9
+ import type {
10
+ LogWriteCommandPayload,
11
+ } from './handlers';
12
+
13
+ //-----------------------------------------------------------------------
14
+
15
+ type LogCommandMapRaw = {
16
+ [LogCommand.WRITE]: LogWriteCommandPayload,
17
+ };
18
+
19
+ export type LogCommandMap = {
20
+ [K in keyof LogCommandMapRaw as `${K}`]: LogCommandMapRaw[K]
21
+ };
22
+
23
+ export type LogCommandContext = {
24
+ [K in keyof LogCommandMap]: {
25
+ command: K,
26
+ data: LogCommandMap[K]
27
+ }
28
+ }[keyof LogCommandMap];
29
+
30
+ //-----------------------------------------------------------------------
31
+
32
+ type LogEventMapRaw = {
33
+ [key: string]: any
34
+ };
35
+
36
+ export type LogEventMap = {
37
+ [K in keyof LogEventMapRaw as `${K}`]: LogEventMapRaw[K]
38
+ };
39
+
40
+ export type LogEventContext = {
41
+ [K in keyof LogEventMap]: {
42
+ event: K,
43
+ data: LogEventMap[K]
44
+ }
45
+ }[keyof LogEventMap];
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
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 './components';
9
+ export * from './services';
@@ -0,0 +1,9 @@
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 './module';
9
+ export * from './singleton';
@@ -0,0 +1,56 @@
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 { buildQueueRouterPublishPayload, isQueueRouterUsable, useQueueRouter } from '@privateaim/server-kit';
9
+ import type { EventCommandContext, EventEventContext } from '../../components';
10
+ import { EventEventQueueRouterRouting, EventTaskQueueRouterRouting } from '../../components';
11
+
12
+ export class EventComponentService {
13
+ async command(ctx: EventCommandContext) {
14
+ if (isQueueRouterUsable()) {
15
+ const queueRouter = useQueueRouter();
16
+
17
+ const queueRouterPayload = buildQueueRouterPublishPayload({
18
+ type: ctx.command,
19
+ data: ctx.data,
20
+ metadata: {
21
+ routing: EventTaskQueueRouterRouting,
22
+ },
23
+ });
24
+
25
+ await queueRouter.publish(queueRouterPayload);
26
+
27
+ return;
28
+ }
29
+
30
+ throw new Error(`Event command ${ctx.command} can not be executed.`);
31
+
32
+ // todo: execute component directly
33
+ }
34
+
35
+ async event(ctx: EventEventContext) {
36
+ if (isQueueRouterUsable()) {
37
+ const queueRouter = useQueueRouter();
38
+
39
+ const queueRouterPayload = buildQueueRouterPublishPayload({
40
+ type: ctx.event,
41
+ data: ctx.data,
42
+ metadata: {
43
+ routing: EventEventQueueRouterRouting,
44
+ },
45
+ });
46
+
47
+ await queueRouter.publish(queueRouterPayload);
48
+
49
+ return;
50
+ }
51
+
52
+ throw new Error(`Event event ${ctx.event} can not be transmitted.`);
53
+
54
+ // todo: execute component directly
55
+ }
56
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2024.
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 { singa } from 'singa';
9
+ import { isQueueRouterUsable } from '@privateaim/server-kit';
10
+ import { EventComponentService } from './module';
11
+
12
+ const instance = singa<EventComponentService>({
13
+ name: 'eventComponentService',
14
+ factory: () => new EventComponentService(),
15
+ });
16
+
17
+ export function isEventComponentServiceUsable() {
18
+ return isQueueRouterUsable();
19
+ }
20
+
21
+ export function useEventComponentService(): EventComponentService {
22
+ return instance.use();
23
+ }
@@ -0,0 +1,10 @@
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';
9
+ export * from './log';
10
+ export * from './logger';
@@ -0,0 +1,9 @@
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 './module';
9
+ export * from './singleton';
@@ -0,0 +1,60 @@
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 { buildQueueRouterPublishPayload, isQueueRouterUsable, useQueueRouter } from '@privateaim/server-kit';
9
+ import { LogEventQueueRouterRouting, LogTaskQueueRouterRouting } from '../../components';
10
+ import type { LogCommandContext, LogEventContext } from '../../components';
11
+
12
+ export class LogComponentService {
13
+ async command(ctx: LogCommandContext) {
14
+ if (isQueueRouterUsable()) {
15
+ const queueRouter = useQueueRouter();
16
+
17
+ const queueRouterPayload = buildQueueRouterPublishPayload({
18
+ type: ctx.command,
19
+ data: ctx.data,
20
+ metadata: {
21
+ routing: LogTaskQueueRouterRouting,
22
+ },
23
+ });
24
+
25
+ await queueRouter.publish(queueRouterPayload, {
26
+ logging: false,
27
+ });
28
+
29
+ return;
30
+ }
31
+
32
+ // todo: use http api client if possible
33
+
34
+ throw new Error(`Log command ${ctx.command} can not be executed.`);
35
+
36
+ // todo: execute component directly
37
+ }
38
+
39
+ async event(ctx: LogEventContext) {
40
+ if (isQueueRouterUsable()) {
41
+ const queueRouter = useQueueRouter();
42
+
43
+ const queueRouterPayload = buildQueueRouterPublishPayload({
44
+ type: ctx.event,
45
+ data: ctx.data,
46
+ metadata: {
47
+ routing: LogEventQueueRouterRouting,
48
+ },
49
+ });
50
+
51
+ await queueRouter.publish(queueRouterPayload);
52
+
53
+ return;
54
+ }
55
+
56
+ throw new Error(`Log event ${ctx.event} can not be transmitted.`);
57
+
58
+ // todo: execute component directly
59
+ }
60
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2024.
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 { singa } from 'singa';
9
+ import { isQueueRouterUsable } from '@privateaim/server-kit';
10
+ import { LogComponentService } from './module';
11
+
12
+ const instance = singa<LogComponentService>({
13
+ name: 'logComponentService',
14
+ factory: () => new LogComponentService(),
15
+ });
16
+
17
+ export function isLogComponentServiceUsable() {
18
+ return isQueueRouterUsable();
19
+ }
20
+
21
+ export function useLogComponentService(): LogComponentService {
22
+ return instance.use();
23
+ }
@@ -0,0 +1,9 @@
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 './type';
9
+ export * from './transport';