@uniformdev/redirect
Advanced tools
Comparing version 19.8.0 to 19.9.2-alpha.3
@@ -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 @@ } |
{ | ||
"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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
93605
2356
2
1
- Removed@uniformdev/context@19.8.0(transitive)
- Removeddequal@2.0.3(transitive)
- Removedjs-cookie@3.0.5(transitive)
- Removedmitt@3.0.1(transitive)
- Removedrfdc@1.4.1(transitive)