@uniformdev/redirect 19.38.2 → 19.38.3-alpha.78

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
@@ -137,6 +137,8 @@ interface paths {
137
137
  ids?: string[];
138
138
  /** Source url to attempt to find redirects for */
139
139
  sourceUrl?: string;
140
+ /** Find redirects that could redirect to this url */
141
+ targetUrl?: string;
140
142
  /** Id of the project map the source or target belongs to. */
141
143
  projectMapId?: string;
142
144
  /** Id of the project map node to find redirects for. */
@@ -389,7 +391,7 @@ type RedirectDataCache = {
389
391
  preload?: boolean;
390
392
  };
391
393
  type RedirectClientGetRedirect = Pick<RedirectClientGetRequest, 'id' | 'projectMapId' | 'sourceProjectMapNodeId' | 'targetProjectMapNodeId'>;
392
- type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search' | 'sourceUrl'>;
394
+ type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search' | 'sourceUrl' | 'targetUrl'>;
393
395
 
394
396
  declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
395
397
  private static refresher?;
package/dist/index.d.ts CHANGED
@@ -137,6 +137,8 @@ interface paths {
137
137
  ids?: string[];
138
138
  /** Source url to attempt to find redirects for */
139
139
  sourceUrl?: string;
140
+ /** Find redirects that could redirect to this url */
141
+ targetUrl?: string;
140
142
  /** Id of the project map the source or target belongs to. */
141
143
  projectMapId?: string;
142
144
  /** Id of the project map node to find redirects for. */
@@ -389,7 +391,7 @@ type RedirectDataCache = {
389
391
  preload?: boolean;
390
392
  };
391
393
  type RedirectClientGetRedirect = Pick<RedirectClientGetRequest, 'id' | 'projectMapId' | 'sourceProjectMapNodeId' | 'targetProjectMapNodeId'>;
392
- type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search' | 'sourceUrl'>;
394
+ type RedirectClientGetRedirects = Pick<RedirectClientGetRequest, 'ids' | 'limit' | 'offset' | 'orderBy' | 'search' | 'sourceUrl' | 'targetUrl'>;
393
395
 
394
396
  declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOptions> {
395
397
  private static refresher?;
package/dist/index.esm.js CHANGED
@@ -359,39 +359,50 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
359
359
  return result.id;
360
360
  };
361
361
  this.processUrlBestMatch = async (url, options, useTrie) => {
362
- var _a;
362
+ var _a, _b;
363
+ const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
363
364
  if (!useTrie) {
364
- const redirects = await this.getRedirects({ sourceUrl: url });
365
- const processedUrl = processUrl(url);
366
- const redirect = redirects.redirects[0];
365
+ const redirects = await this.getRedirects(
366
+ (options == null ? void 0 : options.reverse) ? { targetUrl: sanitizedUrl } : { sourceUrl: sanitizedUrl }
367
+ );
368
+ const processedUrl = processUrl(sanitizedUrl);
369
+ const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
370
+ if (!redirect)
371
+ return void 0;
367
372
  return _RedirectClient.processDefinitionToResults(
368
373
  processedUrl,
369
374
  redirect,
370
- _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
375
+ _RedirectClient.getSourceVariables(
376
+ processedUrl.path,
377
+ processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
378
+ ),
371
379
  options
372
380
  );
373
381
  }
374
382
  const trie = await this.getRedirectTrie();
375
- return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
383
+ return (_b = _RedirectClient.processHops(sanitizedUrl, trie, true, options)) == null ? void 0 : _b[0];
376
384
  };
377
385
  this.processUrlAllMatches = async (url, options, useTrie) => {
386
+ const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
378
387
  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(
388
+ const redirects = await this.getRedirects(
389
+ (options == null ? void 0 : options.reverse) ? { targetUrl: sanitizedUrl } : { sourceUrl: sanitizedUrl }
390
+ );
391
+ const processedUrl = processUrl(sanitizedUrl);
392
+ return redirects.redirects.filter((redirect) => redirect.redirect).map((redirect) => {
393
+ return _RedirectClient.processDefinitionToResults(
383
394
  processedUrl,
384
395
  redirect,
385
396
  _RedirectClient.getSourceVariables(
386
397
  processedUrl.path,
387
- processUrl(redirect.redirect.sourceUrl).path
398
+ processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
388
399
  ),
389
400
  options
390
- )
391
- );
401
+ );
402
+ });
392
403
  }
393
404
  const trie = await this.getRedirectTrie();
394
- return _RedirectClient.processHops(url, trie, false, options);
405
+ return _RedirectClient.processHops(sanitizedUrl, trie, false, options);
395
406
  };
396
407
  if (options.dataCache && options.dataCache.options.prePopulate) {
397
408
  if (!options.dataCache.get(options.projectId)) {
@@ -613,7 +624,7 @@ var UncachedRedirectClient = class extends RedirectClient {
613
624
 
614
625
  // src/util/RedirectFileConverter.ts
615
626
  var getDefaultClient = async () => {
616
- const dotenv = await import("./main-HWDEQR7W.mjs");
627
+ const dotenv = await import("./main-4Y7KG46W.mjs");
617
628
  dotenv.config();
618
629
  return new RedirectClient({
619
630
  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)) {
@@ -686,39 +697,50 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
686
697
  return result.id;
687
698
  };
688
699
  this.processUrlBestMatch = async (url, options, useTrie) => {
689
- var _a;
700
+ var _a, _b;
701
+ const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
690
702
  if (!useTrie) {
691
- const redirects = await this.getRedirects({ sourceUrl: url });
692
- const processedUrl = processUrl(url);
693
- const redirect = redirects.redirects[0];
703
+ const redirects = await this.getRedirects(
704
+ (options == null ? void 0 : options.reverse) ? { targetUrl: sanitizedUrl } : { sourceUrl: sanitizedUrl }
705
+ );
706
+ const processedUrl = processUrl(sanitizedUrl);
707
+ const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
708
+ if (!redirect)
709
+ return void 0;
694
710
  return _RedirectClient.processDefinitionToResults(
695
711
  processedUrl,
696
712
  redirect,
697
- _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
713
+ _RedirectClient.getSourceVariables(
714
+ processedUrl.path,
715
+ processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
716
+ ),
698
717
  options
699
718
  );
700
719
  }
701
720
  const trie = await this.getRedirectTrie();
702
- return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
721
+ return (_b = _RedirectClient.processHops(sanitizedUrl, trie, true, options)) == null ? void 0 : _b[0];
703
722
  };
704
723
  this.processUrlAllMatches = async (url, options, useTrie) => {
724
+ const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
705
725
  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(
726
+ const redirects = await this.getRedirects(
727
+ (options == null ? void 0 : options.reverse) ? { targetUrl: sanitizedUrl } : { sourceUrl: sanitizedUrl }
728
+ );
729
+ const processedUrl = processUrl(sanitizedUrl);
730
+ return redirects.redirects.filter((redirect) => redirect.redirect).map((redirect) => {
731
+ return _RedirectClient.processDefinitionToResults(
710
732
  processedUrl,
711
733
  redirect,
712
734
  _RedirectClient.getSourceVariables(
713
735
  processedUrl.path,
714
- processUrl(redirect.redirect.sourceUrl).path
736
+ processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
715
737
  ),
716
738
  options
717
- )
718
- );
739
+ );
740
+ });
719
741
  }
720
742
  const trie = await this.getRedirectTrie();
721
- return _RedirectClient.processHops(url, trie, false, options);
743
+ return _RedirectClient.processHops(sanitizedUrl, trie, false, options);
722
744
  };
723
745
  if (options.dataCache && options.dataCache.options.prePopulate) {
724
746
  if (!options.dataCache.get(options.projectId)) {
package/dist/index.mjs CHANGED
@@ -359,39 +359,50 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
359
359
  return result.id;
360
360
  };
361
361
  this.processUrlBestMatch = async (url, options, useTrie) => {
362
- var _a;
362
+ var _a, _b;
363
+ const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
363
364
  if (!useTrie) {
364
- const redirects = await this.getRedirects({ sourceUrl: url });
365
- const processedUrl = processUrl(url);
366
- const redirect = redirects.redirects[0];
365
+ const redirects = await this.getRedirects(
366
+ (options == null ? void 0 : options.reverse) ? { targetUrl: sanitizedUrl } : { sourceUrl: sanitizedUrl }
367
+ );
368
+ const processedUrl = processUrl(sanitizedUrl);
369
+ const redirect = (_a = redirects == null ? void 0 : redirects.redirects) == null ? void 0 : _a[0];
370
+ if (!redirect)
371
+ return void 0;
367
372
  return _RedirectClient.processDefinitionToResults(
368
373
  processedUrl,
369
374
  redirect,
370
- _RedirectClient.getSourceVariables(processedUrl.path, processUrl(redirect.redirect.sourceUrl).path),
375
+ _RedirectClient.getSourceVariables(
376
+ processedUrl.path,
377
+ processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
378
+ ),
371
379
  options
372
380
  );
373
381
  }
374
382
  const trie = await this.getRedirectTrie();
375
- return (_a = _RedirectClient.processHops(url, trie, true, options)) == null ? void 0 : _a[0];
383
+ return (_b = _RedirectClient.processHops(sanitizedUrl, trie, true, options)) == null ? void 0 : _b[0];
376
384
  };
377
385
  this.processUrlAllMatches = async (url, options, useTrie) => {
386
+ const sanitizedUrl = url.endsWith("/") ? url.replace(/\/+$/, "") : url;
378
387
  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(
388
+ const redirects = await this.getRedirects(
389
+ (options == null ? void 0 : options.reverse) ? { targetUrl: sanitizedUrl } : { sourceUrl: sanitizedUrl }
390
+ );
391
+ const processedUrl = processUrl(sanitizedUrl);
392
+ return redirects.redirects.filter((redirect) => redirect.redirect).map((redirect) => {
393
+ return _RedirectClient.processDefinitionToResults(
383
394
  processedUrl,
384
395
  redirect,
385
396
  _RedirectClient.getSourceVariables(
386
397
  processedUrl.path,
387
- processUrl(redirect.redirect.sourceUrl).path
398
+ processUrl((options == null ? void 0 : options.reverse) ? redirect.redirect.targetUrl : redirect.redirect.sourceUrl).path
388
399
  ),
389
400
  options
390
- )
391
- );
401
+ );
402
+ });
392
403
  }
393
404
  const trie = await this.getRedirectTrie();
394
- return _RedirectClient.processHops(url, trie, false, options);
405
+ return _RedirectClient.processHops(sanitizedUrl, trie, false, options);
395
406
  };
396
407
  if (options.dataCache && options.dataCache.options.prePopulate) {
397
408
  if (!options.dataCache.get(options.projectId)) {
@@ -613,7 +624,7 @@ var UncachedRedirectClient = class extends RedirectClient {
613
624
 
614
625
  // src/util/RedirectFileConverter.ts
615
626
  var getDefaultClient = async () => {
616
- const dotenv = await import("./main-HWDEQR7W.mjs");
627
+ const dotenv = await import("./main-4Y7KG46W.mjs");
617
628
  dotenv.config();
618
629
  return new RedirectClient({
619
630
  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.38.2",
3
+ "version": "19.38.3-alpha.78+5c9892bf1",
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.38.2",
35
+ "@uniformdev/context": "19.38.3-alpha.78+5c9892bf1",
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": "b97fd17fd44e0f5bd3806e942b516cb2bd218096"
42
+ "gitHead": "5c9892bf101584d351d06b65e1658a1237594cfb"
43
43
  }