@geekmidas/constructs 0.0.14 → 0.0.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.
- package/dist/{EndpointBuilder-DpGmObMb.cjs → EndpointBuilder-B8vyK_Fy.cjs} +7 -2
- package/dist/EndpointBuilder-B8vyK_Fy.cjs.map +1 -0
- package/dist/{EndpointBuilder-CPxmF_w7.d.cts → EndpointBuilder-C3cdFvpS.d.cts} +5 -4
- package/dist/{EndpointBuilder-Csfyfjd7.d.mts → EndpointBuilder-DLoHiV83.d.mts} +5 -4
- package/dist/{EndpointBuilder-aE2E6WTx.mjs → EndpointBuilder-I--56szz.mjs} +7 -2
- package/dist/EndpointBuilder-I--56szz.mjs.map +1 -0
- package/dist/{EndpointFactory-BU_R-9LH.d.mts → EndpointFactory-6YMPR9pB.d.mts} +46 -22
- package/dist/{EndpointFactory-BfH6mjJ3.cjs → EndpointFactory-BR9goiXy.cjs} +96 -10
- package/dist/EndpointFactory-BR9goiXy.cjs.map +1 -0
- package/dist/{EndpointFactory-D0Ql2Ofm.d.cts → EndpointFactory-Sho97vyd.d.cts} +46 -22
- package/dist/{EndpointFactory-D4leYk1N.mjs → EndpointFactory-jm5ZKNDj.mjs} +96 -10
- package/dist/EndpointFactory-jm5ZKNDj.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DANYfDu9.d.mts → HonoEndpointAdaptor-7hIKI32d.d.mts} +3 -3
- package/dist/{HonoEndpointAdaptor-_uLz8Bak.d.cts → HonoEndpointAdaptor-Bwp0-Z-K.d.cts} +3 -3
- package/dist/{Subscriber-CJOWwaw1.mjs → Subscriber-CGb8LjZa.mjs} +1 -1
- package/dist/{Subscriber-CJOWwaw1.mjs.map → Subscriber-CGb8LjZa.mjs.map} +1 -1
- package/dist/{Subscriber-Bdh8rMSL.cjs → Subscriber-D-FPWts6.cjs} +1 -1
- package/dist/{Subscriber-Bdh8rMSL.cjs.map → Subscriber-D-FPWts6.cjs.map} +1 -1
- package/dist/{SubscriberBuilder-BWQmiYd8.mjs → SubscriberBuilder-BcAspHv9.mjs} +2 -2
- package/dist/{SubscriberBuilder-BWQmiYd8.mjs.map → SubscriberBuilder-BcAspHv9.mjs.map} +1 -1
- package/dist/{SubscriberBuilder-DieD_60p.cjs → SubscriberBuilder-BfE2cL1q.cjs} +2 -2
- package/dist/{SubscriberBuilder-DieD_60p.cjs.map → SubscriberBuilder-BfE2cL1q.cjs.map} +1 -1
- package/dist/adaptors/aws.d.cts +1 -1
- package/dist/adaptors/aws.d.mts +1 -1
- package/dist/adaptors/hono.d.cts +2 -2
- package/dist/adaptors/hono.d.mts +2 -2
- package/dist/adaptors/testing.d.cts +1 -1
- package/dist/adaptors/testing.d.mts +1 -1
- package/dist/crons/Cron.d.cts +1 -1
- package/dist/crons/Cron.d.mts +1 -1
- package/dist/crons/CronBuilder.d.cts +1 -1
- package/dist/crons/CronBuilder.d.mts +1 -1
- package/dist/crons/index.d.cts +1 -1
- package/dist/crons/index.d.mts +5 -5
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.mts +1 -1
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.mts +1 -1
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.mts +1 -1
- package/dist/endpoints/Endpoint.d.cts +1 -1
- package/dist/endpoints/Endpoint.d.mts +1 -1
- package/dist/endpoints/EndpointBuilder.cjs +1 -1
- package/dist/endpoints/EndpointBuilder.d.cts +2 -2
- package/dist/endpoints/EndpointBuilder.d.mts +2 -2
- package/dist/endpoints/EndpointBuilder.mjs +1 -1
- package/dist/endpoints/EndpointFactory.cjs +2 -2
- package/dist/endpoints/EndpointFactory.d.cts +3 -3
- package/dist/endpoints/EndpointFactory.d.mts +3 -3
- package/dist/endpoints/EndpointFactory.mjs +2 -2
- package/dist/endpoints/HonoEndpointAdaptor.d.cts +2 -2
- package/dist/endpoints/HonoEndpointAdaptor.d.mts +2 -2
- package/dist/endpoints/TestEndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/TestEndpointAdaptor.d.mts +1 -1
- package/dist/endpoints/audit.d.cts +1 -1
- package/dist/endpoints/audit.d.mts +1 -1
- package/dist/endpoints/helpers.d.cts +1 -1
- package/dist/endpoints/helpers.d.mts +1 -1
- package/dist/endpoints/index.cjs +2 -2
- package/dist/endpoints/index.d.cts +5 -5
- package/dist/endpoints/index.d.mts +4 -4
- package/dist/endpoints/index.mjs +2 -2
- package/dist/endpoints/processAudits.d.cts +1 -1
- package/dist/endpoints/processAudits.d.mts +1 -1
- package/dist/functions/index.d.cts +1 -1
- package/dist/functions/index.d.mts +1 -1
- package/dist/index-Bu0XAj5A.d.cts +10 -0
- package/dist/index-Chb-374q.d.mts +10 -0
- package/dist/subscribers/Subscriber.cjs +1 -1
- package/dist/subscribers/Subscriber.mjs +1 -1
- package/dist/subscribers/SubscriberBuilder.cjs +2 -2
- package/dist/subscribers/SubscriberBuilder.mjs +2 -2
- package/dist/subscribers/index.cjs +2 -2
- package/dist/subscribers/index.d.cts +2 -2
- package/dist/subscribers/index.d.mts +2 -2
- package/dist/subscribers/index.mjs +2 -2
- package/package.json +5 -5
- package/src/endpoints/EndpointBuilder.ts +23 -4
- package/src/endpoints/EndpointFactory.ts +290 -20
- package/src/endpoints/__tests__/EndpointFactory.database-auditor.spec.ts +509 -0
- package/dist/EndpointBuilder-DpGmObMb.cjs.map +0 -1
- package/dist/EndpointBuilder-aE2E6WTx.mjs.map +0 -1
- package/dist/EndpointFactory-BfH6mjJ3.cjs.map +0 -1
- package/dist/EndpointFactory-D4leYk1N.mjs.map +0 -1
- package/dist/index-DRf5AP3P.d.mts +0 -10
- package/dist/index-twsdbZWU.d.cts +0 -10
|
@@ -45,7 +45,9 @@ export class EndpointBuilder<
|
|
|
45
45
|
TEventPublisher,
|
|
46
46
|
TEventPublisherServiceName,
|
|
47
47
|
TAuditStorage,
|
|
48
|
-
TAuditStorageServiceName
|
|
48
|
+
TAuditStorageServiceName,
|
|
49
|
+
TDatabase,
|
|
50
|
+
TDatabaseServiceName
|
|
49
51
|
> {
|
|
50
52
|
protected schemas: TInput = {} as TInput;
|
|
51
53
|
protected _description?: string;
|
|
@@ -59,7 +61,6 @@ export class EndpointBuilder<
|
|
|
59
61
|
_authorizerName?: TAuthorizers[number];
|
|
60
62
|
_actorExtractor?: ActorExtractor<TServices, TSession, TLogger>;
|
|
61
63
|
_audits: MappedAudit<TAuditAction, OutSchema>[] = [];
|
|
62
|
-
_databaseService?: Service<TDatabaseServiceName, TDatabase>;
|
|
63
64
|
|
|
64
65
|
constructor(
|
|
65
66
|
readonly route: TRoute,
|
|
@@ -75,6 +76,18 @@ export class EndpointBuilder<
|
|
|
75
76
|
this._publisher = publisher;
|
|
76
77
|
}
|
|
77
78
|
|
|
79
|
+
// Internal setter for EndpointFactory to set default auditor storage
|
|
80
|
+
_setAuditorStorage(
|
|
81
|
+
storage: Service<TAuditStorageServiceName, TAuditStorage>,
|
|
82
|
+
) {
|
|
83
|
+
this._auditorStorage = storage;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// Internal setter for EndpointFactory to set default database service
|
|
87
|
+
_setDatabaseService(service: Service<TDatabaseServiceName, TDatabase>) {
|
|
88
|
+
this._databaseService = service;
|
|
89
|
+
}
|
|
90
|
+
|
|
78
91
|
description(description: string): this {
|
|
79
92
|
this._description = description;
|
|
80
93
|
return this;
|
|
@@ -116,7 +129,10 @@ export class EndpointBuilder<
|
|
|
116
129
|
TName,
|
|
117
130
|
TAuthorizers,
|
|
118
131
|
TAuditStorage,
|
|
119
|
-
TAuditStorageServiceName
|
|
132
|
+
TAuditStorageServiceName,
|
|
133
|
+
TAuditAction,
|
|
134
|
+
TDatabase,
|
|
135
|
+
TDatabaseServiceName
|
|
120
136
|
> {
|
|
121
137
|
this._publisher = publisher as unknown as Service<
|
|
122
138
|
TEventPublisherServiceName,
|
|
@@ -135,7 +151,10 @@ export class EndpointBuilder<
|
|
|
135
151
|
TName,
|
|
136
152
|
TAuthorizers,
|
|
137
153
|
TAuditStorage,
|
|
138
|
-
TAuditStorageServiceName
|
|
154
|
+
TAuditStorageServiceName,
|
|
155
|
+
TAuditAction,
|
|
156
|
+
TDatabase,
|
|
157
|
+
TDatabaseServiceName
|
|
139
158
|
>;
|
|
140
159
|
}
|
|
141
160
|
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import type { AuditStorage } from '@geekmidas/audit';
|
|
2
|
+
import type { EventPublisher, MappedEvent } from '@geekmidas/events';
|
|
1
3
|
import type { Logger } from '@geekmidas/logger';
|
|
2
4
|
import { ConsoleLogger } from '@geekmidas/logger/console';
|
|
3
5
|
import type { Service } from '@geekmidas/services';
|
|
4
6
|
import uniqBy from 'lodash.uniqby';
|
|
7
|
+
import type { HttpMethod } from '../types';
|
|
8
|
+
import type { ActorExtractor } from './audit';
|
|
5
9
|
import type { Authorizer } from './Authorizer';
|
|
6
10
|
import type { AuthorizeFn, SessionFn } from './Endpoint';
|
|
7
11
|
import { EndpointBuilder } from './EndpointBuilder';
|
|
8
12
|
|
|
9
|
-
import type { EventPublisher, MappedEvent } from '@geekmidas/events';
|
|
10
|
-
import type { HttpMethod } from '../types';
|
|
11
|
-
|
|
12
13
|
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
13
14
|
|
|
14
15
|
export class EndpointFactory<
|
|
@@ -19,6 +20,10 @@ export class EndpointFactory<
|
|
|
19
20
|
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
20
21
|
TEventPublisherServiceName extends string = string,
|
|
21
22
|
TAuthorizers extends readonly string[] = readonly string[],
|
|
23
|
+
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
24
|
+
TAuditStorageServiceName extends string = string,
|
|
25
|
+
TDatabase = undefined,
|
|
26
|
+
TDatabaseServiceName extends string = string,
|
|
22
27
|
> {
|
|
23
28
|
// @ts-ignore
|
|
24
29
|
private defaultServices: TServices;
|
|
@@ -31,6 +36,13 @@ export class EndpointFactory<
|
|
|
31
36
|
private defaultLogger: TLogger = DEFAULT_LOGGER;
|
|
32
37
|
private availableAuthorizers: Authorizer[] = [];
|
|
33
38
|
private defaultAuthorizerName?: TAuthorizers[number];
|
|
39
|
+
private defaultAuditorStorage:
|
|
40
|
+
| Service<TAuditStorageServiceName, TAuditStorage>
|
|
41
|
+
| undefined;
|
|
42
|
+
private defaultDatabaseService:
|
|
43
|
+
| Service<TDatabaseServiceName, TDatabase>
|
|
44
|
+
| undefined;
|
|
45
|
+
private defaultActorExtractor?: ActorExtractor<TServices, TSession, TLogger>;
|
|
34
46
|
|
|
35
47
|
constructor({
|
|
36
48
|
basePath,
|
|
@@ -42,6 +54,9 @@ export class EndpointFactory<
|
|
|
42
54
|
defaultEventPublisher,
|
|
43
55
|
availableAuthorizers = [],
|
|
44
56
|
defaultAuthorizerName,
|
|
57
|
+
defaultAuditorStorage,
|
|
58
|
+
defaultDatabaseService,
|
|
59
|
+
defaultActorExtractor,
|
|
45
60
|
}: EndpointFactoryOptions<
|
|
46
61
|
TServices,
|
|
47
62
|
TBasePath,
|
|
@@ -49,7 +64,11 @@ export class EndpointFactory<
|
|
|
49
64
|
TSession,
|
|
50
65
|
TEventPublisher,
|
|
51
66
|
TEventPublisherServiceName,
|
|
52
|
-
TAuthorizers
|
|
67
|
+
TAuthorizers,
|
|
68
|
+
TAuditStorage,
|
|
69
|
+
TAuditStorageServiceName,
|
|
70
|
+
TDatabase,
|
|
71
|
+
TDatabaseServiceName
|
|
53
72
|
> = {}) {
|
|
54
73
|
// Initialize default services
|
|
55
74
|
this.defaultServices = uniqBy(
|
|
@@ -64,6 +83,9 @@ export class EndpointFactory<
|
|
|
64
83
|
this.defaultEventPublisher = defaultEventPublisher;
|
|
65
84
|
this.availableAuthorizers = availableAuthorizers;
|
|
66
85
|
this.defaultAuthorizerName = defaultAuthorizerName;
|
|
86
|
+
this.defaultAuditorStorage = defaultAuditorStorage;
|
|
87
|
+
this.defaultDatabaseService = defaultDatabaseService;
|
|
88
|
+
this.defaultActorExtractor = defaultActorExtractor;
|
|
67
89
|
}
|
|
68
90
|
|
|
69
91
|
static joinPaths<TBasePath extends string, P extends string>(
|
|
@@ -113,7 +135,11 @@ export class EndpointFactory<
|
|
|
113
135
|
TSession,
|
|
114
136
|
TEventPublisher,
|
|
115
137
|
TEventPublisherServiceName,
|
|
116
|
-
T
|
|
138
|
+
T,
|
|
139
|
+
TAuditStorage,
|
|
140
|
+
TAuditStorageServiceName,
|
|
141
|
+
TDatabase,
|
|
142
|
+
TDatabaseServiceName
|
|
117
143
|
> {
|
|
118
144
|
const authorizerConfigs = authorizers.map((name) => ({
|
|
119
145
|
name,
|
|
@@ -125,7 +151,11 @@ export class EndpointFactory<
|
|
|
125
151
|
TSession,
|
|
126
152
|
TEventPublisher,
|
|
127
153
|
TEventPublisherServiceName,
|
|
128
|
-
T
|
|
154
|
+
T,
|
|
155
|
+
TAuditStorage,
|
|
156
|
+
TAuditStorageServiceName,
|
|
157
|
+
TDatabase,
|
|
158
|
+
TDatabaseServiceName
|
|
129
159
|
>({
|
|
130
160
|
defaultServices: this.defaultServices,
|
|
131
161
|
basePath: this.basePath,
|
|
@@ -135,6 +165,9 @@ export class EndpointFactory<
|
|
|
135
165
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
136
166
|
availableAuthorizers: authorizerConfigs,
|
|
137
167
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
168
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
169
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
170
|
+
defaultActorExtractor: this.defaultActorExtractor,
|
|
138
171
|
});
|
|
139
172
|
}
|
|
140
173
|
|
|
@@ -148,7 +181,11 @@ export class EndpointFactory<
|
|
|
148
181
|
TSession,
|
|
149
182
|
TEventPublisher,
|
|
150
183
|
TEventPublisherServiceName,
|
|
151
|
-
TAuthorizers
|
|
184
|
+
TAuthorizers,
|
|
185
|
+
TAuditStorage,
|
|
186
|
+
TAuditStorageServiceName,
|
|
187
|
+
TDatabase,
|
|
188
|
+
TDatabaseServiceName
|
|
152
189
|
> {
|
|
153
190
|
const newBasePath = EndpointFactory.joinPaths(path, this.basePath);
|
|
154
191
|
return new EndpointFactory<
|
|
@@ -158,7 +195,11 @@ export class EndpointFactory<
|
|
|
158
195
|
TSession,
|
|
159
196
|
TEventPublisher,
|
|
160
197
|
TEventPublisherServiceName,
|
|
161
|
-
TAuthorizers
|
|
198
|
+
TAuthorizers,
|
|
199
|
+
TAuditStorage,
|
|
200
|
+
TAuditStorageServiceName,
|
|
201
|
+
TDatabase,
|
|
202
|
+
TDatabaseServiceName
|
|
162
203
|
>({
|
|
163
204
|
defaultServices: this.defaultServices,
|
|
164
205
|
basePath: newBasePath,
|
|
@@ -168,6 +209,9 @@ export class EndpointFactory<
|
|
|
168
209
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
169
210
|
availableAuthorizers: this.availableAuthorizers,
|
|
170
211
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
212
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
213
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
214
|
+
defaultActorExtractor: this.defaultActorExtractor,
|
|
171
215
|
});
|
|
172
216
|
}
|
|
173
217
|
|
|
@@ -181,7 +225,11 @@ export class EndpointFactory<
|
|
|
181
225
|
TSession,
|
|
182
226
|
TEventPublisher,
|
|
183
227
|
TEventPublisherServiceName,
|
|
184
|
-
TAuthorizers
|
|
228
|
+
TAuthorizers,
|
|
229
|
+
TAuditStorage,
|
|
230
|
+
TAuditStorageServiceName,
|
|
231
|
+
TDatabase,
|
|
232
|
+
TDatabaseServiceName
|
|
185
233
|
> {
|
|
186
234
|
return new EndpointFactory<
|
|
187
235
|
TServices,
|
|
@@ -190,7 +238,11 @@ export class EndpointFactory<
|
|
|
190
238
|
TSession,
|
|
191
239
|
TEventPublisher,
|
|
192
240
|
TEventPublisherServiceName,
|
|
193
|
-
TAuthorizers
|
|
241
|
+
TAuthorizers,
|
|
242
|
+
TAuditStorage,
|
|
243
|
+
TAuditStorageServiceName,
|
|
244
|
+
TDatabase,
|
|
245
|
+
TDatabaseServiceName
|
|
194
246
|
>({
|
|
195
247
|
defaultServices: this.defaultServices,
|
|
196
248
|
basePath: this.basePath,
|
|
@@ -200,6 +252,9 @@ export class EndpointFactory<
|
|
|
200
252
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
201
253
|
availableAuthorizers: this.availableAuthorizers,
|
|
202
254
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
255
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
256
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
257
|
+
defaultActorExtractor: this.defaultActorExtractor,
|
|
203
258
|
});
|
|
204
259
|
}
|
|
205
260
|
|
|
@@ -213,7 +268,11 @@ export class EndpointFactory<
|
|
|
213
268
|
TSession,
|
|
214
269
|
TEventPublisher,
|
|
215
270
|
TEventPublisherServiceName,
|
|
216
|
-
TAuthorizers
|
|
271
|
+
TAuthorizers,
|
|
272
|
+
TAuditStorage,
|
|
273
|
+
TAuditStorageServiceName,
|
|
274
|
+
TDatabase,
|
|
275
|
+
TDatabaseServiceName
|
|
217
276
|
> {
|
|
218
277
|
return new EndpointFactory<
|
|
219
278
|
[...S, ...TServices],
|
|
@@ -222,7 +281,11 @@ export class EndpointFactory<
|
|
|
222
281
|
TSession,
|
|
223
282
|
TEventPublisher,
|
|
224
283
|
TEventPublisherServiceName,
|
|
225
|
-
TAuthorizers
|
|
284
|
+
TAuthorizers,
|
|
285
|
+
TAuditStorage,
|
|
286
|
+
TAuditStorageServiceName,
|
|
287
|
+
TDatabase,
|
|
288
|
+
TDatabaseServiceName
|
|
226
289
|
>({
|
|
227
290
|
defaultServices: [...services, ...this.defaultServices],
|
|
228
291
|
basePath: this.basePath,
|
|
@@ -232,6 +295,9 @@ export class EndpointFactory<
|
|
|
232
295
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
233
296
|
availableAuthorizers: this.availableAuthorizers,
|
|
234
297
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
298
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
299
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
300
|
+
defaultActorExtractor: this.defaultActorExtractor,
|
|
235
301
|
});
|
|
236
302
|
}
|
|
237
303
|
|
|
@@ -244,7 +310,11 @@ export class EndpointFactory<
|
|
|
244
310
|
TSession,
|
|
245
311
|
TEventPublisher,
|
|
246
312
|
TEventPublisherServiceName,
|
|
247
|
-
TAuthorizers
|
|
313
|
+
TAuthorizers,
|
|
314
|
+
TAuditStorage,
|
|
315
|
+
TAuditStorageServiceName,
|
|
316
|
+
TDatabase,
|
|
317
|
+
TDatabaseServiceName
|
|
248
318
|
> {
|
|
249
319
|
return new EndpointFactory<
|
|
250
320
|
TServices,
|
|
@@ -253,7 +323,11 @@ export class EndpointFactory<
|
|
|
253
323
|
TSession,
|
|
254
324
|
TEventPublisher,
|
|
255
325
|
TEventPublisherServiceName,
|
|
256
|
-
TAuthorizers
|
|
326
|
+
TAuthorizers,
|
|
327
|
+
TAuditStorage,
|
|
328
|
+
TAuditStorageServiceName,
|
|
329
|
+
TDatabase,
|
|
330
|
+
TDatabaseServiceName
|
|
257
331
|
>({
|
|
258
332
|
defaultServices: this.defaultServices,
|
|
259
333
|
basePath: this.basePath,
|
|
@@ -272,6 +346,10 @@ export class EndpointFactory<
|
|
|
272
346
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
273
347
|
availableAuthorizers: this.availableAuthorizers,
|
|
274
348
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
349
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
350
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
351
|
+
defaultActorExtractor: this
|
|
352
|
+
.defaultActorExtractor as unknown as ActorExtractor<TServices, TSession, L>,
|
|
275
353
|
});
|
|
276
354
|
}
|
|
277
355
|
|
|
@@ -287,7 +365,11 @@ export class EndpointFactory<
|
|
|
287
365
|
TSession,
|
|
288
366
|
T,
|
|
289
367
|
TServiceName,
|
|
290
|
-
TAuthorizers
|
|
368
|
+
TAuthorizers,
|
|
369
|
+
TAuditStorage,
|
|
370
|
+
TAuditStorageServiceName,
|
|
371
|
+
TDatabase,
|
|
372
|
+
TDatabaseServiceName
|
|
291
373
|
> {
|
|
292
374
|
return new EndpointFactory<
|
|
293
375
|
TServices,
|
|
@@ -296,7 +378,11 @@ export class EndpointFactory<
|
|
|
296
378
|
TSession,
|
|
297
379
|
T,
|
|
298
380
|
TServiceName,
|
|
299
|
-
TAuthorizers
|
|
381
|
+
TAuthorizers,
|
|
382
|
+
TAuditStorage,
|
|
383
|
+
TAuditStorageServiceName,
|
|
384
|
+
TDatabase,
|
|
385
|
+
TDatabaseServiceName
|
|
300
386
|
>({
|
|
301
387
|
defaultServices: this.defaultServices,
|
|
302
388
|
basePath: this.basePath,
|
|
@@ -306,6 +392,9 @@ export class EndpointFactory<
|
|
|
306
392
|
defaultEventPublisher: publisher,
|
|
307
393
|
availableAuthorizers: this.availableAuthorizers,
|
|
308
394
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
395
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
396
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
397
|
+
defaultActorExtractor: this.defaultActorExtractor,
|
|
309
398
|
});
|
|
310
399
|
}
|
|
311
400
|
|
|
@@ -318,7 +407,11 @@ export class EndpointFactory<
|
|
|
318
407
|
T,
|
|
319
408
|
TEventPublisher,
|
|
320
409
|
TEventPublisherServiceName,
|
|
321
|
-
TAuthorizers
|
|
410
|
+
TAuthorizers,
|
|
411
|
+
TAuditStorage,
|
|
412
|
+
TAuditStorageServiceName,
|
|
413
|
+
TDatabase,
|
|
414
|
+
TDatabaseServiceName
|
|
322
415
|
> {
|
|
323
416
|
return new EndpointFactory<
|
|
324
417
|
TServices,
|
|
@@ -327,7 +420,11 @@ export class EndpointFactory<
|
|
|
327
420
|
T,
|
|
328
421
|
TEventPublisher,
|
|
329
422
|
TEventPublisherServiceName,
|
|
330
|
-
TAuthorizers
|
|
423
|
+
TAuthorizers,
|
|
424
|
+
TAuditStorage,
|
|
425
|
+
TAuditStorageServiceName,
|
|
426
|
+
TDatabase,
|
|
427
|
+
TDatabaseServiceName
|
|
331
428
|
>({
|
|
332
429
|
defaultServices: this.defaultServices,
|
|
333
430
|
basePath: this.basePath,
|
|
@@ -341,6 +438,147 @@ export class EndpointFactory<
|
|
|
341
438
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
342
439
|
availableAuthorizers: this.availableAuthorizers,
|
|
343
440
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
441
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
442
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
443
|
+
defaultActorExtractor: this
|
|
444
|
+
.defaultActorExtractor as unknown as ActorExtractor<TServices, T, TLogger>,
|
|
445
|
+
});
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Set the database service for endpoints created from this factory.
|
|
450
|
+
* The database will be available in handler context as `db`.
|
|
451
|
+
*/
|
|
452
|
+
database<T, TName extends string>(
|
|
453
|
+
service: Service<TName, T>,
|
|
454
|
+
): EndpointFactory<
|
|
455
|
+
TServices,
|
|
456
|
+
TBasePath,
|
|
457
|
+
TLogger,
|
|
458
|
+
TSession,
|
|
459
|
+
TEventPublisher,
|
|
460
|
+
TEventPublisherServiceName,
|
|
461
|
+
TAuthorizers,
|
|
462
|
+
TAuditStorage,
|
|
463
|
+
TAuditStorageServiceName,
|
|
464
|
+
T,
|
|
465
|
+
TName
|
|
466
|
+
> {
|
|
467
|
+
return new EndpointFactory<
|
|
468
|
+
TServices,
|
|
469
|
+
TBasePath,
|
|
470
|
+
TLogger,
|
|
471
|
+
TSession,
|
|
472
|
+
TEventPublisher,
|
|
473
|
+
TEventPublisherServiceName,
|
|
474
|
+
TAuthorizers,
|
|
475
|
+
TAuditStorage,
|
|
476
|
+
TAuditStorageServiceName,
|
|
477
|
+
T,
|
|
478
|
+
TName
|
|
479
|
+
>({
|
|
480
|
+
defaultServices: this.defaultServices,
|
|
481
|
+
basePath: this.basePath,
|
|
482
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
483
|
+
defaultLogger: this.defaultLogger,
|
|
484
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
485
|
+
defaultEventPublisher: this.defaultEventPublisher,
|
|
486
|
+
availableAuthorizers: this.availableAuthorizers,
|
|
487
|
+
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
488
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
489
|
+
defaultDatabaseService: service,
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Set the auditor storage service for endpoints created from this factory.
|
|
495
|
+
* This enables audit functionality and makes `auditor` available in handler context.
|
|
496
|
+
*/
|
|
497
|
+
auditor<T extends AuditStorage, TName extends string>(
|
|
498
|
+
storage: Service<TName, T>,
|
|
499
|
+
): EndpointFactory<
|
|
500
|
+
TServices,
|
|
501
|
+
TBasePath,
|
|
502
|
+
TLogger,
|
|
503
|
+
TSession,
|
|
504
|
+
TEventPublisher,
|
|
505
|
+
TEventPublisherServiceName,
|
|
506
|
+
TAuthorizers,
|
|
507
|
+
T,
|
|
508
|
+
TName,
|
|
509
|
+
TDatabase,
|
|
510
|
+
TDatabaseServiceName
|
|
511
|
+
> {
|
|
512
|
+
return new EndpointFactory<
|
|
513
|
+
TServices,
|
|
514
|
+
TBasePath,
|
|
515
|
+
TLogger,
|
|
516
|
+
TSession,
|
|
517
|
+
TEventPublisher,
|
|
518
|
+
TEventPublisherServiceName,
|
|
519
|
+
TAuthorizers,
|
|
520
|
+
T,
|
|
521
|
+
TName,
|
|
522
|
+
TDatabase,
|
|
523
|
+
TDatabaseServiceName
|
|
524
|
+
>({
|
|
525
|
+
defaultServices: this.defaultServices,
|
|
526
|
+
basePath: this.basePath,
|
|
527
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
528
|
+
defaultLogger: this.defaultLogger,
|
|
529
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
530
|
+
defaultEventPublisher: this.defaultEventPublisher,
|
|
531
|
+
availableAuthorizers: this.availableAuthorizers,
|
|
532
|
+
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
533
|
+
defaultAuditorStorage: storage,
|
|
534
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
535
|
+
defaultActorExtractor: this.defaultActorExtractor,
|
|
536
|
+
});
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
/**
|
|
540
|
+
* Set the actor extractor function for endpoints created from this factory.
|
|
541
|
+
* The actor is extracted from the request context and attached to all audits.
|
|
542
|
+
*/
|
|
543
|
+
actor(
|
|
544
|
+
extractor: ActorExtractor<TServices, TSession, TLogger>,
|
|
545
|
+
): EndpointFactory<
|
|
546
|
+
TServices,
|
|
547
|
+
TBasePath,
|
|
548
|
+
TLogger,
|
|
549
|
+
TSession,
|
|
550
|
+
TEventPublisher,
|
|
551
|
+
TEventPublisherServiceName,
|
|
552
|
+
TAuthorizers,
|
|
553
|
+
TAuditStorage,
|
|
554
|
+
TAuditStorageServiceName,
|
|
555
|
+
TDatabase,
|
|
556
|
+
TDatabaseServiceName
|
|
557
|
+
> {
|
|
558
|
+
return new EndpointFactory<
|
|
559
|
+
TServices,
|
|
560
|
+
TBasePath,
|
|
561
|
+
TLogger,
|
|
562
|
+
TSession,
|
|
563
|
+
TEventPublisher,
|
|
564
|
+
TEventPublisherServiceName,
|
|
565
|
+
TAuthorizers,
|
|
566
|
+
TAuditStorage,
|
|
567
|
+
TAuditStorageServiceName,
|
|
568
|
+
TDatabase,
|
|
569
|
+
TDatabaseServiceName
|
|
570
|
+
>({
|
|
571
|
+
defaultServices: this.defaultServices,
|
|
572
|
+
basePath: this.basePath,
|
|
573
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
574
|
+
defaultLogger: this.defaultLogger,
|
|
575
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
576
|
+
defaultEventPublisher: this.defaultEventPublisher,
|
|
577
|
+
availableAuthorizers: this.availableAuthorizers,
|
|
578
|
+
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
579
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
580
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
581
|
+
defaultActorExtractor: extractor,
|
|
344
582
|
});
|
|
345
583
|
}
|
|
346
584
|
|
|
@@ -357,7 +595,12 @@ export class EndpointFactory<
|
|
|
357
595
|
TSession,
|
|
358
596
|
TEventPublisher,
|
|
359
597
|
TEventPublisherServiceName,
|
|
360
|
-
TAuthorizers
|
|
598
|
+
TAuthorizers,
|
|
599
|
+
TAuditStorage,
|
|
600
|
+
TAuditStorageServiceName,
|
|
601
|
+
any,
|
|
602
|
+
TDatabase,
|
|
603
|
+
TDatabaseServiceName
|
|
361
604
|
> {
|
|
362
605
|
const fullPath = EndpointFactory.joinPaths(path, this.basePath);
|
|
363
606
|
const builder = new EndpointBuilder<
|
|
@@ -370,7 +613,12 @@ export class EndpointFactory<
|
|
|
370
613
|
TSession,
|
|
371
614
|
TEventPublisher,
|
|
372
615
|
TEventPublisherServiceName,
|
|
373
|
-
TAuthorizers
|
|
616
|
+
TAuthorizers,
|
|
617
|
+
TAuditStorage,
|
|
618
|
+
TAuditStorageServiceName,
|
|
619
|
+
any,
|
|
620
|
+
TDatabase,
|
|
621
|
+
TDatabaseServiceName
|
|
374
622
|
>(fullPath, method);
|
|
375
623
|
|
|
376
624
|
if (this.defaultAuthorizeFn) {
|
|
@@ -404,6 +652,21 @@ export class EndpointFactory<
|
|
|
404
652
|
builder._authorizerName = this.defaultAuthorizerName;
|
|
405
653
|
}
|
|
406
654
|
|
|
655
|
+
// Set auditor storage if configured
|
|
656
|
+
if (this.defaultAuditorStorage) {
|
|
657
|
+
builder._setAuditorStorage(this.defaultAuditorStorage as any);
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
// Set database service if configured
|
|
661
|
+
if (this.defaultDatabaseService) {
|
|
662
|
+
builder._setDatabaseService(this.defaultDatabaseService as any);
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// Set actor extractor if configured
|
|
666
|
+
if (this.defaultActorExtractor) {
|
|
667
|
+
builder._actorExtractor = this.defaultActorExtractor;
|
|
668
|
+
}
|
|
669
|
+
|
|
407
670
|
return builder;
|
|
408
671
|
}
|
|
409
672
|
|
|
@@ -467,6 +730,10 @@ export interface EndpointFactoryOptions<
|
|
|
467
730
|
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
468
731
|
TEventPublisherServiceName extends string = string,
|
|
469
732
|
TAuthorizers extends readonly string[] = readonly string[],
|
|
733
|
+
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
734
|
+
TAuditStorageServiceName extends string = string,
|
|
735
|
+
TDatabase = undefined,
|
|
736
|
+
TDatabaseServiceName extends string = string,
|
|
470
737
|
> {
|
|
471
738
|
defaultServices?: TServices;
|
|
472
739
|
basePath?: TBasePath;
|
|
@@ -477,6 +744,9 @@ export interface EndpointFactoryOptions<
|
|
|
477
744
|
defaultEvents?: MappedEvent<TEventPublisher, undefined>[];
|
|
478
745
|
availableAuthorizers?: Authorizer[];
|
|
479
746
|
defaultAuthorizerName?: TAuthorizers[number];
|
|
747
|
+
defaultAuditorStorage?: Service<TAuditStorageServiceName, TAuditStorage>;
|
|
748
|
+
defaultDatabaseService?: Service<TDatabaseServiceName, TDatabase>;
|
|
749
|
+
defaultActorExtractor?: ActorExtractor<TServices, TSession, TLogger>;
|
|
480
750
|
}
|
|
481
751
|
|
|
482
752
|
export const e = new EndpointFactory();
|