@xeno-js/core 5.0.2 → 5.1.0
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 +580 -527
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +122 -68
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.cjs
CHANGED
|
@@ -65,11 +65,11 @@ var init_concurrency = __esm({
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
// src/infrastructure/context/request-context.ts
|
|
68
|
-
var
|
|
68
|
+
var import_shared60, NodeRequestContext;
|
|
69
69
|
var init_request_context = __esm({
|
|
70
70
|
"src/infrastructure/context/request-context.ts"() {
|
|
71
71
|
"use strict";
|
|
72
|
-
|
|
72
|
+
import_shared60 = require("@xeno-js/shared");
|
|
73
73
|
NodeRequestContext = class {
|
|
74
74
|
/**
|
|
75
75
|
* @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.
|
|
@@ -97,7 +97,7 @@ var init_request_context = __esm({
|
|
|
97
97
|
}
|
|
98
98
|
updateIdentity(identity) {
|
|
99
99
|
const store = this._storage.getStore();
|
|
100
|
-
if (
|
|
100
|
+
if (import_shared60.Guards.isDefined(store) && import_shared60.Guards.isDefined(store.context)) {
|
|
101
101
|
store.context = Object.freeze({
|
|
102
102
|
...store.context,
|
|
103
103
|
identity: Object.freeze(identity)
|
|
@@ -106,28 +106,28 @@ var init_request_context = __esm({
|
|
|
106
106
|
}
|
|
107
107
|
getContext() {
|
|
108
108
|
const store = this._storage.getStore();
|
|
109
|
-
if (!
|
|
109
|
+
if (!import_shared60.Guards.isDefined(store)) return void 0;
|
|
110
110
|
const context = store.context;
|
|
111
111
|
return Object.freeze(context);
|
|
112
112
|
}
|
|
113
113
|
getIdentity() {
|
|
114
114
|
const store = this._storage.getStore();
|
|
115
|
-
if (!
|
|
115
|
+
if (!import_shared60.Guards.isDefined(store)) return void 0;
|
|
116
116
|
return Object.freeze(store.context?.identity);
|
|
117
117
|
}
|
|
118
118
|
getScope() {
|
|
119
119
|
const store = this._storage.getStore();
|
|
120
|
-
if (!
|
|
120
|
+
if (!import_shared60.Guards.isDefined(store)) return void 0;
|
|
121
121
|
return store.scope;
|
|
122
122
|
}
|
|
123
123
|
getNetworkContext() {
|
|
124
124
|
const store = this._storage.getStore();
|
|
125
|
-
if (!
|
|
125
|
+
if (!import_shared60.Guards.isDefined(store)) return void 0;
|
|
126
126
|
return Object.freeze(store.context?.network);
|
|
127
127
|
}
|
|
128
128
|
getTracingContext() {
|
|
129
129
|
const store = this._storage.getStore();
|
|
130
|
-
if (!
|
|
130
|
+
if (!import_shared60.Guards.isDefined(store)) return void 0;
|
|
131
131
|
return Object.freeze(store.context?.tracing);
|
|
132
132
|
}
|
|
133
133
|
};
|
|
@@ -186,6 +186,7 @@ __export(index_exports, {
|
|
|
186
186
|
withCors: () => withCors,
|
|
187
187
|
withCsrf: () => withCsrf,
|
|
188
188
|
withCustomHttp: () => withCustomHttp,
|
|
189
|
+
withEnrichmentIdentity: () => withEnrichmentIdentity,
|
|
189
190
|
withIdempotency: () => withIdempotency,
|
|
190
191
|
withPerformance: () => withPerformance,
|
|
191
192
|
withQueryCaching: () => withQueryCaching,
|
|
@@ -541,6 +542,21 @@ var IdempotencyPipeline = class _IdempotencyPipeline {
|
|
|
541
542
|
}
|
|
542
543
|
};
|
|
543
544
|
|
|
545
|
+
// src/application/cqrs/pipelines/identity-enrichment.pipeline.ts
|
|
546
|
+
var IdentityEnrichmentPipeline = class {
|
|
547
|
+
constructor(_requestContext, _strategy) {
|
|
548
|
+
this._requestContext = _requestContext;
|
|
549
|
+
this._strategy = _strategy;
|
|
550
|
+
}
|
|
551
|
+
_requestContext;
|
|
552
|
+
_strategy;
|
|
553
|
+
async handle(request, next) {
|
|
554
|
+
const identity = this._requestContext.getIdentity() ?? {};
|
|
555
|
+
await this._strategy.execute(identity);
|
|
556
|
+
return next();
|
|
557
|
+
}
|
|
558
|
+
};
|
|
559
|
+
|
|
544
560
|
// src/application/cqrs/pipelines/logging.pipeline.ts
|
|
545
561
|
var LoggingPipeline = class {
|
|
546
562
|
/**
|
|
@@ -785,8 +801,16 @@ var UserAuthorizationStrategy = class extends BaseAuthorizationStrategy {
|
|
|
785
801
|
}
|
|
786
802
|
};
|
|
787
803
|
|
|
788
|
-
// src/application/cqrs/pipelines/pipeline_strategies/
|
|
804
|
+
// src/application/cqrs/pipelines/pipeline_strategies/enrichment/noop-identity-enrichment.strategy.ts
|
|
789
805
|
var import_shared23 = require("@xeno-js/shared");
|
|
806
|
+
var NoopIdentityEnrichmentStrategy = class {
|
|
807
|
+
async execute(_identity) {
|
|
808
|
+
return import_shared23.Result.ok();
|
|
809
|
+
}
|
|
810
|
+
};
|
|
811
|
+
|
|
812
|
+
// src/application/cqrs/pipelines/pipeline_strategies/validation/schema-validation.strategy.ts
|
|
813
|
+
var import_shared24 = require("@xeno-js/shared");
|
|
790
814
|
var SchemaValidationStrategy = class {
|
|
791
815
|
/**
|
|
792
816
|
* @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.
|
|
@@ -807,19 +831,19 @@ var SchemaValidationStrategy = class {
|
|
|
807
831
|
if (!parseResult.isOk()) {
|
|
808
832
|
const validatorError = parseResult.getErrorOrThrow();
|
|
809
833
|
const details = validatorError.cause instanceof Error ? validatorError.cause.message : validatorError.message;
|
|
810
|
-
return
|
|
811
|
-
Object.assign(
|
|
834
|
+
return import_shared24.Result.fail(
|
|
835
|
+
Object.assign(import_shared24.AppError.validationError(request.intent, `Validation failed: ${details}`), {
|
|
812
836
|
validatorError
|
|
813
837
|
})
|
|
814
838
|
);
|
|
815
839
|
}
|
|
816
|
-
return
|
|
840
|
+
return import_shared24.Result.ok(true);
|
|
817
841
|
}
|
|
818
842
|
};
|
|
819
843
|
|
|
820
844
|
// src/application/cqrs/pipelines/query-caching.pipeline.ts
|
|
821
|
-
var import_shared24 = require("@xeno-js/shared");
|
|
822
845
|
var import_shared25 = require("@xeno-js/shared");
|
|
846
|
+
var import_shared26 = require("@xeno-js/shared");
|
|
823
847
|
var QueryCachingPipeline = class {
|
|
824
848
|
/**
|
|
825
849
|
* @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.
|
|
@@ -841,18 +865,18 @@ var QueryCachingPipeline = class {
|
|
|
841
865
|
_cacheKeyBuilder;
|
|
842
866
|
_logger;
|
|
843
867
|
async handle(request, next) {
|
|
844
|
-
if (
|
|
868
|
+
if (import_shared26.Guards.isNullOrEmpty(request.cacheOptions) || import_shared26.Guards.isNullOrEmpty(request.cacheOptions.cacheKey))
|
|
845
869
|
return next();
|
|
846
870
|
const bypass = request.cacheOptions.bypassCache === true || request.cacheOptions.consistentRead === true;
|
|
847
871
|
const key = request.cacheOptions.isUserScoped ? this._cacheKeyBuilder.buildUserScopedKey(request.cacheOptions.cacheKey) : this._cacheKeyBuilder.buildContextualKey(request.cacheOptions.cacheKey);
|
|
848
872
|
if (!bypass) {
|
|
849
873
|
try {
|
|
850
874
|
const cachedResponse = await this._cacheService.get(key);
|
|
851
|
-
if (
|
|
875
|
+
if (import_shared26.Guards.isDefined(cachedResponse)) {
|
|
852
876
|
this._logger.debug(
|
|
853
877
|
`[Cache HIT] Returning data from cache for: ${request.cacheOptions.cacheKey}`
|
|
854
878
|
);
|
|
855
|
-
return
|
|
879
|
+
return import_shared25.Result.ok(cachedResponse);
|
|
856
880
|
}
|
|
857
881
|
} catch (error) {
|
|
858
882
|
this._logger.warn(
|
|
@@ -876,7 +900,7 @@ var QueryCachingPipeline = class {
|
|
|
876
900
|
};
|
|
877
901
|
|
|
878
902
|
// src/application/cqrs/pipelines/validation.pipeline.ts
|
|
879
|
-
var
|
|
903
|
+
var import_shared27 = require("@xeno-js/shared");
|
|
880
904
|
var ValidationPipeline = class {
|
|
881
905
|
/** @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.
|
|
882
906
|
* @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.
|
|
@@ -894,7 +918,7 @@ var ValidationPipeline = class {
|
|
|
894
918
|
for (const validator of this._validators) {
|
|
895
919
|
const validationResult = await validator.execute(request);
|
|
896
920
|
if (!validationResult.isOk()) {
|
|
897
|
-
return
|
|
921
|
+
return import_shared27.Result.fail(validationResult.getErrorOrThrow());
|
|
898
922
|
}
|
|
899
923
|
}
|
|
900
924
|
return next();
|
|
@@ -902,7 +926,7 @@ var ValidationPipeline = class {
|
|
|
902
926
|
};
|
|
903
927
|
|
|
904
928
|
// src/application/cqrs/query/query.ts
|
|
905
|
-
var
|
|
929
|
+
var import_shared28 = require("@xeno-js/shared");
|
|
906
930
|
var Query = class {
|
|
907
931
|
constructor(intent, cacheOptions) {
|
|
908
932
|
this.intent = intent;
|
|
@@ -910,12 +934,12 @@ var Query = class {
|
|
|
910
934
|
}
|
|
911
935
|
intent;
|
|
912
936
|
cacheOptions;
|
|
913
|
-
type =
|
|
937
|
+
type = import_shared28.REQUEST_TYPE.QUERY;
|
|
914
938
|
};
|
|
915
939
|
|
|
916
940
|
// src/application/gate_keepers/gate-keeper.ts
|
|
917
|
-
var import_shared28 = require("@xeno-js/shared");
|
|
918
941
|
var import_shared29 = require("@xeno-js/shared");
|
|
942
|
+
var import_shared30 = require("@xeno-js/shared");
|
|
919
943
|
var GateKeeper = class {
|
|
920
944
|
constructor(_authServiceResolver, _mapper) {
|
|
921
945
|
this._authServiceResolver = _authServiceResolver;
|
|
@@ -924,41 +948,41 @@ var GateKeeper = class {
|
|
|
924
948
|
_authServiceResolver;
|
|
925
949
|
_mapper;
|
|
926
950
|
async authenticate(token) {
|
|
927
|
-
const guest =
|
|
951
|
+
const guest = import_shared30.GUEST;
|
|
928
952
|
const authService = this._authServiceResolver();
|
|
929
|
-
if (!
|
|
953
|
+
if (!import_shared30.Guards.isNullOrEmpty(token)) {
|
|
930
954
|
const authResult = await authService.authenticate(token);
|
|
931
|
-
if (!authResult.isOk()) return
|
|
955
|
+
if (!authResult.isOk()) return import_shared29.Result.fail(authResult.getErrorOrThrow());
|
|
932
956
|
const claims = authResult.getValueOrThrow();
|
|
933
|
-
if (!
|
|
934
|
-
return
|
|
957
|
+
if (!import_shared30.Guards.isNullOrEmpty(claims)) return import_shared29.Result.ok(this._mapper.map(claims));
|
|
958
|
+
return import_shared29.Result.ok(guest);
|
|
935
959
|
}
|
|
936
960
|
const userResult = await authService.getUser();
|
|
937
961
|
if (userResult.isOk()) {
|
|
938
962
|
const user = userResult.getValueOrThrow();
|
|
939
|
-
if (
|
|
940
|
-
return
|
|
963
|
+
if (import_shared30.Guards.isDefined(user)) {
|
|
964
|
+
return import_shared29.Result.ok(this._mapper.map(user));
|
|
941
965
|
}
|
|
942
966
|
}
|
|
943
|
-
return
|
|
967
|
+
return import_shared29.Result.ok(guest);
|
|
944
968
|
}
|
|
945
969
|
};
|
|
946
970
|
|
|
947
971
|
// src/application/gate_keepers/noauth.gate-keeper.ts
|
|
948
|
-
var import_shared30 = require("@xeno-js/shared");
|
|
949
972
|
var import_shared31 = require("@xeno-js/shared");
|
|
973
|
+
var import_shared32 = require("@xeno-js/shared");
|
|
950
974
|
var NoAuthGateKeeper = class {
|
|
951
975
|
async authenticate(_token) {
|
|
952
|
-
const guest =
|
|
953
|
-
return
|
|
976
|
+
const guest = import_shared32.GUEST;
|
|
977
|
+
return import_shared31.Result.ok(guest);
|
|
954
978
|
}
|
|
955
979
|
};
|
|
956
980
|
|
|
957
981
|
// src/application/loggers/base.logger.ts
|
|
958
|
-
var
|
|
982
|
+
var import_shared34 = require("@xeno-js/shared");
|
|
959
983
|
|
|
960
984
|
// src/application/loggers/utils/logger-context.utils.ts
|
|
961
|
-
var
|
|
985
|
+
var import_shared33 = require("@xeno-js/shared");
|
|
962
986
|
var LoggerUtils = Object.freeze({
|
|
963
987
|
/**
|
|
964
988
|
* @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
|
|
@@ -975,33 +999,32 @@ var LoggerUtils = Object.freeze({
|
|
|
975
999
|
requestId: ctx?.network?.requestId,
|
|
976
1000
|
path: ctx?.network?.path,
|
|
977
1001
|
origin: ctx?.network?.origin,
|
|
978
|
-
clientIp:
|
|
1002
|
+
clientIp: import_shared33.HttpHelper.maskIp(ctx?.network?.clientIp)
|
|
979
1003
|
},
|
|
980
1004
|
tracing: {
|
|
981
1005
|
correlationId: ctx?.tracing?.correlationId,
|
|
982
1006
|
spanId: ctx?.tracing?.spanId,
|
|
983
1007
|
startTime: ctx?.tracing?.startTime,
|
|
984
|
-
parentSpanId: ctx?.tracing
|
|
1008
|
+
parentSpanId: ctx?.tracing?.parentSpanId
|
|
985
1009
|
},
|
|
986
1010
|
messaging: ctx?.messaging
|
|
987
1011
|
};
|
|
988
|
-
return
|
|
1012
|
+
return import_shared33.StringHelper.safeStringifyObject(context);
|
|
989
1013
|
},
|
|
990
1014
|
toNormalizeError(error) {
|
|
991
1015
|
if (error instanceof Error) {
|
|
992
1016
|
return {
|
|
993
|
-
|
|
1017
|
+
...error,
|
|
994
1018
|
name: error.name,
|
|
1019
|
+
message: error.message,
|
|
995
1020
|
stack: error.stack,
|
|
996
|
-
cause: error.cause
|
|
1021
|
+
cause: import_shared33.Guards.isDefined(error.cause) ? LoggerUtils.toNormalizeError(error.cause) : error.cause
|
|
997
1022
|
};
|
|
998
1023
|
}
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
if (import_shared32.Guards.isObject(error) && import_shared32.Guards.isDefined(error)) {
|
|
1002
|
-
Object.assign(customError, error);
|
|
1024
|
+
if (import_shared33.Guards.isObject(error)) {
|
|
1025
|
+
return { ...error };
|
|
1003
1026
|
}
|
|
1004
|
-
return
|
|
1027
|
+
return { message: import_shared33.Guards.isString(error) ? error : import_shared33.StringHelper.safeStringify(error) };
|
|
1005
1028
|
}
|
|
1006
1029
|
});
|
|
1007
1030
|
|
|
@@ -1028,16 +1051,16 @@ var BaseLogger = class {
|
|
|
1028
1051
|
_minLevel;
|
|
1029
1052
|
_loggers;
|
|
1030
1053
|
info(message) {
|
|
1031
|
-
this.broadcast(
|
|
1054
|
+
this.broadcast(import_shared34.LOG_LEVEL.INFO, message);
|
|
1032
1055
|
}
|
|
1033
1056
|
warn(message) {
|
|
1034
|
-
this.broadcast(
|
|
1057
|
+
this.broadcast(import_shared34.LOG_LEVEL.WARN, message);
|
|
1035
1058
|
}
|
|
1036
1059
|
debug(message) {
|
|
1037
|
-
this.broadcast(
|
|
1060
|
+
this.broadcast(import_shared34.LOG_LEVEL.DEBUG, message);
|
|
1038
1061
|
}
|
|
1039
1062
|
error(message, error) {
|
|
1040
|
-
this.broadcast(
|
|
1063
|
+
this.broadcast(import_shared34.LOG_LEVEL.ERROR, message, error);
|
|
1041
1064
|
}
|
|
1042
1065
|
/**
|
|
1043
1066
|
* @description Private method to broadcast log messages to all registered ILoggerClient instances. This method checks if the log level of the message meets or exceeds the configured minimum log level before forwarding the message to the logging clients. It iterates through the array of ILoggerClient instances and calls their track method with the appropriate parameters (log level, message, context, and error if applicable). This design allows for efficient logging by ensuring that only relevant log messages are processed and forwarded to the logging clients based on the configured log level.
|
|
@@ -1053,24 +1076,25 @@ var BaseLogger = class {
|
|
|
1053
1076
|
*/
|
|
1054
1077
|
broadcast(level, message, error = void 0) {
|
|
1055
1078
|
if (level < this._minLevel) return;
|
|
1056
|
-
const logMessage = `[${
|
|
1079
|
+
const logMessage = `[${import_shared34.LOG_LEVEL_NAMES[level]}] ${message}`;
|
|
1057
1080
|
const context = this._requestContext.getContext();
|
|
1058
1081
|
const safeContext = LoggerUtils.toSafeContext(context);
|
|
1082
|
+
const safeError = LoggerUtils.toNormalizeError(error);
|
|
1059
1083
|
for (const logger of this._loggers) {
|
|
1060
|
-
logger.track(level, logMessage, safeContext,
|
|
1084
|
+
logger.track(level, logMessage, safeContext, safeError);
|
|
1061
1085
|
}
|
|
1062
1086
|
}
|
|
1063
1087
|
};
|
|
1064
1088
|
|
|
1065
1089
|
// src/application/mappers/claims-identity.mapper.ts
|
|
1066
|
-
var
|
|
1090
|
+
var import_shared35 = require("@xeno-js/shared");
|
|
1067
1091
|
var ClaimsIdentityMapper = class {
|
|
1068
1092
|
map(claims) {
|
|
1069
1093
|
return {
|
|
1070
|
-
userId:
|
|
1094
|
+
userId: import_shared35.GuidHelper.parse(claims.sub),
|
|
1071
1095
|
email: claims.email,
|
|
1072
1096
|
name: claims.name,
|
|
1073
|
-
tenantId:
|
|
1097
|
+
tenantId: import_shared35.GuidHelper.parse(claims.tenantId),
|
|
1074
1098
|
roles: claims.roles,
|
|
1075
1099
|
permissions: claims.permissions
|
|
1076
1100
|
};
|
|
@@ -1195,10 +1219,10 @@ var NotSpecification = class extends Specification {
|
|
|
1195
1219
|
};
|
|
1196
1220
|
|
|
1197
1221
|
// src/infrastructure/builder/app.builder.ts
|
|
1198
|
-
var
|
|
1222
|
+
var import_shared114 = require("@xeno-js/shared");
|
|
1199
1223
|
|
|
1200
1224
|
// src/infrastructure/configuration/node.configuration.ts
|
|
1201
|
-
var
|
|
1225
|
+
var import_shared36 = require("@xeno-js/shared");
|
|
1202
1226
|
var EnvironmentConfigurationService = class {
|
|
1203
1227
|
/**
|
|
1204
1228
|
* @description Internal dictionary to hold environment variables.
|
|
@@ -1220,7 +1244,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1220
1244
|
}
|
|
1221
1245
|
get(key, defaultValue) {
|
|
1222
1246
|
const value = this._env[key];
|
|
1223
|
-
if (
|
|
1247
|
+
if (import_shared36.Guards.isNullOrEmpty(value)) {
|
|
1224
1248
|
return defaultValue;
|
|
1225
1249
|
}
|
|
1226
1250
|
return value;
|
|
@@ -1230,7 +1254,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1230
1254
|
}
|
|
1231
1255
|
getNumber(key, defaultValue) {
|
|
1232
1256
|
const value = this.get(key);
|
|
1233
|
-
if (
|
|
1257
|
+
if (import_shared36.Guards.isNullOrEmpty(value)) {
|
|
1234
1258
|
return defaultValue;
|
|
1235
1259
|
}
|
|
1236
1260
|
const parsed = Number(value);
|
|
@@ -1243,7 +1267,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1243
1267
|
}
|
|
1244
1268
|
getBoolean(key, defaultValue) {
|
|
1245
1269
|
const value = this.get(key);
|
|
1246
|
-
if (
|
|
1270
|
+
if (import_shared36.Guards.isNullOrEmpty(value)) {
|
|
1247
1271
|
return defaultValue;
|
|
1248
1272
|
}
|
|
1249
1273
|
const normalized = value.toLowerCase().trim();
|
|
@@ -1255,7 +1279,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1255
1279
|
}
|
|
1256
1280
|
getOrThrow(key) {
|
|
1257
1281
|
const value = this.get(key);
|
|
1258
|
-
if (!
|
|
1282
|
+
if (!import_shared36.Guards.isDefined(value)) {
|
|
1259
1283
|
throw new Error(
|
|
1260
1284
|
`[Configuration Error]: Required configuration key "${key}" is missing in the environment.`
|
|
1261
1285
|
);
|
|
@@ -1265,7 +1289,7 @@ var EnvironmentConfigurationService = class {
|
|
|
1265
1289
|
};
|
|
1266
1290
|
|
|
1267
1291
|
// src/infrastructure/configuration/vite.configuration.ts
|
|
1268
|
-
var
|
|
1292
|
+
var import_shared37 = require("@xeno-js/shared");
|
|
1269
1293
|
var import_meta = {};
|
|
1270
1294
|
var VITE_PREFIX = "VITE_";
|
|
1271
1295
|
var ViteConfigurationService = class {
|
|
@@ -1276,12 +1300,12 @@ var ViteConfigurationService = class {
|
|
|
1276
1300
|
get(key, defaultValue) {
|
|
1277
1301
|
const fullKey = key.startsWith(VITE_PREFIX) ? key : `VITE_${key}`;
|
|
1278
1302
|
const value = String(this._env[fullKey]);
|
|
1279
|
-
if (!
|
|
1303
|
+
if (!import_shared37.Guards.isNullOrEmpty(value)) return value;
|
|
1280
1304
|
return defaultValue;
|
|
1281
1305
|
}
|
|
1282
1306
|
getNumber(key, defaultValue) {
|
|
1283
1307
|
const rawValue = this.get(key);
|
|
1284
|
-
if (
|
|
1308
|
+
if (import_shared37.Guards.isDefined(rawValue)) {
|
|
1285
1309
|
const parsed = Number(rawValue);
|
|
1286
1310
|
if (!Number.isNaN(parsed)) return parsed;
|
|
1287
1311
|
}
|
|
@@ -1289,7 +1313,7 @@ var ViteConfigurationService = class {
|
|
|
1289
1313
|
}
|
|
1290
1314
|
getBoolean(key, defaultValue) {
|
|
1291
1315
|
const rawValue = this.get(key);
|
|
1292
|
-
if (
|
|
1316
|
+
if (import_shared37.Guards.isDefined(rawValue)) {
|
|
1293
1317
|
const str = String(rawValue).toLowerCase().trim();
|
|
1294
1318
|
if (str.toLowerCase() === "true" || str === "1") return true;
|
|
1295
1319
|
if (str.toLowerCase() === "false" || str === "0") return false;
|
|
@@ -1298,7 +1322,7 @@ var ViteConfigurationService = class {
|
|
|
1298
1322
|
}
|
|
1299
1323
|
getOrThrow(key) {
|
|
1300
1324
|
const val = this.get(key);
|
|
1301
|
-
if (!
|
|
1325
|
+
if (!import_shared37.Guards.isDefined(val)) {
|
|
1302
1326
|
throw new Error(`[Configuration Error]: Missing required environment variable "${key}".`);
|
|
1303
1327
|
}
|
|
1304
1328
|
return val;
|
|
@@ -1309,7 +1333,7 @@ var ViteConfigurationService = class {
|
|
|
1309
1333
|
};
|
|
1310
1334
|
|
|
1311
1335
|
// src/infrastructure/container/service-container.ts
|
|
1312
|
-
var
|
|
1336
|
+
var import_shared38 = require("@xeno-js/shared");
|
|
1313
1337
|
var ContainerScope = class {
|
|
1314
1338
|
constructor(container, parentScope) {
|
|
1315
1339
|
this.container = container;
|
|
@@ -1415,7 +1439,7 @@ var ServiceContainer = class {
|
|
|
1415
1439
|
* @link https://github.com/xeno-js/xeno-js
|
|
1416
1440
|
*/
|
|
1417
1441
|
internalExecuteInContext(callback) {
|
|
1418
|
-
if (
|
|
1442
|
+
if (import_shared38.Guards.isDefined(this.resolutionStack)) return callback();
|
|
1419
1443
|
this.resolutionStack = {
|
|
1420
1444
|
stack: /* @__PURE__ */ new Set()
|
|
1421
1445
|
};
|
|
@@ -1440,14 +1464,14 @@ var ServiceContainer = class {
|
|
|
1440
1464
|
*/
|
|
1441
1465
|
internalResolveInternal(token, currentScope) {
|
|
1442
1466
|
const registration = this.registrations.get(token);
|
|
1443
|
-
if (!
|
|
1467
|
+
if (!import_shared38.Guards.isDefined(registration)) {
|
|
1444
1468
|
const tokenName = token.toString();
|
|
1445
1469
|
throw new Error(
|
|
1446
1470
|
`[DI Container Error]: Registration not found for token '${tokenName}'. Ensure the service is registered before resolving.`
|
|
1447
1471
|
);
|
|
1448
1472
|
}
|
|
1449
1473
|
const currentStack = this.resolutionStack;
|
|
1450
|
-
if (!
|
|
1474
|
+
if (!import_shared38.Guards.isDefined(currentStack)) {
|
|
1451
1475
|
throw new Error(`[DI Container Error]: Execution outside the IoC container context.`);
|
|
1452
1476
|
}
|
|
1453
1477
|
if (currentStack.stack.has(token)) {
|
|
@@ -1487,7 +1511,7 @@ var ServiceContainer = class {
|
|
|
1487
1511
|
}
|
|
1488
1512
|
if (registration.lifetime === "scoped") {
|
|
1489
1513
|
const existingInstance = currentScope.getScopedInstance(token);
|
|
1490
|
-
if (
|
|
1514
|
+
if (import_shared38.Guards.isDefined(existingInstance)) {
|
|
1491
1515
|
return existingInstance;
|
|
1492
1516
|
}
|
|
1493
1517
|
return executeWithStackIsolation("scoped", () => {
|
|
@@ -1512,45 +1536,45 @@ var ServiceContainer = class {
|
|
|
1512
1536
|
};
|
|
1513
1537
|
var isDisposable = Object.freeze({
|
|
1514
1538
|
check: (obj) => {
|
|
1515
|
-
return
|
|
1539
|
+
return import_shared38.Guards.isDefined(obj) && import_shared38.Guards.isObject(obj) && "dispose" in obj && import_shared38.Guards.hasMethod(obj, "dispose");
|
|
1516
1540
|
}
|
|
1517
1541
|
});
|
|
1518
1542
|
|
|
1519
1543
|
// src/infrastructure/modules/auth.module.ts
|
|
1520
|
-
var import_shared46 = require("@xeno-js/shared");
|
|
1521
1544
|
var import_shared47 = require("@xeno-js/shared");
|
|
1545
|
+
var import_shared48 = require("@xeno-js/shared");
|
|
1522
1546
|
|
|
1523
1547
|
// src/infrastructure/services/allow_methods/allow-method.service.ts
|
|
1524
|
-
var
|
|
1548
|
+
var import_shared39 = require("@xeno-js/shared");
|
|
1525
1549
|
var AllowMethodRegistry = class {
|
|
1526
1550
|
_staticRoutes = /* @__PURE__ */ new Map();
|
|
1527
1551
|
_dynamicRoutes = [];
|
|
1528
1552
|
add(path, methods) {
|
|
1529
|
-
const normalizedPath =
|
|
1530
|
-
if (
|
|
1531
|
-
const pattern =
|
|
1553
|
+
const normalizedPath = import_shared39.RoutePatternHelper.normalizePath(path);
|
|
1554
|
+
if (import_shared39.RoutePatternHelper.isDynamicPath(normalizedPath)) {
|
|
1555
|
+
const pattern = import_shared39.RoutePatternHelper.createRoutePattern(normalizedPath);
|
|
1532
1556
|
this._dynamicRoutes.push({ pattern, methods });
|
|
1533
1557
|
} else {
|
|
1534
1558
|
this._staticRoutes.set(normalizedPath, methods);
|
|
1535
1559
|
}
|
|
1536
1560
|
}
|
|
1537
1561
|
check(path, method) {
|
|
1538
|
-
const cleanPath =
|
|
1562
|
+
const cleanPath = import_shared39.RoutePatternHelper.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1539
1563
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1540
|
-
if (
|
|
1564
|
+
if (import_shared39.Guards.isDefined(staticMethods)) return staticMethods.includes(method);
|
|
1541
1565
|
for (const route of this._dynamicRoutes) {
|
|
1542
1566
|
if (route.pattern.test(cleanPath)) return route.methods.includes(method);
|
|
1543
1567
|
}
|
|
1544
1568
|
return false;
|
|
1545
1569
|
}
|
|
1546
1570
|
getMethods(path) {
|
|
1547
|
-
const cleanPath =
|
|
1571
|
+
const cleanPath = import_shared39.RoutePatternHelper.normalizePath(path.split("?")[0].split("#")[0]);
|
|
1548
1572
|
const methods = this.findMethods(cleanPath);
|
|
1549
|
-
return
|
|
1573
|
+
return import_shared39.Guards.isDefined(methods) ? methods.join(", ").toUpperCase() : "";
|
|
1550
1574
|
}
|
|
1551
1575
|
findMethods(cleanPath) {
|
|
1552
1576
|
const staticMethods = this._staticRoutes.get(cleanPath);
|
|
1553
|
-
if (
|
|
1577
|
+
if (import_shared39.Guards.isDefined(staticMethods)) return staticMethods;
|
|
1554
1578
|
for (const route of this._dynamicRoutes) {
|
|
1555
1579
|
if (route.pattern.test(cleanPath)) return route.methods;
|
|
1556
1580
|
}
|
|
@@ -1559,14 +1583,14 @@ var AllowMethodRegistry = class {
|
|
|
1559
1583
|
};
|
|
1560
1584
|
|
|
1561
1585
|
// src/infrastructure/services/allow_origins/allow-origin.http.ts
|
|
1562
|
-
var
|
|
1586
|
+
var import_shared40 = require("@xeno-js/shared");
|
|
1563
1587
|
var AllowOrigin = class {
|
|
1564
1588
|
constructor(_list) {
|
|
1565
1589
|
this._list = _list;
|
|
1566
1590
|
}
|
|
1567
1591
|
_list;
|
|
1568
1592
|
isAllowed(origin) {
|
|
1569
|
-
if (
|
|
1593
|
+
if (import_shared40.Guards.isNullOrEmpty(origin)) return true;
|
|
1570
1594
|
const cleanOrigin = origin.trim().toLowerCase();
|
|
1571
1595
|
for (const pattern of this._list) {
|
|
1572
1596
|
const cleanPattern = pattern.trim().toLowerCase();
|
|
@@ -1576,7 +1600,7 @@ var AllowOrigin = class {
|
|
|
1576
1600
|
const domainSuffix = cleanPattern.substring(1);
|
|
1577
1601
|
if (cleanOrigin.endsWith(domainSuffix)) {
|
|
1578
1602
|
const prefix = cleanOrigin.slice(0, cleanOrigin.length - domainSuffix.length);
|
|
1579
|
-
if (!
|
|
1603
|
+
if (!import_shared40.Guards.isNullOrEmpty(prefix) && !prefix.includes(".")) return true;
|
|
1580
1604
|
}
|
|
1581
1605
|
}
|
|
1582
1606
|
}
|
|
@@ -1588,7 +1612,7 @@ var AllowOrigin = class {
|
|
|
1588
1612
|
init_concurrency();
|
|
1589
1613
|
|
|
1590
1614
|
// src/infrastructure/services/cookies/cookies.service.ts
|
|
1591
|
-
var
|
|
1615
|
+
var import_shared41 = require("@xeno-js/shared");
|
|
1592
1616
|
var CookieHandler = class {
|
|
1593
1617
|
constructor(_contextAccessor, _config, _defaultOpts) {
|
|
1594
1618
|
this._contextAccessor = _contextAccessor;
|
|
@@ -1602,8 +1626,8 @@ var CookieHandler = class {
|
|
|
1602
1626
|
getAll() {
|
|
1603
1627
|
const network = this._contextAccessor.getNetworkContext();
|
|
1604
1628
|
const cookie = network?.cookies;
|
|
1605
|
-
if (
|
|
1606
|
-
const parsedCookies =
|
|
1629
|
+
if (import_shared41.Guards.isNullOrEmpty(cookie)) return [];
|
|
1630
|
+
const parsedCookies = import_shared41.HttpHelper.parseCookies(network?.cookies);
|
|
1607
1631
|
return Object.entries(parsedCookies).map(([name, value]) => ({
|
|
1608
1632
|
name,
|
|
1609
1633
|
value
|
|
@@ -1628,14 +1652,14 @@ var CookieHandler = class {
|
|
|
1628
1652
|
...this._defaultOpts,
|
|
1629
1653
|
...cookie
|
|
1630
1654
|
};
|
|
1631
|
-
if (!
|
|
1632
|
-
if (!
|
|
1633
|
-
if (!
|
|
1634
|
-
if (!
|
|
1635
|
-
if (!
|
|
1636
|
-
if (!
|
|
1637
|
-
if (!
|
|
1638
|
-
if (
|
|
1655
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.path)) str += `; Path=${merged.path}`;
|
|
1656
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.maxAge)) str += `; Max-Age=${merged.maxAge}`;
|
|
1657
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.expires)) str += `; Expires=${merged.expires.toUTCString()}`;
|
|
1658
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.domain)) str += `; Domain=${merged.domain}`;
|
|
1659
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.secure) && merged.secure) str += "; Secure";
|
|
1660
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.httpOnly) && merged.httpOnly) str += "; HttpOnly";
|
|
1661
|
+
if (!import_shared41.Guards.isNullOrEmpty(merged.sameSite)) {
|
|
1662
|
+
if (import_shared41.Guards.isBoolean(merged.sameSite)) {
|
|
1639
1663
|
str += merged.sameSite ? "; SameSite=Strict" : "";
|
|
1640
1664
|
} else {
|
|
1641
1665
|
const val = merged.sameSite.toLowerCase();
|
|
@@ -1643,8 +1667,8 @@ var CookieHandler = class {
|
|
|
1643
1667
|
str += `; SameSite=${formatted}`;
|
|
1644
1668
|
}
|
|
1645
1669
|
}
|
|
1646
|
-
if (
|
|
1647
|
-
if (
|
|
1670
|
+
if (import_shared41.Guards.isDefined(merged.partitioned)) str += "; Partitioned";
|
|
1671
|
+
if (import_shared41.Guards.isDefined(merged.priority)) {
|
|
1648
1672
|
const p = merged.priority.toLowerCase();
|
|
1649
1673
|
const formattedPriority = p.charAt(0).toUpperCase() + p.slice(1);
|
|
1650
1674
|
str += `; Priority=${formattedPriority}`;
|
|
@@ -1687,7 +1711,7 @@ var EdgeCryptoService = class {
|
|
|
1687
1711
|
};
|
|
1688
1712
|
|
|
1689
1713
|
// src/infrastructure/services/csrf/csrf-token.service.ts
|
|
1690
|
-
var
|
|
1714
|
+
var import_shared42 = require("@xeno-js/shared");
|
|
1691
1715
|
var CsrfTokenService = class {
|
|
1692
1716
|
constructor(_secret, _cryptoService) {
|
|
1693
1717
|
this._secret = _secret;
|
|
@@ -1706,7 +1730,7 @@ var CsrfTokenService = class {
|
|
|
1706
1730
|
if (separatorIndex <= 0) return false;
|
|
1707
1731
|
const nonce = token.slice(0, separatorIndex);
|
|
1708
1732
|
const signature = token.slice(separatorIndex + 1);
|
|
1709
|
-
if (
|
|
1733
|
+
if (import_shared42.Guards.isNullOrEmpty(nonce) || import_shared42.Guards.isNullOrEmpty(signature)) return false;
|
|
1710
1734
|
const expected = await this._cryptoService.hmacSha256(this._secret, `${subject}.${nonce}`);
|
|
1711
1735
|
const encoder = new TextEncoder();
|
|
1712
1736
|
const actualBuffer = encoder.encode(signature);
|
|
@@ -1717,7 +1741,7 @@ var CsrfTokenService = class {
|
|
|
1717
1741
|
};
|
|
1718
1742
|
|
|
1719
1743
|
// src/infrastructure/services/extractors/extract-bearer.extractor.ts
|
|
1720
|
-
var
|
|
1744
|
+
var import_shared43 = require("@xeno-js/shared");
|
|
1721
1745
|
var BearerTokenExtractor = class {
|
|
1722
1746
|
constructor(_cookiePrefix) {
|
|
1723
1747
|
this._cookiePrefix = _cookiePrefix;
|
|
@@ -1725,14 +1749,14 @@ var BearerTokenExtractor = class {
|
|
|
1725
1749
|
_cookiePrefix;
|
|
1726
1750
|
extract(headers) {
|
|
1727
1751
|
const authHeader = headers.get("Authorization");
|
|
1728
|
-
if (
|
|
1752
|
+
if (import_shared43.Guards.isDefined(authHeader) && authHeader.toLowerCase().startsWith("bearer ")) {
|
|
1729
1753
|
return authHeader.substring(7);
|
|
1730
1754
|
}
|
|
1731
1755
|
const cookieHeader = headers.get("cookie");
|
|
1732
|
-
if (
|
|
1733
|
-
const cookies =
|
|
1756
|
+
if (import_shared43.Guards.isDefined(cookieHeader)) {
|
|
1757
|
+
const cookies = import_shared43.HttpHelper.parseCookies(cookieHeader);
|
|
1734
1758
|
const token = cookies[this._cookiePrefix];
|
|
1735
|
-
if (
|
|
1759
|
+
if (import_shared43.Guards.isDefined(token)) {
|
|
1736
1760
|
return token;
|
|
1737
1761
|
}
|
|
1738
1762
|
}
|
|
@@ -1741,17 +1765,17 @@ var BearerTokenExtractor = class {
|
|
|
1741
1765
|
};
|
|
1742
1766
|
|
|
1743
1767
|
// src/infrastructure/services/extractors/http-cookie.extractor.ts
|
|
1744
|
-
var
|
|
1768
|
+
var import_shared44 = require("@xeno-js/shared");
|
|
1745
1769
|
var HttpCookieExtractor = class {
|
|
1746
1770
|
extract(cookie) {
|
|
1747
|
-
if (!
|
|
1748
|
-
const cookies =
|
|
1771
|
+
if (!import_shared44.Guards.isDefined(cookie.header)) return void 0;
|
|
1772
|
+
const cookies = import_shared44.HttpHelper.parseCookies(cookie.header);
|
|
1749
1773
|
return cookies[cookie.name];
|
|
1750
1774
|
}
|
|
1751
1775
|
};
|
|
1752
1776
|
|
|
1753
1777
|
// src/infrastructure/services/extractors/http-header.extractor.ts
|
|
1754
|
-
var
|
|
1778
|
+
var import_shared45 = require("@xeno-js/shared");
|
|
1755
1779
|
var HttpHeaderExtractor = class {
|
|
1756
1780
|
/**
|
|
1757
1781
|
* @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.
|
|
@@ -1773,10 +1797,10 @@ var HttpHeaderExtractor = class {
|
|
|
1773
1797
|
_cookieName;
|
|
1774
1798
|
_csrfCookieHeader;
|
|
1775
1799
|
extract(headers) {
|
|
1776
|
-
const correlationId =
|
|
1777
|
-
const requestId =
|
|
1800
|
+
const correlationId = import_shared45.GuidHelper.parse(headers.get("x-correlation-id") ?? void 0);
|
|
1801
|
+
const requestId = import_shared45.GuidHelper.parse(headers.get("x-request-id") ?? void 0);
|
|
1778
1802
|
const clientIp = headers.get(this._trustedIp?.toLowerCase() ?? "x-forwarded-for") ?? headers.get("x-real-ip") ?? void 0;
|
|
1779
|
-
const spanId =
|
|
1803
|
+
const spanId = import_shared45.GuidHelper.parse(headers.get("x-span-id") ?? void 0);
|
|
1780
1804
|
const parentSpanId = headers.get("x-parent-span-id") ?? void 0;
|
|
1781
1805
|
const acceptHeader = headers.get("accept") ?? void 0;
|
|
1782
1806
|
const contentTypeHeader = headers.get("content-type") ?? void 0;
|
|
@@ -1793,10 +1817,10 @@ var HttpHeaderExtractor = class {
|
|
|
1793
1817
|
name: this._cookieName
|
|
1794
1818
|
});
|
|
1795
1819
|
const origin = headers.get("origin") ?? void 0;
|
|
1796
|
-
const cleanOrigin =
|
|
1820
|
+
const cleanOrigin = import_shared45.HttpHelper.sanitizeOriginUrl(origin);
|
|
1797
1821
|
const referer = headers.get("referer") ?? void 0;
|
|
1798
|
-
const cleanReferer =
|
|
1799
|
-
const formatIndicator =
|
|
1822
|
+
const cleanReferer = import_shared45.HttpHelper.sanitizeOriginUrl(referer);
|
|
1823
|
+
const formatIndicator = import_shared45.HttpHelper.resolveFormatIndicator(acceptHeader, contentTypeHeader);
|
|
1800
1824
|
const metadata = {
|
|
1801
1825
|
correlationId,
|
|
1802
1826
|
requestId,
|
|
@@ -1813,17 +1837,17 @@ var HttpHeaderExtractor = class {
|
|
|
1813
1837
|
referer: cleanReferer,
|
|
1814
1838
|
sequence: {
|
|
1815
1839
|
sequenceId,
|
|
1816
|
-
position:
|
|
1817
|
-
size:
|
|
1840
|
+
position: import_shared45.Guards.isDefined(position) ? import_shared45.MathHelper.toNumber(position) : void 0,
|
|
1841
|
+
size: import_shared45.Guards.isDefined(size) ? import_shared45.MathHelper.toNumber(size) : void 0
|
|
1818
1842
|
},
|
|
1819
|
-
expiration:
|
|
1843
|
+
expiration: import_shared45.Guards.isDefined(expiration) ? import_shared45.MathHelper.toNumber(expiration) : void 0
|
|
1820
1844
|
};
|
|
1821
1845
|
return metadata;
|
|
1822
1846
|
}
|
|
1823
1847
|
};
|
|
1824
1848
|
|
|
1825
1849
|
// src/infrastructure/services/resolver/client-ip.resolver.ts
|
|
1826
|
-
var
|
|
1850
|
+
var import_shared46 = require("@xeno-js/shared");
|
|
1827
1851
|
var ClientIpResolver = class {
|
|
1828
1852
|
constructor(_trustedProxies = []) {
|
|
1829
1853
|
this._trustedProxies = _trustedProxies;
|
|
@@ -1831,11 +1855,11 @@ var ClientIpResolver = class {
|
|
|
1831
1855
|
_trustedProxies;
|
|
1832
1856
|
resolve(req, clientIp) {
|
|
1833
1857
|
const socketIp = req.socket?.remoteAddress;
|
|
1834
|
-
if (!
|
|
1835
|
-
return !
|
|
1858
|
+
if (!import_shared46.Guards.isDefined(socketIp))
|
|
1859
|
+
return !import_shared46.Guards.isNullOrEmpty(clientIp) ? clientIp.split(",")[0].trim() : void 0;
|
|
1836
1860
|
const isTrustedProxy = this._trustedProxies.includes(socketIp);
|
|
1837
1861
|
if (!isTrustedProxy) return socketIp;
|
|
1838
|
-
if (
|
|
1862
|
+
if (import_shared46.Guards.isDefined(clientIp)) return clientIp.split(",")[0].trim();
|
|
1839
1863
|
return socketIp;
|
|
1840
1864
|
}
|
|
1841
1865
|
};
|
|
@@ -1843,37 +1867,37 @@ var ClientIpResolver = class {
|
|
|
1843
1867
|
// src/infrastructure/modules/auth.module.ts
|
|
1844
1868
|
var AuthModule = class {
|
|
1845
1869
|
async configure(container, opts) {
|
|
1846
|
-
if (!
|
|
1870
|
+
if (!import_shared47.Guards.isDefined(opts.authService))
|
|
1847
1871
|
throw new Error(
|
|
1848
1872
|
"[AuthModule Error]: An authService instance is required to configure AuthModule."
|
|
1849
1873
|
);
|
|
1850
|
-
if (
|
|
1851
|
-
if (
|
|
1874
|
+
if (import_shared47.Guards.isDefined(opts.cookieHandlerOptions)) {
|
|
1875
|
+
if (import_shared47.Guards.isDefined(opts.cookieHandlerOptions.cookieHandlerCustom)) {
|
|
1852
1876
|
container.addScoped(
|
|
1853
|
-
|
|
1877
|
+
import_shared48.TOKENS.COOKIE_HANDLER,
|
|
1854
1878
|
(c) => opts.cookieHandlerOptions.cookieHandlerCustom(c)
|
|
1855
1879
|
);
|
|
1856
|
-
} else if (
|
|
1880
|
+
} else if (import_shared47.Guards.isDefined(opts.cookieHandlerOptions.enableDefault) && opts.cookieHandlerOptions.enableDefault.enable) {
|
|
1857
1881
|
container.addScoped(
|
|
1858
|
-
|
|
1882
|
+
import_shared48.TOKENS.COOKIE_HANDLER,
|
|
1859
1883
|
(c) => new CookieHandler(
|
|
1860
|
-
c.resolve(
|
|
1861
|
-
c.resolve(
|
|
1884
|
+
c.resolve(import_shared48.TOKENS.NETWORK_CONTEXT_ACCESSOR),
|
|
1885
|
+
c.resolve(import_shared48.TOKENS.CONFIGURATION_SERVICE),
|
|
1862
1886
|
opts.cookieHandlerOptions.enableDefault?.options
|
|
1863
1887
|
)
|
|
1864
1888
|
);
|
|
1865
1889
|
}
|
|
1866
1890
|
}
|
|
1867
1891
|
this.getExtractor(opts, container);
|
|
1868
|
-
container.addScoped(
|
|
1869
|
-
container.addScoped(
|
|
1892
|
+
container.addScoped(import_shared48.TOKENS.AUTH_SERVICE, (c) => opts.authService(c));
|
|
1893
|
+
container.addScoped(import_shared48.TOKENS.BASE_AUTH_SERVICE, (c) => c.resolve(import_shared48.TOKENS.AUTH_SERVICE));
|
|
1870
1894
|
}
|
|
1871
1895
|
getExtractor(opts, container) {
|
|
1872
|
-
if (
|
|
1873
|
-
container.addSingleton(
|
|
1896
|
+
if (import_shared47.Guards.isDefined(opts.tokenExtractor)) {
|
|
1897
|
+
container.addSingleton(import_shared48.TOKENS.TOKEN_SERVICE_EXTRACTOR, (c) => opts.tokenExtractor(c));
|
|
1874
1898
|
} else {
|
|
1875
1899
|
container.addSingleton(
|
|
1876
|
-
|
|
1900
|
+
import_shared48.TOKENS.TOKEN_SERVICE_EXTRACTOR,
|
|
1877
1901
|
() => new BearerTokenExtractor(opts.defaultCookieName ?? "sb-access-token")
|
|
1878
1902
|
);
|
|
1879
1903
|
}
|
|
@@ -1881,10 +1905,10 @@ var AuthModule = class {
|
|
|
1881
1905
|
};
|
|
1882
1906
|
|
|
1883
1907
|
// src/infrastructure/modules/cache.module.ts
|
|
1884
|
-
var
|
|
1908
|
+
var import_shared58 = require("@xeno-js/shared");
|
|
1885
1909
|
|
|
1886
1910
|
// src/infrastructure/cache/inmemory.cache.ts
|
|
1887
|
-
var
|
|
1911
|
+
var import_shared49 = require("@xeno-js/shared");
|
|
1888
1912
|
var InMemoryCache = class {
|
|
1889
1913
|
/**
|
|
1890
1914
|
* @description Constructs a new instance of the InMemoryCache class, which initializes an internal Map to store cached values. The Map is used to associate cache keys with their corresponding values and expiration times, allowing for efficient retrieval and management of cached data. The constructor does not take any parameters, as the in-memory cache is self-contained and does not require external dependencies or configuration.
|
|
@@ -1906,22 +1930,22 @@ var InMemoryCache = class {
|
|
|
1906
1930
|
_cache;
|
|
1907
1931
|
_cleanupInterval;
|
|
1908
1932
|
_isNodeTimeout(timer) {
|
|
1909
|
-
return
|
|
1933
|
+
return import_shared49.Guards.isDefined(timer) && import_shared49.Guards.isObject(timer) && import_shared49.Guards.hasMethod(timer, "unref");
|
|
1910
1934
|
}
|
|
1911
1935
|
async get(key) {
|
|
1912
1936
|
const entry = this._cache.get(key);
|
|
1913
|
-
if (!
|
|
1937
|
+
if (!import_shared49.Guards.isDefined(entry)) {
|
|
1914
1938
|
return void 0;
|
|
1915
1939
|
}
|
|
1916
|
-
if (
|
|
1940
|
+
if (import_shared49.Guards.isDefined(entry.expiresAt) && entry.expiresAt < Date.now()) {
|
|
1917
1941
|
this._cache.delete(key);
|
|
1918
1942
|
return void 0;
|
|
1919
1943
|
}
|
|
1920
1944
|
return JSON.parse(entry.value);
|
|
1921
1945
|
}
|
|
1922
1946
|
async set(key, value, ttl) {
|
|
1923
|
-
const expiresAt =
|
|
1924
|
-
this._cache.set(key, { value:
|
|
1947
|
+
const expiresAt = import_shared49.Guards.isDefined(ttl) ? Date.now() + ttl * 1e3 : void 0;
|
|
1948
|
+
this._cache.set(key, { value: import_shared49.StringHelper.safeStringify(value), expiresAt });
|
|
1925
1949
|
}
|
|
1926
1950
|
async setIfAbsent(key, value, ttl) {
|
|
1927
1951
|
if (this._cache.has(key)) {
|
|
@@ -1935,10 +1959,10 @@ var InMemoryCache = class {
|
|
|
1935
1959
|
}
|
|
1936
1960
|
async has(key) {
|
|
1937
1961
|
const entry = this._cache.get(key);
|
|
1938
|
-
if (!
|
|
1962
|
+
if (!import_shared49.Guards.isDefined(entry)) {
|
|
1939
1963
|
return false;
|
|
1940
1964
|
}
|
|
1941
|
-
if (
|
|
1965
|
+
if (import_shared49.Guards.isDefined(entry.expiresAt) && entry.expiresAt < Date.now()) {
|
|
1942
1966
|
this._cache.delete(key);
|
|
1943
1967
|
return false;
|
|
1944
1968
|
}
|
|
@@ -1950,23 +1974,23 @@ var InMemoryCache = class {
|
|
|
1950
1974
|
async increment(key, ttlSeconds) {
|
|
1951
1975
|
const entry = this._cache.get(key);
|
|
1952
1976
|
const now = Date.now();
|
|
1953
|
-
if (
|
|
1954
|
-
const nextValue = Number(
|
|
1977
|
+
if (import_shared49.Guards.isDefined(entry) && (!import_shared49.Guards.isDefined(entry.expiresAt) || entry.expiresAt > now)) {
|
|
1978
|
+
const nextValue = Number(import_shared49.StringHelper.safeParse(entry.value)) + 1;
|
|
1955
1979
|
this._cache.set(key, {
|
|
1956
|
-
value:
|
|
1980
|
+
value: import_shared49.StringHelper.safeStringify(nextValue),
|
|
1957
1981
|
expiresAt: entry.expiresAt
|
|
1958
1982
|
});
|
|
1959
1983
|
return nextValue;
|
|
1960
1984
|
}
|
|
1961
|
-
const ttl = !
|
|
1985
|
+
const ttl = !import_shared49.Guards.isNullOrEmpty(ttlSeconds) ? Number(ttlSeconds) : 60;
|
|
1962
1986
|
const expiresAt = now + ttl * 1e3;
|
|
1963
|
-
this._cache.set(key, { value:
|
|
1987
|
+
this._cache.set(key, { value: import_shared49.StringHelper.safeStringify(1), expiresAt });
|
|
1964
1988
|
return 1;
|
|
1965
1989
|
}
|
|
1966
1990
|
evictExpired() {
|
|
1967
1991
|
const now = Date.now();
|
|
1968
1992
|
for (const [key, entry] of this._cache.entries()) {
|
|
1969
|
-
if (!
|
|
1993
|
+
if (!import_shared49.Guards.isDefined(entry.expiresAt) || entry.expiresAt > now) {
|
|
1970
1994
|
this._cache.delete(key);
|
|
1971
1995
|
}
|
|
1972
1996
|
}
|
|
@@ -1988,7 +2012,7 @@ var InMemoryCache = class {
|
|
|
1988
2012
|
};
|
|
1989
2013
|
|
|
1990
2014
|
// src/infrastructure/cache/key-builder.cache.ts
|
|
1991
|
-
var
|
|
2015
|
+
var import_shared50 = require("@xeno-js/shared");
|
|
1992
2016
|
var CacheKeyBuilder = class {
|
|
1993
2017
|
/**
|
|
1994
2018
|
* @description Constructs a new instance of the CacheKeyBuilder class, which requires an IIdentityAccessor to access the current user's identity. The constructor initializes the dependency needed for building contextual cache keys based on the user's identity, enabling tenant-specific caching behavior in multi-tenant applications.
|
|
@@ -2005,14 +2029,14 @@ var CacheKeyBuilder = class {
|
|
|
2005
2029
|
_identityAccessor;
|
|
2006
2030
|
buildContextualKey(key) {
|
|
2007
2031
|
const identity = this._identityAccessor.getIdentity();
|
|
2008
|
-
if (
|
|
2032
|
+
if (import_shared50.Guards.isDefined(identity) && !import_shared50.Guards.isNullOrEmpty(identity.tenantId)) {
|
|
2009
2033
|
return `tenant:${identity.tenantId}:${key}`;
|
|
2010
2034
|
}
|
|
2011
2035
|
return `${key}:public`;
|
|
2012
2036
|
}
|
|
2013
2037
|
buildUserScopedKey(key) {
|
|
2014
2038
|
const identity = this._identityAccessor.getIdentity();
|
|
2015
|
-
if (
|
|
2039
|
+
if (import_shared50.Guards.isDefined(identity) && !import_shared50.Guards.isNullOrEmpty(identity.userId)) {
|
|
2016
2040
|
return this.buildContextualKey(`user:${identity.userId}:${key}`);
|
|
2017
2041
|
}
|
|
2018
2042
|
return this.buildContextualKey(key);
|
|
@@ -2020,7 +2044,7 @@ var CacheKeyBuilder = class {
|
|
|
2020
2044
|
};
|
|
2021
2045
|
|
|
2022
2046
|
// src/infrastructure/cache/rate-limit-key-builder.cache.ts
|
|
2023
|
-
var
|
|
2047
|
+
var import_shared51 = require("@xeno-js/shared");
|
|
2024
2048
|
var RateLimitKeyBuilder = class {
|
|
2025
2049
|
constructor(_contextAccessor) {
|
|
2026
2050
|
this._contextAccessor = _contextAccessor;
|
|
@@ -2031,19 +2055,19 @@ var RateLimitKeyBuilder = class {
|
|
|
2031
2055
|
const tenantId = ctx?.identity?.tenantId;
|
|
2032
2056
|
const userId = ctx?.identity?.userId;
|
|
2033
2057
|
const clientIp = ctx?.network?.clientIp;
|
|
2034
|
-
if (!
|
|
2058
|
+
if (!import_shared51.Guards.isNullOrEmpty(tenantId) && !import_shared51.Guards.isNullOrEmpty(userId))
|
|
2035
2059
|
return `ratelimit:tenant:${tenantId}:user:${userId}:${resource}`;
|
|
2036
|
-
if (!
|
|
2060
|
+
if (!import_shared51.Guards.isNullOrEmpty(tenantId) && !import_shared51.Guards.isNullOrEmpty(clientIp))
|
|
2037
2061
|
return `ratelimit:tenant:${tenantId}:ip:${clientIp}:${resource}`;
|
|
2038
|
-
if (!
|
|
2039
|
-
if (!
|
|
2062
|
+
if (!import_shared51.Guards.isNullOrEmpty(userId)) return `ratelimit:user:${userId}:${resource}`;
|
|
2063
|
+
if (!import_shared51.Guards.isNullOrEmpty(clientIp)) return `ratelimit:ip:${clientIp}:${resource}`;
|
|
2040
2064
|
return void 0;
|
|
2041
2065
|
}
|
|
2042
2066
|
};
|
|
2043
2067
|
|
|
2044
2068
|
// src/infrastructure/modules/utils/auth.utils.ts
|
|
2045
|
-
var import_shared51 = require("@xeno-js/shared");
|
|
2046
2069
|
var import_shared52 = require("@xeno-js/shared");
|
|
2070
|
+
var import_shared53 = require("@xeno-js/shared");
|
|
2047
2071
|
var AuthUtils = Object.freeze({
|
|
2048
2072
|
/**
|
|
2049
2073
|
* @description Checks if the provided authorization configuration requires any authorization strategies.
|
|
@@ -2057,28 +2081,28 @@ var AuthUtils = Object.freeze({
|
|
|
2057
2081
|
*/
|
|
2058
2082
|
async addAuthZ(container, opts) {
|
|
2059
2083
|
const strategies = [];
|
|
2060
|
-
if (
|
|
2084
|
+
if (import_shared52.Guards.isDefined(opts.policies)) {
|
|
2061
2085
|
const policyRegistry = opts.policies;
|
|
2062
2086
|
const registryInstance = new PolicyRegistry();
|
|
2063
|
-
const ctxAccessor = container.resolve(
|
|
2087
|
+
const ctxAccessor = container.resolve(import_shared53.TOKENS.CONTEXT_ACCESSOR);
|
|
2064
2088
|
const Policies = /* @__PURE__ */ new Set();
|
|
2065
|
-
if (
|
|
2066
|
-
const superadminRoles =
|
|
2089
|
+
if (import_shared52.Guards.isDefined(opts.superadmin)) {
|
|
2090
|
+
const superadminRoles = import_shared52.Guards.isArray(opts.superadmin) ? opts.superadmin : [opts.superadmin];
|
|
2067
2091
|
registryInstance.setSuperadminRoles(superadminRoles);
|
|
2068
2092
|
}
|
|
2069
2093
|
for (const [intent, policy] of Object.entries(policyRegistry)) {
|
|
2070
2094
|
const intentLower = intent.toLowerCase();
|
|
2071
2095
|
registryInstance.addPolicy(intentLower, policy);
|
|
2072
|
-
if (!
|
|
2096
|
+
if (!import_shared52.Guards.isNullOrEmpty(policy.roles)) {
|
|
2073
2097
|
Policies.add("roles");
|
|
2074
2098
|
}
|
|
2075
|
-
if (!
|
|
2099
|
+
if (!import_shared52.Guards.isNullOrEmpty(policy.permissions)) {
|
|
2076
2100
|
Policies.add("permissions");
|
|
2077
2101
|
}
|
|
2078
|
-
if (!
|
|
2102
|
+
if (!import_shared52.Guards.isNullOrEmpty(policy.userId)) {
|
|
2079
2103
|
Policies.add("userId");
|
|
2080
2104
|
}
|
|
2081
|
-
if (!
|
|
2105
|
+
if (!import_shared52.Guards.isNullOrEmpty(policy.tenantId)) {
|
|
2082
2106
|
Policies.add("tenantId");
|
|
2083
2107
|
}
|
|
2084
2108
|
}
|
|
@@ -2095,10 +2119,10 @@ var AuthUtils = Object.freeze({
|
|
|
2095
2119
|
strategies.push(new TenantAuthorizationStrategy(registryInstance, ctxAccessor));
|
|
2096
2120
|
}
|
|
2097
2121
|
}
|
|
2098
|
-
if (!
|
|
2122
|
+
if (!import_shared52.Guards.isNullOrEmpty(opts.customAuthorizationStrategy)) {
|
|
2099
2123
|
const customStrategies = opts.customAuthorizationStrategy;
|
|
2100
2124
|
customStrategies.forEach((strategyToken) => {
|
|
2101
|
-
if (
|
|
2125
|
+
if (import_shared52.Guards.isDefined(strategyToken)) {
|
|
2102
2126
|
strategies.push(strategyToken(container));
|
|
2103
2127
|
}
|
|
2104
2128
|
});
|
|
@@ -2108,7 +2132,7 @@ var AuthUtils = Object.freeze({
|
|
|
2108
2132
|
});
|
|
2109
2133
|
|
|
2110
2134
|
// src/infrastructure/modules/utils/cache.utils.ts
|
|
2111
|
-
var
|
|
2135
|
+
var import_shared54 = require("@xeno-js/shared");
|
|
2112
2136
|
var CacheUtils = Object.freeze({
|
|
2113
2137
|
/**
|
|
2114
2138
|
* @description Checks if the provided cache configuration requires any cache strategies.
|
|
@@ -2122,16 +2146,16 @@ var CacheUtils = Object.freeze({
|
|
|
2122
2146
|
* @link https://github.com/xeno-js/xeno-js
|
|
2123
2147
|
*/
|
|
2124
2148
|
async addCache(container) {
|
|
2125
|
-
container.addSingleton(
|
|
2149
|
+
container.addSingleton(import_shared54.TOKENS.CACHE, () => new InMemoryCache());
|
|
2126
2150
|
}
|
|
2127
2151
|
});
|
|
2128
2152
|
|
|
2129
2153
|
// src/infrastructure/modules/utils/logger.utils.ts
|
|
2130
|
-
var import_shared55 = require("@xeno-js/shared");
|
|
2131
2154
|
var import_shared56 = require("@xeno-js/shared");
|
|
2155
|
+
var import_shared57 = require("@xeno-js/shared");
|
|
2132
2156
|
|
|
2133
2157
|
// src/infrastructure/loggers/console.logger.ts
|
|
2134
|
-
var
|
|
2158
|
+
var import_shared55 = require("@xeno-js/shared");
|
|
2135
2159
|
var ConsoleLogger = class {
|
|
2136
2160
|
/**
|
|
2137
2161
|
* 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.
|
|
@@ -2143,22 +2167,22 @@ var ConsoleLogger = class {
|
|
|
2143
2167
|
* @since 2025-09-30
|
|
2144
2168
|
* @link https://github.com/xeno-js/xeno-js
|
|
2145
2169
|
*/
|
|
2146
|
-
constructor(_minLevel =
|
|
2170
|
+
constructor(_minLevel = import_shared55.LOG_LEVEL.DEBUG) {
|
|
2147
2171
|
this._minLevel = _minLevel;
|
|
2148
2172
|
}
|
|
2149
2173
|
_minLevel;
|
|
2150
2174
|
track(level, message, context, error = void 0) {
|
|
2151
2175
|
if (level < this._minLevel) return;
|
|
2152
2176
|
const logMessage = `[${level}] ${message}`;
|
|
2153
|
-
const payload =
|
|
2177
|
+
const payload = import_shared55.Guards.isDefined(error) ? { ...context, error } : context;
|
|
2154
2178
|
switch (level) {
|
|
2155
|
-
case
|
|
2179
|
+
case import_shared55.LOG_LEVEL.ERROR:
|
|
2156
2180
|
console.error(logMessage, payload ?? {});
|
|
2157
2181
|
break;
|
|
2158
|
-
case
|
|
2182
|
+
case import_shared55.LOG_LEVEL.WARN:
|
|
2159
2183
|
console.warn(logMessage, payload ?? {});
|
|
2160
2184
|
break;
|
|
2161
|
-
case
|
|
2185
|
+
case import_shared55.LOG_LEVEL.DEBUG:
|
|
2162
2186
|
console.debug(logMessage, payload ?? {});
|
|
2163
2187
|
break;
|
|
2164
2188
|
default:
|
|
@@ -2184,15 +2208,15 @@ var LoggerUtils2 = Object.freeze({
|
|
|
2184
2208
|
async addLogger(container, opts) {
|
|
2185
2209
|
const loggerDependencies = [];
|
|
2186
2210
|
if (opts.console) loggerDependencies.push(new ConsoleLogger(opts?.level));
|
|
2187
|
-
if (!
|
|
2211
|
+
if (!import_shared56.Guards.isNullOrEmpty(opts.customLoggers)) {
|
|
2188
2212
|
const customLoggers = opts.customLoggers;
|
|
2189
2213
|
for (const logger of customLoggers) {
|
|
2190
2214
|
loggerDependencies.push(logger(container));
|
|
2191
2215
|
}
|
|
2192
2216
|
}
|
|
2193
|
-
container.addSingleton(
|
|
2194
|
-
const context = c.resolve(
|
|
2195
|
-
return new BaseLogger(context, opts?.level ??
|
|
2217
|
+
container.addSingleton(import_shared57.TOKENS.LOGGER, (c) => {
|
|
2218
|
+
const context = c.resolve(import_shared57.TOKENS.CONTEXT_ACCESSOR);
|
|
2219
|
+
return new BaseLogger(context, opts?.level ?? import_shared56.LOG_LEVEL.DEBUG, loggerDependencies);
|
|
2196
2220
|
});
|
|
2197
2221
|
}
|
|
2198
2222
|
});
|
|
@@ -2201,24 +2225,24 @@ var LoggerUtils2 = Object.freeze({
|
|
|
2201
2225
|
var CacheModule = class {
|
|
2202
2226
|
async configure(container, opts = { inMemory: true }) {
|
|
2203
2227
|
container.addSingleton(
|
|
2204
|
-
|
|
2205
|
-
(c) => new CacheKeyBuilder(c.resolve(
|
|
2228
|
+
import_shared58.TOKENS.CACHE_KEY_BUILDER,
|
|
2229
|
+
(c) => new CacheKeyBuilder(c.resolve(import_shared58.TOKENS.IDENTITY_ACCESSOR))
|
|
2206
2230
|
);
|
|
2207
|
-
if (opts.inMemory &&
|
|
2231
|
+
if (opts.inMemory && import_shared58.Guards.isDefined(opts.provider))
|
|
2208
2232
|
throw new Error("Cannot use both in memory and provider cache");
|
|
2209
2233
|
else if (opts.inMemory) {
|
|
2210
2234
|
await CacheUtils.addCache(container);
|
|
2211
|
-
} else if (
|
|
2212
|
-
container.addSingleton(
|
|
2235
|
+
} else if (import_shared58.Guards.isDefined(opts.provider)) {
|
|
2236
|
+
container.addSingleton(import_shared58.TOKENS.CACHE, (c) => opts.provider(c));
|
|
2213
2237
|
} else throw new Error("No cache provider specified");
|
|
2214
2238
|
}
|
|
2215
2239
|
};
|
|
2216
2240
|
|
|
2217
2241
|
// src/infrastructure/modules/context.module.ts
|
|
2218
|
-
var
|
|
2242
|
+
var import_shared64 = require("@xeno-js/shared");
|
|
2219
2243
|
|
|
2220
2244
|
// src/infrastructure/events/event.dispatcher.ts
|
|
2221
|
-
var
|
|
2245
|
+
var import_shared59 = require("@xeno-js/shared");
|
|
2222
2246
|
var EventDispatcher = class {
|
|
2223
2247
|
_handlers = /* @__PURE__ */ new Map();
|
|
2224
2248
|
subscribe(eventType, handler) {
|
|
@@ -2227,19 +2251,19 @@ var EventDispatcher = class {
|
|
|
2227
2251
|
this._handlers.set(eventType, handlers);
|
|
2228
2252
|
}
|
|
2229
2253
|
async publish(event, signal) {
|
|
2230
|
-
|
|
2254
|
+
import_shared59.AppError.throwIfAborted(signal, "EventDispatcher.publish");
|
|
2231
2255
|
const handlers = this._handlers.get(event.eventType);
|
|
2232
|
-
if (
|
|
2256
|
+
if (import_shared59.Guards.isNullOrEmpty(handlers)) return import_shared59.Result.ok();
|
|
2233
2257
|
try {
|
|
2234
2258
|
for (const handler of handlers) {
|
|
2235
2259
|
const result = await handler.handle(event, signal);
|
|
2236
2260
|
if (!result.isOk()) {
|
|
2237
|
-
return
|
|
2261
|
+
return import_shared59.Result.fail(result.getErrorOrThrow());
|
|
2238
2262
|
}
|
|
2239
2263
|
}
|
|
2240
|
-
return
|
|
2264
|
+
return import_shared59.Result.ok();
|
|
2241
2265
|
} catch (error) {
|
|
2242
|
-
return
|
|
2266
|
+
return import_shared59.Result.fail(import_shared59.AppError.internalServerError("EventDispatcher", error));
|
|
2243
2267
|
}
|
|
2244
2268
|
}
|
|
2245
2269
|
};
|
|
@@ -2279,7 +2303,7 @@ var ServiceScopeFactory = class {
|
|
|
2279
2303
|
};
|
|
2280
2304
|
|
|
2281
2305
|
// src/infrastructure/factories/user-context.factory.ts
|
|
2282
|
-
var
|
|
2306
|
+
var import_shared61 = require("@xeno-js/shared");
|
|
2283
2307
|
var UserContextFactory = class {
|
|
2284
2308
|
/**
|
|
2285
2309
|
* @description Constructs an instance of UserContextFactory.
|
|
@@ -2300,7 +2324,7 @@ var UserContextFactory = class {
|
|
|
2300
2324
|
tenantId: void 0
|
|
2301
2325
|
};
|
|
2302
2326
|
const identity = this._identityFactory.getIdentity();
|
|
2303
|
-
if (
|
|
2327
|
+
if (import_shared61.Guards.isDefined(identity)) {
|
|
2304
2328
|
output.userId = identity.userId;
|
|
2305
2329
|
output.tenantId = identity.tenantId;
|
|
2306
2330
|
}
|
|
@@ -2309,7 +2333,7 @@ var UserContextFactory = class {
|
|
|
2309
2333
|
};
|
|
2310
2334
|
|
|
2311
2335
|
// src/infrastructure/http/adapter.http.ts
|
|
2312
|
-
var
|
|
2336
|
+
var import_shared62 = require("@xeno-js/shared");
|
|
2313
2337
|
var HttpAdapter = class {
|
|
2314
2338
|
constructor(_urlFactory) {
|
|
2315
2339
|
this._urlFactory = _urlFactory;
|
|
@@ -2322,34 +2346,34 @@ var HttpAdapter = class {
|
|
|
2322
2346
|
*/
|
|
2323
2347
|
adapt(req) {
|
|
2324
2348
|
const baseUrl = this._urlFactory.create(req.headers);
|
|
2325
|
-
const safeUrl =
|
|
2349
|
+
const safeUrl = import_shared62.HttpHelper.parseSafeUrl(req.url, baseUrl);
|
|
2326
2350
|
const method = req.method.toUpperCase();
|
|
2327
2351
|
const init = {
|
|
2328
2352
|
method,
|
|
2329
2353
|
headers: req.headers
|
|
2330
2354
|
};
|
|
2331
|
-
const parsedBody =
|
|
2332
|
-
if (
|
|
2355
|
+
const parsedBody = import_shared62.HttpHelper.parseBody(method, req.body);
|
|
2356
|
+
if (import_shared62.Guards.isDefined(parsedBody)) {
|
|
2333
2357
|
init.body = parsedBody;
|
|
2334
2358
|
init.duplex = "half";
|
|
2335
2359
|
}
|
|
2336
2360
|
const xenoRequest = new Request(safeUrl.toString(), init);
|
|
2337
2361
|
xenoRequest.path = safeUrl.pathname;
|
|
2338
2362
|
xenoRequest.socket = req.socket;
|
|
2339
|
-
xenoRequest.query = req.query ??
|
|
2363
|
+
xenoRequest.query = req.query ?? import_shared62.HttpRouteParamHelper.extractQueryParams(req.url);
|
|
2340
2364
|
return xenoRequest;
|
|
2341
2365
|
}
|
|
2342
2366
|
};
|
|
2343
2367
|
|
|
2344
2368
|
// src/infrastructure/http/url-builder.http.ts
|
|
2345
|
-
var
|
|
2369
|
+
var import_shared63 = require("@xeno-js/shared");
|
|
2346
2370
|
var UrlBuilder = class {
|
|
2347
2371
|
create(headers) {
|
|
2348
2372
|
const forwardedProto = headers.get("x-forwarded-proto");
|
|
2349
|
-
const protocol =
|
|
2373
|
+
const protocol = import_shared63.Guards.isDefined(forwardedProto) ? forwardedProto.split(",")[0].trim() : "http";
|
|
2350
2374
|
const forwardedHost = headers.get("x-forwarded-host");
|
|
2351
2375
|
const hostHeader = headers.get("host");
|
|
2352
|
-
const host =
|
|
2376
|
+
const host = import_shared63.Guards.isDefined(forwardedHost) ? forwardedHost.split(",")[0].trim() : hostHeader ?? "localhost";
|
|
2353
2377
|
return `${protocol}://${host}`;
|
|
2354
2378
|
}
|
|
2355
2379
|
};
|
|
@@ -2373,24 +2397,24 @@ var CreateServicesProxy = class {
|
|
|
2373
2397
|
// src/infrastructure/modules/context.module.ts
|
|
2374
2398
|
var ContextModule = class {
|
|
2375
2399
|
async configure(container, opts) {
|
|
2376
|
-
if (container.isRegistered(
|
|
2400
|
+
if (container.isRegistered(import_shared64.TOKENS.REQUEST_CONTEXT)) return;
|
|
2377
2401
|
const requestContext = await this._getRequestContext(container, opts);
|
|
2378
|
-
container.addSingleton(
|
|
2379
|
-
container.addSingleton(
|
|
2380
|
-
container.addSingleton(
|
|
2381
|
-
container.addSingleton(
|
|
2382
|
-
container.addSingleton(
|
|
2383
|
-
container.addSingleton(
|
|
2384
|
-
container.addSingleton(
|
|
2402
|
+
container.addSingleton(import_shared64.TOKENS.REQUEST_CONTEXT, () => requestContext);
|
|
2403
|
+
container.addSingleton(import_shared64.TOKENS.CONTEXT_ACCESSOR, () => requestContext);
|
|
2404
|
+
container.addSingleton(import_shared64.TOKENS.IDENTITY_ACCESSOR, () => requestContext);
|
|
2405
|
+
container.addSingleton(import_shared64.TOKENS.SERVICE_SCOPE_ACCESSOR, () => requestContext);
|
|
2406
|
+
container.addSingleton(import_shared64.TOKENS.NETWORK_CONTEXT_ACCESSOR, () => requestContext);
|
|
2407
|
+
container.addSingleton(import_shared64.TOKENS.TRACING_CONTEXT_ACCESSOR, () => requestContext);
|
|
2408
|
+
container.addSingleton(import_shared64.TOKENS.USER_CONTEXT_FACTORY, () => {
|
|
2385
2409
|
return new UserContextFactory(requestContext);
|
|
2386
2410
|
});
|
|
2387
2411
|
const serviceProxy = new CreateServicesProxy();
|
|
2388
|
-
container.addSingleton(
|
|
2389
|
-
container.addSingleton(
|
|
2390
|
-
container.addSingleton(
|
|
2412
|
+
container.addSingleton(import_shared64.TOKENS.SERVICE_PROXY, () => serviceProxy);
|
|
2413
|
+
container.addSingleton(import_shared64.TOKENS.HTTP_ADAPTER, () => new HttpAdapter(new UrlBuilder()));
|
|
2414
|
+
container.addSingleton(import_shared64.TOKENS.EVENT_DISPATCHER, () => new EventDispatcher());
|
|
2391
2415
|
}
|
|
2392
2416
|
async _getRequestContext(container, opts) {
|
|
2393
|
-
if (
|
|
2417
|
+
if (import_shared64.Guards.isDefined(opts)) return opts;
|
|
2394
2418
|
const { NodeRequestContextFactory: NodeRequestContextFactory2 } = await Promise.resolve().then(() => (init_request_context_factory(), request_context_factory_exports));
|
|
2395
2419
|
return new NodeRequestContextFactory2(
|
|
2396
2420
|
new ServiceScopeFactory(container)
|
|
@@ -2399,11 +2423,11 @@ var ContextModule = class {
|
|
|
2399
2423
|
};
|
|
2400
2424
|
|
|
2401
2425
|
// src/infrastructure/modules/cqrs.module.ts
|
|
2402
|
-
var import_shared67 = require("@xeno-js/shared");
|
|
2403
2426
|
var import_shared68 = require("@xeno-js/shared");
|
|
2427
|
+
var import_shared69 = require("@xeno-js/shared");
|
|
2404
2428
|
|
|
2405
2429
|
// src/application/cqrs/pipelines/cache-invalidation.pipeline.ts
|
|
2406
|
-
var
|
|
2430
|
+
var import_shared65 = require("@xeno-js/shared");
|
|
2407
2431
|
var CommandCacheInvalidationBehavior = class {
|
|
2408
2432
|
constructor(_cacheService, _logger) {
|
|
2409
2433
|
this._cacheService = _cacheService;
|
|
@@ -2413,16 +2437,16 @@ var CommandCacheInvalidationBehavior = class {
|
|
|
2413
2437
|
_logger;
|
|
2414
2438
|
async handle(request, next) {
|
|
2415
2439
|
const result = await next();
|
|
2416
|
-
if (result.isOk() &&
|
|
2440
|
+
if (result.isOk() && import_shared65.Guards.isDefined(request.cacheInvalidation)) {
|
|
2417
2441
|
try {
|
|
2418
2442
|
const { keys, patterns } = request.cacheInvalidation;
|
|
2419
|
-
if (
|
|
2443
|
+
if (import_shared65.Guards.isArray(keys)) {
|
|
2420
2444
|
for (const key of keys) {
|
|
2421
2445
|
await this._cacheService.remove(key);
|
|
2422
2446
|
this._logger.debug(`[Cache Invalidation] Removed key: ${key}`);
|
|
2423
2447
|
}
|
|
2424
2448
|
}
|
|
2425
|
-
if (
|
|
2449
|
+
if (import_shared65.Guards.isArray(patterns) && import_shared65.Guards.hasMethod(this._cacheService, "removePattern")) {
|
|
2426
2450
|
for (const pattern of patterns) {
|
|
2427
2451
|
await this._cacheService.removePattern(pattern);
|
|
2428
2452
|
this._logger.debug(`[Cache Invalidation] Removed pattern: ${pattern}`);
|
|
@@ -2439,7 +2463,7 @@ var CommandCacheInvalidationBehavior = class {
|
|
|
2439
2463
|
};
|
|
2440
2464
|
|
|
2441
2465
|
// src/infrastructure/idempotency/idempotency-store.ts
|
|
2442
|
-
var
|
|
2466
|
+
var import_shared66 = require("@xeno-js/shared");
|
|
2443
2467
|
var IdempotencyStore = class {
|
|
2444
2468
|
/**
|
|
2445
2469
|
* @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.
|
|
@@ -2461,54 +2485,63 @@ var IdempotencyStore = class {
|
|
|
2461
2485
|
async acquireLock(requestId, ttlSeconds) {
|
|
2462
2486
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${requestId}`);
|
|
2463
2487
|
return await this._cache.setIfAbsent(
|
|
2464
|
-
`${
|
|
2465
|
-
|
|
2488
|
+
`${import_shared66.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`,
|
|
2489
|
+
import_shared66.IDEMPOTENCY_CONSTANTS.LOCKED_VALUE,
|
|
2466
2490
|
ttlSeconds
|
|
2467
2491
|
);
|
|
2468
2492
|
}
|
|
2469
2493
|
async hasBeenProcessed(commandId) {
|
|
2470
2494
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2471
|
-
return await this._cache.has(`${
|
|
2495
|
+
return await this._cache.has(`${import_shared66.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
2472
2496
|
}
|
|
2473
2497
|
async markAsProcessed(commandId, payload, ttlSeconds) {
|
|
2474
2498
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2475
2499
|
await this._cache.set(
|
|
2476
|
-
`${
|
|
2500
|
+
`${import_shared66.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`,
|
|
2477
2501
|
payload,
|
|
2478
2502
|
ttlSeconds
|
|
2479
2503
|
);
|
|
2480
2504
|
}
|
|
2481
2505
|
async getPayload(commandId) {
|
|
2482
2506
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2483
|
-
const payload = await this._cache.get(`${
|
|
2507
|
+
const payload = await this._cache.get(`${import_shared66.IDEMPOTENCY_CONSTANTS.PROCESSED_KEY_PREFIX}${key}`);
|
|
2484
2508
|
return payload;
|
|
2485
2509
|
}
|
|
2486
2510
|
async releaseLock(commandId) {
|
|
2487
2511
|
const key = this._cacheKeyBuilder.buildContextualKey(`command:${commandId}`);
|
|
2488
|
-
await this._cache.remove(`${
|
|
2512
|
+
await this._cache.remove(`${import_shared66.IDEMPOTENCY_CONSTANTS.LOCK_KEY_PREFIX}${key}`);
|
|
2489
2513
|
}
|
|
2490
2514
|
};
|
|
2491
2515
|
|
|
2492
2516
|
// src/infrastructure/pipeline_setup/setup.pipeline.ts
|
|
2493
|
-
var
|
|
2517
|
+
var import_shared67 = require("@xeno-js/shared");
|
|
2494
2518
|
var PipelineSetupContext = class {
|
|
2495
2519
|
isQueryCaching = false;
|
|
2496
2520
|
_commandBehaviors = [];
|
|
2497
2521
|
_queryBehaviors = [];
|
|
2498
2522
|
_authzOpts = void 0;
|
|
2499
2523
|
_idempotencyOpts = void 0;
|
|
2524
|
+
_identityEnrichmentOpts = void 0;
|
|
2500
2525
|
set idempotencyOpts(opts) {
|
|
2501
2526
|
this._idempotencyOpts = opts;
|
|
2502
2527
|
}
|
|
2503
2528
|
get idempotencyOpts() {
|
|
2504
|
-
if (
|
|
2529
|
+
if (import_shared67.Guards.isDefined(this._idempotencyOpts)) return Object.freeze(this._idempotencyOpts);
|
|
2505
2530
|
return this._idempotencyOpts;
|
|
2506
2531
|
}
|
|
2532
|
+
set identityEnrichmentOpts(opts) {
|
|
2533
|
+
this._identityEnrichmentOpts = opts;
|
|
2534
|
+
}
|
|
2535
|
+
get identityEnrichmentOpts() {
|
|
2536
|
+
if (import_shared67.Guards.isDefined(this._identityEnrichmentOpts))
|
|
2537
|
+
return Object.freeze(this._identityEnrichmentOpts);
|
|
2538
|
+
return this._identityEnrichmentOpts;
|
|
2539
|
+
}
|
|
2507
2540
|
set authzOpts(opts) {
|
|
2508
2541
|
this._authzOpts = opts;
|
|
2509
2542
|
}
|
|
2510
2543
|
get authzOpts() {
|
|
2511
|
-
if (
|
|
2544
|
+
if (import_shared67.Guards.isDefined(this._authzOpts)) return Object.freeze(this._authzOpts);
|
|
2512
2545
|
return this._authzOpts;
|
|
2513
2546
|
}
|
|
2514
2547
|
addCommon(behavior, order = 50) {
|
|
@@ -2535,12 +2568,12 @@ var PipelineSetupContext = class {
|
|
|
2535
2568
|
// src/infrastructure/modules/cqrs.module.ts
|
|
2536
2569
|
var CqrsModule = class {
|
|
2537
2570
|
async configure(container, opts) {
|
|
2538
|
-
if (!container.isRegistered(
|
|
2539
|
-
await LoggerUtils2.addLogger(container, { level:
|
|
2540
|
-
const logger = container.resolve(
|
|
2541
|
-
if (!container.isRegistered(
|
|
2542
|
-
container.addSingleton(
|
|
2543
|
-
const serviceScopeAccessor = c.resolve(
|
|
2571
|
+
if (!container.isRegistered(import_shared69.TOKENS.LOGGER))
|
|
2572
|
+
await LoggerUtils2.addLogger(container, { level: import_shared68.LOG_LEVEL.INFO, console: true });
|
|
2573
|
+
const logger = container.resolve(import_shared69.TOKENS.LOGGER);
|
|
2574
|
+
if (!container.isRegistered(import_shared69.TOKENS.MEDIATOR)) {
|
|
2575
|
+
container.addSingleton(import_shared69.TOKENS.MEDIATOR, (c) => {
|
|
2576
|
+
const serviceScopeAccessor = c.resolve(import_shared69.TOKENS.SERVICE_SCOPE_ACCESSOR);
|
|
2544
2577
|
return new Mediator(serviceScopeAccessor);
|
|
2545
2578
|
});
|
|
2546
2579
|
}
|
|
@@ -2548,20 +2581,25 @@ var CqrsModule = class {
|
|
|
2548
2581
|
context.addCommon(new ExceptionPipeline(), 0);
|
|
2549
2582
|
context.addCommon(new LoggingPipeline(logger), 10);
|
|
2550
2583
|
for (const plugin of opts.plugins)
|
|
2551
|
-
await plugin(opts.builder, container.resolve(
|
|
2552
|
-
if (
|
|
2584
|
+
await plugin(opts.builder, container.resolve(import_shared69.TOKENS.CONFIGURATION_SERVICE), context);
|
|
2585
|
+
if (import_shared68.Guards.isDefined(context.authzOpts)) {
|
|
2553
2586
|
const authzPipeline = await AuthUtils.addAuthZ(container, context.authzOpts);
|
|
2554
2587
|
context.addCommon(authzPipeline, 40);
|
|
2555
2588
|
}
|
|
2556
|
-
if (
|
|
2589
|
+
if (import_shared68.Guards.isDefined(context.identityEnrichmentOpts)) {
|
|
2590
|
+
const requestContext = container.resolve(import_shared69.TOKENS.REQUEST_CONTEXT);
|
|
2591
|
+
const strategy = context.identityEnrichmentOpts.strategy ?? new NoopIdentityEnrichmentStrategy();
|
|
2592
|
+
context.addCommon(new IdentityEnrichmentPipeline(requestContext, strategy), 20);
|
|
2593
|
+
}
|
|
2594
|
+
if ((import_shared68.Guards.isDefined(context.idempotencyOpts) || context.isQueryCaching) && !container.isRegistered(import_shared69.TOKENS.CACHE)) {
|
|
2557
2595
|
await new CacheModule().configure(container);
|
|
2558
2596
|
}
|
|
2559
|
-
if (
|
|
2597
|
+
if (import_shared68.Guards.isDefined(context.idempotencyOpts)) {
|
|
2560
2598
|
const store = new IdempotencyStore(
|
|
2561
|
-
container.resolve(
|
|
2562
|
-
container.resolve(
|
|
2599
|
+
container.resolve(import_shared69.TOKENS.CACHE),
|
|
2600
|
+
container.resolve(import_shared69.TOKENS.CACHE_KEY_BUILDER)
|
|
2563
2601
|
);
|
|
2564
|
-
const networkCtxAccessor = container.resolve(
|
|
2602
|
+
const networkCtxAccessor = container.resolve(import_shared69.TOKENS.NETWORK_CONTEXT_ACCESSOR);
|
|
2565
2603
|
context.addCommand(
|
|
2566
2604
|
new IdempotencyPipeline(networkCtxAccessor, store, context.idempotencyOpts),
|
|
2567
2605
|
30
|
|
@@ -2572,36 +2610,36 @@ var CqrsModule = class {
|
|
|
2572
2610
|
if (context.isQueryCaching) {
|
|
2573
2611
|
sortedCommandBehaviors.push(
|
|
2574
2612
|
new CommandCacheInvalidationBehavior(
|
|
2575
|
-
container.resolve(
|
|
2576
|
-
container.resolve(
|
|
2613
|
+
container.resolve(import_shared69.TOKENS.CACHE),
|
|
2614
|
+
container.resolve(import_shared69.TOKENS.LOGGER)
|
|
2577
2615
|
)
|
|
2578
2616
|
);
|
|
2579
2617
|
sortedQueryBehaviors.push(
|
|
2580
2618
|
new QueryCachingPipeline(
|
|
2581
|
-
container.resolve(
|
|
2582
|
-
container.resolve(
|
|
2583
|
-
container.resolve(
|
|
2619
|
+
container.resolve(import_shared69.TOKENS.CACHE),
|
|
2620
|
+
container.resolve(import_shared69.TOKENS.CACHE_KEY_BUILDER),
|
|
2621
|
+
container.resolve(import_shared69.TOKENS.LOGGER)
|
|
2584
2622
|
)
|
|
2585
2623
|
);
|
|
2586
2624
|
}
|
|
2587
2625
|
container.addSingleton(
|
|
2588
|
-
|
|
2626
|
+
import_shared69.TOKENS.COMMAND_PIPELINES_BEHAVIOR,
|
|
2589
2627
|
() => new CompositePipeline(sortedCommandBehaviors)
|
|
2590
2628
|
);
|
|
2591
2629
|
container.addSingleton(
|
|
2592
|
-
|
|
2630
|
+
import_shared69.TOKENS.QUERY_PIPELINES_BEHAVIOR,
|
|
2593
2631
|
() => new CompositePipeline(sortedQueryBehaviors)
|
|
2594
2632
|
);
|
|
2595
2633
|
}
|
|
2596
2634
|
};
|
|
2597
2635
|
|
|
2598
2636
|
// src/infrastructure/modules/db.module.ts
|
|
2599
|
-
var import_shared71 = require("@xeno-js/shared");
|
|
2600
2637
|
var import_shared72 = require("@xeno-js/shared");
|
|
2638
|
+
var import_shared73 = require("@xeno-js/shared");
|
|
2601
2639
|
|
|
2602
2640
|
// src/infrastructure/transaction/unit-of-work.ts
|
|
2603
|
-
var import_shared69 = require("@xeno-js/shared");
|
|
2604
2641
|
var import_shared70 = require("@xeno-js/shared");
|
|
2642
|
+
var import_shared71 = require("@xeno-js/shared");
|
|
2605
2643
|
var UnitOfWork = class {
|
|
2606
2644
|
/**
|
|
2607
2645
|
* Creates an instance of UnitOfWork.
|
|
@@ -2620,7 +2658,7 @@ var UnitOfWork = class {
|
|
|
2620
2658
|
_dbContext;
|
|
2621
2659
|
_ttx;
|
|
2622
2660
|
async runInTransaction(callback, aggregates, signal) {
|
|
2623
|
-
|
|
2661
|
+
import_shared70.AppError.throwIfAborted(signal, "UnitOfWork.runInTransaction");
|
|
2624
2662
|
return this._dbContext.transaction(async (tx) => {
|
|
2625
2663
|
this._ttx.state = tx;
|
|
2626
2664
|
try {
|
|
@@ -2632,9 +2670,9 @@ var UnitOfWork = class {
|
|
|
2632
2670
|
});
|
|
2633
2671
|
}
|
|
2634
2672
|
async dispose() {
|
|
2635
|
-
if (
|
|
2673
|
+
if (import_shared71.Guards.isDefined(this._ttx.state)) {
|
|
2636
2674
|
try {
|
|
2637
|
-
if (
|
|
2675
|
+
if (import_shared71.Guards.hasMethod(this._ttx.state, "rollback")) {
|
|
2638
2676
|
await this._ttx.state.rollback();
|
|
2639
2677
|
}
|
|
2640
2678
|
} finally {
|
|
@@ -2677,27 +2715,27 @@ var TransactionState = class {
|
|
|
2677
2715
|
var DbModule = class {
|
|
2678
2716
|
async configure(container, opts) {
|
|
2679
2717
|
const db = opts.client;
|
|
2680
|
-
container.addScoped(
|
|
2718
|
+
container.addScoped(import_shared73.TOKENS.TRANSACTION_STATE, () => {
|
|
2681
2719
|
return new TransactionState();
|
|
2682
2720
|
});
|
|
2683
|
-
if (
|
|
2684
|
-
container.addScoped(
|
|
2721
|
+
if (import_shared72.Guards.isDefined(opts.uow)) {
|
|
2722
|
+
container.addScoped(import_shared73.TOKENS.UNIT_OF_WORK, (c) => {
|
|
2685
2723
|
return opts.uow(c);
|
|
2686
2724
|
});
|
|
2687
2725
|
} else {
|
|
2688
|
-
container.addScoped(
|
|
2689
|
-
const ttx = c.resolve(
|
|
2726
|
+
container.addScoped(import_shared73.TOKENS.UNIT_OF_WORK, (c) => {
|
|
2727
|
+
const ttx = c.resolve(import_shared73.TOKENS.TRANSACTION_STATE);
|
|
2690
2728
|
return new UnitOfWork(db, ttx);
|
|
2691
2729
|
});
|
|
2692
2730
|
}
|
|
2693
|
-
container.addScoped(
|
|
2694
|
-
const ttx = c.resolve(
|
|
2731
|
+
container.addScoped(import_shared73.TOKENS.DB_CONTEXT, (c) => {
|
|
2732
|
+
const ttx = c.resolve(import_shared73.TOKENS.TRANSACTION_STATE);
|
|
2695
2733
|
return new Proxy(db, {
|
|
2696
2734
|
get(_target, prop, receiver) {
|
|
2697
2735
|
const activeState = ttx.state;
|
|
2698
|
-
if (
|
|
2736
|
+
if (import_shared72.Guards.isDefined(activeState)) {
|
|
2699
2737
|
const value = Reflect.get(activeState, prop, receiver);
|
|
2700
|
-
if (
|
|
2738
|
+
if (import_shared72.Guards.isFunction(value)) {
|
|
2701
2739
|
return value.bind(activeState);
|
|
2702
2740
|
}
|
|
2703
2741
|
return value;
|
|
@@ -2710,27 +2748,27 @@ var DbModule = class {
|
|
|
2710
2748
|
};
|
|
2711
2749
|
|
|
2712
2750
|
// src/infrastructure/modules/http-server.module.ts
|
|
2713
|
-
var
|
|
2751
|
+
var import_shared76 = require("@xeno-js/shared");
|
|
2714
2752
|
|
|
2715
2753
|
// src/infrastructure/factories/route-matcher.factory.ts
|
|
2716
|
-
var
|
|
2754
|
+
var import_shared75 = require("@xeno-js/shared");
|
|
2717
2755
|
|
|
2718
2756
|
// src/infrastructure/http/route-matcher.http.ts
|
|
2719
|
-
var
|
|
2757
|
+
var import_shared74 = require("@xeno-js/shared");
|
|
2720
2758
|
var RouteMatcher = class {
|
|
2721
2759
|
constructor(_compiledRoutes) {
|
|
2722
2760
|
this._compiledRoutes = _compiledRoutes;
|
|
2723
2761
|
}
|
|
2724
2762
|
_compiledRoutes;
|
|
2725
2763
|
match(rawUrl, method) {
|
|
2726
|
-
const url = !
|
|
2727
|
-
const safeUrl =
|
|
2728
|
-
const parsedPath =
|
|
2764
|
+
const url = !import_shared74.Guards.isNullOrEmpty(rawUrl) ? rawUrl : "/";
|
|
2765
|
+
const safeUrl = import_shared74.HttpHelper.parseSafeUrl(url);
|
|
2766
|
+
const parsedPath = import_shared74.RoutePatternHelper.normalizePath(safeUrl.pathname);
|
|
2729
2767
|
const upperMethod = method.toUpperCase();
|
|
2730
2768
|
const matched = this._compiledRoutes.find(
|
|
2731
2769
|
(r) => r.upperMethod === upperMethod && r.pattern.test(parsedPath)
|
|
2732
2770
|
);
|
|
2733
|
-
if (
|
|
2771
|
+
if (import_shared74.Guards.isDefined(matched)) return matched.definition;
|
|
2734
2772
|
if (upperMethod === "OPTIONS") {
|
|
2735
2773
|
const pathExists = this._compiledRoutes.some((r) => r.pattern.test(parsedPath));
|
|
2736
2774
|
if (pathExists) {
|
|
@@ -2742,7 +2780,7 @@ var RouteMatcher = class {
|
|
|
2742
2780
|
return await ctx.handle("__PREFLIGHT__");
|
|
2743
2781
|
} catch {
|
|
2744
2782
|
return {
|
|
2745
|
-
status:
|
|
2783
|
+
status: import_shared74.STATUS_CODES.NO_CONTENT,
|
|
2746
2784
|
ok: true,
|
|
2747
2785
|
headers: {},
|
|
2748
2786
|
data: void 0
|
|
@@ -2769,8 +2807,8 @@ var RouteMatcher = class {
|
|
|
2769
2807
|
var RouteMatcherFactory = class {
|
|
2770
2808
|
create(opts) {
|
|
2771
2809
|
const routes = opts.map((r) => {
|
|
2772
|
-
const normalizedPath =
|
|
2773
|
-
const { pattern } =
|
|
2810
|
+
const normalizedPath = import_shared75.RoutePatternHelper.normalizePath(r.path);
|
|
2811
|
+
const { pattern } = import_shared75.RoutePatternHelper.parse(normalizedPath);
|
|
2774
2812
|
return {
|
|
2775
2813
|
definition: r,
|
|
2776
2814
|
pattern,
|
|
@@ -2802,27 +2840,27 @@ var ServerOptionsFactory = class {
|
|
|
2802
2840
|
var HttpServerModule = class {
|
|
2803
2841
|
async configure(container) {
|
|
2804
2842
|
container.addSingleton(
|
|
2805
|
-
|
|
2806
|
-
(c) => new ServerOptionsFactory(c.resolve(
|
|
2843
|
+
import_shared76.TOKENS.SERVER_OPTIONS_FACTORY,
|
|
2844
|
+
(c) => new ServerOptionsFactory(c.resolve(import_shared76.TOKENS.CONFIGURATION_SERVICE))
|
|
2807
2845
|
);
|
|
2808
|
-
if (!container.isRegistered(
|
|
2809
|
-
container.addSingleton(
|
|
2846
|
+
if (!container.isRegistered(import_shared76.TOKENS.ROUTE_MATCHER)) {
|
|
2847
|
+
container.addSingleton(import_shared76.TOKENS.ROUTE_MATCHER, () => new RouteMatcherFactory().create([]));
|
|
2810
2848
|
}
|
|
2811
2849
|
}
|
|
2812
2850
|
};
|
|
2813
2851
|
|
|
2814
2852
|
// src/infrastructure/modules/logger.module.ts
|
|
2815
|
-
var
|
|
2853
|
+
var import_shared78 = require("@xeno-js/shared");
|
|
2816
2854
|
|
|
2817
2855
|
// src/infrastructure/loggers/setup.logger.ts
|
|
2818
|
-
var
|
|
2856
|
+
var import_shared77 = require("@xeno-js/shared");
|
|
2819
2857
|
var LoggerSetupContext = class {
|
|
2820
2858
|
console = false;
|
|
2821
|
-
level =
|
|
2859
|
+
level = import_shared77.LOG_LEVEL.DEBUG;
|
|
2822
2860
|
_customLoggers = [];
|
|
2823
2861
|
addConsole(enabled = true, level) {
|
|
2824
2862
|
this.console = enabled;
|
|
2825
|
-
if (
|
|
2863
|
+
if (import_shared77.Guards.isDefined(level)) {
|
|
2826
2864
|
this.level = level;
|
|
2827
2865
|
}
|
|
2828
2866
|
}
|
|
@@ -2839,9 +2877,9 @@ var LoggerModule = class {
|
|
|
2839
2877
|
async configure(container, opts) {
|
|
2840
2878
|
const loggerSetup = new LoggerSetupContext();
|
|
2841
2879
|
loggerSetup.addConsole(opts.console, opts.level);
|
|
2842
|
-
if (!
|
|
2880
|
+
if (!import_shared78.Guards.isNullOrEmpty(opts.plugins))
|
|
2843
2881
|
opts.plugins.forEach((plugin) => plugin(opts.builder, opts.config, loggerSetup));
|
|
2844
|
-
if (!
|
|
2882
|
+
if (!import_shared78.Guards.isNullOrEmpty(opts.customLoggers)) {
|
|
2845
2883
|
for (const logger of opts.customLoggers) {
|
|
2846
2884
|
loggerSetup.addCustomLogger((c) => logger(c));
|
|
2847
2885
|
}
|
|
@@ -2856,11 +2894,11 @@ var LoggerModule = class {
|
|
|
2856
2894
|
};
|
|
2857
2895
|
|
|
2858
2896
|
// src/infrastructure/modules/middleware.module.ts
|
|
2859
|
-
var import_shared92 = require("@xeno-js/shared");
|
|
2860
2897
|
var import_shared93 = require("@xeno-js/shared");
|
|
2898
|
+
var import_shared94 = require("@xeno-js/shared");
|
|
2861
2899
|
|
|
2862
2900
|
// src/presentation/controllers/base.controller.ts
|
|
2863
|
-
var
|
|
2901
|
+
var import_shared79 = require("@xeno-js/shared");
|
|
2864
2902
|
var BaseController = class {
|
|
2865
2903
|
/**
|
|
2866
2904
|
* Constructs a new instance of the BaseController class.
|
|
@@ -2892,7 +2930,7 @@ var BaseController = class {
|
|
|
2892
2930
|
* @link https://github.com/xeno-js/xeno-js
|
|
2893
2931
|
*/
|
|
2894
2932
|
ok(data, status = 200, meta = {}, headers = {}) {
|
|
2895
|
-
return
|
|
2933
|
+
return import_shared79.HttpHelper.success(data, status, meta, headers);
|
|
2896
2934
|
}
|
|
2897
2935
|
/**
|
|
2898
2936
|
* Helper to automatically map a failed Result (from the CQRS pipeline)
|
|
@@ -2910,7 +2948,7 @@ var BaseController = class {
|
|
|
2910
2948
|
fail(error, details = void 0, headers = {}) {
|
|
2911
2949
|
const context = this._requestContext.getContext();
|
|
2912
2950
|
const customHeaders = error["header"];
|
|
2913
|
-
return
|
|
2951
|
+
return import_shared79.HttpHelper.error(
|
|
2914
2952
|
{
|
|
2915
2953
|
success: false,
|
|
2916
2954
|
error: {
|
|
@@ -2919,9 +2957,9 @@ var BaseController = class {
|
|
|
2919
2957
|
path: context?.network.path,
|
|
2920
2958
|
details: details ?? error.message
|
|
2921
2959
|
},
|
|
2922
|
-
correlationId: context?.tracing.correlationId ??
|
|
2923
|
-
requestId: context?.network.requestId ??
|
|
2924
|
-
spanId: context?.tracing.spanId ??
|
|
2960
|
+
correlationId: context?.tracing.correlationId ?? import_shared79.GuidHelper.generate(),
|
|
2961
|
+
requestId: context?.network.requestId ?? import_shared79.GuidHelper.generate(),
|
|
2962
|
+
spanId: context?.tracing.spanId ?? import_shared79.GuidHelper.generate(),
|
|
2925
2963
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2926
2964
|
},
|
|
2927
2965
|
error.status,
|
|
@@ -2966,7 +3004,7 @@ var BaseController = class {
|
|
|
2966
3004
|
};
|
|
2967
3005
|
|
|
2968
3006
|
// src/presentation/middlewares/allow-method.middleware.ts
|
|
2969
|
-
var
|
|
3007
|
+
var import_shared80 = require("@xeno-js/shared");
|
|
2970
3008
|
var MethodCheckMiddleware = class {
|
|
2971
3009
|
constructor(_requestContext, _allowMethod) {
|
|
2972
3010
|
this._requestContext = _requestContext;
|
|
@@ -2978,21 +3016,21 @@ var MethodCheckMiddleware = class {
|
|
|
2978
3016
|
const isAllowed = this._allowMethod.check(req.path, req.method);
|
|
2979
3017
|
if (!isAllowed) {
|
|
2980
3018
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
2981
|
-
return
|
|
3019
|
+
return import_shared80.HttpHelper.error(
|
|
2982
3020
|
{
|
|
2983
3021
|
success: false,
|
|
2984
3022
|
error: {
|
|
2985
|
-
code:
|
|
2986
|
-
message:
|
|
3023
|
+
code: import_shared80.ERROR_CODES.NOT_ALLOWED,
|
|
3024
|
+
message: import_shared80.ERROR_CODE_MESSAGES[import_shared80.ERROR_CODES.NOT_ALLOWED],
|
|
2987
3025
|
details: `Operation blocked by allow method middleware`,
|
|
2988
3026
|
path: req.path
|
|
2989
3027
|
},
|
|
2990
|
-
correlationId: tracing?.correlationId ??
|
|
2991
|
-
requestId: network?.requestId ??
|
|
2992
|
-
spanId: tracing?.spanId ??
|
|
3028
|
+
correlationId: tracing?.correlationId ?? import_shared80.GuidHelper.generate(),
|
|
3029
|
+
requestId: network?.requestId ?? import_shared80.GuidHelper.generate(),
|
|
3030
|
+
spanId: tracing?.spanId ?? import_shared80.GuidHelper.generate(),
|
|
2993
3031
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
2994
3032
|
},
|
|
2995
|
-
|
|
3033
|
+
import_shared80.STATUS_CODES.NOT_ALLOWED,
|
|
2996
3034
|
{
|
|
2997
3035
|
Allow: this._allowMethod.getMethods(req.path)
|
|
2998
3036
|
}
|
|
@@ -3003,7 +3041,7 @@ var MethodCheckMiddleware = class {
|
|
|
3003
3041
|
};
|
|
3004
3042
|
|
|
3005
3043
|
// src/presentation/middlewares/allow-origin.middleware.ts
|
|
3006
|
-
var
|
|
3044
|
+
var import_shared81 = require("@xeno-js/shared");
|
|
3007
3045
|
var AllowOriginMiddleware = class {
|
|
3008
3046
|
constructor(_allowOrigin, _requestContext, _logger, _getRouteMatcher) {
|
|
3009
3047
|
this._allowOrigin = _allowOrigin;
|
|
@@ -3022,27 +3060,27 @@ var AllowOriginMiddleware = class {
|
|
|
3022
3060
|
const isAllowed = this.checkOrigin(policy, origin);
|
|
3023
3061
|
if (!isAllowed) {
|
|
3024
3062
|
this._logger.warn(`Access denied by AllowOrigin policy for origin: ${origin ?? "unknown"}`);
|
|
3025
|
-
return
|
|
3063
|
+
return import_shared81.HttpHelper.error(
|
|
3026
3064
|
{
|
|
3027
3065
|
success: false,
|
|
3028
3066
|
error: {
|
|
3029
|
-
code:
|
|
3030
|
-
message:
|
|
3067
|
+
code: import_shared81.ERROR_CODES.FORBIDDEN,
|
|
3068
|
+
message: import_shared81.ERROR_CODE_MESSAGES[import_shared81.ERROR_CODES.FORBIDDEN],
|
|
3031
3069
|
details: `The origin '${origin ?? "unknown"}' is not allowed to access this resource.`,
|
|
3032
3070
|
path: req.path
|
|
3033
3071
|
},
|
|
3034
|
-
correlationId: tracing?.correlationId ??
|
|
3035
|
-
requestId: network?.requestId ??
|
|
3036
|
-
spanId: tracing?.spanId ??
|
|
3072
|
+
correlationId: tracing?.correlationId ?? import_shared81.GuidHelper.generate(),
|
|
3073
|
+
requestId: network?.requestId ?? import_shared81.GuidHelper.generate(),
|
|
3074
|
+
spanId: tracing?.spanId ?? import_shared81.GuidHelper.generate(),
|
|
3037
3075
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3038
3076
|
},
|
|
3039
|
-
|
|
3077
|
+
import_shared81.STATUS_CODES.FORBIDDEN
|
|
3040
3078
|
);
|
|
3041
3079
|
}
|
|
3042
3080
|
return next();
|
|
3043
3081
|
}
|
|
3044
3082
|
checkOrigin(policy, origin) {
|
|
3045
|
-
if (
|
|
3083
|
+
if (import_shared81.Guards.isDefined(policy.allowOrigins)) {
|
|
3046
3084
|
return policy.allowOrigins.includes("*") || policy.allowOrigins.includes(origin ?? "");
|
|
3047
3085
|
} else {
|
|
3048
3086
|
return this._allowOrigin.isAllowed(origin);
|
|
@@ -3051,7 +3089,7 @@ var AllowOriginMiddleware = class {
|
|
|
3051
3089
|
};
|
|
3052
3090
|
|
|
3053
3091
|
// src/presentation/middlewares/auth.middleware.ts
|
|
3054
|
-
var
|
|
3092
|
+
var import_shared82 = require("@xeno-js/shared");
|
|
3055
3093
|
var AuthenticationMiddleware = class {
|
|
3056
3094
|
constructor(_requestContext, _tokenExtractor, _gateKeeper, _logger) {
|
|
3057
3095
|
this._requestContext = _requestContext;
|
|
@@ -3072,7 +3110,7 @@ var AuthenticationMiddleware = class {
|
|
|
3072
3110
|
`Authentication failed for request on path: ${req.path}. Code: ${error.code}. Error: ${error}`
|
|
3073
3111
|
);
|
|
3074
3112
|
const { network, tracing } = this._requestContext.getContext() ?? {};
|
|
3075
|
-
return
|
|
3113
|
+
return import_shared82.HttpHelper.error(
|
|
3076
3114
|
{
|
|
3077
3115
|
success: false,
|
|
3078
3116
|
error: {
|
|
@@ -3081,12 +3119,12 @@ var AuthenticationMiddleware = class {
|
|
|
3081
3119
|
details: `[Authentication Error] Failed to authenticate request on path: ${req.path}`,
|
|
3082
3120
|
path: req.path
|
|
3083
3121
|
},
|
|
3084
|
-
correlationId: tracing?.correlationId ??
|
|
3085
|
-
requestId: network?.requestId ??
|
|
3086
|
-
spanId: tracing?.spanId ??
|
|
3122
|
+
correlationId: tracing?.correlationId ?? import_shared82.GuidHelper.generate(),
|
|
3123
|
+
requestId: network?.requestId ?? import_shared82.GuidHelper.generate(),
|
|
3124
|
+
spanId: tracing?.spanId ?? import_shared82.GuidHelper.generate(),
|
|
3087
3125
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3088
3126
|
},
|
|
3089
|
-
error.status ??
|
|
3127
|
+
error.status ?? import_shared82.STATUS_CODES.UNAUTHORIZED,
|
|
3090
3128
|
{ "Content-Type": [network?.formatIndicator ?? "application/json"] }
|
|
3091
3129
|
);
|
|
3092
3130
|
}
|
|
@@ -3113,8 +3151,8 @@ var CompositeMiddleware = class {
|
|
|
3113
3151
|
};
|
|
3114
3152
|
|
|
3115
3153
|
// src/presentation/middlewares/cookie-response.middleware.ts
|
|
3116
|
-
var import_shared82 = require("@xeno-js/shared");
|
|
3117
3154
|
var import_shared83 = require("@xeno-js/shared");
|
|
3155
|
+
var import_shared84 = require("@xeno-js/shared");
|
|
3118
3156
|
var CookieResponseMiddleware = class {
|
|
3119
3157
|
constructor(_requestContext) {
|
|
3120
3158
|
this._requestContext = _requestContext;
|
|
@@ -3123,15 +3161,15 @@ var CookieResponseMiddleware = class {
|
|
|
3123
3161
|
async execute(req, next) {
|
|
3124
3162
|
const response = await next();
|
|
3125
3163
|
const scope = this._requestContext.getScope();
|
|
3126
|
-
if (!
|
|
3164
|
+
if (!import_shared83.Guards.isDefined(scope)) {
|
|
3127
3165
|
return response;
|
|
3128
3166
|
}
|
|
3129
3167
|
try {
|
|
3130
|
-
const cookieHandler = scope.resolve(
|
|
3168
|
+
const cookieHandler = scope.resolve(import_shared84.TOKENS.COOKIE_HANDLER);
|
|
3131
3169
|
const pending = cookieHandler.getPendingCookies();
|
|
3132
|
-
if (!
|
|
3170
|
+
if (!import_shared83.Guards.isNullOrEmpty(pending)) {
|
|
3133
3171
|
const existingSetCookie = response.headers?.["Set-Cookie"];
|
|
3134
|
-
const mergedCookies =
|
|
3172
|
+
const mergedCookies = import_shared83.Guards.isArray(existingSetCookie) ? [...existingSetCookie, ...pending] : import_shared83.Guards.isDefined(existingSetCookie) ? [String(existingSetCookie), ...pending] : [...pending];
|
|
3135
3173
|
response.headers = {
|
|
3136
3174
|
...response?.headers ?? {},
|
|
3137
3175
|
"Set-Cookie": mergedCookies
|
|
@@ -3144,7 +3182,7 @@ var CookieResponseMiddleware = class {
|
|
|
3144
3182
|
};
|
|
3145
3183
|
|
|
3146
3184
|
// src/presentation/middlewares/cors.middleware.ts
|
|
3147
|
-
var
|
|
3185
|
+
var import_shared85 = require("@xeno-js/shared");
|
|
3148
3186
|
var CORSMiddleware = class {
|
|
3149
3187
|
constructor(_requestContext, _getRouteMatcher, _withCredentials = "false") {
|
|
3150
3188
|
this._requestContext = _requestContext;
|
|
@@ -3159,12 +3197,12 @@ var CORSMiddleware = class {
|
|
|
3159
3197
|
const origin = network?.origin;
|
|
3160
3198
|
const response = await next();
|
|
3161
3199
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, req.method);
|
|
3162
|
-
const withCredentials =
|
|
3200
|
+
const withCredentials = import_shared85.Guards.isDefined(policy.withCredentials) ? policy.withCredentials ? "true" : "false" : this._withCredentials;
|
|
3163
3201
|
const allowOrigins = policy.allowOrigins;
|
|
3164
|
-
if (
|
|
3202
|
+
if (import_shared85.Guards.isDefined(origin) || import_shared85.Guards.isDefined(allowOrigins) && allowOrigins.includes("*")) {
|
|
3165
3203
|
response.headers = {
|
|
3166
3204
|
...response?.headers ?? {},
|
|
3167
|
-
"Access-Control-Allow-Origin":
|
|
3205
|
+
"Access-Control-Allow-Origin": import_shared85.Guards.isDefined(allowOrigins) && allowOrigins.includes("*") && withCredentials === "false" ? "*" : origin,
|
|
3168
3206
|
"Access-Control-Allow-Credentials": withCredentials,
|
|
3169
3207
|
"Vary": "Origin"
|
|
3170
3208
|
};
|
|
@@ -3174,7 +3212,7 @@ var CORSMiddleware = class {
|
|
|
3174
3212
|
};
|
|
3175
3213
|
|
|
3176
3214
|
// src/presentation/middlewares/csrf.middleware.ts
|
|
3177
|
-
var
|
|
3215
|
+
var import_shared86 = require("@xeno-js/shared");
|
|
3178
3216
|
var CsrfMiddleware = class {
|
|
3179
3217
|
constructor(_requestContext, _csrfTokenService, _getRouteMatcher) {
|
|
3180
3218
|
this._requestContext = _requestContext;
|
|
@@ -3189,68 +3227,68 @@ var CsrfMiddleware = class {
|
|
|
3189
3227
|
const isStateChanging = ["POST", "PUT", "DELETE", "PATCH"].includes(method);
|
|
3190
3228
|
if (isStateChanging) {
|
|
3191
3229
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, method);
|
|
3192
|
-
if (
|
|
3230
|
+
if (import_shared86.Guards.isDefined(policy.withCsrf) && !policy.withCsrf) return await next();
|
|
3193
3231
|
const { network, tracing, identity } = this._requestContext.getContext() ?? {};
|
|
3194
3232
|
const headerToken = network?.csrf;
|
|
3195
3233
|
const cookieToken = network?.csrfCookie;
|
|
3196
|
-
if (!
|
|
3197
|
-
return
|
|
3234
|
+
if (!import_shared86.Guards.isDefined(headerToken) || !import_shared86.Guards.isDefined(cookieToken)) {
|
|
3235
|
+
return import_shared86.HttpHelper.error(
|
|
3198
3236
|
{
|
|
3199
3237
|
success: false,
|
|
3200
3238
|
error: {
|
|
3201
|
-
code:
|
|
3202
|
-
message:
|
|
3239
|
+
code: import_shared86.ERROR_CODES.FORBIDDEN,
|
|
3240
|
+
message: import_shared86.ERROR_CODE_MESSAGES[import_shared86.ERROR_CODES.FORBIDDEN],
|
|
3203
3241
|
details: "CSRF token missing",
|
|
3204
3242
|
path: req.path
|
|
3205
3243
|
},
|
|
3206
|
-
correlationId: tracing?.correlationId ??
|
|
3207
|
-
requestId: network?.requestId ??
|
|
3208
|
-
spanId: tracing?.spanId ??
|
|
3244
|
+
correlationId: tracing?.correlationId ?? import_shared86.GuidHelper.generate(),
|
|
3245
|
+
requestId: network?.requestId ?? import_shared86.GuidHelper.generate(),
|
|
3246
|
+
spanId: tracing?.spanId ?? import_shared86.GuidHelper.generate(),
|
|
3209
3247
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3210
3248
|
},
|
|
3211
|
-
|
|
3249
|
+
import_shared86.STATUS_CODES.FORBIDDEN,
|
|
3212
3250
|
{
|
|
3213
3251
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3214
3252
|
}
|
|
3215
3253
|
);
|
|
3216
3254
|
}
|
|
3217
3255
|
if (headerToken !== cookieToken) {
|
|
3218
|
-
return
|
|
3256
|
+
return import_shared86.HttpHelper.error(
|
|
3219
3257
|
{
|
|
3220
3258
|
success: false,
|
|
3221
3259
|
error: {
|
|
3222
|
-
code:
|
|
3223
|
-
message:
|
|
3260
|
+
code: import_shared86.ERROR_CODES.FORBIDDEN,
|
|
3261
|
+
message: import_shared86.ERROR_CODE_MESSAGES[import_shared86.ERROR_CODES.FORBIDDEN],
|
|
3224
3262
|
details: "CSRF token mismatch",
|
|
3225
3263
|
path: req.path
|
|
3226
3264
|
},
|
|
3227
|
-
correlationId: tracing?.correlationId ??
|
|
3228
|
-
requestId: network?.requestId ??
|
|
3229
|
-
spanId: tracing?.spanId ??
|
|
3265
|
+
correlationId: tracing?.correlationId ?? import_shared86.GuidHelper.generate(),
|
|
3266
|
+
requestId: network?.requestId ?? import_shared86.GuidHelper.generate(),
|
|
3267
|
+
spanId: tracing?.spanId ?? import_shared86.GuidHelper.generate(),
|
|
3230
3268
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3231
3269
|
},
|
|
3232
|
-
|
|
3270
|
+
import_shared86.STATUS_CODES.FORBIDDEN,
|
|
3233
3271
|
{
|
|
3234
3272
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3235
3273
|
}
|
|
3236
3274
|
);
|
|
3237
3275
|
}
|
|
3238
|
-
if (!
|
|
3239
|
-
return
|
|
3276
|
+
if (!import_shared86.Guards.isDefined(identity?.userId) || !await this._csrfTokenService.validate(headerToken, identity?.userId)) {
|
|
3277
|
+
return import_shared86.HttpHelper.error(
|
|
3240
3278
|
{
|
|
3241
3279
|
success: false,
|
|
3242
3280
|
error: {
|
|
3243
|
-
code:
|
|
3244
|
-
message:
|
|
3281
|
+
code: import_shared86.ERROR_CODES.FORBIDDEN,
|
|
3282
|
+
message: import_shared86.ERROR_CODE_MESSAGES[import_shared86.ERROR_CODES.FORBIDDEN],
|
|
3245
3283
|
details: "CSRF token invalid",
|
|
3246
3284
|
path: req.path
|
|
3247
3285
|
},
|
|
3248
|
-
correlationId: tracing?.correlationId ??
|
|
3249
|
-
requestId: network?.requestId ??
|
|
3250
|
-
spanId: tracing?.spanId ??
|
|
3286
|
+
correlationId: tracing?.correlationId ?? import_shared86.GuidHelper.generate(),
|
|
3287
|
+
requestId: network?.requestId ?? import_shared86.GuidHelper.generate(),
|
|
3288
|
+
spanId: tracing?.spanId ?? import_shared86.GuidHelper.generate(),
|
|
3251
3289
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3252
3290
|
},
|
|
3253
|
-
|
|
3291
|
+
import_shared86.STATUS_CODES.FORBIDDEN,
|
|
3254
3292
|
{
|
|
3255
3293
|
"Content-Type": [network?.formatIndicator ?? "application/json"]
|
|
3256
3294
|
}
|
|
@@ -3262,7 +3300,7 @@ var CsrfMiddleware = class {
|
|
|
3262
3300
|
};
|
|
3263
3301
|
|
|
3264
3302
|
// src/presentation/middlewares/csrf-cookie.middleware.ts
|
|
3265
|
-
var
|
|
3303
|
+
var import_shared87 = require("@xeno-js/shared");
|
|
3266
3304
|
var CsrfCookieMiddleware = class {
|
|
3267
3305
|
constructor(_requestContext, _csrfTokenService, _csrf) {
|
|
3268
3306
|
this._requestContext = _requestContext;
|
|
@@ -3277,8 +3315,8 @@ var CsrfCookieMiddleware = class {
|
|
|
3277
3315
|
const context = this._requestContext.getContext();
|
|
3278
3316
|
const identity = context?.identity;
|
|
3279
3317
|
const network = context?.network;
|
|
3280
|
-
if (!
|
|
3281
|
-
if (
|
|
3318
|
+
if (!import_shared87.Guards.isDefined(identity?.userId)) return response;
|
|
3319
|
+
if (import_shared87.Guards.isDefined(network?.csrfCookie)) return response;
|
|
3282
3320
|
const token = await this._csrfTokenService.generate(identity.userId);
|
|
3283
3321
|
const cookieName = this._csrf.cookieName ?? "__Host-xeno-csrf";
|
|
3284
3322
|
const maxAge = this._csrf.cookieMaxAgeSeconds ?? 3600;
|
|
@@ -3294,7 +3332,7 @@ var CsrfCookieMiddleware = class {
|
|
|
3294
3332
|
};
|
|
3295
3333
|
|
|
3296
3334
|
// src/presentation/middlewares/options.middleware.ts
|
|
3297
|
-
var
|
|
3335
|
+
var import_shared88 = require("@xeno-js/shared");
|
|
3298
3336
|
var OptionsMiddleware = class {
|
|
3299
3337
|
constructor(_requestContext, _allowMethod, _getRouteMatcher, _allowHeaders = [], _withCredentials = "false") {
|
|
3300
3338
|
this._requestContext = _requestContext;
|
|
@@ -3314,23 +3352,23 @@ var OptionsMiddleware = class {
|
|
|
3314
3352
|
const origin = network?.origin;
|
|
3315
3353
|
const targetMethod = req.headers.get("access-control-request-method") ?? "GET";
|
|
3316
3354
|
const policy = this._getRouteMatcher().checkRoutePolicy(req.path, targetMethod);
|
|
3317
|
-
const withCredentials =
|
|
3355
|
+
const withCredentials = import_shared88.Guards.isDefined(policy.withCredentials) ? policy.withCredentials ? "true" : "false" : this._withCredentials;
|
|
3318
3356
|
const headers = {};
|
|
3319
|
-
if (
|
|
3320
|
-
headers["Access-Control-Allow-Origin"] =
|
|
3357
|
+
if (import_shared88.Guards.isDefined(origin) || import_shared88.Guards.isDefined(policy.allowOrigins) && policy.allowOrigins.includes("*")) {
|
|
3358
|
+
headers["Access-Control-Allow-Origin"] = import_shared88.Guards.isDefined(policy.allowOrigins) && policy.allowOrigins.includes("*") && withCredentials === "false" ? "*" : origin;
|
|
3321
3359
|
headers["Access-Control-Allow-Credentials"] = withCredentials;
|
|
3322
3360
|
headers["Vary"] = "Origin";
|
|
3323
3361
|
}
|
|
3324
3362
|
headers["Access-Control-Allow-Methods"] = this._allowMethod.getMethods(req.path);
|
|
3325
3363
|
headers["Access-Control-Allow-Headers"] = this._allowHeaders.join(", ");
|
|
3326
|
-
return
|
|
3364
|
+
return import_shared88.HttpHelper.success(null, import_shared88.STATUS_CODES.NO_CONTENT, {}, headers);
|
|
3327
3365
|
}
|
|
3328
3366
|
return await next();
|
|
3329
3367
|
}
|
|
3330
3368
|
};
|
|
3331
3369
|
|
|
3332
3370
|
// src/presentation/middlewares/rate-limiter.middleware.ts
|
|
3333
|
-
var
|
|
3371
|
+
var import_shared89 = require("@xeno-js/shared");
|
|
3334
3372
|
var RateLimitMiddleware = class {
|
|
3335
3373
|
constructor(_ctxAccessor, _cache, _keyBuilder, _logger, _opts) {
|
|
3336
3374
|
this._ctxAccessor = _ctxAccessor;
|
|
@@ -3347,22 +3385,22 @@ var RateLimitMiddleware = class {
|
|
|
3347
3385
|
async execute(req, next) {
|
|
3348
3386
|
const cacheKey = this._keyBuilder.buildRateLimitKey(req.path);
|
|
3349
3387
|
const { network, tracing } = this._ctxAccessor.getContext() ?? {};
|
|
3350
|
-
if (!
|
|
3351
|
-
return
|
|
3388
|
+
if (!import_shared89.Guards.isDefined(cacheKey))
|
|
3389
|
+
return import_shared89.HttpHelper.error(
|
|
3352
3390
|
{
|
|
3353
3391
|
success: false,
|
|
3354
3392
|
error: {
|
|
3355
|
-
code:
|
|
3356
|
-
message:
|
|
3393
|
+
code: import_shared89.ERROR_CODES.SYSTEM_ERROR,
|
|
3394
|
+
message: import_shared89.ERROR_CODE_MESSAGES[import_shared89.ERROR_CODES.SYSTEM_ERROR],
|
|
3357
3395
|
details: `Bad Request: Unable to identify client context for rate limiting.`,
|
|
3358
3396
|
path: req.path
|
|
3359
3397
|
},
|
|
3360
|
-
correlationId: tracing?.correlationId ??
|
|
3361
|
-
requestId: network?.requestId ??
|
|
3362
|
-
spanId: tracing?.spanId ??
|
|
3398
|
+
correlationId: tracing?.correlationId ?? import_shared89.GuidHelper.generate(),
|
|
3399
|
+
requestId: network?.requestId ?? import_shared89.GuidHelper.generate(),
|
|
3400
|
+
spanId: tracing?.spanId ?? import_shared89.GuidHelper.generate(),
|
|
3363
3401
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3364
3402
|
},
|
|
3365
|
-
|
|
3403
|
+
import_shared89.STATUS_CODES.SERVICE_UNAVAILABLE,
|
|
3366
3404
|
{
|
|
3367
3405
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3368
3406
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3371,21 +3409,21 @@ var RateLimitMiddleware = class {
|
|
|
3371
3409
|
const currentHits = await this._cache.increment(cacheKey, this._opts.windowSeconds);
|
|
3372
3410
|
if (currentHits > this._opts.maxRequests) {
|
|
3373
3411
|
this._logger.warn(`[RateLimit] key ${cacheKey} has been blocked on ${req.path}`);
|
|
3374
|
-
return
|
|
3412
|
+
return import_shared89.HttpHelper.error(
|
|
3375
3413
|
{
|
|
3376
3414
|
success: false,
|
|
3377
3415
|
error: {
|
|
3378
|
-
code:
|
|
3379
|
-
message:
|
|
3416
|
+
code: import_shared89.ERROR_CODES.TOO_MANY_REQUESTS,
|
|
3417
|
+
message: import_shared89.ERROR_CODE_MESSAGES[import_shared89.ERROR_CODES.TOO_MANY_REQUESTS],
|
|
3380
3418
|
details: `Rate limit exceeded.`,
|
|
3381
3419
|
path: req.path
|
|
3382
3420
|
},
|
|
3383
|
-
correlationId: tracing?.correlationId ??
|
|
3384
|
-
requestId: network?.requestId ??
|
|
3385
|
-
spanId: tracing?.spanId ??
|
|
3421
|
+
correlationId: tracing?.correlationId ?? import_shared89.GuidHelper.generate(),
|
|
3422
|
+
requestId: network?.requestId ?? import_shared89.GuidHelper.generate(),
|
|
3423
|
+
spanId: tracing?.spanId ?? import_shared89.GuidHelper.generate(),
|
|
3386
3424
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3387
3425
|
},
|
|
3388
|
-
|
|
3426
|
+
import_shared89.STATUS_CODES.TOO_MANY_REQUESTS,
|
|
3389
3427
|
{
|
|
3390
3428
|
"Content-Type": [network?.formatIndicator ?? "application/json"],
|
|
3391
3429
|
"Retry-After": [String(this._opts.windowSeconds)]
|
|
@@ -3397,10 +3435,10 @@ var RateLimitMiddleware = class {
|
|
|
3397
3435
|
};
|
|
3398
3436
|
|
|
3399
3437
|
// src/presentation/middlewares/request.middleware.ts
|
|
3400
|
-
var
|
|
3438
|
+
var import_shared91 = require("@xeno-js/shared");
|
|
3401
3439
|
|
|
3402
3440
|
// src/presentation/mappers/context.mapper.ts
|
|
3403
|
-
var
|
|
3441
|
+
var import_shared90 = require("@xeno-js/shared");
|
|
3404
3442
|
var ContextMapper = Object.freeze({
|
|
3405
3443
|
/**
|
|
3406
3444
|
* @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.
|
|
@@ -3441,13 +3479,13 @@ var ContextMapper = Object.freeze({
|
|
|
3441
3479
|
}
|
|
3442
3480
|
});
|
|
3443
3481
|
function _buildMessagingContext(meta) {
|
|
3444
|
-
const hasSequenceData =
|
|
3445
|
-
const hasMessagingData = hasSequenceData ||
|
|
3482
|
+
const hasSequenceData = import_shared90.Guards.isDefined(meta.sequence?.sequenceId) || import_shared90.Guards.isDefined(meta.sequence?.position) || import_shared90.Guards.isDefined(meta.sequence?.size);
|
|
3483
|
+
const hasMessagingData = hasSequenceData || import_shared90.Guards.isDefined(meta.expiration) || import_shared90.Guards.isDefined(meta.returnAddress);
|
|
3446
3484
|
if (!hasMessagingData) return void 0;
|
|
3447
3485
|
return {
|
|
3448
3486
|
returnAddress: meta.returnAddress,
|
|
3449
3487
|
expiration: meta.expiration,
|
|
3450
|
-
sequence: hasSequenceData &&
|
|
3488
|
+
sequence: hasSequenceData && import_shared90.Guards.isDefined(meta.sequence) ? {
|
|
3451
3489
|
sequenceId: meta.sequence.sequenceId,
|
|
3452
3490
|
position: meta.sequence.position,
|
|
3453
3491
|
size: meta.sequence.size
|
|
@@ -3479,9 +3517,9 @@ var RequestContextMiddleware = class {
|
|
|
3479
3517
|
_resolver;
|
|
3480
3518
|
_logger;
|
|
3481
3519
|
async execute(req, next) {
|
|
3482
|
-
const correlationId =
|
|
3483
|
-
const requestId =
|
|
3484
|
-
const spanId =
|
|
3520
|
+
const correlationId = import_shared91.GuidHelper.generate();
|
|
3521
|
+
const requestId = import_shared91.GuidHelper.generate();
|
|
3522
|
+
const spanId = import_shared91.GuidHelper.generate();
|
|
3485
3523
|
let formatIndicator = "application/json";
|
|
3486
3524
|
try {
|
|
3487
3525
|
const meta = this._extractor.extract(req.headers);
|
|
@@ -3497,7 +3535,7 @@ var RequestContextMiddleware = class {
|
|
|
3497
3535
|
};
|
|
3498
3536
|
const tmpContext = ContextMapper.map({
|
|
3499
3537
|
metadata,
|
|
3500
|
-
identity:
|
|
3538
|
+
identity: import_shared91.GUEST,
|
|
3501
3539
|
path: req.path
|
|
3502
3540
|
});
|
|
3503
3541
|
const result = await this._requestContext.runAsync(tmpContext, async () => {
|
|
@@ -3508,12 +3546,12 @@ var RequestContextMiddleware = class {
|
|
|
3508
3546
|
return result;
|
|
3509
3547
|
} catch (error) {
|
|
3510
3548
|
this._logger.error("RequestContextMiddleware encountered an error", error);
|
|
3511
|
-
return
|
|
3549
|
+
return import_shared91.HttpHelper.error(
|
|
3512
3550
|
{
|
|
3513
3551
|
success: false,
|
|
3514
3552
|
error: {
|
|
3515
|
-
code:
|
|
3516
|
-
message:
|
|
3553
|
+
code: import_shared91.ERROR_CODES.SYSTEM_ERROR,
|
|
3554
|
+
message: import_shared91.ERROR_CODE_MESSAGES[import_shared91.ERROR_CODES.SYSTEM_ERROR],
|
|
3517
3555
|
details: `[Fatal System Error] Exception caught during request handling on path: ${req.path}`,
|
|
3518
3556
|
path: req.path
|
|
3519
3557
|
},
|
|
@@ -3522,7 +3560,7 @@ var RequestContextMiddleware = class {
|
|
|
3522
3560
|
spanId,
|
|
3523
3561
|
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
3524
3562
|
},
|
|
3525
|
-
|
|
3563
|
+
import_shared91.STATUS_CODES.INTERNAL_SERVER_ERROR,
|
|
3526
3564
|
{ "Content-Type": [formatIndicator] }
|
|
3527
3565
|
);
|
|
3528
3566
|
}
|
|
@@ -3530,7 +3568,7 @@ var RequestContextMiddleware = class {
|
|
|
3530
3568
|
};
|
|
3531
3569
|
|
|
3532
3570
|
// src/infrastructure/http/dispatcher.http.ts
|
|
3533
|
-
var
|
|
3571
|
+
var import_shared92 = require("@xeno-js/shared");
|
|
3534
3572
|
var HttpDispatcher = class {
|
|
3535
3573
|
constructor(_requestContext, _middleware, _serviceProxy) {
|
|
3536
3574
|
this._requestContext = _requestContext;
|
|
@@ -3543,14 +3581,14 @@ var HttpDispatcher = class {
|
|
|
3543
3581
|
async handle(req, token, input) {
|
|
3544
3582
|
return await this._middleware.execute(req, async () => {
|
|
3545
3583
|
const scope = this._requestContext.getScope();
|
|
3546
|
-
if (!
|
|
3584
|
+
if (!import_shared92.Guards.isDefined(scope)) {
|
|
3547
3585
|
throw new Error(
|
|
3548
3586
|
"[HttpDispatcher Error]: Active scope not found. Execution outside RequestContext."
|
|
3549
3587
|
);
|
|
3550
3588
|
}
|
|
3551
3589
|
const services = this._serviceProxy.getServiceProxy(scope);
|
|
3552
3590
|
const controller = services[token];
|
|
3553
|
-
if (!
|
|
3591
|
+
if (!import_shared92.Guards.isDefined(controller) || !import_shared92.Guards.hasMethod(controller, "handle")) {
|
|
3554
3592
|
throw new Error(
|
|
3555
3593
|
`[HttpDispatcher Error]: The provided '${String(token)}' does not implement the 'handle' method.`
|
|
3556
3594
|
);
|
|
@@ -3563,14 +3601,14 @@ var HttpDispatcher = class {
|
|
|
3563
3601
|
// src/infrastructure/modules/middleware.module.ts
|
|
3564
3602
|
var MiddlewareModule = class {
|
|
3565
3603
|
async configure(container, opts) {
|
|
3566
|
-
if (!container.isRegistered(
|
|
3567
|
-
await LoggerUtils2.addLogger(container, { level:
|
|
3568
|
-
const logger = container.resolve(
|
|
3569
|
-
const requestContext = container.resolve(
|
|
3570
|
-
const configuration = container.resolve(
|
|
3604
|
+
if (!container.isRegistered(import_shared94.TOKENS.LOGGER))
|
|
3605
|
+
await LoggerUtils2.addLogger(container, { level: import_shared93.LOG_LEVEL.INFO, console: true });
|
|
3606
|
+
const logger = container.resolve(import_shared94.TOKENS.LOGGER);
|
|
3607
|
+
const requestContext = container.resolve(import_shared94.TOKENS.REQUEST_CONTEXT);
|
|
3608
|
+
const configuration = container.resolve(import_shared94.TOKENS.CONFIGURATION_SERVICE);
|
|
3571
3609
|
const allowMethod = new AllowMethodFactory().create(opts.routes);
|
|
3572
3610
|
container.addSingleton(
|
|
3573
|
-
|
|
3611
|
+
import_shared94.TOKENS.SERVICE_EXTRACTOR,
|
|
3574
3612
|
() => new HttpHeaderExtractor(
|
|
3575
3613
|
new HttpCookieExtractor(),
|
|
3576
3614
|
opts.trustedIpHeader,
|
|
@@ -3578,8 +3616,8 @@ var MiddlewareModule = class {
|
|
|
3578
3616
|
opts.csrf?.headerName ?? "x-csrf-token"
|
|
3579
3617
|
)
|
|
3580
3618
|
);
|
|
3581
|
-
const getRouteMatcher = () => container.resolve(
|
|
3582
|
-
const withCredentials =
|
|
3619
|
+
const getRouteMatcher = () => container.resolve(import_shared94.TOKENS.ROUTE_MATCHER);
|
|
3620
|
+
const withCredentials = import_shared93.Guards.isDefined(opts.cors?.withCredentials) && opts.cors?.withCredentials ? "true" : "false";
|
|
3583
3621
|
const [optionsMw, cookieRespMw, corsMw, authMw, csrfMws] = [
|
|
3584
3622
|
this._buildOptionsMiddleware(
|
|
3585
3623
|
opts,
|
|
@@ -3601,12 +3639,12 @@ var MiddlewareModule = class {
|
|
|
3601
3639
|
);
|
|
3602
3640
|
const requestCtxMw = new RequestContextMiddleware(
|
|
3603
3641
|
requestContext,
|
|
3604
|
-
container.resolve(
|
|
3642
|
+
container.resolve(import_shared94.TOKENS.SERVICE_EXTRACTOR),
|
|
3605
3643
|
new ClientIpResolver(opts.trustedProxies),
|
|
3606
3644
|
logger
|
|
3607
3645
|
);
|
|
3608
3646
|
const defaultOrigin = configuration.get("APP_URL") ?? `http://localhost:${configuration.getNumber("PORT", 3e3)}`;
|
|
3609
|
-
const origins = !
|
|
3647
|
+
const origins = !import_shared93.Guards.isNullOrEmpty(opts.cors?.allowOrigins) ? opts.cors.allowOrigins : [defaultOrigin];
|
|
3610
3648
|
const allowOriginMw = new AllowOriginMiddleware(
|
|
3611
3649
|
new AllowOrigin(origins),
|
|
3612
3650
|
requestContext,
|
|
@@ -3616,55 +3654,55 @@ var MiddlewareModule = class {
|
|
|
3616
3654
|
const methodCheckMw = new MethodCheckMiddleware(requestContext, allowMethod);
|
|
3617
3655
|
const pipeline = [
|
|
3618
3656
|
requestCtxMw,
|
|
3619
|
-
...
|
|
3657
|
+
...import_shared93.Guards.isDefined(cookieRespMw) ? [cookieRespMw] : [],
|
|
3620
3658
|
allowOriginMw,
|
|
3621
|
-
...
|
|
3622
|
-
...!
|
|
3623
|
-
...
|
|
3624
|
-
...
|
|
3659
|
+
...import_shared93.Guards.isDefined(optionsMw) && !import_shared93.Guards.isNullOrEmpty(opts.routes) ? [optionsMw] : [],
|
|
3660
|
+
...!import_shared93.Guards.isNullOrEmpty(opts.routes) ? [methodCheckMw] : [],
|
|
3661
|
+
...import_shared93.Guards.isDefined(corsMw) ? [corsMw] : [],
|
|
3662
|
+
...import_shared93.Guards.isDefined(rateLimitMw) ? [rateLimitMw] : [],
|
|
3625
3663
|
authMw,
|
|
3626
|
-
...!
|
|
3664
|
+
...!import_shared93.Guards.isNullOrEmpty(csrfMws) ? csrfMws : []
|
|
3627
3665
|
];
|
|
3628
|
-
container.addSingleton(
|
|
3666
|
+
container.addSingleton(import_shared94.TOKENS.MIDDLEWARE, () => new CompositeMiddleware(pipeline));
|
|
3629
3667
|
container.addSingleton(
|
|
3630
|
-
|
|
3668
|
+
import_shared94.TOKENS.HTTP_DISPATCHER,
|
|
3631
3669
|
(c) => new HttpDispatcher(
|
|
3632
|
-
c.resolve(
|
|
3633
|
-
c.resolve(
|
|
3634
|
-
c.resolve(
|
|
3670
|
+
c.resolve(import_shared94.TOKENS.REQUEST_CONTEXT),
|
|
3671
|
+
c.resolve(import_shared94.TOKENS.MIDDLEWARE),
|
|
3672
|
+
c.resolve(import_shared94.TOKENS.SERVICE_PROXY)
|
|
3635
3673
|
)
|
|
3636
3674
|
);
|
|
3637
3675
|
}
|
|
3638
3676
|
_buildCookieResponseMiddleware(opts, requestContext) {
|
|
3639
|
-
if (!
|
|
3677
|
+
if (!import_shared93.Guards.isDefined(opts.isSSR) || !opts.isSSR) return void 0;
|
|
3640
3678
|
return new CookieResponseMiddleware(requestContext);
|
|
3641
3679
|
}
|
|
3642
3680
|
_buildCsrfMiddlewares(opts, container, requestContext, routePolicyCheck) {
|
|
3643
|
-
if (!
|
|
3681
|
+
if (!import_shared93.Guards.isDefined(opts.csrf)) return [];
|
|
3644
3682
|
const csrf = opts.csrf;
|
|
3645
|
-
container.addSingleton(
|
|
3646
|
-
container.addSingleton(
|
|
3647
|
-
return new CsrfTokenService(csrf.secret, c.resolve(
|
|
3683
|
+
container.addSingleton(import_shared94.TOKENS.CRYPTO_SERVICE, () => new EdgeCryptoService());
|
|
3684
|
+
container.addSingleton(import_shared94.TOKENS.CSRF_TOKEN_SERVICE, (c) => {
|
|
3685
|
+
return new CsrfTokenService(csrf.secret, c.resolve(import_shared94.TOKENS.CRYPTO_SERVICE));
|
|
3648
3686
|
});
|
|
3649
3687
|
return [
|
|
3650
|
-
new CsrfCookieMiddleware(requestContext, container.resolve(
|
|
3688
|
+
new CsrfCookieMiddleware(requestContext, container.resolve(import_shared94.TOKENS.CSRF_TOKEN_SERVICE), csrf),
|
|
3651
3689
|
new CsrfMiddleware(
|
|
3652
3690
|
requestContext,
|
|
3653
|
-
container.resolve(
|
|
3691
|
+
container.resolve(import_shared94.TOKENS.CSRF_TOKEN_SERVICE),
|
|
3654
3692
|
routePolicyCheck
|
|
3655
3693
|
)
|
|
3656
3694
|
];
|
|
3657
3695
|
}
|
|
3658
3696
|
async _buildRateLimitMiddleware(opts, container, requestContext, logger) {
|
|
3659
|
-
if (
|
|
3697
|
+
if (import_shared93.Guards.isDefined(opts.rateLimit?.enabled) && opts.rateLimit?.enabled) {
|
|
3660
3698
|
const maxRequests = opts.rateLimit?.maxRequests ?? 100;
|
|
3661
3699
|
const windowSeconds = opts.rateLimit?.windowSeconds ?? 60;
|
|
3662
|
-
if (!container.isRegistered(
|
|
3700
|
+
if (!container.isRegistered(import_shared94.TOKENS.CACHE)) {
|
|
3663
3701
|
await new CacheModule().configure(container);
|
|
3664
3702
|
}
|
|
3665
3703
|
return new RateLimitMiddleware(
|
|
3666
3704
|
requestContext,
|
|
3667
|
-
container.resolve(
|
|
3705
|
+
container.resolve(import_shared94.TOKENS.CACHE),
|
|
3668
3706
|
new RateLimitKeyBuilder(requestContext),
|
|
3669
3707
|
logger,
|
|
3670
3708
|
{ maxRequests, windowSeconds }
|
|
@@ -3672,12 +3710,12 @@ var MiddlewareModule = class {
|
|
|
3672
3710
|
}
|
|
3673
3711
|
}
|
|
3674
3712
|
_buildCorsMiddleware(opts, requestContext, withCredentials, routePolicyCheck) {
|
|
3675
|
-
if (
|
|
3713
|
+
if (import_shared93.Guards.isDefined(opts.cors?.enabled) && opts.cors.enabled) {
|
|
3676
3714
|
return new CORSMiddleware(requestContext, routePolicyCheck, withCredentials);
|
|
3677
3715
|
}
|
|
3678
3716
|
}
|
|
3679
3717
|
_buildOptionsMiddleware(opts, requestContext, allowMethod, withCredentials, routePolicyCheck) {
|
|
3680
|
-
if (
|
|
3718
|
+
if (import_shared93.Guards.isDefined(opts.cors?.enablePreflight) && opts.cors?.enablePreflight) {
|
|
3681
3719
|
const allowHeaders = Array.from(
|
|
3682
3720
|
/* @__PURE__ */ new Set([
|
|
3683
3721
|
"x-csrf-token",
|
|
@@ -3709,14 +3747,14 @@ var MiddlewareModule = class {
|
|
|
3709
3747
|
}
|
|
3710
3748
|
}
|
|
3711
3749
|
_createAuthMiddleware(container, requestContext, logger, opts) {
|
|
3712
|
-
if (!container.isRegistered(
|
|
3750
|
+
if (!container.isRegistered(import_shared94.TOKENS.TOKEN_SERVICE_EXTRACTOR)) {
|
|
3713
3751
|
container.addSingleton(
|
|
3714
|
-
|
|
3752
|
+
import_shared94.TOKENS.TOKEN_SERVICE_EXTRACTOR,
|
|
3715
3753
|
() => new BearerTokenExtractor(opts.authCookieName ?? "sb-access-token")
|
|
3716
3754
|
);
|
|
3717
3755
|
}
|
|
3718
|
-
const tokenExtractor = container.resolve(
|
|
3719
|
-
if (!container.isRegistered(
|
|
3756
|
+
const tokenExtractor = container.resolve(import_shared94.TOKENS.TOKEN_SERVICE_EXTRACTOR);
|
|
3757
|
+
if (!container.isRegistered(import_shared94.TOKENS.BASE_AUTH_SERVICE)) {
|
|
3720
3758
|
return new AuthenticationMiddleware(
|
|
3721
3759
|
requestContext,
|
|
3722
3760
|
tokenExtractor,
|
|
@@ -3729,10 +3767,10 @@ var MiddlewareModule = class {
|
|
|
3729
3767
|
tokenExtractor,
|
|
3730
3768
|
new GateKeeper(() => {
|
|
3731
3769
|
const scope = requestContext.getScope();
|
|
3732
|
-
if (!
|
|
3770
|
+
if (!import_shared93.Guards.isDefined(scope)) {
|
|
3733
3771
|
throw new Error("[GateKeeper Error]: No active scope found.");
|
|
3734
3772
|
}
|
|
3735
|
-
return scope.resolve(
|
|
3773
|
+
return scope.resolve(import_shared94.TOKENS.BASE_AUTH_SERVICE);
|
|
3736
3774
|
}, new ClaimsIdentityMapper()),
|
|
3737
3775
|
logger
|
|
3738
3776
|
);
|
|
@@ -3740,43 +3778,43 @@ var MiddlewareModule = class {
|
|
|
3740
3778
|
};
|
|
3741
3779
|
|
|
3742
3780
|
// src/infrastructure/modules/route.module.ts
|
|
3743
|
-
var import_shared94 = require("@xeno-js/shared");
|
|
3744
3781
|
var import_shared95 = require("@xeno-js/shared");
|
|
3782
|
+
var import_shared96 = require("@xeno-js/shared");
|
|
3745
3783
|
var RouteModule = class {
|
|
3746
3784
|
async configure(container, opts) {
|
|
3747
3785
|
container.addSingleton(
|
|
3748
|
-
|
|
3786
|
+
import_shared96.TOKENS.ROUTE_MATCHER,
|
|
3749
3787
|
() => new RouteMatcherFactory().create(opts)
|
|
3750
3788
|
);
|
|
3751
|
-
if (!container.isRegistered(
|
|
3752
|
-
const requestContext = container.resolve(
|
|
3753
|
-
container.addSingleton(
|
|
3789
|
+
if (!container.isRegistered(import_shared96.TOKENS.MIDDLEWARE)) {
|
|
3790
|
+
const requestContext = container.resolve(import_shared96.TOKENS.REQUEST_CONTEXT);
|
|
3791
|
+
container.addSingleton(import_shared96.TOKENS.MIDDLEWARE, () => ({
|
|
3754
3792
|
execute: async (req, next) => {
|
|
3755
3793
|
const syntheticContext = {
|
|
3756
|
-
identity:
|
|
3794
|
+
identity: import_shared95.GUEST,
|
|
3757
3795
|
network: {
|
|
3758
|
-
requestId:
|
|
3796
|
+
requestId: import_shared95.GuidHelper.generate(),
|
|
3759
3797
|
clientIp: "127.0.0.1",
|
|
3760
3798
|
path: req.path,
|
|
3761
3799
|
formatIndicator: "application/json"
|
|
3762
3800
|
},
|
|
3763
3801
|
tracing: {
|
|
3764
|
-
correlationId:
|
|
3802
|
+
correlationId: import_shared95.GuidHelper.generate(),
|
|
3765
3803
|
startTime: Date.now(),
|
|
3766
|
-
spanId:
|
|
3804
|
+
spanId: import_shared95.GuidHelper.generate()
|
|
3767
3805
|
}
|
|
3768
3806
|
};
|
|
3769
3807
|
return await requestContext.runAsync(syntheticContext, next);
|
|
3770
3808
|
}
|
|
3771
3809
|
}));
|
|
3772
3810
|
}
|
|
3773
|
-
if (!container.isRegistered(
|
|
3811
|
+
if (!container.isRegistered(import_shared96.TOKENS.HTTP_DISPATCHER)) {
|
|
3774
3812
|
container.addSingleton(
|
|
3775
|
-
|
|
3813
|
+
import_shared96.TOKENS.HTTP_DISPATCHER,
|
|
3776
3814
|
(c) => new HttpDispatcher(
|
|
3777
|
-
c.resolve(
|
|
3778
|
-
c.resolve(
|
|
3779
|
-
c.resolve(
|
|
3815
|
+
c.resolve(import_shared96.TOKENS.REQUEST_CONTEXT),
|
|
3816
|
+
c.resolve(import_shared96.TOKENS.MIDDLEWARE),
|
|
3817
|
+
c.resolve(import_shared96.TOKENS.SERVICE_PROXY)
|
|
3780
3818
|
)
|
|
3781
3819
|
);
|
|
3782
3820
|
}
|
|
@@ -3802,12 +3840,12 @@ var withAuth = (setup) => {
|
|
|
3802
3840
|
};
|
|
3803
3841
|
|
|
3804
3842
|
// src/infrastructure/plugin/authz.plugin.ts
|
|
3805
|
-
var
|
|
3843
|
+
var import_shared97 = require("@xeno-js/shared");
|
|
3806
3844
|
var withAuthZ = (setup) => {
|
|
3807
3845
|
return definePlugin(
|
|
3808
3846
|
"pipeline",
|
|
3809
3847
|
(_builder, config, context) => {
|
|
3810
|
-
if (!
|
|
3848
|
+
if (!import_shared97.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3811
3849
|
const options = {
|
|
3812
3850
|
policies: void 0
|
|
3813
3851
|
};
|
|
@@ -3818,28 +3856,28 @@ var withAuthZ = (setup) => {
|
|
|
3818
3856
|
};
|
|
3819
3857
|
|
|
3820
3858
|
// src/infrastructure/plugin/concurrency.plugin.ts
|
|
3821
|
-
var
|
|
3859
|
+
var import_shared98 = require("@xeno-js/shared");
|
|
3822
3860
|
var withConcurrency = (setup) => {
|
|
3823
3861
|
return definePlugin(
|
|
3824
3862
|
"pipeline",
|
|
3825
3863
|
(_builder, config, context) => {
|
|
3826
|
-
if (!
|
|
3864
|
+
if (!import_shared98.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
3827
3865
|
const options = {};
|
|
3828
|
-
if (
|
|
3866
|
+
if (import_shared98.Guards.isDefined(setup)) setup(options, config);
|
|
3829
3867
|
context.addCommand(new ConcurrencyRetryPipeline(options), 70);
|
|
3830
3868
|
}
|
|
3831
3869
|
);
|
|
3832
3870
|
};
|
|
3833
3871
|
|
|
3834
3872
|
// src/infrastructure/plugin/http.plugin.ts
|
|
3835
|
-
var
|
|
3873
|
+
var import_shared104 = require("@xeno-js/shared");
|
|
3836
3874
|
|
|
3837
3875
|
// src/infrastructure/modules/http-core.module.ts
|
|
3838
|
-
var import_shared101 = require("@xeno-js/shared");
|
|
3839
3876
|
var import_shared102 = require("@xeno-js/shared");
|
|
3877
|
+
var import_shared103 = require("@xeno-js/shared");
|
|
3840
3878
|
|
|
3841
3879
|
// src/infrastructure/datasources/remote.datasource.ts
|
|
3842
|
-
var
|
|
3880
|
+
var import_shared99 = require("@xeno-js/shared");
|
|
3843
3881
|
var RemoteDataSource = class {
|
|
3844
3882
|
/** The constructor of the RemoteDataSource class takes two dependencies: an instance of an agnostic HTTP client that implements the IHttpClient interface, and an instance of a resilience service that implements the IServiceResilience interface.
|
|
3845
3883
|
* These dependencies are injected into the class, allowing for greater flexibility and testability.
|
|
@@ -3882,13 +3920,13 @@ var RemoteDataSource = class {
|
|
|
3882
3920
|
case "DELETE":
|
|
3883
3921
|
return await this._httpClient.delete(endpoint, options);
|
|
3884
3922
|
default:
|
|
3885
|
-
throw
|
|
3923
|
+
throw import_shared99.AppError.notSupported(
|
|
3886
3924
|
this.constructor.name,
|
|
3887
3925
|
`Unsupported HTTP method: ${options.method}`
|
|
3888
3926
|
);
|
|
3889
3927
|
}
|
|
3890
3928
|
}, options.signal);
|
|
3891
|
-
return
|
|
3929
|
+
return import_shared99.Result.ok(response.data);
|
|
3892
3930
|
}
|
|
3893
3931
|
setOptions(request, method, body = void 0) {
|
|
3894
3932
|
return {
|
|
@@ -3924,7 +3962,7 @@ var RemoteDataSource = class {
|
|
|
3924
3962
|
};
|
|
3925
3963
|
|
|
3926
3964
|
// src/infrastructure/factories/http.factory.ts
|
|
3927
|
-
var
|
|
3965
|
+
var import_shared100 = require("@xeno-js/shared");
|
|
3928
3966
|
var HttpClientFactory = class {
|
|
3929
3967
|
_clients = /* @__PURE__ */ new Map();
|
|
3930
3968
|
add(name, client) {
|
|
@@ -3935,9 +3973,9 @@ var HttpClientFactory = class {
|
|
|
3935
3973
|
}
|
|
3936
3974
|
get(name = "default") {
|
|
3937
3975
|
const client = this._clients.get(name);
|
|
3938
|
-
if (!
|
|
3976
|
+
if (!import_shared100.Guards.isDefined(client)) {
|
|
3939
3977
|
const available = Array.from(this._clients.keys()).join(", ") ?? "none";
|
|
3940
|
-
throw
|
|
3978
|
+
throw import_shared100.AppError.notFound(
|
|
3941
3979
|
"HttpClientFactory",
|
|
3942
3980
|
`[HttpClientFactory Error]: Client '${name}' not found. Available clients: [${available}].`
|
|
3943
3981
|
);
|
|
@@ -3947,10 +3985,10 @@ var HttpClientFactory = class {
|
|
|
3947
3985
|
};
|
|
3948
3986
|
|
|
3949
3987
|
// src/infrastructure/services/resiliences/resilience.service.ts
|
|
3950
|
-
var
|
|
3988
|
+
var import_shared101 = require("@xeno-js/shared");
|
|
3951
3989
|
var NoOpResilienceService = class {
|
|
3952
3990
|
async execute(operation, signal) {
|
|
3953
|
-
|
|
3991
|
+
import_shared101.AppError.throwIfAborted(signal, "NoOpResilienceService.execute");
|
|
3954
3992
|
return await operation();
|
|
3955
3993
|
}
|
|
3956
3994
|
};
|
|
@@ -3965,10 +4003,10 @@ var HttpCoreModule = class {
|
|
|
3965
4003
|
const dataSource = new RemoteDataSource(entry.client(container), resilience);
|
|
3966
4004
|
factory.add(clientName, dataSource);
|
|
3967
4005
|
}
|
|
3968
|
-
container.addSingleton(
|
|
4006
|
+
container.addSingleton(import_shared103.TOKENS.HTTP_CLIENT_FACTORY, () => factory);
|
|
3969
4007
|
}
|
|
3970
4008
|
getResilienceService(container, resilience) {
|
|
3971
|
-
if (!
|
|
4009
|
+
if (!import_shared102.Guards.isDefined(resilience)) {
|
|
3972
4010
|
return new NoOpResilienceService();
|
|
3973
4011
|
} else {
|
|
3974
4012
|
return resilience(container);
|
|
@@ -3981,9 +4019,9 @@ var withCustomHttp = (config) => {
|
|
|
3981
4019
|
return definePlugin(
|
|
3982
4020
|
"http",
|
|
3983
4021
|
(builder, _config) => {
|
|
3984
|
-
const clientEntries =
|
|
4022
|
+
const clientEntries = import_shared104.Guards.isArray(config.clients) ? config.clients : [config.clients];
|
|
3985
4023
|
const entries = clientEntries.map((item) => {
|
|
3986
|
-
if (!
|
|
4024
|
+
if (!import_shared104.Guards.isDefined(item.client)) {
|
|
3987
4025
|
throw new Error(
|
|
3988
4026
|
`[withCustomHttp Error]: 'client' instance is required for registration '${item.name ?? "default"}'.`
|
|
3989
4027
|
);
|
|
@@ -4002,29 +4040,43 @@ var withCustomHttp = (config) => {
|
|
|
4002
4040
|
};
|
|
4003
4041
|
|
|
4004
4042
|
// src/infrastructure/plugin/idempotency.plugin.ts
|
|
4005
|
-
var
|
|
4043
|
+
var import_shared105 = require("@xeno-js/shared");
|
|
4006
4044
|
var withIdempotency = (setup) => {
|
|
4007
4045
|
return definePlugin(
|
|
4008
4046
|
"pipeline",
|
|
4009
4047
|
(_builder, config, context) => {
|
|
4010
|
-
if (!
|
|
4048
|
+
if (!import_shared105.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4011
4049
|
const options = {};
|
|
4012
|
-
if (
|
|
4050
|
+
if (import_shared105.Guards.isDefined(setup)) setup(options, config);
|
|
4013
4051
|
context.idempotencyOpts = options;
|
|
4014
4052
|
}
|
|
4015
4053
|
);
|
|
4016
4054
|
};
|
|
4017
4055
|
|
|
4056
|
+
// src/infrastructure/plugin/identity-enrichment.plugin.ts
|
|
4057
|
+
var import_shared106 = require("@xeno-js/shared");
|
|
4058
|
+
var withEnrichmentIdentity = (setup) => {
|
|
4059
|
+
return definePlugin(
|
|
4060
|
+
"pipeline",
|
|
4061
|
+
(_builder, config, context) => {
|
|
4062
|
+
if (!import_shared106.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4063
|
+
const options = {};
|
|
4064
|
+
if (import_shared106.Guards.isDefined(setup)) setup(options, config);
|
|
4065
|
+
context.identityEnrichmentOpts = options;
|
|
4066
|
+
}
|
|
4067
|
+
);
|
|
4068
|
+
};
|
|
4069
|
+
|
|
4018
4070
|
// src/infrastructure/plugin/logger.plugin.ts
|
|
4019
|
-
var
|
|
4071
|
+
var import_shared107 = require("@xeno-js/shared");
|
|
4020
4072
|
var withConsoleLogger = (setup) => {
|
|
4021
4073
|
return definePlugin(
|
|
4022
4074
|
"logger",
|
|
4023
4075
|
(_builder, config, ctx) => {
|
|
4024
|
-
if (!
|
|
4076
|
+
if (!import_shared107.Guards.isDefined(ctx)) throw new Error("LoggerSetup is not defined.");
|
|
4025
4077
|
const options = {
|
|
4026
4078
|
isEnabled: true,
|
|
4027
|
-
level:
|
|
4079
|
+
level: import_shared107.LOG_LEVEL.DEBUG
|
|
4028
4080
|
};
|
|
4029
4081
|
setup(options, config);
|
|
4030
4082
|
ctx.addConsole(options.isEnabled ?? true, options.level);
|
|
@@ -4033,16 +4085,16 @@ var withConsoleLogger = (setup) => {
|
|
|
4033
4085
|
};
|
|
4034
4086
|
|
|
4035
4087
|
// src/infrastructure/plugin/performance.plugin.ts
|
|
4036
|
-
var
|
|
4037
|
-
var
|
|
4088
|
+
var import_shared108 = require("@xeno-js/shared");
|
|
4089
|
+
var import_shared109 = require("@xeno-js/shared");
|
|
4038
4090
|
var withPerformance = (setup) => {
|
|
4039
4091
|
return definePlugin(
|
|
4040
4092
|
"pipeline",
|
|
4041
4093
|
(builder, config, context) => {
|
|
4042
|
-
if (!
|
|
4094
|
+
if (!import_shared108.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4043
4095
|
const options = {};
|
|
4044
|
-
if (
|
|
4045
|
-
const logger = builder.resolve(
|
|
4096
|
+
if (import_shared108.Guards.isDefined(setup)) setup(options, config);
|
|
4097
|
+
const logger = builder.resolve(import_shared109.TOKENS.LOGGER);
|
|
4046
4098
|
context.addCommon(
|
|
4047
4099
|
new PerformancePipeline(logger, options?.intentThresholdMs, options?.thresholdMs ?? 500),
|
|
4048
4100
|
20
|
|
@@ -4052,27 +4104,27 @@ var withPerformance = (setup) => {
|
|
|
4052
4104
|
};
|
|
4053
4105
|
|
|
4054
4106
|
// src/infrastructure/plugin/query.plugin.ts
|
|
4055
|
-
var
|
|
4107
|
+
var import_shared110 = require("@xeno-js/shared");
|
|
4056
4108
|
var withQueryCaching = () => {
|
|
4057
4109
|
return definePlugin(
|
|
4058
4110
|
"pipeline",
|
|
4059
4111
|
(_builder, _config, context) => {
|
|
4060
|
-
if (!
|
|
4112
|
+
if (!import_shared110.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4061
4113
|
context.addQuery();
|
|
4062
4114
|
}
|
|
4063
4115
|
);
|
|
4064
4116
|
};
|
|
4065
4117
|
|
|
4066
4118
|
// src/infrastructure/plugin/validation.plugin.ts
|
|
4067
|
-
var
|
|
4119
|
+
var import_shared111 = require("@xeno-js/shared");
|
|
4068
4120
|
var withValidation = (setup) => {
|
|
4069
4121
|
return definePlugin(
|
|
4070
4122
|
"pipeline",
|
|
4071
4123
|
(_builder, config, context) => {
|
|
4072
|
-
if (!
|
|
4124
|
+
if (!import_shared111.Guards.isDefined(context)) throw new Error("Pipeline setup is not available.");
|
|
4073
4125
|
const strategies = [];
|
|
4074
4126
|
setup(strategies, config);
|
|
4075
|
-
if (
|
|
4127
|
+
if (import_shared111.Guards.isNullOrEmpty(strategies)) return;
|
|
4076
4128
|
const validationPipeline = new ValidationPipeline(strategies);
|
|
4077
4129
|
context.addCommon(validationPipeline, 50);
|
|
4078
4130
|
}
|
|
@@ -4080,8 +4132,8 @@ var withValidation = (setup) => {
|
|
|
4080
4132
|
};
|
|
4081
4133
|
|
|
4082
4134
|
// src/infrastructure/xeno_application/xeno.application.ts
|
|
4083
|
-
var
|
|
4084
|
-
var
|
|
4135
|
+
var import_shared112 = require("@xeno-js/shared");
|
|
4136
|
+
var import_shared113 = require("@xeno-js/shared");
|
|
4085
4137
|
var XenoApplication = class {
|
|
4086
4138
|
constructor(_container) {
|
|
4087
4139
|
this._container = _container;
|
|
@@ -4104,11 +4156,11 @@ var XenoApplication = class {
|
|
|
4104
4156
|
* @returns {ServicesProxy<TRegistry>} The services proxy.
|
|
4105
4157
|
*/
|
|
4106
4158
|
getScopedServices() {
|
|
4107
|
-
const serviceProxy = this._container.resolve(
|
|
4108
|
-
const requestContext = this._container.resolve(
|
|
4159
|
+
const serviceProxy = this._container.resolve(import_shared113.TOKENS.SERVICE_PROXY);
|
|
4160
|
+
const requestContext = this._container.resolve(import_shared113.TOKENS.REQUEST_CONTEXT);
|
|
4109
4161
|
const scope = requestContext.getScope();
|
|
4110
|
-
if (!
|
|
4111
|
-
throw
|
|
4162
|
+
if (!import_shared112.Guards.isDefined(scope)) {
|
|
4163
|
+
throw import_shared112.AppError.notFound(
|
|
4112
4164
|
"[XenoApplication Error]",
|
|
4113
4165
|
'Active scope not found.\nPlease use the "runInScope" or "handle" method for tasks outside the HTTP transport.'
|
|
4114
4166
|
);
|
|
@@ -4122,25 +4174,25 @@ var XenoApplication = class {
|
|
|
4122
4174
|
* @returns {Promise<T>} The result of the operation.
|
|
4123
4175
|
*/
|
|
4124
4176
|
async runInScope(operation, ctx = void 0) {
|
|
4125
|
-
const requestContext = this._container.resolve(
|
|
4177
|
+
const requestContext = this._container.resolve(import_shared113.TOKENS.REQUEST_CONTEXT);
|
|
4126
4178
|
const syntheticContext = {
|
|
4127
|
-
identity: ctx?.identity ??
|
|
4179
|
+
identity: ctx?.identity ?? import_shared112.GUEST,
|
|
4128
4180
|
network: ctx?.network ?? {
|
|
4129
|
-
requestId:
|
|
4181
|
+
requestId: import_shared112.GuidHelper.generate(),
|
|
4130
4182
|
clientIp: "127.0.0.1",
|
|
4131
4183
|
path: "internal://scope-runner",
|
|
4132
4184
|
formatIndicator: "application/json"
|
|
4133
4185
|
},
|
|
4134
4186
|
tracing: ctx?.tracing ?? {
|
|
4135
|
-
correlationId:
|
|
4187
|
+
correlationId: import_shared112.GuidHelper.generate(),
|
|
4136
4188
|
startTime: Date.now(),
|
|
4137
|
-
spanId:
|
|
4189
|
+
spanId: import_shared112.GuidHelper.generate()
|
|
4138
4190
|
},
|
|
4139
4191
|
messaging: ctx?.messaging
|
|
4140
4192
|
};
|
|
4141
4193
|
return await requestContext.runAsync(syntheticContext, async () => {
|
|
4142
4194
|
const scope = requestContext.getScope();
|
|
4143
|
-
const serviceProxy = this._container.resolve(
|
|
4195
|
+
const serviceProxy = this._container.resolve(import_shared113.TOKENS.SERVICE_PROXY);
|
|
4144
4196
|
const services = serviceProxy.getServiceProxy(scope);
|
|
4145
4197
|
return await operation(services);
|
|
4146
4198
|
});
|
|
@@ -4154,8 +4206,8 @@ var XenoApplication = class {
|
|
|
4154
4206
|
* @returns A promise that resolves to the output of the controller operation.
|
|
4155
4207
|
*/
|
|
4156
4208
|
async handle(req, token, input) {
|
|
4157
|
-
const dispatcher = this._container.resolve(
|
|
4158
|
-
const adapter = this._container.resolve(
|
|
4209
|
+
const dispatcher = this._container.resolve(import_shared113.TOKENS.HTTP_DISPATCHER);
|
|
4210
|
+
const adapter = this._container.resolve(import_shared113.TOKENS.HTTP_ADAPTER);
|
|
4159
4211
|
const extendedRequest = adapter.adapt(req);
|
|
4160
4212
|
return await dispatcher.handle(extendedRequest, token, input);
|
|
4161
4213
|
}
|
|
@@ -4165,8 +4217,8 @@ var XenoApplication = class {
|
|
|
4165
4217
|
* @returns A promise that resolves to the result of the HTTP server listen method.
|
|
4166
4218
|
*/
|
|
4167
4219
|
async listen(options) {
|
|
4168
|
-
const server = this._container.resolve(
|
|
4169
|
-
const opts = this._container.resolve(
|
|
4220
|
+
const server = this._container.resolve(import_shared113.TOKENS.HTTP_SERVER);
|
|
4221
|
+
const opts = this._container.resolve(import_shared113.TOKENS.SERVER_OPTIONS_FACTORY).create(options);
|
|
4170
4222
|
return await server.listen(opts);
|
|
4171
4223
|
}
|
|
4172
4224
|
};
|
|
@@ -4181,10 +4233,10 @@ var XenoAppBuilder = class {
|
|
|
4181
4233
|
constructor(container, configurationService) {
|
|
4182
4234
|
this._container = container ?? new ServiceContainer();
|
|
4183
4235
|
this._configuration = this._getConfigurationService(configurationService);
|
|
4184
|
-
this._container.addSingleton(
|
|
4236
|
+
this._container.addSingleton(import_shared114.TOKENS.CONFIGURATION_SERVICE, () => this._configuration);
|
|
4185
4237
|
}
|
|
4186
4238
|
_getConfigurationService(service) {
|
|
4187
|
-
if (!
|
|
4239
|
+
if (!import_shared114.Guards.isDefined(service) || service === "node")
|
|
4188
4240
|
return new EnvironmentConfigurationService();
|
|
4189
4241
|
if (service === "vite") return new ViteConfigurationService();
|
|
4190
4242
|
return service;
|
|
@@ -4272,7 +4324,7 @@ var XenoAppBuilder = class {
|
|
|
4272
4324
|
*/
|
|
4273
4325
|
addMiddlewares(setupAction) {
|
|
4274
4326
|
if (this._isMiddlewareModuleQueued) return this;
|
|
4275
|
-
if (
|
|
4327
|
+
if (import_shared114.Guards.isDefined(setupAction)) setupAction(this._middlewareConfig, this._configuration);
|
|
4276
4328
|
this._modules.push({
|
|
4277
4329
|
priority: 4,
|
|
4278
4330
|
name: "MiddlewareModule",
|
|
@@ -4298,7 +4350,7 @@ var XenoAppBuilder = class {
|
|
|
4298
4350
|
*/
|
|
4299
4351
|
addContext(plugin) {
|
|
4300
4352
|
if (this._isContextModuleQueued) return this;
|
|
4301
|
-
if (
|
|
4353
|
+
if (import_shared114.Guards.isDefined(plugin)) plugin(this, this._configuration);
|
|
4302
4354
|
else
|
|
4303
4355
|
this._modules.push({
|
|
4304
4356
|
priority: 0,
|
|
@@ -4313,21 +4365,21 @@ var XenoAppBuilder = class {
|
|
|
4313
4365
|
}
|
|
4314
4366
|
addLogger(pluginOrSetup) {
|
|
4315
4367
|
if (this._isLoggerModuleQueued) return this;
|
|
4316
|
-
if (!
|
|
4368
|
+
if (!import_shared114.Guards.isDefined(pluginOrSetup)) {
|
|
4317
4369
|
this._modules.push({
|
|
4318
4370
|
priority: 1,
|
|
4319
4371
|
name: "LoggerModule",
|
|
4320
4372
|
action: async () => {
|
|
4321
4373
|
const module2 = new LoggerModule();
|
|
4322
4374
|
await module2.configure(this._container, {
|
|
4323
|
-
level:
|
|
4375
|
+
level: import_shared114.LOG_LEVEL.DEBUG,
|
|
4324
4376
|
console: true,
|
|
4325
4377
|
builder: this,
|
|
4326
4378
|
config: this._configuration
|
|
4327
4379
|
});
|
|
4328
4380
|
}
|
|
4329
4381
|
});
|
|
4330
|
-
} else if (
|
|
4382
|
+
} else if (import_shared114.Guards.isArray(pluginOrSetup)) {
|
|
4331
4383
|
this._modules.push({
|
|
4332
4384
|
priority: 1,
|
|
4333
4385
|
name: "LoggerModule",
|
|
@@ -4358,7 +4410,7 @@ var XenoAppBuilder = class {
|
|
|
4358
4410
|
} else {
|
|
4359
4411
|
const loggerConfig = {
|
|
4360
4412
|
console: true,
|
|
4361
|
-
level:
|
|
4413
|
+
level: import_shared114.LOG_LEVEL.DEBUG,
|
|
4362
4414
|
customLoggers: []
|
|
4363
4415
|
};
|
|
4364
4416
|
const setupAction = pluginOrSetup;
|
|
@@ -4381,7 +4433,7 @@ var XenoAppBuilder = class {
|
|
|
4381
4433
|
}
|
|
4382
4434
|
addCache(pluginOrSetup) {
|
|
4383
4435
|
if (this._isCacheModuleQueued) return this;
|
|
4384
|
-
if (!
|
|
4436
|
+
if (!import_shared114.Guards.isDefined(pluginOrSetup))
|
|
4385
4437
|
this._modules.push({
|
|
4386
4438
|
priority: 2,
|
|
4387
4439
|
name: "CacheModule",
|
|
@@ -4455,7 +4507,7 @@ var XenoAppBuilder = class {
|
|
|
4455
4507
|
action: async () => {
|
|
4456
4508
|
const { PLimitConcurrencyService: PLimitConcurrencyService2 } = await Promise.resolve().then(() => (init_concurrency(), concurrency_exports));
|
|
4457
4509
|
this._container.addSingleton(
|
|
4458
|
-
|
|
4510
|
+
import_shared114.TOKENS.CONCURRENCY_SERVICE,
|
|
4459
4511
|
() => new PLimitConcurrencyService2()
|
|
4460
4512
|
);
|
|
4461
4513
|
}
|
|
@@ -4478,8 +4530,8 @@ var XenoAppBuilder = class {
|
|
|
4478
4530
|
*/
|
|
4479
4531
|
addPipeline(pluginOrPlugins) {
|
|
4480
4532
|
if (this._isPipelineModuleQueued) return this;
|
|
4481
|
-
if (
|
|
4482
|
-
this._pipelinePlugins =
|
|
4533
|
+
if (import_shared114.Guards.isDefined(pluginOrPlugins))
|
|
4534
|
+
this._pipelinePlugins = import_shared114.Guards.isArray(pluginOrPlugins) ? pluginOrPlugins : [pluginOrPlugins];
|
|
4483
4535
|
this._modules.push({
|
|
4484
4536
|
priority: 5,
|
|
4485
4537
|
name: "CqrsModule",
|
|
@@ -4580,7 +4632,7 @@ var XenoAppBuilder = class {
|
|
|
4580
4632
|
* @link https://github.com/xeno-js/xeno-js
|
|
4581
4633
|
*/
|
|
4582
4634
|
build() {
|
|
4583
|
-
if (
|
|
4635
|
+
if (import_shared114.Guards.isDefined(this._buildPromise)) {
|
|
4584
4636
|
return this._buildPromise;
|
|
4585
4637
|
}
|
|
4586
4638
|
const attempt = this._executeBuild();
|
|
@@ -4600,7 +4652,7 @@ var XenoAppBuilder = class {
|
|
|
4600
4652
|
async _resetContainer() {
|
|
4601
4653
|
await this._container.dispose();
|
|
4602
4654
|
this._container = new ServiceContainer();
|
|
4603
|
-
this._container.addSingleton(
|
|
4655
|
+
this._container.addSingleton(import_shared114.TOKENS.CONFIGURATION_SERVICE, () => this._configuration);
|
|
4604
4656
|
}
|
|
4605
4657
|
/**
|
|
4606
4658
|
* @description Executes the build process by initializing all registered modules in the container.
|
|
@@ -4626,21 +4678,21 @@ var XenoAppBuilder = class {
|
|
|
4626
4678
|
console.error(`\u{1F449} Module: **${queued.name}**`);
|
|
4627
4679
|
console.error(`\u{1F4DD} Reason: ${errorMessage}
|
|
4628
4680
|
`);
|
|
4629
|
-
if (error instanceof Error &&
|
|
4681
|
+
if (error instanceof Error && import_shared114.Guards.isDefined(error.stack)) {
|
|
4630
4682
|
console.error(error.stack);
|
|
4631
4683
|
}
|
|
4632
4684
|
throw new Error(`Bootstrap failed at [${queued.name}]: ${errorMessage}`, { cause: error });
|
|
4633
4685
|
}
|
|
4634
4686
|
}
|
|
4635
4687
|
console.info("\u2705 Application modules bootstrapped successfully.");
|
|
4636
|
-
if (
|
|
4688
|
+
if (import_shared114.Guards.isDefined(this._appFactory)) return this._appFactory(this._container);
|
|
4637
4689
|
return new XenoApplication(this._container);
|
|
4638
4690
|
}
|
|
4639
4691
|
};
|
|
4640
4692
|
|
|
4641
4693
|
// src/infrastructure/repositories/read-dao.ts
|
|
4642
|
-
var
|
|
4643
|
-
var
|
|
4694
|
+
var import_shared115 = require("@xeno-js/shared");
|
|
4695
|
+
var import_shared116 = require("@xeno-js/shared");
|
|
4644
4696
|
var ReadDao = class {
|
|
4645
4697
|
/**
|
|
4646
4698
|
* Constructs a new ReadDao instance.
|
|
@@ -4660,23 +4712,23 @@ var ReadDao = class {
|
|
|
4660
4712
|
_dataSource;
|
|
4661
4713
|
_mapper;
|
|
4662
4714
|
async findById(id, ctx, signal) {
|
|
4663
|
-
|
|
4715
|
+
import_shared115.AppError.throwIfAborted(signal, "ReadDao.findById");
|
|
4664
4716
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
4665
|
-
if (
|
|
4717
|
+
if (import_shared116.Guards.isNullOrEmpty(result)) return import_shared115.Result.ok();
|
|
4666
4718
|
const entity = this._mapper.toEntity(result);
|
|
4667
|
-
return
|
|
4719
|
+
return import_shared115.Result.ok(entity);
|
|
4668
4720
|
}
|
|
4669
4721
|
async findAll(ctx, signal) {
|
|
4670
|
-
|
|
4722
|
+
import_shared115.AppError.throwIfAborted(signal, "ReadDao.findAll");
|
|
4671
4723
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
4672
4724
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
4673
|
-
return
|
|
4725
|
+
return import_shared115.Result.ok(entities);
|
|
4674
4726
|
}
|
|
4675
4727
|
};
|
|
4676
4728
|
|
|
4677
4729
|
// src/infrastructure/repositories/repository.ts
|
|
4678
|
-
var
|
|
4679
|
-
var
|
|
4730
|
+
var import_shared117 = require("@xeno-js/shared");
|
|
4731
|
+
var import_shared118 = require("@xeno-js/shared");
|
|
4680
4732
|
var Repository = class {
|
|
4681
4733
|
/**
|
|
4682
4734
|
* Constructs a new Repository instance.
|
|
@@ -4696,35 +4748,35 @@ var Repository = class {
|
|
|
4696
4748
|
_dataSource;
|
|
4697
4749
|
_mapper;
|
|
4698
4750
|
async findById(id, ctx, signal) {
|
|
4699
|
-
|
|
4751
|
+
import_shared117.AppError.throwIfAborted(signal, "Repository.findById");
|
|
4700
4752
|
const result = await this._dataSource.findById(id, ctx, signal);
|
|
4701
|
-
if (
|
|
4753
|
+
if (import_shared118.Guards.isNullOrEmpty(result)) return import_shared117.Result.ok();
|
|
4702
4754
|
const entity = this._mapper.toEntity(result);
|
|
4703
|
-
return
|
|
4755
|
+
return import_shared117.Result.ok(entity);
|
|
4704
4756
|
}
|
|
4705
4757
|
async findAll(ctx, signal) {
|
|
4706
|
-
|
|
4758
|
+
import_shared117.AppError.throwIfAborted(signal, "Repository.findAll");
|
|
4707
4759
|
const results = await this._dataSource.findAll(ctx, signal);
|
|
4708
4760
|
const entities = results.map((result) => this._mapper.toEntity(result));
|
|
4709
|
-
return
|
|
4761
|
+
return import_shared117.Result.ok(entities);
|
|
4710
4762
|
}
|
|
4711
4763
|
async save(entity, signal) {
|
|
4712
4764
|
const dto = this._mapper.toDto(entity);
|
|
4713
|
-
|
|
4765
|
+
import_shared117.AppError.throwIfAborted(signal, "Repository.save");
|
|
4714
4766
|
await this._dataSource.insert(dto, signal);
|
|
4715
|
-
return
|
|
4767
|
+
return import_shared117.Result.ok();
|
|
4716
4768
|
}
|
|
4717
4769
|
async delete(entity, ctx, signal) {
|
|
4718
4770
|
const dto = this._mapper.toDto(entity);
|
|
4719
|
-
|
|
4771
|
+
import_shared117.AppError.throwIfAborted(signal, "Repository.delete");
|
|
4720
4772
|
await this._dataSource.delete(dto, ctx, signal);
|
|
4721
|
-
return
|
|
4773
|
+
return import_shared117.Result.ok();
|
|
4722
4774
|
}
|
|
4723
4775
|
async update(id, entity, ctx, signal) {
|
|
4724
4776
|
const dto = this._mapper.toPartialDto(entity);
|
|
4725
|
-
|
|
4777
|
+
import_shared117.AppError.throwIfAborted(signal, "Repository.update");
|
|
4726
4778
|
await this._dataSource.update(id, dto, ctx, signal);
|
|
4727
|
-
return
|
|
4779
|
+
return import_shared117.Result.ok();
|
|
4728
4780
|
}
|
|
4729
4781
|
};
|
|
4730
4782
|
|
|
@@ -4787,6 +4839,7 @@ __reExport(index_exports, require("@xeno-js/shared"), module.exports);
|
|
|
4787
4839
|
withCors,
|
|
4788
4840
|
withCsrf,
|
|
4789
4841
|
withCustomHttp,
|
|
4842
|
+
withEnrichmentIdentity,
|
|
4790
4843
|
withIdempotency,
|
|
4791
4844
|
withPerformance,
|
|
4792
4845
|
withQueryCaching,
|