@geekmidas/constructs 0.0.14 → 0.0.15
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-2wSubmux.d.mts} +37 -21
- package/dist/{EndpointFactory-BfH6mjJ3.cjs → EndpointFactory-BJ71jEqM.cjs} +66 -10
- package/dist/EndpointFactory-BJ71jEqM.cjs.map +1 -0
- package/dist/{EndpointFactory-D0Ql2Ofm.d.cts → EndpointFactory-D6wQfk6Q.d.cts} +37 -21
- package/dist/{EndpointFactory-D4leYk1N.mjs → EndpointFactory-D_FfajK9.mjs} +66 -10
- package/dist/EndpointFactory-D_FfajK9.mjs.map +1 -0
- package/dist/{HonoEndpointAdaptor-DANYfDu9.d.mts → HonoEndpointAdaptor-7hIKI32d.d.mts} +3 -3
- package/dist/{HonoEndpointAdaptor-_uLz8Bak.d.cts → HonoEndpointAdaptor-C9wC10-w.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/hono.d.cts +2 -2
- package/dist/adaptors/hono.d.mts +1 -1
- package/dist/adaptors/testing.d.cts +1 -1
- package/dist/crons/Cron.d.cts +1 -1
- package/dist/crons/CronBuilder.d.cts +1 -1
- package/dist/crons/index.d.cts +5 -5
- package/dist/crons/index.d.mts +4 -4
- package/dist/endpoints/AmazonApiGatewayEndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/AmazonApiGatewayV1EndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/AmazonApiGatewayV2EndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/Endpoint.d.cts +1 -1
- package/dist/endpoints/EndpointBuilder.cjs +1 -1
- package/dist/endpoints/EndpointBuilder.d.cts +2 -2
- package/dist/endpoints/EndpointBuilder.d.mts +1 -1
- 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 +2 -2
- package/dist/endpoints/EndpointFactory.mjs +2 -2
- package/dist/endpoints/HonoEndpointAdaptor.d.cts +2 -2
- package/dist/endpoints/HonoEndpointAdaptor.d.mts +1 -1
- package/dist/endpoints/TestEndpointAdaptor.d.cts +1 -1
- package/dist/endpoints/audit.d.cts +1 -1
- package/dist/endpoints/helpers.d.cts +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/functions/index.d.cts +1 -1
- package/dist/index-Doa8YPmH.d.cts +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.mjs +2 -2
- package/package.json +5 -5
- package/src/endpoints/EndpointBuilder.ts +23 -4
- package/src/endpoints/EndpointFactory.ts +224 -20
- package/src/endpoints/__tests__/EndpointFactory.database-auditor.spec.ts +413 -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-twsdbZWU.d.cts +0 -10
|
@@ -1,14 +1,14 @@
|
|
|
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';
|
|
5
8
|
import type { Authorizer } from './Authorizer';
|
|
6
9
|
import type { AuthorizeFn, SessionFn } from './Endpoint';
|
|
7
10
|
import { EndpointBuilder } from './EndpointBuilder';
|
|
8
11
|
|
|
9
|
-
import type { EventPublisher, MappedEvent } from '@geekmidas/events';
|
|
10
|
-
import type { HttpMethod } from '../types';
|
|
11
|
-
|
|
12
12
|
const DEFAULT_LOGGER = new ConsoleLogger() as any;
|
|
13
13
|
|
|
14
14
|
export class EndpointFactory<
|
|
@@ -19,6 +19,10 @@ export class EndpointFactory<
|
|
|
19
19
|
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
20
20
|
TEventPublisherServiceName extends string = string,
|
|
21
21
|
TAuthorizers extends readonly string[] = readonly string[],
|
|
22
|
+
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
23
|
+
TAuditStorageServiceName extends string = string,
|
|
24
|
+
TDatabase = undefined,
|
|
25
|
+
TDatabaseServiceName extends string = string,
|
|
22
26
|
> {
|
|
23
27
|
// @ts-ignore
|
|
24
28
|
private defaultServices: TServices;
|
|
@@ -31,6 +35,12 @@ export class EndpointFactory<
|
|
|
31
35
|
private defaultLogger: TLogger = DEFAULT_LOGGER;
|
|
32
36
|
private availableAuthorizers: Authorizer[] = [];
|
|
33
37
|
private defaultAuthorizerName?: TAuthorizers[number];
|
|
38
|
+
private defaultAuditorStorage:
|
|
39
|
+
| Service<TAuditStorageServiceName, TAuditStorage>
|
|
40
|
+
| undefined;
|
|
41
|
+
private defaultDatabaseService:
|
|
42
|
+
| Service<TDatabaseServiceName, TDatabase>
|
|
43
|
+
| undefined;
|
|
34
44
|
|
|
35
45
|
constructor({
|
|
36
46
|
basePath,
|
|
@@ -42,6 +52,8 @@ export class EndpointFactory<
|
|
|
42
52
|
defaultEventPublisher,
|
|
43
53
|
availableAuthorizers = [],
|
|
44
54
|
defaultAuthorizerName,
|
|
55
|
+
defaultAuditorStorage,
|
|
56
|
+
defaultDatabaseService,
|
|
45
57
|
}: EndpointFactoryOptions<
|
|
46
58
|
TServices,
|
|
47
59
|
TBasePath,
|
|
@@ -49,7 +61,11 @@ export class EndpointFactory<
|
|
|
49
61
|
TSession,
|
|
50
62
|
TEventPublisher,
|
|
51
63
|
TEventPublisherServiceName,
|
|
52
|
-
TAuthorizers
|
|
64
|
+
TAuthorizers,
|
|
65
|
+
TAuditStorage,
|
|
66
|
+
TAuditStorageServiceName,
|
|
67
|
+
TDatabase,
|
|
68
|
+
TDatabaseServiceName
|
|
53
69
|
> = {}) {
|
|
54
70
|
// Initialize default services
|
|
55
71
|
this.defaultServices = uniqBy(
|
|
@@ -64,6 +80,8 @@ export class EndpointFactory<
|
|
|
64
80
|
this.defaultEventPublisher = defaultEventPublisher;
|
|
65
81
|
this.availableAuthorizers = availableAuthorizers;
|
|
66
82
|
this.defaultAuthorizerName = defaultAuthorizerName;
|
|
83
|
+
this.defaultAuditorStorage = defaultAuditorStorage;
|
|
84
|
+
this.defaultDatabaseService = defaultDatabaseService;
|
|
67
85
|
}
|
|
68
86
|
|
|
69
87
|
static joinPaths<TBasePath extends string, P extends string>(
|
|
@@ -113,7 +131,11 @@ export class EndpointFactory<
|
|
|
113
131
|
TSession,
|
|
114
132
|
TEventPublisher,
|
|
115
133
|
TEventPublisherServiceName,
|
|
116
|
-
T
|
|
134
|
+
T,
|
|
135
|
+
TAuditStorage,
|
|
136
|
+
TAuditStorageServiceName,
|
|
137
|
+
TDatabase,
|
|
138
|
+
TDatabaseServiceName
|
|
117
139
|
> {
|
|
118
140
|
const authorizerConfigs = authorizers.map((name) => ({
|
|
119
141
|
name,
|
|
@@ -125,7 +147,11 @@ export class EndpointFactory<
|
|
|
125
147
|
TSession,
|
|
126
148
|
TEventPublisher,
|
|
127
149
|
TEventPublisherServiceName,
|
|
128
|
-
T
|
|
150
|
+
T,
|
|
151
|
+
TAuditStorage,
|
|
152
|
+
TAuditStorageServiceName,
|
|
153
|
+
TDatabase,
|
|
154
|
+
TDatabaseServiceName
|
|
129
155
|
>({
|
|
130
156
|
defaultServices: this.defaultServices,
|
|
131
157
|
basePath: this.basePath,
|
|
@@ -135,6 +161,8 @@ export class EndpointFactory<
|
|
|
135
161
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
136
162
|
availableAuthorizers: authorizerConfigs,
|
|
137
163
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
164
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
165
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
138
166
|
});
|
|
139
167
|
}
|
|
140
168
|
|
|
@@ -148,7 +176,11 @@ export class EndpointFactory<
|
|
|
148
176
|
TSession,
|
|
149
177
|
TEventPublisher,
|
|
150
178
|
TEventPublisherServiceName,
|
|
151
|
-
TAuthorizers
|
|
179
|
+
TAuthorizers,
|
|
180
|
+
TAuditStorage,
|
|
181
|
+
TAuditStorageServiceName,
|
|
182
|
+
TDatabase,
|
|
183
|
+
TDatabaseServiceName
|
|
152
184
|
> {
|
|
153
185
|
const newBasePath = EndpointFactory.joinPaths(path, this.basePath);
|
|
154
186
|
return new EndpointFactory<
|
|
@@ -158,7 +190,11 @@ export class EndpointFactory<
|
|
|
158
190
|
TSession,
|
|
159
191
|
TEventPublisher,
|
|
160
192
|
TEventPublisherServiceName,
|
|
161
|
-
TAuthorizers
|
|
193
|
+
TAuthorizers,
|
|
194
|
+
TAuditStorage,
|
|
195
|
+
TAuditStorageServiceName,
|
|
196
|
+
TDatabase,
|
|
197
|
+
TDatabaseServiceName
|
|
162
198
|
>({
|
|
163
199
|
defaultServices: this.defaultServices,
|
|
164
200
|
basePath: newBasePath,
|
|
@@ -168,6 +204,8 @@ export class EndpointFactory<
|
|
|
168
204
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
169
205
|
availableAuthorizers: this.availableAuthorizers,
|
|
170
206
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
207
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
208
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
171
209
|
});
|
|
172
210
|
}
|
|
173
211
|
|
|
@@ -181,7 +219,11 @@ export class EndpointFactory<
|
|
|
181
219
|
TSession,
|
|
182
220
|
TEventPublisher,
|
|
183
221
|
TEventPublisherServiceName,
|
|
184
|
-
TAuthorizers
|
|
222
|
+
TAuthorizers,
|
|
223
|
+
TAuditStorage,
|
|
224
|
+
TAuditStorageServiceName,
|
|
225
|
+
TDatabase,
|
|
226
|
+
TDatabaseServiceName
|
|
185
227
|
> {
|
|
186
228
|
return new EndpointFactory<
|
|
187
229
|
TServices,
|
|
@@ -190,7 +232,11 @@ export class EndpointFactory<
|
|
|
190
232
|
TSession,
|
|
191
233
|
TEventPublisher,
|
|
192
234
|
TEventPublisherServiceName,
|
|
193
|
-
TAuthorizers
|
|
235
|
+
TAuthorizers,
|
|
236
|
+
TAuditStorage,
|
|
237
|
+
TAuditStorageServiceName,
|
|
238
|
+
TDatabase,
|
|
239
|
+
TDatabaseServiceName
|
|
194
240
|
>({
|
|
195
241
|
defaultServices: this.defaultServices,
|
|
196
242
|
basePath: this.basePath,
|
|
@@ -200,6 +246,8 @@ export class EndpointFactory<
|
|
|
200
246
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
201
247
|
availableAuthorizers: this.availableAuthorizers,
|
|
202
248
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
249
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
250
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
203
251
|
});
|
|
204
252
|
}
|
|
205
253
|
|
|
@@ -213,7 +261,11 @@ export class EndpointFactory<
|
|
|
213
261
|
TSession,
|
|
214
262
|
TEventPublisher,
|
|
215
263
|
TEventPublisherServiceName,
|
|
216
|
-
TAuthorizers
|
|
264
|
+
TAuthorizers,
|
|
265
|
+
TAuditStorage,
|
|
266
|
+
TAuditStorageServiceName,
|
|
267
|
+
TDatabase,
|
|
268
|
+
TDatabaseServiceName
|
|
217
269
|
> {
|
|
218
270
|
return new EndpointFactory<
|
|
219
271
|
[...S, ...TServices],
|
|
@@ -222,7 +274,11 @@ export class EndpointFactory<
|
|
|
222
274
|
TSession,
|
|
223
275
|
TEventPublisher,
|
|
224
276
|
TEventPublisherServiceName,
|
|
225
|
-
TAuthorizers
|
|
277
|
+
TAuthorizers,
|
|
278
|
+
TAuditStorage,
|
|
279
|
+
TAuditStorageServiceName,
|
|
280
|
+
TDatabase,
|
|
281
|
+
TDatabaseServiceName
|
|
226
282
|
>({
|
|
227
283
|
defaultServices: [...services, ...this.defaultServices],
|
|
228
284
|
basePath: this.basePath,
|
|
@@ -232,6 +288,8 @@ export class EndpointFactory<
|
|
|
232
288
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
233
289
|
availableAuthorizers: this.availableAuthorizers,
|
|
234
290
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
291
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
292
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
235
293
|
});
|
|
236
294
|
}
|
|
237
295
|
|
|
@@ -244,7 +302,11 @@ export class EndpointFactory<
|
|
|
244
302
|
TSession,
|
|
245
303
|
TEventPublisher,
|
|
246
304
|
TEventPublisherServiceName,
|
|
247
|
-
TAuthorizers
|
|
305
|
+
TAuthorizers,
|
|
306
|
+
TAuditStorage,
|
|
307
|
+
TAuditStorageServiceName,
|
|
308
|
+
TDatabase,
|
|
309
|
+
TDatabaseServiceName
|
|
248
310
|
> {
|
|
249
311
|
return new EndpointFactory<
|
|
250
312
|
TServices,
|
|
@@ -253,7 +315,11 @@ export class EndpointFactory<
|
|
|
253
315
|
TSession,
|
|
254
316
|
TEventPublisher,
|
|
255
317
|
TEventPublisherServiceName,
|
|
256
|
-
TAuthorizers
|
|
318
|
+
TAuthorizers,
|
|
319
|
+
TAuditStorage,
|
|
320
|
+
TAuditStorageServiceName,
|
|
321
|
+
TDatabase,
|
|
322
|
+
TDatabaseServiceName
|
|
257
323
|
>({
|
|
258
324
|
defaultServices: this.defaultServices,
|
|
259
325
|
basePath: this.basePath,
|
|
@@ -272,6 +338,8 @@ export class EndpointFactory<
|
|
|
272
338
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
273
339
|
availableAuthorizers: this.availableAuthorizers,
|
|
274
340
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
341
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
342
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
275
343
|
});
|
|
276
344
|
}
|
|
277
345
|
|
|
@@ -287,7 +355,11 @@ export class EndpointFactory<
|
|
|
287
355
|
TSession,
|
|
288
356
|
T,
|
|
289
357
|
TServiceName,
|
|
290
|
-
TAuthorizers
|
|
358
|
+
TAuthorizers,
|
|
359
|
+
TAuditStorage,
|
|
360
|
+
TAuditStorageServiceName,
|
|
361
|
+
TDatabase,
|
|
362
|
+
TDatabaseServiceName
|
|
291
363
|
> {
|
|
292
364
|
return new EndpointFactory<
|
|
293
365
|
TServices,
|
|
@@ -296,7 +368,11 @@ export class EndpointFactory<
|
|
|
296
368
|
TSession,
|
|
297
369
|
T,
|
|
298
370
|
TServiceName,
|
|
299
|
-
TAuthorizers
|
|
371
|
+
TAuthorizers,
|
|
372
|
+
TAuditStorage,
|
|
373
|
+
TAuditStorageServiceName,
|
|
374
|
+
TDatabase,
|
|
375
|
+
TDatabaseServiceName
|
|
300
376
|
>({
|
|
301
377
|
defaultServices: this.defaultServices,
|
|
302
378
|
basePath: this.basePath,
|
|
@@ -306,6 +382,8 @@ export class EndpointFactory<
|
|
|
306
382
|
defaultEventPublisher: publisher,
|
|
307
383
|
availableAuthorizers: this.availableAuthorizers,
|
|
308
384
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
385
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
386
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
309
387
|
});
|
|
310
388
|
}
|
|
311
389
|
|
|
@@ -318,7 +396,11 @@ export class EndpointFactory<
|
|
|
318
396
|
T,
|
|
319
397
|
TEventPublisher,
|
|
320
398
|
TEventPublisherServiceName,
|
|
321
|
-
TAuthorizers
|
|
399
|
+
TAuthorizers,
|
|
400
|
+
TAuditStorage,
|
|
401
|
+
TAuditStorageServiceName,
|
|
402
|
+
TDatabase,
|
|
403
|
+
TDatabaseServiceName
|
|
322
404
|
> {
|
|
323
405
|
return new EndpointFactory<
|
|
324
406
|
TServices,
|
|
@@ -327,7 +409,11 @@ export class EndpointFactory<
|
|
|
327
409
|
T,
|
|
328
410
|
TEventPublisher,
|
|
329
411
|
TEventPublisherServiceName,
|
|
330
|
-
TAuthorizers
|
|
412
|
+
TAuthorizers,
|
|
413
|
+
TAuditStorage,
|
|
414
|
+
TAuditStorageServiceName,
|
|
415
|
+
TDatabase,
|
|
416
|
+
TDatabaseServiceName
|
|
331
417
|
>({
|
|
332
418
|
defaultServices: this.defaultServices,
|
|
333
419
|
basePath: this.basePath,
|
|
@@ -341,6 +427,98 @@ export class EndpointFactory<
|
|
|
341
427
|
defaultEventPublisher: this.defaultEventPublisher,
|
|
342
428
|
availableAuthorizers: this.availableAuthorizers,
|
|
343
429
|
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
430
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
431
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/**
|
|
436
|
+
* Set the database service for endpoints created from this factory.
|
|
437
|
+
* The database will be available in handler context as `db`.
|
|
438
|
+
*/
|
|
439
|
+
database<T, TName extends string>(
|
|
440
|
+
service: Service<TName, T>,
|
|
441
|
+
): EndpointFactory<
|
|
442
|
+
TServices,
|
|
443
|
+
TBasePath,
|
|
444
|
+
TLogger,
|
|
445
|
+
TSession,
|
|
446
|
+
TEventPublisher,
|
|
447
|
+
TEventPublisherServiceName,
|
|
448
|
+
TAuthorizers,
|
|
449
|
+
TAuditStorage,
|
|
450
|
+
TAuditStorageServiceName,
|
|
451
|
+
T,
|
|
452
|
+
TName
|
|
453
|
+
> {
|
|
454
|
+
return new 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
|
+
defaultServices: this.defaultServices,
|
|
468
|
+
basePath: this.basePath,
|
|
469
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
470
|
+
defaultLogger: this.defaultLogger,
|
|
471
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
472
|
+
defaultEventPublisher: this.defaultEventPublisher,
|
|
473
|
+
availableAuthorizers: this.availableAuthorizers,
|
|
474
|
+
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
475
|
+
defaultAuditorStorage: this.defaultAuditorStorage,
|
|
476
|
+
defaultDatabaseService: service,
|
|
477
|
+
});
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
/**
|
|
481
|
+
* Set the auditor storage service for endpoints created from this factory.
|
|
482
|
+
* This enables audit functionality and makes `auditor` available in handler context.
|
|
483
|
+
*/
|
|
484
|
+
auditor<T extends AuditStorage, TName extends string>(
|
|
485
|
+
storage: Service<TName, T>,
|
|
486
|
+
): EndpointFactory<
|
|
487
|
+
TServices,
|
|
488
|
+
TBasePath,
|
|
489
|
+
TLogger,
|
|
490
|
+
TSession,
|
|
491
|
+
TEventPublisher,
|
|
492
|
+
TEventPublisherServiceName,
|
|
493
|
+
TAuthorizers,
|
|
494
|
+
T,
|
|
495
|
+
TName,
|
|
496
|
+
TDatabase,
|
|
497
|
+
TDatabaseServiceName
|
|
498
|
+
> {
|
|
499
|
+
return new 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
|
+
defaultServices: this.defaultServices,
|
|
513
|
+
basePath: this.basePath,
|
|
514
|
+
defaultAuthorizeFn: this.defaultAuthorizeFn,
|
|
515
|
+
defaultLogger: this.defaultLogger,
|
|
516
|
+
defaultSessionExtractor: this.defaultSessionExtractor,
|
|
517
|
+
defaultEventPublisher: this.defaultEventPublisher,
|
|
518
|
+
availableAuthorizers: this.availableAuthorizers,
|
|
519
|
+
defaultAuthorizerName: this.defaultAuthorizerName,
|
|
520
|
+
defaultAuditorStorage: storage,
|
|
521
|
+
defaultDatabaseService: this.defaultDatabaseService,
|
|
344
522
|
});
|
|
345
523
|
}
|
|
346
524
|
|
|
@@ -357,7 +535,12 @@ export class EndpointFactory<
|
|
|
357
535
|
TSession,
|
|
358
536
|
TEventPublisher,
|
|
359
537
|
TEventPublisherServiceName,
|
|
360
|
-
TAuthorizers
|
|
538
|
+
TAuthorizers,
|
|
539
|
+
TAuditStorage,
|
|
540
|
+
TAuditStorageServiceName,
|
|
541
|
+
any,
|
|
542
|
+
TDatabase,
|
|
543
|
+
TDatabaseServiceName
|
|
361
544
|
> {
|
|
362
545
|
const fullPath = EndpointFactory.joinPaths(path, this.basePath);
|
|
363
546
|
const builder = new EndpointBuilder<
|
|
@@ -370,7 +553,12 @@ export class EndpointFactory<
|
|
|
370
553
|
TSession,
|
|
371
554
|
TEventPublisher,
|
|
372
555
|
TEventPublisherServiceName,
|
|
373
|
-
TAuthorizers
|
|
556
|
+
TAuthorizers,
|
|
557
|
+
TAuditStorage,
|
|
558
|
+
TAuditStorageServiceName,
|
|
559
|
+
any,
|
|
560
|
+
TDatabase,
|
|
561
|
+
TDatabaseServiceName
|
|
374
562
|
>(fullPath, method);
|
|
375
563
|
|
|
376
564
|
if (this.defaultAuthorizeFn) {
|
|
@@ -404,6 +592,16 @@ export class EndpointFactory<
|
|
|
404
592
|
builder._authorizerName = this.defaultAuthorizerName;
|
|
405
593
|
}
|
|
406
594
|
|
|
595
|
+
// Set auditor storage if configured
|
|
596
|
+
if (this.defaultAuditorStorage) {
|
|
597
|
+
builder._setAuditorStorage(this.defaultAuditorStorage as any);
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// Set database service if configured
|
|
601
|
+
if (this.defaultDatabaseService) {
|
|
602
|
+
builder._setDatabaseService(this.defaultDatabaseService as any);
|
|
603
|
+
}
|
|
604
|
+
|
|
407
605
|
return builder;
|
|
408
606
|
}
|
|
409
607
|
|
|
@@ -467,6 +665,10 @@ export interface EndpointFactoryOptions<
|
|
|
467
665
|
TEventPublisher extends EventPublisher<any> | undefined = undefined,
|
|
468
666
|
TEventPublisherServiceName extends string = string,
|
|
469
667
|
TAuthorizers extends readonly string[] = readonly string[],
|
|
668
|
+
TAuditStorage extends AuditStorage | undefined = undefined,
|
|
669
|
+
TAuditStorageServiceName extends string = string,
|
|
670
|
+
TDatabase = undefined,
|
|
671
|
+
TDatabaseServiceName extends string = string,
|
|
470
672
|
> {
|
|
471
673
|
defaultServices?: TServices;
|
|
472
674
|
basePath?: TBasePath;
|
|
@@ -477,6 +679,8 @@ export interface EndpointFactoryOptions<
|
|
|
477
679
|
defaultEvents?: MappedEvent<TEventPublisher, undefined>[];
|
|
478
680
|
availableAuthorizers?: Authorizer[];
|
|
479
681
|
defaultAuthorizerName?: TAuthorizers[number];
|
|
682
|
+
defaultAuditorStorage?: Service<TAuditStorageServiceName, TAuditStorage>;
|
|
683
|
+
defaultDatabaseService?: Service<TDatabaseServiceName, TDatabase>;
|
|
480
684
|
}
|
|
481
685
|
|
|
482
686
|
export const e = new EndpointFactory();
|