@uniformdev/redirect 19.37.1 → 19.38.3-alpha.70

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,40 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
359
358
  this.resetRedirectTrieDataCache();
360
359
  return result.id;
361
360
  };
362
- this.processUrlBestMatch = async (url, options) => {
363
- var _a;
361
+ this.processUrlBestMatch = async (url, options, useTrie) => {
362
+ var _a, _b;
363
+ if (!useTrie) {
364
+ const redirects = await this.getRedirects({ sourceUrl: url });
365
+ const processedUrl = processUrl(url);
366
+ const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
367
+ if (!redirect)
368
+ return void 0;
369
+ return _RedirectClient.processDefinitionToResults(
370
+ processedUrl,
371
+ redirect,
372
+ _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
373
+ options
374
+ );
375
+ }
364
376
  const trie = await this.getRedirectTrie();
365
- return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
377
+ return (_b = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _b[0];
366
378
  };
367
- this.processUrlAllMatches = async (url, options) => {
379
+ this.processUrlAllMatches = async (url, options, useTrie) => {
380
+ if (!useTrie) {
381
+ const redirects = await this.getRedirects({ sourceUrl: url });
382
+ const processedUrl = processUrl(url);
383
+ return redirects.redirects.filter((redirect) => redirect.redirect).map(
384
+ (redirect) => _RedirectClient.processDefinitionToResults(
385
+ processedUrl,
386
+ redirect,
387
+ _RedirectClient.getSourceVariables(
388
+ processedUrl.path,
389
+ processUrl(redirect.redirect.sourceUrl).path
390
+ ),
391
+ options
392
+ )
393
+ );
394
+ }
368
395
  const trie = await this.getRedirectTrie();
369
396
  return _RedirectClient.processHops(url, trie, false, options);
370
397
  };
@@ -427,17 +454,16 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
427
454
  return await _RedirectClient.assemblingPromise;
428
455
  }
429
456
  static processHops(initialUrl, trie, bestMatch, options) {
430
- var _a;
431
457
  const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
432
458
  const isCycle = (id, result) => {
433
- var _a2;
459
+ var _a;
434
460
  if (!id || !result.lastHop)
435
461
  return false;
436
462
  const set = /* @__PURE__ */ new Set([id]);
437
463
  const cycleStack = [result];
438
464
  while (cycleStack.length > 0) {
439
465
  const cur = cycleStack.pop();
440
- const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
466
+ const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
441
467
  if (!(redirect == null ? void 0 : redirect.id))
442
468
  continue;
443
469
  if (set.has(redirect.id))
@@ -455,11 +481,10 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
455
481
  const result = stack.pop();
456
482
  if (!(result == null ? void 0 : result.url))
457
483
  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(
484
+ const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
460
485
  (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);
486
+ var _a, _b;
487
+ return ((_a = h.definition) == null ? void 0 : _a.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
463
488
  }
464
489
  );
465
490
  if (hop.length === 0) {
@@ -500,8 +525,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
500
525
  return {
501
526
  url: finalUrl,
502
527
  definition,
503
- label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {
504
- return cur.replace(o.key, `<em>${o.value}</em>`);
528
+ label: (options == null ? void 0 : options.label) ? Object.keys(variables).reduce((cur, o) => {
529
+ return cur.replace(variables[o], `<em>${variables[o]}</em>`);
505
530
  }, finalUrl) : void 0
506
531
  };
507
532
  }
@@ -531,9 +556,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
531
556
  for (const variable in variables) {
532
557
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
533
558
  }
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;
559
+ let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
560
+ const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
561
+ if (domain === "" && protocol !== "") {
562
+ protocol = "";
563
+ }
564
+ const port = domain === "" ? "" : redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.port : processedTarget.port;
537
565
  const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
538
566
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
539
567
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
@@ -587,7 +615,7 @@ var UncachedRedirectClient = class extends RedirectClient {
587
615
 
588
616
  // src/util/RedirectFileConverter.ts
589
617
  var getDefaultClient = async () => {
590
- const dotenv = await import("./main-HWDEQR7W.mjs");
618
+ const dotenv = await import("./main-4Y7KG46W.mjs");
591
619
  dotenv.config();
592
620
  return new RedirectClient({
593
621
  apiKey: process.env.UNIFORM_API_KEY,
package/dist/index.js CHANGED
@@ -30,12 +30,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
30
30
  ));
31
31
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
32
32
 
33
- // ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json
33
+ // ../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/package.json
34
34
  var require_package = __commonJS({
35
- "../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json"(exports, module2) {
35
+ "../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/package.json"(exports, module2) {
36
36
  module2.exports = {
37
37
  name: "dotenv",
38
- version: "16.1.3",
38
+ version: "16.3.1",
39
39
  description: "Loads environment variables from .env file",
40
40
  main: "lib/main.js",
41
41
  types: "lib/main.d.ts",
@@ -100,9 +100,9 @@ var require_package = __commonJS({
100
100
  }
101
101
  });
102
102
 
103
- // ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js
103
+ // ../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/lib/main.js
104
104
  var require_main = __commonJS({
105
- "../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js"(exports, module2) {
105
+ "../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/lib/main.js"(exports, module2) {
106
106
  "use strict";
107
107
  var fs = require("fs");
108
108
  var path = require("path");
@@ -136,7 +136,7 @@ var require_main = __commonJS({
136
136
  if (!result.parsed) {
137
137
  throw new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
138
138
  }
139
- const keys = _dotenvKey().split(",");
139
+ const keys = _dotenvKey(options).split(",");
140
140
  const length = keys.length;
141
141
  let decrypted;
142
142
  for (let i = 0; i < length; i++) {
@@ -162,7 +162,10 @@ var require_main = __commonJS({
162
162
  function _debug(message) {
163
163
  console.log(`[dotenv@${version}][DEBUG] ${message}`);
164
164
  }
165
- function _dotenvKey() {
165
+ function _dotenvKey(options) {
166
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
167
+ return options.DOTENV_KEY;
168
+ }
166
169
  if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
167
170
  return process.env.DOTENV_KEY;
168
171
  }
@@ -206,7 +209,11 @@ var require_main = __commonJS({
206
209
  function _configVault(options) {
207
210
  _log("Loading env from encrypted .env.vault");
208
211
  const parsed = DotenvModule._parseVault(options);
209
- DotenvModule.populate(process.env, parsed, options);
212
+ let processEnv = process.env;
213
+ if (options && options.processEnv != null) {
214
+ processEnv = options.processEnv;
215
+ }
216
+ DotenvModule.populate(processEnv, parsed, options);
210
217
  return { parsed };
211
218
  }
212
219
  function configDotenv(options) {
@@ -223,7 +230,11 @@ var require_main = __commonJS({
223
230
  }
224
231
  try {
225
232
  const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
226
- DotenvModule.populate(process.env, parsed, options);
233
+ let processEnv = process.env;
234
+ if (options && options.processEnv != null) {
235
+ processEnv = options.processEnv;
236
+ }
237
+ DotenvModule.populate(processEnv, parsed, options);
227
238
  return { parsed };
228
239
  } catch (e) {
229
240
  if (debug) {
@@ -234,7 +245,7 @@ var require_main = __commonJS({
234
245
  }
235
246
  function config(options) {
236
247
  const vaultPath = _vaultPath(options);
237
- if (_dotenvKey().length === 0) {
248
+ if (_dotenvKey(options).length === 0) {
238
249
  return DotenvModule.configDotenv(options);
239
250
  }
240
251
  if (!fs.existsSync(vaultPath)) {
@@ -493,11 +504,10 @@ var PathTrie = class {
493
504
  const splats = [];
494
505
  const processed = /* @__PURE__ */ new Set();
495
506
  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));
507
+ return wildcards.filter((wildcard) => Boolean(wildcard) && wildcard.active).reduce((variables, wildcard) => {
508
+ variables[wildcard.name] = segments[wildcard.start];
509
+ return variables;
510
+ }, new Object());
501
511
  };
502
512
  const getPropsStartingWithColon = (obj) => {
503
513
  const result = [];
@@ -529,9 +539,11 @@ var PathTrie = class {
529
539
  const segment = segments[i];
530
540
  if (Object.hasOwn(cur, "*")) {
531
541
  cur["*"][dataProp].forEach((splat) => {
542
+ const vars = getVariables();
543
+ vars[":splat"] = segments.slice(i).join("/");
532
544
  splats.push({
533
545
  data: splat,
534
- variables: [...getVariables(), { key: ":splat", value: segments.slice(i).join("/") }]
546
+ variables: vars
535
547
  });
536
548
  });
537
549
  }
@@ -646,7 +658,6 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
646
658
  sourceMustMatchDomain,
647
659
  sourceProjectMapNodeId,
648
660
  sourceRetainQuerystring,
649
- stopExecutingAfter,
650
661
  targetMergeQuerystring,
651
662
  targetPreserveIncomingDomain,
652
663
  targetPreserveIncomingProtocol,
@@ -666,7 +677,6 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
666
677
  sourceMustMatchDomain,
667
678
  sourceProjectMapNodeId,
668
679
  sourceRetainQuerystring,
669
- stopExecutingAfter,
670
680
  targetMergeQuerystring,
671
681
  targetPreserveIncomingDomain,
672
682
  targetPreserveIncomingProtocol,
@@ -686,12 +696,40 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
686
696
  this.resetRedirectTrieDataCache();
687
697
  return result.id;
688
698
  };
689
- this.processUrlBestMatch = async (url, options) => {
690
- var _a;
699
+ this.processUrlBestMatch = async (url, options, useTrie) => {
700
+ var _a, _b;
701
+ if (!useTrie) {
702
+ const redirects = await this.getRedirects({ sourceUrl: url });
703
+ const processedUrl = processUrl(url);
704
+ const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
705
+ if (!redirect)
706
+ return void 0;
707
+ return _RedirectClient.processDefinitionToResults(
708
+ processedUrl,
709
+ redirect,
710
+ _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
711
+ options
712
+ );
713
+ }
691
714
  const trie = await this.getRedirectTrie();
692
- return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
715
+ return (_b = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _b[0];
693
716
  };
694
- this.processUrlAllMatches = async (url, options) => {
717
+ this.processUrlAllMatches = async (url, options, useTrie) => {
718
+ if (!useTrie) {
719
+ const redirects = await this.getRedirects({ sourceUrl: url });
720
+ const processedUrl = processUrl(url);
721
+ return redirects.redirects.filter((redirect) => redirect.redirect).map(
722
+ (redirect) => _RedirectClient.processDefinitionToResults(
723
+ processedUrl,
724
+ redirect,
725
+ _RedirectClient.getSourceVariables(
726
+ processedUrl.path,
727
+ processUrl(redirect.redirect.sourceUrl).path
728
+ ),
729
+ options
730
+ )
731
+ );
732
+ }
695
733
  const trie = await this.getRedirectTrie();
696
734
  return _RedirectClient.processHops(url, trie, false, options);
697
735
  };
@@ -754,17 +792,16 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
754
792
  return await _RedirectClient.assemblingPromise;
755
793
  }
756
794
  static processHops(initialUrl, trie, bestMatch, options) {
757
- var _a;
758
795
  const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
759
796
  const isCycle = (id, result) => {
760
- var _a2;
797
+ var _a;
761
798
  if (!id || !result.lastHop)
762
799
  return false;
763
800
  const set = /* @__PURE__ */ new Set([id]);
764
801
  const cycleStack = [result];
765
802
  while (cycleStack.length > 0) {
766
803
  const cur = cycleStack.pop();
767
- const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
804
+ const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
768
805
  if (!(redirect == null ? void 0 : redirect.id))
769
806
  continue;
770
807
  if (set.has(redirect.id))
@@ -782,11 +819,10 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
782
819
  const result = stack.pop();
783
820
  if (!(result == null ? void 0 : result.url))
784
821
  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(
822
+ const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
787
823
  (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);
824
+ var _a, _b;
825
+ return ((_a = h.definition) == null ? void 0 : _a.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
790
826
  }
791
827
  );
792
828
  if (hop.length === 0) {
@@ -827,8 +863,8 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
827
863
  return {
828
864
  url: finalUrl,
829
865
  definition,
830
- label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {
831
- return cur.replace(o.key, `<em>${o.value}</em>`);
866
+ label: (options == null ? void 0 : options.label) ? Object.keys(variables).reduce((cur, o) => {
867
+ return cur.replace(variables[o], `<em>${variables[o]}</em>`);
832
868
  }, finalUrl) : void 0
833
869
  };
834
870
  }
@@ -858,9 +894,12 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
858
894
  for (const variable in variables) {
859
895
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
860
896
  }
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;
897
+ let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
898
+ const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
899
+ if (domain === "" && protocol !== "") {
900
+ protocol = "";
901
+ }
902
+ const port = domain === "" ? "" : redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.port : processedTarget.port;
864
903
  const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
865
904
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
866
905
  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,40 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
359
358
  this.resetRedirectTrieDataCache();
360
359
  return result.id;
361
360
  };
362
- this.processUrlBestMatch = async (url, options) => {
363
- var _a;
361
+ this.processUrlBestMatch = async (url, options, useTrie) => {
362
+ var _a, _b;
363
+ if (!useTrie) {
364
+ const redirects = await this.getRedirects({ sourceUrl: url });
365
+ const processedUrl = processUrl(url);
366
+ const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
367
+ if (!redirect)
368
+ return void 0;
369
+ return _RedirectClient.processDefinitionToResults(
370
+ processedUrl,
371
+ redirect,
372
+ _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
373
+ options
374
+ );
375
+ }
364
376
  const trie = await this.getRedirectTrie();
365
- return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
377
+ return (_b = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _b[0];
366
378
  };
367
- this.processUrlAllMatches = async (url, options) => {
379
+ this.processUrlAllMatches = async (url, options, useTrie) => {
380
+ if (!useTrie) {
381
+ const redirects = await this.getRedirects({ sourceUrl: url });
382
+ const processedUrl = processUrl(url);
383
+ return redirects.redirects.filter((redirect) => redirect.redirect).map(
384
+ (redirect) => _RedirectClient.processDefinitionToResults(
385
+ processedUrl,
386
+ redirect,
387
+ _RedirectClient.getSourceVariables(
388
+ processedUrl.path,
389
+ processUrl(redirect.redirect.sourceUrl).path
390
+ ),
391
+ options
392
+ )
393
+ );
394
+ }
368
395
  const trie = await this.getRedirectTrie();
369
396
  return _RedirectClient.processHops(url, trie, false, options);
370
397
  };
@@ -427,17 +454,16 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
427
454
  return await _RedirectClient.assemblingPromise;
428
455
  }
429
456
  static processHops(initialUrl, trie, bestMatch, options) {
430
- var _a;
431
457
  const url = (options == null ? void 0 : options.reverse) ? initialUrl.replace(/\/:/, "/~~") : initialUrl;
432
458
  const isCycle = (id, result) => {
433
- var _a2;
459
+ var _a;
434
460
  if (!id || !result.lastHop)
435
461
  return false;
436
462
  const set = /* @__PURE__ */ new Set([id]);
437
463
  const cycleStack = [result];
438
464
  while (cycleStack.length > 0) {
439
465
  const cur = cycleStack.pop();
440
- const redirect = (_a2 = cur == null ? void 0 : cur.definition) == null ? void 0 : _a2.redirect;
466
+ const redirect = (_a = cur == null ? void 0 : cur.definition) == null ? void 0 : _a.redirect;
441
467
  if (!(redirect == null ? void 0 : redirect.id))
442
468
  continue;
443
469
  if (set.has(redirect.id))
@@ -455,11 +481,10 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
455
481
  const result = stack.pop();
456
482
  if (!(result == null ? void 0 : result.url))
457
483
  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(
484
+ const hop = this.processHop(result == null ? void 0 : result.url, trie, bestMatch, options).filter(
460
485
  (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);
486
+ var _a, _b;
487
+ return ((_a = h.definition) == null ? void 0 : _a.redirect.id) && !isCycle((_b = h.definition) == null ? void 0 : _b.redirect.id, result);
463
488
  }
464
489
  );
465
490
  if (hop.length === 0) {
@@ -500,8 +525,8 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
500
525
  return {
501
526
  url: finalUrl,
502
527
  definition,
503
- label: (options == null ? void 0 : options.label) ? variables.reduce((cur, o) => {
504
- return cur.replace(o.key, `<em>${o.value}</em>`);
528
+ label: (options == null ? void 0 : options.label) ? Object.keys(variables).reduce((cur, o) => {
529
+ return cur.replace(variables[o], `<em>${variables[o]}</em>`);
505
530
  }, finalUrl) : void 0
506
531
  };
507
532
  }
@@ -531,9 +556,12 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
531
556
  for (const variable in variables) {
532
557
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
533
558
  }
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;
559
+ let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
560
+ const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
561
+ if (domain === "" && protocol !== "") {
562
+ protocol = "";
563
+ }
564
+ const port = domain === "" ? "" : redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.port : processedTarget.port;
537
565
  const query = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.query, processedTarget.query) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.query : processedTarget.query;
538
566
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? this.mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
539
567
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
@@ -587,7 +615,7 @@ var UncachedRedirectClient = class extends RedirectClient {
587
615
 
588
616
  // src/util/RedirectFileConverter.ts
589
617
  var getDefaultClient = async () => {
590
- const dotenv = await import("./main-HWDEQR7W.mjs");
618
+ const dotenv = await import("./main-4Y7KG46W.mjs");
591
619
  dotenv.config();
592
620
  return new RedirectClient({
593
621
  apiKey: process.env.UNIFORM_API_KEY,
@@ -3,12 +3,12 @@ import {
3
3
  __require
4
4
  } from "./chunk-TLYAXJ7N.mjs";
5
5
 
6
- // ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json
6
+ // ../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/package.json
7
7
  var require_package = __commonJS({
8
- "../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/package.json"(exports, module) {
8
+ "../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/package.json"(exports, module) {
9
9
  module.exports = {
10
10
  name: "dotenv",
11
- version: "16.1.3",
11
+ version: "16.3.1",
12
12
  description: "Loads environment variables from .env file",
13
13
  main: "lib/main.js",
14
14
  types: "lib/main.d.ts",
@@ -73,9 +73,9 @@ var require_package = __commonJS({
73
73
  }
74
74
  });
75
75
 
76
- // ../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js
76
+ // ../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/lib/main.js
77
77
  var require_main = __commonJS({
78
- "../../node_modules/.pnpm/dotenv@16.1.3/node_modules/dotenv/lib/main.js"(exports, module) {
78
+ "../../node_modules/.pnpm/dotenv@16.3.1/node_modules/dotenv/lib/main.js"(exports, module) {
79
79
  var fs = __require("fs");
80
80
  var path = __require("path");
81
81
  var os = __require("os");
@@ -108,7 +108,7 @@ var require_main = __commonJS({
108
108
  if (!result.parsed) {
109
109
  throw new Error(`MISSING_DATA: Cannot parse ${vaultPath} for an unknown reason`);
110
110
  }
111
- const keys = _dotenvKey().split(",");
111
+ const keys = _dotenvKey(options).split(",");
112
112
  const length = keys.length;
113
113
  let decrypted;
114
114
  for (let i = 0; i < length; i++) {
@@ -134,7 +134,10 @@ var require_main = __commonJS({
134
134
  function _debug(message) {
135
135
  console.log(`[dotenv@${version}][DEBUG] ${message}`);
136
136
  }
137
- function _dotenvKey() {
137
+ function _dotenvKey(options) {
138
+ if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) {
139
+ return options.DOTENV_KEY;
140
+ }
138
141
  if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) {
139
142
  return process.env.DOTENV_KEY;
140
143
  }
@@ -178,7 +181,11 @@ var require_main = __commonJS({
178
181
  function _configVault(options) {
179
182
  _log("Loading env from encrypted .env.vault");
180
183
  const parsed = DotenvModule._parseVault(options);
181
- DotenvModule.populate(process.env, parsed, options);
184
+ let processEnv = process.env;
185
+ if (options && options.processEnv != null) {
186
+ processEnv = options.processEnv;
187
+ }
188
+ DotenvModule.populate(processEnv, parsed, options);
182
189
  return { parsed };
183
190
  }
184
191
  function configDotenv(options) {
@@ -195,7 +202,11 @@ var require_main = __commonJS({
195
202
  }
196
203
  try {
197
204
  const parsed = DotenvModule.parse(fs.readFileSync(dotenvPath, { encoding }));
198
- DotenvModule.populate(process.env, parsed, options);
205
+ let processEnv = process.env;
206
+ if (options && options.processEnv != null) {
207
+ processEnv = options.processEnv;
208
+ }
209
+ DotenvModule.populate(processEnv, parsed, options);
199
210
  return { parsed };
200
211
  } catch (e) {
201
212
  if (debug) {
@@ -206,7 +217,7 @@ var require_main = __commonJS({
206
217
  }
207
218
  function config(options) {
208
219
  const vaultPath = _vaultPath(options);
209
- if (_dotenvKey().length === 0) {
220
+ if (_dotenvKey(options).length === 0) {
210
221
  return DotenvModule.configDotenv(options);
211
222
  }
212
223
  if (!fs.existsSync(vaultPath)) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/redirect",
3
- "version": "19.37.1",
3
+ "version": "19.38.3-alpha.70+55e5a8fe1",
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.3-alpha.70+55e5a8fe1",
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": "55e5a8fe1d80971a93ea31d3a50cec72e71be70a"
43
43
  }