@xeno-js/shared 0.1.4 → 0.1.6

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/README.md CHANGED
@@ -200,17 +200,11 @@ flows from feature branches ➡️ `develop` ➡️ `main`._
200
200
  | Command | Description |
201
201
  | ------------------- | -------------------------------------------------- |
202
202
  | `npm run build` | Builds the TypeScript source code into `dist/`<br> |
203
- | `npm run typecheck` | Checks types without emitting files |
204
-
205
- | | `npm run lint` | Runs ESLint
206
-
207
- | | `npm run format` | Formats code with Prettier
208
-
209
- | | `npm run test` | Runs the Vitest test suite
210
-
211
- | | `npm run test:coverage` | Runs tests and generates a coverage report
212
-
213
- |
203
+ | `npm run typecheck` | Checks types without emitting files |
204
+ | `npm run lint` | Runs ESLint |
205
+ | `npm run format` | Formats code with Prettier |
206
+ | `npm run test` | Runs the Vitest test suite |
207
+ | `npm run test:coverage` | Runs tests and generates a coverage report |
214
208
 
215
209
  ### Code Quality (Husky & Git Hooks)
216
210
 
package/dist/index.cjs CHANGED
@@ -51,6 +51,7 @@ __export(index_exports, {
51
51
  InMemoryCache: () => InMemoryCache,
52
52
  LOG_LEVEL: () => LOG_LEVEL,
53
53
  LOG_LEVEL_NAMES: () => LOG_LEVEL_NAMES,
54
+ LoggerUtils: () => LoggerUtils,
54
55
  MathHelper: () => MathHelper,
55
56
  PAGINATION_DEFAULTS: () => PAGINATION_DEFAULTS,
56
57
  PERMISSIONS: () => PERMISSIONS,
@@ -1626,6 +1627,29 @@ var GuidHelper = Object.freeze({
1626
1627
 
1627
1628
  // src/shared/utils/http.utils.ts
1628
1629
  var HttpHelper = Object.freeze({
1630
+ /**
1631
+ * @description A function that masks the IP address in the given headers object.
1632
+ * @param ip The IP address to mask.
1633
+ * @returns The masked IP address.
1634
+ */
1635
+ maskIp(ip) {
1636
+ if (!Guards.isDefined(ip)) return void 0;
1637
+ if (ip.includes(".")) {
1638
+ const parts = ip.split(".");
1639
+ if (parts.length === 4) {
1640
+ parts[3] = "x";
1641
+ return parts.join(".");
1642
+ }
1643
+ }
1644
+ if (ip.includes(":")) {
1645
+ const parts = ip.split(":");
1646
+ if (parts.length > 0) {
1647
+ parts[parts.length - 1] = "x";
1648
+ return parts.join(":");
1649
+ }
1650
+ }
1651
+ return ip;
1652
+ },
1629
1653
  /**
1630
1654
  * @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.
1631
1655
  * @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.
@@ -2076,6 +2100,36 @@ var Query = class {
2076
2100
  type = REQUEST_TYPE.QUERY;
2077
2101
  };
2078
2102
 
2103
+ // src/application/loggers/utils/logger-context.utils.ts
2104
+ var LoggerUtils = Object.freeze({
2105
+ /**
2106
+ * @description toSafeContext converts a RequestContext object to a LoggerContext object, ensuring that only the necessary fields are included.
2107
+ * @param ctx The RequestContext object to convert.
2108
+ * @returns The converted LoggerContext object.
2109
+ */
2110
+ toSafeContext(ctx) {
2111
+ return {
2112
+ identity: {
2113
+ userId: ctx?.identity?.userId,
2114
+ tenantId: ctx?.identity?.tenantId
2115
+ },
2116
+ network: {
2117
+ requestId: ctx?.network?.requestId,
2118
+ path: ctx?.network?.path,
2119
+ origin: ctx?.network?.origin,
2120
+ clientIp: HttpHelper.maskIp(ctx?.network?.clientIp)
2121
+ },
2122
+ tracing: {
2123
+ correlationId: ctx?.tracing?.correlationId,
2124
+ spanId: ctx?.tracing?.spanId,
2125
+ startTime: ctx?.tracing?.startTime,
2126
+ parentSpanId: ctx?.tracing.parentSpanId
2127
+ },
2128
+ messaging: ctx?.messaging
2129
+ };
2130
+ }
2131
+ });
2132
+
2079
2133
  // src/application/loggers/base.logger.ts
2080
2134
  var BaseLogger = class {
2081
2135
  /**
@@ -2128,8 +2182,9 @@ var BaseLogger = class {
2128
2182
  if (level < this._minLevel) return;
2129
2183
  const logMessage = `[${LOG_LEVEL_NAMES[level]}] ${message}`;
2130
2184
  const context = this._requestContext.getContext();
2185
+ const safeContext = LoggerUtils.toSafeContext(context);
2131
2186
  for (const logger of this._loggers) {
2132
- logger.track(level, logMessage, context, error);
2187
+ logger.track(level, logMessage, safeContext, error);
2133
2188
  }
2134
2189
  }
2135
2190
  };
@@ -3154,6 +3209,7 @@ var ZodValidatorService = class _ZodValidatorService {
3154
3209
  InMemoryCache,
3155
3210
  LOG_LEVEL,
3156
3211
  LOG_LEVEL_NAMES,
3212
+ LoggerUtils,
3157
3213
  MathHelper,
3158
3214
  PAGINATION_DEFAULTS,
3159
3215
  PERMISSIONS,