nestjs-infisical 1.0.5 → 1.0.9

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.
@@ -5,4 +5,5 @@ export declare function loadInfisicalSecrets(options: {
5
5
  environment: string;
6
6
  override: boolean;
7
7
  failFast: boolean;
8
+ debug?: boolean;
8
9
  }): Promise<void>;
@@ -6,8 +6,15 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.loadInfisicalSecrets = loadInfisicalSecrets;
7
7
  const axios_1 = __importDefault(require("axios"));
8
8
  const LOG_PREFIX = '[nestjs-infisical]';
9
+ function debugLog(enabled, message) {
10
+ if (enabled) {
11
+ console.log(`${LOG_PREFIX} ${message}`);
12
+ }
13
+ }
9
14
  async function loadInfisicalSecrets(options) {
10
15
  try {
16
+ debugLog(options.debug, `Fetching secrets from Infisical`);
17
+ debugLog(options.debug, `baseUrl=${options.baseUrl}, projectId=${options.projectId}, environment=${options.environment}`);
11
18
  const response = await axios_1.default.get(`${options.baseUrl}/api/v3/secrets/raw`, {
12
19
  headers: {
13
20
  Authorization: `Bearer ${options.token}`,
@@ -18,13 +25,23 @@ async function loadInfisicalSecrets(options) {
18
25
  },
19
26
  });
20
27
  const secrets = response.data?.secrets ?? {};
21
- for (const [key, value] of Object.entries(secrets)) {
22
- if (options.override || process.env[key] === undefined) {
23
- process.env[key] = value;
28
+ debugLog(options.debug, `Fetched ${Object.keys(secrets).length} secrets from Infisical`);
29
+ debugLog(options.debug, `Secret keys fetched: ${Object.keys(secrets).join(', ')}`);
30
+ for (const [key] of Object.entries(secrets)) {
31
+ const exists = process.env[key] !== undefined;
32
+ if (options.override || !exists) {
33
+ debugLog(options.debug, exists
34
+ ? `Overwriting env var: ${key}`
35
+ : `Setting env var: ${key}`);
36
+ process.env[key] = secrets[key];
37
+ }
38
+ else {
39
+ debugLog(options.debug, `Skipping existing env var: ${key}`);
24
40
  }
25
41
  }
26
42
  }
27
43
  catch (err) {
44
+ debugLog(options.debug, `Error loading secrets from Infisical: ${err}`);
28
45
  if (options.failFast) {
29
46
  throw err;
30
47
  }
@@ -7,19 +7,32 @@ exports.initializeInfisical = initializeInfisical;
7
7
  const infisical_loader_1 = require("./infisical.loader");
8
8
  const dotenv_1 = __importDefault(require("dotenv"));
9
9
  const LOG_PREFIX = '[nestjs-infisical]';
10
+ function debugLog(enabled, message) {
11
+ if (enabled) {
12
+ console.log(`${LOG_PREFIX} ${message}`);
13
+ }
14
+ }
10
15
  async function initializeInfisical(options) {
11
- const { dotenv: dotenvOptions, baseUrl, token, projectId, environment, override = true, failFast = true, } = options;
16
+ const { dotenv: dotenvOptions, baseUrl, token, projectId, environment, override = true, failFast = true, debug = false } = options;
12
17
  if (dotenvOptions !== false) {
18
+ debugLog(debug, 'Loading dotenv configuration');
13
19
  dotenv_1.default.config(dotenvOptions);
14
20
  }
21
+ else {
22
+ debugLog(debug, 'Dotenv disabled');
23
+ }
15
24
  const provided = [baseUrl, token, projectId, environment].filter(Boolean).length;
25
+ debugLog(debug, `Infisical config resolved: ${provided === 0 ? 'none' : provided === 4 ? 'complete' : 'partial'}`);
16
26
  if (provided === 0) {
27
+ debugLog(debug, 'No Infisical configuration provided');
17
28
  return;
18
29
  }
19
30
  if (provided !== 4) {
20
31
  console.warn(`${LOG_PREFIX} Partial Infisical configuration detected. Secrets will not be loaded.`);
32
+ debugLog(debug, `baseUrl=${!!baseUrl}, token=${!!token}, projectId=${!!projectId}, environment=${!!environment}`);
21
33
  return;
22
34
  }
35
+ debugLog(debug, 'Loading Infisical secrets');
23
36
  await (0, infisical_loader_1.loadInfisicalSecrets)({
24
37
  baseUrl: baseUrl,
25
38
  token: token,
@@ -8,6 +8,7 @@ export interface InfisicalModuleOptions {
8
8
  dotenv?: DotenvConfigOptions | false;
9
9
  override?: boolean;
10
10
  failFast?: boolean;
11
+ debug?: boolean;
11
12
  }
12
13
  export interface InfisicalModuleAsyncOptions extends Pick<ModuleMetadata, 'imports'> {
13
14
  inject?: any[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-infisical",
3
- "version": "1.0.5",
3
+ "version": "1.0.9",
4
4
  "description": "CLI-free Infisical HTTP integration for NestJS",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",