@privateaim/server-kit 0.8.7 → 0.8.9
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/CHANGELOG.md +41 -0
- package/dist/index.cjs +231 -124
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +227 -121
- package/dist/index.mjs.map +1 -1
- package/dist/services/authup/module.d.ts +1 -2
- package/dist/services/authup/module.d.ts.map +1 -1
- package/dist/services/authup/types.d.ts +2 -2
- package/dist/services/authup/types.d.ts.map +1 -1
- package/dist/services/authup-client-authentication-hook/index.d.ts +2 -0
- package/dist/services/authup-client-authentication-hook/index.d.ts.map +1 -0
- package/dist/services/authup-client-authentication-hook/singleton.d.ts +6 -0
- package/dist/services/authup-client-authentication-hook/singleton.d.ts.map +1 -0
- package/dist/services/domain-event/index.d.ts +6 -0
- package/dist/services/domain-event/index.d.ts.map +1 -0
- package/dist/services/domain-event/module.d.ts +9 -0
- package/dist/services/domain-event/module.d.ts.map +1 -0
- package/dist/services/domain-event/redis/index.d.ts +2 -0
- package/dist/services/domain-event/redis/index.d.ts.map +1 -0
- package/dist/services/domain-event/redis/module.d.ts +8 -0
- package/dist/services/domain-event/redis/module.d.ts.map +1 -0
- package/dist/services/domain-event/singleton.d.ts +3 -0
- package/dist/services/domain-event/singleton.d.ts.map +1 -0
- package/dist/services/domain-event/socket/index.d.ts +2 -0
- package/dist/services/domain-event/socket/index.d.ts.map +1 -0
- package/dist/services/domain-event/socket/module.d.ts +8 -0
- package/dist/services/domain-event/socket/module.d.ts.map +1 -0
- package/dist/services/domain-event/type.d.ts +15 -0
- package/dist/services/domain-event/type.d.ts.map +1 -0
- package/dist/services/domain-event/utils.d.ts +4 -0
- package/dist/services/domain-event/utils.d.ts.map +1 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.d.ts.map +1 -1
- package/package.json +10 -11
- package/src/index.ts +0 -1
- package/src/services/authup/module.ts +16 -18
- package/src/services/authup/types.ts +6 -2
- package/src/services/authup-client-authentication-hook/index.ts +8 -0
- package/src/services/authup-client-authentication-hook/singleton.ts +26 -0
- package/src/{domain-event → services/domain-event}/index.ts +2 -1
- package/src/services/domain-event/module.ts +40 -0
- package/src/{domain-event → services/domain-event}/redis/index.ts +1 -1
- package/src/services/domain-event/redis/module.ts +37 -0
- package/src/services/domain-event/singleton.ts +32 -0
- package/src/{domain-event → services/domain-event}/socket/index.ts +1 -1
- package/src/services/domain-event/socket/module.ts +57 -0
- package/src/{domain-event → services/domain-event}/type.ts +13 -0
- package/src/{domain-event → services/domain-event}/utils.ts +2 -2
- package/src/services/index.ts +2 -0
- package/dist/domain-event/index.d.ts +0 -5
- package/dist/domain-event/index.d.ts.map +0 -1
- package/dist/domain-event/publish.d.ts +0 -5
- package/dist/domain-event/publish.d.ts.map +0 -1
- package/dist/domain-event/redis/index.d.ts +0 -2
- package/dist/domain-event/redis/index.d.ts.map +0 -1
- package/dist/domain-event/redis/publish.d.ts +0 -5
- package/dist/domain-event/redis/publish.d.ts.map +0 -1
- package/dist/domain-event/socket/index.d.ts +0 -2
- package/dist/domain-event/socket/index.d.ts.map +0 -1
- package/dist/domain-event/socket/publish.d.ts +0 -5
- package/dist/domain-event/socket/publish.d.ts.map +0 -1
- package/dist/domain-event/type.d.ts +0 -7
- package/dist/domain-event/type.d.ts.map +0 -1
- package/dist/domain-event/utils.d.ts +0 -4
- package/dist/domain-event/utils.d.ts.map +0 -1
- package/src/domain-event/publish.ts +0 -21
- package/src/domain-event/redis/publish.ts +0 -41
- package/src/domain-event/socket/publish.ts +0 -60
package/dist/index.mjs
CHANGED
|
@@ -1,9 +1,8 @@
|
|
|
1
|
-
import { isObject, hasOwnProperty as hasOwnProperty$1, createNanoID } from '@privateaim/kit';
|
|
1
|
+
import { isObject, hasOwnProperty as hasOwnProperty$1, createNanoID, buildDomainEventFullName } from '@privateaim/kit';
|
|
2
2
|
import { ExchangeType } from 'amqp-extension';
|
|
3
3
|
import { singa } from 'singa';
|
|
4
4
|
export { VaultClient, createClient as createVaultClient } from '@hapic/vault';
|
|
5
|
-
import { Client,
|
|
6
|
-
export { mountClientResponseErrorTokenHook as mountAuthupClientResponseErrorTokenHook } from '@authup/core-http-kit';
|
|
5
|
+
import { Client, ClientAuthenticationHook } from '@authup/core-http-kit';
|
|
7
6
|
import { JsonAdapter, buildKeyPath } from 'redis-extension';
|
|
8
7
|
export { Client as RedisClient, ClientOptions as RedisClientOptions, buildKeyPath as buildRedisKeyPath, createClient as createRedisClient } from 'redis-extension';
|
|
9
8
|
import TTLCache from '@isaacs/ttlcache';
|
|
@@ -11,7 +10,6 @@ import { read } from 'envix';
|
|
|
11
10
|
import path from 'node:path';
|
|
12
11
|
import { EnvironmentName } from 'typeorm-extension';
|
|
13
12
|
import { transports, createLogger as createLogger$1, format } from 'winston';
|
|
14
|
-
import { DomainEventName, buildDomainEventFullName } from '@privateaim/core-kit';
|
|
15
13
|
import { Emitter } from '@socket.io/redis-emitter';
|
|
16
14
|
|
|
17
15
|
/*
|
|
@@ -19,7 +17,7 @@ import { Emitter } from '@socket.io/redis-emitter';
|
|
|
19
17
|
* Author Peter Placzek (tada5hi)
|
|
20
18
|
* For the full copyright and license information,
|
|
21
19
|
* view the LICENSE file that was distributed with this source code.
|
|
22
|
-
*/ function _define_property$
|
|
20
|
+
*/ function _define_property$7(obj, key, value) {
|
|
23
21
|
if (key in obj) {
|
|
24
22
|
Object.defineProperty(obj, key, {
|
|
25
23
|
value: value,
|
|
@@ -36,7 +34,7 @@ class ComponentError extends Error {
|
|
|
36
34
|
constructor(input){
|
|
37
35
|
super(input.message, {
|
|
38
36
|
cause: input.cause
|
|
39
|
-
}), _define_property$
|
|
37
|
+
}), _define_property$7(this, "code", void 0);
|
|
40
38
|
this.code = input.code;
|
|
41
39
|
}
|
|
42
40
|
}
|
|
@@ -84,30 +82,30 @@ function isQueueRouterPayload(input) {
|
|
|
84
82
|
return isObject(input) && typeof input.id === 'string' && typeof input.type === 'string' && hasOwnProperty$1(input, 'data') && isObject(input.data) && hasOwnProperty$1(input, 'metadata') && isObject(input.metadata);
|
|
85
83
|
}
|
|
86
84
|
|
|
87
|
-
const instance$
|
|
85
|
+
const instance$a = singa({
|
|
88
86
|
name: 'amqp'
|
|
89
87
|
});
|
|
90
88
|
function setAmqpClientFactory(factory) {
|
|
91
|
-
instance$
|
|
89
|
+
instance$a.setFactory(factory);
|
|
92
90
|
}
|
|
93
91
|
function isAmqpClientUsable() {
|
|
94
|
-
return instance$
|
|
92
|
+
return instance$a.has() || instance$a.hasFactory();
|
|
95
93
|
}
|
|
96
94
|
function useAmqpClient() {
|
|
97
|
-
return instance$
|
|
95
|
+
return instance$a.use();
|
|
98
96
|
}
|
|
99
97
|
|
|
100
|
-
const instance$
|
|
98
|
+
const instance$9 = singa({
|
|
101
99
|
name: 'vault'
|
|
102
100
|
});
|
|
103
101
|
function setVaultFactory(factory) {
|
|
104
|
-
instance$
|
|
102
|
+
instance$9.setFactory(factory);
|
|
105
103
|
}
|
|
106
104
|
function isVaultClientUsable() {
|
|
107
|
-
return instance$
|
|
105
|
+
return instance$9.has() || instance$9.hasFactory();
|
|
108
106
|
}
|
|
109
107
|
function useVaultClient() {
|
|
110
|
-
return instance$
|
|
108
|
+
return instance$9.use();
|
|
111
109
|
}
|
|
112
110
|
|
|
113
111
|
function guessAuthupTokenCreatorOptions() {
|
|
@@ -128,67 +126,76 @@ function guessAuthupTokenCreatorOptions() {
|
|
|
128
126
|
return options;
|
|
129
127
|
}
|
|
130
128
|
|
|
129
|
+
const instance$8 = singa({
|
|
130
|
+
name: 'clientAuthenticationHook'
|
|
131
|
+
});
|
|
132
|
+
function setClientAuthenticationHookFactory(factory) {
|
|
133
|
+
instance$8.setFactory(factory);
|
|
134
|
+
}
|
|
135
|
+
function isClientAuthenticationHookUsable() {
|
|
136
|
+
return instance$8.has() || instance$8.hasFactory();
|
|
137
|
+
}
|
|
138
|
+
function useClientAuthenticationHook() {
|
|
139
|
+
return instance$8.use();
|
|
140
|
+
}
|
|
141
|
+
|
|
131
142
|
class AuthupClient extends Client {
|
|
132
143
|
constructor(options = {}){
|
|
133
144
|
super(options);
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
const tokenCreator = guessAuthupTokenCreatorOptions();
|
|
140
|
-
tokenHook = {
|
|
141
|
-
baseURL: options.baseURL,
|
|
142
|
-
tokenCreator
|
|
143
|
-
};
|
|
145
|
+
if (!isClientAuthenticationHookUsable()) {
|
|
146
|
+
setClientAuthenticationHookFactory(()=>new ClientAuthenticationHook({
|
|
147
|
+
baseURL: options.baseURL,
|
|
148
|
+
tokenCreator: options.tokenCreator || guessAuthupTokenCreatorOptions()
|
|
149
|
+
}));
|
|
144
150
|
}
|
|
145
|
-
|
|
151
|
+
const hook = useClientAuthenticationHook();
|
|
152
|
+
hook.attach(this);
|
|
146
153
|
}
|
|
147
154
|
}
|
|
148
155
|
|
|
149
|
-
const instance$
|
|
156
|
+
const instance$7 = singa({
|
|
150
157
|
name: 'authup'
|
|
151
158
|
});
|
|
152
159
|
function useAuthupClient() {
|
|
153
|
-
return instance$
|
|
160
|
+
return instance$7.use();
|
|
154
161
|
}
|
|
155
162
|
function isAuthupClientUsable() {
|
|
156
|
-
return instance$
|
|
163
|
+
return instance$7.has() || instance$7.hasFactory();
|
|
157
164
|
}
|
|
158
165
|
function setAuthupClientFactory(factory) {
|
|
159
|
-
instance$
|
|
166
|
+
instance$7.setFactory(factory);
|
|
160
167
|
}
|
|
161
168
|
|
|
162
|
-
const instance$
|
|
169
|
+
const instance$6 = singa({
|
|
163
170
|
name: 'redis'
|
|
164
171
|
});
|
|
165
172
|
function setRedisFactory(factory) {
|
|
166
|
-
instance$
|
|
173
|
+
instance$6.setFactory(factory);
|
|
167
174
|
}
|
|
168
175
|
function isRedisClientUsable() {
|
|
169
|
-
return instance$
|
|
176
|
+
return instance$6.has() || instance$6.hasFactory();
|
|
170
177
|
}
|
|
171
178
|
function setRedisClient(input) {
|
|
172
|
-
instance$
|
|
179
|
+
instance$6.set(input);
|
|
173
180
|
}
|
|
174
181
|
function useRedisClient() {
|
|
175
|
-
return instance$
|
|
182
|
+
return instance$6.use();
|
|
176
183
|
}
|
|
177
184
|
|
|
178
|
-
const instance$
|
|
185
|
+
const instance$5 = singa({
|
|
179
186
|
name: 'redisPublish',
|
|
180
187
|
factory: ()=>useRedisClient().duplicate()
|
|
181
188
|
});
|
|
182
189
|
function useRedisPublishClient() {
|
|
183
|
-
return instance$
|
|
190
|
+
return instance$5.use();
|
|
184
191
|
}
|
|
185
192
|
|
|
186
|
-
const instance$
|
|
193
|
+
const instance$4 = singa({
|
|
187
194
|
name: 'redisSubscribe',
|
|
188
195
|
factory: ()=>useRedisClient().duplicate()
|
|
189
196
|
});
|
|
190
197
|
function useRedisSubscribeClient() {
|
|
191
|
-
return instance$
|
|
198
|
+
return instance$4.use();
|
|
192
199
|
}
|
|
193
200
|
|
|
194
201
|
/*
|
|
@@ -196,7 +203,7 @@ function useRedisSubscribeClient() {
|
|
|
196
203
|
* Author Peter Placzek (tada5hi)
|
|
197
204
|
* For the full copyright and license information,
|
|
198
205
|
* view the LICENSE file that was distributed with this source code.
|
|
199
|
-
*/ function _define_property$
|
|
206
|
+
*/ function _define_property$6(obj, key, value) {
|
|
200
207
|
if (key in obj) {
|
|
201
208
|
Object.defineProperty(obj, key, {
|
|
202
209
|
value: value,
|
|
@@ -244,7 +251,7 @@ class MemoryCacheAdapter {
|
|
|
244
251
|
this.instance.clear();
|
|
245
252
|
}
|
|
246
253
|
constructor(options = {}){
|
|
247
|
-
_define_property$
|
|
254
|
+
_define_property$6(this, "instance", void 0);
|
|
248
255
|
this.instance = new TTLCache({
|
|
249
256
|
checkAgeOnGet: true,
|
|
250
257
|
ttl: Infinity,
|
|
@@ -258,7 +265,7 @@ class MemoryCacheAdapter {
|
|
|
258
265
|
* Author Peter Placzek (tada5hi)
|
|
259
266
|
* For the full copyright and license information,
|
|
260
267
|
* view the LICENSE file that was distributed with this source code.
|
|
261
|
-
*/ function _define_property$
|
|
268
|
+
*/ function _define_property$5(obj, key, value) {
|
|
262
269
|
if (key in obj) {
|
|
263
270
|
Object.defineProperty(obj, key, {
|
|
264
271
|
value: value,
|
|
@@ -307,8 +314,8 @@ class RedisCacheAdapter {
|
|
|
307
314
|
await this.client.flushdb();
|
|
308
315
|
}
|
|
309
316
|
constructor(){
|
|
310
|
-
_define_property$
|
|
311
|
-
_define_property$
|
|
317
|
+
_define_property$5(this, "client", void 0);
|
|
318
|
+
_define_property$5(this, "instance", void 0);
|
|
312
319
|
this.client = useRedisClient();
|
|
313
320
|
this.instance = new JsonAdapter(this.client);
|
|
314
321
|
}
|
|
@@ -330,7 +337,7 @@ function buildCacheKey(options) {
|
|
|
330
337
|
* Author Peter Placzek (tada5hi)
|
|
331
338
|
* For the full copyright and license information,
|
|
332
339
|
* view the LICENSE file that was distributed with this source code.
|
|
333
|
-
*/ function _define_property$
|
|
340
|
+
*/ function _define_property$4(obj, key, value) {
|
|
334
341
|
if (key in obj) {
|
|
335
342
|
Object.defineProperty(obj, key, {
|
|
336
343
|
value: value,
|
|
@@ -363,12 +370,12 @@ class Cache {
|
|
|
363
370
|
return this.adapter.clear(options);
|
|
364
371
|
}
|
|
365
372
|
constructor(adapter){
|
|
366
|
-
_define_property$
|
|
373
|
+
_define_property$4(this, "adapter", void 0);
|
|
367
374
|
this.adapter = adapter;
|
|
368
375
|
}
|
|
369
376
|
}
|
|
370
377
|
|
|
371
|
-
const instance$
|
|
378
|
+
const instance$3 = singa({
|
|
372
379
|
name: 'cache',
|
|
373
380
|
factory: ()=>{
|
|
374
381
|
let adapter;
|
|
@@ -381,7 +388,7 @@ const instance$2 = singa({
|
|
|
381
388
|
}
|
|
382
389
|
});
|
|
383
390
|
function useCache() {
|
|
384
|
-
return instance$
|
|
391
|
+
return instance$3.use();
|
|
385
392
|
}
|
|
386
393
|
|
|
387
394
|
function createLogger(ctx = {}) {
|
|
@@ -423,19 +430,187 @@ function createLogger(ctx = {}) {
|
|
|
423
430
|
});
|
|
424
431
|
}
|
|
425
432
|
|
|
426
|
-
const instance$
|
|
433
|
+
const instance$2 = singa({
|
|
427
434
|
name: 'logger'
|
|
428
435
|
});
|
|
429
436
|
function setLoggerFactory(factory) {
|
|
430
|
-
instance$
|
|
437
|
+
instance$2.setFactory(factory);
|
|
431
438
|
}
|
|
432
439
|
function isLoggerUsable() {
|
|
433
|
-
return instance$
|
|
440
|
+
return instance$2.has() || instance$2.hasFactory();
|
|
434
441
|
}
|
|
435
442
|
function setLogger(input) {
|
|
436
|
-
instance$
|
|
443
|
+
instance$2.set(input);
|
|
437
444
|
}
|
|
438
445
|
function useLogger() {
|
|
446
|
+
return instance$2.use();
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
/*
|
|
450
|
+
* Copyright (c) 2024-2024.
|
|
451
|
+
* Author Peter Placzek (tada5hi)
|
|
452
|
+
* For the full copyright and license information,
|
|
453
|
+
* view the LICENSE file that was distributed with this source code.
|
|
454
|
+
*/ function _define_property$3(obj, key, value) {
|
|
455
|
+
if (key in obj) {
|
|
456
|
+
Object.defineProperty(obj, key, {
|
|
457
|
+
value: value,
|
|
458
|
+
enumerable: true,
|
|
459
|
+
configurable: true,
|
|
460
|
+
writable: true
|
|
461
|
+
});
|
|
462
|
+
} else {
|
|
463
|
+
obj[key] = value;
|
|
464
|
+
}
|
|
465
|
+
return obj;
|
|
466
|
+
}
|
|
467
|
+
class DomainEventPublisher {
|
|
468
|
+
addPublisher(publisher) {
|
|
469
|
+
this.publishers.add(publisher);
|
|
470
|
+
}
|
|
471
|
+
async publish(ctx) {
|
|
472
|
+
if (isLoggerUsable()) {
|
|
473
|
+
useLogger().info(`Publishing event ${ctx.data.event} for ${ctx.data.type}`);
|
|
474
|
+
}
|
|
475
|
+
const publishers = this.publishers.values();
|
|
476
|
+
while(true){
|
|
477
|
+
const it = publishers.next();
|
|
478
|
+
if (it.done) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
await it.value.publish(ctx);
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
constructor(){
|
|
485
|
+
_define_property$3(this, "publishers", void 0);
|
|
486
|
+
this.publishers = new Set();
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
function transformEventData(input) {
|
|
491
|
+
if (isObject(input)) {
|
|
492
|
+
const keys = Object.keys(input);
|
|
493
|
+
for(let i = 0; i < keys.length; i++){
|
|
494
|
+
const value = input[keys[i]];
|
|
495
|
+
if (value instanceof Date) {
|
|
496
|
+
input[keys[i]] = value.toISOString();
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
return input;
|
|
501
|
+
}
|
|
502
|
+
function buildEventChannelName(input, id) {
|
|
503
|
+
if (typeof input === 'string') {
|
|
504
|
+
return input;
|
|
505
|
+
}
|
|
506
|
+
return input(id);
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/*
|
|
510
|
+
* Copyright (c) 2023-2024.
|
|
511
|
+
* Author Peter Placzek (tada5hi)
|
|
512
|
+
* For the full copyright and license information,
|
|
513
|
+
* view the LICENSE file that was distributed with this source code.
|
|
514
|
+
*/ function _define_property$2(obj, key, value) {
|
|
515
|
+
if (key in obj) {
|
|
516
|
+
Object.defineProperty(obj, key, {
|
|
517
|
+
value: value,
|
|
518
|
+
enumerable: true,
|
|
519
|
+
configurable: true,
|
|
520
|
+
writable: true
|
|
521
|
+
});
|
|
522
|
+
} else {
|
|
523
|
+
obj[key] = value;
|
|
524
|
+
}
|
|
525
|
+
return obj;
|
|
526
|
+
}
|
|
527
|
+
class DomainEventRedisPublisher {
|
|
528
|
+
async publish(ctx) {
|
|
529
|
+
const data = JSON.stringify(transformEventData(ctx.data));
|
|
530
|
+
const pipeline = this.driver.pipeline();
|
|
531
|
+
for(let i = 0; i < ctx.destinations.length; i++){
|
|
532
|
+
const keyPrefix = ctx.destinations[i].namespace ? `${ctx.destinations[i].namespace}:` : '';
|
|
533
|
+
let key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel);
|
|
534
|
+
pipeline.publish(key, data);
|
|
535
|
+
if (typeof ctx.destinations[i].channel === 'function') {
|
|
536
|
+
key = keyPrefix + buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id);
|
|
537
|
+
pipeline.publish(key, data);
|
|
538
|
+
}
|
|
539
|
+
}
|
|
540
|
+
await pipeline.exec();
|
|
541
|
+
}
|
|
542
|
+
constructor(client){
|
|
543
|
+
_define_property$2(this, "driver", void 0);
|
|
544
|
+
this.driver = client;
|
|
545
|
+
}
|
|
546
|
+
}
|
|
547
|
+
|
|
548
|
+
/*
|
|
549
|
+
* Copyright (c) 2022-2024.
|
|
550
|
+
* Author Peter Placzek (tada5hi)
|
|
551
|
+
* For the full copyright and license information,
|
|
552
|
+
* view the LICENSE file that was distributed with this source code.
|
|
553
|
+
*/ function _define_property$1(obj, key, value) {
|
|
554
|
+
if (key in obj) {
|
|
555
|
+
Object.defineProperty(obj, key, {
|
|
556
|
+
value: value,
|
|
557
|
+
enumerable: true,
|
|
558
|
+
configurable: true,
|
|
559
|
+
writable: true
|
|
560
|
+
});
|
|
561
|
+
} else {
|
|
562
|
+
obj[key] = value;
|
|
563
|
+
}
|
|
564
|
+
return obj;
|
|
565
|
+
}
|
|
566
|
+
class DomainEventSocketPublisher {
|
|
567
|
+
async publish(ctx) {
|
|
568
|
+
ctx.data = transformEventData(ctx.data);
|
|
569
|
+
for(let i = 0; i < ctx.destinations.length; i++){
|
|
570
|
+
let namespace;
|
|
571
|
+
if (ctx.destinations[i].namespace) {
|
|
572
|
+
namespace = ctx.destinations[i].namespace;
|
|
573
|
+
} else {
|
|
574
|
+
namespace = '/';
|
|
575
|
+
}
|
|
576
|
+
const emitter = new Emitter(this.client, {}, namespace);
|
|
577
|
+
const fullEventName = buildDomainEventFullName(ctx.data.type, ctx.data.event);
|
|
578
|
+
const rooms = [
|
|
579
|
+
buildEventChannelName(ctx.destinations[i].channel)
|
|
580
|
+
];
|
|
581
|
+
if (typeof ctx.destinations[i].channel === 'function') {
|
|
582
|
+
rooms.push(buildEventChannelName(ctx.destinations[i].channel, ctx.data.data.id));
|
|
583
|
+
}
|
|
584
|
+
for(let j = 0; j < rooms.length; j++){
|
|
585
|
+
emitter.in(rooms[j]).emit(fullEventName, {
|
|
586
|
+
...ctx.data,
|
|
587
|
+
meta: {
|
|
588
|
+
namespace,
|
|
589
|
+
roomName: rooms[j]
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
constructor(client){
|
|
596
|
+
_define_property$1(this, "client", void 0);
|
|
597
|
+
this.client = client;
|
|
598
|
+
}
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
const instance$1 = singa({
|
|
602
|
+
name: 'domainEventPublisher',
|
|
603
|
+
factory: ()=>{
|
|
604
|
+
const publisher = new DomainEventPublisher();
|
|
605
|
+
if (isRedisClientUsable()) {
|
|
606
|
+
const client = useRedisClient();
|
|
607
|
+
publisher.addPublisher(new DomainEventRedisPublisher(client));
|
|
608
|
+
publisher.addPublisher(new DomainEventSocketPublisher(client));
|
|
609
|
+
}
|
|
610
|
+
return publisher;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
function useDomainEventPublisher() {
|
|
439
614
|
return instance$1.use();
|
|
440
615
|
}
|
|
441
616
|
|
|
@@ -550,75 +725,6 @@ function useQueueRouter() {
|
|
|
550
725
|
return instance.use();
|
|
551
726
|
}
|
|
552
727
|
|
|
553
|
-
function transformDomainEventData(input) {
|
|
554
|
-
if (isObject(input)) {
|
|
555
|
-
const keys = Object.keys(input);
|
|
556
|
-
for(let i = 0; i < keys.length; i++){
|
|
557
|
-
const value = input[keys[i]];
|
|
558
|
-
if (value instanceof Date) {
|
|
559
|
-
input[keys[i]] = value.toISOString();
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
return input;
|
|
564
|
-
}
|
|
565
|
-
function buildDomainEventChannelName(input, id) {
|
|
566
|
-
if (typeof input === 'string') {
|
|
567
|
-
return input;
|
|
568
|
-
}
|
|
569
|
-
return input(id);
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
async function publishDomainRedisEvent(client, context, destinations) {
|
|
573
|
-
context = transformDomainEventData(context);
|
|
574
|
-
const json = JSON.stringify(context);
|
|
575
|
-
const pipeline = client.pipeline();
|
|
576
|
-
for(let i = 0; i < destinations.length; i++){
|
|
577
|
-
const { namespace } = destinations[i];
|
|
578
|
-
const keyPrefix = namespace ? `${namespace}:` : '';
|
|
579
|
-
let key = keyPrefix + buildDomainEventChannelName(destinations[i].channel);
|
|
580
|
-
pipeline.publish(key, json);
|
|
581
|
-
if (context.event !== DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
582
|
-
key = keyPrefix + buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
583
|
-
pipeline.publish(key, json);
|
|
584
|
-
}
|
|
585
|
-
}
|
|
586
|
-
return pipeline.exec();
|
|
587
|
-
}
|
|
588
|
-
|
|
589
|
-
function publishDomainSocketEvent(client, context, destinations) {
|
|
590
|
-
context = transformDomainEventData(context);
|
|
591
|
-
for(let i = 0; i < destinations.length; i++){
|
|
592
|
-
let emitter = new Emitter(client);
|
|
593
|
-
if (destinations[i].namespace) {
|
|
594
|
-
emitter = emitter.of(destinations[i].namespace);
|
|
595
|
-
}
|
|
596
|
-
let roomName = buildDomainEventChannelName(destinations[i].channel);
|
|
597
|
-
const fullEventName = buildDomainEventFullName(context.type, context.event);
|
|
598
|
-
emitter.in(roomName).emit(fullEventName, {
|
|
599
|
-
...context,
|
|
600
|
-
meta: {
|
|
601
|
-
roomName
|
|
602
|
-
}
|
|
603
|
-
});
|
|
604
|
-
if (context.event !== DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
605
|
-
roomName = buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
606
|
-
emitter.in(roomName).emit(fullEventName, {
|
|
607
|
-
...context,
|
|
608
|
-
meta: {
|
|
609
|
-
roomName,
|
|
610
|
-
roomId: context.data.id
|
|
611
|
-
}
|
|
612
|
-
});
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
}
|
|
616
|
-
|
|
617
|
-
async function publishDomainEvent(client, context, destinations) {
|
|
618
|
-
await publishDomainRedisEvent(client, context, destinations);
|
|
619
|
-
publishDomainSocketEvent(client, context, destinations);
|
|
620
|
-
}
|
|
621
|
-
|
|
622
728
|
/*
|
|
623
729
|
* Copyright (c) 2022-2024.
|
|
624
730
|
* Author Peter Placzek (tada5hi)
|
|
@@ -628,5 +734,5 @@ async function publishDomainEvent(client, context, destinations) {
|
|
|
628
734
|
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
629
735
|
}
|
|
630
736
|
|
|
631
|
-
export { AuthupClient, Cache, ComponentError, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildQueueRouterPublishPayload, createCacheAdapter, createLogger, guessAuthupTokenCreatorOptions, hasOwnProperty, isAmqpClientUsable, isAuthupClientUsable, isComponentError, isLoggerUsable, isQueuePayload, isQueueRouterPayload, isQueueRouterUsable, isRedisClientUsable, isVaultClientUsable,
|
|
737
|
+
export { AuthupClient, Cache, ComponentError, DomainEventPublisher, DomainEventRedisPublisher, DomainEventSocketPublisher, MemoryCacheAdapter, QueueRouter, QueueRouterRoutingType, RedisCacheAdapter, buildCacheKey, buildQueueRouterPublishPayload, createCacheAdapter, createLogger, guessAuthupTokenCreatorOptions, hasOwnProperty, isAmqpClientUsable, isAuthupClientUsable, isClientAuthenticationHookUsable, isComponentError, isLoggerUsable, isQueuePayload, isQueueRouterPayload, isQueueRouterUsable, isRedisClientUsable, isVaultClientUsable, setAmqpClientFactory, setAuthupClientFactory, setClientAuthenticationHookFactory, setLogger, setLoggerFactory, setRedisClient, setRedisFactory, setVaultFactory, useAmqpClient, useAuthupClient, useCache, useClientAuthenticationHook, useDomainEventPublisher, useLogger, useQueueRouter, useRedisClient, useRedisPublishClient, useRedisSubscribeClient, useVaultClient };
|
|
632
738
|
//# sourceMappingURL=index.mjs.map
|