@discomedia/utils 1.0.6 → 1.0.7
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/README.md +95 -3
- package/dist/index-frontend.cjs +16027 -0
- package/dist/index-frontend.cjs.map +1 -0
- package/dist/index-frontend.mjs +16023 -0
- package/dist/index-frontend.mjs.map +1 -0
- package/dist/index.cjs +529 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +529 -10
- package/dist/index.mjs.map +1 -1
- package/dist/package.json +7 -1
- package/dist/test.js +6426 -582
- package/dist/test.js.map +1 -1
- package/dist/types/alpaca-market-data-api.d.ts +1 -0
- package/dist/types/alpaca-market-data-api.d.ts.map +1 -1
- package/dist/types/alpaca-trading-api.d.ts.map +1 -1
- package/dist/types/index-frontend.d.ts +15 -0
- package/dist/types/index-frontend.d.ts.map +1 -0
- package/dist/types/old-test.d.ts +2 -0
- package/dist/types/old-test.d.ts.map +1 -0
- package/dist/types-frontend/alpaca-market-data-api.d.ts +372 -0
- package/dist/types-frontend/alpaca-market-data-api.d.ts.map +1 -0
- package/dist/types-frontend/alpaca-trading-api.d.ts +315 -0
- package/dist/types-frontend/alpaca-trading-api.d.ts.map +1 -0
- package/dist/types-frontend/format-tools.d.ts +46 -0
- package/dist/types-frontend/format-tools.d.ts.map +1 -0
- package/dist/types-frontend/index-frontend.d.ts +15 -0
- package/dist/types-frontend/index-frontend.d.ts.map +1 -0
- package/dist/types-frontend/index.d.ts +125 -0
- package/dist/types-frontend/index.d.ts.map +1 -0
- package/dist/types-frontend/json-tools.d.ts +33 -0
- package/dist/types-frontend/json-tools.d.ts.map +1 -0
- package/dist/types-frontend/llm-config.d.ts +36 -0
- package/dist/types-frontend/llm-config.d.ts.map +1 -0
- package/dist/types-frontend/llm-deepseek.d.ts +12 -0
- package/dist/types-frontend/llm-deepseek.d.ts.map +1 -0
- package/dist/types-frontend/llm-images.d.ts +49 -0
- package/dist/types-frontend/llm-images.d.ts.map +1 -0
- package/dist/types-frontend/llm-openai.d.ts +64 -0
- package/dist/types-frontend/llm-openai.d.ts.map +1 -0
- package/dist/types-frontend/llm-utils.d.ts +16 -0
- package/dist/types-frontend/llm-utils.d.ts.map +1 -0
- package/dist/types-frontend/logging.d.ts +12 -0
- package/dist/types-frontend/logging.d.ts.map +1 -0
- package/dist/types-frontend/market-hours.d.ts +24 -0
- package/dist/types-frontend/market-hours.d.ts.map +1 -0
- package/dist/types-frontend/market-time.d.ts +254 -0
- package/dist/types-frontend/market-time.d.ts.map +1 -0
- package/dist/types-frontend/misc-utils.d.ts +49 -0
- package/dist/types-frontend/misc-utils.d.ts.map +1 -0
- package/dist/types-frontend/old-test.d.ts +2 -0
- package/dist/types-frontend/old-test.d.ts.map +1 -0
- package/dist/types-frontend/polygon-indices.d.ts +85 -0
- package/dist/types-frontend/polygon-indices.d.ts.map +1 -0
- package/dist/types-frontend/polygon.d.ts +126 -0
- package/dist/types-frontend/polygon.d.ts.map +1 -0
- package/dist/types-frontend/technical-analysis.d.ts +90 -0
- package/dist/types-frontend/technical-analysis.d.ts.map +1 -0
- package/dist/types-frontend/test.d.ts +2 -0
- package/dist/types-frontend/test.d.ts.map +1 -0
- package/dist/types-frontend/testing/market-time-refactor-test.d.ts +1 -0
- package/dist/types-frontend/testing/market-time-refactor-test.d.ts.map +1 -0
- package/dist/types-frontend/types/alpaca-types.d.ts +962 -0
- package/dist/types-frontend/types/alpaca-types.d.ts.map +1 -0
- package/dist/types-frontend/types/index.d.ts +7 -0
- package/dist/types-frontend/types/index.d.ts.map +1 -0
- package/dist/types-frontend/types/llm-types.d.ts +82 -0
- package/dist/types-frontend/types/llm-types.d.ts.map +1 -0
- package/dist/types-frontend/types/logging-types.d.ts +10 -0
- package/dist/types-frontend/types/logging-types.d.ts.map +1 -0
- package/dist/types-frontend/types/market-time-types.d.ts +59 -0
- package/dist/types-frontend/types/market-time-types.d.ts.map +1 -0
- package/dist/types-frontend/types/polygon-indices-types.d.ts +190 -0
- package/dist/types-frontend/types/polygon-indices-types.d.ts.map +1 -0
- package/dist/types-frontend/types/polygon-types.d.ts +204 -0
- package/dist/types-frontend/types/polygon-types.d.ts.map +1 -0
- package/dist/types-frontend/types/ta-types.d.ts +89 -0
- package/dist/types-frontend/types/ta-types.d.ts.map +1 -0
- package/package.json +7 -1
package/dist/index.mjs
CHANGED
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { startOfDay, set, endOfDay, add, sub, format, differenceInMilliseconds, isBefore } from 'date-fns';
|
|
2
2
|
import { toZonedTime, fromZonedTime, formatInTimeZone } from 'date-fns-tz';
|
|
3
3
|
import require$$0$3, { EventEmitter } from 'events';
|
|
4
|
-
import require$$1
|
|
4
|
+
import require$$1 from 'https';
|
|
5
5
|
import require$$2 from 'http';
|
|
6
|
-
import require$$3 from 'net';
|
|
7
|
-
import require$$4 from 'tls';
|
|
8
|
-
import require$$
|
|
6
|
+
import require$$3$1 from 'net';
|
|
7
|
+
import require$$4$1 from 'tls';
|
|
8
|
+
import require$$3 from 'crypto';
|
|
9
9
|
import require$$0$2 from 'stream';
|
|
10
10
|
import require$$7 from 'url';
|
|
11
11
|
import require$$0 from 'zlib';
|
|
12
12
|
import require$$0$1 from 'buffer';
|
|
13
|
+
import require$$0$4 from 'fs';
|
|
14
|
+
import require$$1$1 from 'path';
|
|
15
|
+
import require$$2$1 from 'os';
|
|
13
16
|
|
|
14
17
|
/**
|
|
15
18
|
* Logs a message to the console.
|
|
@@ -11878,7 +11881,7 @@ function requireSender () {
|
|
|
11878
11881
|
hasRequiredSender = 1;
|
|
11879
11882
|
|
|
11880
11883
|
const { Duplex } = require$$0$2;
|
|
11881
|
-
const { randomFillSync } = require$$
|
|
11884
|
+
const { randomFillSync } = require$$3;
|
|
11882
11885
|
|
|
11883
11886
|
const PerMessageDeflate = requirePermessageDeflate();
|
|
11884
11887
|
const { EMPTY_BUFFER, kWebSocket, NOOP } = requireConstants();
|
|
@@ -12999,11 +13002,11 @@ function requireWebsocket () {
|
|
|
12999
13002
|
hasRequiredWebsocket = 1;
|
|
13000
13003
|
|
|
13001
13004
|
const EventEmitter = require$$0$3;
|
|
13002
|
-
const https = require$$1
|
|
13005
|
+
const https = require$$1;
|
|
13003
13006
|
const http = require$$2;
|
|
13004
|
-
const net = require$$3;
|
|
13005
|
-
const tls = require$$4;
|
|
13006
|
-
const { randomBytes, createHash } = require$$
|
|
13007
|
+
const net = require$$3$1;
|
|
13008
|
+
const tls = require$$4$1;
|
|
13009
|
+
const { randomBytes, createHash } = require$$3;
|
|
13007
13010
|
const { Duplex, Readable } = require$$0$2;
|
|
13008
13011
|
const { URL } = require$$7;
|
|
13009
13012
|
|
|
@@ -14646,7 +14649,7 @@ function requireWebsocketServer () {
|
|
|
14646
14649
|
const EventEmitter = require$$0$3;
|
|
14647
14650
|
const http = require$$2;
|
|
14648
14651
|
const { Duplex } = require$$0$2;
|
|
14649
|
-
const { createHash } = require$$
|
|
14652
|
+
const { createHash } = require$$3;
|
|
14650
14653
|
|
|
14651
14654
|
const extension = requireExtension();
|
|
14652
14655
|
const PerMessageDeflate = requirePermessageDeflate();
|
|
@@ -15194,6 +15197,522 @@ function requireWebsocketServer () {
|
|
|
15194
15197
|
|
|
15195
15198
|
requireWebsocketServer();
|
|
15196
15199
|
|
|
15200
|
+
var config = {};
|
|
15201
|
+
|
|
15202
|
+
var main = {exports: {}};
|
|
15203
|
+
|
|
15204
|
+
var version = "17.1.0";
|
|
15205
|
+
var require$$4 = {
|
|
15206
|
+
version: version};
|
|
15207
|
+
|
|
15208
|
+
var hasRequiredMain;
|
|
15209
|
+
|
|
15210
|
+
function requireMain () {
|
|
15211
|
+
if (hasRequiredMain) return main.exports;
|
|
15212
|
+
hasRequiredMain = 1;
|
|
15213
|
+
const fs = require$$0$4;
|
|
15214
|
+
const path = require$$1$1;
|
|
15215
|
+
const os = require$$2$1;
|
|
15216
|
+
const crypto = require$$3;
|
|
15217
|
+
const packageJson = require$$4;
|
|
15218
|
+
|
|
15219
|
+
const version = packageJson.version;
|
|
15220
|
+
|
|
15221
|
+
// Array of tips to display randomly
|
|
15222
|
+
const TIPS = [
|
|
15223
|
+
'🔐 encrypt with dotenvx: https://dotenvx.com',
|
|
15224
|
+
'🔐 prevent committing .env to code: https://dotenvx.com/precommit',
|
|
15225
|
+
'🔐 prevent building .env in docker: https://dotenvx.com/prebuild',
|
|
15226
|
+
'🛠️ run anywhere with `dotenvx run -- yourcommand`',
|
|
15227
|
+
'⚙️ specify custom .env file path with { path: \'/custom/path/.env\' }',
|
|
15228
|
+
'⚙️ enable debug logging with { debug: true }',
|
|
15229
|
+
'⚙️ override existing env vars with { override: true }',
|
|
15230
|
+
'⚙️ suppress all logs with { quiet: true }',
|
|
15231
|
+
'⚙️ write to custom object with { processEnv: myObject }',
|
|
15232
|
+
'⚙️ load multiple .env files with { path: [\'.env.local\', \'.env\'] }'
|
|
15233
|
+
];
|
|
15234
|
+
|
|
15235
|
+
// Get a random tip from the tips array
|
|
15236
|
+
function _getRandomTip () {
|
|
15237
|
+
return TIPS[Math.floor(Math.random() * TIPS.length)]
|
|
15238
|
+
}
|
|
15239
|
+
|
|
15240
|
+
function supportsAnsi () {
|
|
15241
|
+
return process.stdout.isTTY // && process.env.TERM !== 'dumb'
|
|
15242
|
+
}
|
|
15243
|
+
|
|
15244
|
+
function dim (text) {
|
|
15245
|
+
return supportsAnsi() ? `\x1b[2m${text}\x1b[0m` : text
|
|
15246
|
+
}
|
|
15247
|
+
|
|
15248
|
+
const LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
15249
|
+
|
|
15250
|
+
// Parse src into an Object
|
|
15251
|
+
function parse (src) {
|
|
15252
|
+
const obj = {};
|
|
15253
|
+
|
|
15254
|
+
// Convert buffer to string
|
|
15255
|
+
let lines = src.toString();
|
|
15256
|
+
|
|
15257
|
+
// Convert line breaks to same format
|
|
15258
|
+
lines = lines.replace(/\r\n?/mg, '\n');
|
|
15259
|
+
|
|
15260
|
+
let match;
|
|
15261
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
15262
|
+
const key = match[1];
|
|
15263
|
+
|
|
15264
|
+
// Default undefined or null to empty string
|
|
15265
|
+
let value = (match[2] || '');
|
|
15266
|
+
|
|
15267
|
+
// Remove whitespace
|
|
15268
|
+
value = value.trim();
|
|
15269
|
+
|
|
15270
|
+
// Check if double quoted
|
|
15271
|
+
const maybeQuote = value[0];
|
|
15272
|
+
|
|
15273
|
+
// Remove surrounding quotes
|
|
15274
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, '$2');
|
|
15275
|
+
|
|
15276
|
+
// Expand newlines if double quoted
|
|
15277
|
+
if (maybeQuote === '"') {
|
|
15278
|
+
value = value.replace(/\\n/g, '\n');
|
|
15279
|
+
value = value.replace(/\\r/g, '\r');
|
|
15280
|
+
}
|
|
15281
|
+
|
|
15282
|
+
// Add to object
|
|
15283
|
+
obj[key] = value;
|
|
15284
|
+
}
|
|
15285
|
+
|
|
15286
|
+
return obj
|
|
15287
|
+
}
|
|
15288
|
+
|
|
15289
|
+
function _parseVault (options) {
|
|
15290
|
+
options = options || {};
|
|
15291
|
+
|
|
15292
|
+
const vaultPath = _vaultPath(options);
|
|
15293
|
+
options.path = vaultPath; // parse .env.vault
|
|
15294
|
+
const result = DotenvModule.configDotenv(options);
|
|
15295
|
+
if (!result.parsed) {
|
|
15296
|
+
const err = new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
15297
|
+
err.code = 'MISSING_DATA';
|
|
15298
|
+
throw err
|
|
15299
|
+
}
|
|
15300
|
+
|
|
15301
|
+
// handle scenario for comma separated keys - for use with key rotation
|
|
15302
|
+
// example: DOTENV_KEY="dotenv://:key_1234@dotenvx.com/vault/.env.vault?environment=prod,dotenv://:key_7890@dotenvx.com/vault/.env.vault?environment=prod"
|
|
15303
|
+
const keys = _dotenvKey(options).split(',');
|
|
15304
|
+
const length = keys.length;
|
|
15305
|
+
|
|
15306
|
+
let decrypted;
|
|
15307
|
+
for (let i = 0; i < length; i++) {
|
|
15308
|
+
try {
|
|
15309
|
+
// Get full key
|
|
15310
|
+
const key = keys[i].trim();
|
|
15311
|
+
|
|
15312
|
+
// Get instructions for decrypt
|
|
15313
|
+
const attrs = _instructions(result, key);
|
|
15314
|
+
|
|
15315
|
+
// Decrypt
|
|
15316
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
15317
|
+
|
|
15318
|
+
break
|
|
15319
|
+
} catch (error) {
|
|
15320
|
+
// last key
|
|
15321
|
+
if (i + 1 >= length) {
|
|
15322
|
+
throw error
|
|
15323
|
+
}
|
|
15324
|
+
// try next key
|
|
15325
|
+
}
|
|
15326
|
+
}
|
|
15327
|
+
|
|
15328
|
+
// Parse decrypted .env string
|
|
15329
|
+
return DotenvModule.parse(decrypted)
|
|
15330
|
+
}
|
|
15331
|
+
|
|
15332
|
+
function _warn (message) {
|
|
15333
|
+
console.error(`[dotenv@${version}][WARN] ${message}`);
|
|
15334
|
+
}
|
|
15335
|
+
|
|
15336
|
+
function _debug (message) {
|
|
15337
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
15338
|
+
}
|
|
15339
|
+
|
|
15340
|
+
function _log (message) {
|
|
15341
|
+
console.log(`[dotenv@${version}] ${message}`);
|
|
15342
|
+
}
|
|
15343
|
+
|
|
15344
|
+
function _dotenvKey (options) {
|
|
15345
|
+
// prioritize developer directly setting options.DOTENV_KEY
|
|
15346
|
+
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
|
|
15347
|
+
return options.DOTENV_KEY
|
|
15348
|
+
}
|
|
15349
|
+
|
|
15350
|
+
// secondary infra already contains a DOTENV_KEY environment variable
|
|
15351
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
15352
|
+
return process.env.DOTENV_KEY
|
|
15353
|
+
}
|
|
15354
|
+
|
|
15355
|
+
// fallback to empty string
|
|
15356
|
+
return ''
|
|
15357
|
+
}
|
|
15358
|
+
|
|
15359
|
+
function _instructions (result, dotenvKey) {
|
|
15360
|
+
// Parse DOTENV_KEY. Format is a URI
|
|
15361
|
+
let uri;
|
|
15362
|
+
try {
|
|
15363
|
+
uri = new URL(dotenvKey);
|
|
15364
|
+
} catch (error) {
|
|
15365
|
+
if (error.code === 'ERR_INVALID_URL') {
|
|
15366
|
+
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');
|
|
15367
|
+
err.code = 'INVALID_DOTENV_KEY';
|
|
15368
|
+
throw err
|
|
15369
|
+
}
|
|
15370
|
+
|
|
15371
|
+
throw error
|
|
15372
|
+
}
|
|
15373
|
+
|
|
15374
|
+
// Get decrypt key
|
|
15375
|
+
const key = uri.password;
|
|
15376
|
+
if (!key) {
|
|
15377
|
+
const err = new Error('INVALID_DOTENV_KEY: Missing key part');
|
|
15378
|
+
err.code = 'INVALID_DOTENV_KEY';
|
|
15379
|
+
throw err
|
|
15380
|
+
}
|
|
15381
|
+
|
|
15382
|
+
// Get environment
|
|
15383
|
+
const environment = uri.searchParams.get('environment');
|
|
15384
|
+
if (!environment) {
|
|
15385
|
+
const err = new Error('INVALID_DOTENV_KEY: Missing environment part');
|
|
15386
|
+
err.code = 'INVALID_DOTENV_KEY';
|
|
15387
|
+
throw err
|
|
15388
|
+
}
|
|
15389
|
+
|
|
15390
|
+
// Get ciphertext payload
|
|
15391
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
15392
|
+
const ciphertext = result.parsed[environmentKey]; // DOTENV_VAULT_PRODUCTION
|
|
15393
|
+
if (!ciphertext) {
|
|
15394
|
+
const err = new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
15395
|
+
err.code = 'NOT_FOUND_DOTENV_ENVIRONMENT';
|
|
15396
|
+
throw err
|
|
15397
|
+
}
|
|
15398
|
+
|
|
15399
|
+
return { ciphertext, key }
|
|
15400
|
+
}
|
|
15401
|
+
|
|
15402
|
+
function _vaultPath (options) {
|
|
15403
|
+
let possibleVaultPath = null;
|
|
15404
|
+
|
|
15405
|
+
if (options && options.path && options.path.length > 0) {
|
|
15406
|
+
if (Array.isArray(options.path)) {
|
|
15407
|
+
for (const filepath of options.path) {
|
|
15408
|
+
if (fs.existsSync(filepath)) {
|
|
15409
|
+
possibleVaultPath = filepath.endsWith('.vault') ? filepath : `${filepath}.vault`;
|
|
15410
|
+
}
|
|
15411
|
+
}
|
|
15412
|
+
} else {
|
|
15413
|
+
possibleVaultPath = options.path.endsWith('.vault') ? options.path : `${options.path}.vault`;
|
|
15414
|
+
}
|
|
15415
|
+
} else {
|
|
15416
|
+
possibleVaultPath = path.resolve(process.cwd(), '.env.vault');
|
|
15417
|
+
}
|
|
15418
|
+
|
|
15419
|
+
if (fs.existsSync(possibleVaultPath)) {
|
|
15420
|
+
return possibleVaultPath
|
|
15421
|
+
}
|
|
15422
|
+
|
|
15423
|
+
return null
|
|
15424
|
+
}
|
|
15425
|
+
|
|
15426
|
+
function _resolveHome (envPath) {
|
|
15427
|
+
return envPath[0] === '~' ? path.join(os.homedir(), envPath.slice(1)) : envPath
|
|
15428
|
+
}
|
|
15429
|
+
|
|
15430
|
+
function _configVault (options) {
|
|
15431
|
+
const debug = Boolean(options && options.debug);
|
|
15432
|
+
const quiet = Boolean(options && options.quiet);
|
|
15433
|
+
|
|
15434
|
+
if (debug || !quiet) {
|
|
15435
|
+
_log('Loading env from encrypted .env.vault');
|
|
15436
|
+
}
|
|
15437
|
+
|
|
15438
|
+
const parsed = DotenvModule._parseVault(options);
|
|
15439
|
+
|
|
15440
|
+
let processEnv = process.env;
|
|
15441
|
+
if (options && options.processEnv != null) {
|
|
15442
|
+
processEnv = options.processEnv;
|
|
15443
|
+
}
|
|
15444
|
+
|
|
15445
|
+
DotenvModule.populate(processEnv, parsed, options);
|
|
15446
|
+
|
|
15447
|
+
return { parsed }
|
|
15448
|
+
}
|
|
15449
|
+
|
|
15450
|
+
function configDotenv (options) {
|
|
15451
|
+
const dotenvPath = path.resolve(process.cwd(), '.env');
|
|
15452
|
+
let encoding = 'utf8';
|
|
15453
|
+
const debug = Boolean(options && options.debug);
|
|
15454
|
+
const quiet = Boolean(options && options.quiet);
|
|
15455
|
+
|
|
15456
|
+
if (options && options.encoding) {
|
|
15457
|
+
encoding = options.encoding;
|
|
15458
|
+
} else {
|
|
15459
|
+
if (debug) {
|
|
15460
|
+
_debug('No encoding is specified. UTF-8 is used by default');
|
|
15461
|
+
}
|
|
15462
|
+
}
|
|
15463
|
+
|
|
15464
|
+
let optionPaths = [dotenvPath]; // default, look for .env
|
|
15465
|
+
if (options && options.path) {
|
|
15466
|
+
if (!Array.isArray(options.path)) {
|
|
15467
|
+
optionPaths = [_resolveHome(options.path)];
|
|
15468
|
+
} else {
|
|
15469
|
+
optionPaths = []; // reset default
|
|
15470
|
+
for (const filepath of options.path) {
|
|
15471
|
+
optionPaths.push(_resolveHome(filepath));
|
|
15472
|
+
}
|
|
15473
|
+
}
|
|
15474
|
+
}
|
|
15475
|
+
|
|
15476
|
+
// Build the parsed data in a temporary object (because we need to return it). Once we have the final
|
|
15477
|
+
// parsed data, we will combine it with process.env (or options.processEnv if provided).
|
|
15478
|
+
let lastError;
|
|
15479
|
+
const parsedAll = {};
|
|
15480
|
+
for (const path of optionPaths) {
|
|
15481
|
+
try {
|
|
15482
|
+
// Specifying an encoding returns a string instead of a buffer
|
|
15483
|
+
const parsed = DotenvModule.parse(fs.readFileSync(path, { encoding }));
|
|
15484
|
+
|
|
15485
|
+
DotenvModule.populate(parsedAll, parsed, options);
|
|
15486
|
+
} catch (e) {
|
|
15487
|
+
if (debug) {
|
|
15488
|
+
_debug(`Failed to load ${path} ${e.message}`);
|
|
15489
|
+
}
|
|
15490
|
+
lastError = e;
|
|
15491
|
+
}
|
|
15492
|
+
}
|
|
15493
|
+
|
|
15494
|
+
let processEnv = process.env;
|
|
15495
|
+
if (options && options.processEnv != null) {
|
|
15496
|
+
processEnv = options.processEnv;
|
|
15497
|
+
}
|
|
15498
|
+
|
|
15499
|
+
const populated = DotenvModule.populate(processEnv, parsedAll, options);
|
|
15500
|
+
|
|
15501
|
+
if (debug || !quiet) {
|
|
15502
|
+
const keysCount = Object.keys(populated).length;
|
|
15503
|
+
const shortPaths = [];
|
|
15504
|
+
for (const filePath of optionPaths) {
|
|
15505
|
+
try {
|
|
15506
|
+
const relative = path.relative(process.cwd(), filePath);
|
|
15507
|
+
shortPaths.push(relative);
|
|
15508
|
+
} catch (e) {
|
|
15509
|
+
if (debug) {
|
|
15510
|
+
_debug(`Failed to load ${filePath} ${e.message}`);
|
|
15511
|
+
}
|
|
15512
|
+
lastError = e;
|
|
15513
|
+
}
|
|
15514
|
+
}
|
|
15515
|
+
|
|
15516
|
+
_log(`injecting env (${keysCount}) from ${shortPaths.join(',')} ${dim(`(tip: ${_getRandomTip()})`)}`);
|
|
15517
|
+
}
|
|
15518
|
+
|
|
15519
|
+
if (lastError) {
|
|
15520
|
+
return { parsed: parsedAll, error: lastError }
|
|
15521
|
+
} else {
|
|
15522
|
+
return { parsed: parsedAll }
|
|
15523
|
+
}
|
|
15524
|
+
}
|
|
15525
|
+
|
|
15526
|
+
// Populates process.env from .env file
|
|
15527
|
+
function config (options) {
|
|
15528
|
+
// fallback to original dotenv if DOTENV_KEY is not set
|
|
15529
|
+
if (_dotenvKey(options).length === 0) {
|
|
15530
|
+
return DotenvModule.configDotenv(options)
|
|
15531
|
+
}
|
|
15532
|
+
|
|
15533
|
+
const vaultPath = _vaultPath(options);
|
|
15534
|
+
|
|
15535
|
+
// dotenvKey exists but .env.vault file does not exist
|
|
15536
|
+
if (!vaultPath) {
|
|
15537
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
15538
|
+
|
|
15539
|
+
return DotenvModule.configDotenv(options)
|
|
15540
|
+
}
|
|
15541
|
+
|
|
15542
|
+
return DotenvModule._configVault(options)
|
|
15543
|
+
}
|
|
15544
|
+
|
|
15545
|
+
function decrypt (encrypted, keyStr) {
|
|
15546
|
+
const key = Buffer.from(keyStr.slice(-64), 'hex');
|
|
15547
|
+
let ciphertext = Buffer.from(encrypted, 'base64');
|
|
15548
|
+
|
|
15549
|
+
const nonce = ciphertext.subarray(0, 12);
|
|
15550
|
+
const authTag = ciphertext.subarray(-16);
|
|
15551
|
+
ciphertext = ciphertext.subarray(12, -16);
|
|
15552
|
+
|
|
15553
|
+
try {
|
|
15554
|
+
const aesgcm = crypto.createDecipheriv('aes-256-gcm', key, nonce);
|
|
15555
|
+
aesgcm.setAuthTag(authTag);
|
|
15556
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`
|
|
15557
|
+
} catch (error) {
|
|
15558
|
+
const isRange = error instanceof RangeError;
|
|
15559
|
+
const invalidKeyLength = error.message === 'Invalid key length';
|
|
15560
|
+
const decryptionFailed = error.message === 'Unsupported state or unable to authenticate data';
|
|
15561
|
+
|
|
15562
|
+
if (isRange || invalidKeyLength) {
|
|
15563
|
+
const err = new Error('INVALID_DOTENV_KEY: It must be 64 characters long (or more)');
|
|
15564
|
+
err.code = 'INVALID_DOTENV_KEY';
|
|
15565
|
+
throw err
|
|
15566
|
+
} else if (decryptionFailed) {
|
|
15567
|
+
const err = new Error('DECRYPTION_FAILED: Please check your DOTENV_KEY');
|
|
15568
|
+
err.code = 'DECRYPTION_FAILED';
|
|
15569
|
+
throw err
|
|
15570
|
+
} else {
|
|
15571
|
+
throw error
|
|
15572
|
+
}
|
|
15573
|
+
}
|
|
15574
|
+
}
|
|
15575
|
+
|
|
15576
|
+
// Populate process.env with parsed values
|
|
15577
|
+
function populate (processEnv, parsed, options = {}) {
|
|
15578
|
+
const debug = Boolean(options && options.debug);
|
|
15579
|
+
const override = Boolean(options && options.override);
|
|
15580
|
+
const populated = {};
|
|
15581
|
+
|
|
15582
|
+
if (typeof parsed !== 'object') {
|
|
15583
|
+
const err = new Error('OBJECT_REQUIRED: Please check the processEnv argument being passed to populate');
|
|
15584
|
+
err.code = 'OBJECT_REQUIRED';
|
|
15585
|
+
throw err
|
|
15586
|
+
}
|
|
15587
|
+
|
|
15588
|
+
// Set process.env
|
|
15589
|
+
for (const key of Object.keys(parsed)) {
|
|
15590
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
15591
|
+
if (override === true) {
|
|
15592
|
+
processEnv[key] = parsed[key];
|
|
15593
|
+
populated[key] = parsed[key];
|
|
15594
|
+
}
|
|
15595
|
+
|
|
15596
|
+
if (debug) {
|
|
15597
|
+
if (override === true) {
|
|
15598
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
15599
|
+
} else {
|
|
15600
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
15601
|
+
}
|
|
15602
|
+
}
|
|
15603
|
+
} else {
|
|
15604
|
+
processEnv[key] = parsed[key];
|
|
15605
|
+
populated[key] = parsed[key];
|
|
15606
|
+
}
|
|
15607
|
+
}
|
|
15608
|
+
|
|
15609
|
+
return populated
|
|
15610
|
+
}
|
|
15611
|
+
|
|
15612
|
+
const DotenvModule = {
|
|
15613
|
+
configDotenv,
|
|
15614
|
+
_configVault,
|
|
15615
|
+
_parseVault,
|
|
15616
|
+
config,
|
|
15617
|
+
decrypt,
|
|
15618
|
+
parse,
|
|
15619
|
+
populate
|
|
15620
|
+
};
|
|
15621
|
+
|
|
15622
|
+
main.exports.configDotenv = DotenvModule.configDotenv;
|
|
15623
|
+
main.exports._configVault = DotenvModule._configVault;
|
|
15624
|
+
main.exports._parseVault = DotenvModule._parseVault;
|
|
15625
|
+
main.exports.config = DotenvModule.config;
|
|
15626
|
+
main.exports.decrypt = DotenvModule.decrypt;
|
|
15627
|
+
main.exports.parse = DotenvModule.parse;
|
|
15628
|
+
main.exports.populate = DotenvModule.populate;
|
|
15629
|
+
|
|
15630
|
+
main.exports = DotenvModule;
|
|
15631
|
+
return main.exports;
|
|
15632
|
+
}
|
|
15633
|
+
|
|
15634
|
+
var envOptions;
|
|
15635
|
+
var hasRequiredEnvOptions;
|
|
15636
|
+
|
|
15637
|
+
function requireEnvOptions () {
|
|
15638
|
+
if (hasRequiredEnvOptions) return envOptions;
|
|
15639
|
+
hasRequiredEnvOptions = 1;
|
|
15640
|
+
// ../config.js accepts options via environment variables
|
|
15641
|
+
const options = {};
|
|
15642
|
+
|
|
15643
|
+
if (process.env.DOTENV_CONFIG_ENCODING != null) {
|
|
15644
|
+
options.encoding = process.env.DOTENV_CONFIG_ENCODING;
|
|
15645
|
+
}
|
|
15646
|
+
|
|
15647
|
+
if (process.env.DOTENV_CONFIG_PATH != null) {
|
|
15648
|
+
options.path = process.env.DOTENV_CONFIG_PATH;
|
|
15649
|
+
}
|
|
15650
|
+
|
|
15651
|
+
if (process.env.DOTENV_CONFIG_QUIET != null) {
|
|
15652
|
+
options.quiet = process.env.DOTENV_CONFIG_QUIET;
|
|
15653
|
+
}
|
|
15654
|
+
|
|
15655
|
+
if (process.env.DOTENV_CONFIG_DEBUG != null) {
|
|
15656
|
+
options.debug = process.env.DOTENV_CONFIG_DEBUG;
|
|
15657
|
+
}
|
|
15658
|
+
|
|
15659
|
+
if (process.env.DOTENV_CONFIG_OVERRIDE != null) {
|
|
15660
|
+
options.override = process.env.DOTENV_CONFIG_OVERRIDE;
|
|
15661
|
+
}
|
|
15662
|
+
|
|
15663
|
+
if (process.env.DOTENV_CONFIG_DOTENV_KEY != null) {
|
|
15664
|
+
options.DOTENV_KEY = process.env.DOTENV_CONFIG_DOTENV_KEY;
|
|
15665
|
+
}
|
|
15666
|
+
|
|
15667
|
+
envOptions = options;
|
|
15668
|
+
return envOptions;
|
|
15669
|
+
}
|
|
15670
|
+
|
|
15671
|
+
var cliOptions;
|
|
15672
|
+
var hasRequiredCliOptions;
|
|
15673
|
+
|
|
15674
|
+
function requireCliOptions () {
|
|
15675
|
+
if (hasRequiredCliOptions) return cliOptions;
|
|
15676
|
+
hasRequiredCliOptions = 1;
|
|
15677
|
+
const re = /^dotenv_config_(encoding|path|quiet|debug|override|DOTENV_KEY)=(.+)$/;
|
|
15678
|
+
|
|
15679
|
+
cliOptions = function optionMatcher (args) {
|
|
15680
|
+
const options = args.reduce(function (acc, cur) {
|
|
15681
|
+
const matches = cur.match(re);
|
|
15682
|
+
if (matches) {
|
|
15683
|
+
acc[matches[1]] = matches[2];
|
|
15684
|
+
}
|
|
15685
|
+
return acc
|
|
15686
|
+
}, {});
|
|
15687
|
+
|
|
15688
|
+
if (!('quiet' in options)) {
|
|
15689
|
+
options.quiet = 'true';
|
|
15690
|
+
}
|
|
15691
|
+
|
|
15692
|
+
return options
|
|
15693
|
+
};
|
|
15694
|
+
return cliOptions;
|
|
15695
|
+
}
|
|
15696
|
+
|
|
15697
|
+
var hasRequiredConfig;
|
|
15698
|
+
|
|
15699
|
+
function requireConfig () {
|
|
15700
|
+
if (hasRequiredConfig) return config;
|
|
15701
|
+
hasRequiredConfig = 1;
|
|
15702
|
+
(function () {
|
|
15703
|
+
requireMain().config(
|
|
15704
|
+
Object.assign(
|
|
15705
|
+
{},
|
|
15706
|
+
requireEnvOptions(),
|
|
15707
|
+
requireCliOptions()(process.argv)
|
|
15708
|
+
)
|
|
15709
|
+
);
|
|
15710
|
+
})();
|
|
15711
|
+
return config;
|
|
15712
|
+
}
|
|
15713
|
+
|
|
15714
|
+
requireConfig();
|
|
15715
|
+
|
|
15197
15716
|
const log = (message, options = { type: 'info' }) => {
|
|
15198
15717
|
log$1(message, { ...options, source: 'AlpacaMarketDataAPI' });
|
|
15199
15718
|
};
|