nestjs-infisical 1.0.11 → 1.0.12

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.
@@ -1,10 +1,6 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.loadInfisicalSecrets = loadInfisicalSecrets;
7
- const axios_1 = __importDefault(require("axios"));
8
4
  const LOG_PREFIX = '[nestjs-infisical]';
9
5
  function debugLog(enabled, message) {
10
6
  if (enabled) {
@@ -12,42 +8,37 @@ function debugLog(enabled, message) {
12
8
  }
13
9
  }
14
10
  async function loadInfisicalSecrets(options) {
11
+ const controller = new AbortController();
12
+ const timeout = setTimeout(() => controller.abort(), 5000); // 5s timeout
15
13
  try {
16
- debugLog(options.debug, `Fetching secrets from Infisical`);
14
+ debugLog(options.debug, 'Fetching secrets from Infisical');
17
15
  debugLog(options.debug, `baseUrl=${options.baseUrl}, projectId=${options.projectId}, environment=${options.environment}`);
18
- const url = `${options.baseUrl}/api/v3/secrets/raw`;
19
- debugLog(options.debug, JSON.stringify({
20
- url,
21
- timeout: 5000,
16
+ const url = new URL(`${options.baseUrl}/api/v3/secrets/raw`);
17
+ url.searchParams.set('projectId', options.projectId);
18
+ url.searchParams.set('environment', options.environment);
19
+ const response = await fetch(url.toString(), {
20
+ method: 'GET',
22
21
  headers: {
23
22
  Authorization: `Bearer ${options.token}`,
23
+ Accept: 'application/json',
24
24
  },
25
- params: {
26
- projectId: options.projectId,
27
- environment: options.environment,
28
- },
29
- }));
30
- const response = await axios_1.default.get(url, {
31
- timeout: 5000,
32
- headers: {
33
- Authorization: `Bearer ${options.token}`,
34
- },
35
- params: {
36
- projectId: options.projectId,
37
- environment: options.environment,
38
- },
25
+ signal: controller.signal,
39
26
  });
40
- debugLog(options.debug, `Received response from Infisical with status ${response.status}`);
41
- const secrets = response.data?.secrets ?? {};
27
+ if (!response.ok) {
28
+ const text = await response.text();
29
+ throw new Error(`Infisical API error ${response.status}: ${text}`);
30
+ }
31
+ const body = await response.json();
32
+ const secrets = body?.secrets ?? {};
42
33
  debugLog(options.debug, `Fetched ${Object.keys(secrets).length} secrets from Infisical`);
43
34
  debugLog(options.debug, `Secret keys fetched: ${Object.keys(secrets).join(', ')}`);
44
- for (const [key] of Object.entries(secrets)) {
35
+ for (const [key, value] of Object.entries(secrets)) {
45
36
  const exists = process.env[key] !== undefined;
46
37
  if (options.override || !exists) {
47
38
  debugLog(options.debug, exists
48
39
  ? `Overwriting env var: ${key}`
49
40
  : `Setting env var: ${key}`);
50
- process.env[key] = secrets[key];
41
+ process.env[key] = value;
51
42
  }
52
43
  else {
53
44
  debugLog(options.debug, `Skipping existing env var: ${key}`);
@@ -55,10 +46,18 @@ async function loadInfisicalSecrets(options) {
55
46
  }
56
47
  }
57
48
  catch (err) {
58
- debugLog(options.debug, `Error loading secrets from Infisical: ${err}`);
49
+ console.error('Error while loading Infisical secrets', err);
50
+ if (err.name === 'AbortError') {
51
+ console.error(`${LOG_PREFIX} Infisical request timed out after 5s`);
52
+ }
53
+ else {
54
+ console.error(`${LOG_PREFIX} Error loading secrets from Infisical`, err);
55
+ }
59
56
  if (options.failFast) {
60
57
  throw err;
61
58
  }
62
- console.warn(`${LOG_PREFIX} Failed to load secrets from Infisical. Continuing without secrets.`);
59
+ }
60
+ finally {
61
+ clearTimeout(timeout);
63
62
  }
64
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nestjs-infisical",
3
- "version": "1.0.11",
3
+ "version": "1.0.12",
4
4
  "description": "CLI-free Infisical HTTP integration for NestJS",
5
5
  "license": "MIT",
6
6
  "main": "dist/index.js",