@klnap/payload-redirect 0.2.0 → 0.3.1

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.
Files changed (109) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +212 -79
  3. package/dist/core/redirects/auto/create-redirect.d.ts +9 -4
  4. package/dist/core/redirects/auto/create-redirect.js +26 -66
  5. package/dist/core/redirects/auto/create-redirect.js.map +1 -0
  6. package/dist/core/redirects/auto/match-existing-rule.d.ts +1 -1
  7. package/dist/core/redirects/auto/match-existing-rule.js +4 -3
  8. package/dist/core/redirects/auto/match-existing-rule.js.map +1 -0
  9. package/dist/core/redirects/auto/persist-auto-rule.d.ts +5 -4
  10. package/dist/core/redirects/auto/persist-auto-rule.js +12 -11
  11. package/dist/core/redirects/auto/persist-auto-rule.js.map +1 -0
  12. package/dist/core/redirects/auto/publication/get-publication-transition.d.ts +3 -3
  13. package/dist/core/redirects/auto/publication/get-publication-transition.js +22 -37
  14. package/dist/core/redirects/auto/publication/get-publication-transition.js.map +1 -0
  15. package/dist/core/redirects/auto/publication/locales.d.ts +7 -5
  16. package/dist/core/redirects/auto/publication/locales.js +33 -28
  17. package/dist/core/redirects/auto/publication/locales.js.map +1 -0
  18. package/dist/core/redirects/auto/publication/publish-intent.d.ts +2 -4
  19. package/dist/core/redirects/auto/publication/publish-intent.js +6 -29
  20. package/dist/core/redirects/auto/publication/publish-intent.js.map +1 -0
  21. package/dist/core/redirects/auto/publication/versions/document-locale.d.ts +4 -6
  22. package/dist/core/redirects/auto/publication/versions/document-locale.js +10 -18
  23. package/dist/core/redirects/auto/publication/versions/document-locale.js.map +1 -0
  24. package/dist/core/redirects/auto/publication/versions/version-pages.d.ts +4 -12
  25. package/dist/core/redirects/auto/publication/versions/version-pages.js +7 -32
  26. package/dist/core/redirects/auto/publication/versions/version-pages.js.map +1 -0
  27. package/dist/core/redirects/auto/publication/versions/version-rows.d.ts +1 -7
  28. package/dist/core/redirects/auto/publication/versions/version-rows.js +7 -30
  29. package/dist/core/redirects/auto/publication/versions/version-rows.js.map +1 -0
  30. package/dist/core/redirects/auto/types.d.ts +27 -8
  31. package/dist/core/redirects/auto/types.js +1 -0
  32. package/dist/core/redirects/auto/types.js.map +1 -0
  33. package/dist/core/redirects/collection/access.d.ts +1 -1
  34. package/dist/core/redirects/collection/access.js +3 -2
  35. package/dist/core/redirects/collection/access.js.map +1 -0
  36. package/dist/core/redirects/collection/collection.d.ts +2 -2
  37. package/dist/core/redirects/collection/collection.js +10 -9
  38. package/dist/core/redirects/collection/collection.js.map +1 -0
  39. package/dist/core/redirects/collection/duplicate-guard.d.ts +1 -1
  40. package/dist/core/redirects/collection/duplicate-guard.js +35 -34
  41. package/dist/core/redirects/collection/duplicate-guard.js.map +1 -0
  42. package/dist/core/redirects/collection/fields.d.ts +1 -1
  43. package/dist/core/redirects/collection/fields.js +52 -51
  44. package/dist/core/redirects/collection/fields.js.map +1 -0
  45. package/dist/core/redirects/collection/graph-lock.d.ts +1 -1
  46. package/dist/core/redirects/collection/graph-lock.js +8 -7
  47. package/dist/core/redirects/collection/graph-lock.js.map +1 -0
  48. package/dist/core/redirects/collection/origin-hook.d.ts +1 -1
  49. package/dist/core/redirects/collection/origin-hook.js +6 -5
  50. package/dist/core/redirects/collection/origin-hook.js.map +1 -0
  51. package/dist/core/redirects/collection/types.d.ts +2 -2
  52. package/dist/core/redirects/collection/types.js +1 -0
  53. package/dist/core/redirects/collection/types.js.map +1 -0
  54. package/dist/core/redirects/context-keys.d.ts +2 -2
  55. package/dist/core/redirects/context-keys.js +3 -2
  56. package/dist/core/redirects/context-keys.js.map +1 -0
  57. package/dist/core/redirects/model/errors.js +2 -1
  58. package/dist/core/redirects/model/errors.js.map +1 -0
  59. package/dist/core/redirects/model/origin.d.ts +1 -1
  60. package/dist/core/redirects/model/origin.js +4 -3
  61. package/dist/core/redirects/model/origin.js.map +1 -0
  62. package/dist/core/redirects/model/status-code.js +5 -4
  63. package/dist/core/redirects/model/status-code.js.map +1 -0
  64. package/dist/core/redirects/normalize-path.js +23 -22
  65. package/dist/core/redirects/normalize-path.js.map +1 -0
  66. package/dist/core/redirects/queries.d.ts +3 -12
  67. package/dist/core/redirects/queries.js +3 -2
  68. package/dist/core/redirects/queries.js.map +1 -0
  69. package/dist/core/url/published-path.d.ts +4 -16
  70. package/dist/core/url/published-path.js +40 -121
  71. package/dist/core/url/published-path.js.map +1 -0
  72. package/dist/core/url/route-params.d.ts +3 -11
  73. package/dist/core/url/route-params.js +32 -99
  74. package/dist/core/url/route-params.js.map +1 -0
  75. package/dist/exports/index.d.ts +4 -4
  76. package/dist/exports/index.js +2 -1
  77. package/dist/exports/index.js.map +1 -0
  78. package/dist/plugin/payload-plugin.d.ts +2 -3
  79. package/dist/plugin/payload-plugin.js +94 -91
  80. package/dist/plugin/payload-plugin.js.map +1 -0
  81. package/dist/plugin/types.d.ts +9 -35
  82. package/dist/plugin/types.js +1 -0
  83. package/dist/plugin/types.js.map +1 -0
  84. package/docs/FAILURE_SEMANTICS.md +31 -27
  85. package/package.json +29 -20
  86. package/dist/core/redirects/auto/publication/identifier-snapshot.d.ts +0 -2
  87. package/dist/core/redirects/auto/publication/identifier-snapshot.js +0 -27
  88. package/dist/core/redirects/auto/publication/identifier-transitions.d.ts +0 -18
  89. package/dist/core/redirects/auto/publication/identifier-transitions.js +0 -36
  90. package/dist/core/redirects/auto/publication/transition-for-locale.d.ts +0 -12
  91. package/dist/core/redirects/auto/publication/transition-for-locale.js +0 -167
  92. package/dist/core/redirects/auto/publication/transitions-to-pairs.d.ts +0 -9
  93. package/dist/core/redirects/auto/publication/transitions-to-pairs.js +0 -22
  94. package/dist/core/redirects/auto/published-link-config.d.ts +0 -6
  95. package/dist/core/redirects/auto/published-link-config.js +0 -53
  96. package/dist/core/redirects/auto/published-path.d.ts +0 -6
  97. package/dist/core/redirects/auto/published-path.js +0 -28
  98. package/dist/core/redirects/auto/redirect-custom.d.ts +0 -7
  99. package/dist/core/redirects/auto/redirect-custom.js +0 -19
  100. package/dist/core/redirects/identifier-field-path.d.ts +0 -14
  101. package/dist/core/redirects/identifier-field-path.js +0 -94
  102. package/dist/core/redirects/runtime.d.ts +0 -9
  103. package/dist/core/redirects/runtime.js +0 -13
  104. package/dist/core/url/preview-path.d.ts +0 -1
  105. package/dist/core/url/preview-path.js +0 -9
  106. package/dist/core/url/preview-routes.d.ts +0 -3
  107. package/dist/core/url/preview-routes.js +0 -31
  108. package/docs/RELEASING.md +0 -41
  109. package/docs/adr/0002-database-indexes.md +0 -44
@@ -1,8 +1,8 @@
1
- import { RedirectValidationError } from './errors.js';
1
+ import { RedirectValidationError } from "./errors.js";
2
2
  const SUPPORTED = [301, 302];
3
3
  export const DEFAULT_REDIRECT_STATUS_CODE = 301;
4
4
  const normalizeStatusCode = (value) => {
5
- const code = typeof value === 'string' ? Number(value) : value;
5
+ const code = typeof value === "string" ? Number(value) : value;
6
6
  if (code === 301 || code === 302)
7
7
  return code;
8
8
  return undefined;
@@ -11,14 +11,15 @@ export const isRedirectStatusCode = (value) => normalizeStatusCode(value) !== un
11
11
  export const assertRedirectStatusCode = (value) => {
12
12
  const code = normalizeStatusCode(value);
13
13
  if (code === undefined) {
14
- throw new RedirectValidationError(`StatusCode must be one of ${SUPPORTED.join(', ')}`);
14
+ throw new RedirectValidationError(`statusCode must be one of ${SUPPORTED.join(", ")}`);
15
15
  }
16
16
  return code;
17
17
  };
18
18
  export const requiresDestination = (_statusCode) => true;
19
19
  export const validateDestinationForStatus = (statusCode, to) => {
20
- const hasTo = typeof to === 'string' && to.trim().length > 0;
20
+ const hasTo = typeof to === "string" && to.trim().length > 0;
21
21
  if (!hasTo) {
22
22
  throw new RedirectValidationError(`statusCode ${statusCode} requires a non-empty "to" field`);
23
23
  }
24
24
  };
25
+ //# sourceMappingURL=status-code.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"status-code.js","sourceRoot":"","sources":["../../../../src/core/redirects/model/status-code.ts"],"names":[],"mappings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,cAAc,UAAU,kCAAkC,CAAC,CAAC;IAChG,CAAC;AACH,CAAC,CAAC","sourcesContent":["import { RedirectValidationError } from \"#redirect/core/redirects/model/errors\";\n\nexport type RedirectStatusCode = 301 | 302;\n\nconst SUPPORTED: readonly RedirectStatusCode[] = [301, 302];\n\nexport const DEFAULT_REDIRECT_STATUS_CODE: RedirectStatusCode = 301;\n\nconst normalizeStatusCode = (value: unknown): RedirectStatusCode | undefined => {\n const code = typeof value === \"string\" ? Number(value) : value;\n if (code === 301 || code === 302) return code;\n return undefined;\n};\n\nexport const isRedirectStatusCode = (value: unknown): value is RedirectStatusCode =>\n normalizeStatusCode(value) !== undefined;\n\nexport const assertRedirectStatusCode = (value: unknown): RedirectStatusCode => {\n const code = normalizeStatusCode(value);\n if (code === undefined) {\n throw new RedirectValidationError(`statusCode must be one of ${SUPPORTED.join(\", \")}`);\n }\n return code;\n};\n\nexport const requiresDestination = (_statusCode: RedirectStatusCode): boolean => true;\n\nexport const validateDestinationForStatus = (statusCode: RedirectStatusCode, to: unknown): void => {\n const hasTo = typeof to === \"string\" && to.trim().length > 0;\n if (!hasTo) {\n throw new RedirectValidationError(`statusCode ${statusCode} requires a non-empty \"to\" field`);\n }\n};\n"]}
@@ -1,27 +1,27 @@
1
- import { RedirectValidationError } from './model/errors.js';
2
- const RELATIVE_PATH_MESSAGE = 'Path must be site-relative (e.g. /blog/post). Do not include a protocol or hostname.';
1
+ import { RedirectValidationError } from "./model/errors.js";
2
+ const RELATIVE_PATH_MESSAGE = "Path must be site-relative (e.g. /blog/post). Do not include a protocol or hostname.";
3
3
  /**
4
4
  * Admin / manual rules: site-relative paths only (no absolute URLs).
5
5
  */
6
6
  export const assertRelativeRedirectPath = (input) => {
7
7
  const trimmed = input.trim();
8
8
  if (!trimmed) {
9
- throw new RedirectValidationError('from/to must be a non-empty site-relative path');
9
+ throw new RedirectValidationError("from/to must be a non-empty site-relative path");
10
10
  }
11
11
  if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(trimmed)) {
12
12
  throw new RedirectValidationError(RELATIVE_PATH_MESSAGE);
13
13
  }
14
- if (trimmed.startsWith('//')) {
14
+ if (trimmed.startsWith("//")) {
15
15
  throw new RedirectValidationError(RELATIVE_PATH_MESSAGE);
16
16
  }
17
17
  // WHATWG URL parsing treats "\" as "/" and strips tabs/newlines, so "/\evil.example"
18
18
  // or "/\t/evil.example" resolve to another origin. Reject those characters outright.
19
19
  if (hasBackslashOrControlChar(trimmed)) {
20
- throw new RedirectValidationError('Path must not contain backslashes or control characters.');
20
+ throw new RedirectValidationError("Path must not contain backslashes or control characters.");
21
21
  }
22
- const pathOnly = trimmed.split(/[?#]/)[0] ?? '';
23
- const firstSegment = pathOnly.replace(/^\/+/, '').split('/')[0] ?? '';
24
- if (!trimmed.startsWith('/') && firstSegment && looksLikeHostname(firstSegment)) {
22
+ const pathOnly = trimmed.split(/[?#]/)[0] ?? "";
23
+ const firstSegment = pathOnly.replace(/^\/+/, "").split("/")[0] ?? "";
24
+ if (!trimmed.startsWith("/") && firstSegment && looksLikeHostname(firstSegment)) {
25
25
  throw new RedirectValidationError(RELATIVE_PATH_MESSAGE);
26
26
  }
27
27
  };
@@ -34,10 +34,10 @@ const hasBackslashOrControlChar = (value) => {
34
34
  return false;
35
35
  };
36
36
  const looksLikeHostname = (segment) => {
37
- if (!segment.includes('.')) {
37
+ if (!segment.includes(".")) {
38
38
  return false;
39
39
  }
40
- if (segment === '.' || segment === '..') {
40
+ if (segment === "." || segment === "..") {
41
41
  return false;
42
42
  }
43
43
  return /^[a-zA-Z0-9.-]+$/.test(segment);
@@ -49,7 +49,7 @@ const looksLikeHostname = (segment) => {
49
49
  export const normalizePathOrUrl = (input) => {
50
50
  const trimmed = input.trim();
51
51
  if (!trimmed) {
52
- throw new RedirectValidationError('from/to must be a non-empty path or URL');
52
+ throw new RedirectValidationError("from/to must be a non-empty path or URL");
53
53
  }
54
54
  if (/^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(trimmed)) {
55
55
  return normalizeAbsoluteUrl(trimmed);
@@ -63,23 +63,23 @@ export const normalizeRelativeRedirectPath = (input) => {
63
63
  };
64
64
  export const normalizeRedirectSourcePath = (input) => {
65
65
  const normalized = normalizeRelativeRedirectPath(input);
66
- if (normalized.includes('#')) {
67
- throw new RedirectValidationError('from must not contain a fragment');
66
+ if (normalized.includes("#")) {
67
+ throw new RedirectValidationError("from must not contain a fragment");
68
68
  }
69
69
  return normalized;
70
70
  };
71
71
  const normalizePath = (path) => {
72
72
  const boundary = path.search(/[?#]/);
73
- const suffix = boundary < 0 ? '' : path.slice(boundary);
73
+ const suffix = boundary < 0 ? "" : path.slice(boundary);
74
74
  let p = boundary < 0 ? path : path.slice(0, boundary);
75
- if (!p.startsWith('/')) {
75
+ if (!p.startsWith("/")) {
76
76
  p = `/${p}`;
77
77
  }
78
- p = p.replace(/\/{2,}/g, '/');
78
+ p = p.replace(/\/{2,}/g, "/");
79
79
  // Browsers resolve these segments before requesting the path.
80
80
  const segments = [];
81
- for (const segment of p.slice(1).split('/')) {
82
- if (segment === '.' || /^%2e$/i.test(segment))
81
+ for (const segment of p.slice(1).split("/")) {
82
+ if (segment === "." || /^%2e$/i.test(segment))
83
83
  continue;
84
84
  if (/^(?:\.\.|\.%2e|%2e\.|%2e%2e)$/i.test(segment)) {
85
85
  segments.pop();
@@ -87,16 +87,16 @@ const normalizePath = (path) => {
87
87
  }
88
88
  segments.push(segment);
89
89
  }
90
- p = `/${segments.join('/')}`;
91
- if (p.length > 1 && p.endsWith('/')) {
90
+ p = `/${segments.join("/")}`;
91
+ if (p.length > 1 && p.endsWith("/")) {
92
92
  p = p.slice(0, -1);
93
93
  }
94
- return `${p === '' ? '/' : p}${suffix}`;
94
+ return `${p === "" ? "/" : p}${suffix}`;
95
95
  };
96
96
  const normalizeAbsoluteUrl = (url) => {
97
97
  try {
98
98
  const parsed = new URL(url);
99
- parsed.pathname = normalizePath(parsed.pathname || '/');
99
+ parsed.pathname = normalizePath(parsed.pathname || "/");
100
100
  return parsed.toString();
101
101
  }
102
102
  catch {
@@ -104,3 +104,4 @@ const normalizeAbsoluteUrl = (url) => {
104
104
  }
105
105
  };
106
106
  export const pathsEqual = (a, b) => normalizePathOrUrl(a) === normalizePathOrUrl(b);
107
+ //# sourceMappingURL=normalize-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalize-path.js","sourceRoot":"","sources":["../../../src/core/redirects/normalize-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,uBAAuB,EAAE,MAAM,uCAAuC,CAAC;AAEhF,MAAM,qBAAqB,GACzB,sFAAsF,CAAC;AAEzF;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,KAAa,EAAQ,EAAE;IAChE,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC;IAC7B,IAAI,CAAC,OAAO,EAAE,CAAC;QACb,MAAM,IAAI,uBAAuB,CAAC,gDAAgD,CAAC,CAAC;IACtF,CAAC;IAED,IAAI,2BAA2B,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9C,MAAM,IAAI,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,OAAO,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,CAAC;QAC7B,MAAM,IAAI,uBAAuB,CAAC,qBAAqB,CAAC,CAAC;IAC3D,CAAC;IAED,qFAAqF;IACrF,qFAAqF;IACrF,IAAI,yBAAyB,CAAC,OAAO,CAAC,EAAE,CAAC;QACvC,MAAM,IAAI,uBAAuB,CAAC,0DAA0D,CAAC,CAAC;IAChG,CAAC;IAED,MAAM,QAAQ,GAAG,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;IAChD,MAAM,YAAY,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAA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AK,kBAAkB,CAAC,CAAC,CAAC,CAAC","sourcesContent":["import { RedirectValidationError } from \"#redirect/core/redirects/model/errors\";\n\nconst RELATIVE_PATH_MESSAGE =\n \"Path must be site-relative (e.g. /blog/post). Do not include a protocol or hostname.\";\n\n/**\n * Admin / manual rules: site-relative paths only (no absolute URLs).\n */\nexport const assertRelativeRedirectPath = (input: string): void => {\n const trimmed = input.trim();\n if (!trimmed) {\n throw new RedirectValidationError(\"from/to must be a non-empty site-relative path\");\n }\n\n if (/^[a-zA-Z][a-zA-Z\\d+\\-.]*:/.test(trimmed)) {\n throw new RedirectValidationError(RELATIVE_PATH_MESSAGE);\n }\n\n if (trimmed.startsWith(\"//\")) {\n throw new RedirectValidationError(RELATIVE_PATH_MESSAGE);\n }\n\n // WHATWG URL parsing treats \"\\\" as \"/\" and strips tabs/newlines, so \"/\\evil.example\"\n // or \"/\\t/evil.example\" resolve to another origin. Reject those characters outright.\n if (hasBackslashOrControlChar(trimmed)) {\n throw new RedirectValidationError(\"Path must not contain backslashes or control characters.\");\n }\n\n const pathOnly = trimmed.split(/[?#]/)[0] ?? \"\";\n const firstSegment = pathOnly.replace(/^\\/+/, \"\").split(\"/\")[0] ?? \"\";\n if (!trimmed.startsWith(\"/\") && firstSegment && looksLikeHostname(firstSegment)) {\n throw new RedirectValidationError(RELATIVE_PATH_MESSAGE);\n }\n};\n\nconst hasBackslashOrControlChar = (value: string): boolean => {\n for (let i = 0; i < value.length; i++) {\n const code = value.charCodeAt(i);\n if (code === 0x5c || code < 0x20 || code === 0x7f) return true;\n }\n return false;\n};\n\nconst looksLikeHostname = (segment: string): boolean => {\n if (!segment.includes(\".\")) {\n return false;\n }\n if (segment === \".\" || segment === \"..\") {\n return false;\n }\n return /^[a-zA-Z0-9.-]+$/.test(segment);\n};\n\n/**\n * Canonical path/URL for storage and lookup.\n * Minimal normalization — no destructive reshaping of materially different URLs.\n */\nexport const normalizePathOrUrl = (input: string): string => {\n const trimmed = input.trim();\n if (!trimmed) {\n throw new RedirectValidationError(\"from/to must be a non-empty path or URL\");\n }\n\n if (/^[a-zA-Z][a-zA-Z\\d+\\-.]*:/.test(trimmed)) {\n return normalizeAbsoluteUrl(trimmed);\n }\n\n return normalizePath(trimmed);\n};\n\n/** Normalize a site-relative path (no protocol/host). */\nexport const normalizeRelativeRedirectPath = (input: string): string => {\n assertRelativeRedirectPath(input);\n return normalizePath(input.trim());\n};\n\nexport const normalizeRedirectSourcePath = (input: string): string => {\n const normalized = normalizeRelativeRedirectPath(input);\n if (normalized.includes(\"#\")) {\n throw new RedirectValidationError(\"from must not contain a fragment\");\n }\n return normalized;\n};\n\nconst normalizePath = (path: string): string => {\n const boundary = path.search(/[?#]/);\n const suffix = boundary < 0 ? \"\" : path.slice(boundary);\n let p = boundary < 0 ? path : path.slice(0, boundary);\n if (!p.startsWith(\"/\")) {\n p = `/${p}`;\n }\n p = p.replace(/\\/{2,}/g, \"/\");\n // Browsers resolve these segments before requesting the path.\n const segments: string[] = [];\n for (const segment of p.slice(1).split(\"/\")) {\n if (segment === \".\" || /^%2e$/i.test(segment)) continue;\n if (/^(?:\\.\\.|\\.%2e|%2e\\.|%2e%2e)$/i.test(segment)) {\n segments.pop();\n continue;\n }\n segments.push(segment);\n }\n p = `/${segments.join(\"/\")}`;\n if (p.length > 1 && p.endsWith(\"/\")) {\n p = p.slice(0, -1);\n }\n return `${p === \"\" ? \"/\" : p}${suffix}`;\n};\n\nconst normalizeAbsoluteUrl = (url: string): string => {\n try {\n const parsed = new URL(url);\n parsed.pathname = normalizePath(parsed.pathname || \"/\");\n return parsed.toString();\n } catch {\n throw new RedirectValidationError(`Invalid absolute URL: ${url}`);\n }\n};\n\nexport const pathsEqual = (a: string, b: string): boolean =>\n normalizePathOrUrl(a) === normalizePathOrUrl(b);\n"]}
@@ -1,19 +1,10 @@
1
- import type { Payload, PayloadRequest, SelectType } from 'payload';
2
- import type { RedirectStatusCode } from './model/status-code.js';
3
- /** Lookup hooks / idempotent writes (includes `id`). */
4
- export declare const redirectLookupSelect: {
5
- readonly id: true;
6
- readonly from: true;
7
- readonly to: true;
8
- readonly StatusCode: true;
9
- readonly enabled: true;
10
- readonly origin: true;
11
- };
1
+ import type { Payload, PayloadRequest, SelectType } from "payload";
2
+ import type { RedirectStatusCode } from "./model/status-code.js";
12
3
  export type RedirectLookupDoc = {
13
4
  id: string | number;
14
5
  from?: string | null;
15
6
  to?: string | null;
16
- StatusCode?: RedirectStatusCode | null;
7
+ statusCode?: RedirectStatusCode | null;
17
8
  enabled?: boolean | null;
18
9
  origin?: string | null;
19
10
  };
@@ -1,9 +1,9 @@
1
1
  /** Lookup hooks / idempotent writes (includes `id`). */
2
- export const redirectLookupSelect = {
2
+ const redirectLookupSelect = {
3
3
  id: true,
4
4
  from: true,
5
5
  to: true,
6
- StatusCode: true,
6
+ statusCode: true,
7
7
  enabled: true,
8
8
  origin: true,
9
9
  };
@@ -24,3 +24,4 @@ export const findRedirectByFrom = async (payload, { collectionSlug, from, req, o
24
24
  req,
25
25
  }));
26
26
  };
27
+ //# sourceMappingURL=queries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"queries.js","sourceRoot":"","sources":["../../../src/core/redirects/queries.ts"],"names":[],"mappings":"AAGA,wDAAwD;AACxD,MAAM,oBAAoB,GAAG;IAC3B,EAAE,EAAE,IAAI;IACR,IAAI,EAAE,IAAI;IACV,EAAE,EAAE,IAAI;IACR,UAAU,EAAE,IAAI;IAChB,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,IAAI;CACJ,CAAC;AAoBX,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EACrC,OAAgB,EAChB,EACE,cAAc,EACd,IAAI,EACJ,GAAG,EACH,cAAc,GAAG,KAAK,EACtB,OAAO,EACP,MAAM,GAAG,oBAAoB,EAC7B,SAAS,GACwC,EACX,EAAE;IAC1C,MAAM,KAAK,GACT,SAAS,KAAK,SAAS;QACrB,CAAC,CAAC;YACE,GAAG,EAAE,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,UAAU,EAAE,SAAS,EAAE,EAAE,CAAC;SACrE;QACH,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,CAAC;IAEjC,OAAO,CAAC,MAAM,OAAO,CAAC,IAAI,CAAC;QACzB,UAAU,EAAE,cAAgC;QAC5C,KAAK;QACL,KAAK,EAAE,CAAC;QACR,KAAK,EAAE,CAAC;QACR,MAAM;QACN,cAAc;QACd,OAAO;QACP,GAAG;KACJ,CAAC,CAA6C,CAAC;AAClD,CAAC,CAAC","sourcesContent":["import type { CollectionSlug, Payload, PayloadRequest, SelectType, Where } from \"payload\";\nimport type { RedirectStatusCode } from \"#redirect/core/redirects/model/status-code\";\n\n/** Lookup hooks / idempotent writes (includes `id`). */\nconst redirectLookupSelect = {\n id: true,\n from: true,\n to: true,\n statusCode: true,\n enabled: true,\n origin: true,\n} as const;\n\nexport type RedirectLookupDoc = {\n id: string | number;\n from?: string | null;\n to?: string | null;\n statusCode?: RedirectStatusCode | null;\n enabled?: boolean | null;\n origin?: string | null;\n};\n\ntype FindByFromBase = {\n collectionSlug: string;\n from: string;\n req?: PayloadRequest;\n overrideAccess?: boolean;\n context?: Record<string, unknown>;\n select?: SelectType;\n};\n\nexport const findRedirectByFrom = async (\n payload: Payload,\n {\n collectionSlug,\n from,\n req,\n overrideAccess = false,\n context,\n select = redirectLookupSelect,\n excludeId,\n }: FindByFromBase & { excludeId?: string | number },\n): Promise<{ docs: RedirectLookupDoc[] }> => {\n const where: Where =\n excludeId !== undefined\n ? {\n and: [{ from: { equals: from } }, { id: { not_equals: excludeId } }],\n }\n : { from: { equals: from } };\n\n return (await payload.find({\n collection: collectionSlug as CollectionSlug,\n where,\n limit: 1,\n depth: 0,\n select,\n overrideAccess,\n context,\n req,\n })) as unknown as { docs: RedirectLookupDoc[] };\n};\n"]}
@@ -1,20 +1,8 @@
1
- import { type PreviewRoutes } from './preview-routes.js';
2
- import { type RouteParamsConfig } from './route-params.js';
3
- export type LocalePrefix = Record<string, string>;
4
- export type PublishedLinkPathTemplate = {
1
+ export type LocalePrefixes = Record<string, string>;
2
+ export type PublishedPathConfiguration = {
5
3
  path?: string;
6
4
  paths?: Record<string, string>;
7
- routes?: PreviewRoutes;
8
- params?: RouteParamsConfig;
9
5
  getPath?: unknown;
10
6
  };
11
- export type ResolvedPublishedPathConfig = PublishedLinkPathTemplate & {
12
- localePrefix: LocalePrefix;
13
- };
14
- export declare function mergeLocalePrefix(plugin?: LocalePrefix, schema?: LocalePrefix): LocalePrefix;
15
- export declare function resolveLocaleRoutePrefix(localePrefix: LocalePrefix, code: string): string | null;
16
- export declare function resolvePathTemplate(config: Pick<PublishedLinkPathTemplate, 'path' | 'paths' | 'routes'>, locale: unknown): string | null;
17
- export declare function buildPublishedPath(config: ResolvedPublishedPathConfig, data: Record<string, unknown>, locale: unknown): string | null;
18
- export declare function resolvePublishedPathConfig(pluginLocalePrefix?: LocalePrefix, link?: PublishedLinkPathTemplate & {
19
- localePrefix?: LocalePrefix;
20
- }): ResolvedPublishedPathConfig | null;
7
+ export declare const isValidLocalePrefix: (prefix: string) => boolean;
8
+ export declare const buildPublishedPath: (config: PublishedPathConfiguration, doc: Record<string, unknown>, locale: unknown, localePrefixes?: LocalePrefixes) => string | null;
@@ -1,131 +1,50 @@
1
- import { localeCode } from './preview-path.js';
2
- import { buildPreviewPath } from './preview-routes.js';
3
- import { applyDynamicSegments } from './route-params.js';
4
- export function mergeLocalePrefix(plugin, schema) {
5
- return Object.assign({}, plugin, schema);
6
- }
7
- function normalizeLocalePrefix(prefix) {
8
- const trimmed = prefix.trim();
9
- if (!trimmed || trimmed === '/')
10
- return '';
11
- const withLeading = trimmed.startsWith('/') ? trimmed : `/${trimmed}`;
12
- return withLeading.replace(/\/+$/, '');
13
- }
14
- export function resolveLocaleRoutePrefix(localePrefix, code) {
15
- if (Object.keys(localePrefix).length === 0) {
16
- return `/${code}`;
1
+ import { applyDynamicSegments, hasControlCharacter, isValidPathTemplate } from "./route-params.js";
2
+ const localeCode = (locale) => {
3
+ if (typeof locale === "string")
4
+ return locale || undefined;
5
+ if (locale && typeof locale === "object" && "code" in locale) {
6
+ const code = locale.code;
7
+ return typeof code === "string" && code ? code : undefined;
17
8
  }
18
- const explicit = localePrefix[code];
19
- if (explicit === undefined) {
20
- return null;
21
- }
22
- return normalizeLocalePrefix(explicit);
23
- }
24
- function patternForLocale(previewRoutes, locale) {
25
- const entries = Object.entries(previewRoutes);
26
- if (entries.length === 0)
27
- return null;
28
- const first = entries[0];
29
- if (!first)
30
- return null;
31
- const [, template] = first;
32
- const code = localeCode(locale);
33
- if (!code)
34
- return null;
35
- if (typeof template === 'string')
36
- return template;
37
- return template[code] ?? null;
38
- }
39
- export function resolvePathTemplate(config, locale) {
40
- const code = localeCode(locale);
41
- if (!code)
42
- return null;
43
- const localized = config.paths?.[code];
44
- if (localized)
45
- return localized;
46
- if (config.path)
47
- return config.path;
48
- if (config.routes)
49
- return patternForLocale(config.routes, locale);
50
- return null;
51
- }
52
- function joinPrefixAndPath(prefix, pathname) {
53
- if (pathname === '/' || pathname === '') {
54
- return prefix || '/';
55
- }
56
- const normalized = pathname.startsWith('/') ? pathname : `/${pathname}`;
57
- return `${prefix}${normalized}`;
58
- }
59
- function isSiteRelativePath(path) {
60
- return (path.startsWith('/') &&
61
- !path.startsWith('//') &&
62
- !path.includes('?') &&
63
- !path.includes('#') &&
64
- !path.includes('\\') &&
65
- ![...path].some((character) => {
66
- const code = character.charCodeAt(0);
67
- return code < 32 || code === 127;
68
- }));
69
- }
70
- function usesLegacyPreviewPathBuilder(config) {
71
- const hasNewTemplate = Boolean(config.path) || Boolean(config.paths && Object.keys(config.paths).length > 0);
72
- if (hasNewTemplate)
73
- return false;
74
- if (!config.routes || Object.keys(config.routes).length === 0)
75
- return false;
76
- return Object.keys(config.localePrefix).length === 0;
77
- }
78
- export function buildPublishedPath(config, data, locale) {
79
- if (typeof config.getPath === 'function') {
80
- const path = config.getPath({ doc: data, locale });
9
+ return undefined;
10
+ };
11
+ export const isValidLocalePrefix = (prefix) => prefix === "" ||
12
+ (prefix.startsWith("/") &&
13
+ !prefix.startsWith("//") &&
14
+ !prefix.includes("?") &&
15
+ !prefix.includes("#") &&
16
+ !prefix.includes("\\") &&
17
+ !hasControlCharacter(prefix));
18
+ const withPrefix = (prefix, path) => path === "/" ? prefix || "/" : `${prefix}${path}`;
19
+ const isSiteRelativePath = (path) => path.startsWith("/") &&
20
+ !path.startsWith("//") &&
21
+ !path.includes("?") &&
22
+ !path.includes("#") &&
23
+ !path.includes("\\") &&
24
+ !hasControlCharacter(path);
25
+ export const buildPublishedPath = (config, doc, locale, localePrefixes) => {
26
+ if (typeof config.getPath === "function") {
27
+ const path = config.getPath({
28
+ doc,
29
+ locale,
30
+ });
81
31
  if (path === null)
82
32
  return null;
83
- if (typeof path !== 'string') {
84
- throw new Error('getPath must return a path or null');
85
- }
86
- const code = localeCode(locale);
87
- if (!code)
33
+ if (typeof path !== "string")
88
34
  return null;
89
- const prefix = resolveLocaleRoutePrefix(config.localePrefix, code);
90
- if (prefix === null)
91
- return null;
92
- const result = joinPrefixAndPath(prefix, path);
93
- return isSiteRelativePath(result) ? result : null;
94
- }
95
- if (usesLegacyPreviewPathBuilder(config)) {
96
- if (!config.routes)
97
- throw new Error('Legacy preview path requires locale routes');
98
- return buildPreviewPath(config.routes, data, locale, config.params);
35
+ return isSiteRelativePath(path) ? path : null;
99
36
  }
100
37
  const code = localeCode(locale);
101
- if (!code)
38
+ const template = config.paths !== undefined ? (code ? config.paths[code] : undefined) : config.path;
39
+ if (typeof template !== "string" || !isValidPathTemplate(template))
102
40
  return null;
103
- const pattern = resolvePathTemplate(config, locale);
104
- if (!pattern)
105
- return null;
106
- const resolved = applyDynamicSegments(pattern, data, locale, config.params);
41
+ const resolved = applyDynamicSegments(template, doc, code);
107
42
  if (resolved === null)
108
43
  return null;
109
- const prefix = resolveLocaleRoutePrefix(config.localePrefix, code);
110
- if (prefix === null)
111
- return null;
112
- const result = joinPrefixAndPath(prefix, resolved);
113
- return isSiteRelativePath(result) ? result : null;
114
- }
115
- export function resolvePublishedPathConfig(pluginLocalePrefix, link) {
116
- if (!link)
117
- return null;
118
- const hasRoutes = link.routes && typeof link.routes === 'object' && Object.keys(link.routes).length > 0;
119
- const hasPath = typeof link.path === 'string' && link.path.length > 0;
120
- const hasPaths = link.paths && Object.keys(link.paths).length > 0;
121
- if (!hasRoutes && !hasPath && !hasPaths && typeof link.getPath !== 'function')
44
+ if (localePrefixes === undefined)
45
+ return resolved;
46
+ if (!code || !Object.hasOwn(localePrefixes, code))
122
47
  return null;
123
- return {
124
- localePrefix: mergeLocalePrefix(pluginLocalePrefix, link.localePrefix),
125
- path: link.path,
126
- paths: link.paths,
127
- routes: hasRoutes ? link.routes : undefined,
128
- params: link.params,
129
- getPath: link.getPath,
130
- };
131
- }
48
+ return withPrefix(localePrefixes[code], resolved);
49
+ };
50
+ //# sourceMappingURL=published-path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"published-path.js","sourceRoot":"","sources":["../../../src/core/url/published-path.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAUnG,MAAM,UAAU,GAAG,CAAC,MAAe,EAAsB,EAAE;IACzD,IAAI,OAAO,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,IAAI,SAAS,CAAC;IAC3D,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,IAAI,MAAM,EAAE,CAAC;QAC7D,MAAM,IAAI,GAAI,MAA6B,CAAC,IAAI,CAAC;QACjD,OAAO,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7D,CAAC;IACD,OAA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IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,IAAI,CAAC;QAC1C,OAAO,kBAAkB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;IAChD,CAAC;IAED,MAAM,IAAI,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAChC,MAAM,QAAQ,GACZ,MAAM,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;IACrF,IAAI,OAAO,QAAQ,KAAK,QAAQ,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAEhF,MAAM,QAAQ,GAAG,oBAAoB,CAAC,QAAQ,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;IAC3D,IAAI,QAAQ,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IAEnC,IAAI,cAAc,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAClD,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,cAAc,EAAE,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAC/D,OAAO,UAAU,CAAC,cAAc,CAAC,IAAI,CAAE,EAAE,QAAQ,CAAC,CAAC;AACrD,CAAC,CAAC","sourcesContent":["import { applyDynamicSegments, hasControlCharacter, isValidPathTemplate } from \"./route-params.js\";\n\nexport type LocalePrefixes = Record<string, string>;\n\nexport type PublishedPathConfiguration = {\n path?: string;\n paths?: Record<string, string>;\n getPath?: unknown;\n};\n\nconst localeCode = (locale: unknown): string | undefined => {\n if (typeof locale === \"string\") return locale || undefined;\n if (locale && typeof locale === \"object\" && \"code\" in locale) {\n const code = (locale as { code?: unknown }).code;\n return typeof code === \"string\" && code ? code : undefined;\n }\n return undefined;\n};\n\nexport const isValidLocalePrefix = (prefix: string): boolean =>\n prefix === \"\" ||\n (prefix.startsWith(\"/\") &&\n !prefix.startsWith(\"//\") &&\n !prefix.includes(\"?\") &&\n !prefix.includes(\"#\") &&\n !prefix.includes(\"\\\\\") &&\n !hasControlCharacter(prefix));\n\nconst withPrefix = (prefix: string, path: string): string =>\n path === \"/\" ? prefix || \"/\" : `${prefix}${path}`;\n\nconst isSiteRelativePath = (path: string): boolean =>\n path.startsWith(\"/\") &&\n !path.startsWith(\"//\") &&\n !path.includes(\"?\") &&\n !path.includes(\"#\") &&\n !path.includes(\"\\\\\") &&\n !hasControlCharacter(path);\n\nexport const buildPublishedPath = (\n config: PublishedPathConfiguration,\n doc: Record<string, unknown>,\n locale: unknown,\n localePrefixes?: LocalePrefixes,\n): string | null => {\n if (typeof config.getPath === \"function\") {\n const path = (\n config.getPath as (args: { doc: Record<string, unknown>; locale: unknown }) => unknown\n )({\n doc,\n locale,\n });\n if (path === null) return null;\n if (typeof path !== \"string\") return null;\n return isSiteRelativePath(path) ? path : null;\n }\n\n const code = localeCode(locale);\n const template =\n config.paths !== undefined ? (code ? config.paths[code] : undefined) : config.path;\n if (typeof template !== \"string\" || !isValidPathTemplate(template)) return null;\n\n const resolved = applyDynamicSegments(template, doc, code);\n if (resolved === null) return null;\n\n if (localePrefixes === undefined) return resolved;\n if (!code || !Object.hasOwn(localePrefixes, code)) return null;\n return withPrefix(localePrefixes[code]!, resolved);\n};\n"]}
@@ -1,11 +1,3 @@
1
- export type RouteParamFieldSpec = {
2
- field: string;
3
- localized?: boolean;
4
- };
5
- export type RouteParamMapping = string | RouteParamFieldSpec;
6
- export type RouteParamsConfig = Record<string, RouteParamMapping>;
7
- export declare function templateHasUnsupportedDynamicSyntax(template: string): boolean;
8
- export declare function extractDynamicSegments(template: string): string[];
9
- export declare function readValueAtPath(data: Record<string, unknown>, fieldPath: string): unknown;
10
- export declare function resolveRouteParam(paramName: string, data: Record<string, unknown>, locale: unknown, routeParams: RouteParamsConfig | undefined): string | null;
11
- export declare function applyDynamicSegments(pattern: string, data: Record<string, unknown>, locale: unknown, routeParams: RouteParamsConfig | undefined): string | null;
1
+ export declare const hasControlCharacter: (value: string) => boolean;
2
+ export declare const isValidPathTemplate: (template: string) => boolean;
3
+ export declare const applyDynamicSegments: (template: string, doc: Record<string, unknown>, locale: string | undefined) => string | null;
@@ -1,107 +1,40 @@
1
- import { localeCode } from './preview-path.js';
2
1
  const DYNAMIC_SEGMENT = /\[([^\]]+)\]/g;
3
- const UNSUPPORTED_TEMPLATE = /\[\[\.\.\.|\[\.\.\.[^\]]*\]|\/\[\](?:\/|$)|\[\[|\]\]|\/\[\.\.\./;
4
- const VALID_PARAM_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
5
- const FORBIDDEN_FIELD_SEGMENTS = new Set(['__proto__', 'constructor', 'prototype']);
6
- export function templateHasUnsupportedDynamicSyntax(template) {
7
- return UNSUPPORTED_TEMPLATE.test(template);
8
- }
9
- function isSupportedParamName(name) {
10
- if (!VALID_PARAM_NAME.test(name))
2
+ const VALID_FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;
3
+ const FORBIDDEN_FIELD_NAMES = new Set(["__proto__", "constructor", "prototype"]);
4
+ export const hasControlCharacter = (value) => [...value].some((character) => {
5
+ const code = character.charCodeAt(0);
6
+ return code <= 0x1f || code === 0x7f;
7
+ });
8
+ export const isValidPathTemplate = (template) => {
9
+ if (!template.startsWith("/") ||
10
+ template.startsWith("//") ||
11
+ /[?#\\]/.test(template) ||
12
+ hasControlCharacter(template)) {
11
13
  return false;
12
- if (name.includes('..'))
13
- return false;
14
- return true;
15
- }
16
- export function extractDynamicSegments(template) {
17
- if (templateHasUnsupportedDynamicSyntax(template))
18
- return [];
19
- const names = [];
20
- const seen = new Set();
21
- for (const match of template.matchAll(DYNAMIC_SEGMENT)) {
22
- const name = match[1];
23
- if (!name || !isSupportedParamName(name) || seen.has(name))
24
- continue;
25
- seen.add(name);
26
- names.push(name);
27
14
  }
28
- return names;
29
- }
30
- export function readValueAtPath(data, fieldPath) {
31
- if (fieldPath.length === 0)
32
- return undefined;
33
- const parts = fieldPath.split('.');
34
- if (parts.some((part) => part.length === 0 || FORBIDDEN_FIELD_SEGMENTS.has(part))) {
35
- return undefined;
15
+ const fields = [...template.matchAll(DYNAMIC_SEGMENT)];
16
+ if (template.replace(DYNAMIC_SEGMENT, "").includes("[") ||
17
+ template.replace(DYNAMIC_SEGMENT, "").includes("]")) {
18
+ return false;
36
19
  }
37
- let current = data;
38
- for (const part of parts) {
39
- if (current === null || current === undefined || typeof current !== 'object') {
40
- return undefined;
20
+ return fields.every(([, name]) => Boolean(name && VALID_FIELD_NAME.test(name) && !FORBIDDEN_FIELD_NAMES.has(name)));
21
+ };
22
+ const extractDynamicSegments = (template) => [...template.matchAll(DYNAMIC_SEGMENT)].flatMap(([, name]) => (name ? [name] : []));
23
+ export const applyDynamicSegments = (template, doc, locale) => {
24
+ if (!isValidPathTemplate(template))
25
+ return null;
26
+ let result = template;
27
+ for (const field of extractDynamicSegments(template)) {
28
+ let value = doc[field];
29
+ if (value && typeof value === "object" && !Array.isArray(value)) {
30
+ value = locale ? value[locale] : undefined;
41
31
  }
42
- if (Array.isArray(current))
43
- return undefined;
44
- if (!Object.hasOwn(current, part))
45
- return undefined;
46
- current = current[part];
47
- }
48
- return current;
49
- }
50
- function normalizeMapping(mapping) {
51
- if (typeof mapping === 'string') {
52
- if (mapping.length === 0)
32
+ if (typeof value === "number" && Number.isFinite(value))
33
+ value = String(value);
34
+ if (typeof value !== "string" || !value || value === "." || value === "..")
53
35
  return null;
54
- return { field: mapping, localized: false };
55
- }
56
- if (typeof mapping.field !== 'string' || mapping.field.length === 0)
57
- return null;
58
- return mapping;
59
- }
60
- function coerceParamString(raw, code, localized) {
61
- if (localized) {
62
- if (typeof raw === 'string')
63
- return raw.length > 0 ? raw : null;
64
- if (raw && typeof raw === 'object' && !Array.isArray(raw)) {
65
- const value = raw[code];
66
- if (typeof value === 'string' && value.length > 0)
67
- return value;
68
- }
69
- return null;
36
+ result = result.replaceAll(`[${field}]`, encodeURIComponent(value));
70
37
  }
71
- if (typeof raw === 'string')
72
- return raw.length > 0 ? raw : null;
73
- if (typeof raw === 'number' && Number.isFinite(raw))
74
- return String(raw);
75
- return null;
76
- }
77
- export function resolveRouteParam(paramName, data, locale, routeParams) {
78
- const code = localeCode(locale);
79
- if (!code)
80
- return null;
81
- const mapping = routeParams?.[paramName];
82
- if (mapping === undefined)
83
- return null;
84
- const spec = normalizeMapping(mapping);
85
- if (!spec)
86
- return null;
87
- const raw = readValueAtPath(data, spec.field);
88
- return coerceParamString(raw, code, spec.localized === true);
89
- }
90
- export function applyDynamicSegments(pattern, data, locale, routeParams) {
91
- if (templateHasUnsupportedDynamicSyntax(pattern))
92
- return null;
93
- const segments = extractDynamicSegments(pattern);
94
- if (segments.length === 0 && DYNAMIC_SEGMENT.test(pattern))
95
- return null;
96
- let result = pattern;
97
- for (const name of segments) {
98
- const value = resolveRouteParam(name, data, locale, routeParams);
99
- // Why: encodeURIComponent leaves dot segments unchanged, so they would rewrite the path.
100
- if (!value || value === '.' || value === '..')
101
- return null;
102
- result = result.replaceAll(`[${name}]`, encodeURIComponent(value));
103
- }
104
- if (/\[[^\]]+\]/.test(result))
105
- return null;
106
38
  return result;
107
- }
39
+ };
40
+ //# sourceMappingURL=route-params.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-params.js","sourceRoot":"","sources":["../../../src/core/url/route-params.ts"],"names":[],"mappings":"AAAA,MAAM,eAAe,GAAG,eAAe,CAAC;AACxC,MAAM,gBAAgB,GAAG,0BAA0B,CAAC;AACpD,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,aAAa,EAAE,WAAW,CAAC,CAAC,CAAC;AAEjF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,KAAa,EAAW,EAAE,CAC5D,CAAC,GAAG,KAAK,CAA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CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEtF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAClC,QAAgB,EAChB,GAA4B,EAC5B,MAA0B,EACX,EAAE;IACjB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,CAAC;QAAE,OAAO,IAAI,CAAC;IAEhD,IAAI,MAAM,GAAG,QAAQ,CAAC;IACtB,KAAK,MAAM,KAAK,IAAI,sBAAsB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACrD,IAAI,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,CAAC;QACvB,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;YAChE,KAAK,GAAG,MAAM,CAAC,CAAC,CAAE,KAAiC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAC1E,CAAC;QAED,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC;YAAE,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;QAC/E,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,IAAI,KAAK,KAAK,GAAG,IAAI,KAAK,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC;QACxF,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,IAAI,KAAK,GAAG,EAAE,kBAAkB,CAAC,KAAK,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC","sourcesContent":["const DYNAMIC_SEGMENT = /\\[([^\\]]+)\\]/g;\nconst VALID_FIELD_NAME = /^[A-Za-z_][A-Za-z0-9_]*$/;\nconst FORBIDDEN_FIELD_NAMES = new Set([\"__proto__\", \"constructor\", \"prototype\"]);\n\nexport const hasControlCharacter = (value: string): boolean =>\n [...value].some((character) => {\n const code = character.charCodeAt(0);\n return code <= 0x1f || code === 0x7f;\n });\n\nexport const isValidPathTemplate = (template: string): boolean => {\n if (\n !template.startsWith(\"/\") ||\n template.startsWith(\"//\") ||\n /[?#\\\\]/.test(template) ||\n hasControlCharacter(template)\n ) {\n return false;\n }\n\n const fields = [...template.matchAll(DYNAMIC_SEGMENT)];\n if (\n template.replace(DYNAMIC_SEGMENT, \"\").includes(\"[\") ||\n template.replace(DYNAMIC_SEGMENT, \"\").includes(\"]\")\n ) {\n return false;\n }\n\n return fields.every(([, name]) =>\n Boolean(name && VALID_FIELD_NAME.test(name) && !FORBIDDEN_FIELD_NAMES.has(name)),\n );\n};\n\nconst extractDynamicSegments = (template: string): string[] =>\n [...template.matchAll(DYNAMIC_SEGMENT)].flatMap(([, name]) => (name ? [name] : []));\n\nexport const applyDynamicSegments = (\n template: string,\n doc: Record<string, unknown>,\n locale: string | undefined,\n): string | null => {\n if (!isValidPathTemplate(template)) return null;\n\n let result = template;\n for (const field of extractDynamicSegments(template)) {\n let value = doc[field];\n if (value && typeof value === \"object\" && !Array.isArray(value)) {\n value = locale ? (value as Record<string, unknown>)[locale] : undefined;\n }\n\n if (typeof value === \"number\" && Number.isFinite(value)) value = String(value);\n if (typeof value !== \"string\" || !value || value === \".\" || value === \"..\") return null;\n result = result.replaceAll(`[${field}]`, encodeURIComponent(value));\n }\n\n return result;\n};\n"]}
@@ -1,4 +1,4 @@
1
- export type { RedirectOrigin } from '../core/redirects/model/origin.js';
2
- export type { RedirectStatusCode } from '../core/redirects/model/status-code.js';
3
- export { redirects } from '../plugin/payload-plugin.js';
4
- export type { RedirectsOptions } from '../plugin/types.js';
1
+ export type { RedirectOrigin } from "../core/redirects/model/origin.js";
2
+ export type { RedirectStatusCode } from "../core/redirects/model/status-code.js";
3
+ export { redirects } from "../plugin/payload-plugin.js";
4
+ export type { RedirectCollectionOptions, RedirectsOptions } from "../plugin/types.js";
@@ -1 +1,2 @@
1
- export { redirects } from '../plugin/payload-plugin.js';
1
+ export { redirects } from "../plugin/payload-plugin.js";
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/exports/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,iCAAiC,CAAC","sourcesContent":["export type { RedirectOrigin } from \"#redirect/core/redirects/model/origin\";\nexport type { RedirectStatusCode } from \"#redirect/core/redirects/model/status-code\";\nexport { redirects } from \"#redirect/plugin/payload-plugin\";\nexport type { RedirectCollectionOptions, RedirectsOptions } from \"#redirect/plugin/types\";\n"]}
@@ -1,4 +1,3 @@
1
- import { type Plugin } from 'payload';
2
- import type { RedirectsOptions } from './types.js';
1
+ import { type Plugin } from "payload";
2
+ import type { RedirectsOptions } from "./types.js";
3
3
  export declare const redirects: (options?: RedirectsOptions) => Plugin;
4
- export type { RedirectsOptions } from './types.js';