@uniformdev/redirect 19.37.1 → 19.38.2

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.mts CHANGED
@@ -3,9 +3,8 @@ import { ClientOptions, ApiClient } from '@uniformdev/context/api';
3
3
  interface pathTrieReturn<T> {
4
4
  data: T;
5
5
  variables: {
6
- key: string;
7
- value: string;
8
- }[];
6
+ [variable: string]: string;
7
+ };
9
8
  }
10
9
  declare class PathTrie<T> {
11
10
  constructor(initialData?: PathTrieData<T>);
@@ -77,7 +76,6 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
77
76
  sourceMustMatchDomain?: boolean | undefined;
78
77
  targetPreserveIncomingProtocol?: boolean | undefined;
79
78
  targetPreserveIncomingDomain?: boolean | undefined;
80
- stopExecutingAfter?: boolean | undefined;
81
79
  targetMergeQuerystring?: boolean | undefined;
82
80
  labelAsSystem?: boolean | undefined;
83
81
  };
@@ -97,8 +95,8 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
97
95
  upsertRedirect: (redirect: RedirectUpsertRequest['redirect']) => Promise<string>;
98
96
  deleteRedirect: (id: string) => Promise<string>;
99
97
  static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
100
- processUrlBestMatch: (url: string, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
101
- processUrlAllMatches: (url: string, options?: RedirectOptions) => Promise<RedirectResult[]>;
98
+ processUrlBestMatch: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult | undefined>;
99
+ processUrlAllMatches: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult[]>;
102
100
  private static assembling;
103
101
  private static assemblingPromise;
104
102
  private assembleTrie;
@@ -311,8 +309,6 @@ interface components {
311
309
  targetPreserveIncomingProtocol?: boolean;
312
310
  /** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target. */
313
311
  targetPreserveIncomingDomain?: boolean;
314
- /** @description Stop running rules after this redirect rule gets executed. */
315
- stopExecutingAfter?: boolean;
316
312
  /** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible. */
317
313
  targetMergeQuerystring?: boolean;
318
314
  /** @description Label as system generated or user generated. */
@@ -393,7 +389,7 @@ type RedirectDataCache = {
393
389
  preload?: boolean;
394
390
  };
395
391
  type RedirectClientGetRedirect = Pick<RedirectClientGetRequest, 'id' | 'projectMapId' | 'sourceProjectMapNodeId' | 'targetProjectMapNodeId'>;
396
- type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search'>;
392
+ type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search' | 'sourceUrl'>;
397
393
 
398
394
  declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
399
395
  private static refresher?;
package/dist/index.d.ts CHANGED
@@ -3,9 +3,8 @@ import { ClientOptions, ApiClient } from '@uniformdev/context/api';
3
3
  interface pathTrieReturn<T> {
4
4
  data: T;
5
5
  variables: {
6
- key: string;
7
- value: string;
8
- }[];
6
+ [variable: string]: string;
7
+ };
9
8
  }
10
9
  declare class PathTrie<T> {
11
10
  constructor(initialData?: PathTrieData<T>);
@@ -77,7 +76,6 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
77
76
  sourceMustMatchDomain?: boolean | undefined;
78
77
  targetPreserveIncomingProtocol?: boolean | undefined;
79
78
  targetPreserveIncomingDomain?: boolean | undefined;
80
- stopExecutingAfter?: boolean | undefined;
81
79
  targetMergeQuerystring?: boolean | undefined;
82
80
  labelAsSystem?: boolean | undefined;
83
81
  };
@@ -97,8 +95,8 @@ declare class RedirectClient extends ApiClient<RedirectClientOptions> {
97
95
  upsertRedirect: (redirect: RedirectUpsertRequest['redirect']) => Promise<string>;
98
96
  deleteRedirect: (id: string) => Promise<string>;
99
97
  static processUrlBestMatch: (url: string, trie: PathTrie<DirectionAwareRedirectDefinition>, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
100
- processUrlBestMatch: (url: string, options?: RedirectOptions) => Promise<RedirectResult | undefined>;
101
- processUrlAllMatches: (url: string, options?: RedirectOptions) => Promise<RedirectResult[]>;
98
+ processUrlBestMatch: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult | undefined>;
99
+ processUrlAllMatches: (url: string, options?: RedirectOptions, useTrie?: boolean) => Promise<RedirectResult[]>;
102
100
  private static assembling;
103
101
  private static assemblingPromise;
104
102
  private assembleTrie;
@@ -311,8 +309,6 @@ interface components {
311
309
  targetPreserveIncomingProtocol?: boolean;
312
310
  /** @description Rewritten url should match the domain of the incoming request regardless of what is defined in the redirection target. */
313
311
  targetPreserveIncomingDomain?: boolean;
314
- /** @description Stop running rules after this redirect rule gets executed. */
315
- stopExecutingAfter?: boolean;
316
312
  /** @description Merge incoming querystring with the querystring defined on the redirection target, taking the incoming querystring parameter where a merge is not possible. */
317
313
  targetMergeQuerystring?: boolean;
318
314
  /** @description Label as system generated or user generated. */
@@ -393,7 +389,7 @@ type RedirectDataCache = {
393
389
  preload?: boolean;
394
390
  };
395
391
  type RedirectClientGetRedirect = Pick<RedirectClientGetRequest, 'id' | 'projectMapId' | 'sourceProjectMapNodeId' | 'targetProjectMapNodeId'>;
396
- type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search'>;
392
+ type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search' | 'sourceUrl'>;
397
393
 
398
394
  declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
399
395
  private static refresher?;
package/dist/index.esm.js CHANGED
@@ -166,11 +166,10 @@ var PathTrie = class {
166
166
  const splats = [];
167
167
  const processed = /* @__PURE__ */ new Set();
168
168
  const getVariables = () => {
169
- return wildcards.map((wildcard) => {
170
- if (wildcard.active)
171
- return { key: wildcard.name, value: segments[wildcard.start] };
172
- return void 0;
173
- }).filter((wildcard) => Boolean(wildcard));
169
+ return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce((variables, wildcard) => {
170
+ variables[wildcard.name] = segments[wildcard.start];
171
+ return variables;
172
+ }, new Object());
174
173
  };
175
174
  const getPropsStartingWithColon = (obj) => {
176
175
  const result = [];
@@ -202,9 +201,11 @@ var PathTrie = class {
202
201
  const segment = segments[i];
203
202
  if (Object.hasOwn(cur, "*")) {
204
203
  cur["*"][dataProp].forEach((splat) => {
204
+ const vars = getVariables();
205
+ vars[":splat"] = segments.slice(i).join("/");
205
206
  splats.push({
206
207
  data: splat,
207
- variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
208
+ variables: vars
208
209
  });
209
210
  });
210
211
  }
@@ -319,7 +320,6 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
319
320
  sourceMustMatchDomain,
320
321
  sourceProjectMapNodeId,
321
322
  sourceRetainQuerystring,
322
- stopExecutingAfter,
323
323
  targetMergeQuerystring,
324
324
  targetPreserveIncomingDomain,
325
325
  targetPreserveIncomingProtocol,
@@ -339,7 +339,6 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
339
339
  sourceMustMatchDomain,
340
340
  sourceProjectMapNodeId,
341
341
  sourceRetainQuerystring,
342
- stopExecutingAfter,
343
342
  targetMergeQuerystring,
344
343
  targetPreserveIncomingDomain,
345
344
  targetPreserveIncomingProtocol,
@@ -359,12 +358,38 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
359
358
  this.resetRedirectTrieDataCache();
360
359
  return result.id;
361
360
  };
362
- this.processUrlBestMatch = async (url, options) => {
361
+ this.processUrlBestMatch = async (url, options, useTrie) => {
363
362
  var _a;
363
+ if (!useTrie) {
364
+ const redirects = await this.getRedirects({ sourceUrl: url });
365
+ const processedUrl = processUrl(url);
366
+ const redirect = redirects.redirects[0];
367
+ return _RedirectClient.processDefinitionToResults(
368
+ processedUrl,
369
+ redirect,
370
+ _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
371
+ options
372
+ );
373
+ }
364
374
  const trie = await this.getRedirectTrie();
365
375
  return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
366
376
  };
367
- this.processUrlAllMatches = async (url, options) => {
377
+ this.processUrlAllMatches = async (url, options, useTrie) => {
378
+ if (!useTrie) {
379
+ const redirects = await this.getRedirects({ sourceUrl: url });
380
+ const processedUrl = processUrl(url);
381
+ return redirects.redirects.filter((redirect) => redirect.redirect).map(
382
+ (redirect) => _RedirectClient.processDefinitionToResults(
383
+ processedUrl,
384
+ redirect,
385
+ _RedirectClient.getSourceVariables(
386
+ processedUrl.path,
387
+ processUrl(redirect.redirect.sourceUrl).path
388
+ ),
389
+ options
390
+ )
391
+ );
392
+ }
368
393
  const trie = await this.getRedirectTrie();
369
394
  return _RedirectClient.processHops(url, trie, false, options);
370
395
  };
@@ -427,17 +452,16 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
427
452
  return await _RedirectClient.assemblingPromise;
428
453
  }
429
454
  static processHops(initialUrl, trie, bestMatch, options) {
430
- var _a;
431
455
  const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
432
456
  const isCycle = (id, result) => {
433
- var _a2;
457
+ var _a;
434
458
  if (!id || !result.lastHop)
435
459
  return false;
436
460
  const set = /* @__PURE__ */ new Set([id]);
437
461
  const cycleStack = [result];
438
462
  while (cycleStack.length > 0) {
439
463
  const cur = cycleStack.pop();
440
- const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
464
+ const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
441
465
  if (!(redirect == null ? void 0 : redirect.id))
442
466
  continue;
443
467
  if (set.has(redirect.id))
@@ -455,11 +479,10 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
455
479
  const result = stack.pop();
456
480
  if (!(result == null ? void 0 : result.url))
457
481
  continue;
458
- const redirect = (_a = result.definition) == null ? void 0 : _a.redirect;
459
- const hop = (redirect == null ? void 0 : redirect.stopExecutingAfter) ? [] : this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
482
+ const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
460
483
  (h) => {
461
- var _a2, _b;
462
- return ((_a2 = h.definition) == null ? void 0 : _a2.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
484
+ var _a, _b;
485
+ return ((_a = h.definition) == null ? void 0 : _a.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
463
486
  }
464
487
  );
465
488
  if (hop.length === 0) {
@@ -500,8 +523,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
500
523
  return {
501
524
  url: finalUrl,
502
525
  definition,
503
- label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {
504
- return cur.replace(o.key, `<em>${o.value}</em>`);
526
+ label: (options == null ? void 0 : options.label) ? Object.keys(variables).reduce((cur, o) => {
527
+ return cur.replace(variables[o], `<em>${variables[o]}</em>`);
505
528
  }, finalUrl) : void 0
506
529
  };
507
530
  }
@@ -531,9 +554,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
531
554
  for (const variable in variables) {
532
555
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
533
556
  }
534
- const protocol = redirectDefinition.targetPreserveIncomingProtocol ? processedUrl.protocol : processedTarget.protocol;
535
- const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
536
- const port = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.port : processedTarget.port;
557
+ let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
558
+ const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
559
+ if (domain === "" && protocol !== "") {
560
+ protocol = "";
561
+ }
562
+ const port = domain === "" ? "" : redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.port : processedTarget.port;
537
563
  const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
538
564
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
539
565
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
package/dist/index.js CHANGED
@@ -493,11 +493,10 @@ var PathTrie = class {
493
493
  const splats = [];
494
494
  const processed = /* @__PURE__ */ new Set();
495
495
  const getVariables = () => {
496
- return wildcards.map((wildcard) => {
497
- if (wildcard.active)
498
- return { key: wildcard.name, value: segments[wildcard.start] };
499
- return void 0;
500
- }).filter((wildcard) => Boolean(wildcard));
496
+ return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce((variables, wildcard) => {
497
+ variables[wildcard.name] = segments[wildcard.start];
498
+ return variables;
499
+ }, new Object());
501
500
  };
502
501
  const getPropsStartingWithColon = (obj) => {
503
502
  const result = [];
@@ -529,9 +528,11 @@ var PathTrie = class {
529
528
  const segment = segments[i];
530
529
  if (Object.hasOwn(cur, "*")) {
531
530
  cur["*"][dataProp].forEach((splat) => {
531
+ const vars = getVariables();
532
+ vars[":splat"] = segments.slice(i).join("/");
532
533
  splats.push({
533
534
  data: splat,
534
- variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
535
+ variables: vars
535
536
  });
536
537
  });
537
538
  }
@@ -646,7 +647,6 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
646
647
  sourceMustMatchDomain,
647
648
  sourceProjectMapNodeId,
648
649
  sourceRetainQuerystring,
649
- stopExecutingAfter,
650
650
  targetMergeQuerystring,
651
651
  targetPreserveIncomingDomain,
652
652
  targetPreserveIncomingProtocol,
@@ -666,7 +666,6 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
666
666
  sourceMustMatchDomain,
667
667
  sourceProjectMapNodeId,
668
668
  sourceRetainQuerystring,
669
- stopExecutingAfter,
670
669
  targetMergeQuerystring,
671
670
  targetPreserveIncomingDomain,
672
671
  targetPreserveIncomingProtocol,
@@ -686,12 +685,38 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
686
685
  this.resetRedirectTrieDataCache();
687
686
  return result.id;
688
687
  };
689
- this.processUrlBestMatch = async (url, options) => {
688
+ this.processUrlBestMatch = async (url, options, useTrie) => {
690
689
  var _a;
690
+ if (!useTrie) {
691
+ const redirects = await this.getRedirects({ sourceUrl: url });
692
+ const processedUrl = processUrl(url);
693
+ const redirect = redirects.redirects[0];
694
+ return _RedirectClient.processDefinitionToResults(
695
+ processedUrl,
696
+ redirect,
697
+ _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
698
+ options
699
+ );
700
+ }
691
701
  const trie = await this.getRedirectTrie();
692
702
  return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
693
703
  };
694
- this.processUrlAllMatches = async (url, options) => {
704
+ this.processUrlAllMatches = async (url, options, useTrie) => {
705
+ if (!useTrie) {
706
+ const redirects = await this.getRedirects({ sourceUrl: url });
707
+ const processedUrl = processUrl(url);
708
+ return redirects.redirects.filter((redirect) => redirect.redirect).map(
709
+ (redirect) => _RedirectClient.processDefinitionToResults(
710
+ processedUrl,
711
+ redirect,
712
+ _RedirectClient.getSourceVariables(
713
+ processedUrl.path,
714
+ processUrl(redirect.redirect.sourceUrl).path
715
+ ),
716
+ options
717
+ )
718
+ );
719
+ }
695
720
  const trie = await this.getRedirectTrie();
696
721
  return _RedirectClient.processHops(url, trie, false, options);
697
722
  };
@@ -754,17 +779,16 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
754
779
  return await _RedirectClient.assemblingPromise;
755
780
  }
756
781
  static processHops(initialUrl, trie, bestMatch, options) {
757
- var _a;
758
782
  const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
759
783
  const isCycle = (id, result) => {
760
- var _a2;
784
+ var _a;
761
785
  if (!id || !result.lastHop)
762
786
  return false;
763
787
  const set = /* @__PURE__ */ new Set([id]);
764
788
  const cycleStack = [result];
765
789
  while (cycleStack.length > 0) {
766
790
  const cur = cycleStack.pop();
767
- const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
791
+ const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
768
792
  if (!(redirect == null ? void 0 : redirect.id))
769
793
  continue;
770
794
  if (set.has(redirect.id))
@@ -782,11 +806,10 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
782
806
  const result = stack.pop();
783
807
  if (!(result == null ? void 0 : result.url))
784
808
  continue;
785
- const redirect = (_a = result.definition) == null ? void 0 : _a.redirect;
786
- const hop = (redirect == null ? void 0 : redirect.stopExecutingAfter) ? [] : this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
809
+ const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
787
810
  (h) => {
788
- var _a2, _b;
789
- return ((_a2 = h.definition) == null ? void 0 : _a2.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
811
+ var _a, _b;
812
+ return ((_a = h.definition) == null ? void 0 : _a.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
790
813
  }
791
814
  );
792
815
  if (hop.length === 0) {
@@ -827,8 +850,8 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
827
850
  return {
828
851
  url: finalUrl,
829
852
  definition,
830
- label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {
831
- return cur.replace(o.key, `<em>${o.value}</em>`);
853
+ label: (options == null ? void 0 : options.label) ? Object.keys(variables).reduce((cur, o) => {
854
+ return cur.replace(variables[o], `<em>${variables[o]}</em>`);
832
855
  }, finalUrl) : void 0
833
856
  };
834
857
  }
@@ -858,9 +881,12 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
858
881
  for (const variable in variables) {
859
882
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
860
883
  }
861
- const protocol = redirectDefinition.targetPreserveIncomingProtocol ? processedUrl.protocol : processedTarget.protocol;
862
- const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
863
- const port = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.port : processedTarget.port;
884
+ let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
885
+ const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
886
+ if (domain === "" && protocol !== "") {
887
+ protocol = "";
888
+ }
889
+ const port = domain === "" ? "" : redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.port : processedTarget.port;
864
890
  const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
865
891
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
866
892
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
package/dist/index.mjs CHANGED
@@ -166,11 +166,10 @@ var PathTrie = class {
166
166
  const splats = [];
167
167
  const processed = /* @__PURE__ */ new Set();
168
168
  const getVariables = () => {
169
- return wildcards.map((wildcard) => {
170
- if (wildcard.active)
171
- return { key: wildcard.name, value: segments[wildcard.start] };
172
- return void 0;
173
- }).filter((wildcard) => Boolean(wildcard));
169
+ return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce((variables, wildcard) => {
170
+ variables[wildcard.name] = segments[wildcard.start];
171
+ return variables;
172
+ }, new Object());
174
173
  };
175
174
  const getPropsStartingWithColon = (obj) => {
176
175
  const result = [];
@@ -202,9 +201,11 @@ var PathTrie = class {
202
201
  const segment = segments[i];
203
202
  if (Object.hasOwn(cur, "*")) {
204
203
  cur["*"][dataProp].forEach((splat) => {
204
+ const vars = getVariables();
205
+ vars[":splat"] = segments.slice(i).join("/");
205
206
  splats.push({
206
207
  data: splat,
207
- variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
208
+ variables: vars
208
209
  });
209
210
  });
210
211
  }
@@ -319,7 +320,6 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
319
320
  sourceMustMatchDomain,
320
321
  sourceProjectMapNodeId,
321
322
  sourceRetainQuerystring,
322
- stopExecutingAfter,
323
323
  targetMergeQuerystring,
324
324
  targetPreserveIncomingDomain,
325
325
  targetPreserveIncomingProtocol,
@@ -339,7 +339,6 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
339
339
  sourceMustMatchDomain,
340
340
  sourceProjectMapNodeId,
341
341
  sourceRetainQuerystring,
342
- stopExecutingAfter,
343
342
  targetMergeQuerystring,
344
343
  targetPreserveIncomingDomain,
345
344
  targetPreserveIncomingProtocol,
@@ -359,12 +358,38 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
359
358
  this.resetRedirectTrieDataCache();
360
359
  return result.id;
361
360
  };
362
- this.processUrlBestMatch = async (url, options) => {
361
+ this.processUrlBestMatch = async (url, options, useTrie) => {
363
362
  var _a;
363
+ if (!useTrie) {
364
+ const redirects = await this.getRedirects({ sourceUrl: url });
365
+ const processedUrl = processUrl(url);
366
+ const redirect = redirects.redirects[0];
367
+ return _RedirectClient.processDefinitionToResults(
368
+ processedUrl,
369
+ redirect,
370
+ _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
371
+ options
372
+ );
373
+ }
364
374
  const trie = await this.getRedirectTrie();
365
375
  return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
366
376
  };
367
- this.processUrlAllMatches = async (url, options) => {
377
+ this.processUrlAllMatches = async (url, options, useTrie) => {
378
+ if (!useTrie) {
379
+ const redirects = await this.getRedirects({ sourceUrl: url });
380
+ const processedUrl = processUrl(url);
381
+ return redirects.redirects.filter((redirect) => redirect.redirect).map(
382
+ (redirect) => _RedirectClient.processDefinitionToResults(
383
+ processedUrl,
384
+ redirect,
385
+ _RedirectClient.getSourceVariables(
386
+ processedUrl.path,
387
+ processUrl(redirect.redirect.sourceUrl).path
388
+ ),
389
+ options
390
+ )
391
+ );
392
+ }
368
393
  const trie = await this.getRedirectTrie();
369
394
  return _RedirectClient.processHops(url, trie, false, options);
370
395
  };
@@ -427,17 +452,16 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
427
452
  return await _RedirectClient.assemblingPromise;
428
453
  }
429
454
  static processHops(initialUrl, trie, bestMatch, options) {
430
- var _a;
431
455
  const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
432
456
  const isCycle = (id, result) => {
433
- var _a2;
457
+ var _a;
434
458
  if (!id || !result.lastHop)
435
459
  return false;
436
460
  const set = /* @__PURE__ */ new Set([id]);
437
461
  const cycleStack = [result];
438
462
  while (cycleStack.length > 0) {
439
463
  const cur = cycleStack.pop();
440
- const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
464
+ const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
441
465
  if (!(redirect == null ? void 0 : redirect.id))
442
466
  continue;
443
467
  if (set.has(redirect.id))
@@ -455,11 +479,10 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
455
479
  const result = stack.pop();
456
480
  if (!(result == null ? void 0 : result.url))
457
481
  continue;
458
- const redirect = (_a = result.definition) == null ? void 0 : _a.redirect;
459
- const hop = (redirect == null ? void 0 : redirect.stopExecutingAfter) ? [] : this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
482
+ const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
460
483
  (h) => {
461
- var _a2, _b;
462
- return ((_a2 = h.definition) == null ? void 0 : _a2.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
484
+ var _a, _b;
485
+ return ((_a = h.definition) == null ? void 0 : _a.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
463
486
  }
464
487
  );
465
488
  if (hop.length === 0) {
@@ -500,8 +523,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
500
523
  return {
501
524
  url: finalUrl,
502
525
  definition,
503
- label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {
504
- return cur.replace(o.key, `<em>${o.value}</em>`);
526
+ label: (options == null ? void 0 : options.label) ? Object.keys(variables).reduce((cur, o) => {
527
+ return cur.replace(variables[o], `<em>${variables[o]}</em>`);
505
528
  }, finalUrl) : void 0
506
529
  };
507
530
  }
@@ -531,9 +554,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
531
554
  for (const variable in variables) {
532
555
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
533
556
  }
534
- const protocol = redirectDefinition.targetPreserveIncomingProtocol ? processedUrl.protocol : processedTarget.protocol;
535
- const domain = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.domain : processedTarget.domain;
536
- const port = redirectDefinition.targetPreserveIncomingDomain ? processedUrl.port : processedTarget.port;
557
+ let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
558
+ const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
559
+ if (domain === "" && protocol !== "") {
560
+ protocol = "";
561
+ }
562
+ const port = domain === "" ? "" : redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.port : processedTarget.port;
537
563
  const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
538
564
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
539
565
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/redirect",
3
- "version": "19.37.1",
3
+ "version": "19.38.2",
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.37.1",
35
+ "@uniformdev/context": "19.38.2",
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": "9de2a3f7515d658d07d7d1fb8ebf4805172e655c"
42
+ "gitHead": "b97fd17fd44e0f5bd3806e942b516cb2bd218096"
43
43
  }