node-consul-service 1.0.43 → 1.0.44
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/consul/client.d.ts +8 -2
- package/dist/index.cjs.js +47 -441
- package/dist/index.esm.js +47 -441
- package/package.json +1 -1
package/dist/consul/client.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
import Consul from "consul";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
interface ConsulConfig {
|
|
3
|
+
host: string;
|
|
4
|
+
port: number;
|
|
5
|
+
secure?: boolean;
|
|
6
|
+
}
|
|
7
|
+
export declare function initClient(config: ConsulConfig): void;
|
|
8
|
+
export declare function getClient(): Consul;
|
|
9
|
+
export {};
|
package/dist/index.cjs.js
CHANGED
|
@@ -1,422 +1,24 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
var require$$1 = require('
|
|
5
|
-
var require$$2 = require('os');
|
|
6
|
-
var require$$3 = require('crypto');
|
|
7
|
-
var Consul = require('consul');
|
|
8
|
-
var require$$1$1 = require('util');
|
|
3
|
+
require('consul');
|
|
4
|
+
var require$$1 = require('util');
|
|
9
5
|
var stream = require('stream');
|
|
10
|
-
var require$$
|
|
11
|
-
var require$$
|
|
12
|
-
var require$$
|
|
13
|
-
var require$$
|
|
6
|
+
var require$$1$1 = require('path');
|
|
7
|
+
var require$$3 = require('http');
|
|
8
|
+
var require$$4 = require('https');
|
|
9
|
+
var require$$0$1 = require('url');
|
|
10
|
+
var require$$6 = require('fs');
|
|
11
|
+
var crypto = require('crypto');
|
|
12
|
+
var require$$4$1 = require('assert');
|
|
14
13
|
var zlib = require('zlib');
|
|
15
14
|
var events = require('events');
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
var main = {exports: {}};
|
|
22
|
-
|
|
23
|
-
var version = "16.5.0";
|
|
24
|
-
var require$$4 = {
|
|
25
|
-
version: version};
|
|
26
|
-
|
|
27
|
-
var hasRequiredMain;
|
|
28
|
-
|
|
29
|
-
function requireMain () {
|
|
30
|
-
if (hasRequiredMain) return main.exports;
|
|
31
|
-
hasRequiredMain = 1;
|
|
32
|
-
const fs = require$$0$1;
|
|
33
|
-
const path = require$$1;
|
|
34
|
-
const os = require$$2;
|
|
35
|
-
const crypto = require$$3;
|
|
36
|
-
const packageJson = require$$4;
|
|
37
|
-
|
|
38
|
-
const version = packageJson.version;
|
|
39
|
-
|
|
40
|
-
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
41
|
-
|
|
42
|
-
// Parse src into an Object
|
|
43
|
-
function parse (src) {
|
|
44
|
-
const obj = {};
|
|
45
|
-
|
|
46
|
-
// Convert buffer to string
|
|
47
|
-
let lines = src.toString();
|
|
48
|
-
|
|
49
|
-
// Convert line breaks to same format
|
|
50
|
-
lines = lines.replace(/\r\n?/mg, '\n');
|
|
51
|
-
|
|
52
|
-
let match;
|
|
53
|
-
while ((match = LINE.exec(lines)) != null) {
|
|
54
|
-
const key = match[1];
|
|
55
|
-
|
|
56
|
-
// Default undefined or null to empty string
|
|
57
|
-
let value = (match[2] || '');
|
|
58
|
-
|
|
59
|
-
// Remove whitespace
|
|
60
|
-
value = value.trim();
|
|
61
|
-
|
|
62
|
-
// Check if double quoted
|
|
63
|
-
const maybeQuote = value[0];
|
|
64
|
-
|
|
65
|
-
// Remove surrounding quotes
|
|
66
|
-
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
|
|
67
|
-
|
|
68
|
-
// Expand newlines if double quoted
|
|
69
|
-
if (maybeQuote === '"') {
|
|
70
|
-
value = value.replace(/\\n/g, '\n');
|
|
71
|
-
value = value.replace(/\\r/g, '\r');
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Add to object
|
|
75
|
-
obj[key] = value;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return obj
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function _parseVault (options) {
|
|
82
|
-
const vaultPath = _vaultPath(options);
|
|
83
|
-
|
|
84
|
-
// Parse .env.vault
|
|
85
|
-
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
86
|
-
if (!result.parsed) {
|
|
87
|
-
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
88
|
-
err.code = 'MISSING_DATA';
|
|
89
|
-
throw err
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
// handle scenario for comma separated keys - for use with key rotation
|
|
93
|
-
// example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
|
|
94
|
-
const keys = _dotenvKey(options).split(',');
|
|
95
|
-
const length = keys.length;
|
|
96
|
-
|
|
97
|
-
let decrypted;
|
|
98
|
-
for (let i = 0; i < length; i++) {
|
|
99
|
-
try {
|
|
100
|
-
// Get full key
|
|
101
|
-
const key = keys[i].trim();
|
|
102
|
-
|
|
103
|
-
// Get instructions for decrypt
|
|
104
|
-
const attrs = _instructions(result, key);
|
|
105
|
-
|
|
106
|
-
// Decrypt
|
|
107
|
-
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
108
|
-
|
|
109
|
-
break
|
|
110
|
-
} catch (error) {
|
|
111
|
-
// last key
|
|
112
|
-
if (i + 1 >= length) {
|
|
113
|
-
throw error
|
|
114
|
-
}
|
|
115
|
-
// try next key
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
// Parse decrypted .env string
|
|
120
|
-
return DotenvModule.parse(decrypted)
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
function _warn (message) {
|
|
124
|
-
console.log(`[dotenv@${version}][WARN] ${message}`);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function _debug (message) {
|
|
128
|
-
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
function _dotenvKey (options) {
|
|
132
|
-
// prioritize developer directly setting options.DOTENV_KEY
|
|
133
|
-
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
134
|
-
return options.DOTENV_KEY
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
// secondary infra already contains a DOTENV_KEY environment variable
|
|
138
|
-
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
139
|
-
return process.env.DOTENV_KEY
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
// fallback to empty string
|
|
143
|
-
return ''
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
function _instructions (result, dotenvKey) {
|
|
147
|
-
// Parse DOTENV_KEY. Format is a URI
|
|
148
|
-
let uri;
|
|
149
|
-
try {
|
|
150
|
-
uri = new URL(dotenvKey);
|
|
151
|
-
} catch (error) {
|
|
152
|
-
if (error.code === 'ERR_INVALID_URL') {
|
|
153
|
-
const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
|
|
154
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
155
|
-
throw err
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
throw error
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Get decrypt key
|
|
162
|
-
const key = uri.password;
|
|
163
|
-
if (!key) {
|
|
164
|
-
const err = new Error('INVALID_DOTENV_KEY: Missing key part');
|
|
165
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
166
|
-
throw err
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
// Get environment
|
|
170
|
-
const environment = uri.searchParams.get('environment');
|
|
171
|
-
if (!environment) {
|
|
172
|
-
const err = new Error('INVALID_DOTENV_KEY: Missing environment part');
|
|
173
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
174
|
-
throw err
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
// Get ciphertext payload
|
|
178
|
-
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
179
|
-
const ciphertext = result.parsed[environmentKey]; // DOTENV_VAULT_PRODUCTION
|
|
180
|
-
if (!ciphertext) {
|
|
181
|
-
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
182
|
-
err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT';
|
|
183
|
-
throw err
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return { ciphertext, key }
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function _vaultPath (options) {
|
|
190
|
-
let possibleVaultPath = null;
|
|
191
|
-
|
|
192
|
-
if (options && options.path && options.path.length > 0) {
|
|
193
|
-
if (Array.isArray(options.path)) {
|
|
194
|
-
for (const filepath of options.path) {
|
|
195
|
-
if (fs.existsSync(filepath)) {
|
|
196
|
-
possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`;
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
} else {
|
|
200
|
-
possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
|
|
201
|
-
}
|
|
202
|
-
} else {
|
|
203
|
-
possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
if (fs.existsSync(possibleVaultPath)) {
|
|
207
|
-
return possibleVaultPath
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return null
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
function _resolveHome (envPath) {
|
|
214
|
-
return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
function _configVault (options) {
|
|
218
|
-
const debug = Boolean(options && options.debug);
|
|
219
|
-
if (debug) {
|
|
220
|
-
_debug('Loading env from encrypted .env.vault');
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
const parsed = DotenvModule._parseVault(options);
|
|
224
|
-
|
|
225
|
-
let processEnv = process.env;
|
|
226
|
-
if (options && options.processEnv != null) {
|
|
227
|
-
processEnv = options.processEnv;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
DotenvModule.populate(processEnv, parsed, options);
|
|
231
|
-
|
|
232
|
-
return { parsed }
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
function configDotenv (options) {
|
|
236
|
-
const dotenvPath = path.resolve(process.cwd(), '.env');
|
|
237
|
-
let encoding = 'utf8';
|
|
238
|
-
const debug = Boolean(options && options.debug);
|
|
239
|
-
|
|
240
|
-
if (options && options.encoding) {
|
|
241
|
-
encoding = options.encoding;
|
|
242
|
-
} else {
|
|
243
|
-
if (debug) {
|
|
244
|
-
_debug('No encoding is specified. UTF-8 is used by default');
|
|
245
|
-
}
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
let optionPaths = [dotenvPath]; // default, look for .env
|
|
249
|
-
if (options && options.path) {
|
|
250
|
-
if (!Array.isArray(options.path)) {
|
|
251
|
-
optionPaths = [_resolveHome(options.path)];
|
|
252
|
-
} else {
|
|
253
|
-
optionPaths = []; // reset default
|
|
254
|
-
for (const filepath of options.path) {
|
|
255
|
-
optionPaths.push(_resolveHome(filepath));
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
// Build the parsed data in a temporary object (because we need to return it). Once we have the final
|
|
261
|
-
// parsed data, we will combine it with process.env (or options.processEnv if provided).
|
|
262
|
-
let lastError;
|
|
263
|
-
const parsedAll = {};
|
|
264
|
-
for (const path of optionPaths) {
|
|
265
|
-
try {
|
|
266
|
-
// Specifying an encoding returns a string instead of a buffer
|
|
267
|
-
const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
|
|
268
|
-
|
|
269
|
-
DotenvModule.populate(parsedAll, parsed, options);
|
|
270
|
-
} catch (e) {
|
|
271
|
-
if (debug) {
|
|
272
|
-
_debug(`Failed to load ${path} ${e.message}`);
|
|
273
|
-
}
|
|
274
|
-
lastError = e;
|
|
275
|
-
}
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
let processEnv = process.env;
|
|
279
|
-
if (options && options.processEnv != null) {
|
|
280
|
-
processEnv = options.processEnv;
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
DotenvModule.populate(processEnv, parsedAll, options);
|
|
284
|
-
|
|
285
|
-
if (lastError) {
|
|
286
|
-
return { parsed: parsedAll, error: lastError }
|
|
287
|
-
} else {
|
|
288
|
-
return { parsed: parsedAll }
|
|
289
|
-
}
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
// Populates process.env from .env file
|
|
293
|
-
function config (options) {
|
|
294
|
-
// fallback to original dotenv if DOTENV_KEY is not set
|
|
295
|
-
if (_dotenvKey(options).length === 0) {
|
|
296
|
-
return DotenvModule.configDotenv(options)
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
const vaultPath = _vaultPath(options);
|
|
300
|
-
|
|
301
|
-
// dotenvKey exists but .env.vault file does not exist
|
|
302
|
-
if (!vaultPath) {
|
|
303
|
-
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
304
|
-
|
|
305
|
-
return DotenvModule.configDotenv(options)
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
return DotenvModule._configVault(options)
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
function decrypt (encrypted, keyStr) {
|
|
312
|
-
const key = Buffer.from(keyStr.slice(-64), 'hex');
|
|
313
|
-
let ciphertext = Buffer.from(encrypted, 'base64');
|
|
314
|
-
|
|
315
|
-
const nonce = ciphertext.subarray(0, 12);
|
|
316
|
-
const authTag = ciphertext.subarray(-16);
|
|
317
|
-
ciphertext = ciphertext.subarray(12, -16);
|
|
318
|
-
|
|
319
|
-
try {
|
|
320
|
-
const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce);
|
|
321
|
-
aesgcm.setAuthTag(authTag);
|
|
322
|
-
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`
|
|
323
|
-
} catch (error) {
|
|
324
|
-
const isRange = error instanceof RangeError;
|
|
325
|
-
const invalidKeyLength = error.message === 'Invalid key length';
|
|
326
|
-
const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data';
|
|
327
|
-
|
|
328
|
-
if (isRange || invalidKeyLength) {
|
|
329
|
-
const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)');
|
|
330
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
331
|
-
throw err
|
|
332
|
-
} else if (decryptionFailed) {
|
|
333
|
-
const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY');
|
|
334
|
-
err.code = 'DECRYPTION_FAILED';
|
|
335
|
-
throw err
|
|
336
|
-
} else {
|
|
337
|
-
throw error
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
// Populate process.env with parsed values
|
|
343
|
-
function populate (processEnv, parsed, options = {}) {
|
|
344
|
-
const debug = Boolean(options && options.debug);
|
|
345
|
-
const override = Boolean(options && options.override);
|
|
346
|
-
|
|
347
|
-
if (typeof parsed !== 'object') {
|
|
348
|
-
const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate');
|
|
349
|
-
err.code = 'OBJECT_REQUIRED';
|
|
350
|
-
throw err
|
|
351
|
-
}
|
|
352
|
-
|
|
353
|
-
// Set process.env
|
|
354
|
-
for (const key of Object.keys(parsed)) {
|
|
355
|
-
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
356
|
-
if (override === true) {
|
|
357
|
-
processEnv[key] = parsed[key];
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
if (debug) {
|
|
361
|
-
if (override === true) {
|
|
362
|
-
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
363
|
-
} else {
|
|
364
|
-
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
} else {
|
|
368
|
-
processEnv[key] = parsed[key];
|
|
369
|
-
}
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
const DotenvModule = {
|
|
374
|
-
configDotenv,
|
|
375
|
-
_configVault,
|
|
376
|
-
_parseVault,
|
|
377
|
-
config,
|
|
378
|
-
decrypt,
|
|
379
|
-
parse,
|
|
380
|
-
populate
|
|
381
|
-
};
|
|
382
|
-
|
|
383
|
-
main.exports.configDotenv = DotenvModule.configDotenv;
|
|
384
|
-
main.exports._configVault = DotenvModule._configVault;
|
|
385
|
-
main.exports._parseVault = DotenvModule._parseVault;
|
|
386
|
-
main.exports.config = DotenvModule.config;
|
|
387
|
-
main.exports.decrypt = DotenvModule.decrypt;
|
|
388
|
-
main.exports.parse = DotenvModule.parse;
|
|
389
|
-
main.exports.populate = DotenvModule.populate;
|
|
390
|
-
|
|
391
|
-
main.exports = DotenvModule;
|
|
392
|
-
return main.exports;
|
|
393
|
-
}
|
|
394
|
-
|
|
395
|
-
var mainExports = requireMain();
|
|
396
|
-
var dotenv = /*@__PURE__*/getDefaultExportFromCjs(mainExports);
|
|
397
|
-
|
|
398
|
-
dotenv.config();
|
|
399
|
-
const { CONSUL_HOST, CONSUL_PORT, CONSUL_SECURE } = process.env;
|
|
400
|
-
if (!CONSUL_HOST) {
|
|
401
|
-
throw new Error("Missing environment variable: CONSUL_HOST");
|
|
402
|
-
}
|
|
403
|
-
if (!CONSUL_PORT) {
|
|
404
|
-
throw new Error("Missing environment variable: CONSUL_PORT");
|
|
405
|
-
}
|
|
406
|
-
const client = new Consul({
|
|
407
|
-
host: CONSUL_HOST,
|
|
408
|
-
port: Number(CONSUL_PORT),
|
|
409
|
-
secure: CONSUL_SECURE === "true",
|
|
410
|
-
});
|
|
411
|
-
// اختبار الاتصال
|
|
412
|
-
client.agent.self((err) => {
|
|
413
|
-
if (err) {
|
|
414
|
-
console.error("❌ Failed to connect to Consul:", err.message);
|
|
415
|
-
}
|
|
416
|
-
else {
|
|
417
|
-
console.log("✅ Connected to Consul successfully");
|
|
16
|
+
// src/lib/client.ts
|
|
17
|
+
function getClient() {
|
|
18
|
+
{
|
|
19
|
+
throw new Error("Consul client not initialized. Call initClient() first.");
|
|
418
20
|
}
|
|
419
|
-
}
|
|
21
|
+
}
|
|
420
22
|
|
|
421
23
|
const registeredServices = new Set();
|
|
422
24
|
async function registerService(options) {
|
|
@@ -446,7 +48,7 @@ async function registerService(options) {
|
|
|
446
48
|
}
|
|
447
49
|
serviceDefinition.check = checkDefinition;
|
|
448
50
|
}
|
|
449
|
-
await
|
|
51
|
+
await getClient().agent.service.register(serviceDefinition);
|
|
450
52
|
registeredServices.add(id);
|
|
451
53
|
console.log(`✅ Service "${id}" registered successfully.`);
|
|
452
54
|
}
|
|
@@ -455,17 +57,17 @@ async function deregisterService(id) {
|
|
|
455
57
|
console.log(`⚠️ Service "${id}" is not registered.`);
|
|
456
58
|
return;
|
|
457
59
|
}
|
|
458
|
-
await
|
|
60
|
+
await getClient().agent.service.deregister(id);
|
|
459
61
|
registeredServices.delete(id);
|
|
460
62
|
console.log(`🛑 Service "${id}" deregistered successfully.`);
|
|
461
63
|
}
|
|
462
64
|
|
|
463
65
|
async function listServices() {
|
|
464
|
-
const services = await
|
|
66
|
+
const services = await getClient().agent.service.list();
|
|
465
67
|
return Object.values(services);
|
|
466
68
|
}
|
|
467
69
|
async function getServiceInstances(serviceName) {
|
|
468
|
-
const services = await
|
|
70
|
+
const services = await getClient().catalog.service.nodes(serviceName);
|
|
469
71
|
return services;
|
|
470
72
|
}
|
|
471
73
|
async function getRandomServiceInstance(serviceName) {
|
|
@@ -1325,6 +927,10 @@ AxiosError$1.from = (error, code, config, request, response, customProps) => {
|
|
|
1325
927
|
return axiosError;
|
|
1326
928
|
};
|
|
1327
929
|
|
|
930
|
+
function getDefaultExportFromCjs (x) {
|
|
931
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
932
|
+
}
|
|
933
|
+
|
|
1328
934
|
var delayed_stream;
|
|
1329
935
|
var hasRequiredDelayed_stream;
|
|
1330
936
|
|
|
@@ -1332,7 +938,7 @@ function requireDelayed_stream () {
|
|
|
1332
938
|
if (hasRequiredDelayed_stream) return delayed_stream;
|
|
1333
939
|
hasRequiredDelayed_stream = 1;
|
|
1334
940
|
var Stream = stream.Stream;
|
|
1335
|
-
var util = require$$1
|
|
941
|
+
var util = require$$1;
|
|
1336
942
|
|
|
1337
943
|
delayed_stream = DelayedStream;
|
|
1338
944
|
function DelayedStream() {
|
|
@@ -1447,7 +1053,7 @@ var hasRequiredCombined_stream;
|
|
|
1447
1053
|
function requireCombined_stream () {
|
|
1448
1054
|
if (hasRequiredCombined_stream) return combined_stream;
|
|
1449
1055
|
hasRequiredCombined_stream = 1;
|
|
1450
|
-
var util = require$$1
|
|
1056
|
+
var util = require$$1;
|
|
1451
1057
|
var Stream = stream.Stream;
|
|
1452
1058
|
var DelayedStream = requireDelayed_stream();
|
|
1453
1059
|
|
|
@@ -12404,7 +12010,7 @@ function requireMimeTypes () {
|
|
|
12404
12010
|
*/
|
|
12405
12011
|
|
|
12406
12012
|
var db = requireMimeDb();
|
|
12407
|
-
var extname = require$$1.extname;
|
|
12013
|
+
var extname = require$$1$1.extname;
|
|
12408
12014
|
|
|
12409
12015
|
/**
|
|
12410
12016
|
* Module variables.
|
|
@@ -14144,12 +13750,12 @@ function requireForm_data () {
|
|
|
14144
13750
|
if (hasRequiredForm_data) return form_data;
|
|
14145
13751
|
hasRequiredForm_data = 1;
|
|
14146
13752
|
var CombinedStream = requireCombined_stream();
|
|
14147
|
-
var util = require$$1
|
|
14148
|
-
var path = require$$1;
|
|
14149
|
-
var http = require$$3
|
|
14150
|
-
var https = require$$4
|
|
14151
|
-
var parseUrl = require$$0$
|
|
14152
|
-
var fs = require$$
|
|
13753
|
+
var util = require$$1;
|
|
13754
|
+
var path = require$$1$1;
|
|
13755
|
+
var http = require$$3;
|
|
13756
|
+
var https = require$$4;
|
|
13757
|
+
var parseUrl = require$$0$1.parse;
|
|
13758
|
+
var fs = require$$6;
|
|
14153
13759
|
var Stream = stream.Stream;
|
|
14154
13760
|
var mime = requireMimeTypes();
|
|
14155
13761
|
var asynckit = requireAsynckit();
|
|
@@ -15053,7 +14659,7 @@ var transitionalDefaults = {
|
|
|
15053
14659
|
clarifyTimeoutError: false
|
|
15054
14660
|
};
|
|
15055
14661
|
|
|
15056
|
-
var URLSearchParams = require$$0$
|
|
14662
|
+
var URLSearchParams = require$$0$1.URLSearchParams;
|
|
15057
14663
|
|
|
15058
14664
|
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|
15059
14665
|
|
|
@@ -15069,7 +14675,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
15069
14675
|
let str = '';
|
|
15070
14676
|
const {length} = alphabet;
|
|
15071
14677
|
const randomValues = new Uint32Array(size);
|
|
15072
|
-
|
|
14678
|
+
crypto.randomFillSync(randomValues);
|
|
15073
14679
|
for (let i = 0; i < size; i++) {
|
|
15074
14680
|
str += alphabet[randomValues[i] % length];
|
|
15075
14681
|
}
|
|
@@ -15135,12 +14741,12 @@ const hasStandardBrowserWebWorkerEnv = (() => {
|
|
|
15135
14741
|
const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
|
15136
14742
|
|
|
15137
14743
|
var utils = /*#__PURE__*/Object.freeze({
|
|
15138
|
-
|
|
15139
|
-
|
|
15140
|
-
|
|
15141
|
-
|
|
15142
|
-
|
|
15143
|
-
|
|
14744
|
+
__proto__: null,
|
|
14745
|
+
hasBrowserEnv: hasBrowserEnv,
|
|
14746
|
+
hasStandardBrowserEnv: hasStandardBrowserEnv,
|
|
14747
|
+
hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
|
|
14748
|
+
navigator: _navigator,
|
|
14749
|
+
origin: origin
|
|
15144
14750
|
});
|
|
15145
14751
|
|
|
15146
14752
|
var platform = {
|
|
@@ -15885,7 +15491,7 @@ function requireProxyFromEnv () {
|
|
|
15885
15491
|
if (hasRequiredProxyFromEnv) return proxyFromEnv$1;
|
|
15886
15492
|
hasRequiredProxyFromEnv = 1;
|
|
15887
15493
|
|
|
15888
|
-
var parseUrl = require$$0$
|
|
15494
|
+
var parseUrl = require$$0$1.parse;
|
|
15889
15495
|
|
|
15890
15496
|
var DEFAULT_PORTS = {
|
|
15891
15497
|
ftp: 21,
|
|
@@ -16028,12 +15634,12 @@ var hasRequiredFollowRedirects;
|
|
|
16028
15634
|
function requireFollowRedirects () {
|
|
16029
15635
|
if (hasRequiredFollowRedirects) return followRedirects$1.exports;
|
|
16030
15636
|
hasRequiredFollowRedirects = 1;
|
|
16031
|
-
var url = require$$0$
|
|
15637
|
+
var url = require$$0$1;
|
|
16032
15638
|
var URL = url.URL;
|
|
16033
|
-
var http = require$$3
|
|
16034
|
-
var https = require$$4
|
|
15639
|
+
var http = require$$3;
|
|
15640
|
+
var https = require$$4;
|
|
16035
15641
|
var Writable = stream.Writable;
|
|
16036
|
-
var assert = require$$4$
|
|
15642
|
+
var assert = require$$4$1;
|
|
16037
15643
|
var debug = requireDebug();
|
|
16038
15644
|
|
|
16039
15645
|
// Preventive platform detection
|
|
@@ -16928,7 +16534,7 @@ const readBlob = async function* (blob) {
|
|
|
16928
16534
|
|
|
16929
16535
|
const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
|
|
16930
16536
|
|
|
16931
|
-
const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new require$$1
|
|
16537
|
+
const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new require$$1.TextEncoder();
|
|
16932
16538
|
|
|
16933
16539
|
const CRLF = '\r\n';
|
|
16934
16540
|
const CRLF_BYTES = textEncoder.encode(CRLF);
|
|
@@ -17485,7 +17091,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17485
17091
|
|
|
17486
17092
|
if (!headers.hasContentLength()) {
|
|
17487
17093
|
try {
|
|
17488
|
-
const knownLength = await require$$1
|
|
17094
|
+
const knownLength = await require$$1.promisify(data.getLength).call(data);
|
|
17489
17095
|
Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
|
|
17490
17096
|
/*eslint no-empty:0*/
|
|
17491
17097
|
} catch (e) {
|
|
@@ -17613,7 +17219,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17613
17219
|
if (config.transport) {
|
|
17614
17220
|
transport = config.transport;
|
|
17615
17221
|
} else if (config.maxRedirects === 0) {
|
|
17616
|
-
transport = isHttpsRequest ? require$$4
|
|
17222
|
+
transport = isHttpsRequest ? require$$4 : require$$3;
|
|
17617
17223
|
} else {
|
|
17618
17224
|
if (config.maxRedirects) {
|
|
17619
17225
|
options.maxRedirects = config.maxRedirects;
|
package/dist/index.esm.js
CHANGED
|
@@ -1,420 +1,22 @@
|
|
|
1
|
-
import
|
|
2
|
-
import require$$1 from '
|
|
3
|
-
import require$$2 from 'os';
|
|
4
|
-
import require$$3 from 'crypto';
|
|
5
|
-
import Consul from 'consul';
|
|
6
|
-
import require$$1$1 from 'util';
|
|
1
|
+
import 'consul';
|
|
2
|
+
import require$$1 from 'util';
|
|
7
3
|
import stream, { Readable } from 'stream';
|
|
8
|
-
import require$$
|
|
9
|
-
import require$$
|
|
10
|
-
import require$$
|
|
11
|
-
import require$$
|
|
4
|
+
import require$$1$1 from 'path';
|
|
5
|
+
import require$$3 from 'http';
|
|
6
|
+
import require$$4 from 'https';
|
|
7
|
+
import require$$0$1 from 'url';
|
|
8
|
+
import require$$6 from 'fs';
|
|
9
|
+
import crypto from 'crypto';
|
|
10
|
+
import require$$4$1 from 'assert';
|
|
12
11
|
import zlib from 'zlib';
|
|
13
12
|
import { EventEmitter } from 'events';
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
var main = {exports: {}};
|
|
20
|
-
|
|
21
|
-
var version = "16.5.0";
|
|
22
|
-
var require$$4 = {
|
|
23
|
-
version: version};
|
|
24
|
-
|
|
25
|
-
var hasRequiredMain;
|
|
26
|
-
|
|
27
|
-
function requireMain () {
|
|
28
|
-
if (hasRequiredMain) return main.exports;
|
|
29
|
-
hasRequiredMain = 1;
|
|
30
|
-
const fs = require$$0$1;
|
|
31
|
-
const path = require$$1;
|
|
32
|
-
const os = require$$2;
|
|
33
|
-
const crypto = require$$3;
|
|
34
|
-
const packageJson = require$$4;
|
|
35
|
-
|
|
36
|
-
const version = packageJson.version;
|
|
37
|
-
|
|
38
|
-
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
39
|
-
|
|
40
|
-
// Parse src into an Object
|
|
41
|
-
function parse (src) {
|
|
42
|
-
const obj = {};
|
|
43
|
-
|
|
44
|
-
// Convert buffer to string
|
|
45
|
-
let lines = src.toString();
|
|
46
|
-
|
|
47
|
-
// Convert line breaks to same format
|
|
48
|
-
lines = lines.replace(/\r\n?/mg, '\n');
|
|
49
|
-
|
|
50
|
-
let match;
|
|
51
|
-
while ((match = LINE.exec(lines)) != null) {
|
|
52
|
-
const key = match[1];
|
|
53
|
-
|
|
54
|
-
// Default undefined or null to empty string
|
|
55
|
-
let value = (match[2] || '');
|
|
56
|
-
|
|
57
|
-
// Remove whitespace
|
|
58
|
-
value = value.trim();
|
|
59
|
-
|
|
60
|
-
// Check if double quoted
|
|
61
|
-
const maybeQuote = value[0];
|
|
62
|
-
|
|
63
|
-
// Remove surrounding quotes
|
|
64
|
-
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
|
|
65
|
-
|
|
66
|
-
// Expand newlines if double quoted
|
|
67
|
-
if (maybeQuote === '"') {
|
|
68
|
-
value = value.replace(/\\n/g, '\n');
|
|
69
|
-
value = value.replace(/\\r/g, '\r');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// Add to object
|
|
73
|
-
obj[key] = value;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return obj
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function _parseVault (options) {
|
|
80
|
-
const vaultPath = _vaultPath(options);
|
|
81
|
-
|
|
82
|
-
// Parse .env.vault
|
|
83
|
-
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
84
|
-
if (!result.parsed) {
|
|
85
|
-
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
86
|
-
err.code = 'MISSING_DATA';
|
|
87
|
-
throw err
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
// handle scenario for comma separated keys - for use with key rotation
|
|
91
|
-
// example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
|
|
92
|
-
const keys = _dotenvKey(options).split(',');
|
|
93
|
-
const length = keys.length;
|
|
94
|
-
|
|
95
|
-
let decrypted;
|
|
96
|
-
for (let i = 0; i < length; i++) {
|
|
97
|
-
try {
|
|
98
|
-
// Get full key
|
|
99
|
-
const key = keys[i].trim();
|
|
100
|
-
|
|
101
|
-
// Get instructions for decrypt
|
|
102
|
-
const attrs = _instructions(result, key);
|
|
103
|
-
|
|
104
|
-
// Decrypt
|
|
105
|
-
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
106
|
-
|
|
107
|
-
break
|
|
108
|
-
} catch (error) {
|
|
109
|
-
// last key
|
|
110
|
-
if (i + 1 >= length) {
|
|
111
|
-
throw error
|
|
112
|
-
}
|
|
113
|
-
// try next key
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
// Parse decrypted .env string
|
|
118
|
-
return DotenvModule.parse(decrypted)
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function _warn (message) {
|
|
122
|
-
console.log(`[dotenv@${version}][WARN] ${message}`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function _debug (message) {
|
|
126
|
-
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
function _dotenvKey (options) {
|
|
130
|
-
// prioritize developer directly setting options.DOTENV_KEY
|
|
131
|
-
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
132
|
-
return options.DOTENV_KEY
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// secondary infra already contains a DOTENV_KEY environment variable
|
|
136
|
-
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
137
|
-
return process.env.DOTENV_KEY
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// fallback to empty string
|
|
141
|
-
return ''
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function _instructions (result, dotenvKey) {
|
|
145
|
-
// Parse DOTENV_KEY. Format is a URI
|
|
146
|
-
let uri;
|
|
147
|
-
try {
|
|
148
|
-
uri = new URL(dotenvKey);
|
|
149
|
-
} catch (error) {
|
|
150
|
-
if (error.code === 'ERR_INVALID_URL') {
|
|
151
|
-
const err = new Error('INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=development');
|
|
152
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
153
|
-
throw err
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
throw error
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
// Get decrypt key
|
|
160
|
-
const key = uri.password;
|
|
161
|
-
if (!key) {
|
|
162
|
-
const err = new Error('INVALID_DOTENV_KEY: Missing key part');
|
|
163
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
164
|
-
throw err
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
// Get environment
|
|
168
|
-
const environment = uri.searchParams.get('environment');
|
|
169
|
-
if (!environment) {
|
|
170
|
-
const err = new Error('INVALID_DOTENV_KEY: Missing environment part');
|
|
171
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
172
|
-
throw err
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
// Get ciphertext payload
|
|
176
|
-
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
177
|
-
const ciphertext = result.parsed[environmentKey]; // DOTENV_VAULT_PRODUCTION
|
|
178
|
-
if (!ciphertext) {
|
|
179
|
-
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
180
|
-
err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT';
|
|
181
|
-
throw err
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
return { ciphertext, key }
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function _vaultPath (options) {
|
|
188
|
-
let possibleVaultPath = null;
|
|
189
|
-
|
|
190
|
-
if (options && options.path && options.path.length > 0) {
|
|
191
|
-
if (Array.isArray(options.path)) {
|
|
192
|
-
for (const filepath of options.path) {
|
|
193
|
-
if (fs.existsSync(filepath)) {
|
|
194
|
-
possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
} else {
|
|
198
|
-
possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
|
|
199
|
-
}
|
|
200
|
-
} else {
|
|
201
|
-
possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
if (fs.existsSync(possibleVaultPath)) {
|
|
205
|
-
return possibleVaultPath
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
return null
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function _resolveHome (envPath) {
|
|
212
|
-
return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
function _configVault (options) {
|
|
216
|
-
const debug = Boolean(options && options.debug);
|
|
217
|
-
if (debug) {
|
|
218
|
-
_debug('Loading env from encrypted .env.vault');
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
const parsed = DotenvModule._parseVault(options);
|
|
222
|
-
|
|
223
|
-
let processEnv = process.env;
|
|
224
|
-
if (options && options.processEnv != null) {
|
|
225
|
-
processEnv = options.processEnv;
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
DotenvModule.populate(processEnv, parsed, options);
|
|
229
|
-
|
|
230
|
-
return { parsed }
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
function configDotenv (options) {
|
|
234
|
-
const dotenvPath = path.resolve(process.cwd(), '.env');
|
|
235
|
-
let encoding = 'utf8';
|
|
236
|
-
const debug = Boolean(options && options.debug);
|
|
237
|
-
|
|
238
|
-
if (options && options.encoding) {
|
|
239
|
-
encoding = options.encoding;
|
|
240
|
-
} else {
|
|
241
|
-
if (debug) {
|
|
242
|
-
_debug('No encoding is specified. UTF-8 is used by default');
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
let optionPaths = [dotenvPath]; // default, look for .env
|
|
247
|
-
if (options && options.path) {
|
|
248
|
-
if (!Array.isArray(options.path)) {
|
|
249
|
-
optionPaths = [_resolveHome(options.path)];
|
|
250
|
-
} else {
|
|
251
|
-
optionPaths = []; // reset default
|
|
252
|
-
for (const filepath of options.path) {
|
|
253
|
-
optionPaths.push(_resolveHome(filepath));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
// Build the parsed data in a temporary object (because we need to return it). Once we have the final
|
|
259
|
-
// parsed data, we will combine it with process.env (or options.processEnv if provided).
|
|
260
|
-
let lastError;
|
|
261
|
-
const parsedAll = {};
|
|
262
|
-
for (const path of optionPaths) {
|
|
263
|
-
try {
|
|
264
|
-
// Specifying an encoding returns a string instead of a buffer
|
|
265
|
-
const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
|
|
266
|
-
|
|
267
|
-
DotenvModule.populate(parsedAll, parsed, options);
|
|
268
|
-
} catch (e) {
|
|
269
|
-
if (debug) {
|
|
270
|
-
_debug(`Failed to load ${path} ${e.message}`);
|
|
271
|
-
}
|
|
272
|
-
lastError = e;
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
|
|
276
|
-
let processEnv = process.env;
|
|
277
|
-
if (options && options.processEnv != null) {
|
|
278
|
-
processEnv = options.processEnv;
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
DotenvModule.populate(processEnv, parsedAll, options);
|
|
282
|
-
|
|
283
|
-
if (lastError) {
|
|
284
|
-
return { parsed: parsedAll, error: lastError }
|
|
285
|
-
} else {
|
|
286
|
-
return { parsed: parsedAll }
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
// Populates process.env from .env file
|
|
291
|
-
function config (options) {
|
|
292
|
-
// fallback to original dotenv if DOTENV_KEY is not set
|
|
293
|
-
if (_dotenvKey(options).length === 0) {
|
|
294
|
-
return DotenvModule.configDotenv(options)
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const vaultPath = _vaultPath(options);
|
|
298
|
-
|
|
299
|
-
// dotenvKey exists but .env.vault file does not exist
|
|
300
|
-
if (!vaultPath) {
|
|
301
|
-
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
302
|
-
|
|
303
|
-
return DotenvModule.configDotenv(options)
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
return DotenvModule._configVault(options)
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
function decrypt (encrypted, keyStr) {
|
|
310
|
-
const key = Buffer.from(keyStr.slice(-64), 'hex');
|
|
311
|
-
let ciphertext = Buffer.from(encrypted, 'base64');
|
|
312
|
-
|
|
313
|
-
const nonce = ciphertext.subarray(0, 12);
|
|
314
|
-
const authTag = ciphertext.subarray(-16);
|
|
315
|
-
ciphertext = ciphertext.subarray(12, -16);
|
|
316
|
-
|
|
317
|
-
try {
|
|
318
|
-
const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce);
|
|
319
|
-
aesgcm.setAuthTag(authTag);
|
|
320
|
-
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`
|
|
321
|
-
} catch (error) {
|
|
322
|
-
const isRange = error instanceof RangeError;
|
|
323
|
-
const invalidKeyLength = error.message === 'Invalid key length';
|
|
324
|
-
const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data';
|
|
325
|
-
|
|
326
|
-
if (isRange || invalidKeyLength) {
|
|
327
|
-
const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)');
|
|
328
|
-
err.code = 'INVALID_DOTENV_KEY';
|
|
329
|
-
throw err
|
|
330
|
-
} else if (decryptionFailed) {
|
|
331
|
-
const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY');
|
|
332
|
-
err.code = 'DECRYPTION_FAILED';
|
|
333
|
-
throw err
|
|
334
|
-
} else {
|
|
335
|
-
throw error
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
}
|
|
339
|
-
|
|
340
|
-
// Populate process.env with parsed values
|
|
341
|
-
function populate (processEnv, parsed, options = {}) {
|
|
342
|
-
const debug = Boolean(options && options.debug);
|
|
343
|
-
const override = Boolean(options && options.override);
|
|
344
|
-
|
|
345
|
-
if (typeof parsed !== 'object') {
|
|
346
|
-
const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate');
|
|
347
|
-
err.code = 'OBJECT_REQUIRED';
|
|
348
|
-
throw err
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
// Set process.env
|
|
352
|
-
for (const key of Object.keys(parsed)) {
|
|
353
|
-
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
354
|
-
if (override === true) {
|
|
355
|
-
processEnv[key] = parsed[key];
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (debug) {
|
|
359
|
-
if (override === true) {
|
|
360
|
-
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
361
|
-
} else {
|
|
362
|
-
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
363
|
-
}
|
|
364
|
-
}
|
|
365
|
-
} else {
|
|
366
|
-
processEnv[key] = parsed[key];
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
const DotenvModule = {
|
|
372
|
-
configDotenv,
|
|
373
|
-
_configVault,
|
|
374
|
-
_parseVault,
|
|
375
|
-
config,
|
|
376
|
-
decrypt,
|
|
377
|
-
parse,
|
|
378
|
-
populate
|
|
379
|
-
};
|
|
380
|
-
|
|
381
|
-
main.exports.configDotenv = DotenvModule.configDotenv;
|
|
382
|
-
main.exports._configVault = DotenvModule._configVault;
|
|
383
|
-
main.exports._parseVault = DotenvModule._parseVault;
|
|
384
|
-
main.exports.config = DotenvModule.config;
|
|
385
|
-
main.exports.decrypt = DotenvModule.decrypt;
|
|
386
|
-
main.exports.parse = DotenvModule.parse;
|
|
387
|
-
main.exports.populate = DotenvModule.populate;
|
|
388
|
-
|
|
389
|
-
main.exports = DotenvModule;
|
|
390
|
-
return main.exports;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
var mainExports = requireMain();
|
|
394
|
-
var dotenv = /*@__PURE__*/getDefaultExportFromCjs(mainExports);
|
|
395
|
-
|
|
396
|
-
dotenv.config();
|
|
397
|
-
const { CONSUL_HOST, CONSUL_PORT, CONSUL_SECURE } = process.env;
|
|
398
|
-
if (!CONSUL_HOST) {
|
|
399
|
-
throw new Error("Missing environment variable: CONSUL_HOST");
|
|
400
|
-
}
|
|
401
|
-
if (!CONSUL_PORT) {
|
|
402
|
-
throw new Error("Missing environment variable: CONSUL_PORT");
|
|
403
|
-
}
|
|
404
|
-
const client = new Consul({
|
|
405
|
-
host: CONSUL_HOST,
|
|
406
|
-
port: Number(CONSUL_PORT),
|
|
407
|
-
secure: CONSUL_SECURE === "true",
|
|
408
|
-
});
|
|
409
|
-
// اختبار الاتصال
|
|
410
|
-
client.agent.self((err) => {
|
|
411
|
-
if (err) {
|
|
412
|
-
console.error("❌ Failed to connect to Consul:", err.message);
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
console.log("✅ Connected to Consul successfully");
|
|
14
|
+
// src/lib/client.ts
|
|
15
|
+
function getClient() {
|
|
16
|
+
{
|
|
17
|
+
throw new Error("Consul client not initialized. Call initClient() first.");
|
|
416
18
|
}
|
|
417
|
-
}
|
|
19
|
+
}
|
|
418
20
|
|
|
419
21
|
const registeredServices = new Set();
|
|
420
22
|
async function registerService(options) {
|
|
@@ -444,7 +46,7 @@ async function registerService(options) {
|
|
|
444
46
|
}
|
|
445
47
|
serviceDefinition.check = checkDefinition;
|
|
446
48
|
}
|
|
447
|
-
await
|
|
49
|
+
await getClient().agent.service.register(serviceDefinition);
|
|
448
50
|
registeredServices.add(id);
|
|
449
51
|
console.log(`✅ Service "${id}" registered successfully.`);
|
|
450
52
|
}
|
|
@@ -453,17 +55,17 @@ async function deregisterService(id) {
|
|
|
453
55
|
console.log(`⚠️ Service "${id}" is not registered.`);
|
|
454
56
|
return;
|
|
455
57
|
}
|
|
456
|
-
await
|
|
58
|
+
await getClient().agent.service.deregister(id);
|
|
457
59
|
registeredServices.delete(id);
|
|
458
60
|
console.log(`🛑 Service "${id}" deregistered successfully.`);
|
|
459
61
|
}
|
|
460
62
|
|
|
461
63
|
async function listServices() {
|
|
462
|
-
const services = await
|
|
64
|
+
const services = await getClient().agent.service.list();
|
|
463
65
|
return Object.values(services);
|
|
464
66
|
}
|
|
465
67
|
async function getServiceInstances(serviceName) {
|
|
466
|
-
const services = await
|
|
68
|
+
const services = await getClient().catalog.service.nodes(serviceName);
|
|
467
69
|
return services;
|
|
468
70
|
}
|
|
469
71
|
async function getRandomServiceInstance(serviceName) {
|
|
@@ -1323,6 +925,10 @@ AxiosError$1.from = (error, code, config, request, response, customProps) => {
|
|
|
1323
925
|
return axiosError;
|
|
1324
926
|
};
|
|
1325
927
|
|
|
928
|
+
function getDefaultExportFromCjs (x) {
|
|
929
|
+
return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;
|
|
930
|
+
}
|
|
931
|
+
|
|
1326
932
|
var delayed_stream;
|
|
1327
933
|
var hasRequiredDelayed_stream;
|
|
1328
934
|
|
|
@@ -1330,7 +936,7 @@ function requireDelayed_stream () {
|
|
|
1330
936
|
if (hasRequiredDelayed_stream) return delayed_stream;
|
|
1331
937
|
hasRequiredDelayed_stream = 1;
|
|
1332
938
|
var Stream = stream.Stream;
|
|
1333
|
-
var util = require$$1
|
|
939
|
+
var util = require$$1;
|
|
1334
940
|
|
|
1335
941
|
delayed_stream = DelayedStream;
|
|
1336
942
|
function DelayedStream() {
|
|
@@ -1445,7 +1051,7 @@ var hasRequiredCombined_stream;
|
|
|
1445
1051
|
function requireCombined_stream () {
|
|
1446
1052
|
if (hasRequiredCombined_stream) return combined_stream;
|
|
1447
1053
|
hasRequiredCombined_stream = 1;
|
|
1448
|
-
var util = require$$1
|
|
1054
|
+
var util = require$$1;
|
|
1449
1055
|
var Stream = stream.Stream;
|
|
1450
1056
|
var DelayedStream = requireDelayed_stream();
|
|
1451
1057
|
|
|
@@ -12402,7 +12008,7 @@ function requireMimeTypes () {
|
|
|
12402
12008
|
*/
|
|
12403
12009
|
|
|
12404
12010
|
var db = requireMimeDb();
|
|
12405
|
-
var extname = require$$1.extname;
|
|
12011
|
+
var extname = require$$1$1.extname;
|
|
12406
12012
|
|
|
12407
12013
|
/**
|
|
12408
12014
|
* Module variables.
|
|
@@ -14142,12 +13748,12 @@ function requireForm_data () {
|
|
|
14142
13748
|
if (hasRequiredForm_data) return form_data;
|
|
14143
13749
|
hasRequiredForm_data = 1;
|
|
14144
13750
|
var CombinedStream = requireCombined_stream();
|
|
14145
|
-
var util = require$$1
|
|
14146
|
-
var path = require$$1;
|
|
14147
|
-
var http = require$$3
|
|
14148
|
-
var https = require$$4
|
|
14149
|
-
var parseUrl = require$$0$
|
|
14150
|
-
var fs = require$$
|
|
13751
|
+
var util = require$$1;
|
|
13752
|
+
var path = require$$1$1;
|
|
13753
|
+
var http = require$$3;
|
|
13754
|
+
var https = require$$4;
|
|
13755
|
+
var parseUrl = require$$0$1.parse;
|
|
13756
|
+
var fs = require$$6;
|
|
14151
13757
|
var Stream = stream.Stream;
|
|
14152
13758
|
var mime = requireMimeTypes();
|
|
14153
13759
|
var asynckit = requireAsynckit();
|
|
@@ -15051,7 +14657,7 @@ var transitionalDefaults = {
|
|
|
15051
14657
|
clarifyTimeoutError: false
|
|
15052
14658
|
};
|
|
15053
14659
|
|
|
15054
|
-
var URLSearchParams = require$$0$
|
|
14660
|
+
var URLSearchParams = require$$0$1.URLSearchParams;
|
|
15055
14661
|
|
|
15056
14662
|
const ALPHA = 'abcdefghijklmnopqrstuvwxyz';
|
|
15057
14663
|
|
|
@@ -15067,7 +14673,7 @@ const generateString = (size = 16, alphabet = ALPHABET.ALPHA_DIGIT) => {
|
|
|
15067
14673
|
let str = '';
|
|
15068
14674
|
const {length} = alphabet;
|
|
15069
14675
|
const randomValues = new Uint32Array(size);
|
|
15070
|
-
|
|
14676
|
+
crypto.randomFillSync(randomValues);
|
|
15071
14677
|
for (let i = 0; i < size; i++) {
|
|
15072
14678
|
str += alphabet[randomValues[i] % length];
|
|
15073
14679
|
}
|
|
@@ -15133,12 +14739,12 @@ const hasStandardBrowserWebWorkerEnv = (() => {
|
|
|
15133
14739
|
const origin = hasBrowserEnv && window.location.href || 'http://localhost';
|
|
15134
14740
|
|
|
15135
14741
|
var utils = /*#__PURE__*/Object.freeze({
|
|
15136
|
-
|
|
15137
|
-
|
|
15138
|
-
|
|
15139
|
-
|
|
15140
|
-
|
|
15141
|
-
|
|
14742
|
+
__proto__: null,
|
|
14743
|
+
hasBrowserEnv: hasBrowserEnv,
|
|
14744
|
+
hasStandardBrowserEnv: hasStandardBrowserEnv,
|
|
14745
|
+
hasStandardBrowserWebWorkerEnv: hasStandardBrowserWebWorkerEnv,
|
|
14746
|
+
navigator: _navigator,
|
|
14747
|
+
origin: origin
|
|
15142
14748
|
});
|
|
15143
14749
|
|
|
15144
14750
|
var platform = {
|
|
@@ -15883,7 +15489,7 @@ function requireProxyFromEnv () {
|
|
|
15883
15489
|
if (hasRequiredProxyFromEnv) return proxyFromEnv$1;
|
|
15884
15490
|
hasRequiredProxyFromEnv = 1;
|
|
15885
15491
|
|
|
15886
|
-
var parseUrl = require$$0$
|
|
15492
|
+
var parseUrl = require$$0$1.parse;
|
|
15887
15493
|
|
|
15888
15494
|
var DEFAULT_PORTS = {
|
|
15889
15495
|
ftp: 21,
|
|
@@ -16026,12 +15632,12 @@ var hasRequiredFollowRedirects;
|
|
|
16026
15632
|
function requireFollowRedirects () {
|
|
16027
15633
|
if (hasRequiredFollowRedirects) return followRedirects$1.exports;
|
|
16028
15634
|
hasRequiredFollowRedirects = 1;
|
|
16029
|
-
var url = require$$0$
|
|
15635
|
+
var url = require$$0$1;
|
|
16030
15636
|
var URL = url.URL;
|
|
16031
|
-
var http = require$$3
|
|
16032
|
-
var https = require$$4
|
|
15637
|
+
var http = require$$3;
|
|
15638
|
+
var https = require$$4;
|
|
16033
15639
|
var Writable = stream.Writable;
|
|
16034
|
-
var assert = require$$4$
|
|
15640
|
+
var assert = require$$4$1;
|
|
16035
15641
|
var debug = requireDebug();
|
|
16036
15642
|
|
|
16037
15643
|
// Preventive platform detection
|
|
@@ -16926,7 +16532,7 @@ const readBlob = async function* (blob) {
|
|
|
16926
16532
|
|
|
16927
16533
|
const BOUNDARY_ALPHABET = platform.ALPHABET.ALPHA_DIGIT + '-_';
|
|
16928
16534
|
|
|
16929
|
-
const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new require$$1
|
|
16535
|
+
const textEncoder = typeof TextEncoder === 'function' ? new TextEncoder() : new require$$1.TextEncoder();
|
|
16930
16536
|
|
|
16931
16537
|
const CRLF = '\r\n';
|
|
16932
16538
|
const CRLF_BYTES = textEncoder.encode(CRLF);
|
|
@@ -17483,7 +17089,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17483
17089
|
|
|
17484
17090
|
if (!headers.hasContentLength()) {
|
|
17485
17091
|
try {
|
|
17486
|
-
const knownLength = await require$$1
|
|
17092
|
+
const knownLength = await require$$1.promisify(data.getLength).call(data);
|
|
17487
17093
|
Number.isFinite(knownLength) && knownLength >= 0 && headers.setContentLength(knownLength);
|
|
17488
17094
|
/*eslint no-empty:0*/
|
|
17489
17095
|
} catch (e) {
|
|
@@ -17611,7 +17217,7 @@ var httpAdapter = isHttpAdapterSupported && function httpAdapter(config) {
|
|
|
17611
17217
|
if (config.transport) {
|
|
17612
17218
|
transport = config.transport;
|
|
17613
17219
|
} else if (config.maxRedirects === 0) {
|
|
17614
|
-
transport = isHttpsRequest ? require$$4
|
|
17220
|
+
transport = isHttpsRequest ? require$$4 : require$$3;
|
|
17615
17221
|
} else {
|
|
17616
17222
|
if (config.maxRedirects) {
|
|
17617
17223
|
options.maxRedirects = config.maxRedirects;
|