@uniformdev/redirect 19.15.0 → 19.19.0
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 +52 -2
- package/dist/index.esm.js +73 -39
- package/dist/index.js +240 -72
- package/dist/index.mjs +73 -39
- package/dist/main-DHQ5ANFI.mjs +287 -0
- package/package.json +3 -3
- package/dist/main-NHOL4NFR.mjs +0 -154
package/dist/index.d.ts
CHANGED
|
@@ -64,6 +64,31 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
|
64
64
|
constructor(options: RedirectClientOptions);
|
|
65
65
|
getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
|
|
66
66
|
getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
|
|
67
|
+
getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
|
|
68
|
+
redirect: {
|
|
69
|
+
id?: string | undefined;
|
|
70
|
+
sourceUrl: string;
|
|
71
|
+
targetUrl: string;
|
|
72
|
+
targetStatusCode: number;
|
|
73
|
+
sourceProjectMapNodeId?: string | undefined;
|
|
74
|
+
targetProjectMapNodeId?: string | undefined;
|
|
75
|
+
projectMapId?: string | undefined;
|
|
76
|
+
sourceRetainQuerystring?: boolean | undefined;
|
|
77
|
+
sourceMustMatchDomain?: boolean | undefined;
|
|
78
|
+
targetPreserveIncomingProtocol?: boolean | undefined;
|
|
79
|
+
targetPreserveIncomingDomain?: boolean | undefined;
|
|
80
|
+
stopExecutingAfter?: boolean | undefined;
|
|
81
|
+
targetMergeQuerystring?: boolean | undefined;
|
|
82
|
+
labelAsSystem?: boolean | undefined;
|
|
83
|
+
};
|
|
84
|
+
metadata: {
|
|
85
|
+
updatedAt?: string | undefined;
|
|
86
|
+
updatedBy?: string | undefined;
|
|
87
|
+
createdAt?: string | undefined;
|
|
88
|
+
createdBy?: string | undefined;
|
|
89
|
+
};
|
|
90
|
+
total: number | undefined;
|
|
91
|
+
}, void, unknown>;
|
|
67
92
|
getRedirectTrie: (options?: {
|
|
68
93
|
reverse?: boolean;
|
|
69
94
|
bypassDataCache?: boolean;
|
|
@@ -85,10 +110,10 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
|
85
110
|
* @param options - Different options available to the redirect engine
|
|
86
111
|
*/
|
|
87
112
|
private static processDefinitionToResults;
|
|
113
|
+
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
88
114
|
static getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string) => boolean): string;
|
|
89
115
|
private static mergeQueryStrings;
|
|
90
116
|
private static getSourceVariables;
|
|
91
|
-
private static processUrl;
|
|
92
117
|
}
|
|
93
118
|
declare class UncachedRedirectClient extends RedirectClient {
|
|
94
119
|
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
@@ -392,4 +417,29 @@ type RedirectFileConverterParams<T> = {
|
|
|
392
417
|
declare function ExtractWildcards(url: string): Wildcard[];
|
|
393
418
|
declare function RedirectFileConverter<T>({ client, redirectEntryObject, wildcardConverter, writeFile, }: RedirectFileConverterParams<T>): Promise<void>;
|
|
394
419
|
|
|
395
|
-
|
|
420
|
+
/**
|
|
421
|
+
* @typedef {Object} ProcessedUrl
|
|
422
|
+
* @property {string} url - The full url used during processing
|
|
423
|
+
* @property {string} path - The path portion of the URL
|
|
424
|
+
* @property {string} domain - The domain of the URL
|
|
425
|
+
* @property {string} port - The port of the URL
|
|
426
|
+
* @property {string} query - The querystring of the URL
|
|
427
|
+
* @property {string} fragment - The fragment of the URL
|
|
428
|
+
* @property {string} protocol - The protocol of the URL
|
|
429
|
+
*/
|
|
430
|
+
type ProcessedUrl = {
|
|
431
|
+
url: string;
|
|
432
|
+
path: string;
|
|
433
|
+
domain: string;
|
|
434
|
+
port: string;
|
|
435
|
+
query: string;
|
|
436
|
+
fragment: string;
|
|
437
|
+
protocol: string;
|
|
438
|
+
};
|
|
439
|
+
/**
|
|
440
|
+
* Breaks a url into the separate parts for processing
|
|
441
|
+
* @returns {ProcessedUrl} The url broken down into independent components
|
|
442
|
+
*/
|
|
443
|
+
declare function processUrl(url: string): ProcessedUrl;
|
|
444
|
+
|
|
445
|
+
export { ExtractWildcards, PathTrie, PathTrieData, ProcessedUrl, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn, processUrl };
|
package/dist/index.esm.js
CHANGED
|
@@ -197,6 +197,23 @@ var PathTrieData = class {
|
|
|
197
197
|
|
|
198
198
|
// src/redirectClient.ts
|
|
199
199
|
import { ApiClient } from "@uniformdev/context/api";
|
|
200
|
+
|
|
201
|
+
// src/util/url.ts
|
|
202
|
+
function processUrl(url) {
|
|
203
|
+
var _a, _b, _c, _d, _e, _f;
|
|
204
|
+
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
205
|
+
return {
|
|
206
|
+
url,
|
|
207
|
+
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
|
|
208
|
+
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
|
|
209
|
+
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
|
|
210
|
+
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
|
|
211
|
+
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
|
|
212
|
+
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/redirectClient.ts
|
|
200
217
|
var _RedirectClient = class extends ApiClient {
|
|
201
218
|
constructor(options) {
|
|
202
219
|
super(options);
|
|
@@ -223,8 +240,8 @@ var _RedirectClient = class extends ApiClient {
|
|
|
223
240
|
if (result)
|
|
224
241
|
return result;
|
|
225
242
|
}
|
|
226
|
-
const ret = this.assembleTrie(projectId
|
|
227
|
-
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId
|
|
243
|
+
const ret = this.assembleTrie(projectId);
|
|
244
|
+
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId));
|
|
228
245
|
return ret;
|
|
229
246
|
};
|
|
230
247
|
this.resetRedirectTrieDataCache = async () => {
|
|
@@ -302,25 +319,37 @@ var _RedirectClient = class extends ApiClient {
|
|
|
302
319
|
}
|
|
303
320
|
}
|
|
304
321
|
}
|
|
305
|
-
async
|
|
306
|
-
var _a;
|
|
307
|
-
const
|
|
308
|
-
let
|
|
309
|
-
let
|
|
310
|
-
|
|
322
|
+
async *getAllRedirects(orderBy = "updated_at desc") {
|
|
323
|
+
var _a, _b;
|
|
324
|
+
const { projectId } = this.options;
|
|
325
|
+
let requestCount = 0;
|
|
326
|
+
let results = void 0;
|
|
327
|
+
while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) {
|
|
311
328
|
const fetchUri = this.createUrl("/api/v1/redirect", {
|
|
312
|
-
projectId,
|
|
313
329
|
limit: 50,
|
|
314
|
-
offset
|
|
330
|
+
offset: requestCount * 50,
|
|
331
|
+
orderBy,
|
|
332
|
+
projectId
|
|
315
333
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
334
|
+
results = await this.apiClient(fetchUri);
|
|
335
|
+
const redirectCount = results.redirects.length;
|
|
336
|
+
for (let i = 0; i < redirectCount; i++) {
|
|
337
|
+
yield { total: results.total, ...results.redirects[i] };
|
|
338
|
+
}
|
|
339
|
+
requestCount++;
|
|
340
|
+
if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) {
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async assembleTrie(projectId, options) {
|
|
346
|
+
const trie = new PathTrie();
|
|
347
|
+
for await (const redirect of this.getAllRedirects()) {
|
|
348
|
+
const path = processUrl(
|
|
349
|
+
(options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
|
|
350
|
+
).path;
|
|
351
|
+
trie.insert(path, redirect);
|
|
352
|
+
}
|
|
324
353
|
return trie;
|
|
325
354
|
}
|
|
326
355
|
static processHops(url, trie, bestMatch, options) {
|
|
@@ -368,7 +397,7 @@ var _RedirectClient = class extends ApiClient {
|
|
|
368
397
|
return ret;
|
|
369
398
|
}
|
|
370
399
|
static processHop(url, trie, bestMatch, options) {
|
|
371
|
-
const processedUrl =
|
|
400
|
+
const processedUrl = processUrl(url);
|
|
372
401
|
let definition = trie.find(url, false);
|
|
373
402
|
if (!(definition == null ? void 0 : definition.length)) {
|
|
374
403
|
definition = trie.find(processedUrl.path + processedUrl.query, bestMatch);
|
|
@@ -377,7 +406,7 @@ var _RedirectClient = class extends ApiClient {
|
|
|
377
406
|
definition = trie.find(processedUrl.path, bestMatch);
|
|
378
407
|
}
|
|
379
408
|
if (definition == null ? void 0 : definition.length) {
|
|
380
|
-
return definition.map(
|
|
409
|
+
return definition.filter((def) => _RedirectClient.validateRedirect(url, def.data.redirect)).map(
|
|
381
410
|
(def) => this.processDefinitionToResults(processedUrl, def.data, def.variables, options)
|
|
382
411
|
).filter((r) => Boolean(r));
|
|
383
412
|
}
|
|
@@ -393,7 +422,7 @@ var _RedirectClient = class extends ApiClient {
|
|
|
393
422
|
static processDefinitionToResults(processedUrl, definition, variables, options) {
|
|
394
423
|
var _a, _b, _c, _d, _e;
|
|
395
424
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
396
|
-
const processedResult =
|
|
425
|
+
const processedResult = processUrl(resultUrl);
|
|
397
426
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
398
427
|
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
399
428
|
return void 0;
|
|
@@ -411,11 +440,28 @@ var _RedirectClient = class extends ApiClient {
|
|
|
411
440
|
}, finalUrl) : void 0
|
|
412
441
|
};
|
|
413
442
|
}
|
|
443
|
+
static validateRedirect(url, redirectDefinition) {
|
|
444
|
+
const processedSource = processUrl(redirectDefinition.sourceUrl);
|
|
445
|
+
const processedUrl = processUrl(url);
|
|
446
|
+
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
447
|
+
return false;
|
|
448
|
+
if (processedSource.query && !processedUrl.query)
|
|
449
|
+
return false;
|
|
450
|
+
if (processedSource.query && processedUrl.query) {
|
|
451
|
+
const sourceqs = new URLSearchParams(processedSource.query);
|
|
452
|
+
const urlqs = new URLSearchParams(processedUrl.query);
|
|
453
|
+
for (const [key] of sourceqs) {
|
|
454
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
414
460
|
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
|
|
415
|
-
const processedTarget =
|
|
416
|
-
const processedSource =
|
|
461
|
+
const processedTarget = processUrl(redirectDefinition.targetUrl);
|
|
462
|
+
const processedSource = processUrl(redirectDefinition.sourceUrl);
|
|
417
463
|
let finalUrlPath = processedTarget.path;
|
|
418
|
-
const processedUrl =
|
|
464
|
+
const processedUrl = processUrl(url);
|
|
419
465
|
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
|
|
420
466
|
for (const variable in variables) {
|
|
421
467
|
finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
|
|
@@ -458,19 +504,6 @@ var _RedirectClient = class extends ApiClient {
|
|
|
458
504
|
});
|
|
459
505
|
return variables;
|
|
460
506
|
}
|
|
461
|
-
static processUrl(url) {
|
|
462
|
-
var _a, _b, _c, _d, _e, _f;
|
|
463
|
-
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
464
|
-
return {
|
|
465
|
-
url,
|
|
466
|
-
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
|
|
467
|
-
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
|
|
468
|
-
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
|
|
469
|
-
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
|
|
470
|
-
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
|
|
471
|
-
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
507
|
};
|
|
475
508
|
var RedirectClient = _RedirectClient;
|
|
476
509
|
RedirectClient.processUrlBestMatch = async (url, trie, options) => {
|
|
@@ -485,7 +518,7 @@ var UncachedRedirectClient = class extends RedirectClient {
|
|
|
485
518
|
|
|
486
519
|
// src/util/RedirectFileConverter.ts
|
|
487
520
|
var getDefaultClient = async () => {
|
|
488
|
-
const dotenv = await import("./main-
|
|
521
|
+
const dotenv = await import("./main-DHQ5ANFI.mjs");
|
|
489
522
|
dotenv.config();
|
|
490
523
|
return new RedirectClient({
|
|
491
524
|
apiKey: process.env.UNIFORM_API_KEY,
|
|
@@ -562,5 +595,6 @@ export {
|
|
|
562
595
|
RedirectClient,
|
|
563
596
|
RedirectFileConverter,
|
|
564
597
|
UncachedRedirectClient,
|
|
565
|
-
WithMemoryCache
|
|
598
|
+
WithMemoryCache,
|
|
599
|
+
processUrl
|
|
566
600
|
};
|
package/dist/index.js
CHANGED
|
@@ -30,19 +30,19 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
30
30
|
));
|
|
31
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
32
32
|
|
|
33
|
-
// ../../node_modules/.pnpm/dotenv@16.
|
|
33
|
+
// ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json
|
|
34
34
|
var require_package = __commonJS({
|
|
35
|
-
"../../node_modules/.pnpm/dotenv@16.
|
|
35
|
+
"../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json"(exports, module2) {
|
|
36
36
|
module2.exports = {
|
|
37
37
|
name: "dotenv",
|
|
38
|
-
version: "16.
|
|
38
|
+
version: "16.1.3",
|
|
39
39
|
description: "Loads environment variables from .env file",
|
|
40
40
|
main: "lib/main.js",
|
|
41
41
|
types: "lib/main.d.ts",
|
|
42
42
|
exports: {
|
|
43
43
|
".": {
|
|
44
|
-
require: "./lib/main.js",
|
|
45
44
|
types: "./lib/main.d.ts",
|
|
45
|
+
require: "./lib/main.js",
|
|
46
46
|
default: "./lib/main.js"
|
|
47
47
|
},
|
|
48
48
|
"./config": "./config.js",
|
|
@@ -66,6 +66,7 @@ var require_package = __commonJS({
|
|
|
66
66
|
type: "git",
|
|
67
67
|
url: "git://github.com/motdotla/dotenv.git"
|
|
68
68
|
},
|
|
69
|
+
funding: "https://github.com/motdotla/dotenv?sponsor=1",
|
|
69
70
|
keywords: [
|
|
70
71
|
"dotenv",
|
|
71
72
|
"env",
|
|
@@ -78,30 +79,34 @@ var require_package = __commonJS({
|
|
|
78
79
|
readmeFilename: "README.md",
|
|
79
80
|
license: "BSD-2-Clause",
|
|
80
81
|
devDependencies: {
|
|
81
|
-
"@
|
|
82
|
+
"@definitelytyped/dtslint": "^0.0.133",
|
|
83
|
+
"@types/node": "^18.11.3",
|
|
82
84
|
decache: "^4.6.1",
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
standard: "^16.0.4",
|
|
85
|
+
sinon: "^14.0.1",
|
|
86
|
+
standard: "^17.0.0",
|
|
86
87
|
"standard-markdown": "^7.1.0",
|
|
87
|
-
"standard-version": "^9.
|
|
88
|
-
tap: "^
|
|
88
|
+
"standard-version": "^9.5.0",
|
|
89
|
+
tap: "^16.3.0",
|
|
89
90
|
tar: "^6.1.11",
|
|
90
|
-
typescript: "^4.
|
|
91
|
+
typescript: "^4.8.4"
|
|
91
92
|
},
|
|
92
93
|
engines: {
|
|
93
94
|
node: ">=12"
|
|
95
|
+
},
|
|
96
|
+
browser: {
|
|
97
|
+
fs: false
|
|
94
98
|
}
|
|
95
99
|
};
|
|
96
100
|
}
|
|
97
101
|
});
|
|
98
102
|
|
|
99
|
-
// ../../node_modules/.pnpm/dotenv@16.
|
|
103
|
+
// ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js
|
|
100
104
|
var require_main = __commonJS({
|
|
101
|
-
"../../node_modules/.pnpm/dotenv@16.
|
|
105
|
+
"../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js"(exports, module2) {
|
|
102
106
|
var fs = require("fs");
|
|
103
107
|
var path = require("path");
|
|
104
108
|
var os = require("os");
|
|
109
|
+
var crypto = require("crypto");
|
|
105
110
|
var packageJson = require_package();
|
|
106
111
|
var version = packageJson.version;
|
|
107
112
|
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
@@ -124,17 +129,89 @@ var require_main = __commonJS({
|
|
|
124
129
|
}
|
|
125
130
|
return obj;
|
|
126
131
|
}
|
|
132
|
+
function _parseVault(options) {
|
|
133
|
+
const vaultPath = _vaultPath(options);
|
|
134
|
+
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
135
|
+
if (!result.parsed) {
|
|
136
|
+
throw new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
137
|
+
}
|
|
138
|
+
const keys = _dotenvKey().split(",");
|
|
139
|
+
const length = keys.length;
|
|
140
|
+
let decrypted;
|
|
141
|
+
for (let i = 0; i < length; i++) {
|
|
142
|
+
try {
|
|
143
|
+
const key = keys[i].trim();
|
|
144
|
+
const attrs = _instructions(result, key);
|
|
145
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
146
|
+
break;
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (i + 1 >= length) {
|
|
149
|
+
throw error;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return DotenvModule.parse(decrypted);
|
|
154
|
+
}
|
|
127
155
|
function _log(message) {
|
|
156
|
+
console.log(`[dotenv@${version}][INFO] ${message}`);
|
|
157
|
+
}
|
|
158
|
+
function _warn(message) {
|
|
159
|
+
console.log(`[dotenv@${version}][WARN] ${message}`);
|
|
160
|
+
}
|
|
161
|
+
function _debug(message) {
|
|
128
162
|
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
129
163
|
}
|
|
164
|
+
function _dotenvKey() {
|
|
165
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
166
|
+
return process.env.DOTENV_KEY;
|
|
167
|
+
}
|
|
168
|
+
return "";
|
|
169
|
+
}
|
|
170
|
+
function _instructions(result, dotenvKey) {
|
|
171
|
+
let uri;
|
|
172
|
+
try {
|
|
173
|
+
uri = new URL(dotenvKey);
|
|
174
|
+
} catch (error) {
|
|
175
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
176
|
+
throw new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development");
|
|
177
|
+
}
|
|
178
|
+
throw error;
|
|
179
|
+
}
|
|
180
|
+
const key = uri.password;
|
|
181
|
+
if (!key) {
|
|
182
|
+
throw new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
183
|
+
}
|
|
184
|
+
const environment = uri.searchParams.get("environment");
|
|
185
|
+
if (!environment) {
|
|
186
|
+
throw new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
187
|
+
}
|
|
188
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
189
|
+
const ciphertext = result.parsed[environmentKey];
|
|
190
|
+
if (!ciphertext) {
|
|
191
|
+
throw new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
192
|
+
}
|
|
193
|
+
return { ciphertext, key };
|
|
194
|
+
}
|
|
195
|
+
function _vaultPath(options) {
|
|
196
|
+
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
197
|
+
if (options && options.path && options.path.length > 0) {
|
|
198
|
+
dotenvPath = options.path;
|
|
199
|
+
}
|
|
200
|
+
return dotenvPath.endsWith(".vault") ? dotenvPath : `${dotenvPath}.vault`;
|
|
201
|
+
}
|
|
130
202
|
function _resolveHome(envPath) {
|
|
131
203
|
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
132
204
|
}
|
|
133
|
-
function
|
|
205
|
+
function _configVault(options) {
|
|
206
|
+
_log("Loading env from encrypted .env.vault");
|
|
207
|
+
const parsed = DotenvModule._parseVault(options);
|
|
208
|
+
DotenvModule.populate(process.env, parsed, options);
|
|
209
|
+
return { parsed };
|
|
210
|
+
}
|
|
211
|
+
function configDotenv(options) {
|
|
134
212
|
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
135
213
|
let encoding = "utf8";
|
|
136
214
|
const debug = Boolean(options && options.debug);
|
|
137
|
-
const override = Boolean(options && options.override);
|
|
138
215
|
if (options) {
|
|
139
216
|
if (options.path != null) {
|
|
140
217
|
dotenvPath = _resolveHome(options.path);
|
|
@@ -145,36 +222,92 @@ var require_main = __commonJS({
|
|
|
145
222
|
}
|
|
146
223
|
try {
|
|
147
224
|
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
|
|
148
|
-
|
|
149
|
-
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
|
150
|
-
process.env[key] = parsed[key];
|
|
151
|
-
} else {
|
|
152
|
-
if (override === true) {
|
|
153
|
-
process.env[key] = parsed[key];
|
|
154
|
-
}
|
|
155
|
-
if (debug) {
|
|
156
|
-
if (override === true) {
|
|
157
|
-
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
|
|
158
|
-
} else {
|
|
159
|
-
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
});
|
|
225
|
+
DotenvModule.populate(process.env, parsed, options);
|
|
164
226
|
return { parsed };
|
|
165
227
|
} catch (e) {
|
|
166
228
|
if (debug) {
|
|
167
|
-
|
|
229
|
+
_debug(`Failed to load ${dotenvPath} ${e.message}`);
|
|
168
230
|
}
|
|
169
231
|
return { error: e };
|
|
170
232
|
}
|
|
171
233
|
}
|
|
234
|
+
function config(options) {
|
|
235
|
+
const vaultPath = _vaultPath(options);
|
|
236
|
+
if (_dotenvKey().length === 0) {
|
|
237
|
+
return DotenvModule.configDotenv(options);
|
|
238
|
+
}
|
|
239
|
+
if (!fs.existsSync(vaultPath)) {
|
|
240
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
241
|
+
return DotenvModule.configDotenv(options);
|
|
242
|
+
}
|
|
243
|
+
return DotenvModule._configVault(options);
|
|
244
|
+
}
|
|
245
|
+
function decrypt(encrypted, keyStr) {
|
|
246
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
247
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
248
|
+
const nonce = ciphertext.slice(0, 12);
|
|
249
|
+
const authTag = ciphertext.slice(-16);
|
|
250
|
+
ciphertext = ciphertext.slice(12, -16);
|
|
251
|
+
try {
|
|
252
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
253
|
+
aesgcm.setAuthTag(authTag);
|
|
254
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
255
|
+
} catch (error) {
|
|
256
|
+
const isRange = error instanceof RangeError;
|
|
257
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
258
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
259
|
+
if (isRange || invalidKeyLength) {
|
|
260
|
+
const msg = "INVALID_DOTENV_KEY: It must be 64 characters long (or more)";
|
|
261
|
+
throw new Error(msg);
|
|
262
|
+
} else if (decryptionFailed) {
|
|
263
|
+
const msg = "DECRYPTION_FAILED: Please check your DOTENV_KEY";
|
|
264
|
+
throw new Error(msg);
|
|
265
|
+
} else {
|
|
266
|
+
console.error("Error: ", error.code);
|
|
267
|
+
console.error("Error: ", error.message);
|
|
268
|
+
throw error;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
function populate(processEnv, parsed, options = {}) {
|
|
273
|
+
const debug = Boolean(options && options.debug);
|
|
274
|
+
const override = Boolean(options && options.override);
|
|
275
|
+
if (typeof parsed !== "object") {
|
|
276
|
+
throw new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
277
|
+
}
|
|
278
|
+
for (const key of Object.keys(parsed)) {
|
|
279
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
280
|
+
if (override === true) {
|
|
281
|
+
processEnv[key] = parsed[key];
|
|
282
|
+
}
|
|
283
|
+
if (debug) {
|
|
284
|
+
if (override === true) {
|
|
285
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
286
|
+
} else {
|
|
287
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
} else {
|
|
291
|
+
processEnv[key] = parsed[key];
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
172
295
|
var DotenvModule = {
|
|
296
|
+
configDotenv,
|
|
297
|
+
_configVault,
|
|
298
|
+
_parseVault,
|
|
173
299
|
config,
|
|
174
|
-
|
|
300
|
+
decrypt,
|
|
301
|
+
parse,
|
|
302
|
+
populate
|
|
175
303
|
};
|
|
304
|
+
module2.exports.configDotenv = DotenvModule.configDotenv;
|
|
305
|
+
module2.exports._configVault = DotenvModule._configVault;
|
|
306
|
+
module2.exports._parseVault = DotenvModule._parseVault;
|
|
176
307
|
module2.exports.config = DotenvModule.config;
|
|
308
|
+
module2.exports.decrypt = DotenvModule.decrypt;
|
|
177
309
|
module2.exports.parse = DotenvModule.parse;
|
|
310
|
+
module2.exports.populate = DotenvModule.populate;
|
|
178
311
|
module2.exports = DotenvModule;
|
|
179
312
|
}
|
|
180
313
|
});
|
|
@@ -188,7 +321,8 @@ __export(src_exports, {
|
|
|
188
321
|
RedirectClient: () => RedirectClient,
|
|
189
322
|
RedirectFileConverter: () => RedirectFileConverter,
|
|
190
323
|
UncachedRedirectClient: () => UncachedRedirectClient,
|
|
191
|
-
WithMemoryCache: () => WithMemoryCache
|
|
324
|
+
WithMemoryCache: () => WithMemoryCache,
|
|
325
|
+
processUrl: () => processUrl
|
|
192
326
|
});
|
|
193
327
|
module.exports = __toCommonJS(src_exports);
|
|
194
328
|
|
|
@@ -389,6 +523,23 @@ var PathTrieData = class {
|
|
|
389
523
|
|
|
390
524
|
// src/redirectClient.ts
|
|
391
525
|
var import_api = require("@uniformdev/context/api");
|
|
526
|
+
|
|
527
|
+
// src/util/url.ts
|
|
528
|
+
function processUrl(url) {
|
|
529
|
+
var _a, _b, _c, _d, _e, _f;
|
|
530
|
+
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
531
|
+
return {
|
|
532
|
+
url,
|
|
533
|
+
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
|
|
534
|
+
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
|
|
535
|
+
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
|
|
536
|
+
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
|
|
537
|
+
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
|
|
538
|
+
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
|
|
539
|
+
};
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
// src/redirectClient.ts
|
|
392
543
|
var _RedirectClient = class extends import_api.ApiClient {
|
|
393
544
|
constructor(options) {
|
|
394
545
|
super(options);
|
|
@@ -415,8 +566,8 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
415
566
|
if (result)
|
|
416
567
|
return result;
|
|
417
568
|
}
|
|
418
|
-
const ret = this.assembleTrie(projectId
|
|
419
|
-
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId
|
|
569
|
+
const ret = this.assembleTrie(projectId);
|
|
570
|
+
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId));
|
|
420
571
|
return ret;
|
|
421
572
|
};
|
|
422
573
|
this.resetRedirectTrieDataCache = async () => {
|
|
@@ -494,25 +645,37 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
494
645
|
}
|
|
495
646
|
}
|
|
496
647
|
}
|
|
497
|
-
async
|
|
498
|
-
var _a;
|
|
499
|
-
const
|
|
500
|
-
let
|
|
501
|
-
let
|
|
502
|
-
|
|
648
|
+
async *getAllRedirects(orderBy = "updated_at desc") {
|
|
649
|
+
var _a, _b;
|
|
650
|
+
const { projectId } = this.options;
|
|
651
|
+
let requestCount = 0;
|
|
652
|
+
let results = void 0;
|
|
653
|
+
while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) {
|
|
503
654
|
const fetchUri = this.createUrl("/api/v1/redirect", {
|
|
504
|
-
projectId,
|
|
505
655
|
limit: 50,
|
|
506
|
-
offset
|
|
656
|
+
offset: requestCount * 50,
|
|
657
|
+
orderBy,
|
|
658
|
+
projectId
|
|
507
659
|
});
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
660
|
+
results = await this.apiClient(fetchUri);
|
|
661
|
+
const redirectCount = results.redirects.length;
|
|
662
|
+
for (let i = 0; i < redirectCount; i++) {
|
|
663
|
+
yield { total: results.total, ...results.redirects[i] };
|
|
664
|
+
}
|
|
665
|
+
requestCount++;
|
|
666
|
+
if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) {
|
|
667
|
+
break;
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
async assembleTrie(projectId, options) {
|
|
672
|
+
const trie = new PathTrie();
|
|
673
|
+
for await (const redirect of this.getAllRedirects()) {
|
|
674
|
+
const path = processUrl(
|
|
675
|
+
(options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
|
|
676
|
+
).path;
|
|
677
|
+
trie.insert(path, redirect);
|
|
678
|
+
}
|
|
516
679
|
return trie;
|
|
517
680
|
}
|
|
518
681
|
static processHops(url, trie, bestMatch, options) {
|
|
@@ -560,7 +723,7 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
560
723
|
return ret;
|
|
561
724
|
}
|
|
562
725
|
static processHop(url, trie, bestMatch, options) {
|
|
563
|
-
const processedUrl =
|
|
726
|
+
const processedUrl = processUrl(url);
|
|
564
727
|
let definition = trie.find(url, false);
|
|
565
728
|
if (!(definition == null ? void 0 : definition.length)) {
|
|
566
729
|
definition = trie.find(processedUrl.path + processedUrl.query, bestMatch);
|
|
@@ -569,7 +732,7 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
569
732
|
definition = trie.find(processedUrl.path, bestMatch);
|
|
570
733
|
}
|
|
571
734
|
if (definition == null ? void 0 : definition.length) {
|
|
572
|
-
return definition.map(
|
|
735
|
+
return definition.filter((def) => _RedirectClient.validateRedirect(url, def.data.redirect)).map(
|
|
573
736
|
(def) => this.processDefinitionToResults(processedUrl, def.data, def.variables, options)
|
|
574
737
|
).filter((r) => Boolean(r));
|
|
575
738
|
}
|
|
@@ -585,7 +748,7 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
585
748
|
static processDefinitionToResults(processedUrl, definition, variables, options) {
|
|
586
749
|
var _a, _b, _c, _d, _e;
|
|
587
750
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
588
|
-
const processedResult =
|
|
751
|
+
const processedResult = processUrl(resultUrl);
|
|
589
752
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
590
753
|
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
591
754
|
return void 0;
|
|
@@ -603,11 +766,28 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
603
766
|
}, finalUrl) : void 0
|
|
604
767
|
};
|
|
605
768
|
}
|
|
769
|
+
static validateRedirect(url, redirectDefinition) {
|
|
770
|
+
const processedSource = processUrl(redirectDefinition.sourceUrl);
|
|
771
|
+
const processedUrl = processUrl(url);
|
|
772
|
+
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
773
|
+
return false;
|
|
774
|
+
if (processedSource.query && !processedUrl.query)
|
|
775
|
+
return false;
|
|
776
|
+
if (processedSource.query && processedUrl.query) {
|
|
777
|
+
const sourceqs = new URLSearchParams(processedSource.query);
|
|
778
|
+
const urlqs = new URLSearchParams(processedUrl.query);
|
|
779
|
+
for (const [key] of sourceqs) {
|
|
780
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
781
|
+
return false;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
return true;
|
|
785
|
+
}
|
|
606
786
|
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
|
|
607
|
-
const processedTarget =
|
|
608
|
-
const processedSource =
|
|
787
|
+
const processedTarget = processUrl(redirectDefinition.targetUrl);
|
|
788
|
+
const processedSource = processUrl(redirectDefinition.sourceUrl);
|
|
609
789
|
let finalUrlPath = processedTarget.path;
|
|
610
|
-
const processedUrl =
|
|
790
|
+
const processedUrl = processUrl(url);
|
|
611
791
|
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
|
|
612
792
|
for (const variable in variables) {
|
|
613
793
|
finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
|
|
@@ -650,19 +830,6 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
650
830
|
});
|
|
651
831
|
return variables;
|
|
652
832
|
}
|
|
653
|
-
static processUrl(url) {
|
|
654
|
-
var _a, _b, _c, _d, _e, _f;
|
|
655
|
-
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
656
|
-
return {
|
|
657
|
-
url,
|
|
658
|
-
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
|
|
659
|
-
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
|
|
660
|
-
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
|
|
661
|
-
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
|
|
662
|
-
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
|
|
663
|
-
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
833
|
};
|
|
667
834
|
var RedirectClient = _RedirectClient;
|
|
668
835
|
RedirectClient.processUrlBestMatch = async (url, trie, options) => {
|
|
@@ -755,5 +922,6 @@ async function RedirectFileConverter({
|
|
|
755
922
|
RedirectClient,
|
|
756
923
|
RedirectFileConverter,
|
|
757
924
|
UncachedRedirectClient,
|
|
758
|
-
WithMemoryCache
|
|
925
|
+
WithMemoryCache,
|
|
926
|
+
processUrl
|
|
759
927
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -197,6 +197,23 @@ var PathTrieData = class {
|
|
|
197
197
|
|
|
198
198
|
// src/redirectClient.ts
|
|
199
199
|
import { ApiClient } from "@uniformdev/context/api";
|
|
200
|
+
|
|
201
|
+
// src/util/url.ts
|
|
202
|
+
function processUrl(url) {
|
|
203
|
+
var _a, _b, _c, _d, _e, _f;
|
|
204
|
+
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
205
|
+
return {
|
|
206
|
+
url,
|
|
207
|
+
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
|
|
208
|
+
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
|
|
209
|
+
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
|
|
210
|
+
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
|
|
211
|
+
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
|
|
212
|
+
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// src/redirectClient.ts
|
|
200
217
|
var _RedirectClient = class extends ApiClient {
|
|
201
218
|
constructor(options) {
|
|
202
219
|
super(options);
|
|
@@ -223,8 +240,8 @@ var _RedirectClient = class extends ApiClient {
|
|
|
223
240
|
if (result)
|
|
224
241
|
return result;
|
|
225
242
|
}
|
|
226
|
-
const ret = this.assembleTrie(projectId
|
|
227
|
-
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId
|
|
243
|
+
const ret = this.assembleTrie(projectId);
|
|
244
|
+
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId));
|
|
228
245
|
return ret;
|
|
229
246
|
};
|
|
230
247
|
this.resetRedirectTrieDataCache = async () => {
|
|
@@ -302,25 +319,37 @@ var _RedirectClient = class extends ApiClient {
|
|
|
302
319
|
}
|
|
303
320
|
}
|
|
304
321
|
}
|
|
305
|
-
async
|
|
306
|
-
var _a;
|
|
307
|
-
const
|
|
308
|
-
let
|
|
309
|
-
let
|
|
310
|
-
|
|
322
|
+
async *getAllRedirects(orderBy = "updated_at desc") {
|
|
323
|
+
var _a, _b;
|
|
324
|
+
const { projectId } = this.options;
|
|
325
|
+
let requestCount = 0;
|
|
326
|
+
let results = void 0;
|
|
327
|
+
while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) {
|
|
311
328
|
const fetchUri = this.createUrl("/api/v1/redirect", {
|
|
312
|
-
projectId,
|
|
313
329
|
limit: 50,
|
|
314
|
-
offset
|
|
330
|
+
offset: requestCount * 50,
|
|
331
|
+
orderBy,
|
|
332
|
+
projectId
|
|
315
333
|
});
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
334
|
+
results = await this.apiClient(fetchUri);
|
|
335
|
+
const redirectCount = results.redirects.length;
|
|
336
|
+
for (let i = 0; i < redirectCount; i++) {
|
|
337
|
+
yield { total: results.total, ...results.redirects[i] };
|
|
338
|
+
}
|
|
339
|
+
requestCount++;
|
|
340
|
+
if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) {
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
async assembleTrie(projectId, options) {
|
|
346
|
+
const trie = new PathTrie();
|
|
347
|
+
for await (const redirect of this.getAllRedirects()) {
|
|
348
|
+
const path = processUrl(
|
|
349
|
+
(options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
|
|
350
|
+
).path;
|
|
351
|
+
trie.insert(path, redirect);
|
|
352
|
+
}
|
|
324
353
|
return trie;
|
|
325
354
|
}
|
|
326
355
|
static processHops(url, trie, bestMatch, options) {
|
|
@@ -368,7 +397,7 @@ var _RedirectClient = class extends ApiClient {
|
|
|
368
397
|
return ret;
|
|
369
398
|
}
|
|
370
399
|
static processHop(url, trie, bestMatch, options) {
|
|
371
|
-
const processedUrl =
|
|
400
|
+
const processedUrl = processUrl(url);
|
|
372
401
|
let definition = trie.find(url, false);
|
|
373
402
|
if (!(definition == null ? void 0 : definition.length)) {
|
|
374
403
|
definition = trie.find(processedUrl.path + processedUrl.query, bestMatch);
|
|
@@ -377,7 +406,7 @@ var _RedirectClient = class extends ApiClient {
|
|
|
377
406
|
definition = trie.find(processedUrl.path, bestMatch);
|
|
378
407
|
}
|
|
379
408
|
if (definition == null ? void 0 : definition.length) {
|
|
380
|
-
return definition.map(
|
|
409
|
+
return definition.filter((def) => _RedirectClient.validateRedirect(url, def.data.redirect)).map(
|
|
381
410
|
(def) => this.processDefinitionToResults(processedUrl, def.data, def.variables, options)
|
|
382
411
|
).filter((r) => Boolean(r));
|
|
383
412
|
}
|
|
@@ -393,7 +422,7 @@ var _RedirectClient = class extends ApiClient {
|
|
|
393
422
|
static processDefinitionToResults(processedUrl, definition, variables, options) {
|
|
394
423
|
var _a, _b, _c, _d, _e;
|
|
395
424
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
396
|
-
const processedResult =
|
|
425
|
+
const processedResult = processUrl(resultUrl);
|
|
397
426
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
398
427
|
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
399
428
|
return void 0;
|
|
@@ -411,11 +440,28 @@ var _RedirectClient = class extends ApiClient {
|
|
|
411
440
|
}, finalUrl) : void 0
|
|
412
441
|
};
|
|
413
442
|
}
|
|
443
|
+
static validateRedirect(url, redirectDefinition) {
|
|
444
|
+
const processedSource = processUrl(redirectDefinition.sourceUrl);
|
|
445
|
+
const processedUrl = processUrl(url);
|
|
446
|
+
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
447
|
+
return false;
|
|
448
|
+
if (processedSource.query && !processedUrl.query)
|
|
449
|
+
return false;
|
|
450
|
+
if (processedSource.query && processedUrl.query) {
|
|
451
|
+
const sourceqs = new URLSearchParams(processedSource.query);
|
|
452
|
+
const urlqs = new URLSearchParams(processedUrl.query);
|
|
453
|
+
for (const [key] of sourceqs) {
|
|
454
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
455
|
+
return false;
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
return true;
|
|
459
|
+
}
|
|
414
460
|
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
|
|
415
|
-
const processedTarget =
|
|
416
|
-
const processedSource =
|
|
461
|
+
const processedTarget = processUrl(redirectDefinition.targetUrl);
|
|
462
|
+
const processedSource = processUrl(redirectDefinition.sourceUrl);
|
|
417
463
|
let finalUrlPath = processedTarget.path;
|
|
418
|
-
const processedUrl =
|
|
464
|
+
const processedUrl = processUrl(url);
|
|
419
465
|
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
|
|
420
466
|
for (const variable in variables) {
|
|
421
467
|
finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
|
|
@@ -458,19 +504,6 @@ var _RedirectClient = class extends ApiClient {
|
|
|
458
504
|
});
|
|
459
505
|
return variables;
|
|
460
506
|
}
|
|
461
|
-
static processUrl(url) {
|
|
462
|
-
var _a, _b, _c, _d, _e, _f;
|
|
463
|
-
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
|
|
464
|
-
return {
|
|
465
|
-
url,
|
|
466
|
-
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
|
|
467
|
-
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
|
|
468
|
-
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
|
|
469
|
-
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
|
|
470
|
-
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
|
|
471
|
-
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
|
|
472
|
-
};
|
|
473
|
-
}
|
|
474
507
|
};
|
|
475
508
|
var RedirectClient = _RedirectClient;
|
|
476
509
|
RedirectClient.processUrlBestMatch = async (url, trie, options) => {
|
|
@@ -485,7 +518,7 @@ var UncachedRedirectClient = class extends RedirectClient {
|
|
|
485
518
|
|
|
486
519
|
// src/util/RedirectFileConverter.ts
|
|
487
520
|
var getDefaultClient = async () => {
|
|
488
|
-
const dotenv = await import("./main-
|
|
521
|
+
const dotenv = await import("./main-DHQ5ANFI.mjs");
|
|
489
522
|
dotenv.config();
|
|
490
523
|
return new RedirectClient({
|
|
491
524
|
apiKey: process.env.UNIFORM_API_KEY,
|
|
@@ -562,5 +595,6 @@ export {
|
|
|
562
595
|
RedirectClient,
|
|
563
596
|
RedirectFileConverter,
|
|
564
597
|
UncachedRedirectClient,
|
|
565
|
-
WithMemoryCache
|
|
598
|
+
WithMemoryCache,
|
|
599
|
+
processUrl
|
|
566
600
|
};
|
|
@@ -0,0 +1,287 @@
|
|
|
1
|
+
import {
|
|
2
|
+
__commonJS,
|
|
3
|
+
__require
|
|
4
|
+
} from "./chunk-FFYIGW52.mjs";
|
|
5
|
+
|
|
6
|
+
// ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json
|
|
7
|
+
var require_package = __commonJS({
|
|
8
|
+
"../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json"(exports, module) {
|
|
9
|
+
module.exports = {
|
|
10
|
+
name: "dotenv",
|
|
11
|
+
version: "16.1.3",
|
|
12
|
+
description: "Loads environment variables from .env file",
|
|
13
|
+
main: "lib/main.js",
|
|
14
|
+
types: "lib/main.d.ts",
|
|
15
|
+
exports: {
|
|
16
|
+
".": {
|
|
17
|
+
types: "./lib/main.d.ts",
|
|
18
|
+
require: "./lib/main.js",
|
|
19
|
+
default: "./lib/main.js"
|
|
20
|
+
},
|
|
21
|
+
"./config": "./config.js",
|
|
22
|
+
"./config.js": "./config.js",
|
|
23
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
24
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
25
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
26
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
27
|
+
"./package.json": "./package.json"
|
|
28
|
+
},
|
|
29
|
+
scripts: {
|
|
30
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
31
|
+
lint: "standard",
|
|
32
|
+
"lint-readme": "standard-markdown",
|
|
33
|
+
pretest: "npm run lint && npm run dts-check",
|
|
34
|
+
test: "tap tests/*.js --100 -Rspec",
|
|
35
|
+
prerelease: "npm test",
|
|
36
|
+
release: "standard-version"
|
|
37
|
+
},
|
|
38
|
+
repository: {
|
|
39
|
+
type: "git",
|
|
40
|
+
url: "git://github.com/motdotla/dotenv.git"
|
|
41
|
+
},
|
|
42
|
+
funding: "https://github.com/motdotla/dotenv?sponsor=1",
|
|
43
|
+
keywords: [
|
|
44
|
+
"dotenv",
|
|
45
|
+
"env",
|
|
46
|
+
".env",
|
|
47
|
+
"environment",
|
|
48
|
+
"variables",
|
|
49
|
+
"config",
|
|
50
|
+
"settings"
|
|
51
|
+
],
|
|
52
|
+
readmeFilename: "README.md",
|
|
53
|
+
license: "BSD-2-Clause",
|
|
54
|
+
devDependencies: {
|
|
55
|
+
"@definitelytyped/dtslint": "^0.0.133",
|
|
56
|
+
"@types/node": "^18.11.3",
|
|
57
|
+
decache: "^4.6.1",
|
|
58
|
+
sinon: "^14.0.1",
|
|
59
|
+
standard: "^17.0.0",
|
|
60
|
+
"standard-markdown": "^7.1.0",
|
|
61
|
+
"standard-version": "^9.5.0",
|
|
62
|
+
tap: "^16.3.0",
|
|
63
|
+
tar: "^6.1.11",
|
|
64
|
+
typescript: "^4.8.4"
|
|
65
|
+
},
|
|
66
|
+
engines: {
|
|
67
|
+
node: ">=12"
|
|
68
|
+
},
|
|
69
|
+
browser: {
|
|
70
|
+
fs: false
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
// ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js
|
|
77
|
+
var require_main = __commonJS({
|
|
78
|
+
"../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js"(exports, module) {
|
|
79
|
+
var fs = __require("fs");
|
|
80
|
+
var path = __require("path");
|
|
81
|
+
var os = __require("os");
|
|
82
|
+
var crypto = __require("crypto");
|
|
83
|
+
var packageJson = require_package();
|
|
84
|
+
var version = packageJson.version;
|
|
85
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
86
|
+
function parse(src) {
|
|
87
|
+
const obj = {};
|
|
88
|
+
let lines = src.toString();
|
|
89
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
90
|
+
let match;
|
|
91
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
92
|
+
const key = match[1];
|
|
93
|
+
let value = match[2] || "";
|
|
94
|
+
value = value.trim();
|
|
95
|
+
const maybeQuote = value[0];
|
|
96
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
97
|
+
if (maybeQuote === '"') {
|
|
98
|
+
value = value.replace(/\\n/g, "\n");
|
|
99
|
+
value = value.replace(/\\r/g, "\r");
|
|
100
|
+
}
|
|
101
|
+
obj[key] = value;
|
|
102
|
+
}
|
|
103
|
+
return obj;
|
|
104
|
+
}
|
|
105
|
+
function _parseVault(options) {
|
|
106
|
+
const vaultPath = _vaultPath(options);
|
|
107
|
+
const result = DotenvModule.configDotenv({ path: vaultPath });
|
|
108
|
+
if (!result.parsed) {
|
|
109
|
+
throw new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
|
|
110
|
+
}
|
|
111
|
+
const keys = _dotenvKey().split(",");
|
|
112
|
+
const length = keys.length;
|
|
113
|
+
let decrypted;
|
|
114
|
+
for (let i = 0; i < length; i++) {
|
|
115
|
+
try {
|
|
116
|
+
const key = keys[i].trim();
|
|
117
|
+
const attrs = _instructions(result, key);
|
|
118
|
+
decrypted = DotenvModule.decrypt(attrs.ciphertext, attrs.key);
|
|
119
|
+
break;
|
|
120
|
+
} catch (error) {
|
|
121
|
+
if (i + 1 >= length) {
|
|
122
|
+
throw error;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return DotenvModule.parse(decrypted);
|
|
127
|
+
}
|
|
128
|
+
function _log(message) {
|
|
129
|
+
console.log(`[dotenv@${version}][INFO] ${message}`);
|
|
130
|
+
}
|
|
131
|
+
function _warn(message) {
|
|
132
|
+
console.log(`[dotenv@${version}][WARN] ${message}`);
|
|
133
|
+
}
|
|
134
|
+
function _debug(message) {
|
|
135
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
136
|
+
}
|
|
137
|
+
function _dotenvKey() {
|
|
138
|
+
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
|
|
139
|
+
return process.env.DOTENV_KEY;
|
|
140
|
+
}
|
|
141
|
+
return "";
|
|
142
|
+
}
|
|
143
|
+
function _instructions(result, dotenvKey) {
|
|
144
|
+
let uri;
|
|
145
|
+
try {
|
|
146
|
+
uri = new URL(dotenvKey);
|
|
147
|
+
} catch (error) {
|
|
148
|
+
if (error.code === "ERR_INVALID_URL") {
|
|
149
|
+
throw new Error("INVALID_DOTENV_KEY: Wrong format. Must be in valid uri format like dotenv://:key_1234@dotenv.org/vault/.env.vault?environment=development");
|
|
150
|
+
}
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
const key = uri.password;
|
|
154
|
+
if (!key) {
|
|
155
|
+
throw new Error("INVALID_DOTENV_KEY: Missing key part");
|
|
156
|
+
}
|
|
157
|
+
const environment = uri.searchParams.get("environment");
|
|
158
|
+
if (!environment) {
|
|
159
|
+
throw new Error("INVALID_DOTENV_KEY: Missing environment part");
|
|
160
|
+
}
|
|
161
|
+
const environmentKey = `DOTENV_VAULT_${environment.toUpperCase()}`;
|
|
162
|
+
const ciphertext = result.parsed[environmentKey];
|
|
163
|
+
if (!ciphertext) {
|
|
164
|
+
throw new Error(`NOT_FOUND_DOTENV_ENVIRONMENT: Cannot locate environment ${environmentKey} in your .env.vault file.`);
|
|
165
|
+
}
|
|
166
|
+
return { ciphertext, key };
|
|
167
|
+
}
|
|
168
|
+
function _vaultPath(options) {
|
|
169
|
+
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
170
|
+
if (options && options.path && options.path.length > 0) {
|
|
171
|
+
dotenvPath = options.path;
|
|
172
|
+
}
|
|
173
|
+
return dotenvPath.endsWith(".vault") ? dotenvPath : `${dotenvPath}.vault`;
|
|
174
|
+
}
|
|
175
|
+
function _resolveHome(envPath) {
|
|
176
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
177
|
+
}
|
|
178
|
+
function _configVault(options) {
|
|
179
|
+
_log("Loading env from encrypted .env.vault");
|
|
180
|
+
const parsed = DotenvModule._parseVault(options);
|
|
181
|
+
DotenvModule.populate(process.env, parsed, options);
|
|
182
|
+
return { parsed };
|
|
183
|
+
}
|
|
184
|
+
function configDotenv(options) {
|
|
185
|
+
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
186
|
+
let encoding = "utf8";
|
|
187
|
+
const debug = Boolean(options && options.debug);
|
|
188
|
+
if (options) {
|
|
189
|
+
if (options.path != null) {
|
|
190
|
+
dotenvPath = _resolveHome(options.path);
|
|
191
|
+
}
|
|
192
|
+
if (options.encoding != null) {
|
|
193
|
+
encoding = options.encoding;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
try {
|
|
197
|
+
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
|
|
198
|
+
DotenvModule.populate(process.env, parsed, options);
|
|
199
|
+
return { parsed };
|
|
200
|
+
} catch (e) {
|
|
201
|
+
if (debug) {
|
|
202
|
+
_debug(`Failed to load ${dotenvPath} ${e.message}`);
|
|
203
|
+
}
|
|
204
|
+
return { error: e };
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
function config(options) {
|
|
208
|
+
const vaultPath = _vaultPath(options);
|
|
209
|
+
if (_dotenvKey().length === 0) {
|
|
210
|
+
return DotenvModule.configDotenv(options);
|
|
211
|
+
}
|
|
212
|
+
if (!fs.existsSync(vaultPath)) {
|
|
213
|
+
_warn(`You set DOTENV_KEY but you are missing a .env.vault file at ${vaultPath}. Did you forget to build it?`);
|
|
214
|
+
return DotenvModule.configDotenv(options);
|
|
215
|
+
}
|
|
216
|
+
return DotenvModule._configVault(options);
|
|
217
|
+
}
|
|
218
|
+
function decrypt(encrypted, keyStr) {
|
|
219
|
+
const key = Buffer.from(keyStr.slice(-64), "hex");
|
|
220
|
+
let ciphertext = Buffer.from(encrypted, "base64");
|
|
221
|
+
const nonce = ciphertext.slice(0, 12);
|
|
222
|
+
const authTag = ciphertext.slice(-16);
|
|
223
|
+
ciphertext = ciphertext.slice(12, -16);
|
|
224
|
+
try {
|
|
225
|
+
const aesgcm = crypto.createDecipheriv("aes-256-gcm", key, nonce);
|
|
226
|
+
aesgcm.setAuthTag(authTag);
|
|
227
|
+
return `${aesgcm.update(ciphertext)}${aesgcm.final()}`;
|
|
228
|
+
} catch (error) {
|
|
229
|
+
const isRange = error instanceof RangeError;
|
|
230
|
+
const invalidKeyLength = error.message === "Invalid key length";
|
|
231
|
+
const decryptionFailed = error.message === "Unsupported state or unable to authenticate data";
|
|
232
|
+
if (isRange || invalidKeyLength) {
|
|
233
|
+
const msg = "INVALID_DOTENV_KEY: It must be 64 characters long (or more)";
|
|
234
|
+
throw new Error(msg);
|
|
235
|
+
} else if (decryptionFailed) {
|
|
236
|
+
const msg = "DECRYPTION_FAILED: Please check your DOTENV_KEY";
|
|
237
|
+
throw new Error(msg);
|
|
238
|
+
} else {
|
|
239
|
+
console.error("Error: ", error.code);
|
|
240
|
+
console.error("Error: ", error.message);
|
|
241
|
+
throw error;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
function populate(processEnv, parsed, options = {}) {
|
|
246
|
+
const debug = Boolean(options && options.debug);
|
|
247
|
+
const override = Boolean(options && options.override);
|
|
248
|
+
if (typeof parsed !== "object") {
|
|
249
|
+
throw new Error("OBJECT_REQUIRED: Please check the processEnv argument being passed to populate");
|
|
250
|
+
}
|
|
251
|
+
for (const key of Object.keys(parsed)) {
|
|
252
|
+
if (Object.prototype.hasOwnProperty.call(processEnv, key)) {
|
|
253
|
+
if (override === true) {
|
|
254
|
+
processEnv[key] = parsed[key];
|
|
255
|
+
}
|
|
256
|
+
if (debug) {
|
|
257
|
+
if (override === true) {
|
|
258
|
+
_debug(`"${key}" is already defined and WAS overwritten`);
|
|
259
|
+
} else {
|
|
260
|
+
_debug(`"${key}" is already defined and was NOT overwritten`);
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
} else {
|
|
264
|
+
processEnv[key] = parsed[key];
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
var DotenvModule = {
|
|
269
|
+
configDotenv,
|
|
270
|
+
_configVault,
|
|
271
|
+
_parseVault,
|
|
272
|
+
config,
|
|
273
|
+
decrypt,
|
|
274
|
+
parse,
|
|
275
|
+
populate
|
|
276
|
+
};
|
|
277
|
+
module.exports.configDotenv = DotenvModule.configDotenv;
|
|
278
|
+
module.exports._configVault = DotenvModule._configVault;
|
|
279
|
+
module.exports._parseVault = DotenvModule._parseVault;
|
|
280
|
+
module.exports.config = DotenvModule.config;
|
|
281
|
+
module.exports.decrypt = DotenvModule.decrypt;
|
|
282
|
+
module.exports.parse = DotenvModule.parse;
|
|
283
|
+
module.exports.populate = DotenvModule.populate;
|
|
284
|
+
module.exports = DotenvModule;
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
export default require_main();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/redirect",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.19.0",
|
|
4
4
|
"description": "Uniform redirect client",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"/dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@uniformdev/context": "19.
|
|
35
|
+
"@uniformdev/context": "19.19.0",
|
|
36
36
|
"p-limit": "^3.1.0",
|
|
37
37
|
"rfdc": "^1.3.0"
|
|
38
38
|
},
|
|
39
39
|
"publishConfig": {
|
|
40
40
|
"access": "public"
|
|
41
41
|
},
|
|
42
|
-
"gitHead": "
|
|
42
|
+
"gitHead": "631d1e21b1303220d80bea12611ea6c98d5fe354"
|
|
43
43
|
}
|
package/dist/main-NHOL4NFR.mjs
DELETED
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
__commonJS,
|
|
3
|
-
__require
|
|
4
|
-
} from "./chunk-FFYIGW52.mjs";
|
|
5
|
-
|
|
6
|
-
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json
|
|
7
|
-
var require_package = __commonJS({
|
|
8
|
-
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module) {
|
|
9
|
-
module.exports = {
|
|
10
|
-
name: "dotenv",
|
|
11
|
-
version: "16.0.3",
|
|
12
|
-
description: "Loads environment variables from .env file",
|
|
13
|
-
main: "lib/main.js",
|
|
14
|
-
types: "lib/main.d.ts",
|
|
15
|
-
exports: {
|
|
16
|
-
".": {
|
|
17
|
-
require: "./lib/main.js",
|
|
18
|
-
types: "./lib/main.d.ts",
|
|
19
|
-
default: "./lib/main.js"
|
|
20
|
-
},
|
|
21
|
-
"./config": "./config.js",
|
|
22
|
-
"./config.js": "./config.js",
|
|
23
|
-
"./lib/env-options": "./lib/env-options.js",
|
|
24
|
-
"./lib/env-options.js": "./lib/env-options.js",
|
|
25
|
-
"./lib/cli-options": "./lib/cli-options.js",
|
|
26
|
-
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
27
|
-
"./package.json": "./package.json"
|
|
28
|
-
},
|
|
29
|
-
scripts: {
|
|
30
|
-
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
31
|
-
lint: "standard",
|
|
32
|
-
"lint-readme": "standard-markdown",
|
|
33
|
-
pretest: "npm run lint && npm run dts-check",
|
|
34
|
-
test: "tap tests/*.js --100 -Rspec",
|
|
35
|
-
prerelease: "npm test",
|
|
36
|
-
release: "standard-version"
|
|
37
|
-
},
|
|
38
|
-
repository: {
|
|
39
|
-
type: "git",
|
|
40
|
-
url: "git://github.com/motdotla/dotenv.git"
|
|
41
|
-
},
|
|
42
|
-
keywords: [
|
|
43
|
-
"dotenv",
|
|
44
|
-
"env",
|
|
45
|
-
".env",
|
|
46
|
-
"environment",
|
|
47
|
-
"variables",
|
|
48
|
-
"config",
|
|
49
|
-
"settings"
|
|
50
|
-
],
|
|
51
|
-
readmeFilename: "README.md",
|
|
52
|
-
license: "BSD-2-Clause",
|
|
53
|
-
devDependencies: {
|
|
54
|
-
"@types/node": "^17.0.9",
|
|
55
|
-
decache: "^4.6.1",
|
|
56
|
-
dtslint: "^3.7.0",
|
|
57
|
-
sinon: "^12.0.1",
|
|
58
|
-
standard: "^16.0.4",
|
|
59
|
-
"standard-markdown": "^7.1.0",
|
|
60
|
-
"standard-version": "^9.3.2",
|
|
61
|
-
tap: "^15.1.6",
|
|
62
|
-
tar: "^6.1.11",
|
|
63
|
-
typescript: "^4.5.4"
|
|
64
|
-
},
|
|
65
|
-
engines: {
|
|
66
|
-
node: ">=12"
|
|
67
|
-
}
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js
|
|
73
|
-
var require_main = __commonJS({
|
|
74
|
-
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module) {
|
|
75
|
-
var fs = __require("fs");
|
|
76
|
-
var path = __require("path");
|
|
77
|
-
var os = __require("os");
|
|
78
|
-
var packageJson = require_package();
|
|
79
|
-
var version = packageJson.version;
|
|
80
|
-
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
81
|
-
function parse(src) {
|
|
82
|
-
const obj = {};
|
|
83
|
-
let lines = src.toString();
|
|
84
|
-
lines = lines.replace(/\r\n?/mg, "\n");
|
|
85
|
-
let match;
|
|
86
|
-
while ((match = LINE.exec(lines)) != null) {
|
|
87
|
-
const key = match[1];
|
|
88
|
-
let value = match[2] || "";
|
|
89
|
-
value = value.trim();
|
|
90
|
-
const maybeQuote = value[0];
|
|
91
|
-
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
92
|
-
if (maybeQuote === '"') {
|
|
93
|
-
value = value.replace(/\\n/g, "\n");
|
|
94
|
-
value = value.replace(/\\r/g, "\r");
|
|
95
|
-
}
|
|
96
|
-
obj[key] = value;
|
|
97
|
-
}
|
|
98
|
-
return obj;
|
|
99
|
-
}
|
|
100
|
-
function _log(message) {
|
|
101
|
-
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
102
|
-
}
|
|
103
|
-
function _resolveHome(envPath) {
|
|
104
|
-
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
105
|
-
}
|
|
106
|
-
function config(options) {
|
|
107
|
-
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
108
|
-
let encoding = "utf8";
|
|
109
|
-
const debug = Boolean(options && options.debug);
|
|
110
|
-
const override = Boolean(options && options.override);
|
|
111
|
-
if (options) {
|
|
112
|
-
if (options.path != null) {
|
|
113
|
-
dotenvPath = _resolveHome(options.path);
|
|
114
|
-
}
|
|
115
|
-
if (options.encoding != null) {
|
|
116
|
-
encoding = options.encoding;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
try {
|
|
120
|
-
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
|
|
121
|
-
Object.keys(parsed).forEach(function(key) {
|
|
122
|
-
if (!Object.prototype.hasOwnProperty.call(process.env, key)) {
|
|
123
|
-
process.env[key] = parsed[key];
|
|
124
|
-
} else {
|
|
125
|
-
if (override === true) {
|
|
126
|
-
process.env[key] = parsed[key];
|
|
127
|
-
}
|
|
128
|
-
if (debug) {
|
|
129
|
-
if (override === true) {
|
|
130
|
-
_log(`"${key}" is already defined in \`process.env\` and WAS overwritten`);
|
|
131
|
-
} else {
|
|
132
|
-
_log(`"${key}" is already defined in \`process.env\` and was NOT overwritten`);
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
});
|
|
137
|
-
return { parsed };
|
|
138
|
-
} catch (e) {
|
|
139
|
-
if (debug) {
|
|
140
|
-
_log(`Failed to load ${dotenvPath} ${e.message}`);
|
|
141
|
-
}
|
|
142
|
-
return { error: e };
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
var DotenvModule = {
|
|
146
|
-
config,
|
|
147
|
-
parse
|
|
148
|
-
};
|
|
149
|
-
module.exports.config = DotenvModule.config;
|
|
150
|
-
module.exports.parse = DotenvModule.parse;
|
|
151
|
-
module.exports = DotenvModule;
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
export default require_main();
|