Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@uniformdev/redirect

Package Overview
Dependencies
Maintainers
10
Versions
468
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@uniformdev/redirect - npm Package Compare versions

Comparing version 19.27.1-alpha.3 to 19.29.0

143

./dist/index.js

@@ -329,2 +329,40 @@ "use strict";

// src/cache/data/refresher.ts
var Refresher = class {
/**
* Create new refresher
* @param refreshRate - How often the refresher will refresh. Cannot be less than 20000 ms or 20 seconds
* @param refreshDuration - How many times it should refresh before sleeps until something accesses the cache. Cannot be more than 5
* @param refresh - Refresh method to run at the refresh rate intervals
*/
constructor({ refreshRate, refreshDuration, refresh }) {
this.refreshCounter = 0;
this.finalRate = refreshRate >= 2e4 ? refreshRate : 2e4;
this.finalDuration = refreshDuration <= 5 ? refreshDuration : 5;
this.refreshCounter = 1;
this.refresh = refresh;
this.start();
}
/**
* Start async updating process again, will run for the same duration as the original. refreshRate * refreshDuration milliseconds
*/
kick() {
if (this.refreshCounter === 0) {
this.start();
}
this.refreshCounter = 1;
}
start() {
this.interval = setTimeout(async () => {
if (this.refreshCounter > this.finalDuration) {
this.refreshCounter = 0;
} else {
await this.refresh();
this.refreshCounter++;
this.start();
}
}, this.finalRate);
}
};
// src/cache/redirectClientCache.ts

@@ -341,7 +379,15 @@ var RedirectClientCache = class {

super(options);
if (options.refreshRate && !_WithMemoryCache.refresher) {
_WithMemoryCache.refresher = new Refresher({
refreshRate: options.refreshRate,
refreshDuration: 5,
refresh: this.refresh
});
}
}
/* Get data from the cache and debounce pausing refresh */
get(key) {
var _a, _b;
return (_b = (_a = _WithMemoryCache.trieCache[key]) == null ? void 0 : _a.data) != null ? _b : void 0;
var _a, _b, _c;
(_a = _WithMemoryCache.refresher) == null ? void 0 : _a.kick();
return (_c = (_b = _WithMemoryCache.trieCache[key]) == null ? void 0 : _b.data) != null ? _c : void 0;
}

@@ -370,2 +416,3 @@ /* Set new data to the cache and reset the refresh method */

var _a, _b;
const caches = [];
for (const key in _WithMemoryCache.trieCache) {

@@ -375,5 +422,6 @@ const p = (_b = (_a = _WithMemoryCache.trieCache[key]) == null ? void 0 : _a.refresh) == null ? void 0 : _b.call(_a);

_WithMemoryCache.trieCache[key] = { ..._WithMemoryCache.trieCache[key], data: p };
caches.push(p.then());
}
}
return Promise.all([]);
return Promise.all(caches);
}

@@ -463,3 +511,3 @@ };

};
const scanWildcards = () => {
const scanWildcards = (i) => {
let wildcard = void 0;

@@ -474,2 +522,7 @@ while ((!wildcard || wildcard.active) && wildcards.length) {

wildcards.push(wildcard);
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
(d) => ret.push({ data: d, variables: getVariables() })
);
}
return wildcard == null ? void 0 : wildcard.start;

@@ -503,17 +556,18 @@ };

cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
} else {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];
i = more;
}
}
} else if (i === segments.length - 1) {
const more = scanWildcards();
if (typeof more === "undefined")
} else {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];
i = more;
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
(d) => ret.push({ data: d, variables: getVariables() })
);
}
} else {
const more = scanWildcards();
if (typeof more === "undefined")
}
if (i === segments.length - 1 && wildcards.length !== 0) {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];

@@ -678,18 +732,25 @@ i = more;

async assembleTrie() {
const trie = new PathTrie();
for await (const redirect of this.getAllRedirects()) {
const source = processUrl(redirect.redirect.sourceUrl);
const target = processUrl(redirect.redirect.targetUrl);
trie.insert(source.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: false
});
trie.insert(target.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: true
});
if (!_RedirectClient.assembling) {
_RedirectClient.assembling = true;
_RedirectClient.assemblingPromise = (async () => {
const trie = new PathTrie();
for await (const redirect of this.getAllRedirects()) {
const source = processUrl(redirect.redirect.sourceUrl);
const target = processUrl(redirect.redirect.targetUrl);
trie.insert(source.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: false
});
trie.insert(target.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: true
});
}
_RedirectClient.assembling = false;
return trie;
})();
}
return trie;
return await _RedirectClient.assemblingPromise;
}

@@ -766,3 +827,2 @@ static processHops(url, trie, bestMatch, options) {

static processDefinitionToResults(processedUrl, definition, variables, options) {
var _a, _b, _c, _d, _e;
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;

@@ -773,10 +833,5 @@ const processedResult = processUrl(resultUrl);

return void 0;
const protocol = redirect.targetPreserveIncomingProtocol ? processedUrl.protocol : (_b = (_a = processedResult.protocol) != null ? _a : processedUrl.protocol) != null ? _b : "";
const domain = redirect.targetPreserveIncomingDomain ? processedUrl.domain : (_d = (_c = processedResult.domain) != null ? _c : processedUrl.domain) != null ? _d : "";
const queryString = redirect.sourceRetainQuerystring && processedResult.query ? (_e = processedResult.query) != null ? _e : "" : definition.redirect.sourceRetainQuerystring ? processedUrl.query : "";
const finalUrl = `${protocol}${domain}${processedResult.port}${processedResult.path}${queryString}`;
const finalUrl = _RedirectClient.getTargetVariableExpandedUrl(processedUrl.url, redirect);
return {
url: variables.reduce((cur, o) => {
return cur.replace(o.key, o.value);
}, finalUrl),
url: finalUrl,
definition,

@@ -816,3 +871,3 @@ label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {

const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
const port = processedTarget.port;
const port = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.port : processedTarget.port;
const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;

@@ -839,11 +894,11 @@ const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;

}
static getSourceVariables(path, source, isVariable = (pathSegment) => pathSegment.startsWith(":")) {
static getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
const variables = {};
const pathSegments = path.split("/");
const sourceSegments = source.split("/");
if (pathSegments.length !== sourceSegments.length) {
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
throw new Error("Path and source have different numbers of path segments, must be the same");
}
sourceSegments.forEach((sourceSegment, i) => {
if (isVariable(sourceSegment)) {
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
variables[sourceSegment] = pathSegments[i];

@@ -860,2 +915,6 @@ }

};
RedirectClient.assembling = false;
RedirectClient.assemblingPromise = new Promise(
() => new PathTrie()
);
var UncachedRedirectClient = class extends RedirectClient {

@@ -862,0 +921,0 @@ constructor(options) {

@@ -101,2 +101,4 @@ import { ClientOptions, ApiClient } from '@uniformdev/context/api';

processUrlAllMatches: (url: string, options?: RedirectOptions) => Promise<RedirectResult[]>;
private static assembling;
private static assemblingPromise;
private assembleTrie;

@@ -395,2 +397,3 @@ private static processHops;

declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
private static refresher?;
constructor(options: RedirectClientCacheOptions);

@@ -397,0 +400,0 @@ private static trieCache;

import "./chunk-FFYIGW52.mjs";
// src/cache/data/refresher.ts
var Refresher = class {
/**
* Create new refresher
* @param refreshRate - How often the refresher will refresh. Cannot be less than 20000 ms or 20 seconds
* @param refreshDuration - How many times it should refresh before sleeps until something accesses the cache. Cannot be more than 5
* @param refresh - Refresh method to run at the refresh rate intervals
*/
constructor({ refreshRate, refreshDuration, refresh }) {
this.refreshCounter = 0;
this.finalRate = refreshRate >= 2e4 ? refreshRate : 2e4;
this.finalDuration = refreshDuration <= 5 ? refreshDuration : 5;
this.refreshCounter = 1;
this.refresh = refresh;
this.start();
}
/**
* Start async updating process again, will run for the same duration as the original. refreshRate * refreshDuration milliseconds
*/
kick() {
if (this.refreshCounter === 0) {
this.start();
}
this.refreshCounter = 1;
}
start() {
this.interval = setTimeout(async () => {
if (this.refreshCounter > this.finalDuration) {
this.refreshCounter = 0;
} else {
await this.refresh();
this.refreshCounter++;
this.start();
}
}, this.finalRate);
}
};
// src/cache/redirectClientCache.ts

@@ -14,7 +52,15 @@ var RedirectClientCache = class {

super(options);
if (options.refreshRate && !_WithMemoryCache.refresher) {
_WithMemoryCache.refresher = new Refresher({
refreshRate: options.refreshRate,
refreshDuration: 5,
refresh: this.refresh
});
}
}
/* Get data from the cache and debounce pausing refresh */
get(key) {
var _a, _b;
return (_b = (_a = _WithMemoryCache.trieCache[key]) == null ? void 0 : _a.data) != null ? _b : void 0;
var _a, _b, _c;
(_a = _WithMemoryCache.refresher) == null ? void 0 : _a.kick();
return (_c = (_b = _WithMemoryCache.trieCache[key]) == null ? void 0 : _b.data) != null ? _c : void 0;
}

@@ -43,2 +89,3 @@ /* Set new data to the cache and reset the refresh method */

var _a, _b;
const caches = [];
for (const key in _WithMemoryCache.trieCache) {

@@ -48,5 +95,6 @@ const p = (_b = (_a = _WithMemoryCache.trieCache[key]) == null ? void 0 : _a.refresh) == null ? void 0 : _b.call(_a);

_WithMemoryCache.trieCache[key] = { ..._WithMemoryCache.trieCache[key], data: p };
caches.push(p.then());
}
}
return Promise.all([]);
return Promise.all(caches);
}

@@ -136,3 +184,3 @@ };

};
const scanWildcards = () => {
const scanWildcards = (i) => {
let wildcard = void 0;

@@ -147,2 +195,7 @@ while ((!wildcard || wildcard.active) && wildcards.length) {

wildcards.push(wildcard);
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
(d) => ret.push({ data: d, variables: getVariables() })
);
}
return wildcard == null ? void 0 : wildcard.start;

@@ -176,17 +229,18 @@ };

cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
} else {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];
i = more;
}
}
} else if (i === segments.length - 1) {
const more = scanWildcards();
if (typeof more === "undefined")
} else {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];
i = more;
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
(d) => ret.push({ data: d, variables: getVariables() })
);
}
} else {
const more = scanWildcards();
if (typeof more === "undefined")
}
if (i === segments.length - 1 && wildcards.length !== 0) {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];

@@ -351,18 +405,25 @@ i = more;

async assembleTrie() {
const trie = new PathTrie();
for await (const redirect of this.getAllRedirects()) {
const source = processUrl(redirect.redirect.sourceUrl);
const target = processUrl(redirect.redirect.targetUrl);
trie.insert(source.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: false
});
trie.insert(target.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: true
});
if (!_RedirectClient.assembling) {
_RedirectClient.assembling = true;
_RedirectClient.assemblingPromise = (async () => {
const trie = new PathTrie();
for await (const redirect of this.getAllRedirects()) {
const source = processUrl(redirect.redirect.sourceUrl);
const target = processUrl(redirect.redirect.targetUrl);
trie.insert(source.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: false
});
trie.insert(target.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: true
});
}
_RedirectClient.assembling = false;
return trie;
})();
}
return trie;
return await _RedirectClient.assemblingPromise;
}

@@ -439,3 +500,2 @@ static processHops(url, trie, bestMatch, options) {

static processDefinitionToResults(processedUrl, definition, variables, options) {
var _a, _b, _c, _d, _e;
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;

@@ -446,10 +506,5 @@ const processedResult = processUrl(resultUrl);

return void 0;
const protocol = redirect.targetPreserveIncomingProtocol ? processedUrl.protocol : (_b = (_a = processedResult.protocol) != null ? _a : processedUrl.protocol) != null ? _b : "";
const domain = redirect.targetPreserveIncomingDomain ? processedUrl.domain : (_d = (_c = processedResult.domain) != null ? _c : processedUrl.domain) != null ? _d : "";
const queryString = redirect.sourceRetainQuerystring && processedResult.query ? (_e = processedResult.query) != null ? _e : "" : definition.redirect.sourceRetainQuerystring ? processedUrl.query : "";
const finalUrl = `${protocol}${domain}${processedResult.port}${processedResult.path}${queryString}`;
const finalUrl = _RedirectClient.getTargetVariableExpandedUrl(processedUrl.url, redirect);
return {
url: variables.reduce((cur, o) => {
return cur.replace(o.key, o.value);
}, finalUrl),
url: finalUrl,
definition,

@@ -489,3 +544,3 @@ label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {

const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
const port = processedTarget.port;
const port = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.port : processedTarget.port;
const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;

@@ -512,11 +567,11 @@ const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;

}
static getSourceVariables(path, source, isVariable = (pathSegment) => pathSegment.startsWith(":")) {
static getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
const variables = {};
const pathSegments = path.split("/");
const sourceSegments = source.split("/");
if (pathSegments.length !== sourceSegments.length) {
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
throw new Error("Path and source have different numbers of path segments, must be the same");
}
sourceSegments.forEach((sourceSegment, i) => {
if (isVariable(sourceSegment)) {
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
variables[sourceSegment] = pathSegments[i];

@@ -533,2 +588,6 @@ }

};
RedirectClient.assembling = false;
RedirectClient.assemblingPromise = new Promise(
() => new PathTrie()
);
var UncachedRedirectClient = class extends RedirectClient {

@@ -535,0 +594,0 @@ constructor(options) {

@@ -329,2 +329,40 @@ "use strict";

// src/cache/data/refresher.ts
var Refresher = class {
/**
* Create new refresher
* @param refreshRate - How often the refresher will refresh. Cannot be less than 20000 ms or 20 seconds
* @param refreshDuration - How many times it should refresh before sleeps until something accesses the cache. Cannot be more than 5
* @param refresh - Refresh method to run at the refresh rate intervals
*/
constructor({ refreshRate, refreshDuration, refresh }) {
this.refreshCounter = 0;
this.finalRate = refreshRate >= 2e4 ? refreshRate : 2e4;
this.finalDuration = refreshDuration <= 5 ? refreshDuration : 5;
this.refreshCounter = 1;
this.refresh = refresh;
this.start();
}
/**
* Start async updating process again, will run for the same duration as the original. refreshRate * refreshDuration milliseconds
*/
kick() {
if (this.refreshCounter === 0) {
this.start();
}
this.refreshCounter = 1;
}
start() {
this.interval = setTimeout(async () => {
if (this.refreshCounter > this.finalDuration) {
this.refreshCounter = 0;
} else {
await this.refresh();
this.refreshCounter++;
this.start();
}
}, this.finalRate);
}
};
// src/cache/redirectClientCache.ts

@@ -341,7 +379,15 @@ var RedirectClientCache = class {

super(options);
if (options.refreshRate && !_WithMemoryCache.refresher) {
_WithMemoryCache.refresher = new Refresher({
refreshRate: options.refreshRate,
refreshDuration: 5,
refresh: this.refresh
});
}
}
/* Get data from the cache and debounce pausing refresh */
get(key) {
var _a, _b;
return (_b = (_a = _WithMemoryCache.trieCache[key]) == null ? void 0 : _a.data) != null ? _b : void 0;
var _a, _b, _c;
(_a = _WithMemoryCache.refresher) == null ? void 0 : _a.kick();
return (_c = (_b = _WithMemoryCache.trieCache[key]) == null ? void 0 : _b.data) != null ? _c : void 0;
}

@@ -370,2 +416,3 @@ /* Set new data to the cache and reset the refresh method */

var _a, _b;
const caches = [];
for (const key in _WithMemoryCache.trieCache) {

@@ -375,5 +422,6 @@ const p = (_b = (_a = _WithMemoryCache.trieCache[key]) == null ? void 0 : _a.refresh) == null ? void 0 : _b.call(_a);

_WithMemoryCache.trieCache[key] = { ..._WithMemoryCache.trieCache[key], data: p };
caches.push(p.then());
}
}
return Promise.all([]);
return Promise.all(caches);
}

@@ -463,3 +511,3 @@ };

};
const scanWildcards = () => {
const scanWildcards = (i) => {
let wildcard = void 0;

@@ -474,2 +522,7 @@ while ((!wildcard || wildcard.active) && wildcards.length) {

wildcards.push(wildcard);
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
(d) => ret.push({ data: d, variables: getVariables() })
);
}
return wildcard == null ? void 0 : wildcard.start;

@@ -503,17 +556,18 @@ };

cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
} else {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];
i = more;
}
}
} else if (i === segments.length - 1) {
const more = scanWildcards();
if (typeof more === "undefined")
} else {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];
i = more;
if (i === segments.length - 1 && wildcards.length && wildcards[wildcards.length - 1].active && wildcards[wildcards.length - 1].startTrie[dataProp]) {
wildcards[wildcards.length - 1].startTrie[dataProp].forEach(
(d) => ret.push({ data: d, variables: getVariables() })
);
}
} else {
const more = scanWildcards();
if (typeof more === "undefined")
}
if (i === segments.length - 1 && wildcards.length !== 0) {
const more = scanWildcards(i);
if (typeof more === "undefined" || ret.length > 0 && bestMatch)
return [...ret, ...splats];

@@ -678,18 +732,25 @@ i = more;

async assembleTrie() {
const trie = new PathTrie();
for await (const redirect of this.getAllRedirects()) {
const source = processUrl(redirect.redirect.sourceUrl);
const target = processUrl(redirect.redirect.targetUrl);
trie.insert(source.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: false
});
trie.insert(target.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: true
});
if (!_RedirectClient.assembling) {
_RedirectClient.assembling = true;
_RedirectClient.assemblingPromise = (async () => {
const trie = new PathTrie();
for await (const redirect of this.getAllRedirects()) {
const source = processUrl(redirect.redirect.sourceUrl);
const target = processUrl(redirect.redirect.targetUrl);
trie.insert(source.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: false
});
trie.insert(target.path, {
redirect: redirect.redirect,
metadata: redirect.metadata,
reverse: true
});
}
_RedirectClient.assembling = false;
return trie;
})();
}
return trie;
return await _RedirectClient.assemblingPromise;
}

@@ -766,3 +827,2 @@ static processHops(url, trie, bestMatch, options) {

static processDefinitionToResults(processedUrl, definition, variables, options) {
var _a, _b, _c, _d, _e;
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;

@@ -773,10 +833,5 @@ const processedResult = processUrl(resultUrl);

return void 0;
const protocol = redirect.targetPreserveIncomingProtocol ? processedUrl.protocol : (_b = (_a = processedResult.protocol) != null ? _a : processedUrl.protocol) != null ? _b : "";
const domain = redirect.targetPreserveIncomingDomain ? processedUrl.domain : (_d = (_c = processedResult.domain) != null ? _c : processedUrl.domain) != null ? _d : "";
const queryString = redirect.sourceRetainQuerystring && processedResult.query ? (_e = processedResult.query) != null ? _e : "" : definition.redirect.sourceRetainQuerystring ? processedUrl.query : "";
const finalUrl = `${protocol}${domain}${processedResult.port}${processedResult.path}${queryString}`;
const finalUrl = _RedirectClient.getTargetVariableExpandedUrl(processedUrl.url, redirect);
return {
url: variables.reduce((cur, o) => {
return cur.replace(o.key, o.value);
}, finalUrl),
url: finalUrl,
definition,

@@ -816,3 +871,3 @@ label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {

const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
const port = processedTarget.port;
const port = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.port : processedTarget.port;
const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;

@@ -839,11 +894,11 @@ const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;

}
static getSourceVariables(path, source, isVariable = (pathSegment) => pathSegment.startsWith(":")) {
static getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
const variables = {};
const pathSegments = path.split("/");
const sourceSegments = source.split("/");
if (pathSegments.length !== sourceSegments.length) {
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
throw new Error("Path and source have different numbers of path segments, must be the same");
}
sourceSegments.forEach((sourceSegment, i) => {
if (isVariable(sourceSegment)) {
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
variables[sourceSegment] = pathSegments[i];

@@ -860,2 +915,6 @@ }

};
RedirectClient.assembling = false;
RedirectClient.assemblingPromise = new Promise(
() => new PathTrie()
);
var UncachedRedirectClient = class extends RedirectClient {

@@ -862,0 +921,0 @@ constructor(options) {

{
"name": "@uniformdev/redirect",
"version": "19.27.1-alpha.3+9f5adae97",
"version": "19.29.0",
"description": "Uniform redirect client",

@@ -35,3 +35,3 @@ "license": "SEE LICENSE IN LICENSE.txt",

"dependencies": {
"@uniformdev/context": "19.27.1-alpha.3+9f5adae97",
"@uniformdev/context": "19.29.0",
"p-limit": "^3.1.0",

@@ -43,3 +43,3 @@ "rfdc": "^1.3.0"

},
"gitHead": "9f5adae974295b306b539dea3657d728fed7f527"
"gitHead": "f8e9d5f6283fb3d72ba095c0e307907dc591ce4a"
}

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc