nestjs-infisical 1.0.11 → 1.0.13
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/infisical.loader.js +28 -29
- package/dist/infisical.module.js +2 -2
- package/package.json +1 -1
package/dist/infisical.loader.js
CHANGED
|
@@ -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,
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
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
|
-
|
|
41
|
-
|
|
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] =
|
|
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
|
-
|
|
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
|
-
|
|
59
|
+
}
|
|
60
|
+
finally {
|
|
61
|
+
clearTimeout(timeout);
|
|
63
62
|
}
|
|
64
63
|
}
|
package/dist/infisical.module.js
CHANGED
|
@@ -61,7 +61,7 @@ let InfisicalModule = (() => {
|
|
|
61
61
|
module: InfisicalModule,
|
|
62
62
|
providers: [
|
|
63
63
|
{
|
|
64
|
-
provide: '
|
|
64
|
+
provide: 'INFISICAL_BOOTSTRAP',
|
|
65
65
|
useFactory: async () => {
|
|
66
66
|
await (0, infisical_service_1.initializeInfisical)(resolved);
|
|
67
67
|
},
|
|
@@ -75,7 +75,7 @@ let InfisicalModule = (() => {
|
|
|
75
75
|
imports: options.imports,
|
|
76
76
|
providers: [
|
|
77
77
|
{
|
|
78
|
-
provide: '
|
|
78
|
+
provide: 'INFISICAL_BOOTSTRAP',
|
|
79
79
|
inject: options.inject ?? [],
|
|
80
80
|
useFactory: async (...args) => {
|
|
81
81
|
const resolved = await options.useFactory(...args);
|