@tstdl/base 0.93.37 → 0.93.39

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.
@@ -35,7 +35,7 @@ export class RequestDetails {
35
35
  sessionId;
36
36
  }
37
37
  __decorate([
38
- StringProperty(),
38
+ StringProperty({ nullable: true }),
39
39
  __metadata("design:type", Object)
40
40
  ], RequestDetails.prototype, "path", void 0);
41
41
  __decorate([
@@ -179,7 +179,7 @@ __decorate([
179
179
  __metadata("design:type", String)
180
180
  ], AuditEvent.prototype, "actorType", void 0);
181
181
  __decorate([
182
- StringProperty(),
182
+ StringProperty({ nullable: true }),
183
183
  __metadata("design:type", Object)
184
184
  ], AuditEvent.prototype, "actor", void 0);
185
185
  __decorate([
@@ -98,7 +98,7 @@ export declare class Auditor<Events extends AuditEvents = Record<never, never>>
98
98
  * @param action The name of the action being logged.
99
99
  * @param data The payload containing details about the event.
100
100
  */
101
- info<const E extends Extract<keyof Events, string>>(action: E, data: AuditPayload<Events[E]>): Promise<void>;
101
+ info<const E extends Extract<keyof Events, string>>(action: E, data?: AuditPayload<Events[E]>): Promise<void>;
102
102
  /**
103
103
  * Logs a warning event.
104
104
  * Automatically sets severity to `Warn` and defaults outcome to `Failure`.
@@ -106,7 +106,7 @@ export declare class Auditor<Events extends AuditEvents = Record<never, never>>
106
106
  * @param action The name of the action being logged.
107
107
  * @param data The payload containing details about the event.
108
108
  */
109
- warn<const E extends Extract<keyof Events, string>>(action: E, data: AuditPayload<Events[E]>): Promise<void>;
109
+ warn<const E extends Extract<keyof Events, string>>(action: E, data?: AuditPayload<Events[E]>): Promise<void>;
110
110
  /**
111
111
  * Logs an error event.
112
112
  * Automatically sets severity to `Error` and defaults outcome to `Failure`.
@@ -114,7 +114,7 @@ export declare class Auditor<Events extends AuditEvents = Record<never, never>>
114
114
  * @param action The name of the action being logged.
115
115
  * @param data The payload containing details about the event.
116
116
  */
117
- error<const E extends Extract<keyof Events, string>>(action: E, data: AuditPayload<Events[E]>): Promise<void>;
117
+ error<const E extends Extract<keyof Events, string>>(action: E, data?: AuditPayload<Events[E]>): Promise<void>;
118
118
  /**
119
119
  * Logs a critical event.
120
120
  * Automatically sets severity to `Critical` and defaults outcome to `Failure`.
@@ -122,6 +122,6 @@ export declare class Auditor<Events extends AuditEvents = Record<never, never>>
122
122
  * @param action The name of the action being logged.
123
123
  * @param data The payload containing details about the event.
124
124
  */
125
- critical<const E extends Extract<keyof Events, string>>(action: E, data: AuditPayload<Events[E]>): Promise<void>;
125
+ critical<const E extends Extract<keyof Events, string>>(action: E, data?: AuditPayload<Events[E]>): Promise<void>;
126
126
  }
127
127
  export {};
package/audit/auditor.js CHANGED
@@ -16,10 +16,10 @@ import { DatabaseConfig, EntityRepositoryConfig, injectRepository, isInTransacti
16
16
  import { toArray } from '../utils/array/index.js';
17
17
  import { Memoize } from '../utils/function/memoize.js';
18
18
  import { filterNullishFromRecord, filterUndefinedFromRecord, objectKeys } from '../utils/object/object.js';
19
- import { assertDefinedPass, isArray, isNotArray, isObject, isString } from '../utils/type-guards.js';
19
+ import { assertDefinedPass, assertNotNullOrUndefined, isArray, isNotArray, isObject, isString } from '../utils/type-guards.js';
20
20
  import { AuditEvent } from './audit.model.js';
21
21
  import { AuditModuleConfig } from './module.js';
22
- import { AuditOutcome, AuditSeverity } from './types.js';
22
+ import { ActorType, AuditOutcome, AuditSeverity } from './types.js';
23
23
  const { runInAuditorCreationContext, getCurrentAuditorCreationContext, isInAuditorCreationContext } = createContextProvider('AuditorCreation');
24
24
  const severityLogLevelMap = {
25
25
  [AuditSeverity.Info]: 'info',
@@ -140,6 +140,9 @@ let Auditor = Auditor_1 = class Auditor {
140
140
  details,
141
141
  });
142
142
  this.#logger[severityLogLevelMap[severity]](logMessage, logContext);
143
+ if ((mergedData.actorType != ActorType.Anonymous) && (mergedData.actorType != ActorType.System)) {
144
+ assertNotNullOrUndefined(mergedData.actor, 'Audit actor is required for non-anonymous/system actors.');
145
+ }
143
146
  await this.#repository.insert({
144
147
  timestamp: TRANSACTION_TIMESTAMP,
145
148
  tenantId: mergedData.tenantId ?? null,
@@ -149,7 +152,7 @@ let Auditor = Auditor_1 = class Auditor {
149
152
  outcome,
150
153
  severity,
151
154
  actorType: assertDefinedPass(mergedData.actorType, 'Audit actorType is required'),
152
- actor: assertDefinedPass(mergedData.actor, 'Audit actor is required'),
155
+ actor: mergedData.actor ?? null,
153
156
  impersonatorType: mergedData.impersonatorType ?? null,
154
157
  impersonator: mergedData.impersonator ?? null,
155
158
  targetType: assertDefinedPass(mergedData.targetType, 'Audit targetType is required'),
@@ -178,7 +181,7 @@ let Auditor = Auditor_1 = class Auditor {
178
181
  await this.log(action, {
179
182
  ...data,
180
183
  severity: AuditSeverity.Info,
181
- outcome: data.outcome ?? AuditOutcome.Success,
184
+ outcome: data?.outcome ?? AuditOutcome.Success,
182
185
  });
183
186
  }
184
187
  /**
@@ -192,7 +195,7 @@ let Auditor = Auditor_1 = class Auditor {
192
195
  await this.log(action, {
193
196
  ...data,
194
197
  severity: AuditSeverity.Warn,
195
- outcome: data.outcome ?? AuditOutcome.Failure,
198
+ outcome: data?.outcome ?? AuditOutcome.Failure,
196
199
  });
197
200
  }
198
201
  /**
@@ -206,7 +209,7 @@ let Auditor = Auditor_1 = class Auditor {
206
209
  await this.log(action, {
207
210
  ...data,
208
211
  severity: AuditSeverity.Error,
209
- outcome: data.outcome ?? AuditOutcome.Failure,
212
+ outcome: data?.outcome ?? AuditOutcome.Failure,
210
213
  });
211
214
  }
212
215
  /**
@@ -220,7 +223,7 @@ let Auditor = Auditor_1 = class Auditor {
220
223
  await this.log(action, {
221
224
  ...data,
222
225
  severity: AuditSeverity.Critical,
223
- outcome: data.outcome ?? AuditOutcome.Failure,
226
+ outcome: data?.outcome ?? AuditOutcome.Failure,
224
227
  });
225
228
  }
226
229
  };
@@ -0,0 +1,2 @@
1
+ ALTER TABLE "audit"."event" ALTER COLUMN "actor" DROP NOT NULL;--> statement-breakpoint
2
+ ALTER TABLE "audit"."event" ALTER COLUMN "network_path" DROP NOT NULL;
@@ -0,0 +1,195 @@
1
+ {
2
+ "id": "12d8d2c6-0f8e-4958-a036-cd42c36f2b1f",
3
+ "prevId": "8f6c87f8-1692-49bd-9bd4-09dc9d0bdcd4",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "audit.event": {
8
+ "name": "event",
9
+ "schema": "audit",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "timestamp": {
19
+ "name": "timestamp",
20
+ "type": "timestamp with time zone",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "tenant_id": {
25
+ "name": "tenant_id",
26
+ "type": "uuid",
27
+ "primaryKey": false,
28
+ "notNull": false
29
+ },
30
+ "correlation_id": {
31
+ "name": "correlation_id",
32
+ "type": "uuid",
33
+ "primaryKey": false,
34
+ "notNull": false
35
+ },
36
+ "module": {
37
+ "name": "module",
38
+ "type": "text",
39
+ "primaryKey": false,
40
+ "notNull": true
41
+ },
42
+ "action": {
43
+ "name": "action",
44
+ "type": "text",
45
+ "primaryKey": false,
46
+ "notNull": true
47
+ },
48
+ "outcome": {
49
+ "name": "outcome",
50
+ "type": "audit_outcome",
51
+ "typeSchema": "audit",
52
+ "primaryKey": false,
53
+ "notNull": true
54
+ },
55
+ "severity": {
56
+ "name": "severity",
57
+ "type": "audit_severity",
58
+ "typeSchema": "audit",
59
+ "primaryKey": false,
60
+ "notNull": true
61
+ },
62
+ "actor_type": {
63
+ "name": "actor_type",
64
+ "type": "actor_type",
65
+ "typeSchema": "audit",
66
+ "primaryKey": false,
67
+ "notNull": true
68
+ },
69
+ "actor": {
70
+ "name": "actor",
71
+ "type": "text",
72
+ "primaryKey": false,
73
+ "notNull": false
74
+ },
75
+ "impersonator_type": {
76
+ "name": "impersonator_type",
77
+ "type": "actor_type",
78
+ "typeSchema": "audit",
79
+ "primaryKey": false,
80
+ "notNull": false
81
+ },
82
+ "impersonator": {
83
+ "name": "impersonator",
84
+ "type": "text",
85
+ "primaryKey": false,
86
+ "notNull": false
87
+ },
88
+ "target_type": {
89
+ "name": "target_type",
90
+ "type": "text",
91
+ "primaryKey": false,
92
+ "notNull": true
93
+ },
94
+ "target_id": {
95
+ "name": "target_id",
96
+ "type": "uuid",
97
+ "primaryKey": false,
98
+ "notNull": true
99
+ },
100
+ "network_path": {
101
+ "name": "network_path",
102
+ "type": "text",
103
+ "primaryKey": false,
104
+ "notNull": false
105
+ },
106
+ "network_ip_address": {
107
+ "name": "network_ip_address",
108
+ "type": "text",
109
+ "primaryKey": false,
110
+ "notNull": false
111
+ },
112
+ "network_user_agent": {
113
+ "name": "network_user_agent",
114
+ "type": "text",
115
+ "primaryKey": false,
116
+ "notNull": false
117
+ },
118
+ "network_session_id": {
119
+ "name": "network_session_id",
120
+ "type": "uuid",
121
+ "primaryKey": false,
122
+ "notNull": false
123
+ },
124
+ "changes_before": {
125
+ "name": "changes_before",
126
+ "type": "jsonb",
127
+ "primaryKey": false,
128
+ "notNull": false
129
+ },
130
+ "changes_after": {
131
+ "name": "changes_after",
132
+ "type": "jsonb",
133
+ "primaryKey": false,
134
+ "notNull": false
135
+ },
136
+ "details": {
137
+ "name": "details",
138
+ "type": "jsonb",
139
+ "primaryKey": false,
140
+ "notNull": false
141
+ }
142
+ },
143
+ "indexes": {},
144
+ "foreignKeys": {},
145
+ "compositePrimaryKeys": {},
146
+ "uniqueConstraints": {},
147
+ "policies": {},
148
+ "checkConstraints": {},
149
+ "isRLSEnabled": false
150
+ }
151
+ },
152
+ "enums": {
153
+ "audit.actor_type": {
154
+ "name": "actor_type",
155
+ "schema": "audit",
156
+ "values": [
157
+ "anonymous",
158
+ "system",
159
+ "api-key",
160
+ "user"
161
+ ]
162
+ },
163
+ "audit.audit_outcome": {
164
+ "name": "audit_outcome",
165
+ "schema": "audit",
166
+ "values": [
167
+ "pending",
168
+ "success",
169
+ "cancelled",
170
+ "failure",
171
+ "denied"
172
+ ]
173
+ },
174
+ "audit.audit_severity": {
175
+ "name": "audit_severity",
176
+ "schema": "audit",
177
+ "values": [
178
+ "info",
179
+ "warn",
180
+ "error",
181
+ "critical"
182
+ ]
183
+ }
184
+ },
185
+ "schemas": {},
186
+ "sequences": {},
187
+ "roles": {},
188
+ "policies": {},
189
+ "views": {},
190
+ "_meta": {
191
+ "columns": {},
192
+ "schemas": {},
193
+ "tables": {}
194
+ }
195
+ }
@@ -8,6 +8,13 @@
8
8
  "when": 1758041172363,
9
9
  "tag": "0000_bored_stick",
10
10
  "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1762968766536,
16
+ "tag": "0001_previous_network",
17
+ "breakpoints": true
11
18
  }
12
19
  ]
13
20
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tstdl/base",
3
- "version": "0.93.37",
3
+ "version": "0.93.39",
4
4
  "author": "Patrick Hein",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -0,0 +1,2 @@
1
+ DROP INDEX "test"."test_parade_idx";--> statement-breakpoint
2
+ CREATE INDEX "test_parade_idx" ON "test"."test" USING bm25 ("id","language","title","content","tags",(("title" || ' ' || "content" || ' ' || "tags")::pdb.simple('alias=search_text')),(('foo')::pdb.simple('alias=foo'))) WITH (key_field='id');
@@ -0,0 +1,117 @@
1
+ {
2
+ "id": "68a0bdde-47d3-4390-b409-27a74dd269f3",
3
+ "prevId": "bbffc0f2-678b-42e9-8121-1731a04b8987",
4
+ "version": "7",
5
+ "dialect": "postgresql",
6
+ "tables": {
7
+ "test.test": {
8
+ "name": "test",
9
+ "schema": "test",
10
+ "columns": {
11
+ "id": {
12
+ "name": "id",
13
+ "type": "uuid",
14
+ "primaryKey": true,
15
+ "notNull": true,
16
+ "default": "gen_random_uuid()"
17
+ },
18
+ "title": {
19
+ "name": "title",
20
+ "type": "text",
21
+ "primaryKey": false,
22
+ "notNull": true
23
+ },
24
+ "content": {
25
+ "name": "content",
26
+ "type": "text",
27
+ "primaryKey": false,
28
+ "notNull": true
29
+ },
30
+ "tags": {
31
+ "name": "tags",
32
+ "type": "text",
33
+ "primaryKey": false,
34
+ "notNull": true
35
+ },
36
+ "language": {
37
+ "name": "language",
38
+ "type": "text",
39
+ "primaryKey": false,
40
+ "notNull": true
41
+ }
42
+ },
43
+ "indexes": {
44
+ "test_parade_idx": {
45
+ "name": "test_parade_idx",
46
+ "columns": [
47
+ {
48
+ "expression": "id",
49
+ "isExpression": false,
50
+ "asc": true,
51
+ "nulls": "last"
52
+ },
53
+ {
54
+ "expression": "\"language\"",
55
+ "asc": true,
56
+ "isExpression": true,
57
+ "nulls": "last"
58
+ },
59
+ {
60
+ "expression": "\"title\"",
61
+ "asc": true,
62
+ "isExpression": true,
63
+ "nulls": "last"
64
+ },
65
+ {
66
+ "expression": "\"content\"",
67
+ "asc": true,
68
+ "isExpression": true,
69
+ "nulls": "last"
70
+ },
71
+ {
72
+ "expression": "\"tags\"",
73
+ "asc": true,
74
+ "isExpression": true,
75
+ "nulls": "last"
76
+ },
77
+ {
78
+ "expression": "((\"title\" || ' ' || \"content\" || ' ' || \"tags\")::pdb.simple('alias=search_text'))",
79
+ "asc": true,
80
+ "isExpression": true,
81
+ "nulls": "last"
82
+ },
83
+ {
84
+ "expression": "(('foo')::pdb.simple('alias=foo'))",
85
+ "asc": true,
86
+ "isExpression": true,
87
+ "nulls": "last"
88
+ }
89
+ ],
90
+ "isUnique": false,
91
+ "concurrently": false,
92
+ "method": "bm25",
93
+ "with": {
94
+ "key_field": "'id'"
95
+ }
96
+ }
97
+ },
98
+ "foreignKeys": {},
99
+ "compositePrimaryKeys": {},
100
+ "uniqueConstraints": {},
101
+ "policies": {},
102
+ "checkConstraints": {},
103
+ "isRLSEnabled": false
104
+ }
105
+ },
106
+ "enums": {},
107
+ "schemas": {},
108
+ "sequences": {},
109
+ "roles": {},
110
+ "policies": {},
111
+ "views": {},
112
+ "_meta": {
113
+ "columns": {},
114
+ "schemas": {},
115
+ "tables": {}
116
+ }
117
+ }
@@ -8,6 +8,13 @@
8
8
  "when": 1762381204799,
9
9
  "tag": "0000_natural_cannonball",
10
10
  "breakpoints": true
11
+ },
12
+ {
13
+ "idx": 1,
14
+ "version": "7",
15
+ "when": 1762968768532,
16
+ "tag": "0001_closed_the_captain",
17
+ "breakpoints": true
11
18
  }
12
19
  ]
13
20
  }