voltenv-sdk 1.1.3 → 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 +28 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +70 -57
- 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 +83 -63
- package/package.json +1 -1
- package/utilities/errorHandler.ts +1 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,11 +3,12 @@ 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
|
*/
|
|
@@ -23,72 +24,72 @@ export declare class VoltEnv {
|
|
|
23
24
|
private applyPrefix;
|
|
24
25
|
/**
|
|
25
26
|
* Get a variable from a specific environment
|
|
26
|
-
* @param environment The environment name (e.g., 'production', 'development')
|
|
27
27
|
* @param key The variable key
|
|
28
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
28
29
|
* @param defaultValue Optional default value if not found
|
|
29
30
|
* @returns The variable value or the default value
|
|
30
31
|
*/
|
|
31
|
-
get(
|
|
32
|
+
get(key: string, environment?: string, defaultValue?: string): Promise<string | undefined>;
|
|
32
33
|
/**
|
|
33
34
|
* Get all variables from an environment
|
|
34
|
-
* @param environment
|
|
35
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
35
36
|
* @returns A record of key-value pairs
|
|
36
37
|
*/
|
|
37
|
-
getAll(environment
|
|
38
|
+
getAll(environment?: string): Promise<Record<string, string>>;
|
|
38
39
|
/**
|
|
39
40
|
* Set a variable in a specific environment
|
|
40
|
-
* @param environment The environment name
|
|
41
41
|
* @param key The variable key
|
|
42
42
|
* @param value The variable value
|
|
43
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
43
44
|
*/
|
|
44
|
-
set(
|
|
45
|
+
set(key: string, value: string, environment?: string): Promise<void>;
|
|
45
46
|
/**
|
|
46
47
|
* Set a secret variable in a specific environment
|
|
47
|
-
* @param environment The environment name
|
|
48
48
|
* @param key The variable key
|
|
49
49
|
* @param value The secret value
|
|
50
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
50
51
|
*/
|
|
51
|
-
setSecret(
|
|
52
|
+
setSecret(key: string, value: string, environment?: string): Promise<void>;
|
|
52
53
|
/**
|
|
53
54
|
* Watch for changes in an environment
|
|
54
|
-
* @param environment The environment name
|
|
55
55
|
* @param callback Function to call when changes occur
|
|
56
56
|
* @param interval Polling interval in milliseconds (default: 30000)
|
|
57
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
57
58
|
* @returns A function to stop watching
|
|
58
59
|
*/
|
|
59
|
-
watch(
|
|
60
|
+
watch(callback: (variables: Record<string, string>) => void, interval?: number, environment?: string): () => void;
|
|
60
61
|
/**
|
|
61
62
|
* Set multiple variables at once
|
|
62
|
-
* @param environment The environment name
|
|
63
63
|
* @param variables A record of key-value pairs to set
|
|
64
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
64
65
|
*/
|
|
65
|
-
setMany(
|
|
66
|
+
setMany(variables: Record<string, string>, environment?: string): Promise<void>;
|
|
66
67
|
/**
|
|
67
68
|
* Delete a variable from a specific environment
|
|
68
|
-
* @param environment The environment name
|
|
69
69
|
* @param key The variable key
|
|
70
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
70
71
|
*/
|
|
71
|
-
delete(
|
|
72
|
+
delete(key: string, environment?: string): Promise<void>;
|
|
72
73
|
/**
|
|
73
74
|
* Delete multiple variables at once
|
|
74
|
-
* @param environment The environment name
|
|
75
75
|
* @param keys Array of keys to delete
|
|
76
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
76
77
|
*/
|
|
77
|
-
deleteMany(
|
|
78
|
+
deleteMany(keys: string[], environment?: string): Promise<void>;
|
|
78
79
|
/**
|
|
79
80
|
* Export all variables in an environment to a .env file
|
|
80
81
|
* Node.js only - will throw error in browser
|
|
81
|
-
* @param environment The environment name
|
|
82
82
|
* @param filePath Path to the .env file to create/overwrite
|
|
83
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
83
84
|
*/
|
|
84
|
-
exportToEnvFile(
|
|
85
|
+
exportToEnvFile(filePath: string, environment?: string): Promise<void>;
|
|
85
86
|
/**
|
|
86
87
|
* Load variables from a .env file and set them in an environment
|
|
87
88
|
* Node.js only - will throw error in browser
|
|
88
|
-
* @param environment The environment name
|
|
89
89
|
* @param filePath Path to the .env file to read from
|
|
90
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
90
91
|
*/
|
|
91
|
-
loadFromEnvFile(
|
|
92
|
+
loadFromEnvFile(filePath: string, environment?: string): Promise<void>;
|
|
92
93
|
/**
|
|
93
94
|
* List all environments accessible by this API key
|
|
94
95
|
* @returns Array of environment names
|
|
@@ -113,11 +114,15 @@ export declare class VoltEnv {
|
|
|
113
114
|
deleteEnvironment(name: string): Promise<void>;
|
|
114
115
|
/**
|
|
115
116
|
* Sync/refresh variables from server (bypassing cache)
|
|
116
|
-
* If an environment is provided, it
|
|
117
|
-
* 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.
|
|
118
119
|
* @param environment Optional environment to sync
|
|
119
120
|
*/
|
|
120
121
|
sync(environment?: string): Promise<void>;
|
|
122
|
+
/**
|
|
123
|
+
* Sync/refresh all environments accessible by this API key
|
|
124
|
+
*/
|
|
125
|
+
syncAll(): Promise<void>;
|
|
121
126
|
/**
|
|
122
127
|
* Clear the entire cache
|
|
123
128
|
*/
|
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,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAiBnE;;;;;OAKG;IACG,GAAG,CACL,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;;OAKG;IACG,SAAS,CACX,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,MAAM,EACb,WAAW,CAAC,EAAE,MAAM,GACrB,OAAO,CAAC,IAAI,CAAC;IAahB;;;;;;OAMG;IACH,KAAK,CACD,QAAQ,EAAE,CAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,IAAI,EACrD,QAAQ,G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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,7 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Remove these imports entirely
|
|
3
|
-
// import * as fs from 'fs';
|
|
4
|
-
// import * as path from 'path';
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.VoltEnv = void 0;
|
|
7
4
|
const errorHandler_1 = require("./utilities/errorHandler");
|
|
@@ -15,9 +12,13 @@ class VoltEnv {
|
|
|
15
12
|
constructor(options) {
|
|
16
13
|
this.resolvedPrefix = '';
|
|
17
14
|
const config = typeof options === 'string'
|
|
18
|
-
? { apiKey: options }
|
|
15
|
+
? { apiKey: options, environment: 'development' }
|
|
19
16
|
: options;
|
|
20
|
-
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;
|
|
21
22
|
this.httpClient = new httpClient_1.HttpClient({
|
|
22
23
|
apiKey,
|
|
23
24
|
baseURL,
|
|
@@ -115,19 +116,20 @@ class VoltEnv {
|
|
|
115
116
|
}
|
|
116
117
|
/**
|
|
117
118
|
* Get a variable from a specific environment
|
|
118
|
-
* @param environment The environment name (e.g., 'production', 'development')
|
|
119
119
|
* @param key The variable key
|
|
120
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
120
121
|
* @param defaultValue Optional default value if not found
|
|
121
122
|
* @returns The variable value or the default value
|
|
122
123
|
*/
|
|
123
|
-
async get(
|
|
124
|
+
async get(key, environment, defaultValue) {
|
|
125
|
+
const env = environment || this.environment;
|
|
124
126
|
const prefixedKey = this.applyPrefix(key);
|
|
125
|
-
const cacheKey = `${
|
|
127
|
+
const cacheKey = `${env}:${prefixedKey}`;
|
|
126
128
|
if (this.cacheService?.has(cacheKey)) {
|
|
127
129
|
return this.cacheService.get(cacheKey);
|
|
128
130
|
}
|
|
129
131
|
try {
|
|
130
|
-
const data = await this.httpClient.get(`/v1/variables/${
|
|
132
|
+
const data = await this.httpClient.get(`/v1/variables/${env}/${prefixedKey}`);
|
|
131
133
|
const value = data.value;
|
|
132
134
|
if (value && this.cacheService) {
|
|
133
135
|
this.cacheService.set(cacheKey, value);
|
|
@@ -143,62 +145,66 @@ class VoltEnv {
|
|
|
143
145
|
}
|
|
144
146
|
/**
|
|
145
147
|
* Get all variables from an environment
|
|
146
|
-
* @param environment
|
|
148
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
147
149
|
* @returns A record of key-value pairs
|
|
148
150
|
*/
|
|
149
151
|
async getAll(environment) {
|
|
150
|
-
const
|
|
152
|
+
const env = environment || this.environment;
|
|
153
|
+
const data = await this.httpClient.get(`/v1/variables/${env}`);
|
|
151
154
|
const variables = data.variables;
|
|
152
155
|
if (this.cacheService) {
|
|
153
156
|
Object.entries(variables).forEach(([key, value]) => {
|
|
154
|
-
this.cacheService.set(`${
|
|
157
|
+
this.cacheService.set(`${env}:${key}`, value);
|
|
155
158
|
});
|
|
156
159
|
}
|
|
157
160
|
return variables;
|
|
158
161
|
}
|
|
159
162
|
/**
|
|
160
163
|
* Set a variable in a specific environment
|
|
161
|
-
* @param environment The environment name
|
|
162
164
|
* @param key The variable key
|
|
163
165
|
* @param value The variable value
|
|
166
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
164
167
|
*/
|
|
165
|
-
async set(
|
|
168
|
+
async set(key, value, environment) {
|
|
169
|
+
const env = environment || this.environment;
|
|
166
170
|
const prefixedKey = this.applyPrefix(key);
|
|
167
|
-
await this.httpClient.put(`/v1/variables/${
|
|
171
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
168
172
|
value,
|
|
169
173
|
});
|
|
170
174
|
if (this.cacheService) {
|
|
171
|
-
this.cacheService.set(`${
|
|
175
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
172
176
|
}
|
|
173
177
|
}
|
|
174
178
|
/**
|
|
175
179
|
* Set a secret variable in a specific environment
|
|
176
|
-
* @param environment The environment name
|
|
177
180
|
* @param key The variable key
|
|
178
181
|
* @param value The secret value
|
|
182
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
179
183
|
*/
|
|
180
|
-
async setSecret(
|
|
184
|
+
async setSecret(key, value, environment) {
|
|
185
|
+
const env = environment || this.environment;
|
|
181
186
|
const prefixedKey = this.applyPrefix(key);
|
|
182
|
-
await this.httpClient.put(`/v1/variables/${
|
|
187
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
183
188
|
value,
|
|
184
189
|
isSecret: true
|
|
185
190
|
});
|
|
186
191
|
if (this.cacheService) {
|
|
187
|
-
this.cacheService.set(`${
|
|
192
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
188
193
|
}
|
|
189
194
|
}
|
|
190
195
|
/**
|
|
191
196
|
* Watch for changes in an environment
|
|
192
|
-
* @param environment The environment name
|
|
193
197
|
* @param callback Function to call when changes occur
|
|
194
198
|
* @param interval Polling interval in milliseconds (default: 30000)
|
|
199
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
195
200
|
* @returns A function to stop watching
|
|
196
201
|
*/
|
|
197
|
-
watch(
|
|
202
|
+
watch(callback, interval = 30000, environment) {
|
|
203
|
+
const env = environment || this.environment;
|
|
198
204
|
let previousVariables = '';
|
|
199
205
|
const fetchAndCompare = async () => {
|
|
200
206
|
try {
|
|
201
|
-
const variables = await this.getAll(
|
|
207
|
+
const variables = await this.getAll(env);
|
|
202
208
|
const currentVariables = JSON.stringify(variables);
|
|
203
209
|
if (currentVariables !== previousVariables) {
|
|
204
210
|
previousVariables = currentVariables;
|
|
@@ -206,7 +212,7 @@ class VoltEnv {
|
|
|
206
212
|
}
|
|
207
213
|
}
|
|
208
214
|
catch (error) {
|
|
209
|
-
console.error(`Error in VoltEnv watcher for ${
|
|
215
|
+
console.error(`Error in VoltEnv watcher for ${env}:`, error);
|
|
210
216
|
}
|
|
211
217
|
};
|
|
212
218
|
// Initial fetch
|
|
@@ -216,66 +222,70 @@ class VoltEnv {
|
|
|
216
222
|
}
|
|
217
223
|
/**
|
|
218
224
|
* Set multiple variables at once
|
|
219
|
-
* @param environment The environment name
|
|
220
225
|
* @param variables A record of key-value pairs to set
|
|
226
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
221
227
|
*/
|
|
222
|
-
async setMany(
|
|
228
|
+
async setMany(variables, environment) {
|
|
229
|
+
const env = environment || this.environment;
|
|
223
230
|
const prefixedVariables = {};
|
|
224
231
|
Object.entries(variables).forEach(([key, value]) => {
|
|
225
232
|
prefixedVariables[this.applyPrefix(key)] = value;
|
|
226
233
|
});
|
|
227
|
-
await this.httpClient.post(`/v1/variables/${
|
|
234
|
+
await this.httpClient.post(`/v1/variables/${env}/batch`, {
|
|
228
235
|
variables: prefixedVariables,
|
|
229
236
|
});
|
|
230
237
|
if (this.cacheService) {
|
|
231
238
|
Object.entries(prefixedVariables).forEach(([key, value]) => {
|
|
232
|
-
this.cacheService.set(`${
|
|
239
|
+
this.cacheService.set(`${env}:${key}`, value);
|
|
233
240
|
});
|
|
234
241
|
}
|
|
235
242
|
}
|
|
236
243
|
/**
|
|
237
244
|
* Delete a variable from a specific environment
|
|
238
|
-
* @param environment The environment name
|
|
239
245
|
* @param key The variable key
|
|
246
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
240
247
|
*/
|
|
241
|
-
async delete(
|
|
248
|
+
async delete(key, environment) {
|
|
249
|
+
const env = environment || this.environment;
|
|
242
250
|
const prefixedKey = this.applyPrefix(key);
|
|
243
|
-
await this.httpClient.delete(`/v1/variables/${
|
|
251
|
+
await this.httpClient.delete(`/v1/variables/${env}/${prefixedKey}`);
|
|
244
252
|
if (this.cacheService) {
|
|
245
|
-
this.cacheService.delete(`${
|
|
253
|
+
this.cacheService.delete(`${env}:${prefixedKey}`);
|
|
246
254
|
}
|
|
247
255
|
}
|
|
248
256
|
/**
|
|
249
257
|
* Delete multiple variables at once
|
|
250
|
-
* @param environment The environment name
|
|
251
258
|
* @param keys Array of keys to delete
|
|
259
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
252
260
|
*/
|
|
253
|
-
async deleteMany(
|
|
261
|
+
async deleteMany(keys, environment) {
|
|
262
|
+
const env = environment || this.environment;
|
|
254
263
|
const prefixedKeys = keys.map(k => this.applyPrefix(k));
|
|
255
|
-
await this.httpClient.post(`/v1/variables/${
|
|
264
|
+
await this.httpClient.post(`/v1/variables/${env}/batch-delete`, {
|
|
256
265
|
keys: prefixedKeys,
|
|
257
266
|
});
|
|
258
267
|
if (this.cacheService) {
|
|
259
268
|
prefixedKeys.forEach(key => {
|
|
260
|
-
this.cacheService.delete(`${
|
|
269
|
+
this.cacheService.delete(`${env}:${key}`);
|
|
261
270
|
});
|
|
262
271
|
}
|
|
263
272
|
}
|
|
264
273
|
/**
|
|
265
274
|
* Export all variables in an environment to a .env file
|
|
266
275
|
* Node.js only - will throw error in browser
|
|
267
|
-
* @param environment The environment name
|
|
268
276
|
* @param filePath Path to the .env file to create/overwrite
|
|
277
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
269
278
|
*/
|
|
270
|
-
async exportToEnvFile(
|
|
279
|
+
async exportToEnvFile(filePath, environment) {
|
|
271
280
|
// Check if we're in Node.js
|
|
272
281
|
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
273
282
|
throw new Error('exportToEnvFile is only available in Node.js environments');
|
|
274
283
|
}
|
|
284
|
+
const env = environment || this.environment;
|
|
275
285
|
try {
|
|
276
286
|
const fs = require('fs');
|
|
277
287
|
const path = require('path');
|
|
278
|
-
const variables = await this.getAll(
|
|
288
|
+
const variables = await this.getAll(env);
|
|
279
289
|
const content = Object.entries(variables)
|
|
280
290
|
.map(([key, value]) => `${key}=${value}`)
|
|
281
291
|
.join('\n');
|
|
@@ -291,14 +301,15 @@ class VoltEnv {
|
|
|
291
301
|
/**
|
|
292
302
|
* Load variables from a .env file and set them in an environment
|
|
293
303
|
* Node.js only - will throw error in browser
|
|
294
|
-
* @param environment The environment name
|
|
295
304
|
* @param filePath Path to the .env file to read from
|
|
305
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
296
306
|
*/
|
|
297
|
-
async loadFromEnvFile(
|
|
307
|
+
async loadFromEnvFile(filePath, environment) {
|
|
298
308
|
// Check if we're in Node.js
|
|
299
309
|
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
300
310
|
throw new Error('loadFromEnvFile is only available in Node.js environments');
|
|
301
311
|
}
|
|
312
|
+
const env = environment || this.environment;
|
|
302
313
|
try {
|
|
303
314
|
const fs = require('fs');
|
|
304
315
|
const path = require('path');
|
|
@@ -320,7 +331,7 @@ class VoltEnv {
|
|
|
320
331
|
}
|
|
321
332
|
});
|
|
322
333
|
if (Object.keys(variables).length > 0) {
|
|
323
|
-
await this.setMany(
|
|
334
|
+
await this.setMany(variables, env);
|
|
324
335
|
}
|
|
325
336
|
}
|
|
326
337
|
catch (error) {
|
|
@@ -366,25 +377,27 @@ 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
|
/**
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA,gCAAgC;AAChC,4BAA4B;AAC5B,gCAAgC;;;AAEhC,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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AAY,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,CAAkB;QACtB,eAAU,GAAV,UAAU,CAAS;QACnB,kBAAa,GAAb,aAAa,CAAM;QAG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|
-
// Remove these imports entirely
|
|
2
|
-
// import * as fs from 'fs';
|
|
3
|
-
// import * as path from 'path';
|
|
4
|
-
|
|
5
1
|
import { VoltEnvError, VoltEnvOptions } from './utilities/errorHandler';
|
|
6
2
|
import { HttpClient } from './utilities/httpClient';
|
|
7
3
|
import { CacheService } from './utilities/cacheService';
|
|
@@ -10,18 +6,20 @@ export class VoltEnv {
|
|
|
10
6
|
private httpClient: HttpClient;
|
|
11
7
|
private cacheService: CacheService | null;
|
|
12
8
|
private resolvedPrefix: string = '';
|
|
9
|
+
private environment: string;
|
|
13
10
|
|
|
14
11
|
/**
|
|
15
12
|
* Initialize the VoltEnv SDK
|
|
16
13
|
* @param options Configuration options or API key string
|
|
17
14
|
*/
|
|
18
|
-
constructor(options: VoltEnvOptions
|
|
15
|
+
constructor(options: VoltEnvOptions) {
|
|
19
16
|
const config = typeof options === 'string'
|
|
20
|
-
? { apiKey: options }
|
|
17
|
+
? { apiKey: options, environment: 'development' }
|
|
21
18
|
: options;
|
|
22
19
|
|
|
23
20
|
const {
|
|
24
21
|
apiKey,
|
|
22
|
+
environment,
|
|
25
23
|
baseURL = 'https://api.voltenv.com',
|
|
26
24
|
timeout = 5000,
|
|
27
25
|
cache = true,
|
|
@@ -30,6 +28,12 @@ export class VoltEnv {
|
|
|
30
28
|
prefix
|
|
31
29
|
} = config;
|
|
32
30
|
|
|
31
|
+
if (!environment) {
|
|
32
|
+
throw new Error('Environment is required in VoltEnv constructor');
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
this.environment = environment;
|
|
36
|
+
|
|
33
37
|
this.httpClient = new HttpClient({
|
|
34
38
|
apiKey,
|
|
35
39
|
baseURL,
|
|
@@ -127,18 +131,19 @@ export class VoltEnv {
|
|
|
127
131
|
|
|
128
132
|
/**
|
|
129
133
|
* Get a variable from a specific environment
|
|
130
|
-
* @param environment The environment name (e.g., 'production', 'development')
|
|
131
134
|
* @param key The variable key
|
|
135
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
132
136
|
* @param defaultValue Optional default value if not found
|
|
133
137
|
* @returns The variable value or the default value
|
|
134
138
|
*/
|
|
135
139
|
async get(
|
|
136
|
-
environment: string,
|
|
137
140
|
key: string,
|
|
141
|
+
environment?: string,
|
|
138
142
|
defaultValue?: string
|
|
139
143
|
): Promise<string | undefined> {
|
|
144
|
+
const env = environment || this.environment;
|
|
140
145
|
const prefixedKey = this.applyPrefix(key);
|
|
141
|
-
const cacheKey = `${
|
|
146
|
+
const cacheKey = `${env}:${prefixedKey}`;
|
|
142
147
|
|
|
143
148
|
if (this.cacheService?.has(cacheKey)) {
|
|
144
149
|
return this.cacheService.get<string>(cacheKey);
|
|
@@ -146,7 +151,7 @@ export class VoltEnv {
|
|
|
146
151
|
|
|
147
152
|
try {
|
|
148
153
|
const data = await this.httpClient.get<{ value: string }>(
|
|
149
|
-
`/v1/variables/${
|
|
154
|
+
`/v1/variables/${env}/${prefixedKey}`
|
|
150
155
|
);
|
|
151
156
|
|
|
152
157
|
const value = data.value;
|
|
@@ -166,19 +171,20 @@ export class VoltEnv {
|
|
|
166
171
|
|
|
167
172
|
/**
|
|
168
173
|
* Get all variables from an environment
|
|
169
|
-
* @param environment
|
|
174
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
170
175
|
* @returns A record of key-value pairs
|
|
171
176
|
*/
|
|
172
|
-
async getAll(environment
|
|
177
|
+
async getAll(environment?: string): Promise<Record<string, string>> {
|
|
178
|
+
const env = environment || this.environment;
|
|
173
179
|
const data = await this.httpClient.get<{ variables: Record<string, string> }>(
|
|
174
|
-
`/v1/variables/${
|
|
180
|
+
`/v1/variables/${env}`
|
|
175
181
|
);
|
|
176
182
|
|
|
177
183
|
const variables = data.variables;
|
|
178
184
|
|
|
179
185
|
if (this.cacheService) {
|
|
180
186
|
Object.entries(variables).forEach(([key, value]) => {
|
|
181
|
-
this.cacheService!.set(`${
|
|
187
|
+
this.cacheService!.set(`${env}:${key}`, value);
|
|
182
188
|
});
|
|
183
189
|
}
|
|
184
190
|
|
|
@@ -187,64 +193,67 @@ export class VoltEnv {
|
|
|
187
193
|
|
|
188
194
|
/**
|
|
189
195
|
* Set a variable in a specific environment
|
|
190
|
-
* @param environment The environment name
|
|
191
196
|
* @param key The variable key
|
|
192
197
|
* @param value The variable value
|
|
198
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
193
199
|
*/
|
|
194
200
|
async set(
|
|
195
|
-
environment: string,
|
|
196
201
|
key: string,
|
|
197
|
-
value: string
|
|
202
|
+
value: string,
|
|
203
|
+
environment?: string
|
|
198
204
|
): Promise<void> {
|
|
205
|
+
const env = environment || this.environment;
|
|
199
206
|
const prefixedKey = this.applyPrefix(key);
|
|
200
|
-
await this.httpClient.put(`/v1/variables/${
|
|
207
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
201
208
|
value,
|
|
202
209
|
});
|
|
203
210
|
|
|
204
211
|
if (this.cacheService) {
|
|
205
|
-
this.cacheService.set(`${
|
|
212
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
206
213
|
}
|
|
207
214
|
}
|
|
208
215
|
|
|
209
216
|
/**
|
|
210
217
|
* Set a secret variable in a specific environment
|
|
211
|
-
* @param environment The environment name
|
|
212
218
|
* @param key The variable key
|
|
213
219
|
* @param value The secret value
|
|
220
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
214
221
|
*/
|
|
215
222
|
async setSecret(
|
|
216
|
-
environment: string,
|
|
217
223
|
key: string,
|
|
218
|
-
value: string
|
|
224
|
+
value: string,
|
|
225
|
+
environment?: string
|
|
219
226
|
): Promise<void> {
|
|
227
|
+
const env = environment || this.environment;
|
|
220
228
|
const prefixedKey = this.applyPrefix(key);
|
|
221
|
-
await this.httpClient.put(`/v1/variables/${
|
|
229
|
+
await this.httpClient.put(`/v1/variables/${env}/${prefixedKey}`, {
|
|
222
230
|
value,
|
|
223
231
|
isSecret: true
|
|
224
232
|
});
|
|
225
233
|
|
|
226
234
|
if (this.cacheService) {
|
|
227
|
-
this.cacheService.set(`${
|
|
235
|
+
this.cacheService.set(`${env}:${prefixedKey}`, value);
|
|
228
236
|
}
|
|
229
237
|
}
|
|
230
238
|
|
|
231
239
|
/**
|
|
232
240
|
* Watch for changes in an environment
|
|
233
|
-
* @param environment The environment name
|
|
234
241
|
* @param callback Function to call when changes occur
|
|
235
242
|
* @param interval Polling interval in milliseconds (default: 30000)
|
|
243
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
236
244
|
* @returns A function to stop watching
|
|
237
245
|
*/
|
|
238
246
|
watch(
|
|
239
|
-
environment: string,
|
|
240
247
|
callback: (variables: Record<string, string>) => void,
|
|
241
|
-
interval: number = 30000
|
|
248
|
+
interval: number = 30000,
|
|
249
|
+
environment?: string
|
|
242
250
|
): () => void {
|
|
251
|
+
const env = environment || this.environment;
|
|
243
252
|
let previousVariables: string = '';
|
|
244
253
|
|
|
245
254
|
const fetchAndCompare = async () => {
|
|
246
255
|
try {
|
|
247
|
-
const variables = await this.getAll(
|
|
256
|
+
const variables = await this.getAll(env);
|
|
248
257
|
const currentVariables = JSON.stringify(variables);
|
|
249
258
|
|
|
250
259
|
if (currentVariables !== previousVariables) {
|
|
@@ -252,7 +261,7 @@ export class VoltEnv {
|
|
|
252
261
|
callback(variables);
|
|
253
262
|
}
|
|
254
263
|
} catch (error) {
|
|
255
|
-
console.error(`Error in VoltEnv watcher for ${
|
|
264
|
+
console.error(`Error in VoltEnv watcher for ${env}:`, error);
|
|
256
265
|
}
|
|
257
266
|
};
|
|
258
267
|
|
|
@@ -266,57 +275,60 @@ export class VoltEnv {
|
|
|
266
275
|
|
|
267
276
|
/**
|
|
268
277
|
* Set multiple variables at once
|
|
269
|
-
* @param environment The environment name
|
|
270
278
|
* @param variables A record of key-value pairs to set
|
|
279
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
271
280
|
*/
|
|
272
281
|
async setMany(
|
|
273
|
-
|
|
274
|
-
|
|
282
|
+
variables: Record<string, string>,
|
|
283
|
+
environment?: string
|
|
275
284
|
): Promise<void> {
|
|
285
|
+
const env = environment || this.environment;
|
|
276
286
|
const prefixedVariables: Record<string, string> = {};
|
|
277
287
|
Object.entries(variables).forEach(([key, value]) => {
|
|
278
288
|
prefixedVariables[this.applyPrefix(key)] = value;
|
|
279
289
|
});
|
|
280
290
|
|
|
281
|
-
await this.httpClient.post(`/v1/variables/${
|
|
291
|
+
await this.httpClient.post(`/v1/variables/${env}/batch`, {
|
|
282
292
|
variables: prefixedVariables,
|
|
283
293
|
});
|
|
284
294
|
|
|
285
295
|
if (this.cacheService) {
|
|
286
296
|
Object.entries(prefixedVariables).forEach(([key, value]) => {
|
|
287
|
-
this.cacheService!.set(`${
|
|
297
|
+
this.cacheService!.set(`${env}:${key}`, value);
|
|
288
298
|
});
|
|
289
299
|
}
|
|
290
300
|
}
|
|
291
301
|
|
|
292
302
|
/**
|
|
293
303
|
* Delete a variable from a specific environment
|
|
294
|
-
* @param environment The environment name
|
|
295
304
|
* @param key The variable key
|
|
305
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
296
306
|
*/
|
|
297
|
-
async delete(
|
|
307
|
+
async delete(key: string, environment?: string): Promise<void> {
|
|
308
|
+
const env = environment || this.environment;
|
|
298
309
|
const prefixedKey = this.applyPrefix(key);
|
|
299
|
-
await this.httpClient.delete(`/v1/variables/${
|
|
310
|
+
await this.httpClient.delete(`/v1/variables/${env}/${prefixedKey}`);
|
|
300
311
|
|
|
301
312
|
if (this.cacheService) {
|
|
302
|
-
this.cacheService.delete(`${
|
|
313
|
+
this.cacheService.delete(`${env}:${prefixedKey}`);
|
|
303
314
|
}
|
|
304
315
|
}
|
|
305
316
|
|
|
306
317
|
/**
|
|
307
318
|
* Delete multiple variables at once
|
|
308
|
-
* @param environment The environment name
|
|
309
319
|
* @param keys Array of keys to delete
|
|
320
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
310
321
|
*/
|
|
311
|
-
async deleteMany(
|
|
322
|
+
async deleteMany(keys: string[], environment?: string): Promise<void> {
|
|
323
|
+
const env = environment || this.environment;
|
|
312
324
|
const prefixedKeys = keys.map(k => this.applyPrefix(k));
|
|
313
|
-
await this.httpClient.post(`/v1/variables/${
|
|
325
|
+
await this.httpClient.post(`/v1/variables/${env}/batch-delete`, {
|
|
314
326
|
keys: prefixedKeys,
|
|
315
327
|
});
|
|
316
328
|
|
|
317
329
|
if (this.cacheService) {
|
|
318
330
|
prefixedKeys.forEach(key => {
|
|
319
|
-
this.cacheService!.delete(`${
|
|
331
|
+
this.cacheService!.delete(`${env}:${key}`);
|
|
320
332
|
});
|
|
321
333
|
}
|
|
322
334
|
}
|
|
@@ -324,20 +336,22 @@ export class VoltEnv {
|
|
|
324
336
|
/**
|
|
325
337
|
* Export all variables in an environment to a .env file
|
|
326
338
|
* Node.js only - will throw error in browser
|
|
327
|
-
* @param environment The environment name
|
|
328
339
|
* @param filePath Path to the .env file to create/overwrite
|
|
340
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
329
341
|
*/
|
|
330
|
-
async exportToEnvFile(
|
|
342
|
+
async exportToEnvFile(filePath: string, environment?: string): Promise<void> {
|
|
331
343
|
// Check if we're in Node.js
|
|
332
344
|
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
333
345
|
throw new Error('exportToEnvFile is only available in Node.js environments');
|
|
334
346
|
}
|
|
335
347
|
|
|
348
|
+
const env = environment || this.environment;
|
|
349
|
+
|
|
336
350
|
try {
|
|
337
351
|
const fs = require('fs');
|
|
338
352
|
const path = require('path');
|
|
339
353
|
|
|
340
|
-
const variables = await this.getAll(
|
|
354
|
+
const variables = await this.getAll(env);
|
|
341
355
|
const content = Object.entries(variables)
|
|
342
356
|
.map(([key, value]) => `${key}=${value}`)
|
|
343
357
|
.join('\n');
|
|
@@ -355,15 +369,17 @@ export class VoltEnv {
|
|
|
355
369
|
/**
|
|
356
370
|
* Load variables from a .env file and set them in an environment
|
|
357
371
|
* Node.js only - will throw error in browser
|
|
358
|
-
* @param environment The environment name
|
|
359
372
|
* @param filePath Path to the .env file to read from
|
|
373
|
+
* @param environment Optional environment name (defaults to instance environment)
|
|
360
374
|
*/
|
|
361
|
-
async loadFromEnvFile(
|
|
375
|
+
async loadFromEnvFile(filePath: string, environment?: string): Promise<void> {
|
|
362
376
|
// Check if we're in Node.js
|
|
363
377
|
if (typeof process === 'undefined' || typeof require === 'undefined') {
|
|
364
378
|
throw new Error('loadFromEnvFile is only available in Node.js environments');
|
|
365
379
|
}
|
|
366
380
|
|
|
381
|
+
const env = environment || this.environment;
|
|
382
|
+
|
|
367
383
|
try {
|
|
368
384
|
const fs = require('fs');
|
|
369
385
|
const path = require('path');
|
|
@@ -390,7 +406,7 @@ export class VoltEnv {
|
|
|
390
406
|
});
|
|
391
407
|
|
|
392
408
|
if (Object.keys(variables).length > 0) {
|
|
393
|
-
await this.setMany(
|
|
409
|
+
await this.setMany(variables, env);
|
|
394
410
|
}
|
|
395
411
|
} catch (error) {
|
|
396
412
|
throw new Error(`Failed to load from env file: ${error}`);
|
|
@@ -443,27 +459,31 @@ export class VoltEnv {
|
|
|
443
459
|
|
|
444
460
|
/**
|
|
445
461
|
* Sync/refresh variables from server (bypassing cache)
|
|
446
|
-
* If an environment is provided, it
|
|
447
|
-
* 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.
|
|
448
464
|
* @param environment Optional environment to sync
|
|
449
465
|
*/
|
|
450
466
|
async sync(environment?: string): Promise<void> {
|
|
451
|
-
|
|
452
|
-
|
|
467
|
+
const env = environment || this.environment;
|
|
468
|
+
const variables = await this.getAll(env);
|
|
453
469
|
|
|
454
|
-
|
|
455
|
-
|
|
470
|
+
if (this.cacheService) {
|
|
471
|
+
this.cacheService.deleteByPrefix(`${env}:`);
|
|
456
472
|
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
const environments = await this.listEnvironments();
|
|
473
|
+
Object.entries(variables).forEach(([key, value]) => {
|
|
474
|
+
this.cacheService!.set(`${env}:${key}`, value);
|
|
475
|
+
});
|
|
476
|
+
}
|
|
477
|
+
}
|
|
463
478
|
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
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);
|
|
467
487
|
}
|
|
468
488
|
}
|
|
469
489
|
|
package/package.json
CHANGED