@uniformdev/redirect 19.159.0 → 19.159.1-alpha.27
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.esm.js +18 -36
- package/dist/index.js +18 -36
- package/dist/index.mjs +18 -36
- package/package.json +3 -3
package/dist/index.esm.js
CHANGED
|
@@ -64,8 +64,7 @@ var _WithMemoryCache = class _WithMemoryCache extends RedirectClientCache {
|
|
|
64
64
|
/* Set new data to the cache and reset the refresh method */
|
|
65
65
|
set(key, data, refresh) {
|
|
66
66
|
var _a;
|
|
67
|
-
if (!data)
|
|
68
|
-
return;
|
|
67
|
+
if (!data) return;
|
|
69
68
|
const setCache = () => {
|
|
70
69
|
_WithMemoryCache.trieCache[key] = {
|
|
71
70
|
..._WithMemoryCache.trieCache[key],
|
|
@@ -142,8 +141,7 @@ var PathTrie = class {
|
|
|
142
141
|
const segments = this.splitUrl(path);
|
|
143
142
|
for (let i = 0; i < segments.length; i++) {
|
|
144
143
|
const segment = segments[i];
|
|
145
|
-
if (i === 0 && segment === "")
|
|
146
|
-
continue;
|
|
144
|
+
if (i === 0 && segment === "") continue;
|
|
147
145
|
if (!Object.hasOwn(cur, segment)) {
|
|
148
146
|
cur[segment] = new PathTrieData();
|
|
149
147
|
}
|
|
@@ -183,8 +181,7 @@ var PathTrie = class {
|
|
|
183
181
|
while ((!wildcard || wildcard.active) && wildcards.length) {
|
|
184
182
|
wildcard = wildcards.pop();
|
|
185
183
|
}
|
|
186
|
-
if (!wildcard || wildcard.active)
|
|
187
|
-
return void 0;
|
|
184
|
+
if (!wildcard || wildcard.active) return void 0;
|
|
188
185
|
wildcard.active = true;
|
|
189
186
|
cur = wildcard == null ? void 0 : wildcard.startTrie;
|
|
190
187
|
wildcards.push(wildcard);
|
|
@@ -225,28 +222,23 @@ var PathTrie = class {
|
|
|
225
222
|
cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
|
|
226
223
|
} else {
|
|
227
224
|
const more = scanWildcards();
|
|
228
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
229
|
-
return [...ret, ...splats];
|
|
225
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
230
226
|
i = more;
|
|
231
227
|
}
|
|
232
228
|
}
|
|
233
229
|
} else {
|
|
234
230
|
const more = scanWildcards();
|
|
235
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
236
|
-
return [...ret, ...splats];
|
|
231
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
237
232
|
i = more;
|
|
238
|
-
if (ret.length > 0 && bestMatch)
|
|
239
|
-
return [...ret, ...splats];
|
|
233
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
240
234
|
continue;
|
|
241
235
|
}
|
|
242
236
|
if (i === segments.length - 1 && wildcards.length !== 0) {
|
|
243
237
|
const more = scanWildcards();
|
|
244
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
245
|
-
return [...ret, ...splats];
|
|
238
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
246
239
|
i = more;
|
|
247
240
|
}
|
|
248
|
-
if (ret.length > 0 && bestMatch)
|
|
249
|
-
return [...ret, ...splats];
|
|
241
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
250
242
|
}
|
|
251
243
|
return [...ret, ...splats];
|
|
252
244
|
}
|
|
@@ -322,8 +314,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
322
314
|
const params1 = new URLSearchParams(qs1);
|
|
323
315
|
const params2 = new URLSearchParams(qs2);
|
|
324
316
|
const merged = new URLSearchParams([...params1, ...params2]).toString();
|
|
325
|
-
if (merged.length > 0)
|
|
326
|
-
return (fragment ? "#" : "?") + merged;
|
|
317
|
+
if (merged.length > 0) return (fragment ? "#" : "?") + merged;
|
|
327
318
|
return "";
|
|
328
319
|
}
|
|
329
320
|
|
|
@@ -354,8 +345,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
354
345
|
const cachePromise = (options == null ? void 0 : options.bypassDataCache) ? void 0 : (_a = this.options.dataCache) == null ? void 0 : _a.get(key);
|
|
355
346
|
if (cachePromise) {
|
|
356
347
|
const result = await cachePromise;
|
|
357
|
-
if (result)
|
|
358
|
-
return result;
|
|
348
|
+
if (result) return result;
|
|
359
349
|
}
|
|
360
350
|
const ret = this.assembleTrie();
|
|
361
351
|
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
|
|
@@ -423,8 +413,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
423
413
|
);
|
|
424
414
|
const processedUrl = processUrl(sanitizedUrl);
|
|
425
415
|
const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
|
|
426
|
-
if (!redirect)
|
|
427
|
-
return void 0;
|
|
416
|
+
if (!redirect) return void 0;
|
|
428
417
|
return _RedirectClient.processDefinitionToResults(
|
|
429
418
|
processedUrl,
|
|
430
419
|
redirect,
|
|
@@ -527,17 +516,14 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
527
516
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
528
517
|
const isCycle = (id, result) => {
|
|
529
518
|
var _a;
|
|
530
|
-
if (!id || !result.lastHop)
|
|
531
|
-
return false;
|
|
519
|
+
if (!id || !result.lastHop) return false;
|
|
532
520
|
const set = /* @__PURE__ */ new Set([id]);
|
|
533
521
|
const cycleStack = [result];
|
|
534
522
|
while (cycleStack.length > 0) {
|
|
535
523
|
const cur = cycleStack.pop();
|
|
536
524
|
const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
|
|
537
|
-
if (!(redirect == null ? void 0 : redirect.id))
|
|
538
|
-
|
|
539
|
-
if (set.has(redirect.id))
|
|
540
|
-
return true;
|
|
525
|
+
if (!(redirect == null ? void 0 : redirect.id)) continue;
|
|
526
|
+
if (set.has(redirect.id)) return true;
|
|
541
527
|
set.add(redirect.id);
|
|
542
528
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
543
529
|
cycleStack.push(cur.lastHop);
|
|
@@ -549,8 +535,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
549
535
|
const ret = [];
|
|
550
536
|
while (stack.length > 0) {
|
|
551
537
|
const result = stack.pop();
|
|
552
|
-
if (!(result == null ? void 0 : result.url))
|
|
553
|
-
continue;
|
|
538
|
+
if (!(result == null ? void 0 : result.url)) continue;
|
|
554
539
|
const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
555
540
|
(h) => {
|
|
556
541
|
var _a, _b;
|
|
@@ -589,8 +574,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
589
574
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
590
575
|
const processedResult = processUrl(resultUrl);
|
|
591
576
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
592
|
-
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
593
|
-
return void 0;
|
|
577
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
|
|
594
578
|
const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
|
|
595
579
|
return {
|
|
596
580
|
url: finalUrl,
|
|
@@ -605,14 +589,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
605
589
|
const processedUrl = processUrl(url);
|
|
606
590
|
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
607
591
|
return false;
|
|
608
|
-
if (processedSource.query && !processedUrl.query)
|
|
609
|
-
return false;
|
|
592
|
+
if (processedSource.query && !processedUrl.query) return false;
|
|
610
593
|
if (processedSource.query && processedUrl.query) {
|
|
611
594
|
const sourceqs = new URLSearchParams(processedSource.query);
|
|
612
595
|
const urlqs = new URLSearchParams(processedUrl.query);
|
|
613
596
|
for (const [key] of sourceqs) {
|
|
614
|
-
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
615
|
-
return false;
|
|
597
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key)) return false;
|
|
616
598
|
}
|
|
617
599
|
}
|
|
618
600
|
return true;
|
package/dist/index.js
CHANGED
|
@@ -110,8 +110,7 @@ var _WithMemoryCache = class _WithMemoryCache extends RedirectClientCache {
|
|
|
110
110
|
/* Set new data to the cache and reset the refresh method */
|
|
111
111
|
set(key, data, refresh) {
|
|
112
112
|
var _a;
|
|
113
|
-
if (!data)
|
|
114
|
-
return;
|
|
113
|
+
if (!data) return;
|
|
115
114
|
const setCache = () => {
|
|
116
115
|
_WithMemoryCache.trieCache[key] = {
|
|
117
116
|
..._WithMemoryCache.trieCache[key],
|
|
@@ -188,8 +187,7 @@ var PathTrie = class {
|
|
|
188
187
|
const segments = this.splitUrl(path);
|
|
189
188
|
for (let i = 0; i < segments.length; i++) {
|
|
190
189
|
const segment = segments[i];
|
|
191
|
-
if (i === 0 && segment === "")
|
|
192
|
-
continue;
|
|
190
|
+
if (i === 0 && segment === "") continue;
|
|
193
191
|
if (!Object.hasOwn(cur, segment)) {
|
|
194
192
|
cur[segment] = new PathTrieData();
|
|
195
193
|
}
|
|
@@ -229,8 +227,7 @@ var PathTrie = class {
|
|
|
229
227
|
while ((!wildcard || wildcard.active) && wildcards.length) {
|
|
230
228
|
wildcard = wildcards.pop();
|
|
231
229
|
}
|
|
232
|
-
if (!wildcard || wildcard.active)
|
|
233
|
-
return void 0;
|
|
230
|
+
if (!wildcard || wildcard.active) return void 0;
|
|
234
231
|
wildcard.active = true;
|
|
235
232
|
cur = wildcard == null ? void 0 : wildcard.startTrie;
|
|
236
233
|
wildcards.push(wildcard);
|
|
@@ -271,28 +268,23 @@ var PathTrie = class {
|
|
|
271
268
|
cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
|
|
272
269
|
} else {
|
|
273
270
|
const more = scanWildcards();
|
|
274
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
275
|
-
return [...ret, ...splats];
|
|
271
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
276
272
|
i = more;
|
|
277
273
|
}
|
|
278
274
|
}
|
|
279
275
|
} else {
|
|
280
276
|
const more = scanWildcards();
|
|
281
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
282
|
-
return [...ret, ...splats];
|
|
277
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
283
278
|
i = more;
|
|
284
|
-
if (ret.length > 0 && bestMatch)
|
|
285
|
-
return [...ret, ...splats];
|
|
279
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
286
280
|
continue;
|
|
287
281
|
}
|
|
288
282
|
if (i === segments.length - 1 && wildcards.length !== 0) {
|
|
289
283
|
const more = scanWildcards();
|
|
290
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
291
|
-
return [...ret, ...splats];
|
|
284
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
292
285
|
i = more;
|
|
293
286
|
}
|
|
294
|
-
if (ret.length > 0 && bestMatch)
|
|
295
|
-
return [...ret, ...splats];
|
|
287
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
296
288
|
}
|
|
297
289
|
return [...ret, ...splats];
|
|
298
290
|
}
|
|
@@ -368,8 +360,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
368
360
|
const params1 = new URLSearchParams(qs1);
|
|
369
361
|
const params2 = new URLSearchParams(qs2);
|
|
370
362
|
const merged = new URLSearchParams([...params1, ...params2]).toString();
|
|
371
|
-
if (merged.length > 0)
|
|
372
|
-
return (fragment ? "#" : "?") + merged;
|
|
363
|
+
if (merged.length > 0) return (fragment ? "#" : "?") + merged;
|
|
373
364
|
return "";
|
|
374
365
|
}
|
|
375
366
|
|
|
@@ -400,8 +391,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
400
391
|
const cachePromise = (options == null ? void 0 : options.bypassDataCache) ? void 0 : (_a = this.options.dataCache) == null ? void 0 : _a.get(key);
|
|
401
392
|
if (cachePromise) {
|
|
402
393
|
const result = await cachePromise;
|
|
403
|
-
if (result)
|
|
404
|
-
return result;
|
|
394
|
+
if (result) return result;
|
|
405
395
|
}
|
|
406
396
|
const ret = this.assembleTrie();
|
|
407
397
|
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
|
|
@@ -469,8 +459,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
469
459
|
);
|
|
470
460
|
const processedUrl = processUrl(sanitizedUrl);
|
|
471
461
|
const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
|
|
472
|
-
if (!redirect)
|
|
473
|
-
return void 0;
|
|
462
|
+
if (!redirect) return void 0;
|
|
474
463
|
return _RedirectClient.processDefinitionToResults(
|
|
475
464
|
processedUrl,
|
|
476
465
|
redirect,
|
|
@@ -573,17 +562,14 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
573
562
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
574
563
|
const isCycle = (id, result) => {
|
|
575
564
|
var _a;
|
|
576
|
-
if (!id || !result.lastHop)
|
|
577
|
-
return false;
|
|
565
|
+
if (!id || !result.lastHop) return false;
|
|
578
566
|
const set = /* @__PURE__ */ new Set([id]);
|
|
579
567
|
const cycleStack = [result];
|
|
580
568
|
while (cycleStack.length > 0) {
|
|
581
569
|
const cur = cycleStack.pop();
|
|
582
570
|
const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
|
|
583
|
-
if (!(redirect == null ? void 0 : redirect.id))
|
|
584
|
-
|
|
585
|
-
if (set.has(redirect.id))
|
|
586
|
-
return true;
|
|
571
|
+
if (!(redirect == null ? void 0 : redirect.id)) continue;
|
|
572
|
+
if (set.has(redirect.id)) return true;
|
|
587
573
|
set.add(redirect.id);
|
|
588
574
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
589
575
|
cycleStack.push(cur.lastHop);
|
|
@@ -595,8 +581,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
595
581
|
const ret = [];
|
|
596
582
|
while (stack.length > 0) {
|
|
597
583
|
const result = stack.pop();
|
|
598
|
-
if (!(result == null ? void 0 : result.url))
|
|
599
|
-
continue;
|
|
584
|
+
if (!(result == null ? void 0 : result.url)) continue;
|
|
600
585
|
const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
601
586
|
(h) => {
|
|
602
587
|
var _a, _b;
|
|
@@ -635,8 +620,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
635
620
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
636
621
|
const processedResult = processUrl(resultUrl);
|
|
637
622
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
638
|
-
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
639
|
-
return void 0;
|
|
623
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
|
|
640
624
|
const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
|
|
641
625
|
return {
|
|
642
626
|
url: finalUrl,
|
|
@@ -651,14 +635,12 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
651
635
|
const processedUrl = processUrl(url);
|
|
652
636
|
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
653
637
|
return false;
|
|
654
|
-
if (processedSource.query && !processedUrl.query)
|
|
655
|
-
return false;
|
|
638
|
+
if (processedSource.query && !processedUrl.query) return false;
|
|
656
639
|
if (processedSource.query && processedUrl.query) {
|
|
657
640
|
const sourceqs = new URLSearchParams(processedSource.query);
|
|
658
641
|
const urlqs = new URLSearchParams(processedUrl.query);
|
|
659
642
|
for (const [key] of sourceqs) {
|
|
660
|
-
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
661
|
-
return false;
|
|
643
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key)) return false;
|
|
662
644
|
}
|
|
663
645
|
}
|
|
664
646
|
return true;
|
package/dist/index.mjs
CHANGED
|
@@ -64,8 +64,7 @@ var _WithMemoryCache = class _WithMemoryCache extends RedirectClientCache {
|
|
|
64
64
|
/* Set new data to the cache and reset the refresh method */
|
|
65
65
|
set(key, data, refresh) {
|
|
66
66
|
var _a;
|
|
67
|
-
if (!data)
|
|
68
|
-
return;
|
|
67
|
+
if (!data) return;
|
|
69
68
|
const setCache = () => {
|
|
70
69
|
_WithMemoryCache.trieCache[key] = {
|
|
71
70
|
..._WithMemoryCache.trieCache[key],
|
|
@@ -142,8 +141,7 @@ var PathTrie = class {
|
|
|
142
141
|
const segments = this.splitUrl(path);
|
|
143
142
|
for (let i = 0; i < segments.length; i++) {
|
|
144
143
|
const segment = segments[i];
|
|
145
|
-
if (i === 0 && segment === "")
|
|
146
|
-
continue;
|
|
144
|
+
if (i === 0 && segment === "") continue;
|
|
147
145
|
if (!Object.hasOwn(cur, segment)) {
|
|
148
146
|
cur[segment] = new PathTrieData();
|
|
149
147
|
}
|
|
@@ -183,8 +181,7 @@ var PathTrie = class {
|
|
|
183
181
|
while ((!wildcard || wildcard.active) && wildcards.length) {
|
|
184
182
|
wildcard = wildcards.pop();
|
|
185
183
|
}
|
|
186
|
-
if (!wildcard || wildcard.active)
|
|
187
|
-
return void 0;
|
|
184
|
+
if (!wildcard || wildcard.active) return void 0;
|
|
188
185
|
wildcard.active = true;
|
|
189
186
|
cur = wildcard == null ? void 0 : wildcard.startTrie;
|
|
190
187
|
wildcards.push(wildcard);
|
|
@@ -225,28 +222,23 @@ var PathTrie = class {
|
|
|
225
222
|
cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
|
|
226
223
|
} else {
|
|
227
224
|
const more = scanWildcards();
|
|
228
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
229
|
-
return [...ret, ...splats];
|
|
225
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
230
226
|
i = more;
|
|
231
227
|
}
|
|
232
228
|
}
|
|
233
229
|
} else {
|
|
234
230
|
const more = scanWildcards();
|
|
235
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
236
|
-
return [...ret, ...splats];
|
|
231
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
237
232
|
i = more;
|
|
238
|
-
if (ret.length > 0 && bestMatch)
|
|
239
|
-
return [...ret, ...splats];
|
|
233
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
240
234
|
continue;
|
|
241
235
|
}
|
|
242
236
|
if (i === segments.length - 1 && wildcards.length !== 0) {
|
|
243
237
|
const more = scanWildcards();
|
|
244
|
-
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
|
|
245
|
-
return [...ret, ...splats];
|
|
238
|
+
if (typeof more === "undefined" || ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
246
239
|
i = more;
|
|
247
240
|
}
|
|
248
|
-
if (ret.length > 0 && bestMatch)
|
|
249
|
-
return [...ret, ...splats];
|
|
241
|
+
if (ret.length > 0 && bestMatch) return [...ret, ...splats];
|
|
250
242
|
}
|
|
251
243
|
return [...ret, ...splats];
|
|
252
244
|
}
|
|
@@ -322,8 +314,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
322
314
|
const params1 = new URLSearchParams(qs1);
|
|
323
315
|
const params2 = new URLSearchParams(qs2);
|
|
324
316
|
const merged = new URLSearchParams([...params1, ...params2]).toString();
|
|
325
|
-
if (merged.length > 0)
|
|
326
|
-
return (fragment ? "#" : "?") + merged;
|
|
317
|
+
if (merged.length > 0) return (fragment ? "#" : "?") + merged;
|
|
327
318
|
return "";
|
|
328
319
|
}
|
|
329
320
|
|
|
@@ -354,8 +345,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
354
345
|
const cachePromise = (options == null ? void 0 : options.bypassDataCache) ? void 0 : (_a = this.options.dataCache) == null ? void 0 : _a.get(key);
|
|
355
346
|
if (cachePromise) {
|
|
356
347
|
const result = await cachePromise;
|
|
357
|
-
if (result)
|
|
358
|
-
return result;
|
|
348
|
+
if (result) return result;
|
|
359
349
|
}
|
|
360
350
|
const ret = this.assembleTrie();
|
|
361
351
|
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie());
|
|
@@ -423,8 +413,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
423
413
|
);
|
|
424
414
|
const processedUrl = processUrl(sanitizedUrl);
|
|
425
415
|
const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
|
|
426
|
-
if (!redirect)
|
|
427
|
-
return void 0;
|
|
416
|
+
if (!redirect) return void 0;
|
|
428
417
|
return _RedirectClient.processDefinitionToResults(
|
|
429
418
|
processedUrl,
|
|
430
419
|
redirect,
|
|
@@ -527,17 +516,14 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
527
516
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
528
517
|
const isCycle = (id, result) => {
|
|
529
518
|
var _a;
|
|
530
|
-
if (!id || !result.lastHop)
|
|
531
|
-
return false;
|
|
519
|
+
if (!id || !result.lastHop) return false;
|
|
532
520
|
const set = /* @__PURE__ */ new Set([id]);
|
|
533
521
|
const cycleStack = [result];
|
|
534
522
|
while (cycleStack.length > 0) {
|
|
535
523
|
const cur = cycleStack.pop();
|
|
536
524
|
const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
|
|
537
|
-
if (!(redirect == null ? void 0 : redirect.id))
|
|
538
|
-
|
|
539
|
-
if (set.has(redirect.id))
|
|
540
|
-
return true;
|
|
525
|
+
if (!(redirect == null ? void 0 : redirect.id)) continue;
|
|
526
|
+
if (set.has(redirect.id)) return true;
|
|
541
527
|
set.add(redirect.id);
|
|
542
528
|
if (cur == null ? void 0 : cur.lastHop) {
|
|
543
529
|
cycleStack.push(cur.lastHop);
|
|
@@ -549,8 +535,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
549
535
|
const ret = [];
|
|
550
536
|
while (stack.length > 0) {
|
|
551
537
|
const result = stack.pop();
|
|
552
|
-
if (!(result == null ? void 0 : result.url))
|
|
553
|
-
continue;
|
|
538
|
+
if (!(result == null ? void 0 : result.url)) continue;
|
|
554
539
|
const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
|
|
555
540
|
(h) => {
|
|
556
541
|
var _a, _b;
|
|
@@ -589,8 +574,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
589
574
|
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
|
|
590
575
|
const processedResult = processUrl(resultUrl);
|
|
591
576
|
const redirect = definition == null ? void 0 : definition.redirect;
|
|
592
|
-
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
|
|
593
|
-
return void 0;
|
|
577
|
+
if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
|
|
594
578
|
const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
|
|
595
579
|
return {
|
|
596
580
|
url: finalUrl,
|
|
@@ -605,14 +589,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
605
589
|
const processedUrl = processUrl(url);
|
|
606
590
|
if (redirectDefinition.sourceMustMatchDomain && processedSource.domain !== processedUrl.domain)
|
|
607
591
|
return false;
|
|
608
|
-
if (processedSource.query && !processedUrl.query)
|
|
609
|
-
return false;
|
|
592
|
+
if (processedSource.query && !processedUrl.query) return false;
|
|
610
593
|
if (processedSource.query && processedUrl.query) {
|
|
611
594
|
const sourceqs = new URLSearchParams(processedSource.query);
|
|
612
595
|
const urlqs = new URLSearchParams(processedUrl.query);
|
|
613
596
|
for (const [key] of sourceqs) {
|
|
614
|
-
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key))
|
|
615
|
-
return false;
|
|
597
|
+
if (!urlqs.has(key) || urlqs.get(key) !== sourceqs.get(key)) return false;
|
|
616
598
|
}
|
|
617
599
|
}
|
|
618
600
|
return true;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/redirect",
|
|
3
|
-
"version": "19.159.
|
|
3
|
+
"version": "19.159.1-alpha.27+344f3d36db",
|
|
4
4
|
"description": "Uniform redirect client",
|
|
5
5
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -33,12 +33,12 @@
|
|
|
33
33
|
"/dist"
|
|
34
34
|
],
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@uniformdev/context": "19.159.
|
|
36
|
+
"@uniformdev/context": "19.159.1-alpha.27+344f3d36db",
|
|
37
37
|
"p-limit": "^3.1.0",
|
|
38
38
|
"rfdc": "^1.3.0"
|
|
39
39
|
},
|
|
40
40
|
"publishConfig": {
|
|
41
41
|
"access": "public"
|
|
42
42
|
},
|
|
43
|
-
"gitHead": "
|
|
43
|
+
"gitHead": "344f3d36dba87d4e2340a1687c20b163be1d2c83"
|
|
44
44
|
}
|