@xeno-js/shared 0.1.5 → 0.1.7

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.js CHANGED
@@ -657,17 +657,7 @@ var RESILIENCE_DEFAULTS = Object.freeze({
657
657
 
658
658
  // src/shared/constants/tokens.constants.ts
659
659
  var TOKENS = Object.freeze({
660
- ALLOW_ORIGIN: "ALLOW_ORIGIN",
661
- ALLOW_METHOD: "ALLOW_METHOD",
662
- /** @description Token used to register and resolve the AuthorizationPipeline instance in the dependency injection container.
663
- *
664
- * @author Xeno
665
- * @version 1.0.0
666
- * @since 2025-09-30
667
- * @link https://github.com/xeno-js/xeno-js
668
- */
669
- AUTHORIZATION_PIPELINE: "AUTHORIZATION_PIPELINE",
670
- /** @description Token used to register and resolve the AuthService instance in the dependency injection container.
660
+ /** @description Token used to register and resolve the Extendend AuthService instance in the dependency injection container.
671
661
  *
672
662
  * @author Xeno
673
663
  * @version 1.0.0
@@ -675,15 +665,14 @@ var TOKENS = Object.freeze({
675
665
  * @link https://github.com/xeno-js/xeno-js
676
666
  */
677
667
  AUTH_SERVICE: "AUTH_SERVICE",
678
- BASE_AUTH_SERVICE: "BASE_AUTH_SERVICE",
679
- /** @description Token used to register and resolve the BearerTokenExtractor instance in the dependency injection container.
668
+ /** @description Token used to register and resolve the BaseAuthService instance in the dependency injection container.
680
669
  *
681
670
  * @author Xeno
682
671
  * @version 1.0.0
683
672
  * @since 2025-09-30
684
673
  * @link https://github.com/xeno-js/xeno-js
685
674
  */
686
- BEARER_TOKEN_EXTRACTOR: "BEARER_TOKEN_EXTRACTOR",
675
+ BASE_AUTH_SERVICE: "BASE_AUTH_SERVICE",
687
676
  /** @description Token used to register and resolve the InMemoryCache instance in the dependency injection container.
688
677
  *
689
678
  * @author Xeno
@@ -700,14 +689,6 @@ var TOKENS = Object.freeze({
700
689
  * @link https://github.com/xeno-js/xeno-js
701
690
  */
702
691
  CACHE_KEY_BUILDER: "CACHE_KEY_BUILDER",
703
- /** @description Token used to register and resolve the ClaimsIdentityMapper instance in the dependency injection container.
704
- *
705
- * @author Xeno
706
- * @version 1.0.0
707
- * @since 2025-09-30
708
- * @link https://github.com/xeno-js/xeno-js
709
- */
710
- CLAIMS_IDENTITY_MAPPER: "CLAIMS_IDENTITY_MAPPER",
711
692
  /** @description Token used to register and resolve command pipeline behaviors in the dependency injection container.
712
693
  *
713
694
  * @author Xeno
@@ -716,22 +697,6 @@ var TOKENS = Object.freeze({
716
697
  * @link https://github.com/xeno-js/xeno-js
717
698
  */
718
699
  COMMAND_PIPELINES_BEHAVIOR: "COMMAND_PIPELINES_BEHAVIOR",
719
- /** @description Token used to register and resolve the CompositePipeline instance in the dependency injection container.
720
- *
721
- * @author Xeno
722
- * @version 1.0.0
723
- * @since 2025-09-30
724
- * @link https://github.com/xeno-js/xeno-js
725
- */
726
- COMPOSITE_PIPELINE: "COMPOSITE_PIPELINE",
727
- /** @description Token used to register and resolve the ConcurrencyRetryPipeline instance in the dependency injection container.
728
- *
729
- * @author Xeno
730
- * @version 1.0.0
731
- * @since 2025-09-30
732
- * @link https://github.com/xeno-js/xeno-js
733
- */
734
- CONCURRENCY_RETRY_PIPELINE: "CONCURRENCY_RETRY_PIPELINE",
735
700
  /** @description Token used to register and resolve the ConcurrencyService instance in the dependency injection container.
736
701
  *
737
702
  * @author Xeno
@@ -748,14 +713,6 @@ var TOKENS = Object.freeze({
748
713
  * @link https://github.com/xeno-js/xeno-js
749
714
  */
750
715
  CONFIGURATION_SERVICE: "CONFIGURATION_SERVICE",
751
- /** @description Token used to register and resolve the ConsoleLogger instance in the dependency injection container.
752
- *
753
- * @author Xeno
754
- * @version 1.0.0
755
- * @since 2025-09-30
756
- * @link https://github.com/xeno-js/xeno-js
757
- */
758
- CONSOLE_LOGGER: "CONSOLE_LOGGER",
759
716
  /** @description Token used to register and resolve the ContextAccessor instance in the dependency injection container.
760
717
  *
761
718
  * @author Xeno
@@ -764,46 +721,30 @@ var TOKENS = Object.freeze({
764
721
  * @link https://github.com/xeno-js/xeno-js
765
722
  */
766
723
  CONTEXT_ACCESSOR: "CONTEXT_ACCESSOR",
767
- /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
768
- *
769
- * @author Xeno
770
- * @version 1.0.0
771
- * @since 2025-09-30
772
- * @link https://github.com/xeno-js/xeno-js
773
- */
774
- DB_CONTEXT: "DB_CONTEXT",
775
- /** @description Token used to register and resolve the ExceptionPipeline instance in the dependency injection container.
776
- *
777
- * @author Xeno
778
- * @version 1.0.0
779
- * @since 2025-09-30
780
- * @link https://github.com/xeno-js/xeno-js
781
- */
782
- EXCEPTION_PIPELINE: "EXCEPTION_PIPELINE",
783
- /** @description Token used to register and resolve the GateKeeper instance in the dependency injection container.
724
+ /** @description Token used to register and resolve the CryptoService instance in the dependency injection container.
784
725
  *
785
726
  * @author Xeno
786
727
  * @version 1.0.0
787
728
  * @since 2025-09-30
788
729
  * @link https://github.com/xeno-js/xeno-js
789
730
  */
790
- GATE_KEEPER: "GATE_KEEPER",
791
- /** @description Token used to register and resolve the IdempotencyPipeline instance in the dependency injection container.
731
+ CRYPTO_SERVICE: "CRYPTO_SERVICE",
732
+ /** @description Token used to register and resolve the CsrfTokenService instance in the dependency injection container.
792
733
  *
793
734
  * @author Xeno
794
735
  * @version 1.0.0
795
736
  * @since 2025-09-30
796
737
  * @link https://github.com/xeno-js/xeno-js
797
738
  */
798
- IDEMPOTENCY_PIPELINE: "IDEMPOTENCY_PIPELINE",
799
- /** @description Token used to register and resolve the IdempotencyStore instance in the dependency injection container.
739
+ CSRF_TOKEN_SERVICE: "CSRF_TOKEN_SERVICE",
740
+ /** @description Token used to register and resolve the DbContext instance in the dependency injection container.
800
741
  *
801
742
  * @author Xeno
802
743
  * @version 1.0.0
803
744
  * @since 2025-09-30
804
745
  * @link https://github.com/xeno-js/xeno-js
805
746
  */
806
- IDEMPOTENCY_STORE: "IDEMPOTENCY_STORE",
747
+ DB_CONTEXT: "DB_CONTEXT",
807
748
  /** @description Token used to register and resolve the IdentityAccessor instance in the dependency injection container.
808
749
  *
809
750
  * @author Xeno
@@ -820,22 +761,6 @@ var TOKENS = Object.freeze({
820
761
  * @link https://github.com/xeno-js/xeno-js
821
762
  */
822
763
  LOGGER: "LOGGER",
823
- /** @description Token used to register and resolve the LoggerConfig instance in the dependency injection container.
824
- *
825
- * @author Xeno
826
- * @version 1.0.0
827
- * @since 2025-09-30
828
- * @link https://github.com/xeno-js/xeno-js
829
- */
830
- LOGGER_CONFIG: "LOGGER_CONFIG",
831
- /** @description Token used to register and resolve the LoggingPipeline instance in the dependency injection container.
832
- *
833
- * @author Xeno
834
- * @version 1.0.0
835
- * @since 2025-09-30
836
- * @link https://github.com/xeno-js/xeno-js
837
- */
838
- LOGGING_PIPELINE: "LOGGING_PIPELINE",
839
764
  /** @description Token used to register and resolve the Mediator instance in the dependency injection container.
840
765
  *
841
766
  * @author Xeno
@@ -844,46 +769,14 @@ var TOKENS = Object.freeze({
844
769
  * @link https://github.com/xeno-js/xeno-js
845
770
  */
846
771
  MEDIATOR: "MEDIATOR",
847
- /** @description Token used to register and resolve the PerformancePipeline instance in the dependency injection container.
848
- *
849
- * @author Xeno
850
- * @version 1.0.0
851
- * @since 2025-09-30
852
- * @link https://github.com/xeno-js/xeno-js
853
- */
854
- PERFORMANCE_PIPELINE: "PERFORMANCE_PIPELINE",
855
- /** @description Token used to register and resolve the PermissionAuthorizationPipeline instance in the dependency injection container.
856
- *
857
- * @author Xeno
858
- * @version 1.0.0
859
- * @since 2025-09-30
860
- * @link https://github.com/xeno-js/xeno-js
861
- */
862
- PERMISSION_AUTHORIZATION_PIPELINE: "PERMISSION_AUTHORIZATION_PIPELINE",
863
- /** @description Token used to register and resolve the PinoLogger instance in the dependency injection container.
772
+ /** @description Token used to register and resolve the NetworkContextFactory in the dependency injection container.
864
773
  *
865
774
  * @author Xeno
866
775
  * @version 1.0.0
867
776
  * @since 2025-09-30
868
777
  * @link https://github.com/xeno-js/xeno-js
869
778
  */
870
- PINO_LOGGER: "PINO_LOGGER",
871
- /** @description Token used to register and resolve the PolicyRegistry instance in the dependency injection container.
872
- *
873
- * @author Xeno
874
- * @version 1.0.0
875
- * @since 2025-09-30
876
- * @link https://github.com/xeno-js/xeno-js
877
- */
878
- POLICY_REGISTRY: "POLICY_REGISTRY",
879
- /** @description Token used to register and resolve the QueryCachingPipeline instance in the dependency injection container.
880
- *
881
- * @author Xeno
882
- * @version 1.0.0
883
- * @since 2025-09-30
884
- * @link https://github.com/xeno-js/xeno-js
885
- */
886
- QUERY_CACHING_PIPELINE: "QUERY_CACHING_PIPELINE",
779
+ NETWORK_CONTEXT_ACCESSOR: "NETWORK_CONTEXT_ACCESSOR",
887
780
  /** @description Token used to register and resolve query pipeline behaviors in the dependency injection container.
888
781
  *
889
782
  * @author Xeno
@@ -900,7 +793,7 @@ var TOKENS = Object.freeze({
900
793
  * @link https://github.com/xeno-js/xeno-js
901
794
  */
902
795
  REQUEST_CONTEXT: "REQUEST_CONTEXT",
903
- /** @description Token used to register and resolve the RequestContextMiddleware in the dependency injection container.
796
+ /** @description Token used to register and resolve the CompositeMiddleware in the dependency injection container.
904
797
  *
905
798
  * @author Xeno
906
799
  * @version 1.0.0
@@ -908,14 +801,6 @@ var TOKENS = Object.freeze({
908
801
  * @link https://github.com/xeno-js/xeno-js
909
802
  */
910
803
  MIDDLEWARE: "MIDDLEWARE",
911
- AUTH_MIDDLEWARE: "AUTH_MIDDLEWARE",
912
- CSRF_MIDDLEWARE: "CSRF_MIDDLEWARE",
913
- ALLOW_ORIGIN_MIDDLEWARE: "ALLOW_ORIGIN_MIDDLEWARE",
914
- CORS_MIDDLEWARE: "CORS_MIDDLEWARE",
915
- METHOD_CHECK_MIDDLEWARE: "METHOD_CHECK_MIDDLEWARE",
916
- OPTIONS_MIDDLEWARE: "OPTIONS_MIDDLEWARE",
917
- REQUEST_CONTEXT_MIDDLEWARE: "REQUEST_CONTEXT_MIDDLEWARE",
918
- RATE_LIMITER_MIDDLEWARE: "RATE_LIMITER_MIDDLEWARE",
919
804
  /** @description Token used to register and resolve the IServiceResilience instance in the dependency injection container.
920
805
  *
921
806
  * @author Xeno
@@ -924,14 +809,6 @@ var TOKENS = Object.freeze({
924
809
  * @link https://github.com/xeno-js/xeno-js
925
810
  */
926
811
  RESILIENCE_CLIENT: "RESILIENCE_CLIENT",
927
- /** @description Token used to register and resolve the RoleAuthorizationPipeline instance in the dependency injection container.
928
- *
929
- * @author Xeno
930
- * @version 1.0.0
931
- * @since 2025-09-30
932
- * @link https://github.com/xeno-js/xeno-js
933
- */
934
- ROLE_AUTHORIZATION_PIPELINE: "ROLE_AUTHORIZATION_PIPELINE",
935
812
  /** @description Token used to register and resolve the SchemaValidationStrategy instance in the dependency injection container.
936
813
  *
937
814
  * @author Xeno
@@ -940,14 +817,6 @@ var TOKENS = Object.freeze({
940
817
  * @link https://github.com/xeno-js/xeno-js
941
818
  */
942
819
  SCHEMA_VALIDATION_STRATEGY: "SCHEMA_VALIDATION_STRATEGY",
943
- /** @description Token used to register and resolve the SentryLogger instance in the dependency injection container.
944
- *
945
- * @author Xeno
946
- * @version 1.0.0
947
- * @since 2025-09-30
948
- * @link https://github.com/xeno-js/xeno-js
949
- */
950
- SENTRY_LOGGER: "SENTRY_LOGGER",
951
820
  /** @description Token used to register and resolve the ServiceContainer instance in the dependency injection container.
952
821
  *
953
822
  * @author Xeno
@@ -964,22 +833,14 @@ var TOKENS = Object.freeze({
964
833
  * @link https://github.com/xeno-js/xeno-js
965
834
  */
966
835
  SERVICE_EXTRACTOR: "SERVICE_EXTRACTOR",
967
- /** @description Token used to register and resolve the ServiceScopeFactory instance in the dependency injection container.
968
- *
969
- * @author Xeno
970
- * @version 1.0.0
971
- * @since 2025-09-30
972
- * @link https://github.com/xeno-js/xeno-js
973
- */
974
- SERVICE_SCOPE_FACTORY: "SERVICE_SCOPE_FACTORY",
975
- /** @description Token used to register and resolve the TenantAuthorizationPipeline instance in the dependency injection container.
836
+ /** @description Token used to register and resolve the ServiceScopeAccessor in the dependency injection container.
976
837
  *
977
838
  * @author Xeno
978
839
  * @version 1.0.0
979
840
  * @since 2025-09-30
980
841
  * @link https://github.com/xeno-js/xeno-js
981
842
  */
982
- TENANT_AUTHORIZATION_PIPELINE: "TENANT_AUTHORIZATION_PIPELINE",
843
+ SERVICE_SCOPE_ACCESSOR: "SERVICE_SCOPE_ACCESSOR",
983
844
  /** @description Token used to register and resolve the UnitOfWork instance in the dependency injection container.
984
845
  *
985
846
  * @author Xeno
@@ -988,34 +849,14 @@ var TOKENS = Object.freeze({
988
849
  * @link https://github.com/xeno-js/xeno-js
989
850
  */
990
851
  UNIT_OF_WORK: "UNIT_OF_WORK",
991
- /** @description Token used to register and resolve the UserAuthorizationPipeline instance in the dependency injection container.
992
- *
993
- * @author Xeno
994
- * @version 1.0.0
995
- * @since 2025-09-30
996
- * @link https://github.com/xeno-js/xeno-js
997
- */
998
- USER_AUTHORIZATION_PIPELINE: "USER_AUTHORIZATION_PIPELINE",
999
- /** @description Token used to register and resolve the ValidationPipeline instance in the dependency injection container.
852
+ /** @description Token used to register and resolve the ValidatorService instance in the dependency injection container.
1000
853
  *
1001
854
  * @author Xeno
1002
855
  * @version 1.0.0
1003
856
  * @since 2025-09-30
1004
857
  * @link https://github.com/xeno-js/xeno-js
1005
858
  */
1006
- VALIDATION_PIPELINE: "VALIDATION_PIPELINE",
1007
- /** @description Token used to register and resolve the ZodValidator instance in the dependency injection container.
1008
- *
1009
- * @author Xeno
1010
- * @version 1.0.0
1011
- * @since 2025-09-30
1012
- * @link https://github.com/xeno-js/xeno-js
1013
- */
1014
- ZOD_VALIDATOR: "ZOD_VALIDATOR",
1015
- SERVICE_SCOPE_ACCESSOR: "SERVICE_SCOPE_ACCESSOR",
1016
- NETWORK_CONTEXT_ACCESSOR: "NETWORK_CONTEXT_ACCESSOR",
1017
- USER_CONTEXT_FACTORY: "USER_CONTEXT_FACTORY",
1018
- TRANSACTION_STATE: "TRANSACTION_STATE"
859
+ VALIDATOR_SERVICE: "VALIDATOR_SERVICE"
1019
860
  });
1020
861
 
1021
862
  // src/shared/utils/guards.utils.ts
@@ -1548,6 +1389,29 @@ var GuidHelper = Object.freeze({
1548
1389
 
1549
1390
  // src/shared/utils/http.utils.ts
1550
1391
  var HttpHelper = Object.freeze({
1392
+ /**
1393
+ * @description A function that masks the IP address in the given headers object.
1394
+ * @param ip The IP address to mask.
1395
+ * @returns The masked IP address.
1396
+ */
1397
+ maskIp(ip) {
1398
+ if (!Guards.isDefined(ip)) return void 0;
1399
+ if (ip.includes(".")) {
1400
+ const parts = ip.split(".");
1401
+ if (parts.length === 4) {
1402
+ parts[3] = "x";
1403
+ return parts.join(".");
1404
+ }
1405
+ }
1406
+ if (ip.includes(":")) {
1407
+ const parts = ip.split(":");
1408
+ if (parts.length > 0) {
1409
+ parts[parts.length - 1] = "x";
1410
+ return parts.join(":");
1411
+ }
1412
+ }
1413
+ return ip;
1414
+ },
1551
1415
  /**
1552
1416
  * @description Normalizes HTTP headers by converting all header values to strings. If a header value is an array, it joins the array elements into a single string separated by commas. This method ensures that the headers are in a consistent format, which can be particularly useful when working with different HTTP client libraries that may represent headers in various ways. If the input headers are not defined or not an object, it returns an empty object.
1553
1417
  * @param headers The input headers to be normalized, which can be of any type. The method checks if the headers are defined and are an object before processing them.
@@ -1998,6 +1862,36 @@ var Query = class {
1998
1862
  type = REQUEST_TYPE.QUERY;
1999
1863
  };
2000
1864
 
1865
+ // src/application/loggers/utils/logger-context.utils.ts
1866
+ var LoggerUtils = Object.freeze({
1867
+ /**
1868
+ * @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
1869
+ * @param ctx The RequestContext object to convert.
1870
+ * @returns The converted LoggerContext object.
1871
+ */
1872
+ toSafeContext(ctx) {
1873
+ return {
1874
+ identity: {
1875
+ userId: ctx?.identity?.userId,
1876
+ tenantId: ctx?.identity?.tenantId
1877
+ },
1878
+ network: {
1879
+ requestId: ctx?.network?.requestId,
1880
+ path: ctx?.network?.path,
1881
+ origin: ctx?.network?.origin,
1882
+ clientIp: HttpHelper.maskIp(ctx?.network?.clientIp)
1883
+ },
1884
+ tracing: {
1885
+ correlationId: ctx?.tracing?.correlationId,
1886
+ spanId: ctx?.tracing?.spanId,
1887
+ startTime: ctx?.tracing?.startTime,
1888
+ parentSpanId: ctx?.tracing.parentSpanId
1889
+ },
1890
+ messaging: ctx?.messaging
1891
+ };
1892
+ }
1893
+ });
1894
+
2001
1895
  // src/application/loggers/base.logger.ts
2002
1896
  var BaseLogger = class {
2003
1897
  /**
@@ -2005,12 +1899,11 @@ var BaseLogger = class {
2005
1899
  * @param _requestContext The request context that provides contextual information for log messages, such as request-specific data or metadata.
2006
1900
  * @param config The minimum log level for this logger instance. Only messages with a log level equal to or higher than this level will be processed and forwarded to the logging clients.
2007
1901
  * @param loggers An array of ILoggerClient instances that will receive log messages from this logger. Each ILoggerClient represents a different logging provider or destination (e.g., console, file, external service).
2008
-
2009
- *
1902
+ *
2010
1903
  * @author Xeno
2011
1904
  * @version 1.0.0
2012
1905
  * @since 2025-09-30
2013
- * @link https://github.com/xeno-js/xeno-js
1906
+ * @link https://github.com/xeno-js/xeno-js
2014
1907
  */
2015
1908
  constructor(_requestContext, config, loggers) {
2016
1909
  this._requestContext = _requestContext;
@@ -2039,19 +1932,19 @@ var BaseLogger = class {
2039
1932
  * @param message The log message.
2040
1933
  * @param context Optional context information to include with the log message.
2041
1934
  * @param error Optional error object to include with the log message.
2042
-
2043
- *
1935
+ *
2044
1936
  * @author Xeno
2045
1937
  * @version 1.0.0
2046
1938
  * @since 2025-09-30
2047
- * @link https://github.com/xeno-js/xeno-js
1939
+ * @link https://github.com/xeno-js/xeno-js
2048
1940
  */
2049
1941
  broadcast(level, message, error = void 0) {
2050
1942
  if (level < this._minLevel) return;
2051
1943
  const logMessage = `[${LOG_LEVEL_NAMES[level]}] ${message}`;
2052
1944
  const context = this._requestContext.getContext();
1945
+ const safeContext = LoggerUtils.toSafeContext(context);
2053
1946
  for (const logger of this._loggers) {
2054
- logger.track(level, logMessage, context, error);
1947
+ logger.track(level, logMessage, safeContext, error);
2055
1948
  }
2056
1949
  }
2057
1950
  };
@@ -3075,6 +2968,7 @@ export {
3075
2968
  InMemoryCache,
3076
2969
  LOG_LEVEL,
3077
2970
  LOG_LEVEL_NAMES,
2971
+ LoggerUtils,
3078
2972
  MathHelper,
3079
2973
  PAGINATION_DEFAULTS,
3080
2974
  PERMISSIONS,