@uniformdev/redirect 19.79.1-alpha.11 → 19.79.1-alpha.18
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/LICENSE.txt +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.ts +1 -2
- package/dist/index.esm.js +25 -28
- package/dist/index.js +25 -28
- package/dist/index.mjs +25 -28
- package/package.json +3 -3
package/LICENSE.txt
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
©
|
|
1
|
+
© 2024 Uniform Systems, Inc. All Rights Reserved.
|
|
2
2
|
See details of Uniform Systems, Inc. Master Subscription Agreement here: https://uniform.dev/eula
|
package/dist/index.d.mts
CHANGED
|
@@ -111,7 +111,6 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
|
111
111
|
*/
|
|
112
112
|
private static processDefinitionToResults;
|
|
113
113
|
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
114
|
-
private static getSourceVariables;
|
|
115
114
|
}
|
|
116
115
|
declare class UncachedRedirectClient extends RedirectClient {
|
|
117
116
|
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
@@ -452,4 +451,4 @@ type ProcessedUrl = {
|
|
|
452
451
|
*/
|
|
453
452
|
declare function processUrl(url: string): ProcessedUrl;
|
|
454
453
|
|
|
455
|
-
export { DirectionAwareRedirectDefinition, 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, getSourceVariables, getTargetVariableExpandedUrl, mergeQueryStrings, pathTrieReturn, processUrl };
|
|
454
|
+
export { type DirectionAwareRedirectDefinition, ExtractWildcards, PathTrie, PathTrieData, type ProcessedUrl, RedirectClient, type RedirectClientGetRedirect, type RedirectClientGetRedirects, type RedirectClientGetRequest, type RedirectClientOptions, type RedirectDataCache, type RedirectDefinition, type RedirectDefinitions, type RedirectDeleteRequest, type RedirectDeleteResponse, RedirectFileConverter, type RedirectFileConverterParams, type RedirectGetRequest, type RedirectGetResponse, type RedirectOptions, type RedirectResult, type RedirectUpsertRequest, type RedirectUpsertResponse, type SourceAndTarget, type SourceTargetAndWildcards, UncachedRedirectClient, type Wildcard, WithMemoryCache, getSourceVariables, getTargetVariableExpandedUrl, mergeQueryStrings, type pathTrieReturn, processUrl };
|
package/dist/index.d.ts
CHANGED
|
@@ -111,7 +111,6 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
|
|
|
111
111
|
*/
|
|
112
112
|
private static processDefinitionToResults;
|
|
113
113
|
static validateRedirect(url: string, redirectDefinition: RedirectDefinition['redirect']): boolean;
|
|
114
|
-
private static getSourceVariables;
|
|
115
114
|
}
|
|
116
115
|
declare class UncachedRedirectClient extends RedirectClient {
|
|
117
116
|
constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
|
|
@@ -452,4 +451,4 @@ type ProcessedUrl = {
|
|
|
452
451
|
*/
|
|
453
452
|
declare function processUrl(url: string): ProcessedUrl;
|
|
454
453
|
|
|
455
|
-
export { DirectionAwareRedirectDefinition, 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, getSourceVariables, getTargetVariableExpandedUrl, mergeQueryStrings, pathTrieReturn, processUrl };
|
|
454
|
+
export { type DirectionAwareRedirectDefinition, ExtractWildcards, PathTrie, PathTrieData, type ProcessedUrl, RedirectClient, type RedirectClientGetRedirect, type RedirectClientGetRedirects, type RedirectClientGetRequest, type RedirectClientOptions, type RedirectDataCache, type RedirectDefinition, type RedirectDefinitions, type RedirectDeleteRequest, type RedirectDeleteResponse, RedirectFileConverter, type RedirectFileConverterParams, type RedirectGetRequest, type RedirectGetResponse, type RedirectOptions, type RedirectResult, type RedirectUpsertRequest, type RedirectUpsertResponse, type SourceAndTarget, type SourceTargetAndWildcards, UncachedRedirectClient, type Wildcard, WithMemoryCache, getSourceVariables, getTargetVariableExpandedUrl, mergeQueryStrings, type pathTrieReturn, processUrl };
|
package/dist/index.esm.js
CHANGED
|
@@ -260,15 +260,21 @@ import { ApiClient } from "@uniformdev/context/api";
|
|
|
260
260
|
// src/util/url.ts
|
|
261
261
|
function processUrl(url) {
|
|
262
262
|
var _a, _b, _c, _d, _e, _f;
|
|
263
|
-
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[
|
|
263
|
+
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#?]*|)(#.*|)$/);
|
|
264
|
+
const protocol = (_a = matches == null ? void 0 : matches[1]) != null ? _a : "";
|
|
265
|
+
const domain = (_b = matches == null ? void 0 : matches[3]) != null ? _b : "";
|
|
266
|
+
const port = (_c = matches == null ? void 0 : matches[4]) != null ? _c : "";
|
|
267
|
+
const path = (_d = matches == null ? void 0 : matches[5].replace(/\/+$/g, "")) != null ? _d : "";
|
|
268
|
+
const query = (_e = matches == null ? void 0 : matches[6]) != null ? _e : "";
|
|
269
|
+
const fragment = (_f = matches == null ? void 0 : matches[7]) != null ? _f : "";
|
|
264
270
|
return {
|
|
265
|
-
url
|
|
266
|
-
protocol
|
|
267
|
-
domain
|
|
268
|
-
port
|
|
269
|
-
path
|
|
270
|
-
query
|
|
271
|
-
fragment
|
|
271
|
+
url: `${protocol}${domain}${port}${path}${query}${fragment}`,
|
|
272
|
+
protocol,
|
|
273
|
+
domain,
|
|
274
|
+
port,
|
|
275
|
+
path,
|
|
276
|
+
query,
|
|
277
|
+
fragment
|
|
272
278
|
};
|
|
273
279
|
}
|
|
274
280
|
|
|
@@ -296,11 +302,8 @@ function getSourceVariables(path, source, isVariable = (pathSegment, isLast) =>
|
|
|
296
302
|
const variables = {};
|
|
297
303
|
const pathSegments = path.split("/");
|
|
298
304
|
const sourceSegments = source.split("/");
|
|
299
|
-
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
|
|
300
|
-
throw new Error("Path and source have different numbers of path segments, must be the same");
|
|
301
|
-
}
|
|
302
305
|
sourceSegments.forEach((sourceSegment, i) => {
|
|
303
|
-
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
306
|
+
if (pathSegments.length >= i && isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
304
307
|
variables[sourceSegment] = pathSegments[i];
|
|
305
308
|
}
|
|
306
309
|
});
|
|
@@ -328,6 +331,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
328
331
|
var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
329
332
|
constructor(options) {
|
|
330
333
|
super(options);
|
|
334
|
+
// Get a single redirect by ID or project map id
|
|
331
335
|
this.getRedirect = async (options) => {
|
|
332
336
|
var _a;
|
|
333
337
|
const { projectId } = this.options;
|
|
@@ -335,12 +339,14 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
335
339
|
const results = await this.apiClient(fetchUri);
|
|
336
340
|
return (_a = results.redirects) == null ? void 0 : _a[0];
|
|
337
341
|
};
|
|
342
|
+
// Get redirects by list of IDs, source URL, target URL, or search
|
|
338
343
|
this.getRedirects = async (options) => {
|
|
339
344
|
const { projectId } = this.options;
|
|
340
345
|
const fetchUri = this.createUrl("/api/v1/redirect", { ...options, projectId });
|
|
341
346
|
const results = await this.apiClient(fetchUri);
|
|
342
347
|
return results;
|
|
343
348
|
};
|
|
349
|
+
// Assemble a trie powered search structure, used to have instant resolution of redirects. Note, result set may be large.
|
|
344
350
|
this.getRedirectTrie = async (options) => {
|
|
345
351
|
var _a, _b;
|
|
346
352
|
const { projectId } = this.options;
|
|
@@ -422,7 +428,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
422
428
|
return _RedirectClient.processDefinitionToResults(
|
|
423
429
|
processedUrl,
|
|
424
430
|
redirect,
|
|
425
|
-
|
|
431
|
+
getSourceVariables(
|
|
426
432
|
processedUrl.path,
|
|
427
433
|
processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
|
|
428
434
|
),
|
|
@@ -432,6 +438,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
432
438
|
const trie = await this.getRedirectTrie();
|
|
433
439
|
return (_b = _RedirectClient.processHops(sanitizedUrl, trie, true, options)) == null ? void 0 : _b[0];
|
|
434
440
|
};
|
|
441
|
+
// Caculate redirect matches based on an incoming URL with an option to use a trie storage structure to streamline future
|
|
442
|
+
// redirect resolutions. Note this may cause a large in memory load for large collections of redirect, off by default.
|
|
435
443
|
this.processUrlAllMatches = async (url, options, useTrie) => {
|
|
436
444
|
const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
|
|
437
445
|
if (!useTrie) {
|
|
@@ -443,7 +451,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
443
451
|
return _RedirectClient.processDefinitionToResults(
|
|
444
452
|
processedUrl,
|
|
445
453
|
redirect,
|
|
446
|
-
|
|
454
|
+
getSourceVariables(
|
|
447
455
|
processedUrl.path,
|
|
448
456
|
processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
|
|
449
457
|
),
|
|
@@ -464,6 +472,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
464
472
|
}
|
|
465
473
|
}
|
|
466
474
|
}
|
|
475
|
+
// Get all redirects in Uniform 500 at a time.
|
|
467
476
|
async *getAllRedirects(orderBy = "updated_at desc") {
|
|
468
477
|
var _a, _b;
|
|
469
478
|
const { projectId } = this.options;
|
|
@@ -512,6 +521,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
512
521
|
}
|
|
513
522
|
return await _RedirectClient.assemblingPromise;
|
|
514
523
|
}
|
|
524
|
+
// Find all redirects involved for the current URL, this is for the case where a redirect definition leads to
|
|
525
|
+
// another redirect. This also involves cycle busting error handling
|
|
515
526
|
static processHops(initialUrl, trie, bestMatch, options) {
|
|
516
527
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
517
528
|
const isCycle = (id, result) => {
|
|
@@ -606,20 +617,6 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
606
617
|
}
|
|
607
618
|
return true;
|
|
608
619
|
}
|
|
609
|
-
static getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
|
|
610
|
-
const variables = {};
|
|
611
|
-
const pathSegments = path.split("/");
|
|
612
|
-
const sourceSegments = source.split("/");
|
|
613
|
-
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
|
|
614
|
-
throw new Error("Path and source have different numbers of path segments, must be the same");
|
|
615
|
-
}
|
|
616
|
-
sourceSegments.forEach((sourceSegment, i) => {
|
|
617
|
-
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
618
|
-
variables[sourceSegment] = pathSegments[i];
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
return variables;
|
|
622
|
-
}
|
|
623
620
|
};
|
|
624
621
|
_RedirectClient.processUrlBestMatch = async (url, trie, options) => {
|
|
625
622
|
var _a;
|
package/dist/index.js
CHANGED
|
@@ -306,15 +306,21 @@ var import_api = require("@uniformdev/context/api");
|
|
|
306
306
|
// src/util/url.ts
|
|
307
307
|
function processUrl(url) {
|
|
308
308
|
var _a, _b, _c, _d, _e, _f;
|
|
309
|
-
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[
|
|
309
|
+
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#?]*|)(#.*|)$/);
|
|
310
|
+
const protocol = (_a = matches == null ? void 0 : matches[1]) != null ? _a : "";
|
|
311
|
+
const domain = (_b = matches == null ? void 0 : matches[3]) != null ? _b : "";
|
|
312
|
+
const port = (_c = matches == null ? void 0 : matches[4]) != null ? _c : "";
|
|
313
|
+
const path = (_d = matches == null ? void 0 : matches[5].replace(/\/+$/g, "")) != null ? _d : "";
|
|
314
|
+
const query = (_e = matches == null ? void 0 : matches[6]) != null ? _e : "";
|
|
315
|
+
const fragment = (_f = matches == null ? void 0 : matches[7]) != null ? _f : "";
|
|
310
316
|
return {
|
|
311
|
-
url
|
|
312
|
-
protocol
|
|
313
|
-
domain
|
|
314
|
-
port
|
|
315
|
-
path
|
|
316
|
-
query
|
|
317
|
-
fragment
|
|
317
|
+
url: `${protocol}${domain}${port}${path}${query}${fragment}`,
|
|
318
|
+
protocol,
|
|
319
|
+
domain,
|
|
320
|
+
port,
|
|
321
|
+
path,
|
|
322
|
+
query,
|
|
323
|
+
fragment
|
|
318
324
|
};
|
|
319
325
|
}
|
|
320
326
|
|
|
@@ -342,11 +348,8 @@ function getSourceVariables(path, source, isVariable = (pathSegment, isLast) =>
|
|
|
342
348
|
const variables = {};
|
|
343
349
|
const pathSegments = path.split("/");
|
|
344
350
|
const sourceSegments = source.split("/");
|
|
345
|
-
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
|
|
346
|
-
throw new Error("Path and source have different numbers of path segments, must be the same");
|
|
347
|
-
}
|
|
348
351
|
sourceSegments.forEach((sourceSegment, i) => {
|
|
349
|
-
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
352
|
+
if (pathSegments.length >= i && isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
350
353
|
variables[sourceSegment] = pathSegments[i];
|
|
351
354
|
}
|
|
352
355
|
});
|
|
@@ -374,6 +377,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
374
377
|
var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
375
378
|
constructor(options) {
|
|
376
379
|
super(options);
|
|
380
|
+
// Get a single redirect by ID or project map id
|
|
377
381
|
this.getRedirect = async (options) => {
|
|
378
382
|
var _a;
|
|
379
383
|
const { projectId } = this.options;
|
|
@@ -381,12 +385,14 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
381
385
|
const results = await this.apiClient(fetchUri);
|
|
382
386
|
return (_a = results.redirects) == null ? void 0 : _a[0];
|
|
383
387
|
};
|
|
388
|
+
// Get redirects by list of IDs, source URL, target URL, or search
|
|
384
389
|
this.getRedirects = async (options) => {
|
|
385
390
|
const { projectId } = this.options;
|
|
386
391
|
const fetchUri = this.createUrl("/api/v1/redirect", { ...options, projectId });
|
|
387
392
|
const results = await this.apiClient(fetchUri);
|
|
388
393
|
return results;
|
|
389
394
|
};
|
|
395
|
+
// Assemble a trie powered search structure, used to have instant resolution of redirects. Note, result set may be large.
|
|
390
396
|
this.getRedirectTrie = async (options) => {
|
|
391
397
|
var _a, _b;
|
|
392
398
|
const { projectId } = this.options;
|
|
@@ -468,7 +474,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
468
474
|
return _RedirectClient.processDefinitionToResults(
|
|
469
475
|
processedUrl,
|
|
470
476
|
redirect,
|
|
471
|
-
|
|
477
|
+
getSourceVariables(
|
|
472
478
|
processedUrl.path,
|
|
473
479
|
processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
|
|
474
480
|
),
|
|
@@ -478,6 +484,8 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
478
484
|
const trie = await this.getRedirectTrie();
|
|
479
485
|
return (_b = _RedirectClient.processHops(sanitizedUrl, trie, true, options)) == null ? void 0 : _b[0];
|
|
480
486
|
};
|
|
487
|
+
// Caculate redirect matches based on an incoming URL with an option to use a trie storage structure to streamline future
|
|
488
|
+
// redirect resolutions. Note this may cause a large in memory load for large collections of redirect, off by default.
|
|
481
489
|
this.processUrlAllMatches = async (url, options, useTrie) => {
|
|
482
490
|
const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
|
|
483
491
|
if (!useTrie) {
|
|
@@ -489,7 +497,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
489
497
|
return _RedirectClient.processDefinitionToResults(
|
|
490
498
|
processedUrl,
|
|
491
499
|
redirect,
|
|
492
|
-
|
|
500
|
+
getSourceVariables(
|
|
493
501
|
processedUrl.path,
|
|
494
502
|
processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
|
|
495
503
|
),
|
|
@@ -510,6 +518,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
510
518
|
}
|
|
511
519
|
}
|
|
512
520
|
}
|
|
521
|
+
// Get all redirects in Uniform 500 at a time.
|
|
513
522
|
async *getAllRedirects(orderBy = "updated_at desc") {
|
|
514
523
|
var _a, _b;
|
|
515
524
|
const { projectId } = this.options;
|
|
@@ -558,6 +567,8 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
558
567
|
}
|
|
559
568
|
return await _RedirectClient.assemblingPromise;
|
|
560
569
|
}
|
|
570
|
+
// Find all redirects involved for the current URL, this is for the case where a redirect definition leads to
|
|
571
|
+
// another redirect. This also involves cycle busting error handling
|
|
561
572
|
static processHops(initialUrl, trie, bestMatch, options) {
|
|
562
573
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
563
574
|
const isCycle = (id, result) => {
|
|
@@ -652,20 +663,6 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
|
|
|
652
663
|
}
|
|
653
664
|
return true;
|
|
654
665
|
}
|
|
655
|
-
static getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
|
|
656
|
-
const variables = {};
|
|
657
|
-
const pathSegments = path.split("/");
|
|
658
|
-
const sourceSegments = source.split("/");
|
|
659
|
-
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
|
|
660
|
-
throw new Error("Path and source have different numbers of path segments, must be the same");
|
|
661
|
-
}
|
|
662
|
-
sourceSegments.forEach((sourceSegment, i) => {
|
|
663
|
-
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
664
|
-
variables[sourceSegment] = pathSegments[i];
|
|
665
|
-
}
|
|
666
|
-
});
|
|
667
|
-
return variables;
|
|
668
|
-
}
|
|
669
666
|
};
|
|
670
667
|
_RedirectClient.processUrlBestMatch = async (url, trie, options) => {
|
|
671
668
|
var _a;
|
package/dist/index.mjs
CHANGED
|
@@ -260,15 +260,21 @@ import { ApiClient } from "@uniformdev/context/api";
|
|
|
260
260
|
// src/util/url.ts
|
|
261
261
|
function processUrl(url) {
|
|
262
262
|
var _a, _b, _c, _d, _e, _f;
|
|
263
|
-
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[
|
|
263
|
+
const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#?]*|)(#.*|)$/);
|
|
264
|
+
const protocol = (_a = matches == null ? void 0 : matches[1]) != null ? _a : "";
|
|
265
|
+
const domain = (_b = matches == null ? void 0 : matches[3]) != null ? _b : "";
|
|
266
|
+
const port = (_c = matches == null ? void 0 : matches[4]) != null ? _c : "";
|
|
267
|
+
const path = (_d = matches == null ? void 0 : matches[5].replace(/\/+$/g, "")) != null ? _d : "";
|
|
268
|
+
const query = (_e = matches == null ? void 0 : matches[6]) != null ? _e : "";
|
|
269
|
+
const fragment = (_f = matches == null ? void 0 : matches[7]) != null ? _f : "";
|
|
264
270
|
return {
|
|
265
|
-
url
|
|
266
|
-
protocol
|
|
267
|
-
domain
|
|
268
|
-
port
|
|
269
|
-
path
|
|
270
|
-
query
|
|
271
|
-
fragment
|
|
271
|
+
url: `${protocol}${domain}${port}${path}${query}${fragment}`,
|
|
272
|
+
protocol,
|
|
273
|
+
domain,
|
|
274
|
+
port,
|
|
275
|
+
path,
|
|
276
|
+
query,
|
|
277
|
+
fragment
|
|
272
278
|
};
|
|
273
279
|
}
|
|
274
280
|
|
|
@@ -296,11 +302,8 @@ function getSourceVariables(path, source, isVariable = (pathSegment, isLast) =>
|
|
|
296
302
|
const variables = {};
|
|
297
303
|
const pathSegments = path.split("/");
|
|
298
304
|
const sourceSegments = source.split("/");
|
|
299
|
-
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
|
|
300
|
-
throw new Error("Path and source have different numbers of path segments, must be the same");
|
|
301
|
-
}
|
|
302
305
|
sourceSegments.forEach((sourceSegment, i) => {
|
|
303
|
-
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
306
|
+
if (pathSegments.length >= i && isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
304
307
|
variables[sourceSegment] = pathSegments[i];
|
|
305
308
|
}
|
|
306
309
|
});
|
|
@@ -328,6 +331,7 @@ function mergeQueryStrings(qs1, qs2) {
|
|
|
328
331
|
var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
329
332
|
constructor(options) {
|
|
330
333
|
super(options);
|
|
334
|
+
// Get a single redirect by ID or project map id
|
|
331
335
|
this.getRedirect = async (options) => {
|
|
332
336
|
var _a;
|
|
333
337
|
const { projectId } = this.options;
|
|
@@ -335,12 +339,14 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
335
339
|
const results = await this.apiClient(fetchUri);
|
|
336
340
|
return (_a = results.redirects) == null ? void 0 : _a[0];
|
|
337
341
|
};
|
|
342
|
+
// Get redirects by list of IDs, source URL, target URL, or search
|
|
338
343
|
this.getRedirects = async (options) => {
|
|
339
344
|
const { projectId } = this.options;
|
|
340
345
|
const fetchUri = this.createUrl("/api/v1/redirect", { ...options, projectId });
|
|
341
346
|
const results = await this.apiClient(fetchUri);
|
|
342
347
|
return results;
|
|
343
348
|
};
|
|
349
|
+
// Assemble a trie powered search structure, used to have instant resolution of redirects. Note, result set may be large.
|
|
344
350
|
this.getRedirectTrie = async (options) => {
|
|
345
351
|
var _a, _b;
|
|
346
352
|
const { projectId } = this.options;
|
|
@@ -422,7 +428,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
422
428
|
return _RedirectClient.processDefinitionToResults(
|
|
423
429
|
processedUrl,
|
|
424
430
|
redirect,
|
|
425
|
-
|
|
431
|
+
getSourceVariables(
|
|
426
432
|
processedUrl.path,
|
|
427
433
|
processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
|
|
428
434
|
),
|
|
@@ -432,6 +438,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
432
438
|
const trie = await this.getRedirectTrie();
|
|
433
439
|
return (_b = _RedirectClient.processHops(sanitizedUrl, trie, true, options)) == null ? void 0 : _b[0];
|
|
434
440
|
};
|
|
441
|
+
// Caculate redirect matches based on an incoming URL with an option to use a trie storage structure to streamline future
|
|
442
|
+
// redirect resolutions. Note this may cause a large in memory load for large collections of redirect, off by default.
|
|
435
443
|
this.processUrlAllMatches = async (url, options, useTrie) => {
|
|
436
444
|
const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
|
|
437
445
|
if (!useTrie) {
|
|
@@ -443,7 +451,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
443
451
|
return _RedirectClient.processDefinitionToResults(
|
|
444
452
|
processedUrl,
|
|
445
453
|
redirect,
|
|
446
|
-
|
|
454
|
+
getSourceVariables(
|
|
447
455
|
processedUrl.path,
|
|
448
456
|
processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
|
|
449
457
|
),
|
|
@@ -464,6 +472,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
464
472
|
}
|
|
465
473
|
}
|
|
466
474
|
}
|
|
475
|
+
// Get all redirects in Uniform 500 at a time.
|
|
467
476
|
async *getAllRedirects(orderBy = "updated_at desc") {
|
|
468
477
|
var _a, _b;
|
|
469
478
|
const { projectId } = this.options;
|
|
@@ -512,6 +521,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
512
521
|
}
|
|
513
522
|
return await _RedirectClient.assemblingPromise;
|
|
514
523
|
}
|
|
524
|
+
// Find all redirects involved for the current URL, this is for the case where a redirect definition leads to
|
|
525
|
+
// another redirect. This also involves cycle busting error handling
|
|
515
526
|
static processHops(initialUrl, trie, bestMatch, options) {
|
|
516
527
|
const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
|
|
517
528
|
const isCycle = (id, result) => {
|
|
@@ -606,20 +617,6 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
|
|
|
606
617
|
}
|
|
607
618
|
return true;
|
|
608
619
|
}
|
|
609
|
-
static getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
|
|
610
|
-
const variables = {};
|
|
611
|
-
const pathSegments = path.split("/");
|
|
612
|
-
const sourceSegments = source.split("/");
|
|
613
|
-
if (pathSegments.length !== sourceSegments.length && !source.endsWith("/*")) {
|
|
614
|
-
throw new Error("Path and source have different numbers of path segments, must be the same");
|
|
615
|
-
}
|
|
616
|
-
sourceSegments.forEach((sourceSegment, i) => {
|
|
617
|
-
if (isVariable(sourceSegment, i === sourceSegments.length - 1)) {
|
|
618
|
-
variables[sourceSegment] = pathSegments[i];
|
|
619
|
-
}
|
|
620
|
-
});
|
|
621
|
-
return variables;
|
|
622
|
-
}
|
|
623
620
|
};
|
|
624
621
|
_RedirectClient.processUrlBestMatch = async (url, trie, options) => {
|
|
625
622
|
var _a;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/redirect",
|
|
3
|
-
"version": "19.79.1-alpha.
|
|
3
|
+
"version": "19.79.1-alpha.18+12234b9350",
|
|
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.79.1-alpha.
|
|
36
|
+
"@uniformdev/context": "19.79.1-alpha.18+12234b9350",
|
|
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": "12234b9350cfa4209bc7e242701d2dc535ece19e"
|
|
44
44
|
}
|