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
464
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.8.0 to 19.9.2-alpha.3

51

./dist/index.js

@@ -438,5 +438,52 @@ "use strict";

}
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
const processedTarget = this.processUrl(redirectDefinition.targetUrl);
const processedSource = this.processUrl(redirectDefinition.sourceUrl);
let finalUrlPath = processedTarget.path;
const processedUrl = this.processUrl(url);
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
for (const variable in variables) {
finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
}
const protocol = redirectDefinition.targetPreserveIncomingProtocol ? processedUrl.protocol : processedTarget.protocol;
const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
const port = processedTarget.port;
const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
}
static mergeQueryStrings(qs1, qs2) {
let fragment = false;
if (qs1.startsWith("#")) {
fragment = true;
qs1 = qs1.substring(1);
}
if (qs2.startsWith("#")) {
fragment = true;
qs2 = qs2.substring(1);
}
const params1 = new URLSearchParams(qs1);
const params2 = new URLSearchParams(qs2);
const merged = new URLSearchParams([...params1, ...params2]).toString();
if (merged.length > 0)
return (fragment ? "#" : "?") + merged;
return "";
}
static getSourceVariables(path, source, isVariable = (pathSegment) => pathSegment.startsWith(":")) {
const variables = {};
const pathSegments = path.split("/");
const sourceSegments = source.split("/");
if (pathSegments.length !== sourceSegments.length) {
throw new Error("Path and source have different numbers of path segments, must be the same");
}
sourceSegments.forEach((sourceSegment, i) => {
if (isVariable(sourceSegment)) {
variables[sourceSegment] = pathSegments[i];
}
});
return variables;
}
static processUrl(url) {
var _a, _b, _c, _d, _e, _f;
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?::([0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
return {

@@ -449,3 +496,3 @@ url,

query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
hash: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
};

@@ -452,0 +499,0 @@ }

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

private static processDefinitionToResults;
static getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string) => boolean): string;
private static mergeQueryStrings;
private static getSourceVariables;
private static processUrl;

@@ -109,2 +112,4 @@ }

ids?: string[];
/** Source url to attempt to find redirects for */
sourceUrl?: string;
/** Id of the project map the source or target belongs to. */

@@ -111,0 +116,0 @@ projectMapId?: string;

@@ -408,5 +408,52 @@ // src/cache/redirectClientCache.ts

}
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
const processedTarget = this.processUrl(redirectDefinition.targetUrl);
const processedSource = this.processUrl(redirectDefinition.sourceUrl);
let finalUrlPath = processedTarget.path;
const processedUrl = this.processUrl(url);
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
for (const variable in variables) {
finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
}
const protocol = redirectDefinition.targetPreserveIncomingProtocol ? processedUrl.protocol : processedTarget.protocol;
const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
const port = processedTarget.port;
const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
}
static mergeQueryStrings(qs1, qs2) {
let fragment = false;
if (qs1.startsWith("#")) {
fragment = true;
qs1 = qs1.substring(1);
}
if (qs2.startsWith("#")) {
fragment = true;
qs2 = qs2.substring(1);
}
const params1 = new URLSearchParams(qs1);
const params2 = new URLSearchParams(qs2);
const merged = new URLSearchParams([...params1, ...params2]).toString();
if (merged.length > 0)
return (fragment ? "#" : "?") + merged;
return "";
}
static getSourceVariables(path, source, isVariable = (pathSegment) => pathSegment.startsWith(":")) {
const variables = {};
const pathSegments = path.split("/");
const sourceSegments = source.split("/");
if (pathSegments.length !== sourceSegments.length) {
throw new Error("Path and source have different numbers of path segments, must be the same");
}
sourceSegments.forEach((sourceSegment, i) => {
if (isVariable(sourceSegment)) {
variables[sourceSegment] = pathSegments[i];
}
});
return variables;
}
static processUrl(url) {
var _a, _b, _c, _d, _e, _f;
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?::([0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
return {

@@ -419,3 +466,3 @@ url,

query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
hash: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
};

@@ -422,0 +469,0 @@ }

@@ -438,5 +438,52 @@ "use strict";

}
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
const processedTarget = this.processUrl(redirectDefinition.targetUrl);
const processedSource = this.processUrl(redirectDefinition.sourceUrl);
let finalUrlPath = processedTarget.path;
const processedUrl = this.processUrl(url);
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
for (const variable in variables) {
finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
}
const protocol = redirectDefinition.targetPreserveIncomingProtocol ? processedUrl.protocol : processedTarget.protocol;
const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
const port = processedTarget.port;
const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
}
static mergeQueryStrings(qs1, qs2) {
let fragment = false;
if (qs1.startsWith("#")) {
fragment = true;
qs1 = qs1.substring(1);
}
if (qs2.startsWith("#")) {
fragment = true;
qs2 = qs2.substring(1);
}
const params1 = new URLSearchParams(qs1);
const params2 = new URLSearchParams(qs2);
const merged = new URLSearchParams([...params1, ...params2]).toString();
if (merged.length > 0)
return (fragment ? "#" : "?") + merged;
return "";
}
static getSourceVariables(path, source, isVariable = (pathSegment) => pathSegment.startsWith(":")) {
const variables = {};
const pathSegments = path.split("/");
const sourceSegments = source.split("/");
if (pathSegments.length !== sourceSegments.length) {
throw new Error("Path and source have different numbers of path segments, must be the same");
}
sourceSegments.forEach((sourceSegment, i) => {
if (isVariable(sourceSegment)) {
variables[sourceSegment] = pathSegments[i];
}
});
return variables;
}
static processUrl(url) {
var _a, _b, _c, _d, _e, _f;
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?::([0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
return {

@@ -449,3 +496,3 @@ url,

query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
hash: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
};

@@ -452,0 +499,0 @@ }

6

package.json
{
"name": "@uniformdev/redirect",
"version": "19.8.0",
"version": "19.9.2-alpha.3+547c8b11d",
"description": "Uniform redirect client",

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

"dependencies": {
"@uniformdev/context": "19.8.0",
"@uniformdev/context": "19.9.2-alpha.3+547c8b11d",
"p-limit": "^3.1.0"

@@ -42,3 +42,3 @@ },

},
"gitHead": "70eb9277bbfaee5f9245e1b26b4e77caede22944"
"gitHead": "547c8b11d4655b34250c2fbe3f016c9bc12c3905"
}

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