@uniformdev/redirect
Advanced tools
Comparing version 19.15.0 to 19.17.0
@@ -191,3 +191,4 @@ "use strict"; | ||
UncachedRedirectClient: () => UncachedRedirectClient, | ||
WithMemoryCache: () => WithMemoryCache | ||
WithMemoryCache: () => WithMemoryCache, | ||
processUrl: () => processUrl | ||
}); | ||
@@ -393,2 +394,19 @@ module.exports = __toCommonJS(src_exports); | ||
var import_api = require("@uniformdev/context/api"); | ||
// src/util/url.ts | ||
function processUrl(url) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/); | ||
return { | ||
url, | ||
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "", | ||
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "", | ||
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "", | ||
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "", | ||
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "", | ||
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : "" | ||
}; | ||
} | ||
// src/redirectClient.ts | ||
var _RedirectClient = class extends import_api.ApiClient { | ||
@@ -420,4 +438,4 @@ constructor(options) { | ||
} | ||
const ret = this.assembleTrie(projectId, options); | ||
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId, options)); | ||
const ret = this.assembleTrie(options); | ||
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(options)); | ||
return ret; | ||
@@ -500,21 +518,33 @@ }; | ||
} | ||
async assembleTrie(projectId, options) { | ||
var _a; | ||
const trie = new PathTrie(); | ||
let offset = 0; | ||
let total = 0; | ||
do { | ||
async *getAllRedirects(orderBy = "updated_at desc") { | ||
var _a, _b; | ||
const { projectId } = this.options; | ||
let requestCount = 0; | ||
let results = void 0; | ||
while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) { | ||
const fetchUri = this.createUrl("/api/v1/redirect", { | ||
projectId, | ||
limit: 50, | ||
offset | ||
offset: requestCount * 50, | ||
orderBy, | ||
projectId | ||
}); | ||
const redirects = await this.apiClient(fetchUri); | ||
trie.insertMany( | ||
redirects.redirects, | ||
(r) => (options == null ? void 0 : options.reverse) ? r.redirect.targetUrl : r.redirect.sourceUrl | ||
); | ||
total = (_a = redirects.total) != null ? _a : 0; | ||
offset += 50; | ||
} while (offset < total); | ||
results = await this.apiClient(fetchUri); | ||
const redirectCount = results.redirects.length; | ||
for (let i = 0; i < redirectCount; i++) { | ||
yield { total: results.total, ...results.redirects[i] }; | ||
} | ||
requestCount++; | ||
if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) { | ||
break; | ||
} | ||
} | ||
} | ||
async assembleTrie(options) { | ||
const trie = new PathTrie(); | ||
for await (const redirect of this.getAllRedirects()) { | ||
const path = processUrl( | ||
(options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl | ||
).path; | ||
trie.insert(path, redirect); | ||
} | ||
return trie; | ||
@@ -567,3 +597,3 @@ } | ||
static processHop(url, trie, bestMatch, options) { | ||
const processedUrl = this.processUrl(url); | ||
const processedUrl = processUrl(url); | ||
let definition = trie.find(url, false); | ||
@@ -593,3 +623,3 @@ if (!(definition == null ? void 0 : definition.length)) { | ||
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl; | ||
const processedResult = this.processUrl(resultUrl); | ||
const processedResult = processUrl(resultUrl); | ||
const redirect = definition == null ? void 0 : definition.redirect; | ||
@@ -613,6 +643,6 @@ if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) | ||
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) { | ||
const processedTarget = this.processUrl(redirectDefinition.targetUrl); | ||
const processedSource = this.processUrl(redirectDefinition.sourceUrl); | ||
const processedTarget = processUrl(redirectDefinition.targetUrl); | ||
const processedSource = processUrl(redirectDefinition.sourceUrl); | ||
let finalUrlPath = processedTarget.path; | ||
const processedUrl = this.processUrl(url); | ||
const processedUrl = processUrl(url); | ||
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable); | ||
@@ -660,15 +690,2 @@ for (const variable in variables) { | ||
} | ||
static processUrl(url) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/); | ||
return { | ||
url, | ||
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "", | ||
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "", | ||
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "", | ||
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "", | ||
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "", | ||
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : "" | ||
}; | ||
} | ||
}; | ||
@@ -766,3 +783,4 @@ var RedirectClient = _RedirectClient; | ||
UncachedRedirectClient, | ||
WithMemoryCache | ||
WithMemoryCache, | ||
processUrl | ||
}); |
@@ -67,2 +67,27 @@ import { ClientOptions, ApiClient } from '@uniformdev/context/api'; | ||
getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>; | ||
getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{ | ||
redirect: { | ||
id?: string | undefined; | ||
sourceUrl: string; | ||
targetUrl: string; | ||
targetStatusCode: number; | ||
sourceProjectMapNodeId?: string | undefined; | ||
targetProjectMapNodeId?: string | undefined; | ||
projectMapId?: string | undefined; | ||
sourceRetainQuerystring?: boolean | undefined; | ||
sourceMustMatchDomain?: boolean | undefined; | ||
targetPreserveIncomingProtocol?: boolean | undefined; | ||
targetPreserveIncomingDomain?: boolean | undefined; | ||
stopExecutingAfter?: boolean | undefined; | ||
targetMergeQuerystring?: boolean | undefined; | ||
labelAsSystem?: boolean | undefined; | ||
}; | ||
metadata: { | ||
updatedAt?: string | undefined; | ||
updatedBy?: string | undefined; | ||
createdAt?: string | undefined; | ||
createdBy?: string | undefined; | ||
}; | ||
total: number | undefined; | ||
}, void, unknown>; | ||
getRedirectTrie: (options?: { | ||
@@ -92,3 +117,2 @@ reverse?: boolean; | ||
private static getSourceVariables; | ||
private static processUrl; | ||
} | ||
@@ -397,2 +421,27 @@ declare class UncachedRedirectClient extends RedirectClient { | ||
export { ExtractWildcards, PathTrie, PathTrieData, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn }; | ||
/** | ||
* @typedef {Object} ProcessedUrl | ||
* @property {string} url - The full url used during processing | ||
* @property {string} path - The path portion of the URL | ||
* @property {string} domain - The domain of the URL | ||
* @property {string} port - The port of the URL | ||
* @property {string} query - The querystring of the URL | ||
* @property {string} fragment - The fragment of the URL | ||
* @property {string} protocol - The protocol of the URL | ||
*/ | ||
type ProcessedUrl = { | ||
url: string; | ||
path: string; | ||
domain: string; | ||
port: string; | ||
query: string; | ||
fragment: string; | ||
protocol: string; | ||
}; | ||
/** | ||
* Breaks a url into the separate parts for processing | ||
* @returns {ProcessedUrl} The url broken down into independent components | ||
*/ | ||
declare function processUrl(url: string): ProcessedUrl; | ||
export { ExtractWildcards, PathTrie, PathTrieData, ProcessedUrl, RedirectClient, RedirectClientGetRedirect, RedirectClientGetRedirects, RedirectClientGetRequest, RedirectClientOptions, RedirectDataCache, RedirectDefinition, RedirectDefinitions, RedirectDeleteRequest, RedirectDeleteResponse, RedirectFileConverter, RedirectFileConverterParams, RedirectGetRequest, RedirectGetResponse, RedirectOptions, RedirectResult, RedirectUpsertRequest, RedirectUpsertResponse, SourceAndTarget, SourceTargetAndWildcards, UncachedRedirectClient, Wildcard, WithMemoryCache, pathTrieReturn, processUrl }; |
@@ -200,2 +200,19 @@ import "./chunk-FFYIGW52.mjs"; | ||
import { ApiClient } from "@uniformdev/context/api"; | ||
// src/util/url.ts | ||
function processUrl(url) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/); | ||
return { | ||
url, | ||
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "", | ||
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "", | ||
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "", | ||
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "", | ||
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "", | ||
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : "" | ||
}; | ||
} | ||
// src/redirectClient.ts | ||
var _RedirectClient = class extends ApiClient { | ||
@@ -227,4 +244,4 @@ constructor(options) { | ||
} | ||
const ret = this.assembleTrie(projectId, options); | ||
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId, options)); | ||
const ret = this.assembleTrie(options); | ||
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(options)); | ||
return ret; | ||
@@ -307,21 +324,33 @@ }; | ||
} | ||
async assembleTrie(projectId, options) { | ||
var _a; | ||
const trie = new PathTrie(); | ||
let offset = 0; | ||
let total = 0; | ||
do { | ||
async *getAllRedirects(orderBy = "updated_at desc") { | ||
var _a, _b; | ||
const { projectId } = this.options; | ||
let requestCount = 0; | ||
let results = void 0; | ||
while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) { | ||
const fetchUri = this.createUrl("/api/v1/redirect", { | ||
projectId, | ||
limit: 50, | ||
offset | ||
offset: requestCount * 50, | ||
orderBy, | ||
projectId | ||
}); | ||
const redirects = await this.apiClient(fetchUri); | ||
trie.insertMany( | ||
redirects.redirects, | ||
(r) => (options == null ? void 0 : options.reverse) ? r.redirect.targetUrl : r.redirect.sourceUrl | ||
); | ||
total = (_a = redirects.total) != null ? _a : 0; | ||
offset += 50; | ||
} while (offset < total); | ||
results = await this.apiClient(fetchUri); | ||
const redirectCount = results.redirects.length; | ||
for (let i = 0; i < redirectCount; i++) { | ||
yield { total: results.total, ...results.redirects[i] }; | ||
} | ||
requestCount++; | ||
if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) { | ||
break; | ||
} | ||
} | ||
} | ||
async assembleTrie(options) { | ||
const trie = new PathTrie(); | ||
for await (const redirect of this.getAllRedirects()) { | ||
const path = processUrl( | ||
(options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl | ||
).path; | ||
trie.insert(path, redirect); | ||
} | ||
return trie; | ||
@@ -374,3 +403,3 @@ } | ||
static processHop(url, trie, bestMatch, options) { | ||
const processedUrl = this.processUrl(url); | ||
const processedUrl = processUrl(url); | ||
let definition = trie.find(url, false); | ||
@@ -400,3 +429,3 @@ if (!(definition == null ? void 0 : definition.length)) { | ||
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl; | ||
const processedResult = this.processUrl(resultUrl); | ||
const processedResult = processUrl(resultUrl); | ||
const redirect = definition == null ? void 0 : definition.redirect; | ||
@@ -420,6 +449,6 @@ if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) | ||
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) { | ||
const processedTarget = this.processUrl(redirectDefinition.targetUrl); | ||
const processedSource = this.processUrl(redirectDefinition.sourceUrl); | ||
const processedTarget = processUrl(redirectDefinition.targetUrl); | ||
const processedSource = processUrl(redirectDefinition.sourceUrl); | ||
let finalUrlPath = processedTarget.path; | ||
const processedUrl = this.processUrl(url); | ||
const processedUrl = processUrl(url); | ||
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable); | ||
@@ -467,15 +496,2 @@ for (const variable in variables) { | ||
} | ||
static processUrl(url) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/); | ||
return { | ||
url, | ||
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "", | ||
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "", | ||
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "", | ||
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "", | ||
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "", | ||
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : "" | ||
}; | ||
} | ||
}; | ||
@@ -572,3 +588,4 @@ var RedirectClient = _RedirectClient; | ||
UncachedRedirectClient, | ||
WithMemoryCache | ||
WithMemoryCache, | ||
processUrl | ||
}; |
@@ -191,3 +191,4 @@ "use strict"; | ||
UncachedRedirectClient: () => UncachedRedirectClient, | ||
WithMemoryCache: () => WithMemoryCache | ||
WithMemoryCache: () => WithMemoryCache, | ||
processUrl: () => processUrl | ||
}); | ||
@@ -393,2 +394,19 @@ module.exports = __toCommonJS(src_exports); | ||
var import_api = require("@uniformdev/context/api"); | ||
// src/util/url.ts | ||
function processUrl(url) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/); | ||
return { | ||
url, | ||
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "", | ||
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "", | ||
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "", | ||
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "", | ||
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "", | ||
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : "" | ||
}; | ||
} | ||
// src/redirectClient.ts | ||
var _RedirectClient = class extends import_api.ApiClient { | ||
@@ -420,4 +438,4 @@ constructor(options) { | ||
} | ||
const ret = this.assembleTrie(projectId, options); | ||
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId, options)); | ||
const ret = this.assembleTrie(options); | ||
(_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(options)); | ||
return ret; | ||
@@ -500,21 +518,33 @@ }; | ||
} | ||
async assembleTrie(projectId, options) { | ||
var _a; | ||
const trie = new PathTrie(); | ||
let offset = 0; | ||
let total = 0; | ||
do { | ||
async *getAllRedirects(orderBy = "updated_at desc") { | ||
var _a, _b; | ||
const { projectId } = this.options; | ||
let requestCount = 0; | ||
let results = void 0; | ||
while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) { | ||
const fetchUri = this.createUrl("/api/v1/redirect", { | ||
projectId, | ||
limit: 50, | ||
offset | ||
offset: requestCount * 50, | ||
orderBy, | ||
projectId | ||
}); | ||
const redirects = await this.apiClient(fetchUri); | ||
trie.insertMany( | ||
redirects.redirects, | ||
(r) => (options == null ? void 0 : options.reverse) ? r.redirect.targetUrl : r.redirect.sourceUrl | ||
); | ||
total = (_a = redirects.total) != null ? _a : 0; | ||
offset += 50; | ||
} while (offset < total); | ||
results = await this.apiClient(fetchUri); | ||
const redirectCount = results.redirects.length; | ||
for (let i = 0; i < redirectCount; i++) { | ||
yield { total: results.total, ...results.redirects[i] }; | ||
} | ||
requestCount++; | ||
if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) { | ||
break; | ||
} | ||
} | ||
} | ||
async assembleTrie(options) { | ||
const trie = new PathTrie(); | ||
for await (const redirect of this.getAllRedirects()) { | ||
const path = processUrl( | ||
(options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl | ||
).path; | ||
trie.insert(path, redirect); | ||
} | ||
return trie; | ||
@@ -567,3 +597,3 @@ } | ||
static processHop(url, trie, bestMatch, options) { | ||
const processedUrl = this.processUrl(url); | ||
const processedUrl = processUrl(url); | ||
let definition = trie.find(url, false); | ||
@@ -593,3 +623,3 @@ if (!(definition == null ? void 0 : definition.length)) { | ||
const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl; | ||
const processedResult = this.processUrl(resultUrl); | ||
const processedResult = processUrl(resultUrl); | ||
const redirect = definition == null ? void 0 : definition.redirect; | ||
@@ -613,6 +643,6 @@ if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) | ||
static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) { | ||
const processedTarget = this.processUrl(redirectDefinition.targetUrl); | ||
const processedSource = this.processUrl(redirectDefinition.sourceUrl); | ||
const processedTarget = processUrl(redirectDefinition.targetUrl); | ||
const processedSource = processUrl(redirectDefinition.sourceUrl); | ||
let finalUrlPath = processedTarget.path; | ||
const processedUrl = this.processUrl(url); | ||
const processedUrl = processUrl(url); | ||
const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable); | ||
@@ -660,15 +690,2 @@ for (const variable in variables) { | ||
} | ||
static processUrl(url) { | ||
var _a, _b, _c, _d, _e, _f; | ||
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/); | ||
return { | ||
url, | ||
protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "", | ||
domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "", | ||
port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "", | ||
path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "", | ||
query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "", | ||
fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : "" | ||
}; | ||
} | ||
}; | ||
@@ -766,3 +783,4 @@ var RedirectClient = _RedirectClient; | ||
UncachedRedirectClient, | ||
WithMemoryCache | ||
WithMemoryCache, | ||
processUrl | ||
}); |
{ | ||
"name": "@uniformdev/redirect", | ||
"version": "19.15.0", | ||
"version": "19.17.0", | ||
"description": "Uniform redirect client", | ||
@@ -35,3 +35,3 @@ "license": "SEE LICENSE IN LICENSE.txt", | ||
"dependencies": { | ||
"@uniformdev/context": "19.15.0", | ||
"@uniformdev/context": "19.17.0", | ||
"p-limit": "^3.1.0", | ||
@@ -43,3 +43,3 @@ "rfdc": "^1.3.0" | ||
}, | ||
"gitHead": "f48353eea4cf921b6c9878c007de12a9da2ab885" | ||
"gitHead": "ed86997d97cefd0d6849abdeb3bdf3737812ea01" | ||
} |
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
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
124898
3297
+ Added@uniformdev/context@19.17.0(transitive)
- Removed@uniformdev/context@19.15.0(transitive)
Updated@uniformdev/context@19.17.0