@uniformdev/redirect 19.10.0 → 19.12.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/chunk-FFYIGW52.mjs +16 -0
- package/dist/index.d.ts +25 -1
- package/dist/index.esm.js +90 -4
- package/dist/index.js +252 -4
- package/dist/index.mjs +90 -4
- package/dist/main-NHOL4NFR.mjs +154 -0
- package/package.json +3 -3
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
2
|
+
var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
|
|
3
|
+
get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
|
|
4
|
+
}) : x)(function(x) {
|
|
5
|
+
if (typeof require !== "undefined")
|
|
6
|
+
return require.apply(this, arguments);
|
|
7
|
+
throw new Error('Dynamic require of "' + x + '" is not supported');
|
|
8
|
+
});
|
|
9
|
+
var __commonJS = (cb, mod) => function __require2() {
|
|
10
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
__require,
|
|
15
|
+
__commonJS
|
|
16
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -342,6 +342,9 @@ type RedirectDeleteResponse = paths['/api/v1/redirect']['delete']['responses']['
|
|
|
342
342
|
type RedirectGetResponse = paths['/api/v1/redirect']['get']['responses']['200']['content']['application/json'];
|
|
343
343
|
type RedirectClientGetRequest = Omit<RedirectGetRequest, 'projectId'>;
|
|
344
344
|
type RedirectDefinition = RedirectGetResponse['redirects'][0];
|
|
345
|
+
type RedirectDefinitions = {
|
|
346
|
+
redirects: RedirectDefinition['redirect'][];
|
|
347
|
+
};
|
|
345
348
|
type RedirectResult = {
|
|
346
349
|
url: string;
|
|
347
350
|
label?: string;
|
|
@@ -366,4 +369,25 @@ declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOpt
|
|
|
366
369
|
refresh(): Promise<void[]>;
|
|
367
370
|
}
|
|
368
371
|
|
|
369
|
-
|
|
372
|
+
type Wildcard = {
|
|
373
|
+
pathSegment: string;
|
|
374
|
+
index: number;
|
|
375
|
+
};
|
|
376
|
+
type SourceAndTarget = {
|
|
377
|
+
sourceUrl: string;
|
|
378
|
+
targetUrl: string;
|
|
379
|
+
};
|
|
380
|
+
type SourceTargetAndWildcards = SourceAndTarget & {
|
|
381
|
+
sourceWildcards: Wildcard[];
|
|
382
|
+
targetWildcards: Wildcard[];
|
|
383
|
+
};
|
|
384
|
+
type RedirectFileConverterParams<T> = {
|
|
385
|
+
client?: RedirectClient;
|
|
386
|
+
redirectEntryObject: (redirect: RedirectDefinition) => T;
|
|
387
|
+
wildcardConverter?: (sourceTarget: SourceTargetAndWildcards) => SourceAndTarget;
|
|
388
|
+
writeFile: (redirects: T[]) => void;
|
|
389
|
+
};
|
|
390
|
+
declare function ExtractWildcards(url: string): Wildcard[];
|
|
391
|
+
declare function RedirectFileConverter<T>({ client, redirectEntryObject, wildcardConverter, writeFile, }: RedirectFileConverterParams<T>): Promise<void>;
|
|
392
|
+
|
|
393
|
+
export { ExtractWildcards, PathTrie, PathTrieData, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn };
|
package/dist/index.esm.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "./chunk-FFYIGW52.mjs";
|
|
2
|
+
|
|
1
3
|
// src/cache/redirectClientCache.ts
|
|
2
4
|
var RedirectClientCache = class {
|
|
3
5
|
constructor(options) {
|
|
@@ -115,6 +117,7 @@ var PathTrie = class {
|
|
|
115
117
|
const segments = this.splitUrl(path);
|
|
116
118
|
const wildcards = [];
|
|
117
119
|
const ret = [];
|
|
120
|
+
const splats = [];
|
|
118
121
|
const processed = /* @__PURE__ */ new Set();
|
|
119
122
|
const getVariables = () => {
|
|
120
123
|
return wildcards.map((wildcard) => {
|
|
@@ -146,6 +149,14 @@ var PathTrie = class {
|
|
|
146
149
|
};
|
|
147
150
|
for (let i = 0; i < segments.length; i++) {
|
|
148
151
|
const segment = segments[i];
|
|
152
|
+
if (Object.hasOwn(cur, "*")) {
|
|
153
|
+
cur["*"][dataProp].forEach((splat) => {
|
|
154
|
+
splats.push({
|
|
155
|
+
data: splat,
|
|
156
|
+
variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
149
160
|
getPropsStartingWithColon(cur).forEach((wildcard) => {
|
|
150
161
|
if (!processed.has(wildcard)) {
|
|
151
162
|
wildcards.push({
|
|
@@ -167,7 +178,7 @@ var PathTrie = class {
|
|
|
167
178
|
} else if (i === segments.length - 1) {
|
|
168
179
|
const more = scanWildcards();
|
|
169
180
|
if (typeof more === "undefined")
|
|
170
|
-
return ret;
|
|
181
|
+
return [...ret, ...splats];
|
|
171
182
|
i = more;
|
|
172
183
|
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
|
|
173
184
|
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
|
|
@@ -177,13 +188,13 @@ var PathTrie = class {
|
|
|
177
188
|
} else {
|
|
178
189
|
const more = scanWildcards();
|
|
179
190
|
if (typeof more === "undefined")
|
|
180
|
-
return ret;
|
|
191
|
+
return [...ret, ...splats];
|
|
181
192
|
i = more;
|
|
182
193
|
}
|
|
183
194
|
if (ret.length > 0 && bestMatch)
|
|
184
|
-
return ret;
|
|
195
|
+
return [...ret, ...splats];
|
|
185
196
|
}
|
|
186
|
-
return ret;
|
|
197
|
+
return [...ret, ...splats];
|
|
187
198
|
}
|
|
188
199
|
};
|
|
189
200
|
var PathTrieData = class {
|
|
@@ -476,10 +487,85 @@ var UncachedRedirectClient = class extends RedirectClient {
|
|
|
476
487
|
super({ ...options, bypassCache: true });
|
|
477
488
|
}
|
|
478
489
|
};
|
|
490
|
+
|
|
491
|
+
// src/util/RedirectFileConverter.ts
|
|
492
|
+
var getDefaultClient = async () => {
|
|
493
|
+
const dotenv = await import("./main-NHOL4NFR.mjs");
|
|
494
|
+
dotenv.config();
|
|
495
|
+
return new RedirectClient({
|
|
496
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
497
|
+
apiHost: process.env.UNIFORM_BASE_URL,
|
|
498
|
+
projectId: process.env.UNIFORM_PROJECT_ID
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
function ExtractWildcards(url) {
|
|
502
|
+
let last = "";
|
|
503
|
+
let wildcardStart = -1;
|
|
504
|
+
const terminators = ["/", "?", "&", "#"];
|
|
505
|
+
const ret = [];
|
|
506
|
+
for (let i = 0; i < url.length; i++) {
|
|
507
|
+
const cur = url.charAt(i);
|
|
508
|
+
if (terminators.includes(last) && cur === ":") {
|
|
509
|
+
wildcardStart = i;
|
|
510
|
+
}
|
|
511
|
+
if (terminators.includes(cur) && wildcardStart !== -1) {
|
|
512
|
+
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart, i) });
|
|
513
|
+
wildcardStart = -1;
|
|
514
|
+
}
|
|
515
|
+
last = cur;
|
|
516
|
+
}
|
|
517
|
+
if (wildcardStart > -1) {
|
|
518
|
+
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart) });
|
|
519
|
+
}
|
|
520
|
+
if (last === "*") {
|
|
521
|
+
ret.push({ index: url.length, pathSegment: "*" });
|
|
522
|
+
}
|
|
523
|
+
return ret;
|
|
524
|
+
}
|
|
525
|
+
async function RedirectFileConverter({
|
|
526
|
+
client,
|
|
527
|
+
redirectEntryObject,
|
|
528
|
+
wildcardConverter = (s) => s,
|
|
529
|
+
writeFile
|
|
530
|
+
}) {
|
|
531
|
+
if (!client) {
|
|
532
|
+
client = await getDefaultClient();
|
|
533
|
+
}
|
|
534
|
+
let redirects = (await client.getRedirects({ limit: 50, offset: 0 })).redirects;
|
|
535
|
+
let count = 0;
|
|
536
|
+
const ret = [];
|
|
537
|
+
while (redirects.length) {
|
|
538
|
+
const redirect = redirects.pop();
|
|
539
|
+
if (redirect == null ? void 0 : redirect.redirect) {
|
|
540
|
+
const st = wildcardConverter({
|
|
541
|
+
...redirect.redirect,
|
|
542
|
+
sourceWildcards: ExtractWildcards(redirect.redirect.sourceUrl),
|
|
543
|
+
targetWildcards: ExtractWildcards(redirect.redirect.targetUrl)
|
|
544
|
+
});
|
|
545
|
+
ret.push(
|
|
546
|
+
redirectEntryObject({
|
|
547
|
+
metadata: redirect.metadata,
|
|
548
|
+
redirect: {
|
|
549
|
+
...redirect.redirect,
|
|
550
|
+
sourceUrl: st.sourceUrl,
|
|
551
|
+
targetUrl: st.targetUrl
|
|
552
|
+
}
|
|
553
|
+
})
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
if (!redirects.length) {
|
|
557
|
+
count++;
|
|
558
|
+
redirects = (await client.getRedirects({ limit: 50, offset: count * 50 })).redirects;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
writeFile(ret);
|
|
562
|
+
}
|
|
479
563
|
export {
|
|
564
|
+
ExtractWildcards,
|
|
480
565
|
PathTrie,
|
|
481
566
|
PathTrieData,
|
|
482
567
|
RedirectClient,
|
|
568
|
+
RedirectFileConverter,
|
|
483
569
|
UncachedRedirectClient,
|
|
484
570
|
WithMemoryCache
|
|
485
571
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
9
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
10
|
+
};
|
|
6
11
|
var __export = (target, all) => {
|
|
7
12
|
for (var name in all)
|
|
8
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -15,14 +20,173 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
20
|
}
|
|
16
21
|
return to;
|
|
17
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
18
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
32
|
|
|
33
|
+
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json
|
|
34
|
+
var require_package = __commonJS({
|
|
35
|
+
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/package.json"(exports, module2) {
|
|
36
|
+
module2.exports = {
|
|
37
|
+
name: "dotenv",
|
|
38
|
+
version: "16.0.3",
|
|
39
|
+
description: "Loads environment variables from .env file",
|
|
40
|
+
main: "lib/main.js",
|
|
41
|
+
types: "lib/main.d.ts",
|
|
42
|
+
exports: {
|
|
43
|
+
".": {
|
|
44
|
+
require: "./lib/main.js",
|
|
45
|
+
types: "./lib/main.d.ts",
|
|
46
|
+
default: "./lib/main.js"
|
|
47
|
+
},
|
|
48
|
+
"./config": "./config.js",
|
|
49
|
+
"./config.js": "./config.js",
|
|
50
|
+
"./lib/env-options": "./lib/env-options.js",
|
|
51
|
+
"./lib/env-options.js": "./lib/env-options.js",
|
|
52
|
+
"./lib/cli-options": "./lib/cli-options.js",
|
|
53
|
+
"./lib/cli-options.js": "./lib/cli-options.js",
|
|
54
|
+
"./package.json": "./package.json"
|
|
55
|
+
},
|
|
56
|
+
scripts: {
|
|
57
|
+
"dts-check": "tsc --project tests/types/tsconfig.json",
|
|
58
|
+
lint: "standard",
|
|
59
|
+
"lint-readme": "standard-markdown",
|
|
60
|
+
pretest: "npm run lint && npm run dts-check",
|
|
61
|
+
test: "tap tests/*.js --100 -Rspec",
|
|
62
|
+
prerelease: "npm test",
|
|
63
|
+
release: "standard-version"
|
|
64
|
+
},
|
|
65
|
+
repository: {
|
|
66
|
+
type: "git",
|
|
67
|
+
url: "git://github.com/motdotla/dotenv.git"
|
|
68
|
+
},
|
|
69
|
+
keywords: [
|
|
70
|
+
"dotenv",
|
|
71
|
+
"env",
|
|
72
|
+
".env",
|
|
73
|
+
"environment",
|
|
74
|
+
"variables",
|
|
75
|
+
"config",
|
|
76
|
+
"settings"
|
|
77
|
+
],
|
|
78
|
+
readmeFilename: "README.md",
|
|
79
|
+
license: "BSD-2-Clause",
|
|
80
|
+
devDependencies: {
|
|
81
|
+
"@types/node": "^17.0.9",
|
|
82
|
+
decache: "^4.6.1",
|
|
83
|
+
dtslint: "^3.7.0",
|
|
84
|
+
sinon: "^12.0.1",
|
|
85
|
+
standard: "^16.0.4",
|
|
86
|
+
"standard-markdown": "^7.1.0",
|
|
87
|
+
"standard-version": "^9.3.2",
|
|
88
|
+
tap: "^15.1.6",
|
|
89
|
+
tar: "^6.1.11",
|
|
90
|
+
typescript: "^4.5.4"
|
|
91
|
+
},
|
|
92
|
+
engines: {
|
|
93
|
+
node: ">=12"
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
// ../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js
|
|
100
|
+
var require_main = __commonJS({
|
|
101
|
+
"../../node_modules/.pnpm/dotenv@16.0.3/node_modules/dotenv/lib/main.js"(exports, module2) {
|
|
102
|
+
var fs = require("fs");
|
|
103
|
+
var path = require("path");
|
|
104
|
+
var os = require("os");
|
|
105
|
+
var packageJson = require_package();
|
|
106
|
+
var version = packageJson.version;
|
|
107
|
+
var LINE = /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(?:#.*)?(?:$|$)/mg;
|
|
108
|
+
function parse(src) {
|
|
109
|
+
const obj = {};
|
|
110
|
+
let lines = src.toString();
|
|
111
|
+
lines = lines.replace(/\r\n?/mg, "\n");
|
|
112
|
+
let match;
|
|
113
|
+
while ((match = LINE.exec(lines)) != null) {
|
|
114
|
+
const key = match[1];
|
|
115
|
+
let value = match[2] || "";
|
|
116
|
+
value = value.trim();
|
|
117
|
+
const maybeQuote = value[0];
|
|
118
|
+
value = value.replace(/^(['"`])([\s\S]*)\1$/mg, "$2");
|
|
119
|
+
if (maybeQuote === '"') {
|
|
120
|
+
value = value.replace(/\\n/g, "\n");
|
|
121
|
+
value = value.replace(/\\r/g, "\r");
|
|
122
|
+
}
|
|
123
|
+
obj[key] = value;
|
|
124
|
+
}
|
|
125
|
+
return obj;
|
|
126
|
+
}
|
|
127
|
+
function _log(message) {
|
|
128
|
+
console.log(`[dotenv@${version}][DEBUG] ${message}`);
|
|
129
|
+
}
|
|
130
|
+
function _resolveHome(envPath) {
|
|
131
|
+
return envPath[0] === "~" ? path.join(os.homedir(), envPath.slice(1)) : envPath;
|
|
132
|
+
}
|
|
133
|
+
function config(options) {
|
|
134
|
+
let dotenvPath = path.resolve(process.cwd(), ".env");
|
|
135
|
+
let encoding = "utf8";
|
|
136
|
+
const debug = Boolean(options && options.debug);
|
|
137
|
+
const override = Boolean(options && options.override);
|
|
138
|
+
if (options) {
|
|
139
|
+
if (options.path != null) {
|
|
140
|
+
dotenvPath = _resolveHome(options.path);
|
|
141
|
+
}
|
|
142
|
+
if (options.encoding != null) {
|
|
143
|
+
encoding = options.encoding;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
|
|
148
|
+
Object.keys(parsed).forEach(function(key) {
|
|
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
|
+
});
|
|
164
|
+
return { parsed };
|
|
165
|
+
} catch (e) {
|
|
166
|
+
if (debug) {
|
|
167
|
+
_log(`Failed to load ${dotenvPath} ${e.message}`);
|
|
168
|
+
}
|
|
169
|
+
return { error: e };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
var DotenvModule = {
|
|
173
|
+
config,
|
|
174
|
+
parse
|
|
175
|
+
};
|
|
176
|
+
module2.exports.config = DotenvModule.config;
|
|
177
|
+
module2.exports.parse = DotenvModule.parse;
|
|
178
|
+
module2.exports = DotenvModule;
|
|
179
|
+
}
|
|
180
|
+
});
|
|
181
|
+
|
|
20
182
|
// src/index.ts
|
|
21
183
|
var src_exports = {};
|
|
22
184
|
__export(src_exports, {
|
|
185
|
+
ExtractWildcards: () => ExtractWildcards,
|
|
23
186
|
PathTrie: () => PathTrie,
|
|
24
187
|
PathTrieData: () => PathTrieData,
|
|
25
188
|
RedirectClient: () => RedirectClient,
|
|
189
|
+
RedirectFileConverter: () => RedirectFileConverter,
|
|
26
190
|
UncachedRedirectClient: () => UncachedRedirectClient,
|
|
27
191
|
WithMemoryCache: () => WithMemoryCache
|
|
28
192
|
});
|
|
@@ -145,6 +309,7 @@ var PathTrie = class {
|
|
|
145
309
|
const segments = this.splitUrl(path);
|
|
146
310
|
const wildcards = [];
|
|
147
311
|
const ret = [];
|
|
312
|
+
const splats = [];
|
|
148
313
|
const processed = /* @__PURE__ */ new Set();
|
|
149
314
|
const getVariables = () => {
|
|
150
315
|
return wildcards.map((wildcard) => {
|
|
@@ -176,6 +341,14 @@ var PathTrie = class {
|
|
|
176
341
|
};
|
|
177
342
|
for (let i = 0; i < segments.length; i++) {
|
|
178
343
|
const segment = segments[i];
|
|
344
|
+
if (Object.hasOwn(cur, "*")) {
|
|
345
|
+
cur["*"][dataProp].forEach((splat) => {
|
|
346
|
+
splats.push({
|
|
347
|
+
data: splat,
|
|
348
|
+
variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
|
|
349
|
+
});
|
|
350
|
+
});
|
|
351
|
+
}
|
|
179
352
|
getPropsStartingWithColon(cur).forEach((wildcard) => {
|
|
180
353
|
if (!processed.has(wildcard)) {
|
|
181
354
|
wildcards.push({
|
|
@@ -197,7 +370,7 @@ var PathTrie = class {
|
|
|
197
370
|
} else if (i === segments.length - 1) {
|
|
198
371
|
const more = scanWildcards();
|
|
199
372
|
if (typeof more === "undefined")
|
|
200
|
-
return ret;
|
|
373
|
+
return [...ret, ...splats];
|
|
201
374
|
i = more;
|
|
202
375
|
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
|
|
203
376
|
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
|
|
@@ -207,13 +380,13 @@ var PathTrie = class {
|
|
|
207
380
|
} else {
|
|
208
381
|
const more = scanWildcards();
|
|
209
382
|
if (typeof more === "undefined")
|
|
210
|
-
return ret;
|
|
383
|
+
return [...ret, ...splats];
|
|
211
384
|
i = more;
|
|
212
385
|
}
|
|
213
386
|
if (ret.length > 0 && bestMatch)
|
|
214
|
-
return ret;
|
|
387
|
+
return [...ret, ...splats];
|
|
215
388
|
}
|
|
216
|
-
return ret;
|
|
389
|
+
return [...ret, ...splats];
|
|
217
390
|
}
|
|
218
391
|
};
|
|
219
392
|
var PathTrieData = class {
|
|
@@ -506,11 +679,86 @@ var UncachedRedirectClient = class extends RedirectClient {
|
|
|
506
679
|
super({ ...options, bypassCache: true });
|
|
507
680
|
}
|
|
508
681
|
};
|
|
682
|
+
|
|
683
|
+
// src/util/RedirectFileConverter.ts
|
|
684
|
+
var getDefaultClient = async () => {
|
|
685
|
+
const dotenv = await Promise.resolve().then(() => __toESM(require_main()));
|
|
686
|
+
dotenv.config();
|
|
687
|
+
return new RedirectClient({
|
|
688
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
689
|
+
apiHost: process.env.UNIFORM_BASE_URL,
|
|
690
|
+
projectId: process.env.UNIFORM_PROJECT_ID
|
|
691
|
+
});
|
|
692
|
+
};
|
|
693
|
+
function ExtractWildcards(url) {
|
|
694
|
+
let last = "";
|
|
695
|
+
let wildcardStart = -1;
|
|
696
|
+
const terminators = ["/", "?", "&", "#"];
|
|
697
|
+
const ret = [];
|
|
698
|
+
for (let i = 0; i < url.length; i++) {
|
|
699
|
+
const cur = url.charAt(i);
|
|
700
|
+
if (terminators.includes(last) && cur === ":") {
|
|
701
|
+
wildcardStart = i;
|
|
702
|
+
}
|
|
703
|
+
if (terminators.includes(cur) && wildcardStart !== -1) {
|
|
704
|
+
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart, i) });
|
|
705
|
+
wildcardStart = -1;
|
|
706
|
+
}
|
|
707
|
+
last = cur;
|
|
708
|
+
}
|
|
709
|
+
if (wildcardStart > -1) {
|
|
710
|
+
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart) });
|
|
711
|
+
}
|
|
712
|
+
if (last === "*") {
|
|
713
|
+
ret.push({ index: url.length, pathSegment: "*" });
|
|
714
|
+
}
|
|
715
|
+
return ret;
|
|
716
|
+
}
|
|
717
|
+
async function RedirectFileConverter({
|
|
718
|
+
client,
|
|
719
|
+
redirectEntryObject,
|
|
720
|
+
wildcardConverter = (s) => s,
|
|
721
|
+
writeFile
|
|
722
|
+
}) {
|
|
723
|
+
if (!client) {
|
|
724
|
+
client = await getDefaultClient();
|
|
725
|
+
}
|
|
726
|
+
let redirects = (await client.getRedirects({ limit: 50, offset: 0 })).redirects;
|
|
727
|
+
let count = 0;
|
|
728
|
+
const ret = [];
|
|
729
|
+
while (redirects.length) {
|
|
730
|
+
const redirect = redirects.pop();
|
|
731
|
+
if (redirect == null ? void 0 : redirect.redirect) {
|
|
732
|
+
const st = wildcardConverter({
|
|
733
|
+
...redirect.redirect,
|
|
734
|
+
sourceWildcards: ExtractWildcards(redirect.redirect.sourceUrl),
|
|
735
|
+
targetWildcards: ExtractWildcards(redirect.redirect.targetUrl)
|
|
736
|
+
});
|
|
737
|
+
ret.push(
|
|
738
|
+
redirectEntryObject({
|
|
739
|
+
metadata: redirect.metadata,
|
|
740
|
+
redirect: {
|
|
741
|
+
...redirect.redirect,
|
|
742
|
+
sourceUrl: st.sourceUrl,
|
|
743
|
+
targetUrl: st.targetUrl
|
|
744
|
+
}
|
|
745
|
+
})
|
|
746
|
+
);
|
|
747
|
+
}
|
|
748
|
+
if (!redirects.length) {
|
|
749
|
+
count++;
|
|
750
|
+
redirects = (await client.getRedirects({ limit: 50, offset: count * 50 })).redirects;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
writeFile(ret);
|
|
754
|
+
}
|
|
509
755
|
// Annotate the CommonJS export names for ESM import in node:
|
|
510
756
|
0 && (module.exports = {
|
|
757
|
+
ExtractWildcards,
|
|
511
758
|
PathTrie,
|
|
512
759
|
PathTrieData,
|
|
513
760
|
RedirectClient,
|
|
761
|
+
RedirectFileConverter,
|
|
514
762
|
UncachedRedirectClient,
|
|
515
763
|
WithMemoryCache
|
|
516
764
|
});
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import "./chunk-FFYIGW52.mjs";
|
|
2
|
+
|
|
1
3
|
// src/cache/redirectClientCache.ts
|
|
2
4
|
var RedirectClientCache = class {
|
|
3
5
|
constructor(options) {
|
|
@@ -115,6 +117,7 @@ var PathTrie = class {
|
|
|
115
117
|
const segments = this.splitUrl(path);
|
|
116
118
|
const wildcards = [];
|
|
117
119
|
const ret = [];
|
|
120
|
+
const splats = [];
|
|
118
121
|
const processed = /* @__PURE__ */ new Set();
|
|
119
122
|
const getVariables = () => {
|
|
120
123
|
return wildcards.map((wildcard) => {
|
|
@@ -146,6 +149,14 @@ var PathTrie = class {
|
|
|
146
149
|
};
|
|
147
150
|
for (let i = 0; i < segments.length; i++) {
|
|
148
151
|
const segment = segments[i];
|
|
152
|
+
if (Object.hasOwn(cur, "*")) {
|
|
153
|
+
cur["*"][dataProp].forEach((splat) => {
|
|
154
|
+
splats.push({
|
|
155
|
+
data: splat,
|
|
156
|
+
variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
149
160
|
getPropsStartingWithColon(cur).forEach((wildcard) => {
|
|
150
161
|
if (!processed.has(wildcard)) {
|
|
151
162
|
wildcards.push({
|
|
@@ -167,7 +178,7 @@ var PathTrie = class {
|
|
|
167
178
|
} else if (i === segments.length - 1) {
|
|
168
179
|
const more = scanWildcards();
|
|
169
180
|
if (typeof more === "undefined")
|
|
170
|
-
return ret;
|
|
181
|
+
return [...ret, ...splats];
|
|
171
182
|
i = more;
|
|
172
183
|
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
|
|
173
184
|
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
|
|
@@ -177,13 +188,13 @@ var PathTrie = class {
|
|
|
177
188
|
} else {
|
|
178
189
|
const more = scanWildcards();
|
|
179
190
|
if (typeof more === "undefined")
|
|
180
|
-
return ret;
|
|
191
|
+
return [...ret, ...splats];
|
|
181
192
|
i = more;
|
|
182
193
|
}
|
|
183
194
|
if (ret.length > 0 && bestMatch)
|
|
184
|
-
return ret;
|
|
195
|
+
return [...ret, ...splats];
|
|
185
196
|
}
|
|
186
|
-
return ret;
|
|
197
|
+
return [...ret, ...splats];
|
|
187
198
|
}
|
|
188
199
|
};
|
|
189
200
|
var PathTrieData = class {
|
|
@@ -476,10 +487,85 @@ var UncachedRedirectClient = class extends RedirectClient {
|
|
|
476
487
|
super({ ...options, bypassCache: true });
|
|
477
488
|
}
|
|
478
489
|
};
|
|
490
|
+
|
|
491
|
+
// src/util/RedirectFileConverter.ts
|
|
492
|
+
var getDefaultClient = async () => {
|
|
493
|
+
const dotenv = await import("./main-NHOL4NFR.mjs");
|
|
494
|
+
dotenv.config();
|
|
495
|
+
return new RedirectClient({
|
|
496
|
+
apiKey: process.env.UNIFORM_API_KEY,
|
|
497
|
+
apiHost: process.env.UNIFORM_BASE_URL,
|
|
498
|
+
projectId: process.env.UNIFORM_PROJECT_ID
|
|
499
|
+
});
|
|
500
|
+
};
|
|
501
|
+
function ExtractWildcards(url) {
|
|
502
|
+
let last = "";
|
|
503
|
+
let wildcardStart = -1;
|
|
504
|
+
const terminators = ["/", "?", "&", "#"];
|
|
505
|
+
const ret = [];
|
|
506
|
+
for (let i = 0; i < url.length; i++) {
|
|
507
|
+
const cur = url.charAt(i);
|
|
508
|
+
if (terminators.includes(last) && cur === ":") {
|
|
509
|
+
wildcardStart = i;
|
|
510
|
+
}
|
|
511
|
+
if (terminators.includes(cur) && wildcardStart !== -1) {
|
|
512
|
+
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart, i) });
|
|
513
|
+
wildcardStart = -1;
|
|
514
|
+
}
|
|
515
|
+
last = cur;
|
|
516
|
+
}
|
|
517
|
+
if (wildcardStart > -1) {
|
|
518
|
+
ret.push({ index: wildcardStart, pathSegment: url.substring(wildcardStart) });
|
|
519
|
+
}
|
|
520
|
+
if (last === "*") {
|
|
521
|
+
ret.push({ index: url.length, pathSegment: "*" });
|
|
522
|
+
}
|
|
523
|
+
return ret;
|
|
524
|
+
}
|
|
525
|
+
async function RedirectFileConverter({
|
|
526
|
+
client,
|
|
527
|
+
redirectEntryObject,
|
|
528
|
+
wildcardConverter = (s) => s,
|
|
529
|
+
writeFile
|
|
530
|
+
}) {
|
|
531
|
+
if (!client) {
|
|
532
|
+
client = await getDefaultClient();
|
|
533
|
+
}
|
|
534
|
+
let redirects = (await client.getRedirects({ limit: 50, offset: 0 })).redirects;
|
|
535
|
+
let count = 0;
|
|
536
|
+
const ret = [];
|
|
537
|
+
while (redirects.length) {
|
|
538
|
+
const redirect = redirects.pop();
|
|
539
|
+
if (redirect == null ? void 0 : redirect.redirect) {
|
|
540
|
+
const st = wildcardConverter({
|
|
541
|
+
...redirect.redirect,
|
|
542
|
+
sourceWildcards: ExtractWildcards(redirect.redirect.sourceUrl),
|
|
543
|
+
targetWildcards: ExtractWildcards(redirect.redirect.targetUrl)
|
|
544
|
+
});
|
|
545
|
+
ret.push(
|
|
546
|
+
redirectEntryObject({
|
|
547
|
+
metadata: redirect.metadata,
|
|
548
|
+
redirect: {
|
|
549
|
+
...redirect.redirect,
|
|
550
|
+
sourceUrl: st.sourceUrl,
|
|
551
|
+
targetUrl: st.targetUrl
|
|
552
|
+
}
|
|
553
|
+
})
|
|
554
|
+
);
|
|
555
|
+
}
|
|
556
|
+
if (!redirects.length) {
|
|
557
|
+
count++;
|
|
558
|
+
redirects = (await client.getRedirects({ limit: 50, offset: count * 50 })).redirects;
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
writeFile(ret);
|
|
562
|
+
}
|
|
479
563
|
export {
|
|
564
|
+
ExtractWildcards,
|
|
480
565
|
PathTrie,
|
|
481
566
|
PathTrieData,
|
|
482
567
|
RedirectClient,
|
|
568
|
+
RedirectFileConverter,
|
|
483
569
|
UncachedRedirectClient,
|
|
484
570
|
WithMemoryCache
|
|
485
571
|
};
|
|
@@ -0,0 +1,154 @@
|
|
|
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();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/redirect",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.12.0",
|
|
4
4
|
"description": "Uniform redirect client",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,11 +32,11 @@
|
|
|
32
32
|
"/dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@uniformdev/context": "19.
|
|
35
|
+
"@uniformdev/context": "19.12.0",
|
|
36
36
|
"p-limit": "^3.1.0"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"access": "public"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "ca508c44f1b274e3e47d90717a98036256ae8379"
|
|
42
42
|
}
|