@xeno-js/core 2.0.1 → 2.0.2
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/index.cjs +439 -470
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -41
- package/dist/index.d.ts +2 -41
- package/dist/index.js +42 -74
- package/dist/index.js.map +1 -1
- package/package.json +7 -1
package/dist/index.cjs
CHANGED
|
@@ -86,40 +86,13 @@ var init_containers = __esm({
|
|
|
86
86
|
}
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
// src/application/cqrs/base-handler.ts
|
|
90
|
-
var import_shared2, BaseHandler;
|
|
91
|
-
var init_base_handler = __esm({
|
|
92
|
-
"src/application/cqrs/base-handler.ts"() {
|
|
93
|
-
"use strict";
|
|
94
|
-
import_shared2 = require("@xeno-js/shared");
|
|
95
|
-
BaseHandler = class {
|
|
96
|
-
constructor(_identityFactory) {
|
|
97
|
-
this._identityFactory = _identityFactory;
|
|
98
|
-
}
|
|
99
|
-
_identityFactory;
|
|
100
|
-
async handle(request, signal) {
|
|
101
|
-
import_shared2.AppError.throwIfAborted(signal, this.constructor.name);
|
|
102
|
-
return await this.executeAsync(request, signal);
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Gets the current context.
|
|
106
|
-
* @returns {UserContext} The current context.
|
|
107
|
-
* {@link UserContext}
|
|
108
|
-
*/
|
|
109
|
-
_getCurrentContext() {
|
|
110
|
-
return this._identityFactory.create();
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
}
|
|
114
|
-
});
|
|
115
|
-
|
|
116
89
|
// src/application/cqrs/mediator.ts
|
|
117
|
-
var
|
|
90
|
+
var import_shared2, import_shared3, Mediator;
|
|
118
91
|
var init_mediator = __esm({
|
|
119
92
|
"src/application/cqrs/mediator.ts"() {
|
|
120
93
|
"use strict";
|
|
94
|
+
import_shared2 = require("@xeno-js/shared");
|
|
121
95
|
import_shared3 = require("@xeno-js/shared");
|
|
122
|
-
import_shared4 = require("@xeno-js/shared");
|
|
123
96
|
Mediator = class {
|
|
124
97
|
/**
|
|
125
98
|
* @param _factoryScope - An instance of IServiceScopeAccessor used to access the current service scope, which is necessary for resolving handlers and pipeline behaviors for processing requests.
|
|
@@ -144,7 +117,7 @@ var init_mediator = __esm({
|
|
|
144
117
|
* @link https://github.com/xeno-js/xeno-js
|
|
145
118
|
*/
|
|
146
119
|
async send(request, signal) {
|
|
147
|
-
return this.process(request,
|
|
120
|
+
return this.process(request, import_shared3.TOKENS.COMMAND_PIPELINES_BEHAVIOR, signal);
|
|
148
121
|
}
|
|
149
122
|
/**
|
|
150
123
|
* @inheritdoc
|
|
@@ -155,7 +128,7 @@ var init_mediator = __esm({
|
|
|
155
128
|
* @link https://github.com/xeno-js/xeno-js
|
|
156
129
|
*/
|
|
157
130
|
async query(request, signal) {
|
|
158
|
-
return this.process(request,
|
|
131
|
+
return this.process(request, import_shared3.TOKENS.QUERY_PIPELINES_BEHAVIOR, signal);
|
|
159
132
|
}
|
|
160
133
|
/**
|
|
161
134
|
* @description Internal method to process both commands and queries. It resolves the appropriate handler for the request and applies the registered pipeline behaviors in the correct order.
|
|
@@ -171,39 +144,39 @@ var init_mediator = __esm({
|
|
|
171
144
|
* @link https://github.com/xeno-js/xeno-js
|
|
172
145
|
*/
|
|
173
146
|
async process(request, pipelineToken, signal) {
|
|
174
|
-
if (
|
|
175
|
-
return
|
|
147
|
+
if (import_shared3.Guards.isDefined(signal) && signal.aborted)
|
|
148
|
+
return import_shared2.Result.fail(import_shared2.AppError.aborted(request.intent));
|
|
176
149
|
const scope = this._factoryScope.getScope();
|
|
177
|
-
if (!
|
|
178
|
-
return
|
|
179
|
-
|
|
180
|
-
code:
|
|
181
|
-
status:
|
|
150
|
+
if (!import_shared3.Guards.isDefined(scope))
|
|
151
|
+
return import_shared2.Result.fail(
|
|
152
|
+
import_shared2.AppError.create({
|
|
153
|
+
code: import_shared3.ERROR_CODES.SCOPE_NOT_AVAILABLE,
|
|
154
|
+
status: import_shared3.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
182
155
|
name: request.intent,
|
|
183
|
-
message:
|
|
156
|
+
message: import_shared3.ERROR_CODE_MESSAGES[import_shared3.ERROR_CODES.SCOPE_NOT_AVAILABLE],
|
|
184
157
|
cause: new Error("Service scope is required to process the request.")
|
|
185
158
|
})
|
|
186
159
|
);
|
|
187
160
|
const pipelines = scope.resolve(pipelineToken);
|
|
188
|
-
if (!
|
|
189
|
-
return
|
|
190
|
-
|
|
191
|
-
code:
|
|
192
|
-
status:
|
|
161
|
+
if (!import_shared3.Guards.isDefined(pipelines) || !import_shared3.Guards.hasMethod(pipelines, "handle")) {
|
|
162
|
+
return import_shared2.Result.fail(
|
|
163
|
+
import_shared2.AppError.create({
|
|
164
|
+
code: import_shared3.ERROR_CODES.PIPELINE_NOT_AVAILABLE,
|
|
165
|
+
status: import_shared3.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
193
166
|
name: request.intent,
|
|
194
|
-
message:
|
|
167
|
+
message: import_shared3.ERROR_CODE_MESSAGES[import_shared3.ERROR_CODES.PIPELINE_NOT_AVAILABLE],
|
|
195
168
|
cause: new Error("Pipeline behavior is required to process the request.")
|
|
196
169
|
})
|
|
197
170
|
);
|
|
198
171
|
}
|
|
199
172
|
const next = () => {
|
|
200
173
|
const handler = scope.resolve(request.intent);
|
|
201
|
-
if (!
|
|
202
|
-
|
|
203
|
-
code:
|
|
204
|
-
status:
|
|
174
|
+
if (!import_shared3.Guards.isDefined(handler) || !import_shared3.Guards.hasMethod(handler, "handle")) {
|
|
175
|
+
import_shared2.AppError.throw({
|
|
176
|
+
code: import_shared3.ERROR_CODES.HANDLER_NOT_FOUND,
|
|
177
|
+
status: import_shared3.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
205
178
|
name: request.intent,
|
|
206
|
-
message:
|
|
179
|
+
message: import_shared3.ERROR_CODE_MESSAGES[import_shared3.ERROR_CODES.HANDLER_NOT_FOUND],
|
|
207
180
|
cause: new Error("Handler is required to process the request.")
|
|
208
181
|
});
|
|
209
182
|
}
|
|
@@ -216,11 +189,11 @@ var init_mediator = __esm({
|
|
|
216
189
|
});
|
|
217
190
|
|
|
218
191
|
// src/application/cqrs/pipelines/authorization.pipeline.ts
|
|
219
|
-
var
|
|
192
|
+
var import_shared4, AuthorizationPipeline;
|
|
220
193
|
var init_authorization_pipeline = __esm({
|
|
221
194
|
"src/application/cqrs/pipelines/authorization.pipeline.ts"() {
|
|
222
195
|
"use strict";
|
|
223
|
-
|
|
196
|
+
import_shared4 = require("@xeno-js/shared");
|
|
224
197
|
AuthorizationPipeline = class {
|
|
225
198
|
/**
|
|
226
199
|
* @description Costruisce una nuova istanza di AuthorizationPipeline, accettando un array di strategie di autorizzazione. Ogni strategia rappresenta una regola o un criterio specifico per determinare se un comando è autorizzato o meno. Durante l'esecuzione del pipeline, ogni strategia viene valutata in ordine, e se una qualsiasi strategia determina che il comando non è autorizzato, il pipeline restituisce un risultato di fallimento con l'errore corrispondente. Se tutte le strategie passano, il pipeline delega al prossimo comportamento nella catena.
|
|
@@ -239,7 +212,7 @@ var init_authorization_pipeline = __esm({
|
|
|
239
212
|
for (const strategy of this._strategies) {
|
|
240
213
|
const result = await strategy.execute(request);
|
|
241
214
|
if (!result.isOk()) {
|
|
242
|
-
return
|
|
215
|
+
return import_shared4.Result.fail(result.getErrorOrThrow());
|
|
243
216
|
}
|
|
244
217
|
}
|
|
245
218
|
return next();
|
|
@@ -281,12 +254,12 @@ var init_composite_pipeline = __esm({
|
|
|
281
254
|
});
|
|
282
255
|
|
|
283
256
|
// src/application/cqrs/pipelines/concurrency-retry.pipeline.ts
|
|
284
|
-
var
|
|
257
|
+
var import_shared5, import_shared6, ConcurrencyRetryPipeline;
|
|
285
258
|
var init_concurrency_retry_pipeline = __esm({
|
|
286
259
|
"src/application/cqrs/pipelines/concurrency-retry.pipeline.ts"() {
|
|
287
260
|
"use strict";
|
|
261
|
+
import_shared5 = require("@xeno-js/shared");
|
|
288
262
|
import_shared6 = require("@xeno-js/shared");
|
|
289
|
-
import_shared7 = require("@xeno-js/shared");
|
|
290
263
|
ConcurrencyRetryPipeline = class {
|
|
291
264
|
/**
|
|
292
265
|
* @description Configuration for the retry mechanism, including the base delay and maximum jitter for calculating the delay between retry attempts, as well as the maximum number of retry attempts allowed before giving up and returning a failed Result with an AppError indicating the concurrency conflict.
|
|
@@ -317,9 +290,9 @@ var init_concurrency_retry_pipeline = __esm({
|
|
|
317
290
|
* @since 2025-09-30
|
|
318
291
|
* @link https://github.com/xeno-js/xeno-js
|
|
319
292
|
*/
|
|
320
|
-
constructor(maxRetries =
|
|
321
|
-
baseDelayMs:
|
|
322
|
-
maxJitterMs:
|
|
293
|
+
constructor(maxRetries = import_shared6.DEFAULT_CONCURRENCY.MAX_RETRIES, delayConfig = {
|
|
294
|
+
baseDelayMs: import_shared6.DEFAULT_CONCURRENCY.BASE_DELAY,
|
|
295
|
+
maxJitterMs: import_shared6.DEFAULT_CONCURRENCY.MAX_JITTER
|
|
323
296
|
}) {
|
|
324
297
|
const values = [maxRetries, delayConfig?.baseDelayMs, delayConfig?.maxJitterMs];
|
|
325
298
|
const errorMessages = [
|
|
@@ -328,8 +301,8 @@ var init_concurrency_retry_pipeline = __esm({
|
|
|
328
301
|
`Invalid maxJitterMs value: ${delayConfig.maxJitterMs}. It must be a non-negative integer.`
|
|
329
302
|
];
|
|
330
303
|
values.forEach((value, index) => {
|
|
331
|
-
|
|
332
|
-
|
|
304
|
+
import_shared6.Guards.throwIfNotInteger(value, errorMessages[index]);
|
|
305
|
+
import_shared6.Guards.throwIfNegative(value, errorMessages[index]);
|
|
333
306
|
if (index === 0 && value === 0) {
|
|
334
307
|
throw new Error(errorMessages[index]);
|
|
335
308
|
}
|
|
@@ -355,14 +328,14 @@ var init_concurrency_retry_pipeline = __esm({
|
|
|
355
328
|
const result = await next();
|
|
356
329
|
if (result.isOk() || !this.isConcurrencyError(result.getErrorOrThrow())) return result;
|
|
357
330
|
if (attempts >= this._maxRetries)
|
|
358
|
-
return
|
|
359
|
-
|
|
331
|
+
return import_shared5.Result.fail(
|
|
332
|
+
import_shared5.AppError.conflict(
|
|
360
333
|
request.intent,
|
|
361
334
|
`Maximum retry attempts (${this._maxRetries}) exceeded due to concurrency conflicts.`
|
|
362
335
|
)
|
|
363
336
|
);
|
|
364
337
|
const { baseDelayMs, maxJitterMs } = this._delayConfig;
|
|
365
|
-
await
|
|
338
|
+
await import_shared6.PromiseHelper.delayWithJitter(baseDelayMs, maxJitterMs);
|
|
366
339
|
}
|
|
367
340
|
}
|
|
368
341
|
/**
|
|
@@ -376,33 +349,33 @@ var init_concurrency_retry_pipeline = __esm({
|
|
|
376
349
|
* @link https://github.com/xeno-js/xeno-js
|
|
377
350
|
*/
|
|
378
351
|
isConcurrencyError(error) {
|
|
379
|
-
return error.code ===
|
|
352
|
+
return error.code === import_shared6.ERROR_CODES.CONFLICT && error.status === import_shared6.STATUS_CODES.CONFLICT;
|
|
380
353
|
}
|
|
381
354
|
};
|
|
382
355
|
}
|
|
383
356
|
});
|
|
384
357
|
|
|
385
358
|
// src/application/cqrs/pipelines/exception.pipeline.ts
|
|
386
|
-
var
|
|
359
|
+
var import_shared7, import_shared8, ExceptionPipeline;
|
|
387
360
|
var init_exception_pipeline = __esm({
|
|
388
361
|
"src/application/cqrs/pipelines/exception.pipeline.ts"() {
|
|
389
362
|
"use strict";
|
|
363
|
+
import_shared7 = require("@xeno-js/shared");
|
|
390
364
|
import_shared8 = require("@xeno-js/shared");
|
|
391
|
-
import_shared9 = require("@xeno-js/shared");
|
|
392
365
|
ExceptionPipeline = class {
|
|
393
366
|
async handle(request, next) {
|
|
394
367
|
try {
|
|
395
368
|
return await next();
|
|
396
369
|
} catch (error) {
|
|
397
|
-
if (error instanceof
|
|
398
|
-
const appError =
|
|
399
|
-
code:
|
|
400
|
-
message:
|
|
401
|
-
status:
|
|
370
|
+
if (error instanceof import_shared7.AppError) return import_shared7.Result.fail(error);
|
|
371
|
+
const appError = import_shared7.AppError.create({
|
|
372
|
+
code: import_shared8.ERROR_CODES.SYSTEM_ERROR,
|
|
373
|
+
message: import_shared8.ERROR_CODE_MESSAGES[import_shared8.ERROR_CODES.SYSTEM_ERROR],
|
|
374
|
+
status: import_shared8.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
402
375
|
name: request.intent,
|
|
403
376
|
cause: error
|
|
404
377
|
});
|
|
405
|
-
return
|
|
378
|
+
return import_shared7.Result.fail(appError);
|
|
406
379
|
}
|
|
407
380
|
}
|
|
408
381
|
};
|
|
@@ -410,12 +383,12 @@ var init_exception_pipeline = __esm({
|
|
|
410
383
|
});
|
|
411
384
|
|
|
412
385
|
// src/application/cqrs/pipelines/idempotency.pipeline.ts
|
|
413
|
-
var
|
|
386
|
+
var import_shared9, import_shared10, IdempotencyPipeline;
|
|
414
387
|
var init_idempotency_pipeline = __esm({
|
|
415
388
|
"src/application/cqrs/pipelines/idempotency.pipeline.ts"() {
|
|
416
389
|
"use strict";
|
|
390
|
+
import_shared9 = require("@xeno-js/shared");
|
|
417
391
|
import_shared10 = require("@xeno-js/shared");
|
|
418
|
-
import_shared11 = require("@xeno-js/shared");
|
|
419
392
|
IdempotencyPipeline = class {
|
|
420
393
|
/**
|
|
421
394
|
* @description Constructs a new instance of the IdempotencyPipeline class, which requires an IIdempotencyStore for managing locks and storing results of processed commands. The constructor also accepts optional parameters for configuring the TTL (time-to-live) values for locks and processed results, allowing for customization of the idempotency behavior based on the specific needs of the application. The constructor validates the input parameters to ensure that they are positive integers and throws an error if they are not, ensuring that the pipeline is configured with valid TTL values for proper functioning of the idempotency mechanism.
|
|
@@ -430,7 +403,7 @@ var init_idempotency_pipeline = __esm({
|
|
|
430
403
|
* @since 2025-09-30
|
|
431
404
|
* @link https://github.com/xeno-js/xeno-js
|
|
432
405
|
*/
|
|
433
|
-
constructor(_requestContextFactory, _idempotencyStore, lockTtlSeconds =
|
|
406
|
+
constructor(_requestContextFactory, _idempotencyStore, lockTtlSeconds = import_shared10.IDEMPOTENCY_CONSTANTS.DEFAULT_IDEMPOTENCY_LOCK_TTL_SECONDS, processedTtlSeconds = import_shared10.IDEMPOTENCY_CONSTANTS.DEFAULT_TTL_SECONDS) {
|
|
434
407
|
this._requestContextFactory = _requestContextFactory;
|
|
435
408
|
this._idempotencyStore = _idempotencyStore;
|
|
436
409
|
const values = [lockTtlSeconds, processedTtlSeconds];
|
|
@@ -439,8 +412,8 @@ var init_idempotency_pipeline = __esm({
|
|
|
439
412
|
`Invalid processedTtlSeconds value: ${processedTtlSeconds}. It must be a positive integer.`
|
|
440
413
|
];
|
|
441
414
|
values.forEach((value, index) => {
|
|
442
|
-
|
|
443
|
-
|
|
415
|
+
import_shared10.Guards.throwIfNotInteger(value, errorMessages[index]);
|
|
416
|
+
import_shared10.Guards.throwIfNegative(value, errorMessages[index]);
|
|
444
417
|
if (value === 0) {
|
|
445
418
|
throw new Error(errorMessages[index]);
|
|
446
419
|
}
|
|
@@ -468,9 +441,9 @@ var init_idempotency_pipeline = __esm({
|
|
|
468
441
|
_processedTtlSeconds;
|
|
469
442
|
async handle(request, next) {
|
|
470
443
|
const network = this._requestContextFactory.getNetworkContext();
|
|
471
|
-
if (!
|
|
472
|
-
return
|
|
473
|
-
|
|
444
|
+
if (!import_shared10.Guards.isDefined(network))
|
|
445
|
+
return import_shared9.Result.fail(
|
|
446
|
+
import_shared9.AppError.conflict(
|
|
474
447
|
request.intent,
|
|
475
448
|
`Network context is not defined for request ${request.intent}`
|
|
476
449
|
)
|
|
@@ -479,11 +452,11 @@ var init_idempotency_pipeline = __esm({
|
|
|
479
452
|
const alreadyProcessed = await this._idempotencyStore.hasBeenProcessed(network.requestId);
|
|
480
453
|
if (alreadyProcessed) {
|
|
481
454
|
const payload = await this._idempotencyStore.getPayload(network.requestId);
|
|
482
|
-
if (
|
|
483
|
-
return
|
|
455
|
+
if (import_shared10.Guards.isDefined(payload)) {
|
|
456
|
+
return import_shared9.Result.ok(payload);
|
|
484
457
|
} else {
|
|
485
|
-
return
|
|
486
|
-
|
|
458
|
+
return import_shared9.Result.fail(
|
|
459
|
+
import_shared9.AppError.conflict(
|
|
487
460
|
request.intent,
|
|
488
461
|
`Idempotency store indicates request has been processed but no payload found for request ID ${network.requestId}`
|
|
489
462
|
)
|
|
@@ -495,8 +468,8 @@ var init_idempotency_pipeline = __esm({
|
|
|
495
468
|
this._lockTtlSeconds
|
|
496
469
|
);
|
|
497
470
|
if (!lockAcquired) {
|
|
498
|
-
return
|
|
499
|
-
|
|
471
|
+
return import_shared9.Result.fail(
|
|
472
|
+
import_shared9.AppError.conflict(
|
|
500
473
|
request.intent,
|
|
501
474
|
`Failed to acquire lock for request ID ${network.requestId}`
|
|
502
475
|
)
|
|
@@ -566,11 +539,11 @@ var init_logging_pipeline = __esm({
|
|
|
566
539
|
});
|
|
567
540
|
|
|
568
541
|
// src/application/cqrs/pipelines/performance.pipeline.ts
|
|
569
|
-
var
|
|
542
|
+
var import_shared11, defaultThresholdMs, PerformancePipeline;
|
|
570
543
|
var init_performance_pipeline = __esm({
|
|
571
544
|
"src/application/cqrs/pipelines/performance.pipeline.ts"() {
|
|
572
545
|
"use strict";
|
|
573
|
-
|
|
546
|
+
import_shared11 = require("@xeno-js/shared");
|
|
574
547
|
defaultThresholdMs = 500;
|
|
575
548
|
PerformancePipeline = class {
|
|
576
549
|
/**
|
|
@@ -588,15 +561,15 @@ var init_performance_pipeline = __esm({
|
|
|
588
561
|
constructor(_logger, intentThresholdMS = {}, thresholdMs = defaultThresholdMs) {
|
|
589
562
|
this._logger = _logger;
|
|
590
563
|
const message = `Invalid thresholdMs value: ${thresholdMs}. It must be a positive integer.`;
|
|
591
|
-
|
|
564
|
+
import_shared11.Guards.throwIfNegative(thresholdMs, message);
|
|
592
565
|
if (thresholdMs === 0) {
|
|
593
566
|
throw new Error(message);
|
|
594
567
|
}
|
|
595
568
|
this._thresholdMs = thresholdMs;
|
|
596
569
|
for (const [intent, val] of Object.entries(intentThresholdMS)) {
|
|
597
570
|
const intentMessage = `Invalid thresholdMs value for intent '${intent}': ${val}. It must be a positive integer.`;
|
|
598
|
-
|
|
599
|
-
|
|
571
|
+
import_shared11.Guards.throwIfNegative(val, intentMessage);
|
|
572
|
+
import_shared11.Guards.throwIfNotInteger(val, intentMessage);
|
|
600
573
|
if (val === 0) {
|
|
601
574
|
throw new Error(intentMessage);
|
|
602
575
|
}
|
|
@@ -633,12 +606,12 @@ var init_performance_pipeline = __esm({
|
|
|
633
606
|
});
|
|
634
607
|
|
|
635
608
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/base-authorization.strategy.ts
|
|
636
|
-
var
|
|
609
|
+
var import_shared12, import_shared13, BaseAuthorizationStrategy;
|
|
637
610
|
var init_base_authorization_strategy = __esm({
|
|
638
611
|
"src/application/cqrs/pipelines/pipeline_strategies/auth/base-authorization.strategy.ts"() {
|
|
639
612
|
"use strict";
|
|
613
|
+
import_shared12 = require("@xeno-js/shared");
|
|
640
614
|
import_shared13 = require("@xeno-js/shared");
|
|
641
|
-
import_shared14 = require("@xeno-js/shared");
|
|
642
615
|
BaseAuthorizationStrategy = class {
|
|
643
616
|
/**
|
|
644
617
|
* @description Constructs a new instance of the BaseAuthorizationStrategy class, which serves as an abstract base for specific authorization strategies in the CQRS pipeline. It takes an IRequestContext as a parameter, which is used to retrieve the identity of the currently authenticated user during the authorization process. This context is essential for performing the authorization checks based on the user's identity when executing requests that require specific permissions.
|
|
@@ -655,8 +628,8 @@ var init_base_authorization_strategy = __esm({
|
|
|
655
628
|
_requestContext;
|
|
656
629
|
async execute(request) {
|
|
657
630
|
const context = this._requestContext.getContext();
|
|
658
|
-
if (!
|
|
659
|
-
return
|
|
631
|
+
if (!import_shared13.Guards.isDefined(context)) {
|
|
632
|
+
return import_shared12.Result.fail(import_shared12.AppError.unauthorized(request.intent, "User is not authenticated."));
|
|
660
633
|
}
|
|
661
634
|
return await this.performAuthorizationCheck(request, context.identity);
|
|
662
635
|
}
|
|
@@ -665,12 +638,12 @@ var init_base_authorization_strategy = __esm({
|
|
|
665
638
|
});
|
|
666
639
|
|
|
667
640
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/permission-authorization.strategy.ts
|
|
668
|
-
var
|
|
641
|
+
var import_shared14, import_shared15, PermissionAuthorizationStrategy;
|
|
669
642
|
var init_permission_authorization_strategy = __esm({
|
|
670
643
|
"src/application/cqrs/pipelines/pipeline_strategies/auth/permission-authorization.strategy.ts"() {
|
|
671
644
|
"use strict";
|
|
645
|
+
import_shared14 = require("@xeno-js/shared");
|
|
672
646
|
import_shared15 = require("@xeno-js/shared");
|
|
673
|
-
import_shared16 = require("@xeno-js/shared");
|
|
674
647
|
init_base_authorization_strategy();
|
|
675
648
|
PermissionAuthorizationStrategy = class extends BaseAuthorizationStrategy {
|
|
676
649
|
/** @description Constructs a new instance of the PermissionAuthorizationStrategy class, which is responsible for checking if the authenticated user has the required permissions specified in the command. It takes an IRequestContext as a parameter, which is used to retrieve the identity of the currently authenticated user during the authorization process.
|
|
@@ -689,29 +662,29 @@ var init_permission_authorization_strategy = __esm({
|
|
|
689
662
|
_policy;
|
|
690
663
|
async performAuthorizationCheck(command, auth) {
|
|
691
664
|
const policy = this._policy.getPolicy(command.intent);
|
|
692
|
-
if (!
|
|
665
|
+
if (!import_shared15.Guards.isNullOrEmpty(policy?.permissions)) {
|
|
693
666
|
const permissions = auth.permissions ?? [];
|
|
694
667
|
const hasRequiredPermission = policy.permissions?.some(
|
|
695
668
|
(permission) => permissions.includes(permission)
|
|
696
669
|
);
|
|
697
670
|
if (!hasRequiredPermission)
|
|
698
|
-
return
|
|
699
|
-
|
|
671
|
+
return import_shared14.Result.fail(
|
|
672
|
+
import_shared14.AppError.forbidden(command.intent, "User does not have the required permissions.")
|
|
700
673
|
);
|
|
701
674
|
}
|
|
702
|
-
return
|
|
675
|
+
return import_shared14.Result.ok();
|
|
703
676
|
}
|
|
704
677
|
};
|
|
705
678
|
}
|
|
706
679
|
});
|
|
707
680
|
|
|
708
681
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/role-authorization.strategy.ts
|
|
709
|
-
var
|
|
682
|
+
var import_shared16, import_shared17, RoleAuthorizationStrategy;
|
|
710
683
|
var init_role_authorization_strategy = __esm({
|
|
711
684
|
"src/application/cqrs/pipelines/pipeline_strategies/auth/role-authorization.strategy.ts"() {
|
|
712
685
|
"use strict";
|
|
686
|
+
import_shared16 = require("@xeno-js/shared");
|
|
713
687
|
import_shared17 = require("@xeno-js/shared");
|
|
714
|
-
import_shared18 = require("@xeno-js/shared");
|
|
715
688
|
init_base_authorization_strategy();
|
|
716
689
|
RoleAuthorizationStrategy = class extends BaseAuthorizationStrategy {
|
|
717
690
|
/** @description Constructs a new instance of the RoleAuthorizationStrategy class, which is responsible for checking if the authenticated user has the required roles specified in the command. It takes an IRequestContext as a parameter, which is used to retrieve the identity of the currently authenticated user during the authorization process.
|
|
@@ -729,27 +702,27 @@ var init_role_authorization_strategy = __esm({
|
|
|
729
702
|
_policy;
|
|
730
703
|
async performAuthorizationCheck(command, auth) {
|
|
731
704
|
const policy = this._policy.getPolicy(command.intent);
|
|
732
|
-
if (!
|
|
705
|
+
if (!import_shared17.Guards.isNullOrEmpty(policy?.roles)) {
|
|
733
706
|
const roles = auth.roles ?? [];
|
|
734
707
|
const hasRequiredRole = policy.roles?.some((role) => roles.includes(role));
|
|
735
708
|
if (!hasRequiredRole)
|
|
736
|
-
return
|
|
737
|
-
|
|
709
|
+
return import_shared16.Result.fail(
|
|
710
|
+
import_shared16.AppError.forbidden(command.intent, "User does not have the required roles.")
|
|
738
711
|
);
|
|
739
712
|
}
|
|
740
|
-
return
|
|
713
|
+
return import_shared16.Result.ok();
|
|
741
714
|
}
|
|
742
715
|
};
|
|
743
716
|
}
|
|
744
717
|
});
|
|
745
718
|
|
|
746
719
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/tenant-authorization.strategy.ts
|
|
747
|
-
var
|
|
720
|
+
var import_shared18, import_shared19, TenantAuthorizationStrategy;
|
|
748
721
|
var init_tenant_authorization_strategy = __esm({
|
|
749
722
|
"src/application/cqrs/pipelines/pipeline_strategies/auth/tenant-authorization.strategy.ts"() {
|
|
750
723
|
"use strict";
|
|
724
|
+
import_shared18 = require("@xeno-js/shared");
|
|
751
725
|
import_shared19 = require("@xeno-js/shared");
|
|
752
|
-
import_shared20 = require("@xeno-js/shared");
|
|
753
726
|
init_base_authorization_strategy();
|
|
754
727
|
TenantAuthorizationStrategy = class extends BaseAuthorizationStrategy {
|
|
755
728
|
/** @description Constructs a new instance of the TenantAuthorizationStrategy class, which is responsible for checking if the authenticated tenant has the required tenant ID specified in the command. It takes an IContextAccessor as a parameter, which is used to retrieve the identity of the currently authenticated tenant during the authorization process.
|
|
@@ -767,23 +740,23 @@ var init_tenant_authorization_strategy = __esm({
|
|
|
767
740
|
_policy;
|
|
768
741
|
async performAuthorizationCheck(command, auth) {
|
|
769
742
|
const policy = this._policy.getPolicy(command.intent);
|
|
770
|
-
if (
|
|
771
|
-
if (
|
|
772
|
-
return
|
|
743
|
+
if (import_shared19.Guards.isDefined(policy?.tenantId)) {
|
|
744
|
+
if (import_shared19.Guards.isNullOrEmpty(auth.tenantId) || !import_shared19.GuidHelper.isValidGuid(auth.tenantId))
|
|
745
|
+
return import_shared18.Result.fail(import_shared18.AppError.unauthorized(command.intent, "Tenant is not authenticated."));
|
|
773
746
|
}
|
|
774
|
-
return
|
|
747
|
+
return import_shared18.Result.ok();
|
|
775
748
|
}
|
|
776
749
|
};
|
|
777
750
|
}
|
|
778
751
|
});
|
|
779
752
|
|
|
780
753
|
// src/application/cqrs/pipelines/pipeline_strategies/auth/user-authorization.strategy.ts
|
|
781
|
-
var
|
|
754
|
+
var import_shared20, import_shared21, UserAuthorizationStrategy;
|
|
782
755
|
var init_user_authorization_strategy = __esm({
|
|
783
756
|
"src/application/cqrs/pipelines/pipeline_strategies/auth/user-authorization.strategy.ts"() {
|
|
784
757
|
"use strict";
|
|
758
|
+
import_shared20 = require("@xeno-js/shared");
|
|
785
759
|
import_shared21 = require("@xeno-js/shared");
|
|
786
|
-
import_shared22 = require("@xeno-js/shared");
|
|
787
760
|
init_base_authorization_strategy();
|
|
788
761
|
UserAuthorizationStrategy = class extends BaseAuthorizationStrategy {
|
|
789
762
|
/** @description Constructs a new instance of the UserAuthorizationStrategy class, which is responsible for checking if the authenticated user has the required user ID specified in the command. It takes an IContextAccessor as a parameter, which is used to retrieve the identity of the currently authenticated user during the authorization process.
|
|
@@ -801,11 +774,11 @@ var init_user_authorization_strategy = __esm({
|
|
|
801
774
|
_policy;
|
|
802
775
|
async performAuthorizationCheck(command, auth) {
|
|
803
776
|
const policy = this._policy.getPolicy(command.intent);
|
|
804
|
-
if (
|
|
805
|
-
if (
|
|
806
|
-
return
|
|
777
|
+
if (import_shared21.Guards.isDefined(policy?.userId)) {
|
|
778
|
+
if (import_shared21.Guards.isNullOrEmpty(auth.userId) || !import_shared21.GuidHelper.isValidGuid(auth.userId))
|
|
779
|
+
return import_shared20.Result.fail(import_shared20.AppError.unauthorized(command.intent, "User is not authenticated."));
|
|
807
780
|
}
|
|
808
|
-
return
|
|
781
|
+
return import_shared20.Result.ok();
|
|
809
782
|
}
|
|
810
783
|
};
|
|
811
784
|
}
|
|
@@ -824,11 +797,11 @@ var init_auth = __esm({
|
|
|
824
797
|
});
|
|
825
798
|
|
|
826
799
|
// src/application/cqrs/pipelines/pipeline_strategies/validation/schema-validation.strategy.ts
|
|
827
|
-
var
|
|
800
|
+
var import_shared22, SchemaValidationStrategy;
|
|
828
801
|
var init_schema_validation_strategy = __esm({
|
|
829
802
|
"src/application/cqrs/pipelines/pipeline_strategies/validation/schema-validation.strategy.ts"() {
|
|
830
803
|
"use strict";
|
|
831
|
-
|
|
804
|
+
import_shared22 = require("@xeno-js/shared");
|
|
832
805
|
SchemaValidationStrategy = class {
|
|
833
806
|
/**
|
|
834
807
|
* @description Constructs a new instance of the SchemaValidationStrategy class, which takes an IValidatorService as a parameter. This service is used to check for the existence of validation schemas and to perform the actual validation of requests against those schemas. The constructor initializes the strategy with the provided validator service, allowing it to execute the validation logic when handling requests in the CQRS pipeline.
|
|
@@ -847,13 +820,13 @@ var init_schema_validation_strategy = __esm({
|
|
|
847
820
|
const key = request.intent;
|
|
848
821
|
const parseResult = await this._validator.validate(key, request);
|
|
849
822
|
if (!parseResult.isOk())
|
|
850
|
-
return
|
|
851
|
-
|
|
823
|
+
return import_shared22.Result.fail(
|
|
824
|
+
import_shared22.AppError.validationError(
|
|
852
825
|
request.intent,
|
|
853
826
|
`Validation failed: ${parseResult.getErrorOrThrow().message}`
|
|
854
827
|
)
|
|
855
828
|
);
|
|
856
|
-
return
|
|
829
|
+
return import_shared22.Result.ok(true);
|
|
857
830
|
}
|
|
858
831
|
};
|
|
859
832
|
}
|
|
@@ -877,12 +850,12 @@ var init_pipeline_strategies = __esm({
|
|
|
877
850
|
});
|
|
878
851
|
|
|
879
852
|
// src/application/cqrs/pipelines/query-caching.pipeline.ts
|
|
880
|
-
var
|
|
853
|
+
var import_shared23, import_shared24, QueryCachingPipeline;
|
|
881
854
|
var init_query_caching_pipeline = __esm({
|
|
882
855
|
"src/application/cqrs/pipelines/query-caching.pipeline.ts"() {
|
|
883
856
|
"use strict";
|
|
857
|
+
import_shared23 = require("@xeno-js/shared");
|
|
884
858
|
import_shared24 = require("@xeno-js/shared");
|
|
885
|
-
import_shared25 = require("@xeno-js/shared");
|
|
886
859
|
QueryCachingPipeline = class {
|
|
887
860
|
/**
|
|
888
861
|
* @description Constructs a new instance of the QueryCachingPipeline class, which requires an ICache implementation for interacting with the cache and an ILogger for logging cache-related operations and errors. The constructor initializes the dependencies needed for the caching behavior to function properly within the CQRS pipeline.
|
|
@@ -904,18 +877,18 @@ var init_query_caching_pipeline = __esm({
|
|
|
904
877
|
_cacheKeyBuilder;
|
|
905
878
|
_logger;
|
|
906
879
|
async handle(request, next) {
|
|
907
|
-
if (
|
|
880
|
+
if (import_shared24.Guards.isNullOrEmpty(request.cacheOptions) || import_shared24.Guards.isNullOrEmpty(request.cacheOptions.cacheKey))
|
|
908
881
|
return next();
|
|
909
882
|
const bypass = request.cacheOptions.bypassCache === true || request.cacheOptions.consistentRead === true;
|
|
910
883
|
const key = request.cacheOptions.isUserScoped ? this._cacheKeyBuilder.buildUserScopedKey(request.cacheOptions.cacheKey) : this._cacheKeyBuilder.buildContextualKey(request.cacheOptions.cacheKey);
|
|
911
884
|
if (!bypass) {
|
|
912
885
|
try {
|
|
913
886
|
const cachedResponse = await this._cacheService.get(key);
|
|
914
|
-
if (
|
|
887
|
+
if (import_shared24.Guards.isDefined(cachedResponse)) {
|
|
915
888
|
this._logger.debug(
|
|
916
889
|
`[Cache HIT] Returning data from cache for: ${request.cacheOptions.cacheKey}`
|
|
917
890
|
);
|
|
918
|
-
return
|
|
891
|
+
return import_shared23.Result.ok(cachedResponse);
|
|
919
892
|
}
|
|
920
893
|
} catch (error) {
|
|
921
894
|
this._logger.warn(
|
|
@@ -941,11 +914,11 @@ var init_query_caching_pipeline = __esm({
|
|
|
941
914
|
});
|
|
942
915
|
|
|
943
916
|
// src/application/cqrs/pipelines/validation.pipeline.ts
|
|
944
|
-
var
|
|
917
|
+
var import_shared25, ValidationPipeline;
|
|
945
918
|
var init_validation_pipeline = __esm({
|
|
946
919
|
"src/application/cqrs/pipelines/validation.pipeline.ts"() {
|
|
947
920
|
"use strict";
|
|
948
|
-
|
|
921
|
+
import_shared25 = require("@xeno-js/shared");
|
|
949
922
|
ValidationPipeline = class {
|
|
950
923
|
/** @description Constructs a new instance of the ValidationPipeline class, which takes an array of IStrategy instances as validators. These validators are used to perform validation checks on the incoming requests. The constructor initializes the pipeline with the provided validators, allowing it to execute the validation logic when handling requests in the CQRS pipeline.
|
|
951
924
|
* @param _validators An array of IStrategy instances that represent the validation strategies to be applied to incoming requests. Each strategy should implement the isApplicable method to determine if it should be applied to a given request and the execute method to perform the actual validation logic, returning a Result indicating the success or failure of the validation.
|
|
@@ -964,7 +937,7 @@ var init_validation_pipeline = __esm({
|
|
|
964
937
|
for (const validator of this._validators) {
|
|
965
938
|
const validationResult = await validator.execute(request);
|
|
966
939
|
if (!validationResult.isOk()) {
|
|
967
|
-
return
|
|
940
|
+
return import_shared25.Result.fail(validationResult.getErrorOrThrow());
|
|
968
941
|
}
|
|
969
942
|
}
|
|
970
943
|
return next();
|
|
@@ -994,19 +967,18 @@ var init_pipelines = __esm({
|
|
|
994
967
|
var init_cqrs = __esm({
|
|
995
968
|
"src/application/cqrs/index.ts"() {
|
|
996
969
|
"use strict";
|
|
997
|
-
init_base_handler();
|
|
998
970
|
init_mediator();
|
|
999
971
|
init_pipelines();
|
|
1000
972
|
}
|
|
1001
973
|
});
|
|
1002
974
|
|
|
1003
975
|
// src/application/gate_keepers/gate-keeper.ts
|
|
1004
|
-
var
|
|
976
|
+
var import_shared26, import_shared27, GateKeeper;
|
|
1005
977
|
var init_gate_keeper = __esm({
|
|
1006
978
|
"src/application/gate_keepers/gate-keeper.ts"() {
|
|
1007
979
|
"use strict";
|
|
980
|
+
import_shared26 = require("@xeno-js/shared");
|
|
1008
981
|
import_shared27 = require("@xeno-js/shared");
|
|
1009
|
-
import_shared28 = require("@xeno-js/shared");
|
|
1010
982
|
GateKeeper = class {
|
|
1011
983
|
constructor(_authService, _mapper) {
|
|
1012
984
|
this._authService = _authService;
|
|
@@ -1015,38 +987,38 @@ var init_gate_keeper = __esm({
|
|
|
1015
987
|
_authService;
|
|
1016
988
|
_mapper;
|
|
1017
989
|
async authenticate(token) {
|
|
1018
|
-
const guest =
|
|
1019
|
-
if (!
|
|
990
|
+
const guest = import_shared27.GUEST;
|
|
991
|
+
if (!import_shared27.Guards.isNullOrEmpty(token)) {
|
|
1020
992
|
const authResult = await this._authService.authenticate(token);
|
|
1021
|
-
if (!authResult.isOk()) return
|
|
993
|
+
if (!authResult.isOk()) return import_shared26.Result.fail(authResult.getErrorOrThrow());
|
|
1022
994
|
const claims = authResult.getValueOrThrow();
|
|
1023
|
-
if (
|
|
1024
|
-
return
|
|
995
|
+
if (import_shared27.Guards.isDefined(claims)) return import_shared26.Result.ok(this._mapper.map(claims));
|
|
996
|
+
return import_shared26.Result.ok(guest);
|
|
1025
997
|
}
|
|
1026
998
|
const userResult = await this._authService.getUser();
|
|
1027
999
|
if (userResult.isOk()) {
|
|
1028
1000
|
const user = userResult.getValueOrThrow();
|
|
1029
|
-
if (
|
|
1030
|
-
return
|
|
1001
|
+
if (import_shared27.Guards.isDefined(user)) {
|
|
1002
|
+
return import_shared26.Result.ok(this._mapper.map(user));
|
|
1031
1003
|
}
|
|
1032
1004
|
}
|
|
1033
|
-
return
|
|
1005
|
+
return import_shared26.Result.ok(guest);
|
|
1034
1006
|
}
|
|
1035
1007
|
};
|
|
1036
1008
|
}
|
|
1037
1009
|
});
|
|
1038
1010
|
|
|
1039
1011
|
// src/application/gate_keepers/noauth.gate-keeper.ts
|
|
1040
|
-
var
|
|
1012
|
+
var import_shared28, import_shared29, NoAuthGateKeeper;
|
|
1041
1013
|
var init_noauth_gate_keeper = __esm({
|
|
1042
1014
|
"src/application/gate_keepers/noauth.gate-keeper.ts"() {
|
|
1043
1015
|
"use strict";
|
|
1016
|
+
import_shared28 = require("@xeno-js/shared");
|
|
1044
1017
|
import_shared29 = require("@xeno-js/shared");
|
|
1045
|
-
import_shared30 = require("@xeno-js/shared");
|
|
1046
1018
|
NoAuthGateKeeper = class {
|
|
1047
1019
|
async authenticate(_token) {
|
|
1048
|
-
const guest =
|
|
1049
|
-
return
|
|
1020
|
+
const guest = import_shared29.GUEST;
|
|
1021
|
+
return import_shared28.Result.ok(guest);
|
|
1050
1022
|
}
|
|
1051
1023
|
};
|
|
1052
1024
|
}
|
|
@@ -1062,18 +1034,18 @@ var init_gate_keepers = __esm({
|
|
|
1062
1034
|
});
|
|
1063
1035
|
|
|
1064
1036
|
// src/application/mappers/claims-identity.mapper.ts
|
|
1065
|
-
var
|
|
1037
|
+
var import_shared30, ClaimsIdentityMapper;
|
|
1066
1038
|
var init_claims_identity_mapper = __esm({
|
|
1067
1039
|
"src/application/mappers/claims-identity.mapper.ts"() {
|
|
1068
1040
|
"use strict";
|
|
1069
|
-
|
|
1041
|
+
import_shared30 = require("@xeno-js/shared");
|
|
1070
1042
|
ClaimsIdentityMapper = class {
|
|
1071
1043
|
map(claims) {
|
|
1072
1044
|
return {
|
|
1073
|
-
userId:
|
|
1045
|
+
userId: import_shared30.GuidHelper.parse(claims.sub),
|
|
1074
1046
|
email: claims.email,
|
|
1075
1047
|
name: claims.name,
|
|
1076
|
-
tenantId:
|
|
1048
|
+
tenantId: import_shared30.GuidHelper.parse(claims.tenantId),
|
|
1077
1049
|
roles: claims.roles,
|
|
1078
1050
|
permissions: claims.permissions
|
|
1079
1051
|
};
|
|
@@ -1235,7 +1207,6 @@ var application_exports = {};
|
|
|
1235
1207
|
__export(application_exports, {
|
|
1236
1208
|
AuthorizationPipeline: () => AuthorizationPipeline,
|
|
1237
1209
|
BaseAuthorizationStrategy: () => BaseAuthorizationStrategy,
|
|
1238
|
-
BaseHandler: () => BaseHandler,
|
|
1239
1210
|
ClaimsIdentityMapper: () => ClaimsIdentityMapper,
|
|
1240
1211
|
CompositePipeline: () => CompositePipeline,
|
|
1241
1212
|
ConcurrencyRetryPipeline: () => ConcurrencyRetryPipeline,
|
|
@@ -1291,11 +1262,11 @@ var init_service_scope_factory = __esm({
|
|
|
1291
1262
|
});
|
|
1292
1263
|
|
|
1293
1264
|
// src/infrastructure/context/request-context.ts
|
|
1294
|
-
var
|
|
1265
|
+
var import_shared33, NodeRequestContext;
|
|
1295
1266
|
var init_request_context = __esm({
|
|
1296
1267
|
"src/infrastructure/context/request-context.ts"() {
|
|
1297
1268
|
"use strict";
|
|
1298
|
-
|
|
1269
|
+
import_shared33 = require("@xeno-js/shared");
|
|
1299
1270
|
NodeRequestContext = class {
|
|
1300
1271
|
/**
|
|
1301
1272
|
* @description Constructs a new instance of the NodeRequestContext class, which requires an instance of AsyncLocalStorage to manage the request context. The AsyncLocalStorage instance is used to create and access the context for each request, allowing for the storage of identity information and other relevant data that needs to be accessible across asynchronous operations. This constructor initializes the NodeRequestContext with the provided AsyncLocalStorage, enabling it to implement the methods defined in the IRequestContext interface for managing request-specific context data.
|
|
@@ -1323,7 +1294,7 @@ var init_request_context = __esm({
|
|
|
1323
1294
|
}
|
|
1324
1295
|
updateIdentity(identity) {
|
|
1325
1296
|
const store = this._storage.getStore();
|
|
1326
|
-
if (
|
|
1297
|
+
if (import_shared33.Guards.isDefined(store) && import_shared33.Guards.isDefined(store.context)) {
|
|
1327
1298
|
store.context = Object.freeze({
|
|
1328
1299
|
...store.context,
|
|
1329
1300
|
identity: Object.freeze(identity)
|
|
@@ -1332,23 +1303,23 @@ var init_request_context = __esm({
|
|
|
1332
1303
|
}
|
|
1333
1304
|
getContext() {
|
|
1334
1305
|
const store = this._storage.getStore();
|
|
1335
|
-
if (!
|
|
1306
|
+
if (!import_shared33.Guards.isDefined(store)) return void 0;
|
|
1336
1307
|
const context = store.context;
|
|
1337
1308
|
return Object.freeze(context);
|
|
1338
1309
|
}
|
|
1339
1310
|
getIdentity() {
|
|
1340
1311
|
const store = this._storage.getStore();
|
|
1341
|
-
if (!
|
|
1312
|
+
if (!import_shared33.Guards.isDefined(store)) return void 0;
|
|
1342
1313
|
return Object.freeze(store.context?.identity);
|
|
1343
1314
|
}
|
|
1344
1315
|
getScope() {
|
|
1345
1316
|
const store = this._storage.getStore();
|
|
1346
|
-
if (!
|
|
1317
|
+
if (!import_shared33.Guards.isDefined(store)) return void 0;
|
|
1347
1318
|
return store.scope;
|
|
1348
1319
|
}
|
|
1349
1320
|
getNetworkContext() {
|
|
1350
1321
|
const store = this._storage.getStore();
|
|
1351
|
-
if (!
|
|
1322
|
+
if (!import_shared33.Guards.isDefined(store)) return void 0;
|
|
1352
1323
|
return Object.freeze(store.context?.network);
|
|
1353
1324
|
}
|
|
1354
1325
|
};
|
|
@@ -1384,11 +1355,11 @@ var user_context_factory_exports = {};
|
|
|
1384
1355
|
__export(user_context_factory_exports, {
|
|
1385
1356
|
UserContextFactory: () => UserContextFactory
|
|
1386
1357
|
});
|
|
1387
|
-
var
|
|
1358
|
+
var import_shared34, UserContextFactory;
|
|
1388
1359
|
var init_user_context_factory = __esm({
|
|
1389
1360
|
"src/infrastructure/factories/user-context.factory.ts"() {
|
|
1390
1361
|
"use strict";
|
|
1391
|
-
|
|
1362
|
+
import_shared34 = require("@xeno-js/shared");
|
|
1392
1363
|
UserContextFactory = class {
|
|
1393
1364
|
/**
|
|
1394
1365
|
* @description Constructs an instance of UserContextFactory.
|
|
@@ -1409,7 +1380,7 @@ var init_user_context_factory = __esm({
|
|
|
1409
1380
|
tenantId: void 0
|
|
1410
1381
|
};
|
|
1411
1382
|
const identity = this._identityFactory.getIdentity();
|
|
1412
|
-
if (
|
|
1383
|
+
if (import_shared34.Guards.isDefined(identity)) {
|
|
1413
1384
|
output.userId = identity.userId;
|
|
1414
1385
|
output.tenantId = identity.tenantId;
|
|
1415
1386
|
}
|
|
@@ -1451,11 +1422,11 @@ var init_context_module = __esm({
|
|
|
1451
1422
|
});
|
|
1452
1423
|
|
|
1453
1424
|
// src/infrastructure/services/allow_methods/allow-method.service.ts
|
|
1454
|
-
var
|
|
1425
|
+
var import_shared35, AllowMethodRegistry;
|
|
1455
1426
|
var init_allow_method_service = __esm({
|
|
1456
1427
|
"src/infrastructure/services/allow_methods/allow-method.service.ts"() {
|
|
1457
1428
|
"use strict";
|
|
1458
|
-
|
|
1429
|
+
import_shared35 = require("@xeno-js/shared");
|
|
1459
1430
|
AllowMethodRegistry = class {
|
|
1460
1431
|
_staticRoutes = /* @__PURE__ */ new Map();
|
|
1461
1432
|
_dynamicRoutes = [];
|
|
@@ -1471,7 +1442,7 @@ var init_allow_method_service = __esm({
|
|
|
1471
1442
|
check(path, method) {
|
|
1472
1443
|
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1473
1444
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1474
|
-
if (
|
|
1445
|
+
if (import_shared35.Guards.isDefined(staticMethods)) return staticMethods.includes(method);
|
|
1475
1446
|
for (const route of this._dynamicRoutes) {
|
|
1476
1447
|
if (route.pattern.test(cleanPath)) return route.methods.includes(method);
|
|
1477
1448
|
}
|
|
@@ -1480,11 +1451,11 @@ var init_allow_method_service = __esm({
|
|
|
1480
1451
|
getMethods(path) {
|
|
1481
1452
|
const cleanPath = this.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1482
1453
|
const methods = this.findMethods(cleanPath);
|
|
1483
|
-
return
|
|
1454
|
+
return import_shared35.Guards.isDefined(methods) ? methods.join(", ").toUpperCase() : "";
|
|
1484
1455
|
}
|
|
1485
1456
|
findMethods(cleanPath) {
|
|
1486
1457
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1487
|
-
if (
|
|
1458
|
+
if (import_shared35.Guards.isDefined(staticMethods)) return staticMethods;
|
|
1488
1459
|
for (const route of this._dynamicRoutes) if (route.pattern.test(cleanPath)) return route.methods;
|
|
1489
1460
|
return void 0;
|
|
1490
1461
|
}
|
|
@@ -1519,18 +1490,18 @@ var init_allow_methods = __esm({
|
|
|
1519
1490
|
});
|
|
1520
1491
|
|
|
1521
1492
|
// src/infrastructure/services/allow_origins/allow-origin.http.ts
|
|
1522
|
-
var
|
|
1493
|
+
var import_shared36, AllowOrigin;
|
|
1523
1494
|
var init_allow_origin_http = __esm({
|
|
1524
1495
|
"src/infrastructure/services/allow_origins/allow-origin.http.ts"() {
|
|
1525
1496
|
"use strict";
|
|
1526
|
-
|
|
1497
|
+
import_shared36 = require("@xeno-js/shared");
|
|
1527
1498
|
AllowOrigin = class {
|
|
1528
1499
|
constructor(_list) {
|
|
1529
1500
|
this._list = _list;
|
|
1530
1501
|
}
|
|
1531
1502
|
_list;
|
|
1532
1503
|
isAllowed(origin) {
|
|
1533
|
-
if (
|
|
1504
|
+
if (import_shared36.Guards.isNullOrEmpty(origin)) return true;
|
|
1534
1505
|
const cleanOrigin = origin.trim().toLowerCase();
|
|
1535
1506
|
for (const pattern of this._list) {
|
|
1536
1507
|
const cleanPattern = pattern.trim().toLowerCase();
|
|
@@ -1540,7 +1511,7 @@ var init_allow_origin_http = __esm({
|
|
|
1540
1511
|
const domainSuffix = cleanPattern.substring(1);
|
|
1541
1512
|
if (cleanOrigin.endsWith(domainSuffix)) {
|
|
1542
1513
|
const prefix = cleanOrigin.slice(0, cleanOrigin.length - domainSuffix.length);
|
|
1543
|
-
if (!
|
|
1514
|
+
if (!import_shared36.Guards.isNullOrEmpty(prefix) && !prefix.includes(".")) return true;
|
|
1544
1515
|
}
|
|
1545
1516
|
}
|
|
1546
1517
|
}
|
|
@@ -1587,11 +1558,11 @@ var init_concurrency = __esm({
|
|
|
1587
1558
|
});
|
|
1588
1559
|
|
|
1589
1560
|
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1590
|
-
var
|
|
1561
|
+
var import_shared37, CookieHandler;
|
|
1591
1562
|
var init_cookies_service = __esm({
|
|
1592
1563
|
"src/infrastructure/services/cookies/cookies.service.ts"() {
|
|
1593
1564
|
"use strict";
|
|
1594
|
-
|
|
1565
|
+
import_shared37 = require("@xeno-js/shared");
|
|
1595
1566
|
CookieHandler = class {
|
|
1596
1567
|
constructor(contextAccessor, _config, _cookieOpts) {
|
|
1597
1568
|
this.contextAccessor = contextAccessor;
|
|
@@ -1604,7 +1575,7 @@ var init_cookies_service = __esm({
|
|
|
1604
1575
|
getAll() {
|
|
1605
1576
|
const network = this.contextAccessor.getNetworkContext();
|
|
1606
1577
|
const req = network?.transport?.req;
|
|
1607
|
-
if (!
|
|
1578
|
+
if (!import_shared37.Guards.isDefined(req) || import_shared37.Guards.isNullOrEmpty(req.headers.get("cookie"))) return [];
|
|
1608
1579
|
return req.headers.get("cookie")?.split(";").map((cookie) => {
|
|
1609
1580
|
const [name, ...rest] = cookie.split("=");
|
|
1610
1581
|
return { name: name.trim(), value: rest.join("=") };
|
|
@@ -1613,7 +1584,7 @@ var init_cookies_service = __esm({
|
|
|
1613
1584
|
setAll(cookies) {
|
|
1614
1585
|
const network = this.contextAccessor.getNetworkContext();
|
|
1615
1586
|
const res = network?.transport?.res;
|
|
1616
|
-
if (!
|
|
1587
|
+
if (!import_shared37.Guards.isDefined(res)) return;
|
|
1617
1588
|
const serializedCookies = cookies.map((c) => this.serialize(c));
|
|
1618
1589
|
const existingSetCookie = res.headers.getSetCookie();
|
|
1619
1590
|
res.headers.delete("Set-Cookie");
|
|
@@ -1634,9 +1605,9 @@ var init_cookies_service = __esm({
|
|
|
1634
1605
|
};
|
|
1635
1606
|
const opts = { ...defaultOptions, ...cookie.options ?? {} };
|
|
1636
1607
|
str += `; Path=${opts.path}`;
|
|
1637
|
-
if (
|
|
1638
|
-
if (
|
|
1639
|
-
if (
|
|
1608
|
+
if (import_shared37.Guards.isDefined(opts.maxAge)) str += `; Max-Age=${opts.maxAge}`;
|
|
1609
|
+
if (import_shared37.Guards.isDefined(opts.domain)) str += `; Domain=${opts.domain}`;
|
|
1610
|
+
if (import_shared37.Guards.isDefined(opts.sameSite)) str += `; SameSite=${opts.sameSite}`;
|
|
1640
1611
|
if (opts.secure) str += `; Secure`;
|
|
1641
1612
|
if (opts.httpOnly) str += `; HttpOnly`;
|
|
1642
1613
|
return str;
|
|
@@ -1701,11 +1672,11 @@ var init_crypto = __esm({
|
|
|
1701
1672
|
});
|
|
1702
1673
|
|
|
1703
1674
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1704
|
-
var
|
|
1675
|
+
var import_shared38, CsrfTokenService;
|
|
1705
1676
|
var init_csrf_token_service = __esm({
|
|
1706
1677
|
"src/infrastructure/services/csrf/csrf-token.service.ts"() {
|
|
1707
1678
|
"use strict";
|
|
1708
|
-
|
|
1679
|
+
import_shared38 = require("@xeno-js/shared");
|
|
1709
1680
|
CsrfTokenService = class {
|
|
1710
1681
|
constructor(_secret, _cryptoService) {
|
|
1711
1682
|
this._secret = _secret;
|
|
@@ -1724,7 +1695,7 @@ var init_csrf_token_service = __esm({
|
|
|
1724
1695
|
if (separatorIndex <= 0) return false;
|
|
1725
1696
|
const nonce = token.slice(0, separatorIndex);
|
|
1726
1697
|
const signature = token.slice(separatorIndex + 1);
|
|
1727
|
-
if (
|
|
1698
|
+
if (import_shared38.Guards.isNullOrEmpty(nonce) || import_shared38.Guards.isNullOrEmpty(signature)) return false;
|
|
1728
1699
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1729
1700
|
const encoder = new TextEncoder();
|
|
1730
1701
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1745,11 +1716,11 @@ var init_csrf = __esm({
|
|
|
1745
1716
|
});
|
|
1746
1717
|
|
|
1747
1718
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1748
|
-
var
|
|
1719
|
+
var import_shared39, BearerTokenExtractor;
|
|
1749
1720
|
var init_extract_bearer_extractor = __esm({
|
|
1750
1721
|
"src/infrastructure/services/extractors/extract-bearer.extractor.ts"() {
|
|
1751
1722
|
"use strict";
|
|
1752
|
-
|
|
1723
|
+
import_shared39 = require("@xeno-js/shared");
|
|
1753
1724
|
BearerTokenExtractor = class {
|
|
1754
1725
|
constructor(_cookiePrefix) {
|
|
1755
1726
|
this._cookiePrefix = _cookiePrefix;
|
|
@@ -1757,14 +1728,14 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1757
1728
|
_cookiePrefix;
|
|
1758
1729
|
extract(headers) {
|
|
1759
1730
|
const authHeader = headers.get("Authorization");
|
|
1760
|
-
if (
|
|
1731
|
+
if (import_shared39.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1761
1732
|
return authHeader.substring(7);
|
|
1762
1733
|
}
|
|
1763
1734
|
const cookieHeader = headers.get("cookie");
|
|
1764
|
-
if (
|
|
1735
|
+
if (import_shared39.Guards.isDefined(cookieHeader)) {
|
|
1765
1736
|
const regex = new RegExp(`${this._cookiePrefix}=([^;]+)`);
|
|
1766
1737
|
const match = regex.exec(cookieHeader);
|
|
1767
|
-
if (!
|
|
1738
|
+
if (!import_shared39.Guards.isNullOrEmpty(match) && import_shared39.Guards.isDefined(match[1])) {
|
|
1768
1739
|
return match[1].trim();
|
|
1769
1740
|
}
|
|
1770
1741
|
}
|
|
@@ -1775,44 +1746,44 @@ var init_extract_bearer_extractor = __esm({
|
|
|
1775
1746
|
});
|
|
1776
1747
|
|
|
1777
1748
|
// src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts
|
|
1778
|
-
var
|
|
1749
|
+
var import_shared40, SupabaseSsrTokenExtractor;
|
|
1779
1750
|
var init_extract_ssr_bearer_extractor = __esm({
|
|
1780
1751
|
"src/infrastructure/services/extractors/extract-ssr-bearer.extractor.ts"() {
|
|
1781
1752
|
"use strict";
|
|
1782
|
-
|
|
1753
|
+
import_shared40 = require("@xeno-js/shared");
|
|
1783
1754
|
SupabaseSsrTokenExtractor = class {
|
|
1784
1755
|
extract(headers) {
|
|
1785
1756
|
const authHeader = headers.get("authorization");
|
|
1786
|
-
if (
|
|
1757
|
+
if (import_shared40.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1787
1758
|
return authHeader.substring(7);
|
|
1788
1759
|
}
|
|
1789
1760
|
const cookieHeader = headers.get("cookie");
|
|
1790
|
-
if (
|
|
1761
|
+
if (import_shared40.Guards.isNullOrEmpty(cookieHeader)) return void 0;
|
|
1791
1762
|
const cookies = cookieHeader.split(";").map((c) => c.trim());
|
|
1792
1763
|
const tokenChunks = {};
|
|
1793
1764
|
let unchunkedToken;
|
|
1794
1765
|
for (const cookie of cookies) {
|
|
1795
1766
|
const [name, ...rest] = cookie.split("=");
|
|
1796
|
-
if (!
|
|
1767
|
+
if (!import_shared40.Guards.isDefined(name) || import_shared40.Guards.isNullOrEmpty(rest)) continue;
|
|
1797
1768
|
const value = decodeURIComponent(rest.join("="));
|
|
1798
|
-
if (
|
|
1769
|
+
if (import_shared40.Guards.isDefined(/^sb-[a-z0-9]+-auth-token$/.exec(name))) {
|
|
1799
1770
|
unchunkedToken = value;
|
|
1800
1771
|
} else {
|
|
1801
1772
|
const match = /^sb-[a-z0-9]+-auth-token\.(\d+)$/.exec(name);
|
|
1802
|
-
if (
|
|
1773
|
+
if (import_shared40.Guards.isDefined(match)) tokenChunks[parseInt(match[1], 10)] = value;
|
|
1803
1774
|
}
|
|
1804
1775
|
}
|
|
1805
1776
|
let fullTokenString = unchunkedToken;
|
|
1806
|
-
if (!
|
|
1777
|
+
if (!import_shared40.Guards.isDefined(fullTokenString) && Object.keys(tokenChunks).length > 0) {
|
|
1807
1778
|
const indices = Object.keys(tokenChunks).map(Number).sort((a, b) => a - b);
|
|
1808
1779
|
fullTokenString = indices.map((i) => tokenChunks[i]).join("");
|
|
1809
1780
|
}
|
|
1810
|
-
if (
|
|
1781
|
+
if (import_shared40.Guards.isNullOrEmpty(fullTokenString)) return void 0;
|
|
1811
1782
|
try {
|
|
1812
|
-
const parsed =
|
|
1813
|
-
if (
|
|
1783
|
+
const parsed = import_shared40.StringHelper.safeParse(fullTokenString);
|
|
1784
|
+
if (import_shared40.Guards.isDefined(parsed) && import_shared40.Guards.isObject(parsed) && "access_token" in parsed) {
|
|
1814
1785
|
const accessToken = parsed["access_token"];
|
|
1815
|
-
if (
|
|
1786
|
+
if (import_shared40.Guards.isString(accessToken)) return accessToken;
|
|
1816
1787
|
}
|
|
1817
1788
|
} catch {
|
|
1818
1789
|
return void 0;
|
|
@@ -1823,14 +1794,14 @@ var init_extract_ssr_bearer_extractor = __esm({
|
|
|
1823
1794
|
});
|
|
1824
1795
|
|
|
1825
1796
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
1826
|
-
var
|
|
1797
|
+
var import_shared41, HttpCookieExtractor;
|
|
1827
1798
|
var init_http_cookie_extractor = __esm({
|
|
1828
1799
|
"src/infrastructure/services/extractors/http-cookie.extractor.ts"() {
|
|
1829
1800
|
"use strict";
|
|
1830
|
-
|
|
1801
|
+
import_shared41 = require("@xeno-js/shared");
|
|
1831
1802
|
HttpCookieExtractor = class {
|
|
1832
1803
|
extract(cookie) {
|
|
1833
|
-
if (!
|
|
1804
|
+
if (!import_shared41.Guards.isDefined(cookie.header)) return void 0;
|
|
1834
1805
|
for (const rawCookie of cookie.header.split(";")) {
|
|
1835
1806
|
const separatorIndex = rawCookie.indexOf("=");
|
|
1836
1807
|
if (separatorIndex <= 0) continue;
|
|
@@ -1850,11 +1821,11 @@ var init_http_cookie_extractor = __esm({
|
|
|
1850
1821
|
});
|
|
1851
1822
|
|
|
1852
1823
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
1853
|
-
var
|
|
1824
|
+
var import_shared42, HttpHeaderExtractor;
|
|
1854
1825
|
var init_http_header_extractor = __esm({
|
|
1855
1826
|
"src/infrastructure/services/extractors/http-header.extractor.ts"() {
|
|
1856
1827
|
"use strict";
|
|
1857
|
-
|
|
1828
|
+
import_shared42 = require("@xeno-js/shared");
|
|
1858
1829
|
HttpHeaderExtractor = class {
|
|
1859
1830
|
/**
|
|
1860
1831
|
* @description Constructor for HttpHeaderExtractor. It takes an instance of IServiceExtractor for extracting Bearer tokens, allowing for separation of concerns and adherence to the Single Responsibility Principle (SRP). This design enables the HttpHeaderExtractor to focus on general header extraction while delegating the specific logic of Bearer token extraction to a dedicated extractor, promoting code reusability and maintainability.
|
|
@@ -1876,11 +1847,11 @@ var init_http_header_extractor = __esm({
|
|
|
1876
1847
|
_trustedIp;
|
|
1877
1848
|
_cookieName;
|
|
1878
1849
|
extract(headers) {
|
|
1879
|
-
const correlationId =
|
|
1880
|
-
const requestId =
|
|
1850
|
+
const correlationId = import_shared42.GuidHelper.parse(headers.get("x-correlation-id") ?? void 0);
|
|
1851
|
+
const requestId = import_shared42.GuidHelper.parse(headers.get("x-request-id") ?? void 0);
|
|
1881
1852
|
const token = this._bearerExtractor.extract(headers);
|
|
1882
1853
|
const clientIp = headers.get(this._trustedIp?.toLowerCase() ?? "x-forwarded-for") ?? headers.get("x-real-ip") ?? void 0;
|
|
1883
|
-
const spanId =
|
|
1854
|
+
const spanId = import_shared42.GuidHelper.parse(headers.get("x-span-id") ?? void 0);
|
|
1884
1855
|
const parentSpanId = headers.get("x-parent-span-id") ?? void 0;
|
|
1885
1856
|
const acceptHeader = headers.get("accept");
|
|
1886
1857
|
const contentTypeHeader = headers.get("content-type");
|
|
@@ -1897,9 +1868,9 @@ var init_http_header_extractor = __esm({
|
|
|
1897
1868
|
name: this._cookieName
|
|
1898
1869
|
});
|
|
1899
1870
|
const origin = headers.get("origin") ?? void 0;
|
|
1900
|
-
const cleanOrigin =
|
|
1871
|
+
const cleanOrigin = import_shared42.HttpHelper.sanitizeOriginUrl(origin);
|
|
1901
1872
|
const referer = headers.get("referer") ?? void 0;
|
|
1902
|
-
const cleanReferer =
|
|
1873
|
+
const cleanReferer = import_shared42.HttpHelper.sanitizeOriginUrl(referer);
|
|
1903
1874
|
const accept = acceptHeader === "*/*" ? void 0 : acceptHeader;
|
|
1904
1875
|
const formatIndicator = accept ?? contentTypeHeader ?? "application/json";
|
|
1905
1876
|
const metadata = {
|
|
@@ -1918,10 +1889,10 @@ var init_http_header_extractor = __esm({
|
|
|
1918
1889
|
referer: cleanReferer,
|
|
1919
1890
|
sequence: {
|
|
1920
1891
|
sequenceId,
|
|
1921
|
-
position:
|
|
1922
|
-
size:
|
|
1892
|
+
position: import_shared42.Guards.isDefined(position) ? import_shared42.MathHelper.toNumber(position) : void 0,
|
|
1893
|
+
size: import_shared42.Guards.isDefined(size) ? import_shared42.MathHelper.toNumber(size) : void 0
|
|
1923
1894
|
},
|
|
1924
|
-
expiration:
|
|
1895
|
+
expiration: import_shared42.Guards.isDefined(expiration) ? import_shared42.MathHelper.toNumber(expiration) : void 0
|
|
1925
1896
|
};
|
|
1926
1897
|
return metadata;
|
|
1927
1898
|
}
|
|
@@ -1941,18 +1912,18 @@ var init_extractors = __esm({
|
|
|
1941
1912
|
});
|
|
1942
1913
|
|
|
1943
1914
|
// src/infrastructure/services/resiliences/resilience.service.ts
|
|
1944
|
-
var
|
|
1915
|
+
var import_shared43, ServiceResilience;
|
|
1945
1916
|
var init_resilience_service = __esm({
|
|
1946
1917
|
"src/infrastructure/services/resiliences/resilience.service.ts"() {
|
|
1947
1918
|
"use strict";
|
|
1948
|
-
|
|
1919
|
+
import_shared43 = require("@xeno-js/shared");
|
|
1949
1920
|
ServiceResilience = class {
|
|
1950
1921
|
constructor(policy) {
|
|
1951
1922
|
this.policy = policy;
|
|
1952
1923
|
}
|
|
1953
1924
|
policy;
|
|
1954
1925
|
async execute(operation, signal) {
|
|
1955
|
-
|
|
1926
|
+
import_shared43.AppError.throwIfAborted(signal, "ServiceResilience.execute");
|
|
1956
1927
|
return this.policy.execute(() => operation(), signal);
|
|
1957
1928
|
}
|
|
1958
1929
|
};
|
|
@@ -1968,11 +1939,11 @@ var init_resiliences = __esm({
|
|
|
1968
1939
|
});
|
|
1969
1940
|
|
|
1970
1941
|
// src/infrastructure/services/resolver/utils/socket.utils.ts
|
|
1971
|
-
var
|
|
1942
|
+
var import_shared44, SocketIpExtractor;
|
|
1972
1943
|
var init_socket_utils = __esm({
|
|
1973
1944
|
"src/infrastructure/services/resolver/utils/socket.utils.ts"() {
|
|
1974
1945
|
"use strict";
|
|
1975
|
-
|
|
1946
|
+
import_shared44 = require("@xeno-js/shared");
|
|
1976
1947
|
SocketIpExtractor = Object.freeze({
|
|
1977
1948
|
/**
|
|
1978
1949
|
* @description Extracts the IP address of the remote socket from an incoming request.
|
|
@@ -1980,7 +1951,7 @@ var init_socket_utils = __esm({
|
|
|
1980
1951
|
* @returns The IP address of the remote socket, or undefined if not available.
|
|
1981
1952
|
*/
|
|
1982
1953
|
extract(req) {
|
|
1983
|
-
if (
|
|
1954
|
+
if (import_shared44.Guards.isDefined(req) && import_shared44.Guards.isObject(req)) {
|
|
1984
1955
|
const candidate = req;
|
|
1985
1956
|
return candidate.socket?.remoteAddress ?? candidate.connection?.remoteAddress;
|
|
1986
1957
|
}
|
|
@@ -1999,11 +1970,11 @@ var init_utils = __esm({
|
|
|
1999
1970
|
});
|
|
2000
1971
|
|
|
2001
1972
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
2002
|
-
var
|
|
1973
|
+
var import_shared45, ClientIpResolver;
|
|
2003
1974
|
var init_client_ip_resolver = __esm({
|
|
2004
1975
|
"src/infrastructure/services/resolver/client-ip.resolver.ts"() {
|
|
2005
1976
|
"use strict";
|
|
2006
|
-
|
|
1977
|
+
import_shared45 = require("@xeno-js/shared");
|
|
2007
1978
|
init_utils();
|
|
2008
1979
|
ClientIpResolver = class {
|
|
2009
1980
|
constructor(_trustedProxies = []) {
|
|
@@ -2012,11 +1983,11 @@ var init_client_ip_resolver = __esm({
|
|
|
2012
1983
|
_trustedProxies;
|
|
2013
1984
|
resolve(req, clientIp) {
|
|
2014
1985
|
const socketIp = SocketIpExtractor.extract(req);
|
|
2015
|
-
if (!
|
|
2016
|
-
return !
|
|
1986
|
+
if (!import_shared45.Guards.isDefined(socketIp))
|
|
1987
|
+
return !import_shared45.Guards.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
2017
1988
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
2018
1989
|
if (!isTrustedProxy) return socketIp;
|
|
2019
|
-
if (
|
|
1990
|
+
if (import_shared45.Guards.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
2020
1991
|
return socketIp;
|
|
2021
1992
|
}
|
|
2022
1993
|
};
|
|
@@ -2067,12 +2038,12 @@ var supabase_factory_exports = {};
|
|
|
2067
2038
|
__export(supabase_factory_exports, {
|
|
2068
2039
|
SupabaseServerAuthFactory: () => SupabaseServerAuthFactory
|
|
2069
2040
|
});
|
|
2070
|
-
var import_ssr,
|
|
2041
|
+
var import_ssr, import_shared46, import_supabase, SupabaseServerAuthFactory;
|
|
2071
2042
|
var init_supabase_factory = __esm({
|
|
2072
2043
|
"src/infrastructure/factories/supabase.factory.ts"() {
|
|
2073
2044
|
"use strict";
|
|
2074
2045
|
import_ssr = require("@supabase/ssr");
|
|
2075
|
-
|
|
2046
|
+
import_shared46 = require("@xeno-js/shared");
|
|
2076
2047
|
import_supabase = require("@xeno-js/shared/supabase");
|
|
2077
2048
|
init_services();
|
|
2078
2049
|
SupabaseServerAuthFactory = class {
|
|
@@ -2097,12 +2068,12 @@ var init_supabase_factory = __esm({
|
|
|
2097
2068
|
return new import_supabase.SupabaseAuthService(client, mapper, sessionMapper, config);
|
|
2098
2069
|
}
|
|
2099
2070
|
_getCookieSsr(ssrOpts, container, config) {
|
|
2100
|
-
if (
|
|
2071
|
+
if (import_shared46.Guards.isDefined(ssrOpts)) {
|
|
2101
2072
|
return ssrOpts(container);
|
|
2102
2073
|
} else {
|
|
2103
2074
|
return new CookieHandler(
|
|
2104
|
-
container.resolve(
|
|
2105
|
-
container.resolve(
|
|
2075
|
+
container.resolve(import_shared46.TOKENS.NETWORK_CONTEXT_ACCESSOR),
|
|
2076
|
+
container.resolve(import_shared46.TOKENS.CONFIGURATION_SERVICE),
|
|
2106
2077
|
config
|
|
2107
2078
|
);
|
|
2108
2079
|
}
|
|
@@ -2292,11 +2263,11 @@ var init_validation_utils = __esm({
|
|
|
2292
2263
|
});
|
|
2293
2264
|
|
|
2294
2265
|
// src/infrastructure/idempotency/idempotency-store.ts
|
|
2295
|
-
var
|
|
2266
|
+
var import_shared47, IdempotencyStore;
|
|
2296
2267
|
var init_idempotency_store = __esm({
|
|
2297
2268
|
"src/infrastructure/idempotency/idempotency-store.ts"() {
|
|
2298
2269
|
"use strict";
|
|
2299
|
-
|
|
2270
|
+
import_shared47 = require("@xeno-js/shared");
|
|
2300
2271
|
IdempotencyStore = class {
|
|
2301
2272
|
/**
|
|
2302
2273
|
* @description Constructs a new instance of IdempotencyStore, accepting an instance of ICache for accessing the caching system and an instance of IIdentityAccessor for obtaining the user's identity context. The IdempotencyStore uses the caching system to manage locks and results of idempotent commands, ensuring that commands with the same ID are processed only once. The identity context is used to build contextual keys, allowing for more granular management of idempotent commands in multi-tenant scenarios.
|
|
@@ -2318,31 +2289,31 @@ var init_idempotency_store = __esm({
|
|
|
2318
2289
|
async acquireLock(requestId, ttlSeconds) {
|
|
2319
2290
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
2320
2291
|
return await this._cache.setIfAbsent(
|
|
2321
|
-
`${
|
|
2322
|
-
|
|
2292
|
+
`${import_shared47.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`,
|
|
2293
|
+
import_shared47.IDEMPOTENCY_CONSTANTS.LOCKED_VALUE,
|
|
2323
2294
|
ttlSeconds
|
|
2324
2295
|
);
|
|
2325
2296
|
}
|
|
2326
2297
|
async hasBeenProcessed(commandId) {
|
|
2327
2298
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2328
|
-
return await this._cache.has(`${
|
|
2299
|
+
return await this._cache.has(`${import_shared47.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
2329
2300
|
}
|
|
2330
2301
|
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
2331
2302
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2332
2303
|
await this._cache.set(
|
|
2333
|
-
`${
|
|
2304
|
+
`${import_shared47.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`,
|
|
2334
2305
|
payload,
|
|
2335
2306
|
ttlSeconds
|
|
2336
2307
|
);
|
|
2337
2308
|
}
|
|
2338
2309
|
async getPayload(commandId) {
|
|
2339
2310
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2340
|
-
const payload = await this._cache.get(`${
|
|
2311
|
+
const payload = await this._cache.get(`${import_shared47.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
2341
2312
|
return payload;
|
|
2342
2313
|
}
|
|
2343
2314
|
async releaseLock(commandId) {
|
|
2344
2315
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2345
|
-
await this._cache.remove(`${
|
|
2316
|
+
await this._cache.remove(`${import_shared47.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`);
|
|
2346
2317
|
}
|
|
2347
2318
|
};
|
|
2348
2319
|
}
|
|
@@ -2624,12 +2595,12 @@ var unit_of_work_exports = {};
|
|
|
2624
2595
|
__export(unit_of_work_exports, {
|
|
2625
2596
|
UnitOfWork: () => UnitOfWork
|
|
2626
2597
|
});
|
|
2627
|
-
var
|
|
2598
|
+
var import_shared48, import_shared49, UnitOfWork;
|
|
2628
2599
|
var init_unit_of_work = __esm({
|
|
2629
2600
|
"src/infrastructure/transaction/unit-of-work.ts"() {
|
|
2630
2601
|
"use strict";
|
|
2602
|
+
import_shared48 = require("@xeno-js/shared");
|
|
2631
2603
|
import_shared49 = require("@xeno-js/shared");
|
|
2632
|
-
import_shared50 = require("@xeno-js/shared");
|
|
2633
2604
|
UnitOfWork = class {
|
|
2634
2605
|
/**
|
|
2635
2606
|
* Creates an instance of UnitOfWork.
|
|
@@ -2648,7 +2619,7 @@ var init_unit_of_work = __esm({
|
|
|
2648
2619
|
_dbContext;
|
|
2649
2620
|
_ttx;
|
|
2650
2621
|
async runInTransaction(callback, signal) {
|
|
2651
|
-
|
|
2622
|
+
import_shared48.AppError.throwIfAborted(signal, "UnitOfWork.runInTransaction");
|
|
2652
2623
|
return this._dbContext.transaction(async (tx) => {
|
|
2653
2624
|
this._ttx.state = tx;
|
|
2654
2625
|
try {
|
|
@@ -2660,9 +2631,9 @@ var init_unit_of_work = __esm({
|
|
|
2660
2631
|
});
|
|
2661
2632
|
}
|
|
2662
2633
|
async dispose() {
|
|
2663
|
-
if (
|
|
2634
|
+
if (import_shared49.Guards.isDefined(this._ttx.state)) {
|
|
2664
2635
|
try {
|
|
2665
|
-
if (
|
|
2636
|
+
if (import_shared49.Guards.hasMethod(this._ttx.state, "rollback")) {
|
|
2666
2637
|
await this._ttx.state.rollback();
|
|
2667
2638
|
}
|
|
2668
2639
|
} finally {
|
|
@@ -2718,11 +2689,11 @@ var init_db_module = __esm({
|
|
|
2718
2689
|
});
|
|
2719
2690
|
|
|
2720
2691
|
// src/infrastructure/http/base.http-adapter.ts
|
|
2721
|
-
var
|
|
2692
|
+
var import_shared50, BaseHttpAdapter;
|
|
2722
2693
|
var init_base_http_adapter = __esm({
|
|
2723
2694
|
"src/infrastructure/http/base.http-adapter.ts"() {
|
|
2724
2695
|
"use strict";
|
|
2725
|
-
|
|
2696
|
+
import_shared50 = require("@xeno-js/shared");
|
|
2726
2697
|
BaseHttpAdapter = class {
|
|
2727
2698
|
/**
|
|
2728
2699
|
* @description Parse the URL from the request.
|
|
@@ -2732,15 +2703,15 @@ var init_base_http_adapter = __esm({
|
|
|
2732
2703
|
* @returns The parsed URL.
|
|
2733
2704
|
*/
|
|
2734
2705
|
parseUrl(rawUrl = "/", headers, queryParams) {
|
|
2735
|
-
const protocol =
|
|
2736
|
-
const host =
|
|
2706
|
+
const protocol = import_shared50.StringHelper.getSingleValue(headers["x-forwarded-proto"]) ?? "https";
|
|
2707
|
+
const host = import_shared50.StringHelper.safeStringify(headers["host"]) ?? "localhost";
|
|
2737
2708
|
const cleanHost = host.replace(/['"]/g, "");
|
|
2738
2709
|
const url = new URL(rawUrl, `${protocol}://${cleanHost}`);
|
|
2739
|
-
if (!
|
|
2710
|
+
if (!import_shared50.Guards.isNullOrEmpty(queryParams)) {
|
|
2740
2711
|
for (const [key, value] of Object.entries(queryParams)) {
|
|
2741
|
-
if (
|
|
2712
|
+
if (import_shared50.Guards.isArray(value)) {
|
|
2742
2713
|
value.forEach((v) => url.searchParams.append(key, String(v)));
|
|
2743
|
-
} else if (
|
|
2714
|
+
} else if (import_shared50.Guards.isDefined(value)) {
|
|
2744
2715
|
url.searchParams.set(key, String(value));
|
|
2745
2716
|
}
|
|
2746
2717
|
}
|
|
@@ -2755,8 +2726,8 @@ var init_base_http_adapter = __esm({
|
|
|
2755
2726
|
parseHeaders(rawHeaders) {
|
|
2756
2727
|
const headers = new Headers();
|
|
2757
2728
|
for (const [key, value] of Object.entries(rawHeaders)) {
|
|
2758
|
-
if (
|
|
2759
|
-
if (
|
|
2729
|
+
if (import_shared50.Guards.isDefined(value)) {
|
|
2730
|
+
if (import_shared50.Guards.isArray(value)) {
|
|
2760
2731
|
value.forEach((v) => headers.append(key, String(v)));
|
|
2761
2732
|
} else {
|
|
2762
2733
|
headers.set(key, String(value));
|
|
@@ -2772,10 +2743,10 @@ var init_base_http_adapter = __esm({
|
|
|
2772
2743
|
* @returns The parsed body.
|
|
2773
2744
|
*/
|
|
2774
2745
|
parseBody(method, rawBody) {
|
|
2775
|
-
if (!
|
|
2746
|
+
if (!import_shared50.Guards.isDefined(method) || !["POST", "PUT", "PATCH", "DELETE"].includes(method.toUpperCase()) || !import_shared50.Guards.isDefined(rawBody))
|
|
2776
2747
|
return void 0;
|
|
2777
|
-
if (
|
|
2778
|
-
if (
|
|
2748
|
+
if (import_shared50.Guards.isObject(rawBody)) return JSON.stringify(rawBody);
|
|
2749
|
+
if (import_shared50.Guards.isString(rawBody) || rawBody instanceof Blob || rawBody instanceof ArrayBuffer || ArrayBuffer.isView(rawBody) || rawBody instanceof URLSearchParams || rawBody instanceof FormData)
|
|
2779
2750
|
return rawBody;
|
|
2780
2751
|
return String(rawBody);
|
|
2781
2752
|
}
|
|
@@ -2793,14 +2764,14 @@ var init_base_http_adapter = __esm({
|
|
|
2793
2764
|
headers
|
|
2794
2765
|
};
|
|
2795
2766
|
const parsedBody = this.parseBody(method, body);
|
|
2796
|
-
if (
|
|
2767
|
+
if (import_shared50.Guards.isDefined(parsedBody)) {
|
|
2797
2768
|
init2.body = parsedBody;
|
|
2798
2769
|
init2.duplex = "half";
|
|
2799
2770
|
}
|
|
2800
2771
|
const extendedRequest = new Request(url, init2);
|
|
2801
2772
|
extendedRequest.path = url.pathname;
|
|
2802
2773
|
const webResponse = new Response();
|
|
2803
|
-
if (
|
|
2774
|
+
if (import_shared50.Guards.isDefined(res)) {
|
|
2804
2775
|
const originalAppend = webResponse.headers.append.bind(webResponse.headers);
|
|
2805
2776
|
const originalSet = webResponse.headers.set.bind(webResponse.headers);
|
|
2806
2777
|
const originalDelete = webResponse.headers.delete.bind(webResponse.headers);
|
|
@@ -2831,11 +2802,11 @@ var vercel_http_adapter_exports = {};
|
|
|
2831
2802
|
__export(vercel_http_adapter_exports, {
|
|
2832
2803
|
VercelHttpAdapter: () => VercelHttpAdapter
|
|
2833
2804
|
});
|
|
2834
|
-
var
|
|
2805
|
+
var import_shared51, VercelHttpAdapter;
|
|
2835
2806
|
var init_vercel_http_adapter = __esm({
|
|
2836
2807
|
"src/infrastructure/http/vercel.http-adapter.ts"() {
|
|
2837
2808
|
"use strict";
|
|
2838
|
-
|
|
2809
|
+
import_shared51 = require("@xeno-js/shared");
|
|
2839
2810
|
init_base_http_adapter();
|
|
2840
2811
|
VercelHttpAdapter = class extends BaseHttpAdapter {
|
|
2841
2812
|
adapt(req, res) {
|
|
@@ -2851,9 +2822,9 @@ var init_vercel_http_adapter = __esm({
|
|
|
2851
2822
|
if (name.toLowerCase() === "set-cookie") {
|
|
2852
2823
|
const existing = res.getHeader("Set-Cookie");
|
|
2853
2824
|
let cookies = [];
|
|
2854
|
-
if (
|
|
2825
|
+
if (import_shared51.Guards.isArray(existing)) {
|
|
2855
2826
|
cookies = existing;
|
|
2856
|
-
} else if (
|
|
2827
|
+
} else if (import_shared51.Guards.isString(existing)) {
|
|
2857
2828
|
cookies = [existing];
|
|
2858
2829
|
}
|
|
2859
2830
|
if (action === "append") {
|
|
@@ -2875,11 +2846,11 @@ var fastify_http_adapter_exports = {};
|
|
|
2875
2846
|
__export(fastify_http_adapter_exports, {
|
|
2876
2847
|
FastifyHttpAdapter: () => FastifyHttpAdapter
|
|
2877
2848
|
});
|
|
2878
|
-
var
|
|
2849
|
+
var import_shared52, FastifyHttpAdapter;
|
|
2879
2850
|
var init_fastify_http_adapter = __esm({
|
|
2880
2851
|
"src/infrastructure/http/fastify.http-adapter.ts"() {
|
|
2881
2852
|
"use strict";
|
|
2882
|
-
|
|
2853
|
+
import_shared52 = require("@xeno-js/shared");
|
|
2883
2854
|
init_base_http_adapter();
|
|
2884
2855
|
FastifyHttpAdapter = class extends BaseHttpAdapter {
|
|
2885
2856
|
adapt(req, res) {
|
|
@@ -2896,9 +2867,9 @@ var init_fastify_http_adapter = __esm({
|
|
|
2896
2867
|
if (name.toLowerCase() === "set-cookie") {
|
|
2897
2868
|
const existing = res.getHeader("set-cookie");
|
|
2898
2869
|
let cookies = [];
|
|
2899
|
-
if (
|
|
2870
|
+
if (import_shared52.Guards.isArray(existing)) {
|
|
2900
2871
|
cookies = existing;
|
|
2901
|
-
} else if (
|
|
2872
|
+
} else if (import_shared52.Guards.isString(existing)) {
|
|
2902
2873
|
cookies = [existing];
|
|
2903
2874
|
}
|
|
2904
2875
|
if (action === "append") {
|
|
@@ -2942,11 +2913,11 @@ var init_native_http_adapter = __esm({
|
|
|
2942
2913
|
});
|
|
2943
2914
|
|
|
2944
2915
|
// src/infrastructure/modules/http-adapter.module.ts
|
|
2945
|
-
var
|
|
2916
|
+
var import_shared53, HttpAdapterModule;
|
|
2946
2917
|
var init_http_adapter_module = __esm({
|
|
2947
2918
|
"src/infrastructure/modules/http-adapter.module.ts"() {
|
|
2948
2919
|
"use strict";
|
|
2949
|
-
|
|
2920
|
+
import_shared53 = require("@xeno-js/shared");
|
|
2950
2921
|
HttpAdapterModule = class {
|
|
2951
2922
|
async configure(container, opts) {
|
|
2952
2923
|
const adapter = await this._getAdapter(opts);
|
|
@@ -2959,7 +2930,7 @@ var init_http_adapter_module = __esm({
|
|
|
2959
2930
|
} else if (opts.fastify) {
|
|
2960
2931
|
const { FastifyHttpAdapter: FastifyHttpAdapter2 } = await Promise.resolve().then(() => (init_fastify_http_adapter(), fastify_http_adapter_exports));
|
|
2961
2932
|
return new FastifyHttpAdapter2();
|
|
2962
|
-
} else if (
|
|
2933
|
+
} else if (import_shared53.Guards.isDefined(opts.custom)) {
|
|
2963
2934
|
return opts.custom();
|
|
2964
2935
|
} else {
|
|
2965
2936
|
const { NativeHttpAdapter: NativeHttpAdapter2 } = await Promise.resolve().then(() => (init_native_http_adapter(), native_http_adapter_exports));
|
|
@@ -3019,11 +2990,11 @@ var cockatiel_resilience_factory_exports = {};
|
|
|
3019
2990
|
__export(cockatiel_resilience_factory_exports, {
|
|
3020
2991
|
CockatielResilienceFactory: () => CockatielResilienceFactory
|
|
3021
2992
|
});
|
|
3022
|
-
var
|
|
2993
|
+
var import_shared54, import_cockatiel, CockatielResilienceFactory;
|
|
3023
2994
|
var init_cockatiel_resilience_factory = __esm({
|
|
3024
2995
|
"src/infrastructure/factories/cockatiel-resilience.factory.ts"() {
|
|
3025
2996
|
"use strict";
|
|
3026
|
-
|
|
2997
|
+
import_shared54 = require("@xeno-js/shared");
|
|
3027
2998
|
import_cockatiel = require("cockatiel");
|
|
3028
2999
|
init_resilience_service();
|
|
3029
3000
|
CockatielResilienceFactory = class {
|
|
@@ -3033,36 +3004,36 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
3033
3004
|
retry: {
|
|
3034
3005
|
attempts: this.checkConfigValue(
|
|
3035
3006
|
config.retry.attempts,
|
|
3036
|
-
|
|
3007
|
+
import_shared54.RESILIENCE_DEFAULTS.RETRY.ATTEMPTS,
|
|
3037
3008
|
message
|
|
3038
3009
|
),
|
|
3039
3010
|
baseDelayMs: this.checkConfigValue(
|
|
3040
3011
|
config.retry.baseDelayMs,
|
|
3041
|
-
|
|
3012
|
+
import_shared54.RESILIENCE_DEFAULTS.RETRY.BASE_DELAY_MS,
|
|
3042
3013
|
message
|
|
3043
3014
|
),
|
|
3044
3015
|
maxDelayMs: this.checkConfigValue(
|
|
3045
3016
|
config.retry.maxDelayMs,
|
|
3046
|
-
|
|
3017
|
+
import_shared54.RESILIENCE_DEFAULTS.RETRY.MAX_DELAY_MS,
|
|
3047
3018
|
message
|
|
3048
3019
|
)
|
|
3049
3020
|
},
|
|
3050
3021
|
circuitBreaker: {
|
|
3051
3022
|
consecutiveFailures: this.checkConfigValue(
|
|
3052
3023
|
config.circuitBreaker.consecutiveFailures,
|
|
3053
|
-
|
|
3024
|
+
import_shared54.RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.CONSECUTIVE_FAILURES,
|
|
3054
3025
|
message
|
|
3055
3026
|
),
|
|
3056
3027
|
halfOpenTimeoutMs: this.checkConfigValue(
|
|
3057
3028
|
config.circuitBreaker.halfOpenTimeoutMs,
|
|
3058
|
-
|
|
3029
|
+
import_shared54.RESILIENCE_DEFAULTS.CIRCUIT_BREAKER.HALF_OPEN_TIMEOUT_MS,
|
|
3059
3030
|
message
|
|
3060
3031
|
)
|
|
3061
3032
|
},
|
|
3062
3033
|
bulkhead: {
|
|
3063
3034
|
maxConcurrent: this.checkConfigValue(
|
|
3064
3035
|
config.bulkhead.maxConcurrent,
|
|
3065
|
-
|
|
3036
|
+
import_shared54.RESILIENCE_DEFAULTS.BULKHEAD.MAX_CONCURRENT,
|
|
3066
3037
|
message
|
|
3067
3038
|
)
|
|
3068
3039
|
}
|
|
@@ -3088,13 +3059,13 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
3088
3059
|
return new ServiceResilience((0, import_cockatiel.wrap)(bulkheadPolicy, circuitBreakerPolicy, retryPolicy));
|
|
3089
3060
|
}
|
|
3090
3061
|
isTransientError(error) {
|
|
3091
|
-
if (!
|
|
3062
|
+
if (!import_shared54.Guards.isDefined(error) || !import_shared54.Guards.isObject(error)) return false;
|
|
3092
3063
|
let status;
|
|
3093
3064
|
let isNetworkError = false;
|
|
3094
|
-
if (error instanceof
|
|
3065
|
+
if (error instanceof import_shared54.AppError) {
|
|
3095
3066
|
status = error.status;
|
|
3096
3067
|
const cause = error.cause;
|
|
3097
|
-
if (
|
|
3068
|
+
if (import_shared54.Guards.isDefined(cause) && import_shared54.Guards.isString(cause.code)) {
|
|
3098
3069
|
isNetworkError = [
|
|
3099
3070
|
"ECONNABORTED",
|
|
3100
3071
|
"ECONNRESET",
|
|
@@ -3106,7 +3077,7 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
3106
3077
|
} else {
|
|
3107
3078
|
const err = error;
|
|
3108
3079
|
status = err.status;
|
|
3109
|
-
if (
|
|
3080
|
+
if (import_shared54.Guards.isString(err.code)) {
|
|
3110
3081
|
isNetworkError = [
|
|
3111
3082
|
"ECONNABORTED",
|
|
3112
3083
|
"ECONNRESET",
|
|
@@ -3117,30 +3088,30 @@ var init_cockatiel_resilience_factory = __esm({
|
|
|
3117
3088
|
}
|
|
3118
3089
|
}
|
|
3119
3090
|
if (isNetworkError) return true;
|
|
3120
|
-
if (
|
|
3091
|
+
if (import_shared54.Guards.isDefined(status)) return status === 408 || status >= 500 && status < 600;
|
|
3121
3092
|
return false;
|
|
3122
3093
|
}
|
|
3123
3094
|
isTransientAndIdempotent(error) {
|
|
3124
3095
|
if (!this.isTransientError(error)) return false;
|
|
3125
3096
|
let method;
|
|
3126
|
-
if (error instanceof
|
|
3097
|
+
if (error instanceof import_shared54.AppError) {
|
|
3127
3098
|
const cause = error.cause;
|
|
3128
|
-
if (
|
|
3099
|
+
if (import_shared54.Guards.isDefined(cause) && import_shared54.Guards.isDefined(cause.config) && import_shared54.Guards.isString(cause.config.method)) {
|
|
3129
3100
|
method = cause.config.method.toUpperCase();
|
|
3130
3101
|
}
|
|
3131
3102
|
} else {
|
|
3132
3103
|
const err = error;
|
|
3133
|
-
if (
|
|
3104
|
+
if (import_shared54.Guards.isDefined(err.config) && import_shared54.Guards.isString(err.config.method)) {
|
|
3134
3105
|
method = err.config.method.toUpperCase();
|
|
3135
3106
|
}
|
|
3136
3107
|
}
|
|
3137
|
-
if (
|
|
3108
|
+
if (import_shared54.Guards.isNullOrEmpty(method)) return false;
|
|
3138
3109
|
const idempotentMethods = ["GET", "PUT", "DELETE", "HEAD", "OPTIONS"];
|
|
3139
3110
|
return idempotentMethods.includes(method);
|
|
3140
3111
|
}
|
|
3141
3112
|
checkConfigValue(value, defaultValue, message) {
|
|
3142
|
-
if (
|
|
3143
|
-
|
|
3113
|
+
if (import_shared54.Guards.isDefined(value)) {
|
|
3114
|
+
import_shared54.Guards.throwIfNegative(value, message);
|
|
3144
3115
|
return value;
|
|
3145
3116
|
}
|
|
3146
3117
|
return defaultValue;
|
|
@@ -3228,11 +3199,11 @@ var init_http_core_module = __esm({
|
|
|
3228
3199
|
});
|
|
3229
3200
|
|
|
3230
3201
|
// src/presentation/controllers/base.controller.ts
|
|
3231
|
-
var
|
|
3202
|
+
var import_shared55, BaseController;
|
|
3232
3203
|
var init_base_controller = __esm({
|
|
3233
3204
|
"src/presentation/controllers/base.controller.ts"() {
|
|
3234
3205
|
"use strict";
|
|
3235
|
-
|
|
3206
|
+
import_shared55 = require("@xeno-js/shared");
|
|
3236
3207
|
BaseController = class {
|
|
3237
3208
|
/**
|
|
3238
3209
|
* Constructs a new instance of the BaseController class.
|
|
@@ -3264,7 +3235,7 @@ var init_base_controller = __esm({
|
|
|
3264
3235
|
* @link https://github.com/xeno-js/xeno-js
|
|
3265
3236
|
*/
|
|
3266
3237
|
ok(data, status = 200, meta = {}, headers = {}) {
|
|
3267
|
-
return
|
|
3238
|
+
return import_shared55.HttpHelper.success(data, status, meta, headers);
|
|
3268
3239
|
}
|
|
3269
3240
|
/**
|
|
3270
3241
|
* Helper to automatically map a failed Result (from the CQRS pipeline)
|
|
@@ -3282,7 +3253,7 @@ var init_base_controller = __esm({
|
|
|
3282
3253
|
fail(error, details = void 0, headers = {}) {
|
|
3283
3254
|
const context = this._requestContext.getContext();
|
|
3284
3255
|
const customHeaders = error["header"];
|
|
3285
|
-
return
|
|
3256
|
+
return import_shared55.HttpHelper.error(
|
|
3286
3257
|
{
|
|
3287
3258
|
success: false,
|
|
3288
3259
|
error: {
|
|
@@ -3291,9 +3262,9 @@ var init_base_controller = __esm({
|
|
|
3291
3262
|
path: context?.network.path,
|
|
3292
3263
|
details: details ?? error.message
|
|
3293
3264
|
},
|
|
3294
|
-
correlationId: context?.tracing.correlationId ??
|
|
3295
|
-
requestId: context?.network.requestId ??
|
|
3296
|
-
spanId: context?.tracing.spanId ??
|
|
3265
|
+
correlationId: context?.tracing.correlationId ?? import_shared55.GuidHelper.generate(),
|
|
3266
|
+
requestId: context?.network.requestId ?? import_shared55.GuidHelper.generate(),
|
|
3267
|
+
spanId: context?.tracing.spanId ?? import_shared55.GuidHelper.generate(),
|
|
3297
3268
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3298
3269
|
},
|
|
3299
3270
|
error.status,
|
|
@@ -3348,11 +3319,11 @@ var init_controllers = __esm({
|
|
|
3348
3319
|
});
|
|
3349
3320
|
|
|
3350
3321
|
// src/presentation/middlewares/allow-method.middleware.ts
|
|
3351
|
-
var
|
|
3322
|
+
var import_shared56, MethodCheckMiddleware;
|
|
3352
3323
|
var init_allow_method_middleware = __esm({
|
|
3353
3324
|
"src/presentation/middlewares/allow-method.middleware.ts"() {
|
|
3354
3325
|
"use strict";
|
|
3355
|
-
|
|
3326
|
+
import_shared56 = require("@xeno-js/shared");
|
|
3356
3327
|
MethodCheckMiddleware = class {
|
|
3357
3328
|
constructor(_requestContext, _allowMethod) {
|
|
3358
3329
|
this._requestContext = _requestContext;
|
|
@@ -3364,21 +3335,21 @@ var init_allow_method_middleware = __esm({
|
|
|
3364
3335
|
const isAllowed = this._allowMethod.check(req.path, req.method);
|
|
3365
3336
|
if (!isAllowed) {
|
|
3366
3337
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3367
|
-
return
|
|
3338
|
+
return import_shared56.HttpHelper.error(
|
|
3368
3339
|
{
|
|
3369
3340
|
success: false,
|
|
3370
3341
|
error: {
|
|
3371
|
-
code:
|
|
3372
|
-
message:
|
|
3342
|
+
code: import_shared56.ERROR_CODES.NOT_ALLOWED,
|
|
3343
|
+
message: import_shared56.ERROR_CODE_MESSAGES[import_shared56.ERROR_CODES.NOT_ALLOWED],
|
|
3373
3344
|
details: `Operation blocked by allow method middleware`,
|
|
3374
3345
|
path: req.path
|
|
3375
3346
|
},
|
|
3376
|
-
correlationId: tracing?.correlationId ??
|
|
3377
|
-
requestId: network?.requestId ??
|
|
3378
|
-
spanId: tracing?.spanId ??
|
|
3347
|
+
correlationId: tracing?.correlationId ?? import_shared56.GuidHelper.generate(),
|
|
3348
|
+
requestId: network?.requestId ?? import_shared56.GuidHelper.generate(),
|
|
3349
|
+
spanId: tracing?.spanId ?? import_shared56.GuidHelper.generate(),
|
|
3379
3350
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3380
3351
|
},
|
|
3381
|
-
|
|
3352
|
+
import_shared56.STATUS_CODES.NOT_ALLOWED,
|
|
3382
3353
|
{
|
|
3383
3354
|
Allow: this._allowMethod.getMethods(req.path)
|
|
3384
3355
|
}
|
|
@@ -3391,11 +3362,11 @@ var init_allow_method_middleware = __esm({
|
|
|
3391
3362
|
});
|
|
3392
3363
|
|
|
3393
3364
|
// src/presentation/middlewares/allow-origin.middleware.ts
|
|
3394
|
-
var
|
|
3365
|
+
var import_shared57, AllowOriginMiddleware;
|
|
3395
3366
|
var init_allow_origin_middleware = __esm({
|
|
3396
3367
|
"src/presentation/middlewares/allow-origin.middleware.ts"() {
|
|
3397
3368
|
"use strict";
|
|
3398
|
-
|
|
3369
|
+
import_shared57 = require("@xeno-js/shared");
|
|
3399
3370
|
AllowOriginMiddleware = class {
|
|
3400
3371
|
constructor(_allowOrigin, _requestContext, _logger) {
|
|
3401
3372
|
this._allowOrigin = _allowOrigin;
|
|
@@ -3410,21 +3381,21 @@ var init_allow_origin_middleware = __esm({
|
|
|
3410
3381
|
const origin = network?.origin;
|
|
3411
3382
|
if (!this._allowOrigin.isAllowed(origin)) {
|
|
3412
3383
|
this._logger.warn(`Access denied by AllowOrigin policy for origin: ${origin ?? "unknown"}`);
|
|
3413
|
-
return
|
|
3384
|
+
return import_shared57.HttpHelper.error(
|
|
3414
3385
|
{
|
|
3415
3386
|
success: false,
|
|
3416
3387
|
error: {
|
|
3417
|
-
code:
|
|
3418
|
-
message:
|
|
3388
|
+
code: import_shared57.ERROR_CODES.FORBIDDEN,
|
|
3389
|
+
message: import_shared57.ERROR_CODE_MESSAGES[import_shared57.ERROR_CODES.FORBIDDEN],
|
|
3419
3390
|
details: `The origin '${origin ?? "unknown"}' is not allowed to access this resource.`,
|
|
3420
3391
|
path: req.path
|
|
3421
3392
|
},
|
|
3422
|
-
correlationId: tracing?.correlationId ??
|
|
3423
|
-
requestId: network?.requestId ??
|
|
3424
|
-
spanId: tracing?.spanId ??
|
|
3393
|
+
correlationId: tracing?.correlationId ?? import_shared57.GuidHelper.generate(),
|
|
3394
|
+
requestId: network?.requestId ?? import_shared57.GuidHelper.generate(),
|
|
3395
|
+
spanId: tracing?.spanId ?? import_shared57.GuidHelper.generate(),
|
|
3425
3396
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3426
3397
|
},
|
|
3427
|
-
|
|
3398
|
+
import_shared57.STATUS_CODES.FORBIDDEN
|
|
3428
3399
|
);
|
|
3429
3400
|
}
|
|
3430
3401
|
return next();
|
|
@@ -3434,11 +3405,11 @@ var init_allow_origin_middleware = __esm({
|
|
|
3434
3405
|
});
|
|
3435
3406
|
|
|
3436
3407
|
// src/presentation/middlewares/auth.middleware.ts
|
|
3437
|
-
var
|
|
3408
|
+
var import_shared58, AuthenticationMiddleware;
|
|
3438
3409
|
var init_auth_middleware = __esm({
|
|
3439
3410
|
"src/presentation/middlewares/auth.middleware.ts"() {
|
|
3440
3411
|
"use strict";
|
|
3441
|
-
|
|
3412
|
+
import_shared58 = require("@xeno-js/shared");
|
|
3442
3413
|
AuthenticationMiddleware = class {
|
|
3443
3414
|
constructor(_requestContext, _tokenExtractor, _gateKeeper, _logger) {
|
|
3444
3415
|
this._requestContext = _requestContext;
|
|
@@ -3459,7 +3430,7 @@ var init_auth_middleware = __esm({
|
|
|
3459
3430
|
`Authentication failed for request on path: ${req.path}. Code: ${error.code}. Error: ${error}`
|
|
3460
3431
|
);
|
|
3461
3432
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3462
|
-
return
|
|
3433
|
+
return import_shared58.HttpHelper.error(
|
|
3463
3434
|
{
|
|
3464
3435
|
success: false,
|
|
3465
3436
|
error: {
|
|
@@ -3468,12 +3439,12 @@ var init_auth_middleware = __esm({
|
|
|
3468
3439
|
details: `[Authentication Error] Failed to authenticate request on path: ${req.path}`,
|
|
3469
3440
|
path: req.path
|
|
3470
3441
|
},
|
|
3471
|
-
correlationId: tracing?.correlationId ??
|
|
3472
|
-
requestId: network?.requestId ??
|
|
3473
|
-
spanId: tracing?.spanId ??
|
|
3442
|
+
correlationId: tracing?.correlationId ?? import_shared58.GuidHelper.generate(),
|
|
3443
|
+
requestId: network?.requestId ?? import_shared58.GuidHelper.generate(),
|
|
3444
|
+
spanId: tracing?.spanId ?? import_shared58.GuidHelper.generate(),
|
|
3474
3445
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3475
3446
|
},
|
|
3476
|
-
error.status ??
|
|
3447
|
+
error.status ?? import_shared58.STATUS_CODES.UNAUTHORIZED,
|
|
3477
3448
|
{ "Content-Type": [network?.formatIndicator ?? "application/json"] }
|
|
3478
3449
|
);
|
|
3479
3450
|
}
|
|
@@ -3508,11 +3479,11 @@ var init_composite_middleware = __esm({
|
|
|
3508
3479
|
});
|
|
3509
3480
|
|
|
3510
3481
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3511
|
-
var
|
|
3482
|
+
var import_shared59, CORSMiddleware;
|
|
3512
3483
|
var init_cors_middleware = __esm({
|
|
3513
3484
|
"src/presentation/middlewares/cors.middleware.ts"() {
|
|
3514
3485
|
"use strict";
|
|
3515
|
-
|
|
3486
|
+
import_shared59 = require("@xeno-js/shared");
|
|
3516
3487
|
CORSMiddleware = class {
|
|
3517
3488
|
constructor(_requestContext, _withCredentials = "false") {
|
|
3518
3489
|
this._requestContext = _requestContext;
|
|
@@ -3524,7 +3495,7 @@ var init_cors_middleware = __esm({
|
|
|
3524
3495
|
const { network } = this._requestContext.getContext() ?? {};
|
|
3525
3496
|
const origin = network?.origin;
|
|
3526
3497
|
const response = await next();
|
|
3527
|
-
if (
|
|
3498
|
+
if (import_shared59.Guards.isDefined(origin))
|
|
3528
3499
|
response.headers = {
|
|
3529
3500
|
...response.headers ?? {},
|
|
3530
3501
|
"Access-Control-Allow-Origin": origin,
|
|
@@ -3538,11 +3509,11 @@ var init_cors_middleware = __esm({
|
|
|
3538
3509
|
});
|
|
3539
3510
|
|
|
3540
3511
|
// src/presentation/middlewares/csrf.middleware.ts
|
|
3541
|
-
var
|
|
3512
|
+
var import_shared60, CsrfMiddleware;
|
|
3542
3513
|
var init_csrf_middleware = __esm({
|
|
3543
3514
|
"src/presentation/middlewares/csrf.middleware.ts"() {
|
|
3544
3515
|
"use strict";
|
|
3545
|
-
|
|
3516
|
+
import_shared60 = require("@xeno-js/shared");
|
|
3546
3517
|
CsrfMiddleware = class {
|
|
3547
3518
|
constructor(_requestContext, _csrfTokenService) {
|
|
3548
3519
|
this._requestContext = _requestContext;
|
|
@@ -3557,64 +3528,64 @@ var init_csrf_middleware = __esm({
|
|
|
3557
3528
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3558
3529
|
const headerToken = network?.csrf;
|
|
3559
3530
|
const cookieToken = network?.csrfCookie;
|
|
3560
|
-
if (!
|
|
3561
|
-
return
|
|
3531
|
+
if (!import_shared60.Guards.isDefined(headerToken) || !import_shared60.Guards.isDefined(cookieToken)) {
|
|
3532
|
+
return import_shared60.HttpHelper.error(
|
|
3562
3533
|
{
|
|
3563
3534
|
success: false,
|
|
3564
3535
|
error: {
|
|
3565
|
-
code:
|
|
3566
|
-
message:
|
|
3536
|
+
code: import_shared60.ERROR_CODES.FORBIDDEN,
|
|
3537
|
+
message: import_shared60.ERROR_CODE_MESSAGES[import_shared60.ERROR_CODES.FORBIDDEN],
|
|
3567
3538
|
details: "CSRF token missing",
|
|
3568
3539
|
path: req.path
|
|
3569
3540
|
},
|
|
3570
|
-
correlationId: tracing?.correlationId ??
|
|
3571
|
-
requestId: network?.requestId ??
|
|
3572
|
-
spanId: tracing?.spanId ??
|
|
3541
|
+
correlationId: tracing?.correlationId ?? import_shared60.GuidHelper.generate(),
|
|
3542
|
+
requestId: network?.requestId ?? import_shared60.GuidHelper.generate(),
|
|
3543
|
+
spanId: tracing?.spanId ?? import_shared60.GuidHelper.generate(),
|
|
3573
3544
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3574
3545
|
},
|
|
3575
|
-
|
|
3546
|
+
import_shared60.STATUS_CODES.FORBIDDEN,
|
|
3576
3547
|
{
|
|
3577
3548
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3578
3549
|
}
|
|
3579
3550
|
);
|
|
3580
3551
|
}
|
|
3581
3552
|
if (headerToken !== cookieToken) {
|
|
3582
|
-
return
|
|
3553
|
+
return import_shared60.HttpHelper.error(
|
|
3583
3554
|
{
|
|
3584
3555
|
success: false,
|
|
3585
3556
|
error: {
|
|
3586
|
-
code:
|
|
3587
|
-
message:
|
|
3557
|
+
code: import_shared60.ERROR_CODES.FORBIDDEN,
|
|
3558
|
+
message: import_shared60.ERROR_CODE_MESSAGES[import_shared60.ERROR_CODES.FORBIDDEN],
|
|
3588
3559
|
details: "CSRF token mismatch",
|
|
3589
3560
|
path: req.path
|
|
3590
3561
|
},
|
|
3591
|
-
correlationId: tracing?.correlationId ??
|
|
3592
|
-
requestId: network?.requestId ??
|
|
3593
|
-
spanId: tracing?.spanId ??
|
|
3562
|
+
correlationId: tracing?.correlationId ?? import_shared60.GuidHelper.generate(),
|
|
3563
|
+
requestId: network?.requestId ?? import_shared60.GuidHelper.generate(),
|
|
3564
|
+
spanId: tracing?.spanId ?? import_shared60.GuidHelper.generate(),
|
|
3594
3565
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3595
3566
|
},
|
|
3596
|
-
|
|
3567
|
+
import_shared60.STATUS_CODES.FORBIDDEN,
|
|
3597
3568
|
{
|
|
3598
3569
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3599
3570
|
}
|
|
3600
3571
|
);
|
|
3601
3572
|
}
|
|
3602
|
-
if (!
|
|
3603
|
-
return
|
|
3573
|
+
if (!import_shared60.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3574
|
+
return import_shared60.HttpHelper.error(
|
|
3604
3575
|
{
|
|
3605
3576
|
success: false,
|
|
3606
3577
|
error: {
|
|
3607
|
-
code:
|
|
3608
|
-
message:
|
|
3578
|
+
code: import_shared60.ERROR_CODES.FORBIDDEN,
|
|
3579
|
+
message: import_shared60.ERROR_CODE_MESSAGES[import_shared60.ERROR_CODES.FORBIDDEN],
|
|
3609
3580
|
details: "CSRF token invalid",
|
|
3610
3581
|
path: req.path
|
|
3611
3582
|
},
|
|
3612
|
-
correlationId: tracing?.correlationId ??
|
|
3613
|
-
requestId: network?.requestId ??
|
|
3614
|
-
spanId: tracing?.spanId ??
|
|
3583
|
+
correlationId: tracing?.correlationId ?? import_shared60.GuidHelper.generate(),
|
|
3584
|
+
requestId: network?.requestId ?? import_shared60.GuidHelper.generate(),
|
|
3585
|
+
spanId: tracing?.spanId ?? import_shared60.GuidHelper.generate(),
|
|
3615
3586
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3616
3587
|
},
|
|
3617
|
-
|
|
3588
|
+
import_shared60.STATUS_CODES.FORBIDDEN,
|
|
3618
3589
|
{
|
|
3619
3590
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3620
3591
|
}
|
|
@@ -3628,11 +3599,11 @@ var init_csrf_middleware = __esm({
|
|
|
3628
3599
|
});
|
|
3629
3600
|
|
|
3630
3601
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3631
|
-
var
|
|
3602
|
+
var import_shared61, CsrfCookieMiddleware;
|
|
3632
3603
|
var init_csrf_cookie_middleware = __esm({
|
|
3633
3604
|
"src/presentation/middlewares/csrf-cookie.middleware.ts"() {
|
|
3634
3605
|
"use strict";
|
|
3635
|
-
|
|
3606
|
+
import_shared61 = require("@xeno-js/shared");
|
|
3636
3607
|
CsrfCookieMiddleware = class {
|
|
3637
3608
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3638
3609
|
this._requestContext = _requestContext;
|
|
@@ -3647,8 +3618,8 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3647
3618
|
const context = this._requestContext.getContext();
|
|
3648
3619
|
const identity = context?.identity;
|
|
3649
3620
|
const network = context?.network;
|
|
3650
|
-
if (!
|
|
3651
|
-
if (
|
|
3621
|
+
if (!import_shared61.Guards.isDefined(identity?.userId)) return response;
|
|
3622
|
+
if (import_shared61.Guards.isDefined(network?.csrfCookie)) return response;
|
|
3652
3623
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3653
3624
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3654
3625
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3666,11 +3637,11 @@ var init_csrf_cookie_middleware = __esm({
|
|
|
3666
3637
|
});
|
|
3667
3638
|
|
|
3668
3639
|
// src/presentation/middlewares/options.middleware.ts
|
|
3669
|
-
var
|
|
3640
|
+
var import_shared62, OptionsMiddleware;
|
|
3670
3641
|
var init_options_middleware = __esm({
|
|
3671
3642
|
"src/presentation/middlewares/options.middleware.ts"() {
|
|
3672
3643
|
"use strict";
|
|
3673
|
-
|
|
3644
|
+
import_shared62 = require("@xeno-js/shared");
|
|
3674
3645
|
OptionsMiddleware = class {
|
|
3675
3646
|
constructor(_requestContext, _alloewMethod, _allowHeaders = [], _withCredentials = "false") {
|
|
3676
3647
|
this._requestContext = _requestContext;
|
|
@@ -3687,14 +3658,14 @@ var init_options_middleware = __esm({
|
|
|
3687
3658
|
const network = this._requestContext.getNetworkContext();
|
|
3688
3659
|
const origin = network?.origin;
|
|
3689
3660
|
const headers = {};
|
|
3690
|
-
if (
|
|
3661
|
+
if (import_shared62.Guards.isDefined(origin)) {
|
|
3691
3662
|
headers["Access-Control-Allow-Origin"] = origin;
|
|
3692
3663
|
headers["Access-Control-Allow-Credentials"] = this._withCredentials;
|
|
3693
3664
|
headers["Vary"] = "Origin";
|
|
3694
3665
|
}
|
|
3695
3666
|
headers["Access-Control-Allow-Methods"] = this._alloewMethod.getMethods(req.path);
|
|
3696
3667
|
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3697
|
-
return
|
|
3668
|
+
return import_shared62.HttpHelper.success(null, import_shared62.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3698
3669
|
}
|
|
3699
3670
|
return await next();
|
|
3700
3671
|
}
|
|
@@ -3703,11 +3674,11 @@ var init_options_middleware = __esm({
|
|
|
3703
3674
|
});
|
|
3704
3675
|
|
|
3705
3676
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
3706
|
-
var
|
|
3677
|
+
var import_shared63, RateLimitMiddleware;
|
|
3707
3678
|
var init_rate_limiter_middleware = __esm({
|
|
3708
3679
|
"src/presentation/middlewares/rate-limiter.middleware.ts"() {
|
|
3709
3680
|
"use strict";
|
|
3710
|
-
|
|
3681
|
+
import_shared63 = require("@xeno-js/shared");
|
|
3711
3682
|
RateLimitMiddleware = class {
|
|
3712
3683
|
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3713
3684
|
this._ctxAccessor = _ctxAccessor;
|
|
@@ -3724,22 +3695,22 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3724
3695
|
async execute(req, _res, next) {
|
|
3725
3696
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3726
3697
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3727
|
-
if (!
|
|
3728
|
-
return
|
|
3698
|
+
if (!import_shared63.Guards.isDefined(cacheKey))
|
|
3699
|
+
return import_shared63.HttpHelper.error(
|
|
3729
3700
|
{
|
|
3730
3701
|
success: false,
|
|
3731
3702
|
error: {
|
|
3732
|
-
code:
|
|
3733
|
-
message:
|
|
3703
|
+
code: import_shared63.ERROR_CODES.SYSTEM_ERROR,
|
|
3704
|
+
message: import_shared63.ERROR_CODE_MESSAGES[import_shared63.ERROR_CODES.SYSTEM_ERROR],
|
|
3734
3705
|
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3735
3706
|
path: req.path
|
|
3736
3707
|
},
|
|
3737
|
-
correlationId: tracing?.correlationId ??
|
|
3738
|
-
requestId: network?.requestId ??
|
|
3739
|
-
spanId: tracing?.spanId ??
|
|
3708
|
+
correlationId: tracing?.correlationId ?? import_shared63.GuidHelper.generate(),
|
|
3709
|
+
requestId: network?.requestId ?? import_shared63.GuidHelper.generate(),
|
|
3710
|
+
spanId: tracing?.spanId ?? import_shared63.GuidHelper.generate(),
|
|
3740
3711
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3741
3712
|
},
|
|
3742
|
-
|
|
3713
|
+
import_shared63.STATUS_CODES.SERVICE_UNAVAILABLE,
|
|
3743
3714
|
{
|
|
3744
3715
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3745
3716
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3748,21 +3719,21 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3748
3719
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3749
3720
|
if (currentHits > this._opts.maxRequests) {
|
|
3750
3721
|
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
3751
|
-
return
|
|
3722
|
+
return import_shared63.HttpHelper.error(
|
|
3752
3723
|
{
|
|
3753
3724
|
success: false,
|
|
3754
3725
|
error: {
|
|
3755
|
-
code:
|
|
3756
|
-
message:
|
|
3726
|
+
code: import_shared63.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
3727
|
+
message: import_shared63.ERROR_CODE_MESSAGES[import_shared63.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
3757
3728
|
details: `Rate limit exceeded.`,
|
|
3758
3729
|
path: req.path
|
|
3759
3730
|
},
|
|
3760
|
-
correlationId: tracing?.correlationId ??
|
|
3761
|
-
requestId: network?.requestId ??
|
|
3762
|
-
spanId: tracing?.spanId ??
|
|
3731
|
+
correlationId: tracing?.correlationId ?? import_shared63.GuidHelper.generate(),
|
|
3732
|
+
requestId: network?.requestId ?? import_shared63.GuidHelper.generate(),
|
|
3733
|
+
spanId: tracing?.spanId ?? import_shared63.GuidHelper.generate(),
|
|
3763
3734
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3764
3735
|
},
|
|
3765
|
-
|
|
3736
|
+
import_shared63.STATUS_CODES.TOO_MANY_REQUESTS,
|
|
3766
3737
|
{
|
|
3767
3738
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3768
3739
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3777,8 +3748,8 @@ var init_rate_limiter_middleware = __esm({
|
|
|
3777
3748
|
|
|
3778
3749
|
// src/presentation/mappers/context.mapper.ts
|
|
3779
3750
|
function _buildMessagingContext(meta) {
|
|
3780
|
-
const hasSequenceData =
|
|
3781
|
-
const hasMessagingData = hasSequenceData ||
|
|
3751
|
+
const hasSequenceData = import_shared64.Guards.isDefined(meta.sequence?.sequenceId) || import_shared64.Guards.isDefined(meta.sequence?.position) || import_shared64.Guards.isDefined(meta.sequence?.size);
|
|
3752
|
+
const hasMessagingData = hasSequenceData || import_shared64.Guards.isDefined(meta.expiration) || import_shared64.Guards.isDefined(meta.returnAddress);
|
|
3782
3753
|
const messaging = hasMessagingData ? {
|
|
3783
3754
|
returnAddress: meta.returnAddress,
|
|
3784
3755
|
expiration: meta.expiration,
|
|
@@ -3786,11 +3757,11 @@ function _buildMessagingContext(meta) {
|
|
|
3786
3757
|
} : void 0;
|
|
3787
3758
|
return messaging;
|
|
3788
3759
|
}
|
|
3789
|
-
var
|
|
3760
|
+
var import_shared64, ContextMapper;
|
|
3790
3761
|
var init_context_mapper = __esm({
|
|
3791
3762
|
"src/presentation/mappers/context.mapper.ts"() {
|
|
3792
3763
|
"use strict";
|
|
3793
|
-
|
|
3764
|
+
import_shared64 = require("@xeno-js/shared");
|
|
3794
3765
|
ContextMapper = Object.freeze({
|
|
3795
3766
|
/**
|
|
3796
3767
|
* @description Maps to RequestContext. It extracts relevant information from the object, such as correlation ID, request ID, authentication token, client IP, user agent, format indicator, and messaging context (if available). The method constructs a RequestContext object that encapsulates all this information, providing a structured representation of the request context for further processing in the application.
|
|
@@ -3834,11 +3805,11 @@ var init_context_mapper = __esm({
|
|
|
3834
3805
|
});
|
|
3835
3806
|
|
|
3836
3807
|
// src/presentation/middlewares/request.middleware.ts
|
|
3837
|
-
var
|
|
3808
|
+
var import_shared65, RequestContextMiddleware;
|
|
3838
3809
|
var init_request_middleware = __esm({
|
|
3839
3810
|
"src/presentation/middlewares/request.middleware.ts"() {
|
|
3840
3811
|
"use strict";
|
|
3841
|
-
|
|
3812
|
+
import_shared65 = require("@xeno-js/shared");
|
|
3842
3813
|
init_context_mapper();
|
|
3843
3814
|
RequestContextMiddleware = class {
|
|
3844
3815
|
/**
|
|
@@ -3863,8 +3834,8 @@ var init_request_middleware = __esm({
|
|
|
3863
3834
|
_resolver;
|
|
3864
3835
|
_logger;
|
|
3865
3836
|
async execute(req, res, next) {
|
|
3866
|
-
const correlationId =
|
|
3867
|
-
const requestId =
|
|
3837
|
+
const correlationId = import_shared65.GuidHelper.generate();
|
|
3838
|
+
const requestId = import_shared65.GuidHelper.generate();
|
|
3868
3839
|
const spanId = correlationId;
|
|
3869
3840
|
const formatIndicator = "application/json";
|
|
3870
3841
|
try {
|
|
@@ -3880,7 +3851,7 @@ var init_request_middleware = __esm({
|
|
|
3880
3851
|
};
|
|
3881
3852
|
const tmpContext = ContextMapper.map({
|
|
3882
3853
|
metadata,
|
|
3883
|
-
identity:
|
|
3854
|
+
identity: import_shared65.GUEST,
|
|
3884
3855
|
path: req.path,
|
|
3885
3856
|
transport: { req, res }
|
|
3886
3857
|
});
|
|
@@ -3892,12 +3863,12 @@ var init_request_middleware = __esm({
|
|
|
3892
3863
|
return result;
|
|
3893
3864
|
} catch (error) {
|
|
3894
3865
|
this._logger.error("RequestContextMiddleware encountered an error", error);
|
|
3895
|
-
return
|
|
3866
|
+
return import_shared65.HttpHelper.error(
|
|
3896
3867
|
{
|
|
3897
3868
|
success: false,
|
|
3898
3869
|
error: {
|
|
3899
|
-
code:
|
|
3900
|
-
message:
|
|
3870
|
+
code: import_shared65.ERROR_CODES.SYSTEM_ERROR,
|
|
3871
|
+
message: import_shared65.ERROR_CODE_MESSAGES[import_shared65.ERROR_CODES.SYSTEM_ERROR],
|
|
3901
3872
|
details: `[Fatal System Error] Exception caught during request handling on path: ${req.path}`,
|
|
3902
3873
|
path: req.path
|
|
3903
3874
|
},
|
|
@@ -3906,7 +3877,7 @@ var init_request_middleware = __esm({
|
|
|
3906
3877
|
spanId,
|
|
3907
3878
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3908
3879
|
},
|
|
3909
|
-
|
|
3880
|
+
import_shared65.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
3910
3881
|
{ "Content-Type": [formatIndicator] }
|
|
3911
3882
|
);
|
|
3912
3883
|
}
|
|
@@ -3960,16 +3931,16 @@ var inmemory_cache_exports = {};
|
|
|
3960
3931
|
__export(inmemory_cache_exports, {
|
|
3961
3932
|
InMemoryCacheExtended: () => InMemoryCacheExtended
|
|
3962
3933
|
});
|
|
3963
|
-
var
|
|
3934
|
+
var import_shared66, InMemoryCacheExtended;
|
|
3964
3935
|
var init_inmemory_cache = __esm({
|
|
3965
3936
|
"src/infrastructure/cache/inmemory.cache.ts"() {
|
|
3966
3937
|
"use strict";
|
|
3967
|
-
|
|
3968
|
-
InMemoryCacheExtended = class extends
|
|
3938
|
+
import_shared66 = require("@xeno-js/shared");
|
|
3939
|
+
InMemoryCacheExtended = class extends import_shared66.InMemoryCache {
|
|
3969
3940
|
async increment(key, ttlSeconds) {
|
|
3970
3941
|
const current = await this.get(key) ?? 0;
|
|
3971
3942
|
const next = Number(current) + 1;
|
|
3972
|
-
const ttl =
|
|
3943
|
+
const ttl = import_shared66.Guards.isDefined(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
3973
3944
|
await this.set(key, next, ttl);
|
|
3974
3945
|
return next;
|
|
3975
3946
|
}
|
|
@@ -3978,11 +3949,11 @@ var init_inmemory_cache = __esm({
|
|
|
3978
3949
|
});
|
|
3979
3950
|
|
|
3980
3951
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
3981
|
-
var
|
|
3952
|
+
var import_shared67, RateLimitKeyBuilder;
|
|
3982
3953
|
var init_rate_limit_key_builder_cache = __esm({
|
|
3983
3954
|
"src/infrastructure/cache/rate-limit-key-builder.cache.ts"() {
|
|
3984
3955
|
"use strict";
|
|
3985
|
-
|
|
3956
|
+
import_shared67 = require("@xeno-js/shared");
|
|
3986
3957
|
RateLimitKeyBuilder = class {
|
|
3987
3958
|
constructor(_contextAccessor) {
|
|
3988
3959
|
this._contextAccessor = _contextAccessor;
|
|
@@ -3993,12 +3964,12 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
3993
3964
|
const tenantId = ctx?.identity?.tenantId;
|
|
3994
3965
|
const userId = ctx?.identity?.userId;
|
|
3995
3966
|
const clientIp = ctx?.network?.clientIp;
|
|
3996
|
-
if (!
|
|
3967
|
+
if (!import_shared67.Guards.isNullOrEmpty(tenantId) && !import_shared67.Guards.isNullOrEmpty(userId))
|
|
3997
3968
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
3998
|
-
if (!
|
|
3969
|
+
if (!import_shared67.Guards.isNullOrEmpty(tenantId) && !import_shared67.Guards.isNullOrEmpty(clientIp))
|
|
3999
3970
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
4000
|
-
if (!
|
|
4001
|
-
if (!
|
|
3971
|
+
if (!import_shared67.Guards.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
3972
|
+
if (!import_shared67.Guards.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
4002
3973
|
return void 0;
|
|
4003
3974
|
}
|
|
4004
3975
|
};
|
|
@@ -4006,11 +3977,11 @@ var init_rate_limit_key_builder_cache = __esm({
|
|
|
4006
3977
|
});
|
|
4007
3978
|
|
|
4008
3979
|
// src/infrastructure/cache/redis.cache.ts
|
|
4009
|
-
var
|
|
3980
|
+
var import_shared68, RedisCache;
|
|
4010
3981
|
var init_redis_cache = __esm({
|
|
4011
3982
|
"src/infrastructure/cache/redis.cache.ts"() {
|
|
4012
3983
|
"use strict";
|
|
4013
|
-
|
|
3984
|
+
import_shared68 = require("@xeno-js/shared");
|
|
4014
3985
|
RedisCache = class {
|
|
4015
3986
|
/**
|
|
4016
3987
|
* @description Constructs a new instance of the RedisCache class, which takes an instance of the Redis client as a parameter. This client is used to perform caching operations such as setting, getting, and removing values from the Redis database. The constructor initializes the RedisCache with the provided Redis client, allowing it to interact with the Redis server for all caching operations defined in the ICache interface.
|
|
@@ -4035,19 +4006,19 @@ var init_redis_cache = __esm({
|
|
|
4035
4006
|
}
|
|
4036
4007
|
async get(key) {
|
|
4037
4008
|
const value = await this._redisClient.get(key);
|
|
4038
|
-
if (!
|
|
4009
|
+
if (!import_shared68.Guards.isDefined(value)) {
|
|
4039
4010
|
return void 0;
|
|
4040
4011
|
}
|
|
4041
4012
|
return JSON.parse(value);
|
|
4042
4013
|
}
|
|
4043
4014
|
async set(key, value, ttl) {
|
|
4044
|
-
const stringValue =
|
|
4045
|
-
const ttlOption =
|
|
4015
|
+
const stringValue = import_shared68.StringHelper.safeStringify(value);
|
|
4016
|
+
const ttlOption = import_shared68.Guards.isDefined(ttl) ? ttl : 86400;
|
|
4046
4017
|
await this._redisClient.set(key, stringValue, "EX", ttlOption);
|
|
4047
4018
|
}
|
|
4048
4019
|
async setIfAbsent(key, value, ttl) {
|
|
4049
|
-
const stringValue =
|
|
4050
|
-
const ttlOption =
|
|
4020
|
+
const stringValue = import_shared68.StringHelper.safeStringify(value);
|
|
4021
|
+
const ttlOption = import_shared68.Guards.isDefined(ttl) ? ttl : 300;
|
|
4051
4022
|
const result = await this._redisClient.set(key, stringValue, "EX", ttlOption, "NX");
|
|
4052
4023
|
return result === "OK";
|
|
4053
4024
|
}
|
|
@@ -4265,11 +4236,11 @@ var redis_cache_factory_exports = {};
|
|
|
4265
4236
|
__export(redis_cache_factory_exports, {
|
|
4266
4237
|
RedisCacheFactory: () => RedisCacheFactory
|
|
4267
4238
|
});
|
|
4268
|
-
var
|
|
4239
|
+
var import_shared69, import_ioredis, RedisCacheFactory;
|
|
4269
4240
|
var init_redis_cache_factory = __esm({
|
|
4270
4241
|
"src/infrastructure/factories/redis-cache.factory.ts"() {
|
|
4271
4242
|
"use strict";
|
|
4272
|
-
|
|
4243
|
+
import_shared69 = require("@xeno-js/shared");
|
|
4273
4244
|
import_ioredis = require("ioredis");
|
|
4274
4245
|
init_redis_cache();
|
|
4275
4246
|
RedisCacheFactory = class {
|
|
@@ -4290,10 +4261,10 @@ var init_redis_cache_factory = __esm({
|
|
|
4290
4261
|
return delay;
|
|
4291
4262
|
}
|
|
4292
4263
|
};
|
|
4293
|
-
if (
|
|
4264
|
+
if (import_shared69.Guards.isDefined(password)) {
|
|
4294
4265
|
redisOptions.password = password;
|
|
4295
4266
|
}
|
|
4296
|
-
if (
|
|
4267
|
+
if (import_shared69.Guards.isDefined(username)) {
|
|
4297
4268
|
redisOptions.username = username;
|
|
4298
4269
|
}
|
|
4299
4270
|
if (useTls) {
|
|
@@ -4364,11 +4335,11 @@ var console_logger_exports = {};
|
|
|
4364
4335
|
__export(console_logger_exports, {
|
|
4365
4336
|
ConsoleLogger: () => ConsoleLogger
|
|
4366
4337
|
});
|
|
4367
|
-
var
|
|
4338
|
+
var import_shared70, ConsoleLogger;
|
|
4368
4339
|
var init_console_logger = __esm({
|
|
4369
4340
|
"src/infrastructure/loggers/console.logger.ts"() {
|
|
4370
4341
|
"use strict";
|
|
4371
|
-
|
|
4342
|
+
import_shared70 = require("@xeno-js/shared");
|
|
4372
4343
|
ConsoleLogger = class {
|
|
4373
4344
|
/**
|
|
4374
4345
|
* Constructs a new instance of the ConsoleLogger class, which takes an optional minimum log level. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
|
|
@@ -4380,22 +4351,22 @@ var init_console_logger = __esm({
|
|
|
4380
4351
|
* @since 2025-09-30
|
|
4381
4352
|
* @link https://github.com/xeno-js/xeno-js
|
|
4382
4353
|
*/
|
|
4383
|
-
constructor(_minLevel =
|
|
4354
|
+
constructor(_minLevel = import_shared70.LOG_LEVEL.DEBUG) {
|
|
4384
4355
|
this._minLevel = _minLevel;
|
|
4385
4356
|
}
|
|
4386
4357
|
_minLevel;
|
|
4387
4358
|
track(level, message, context, error = void 0) {
|
|
4388
4359
|
if (level < this._minLevel) return;
|
|
4389
4360
|
const logMessage = `[${level}] ${message}`;
|
|
4390
|
-
const payload =
|
|
4361
|
+
const payload = import_shared70.Guards.isDefined(error) ? { ...context, error } : context;
|
|
4391
4362
|
switch (level) {
|
|
4392
|
-
case
|
|
4363
|
+
case import_shared70.LOG_LEVEL.ERROR:
|
|
4393
4364
|
console.error(logMessage, payload ?? {});
|
|
4394
4365
|
break;
|
|
4395
|
-
case
|
|
4366
|
+
case import_shared70.LOG_LEVEL.WARN:
|
|
4396
4367
|
console.warn(logMessage, payload ?? {});
|
|
4397
4368
|
break;
|
|
4398
|
-
case
|
|
4369
|
+
case import_shared70.LOG_LEVEL.DEBUG:
|
|
4399
4370
|
console.debug(logMessage, payload ?? {});
|
|
4400
4371
|
break;
|
|
4401
4372
|
default:
|
|
@@ -4408,11 +4379,11 @@ var init_console_logger = __esm({
|
|
|
4408
4379
|
});
|
|
4409
4380
|
|
|
4410
4381
|
// src/infrastructure/loggers/sentry.logger.ts
|
|
4411
|
-
var
|
|
4382
|
+
var import_shared71, SentryLogger;
|
|
4412
4383
|
var init_sentry_logger = __esm({
|
|
4413
4384
|
"src/infrastructure/loggers/sentry.logger.ts"() {
|
|
4414
4385
|
"use strict";
|
|
4415
|
-
|
|
4386
|
+
import_shared71 = require("@xeno-js/shared");
|
|
4416
4387
|
SentryLogger = class {
|
|
4417
4388
|
constructor(_client, _minLevel) {
|
|
4418
4389
|
this._client = _client;
|
|
@@ -4422,10 +4393,10 @@ var init_sentry_logger = __esm({
|
|
|
4422
4393
|
_minLevel;
|
|
4423
4394
|
track(level, message, context = void 0, error = void 0) {
|
|
4424
4395
|
if (level < this._minLevel) return;
|
|
4425
|
-
if (level ===
|
|
4396
|
+
if (level === import_shared71.LOG_LEVEL.ERROR || level === import_shared71.LOG_LEVEL.WARN) {
|
|
4426
4397
|
this._client.withScope((scope) => {
|
|
4427
|
-
if (
|
|
4428
|
-
if (
|
|
4398
|
+
if (import_shared71.Guards.isDefined(context)) scope.setExtras(context);
|
|
4399
|
+
if (import_shared71.Guards.isDefined(error)) {
|
|
4429
4400
|
this._client.captureException(error);
|
|
4430
4401
|
} else {
|
|
4431
4402
|
this._client.captureMessage(message, "warning");
|
|
@@ -4442,21 +4413,21 @@ var sentry_logger_factory_exports = {};
|
|
|
4442
4413
|
__export(sentry_logger_factory_exports, {
|
|
4443
4414
|
SentryLoggerFactory: () => SentryLoggerFactory
|
|
4444
4415
|
});
|
|
4445
|
-
var Sentry,
|
|
4416
|
+
var Sentry, import_shared72, SentryLoggerFactory;
|
|
4446
4417
|
var init_sentry_logger_factory = __esm({
|
|
4447
4418
|
"src/infrastructure/factories/sentry-logger.factory.ts"() {
|
|
4448
4419
|
"use strict";
|
|
4449
4420
|
Sentry = __toESM(require("@sentry/node"), 1);
|
|
4450
|
-
|
|
4421
|
+
import_shared72 = require("@xeno-js/shared");
|
|
4451
4422
|
init_sentry_logger();
|
|
4452
4423
|
SentryLoggerFactory = class {
|
|
4453
4424
|
create(config) {
|
|
4454
|
-
const level = config.level ??
|
|
4425
|
+
const level = config.level ?? import_shared72.LOG_LEVEL.WARN;
|
|
4455
4426
|
const sentryConfig = config.sentry?.config;
|
|
4456
4427
|
const env = sentryConfig?.environment ?? process.env.NODE_ENV ?? "development";
|
|
4457
|
-
if (!
|
|
4428
|
+
if (!import_shared72.Guards.isDefined(sentryConfig))
|
|
4458
4429
|
throw new Error("Sentry configuration is required when Sentry logging is enabled.");
|
|
4459
|
-
if (!
|
|
4430
|
+
if (!import_shared72.Guards.isDefined(sentryConfig.dsn))
|
|
4460
4431
|
throw new Error("Sentry DSN is required when Sentry logging is enabled.");
|
|
4461
4432
|
Sentry.init({
|
|
4462
4433
|
dsn: sentryConfig.dsn,
|
|
@@ -4478,11 +4449,11 @@ var init_sentry_logger_factory = __esm({
|
|
|
4478
4449
|
});
|
|
4479
4450
|
|
|
4480
4451
|
// src/infrastructure/loggers/pino.logger.ts
|
|
4481
|
-
var
|
|
4452
|
+
var import_shared73, PinoLogger;
|
|
4482
4453
|
var init_pino_logger = __esm({
|
|
4483
4454
|
"src/infrastructure/loggers/pino.logger.ts"() {
|
|
4484
4455
|
"use strict";
|
|
4485
|
-
|
|
4456
|
+
import_shared73 = require("@xeno-js/shared");
|
|
4486
4457
|
PinoLogger = class {
|
|
4487
4458
|
/**
|
|
4488
4459
|
* Constructs a new instance of the PinoTransport class, which takes an optional minimum log level and an optional instance of the Pino logger. If no logger instance is provided, it initializes a new Pino logger with default settings. The minimum log level determines the threshold for logging messages, where messages with a log level below the specified minimum will be ignored.
|
|
@@ -4495,7 +4466,7 @@ var init_pino_logger = __esm({
|
|
|
4495
4466
|
* @since 2025-09-30
|
|
4496
4467
|
* @link https://github.com/xeno-js/xeno-js
|
|
4497
4468
|
*/
|
|
4498
|
-
constructor(_logger, _minLevel =
|
|
4469
|
+
constructor(_logger, _minLevel = import_shared73.LOG_LEVEL.DEBUG) {
|
|
4499
4470
|
this._logger = _logger;
|
|
4500
4471
|
this._minLevel = _minLevel;
|
|
4501
4472
|
}
|
|
@@ -4503,15 +4474,15 @@ var init_pino_logger = __esm({
|
|
|
4503
4474
|
_minLevel;
|
|
4504
4475
|
track(level, message, context, error = void 0) {
|
|
4505
4476
|
if (level < this._minLevel) return;
|
|
4506
|
-
const payload =
|
|
4477
|
+
const payload = import_shared73.Guards.isDefined(error) ? { ...context, error } : context;
|
|
4507
4478
|
switch (level) {
|
|
4508
|
-
case
|
|
4479
|
+
case import_shared73.LOG_LEVEL.ERROR:
|
|
4509
4480
|
this._logger.error(payload ?? {}, message);
|
|
4510
4481
|
break;
|
|
4511
|
-
case
|
|
4482
|
+
case import_shared73.LOG_LEVEL.WARN:
|
|
4512
4483
|
this._logger.warn(payload ?? {}, message);
|
|
4513
4484
|
break;
|
|
4514
|
-
case
|
|
4485
|
+
case import_shared73.LOG_LEVEL.DEBUG:
|
|
4515
4486
|
this._logger.debug(payload ?? {}, message);
|
|
4516
4487
|
break;
|
|
4517
4488
|
default:
|
|
@@ -4528,16 +4499,16 @@ var pino_logger_factory_exports = {};
|
|
|
4528
4499
|
__export(pino_logger_factory_exports, {
|
|
4529
4500
|
PinoLoggerFactory: () => PinoLoggerFactory
|
|
4530
4501
|
});
|
|
4531
|
-
var
|
|
4502
|
+
var import_shared74, import_pino, PinoLoggerFactory;
|
|
4532
4503
|
var init_pino_logger_factory = __esm({
|
|
4533
4504
|
"src/infrastructure/factories/pino-logger.factory.ts"() {
|
|
4534
4505
|
"use strict";
|
|
4535
|
-
|
|
4506
|
+
import_shared74 = require("@xeno-js/shared");
|
|
4536
4507
|
import_pino = __toESM(require("pino"), 1);
|
|
4537
4508
|
init_pino_logger();
|
|
4538
4509
|
PinoLoggerFactory = class {
|
|
4539
4510
|
create(config) {
|
|
4540
|
-
const level = config.level ??
|
|
4511
|
+
const level = config.level ?? import_shared74.LOG_LEVEL.DEBUG;
|
|
4541
4512
|
const env = config.pino.config?.env ?? process.env.NODE_ENV ?? "development";
|
|
4542
4513
|
const destinationType = config.pino.config?.destination ?? "stdout";
|
|
4543
4514
|
const filePath = config.pino.config?.filePath ?? "logs/app.log";
|
|
@@ -4686,10 +4657,9 @@ __export(index_exports, {
|
|
|
4686
4657
|
AppBuilder: () => AppBuilder,
|
|
4687
4658
|
BaseAuthorizationStrategy: () => BaseAuthorizationStrategy,
|
|
4688
4659
|
BaseController: () => BaseController,
|
|
4689
|
-
BaseHandler: () => BaseHandler,
|
|
4690
4660
|
BaseHttpAdapter: () => BaseHttpAdapter,
|
|
4691
4661
|
ContainerUtils: () => ContainerUtils,
|
|
4692
|
-
Query: () =>
|
|
4662
|
+
Query: () => import_shared80.Query,
|
|
4693
4663
|
ReadDao: () => ReadDao,
|
|
4694
4664
|
Repository: () => Repository,
|
|
4695
4665
|
Specification: () => Specification
|
|
@@ -4698,10 +4668,10 @@ module.exports = __toCommonJS(index_exports);
|
|
|
4698
4668
|
init_application();
|
|
4699
4669
|
|
|
4700
4670
|
// src/infrastructure/builder/app.builder.ts
|
|
4701
|
-
var
|
|
4671
|
+
var import_shared75 = require("@xeno-js/shared");
|
|
4702
4672
|
|
|
4703
4673
|
// src/infrastructure/configuration/configuration.ts
|
|
4704
|
-
var
|
|
4674
|
+
var import_shared31 = require("@xeno-js/shared");
|
|
4705
4675
|
var EnvironmentConfigurationService = class {
|
|
4706
4676
|
/**
|
|
4707
4677
|
* @description Internal dictionary to hold environment variables.
|
|
@@ -4723,14 +4693,14 @@ var EnvironmentConfigurationService = class {
|
|
|
4723
4693
|
}
|
|
4724
4694
|
get(key, defaultValue) {
|
|
4725
4695
|
const value = this._env[key];
|
|
4726
|
-
if (
|
|
4696
|
+
if (import_shared31.Guards.isNullOrEmpty(value)) {
|
|
4727
4697
|
return defaultValue;
|
|
4728
4698
|
}
|
|
4729
4699
|
return value;
|
|
4730
4700
|
}
|
|
4731
4701
|
getNumber(key, defaultValue) {
|
|
4732
4702
|
const value = this.get(key);
|
|
4733
|
-
if (!
|
|
4703
|
+
if (!import_shared31.Guards.isDefined(value)) {
|
|
4734
4704
|
return defaultValue;
|
|
4735
4705
|
}
|
|
4736
4706
|
const parsed = Number(value);
|
|
@@ -4743,7 +4713,7 @@ var EnvironmentConfigurationService = class {
|
|
|
4743
4713
|
}
|
|
4744
4714
|
getBoolean(key, defaultValue) {
|
|
4745
4715
|
const value = this.get(key);
|
|
4746
|
-
if (!
|
|
4716
|
+
if (!import_shared31.Guards.isDefined(value)) {
|
|
4747
4717
|
return defaultValue;
|
|
4748
4718
|
}
|
|
4749
4719
|
const normalized = value.toLowerCase().trim();
|
|
@@ -4755,7 +4725,7 @@ var EnvironmentConfigurationService = class {
|
|
|
4755
4725
|
}
|
|
4756
4726
|
getOrThrow(key) {
|
|
4757
4727
|
const value = this.get(key);
|
|
4758
|
-
if (!
|
|
4728
|
+
if (!import_shared31.Guards.isDefined(value)) {
|
|
4759
4729
|
throw new Error(
|
|
4760
4730
|
`[Configuration Error]: Required configuration key "${key}" is missing in the environment.`
|
|
4761
4731
|
);
|
|
@@ -4766,7 +4736,7 @@ var EnvironmentConfigurationService = class {
|
|
|
4766
4736
|
|
|
4767
4737
|
// src/infrastructure/container/service-container.ts
|
|
4768
4738
|
var import_node_async_hooks = require("async_hooks");
|
|
4769
|
-
var
|
|
4739
|
+
var import_shared32 = require("@xeno-js/shared");
|
|
4770
4740
|
var ContainerScope = class {
|
|
4771
4741
|
constructor(container, parentScope) {
|
|
4772
4742
|
this.container = container;
|
|
@@ -4870,7 +4840,7 @@ var ServiceContainer = class {
|
|
|
4870
4840
|
*/
|
|
4871
4841
|
internalExecuteInContext(callback) {
|
|
4872
4842
|
const currentStack = this.resolutionStack.getStore();
|
|
4873
|
-
if (!
|
|
4843
|
+
if (!import_shared32.Guards.isDefined(currentStack)) {
|
|
4874
4844
|
const initialContext = {
|
|
4875
4845
|
stack: /* @__PURE__ */ new Set()
|
|
4876
4846
|
};
|
|
@@ -4893,14 +4863,14 @@ var ServiceContainer = class {
|
|
|
4893
4863
|
*/
|
|
4894
4864
|
internalResolveInternal(token, currentScope) {
|
|
4895
4865
|
const registration = this.registrations.get(token);
|
|
4896
|
-
if (!
|
|
4866
|
+
if (!import_shared32.Guards.isDefined(registration)) {
|
|
4897
4867
|
const tokenName = token.toString();
|
|
4898
4868
|
throw new Error(
|
|
4899
4869
|
`[DI Container Error]: Registration not found for token '${tokenName}'. Ensure the service is registered before resolving.`
|
|
4900
4870
|
);
|
|
4901
4871
|
}
|
|
4902
4872
|
const currentStack = this.resolutionStack.getStore();
|
|
4903
|
-
if (!
|
|
4873
|
+
if (!import_shared32.Guards.isDefined(currentStack)) {
|
|
4904
4874
|
throw new Error(`[DI Container Error]: Execution outside the IoC container context.`);
|
|
4905
4875
|
}
|
|
4906
4876
|
if (currentStack.stack.has(token)) {
|
|
@@ -4940,7 +4910,7 @@ var ServiceContainer = class {
|
|
|
4940
4910
|
}
|
|
4941
4911
|
if (registration.lifetime === "scoped") {
|
|
4942
4912
|
const existingInstance = currentScope.getScopedInstance(token);
|
|
4943
|
-
if (
|
|
4913
|
+
if (import_shared32.Guards.isDefined(existingInstance)) {
|
|
4944
4914
|
return existingInstance;
|
|
4945
4915
|
}
|
|
4946
4916
|
return executeWithStackIsolation("scoped", () => {
|
|
@@ -4965,7 +4935,7 @@ var ServiceContainer = class {
|
|
|
4965
4935
|
};
|
|
4966
4936
|
var isDisposable = Object.freeze({
|
|
4967
4937
|
check: (obj) => {
|
|
4968
|
-
return
|
|
4938
|
+
return import_shared32.Guards.isDefined(obj) && import_shared32.Guards.isObject(obj) && "dispose" in obj && import_shared32.Guards.hasMethod(obj, "dispose");
|
|
4969
4939
|
}
|
|
4970
4940
|
});
|
|
4971
4941
|
|
|
@@ -4977,7 +4947,7 @@ var AppBuilder = class {
|
|
|
4977
4947
|
constructor(container, configurationService) {
|
|
4978
4948
|
this._container = container ?? new ServiceContainer();
|
|
4979
4949
|
this._configuration = configurationService ?? new EnvironmentConfigurationService();
|
|
4980
|
-
this._container.addSingleton(
|
|
4950
|
+
this._container.addSingleton(import_shared75.TOKENS.CONFIGURATION_SERVICE, () => this._configuration);
|
|
4981
4951
|
this.addContext();
|
|
4982
4952
|
}
|
|
4983
4953
|
// --- Module Configurations ---
|
|
@@ -5057,7 +5027,7 @@ var AppBuilder = class {
|
|
|
5057
5027
|
resilience: { retry: {}, circuitBreaker: {}, bulkhead: {} }
|
|
5058
5028
|
};
|
|
5059
5029
|
_loggerConfig = {
|
|
5060
|
-
level:
|
|
5030
|
+
level: import_shared75.LOG_LEVEL.DEBUG,
|
|
5061
5031
|
console: true,
|
|
5062
5032
|
sentry: { config: void 0 },
|
|
5063
5033
|
pino: { config: void 0 },
|
|
@@ -5130,7 +5100,7 @@ var AppBuilder = class {
|
|
|
5130
5100
|
* @link https://github.com/xeno-js/xeno-js
|
|
5131
5101
|
*/
|
|
5132
5102
|
addLogger(setupAction) {
|
|
5133
|
-
if (
|
|
5103
|
+
if (import_shared75.Guards.isDefined(setupAction)) setupAction(this._loggerConfig, this._configuration);
|
|
5134
5104
|
if (this._isLoggerModuleQueued) return this;
|
|
5135
5105
|
this._isLoggerModuleQueued = true;
|
|
5136
5106
|
this._modules.push({
|
|
@@ -5155,7 +5125,7 @@ var AppBuilder = class {
|
|
|
5155
5125
|
* @link https://github.com/xeno-js/xeno-js
|
|
5156
5126
|
*/
|
|
5157
5127
|
addCache(setupAction) {
|
|
5158
|
-
if (
|
|
5128
|
+
if (import_shared75.Guards.isDefined(setupAction)) setupAction(this._config, this._configuration);
|
|
5159
5129
|
if (this._isCacheModuleQueued) return this;
|
|
5160
5130
|
this._isCacheModuleQueued = true;
|
|
5161
5131
|
this._modules.push({
|
|
@@ -5258,7 +5228,7 @@ var AppBuilder = class {
|
|
|
5258
5228
|
* @link https://github.com/xeno-js/xeno-js
|
|
5259
5229
|
*/
|
|
5260
5230
|
addPipeline(setupAction) {
|
|
5261
|
-
if (
|
|
5231
|
+
if (import_shared75.Guards.isDefined(setupAction)) {
|
|
5262
5232
|
setupAction(this._pipelineConfig, this._configuration);
|
|
5263
5233
|
}
|
|
5264
5234
|
this._queuePipelineModule();
|
|
@@ -5377,7 +5347,7 @@ var AppBuilder = class {
|
|
|
5377
5347
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
5378
5348
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
5379
5349
|
`);
|
|
5380
|
-
if (error instanceof Error &&
|
|
5350
|
+
if (error instanceof Error && import_shared75.Guards.isDefined(error.stack)) {
|
|
5381
5351
|
console.error(error.stack);
|
|
5382
5352
|
}
|
|
5383
5353
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
@@ -5470,8 +5440,8 @@ var AppBuilder = class {
|
|
|
5470
5440
|
init_base_http_adapter();
|
|
5471
5441
|
|
|
5472
5442
|
// src/infrastructure/repositories/read-dao.ts
|
|
5443
|
+
var import_shared76 = require("@xeno-js/shared");
|
|
5473
5444
|
var import_shared77 = require("@xeno-js/shared");
|
|
5474
|
-
var import_shared78 = require("@xeno-js/shared");
|
|
5475
5445
|
var ReadDao = class {
|
|
5476
5446
|
/**
|
|
5477
5447
|
* Constructs a new ReadDao instance.
|
|
@@ -5491,23 +5461,23 @@ var ReadDao = class {
|
|
|
5491
5461
|
_dataSource;
|
|
5492
5462
|
_mapper;
|
|
5493
5463
|
async findById(id, ctx, signal) {
|
|
5494
|
-
|
|
5464
|
+
import_shared76.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
5495
5465
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5496
|
-
if (
|
|
5466
|
+
if (import_shared77.Guards.isNullOrEmpty(result)) return import_shared76.Result.ok();
|
|
5497
5467
|
const entity = this._mapper.toEntity(result);
|
|
5498
|
-
return
|
|
5468
|
+
return import_shared76.Result.ok(entity);
|
|
5499
5469
|
}
|
|
5500
5470
|
async findAll(ctx, signal) {
|
|
5501
|
-
|
|
5471
|
+
import_shared76.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
5502
5472
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5503
5473
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5504
|
-
return
|
|
5474
|
+
return import_shared76.Result.ok(entities);
|
|
5505
5475
|
}
|
|
5506
5476
|
};
|
|
5507
5477
|
|
|
5508
5478
|
// src/infrastructure/repositories/repository.ts
|
|
5479
|
+
var import_shared78 = require("@xeno-js/shared");
|
|
5509
5480
|
var import_shared79 = require("@xeno-js/shared");
|
|
5510
|
-
var import_shared80 = require("@xeno-js/shared");
|
|
5511
5481
|
var Repository = class {
|
|
5512
5482
|
/**
|
|
5513
5483
|
* Constructs a new Repository instance.
|
|
@@ -5527,48 +5497,47 @@ var Repository = class {
|
|
|
5527
5497
|
_dataSource;
|
|
5528
5498
|
_mapper;
|
|
5529
5499
|
async findById(id, ctx, signal) {
|
|
5530
|
-
|
|
5500
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.findById");
|
|
5531
5501
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
5532
|
-
if (
|
|
5502
|
+
if (import_shared79.Guards.isNullOrEmpty(result)) return import_shared78.Result.ok();
|
|
5533
5503
|
const entity = this._mapper.toEntity(result);
|
|
5534
|
-
return
|
|
5504
|
+
return import_shared78.Result.ok(entity);
|
|
5535
5505
|
}
|
|
5536
5506
|
async findAll(ctx, signal) {
|
|
5537
|
-
|
|
5507
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
5538
5508
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
5539
5509
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
5540
|
-
return
|
|
5510
|
+
return import_shared78.Result.ok(entities);
|
|
5541
5511
|
}
|
|
5542
5512
|
async save(entity, signal) {
|
|
5543
5513
|
const dto = this._mapper.toDto(entity);
|
|
5544
|
-
|
|
5514
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.save");
|
|
5545
5515
|
await this._dataSource.insert(dto, signal);
|
|
5546
|
-
return
|
|
5516
|
+
return import_shared78.Result.ok();
|
|
5547
5517
|
}
|
|
5548
5518
|
async delete(entity, ctx, signal) {
|
|
5549
5519
|
const dto = this._mapper.toDto(entity);
|
|
5550
|
-
|
|
5520
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.delete");
|
|
5551
5521
|
await this._dataSource.delete(dto, ctx, signal);
|
|
5552
|
-
return
|
|
5522
|
+
return import_shared78.Result.ok();
|
|
5553
5523
|
}
|
|
5554
5524
|
async update(id, entity, ctx, signal) {
|
|
5555
5525
|
const dto = this._mapper.toPartialDto(entity);
|
|
5556
|
-
|
|
5526
|
+
import_shared78.AppError.throwIfAborted(signal, "Repository.update");
|
|
5557
5527
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
5558
|
-
return
|
|
5528
|
+
return import_shared78.Result.ok();
|
|
5559
5529
|
}
|
|
5560
5530
|
};
|
|
5561
5531
|
|
|
5562
5532
|
// src/index.ts
|
|
5563
5533
|
init_presentation();
|
|
5564
5534
|
__reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
5565
|
-
var
|
|
5535
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
5566
5536
|
// Annotate the CommonJS export names for ESM import in node:
|
|
5567
5537
|
0 && (module.exports = {
|
|
5568
5538
|
AppBuilder,
|
|
5569
5539
|
BaseAuthorizationStrategy,
|
|
5570
5540
|
BaseController,
|
|
5571
|
-
BaseHandler,
|
|
5572
5541
|
BaseHttpAdapter,
|
|
5573
5542
|
ContainerUtils,
|
|
5574
5543
|
Query,
|