voltenv-sdk 1.1.2 → 1.1.4
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/index.d.ts +35 -30
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +138 -129
- package/dist/index.js.map +1 -1
- package/dist/utilities/errorHandler.d.ts +1 -0
- package/dist/utilities/errorHandler.d.ts.map +1 -1
- package/dist/utilities/errorHandler.js.map +1 -1
- package/index.ts +159 -104
- package/package.json +1 -1
- package/tsconfig.json +3 -0
- package/utilities/errorHandler.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,17 +3,19 @@ export declare class VoltEnv {
|
|
|
3
3
|
private httpClient;
|
|
4
4
|
private cacheService;
|
|
5
5
|
private resolvedPrefix;
|
|
6
|
+
private environment;
|
|
6
7
|
/**
|
|
7
8
|
* Initialize the VoltEnv SDK
|
|
8
9
|
* @param options Configuration options or API key string
|
|
9
10
|
*/
|
|
10
|
-
constructor(options: VoltEnvOptions
|
|
11
|
+
constructor(options: VoltEnvOptions);
|
|
11
12
|
/**
|
|
12
13
|
* Resolve the prefix based on framework or explicit option
|
|
13
14
|
*/
|
|
14
15
|
private resolvePrefix;
|
|
15
16
|
/**
|
|
16
17
|
* Try to detect the framework from package.json by searching up the directory tree
|
|
18
|
+
* Only works in Node.js environments
|
|
17
19
|
*/
|
|
18
20
|
private detectFramework;
|
|
19
21
|
/**
|
|
@@ -22,70 +24,72 @@ export declare class VoltEnv {
|
|
|
22
24
|
private applyPrefix;
|
|
23
25
|
/**
|
|
24
26
|
* Get a variable from a specific environment
|
|
25
|
-
* @param environment The environment name (e.g., 'production', 'development')
|
|
26
27
|
* @param key The variable key
|
|
28
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
27
29
|
* @param defaultValue Optional default value if not found
|
|
28
30
|
* @returns The variable value or the default value
|
|
29
31
|
*/
|
|
30
|
-
get(
|
|
32
|
+
get(key: string, environment?: string, defaultValue?: string): Promise<string | undefined>;
|
|
31
33
|
/**
|
|
32
34
|
* Get all variables from an environment
|
|
33
|
-
* @param environment
|
|
35
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
34
36
|
* @returns A record of key-value pairs
|
|
35
37
|
*/
|
|
36
|
-
getAll(environment
|
|
38
|
+
getAll(environment?: string): Promise<Record<string, string>>;
|
|
37
39
|
/**
|
|
38
40
|
* Set a variable in a specific environment
|
|
39
|
-
* @param environment The environment name
|
|
40
41
|
* @param key The variable key
|
|
41
42
|
* @param value The variable value
|
|
43
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
42
44
|
*/
|
|
43
|
-
set(
|
|
45
|
+
set(key: string, value: string, environment?: string): Promise<void>;
|
|
44
46
|
/**
|
|
45
47
|
* Set a secret variable in a specific environment
|
|
46
|
-
* @param environment The environment name
|
|
47
48
|
* @param key The variable key
|
|
48
49
|
* @param value The secret value
|
|
50
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
49
51
|
*/
|
|
50
|
-
setSecret(
|
|
52
|
+
setSecret(key: string, value: string, environment?: string): Promise<void>;
|
|
51
53
|
/**
|
|
52
54
|
* Watch for changes in an environment
|
|
53
|
-
* @param environment The environment name
|
|
54
55
|
* @param callback Function to call when changes occur
|
|
55
56
|
* @param interval Polling interval in milliseconds (default: 30000)
|
|
57
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
56
58
|
* @returns A function to stop watching
|
|
57
59
|
*/
|
|
58
|
-
watch(
|
|
60
|
+
watch(callback: (variables: Record<string, string>) => void, interval?: number, environment?: string): () => void;
|
|
59
61
|
/**
|
|
60
62
|
* Set multiple variables at once
|
|
61
|
-
* @param environment The environment name
|
|
62
63
|
* @param variables A record of key-value pairs to set
|
|
64
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
63
65
|
*/
|
|
64
|
-
setMany(
|
|
66
|
+
setMany(variables: Record<string, string>, environment?: string): Promise<void>;
|
|
65
67
|
/**
|
|
66
68
|
* Delete a variable from a specific environment
|
|
67
|
-
* @param environment The environment name
|
|
68
69
|
* @param key The variable key
|
|
70
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
69
71
|
*/
|
|
70
|
-
delete(
|
|
72
|
+
delete(key: string, environment?: string): Promise<void>;
|
|
71
73
|
/**
|
|
72
74
|
* Delete multiple variables at once
|
|
73
|
-
* @param environment The environment name
|
|
74
75
|
* @param keys Array of keys to delete
|
|
76
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
75
77
|
*/
|
|
76
|
-
deleteMany(
|
|
78
|
+
deleteMany(keys: string[], environment?: string): Promise<void>;
|
|
77
79
|
/**
|
|
78
80
|
* Export all variables in an environment to a .env file
|
|
79
|
-
*
|
|
81
|
+
* Node.js only - will throw error in browser
|
|
80
82
|
* @param filePath Path to the .env file to create/overwrite
|
|
83
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
81
84
|
*/
|
|
82
|
-
exportToEnvFile(
|
|
85
|
+
exportToEnvFile(filePath: string, environment?: string): Promise<void>;
|
|
83
86
|
/**
|
|
84
87
|
* Load variables from a .env file and set them in an environment
|
|
85
|
-
*
|
|
88
|
+
* Node.js only - will throw error in browser
|
|
86
89
|
* @param filePath Path to the .env file to read from
|
|
90
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
87
91
|
*/
|
|
88
|
-
loadFromEnvFile(
|
|
92
|
+
loadFromEnvFile(filePath: string, environment?: string): Promise<void>;
|
|
89
93
|
/**
|
|
90
94
|
* List all environments accessible by this API key
|
|
91
95
|
* @returns Array of environment names
|
|
@@ -110,22 +114,23 @@ export declare class VoltEnv {
|
|
|
110
114
|
deleteEnvironment(name: string): Promise<void>;
|
|
111
115
|
/**
|
|
112
116
|
* Sync/refresh variables from server (bypassing cache)
|
|
113
|
-
*If an environment is provided, it
|
|
114
|
-
* If no environment is provided, it
|
|
117
|
+
* If an environment is provided, it syncs that environment.
|
|
118
|
+
* If no environment is provided, it syncs the instance environment.
|
|
115
119
|
* @param environment Optional environment to sync
|
|
116
120
|
*/
|
|
117
121
|
sync(environment?: string): Promise<void>;
|
|
118
122
|
/**
|
|
119
|
-
*
|
|
123
|
+
* Sync/refresh all environments accessible by this API key
|
|
120
124
|
*/
|
|
121
|
-
|
|
125
|
+
syncAll(): Promise<void>;
|
|
126
|
+
/**
|
|
127
|
+
* Clear the entire cache
|
|
128
|
+
*/
|
|
129
|
+
clearCache(): void;
|
|
122
130
|
/**
|
|
123
|
-
* Get
|
|
131
|
+
* Get all cached keys (for debugging)
|
|
124
132
|
*/
|
|
125
|
-
|
|
126
|
-
size: number;
|
|
127
|
-
keys: string[];
|
|
128
|
-
};
|
|
133
|
+
getCacheKeys(): string[];
|
|
129
134
|
}
|
|
130
135
|
export default VoltEnv;
|
|
131
136
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAIxE,qBAAa,OAAO;IAChB,OAAO,CAAC,UAAU,CAAa;IAC/B,OAAO,CAAC,YAAY,CAAsB;IAC1C,OAAO,CAAC,cAAc,CAAc;IACpC,OAAO,CAAC,WAAW,CAAS;IAE5B;;;OAGG;gBACS,OAAO,EAAE,cAAc;IAiCnC;;OAEG;IACH,OAAO,CAAC,aAAa;IAiBrB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAmDvB;;OAEG;IACH,OAAO,CAAC,WAAW;IAMnB;;;;;;OAMG;IACG,GAAG,CACL,GAAG,EAAE,MAAM,EACX,WAAW,CAAC,EAAE,MAAM,EACpB,YAAY,CAAC,EAAE,MAAM,GACtB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC;IA6B9B;;;;OAIG;IACG,MAAM,CAAC,WAAW,CAAC,EAAE,MAAM,GA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AM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnF;;;;OAIG;IACG,iBAAiB,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAIjF;;;OAGG;IACG,iBAAiB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAQpD;;;;;OAKG;IACG,IAAI,CAAC,WAAW,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAa/C;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAQ9B;;OAEG;IACH,UAAU,IAAI,IAAI;IAMlB;;OAEG;IACH,YAAY,IAAI,MAAM,EAAE;CAO3B;AAED,eAAe,OAAO,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
3
|
exports.VoltEnv = void 0;
|
|
37
|
-
const fs = __importStar(require("fs"));
|
|
38
|
-
const path = __importStar(require("path"));
|
|
39
4
|
const errorHandler_1 = require("./utilities/errorHandler");
|
|
40
5
|
const httpClient_1 = require("./utilities/httpClient");
|
|
41
6
|
const cacheService_1 = require("./utilities/cacheService");
|
|
@@ -47,9 +12,13 @@ class VoltEnv {
|
|
|
47
12
|
constructor(options) {
|
|
48
13
|
this.resolvedPrefix = '';
|
|
49
14
|
const config = typeof options === 'string'
|
|
50
|
-
? { apiKey: options }
|
|
15
|
+
? { apiKey: options, environment: 'development' }
|
|
51
16
|
: options;
|
|
52
|
-
const { apiKey, baseURL = 'https://api.voltenv.com', timeout = 5000, cache = true, onError, framework, prefix } = config;
|
|
17
|
+
const { apiKey, environment, baseURL = 'https://api.voltenv.com', timeout = 5000, cache = true, onError, framework, prefix } = config;
|
|
18
|
+
if (!environment) {
|
|
19
|
+
throw new Error('Environment is required in VoltEnv constructor');
|
|
20
|
+
}
|
|
21
|
+
this.environment = environment;
|
|
53
22
|
this.httpClient = new httpClient_1.HttpClient({
|
|
54
23
|
apiKey,
|
|
55
24
|
baseURL,
|
|
@@ -79,9 +48,18 @@ class VoltEnv {
|
|
|
79
48
|
}
|
|
80
49
|
/**
|
|
81
50
|
* Try to detect the framework from package.json by searching up the directory tree
|
|
51
|
+
* Only works in Node.js environments
|
|
82
52
|
*/
|
|
83
53
|
detectFramework() {
|
|
54
|
+
const isNode = typeof process !== 'undefined'
|
|
55
|
+
&& process.versions != null
|
|
56
|
+
&& process.versions.node != null;
|
|
57
|
+
if (!isNode) {
|
|
58
|
+
return '';
|
|
59
|
+
}
|
|
84
60
|
try {
|
|
61
|
+
const fs = require('fs');
|
|
62
|
+
const path = require('path');
|
|
85
63
|
let currentDir = process.cwd();
|
|
86
64
|
const rootDir = path.parse(currentDir).root;
|
|
87
65
|
while (true) {
|
|
@@ -94,15 +72,14 @@ class VoltEnv {
|
|
|
94
72
|
...(packageJson.dependencies || {}),
|
|
95
73
|
...(packageJson.devDependencies || {})
|
|
96
74
|
};
|
|
97
|
-
// Check more specific frameworks first
|
|
98
75
|
if (deps['@remix-run/dev'] || deps['@remix-run/node'])
|
|
99
76
|
return 'remix';
|
|
100
77
|
if (deps['next'] || fs.existsSync(path.join(currentDir, 'next.config.js')))
|
|
101
78
|
return 'nextjs';
|
|
102
|
-
if (deps['nuxt'] || fs.existsSync(path.join(currentDir, 'nuxt.config.ts')))
|
|
103
|
-
return 'nuxt';
|
|
104
79
|
if (deps['@sveltejs/kit'])
|
|
105
80
|
return 'sveltekit';
|
|
81
|
+
if (deps['nuxt'] || fs.existsSync(path.join(currentDir, 'nuxt.config.ts')))
|
|
82
|
+
return 'nuxt';
|
|
106
83
|
if (deps['astro'])
|
|
107
84
|
return 'astro';
|
|
108
85
|
if (deps['react-scripts'])
|
|
@@ -111,19 +88,19 @@ class VoltEnv {
|
|
|
111
88
|
return 'vite';
|
|
112
89
|
}
|
|
113
90
|
catch (e) {
|
|
114
|
-
// Ignore parse errors
|
|
91
|
+
// Ignore parse errors
|
|
115
92
|
}
|
|
116
93
|
}
|
|
117
94
|
if (currentDir === rootDir)
|
|
118
95
|
break;
|
|
119
96
|
const parentDir = path.dirname(currentDir);
|
|
120
97
|
if (parentDir === currentDir)
|
|
121
|
-
break;
|
|
98
|
+
break;
|
|
122
99
|
currentDir = parentDir;
|
|
123
100
|
}
|
|
124
101
|
}
|
|
125
102
|
catch (error) {
|
|
126
|
-
// Silently fail
|
|
103
|
+
// Silently fail
|
|
127
104
|
}
|
|
128
105
|
return '';
|
|
129
106
|
}
|
|
@@ -139,19 +116,20 @@ class VoltEnv {
|
|
|
139
116
|
}
|
|
140
117
|
/**
|
|
141
118
|
* Get a variable from a specific environment
|
|
142
|
-
* @param environment The environment name (e.g., 'production', 'development')
|
|
143
119
|
* @param key The variable key
|
|
120
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
144
121
|
* @param defaultValue Optional default value if not found
|
|
145
122
|
* @returns The variable value or the default value
|
|
146
123
|
*/
|
|
147
|
-
async get(
|
|
124
|
+
async get(key, environment, defaultValue) {
|
|
125
|
+
const env = environment || this.environment;
|
|
148
126
|
const prefixedKey = this.applyPrefix(key);
|
|
149
|
-
const cacheKey = `${
|
|
127
|
+
const cacheKey = `${env}:${prefixedKey}`;
|
|
150
128
|
if (this.cacheService?.has(cacheKey)) {
|
|
151
129
|
return this.cacheService.get(cacheKey);
|
|
152
130
|
}
|
|
153
131
|
try {
|
|
154
|
-
const data = await this.httpClient.get(`/v1/variables/${
|
|
132
|
+
const data = await this.httpClient.get(`/v1/variables/${env}/${prefixedKey}`);
|
|
155
133
|
const value = data.value;
|
|
156
134
|
if (value && this.cacheService) {
|
|
157
135
|
this.cacheService.set(cacheKey, value);
|
|
@@ -167,62 +145,66 @@ class VoltEnv {
|
|
|
167
145
|
}
|
|
168
146
|
/**
|
|
169
147
|
* Get all variables from an environment
|
|
170
|
-
* @param environment
|
|
148
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
171
149
|
* @returns A record of key-value pairs
|
|
172
150
|
*/
|
|
173
151
|
async getAll(environment) {
|
|
174
|
-
const
|
|
152
|
+
const env = environment || this.environment;
|
|
153
|
+
const data = await this.httpClient.get(`/v1/variables/${env}`);
|
|
175
154
|
const variables = data.variables;
|
|
176
155
|
if (this.cacheService) {
|
|
177
156
|
Object.entries(variables).forEach(([key, value]) => {
|
|
178
|
-
this.cacheService.set(`${
|
|
157
|
+
this.cacheService.set(`${env}:${key}`, value);
|
|
179
158
|
});
|
|
180
159
|
}
|
|
181
160
|
return variables;
|
|
182
161
|
}
|
|
183
162
|
/**
|
|
184
163
|
* Set a variable in a specific environment
|
|
185
|
-
* @param environment The environment name
|
|
186
164
|
* @param key The variable key
|
|
187
165
|
* @param value The variable value
|
|
166
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
188
167
|
*/
|
|
189
|
-
async set(
|
|
168
|
+
async set(key, value, environment) {
|
|
169
|
+
const env = environment || this.environment;
|
|
190
170
|
const prefixedKey = this.applyPrefix(key);
|
|
191
|
-
await this.httpClient.put(`/v1/variables/${
|
|
171
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
192
172
|
value,
|
|
193
173
|
});
|
|
194
174
|
if (this.cacheService) {
|
|
195
|
-
this.cacheService.set(`${
|
|
175
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
196
176
|
}
|
|
197
177
|
}
|
|
198
178
|
/**
|
|
199
179
|
* Set a secret variable in a specific environment
|
|
200
|
-
* @param environment The environment name
|
|
201
180
|
* @param key The variable key
|
|
202
181
|
* @param value The secret value
|
|
182
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
203
183
|
*/
|
|
204
|
-
async setSecret(
|
|
184
|
+
async setSecret(key, value, environment) {
|
|
185
|
+
const env = environment || this.environment;
|
|
205
186
|
const prefixedKey = this.applyPrefix(key);
|
|
206
|
-
await this.httpClient.put(`/v1/variables/${
|
|
187
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
207
188
|
value,
|
|
208
189
|
isSecret: true
|
|
209
190
|
});
|
|
210
191
|
if (this.cacheService) {
|
|
211
|
-
this.cacheService.set(`${
|
|
192
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
212
193
|
}
|
|
213
194
|
}
|
|
214
195
|
/**
|
|
215
196
|
* Watch for changes in an environment
|
|
216
|
-
* @param environment The environment name
|
|
217
197
|
* @param callback Function to call when changes occur
|
|
218
198
|
* @param interval Polling interval in milliseconds (default: 30000)
|
|
199
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
219
200
|
* @returns A function to stop watching
|
|
220
201
|
*/
|
|
221
|
-
watch(
|
|
202
|
+
watch(callback, interval = 30000, environment) {
|
|
203
|
+
const env = environment || this.environment;
|
|
222
204
|
let previousVariables = '';
|
|
223
205
|
const fetchAndCompare = async () => {
|
|
224
206
|
try {
|
|
225
|
-
const variables = await this.getAll(
|
|
207
|
+
const variables = await this.getAll(env);
|
|
226
208
|
const currentVariables = JSON.stringify(variables);
|
|
227
209
|
if (currentVariables !== previousVariables) {
|
|
228
210
|
previousVariables = currentVariables;
|
|
@@ -230,7 +212,7 @@ class VoltEnv {
|
|
|
230
212
|
}
|
|
231
213
|
}
|
|
232
214
|
catch (error) {
|
|
233
|
-
console.error(`Error in VoltEnv watcher for ${
|
|
215
|
+
console.error(`Error in VoltEnv watcher for ${env}:`, error);
|
|
234
216
|
}
|
|
235
217
|
};
|
|
236
218
|
// Initial fetch
|
|
@@ -240,91 +222,120 @@ class VoltEnv {
|
|
|
240
222
|
}
|
|
241
223
|
/**
|
|
242
224
|
* Set multiple variables at once
|
|
243
|
-
* @param environment The environment name
|
|
244
225
|
* @param variables A record of key-value pairs to set
|
|
226
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
245
227
|
*/
|
|
246
|
-
async setMany(
|
|
228
|
+
async setMany(variables, environment) {
|
|
229
|
+
const env = environment || this.environment;
|
|
247
230
|
const prefixedVariables = {};
|
|
248
231
|
Object.entries(variables).forEach(([key, value]) => {
|
|
249
232
|
prefixedVariables[this.applyPrefix(key)] = value;
|
|
250
233
|
});
|
|
251
|
-
await this.httpClient.post(`/v1/variables/${
|
|
234
|
+
await this.httpClient.post(`/v1/variables/${env}/batch`, {
|
|
252
235
|
variables: prefixedVariables,
|
|
253
236
|
});
|
|
254
237
|
if (this.cacheService) {
|
|
255
238
|
Object.entries(prefixedVariables).forEach(([key, value]) => {
|
|
256
|
-
this.cacheService.set(`${
|
|
239
|
+
this.cacheService.set(`${env}:${key}`, value);
|
|
257
240
|
});
|
|
258
241
|
}
|
|
259
242
|
}
|
|
260
243
|
/**
|
|
261
244
|
* Delete a variable from a specific environment
|
|
262
|
-
* @param environment The environment name
|
|
263
245
|
* @param key The variable key
|
|
246
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
264
247
|
*/
|
|
265
|
-
async delete(
|
|
248
|
+
async delete(key, environment) {
|
|
249
|
+
const env = environment || this.environment;
|
|
266
250
|
const prefixedKey = this.applyPrefix(key);
|
|
267
|
-
await this.httpClient.delete(`/v1/variables/${
|
|
251
|
+
await this.httpClient.delete(`/v1/variables/${env}/${prefixedKey}`);
|
|
268
252
|
if (this.cacheService) {
|
|
269
|
-
this.cacheService.delete(`${
|
|
253
|
+
this.cacheService.delete(`${env}:${prefixedKey}`);
|
|
270
254
|
}
|
|
271
255
|
}
|
|
272
256
|
/**
|
|
273
257
|
* Delete multiple variables at once
|
|
274
|
-
* @param environment The environment name
|
|
275
258
|
* @param keys Array of keys to delete
|
|
259
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
276
260
|
*/
|
|
277
|
-
async deleteMany(
|
|
261
|
+
async deleteMany(keys, environment) {
|
|
262
|
+
const env = environment || this.environment;
|
|
278
263
|
const prefixedKeys = keys.map(k => this.applyPrefix(k));
|
|
279
|
-
await this.httpClient.post(`/v1/variables/${
|
|
264
|
+
await this.httpClient.post(`/v1/variables/${env}/batch-delete`, {
|
|
280
265
|
keys: prefixedKeys,
|
|
281
266
|
});
|
|
282
267
|
if (this.cacheService) {
|
|
283
268
|
prefixedKeys.forEach(key => {
|
|
284
|
-
this.cacheService.delete(`${
|
|
269
|
+
this.cacheService.delete(`${env}:${key}`);
|
|
285
270
|
});
|
|
286
271
|
}
|
|
287
272
|
}
|
|
288
273
|
/**
|
|
289
274
|
* Export all variables in an environment to a .env file
|
|
290
|
-
*
|
|
275
|
+
* Node.js only - will throw error in browser
|
|
291
276
|
* @param filePath Path to the .env file to create/overwrite
|
|
277
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
292
278
|
*/
|
|
293
|
-
async exportToEnvFile(
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
const
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
279
|
+
async exportToEnvFile(filePath, environment) {
|
|
280
|
+
// Check if we're in Node.js
|
|
281
|
+
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
282
|
+
throw new Error('exportToEnvFile is only available in Node.js environments');
|
|
283
|
+
}
|
|
284
|
+
const env = environment || this.environment;
|
|
285
|
+
try {
|
|
286
|
+
const fs = require('fs');
|
|
287
|
+
const path = require('path');
|
|
288
|
+
const variables = await this.getAll(env);
|
|
289
|
+
const content = Object.entries(variables)
|
|
290
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
291
|
+
.join('\n');
|
|
292
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
293
|
+
? filePath
|
|
294
|
+
: path.join(process.cwd(), filePath);
|
|
295
|
+
fs.writeFileSync(absolutePath, content, 'utf8');
|
|
296
|
+
}
|
|
297
|
+
catch (error) {
|
|
298
|
+
throw new Error(`Failed to export to env file: ${error}`);
|
|
299
|
+
}
|
|
302
300
|
}
|
|
303
301
|
/**
|
|
304
302
|
* Load variables from a .env file and set them in an environment
|
|
305
|
-
*
|
|
303
|
+
* Node.js only - will throw error in browser
|
|
306
304
|
* @param filePath Path to the .env file to read from
|
|
305
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
307
306
|
*/
|
|
308
|
-
async loadFromEnvFile(
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
if (!fs.existsSync(absolutePath)) {
|
|
313
|
-
throw new Error(`File not found: ${absolutePath}`);
|
|
307
|
+
async loadFromEnvFile(filePath, environment) {
|
|
308
|
+
// Check if we're in Node.js
|
|
309
|
+
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
310
|
+
throw new Error('loadFromEnvFile is only available in Node.js environments');
|
|
314
311
|
}
|
|
315
|
-
const
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
const
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
312
|
+
const env = environment || this.environment;
|
|
313
|
+
try {
|
|
314
|
+
const fs = require('fs');
|
|
315
|
+
const path = require('path');
|
|
316
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
317
|
+
? filePath
|
|
318
|
+
: path.join(process.cwd(), filePath);
|
|
319
|
+
if (!fs.existsSync(absolutePath)) {
|
|
320
|
+
throw new Error(`File not found: ${absolutePath}`);
|
|
321
|
+
}
|
|
322
|
+
const content = fs.readFileSync(absolutePath, 'utf8');
|
|
323
|
+
const variables = {};
|
|
324
|
+
content.split(/\r?\n/).forEach((line) => {
|
|
325
|
+
const trimmedLine = line.trim();
|
|
326
|
+
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
327
|
+
const [key, ...valueParts] = trimmedLine.split('=');
|
|
328
|
+
if (key) {
|
|
329
|
+
variables[key.trim()] = valueParts.join('=').trim();
|
|
330
|
+
}
|
|
323
331
|
}
|
|
332
|
+
});
|
|
333
|
+
if (Object.keys(variables).length > 0) {
|
|
334
|
+
await this.setMany(variables, env);
|
|
324
335
|
}
|
|
325
|
-
}
|
|
326
|
-
|
|
327
|
-
|
|
336
|
+
}
|
|
337
|
+
catch (error) {
|
|
338
|
+
throw new Error(`Failed to load from env file: ${error}`);
|
|
328
339
|
}
|
|
329
340
|
}
|
|
330
341
|
/**
|
|
@@ -366,47 +377,45 @@ class VoltEnv {
|
|
|
366
377
|
}
|
|
367
378
|
/**
|
|
368
379
|
* Sync/refresh variables from server (bypassing cache)
|
|
369
|
-
*If an environment is provided, it
|
|
370
|
-
* If no environment is provided, it
|
|
380
|
+
* If an environment is provided, it syncs that environment.
|
|
381
|
+
* If no environment is provided, it syncs the instance environment.
|
|
371
382
|
* @param environment Optional environment to sync
|
|
372
383
|
*/
|
|
373
384
|
async sync(environment) {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
}
|
|
385
|
+
const env = environment || this.environment;
|
|
386
|
+
const variables = await this.getAll(env);
|
|
387
|
+
if (this.cacheService) {
|
|
388
|
+
this.cacheService.deleteByPrefix(`${env}:`);
|
|
389
|
+
Object.entries(variables).forEach(([key, value]) => {
|
|
390
|
+
this.cacheService.set(`${env}:${key}`, value);
|
|
391
|
+
});
|
|
382
392
|
}
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
393
|
+
}
|
|
394
|
+
/**
|
|
395
|
+
* Sync/refresh all environments accessible by this API key
|
|
396
|
+
*/
|
|
397
|
+
async syncAll() {
|
|
398
|
+
const environments = await this.listEnvironments();
|
|
399
|
+
for (const env of environments) {
|
|
400
|
+
await this.sync(env);
|
|
388
401
|
}
|
|
389
402
|
}
|
|
390
403
|
/**
|
|
391
|
-
*
|
|
404
|
+
* Clear the entire cache
|
|
392
405
|
*/
|
|
393
|
-
|
|
394
|
-
if (
|
|
395
|
-
|
|
406
|
+
clearCache() {
|
|
407
|
+
if (this.cacheService) {
|
|
408
|
+
this.cacheService.clear();
|
|
396
409
|
}
|
|
397
|
-
return Array.from(this.cacheService.keys());
|
|
398
410
|
}
|
|
399
411
|
/**
|
|
400
|
-
* Get
|
|
412
|
+
* Get all cached keys (for debugging)
|
|
401
413
|
*/
|
|
402
|
-
|
|
414
|
+
getCacheKeys() {
|
|
403
415
|
if (!this.cacheService) {
|
|
404
|
-
return
|
|
416
|
+
return [];
|
|
405
417
|
}
|
|
406
|
-
return
|
|
407
|
-
size: this.cacheService.size,
|
|
408
|
-
keys: Array.from(this.cacheService.keys())
|
|
409
|
-
};
|
|
418
|
+
return Array.from(this.cacheService.keys());
|
|
410
419
|
}
|
|
411
420
|
}
|
|
412
421
|
exports.VoltEnv = VoltEnv;
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,uCAAyB;AACzB,2CAA6B;AAC7B,2DAAwE;AACxE,uDAAoD;AACpD,2DAAwD;AAExD,MAAa,OAAO;IAKhB;;;OAGG;IACH,YAAY,OAAgC;QANpC,mBAAc,GAAW,EAAE,CAAC;QAOhC,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ;YACtC,CAAC,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE;YACrB,CAAC,CAAC,OAAO,CAAC;QAEd,MAAM,EACF,MAAM,EACN,OAAO,GAAG,yBAAyB,EACnC,OAAO,GAAG,IAAI,EACd,KAAK,GAAG,IAAI,EACZ,OAAO,EACP,SAAS,EACT,MAAM,EACT,GAAG,MAAM,CAAC;QAEX,IAAI,CAAC,UAAU,GAAG,IAAI,uBAAU,CAAC;YAC7B,MAAM;YACN,OAAO;YACP,OAAO;YACP,OAAO;SACV,CAAC,CAAC;QAEH,IAAI,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,IAAI,2BAAY,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;QACtD,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,aAAa,CAAC,SAAS,EAAE,MAAM,CAAC,CAAC;IAChE,CAAC;IAED;;OAEG;IACK,aAAa,CAAC,SAAkB,EAAE,cAAuB;QAC7D,IAAI,cAAc,KAAK,SAAS;YAAE,OAAO,cAAc,CA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,EAAE,CAAC;QACd,CAAC;QACD,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,IAAI,EAAE,CAAC,CAAC;IAChD,CAAC;CAEJ;AAxfD,0BAwfC;AAED,kBAAe,OAAO,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../utilities/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GACtB,iBAAiB,GACjB,mBAAmB,GACnB,WAAW,GACX,qBAAqB,GACrB,cAAc,GACd,eAAe,GACf,eAAe,GACf,eAAe,CAAC;AAEtB,qBAAa,YAAa,SAAQ,KAAK;IAGxB,IAAI,EAAE,gBAAgB;IACtB,UAAU,CAAC,EAAE,MAAM;IACnB,aAAa,CAAC,EAAE,GAAG;gBAH1B,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,gBAAgB,EACtB,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,aAAa,CAAC,EAAE,GAAG,YAAA;CAMjC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CA0ChE"}
|
|
1
|
+
{"version":3,"file":"errorHandler.d.ts","sourceRoot":"","sources":["../../utilities/errorHandler.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAEnC,MAAM,WAAW,cAAc;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IACxC,SAAS,CAAC,EAAE,MAAM,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,CAAC;IACjD,MAAM,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,MAAM,gBAAgB,GACtB,iBAAiB,GACjB,mBAAmB,GACnB,WAAW,GACX,qBAAqB,GACrB,cAAc,GACd,eAAe,GACf,eAAe,GACf,eAAe,CAAC;AAEtB,qBAAa,YAAa,SAAQ,KAAK;IAGxB,IAAI,EAAE,gBAAgB;IACtB,UAAU,CAAC,EAAE,MAAM;IACnB,aAAa,CAAC,EAAE,GAAG;gBAH1B,OAAO,EAAE,MAAM,EACR,IAAI,EAAE,gBAAgB,EACtB,UAAU,CAAC,EAAE,MAAM,YAAA,EACnB,aAAa,CAAC,EAAE,GAAG,YAAA;CAMjC;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,CA0ChE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../utilities/errorHandler.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"errorHandler.js","sourceRoot":"","sources":["../../utilities/errorHandler.ts"],"names":[],"mappings":";;;AAuCA,4CA0CC;AA1DD,MAAa,YAAa,SAAQ,KAAK;IACnC,YACI,OAAe,EACR,IAAsB,EACtB,UAAmB,EACnB,aAAmB;QAE1B,KAAK,CAAC,OAAO,CAAC,CAAC;QAJR,SAAI,GAAJ,IAAI,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ACN,CAAC;AACL,CAAC"}
|
package/index.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import * as fs from 'fs';
|
|
3
|
-
import * as path from 'path';
|
|
4
1
|
import { VoltEnvError, VoltEnvOptions } from './utilities/errorHandler';
|
|
5
2
|
import { HttpClient } from './utilities/httpClient';
|
|
6
3
|
import { CacheService } from './utilities/cacheService';
|
|
@@ -9,18 +6,20 @@ export class VoltEnv {
|
|
|
9
6
|
private httpClient: HttpClient;
|
|
10
7
|
private cacheService: CacheService | null;
|
|
11
8
|
private resolvedPrefix: string = '';
|
|
9
|
+
private environment: string;
|
|
12
10
|
|
|
13
11
|
/**
|
|
14
12
|
* Initialize the VoltEnv SDK
|
|
15
13
|
* @param options Configuration options or API key string
|
|
16
14
|
*/
|
|
17
|
-
constructor(options: VoltEnvOptions
|
|
15
|
+
constructor(options: VoltEnvOptions) {
|
|
18
16
|
const config = typeof options === 'string'
|
|
19
|
-
? { apiKey: options }
|
|
17
|
+
? { apiKey: options, environment: 'development' }
|
|
20
18
|
: options;
|
|
21
19
|
|
|
22
20
|
const {
|
|
23
21
|
apiKey,
|
|
22
|
+
environment,
|
|
24
23
|
baseURL = 'https://api.voltenv.com',
|
|
25
24
|
timeout = 5000,
|
|
26
25
|
cache = true,
|
|
@@ -29,6 +28,12 @@ export class VoltEnv {
|
|
|
29
28
|
prefix
|
|
30
29
|
} = config;
|
|
31
30
|
|
|
31
|
+
if (!environment) {
|
|
32
|
+
throw new Error('Environment is required in VoltEnv constructor');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.environment = environment;
|
|
36
|
+
|
|
32
37
|
this.httpClient = new HttpClient({
|
|
33
38
|
apiKey,
|
|
34
39
|
baseURL,
|
|
@@ -62,9 +67,21 @@ export class VoltEnv {
|
|
|
62
67
|
|
|
63
68
|
/**
|
|
64
69
|
* Try to detect the framework from package.json by searching up the directory tree
|
|
70
|
+
* Only works in Node.js environments
|
|
65
71
|
*/
|
|
66
72
|
private detectFramework(): string {
|
|
73
|
+
const isNode = typeof process !== 'undefined'
|
|
74
|
+
&& process.versions != null
|
|
75
|
+
&& process.versions.node != null;
|
|
76
|
+
|
|
77
|
+
if (!isNode) {
|
|
78
|
+
return '';
|
|
79
|
+
}
|
|
80
|
+
|
|
67
81
|
try {
|
|
82
|
+
const fs = require('fs');
|
|
83
|
+
const path = require('path');
|
|
84
|
+
|
|
68
85
|
let currentDir = process.cwd();
|
|
69
86
|
const rootDir = path.parse(currentDir).root;
|
|
70
87
|
|
|
@@ -80,26 +97,25 @@ export class VoltEnv {
|
|
|
80
97
|
...(packageJson.devDependencies || {})
|
|
81
98
|
};
|
|
82
99
|
|
|
83
|
-
// Check more specific frameworks first
|
|
84
100
|
if (deps['@remix-run/dev'] || deps['@remix-run/node']) return 'remix';
|
|
85
101
|
if (deps['next'] || fs.existsSync(path.join(currentDir, 'next.config.js'))) return 'nextjs';
|
|
86
|
-
if (deps['nuxt'] || fs.existsSync(path.join(currentDir, 'nuxt.config.ts'))) return 'nuxt';
|
|
87
102
|
if (deps['@sveltejs/kit']) return 'sveltekit';
|
|
103
|
+
if (deps['nuxt'] || fs.existsSync(path.join(currentDir, 'nuxt.config.ts'))) return 'nuxt';
|
|
88
104
|
if (deps['astro']) return 'astro';
|
|
89
105
|
if (deps['react-scripts']) return 'cra';
|
|
90
106
|
if (deps['vite']) return 'vite';
|
|
91
107
|
} catch (e) {
|
|
92
|
-
// Ignore parse errors
|
|
108
|
+
// Ignore parse errors
|
|
93
109
|
}
|
|
94
110
|
}
|
|
95
111
|
|
|
96
112
|
if (currentDir === rootDir) break;
|
|
97
113
|
const parentDir = path.dirname(currentDir);
|
|
98
|
-
if (parentDir === currentDir) break;
|
|
114
|
+
if (parentDir === currentDir) break;
|
|
99
115
|
currentDir = parentDir;
|
|
100
116
|
}
|
|
101
117
|
} catch (error) {
|
|
102
|
-
// Silently fail
|
|
118
|
+
// Silently fail
|
|
103
119
|
}
|
|
104
120
|
return '';
|
|
105
121
|
}
|
|
@@ -115,18 +131,19 @@ export class VoltEnv {
|
|
|
115
131
|
|
|
116
132
|
/**
|
|
117
133
|
* Get a variable from a specific environment
|
|
118
|
-
* @param environment The environment name (e.g., 'production', 'development')
|
|
119
134
|
* @param key The variable key
|
|
135
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
120
136
|
* @param defaultValue Optional default value if not found
|
|
121
137
|
* @returns The variable value or the default value
|
|
122
138
|
*/
|
|
123
139
|
async get(
|
|
124
|
-
environment: string,
|
|
125
140
|
key: string,
|
|
141
|
+
environment?: string,
|
|
126
142
|
defaultValue?: string
|
|
127
143
|
): Promise<string | undefined> {
|
|
144
|
+
const env = environment || this.environment;
|
|
128
145
|
const prefixedKey = this.applyPrefix(key);
|
|
129
|
-
const cacheKey = `${
|
|
146
|
+
const cacheKey = `${env}:${prefixedKey}`;
|
|
130
147
|
|
|
131
148
|
if (this.cacheService?.has(cacheKey)) {
|
|
132
149
|
return this.cacheService.get<string>(cacheKey);
|
|
@@ -134,7 +151,7 @@ export class VoltEnv {
|
|
|
134
151
|
|
|
135
152
|
try {
|
|
136
153
|
const data = await this.httpClient.get<{ value: string }>(
|
|
137
|
-
`/v1/variables/${
|
|
154
|
+
`/v1/variables/${env}/${prefixedKey}`
|
|
138
155
|
);
|
|
139
156
|
|
|
140
157
|
const value = data.value;
|
|
@@ -154,19 +171,20 @@ export class VoltEnv {
|
|
|
154
171
|
|
|
155
172
|
/**
|
|
156
173
|
* Get all variables from an environment
|
|
157
|
-
* @param environment
|
|
174
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
158
175
|
* @returns A record of key-value pairs
|
|
159
176
|
*/
|
|
160
|
-
async getAll(environment
|
|
177
|
+
async getAll(environment?: string): Promise<Record<string, string>> {
|
|
178
|
+
const env = environment || this.environment;
|
|
161
179
|
const data = await this.httpClient.get<{ variables: Record<string, string> }>(
|
|
162
|
-
`/v1/variables/${
|
|
180
|
+
`/v1/variables/${env}`
|
|
163
181
|
);
|
|
164
182
|
|
|
165
183
|
const variables = data.variables;
|
|
166
184
|
|
|
167
185
|
if (this.cacheService) {
|
|
168
186
|
Object.entries(variables).forEach(([key, value]) => {
|
|
169
|
-
this.cacheService!.set(`${
|
|
187
|
+
this.cacheService!.set(`${env}:${key}`, value);
|
|
170
188
|
});
|
|
171
189
|
}
|
|
172
190
|
|
|
@@ -175,64 +193,67 @@ export class VoltEnv {
|
|
|
175
193
|
|
|
176
194
|
/**
|
|
177
195
|
* Set a variable in a specific environment
|
|
178
|
-
* @param environment The environment name
|
|
179
196
|
* @param key The variable key
|
|
180
197
|
* @param value The variable value
|
|
198
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
181
199
|
*/
|
|
182
200
|
async set(
|
|
183
|
-
environment: string,
|
|
184
201
|
key: string,
|
|
185
|
-
value: string
|
|
202
|
+
value: string,
|
|
203
|
+
environment?: string
|
|
186
204
|
): Promise<void> {
|
|
205
|
+
const env = environment || this.environment;
|
|
187
206
|
const prefixedKey = this.applyPrefix(key);
|
|
188
|
-
await this.httpClient.put(`/v1/variables/${
|
|
207
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
189
208
|
value,
|
|
190
209
|
});
|
|
191
210
|
|
|
192
211
|
if (this.cacheService) {
|
|
193
|
-
this.cacheService.set(`${
|
|
212
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
194
213
|
}
|
|
195
214
|
}
|
|
196
215
|
|
|
197
216
|
/**
|
|
198
217
|
* Set a secret variable in a specific environment
|
|
199
|
-
* @param environment The environment name
|
|
200
218
|
* @param key The variable key
|
|
201
219
|
* @param value The secret value
|
|
220
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
202
221
|
*/
|
|
203
222
|
async setSecret(
|
|
204
|
-
environment: string,
|
|
205
223
|
key: string,
|
|
206
|
-
value: string
|
|
224
|
+
value: string,
|
|
225
|
+
environment?: string
|
|
207
226
|
): Promise<void> {
|
|
227
|
+
const env = environment || this.environment;
|
|
208
228
|
const prefixedKey = this.applyPrefix(key);
|
|
209
|
-
await this.httpClient.put(`/v1/variables/${
|
|
229
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
210
230
|
value,
|
|
211
231
|
isSecret: true
|
|
212
232
|
});
|
|
213
233
|
|
|
214
234
|
if (this.cacheService) {
|
|
215
|
-
this.cacheService.set(`${
|
|
235
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
216
236
|
}
|
|
217
237
|
}
|
|
218
238
|
|
|
219
239
|
/**
|
|
220
240
|
* Watch for changes in an environment
|
|
221
|
-
* @param environment The environment name
|
|
222
241
|
* @param callback Function to call when changes occur
|
|
223
242
|
* @param interval Polling interval in milliseconds (default: 30000)
|
|
243
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
224
244
|
* @returns A function to stop watching
|
|
225
245
|
*/
|
|
226
246
|
watch(
|
|
227
|
-
environment: string,
|
|
228
247
|
callback: (variables: Record<string, string>) => void,
|
|
229
|
-
interval: number = 30000
|
|
248
|
+
interval: number = 30000,
|
|
249
|
+
environment?: string
|
|
230
250
|
): () => void {
|
|
251
|
+
const env = environment || this.environment;
|
|
231
252
|
let previousVariables: string = '';
|
|
232
253
|
|
|
233
254
|
const fetchAndCompare = async () => {
|
|
234
255
|
try {
|
|
235
|
-
const variables = await this.getAll(
|
|
256
|
+
const variables = await this.getAll(env);
|
|
236
257
|
const currentVariables = JSON.stringify(variables);
|
|
237
258
|
|
|
238
259
|
if (currentVariables !== previousVariables) {
|
|
@@ -240,7 +261,7 @@ export class VoltEnv {
|
|
|
240
261
|
callback(variables);
|
|
241
262
|
}
|
|
242
263
|
} catch (error) {
|
|
243
|
-
console.error(`Error in VoltEnv watcher for ${
|
|
264
|
+
console.error(`Error in VoltEnv watcher for ${env}:`, error);
|
|
244
265
|
}
|
|
245
266
|
};
|
|
246
267
|
|
|
@@ -254,108 +275,141 @@ export class VoltEnv {
|
|
|
254
275
|
|
|
255
276
|
/**
|
|
256
277
|
* Set multiple variables at once
|
|
257
|
-
* @param environment The environment name
|
|
258
278
|
* @param variables A record of key-value pairs to set
|
|
279
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
259
280
|
*/
|
|
260
281
|
async setMany(
|
|
261
|
-
|
|
262
|
-
|
|
282
|
+
variables: Record<string, string>,
|
|
283
|
+
environment?: string
|
|
263
284
|
): Promise<void> {
|
|
285
|
+
const env = environment || this.environment;
|
|
264
286
|
const prefixedVariables: Record<string, string> = {};
|
|
265
287
|
Object.entries(variables).forEach(([key, value]) => {
|
|
266
288
|
prefixedVariables[this.applyPrefix(key)] = value;
|
|
267
289
|
});
|
|
268
290
|
|
|
269
|
-
await this.httpClient.post(`/v1/variables/${
|
|
291
|
+
await this.httpClient.post(`/v1/variables/${env}/batch`, {
|
|
270
292
|
variables: prefixedVariables,
|
|
271
293
|
});
|
|
272
294
|
|
|
273
295
|
if (this.cacheService) {
|
|
274
296
|
Object.entries(prefixedVariables).forEach(([key, value]) => {
|
|
275
|
-
this.cacheService!.set(`${
|
|
297
|
+
this.cacheService!.set(`${env}:${key}`, value);
|
|
276
298
|
});
|
|
277
299
|
}
|
|
278
300
|
}
|
|
279
301
|
|
|
280
302
|
/**
|
|
281
303
|
* Delete a variable from a specific environment
|
|
282
|
-
* @param environment The environment name
|
|
283
304
|
* @param key The variable key
|
|
305
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
284
306
|
*/
|
|
285
|
-
async delete(
|
|
307
|
+
async delete(key: string, environment?: string): Promise<void> {
|
|
308
|
+
const env = environment || this.environment;
|
|
286
309
|
const prefixedKey = this.applyPrefix(key);
|
|
287
|
-
await this.httpClient.delete(`/v1/variables/${
|
|
310
|
+
await this.httpClient.delete(`/v1/variables/${env}/${prefixedKey}`);
|
|
288
311
|
|
|
289
312
|
if (this.cacheService) {
|
|
290
|
-
this.cacheService.delete(`${
|
|
313
|
+
this.cacheService.delete(`${env}:${prefixedKey}`);
|
|
291
314
|
}
|
|
292
315
|
}
|
|
293
316
|
|
|
294
317
|
/**
|
|
295
318
|
* Delete multiple variables at once
|
|
296
|
-
* @param environment The environment name
|
|
297
319
|
* @param keys Array of keys to delete
|
|
320
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
298
321
|
*/
|
|
299
|
-
async deleteMany(
|
|
322
|
+
async deleteMany(keys: string[], environment?: string): Promise<void> {
|
|
323
|
+
const env = environment || this.environment;
|
|
300
324
|
const prefixedKeys = keys.map(k => this.applyPrefix(k));
|
|
301
|
-
await this.httpClient.post(`/v1/variables/${
|
|
325
|
+
await this.httpClient.post(`/v1/variables/${env}/batch-delete`, {
|
|
302
326
|
keys: prefixedKeys,
|
|
303
327
|
});
|
|
304
328
|
|
|
305
329
|
if (this.cacheService) {
|
|
306
330
|
prefixedKeys.forEach(key => {
|
|
307
|
-
this.cacheService!.delete(`${
|
|
331
|
+
this.cacheService!.delete(`${env}:${key}`);
|
|
308
332
|
});
|
|
309
333
|
}
|
|
310
334
|
}
|
|
311
335
|
|
|
312
336
|
/**
|
|
313
337
|
* Export all variables in an environment to a .env file
|
|
314
|
-
*
|
|
338
|
+
* Node.js only - will throw error in browser
|
|
315
339
|
* @param filePath Path to the .env file to create/overwrite
|
|
340
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
316
341
|
*/
|
|
317
|
-
async exportToEnvFile(
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
342
|
+
async exportToEnvFile(filePath: string, environment?: string): Promise<void> {
|
|
343
|
+
// Check if we're in Node.js
|
|
344
|
+
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
345
|
+
throw new Error('exportToEnvFile is only available in Node.js environments');
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
const env = environment || this.environment;
|
|
349
|
+
|
|
350
|
+
try {
|
|
351
|
+
const fs = require('fs');
|
|
352
|
+
const path = require('path');
|
|
353
|
+
|
|
354
|
+
const variables = await this.getAll(env);
|
|
355
|
+
const content = Object.entries(variables)
|
|
356
|
+
.map(([key, value]) => `${key}=${value}`)
|
|
357
|
+
.join('\n');
|
|
322
358
|
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
359
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
360
|
+
? filePath
|
|
361
|
+
: path.join(process.cwd(), filePath);
|
|
326
362
|
|
|
327
|
-
|
|
363
|
+
fs.writeFileSync(absolutePath, content, 'utf8');
|
|
364
|
+
} catch (error) {
|
|
365
|
+
throw new Error(`Failed to export to env file: ${error}`);
|
|
366
|
+
}
|
|
328
367
|
}
|
|
329
368
|
|
|
330
369
|
/**
|
|
331
370
|
* Load variables from a .env file and set them in an environment
|
|
332
|
-
*
|
|
371
|
+
* Node.js only - will throw error in browser
|
|
333
372
|
* @param filePath Path to the .env file to read from
|
|
373
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
334
374
|
*/
|
|
335
|
-
async loadFromEnvFile(
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
if (!fs.existsSync(absolutePath)) {
|
|
341
|
-
throw new Error(`File not found: ${absolutePath}`);
|
|
375
|
+
async loadFromEnvFile(filePath: string, environment?: string): Promise<void> {
|
|
376
|
+
// Check if we're in Node.js
|
|
377
|
+
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
378
|
+
throw new Error('loadFromEnvFile is only available in Node.js environments');
|
|
342
379
|
}
|
|
343
380
|
|
|
344
|
-
const
|
|
345
|
-
const variables: Record<string, string> = {};
|
|
381
|
+
const env = environment || this.environment;
|
|
346
382
|
|
|
347
|
-
|
|
348
|
-
const
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
383
|
+
try {
|
|
384
|
+
const fs = require('fs');
|
|
385
|
+
const path = require('path');
|
|
386
|
+
|
|
387
|
+
const absolutePath = path.isAbsolute(filePath)
|
|
388
|
+
? filePath
|
|
389
|
+
: path.join(process.cwd(), filePath);
|
|
390
|
+
|
|
391
|
+
if (!fs.existsSync(absolutePath)) {
|
|
392
|
+
throw new Error(`File not found: ${absolutePath}`);
|
|
354
393
|
}
|
|
355
|
-
});
|
|
356
394
|
|
|
357
|
-
|
|
358
|
-
|
|
395
|
+
const content = fs.readFileSync(absolutePath, 'utf8');
|
|
396
|
+
const variables: Record<string, string> = {};
|
|
397
|
+
|
|
398
|
+
content.split(/\r?\n/).forEach((line: string) => {
|
|
399
|
+
const trimmedLine = line.trim();
|
|
400
|
+
if (trimmedLine && !trimmedLine.startsWith('#')) {
|
|
401
|
+
const [key, ...valueParts] = trimmedLine.split('=');
|
|
402
|
+
if (key) {
|
|
403
|
+
variables[key.trim()] = valueParts.join('=').trim();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
if (Object.keys(variables).length > 0) {
|
|
409
|
+
await this.setMany(variables, env);
|
|
410
|
+
}
|
|
411
|
+
} catch (error) {
|
|
412
|
+
throw new Error(`Failed to load from env file: ${error}`);
|
|
359
413
|
}
|
|
360
414
|
}
|
|
361
415
|
|
|
@@ -405,52 +459,53 @@ export class VoltEnv {
|
|
|
405
459
|
|
|
406
460
|
/**
|
|
407
461
|
* Sync/refresh variables from server (bypassing cache)
|
|
408
|
-
*If an environment is provided, it
|
|
409
|
-
* If no environment is provided, it
|
|
462
|
+
* If an environment is provided, it syncs that environment.
|
|
463
|
+
* If no environment is provided, it syncs the instance environment.
|
|
410
464
|
* @param environment Optional environment to sync
|
|
411
465
|
*/
|
|
412
466
|
async sync(environment?: string): Promise<void> {
|
|
413
|
-
|
|
414
|
-
|
|
467
|
+
const env = environment || this.environment;
|
|
468
|
+
const variables = await this.getAll(env);
|
|
415
469
|
|
|
416
|
-
|
|
417
|
-
|
|
470
|
+
if (this.cacheService) {
|
|
471
|
+
this.cacheService.deleteByPrefix(`${env}:`);
|
|
418
472
|
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
const environments = await this.listEnvironments();
|
|
473
|
+
Object.entries(variables).forEach(([key, value]) => {
|
|
474
|
+
this.cacheService!.set(`${env}:${key}`, value);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
425
478
|
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
479
|
+
/**
|
|
480
|
+
* Sync/refresh all environments accessible by this API key
|
|
481
|
+
*/
|
|
482
|
+
async syncAll(): Promise<void> {
|
|
483
|
+
const environments = await this.listEnvironments();
|
|
484
|
+
|
|
485
|
+
for (const env of environments) {
|
|
486
|
+
await this.sync(env);
|
|
429
487
|
}
|
|
430
488
|
}
|
|
431
489
|
|
|
432
490
|
/**
|
|
433
|
-
*
|
|
491
|
+
* Clear the entire cache
|
|
434
492
|
*/
|
|
435
|
-
|
|
436
|
-
if (
|
|
437
|
-
|
|
493
|
+
clearCache(): void {
|
|
494
|
+
if (this.cacheService) {
|
|
495
|
+
this.cacheService.clear();
|
|
438
496
|
}
|
|
439
|
-
return Array.from(this.cacheService.keys());
|
|
440
497
|
}
|
|
441
498
|
|
|
442
499
|
/**
|
|
443
|
-
* Get
|
|
500
|
+
* Get all cached keys (for debugging)
|
|
444
501
|
*/
|
|
445
|
-
|
|
502
|
+
getCacheKeys(): string[] {
|
|
446
503
|
if (!this.cacheService) {
|
|
447
|
-
return
|
|
504
|
+
return [];
|
|
448
505
|
}
|
|
449
|
-
return
|
|
450
|
-
size: this.cacheService.size,
|
|
451
|
-
keys: Array.from(this.cacheService.keys())
|
|
452
|
-
};
|
|
506
|
+
return Array.from(this.cacheService.keys());
|
|
453
507
|
}
|
|
508
|
+
|
|
454
509
|
}
|
|
455
510
|
|
|
456
|
-
export default VoltEnv;
|
|
511
|
+
export default VoltEnv;
|
package/package.json
CHANGED
package/tsconfig.json
CHANGED