@privateaim/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 (67) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE +202 -0
  3. package/dist/domains/base.d.ts +8 -0
  4. package/dist/domains/base.d.ts.map +1 -0
  5. package/dist/domains/constants.d.ts +5 -0
  6. package/dist/domains/constants.d.ts.map +1 -0
  7. package/dist/domains/event/api.d.ts +12 -0
  8. package/dist/domains/event/api.d.ts.map +1 -0
  9. package/dist/domains/event/entity.d.ts +50 -0
  10. package/dist/domains/event/entity.d.ts.map +1 -0
  11. package/dist/domains/event/index.d.ts +4 -0
  12. package/dist/domains/event/index.d.ts.map +1 -0
  13. package/dist/domains/event/validator.d.ts +6 -0
  14. package/dist/domains/event/validator.d.ts.map +1 -0
  15. package/dist/domains/index.d.ts +5 -0
  16. package/dist/domains/index.d.ts.map +1 -0
  17. package/dist/domains/log/api.d.ts +10 -0
  18. package/dist/domains/log/api.d.ts.map +1 -0
  19. package/dist/domains/log/constants.d.ts +65 -0
  20. package/dist/domains/log/constants.d.ts.map +1 -0
  21. package/dist/domains/log/entity.d.ts +31 -0
  22. package/dist/domains/log/entity.d.ts.map +1 -0
  23. package/dist/domains/log/helpers.d.ts +3 -0
  24. package/dist/domains/log/helpers.d.ts.map +1 -0
  25. package/dist/domains/log/index.d.ts +6 -0
  26. package/dist/domains/log/index.d.ts.map +1 -0
  27. package/dist/domains/log/validator.d.ts +6 -0
  28. package/dist/domains/log/validator.d.ts.map +1 -0
  29. package/dist/domains/types-base.d.ts +14 -0
  30. package/dist/domains/types-base.d.ts.map +1 -0
  31. package/dist/domains/types.d.ts +12 -0
  32. package/dist/domains/types.d.ts.map +1 -0
  33. package/dist/http/api-client/index.d.ts +2 -0
  34. package/dist/http/api-client/index.d.ts.map +1 -0
  35. package/dist/http/api-client/module.d.ts +9 -0
  36. package/dist/http/api-client/module.d.ts.map +1 -0
  37. package/dist/http/index.d.ts +2 -0
  38. package/dist/http/index.d.ts.map +1 -0
  39. package/dist/index.cjs +414 -0
  40. package/dist/index.cjs.map +1 -0
  41. package/dist/index.d.ts +3 -0
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.mjs +402 -0
  44. package/dist/index.mjs.map +1 -0
  45. package/package.json +51 -0
  46. package/rollup.config.mjs +19 -0
  47. package/src/domains/base.ts +30 -0
  48. package/src/domains/constants.ts +11 -0
  49. package/src/domains/event/api.ts +43 -0
  50. package/src/domains/event/entity.ts +85 -0
  51. package/src/domains/event/index.ts +10 -0
  52. package/src/domains/event/validator.ts +148 -0
  53. package/src/domains/index.ts +12 -0
  54. package/src/domains/log/api.ts +29 -0
  55. package/src/domains/log/constants.ts +84 -0
  56. package/src/domains/log/entity.ts +44 -0
  57. package/src/domains/log/helpers.ts +17 -0
  58. package/src/domains/log/index.ts +12 -0
  59. package/src/domains/log/validator.ts +79 -0
  60. package/src/domains/types-base.ts +22 -0
  61. package/src/domains/types.ts +19 -0
  62. package/src/http/api-client/index.ts +8 -0
  63. package/src/http/api-client/module.ts +39 -0
  64. package/src/http/index.ts +8 -0
  65. package/src/index.ts +9 -0
  66. package/tsconfig.build.json +11 -0
  67. package/tsconfig.json +8 -0
@@ -0,0 +1,85 @@
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
+ // todo: add service, trace ?
9
+
10
+ import type { Realm } from '@authup/core-kit';
11
+ import type { ObjectDiff } from '@privateaim/kit';
12
+
13
+ export type EventData = {
14
+ diff?: ObjectDiff,
15
+ [key: string]: any
16
+ };
17
+
18
+ export interface Event {
19
+ id: string;
20
+
21
+ /**
22
+ * domaine
23
+ *
24
+ * eg. analysis, node, analysisNode, ....
25
+ */
26
+ ref_type: string;
27
+
28
+ /**
29
+ * eg. uuid
30
+ */
31
+ ref_id: string | null;
32
+
33
+ /**
34
+ * component, prozess,
35
+ *
36
+ * eg. build, push, modelChanges, ...
37
+ */
38
+ scope: string;
39
+
40
+ /**
41
+ * eg. started, starting, finished, ...
42
+ */
43
+ name: string;
44
+
45
+ /**
46
+ *
47
+ * { diff: { description: { next: "xxx", previous: "yyy" }, name {}}}
48
+ */
49
+ data: Record<string, any>;
50
+
51
+ /**
52
+ * default: false
53
+ */
54
+ expiring: boolean;
55
+
56
+ // ------------------------------------------------------------------
57
+
58
+ request_path: string | null;
59
+
60
+ request_method: string | null;
61
+
62
+ request_ip_address: string | null;
63
+
64
+ request_user_agent: string | null;
65
+
66
+ // ------------------------------------------------------------------
67
+
68
+ actor_type: string | null;
69
+
70
+ actor_id: string | null;
71
+
72
+ actor_name: string | null;
73
+
74
+ // ------------------------------------------------------------------
75
+
76
+ realm_id: Realm['id'] | null;
77
+
78
+ // ------------------------------------------------------------------
79
+
80
+ expires_at: string | null;
81
+
82
+ created_at: string;
83
+
84
+ updated_at: string;
85
+ }
@@ -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 './api';
9
+ export * from './entity';
10
+ export * from './validator';
@@ -0,0 +1,148 @@
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 { createValidator } from '@validup/adapter-zod';
9
+ import { Container } from 'validup';
10
+ import zod from 'zod';
11
+ import type { Event } from './entity';
12
+
13
+ export class EventValidator extends Container<Event> {
14
+ protected initialize() {
15
+ super.initialize();
16
+
17
+ this.mount(
18
+ 'ref_type',
19
+ createValidator(
20
+ zod
21
+ .string()
22
+ .min(3)
23
+ .max(128),
24
+ ),
25
+ );
26
+
27
+ this.mount(
28
+ 'ref_id',
29
+ { optional: true },
30
+ createValidator(
31
+ zod
32
+ .uuidv4()
33
+ .nullable(),
34
+ ),
35
+ );
36
+
37
+ // ----------------------------------------------
38
+
39
+ this.mount(
40
+ 'scope',
41
+ createValidator(
42
+ zod
43
+ .string()
44
+ .min(3)
45
+ .max(128),
46
+ ),
47
+ );
48
+
49
+ this.mount(
50
+ 'name',
51
+ createValidator(
52
+ zod
53
+ .string()
54
+ .min(3)
55
+ .max(128),
56
+ ),
57
+ );
58
+
59
+ // ----------------------------------------------
60
+
61
+ this.mount(
62
+ 'data',
63
+ { optional: true },
64
+ createValidator(
65
+ zod
66
+ .record(zod.string(), zod.any())
67
+ .nullable(),
68
+ ),
69
+ );
70
+
71
+ // ----------------------------------------------
72
+
73
+ this.mount(
74
+ 'expiring',
75
+ { optional: true },
76
+ createValidator(
77
+ zod
78
+ .boolean()
79
+ .nullable(),
80
+ ),
81
+ );
82
+
83
+ // ----------------------------------------------
84
+
85
+ this.mount(
86
+ 'request_path',
87
+ { optional: true },
88
+ createValidator(zod.string().min(3).max(256).nullable()),
89
+ );
90
+
91
+ this.mount(
92
+ 'request_method',
93
+ { optional: true },
94
+ createValidator(zod.string().min(3).max(10).nullable()),
95
+ );
96
+
97
+ this.mount(
98
+ 'request_ip_address',
99
+ { optional: true },
100
+ createValidator(zod.ipv4().nullable()),
101
+ );
102
+
103
+ this.mount(
104
+ 'request_user_agent',
105
+ { optional: true },
106
+ createValidator(zod.string().min(3).max(512).nullable()),
107
+ );
108
+
109
+ // ----------------------------------------------
110
+
111
+ this.mount(
112
+ 'actor_type',
113
+ { optional: true },
114
+ createValidator(zod.string().min(3).max(64).nullable()),
115
+ );
116
+
117
+ this.mount(
118
+ 'actor_id',
119
+ { optional: true },
120
+ createValidator(zod.uuidv4().nullable()),
121
+ );
122
+
123
+ this.mount(
124
+ 'actor_name',
125
+ { optional: true },
126
+ createValidator(zod.string().min(3).max(64).nullable()),
127
+ );
128
+
129
+ // ----------------------------------------------
130
+
131
+ this.mount(
132
+ 'realm_id',
133
+ { optional: true },
134
+ createValidator(zod.uuidv4().nullable()),
135
+ );
136
+
137
+ // ----------------------------------------------
138
+
139
+ this.mount(
140
+ 'expires_at',
141
+ { optional: true },
142
+ createValidator(
143
+ zod.iso.datetime()
144
+ .nullable(),
145
+ ),
146
+ );
147
+ }
148
+ }
@@ -0,0 +1,12 @@
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
+ export * from './event';
9
+ export * from './log';
10
+
11
+ export * from './constants';
12
+ export * from './types';
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2021-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 { BuildInput } from 'rapiq';
9
+ import { buildQuery } from 'rapiq';
10
+ import type { Log, LogInput } from './entity';
11
+ import type { CollectionResourceResponse, SingleResourceResponse } from '../types-base';
12
+ import { BaseAPI } from '../base';
13
+
14
+ export class LogAPI extends BaseAPI {
15
+ async getMany(options?: BuildInput<Log>): Promise<CollectionResourceResponse<Log>> {
16
+ const { data: response } = await this.client.get(`logs${buildQuery(options)}`);
17
+ return response;
18
+ }
19
+
20
+ async deleteMany(options?: BuildInput<Log>): Promise<void> {
21
+ await this.client.delete(`logs${buildQuery(options)}`);
22
+ }
23
+
24
+ async create(data: Partial<LogInput>): Promise<SingleResourceResponse<Log>> {
25
+ const { data: response } = await this.client.post('logs', data);
26
+
27
+ return response;
28
+ }
29
+ }
@@ -0,0 +1,84 @@
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 enum LogLevel {
9
+ /**
10
+ * indicates that the system is unusable
11
+ * and requires immediate attention
12
+ */
13
+ EMERGENCE = 'emerg',
14
+
15
+ /**
16
+ * indicates that immediate action is necessary
17
+ * to resolve a critical issue.
18
+ */
19
+ ALERT = 'alert',
20
+
21
+ /**
22
+ * signifies critical conditions in the program that demand
23
+ * intervention to prevent system failure.
24
+ */
25
+ CRITICAL = 'crit',
26
+
27
+ /**
28
+ * indicates error conditions that impair
29
+ * some operation but are less severe than critical situations.
30
+ */
31
+ ERROR = 'error',
32
+
33
+ /**
34
+ * signifies potential issues that may lead to errors
35
+ * or unexpected behavior in the future if not addressed.
36
+ */
37
+ WARNING = 'warn',
38
+
39
+ /**
40
+ * applies to normal but significant
41
+ * conditions that may require monitoring
42
+ */
43
+ NOTICE = 'notice',
44
+
45
+ /**
46
+ * includes messages that provide a record
47
+ * of the normal operation of the system.
48
+ */
49
+ INFORMATIONAL = 'info',
50
+
51
+ /**
52
+ * intended for logging detailed information about the system
53
+ * for debugging purposes.
54
+ */
55
+ DEBUG = 'debug',
56
+ }
57
+
58
+ export enum LogLevelColor {
59
+ EMERGENCE = '#8B0000',
60
+ ALERT = '#FF0000',
61
+ CRITICAL = '#FF4500',
62
+ ERROR = '#FF6347',
63
+ WARNING = '#FFD700',
64
+ NOTICE = '#1E90FF',
65
+ INFORMATIONAL = '#228B22',
66
+ DEBUG = '#A9A9A9',
67
+ }
68
+
69
+ export enum LogFlag {
70
+ CHANNEL = 'channel',
71
+
72
+ COMPONENT = 'component',
73
+
74
+ SERVICE = 'service',
75
+
76
+ LEVEL = 'level',
77
+ }
78
+
79
+ export enum LogChannel {
80
+ HTTP = 'http',
81
+ WEBSOCKET = 'websocket',
82
+ BACKGROUND = 'background',
83
+ SYSTEM = 'system',
84
+ }
@@ -0,0 +1,44 @@
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 { LogChannel, LogLevel } from './constants';
9
+
10
+ export interface Log {
11
+ /**
12
+ * Time in micro seconds
13
+ */
14
+ time: string | bigint,
15
+
16
+ /**
17
+ * message
18
+ */
19
+ message: string,
20
+
21
+ /**
22
+ * level
23
+ */
24
+ level: `${LogLevel}`,
25
+
26
+ /**
27
+ * service
28
+ */
29
+ service: string,
30
+
31
+ /**
32
+ * channel
33
+ */
34
+ channel: `${LogChannel}`,
35
+
36
+ /**
37
+ * additional labels
38
+ */
39
+ labels: Record<string, string>
40
+ }
41
+
42
+ type RequiredTypes = ('message' | 'level' | 'service' | 'channel');
43
+
44
+ export type LogInput = Pick<Log, RequiredTypes & keyof Log> & Partial<Omit<Log, RequiredTypes & keyof Log>>;
@@ -0,0 +1,17 @@
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 { nanoSeconds } from '@privateaim/kit';
9
+ import type { Log, LogInput } from './entity';
10
+
11
+ export function normalizeLogInput(input: LogInput) : Log {
12
+ return {
13
+ ...input,
14
+ time: input.time || nanoSeconds(),
15
+ labels: input.labels || {},
16
+ };
17
+ }
@@ -0,0 +1,12 @@
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 './api';
9
+ export * from './constants';
10
+ export * from './entity';
11
+ export * from './helpers';
12
+ export * from './validator';
@@ -0,0 +1,79 @@
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 { createValidator } from '@validup/adapter-zod';
9
+ import { Container } from 'validup';
10
+ import zod from 'zod';
11
+ import { LogChannel, LogLevel } from './constants';
12
+ import type { LogInput } from './entity';
13
+
14
+ export class LogValidator extends Container<LogInput> {
15
+ protected initialize() {
16
+ super.initialize();
17
+
18
+ this.mount(
19
+ 'time',
20
+ { optional: true },
21
+ createValidator(
22
+ zod
23
+ .string()
24
+ .min(0)
25
+ .max(20)
26
+ .or(zod.bigint())
27
+ .optional(),
28
+ ),
29
+ );
30
+
31
+ this.mount(
32
+ 'message',
33
+ createValidator(
34
+ zod
35
+ .string()
36
+ .min(3)
37
+ .max(512),
38
+ ),
39
+ );
40
+
41
+ this.mount(
42
+ 'service',
43
+ createValidator(
44
+ zod
45
+ .string()
46
+ .min(3)
47
+ .max(64),
48
+ ),
49
+ );
50
+
51
+ // ----------------------------------------------
52
+
53
+ this.mount(
54
+ 'level',
55
+ createValidator(
56
+ zod
57
+ .enum(Object.values(LogLevel)),
58
+ ),
59
+ );
60
+
61
+ this.mount(
62
+ 'channel',
63
+ createValidator(
64
+ zod
65
+ .enum(Object.values(LogChannel)),
66
+ ),
67
+ );
68
+
69
+ this.mount(
70
+ 'labels',
71
+ { optional: true },
72
+ createValidator(
73
+ zod
74
+ .record(zod.string(), zod.string())
75
+ .nullable(),
76
+ ),
77
+ );
78
+ }
79
+ }
@@ -0,0 +1,22 @@
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 type { Client, RequestBaseOptions } from 'hapic';
9
+
10
+ export type SingleResourceResponse<R> = R;
11
+ export type CollectionResourceResponse<R> = {
12
+ data: R[],
13
+ meta: {
14
+ limit: number,
15
+ offset: number,
16
+ total: number
17
+ }
18
+ };
19
+
20
+ export type BaseAPIContext = {
21
+ client?: Client | RequestBaseOptions
22
+ };
@@ -0,0 +1,19 @@
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 { DomainType } from './constants';
9
+ import type { Event } from './event';
10
+ import type { Log } from './log';
11
+
12
+ type DomainTypeMapRaw = {
13
+ [DomainType.EVENT]: Event,
14
+ [DomainType.LOG]: Log,
15
+ };
16
+
17
+ export type DomainTypeMap = {
18
+ [K in keyof DomainTypeMapRaw as `${K}`]: DomainTypeMapRaw[K]
19
+ };
@@ -0,0 +1,8 @@
1
+ /*
2
+ * Copyright (c) 2022-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
+ export * from './module';
@@ -0,0 +1,39 @@
1
+ /*
2
+ * Copyright (c) 2022-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 { RequestBaseOptions } from 'hapic';
9
+ import { Client, HookName, isClientError } from 'hapic';
10
+ import {
11
+ EventAPI,
12
+ LogAPI,
13
+ } from '../../domains';
14
+
15
+ export class APIClient extends Client {
16
+ public readonly event : EventAPI;
17
+
18
+ public readonly log : LogAPI;
19
+
20
+ constructor(config: RequestBaseOptions) {
21
+ super(config);
22
+
23
+ this.event = new EventAPI({ client: this });
24
+ this.log = new LogAPI({ client: this });
25
+
26
+ this.on(HookName.RESPONSE_ERROR, ((error) => {
27
+ if (
28
+ isClientError(error) &&
29
+ error.response &&
30
+ error.response.data &&
31
+ typeof error.response.data.message === 'string'
32
+ ) {
33
+ error.message = error.response.data.message;
34
+ }
35
+
36
+ throw error;
37
+ }));
38
+ }
39
+ }
@@ -0,0 +1,8 @@
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
+ export * from './api-client';
package/src/index.ts ADDED
@@ -0,0 +1,9 @@
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
+ export * from './http';
9
+ export * from './domains';
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "../../tsconfig.build.json",
3
+
4
+ "compilerOptions": {
5
+ "outDir": "./dist"
6
+ },
7
+
8
+ "include": [
9
+ "src/**/*.ts"
10
+ ]
11
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,8 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "paths": {
5
+ "@privateaim/kit": ["./packages/kit/src"]
6
+ }
7
+ }
8
+ }