@uniformdev/redirect 19.2.0 → 19.3.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 +1 -1
- package/dist/index.esm.js +21 -14
- package/dist/index.js +21 -14
- package/dist/index.mjs +21 -14
- package/package.json +3 -7
package/dist/index.d.ts
CHANGED
|
@@ -14,7 +14,7 @@ declare class PathTrie<T> {
|
|
|
14
14
|
insertMany(data: T[], key: (data: T) => string): void;
|
|
15
15
|
insert(path: string, data: T): void;
|
|
16
16
|
find(path: string, bestMatch?: boolean): pathTrieReturn<T>[] | undefined;
|
|
17
|
-
|
|
17
|
+
private splitUrl;
|
|
18
18
|
}
|
|
19
19
|
declare class PathTrieData<T> {
|
|
20
20
|
[key: string]: PathTrieData<T> | T;
|
package/dist/index.esm.js
CHANGED
|
@@ -62,6 +62,13 @@ var dataProp = "~~data~~";
|
|
|
62
62
|
var PathTrie = class {
|
|
63
63
|
constructor(initialData) {
|
|
64
64
|
this.map = new PathTrieData();
|
|
65
|
+
this.splitUrl = (url) => {
|
|
66
|
+
if (url.startsWith("https://"))
|
|
67
|
+
return ["https://", ...url.substring("https://".length).split("/")].filter((segment) => segment.length);
|
|
68
|
+
if (url.startsWith("http://"))
|
|
69
|
+
return ["http://", ...url.substring("http://".length).split("/")].filter((segment) => segment.length);
|
|
70
|
+
return url.split("/").filter((segment) => segment.length);
|
|
71
|
+
};
|
|
65
72
|
if (initialData) {
|
|
66
73
|
if (Object.hasOwn(initialData, "map")) {
|
|
67
74
|
this.map = initialData.map;
|
|
@@ -86,7 +93,7 @@ var PathTrie = class {
|
|
|
86
93
|
}
|
|
87
94
|
insert(path, data) {
|
|
88
95
|
let cur = this.map;
|
|
89
|
-
const segments =
|
|
96
|
+
const segments = this.splitUrl(path);
|
|
90
97
|
for (let i = 0; i < segments.length; i++) {
|
|
91
98
|
const segment = segments[i];
|
|
92
99
|
if (i === 0 && segment === "")
|
|
@@ -105,7 +112,7 @@ var PathTrie = class {
|
|
|
105
112
|
}
|
|
106
113
|
find(path, bestMatch = true) {
|
|
107
114
|
let cur = structuredClone(this.map);
|
|
108
|
-
const segments =
|
|
115
|
+
const segments = this.splitUrl(path);
|
|
109
116
|
const wildcards = [];
|
|
110
117
|
const ret = [];
|
|
111
118
|
const processed = /* @__PURE__ */ new Set();
|
|
@@ -178,9 +185,6 @@ var PathTrie = class {
|
|
|
178
185
|
}
|
|
179
186
|
return ret;
|
|
180
187
|
}
|
|
181
|
-
processChar(char) {
|
|
182
|
-
return char;
|
|
183
|
-
}
|
|
184
188
|
};
|
|
185
189
|
var PathTrieData = class {
|
|
186
190
|
};
|
|
@@ -316,18 +320,19 @@ var _RedirectClient = class extends ApiClient {
|
|
|
316
320
|
static processHops(url, trie, bestMatch, options) {
|
|
317
321
|
var _a;
|
|
318
322
|
const isCycle = (id, result) => {
|
|
319
|
-
var _a2
|
|
323
|
+
var _a2;
|
|
320
324
|
if (!id || !result.lastHop)
|
|
321
325
|
return false;
|
|
322
326
|
const set = /* @__PURE__ */ new Set([id]);
|
|
323
327
|
const cycleStack = [result];
|
|
324
328
|
while (cycleStack.length > 0) {
|
|
325
329
|
const cur = cycleStack.pop();
|
|
326
|
-
|
|
330
|
+
const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
|
|
331
|
+
if (!(redirect == null ? void 0 : redirect.id))
|
|
327
332
|
continue;
|
|
328
|
-
if (set.has(
|
|
333
|
+
if (set.has(redirect.id))
|
|
329
334
|
return true;
|
|
330
|
-
set.add(
|
|
335
|
+
set.add(redirect.id);
|
|
331
336
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
332
337
|
cycleStack.push(cur.lastHop);
|
|
333
338
|
}
|
|
@@ -340,7 +345,8 @@ var _RedirectClient = class extends ApiClient {
|
|
|
340
345
|
const result = stack.pop();
|
|
341
346
|
if (!(result == null ? void 0 : result.url))
|
|
342
347
|
continue;
|
|
343
|
-
const
|
|
348
|
+
const redirect = (_a = result.definition) == null ? void 0 : _a.redirect;
|
|
349
|
+
const hop = (redirect == null ? void 0 : redirect.stopExecutingAfter) ? [] : this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
344
350
|
(h) => {
|
|
345
351
|
var _a2, _b;
|
|
346
352
|
return ((_a2 = h.definition) == null ? void 0 : _a2.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
|
|
@@ -382,11 +388,12 @@ var _RedirectClient = class extends ApiClient {
|
|
|
382
388
|
var _a, _b, _c, _d, _e;
|
|
383
389
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
384
390
|
const processedResult = this.processUrl(resultUrl);
|
|
385
|
-
|
|
391
|
+
const redirect = definition == null ? void 0 : definition.redirect;
|
|
392
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
386
393
|
return void 0;
|
|
387
|
-
const protocol =
|
|
388
|
-
const domain =
|
|
389
|
-
const queryString =
|
|
394
|
+
const protocol = redirect.targetPreserveIncomingProtocol ? processedUrl.protocol : (_b = (_a = processedResult.protocol) != null ? _a : processedUrl.protocol) != null ? _b : "";
|
|
395
|
+
const domain = redirect.targetPreserveIncomingDomain ? processedUrl.domain : (_d = (_c = processedResult.domain) != null ? _c : processedUrl.domain) != null ? _d : "";
|
|
396
|
+
const queryString = redirect.sourceRetainQuerystring && processedResult.query ? (_e = processedResult.query) != null ? _e : "" : definition.redirect.sourceRetainQuerystring ? processedUrl.query : "";
|
|
390
397
|
const finalUrl = `${protocol}${domain}${processedResult.port}${processedResult.path}${queryString}`;
|
|
391
398
|
return {
|
|
392
399
|
url: variables.reduce((cur, o) => {
|
package/dist/index.js
CHANGED
|
@@ -92,6 +92,13 @@ var dataProp = "~~data~~";
|
|
|
92
92
|
var PathTrie = class {
|
|
93
93
|
constructor(initialData) {
|
|
94
94
|
this.map = new PathTrieData();
|
|
95
|
+
this.splitUrl = (url) => {
|
|
96
|
+
if (url.startsWith("https://"))
|
|
97
|
+
return ["https://", ...url.substring("https://".length).split("/")].filter((segment) => segment.length);
|
|
98
|
+
if (url.startsWith("http://"))
|
|
99
|
+
return ["http://", ...url.substring("http://".length).split("/")].filter((segment) => segment.length);
|
|
100
|
+
return url.split("/").filter((segment) => segment.length);
|
|
101
|
+
};
|
|
95
102
|
if (initialData) {
|
|
96
103
|
if (Object.hasOwn(initialData, "map")) {
|
|
97
104
|
this.map = initialData.map;
|
|
@@ -116,7 +123,7 @@ var PathTrie = class {
|
|
|
116
123
|
}
|
|
117
124
|
insert(path, data) {
|
|
118
125
|
let cur = this.map;
|
|
119
|
-
const segments =
|
|
126
|
+
const segments = this.splitUrl(path);
|
|
120
127
|
for (let i = 0; i < segments.length; i++) {
|
|
121
128
|
const segment = segments[i];
|
|
122
129
|
if (i === 0 && segment === "")
|
|
@@ -135,7 +142,7 @@ var PathTrie = class {
|
|
|
135
142
|
}
|
|
136
143
|
find(path, bestMatch = true) {
|
|
137
144
|
let cur = structuredClone(this.map);
|
|
138
|
-
const segments =
|
|
145
|
+
const segments = this.splitUrl(path);
|
|
139
146
|
const wildcards = [];
|
|
140
147
|
const ret = [];
|
|
141
148
|
const processed = /* @__PURE__ */ new Set();
|
|
@@ -208,9 +215,6 @@ var PathTrie = class {
|
|
|
208
215
|
}
|
|
209
216
|
return ret;
|
|
210
217
|
}
|
|
211
|
-
processChar(char) {
|
|
212
|
-
return char;
|
|
213
|
-
}
|
|
214
218
|
};
|
|
215
219
|
var PathTrieData = class {
|
|
216
220
|
};
|
|
@@ -346,18 +350,19 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
346
350
|
static processHops(url, trie, bestMatch, options) {
|
|
347
351
|
var _a;
|
|
348
352
|
const isCycle = (id, result) => {
|
|
349
|
-
var _a2
|
|
353
|
+
var _a2;
|
|
350
354
|
if (!id || !result.lastHop)
|
|
351
355
|
return false;
|
|
352
356
|
const set = /* @__PURE__ */ new Set([id]);
|
|
353
357
|
const cycleStack = [result];
|
|
354
358
|
while (cycleStack.length > 0) {
|
|
355
359
|
const cur = cycleStack.pop();
|
|
356
|
-
|
|
360
|
+
const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
|
|
361
|
+
if (!(redirect == null ? void 0 : redirect.id))
|
|
357
362
|
continue;
|
|
358
|
-
if (set.has(
|
|
363
|
+
if (set.has(redirect.id))
|
|
359
364
|
return true;
|
|
360
|
-
set.add(
|
|
365
|
+
set.add(redirect.id);
|
|
361
366
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
362
367
|
cycleStack.push(cur.lastHop);
|
|
363
368
|
}
|
|
@@ -370,7 +375,8 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
370
375
|
const result = stack.pop();
|
|
371
376
|
if (!(result == null ? void 0 : result.url))
|
|
372
377
|
continue;
|
|
373
|
-
const
|
|
378
|
+
const redirect = (_a = result.definition) == null ? void 0 : _a.redirect;
|
|
379
|
+
const hop = (redirect == null ? void 0 : redirect.stopExecutingAfter) ? [] : this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
374
380
|
(h) => {
|
|
375
381
|
var _a2, _b;
|
|
376
382
|
return ((_a2 = h.definition) == null ? void 0 : _a2.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
|
|
@@ -412,11 +418,12 @@ var _RedirectClient = class extends import_api.ApiClient {
|
|
|
412
418
|
var _a, _b, _c, _d, _e;
|
|
413
419
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
414
420
|
const processedResult = this.processUrl(resultUrl);
|
|
415
|
-
|
|
421
|
+
const redirect = definition == null ? void 0 : definition.redirect;
|
|
422
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
416
423
|
return void 0;
|
|
417
|
-
const protocol =
|
|
418
|
-
const domain =
|
|
419
|
-
const queryString =
|
|
424
|
+
const protocol = redirect.targetPreserveIncomingProtocol ? processedUrl.protocol : (_b = (_a = processedResult.protocol) != null ? _a : processedUrl.protocol) != null ? _b : "";
|
|
425
|
+
const domain = redirect.targetPreserveIncomingDomain ? processedUrl.domain : (_d = (_c = processedResult.domain) != null ? _c : processedUrl.domain) != null ? _d : "";
|
|
426
|
+
const queryString = redirect.sourceRetainQuerystring && processedResult.query ? (_e = processedResult.query) != null ? _e : "" : definition.redirect.sourceRetainQuerystring ? processedUrl.query : "";
|
|
420
427
|
const finalUrl = `${protocol}${domain}${processedResult.port}${processedResult.path}${queryString}`;
|
|
421
428
|
return {
|
|
422
429
|
url: variables.reduce((cur, o) => {
|
package/dist/index.mjs
CHANGED
|
@@ -62,6 +62,13 @@ var dataProp = "~~data~~";
|
|
|
62
62
|
var PathTrie = class {
|
|
63
63
|
constructor(initialData) {
|
|
64
64
|
this.map = new PathTrieData();
|
|
65
|
+
this.splitUrl = (url) => {
|
|
66
|
+
if (url.startsWith("https://"))
|
|
67
|
+
return ["https://", ...url.substring("https://".length).split("/")].filter((segment) => segment.length);
|
|
68
|
+
if (url.startsWith("http://"))
|
|
69
|
+
return ["http://", ...url.substring("http://".length).split("/")].filter((segment) => segment.length);
|
|
70
|
+
return url.split("/").filter((segment) => segment.length);
|
|
71
|
+
};
|
|
65
72
|
if (initialData) {
|
|
66
73
|
if (Object.hasOwn(initialData, "map")) {
|
|
67
74
|
this.map = initialData.map;
|
|
@@ -86,7 +93,7 @@ var PathTrie = class {
|
|
|
86
93
|
}
|
|
87
94
|
insert(path, data) {
|
|
88
95
|
let cur = this.map;
|
|
89
|
-
const segments =
|
|
96
|
+
const segments = this.splitUrl(path);
|
|
90
97
|
for (let i = 0; i < segments.length; i++) {
|
|
91
98
|
const segment = segments[i];
|
|
92
99
|
if (i === 0 && segment === "")
|
|
@@ -105,7 +112,7 @@ var PathTrie = class {
|
|
|
105
112
|
}
|
|
106
113
|
find(path, bestMatch = true) {
|
|
107
114
|
let cur = structuredClone(this.map);
|
|
108
|
-
const segments =
|
|
115
|
+
const segments = this.splitUrl(path);
|
|
109
116
|
const wildcards = [];
|
|
110
117
|
const ret = [];
|
|
111
118
|
const processed = /* @__PURE__ */ new Set();
|
|
@@ -178,9 +185,6 @@ var PathTrie = class {
|
|
|
178
185
|
}
|
|
179
186
|
return ret;
|
|
180
187
|
}
|
|
181
|
-
processChar(char) {
|
|
182
|
-
return char;
|
|
183
|
-
}
|
|
184
188
|
};
|
|
185
189
|
var PathTrieData = class {
|
|
186
190
|
};
|
|
@@ -316,18 +320,19 @@ var _RedirectClient = class extends ApiClient {
|
|
|
316
320
|
static processHops(url, trie, bestMatch, options) {
|
|
317
321
|
var _a;
|
|
318
322
|
const isCycle = (id, result) => {
|
|
319
|
-
var _a2
|
|
323
|
+
var _a2;
|
|
320
324
|
if (!id || !result.lastHop)
|
|
321
325
|
return false;
|
|
322
326
|
const set = /* @__PURE__ */ new Set([id]);
|
|
323
327
|
const cycleStack = [result];
|
|
324
328
|
while (cycleStack.length > 0) {
|
|
325
329
|
const cur = cycleStack.pop();
|
|
326
|
-
|
|
330
|
+
const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
|
|
331
|
+
if (!(redirect == null ? void 0 : redirect.id))
|
|
327
332
|
continue;
|
|
328
|
-
if (set.has(
|
|
333
|
+
if (set.has(redirect.id))
|
|
329
334
|
return true;
|
|
330
|
-
set.add(
|
|
335
|
+
set.add(redirect.id);
|
|
331
336
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
332
337
|
cycleStack.push(cur.lastHop);
|
|
333
338
|
}
|
|
@@ -340,7 +345,8 @@ var _RedirectClient = class extends ApiClient {
|
|
|
340
345
|
const result = stack.pop();
|
|
341
346
|
if (!(result == null ? void 0 : result.url))
|
|
342
347
|
continue;
|
|
343
|
-
const
|
|
348
|
+
const redirect = (_a = result.definition) == null ? void 0 : _a.redirect;
|
|
349
|
+
const hop = (redirect == null ? void 0 : redirect.stopExecutingAfter) ? [] : this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
344
350
|
(h) => {
|
|
345
351
|
var _a2, _b;
|
|
346
352
|
return ((_a2 = h.definition) == null ? void 0 : _a2.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
|
|
@@ -382,11 +388,12 @@ var _RedirectClient = class extends ApiClient {
|
|
|
382
388
|
var _a, _b, _c, _d, _e;
|
|
383
389
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
384
390
|
const processedResult = this.processUrl(resultUrl);
|
|
385
|
-
|
|
391
|
+
const redirect = definition == null ? void 0 : definition.redirect;
|
|
392
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
386
393
|
return void 0;
|
|
387
|
-
const protocol =
|
|
388
|
-
const domain =
|
|
389
|
-
const queryString =
|
|
394
|
+
const protocol = redirect.targetPreserveIncomingProtocol ? processedUrl.protocol : (_b = (_a = processedResult.protocol) != null ? _a : processedUrl.protocol) != null ? _b : "";
|
|
395
|
+
const domain = redirect.targetPreserveIncomingDomain ? processedUrl.domain : (_d = (_c = processedResult.domain) != null ? _c : processedUrl.domain) != null ? _d : "";
|
|
396
|
+
const queryString = redirect.sourceRetainQuerystring && processedResult.query ? (_e = processedResult.query) != null ? _e : "" : definition.redirect.sourceRetainQuerystring ? processedUrl.query : "";
|
|
390
397
|
const finalUrl = `${protocol}${domain}${processedResult.port}${processedResult.path}${queryString}`;
|
|
391
398
|
return {
|
|
392
399
|
url: variables.reduce((cur, o) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/redirect",
|
|
3
|
-
"version": "19.
|
|
3
|
+
"version": "19.3.0",
|
|
4
4
|
"description": "Uniform redirect client",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -32,15 +32,11 @@
|
|
|
32
32
|
"/dist"
|
|
33
33
|
],
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@uniformdev/context": "19.
|
|
35
|
+
"@uniformdev/context": "19.3.0",
|
|
36
36
|
"p-limit": "^3.1.0"
|
|
37
37
|
},
|
|
38
|
-
"devDependencies": {
|
|
39
|
-
"@types/yargs": "17.0.22",
|
|
40
|
-
"yargs": "17.6.2"
|
|
41
|
-
},
|
|
42
38
|
"publishConfig": {
|
|
43
39
|
"access": "public"
|
|
44
40
|
},
|
|
45
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "57552ffe10ca66f905d8908c82dde39935fb1803"
|
|
46
42
|
}
|