x-fidelity 3.15.0 → 3.17.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/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ # [3.17.0](https://github.com/zotoio/x-fidelity/compare/v3.16.0...v3.17.0) (2025-03-20)
2
+
3
+
4
+ ### Features
5
+
6
+ * **canary:** example with proxy support for canary installs in ci ([6b5aff3](https://github.com/zotoio/x-fidelity/commit/6b5aff317d0d4fedfccd6cf79304722e8e7a7556))
7
+
8
+ # [3.16.0](https://github.com/zotoio/x-fidelity/compare/v3.15.0...v3.16.0) (2025-03-19)
9
+
10
+
11
+ ### Features
12
+
13
+ * add support for disabling colored logging via XFI_LOG_COLOR env var ([cafcf5b](https://github.com/zotoio/x-fidelity/commit/cafcf5b6fde9b29dbe31a62cba491ab42c24b759))
14
+
1
15
  # [3.15.0](https://github.com/zotoio/x-fidelity/compare/v3.14.0...v3.15.0) (2025-03-12)
2
16
 
3
17
 
package/README.md CHANGED
@@ -50,6 +50,7 @@ x-fidelity is an advanced CLI tool and paired config server designed to perform
50
50
  - [Basic Usage](#basic-usage)
51
51
  - [Advanced Usage](#advanced-usage)
52
52
  - [Environment Variables](#environment-variables)
53
+ - [Logging Options](#logging-options)
53
54
  - [Local Configuration](#local-configuration)
54
55
  - [Remote Configuration](#remote-configuration)
55
56
  8. [Hosting Config Servers](#hosting-config-servers)
@@ -475,6 +476,7 @@ x-fidelity supports the following environment variables:
475
476
  - `CERT_PATH`: The path to SSL certificates for HTTPS config server.
476
477
  - `NODE_TLS_REJECT_UNAUTHORIZED`: Set to '0' to allow self-signed certificates (use with caution).
477
478
  - `XFI_SHARED_SECRET`: Shared secret for securing telemetry and certain server routes.
479
+ - `XFI_LOG_COLOR`: Set to 'false' to disable colored output in logs.
478
480
 
479
481
  Example usage:
480
482
 
@@ -483,6 +485,7 @@ export OPENAI_API_KEY=your_api_key_here
483
485
  export OPENAI_MODEL=gpt-4
484
486
  export XFI_LISTEN_PORT=9999
485
487
  export XFI_SHARED_SECRET=your_shared_secret_here
488
+ export XFI_LOG_COLOR=false
486
489
  xfidelity -o true
487
490
  ```
488
491
 
@@ -500,6 +503,23 @@ The local config directory should contain:
500
503
 
501
504
  You can override default archetypes or add new ones by placing the corresponding JSON files in the local config directory.
502
505
 
506
+ ### Logging Options
507
+
508
+ x-fidelity provides options to customize the logging output:
509
+
510
+ 1. **Log Level**: Set the logging level using the `XFI_LOG_LEVEL` environment variable:
511
+ ```sh
512
+ export XFI_LOG_LEVEL=debug
513
+ ```
514
+ Available levels: trace, debug, info, warn, error, fatal
515
+
516
+ 2. **Colored Output**: You can disable colored logging output using an environment variable:
517
+ ```sh
518
+ export XFI_LOG_COLOR=false
519
+ ```
520
+
521
+ This is particularly useful in CI/CD environments or when redirecting logs to files.
522
+
503
523
  ### Remote Configuration
504
524
 
505
525
  To use a remote configuration server, use the `-c` or `--configServer` option:
@@ -3,10 +3,8 @@
3
3
  # This script uses the LaunchDarkly Node SDK to evaluate a feature flag
4
4
  # and conditionally run a command based on the flag’s value.
5
5
  #
6
- # Requirements:
7
- # - Node.js installed.
8
- # - LaunchDarkly Node SDK installed:
9
- # yarn global add launchdarkly-node-client-sdk
6
+ # global-agent is used to make the launchdarkly connection via proxy set in environment
7
+ # to run a local test proxy: DEBUG=* npx proxy --port 3128
10
8
  #
11
9
  # Set your LaunchDarkly clientid and feature flag key here.
12
10
  # note that the clientid is not a secret, as it is public in the client-side SDKs
@@ -23,7 +21,9 @@ echo "XFI_LD_CLIENT_ID: $XFI_LD_CLIENT_ID"
23
21
  echo "XFI_VERSION_FLAG_KEY: $XFI_VERSION_FLAG_KEY"
24
22
 
25
23
  # Run a Node.js script to evaluate the flag.
26
- FLAG_VALUE=$(node ./flagCheck.js $XFI_CONTEXT_KEY)
24
+ export GLOBAL_AGENT_ENVIRONMENT_VARIABLE_NAMESPACE=
25
+ FLAG_VALUE=$(yarn add -s global-agent launchdarkly-node-client-sdk --ignore-engines \
26
+ && node ./flagCheck.js $XFI_CONTEXT_KEY)
27
27
  echo "FLAG_VALUE: $FLAG_VALUE"
28
28
 
29
29
  # Check if the Node.js command succeeded.
@@ -34,11 +34,11 @@ fi
34
34
 
35
35
  # Decide which command to run based on the flag value.
36
36
  if [ "$FLAG_VALUE" == "true" ]; then
37
- echo "Installing the NEW version of xfi"
38
- # add your canary CI install command here
39
- # eg. yarn global add x-fidelity@3.9.1 --ignore-engines
37
+ export XFI_VERSION=$(cat ./xfi-version-new.txt)
38
+ echo "Installing the NEW version of xfi $XFI_VERSION"
39
+ yarn global add x-fidelity@$XFI_VERSION --ignore-engines
40
40
  else
41
- echo "Installing the current version of xfi"
42
- # add your current CI install command here
43
- # eg. yarn global add x-fidelity@2.17.2 --ignore-engines
41
+ export XFI_VERSION=$(cat ./xfi-version-current.txt)
42
+ echo "Installing the current version of xfi $XFI_VERSION"
43
+ yarn global add x-fidelity@$XFI_VERSION --ignore-engines
44
44
  fi
@@ -1,3 +1,5 @@
1
+
2
+ const bootstrap = require('global-agent/bootstrap');
1
3
  const ldclient = require('launchdarkly-node-client-sdk');
2
4
 
3
5
  (async function main(contextKey) {
@@ -0,0 +1 @@
1
+ 2.17.2
@@ -0,0 +1 @@
1
+ 3.16.0
@@ -17,7 +17,7 @@
17
17
  "cognitiveComplexity": 30,
18
18
  "nestingDepth": 10,
19
19
  "parameterCount": 5,
20
- "returnCount": 5
20
+ "returnCount": 10
21
21
  }
22
22
  },
23
23
  "operator": "astComplexity",
@@ -26,7 +26,7 @@
26
26
  "cognitiveComplexity": 30,
27
27
  "nestingDepth": 10,
28
28
  "parameterCount": 5,
29
- "returnCount": 5
29
+ "returnCount": 10
30
30
  }
31
31
  }
32
32
  ]
@@ -38,6 +38,8 @@ function getLogPrefix() {
38
38
  }
39
39
  // Initialize logger function that will create the singleton if it doesn't exist
40
40
  function getLogger(force) {
41
+ // Determine if color should be enabled based on environment variable only
42
+ const useColor = process.env.XFI_LOG_COLOR !== 'false';
41
43
  if (!loggerInstance || force) {
42
44
  const fileTransport = pino_1.default.destination({
43
45
  dest: 'x-fidelity.log',
@@ -49,7 +51,7 @@ function getLogger(force) {
49
51
  options: {
50
52
  loglevel: loglevel,
51
53
  sync: false,
52
- colorize: true,
54
+ colorize: useColor,
53
55
  translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l o',
54
56
  ignore: 'pid,hostname',
55
57
  singleLine: true,
@@ -2,6 +2,16 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const logger_1 = require("./logger");
4
4
  describe('Logger utilities', () => {
5
+ // Save original environment
6
+ const originalEnv = process.env;
7
+ beforeEach(() => {
8
+ // Reset environment before each test
9
+ process.env = Object.assign({}, originalEnv);
10
+ });
11
+ afterAll(() => {
12
+ // Restore original environment
13
+ process.env = originalEnv;
14
+ });
5
15
  describe('generateLogPrefix', () => {
6
16
  it('should generate a string of length 8', () => {
7
17
  const prefix = (0, logger_1.generateLogPrefix)();
@@ -29,4 +39,13 @@ describe('Logger utilities', () => {
29
39
  expect(newPrefix.length).toBe(8);
30
40
  });
31
41
  });
42
+ describe('logger color configuration', () => {
43
+ it('should respect XFI_LOG_COLOR environment variable', () => {
44
+ process.env.XFI_LOG_COLOR = 'false';
45
+ (0, logger_1.resetLogger)();
46
+ // This test doesn't directly assert the colorize option
47
+ // as it's internal to pino, but ensures the code path is executed
48
+ expect(process.env.XFI_LOG_COLOR).toBe('false');
49
+ });
50
+ });
32
51
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "x-fidelity",
3
- "version": "3.15.0",
3
+ "version": "3.17.0",
4
4
  "description": "cli for opinionated framework adherence checks",
5
5
  "main": "dist/index",
6
6
  "types": "dist/index.d.ts",
@@ -88,6 +88,7 @@
88
88
  "esprima": "^4.0.1",
89
89
  "express": "^4.21.2",
90
90
  "express-rate-limit": "^7.5.0",
91
+ "global-agent": "^3.0.0",
91
92
  "helmet": "^8.0.0",
92
93
  "json-rules-engine": "^7.3.1",
93
94
  "jsonpath-plus": "^10.3.0",
@@ -17,7 +17,7 @@
17
17
  "cognitiveComplexity": 30,
18
18
  "nestingDepth": 10,
19
19
  "parameterCount": 5,
20
- "returnCount": 5
20
+ "returnCount": 10
21
21
  }
22
22
  },
23
23
  "operator": "astComplexity",
@@ -26,7 +26,7 @@
26
26
  "cognitiveComplexity": 30,
27
27
  "nestingDepth": 10,
28
28
  "parameterCount": 5,
29
- "returnCount": 5
29
+ "returnCount": 10
30
30
  }
31
31
  }
32
32
  ]
@@ -17,7 +17,7 @@
17
17
  "cognitiveComplexity": 30,
18
18
  "nestingDepth": 10,
19
19
  "parameterCount": 5,
20
- "returnCount": 5
20
+ "returnCount": 10
21
21
  }
22
22
  },
23
23
  "operator": "astComplexity",
@@ -26,7 +26,7 @@
26
26
  "cognitiveComplexity": 30,
27
27
  "nestingDepth": 10,
28
28
  "parameterCount": 5,
29
- "returnCount": 5
29
+ "returnCount": 10
30
30
  }
31
31
  }
32
32
  ]
@@ -1,6 +1,18 @@
1
- import { generateLogPrefix, setLogPrefix, getLogPrefix, resetLogPrefix } from './logger';
1
+ import { generateLogPrefix, setLogPrefix, getLogPrefix, resetLogPrefix, resetLogger } from './logger';
2
2
 
3
3
  describe('Logger utilities', () => {
4
+ // Save original environment
5
+ const originalEnv = process.env;
6
+
7
+ beforeEach(() => {
8
+ // Reset environment before each test
9
+ process.env = { ...originalEnv };
10
+ });
11
+
12
+ afterAll(() => {
13
+ // Restore original environment
14
+ process.env = originalEnv;
15
+ });
4
16
  describe('generateLogPrefix', () => {
5
17
  it('should generate a string of length 8', () => {
6
18
  const prefix = generateLogPrefix();
@@ -31,4 +43,14 @@ describe('Logger utilities', () => {
31
43
  expect(newPrefix.length).toBe(8);
32
44
  });
33
45
  });
46
+
47
+ describe('logger color configuration', () => {
48
+ it('should respect XFI_LOG_COLOR environment variable', () => {
49
+ process.env.XFI_LOG_COLOR = 'false';
50
+ resetLogger();
51
+ // This test doesn't directly assert the colorize option
52
+ // as it's internal to pino, but ensures the code path is executed
53
+ expect(process.env.XFI_LOG_COLOR).toBe('false');
54
+ });
55
+ });
34
56
  });
@@ -1,6 +1,7 @@
1
1
  import { randomUUID } from 'crypto';
2
2
  import pino from 'pino';
3
3
  import { maskSensitiveData } from './maskSensitiveData';
4
+ import { options } from '../core/cli';
4
5
 
5
6
  // Initialize variables
6
7
  let loggerInstance: pino.Logger | undefined;
@@ -32,6 +33,9 @@ export function getLogPrefix(): string {
32
33
 
33
34
  // Initialize logger function that will create the singleton if it doesn't exist
34
35
  function getLogger(force?: boolean): pino.Logger {
36
+ // Determine if color should be enabled based on environment variable only
37
+ const useColor = process.env.XFI_LOG_COLOR !== 'false';
38
+
35
39
  if (!loggerInstance || force) {
36
40
  const fileTransport = pino.destination({
37
41
  dest: 'x-fidelity.log',
@@ -44,7 +48,7 @@ function getLogger(force?: boolean): pino.Logger {
44
48
  options: {
45
49
  loglevel: loglevel,
46
50
  sync: false,
47
- colorize: true,
51
+ colorize: useColor,
48
52
  translateTime: 'SYS:yyyy-mm-dd HH:MM:ss.l o',
49
53
  ignore: 'pid,hostname',
50
54
  singleLine: true,
@@ -42,8 +42,15 @@ GITHUB_WEBHOOK_SECRET=your_github_webhook_secret
42
42
  ```bash
43
43
  # Set logging level (default: 'info')
44
44
  XFI_LOG_LEVEL=debug
45
+
46
+ # Disable colored output in logs (default: enabled)
47
+ XFI_LOG_COLOR=false
45
48
  ```
46
49
 
50
+ The `XFI_LOG_COLOR` environment variable controls whether log output includes ANSI color codes. This is particularly useful in CI/CD environments, when redirecting logs to files, or when your terminal doesn't support colors.
51
+
52
+ Setting `XFI_LOG_COLOR=false` will disable all colored output in logs, making them plain text. This can improve readability in environments where color codes might appear as strange characters.
53
+
47
54
  ## Usage Examples
48
55
 
49
56
  ### Basic Setup
@@ -62,6 +62,7 @@ Options:
62
62
  - `CERT_PATH`: SSL certificate path
63
63
  - `NODE_TLS_REJECT_UNAUTHORIZED`: Allow self-signed certs
64
64
  - `XFI_SHARED_SECRET`: Shared secret for security
65
+ - `XFI_LOG_COLOR`: Set to 'false' to disable colored output in logs
65
66
  - `NOTIFICATIONS_ENABLED`: Enable notification system
66
67
  - `NOTIFICATION_PROVIDERS`: Comma-separated list of notification providers to use
67
68
  - `CODEOWNERS_PATH`: Path to CODEOWNERS file (default: .github/CODEOWNERS)