@uniformdev/redirect 19.15.0 → 19.17.0

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/dist/index.d.ts CHANGED
@@ -64,6 +64,31 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
64
64
  constructor(options: RedirectClientOptions);
65
65
  getRedirect: (options: RedirectClientGetRedirect) => Promise<RedirectDefinition | undefined>;
66
66
  getRedirects: (options?: RedirectClientGetRedirects) => Promise<RedirectGetResponse>;
67
+ getAllRedirects(orderBy?: RedirectClientGetRedirects['orderBy']): AsyncGenerator<{
68
+ redirect: {
69
+ id?: string | undefined;
70
+ sourceUrl: string;
71
+ targetUrl: string;
72
+ targetStatusCode: number;
73
+ sourceProjectMapNodeId?: string | undefined;
74
+ targetProjectMapNodeId?: string | undefined;
75
+ projectMapId?: string | undefined;
76
+ sourceRetainQuerystring?: boolean | undefined;
77
+ sourceMustMatchDomain?: boolean | undefined;
78
+ targetPreserveIncomingProtocol?: boolean | undefined;
79
+ targetPreserveIncomingDomain?: boolean | undefined;
80
+ stopExecutingAfter?: boolean | undefined;
81
+ targetMergeQuerystring?: boolean | undefined;
82
+ labelAsSystem?: boolean | undefined;
83
+ };
84
+ metadata: {
85
+ updatedAt?: string | undefined;
86
+ updatedBy?: string | undefined;
87
+ createdAt?: string | undefined;
88
+ createdBy?: string | undefined;
89
+ };
90
+ total: number | undefined;
91
+ }, void, unknown>;
67
92
  getRedirectTrie: (options?: {
68
93
  reverse?: boolean;
69
94
  bypassDataCache?: boolean;
@@ -88,7 +113,6 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
88
113
  static getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string) => boolean): string;
89
114
  private static mergeQueryStrings;
90
115
  private static getSourceVariables;
91
- private static processUrl;
92
116
  }
93
117
  declare class UncachedRedirectClient extends RedirectClient {
94
118
  constructor(options: Omit<RedirectClientOptions, 'bypassCache'>);
@@ -392,4 +416,29 @@ type RedirectFileConverterParams<T> = {
392
416
  declare function ExtractWildcards(url: string): Wildcard[];
393
417
  declare function RedirectFileConverter<T>({ client, redirectEntryObject, wildcardConverter, writeFile, }: RedirectFileConverterParams<T>): Promise<void>;
394
418
 
395
- 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 };
419
+ /**
420
+ * @typedef {Object} ProcessedUrl
421
+ * @property {string} url - The full url used during processing
422
+ * @property {string} path - The path portion of the URL
423
+ * @property {string} domain - The domain of the URL
424
+ * @property {string} port - The port of the URL
425
+ * @property {string} query - The querystring of the URL
426
+ * @property {string} fragment - The fragment of the URL
427
+ * @property {string} protocol - The protocol of the URL
428
+ */
429
+ type ProcessedUrl = {
430
+ url: string;
431
+ path: string;
432
+ domain: string;
433
+ port: string;
434
+ query: string;
435
+ fragment: string;
436
+ protocol: string;
437
+ };
438
+ /**
439
+ * Breaks a url into the separate parts for processing
440
+ * @returns {ProcessedUrl} The url broken down into independent components
441
+ */
442
+ declare function processUrl(url: string): ProcessedUrl;
443
+
444
+ 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 };
package/dist/index.esm.js CHANGED
@@ -197,6 +197,23 @@ var PathTrieData = class {
197
197
 
198
198
  // src/redirectClient.ts
199
199
  import { ApiClient } from "@uniformdev/context/api";
200
+
201
+ // src/util/url.ts
202
+ function processUrl(url) {
203
+ var _a, _b, _c, _d, _e, _f;
204
+ const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
205
+ return {
206
+ url,
207
+ protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
208
+ domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
209
+ port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
210
+ path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
211
+ query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
212
+ fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
213
+ };
214
+ }
215
+
216
+ // src/redirectClient.ts
200
217
  var _RedirectClient = class extends ApiClient {
201
218
  constructor(options) {
202
219
  super(options);
@@ -223,8 +240,8 @@ var _RedirectClient = class extends ApiClient {
223
240
  if (result)
224
241
  return result;
225
242
  }
226
- const ret = this.assembleTrie(projectId, options);
227
- (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId, options));
243
+ const ret = this.assembleTrie(options);
244
+ (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(options));
228
245
  return ret;
229
246
  };
230
247
  this.resetRedirectTrieDataCache = async () => {
@@ -302,25 +319,37 @@ var _RedirectClient = class extends ApiClient {
302
319
  }
303
320
  }
304
321
  }
305
- async assembleTrie(projectId, options) {
306
- var _a;
307
- const trie = new PathTrie();
308
- let offset = 0;
309
- let total = 0;
310
- do {
322
+ async *getAllRedirects(orderBy = "updated_at desc") {
323
+ var _a, _b;
324
+ const { projectId } = this.options;
325
+ let requestCount = 0;
326
+ let results = void 0;
327
+ while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) {
311
328
  const fetchUri = this.createUrl("/api/v1/redirect", {
312
- projectId,
313
329
  limit: 50,
314
- offset
330
+ offset: requestCount * 50,
331
+ orderBy,
332
+ projectId
315
333
  });
316
- const redirects = await this.apiClient(fetchUri);
317
- trie.insertMany(
318
- redirects.redirects,
319
- (r) => (options == null ? void 0 : options.reverse) ? r.redirect.targetUrl : r.redirect.sourceUrl
320
- );
321
- total = (_a = redirects.total) != null ? _a : 0;
322
- offset += 50;
323
- } while (offset < total);
334
+ results = await this.apiClient(fetchUri);
335
+ const redirectCount = results.redirects.length;
336
+ for (let i = 0; i < redirectCount; i++) {
337
+ yield { total: results.total, ...results.redirects[i] };
338
+ }
339
+ requestCount++;
340
+ if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) {
341
+ break;
342
+ }
343
+ }
344
+ }
345
+ async assembleTrie(options) {
346
+ const trie = new PathTrie();
347
+ for await (const redirect of this.getAllRedirects()) {
348
+ const path = processUrl(
349
+ (options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
350
+ ).path;
351
+ trie.insert(path, redirect);
352
+ }
324
353
  return trie;
325
354
  }
326
355
  static processHops(url, trie, bestMatch, options) {
@@ -368,7 +397,7 @@ var _RedirectClient = class extends ApiClient {
368
397
  return ret;
369
398
  }
370
399
  static processHop(url, trie, bestMatch, options) {
371
- const processedUrl = this.processUrl(url);
400
+ const processedUrl = processUrl(url);
372
401
  let definition = trie.find(url, false);
373
402
  if (!(definition == null ? void 0 : definition.length)) {
374
403
  definition = trie.find(processedUrl.path + processedUrl.query, bestMatch);
@@ -393,7 +422,7 @@ var _RedirectClient = class extends ApiClient {
393
422
  static processDefinitionToResults(processedUrl, definition, variables, options) {
394
423
  var _a, _b, _c, _d, _e;
395
424
  const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
396
- const processedResult = this.processUrl(resultUrl);
425
+ const processedResult = processUrl(resultUrl);
397
426
  const redirect = definition == null ? void 0 : definition.redirect;
398
427
  if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
399
428
  return void 0;
@@ -412,10 +441,10 @@ var _RedirectClient = class extends ApiClient {
412
441
  };
413
442
  }
414
443
  static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
415
- const processedTarget = this.processUrl(redirectDefinition.targetUrl);
416
- const processedSource = this.processUrl(redirectDefinition.sourceUrl);
444
+ const processedTarget = processUrl(redirectDefinition.targetUrl);
445
+ const processedSource = processUrl(redirectDefinition.sourceUrl);
417
446
  let finalUrlPath = processedTarget.path;
418
- const processedUrl = this.processUrl(url);
447
+ const processedUrl = processUrl(url);
419
448
  const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
420
449
  for (const variable in variables) {
421
450
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
@@ -458,19 +487,6 @@ var _RedirectClient = class extends ApiClient {
458
487
  });
459
488
  return variables;
460
489
  }
461
- static processUrl(url) {
462
- var _a, _b, _c, _d, _e, _f;
463
- const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
464
- return {
465
- url,
466
- protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
467
- domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
468
- port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
469
- path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
470
- query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
471
- fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
472
- };
473
- }
474
490
  };
475
491
  var RedirectClient = _RedirectClient;
476
492
  RedirectClient.processUrlBestMatch = async (url, trie, options) => {
@@ -562,5 +578,6 @@ export {
562
578
  RedirectClient,
563
579
  RedirectFileConverter,
564
580
  UncachedRedirectClient,
565
- WithMemoryCache
581
+ WithMemoryCache,
582
+ processUrl
566
583
  };
package/dist/index.js CHANGED
@@ -188,7 +188,8 @@ __export(src_exports, {
188
188
  RedirectClient: () => RedirectClient,
189
189
  RedirectFileConverter: () => RedirectFileConverter,
190
190
  UncachedRedirectClient: () => UncachedRedirectClient,
191
- WithMemoryCache: () => WithMemoryCache
191
+ WithMemoryCache: () => WithMemoryCache,
192
+ processUrl: () => processUrl
192
193
  });
193
194
  module.exports = __toCommonJS(src_exports);
194
195
 
@@ -389,6 +390,23 @@ var PathTrieData = class {
389
390
 
390
391
  // src/redirectClient.ts
391
392
  var import_api = require("@uniformdev/context/api");
393
+
394
+ // src/util/url.ts
395
+ function processUrl(url) {
396
+ var _a, _b, _c, _d, _e, _f;
397
+ const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
398
+ return {
399
+ url,
400
+ protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
401
+ domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
402
+ port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
403
+ path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
404
+ query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
405
+ fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
406
+ };
407
+ }
408
+
409
+ // src/redirectClient.ts
392
410
  var _RedirectClient = class extends import_api.ApiClient {
393
411
  constructor(options) {
394
412
  super(options);
@@ -415,8 +433,8 @@ var _RedirectClient = class extends import_api.ApiClient {
415
433
  if (result)
416
434
  return result;
417
435
  }
418
- const ret = this.assembleTrie(projectId, options);
419
- (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId, options));
436
+ const ret = this.assembleTrie(options);
437
+ (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(options));
420
438
  return ret;
421
439
  };
422
440
  this.resetRedirectTrieDataCache = async () => {
@@ -494,25 +512,37 @@ var _RedirectClient = class extends import_api.ApiClient {
494
512
  }
495
513
  }
496
514
  }
497
- async assembleTrie(projectId, options) {
498
- var _a;
499
- const trie = new PathTrie();
500
- let offset = 0;
501
- let total = 0;
502
- do {
515
+ async *getAllRedirects(orderBy = "updated_at desc") {
516
+ var _a, _b;
517
+ const { projectId } = this.options;
518
+ let requestCount = 0;
519
+ let results = void 0;
520
+ while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) {
503
521
  const fetchUri = this.createUrl("/api/v1/redirect", {
504
- projectId,
505
522
  limit: 50,
506
- offset
523
+ offset: requestCount * 50,
524
+ orderBy,
525
+ projectId
507
526
  });
508
- const redirects = await this.apiClient(fetchUri);
509
- trie.insertMany(
510
- redirects.redirects,
511
- (r) => (options == null ? void 0 : options.reverse) ? r.redirect.targetUrl : r.redirect.sourceUrl
512
- );
513
- total = (_a = redirects.total) != null ? _a : 0;
514
- offset += 50;
515
- } while (offset < total);
527
+ results = await this.apiClient(fetchUri);
528
+ const redirectCount = results.redirects.length;
529
+ for (let i = 0; i < redirectCount; i++) {
530
+ yield { total: results.total, ...results.redirects[i] };
531
+ }
532
+ requestCount++;
533
+ if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) {
534
+ break;
535
+ }
536
+ }
537
+ }
538
+ async assembleTrie(options) {
539
+ const trie = new PathTrie();
540
+ for await (const redirect of this.getAllRedirects()) {
541
+ const path = processUrl(
542
+ (options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
543
+ ).path;
544
+ trie.insert(path, redirect);
545
+ }
516
546
  return trie;
517
547
  }
518
548
  static processHops(url, trie, bestMatch, options) {
@@ -560,7 +590,7 @@ var _RedirectClient = class extends import_api.ApiClient {
560
590
  return ret;
561
591
  }
562
592
  static processHop(url, trie, bestMatch, options) {
563
- const processedUrl = this.processUrl(url);
593
+ const processedUrl = processUrl(url);
564
594
  let definition = trie.find(url, false);
565
595
  if (!(definition == null ? void 0 : definition.length)) {
566
596
  definition = trie.find(processedUrl.path + processedUrl.query, bestMatch);
@@ -585,7 +615,7 @@ var _RedirectClient = class extends import_api.ApiClient {
585
615
  static processDefinitionToResults(processedUrl, definition, variables, options) {
586
616
  var _a, _b, _c, _d, _e;
587
617
  const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
588
- const processedResult = this.processUrl(resultUrl);
618
+ const processedResult = processUrl(resultUrl);
589
619
  const redirect = definition == null ? void 0 : definition.redirect;
590
620
  if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
591
621
  return void 0;
@@ -604,10 +634,10 @@ var _RedirectClient = class extends import_api.ApiClient {
604
634
  };
605
635
  }
606
636
  static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
607
- const processedTarget = this.processUrl(redirectDefinition.targetUrl);
608
- const processedSource = this.processUrl(redirectDefinition.sourceUrl);
637
+ const processedTarget = processUrl(redirectDefinition.targetUrl);
638
+ const processedSource = processUrl(redirectDefinition.sourceUrl);
609
639
  let finalUrlPath = processedTarget.path;
610
- const processedUrl = this.processUrl(url);
640
+ const processedUrl = processUrl(url);
611
641
  const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
612
642
  for (const variable in variables) {
613
643
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
@@ -650,19 +680,6 @@ var _RedirectClient = class extends import_api.ApiClient {
650
680
  });
651
681
  return variables;
652
682
  }
653
- static processUrl(url) {
654
- var _a, _b, _c, _d, _e, _f;
655
- const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
656
- return {
657
- url,
658
- protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
659
- domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
660
- port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
661
- path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
662
- query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
663
- fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
664
- };
665
- }
666
683
  };
667
684
  var RedirectClient = _RedirectClient;
668
685
  RedirectClient.processUrlBestMatch = async (url, trie, options) => {
@@ -755,5 +772,6 @@ async function RedirectFileConverter({
755
772
  RedirectClient,
756
773
  RedirectFileConverter,
757
774
  UncachedRedirectClient,
758
- WithMemoryCache
775
+ WithMemoryCache,
776
+ processUrl
759
777
  });
package/dist/index.mjs CHANGED
@@ -197,6 +197,23 @@ var PathTrieData = class {
197
197
 
198
198
  // src/redirectClient.ts
199
199
  import { ApiClient } from "@uniformdev/context/api";
200
+
201
+ // src/util/url.ts
202
+ function processUrl(url) {
203
+ var _a, _b, _c, _d, _e, _f;
204
+ const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
205
+ return {
206
+ url,
207
+ protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
208
+ domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
209
+ port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
210
+ path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
211
+ query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
212
+ fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
213
+ };
214
+ }
215
+
216
+ // src/redirectClient.ts
200
217
  var _RedirectClient = class extends ApiClient {
201
218
  constructor(options) {
202
219
  super(options);
@@ -223,8 +240,8 @@ var _RedirectClient = class extends ApiClient {
223
240
  if (result)
224
241
  return result;
225
242
  }
226
- const ret = this.assembleTrie(projectId, options);
227
- (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(projectId, options));
243
+ const ret = this.assembleTrie(options);
244
+ (_b = this.options.dataCache) == null ? void 0 : _b.set(key, ret, () => this.assembleTrie(options));
228
245
  return ret;
229
246
  };
230
247
  this.resetRedirectTrieDataCache = async () => {
@@ -302,25 +319,37 @@ var _RedirectClient = class extends ApiClient {
302
319
  }
303
320
  }
304
321
  }
305
- async assembleTrie(projectId, options) {
306
- var _a;
307
- const trie = new PathTrie();
308
- let offset = 0;
309
- let total = 0;
310
- do {
322
+ async *getAllRedirects(orderBy = "updated_at desc") {
323
+ var _a, _b;
324
+ const { projectId } = this.options;
325
+ let requestCount = 0;
326
+ let results = void 0;
327
+ while (requestCount === 0 || ((_a = results == null ? void 0 : results.redirects) == null ? void 0 : _a.length)) {
311
328
  const fetchUri = this.createUrl("/api/v1/redirect", {
312
- projectId,
313
329
  limit: 50,
314
- offset
330
+ offset: requestCount * 50,
331
+ orderBy,
332
+ projectId
315
333
  });
316
- const redirects = await this.apiClient(fetchUri);
317
- trie.insertMany(
318
- redirects.redirects,
319
- (r) => (options == null ? void 0 : options.reverse) ? r.redirect.targetUrl : r.redirect.sourceUrl
320
- );
321
- total = (_a = redirects.total) != null ? _a : 0;
322
- offset += 50;
323
- } while (offset < total);
334
+ results = await this.apiClient(fetchUri);
335
+ const redirectCount = results.redirects.length;
336
+ for (let i = 0; i < redirectCount; i++) {
337
+ yield { total: results.total, ...results.redirects[i] };
338
+ }
339
+ requestCount++;
340
+ if (requestCount * 50 > ((_b = results.total) != null ? _b : 0)) {
341
+ break;
342
+ }
343
+ }
344
+ }
345
+ async assembleTrie(options) {
346
+ const trie = new PathTrie();
347
+ for await (const redirect of this.getAllRedirects()) {
348
+ const path = processUrl(
349
+ (options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl
350
+ ).path;
351
+ trie.insert(path, redirect);
352
+ }
324
353
  return trie;
325
354
  }
326
355
  static processHops(url, trie, bestMatch, options) {
@@ -368,7 +397,7 @@ var _RedirectClient = class extends ApiClient {
368
397
  return ret;
369
398
  }
370
399
  static processHop(url, trie, bestMatch, options) {
371
- const processedUrl = this.processUrl(url);
400
+ const processedUrl = processUrl(url);
372
401
  let definition = trie.find(url, false);
373
402
  if (!(definition == null ? void 0 : definition.length)) {
374
403
  definition = trie.find(processedUrl.path + processedUrl.query, bestMatch);
@@ -393,7 +422,7 @@ var _RedirectClient = class extends ApiClient {
393
422
  static processDefinitionToResults(processedUrl, definition, variables, options) {
394
423
  var _a, _b, _c, _d, _e;
395
424
  const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
396
- const processedResult = this.processUrl(resultUrl);
425
+ const processedResult = processUrl(resultUrl);
397
426
  const redirect = definition == null ? void 0 : definition.redirect;
398
427
  if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain)
399
428
  return void 0;
@@ -412,10 +441,10 @@ var _RedirectClient = class extends ApiClient {
412
441
  };
413
442
  }
414
443
  static getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
415
- const processedTarget = this.processUrl(redirectDefinition.targetUrl);
416
- const processedSource = this.processUrl(redirectDefinition.sourceUrl);
444
+ const processedTarget = processUrl(redirectDefinition.targetUrl);
445
+ const processedSource = processUrl(redirectDefinition.sourceUrl);
417
446
  let finalUrlPath = processedTarget.path;
418
- const processedUrl = this.processUrl(url);
447
+ const processedUrl = processUrl(url);
419
448
  const variables = this.getSourceVariables(processedUrl.path, processedSource.path, isVariable);
420
449
  for (const variable in variables) {
421
450
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
@@ -458,19 +487,6 @@ var _RedirectClient = class extends ApiClient {
458
487
  });
459
488
  return variables;
460
489
  }
461
- static processUrl(url) {
462
- var _a, _b, _c, _d, _e, _f;
463
- const matches = url.match(/^(https?:\/\/)?(([^:/?#]*)(?:(:[0-9]+))?)?([/]{0,1}[^?#]*)(\?[^#]*|)(#.*|)$/);
464
- return {
465
- url,
466
- protocol: (_a = matches == null ? void 0 : matches[1]) != null ? _a : "",
467
- domain: (_b = matches == null ? void 0 : matches[3]) != null ? _b : "",
468
- port: (_c = matches == null ? void 0 : matches[4]) != null ? _c : "",
469
- path: (_d = matches == null ? void 0 : matches[5]) != null ? _d : "",
470
- query: (_e = matches == null ? void 0 : matches[6]) != null ? _e : "",
471
- fragment: (_f = matches == null ? void 0 : matches[7]) != null ? _f : ""
472
- };
473
- }
474
490
  };
475
491
  var RedirectClient = _RedirectClient;
476
492
  RedirectClient.processUrlBestMatch = async (url, trie, options) => {
@@ -562,5 +578,6 @@ export {
562
578
  RedirectClient,
563
579
  RedirectFileConverter,
564
580
  UncachedRedirectClient,
565
- WithMemoryCache
581
+ WithMemoryCache,
582
+ processUrl
566
583
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/redirect",
3
- "version": "19.15.0",
3
+ "version": "19.17.0",
4
4
  "description": "Uniform redirect client",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "main": "./dist/index.js",
@@ -32,12 +32,12 @@
32
32
  "/dist"
33
33
  ],
34
34
  "dependencies": {
35
- "@uniformdev/context": "19.15.0",
35
+ "@uniformdev/context": "19.17.0",
36
36
  "p-limit": "^3.1.0",
37
37
  "rfdc": "^1.3.0"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "f48353eea4cf921b6c9878c007de12a9da2ab885"
42
+ "gitHead": "ed86997d97cefd0d6849abdeb3bdf3737812ea01"
43
43
  }