@uniformdev/redirect 20.81.1-alpha.7.sha-91a5b13e0c → 20.81.2-alpha.3.sha-a53553700b

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
@@ -440,7 +440,22 @@ declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOpt
440
440
  refresh(): Promise<void[]>;
441
441
  }
442
442
 
443
- declare function getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string) => boolean): string;
443
+ /**
444
+ * Given a redirect definition and an incoming URL, calculate what the final outgoing URL is to be.
445
+ * Wildcards in the target are filled from the matching source wildcards; a source splat can be
446
+ * written in the target either as `*` or as `:splat`.
447
+ *
448
+ * `isVariable` overrides which source path segments count as wildcards. It receives whether the
449
+ * segment is the last one in the source, which is what distinguishes a trailing splat from a
450
+ * literal `*`; a callback that ignores it cannot match splats. The default accepts both.
451
+ */
452
+ declare function getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string, isLast: boolean) => boolean): string;
453
+ /**
454
+ * Extract the variables and their respective values given a source URL and a path. The source URL
455
+ * is expected to contain wildcards in it or end with a splat. A named wildcard takes the single
456
+ * path segment in its position; a trailing splat takes everything left in the path, which is an
457
+ * empty string when the path ends at the splat's parent — a splat covers that path too.
458
+ */
444
459
  declare function getSourceVariables(path: string, source: string, isVariable?: (pathSegment: string, isLast: boolean) => boolean): {
445
460
  [variable: string]: string;
446
461
  };
package/dist/index.d.ts CHANGED
@@ -440,7 +440,22 @@ declare class WithMemoryCache extends RedirectClientCache<RedirectClientCacheOpt
440
440
  refresh(): Promise<void[]>;
441
441
  }
442
442
 
443
- declare function getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string) => boolean): string;
443
+ /**
444
+ * Given a redirect definition and an incoming URL, calculate what the final outgoing URL is to be.
445
+ * Wildcards in the target are filled from the matching source wildcards; a source splat can be
446
+ * written in the target either as `*` or as `:splat`.
447
+ *
448
+ * `isVariable` overrides which source path segments count as wildcards. It receives whether the
449
+ * segment is the last one in the source, which is what distinguishes a trailing splat from a
450
+ * literal `*`; a callback that ignores it cannot match splats. The default accepts both.
451
+ */
452
+ declare function getTargetVariableExpandedUrl(url: string, redirectDefinition: RedirectDefinition['redirect'], isVariable?: (pathSegment: string, isLast: boolean) => boolean): string;
453
+ /**
454
+ * Extract the variables and their respective values given a source URL and a path. The source URL
455
+ * is expected to contain wildcards in it or end with a splat. A named wildcard takes the single
456
+ * path segment in its position; a trailing splat takes everything left in the path, which is an
457
+ * empty string when the path ends at the splat's parent — a splat covers that path too.
458
+ */
444
459
  declare function getSourceVariables(path: string, source: string, isVariable?: (pathSegment: string, isLast: boolean) => boolean): {
445
460
  [variable: string]: string;
446
461
  };
package/dist/index.esm.js CHANGED
@@ -179,6 +179,23 @@ var PathTrie = class {
179
179
  }
180
180
  return result;
181
181
  };
182
+ const collectSplats = (node, remainderFrom) => {
183
+ if (!Object.hasOwn(node, "*")) {
184
+ return;
185
+ }
186
+ const splatData = node["*"][dataProp];
187
+ if (!splatData) {
188
+ return;
189
+ }
190
+ splatData.forEach((splat) => {
191
+ const vars = getVariables();
192
+ vars[":splat"] = segments.slice(remainderFrom).join("/");
193
+ splats.push({
194
+ data: splat,
195
+ variables: vars
196
+ });
197
+ });
198
+ };
182
199
  const scanWildcards = () => {
183
200
  let wildcard = void 0;
184
201
  while ((!wildcard || wildcard.active) && wildcards.length) {
@@ -197,16 +214,7 @@ var PathTrie = class {
197
214
  };
198
215
  for (let i = 0; i < segments.length; i++) {
199
216
  const segment = segments[i];
200
- if (Object.hasOwn(cur, "*")) {
201
- cur["*"][dataProp].forEach((splat) => {
202
- const vars = getVariables();
203
- vars[":splat"] = segments.slice(i).join("/");
204
- splats.push({
205
- data: splat,
206
- variables: vars
207
- });
208
- });
209
- }
217
+ collectSplats(cur, i);
210
218
  getPropsStartingWithColon(cur).forEach((wildcard) => {
211
219
  if (!processed.has(wildcard + i)) {
212
220
  wildcards.push({
@@ -221,6 +229,7 @@ var PathTrie = class {
221
229
  if (Object.hasOwn(cur, segment)) {
222
230
  cur = cur[segment];
223
231
  if (i === segments.length - 1) {
232
+ collectSplats(cur, i + 1);
224
233
  if (cur[dataProp]) {
225
234
  cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
226
235
  } else {
@@ -274,6 +283,8 @@ function processUrl(url) {
274
283
  }
275
284
 
276
285
  // src/util/process.ts
286
+ var splatSegment = "*";
287
+ var splatVariable = ":splat";
277
288
  function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
278
289
  const processedTarget = processUrl(redirectDefinition.targetUrl);
279
290
  const processedSource = processUrl(redirectDefinition.sourceUrl);
@@ -283,6 +294,14 @@ function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
283
294
  for (const variable in variables) {
284
295
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
285
296
  }
297
+ const splatValue = variables[splatSegment];
298
+ if (typeof splatValue !== "undefined") {
299
+ finalUrlPath = finalUrlPath.replace(splatVariable, splatValue);
300
+ const targetNamesSplat = processedTarget.path.includes(splatVariable) || processedTarget.path.includes(splatSegment);
301
+ if (splatValue === "" && targetNamesSplat) {
302
+ finalUrlPath = finalUrlPath.replace(/\/+$/, "") || "/";
303
+ }
304
+ }
286
305
  let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
287
306
  const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
288
307
  if (domain === "" && protocol !== "") {
@@ -293,12 +312,17 @@ function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
293
312
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
294
313
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
295
314
  }
296
- function getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
315
+ function getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === splatSegment && isLast) {
297
316
  const variables = {};
298
317
  const pathSegments = path.split("/");
299
318
  const sourceSegments = source.split("/");
300
319
  sourceSegments.forEach((sourceSegment, i) => {
301
- if (pathSegments.length >= i && isVariable(sourceSegment, i === sourceSegments.length - 1)) {
320
+ const isLast = i === sourceSegments.length - 1;
321
+ if (pathSegments.length >= i && isVariable(sourceSegment, isLast)) {
322
+ if (sourceSegment === splatSegment && isLast) {
323
+ variables[sourceSegment] = pathSegments.slice(i).join("/");
324
+ return;
325
+ }
302
326
  variables[sourceSegment] = pathSegments[i];
303
327
  }
304
328
  });
@@ -574,10 +598,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
574
598
  * @param options - Different options available to the redirect engine
575
599
  */
576
600
  static processDefinitionToResults(processedUrl, definition, variables, options) {
577
- const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
578
- const processedResult = processUrl(resultUrl);
579
601
  const redirect = definition == null ? void 0 : definition.redirect;
580
- if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
581
602
  const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
582
603
  return {
583
604
  url: finalUrl,
package/dist/index.js CHANGED
@@ -225,6 +225,23 @@ var PathTrie = class {
225
225
  }
226
226
  return result;
227
227
  };
228
+ const collectSplats = (node, remainderFrom) => {
229
+ if (!Object.hasOwn(node, "*")) {
230
+ return;
231
+ }
232
+ const splatData = node["*"][dataProp];
233
+ if (!splatData) {
234
+ return;
235
+ }
236
+ splatData.forEach((splat) => {
237
+ const vars = getVariables();
238
+ vars[":splat"] = segments.slice(remainderFrom).join("/");
239
+ splats.push({
240
+ data: splat,
241
+ variables: vars
242
+ });
243
+ });
244
+ };
228
245
  const scanWildcards = () => {
229
246
  let wildcard = void 0;
230
247
  while ((!wildcard || wildcard.active) && wildcards.length) {
@@ -243,16 +260,7 @@ var PathTrie = class {
243
260
  };
244
261
  for (let i = 0; i < segments.length; i++) {
245
262
  const segment = segments[i];
246
- if (Object.hasOwn(cur, "*")) {
247
- cur["*"][dataProp].forEach((splat) => {
248
- const vars = getVariables();
249
- vars[":splat"] = segments.slice(i).join("/");
250
- splats.push({
251
- data: splat,
252
- variables: vars
253
- });
254
- });
255
- }
263
+ collectSplats(cur, i);
256
264
  getPropsStartingWithColon(cur).forEach((wildcard) => {
257
265
  if (!processed.has(wildcard + i)) {
258
266
  wildcards.push({
@@ -267,6 +275,7 @@ var PathTrie = class {
267
275
  if (Object.hasOwn(cur, segment)) {
268
276
  cur = cur[segment];
269
277
  if (i === segments.length - 1) {
278
+ collectSplats(cur, i + 1);
270
279
  if (cur[dataProp]) {
271
280
  cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
272
281
  } else {
@@ -320,6 +329,8 @@ function processUrl(url) {
320
329
  }
321
330
 
322
331
  // src/util/process.ts
332
+ var splatSegment = "*";
333
+ var splatVariable = ":splat";
323
334
  function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
324
335
  const processedTarget = processUrl(redirectDefinition.targetUrl);
325
336
  const processedSource = processUrl(redirectDefinition.sourceUrl);
@@ -329,6 +340,14 @@ function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
329
340
  for (const variable in variables) {
330
341
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
331
342
  }
343
+ const splatValue = variables[splatSegment];
344
+ if (typeof splatValue !== "undefined") {
345
+ finalUrlPath = finalUrlPath.replace(splatVariable, splatValue);
346
+ const targetNamesSplat = processedTarget.path.includes(splatVariable) || processedTarget.path.includes(splatSegment);
347
+ if (splatValue === "" && targetNamesSplat) {
348
+ finalUrlPath = finalUrlPath.replace(/\/+$/, "") || "/";
349
+ }
350
+ }
332
351
  let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
333
352
  const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
334
353
  if (domain === "" && protocol !== "") {
@@ -339,12 +358,17 @@ function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
339
358
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
340
359
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
341
360
  }
342
- function getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
361
+ function getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === splatSegment && isLast) {
343
362
  const variables = {};
344
363
  const pathSegments = path.split("/");
345
364
  const sourceSegments = source.split("/");
346
365
  sourceSegments.forEach((sourceSegment, i) => {
347
- if (pathSegments.length >= i && isVariable(sourceSegment, i === sourceSegments.length - 1)) {
366
+ const isLast = i === sourceSegments.length - 1;
367
+ if (pathSegments.length >= i && isVariable(sourceSegment, isLast)) {
368
+ if (sourceSegment === splatSegment && isLast) {
369
+ variables[sourceSegment] = pathSegments.slice(i).join("/");
370
+ return;
371
+ }
348
372
  variables[sourceSegment] = pathSegments[i];
349
373
  }
350
374
  });
@@ -620,10 +644,7 @@ var _RedirectClient = class _RedirectClient extends import_api.ApiClient {
620
644
  * @param options - Different options available to the redirect engine
621
645
  */
622
646
  static processDefinitionToResults(processedUrl, definition, variables, options) {
623
- const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
624
- const processedResult = processUrl(resultUrl);
625
647
  const redirect = definition == null ? void 0 : definition.redirect;
626
- if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
627
648
  const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
628
649
  return {
629
650
  url: finalUrl,
package/dist/index.mjs CHANGED
@@ -179,6 +179,23 @@ var PathTrie = class {
179
179
  }
180
180
  return result;
181
181
  };
182
+ const collectSplats = (node, remainderFrom) => {
183
+ if (!Object.hasOwn(node, "*")) {
184
+ return;
185
+ }
186
+ const splatData = node["*"][dataProp];
187
+ if (!splatData) {
188
+ return;
189
+ }
190
+ splatData.forEach((splat) => {
191
+ const vars = getVariables();
192
+ vars[":splat"] = segments.slice(remainderFrom).join("/");
193
+ splats.push({
194
+ data: splat,
195
+ variables: vars
196
+ });
197
+ });
198
+ };
182
199
  const scanWildcards = () => {
183
200
  let wildcard = void 0;
184
201
  while ((!wildcard || wildcard.active) && wildcards.length) {
@@ -197,16 +214,7 @@ var PathTrie = class {
197
214
  };
198
215
  for (let i = 0; i < segments.length; i++) {
199
216
  const segment = segments[i];
200
- if (Object.hasOwn(cur, "*")) {
201
- cur["*"][dataProp].forEach((splat) => {
202
- const vars = getVariables();
203
- vars[":splat"] = segments.slice(i).join("/");
204
- splats.push({
205
- data: splat,
206
- variables: vars
207
- });
208
- });
209
- }
217
+ collectSplats(cur, i);
210
218
  getPropsStartingWithColon(cur).forEach((wildcard) => {
211
219
  if (!processed.has(wildcard + i)) {
212
220
  wildcards.push({
@@ -221,6 +229,7 @@ var PathTrie = class {
221
229
  if (Object.hasOwn(cur, segment)) {
222
230
  cur = cur[segment];
223
231
  if (i === segments.length - 1) {
232
+ collectSplats(cur, i + 1);
224
233
  if (cur[dataProp]) {
225
234
  cur[dataProp].forEach((d) => ret.push({ data: d, variables: getVariables() }));
226
235
  } else {
@@ -274,6 +283,8 @@ function processUrl(url) {
274
283
  }
275
284
 
276
285
  // src/util/process.ts
286
+ var splatSegment = "*";
287
+ var splatVariable = ":splat";
277
288
  function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
278
289
  const processedTarget = processUrl(redirectDefinition.targetUrl);
279
290
  const processedSource = processUrl(redirectDefinition.sourceUrl);
@@ -283,6 +294,14 @@ function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
283
294
  for (const variable in variables) {
284
295
  finalUrlPath = finalUrlPath.replace(variable, variables[variable]);
285
296
  }
297
+ const splatValue = variables[splatSegment];
298
+ if (typeof splatValue !== "undefined") {
299
+ finalUrlPath = finalUrlPath.replace(splatVariable, splatValue);
300
+ const targetNamesSplat = processedTarget.path.includes(splatVariable) || processedTarget.path.includes(splatSegment);
301
+ if (splatValue === "" && targetNamesSplat) {
302
+ finalUrlPath = finalUrlPath.replace(/\/+$/, "") || "/";
303
+ }
304
+ }
286
305
  let protocol = redirectDefinition.targetPreserveIncomingProtocol || processedTarget.protocol === "" ? processedUrl.protocol : processedTarget.protocol;
287
306
  const domain = protocol !== "" ? redirectDefinition.targetPreserveIncomingDomain || processedTarget.domain === "" ? processedUrl.domain : processedTarget.domain : "";
288
307
  if (domain === "" && protocol !== "") {
@@ -293,12 +312,17 @@ function getTargetVariableExpandedUrl(url, redirectDefinition, isVariable) {
293
312
  const fragment = redirectDefinition.sourceRetainQuerystring && redirectDefinition.targetMergeQuerystring ? mergeQueryStrings(processedUrl.fragment, processedTarget.fragment) : !redirectDefinition.targetMergeQuerystring && redirectDefinition.sourceRetainQuerystring ? processedUrl.fragment : processedTarget.fragment;
294
313
  return `${protocol}${domain}${port}${finalUrlPath}${query}${fragment}`;
295
314
  }
296
- function getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === "*" && isLast) {
315
+ function getSourceVariables(path, source, isVariable = (pathSegment, isLast) => pathSegment.startsWith(":") || pathSegment === splatSegment && isLast) {
297
316
  const variables = {};
298
317
  const pathSegments = path.split("/");
299
318
  const sourceSegments = source.split("/");
300
319
  sourceSegments.forEach((sourceSegment, i) => {
301
- if (pathSegments.length >= i && isVariable(sourceSegment, i === sourceSegments.length - 1)) {
320
+ const isLast = i === sourceSegments.length - 1;
321
+ if (pathSegments.length >= i && isVariable(sourceSegment, isLast)) {
322
+ if (sourceSegment === splatSegment && isLast) {
323
+ variables[sourceSegment] = pathSegments.slice(i).join("/");
324
+ return;
325
+ }
302
326
  variables[sourceSegment] = pathSegments[i];
303
327
  }
304
328
  });
@@ -574,10 +598,7 @@ var _RedirectClient = class _RedirectClient extends ApiClient {
574
598
  * @param options - Different options available to the redirect engine
575
599
  */
576
600
  static processDefinitionToResults(processedUrl, definition, variables, options) {
577
- const resultUrl = (options == null ? void 0 : options.reverse) ? definition.redirect.sourceUrl : definition.redirect.targetUrl;
578
- const processedResult = processUrl(resultUrl);
579
601
  const redirect = definition == null ? void 0 : definition.redirect;
580
- if (redirect.sourceMustMatchDomain && processedUrl.domain !== processedResult.domain) return void 0;
581
602
  const finalUrl = (options == null ? void 0 : options.reverse) ? "n/a" : getTargetVariableExpandedUrl(processedUrl.url, redirect);
582
603
  return {
583
604
  url: finalUrl,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/redirect",
3
- "version": "20.81.1-alpha.7.sha-91a5b13e0c",
3
+ "version": "20.81.2-alpha.3.sha-a53553700b",
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": "20.81.1-alpha.7.sha-91a5b13e0c",
35
+ "@uniformdev/context": "20.81.2-alpha.3.sha-a53553700b",
36
36
  "p-limit": "^3.1.0",
37
37
  "rfdc": "^1.4.1"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
- "gitHead": "91a5b13e0c542a6925de81498cec7118847f0311"
42
+ "gitHead": "a53553700b84000bd3e1fbe15d187bdd85c1b097"
43
43
  }