@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,26 +1,26 @@
1
- import { ValidationError } from 'payload';
2
- import { lockRedirectRuleGraph } from './graph-lock.js';
3
- import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, validateDestinationForStatus, } from '../model/status-code.js';
4
- import { normalizeRedirectSourcePath, normalizeRelativeRedirectPath, } from '../normalize-path.js';
5
- import { findRedirectByFrom } from '../queries.js';
1
+ import { ValidationError } from "payload";
2
+ import { lockRedirectRuleGraph } from "./graph-lock.js";
3
+ import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, validateDestinationForStatus, } from "../model/status-code.js";
4
+ import { normalizeRedirectSourcePath, normalizeRelativeRedirectPath, } from "../normalize-path.js";
5
+ import { findRedirectByFrom } from "../queries.js";
6
6
  /** Enabled rules followed from `to` before a write is refused as unverifiable. Bounds the lookups per write. */
7
7
  export const MAX_REDIRECT_CHAIN_HOPS = 1000;
8
- const DUPLICATE_MESSAGE = 'A redirect rule already exists for this source path';
9
- const LOOP_MESSAGE = 'Enabled redirect rules already lead from this destination back to this source path';
10
- const CHAIN_LOOP_MESSAGE = 'Enabled redirect rules from this destination already contain a loop';
8
+ const DUPLICATE_MESSAGE = "A redirect rule already exists for this source path";
9
+ const LOOP_MESSAGE = "Enabled redirect rules already lead from this destination back to this source path";
10
+ const CHAIN_LOOP_MESSAGE = "Enabled redirect rules from this destination already contain a loop";
11
11
  const CHAIN_TOO_LONG_MESSAGE = `Enabled redirect rules from this destination chain longer than ${MAX_REDIRECT_CHAIN_HOPS} hops`;
12
12
  const normalizeOrUndefined = (raw) => {
13
- if (typeof raw !== 'string' || raw.trim().length === 0)
13
+ if (typeof raw !== "string" || raw.trim().length === 0)
14
14
  return undefined;
15
15
  try {
16
- return normalizeRelativeRedirectPath(raw).split('#', 1)[0];
16
+ return normalizeRelativeRedirectPath(raw).split("#", 1)[0];
17
17
  }
18
18
  catch {
19
19
  return undefined;
20
20
  }
21
21
  };
22
22
  export const resolveNormalizedFrom = (data) => {
23
- if (typeof data.from !== 'string' || data.from.trim().length === 0)
23
+ if (typeof data.from !== "string" || data.from.trim().length === 0)
24
24
  return undefined;
25
25
  try {
26
26
  return normalizeRedirectSourcePath(data.from);
@@ -43,10 +43,10 @@ export const findDuplicateFrom = async ({ req, collectionSlug, normalizedFrom, e
43
43
  };
44
44
  /** Payload collection `beforeChange` passes `originalDoc`, not top-level `id` (see Payload 3 update op). */
45
45
  export const resolveDuplicateGuardExcludeId = (operation, originalDoc) => {
46
- if (operation !== 'update' || !originalDoc)
46
+ if (operation !== "update" || !originalDoc)
47
47
  return undefined;
48
48
  const { id } = originalDoc;
49
- if (typeof id === 'string' || typeof id === 'number')
49
+ if (typeof id === "string" || typeof id === "number")
50
50
  return id;
51
51
  return undefined;
52
52
  };
@@ -64,14 +64,14 @@ const assertNoLoop = async (args, normalizedFrom, collectionSlug) => {
64
64
  if (!normalizedTo)
65
65
  return;
66
66
  if (normalizedTo === normalizedFrom) {
67
- throw new ValidationError({ errors: [{ message: LOOP_MESSAGE, path: 'to' }] });
67
+ throw new ValidationError({ errors: [{ message: LOOP_MESSAGE, path: "to" }] });
68
68
  }
69
69
  const excludeId = resolveExcludeId(args);
70
70
  const visited = new Set();
71
71
  let current = normalizedTo;
72
72
  for (let hop = 0; hop <= MAX_REDIRECT_CHAIN_HOPS; hop++) {
73
73
  if (visited.has(current)) {
74
- throw new ValidationError({ errors: [{ message: CHAIN_LOOP_MESSAGE, path: 'to' }] });
74
+ throw new ValidationError({ errors: [{ message: CHAIN_LOOP_MESSAGE, path: "to" }] });
75
75
  }
76
76
  visited.add(current);
77
77
  // Integrity lookup: a requester without read access must not hide a rule from the cycle walk.
@@ -89,11 +89,11 @@ const assertNoLoop = async (args, normalizedFrom, collectionSlug) => {
89
89
  if (!next)
90
90
  return;
91
91
  if (next === normalizedFrom) {
92
- throw new ValidationError({ errors: [{ message: LOOP_MESSAGE, path: 'to' }] });
92
+ throw new ValidationError({ errors: [{ message: LOOP_MESSAGE, path: "to" }] });
93
93
  }
94
94
  current = next;
95
95
  }
96
- throw new ValidationError({ errors: [{ message: CHAIN_TOO_LONG_MESSAGE, path: 'to' }] });
96
+ throw new ValidationError({ errors: [{ message: CHAIN_TOO_LONG_MESSAGE, path: "to" }] });
97
97
  };
98
98
  const assertNoDuplicateFrom = async (args, collectionSlug) => {
99
99
  const { data, req } = args;
@@ -109,14 +109,14 @@ const assertNoDuplicateFrom = async (args, collectionSlug) => {
109
109
  excludeId: resolveExcludeId(args),
110
110
  });
111
111
  if (duplicate) {
112
- throw new ValidationError({ errors: [{ message: DUPLICATE_MESSAGE, path: 'from' }] });
112
+ throw new ValidationError({ errors: [{ message: DUPLICATE_MESSAGE, path: "from" }] });
113
113
  }
114
114
  await assertNoLoop(args, normalizedFrom, collectionSlug);
115
115
  return normalizedFrom;
116
116
  };
117
117
  const normalizeRulePaths = (data) => {
118
118
  const normalize = (value, path) => {
119
- if (typeof value !== 'string') {
119
+ if (typeof value !== "string") {
120
120
  throw new ValidationError({ errors: [{ message: `${path} is required`, path }] });
121
121
  }
122
122
  try {
@@ -127,24 +127,24 @@ const normalizeRulePaths = (data) => {
127
127
  throw new ValidationError({ errors: [{ message, path }] });
128
128
  }
129
129
  };
130
- if (typeof data.from !== 'string') {
131
- throw new ValidationError({ errors: [{ message: 'from is required', path: 'from' }] });
130
+ if (typeof data.from !== "string") {
131
+ throw new ValidationError({ errors: [{ message: "from is required", path: "from" }] });
132
132
  }
133
133
  try {
134
134
  data.from = normalizeRedirectSourcePath(data.from);
135
135
  }
136
136
  catch (error) {
137
- const message = error instanceof Error ? error.message : 'Invalid from path';
138
- throw new ValidationError({ errors: [{ message, path: 'from' }] });
137
+ const message = error instanceof Error ? error.message : "Invalid from path";
138
+ throw new ValidationError({ errors: [{ message, path: "from" }] });
139
139
  }
140
- data.to = normalize(data.to, 'to');
140
+ data.to = normalize(data.to, "to");
141
141
  try {
142
- const statusCode = assertRedirectStatusCode(data.StatusCode ?? DEFAULT_REDIRECT_STATUS_CODE);
142
+ const statusCode = assertRedirectStatusCode(data.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE);
143
143
  validateDestinationForStatus(statusCode, data.to);
144
144
  }
145
145
  catch (error) {
146
- const message = error instanceof Error ? error.message : 'Invalid redirect status or destination';
147
- throw new ValidationError({ errors: [{ message, path: 'to' }] });
146
+ const message = error instanceof Error ? error.message : "Invalid redirect status or destination";
147
+ throw new ValidationError({ errors: [{ message, path: "to" }] });
148
148
  }
149
149
  };
150
150
  /**
@@ -155,23 +155,23 @@ const normalizeRulePaths = (data) => {
155
155
  export const effectiveRuleData = (operation, data, originalDoc) => {
156
156
  if (!data)
157
157
  return undefined;
158
- if (operation !== 'update' || !originalDoc)
158
+ if (operation !== "update" || !originalDoc)
159
159
  return data;
160
160
  return { ...originalDoc, ...data };
161
161
  };
162
- export const createDuplicateBeforeChange = (collectionSlug = 'redirects') => {
162
+ export const createDuplicateBeforeChange = (collectionSlug = "redirects") => {
163
163
  return async (args) => {
164
164
  const { data, req, operation, originalDoc } = args;
165
- if (operation === 'create' || operation === 'update') {
165
+ if (operation === "create" || operation === "update") {
166
166
  await lockRedirectRuleGraph(req);
167
167
  }
168
168
  const effective = effectiveRuleData(operation, data, originalDoc);
169
- if (effective && (operation === 'create' || operation === 'update')) {
169
+ if (effective && (operation === "create" || operation === "update")) {
170
170
  normalizeRulePaths(effective);
171
171
  if (data) {
172
- if (typeof data.from === 'string')
172
+ if (typeof data.from === "string")
173
173
  data.from = effective.from;
174
- if (typeof data.to === 'string')
174
+ if (typeof data.to === "string")
175
175
  data.to = effective.to;
176
176
  }
177
177
  }
@@ -181,9 +181,10 @@ export const createDuplicateBeforeChange = (collectionSlug = 'redirects') => {
181
181
  operation,
182
182
  originalDoc: args.originalDoc,
183
183
  }, collectionSlug);
184
- if (data && normalizedFrom && typeof data.from === 'string') {
184
+ if (data && normalizedFrom && typeof data.from === "string") {
185
185
  data.from = normalizedFrom;
186
186
  }
187
187
  return data;
188
188
  };
189
189
  };
190
+ //# sourceMappingURL=duplicate-guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"duplicate-guard.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/duplicate-guard.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,SAAS,CAAC;AAC1C,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EACL,2BAA2B,EAC3B,6BAA6B,GAC9B,MAAM,yCAAyC,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,kCAAkC,CAAC;AAEtE,gHAAgH;AAChH,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAE5C,MAAM,iBAAiB,GAAG,qDAAqD,CAAC;AAChF,MAAM,YAAY,GAChB,oFAAoF,CAAC;AACvF,MAAM,kBAAkB,GAAG,qEAAqE,CAAC;AACjG,MAAM,sBAAsB,GAAG,kEAAkE,uBAAuB,OAAO,CAAC;AAEhI,MAAM,oBAAoB,GAAG,CAAC,GAAY,EAAsB,EAAE;IAChE,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,SAAS,CAAC;IACzE,IAAI,CAAC;QACH,OAAO,6BAA6B,CAA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B,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,SAAS,EAAE,WAAW,EAAE,GAAG,IAAI,CAAC;QACnD,IAAI,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;YACrD,MAAM,qBAAqB,CAAC,GAAG,CAAC,CAAC;QACnC,CAAC;QACD,MAAM,SAAS,GAAG,iBAAiB,CACjC,SAAS,EACT,IAA2C,EAC3C,WAAyD,CAC1D,CAAC;QACF,IAAI,SAAS,IAAI,CAAC,SAAS,KAAK,QAAQ,IAAI,SAAS,KAAK,QAAQ,CAAC,EAAE,CAAC;YACpE,kBAAkB,CAAC,SAAS,CAAC,CAAC;YAC9B,IAAI,IAAI,EAAE,CAAC;gBACT,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ;oBAAE,IAAI,CAAC,IAAI,GAAG,SAAS,CAAC,IAAI,CAAC;gBAC9D,IAAI,OAAO,IAAI,CAAC,EAAE,KAAK,QAAQ;oBAAE,IAAI,CAAC,EAAE,GAAG,SAAS,CAAC,EAAE,CAAC;YAC1D,CAAC;QACH,CAAC;QACD,MAAM,cAAc,GAAG,MAAM,qBAAqB,CAChD;YACE,IAAI,EAAE,SAAS;YACf,GAAG;YACH,SAAS;YACT,WAAW,EAAE,IAAI,CAAC,WAAW;SAC9B,EACD,cAAc,CACf,CAAC;QAEF,IAAI,IAAI,IAAI,cAAc,IAAI,OAAO,IAAI,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YAC5D,IAAI,CAAC,IAAI,GAAG,cAAc,CAAC;QAC7B,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { CollectionBeforeChangeHook, PayloadRequest } from \"payload\";\nimport { ValidationError } from \"payload\";\nimport { lockRedirectRuleGraph } from \"#redirect/core/redirects/collection/graph-lock\";\nimport {\n assertRedirectStatusCode,\n DEFAULT_REDIRECT_STATUS_CODE,\n validateDestinationForStatus,\n} from \"#redirect/core/redirects/model/status-code\";\nimport {\n normalizeRedirectSourcePath,\n normalizeRelativeRedirectPath,\n} from \"#redirect/core/redirects/normalize-path\";\nimport { findRedirectByFrom } from \"#redirect/core/redirects/queries\";\n\n/** Enabled rules followed from `to` before a write is refused as unverifiable. Bounds the lookups per write. */\nexport const MAX_REDIRECT_CHAIN_HOPS = 1000;\n\nconst DUPLICATE_MESSAGE = \"A redirect rule already exists for this source path\";\nconst LOOP_MESSAGE =\n \"Enabled redirect rules already lead from this destination back to this source path\";\nconst CHAIN_LOOP_MESSAGE = \"Enabled redirect rules from this destination already contain a loop\";\nconst CHAIN_TOO_LONG_MESSAGE = `Enabled redirect rules from this destination chain longer than ${MAX_REDIRECT_CHAIN_HOPS} hops`;\n\nconst normalizeOrUndefined = (raw: unknown): string | undefined => {\n if (typeof raw !== \"string\" || raw.trim().length === 0) return undefined;\n try {\n return normalizeRelativeRedirectPath(raw).split(\"#\", 1)[0];\n } catch {\n return undefined;\n }\n};\n\nexport const resolveNormalizedFrom = (data: Record<string, unknown>): string | undefined => {\n if (typeof data.from !== \"string\" || data.from.trim().length === 0) return undefined;\n try {\n return normalizeRedirectSourcePath(data.from);\n } catch {\n return undefined;\n }\n};\n\nexport const findDuplicateFrom = async ({\n req,\n collectionSlug,\n normalizedFrom,\n excludeId,\n}: {\n req: PayloadRequest;\n collectionSlug: string;\n normalizedFrom: string;\n excludeId?: string | number;\n}): Promise<boolean> => {\n // Integrity lookup: it must see every rule, whatever the requester can read. It returns only a boolean.\n const result = await findRedirectByFrom(req.payload, {\n collectionSlug,\n from: normalizedFrom,\n excludeId,\n req,\n overrideAccess: true,\n select: { id: true },\n });\n\n return result.docs.length > 0;\n};\n\ntype HookOperationArgs = {\n data: Record<string, unknown> | undefined;\n req: PayloadRequest;\n operation: string;\n originalDoc?: { id?: string | number } | null;\n};\n\n/** Payload collection `beforeChange` passes `originalDoc`, not top-level `id` (see Payload 3 update op). */\nexport const resolveDuplicateGuardExcludeId = (\n operation: string,\n originalDoc?: { id?: string | number } | null,\n): string | number | undefined => {\n if (operation !== \"update\" || !originalDoc) return undefined;\n const { id } = originalDoc;\n if (typeof id === \"string\" || typeof id === \"number\") return id;\n return undefined;\n};\n\nconst resolveExcludeId = (args: HookOperationArgs): string | number | undefined =>\n resolveDuplicateGuardExcludeId(args.operation, args.originalDoc);\n\n/**\n * Rejects a write whose enabled chain from `to` returns to `from`, of any length. A chain that\n * repeats a hop without reaching `from` predates this write, so it is accepted. Runs past\n * MAX_REDIRECT_CHAIN_HOPS are refused as unverifiable. One indexed lookup on `from` per hop.\n */\nconst assertNoLoop = async (\n args: HookOperationArgs,\n normalizedFrom: string,\n collectionSlug: string,\n): Promise<void> => {\n const { data, req } = args;\n if (!data || data.enabled === false) return;\n\n const normalizedTo = normalizeOrUndefined(data.to);\n if (!normalizedTo) return;\n if (normalizedTo === normalizedFrom) {\n throw new ValidationError({ errors: [{ message: LOOP_MESSAGE, path: \"to\" }] });\n }\n\n const excludeId = resolveExcludeId(args);\n const visited = new Set<string>();\n let current = normalizedTo;\n for (let hop = 0; hop <= MAX_REDIRECT_CHAIN_HOPS; hop++) {\n if (visited.has(current)) {\n throw new ValidationError({ errors: [{ message: CHAIN_LOOP_MESSAGE, path: \"to\" }] });\n }\n visited.add(current);\n // Integrity lookup: a requester without read access must not hide a rule from the cycle walk.\n const { docs } = await findRedirectByFrom(req.payload, {\n collectionSlug,\n from: current,\n excludeId,\n req,\n overrideAccess: true,\n });\n\n const rule = docs[0];\n if (!rule?.enabled) return;\n const next = normalizeOrUndefined(rule.to);\n if (!next) return;\n if (next === normalizedFrom) {\n throw new ValidationError({ errors: [{ message: LOOP_MESSAGE, path: \"to\" }] });\n }\n current = next;\n }\n\n throw new ValidationError({ errors: [{ message: CHAIN_TOO_LONG_MESSAGE, path: \"to\" }] });\n};\n\nconst assertNoDuplicateFrom = async (\n args: HookOperationArgs,\n collectionSlug: string,\n): Promise<string | undefined> => {\n const { data, req } = args;\n if (!data) return undefined;\n\n const normalizedFrom = resolveNormalizedFrom(data);\n if (!normalizedFrom) return undefined;\n\n const duplicate = await findDuplicateFrom({\n req,\n collectionSlug,\n normalizedFrom,\n excludeId: resolveExcludeId(args),\n });\n\n if (duplicate) {\n throw new ValidationError({ errors: [{ message: DUPLICATE_MESSAGE, path: \"from\" }] });\n }\n\n await assertNoLoop(args, normalizedFrom, collectionSlug);\n\n return normalizedFrom;\n};\n\nconst normalizeRulePaths = (data: Record<string, unknown>): void => {\n const normalize = (value: unknown, path: \"from\" | \"to\"): string => {\n if (typeof value !== \"string\") {\n throw new ValidationError({ errors: [{ message: `${path} is required`, path }] });\n }\n try {\n return normalizeRelativeRedirectPath(value);\n } catch (error) {\n const message = error instanceof Error ? error.message : `Invalid ${path} path`;\n throw new ValidationError({ errors: [{ message, path }] });\n }\n };\n\n if (typeof data.from !== \"string\") {\n throw new ValidationError({ errors: [{ message: \"from is required\", path: \"from\" }] });\n }\n try {\n data.from = normalizeRedirectSourcePath(data.from);\n } catch (error) {\n const message = error instanceof Error ? error.message : \"Invalid from path\";\n throw new ValidationError({ errors: [{ message, path: \"from\" }] });\n }\n data.to = normalize(data.to, \"to\");\n\n try {\n const statusCode = assertRedirectStatusCode(data.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE);\n validateDestinationForStatus(statusCode, data.to);\n } catch (error) {\n const message =\n error instanceof Error ? error.message : \"Invalid redirect status or destination\";\n throw new ValidationError({ errors: [{ message, path: \"to\" }] });\n }\n};\n\n/**\n * The rule as it will be stored: on update, the stored document overlaid with the incoming change.\n * Payload passes only the incoming fields to beforeChange, so checking `data` alone would skip the\n * loop walk for any update that omits `from` or `to`.\n */\nexport const effectiveRuleData = (\n operation: string,\n data: Record<string, unknown> | undefined,\n originalDoc: Record<string, unknown> | null | undefined,\n): Record<string, unknown> | undefined => {\n if (!data) return undefined;\n if (operation !== \"update\" || !originalDoc) return data;\n return { ...originalDoc, ...data };\n};\n\nexport const createDuplicateBeforeChange = (\n collectionSlug = \"redirects\",\n): CollectionBeforeChangeHook => {\n return async (args) => {\n const { data, req, operation, originalDoc } = args;\n if (operation === \"create\" || operation === \"update\") {\n await lockRedirectRuleGraph(req);\n }\n const effective = effectiveRuleData(\n operation,\n data as Record<string, unknown> | undefined,\n originalDoc as Record<string, unknown> | null | undefined,\n );\n if (effective && (operation === \"create\" || operation === \"update\")) {\n normalizeRulePaths(effective);\n if (data) {\n if (typeof data.from === \"string\") data.from = effective.from;\n if (typeof data.to === \"string\") data.to = effective.to;\n }\n }\n const normalizedFrom = await assertNoDuplicateFrom(\n {\n data: effective,\n req,\n operation,\n originalDoc: args.originalDoc,\n },\n collectionSlug,\n );\n\n if (data && normalizedFrom && typeof data.from === \"string\") {\n data.from = normalizedFrom;\n }\n\n return data;\n };\n};\n"]}
@@ -1,4 +1,4 @@
1
- import type { Field } from 'payload';
1
+ import type { Field } from "payload";
2
2
  export declare const buildRedirectFields: () => Field[];
3
3
  export declare const mergeRedirectFields: (existingFields: Field[]) => Field[];
4
4
  export declare const assertRedirectFields: (fields: Field[]) => void;
@@ -1,9 +1,9 @@
1
- import { DEFAULT_REDIRECT_ORIGIN, isRedirectOrigin, REDIRECT_ORIGIN_VALUES, } from '../model/origin.js';
2
- import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, validateDestinationForStatus, } from '../model/status-code.js';
3
- import { normalizeRedirectSourcePath, normalizeRelativeRedirectPath } from '../normalize-path.js';
1
+ import { DEFAULT_REDIRECT_ORIGIN, isRedirectOrigin, REDIRECT_ORIGIN_VALUES, } from "../model/origin.js";
2
+ import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, validateDestinationForStatus, } from "../model/status-code.js";
3
+ import { normalizeRedirectSourcePath, normalizeRelativeRedirectPath } from "../normalize-path.js";
4
4
  const publicFieldRead = { read: () => true };
5
5
  const normalizeSiblingFrom = (value) => {
6
- if (typeof value !== 'string')
6
+ if (typeof value !== "string")
7
7
  return undefined;
8
8
  try {
9
9
  return normalizeRedirectSourcePath(value);
@@ -14,55 +14,55 @@ const normalizeSiblingFrom = (value) => {
14
14
  };
15
15
  export const buildRedirectFields = () => [
16
16
  {
17
- name: 'from',
18
- type: 'text',
17
+ name: "from",
18
+ type: "text",
19
19
  required: true,
20
20
  unique: true,
21
21
  access: publicFieldRead,
22
22
  validate: (value) => {
23
- if (typeof value !== 'string')
24
- return 'from is required';
23
+ if (typeof value !== "string")
24
+ return "from is required";
25
25
  if (!value.trim())
26
- return 'from is required';
26
+ return "from is required";
27
27
  try {
28
28
  normalizeRedirectSourcePath(value);
29
29
  return true;
30
30
  }
31
31
  catch (error) {
32
- return error instanceof Error ? error.message : 'Invalid from path';
32
+ return error instanceof Error ? error.message : "Invalid from path";
33
33
  }
34
34
  },
35
35
  },
36
36
  {
37
- name: 'to',
38
- type: 'text',
37
+ name: "to",
38
+ type: "text",
39
39
  required: true,
40
40
  access: publicFieldRead,
41
41
  validate: (value, { siblingData }) => {
42
42
  try {
43
- const statusCode = assertRedirectStatusCode(siblingData?.StatusCode ?? DEFAULT_REDIRECT_STATUS_CODE);
43
+ const statusCode = assertRedirectStatusCode(siblingData?.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE);
44
44
  validateDestinationForStatus(statusCode, value);
45
- if (typeof value === 'string' &&
45
+ if (typeof value === "string" &&
46
46
  normalizeRelativeRedirectPath(value) === normalizeSiblingFrom(siblingData?.from)) {
47
- return 'to must differ from from';
47
+ return "to must differ from from";
48
48
  }
49
49
  return true;
50
50
  }
51
51
  catch (error) {
52
- return error instanceof Error ? error.message : 'Invalid to path';
52
+ return error instanceof Error ? error.message : "Invalid to path";
53
53
  }
54
54
  },
55
55
  },
56
56
  {
57
- name: 'StatusCode',
58
- type: 'select',
59
- label: 'Type',
57
+ name: "statusCode",
58
+ type: "select",
59
+ label: "Type",
60
60
  defaultValue: String(DEFAULT_REDIRECT_STATUS_CODE),
61
61
  required: true,
62
62
  access: publicFieldRead,
63
63
  options: [
64
- { label: 'Permanent', value: '301' },
65
- { label: 'Temporary', value: '302' },
64
+ { label: "Permanent", value: "301" },
65
+ { label: "Temporary", value: "302" },
66
66
  ],
67
67
  validate: (value) => {
68
68
  try {
@@ -70,49 +70,49 @@ export const buildRedirectFields = () => [
70
70
  return true;
71
71
  }
72
72
  catch (error) {
73
- return error instanceof Error ? error.message : 'Invalid StatusCode';
73
+ return error instanceof Error ? error.message : "Invalid statusCode";
74
74
  }
75
75
  },
76
- admin: { position: 'sidebar' },
76
+ admin: { position: "sidebar" },
77
77
  },
78
78
  {
79
- name: 'enabled',
80
- type: 'checkbox',
79
+ name: "enabled",
80
+ type: "checkbox",
81
81
  defaultValue: true,
82
82
  index: true,
83
83
  access: publicFieldRead,
84
- admin: { position: 'sidebar' },
84
+ admin: { position: "sidebar" },
85
85
  },
86
86
  {
87
- name: 'origin',
88
- type: 'select',
87
+ name: "origin",
88
+ type: "select",
89
89
  required: true,
90
90
  defaultValue: DEFAULT_REDIRECT_ORIGIN,
91
91
  access: publicFieldRead,
92
92
  options: [
93
- { label: 'Manual', value: 'manual' },
94
- { label: 'Auto', value: 'auto' },
93
+ { label: "Manual", value: "manual" },
94
+ { label: "Auto", value: "auto" },
95
95
  ],
96
- validate: (value) => isRedirectOrigin(value) ? true : `origin must be ${REDIRECT_ORIGIN_VALUES.join(' or ')}`,
97
- admin: { position: 'sidebar', readOnly: true },
96
+ validate: (value) => isRedirectOrigin(value) ? true : `origin must be ${REDIRECT_ORIGIN_VALUES.join(" or ")}`,
97
+ admin: { position: "sidebar", readOnly: true },
98
98
  },
99
99
  ];
100
100
  export const mergeRedirectFields = (existingFields) => {
101
101
  const defaults = buildRedirectFields();
102
102
  const existingByName = new Map(existingFields
103
- .filter((field) => 'name' in field && typeof field.name === 'string')
103
+ .filter((field) => "name" in field && typeof field.name === "string")
104
104
  .map((field) => [field.name, field]));
105
105
  const defaultNames = new Set(defaults
106
- .filter((field) => 'name' in field && typeof field.name === 'string')
106
+ .filter((field) => "name" in field && typeof field.name === "string")
107
107
  .map((field) => field.name));
108
108
  const merged = defaults.map((field) => {
109
- if (!('name' in field) || typeof field.name !== 'string')
109
+ if (!("name" in field) || typeof field.name !== "string")
110
110
  return field;
111
111
  const override = existingByName.get(field.name);
112
112
  if (!override)
113
113
  return field;
114
- const validate = 'validate' in field && typeof field.validate === 'function' ? field.validate : undefined;
115
- const overrideValidate = 'validate' in override && typeof override.validate === 'function'
114
+ const validate = "validate" in field && typeof field.validate === "function" ? field.validate : undefined;
115
+ const overrideValidate = "validate" in override && typeof override.validate === "function"
116
116
  ? override.validate
117
117
  : undefined;
118
118
  return {
@@ -133,30 +133,31 @@ export const mergeRedirectFields = (existingFields) => {
133
133
  });
134
134
  return [
135
135
  ...merged,
136
- ...existingFields.filter((field) => !('name' in field) || typeof field.name !== 'string' || !defaultNames.has(field.name)),
136
+ ...existingFields.filter((field) => !("name" in field) || typeof field.name !== "string" || !defaultNames.has(field.name)),
137
137
  ];
138
138
  };
139
139
  export const assertRedirectFields = (fields) => {
140
140
  const expected = new Map([
141
- ['from', 'text'],
142
- ['to', 'text'],
143
- ['StatusCode', 'select'],
144
- ['enabled', 'checkbox'],
145
- ['origin', 'select'],
141
+ ["from", "text"],
142
+ ["to", "text"],
143
+ ["statusCode", "select"],
144
+ ["enabled", "checkbox"],
145
+ ["origin", "select"],
146
146
  ]);
147
- const named = fields.filter((field) => 'name' in field && typeof field.name === 'string');
147
+ const named = fields.filter((field) => "name" in field && typeof field.name === "string");
148
148
  for (const [name, type] of expected) {
149
149
  const matching = named.filter((field) => field.name === name);
150
- if (matching.length !== 1 || !('type' in matching[0]) || matching[0].type !== type) {
150
+ if (matching.length !== 1 || !("type" in matching[0]) || matching[0].type !== type) {
151
151
  throw new Error(`payload-redirect: overrides.fields must retain exactly one ${type} field named "${name}"`);
152
152
  }
153
153
  }
154
- const from = named.find((field) => field.name === 'from');
155
- const enabled = named.find((field) => field.name === 'enabled');
156
- if (!from || !('unique' in from) || from.unique !== true) {
157
- throw new Error('payload-redirect: overrides.fields must keep from.unique: true');
154
+ const from = named.find((field) => field.name === "from");
155
+ const enabled = named.find((field) => field.name === "enabled");
156
+ if (!from || !("unique" in from) || from.unique !== true) {
157
+ throw new Error("payload-redirect: overrides.fields must keep from.unique: true");
158
158
  }
159
- if (!enabled || !('index' in enabled) || enabled.index !== true) {
160
- throw new Error('payload-redirect: overrides.fields must keep enabled.index: true');
159
+ if (!enabled || !("index" in enabled) || enabled.index !== true) {
160
+ throw new Error("payload-redirect: overrides.fields must keep enabled.index: true");
161
161
  }
162
162
  };
163
+ //# sourceMappingURL=fields.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fields.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/fields.ts"],"names":[],"mappings":"AACA,OAAO,EACL,uBAAuB,EACvB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,uCAAuC,CAAC;AAC/C,OAAO,EACL,wBAAwB,EACxB,4BAA4B,EAC5B,4BAA4B,GAC7B,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,6BAA6B,EAAE,MAAM,sBAAsB,CAAC;AAElG,MAAM,eAAe,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,IAAI,EAAW,CAAC;AAEtD,MAAM,oBAAoB,GAAG,CAAC,KAAc,EAAsB,EAAE;IAClE,IAAI,OAAO,KAAK,KAAK,QAAQ;QAAE,OAAO,SAAS,CAAC;IAChD,IAAI,CAAC;QACH,OAAO,2BAA2B,CAAC,KAAK,CAAC,CAAC;IAC5C,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,GAAY,EAAE,CAAC;IAChD;QACE,IAAI,EAAE,MAAM;QACZ,IAAI,EAAE,MAAM;QACZ,QAAQ,EAAE,IAAI;QACd,MAAM,EAAE,IAAI;QACZ,MAAM,EAAE,eAAe;QACvB,QAAQ,EAAE,CAAC,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AAK,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,IAAI,QAAQ,EAAE,CAAC;QACpC,MAAM,QAAQ,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;QAC9D,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAE,CAAC,IAAI,QAAQ,CAAC,CAAC,CAAE,CAAC,IAAI,KAAK,IAAI,EAAE,CAAC;YACrF,MAAM,IAAI,KAAK,CACb,8DAA8D,IAAI,iBAAiB,IAAI,GAAG,CAC3F,CAAC;QACJ,CAAC;IACH,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,SAAS,CAAC,CAAC;IAChE,IAAI,CAAC,IAAI,IAAI,CAAC,CAAC,QAAQ,IAAI,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,KAAK,IAAI,EAAE,CAAC;QACzD,MAAM,IAAI,KAAK,CAAC,gEAAgE,CAAC,CAAC;IACpF,CAAC;IACD,IAAI,CAAC,OAAO,IAAI,CAAC,CAAC,OAAO,IAAI,OAAO,CAAC,IAAI,OAAO,CAAC,KAAK,KAAK,IAAI,EAAE,CAAC;QAChE,MAAM,IAAI,KAAK,CAAC,kEAAkE,CAAC,CAAC;IACtF,CAAC;AACH,CAAC,CAAC","sourcesContent":["import type { Field, Validate } from \"payload\";\nimport {\n DEFAULT_REDIRECT_ORIGIN,\n isRedirectOrigin,\n REDIRECT_ORIGIN_VALUES,\n} from \"#redirect/core/redirects/model/origin\";\nimport {\n assertRedirectStatusCode,\n DEFAULT_REDIRECT_STATUS_CODE,\n validateDestinationForStatus,\n} from \"#redirect/core/redirects/model/status-code\";\nimport { normalizeRedirectSourcePath, normalizeRelativeRedirectPath } from \"../normalize-path.js\";\n\nconst publicFieldRead = { read: () => true } as const;\n\nconst normalizeSiblingFrom = (value: unknown): string | undefined => {\n if (typeof value !== \"string\") return undefined;\n try {\n return normalizeRedirectSourcePath(value);\n } catch {\n return undefined;\n }\n};\n\nexport const buildRedirectFields = (): Field[] => [\n {\n name: \"from\",\n type: \"text\",\n required: true,\n unique: true,\n access: publicFieldRead,\n validate: (value: unknown) => {\n if (typeof value !== \"string\") return \"from is required\";\n if (!value.trim()) return \"from is required\";\n try {\n normalizeRedirectSourcePath(value);\n return true;\n } catch (error) {\n return error instanceof Error ? error.message : \"Invalid from path\";\n }\n },\n },\n {\n name: \"to\",\n type: \"text\",\n required: true,\n access: publicFieldRead,\n validate: (value: unknown, { siblingData }: { siblingData: Record<string, unknown> }) => {\n try {\n const statusCode = assertRedirectStatusCode(\n siblingData?.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE,\n );\n validateDestinationForStatus(statusCode, value);\n if (\n typeof value === \"string\" &&\n normalizeRelativeRedirectPath(value) === normalizeSiblingFrom(siblingData?.from)\n ) {\n return \"to must differ from from\";\n }\n return true;\n } catch (error) {\n return error instanceof Error ? error.message : \"Invalid to path\";\n }\n },\n },\n {\n name: \"statusCode\",\n type: \"select\",\n label: \"Type\",\n defaultValue: String(DEFAULT_REDIRECT_STATUS_CODE),\n required: true,\n access: publicFieldRead,\n options: [\n { label: \"Permanent\", value: \"301\" },\n { label: \"Temporary\", value: \"302\" },\n ],\n validate: (value: unknown) => {\n try {\n assertRedirectStatusCode(value);\n return true;\n } catch (error) {\n return error instanceof Error ? error.message : \"Invalid statusCode\";\n }\n },\n admin: { position: \"sidebar\" },\n },\n {\n name: \"enabled\",\n type: \"checkbox\",\n defaultValue: true,\n index: true,\n access: publicFieldRead,\n admin: { position: \"sidebar\" },\n },\n {\n name: \"origin\",\n type: \"select\",\n required: true,\n defaultValue: DEFAULT_REDIRECT_ORIGIN,\n access: publicFieldRead,\n options: [\n { label: \"Manual\", value: \"manual\" },\n { label: \"Auto\", value: \"auto\" },\n ],\n validate: (value: unknown) =>\n isRedirectOrigin(value) ? true : `origin must be ${REDIRECT_ORIGIN_VALUES.join(\" or \")}`,\n admin: { position: \"sidebar\", readOnly: true },\n },\n];\n\nexport const mergeRedirectFields = (existingFields: Field[]): Field[] => {\n const defaults = buildRedirectFields();\n const existingByName = new Map(\n existingFields\n .filter(\n (field): field is Field & { name: string } =>\n \"name\" in field && typeof field.name === \"string\",\n )\n .map((field) => [field.name, field]),\n );\n const defaultNames = new Set(\n defaults\n .filter(\n (field): field is Field & { name: string } =>\n \"name\" in field && typeof field.name === \"string\",\n )\n .map((field) => field.name),\n );\n const merged = defaults.map((field) => {\n if (!(\"name\" in field) || typeof field.name !== \"string\") return field;\n const override = existingByName.get(field.name);\n if (!override) return field;\n const validate =\n \"validate\" in field && typeof field.validate === \"function\" ? field.validate : undefined;\n const overrideValidate =\n \"validate\" in override && typeof override.validate === \"function\"\n ? override.validate\n : undefined;\n return {\n ...field,\n ...override,\n ...(validate\n ? {\n validate: async (value: unknown, options: Parameters<Validate>[1]) => {\n const run = validate as Validate;\n const result = await run(value, options);\n return result === true && overrideValidate\n ? (overrideValidate as Validate)(value, options)\n : result;\n },\n }\n : {}),\n } as Field;\n });\n\n return [\n ...merged,\n ...existingFields.filter(\n (field) =>\n !(\"name\" in field) || typeof field.name !== \"string\" || !defaultNames.has(field.name),\n ),\n ];\n};\n\nexport const assertRedirectFields = (fields: Field[]): void => {\n const expected = new Map([\n [\"from\", \"text\"],\n [\"to\", \"text\"],\n [\"statusCode\", \"select\"],\n [\"enabled\", \"checkbox\"],\n [\"origin\", \"select\"],\n ]);\n const named = fields.filter(\n (field): field is Field & { name: string } => \"name\" in field && typeof field.name === \"string\",\n );\n\n for (const [name, type] of expected) {\n const matching = named.filter((field) => field.name === name);\n if (matching.length !== 1 || !(\"type\" in matching[0]!) || matching[0]!.type !== type) {\n throw new Error(\n `payload-redirect: overrides.fields must retain exactly one ${type} field named \"${name}\"`,\n );\n }\n }\n\n const from = named.find((field) => field.name === \"from\");\n const enabled = named.find((field) => field.name === \"enabled\");\n if (!from || !(\"unique\" in from) || from.unique !== true) {\n throw new Error(\"payload-redirect: overrides.fields must keep from.unique: true\");\n }\n if (!enabled || !(\"index\" in enabled) || enabled.index !== true) {\n throw new Error(\"payload-redirect: overrides.fields must keep enabled.index: true\");\n }\n};\n"]}
@@ -1,2 +1,2 @@
1
- import type { PayloadRequest } from 'payload';
1
+ import type { PayloadRequest } from "payload";
2
2
  export declare function lockRedirectRuleGraph(req: PayloadRequest): Promise<void>;
@@ -7,25 +7,26 @@
7
7
  * isolation, and the function throws when either is missing rather than checking without it.
8
8
  * Adapters without advisory locks return without locking.
9
9
  */
10
- const LOCK_KEY = 'payload-redirect:rule-graph';
10
+ const LOCK_KEY = "payload-redirect:rule-graph";
11
11
  const POSTGRES_ADAPTER_PATTERN = /postgres/;
12
12
  export async function lockRedirectRuleGraph(req) {
13
13
  const db = req.payload?.db;
14
14
  // No database adapter means there is no transaction graph to serialize against.
15
15
  if (db == null)
16
16
  return;
17
- if (!POSTGRES_ADAPTER_PATTERN.test(db.packageName ?? ''))
17
+ if (!POSTGRES_ADAPTER_PATTERN.test(db.packageName ?? ""))
18
18
  return;
19
19
  const transactionID = await req.transactionID;
20
20
  const session = transactionID == null ? undefined : db.sessions?.[String(transactionID)];
21
21
  const tx = session?.db;
22
- if (tx == null || typeof tx.execute !== 'function') {
23
- throw new Error('Redirect rule lock needs the request transaction; refusing without it.');
22
+ if (tx == null || typeof tx.execute !== "function") {
23
+ throw new Error("Redirect rule lock needs the request transaction; refusing without it.");
24
24
  }
25
25
  // LOCK_KEY is a constant, so inlining it into the SQL text is safe.
26
26
  await tx.execute(`select pg_advisory_xact_lock(hashtext('${LOCK_KEY}'))`);
27
- const isolation = await tx.execute('show transaction_isolation');
28
- if (isolation.rows[0]?.transaction_isolation !== 'read committed') {
29
- throw new Error('Redirect rule lock requires READ COMMITTED transactions.');
27
+ const isolation = await tx.execute("show transaction_isolation");
28
+ if (isolation.rows[0]?.transaction_isolation !== "read committed") {
29
+ throw new Error("Redirect rule lock requires READ COMMITTED transactions.");
30
30
  }
31
31
  }
32
+ //# sourceMappingURL=graph-lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph-lock.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/graph-lock.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,QAAQ,GAAG,6BAA6B,CAAC;AAC/C,MAAM,wBAAwB,GAAG,UAAU,CAAC;AAW5C,MAAM,CAAC,KAAK,UAAU,qBAAqB,CAAC,GAAmB;IAC7D,MAAM,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,EAA2C,CAAC;IACpE,gFAAgF;IAChF,IAAI,EAAE,IAAI,IAAI;QAAE,OAAO;IACvB,IAAI,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC,WAAW,IAAI,EAAE,CAAC;QAAE,OAAO;IAEjE,MAAM,aAAa,GAAG,MAAM,GAAG,CAAC,aAAa,CAAC;IAC9C,MAAM,OAAO,GAAG,aAAa,IAAI,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC;IACzF,MAAM,EAAE,GAAG,OAAO,EAAE,EAAsC,CAAC;IAC3D,IAAI,EAAE,IAAI,IAAI,IAAI,OAAO,EAAE,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;QACnD,MAAM,IAAI,KAAK,CAAC,wEAAwE,CAAC,CAAC;IAC5F,CAAC;IAED,oEAAoE;IACpE,MAAM,EAAE,CAAC,OAAO,CAAC,0CAA0C,QAAQ,KAAK,CAAC,CAAC;IAE1E,MAAM,SAAS,GAAG,MAAM,EAAE,CAAC,OAAO,CAAC,4BAA4B,CAAC,CAAC;IACjE,IAAI,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,qBAAqB,KAAK,gBAAgB,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,0DAA0D,CAAC,CAAC;IAC9E,CAAC;AACH,CAAC","sourcesContent":["import type { PayloadRequest } from \"payload\";\n\n/**\n * Serializes writes to the redirect rule graph. The loop and duplicate checks read committed rows,\n * so two concurrent writes that each close a cycle could both pass unless the second waits for the\n * first to commit. The lock is transaction-scoped and released at commit or rollback.\n *\n * Postgres is the supported adapter: the lock needs the request transaction and READ COMMITTED\n * isolation, and the function throws when either is missing rather than checking without it.\n * Adapters without advisory locks return without locking.\n */\nconst LOCK_KEY = \"payload-redirect:rule-graph\";\nconst POSTGRES_ADAPTER_PATTERN = /postgres/;\n\ntype TransactionQueryable = {\n execute: (query: string) => Promise<{ rows: Array<Record<string, unknown>> }>;\n};\n\ntype DbWithSessions = {\n packageName?: string;\n sessions?: Record<string, { db?: unknown } | undefined>;\n};\n\nexport async function lockRedirectRuleGraph(req: PayloadRequest): Promise<void> {\n const db = req.payload?.db as unknown as DbWithSessions | undefined;\n // No database adapter means there is no transaction graph to serialize against.\n if (db == null) return;\n if (!POSTGRES_ADAPTER_PATTERN.test(db.packageName ?? \"\")) return;\n\n const transactionID = await req.transactionID;\n const session = transactionID == null ? undefined : db.sessions?.[String(transactionID)];\n const tx = session?.db as TransactionQueryable | undefined;\n if (tx == null || typeof tx.execute !== \"function\") {\n throw new Error(\"Redirect rule lock needs the request transaction; refusing without it.\");\n }\n\n // LOCK_KEY is a constant, so inlining it into the SQL text is safe.\n await tx.execute(`select pg_advisory_xact_lock(hashtext('${LOCK_KEY}'))`);\n\n const isolation = await tx.execute(\"show transaction_isolation\");\n if (isolation.rows[0]?.transaction_isolation !== \"read committed\") {\n throw new Error(\"Redirect rule lock requires READ COMMITTED transactions.\");\n }\n}\n"]}
@@ -1,2 +1,2 @@
1
- import type { CollectionBeforeChangeHook } from 'payload';
1
+ import type { CollectionBeforeChangeHook } from "payload";
2
2
  export declare const createRedirectOriginBeforeChange: () => CollectionBeforeChangeHook;
@@ -1,15 +1,16 @@
1
- import { isInternalRedirectWrite } from './access.js';
1
+ import { isInternalRedirectWrite } from "./access.js";
2
2
  export const createRedirectOriginBeforeChange = () => async (args) => {
3
3
  const { data, operation, req } = args;
4
4
  if (isInternalRedirectWrite(req)) {
5
- data.origin = 'auto';
5
+ data.origin = "auto";
6
6
  }
7
- else if (operation === 'create') {
8
- data.origin = 'manual';
7
+ else if (operation === "create") {
8
+ data.origin = "manual";
9
9
  }
10
10
  else {
11
11
  data.origin =
12
- args.originalDoc?.origin === 'auto' ? 'manual' : (args.originalDoc?.origin ?? 'manual');
12
+ args.originalDoc?.origin === "auto" ? "manual" : (args.originalDoc?.origin ?? "manual");
13
13
  }
14
14
  return data;
15
15
  };
16
+ //# sourceMappingURL=origin-hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin-hook.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/origin-hook.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,uBAAuB,EAAE,MAAM,aAAa,CAAC;AAEtD,MAAM,CAAC,MAAM,gCAAgC,GAAG,GAA+B,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE;IAC/F,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;IAEtC,IAAI,uBAAuB,CAAC,GAAG,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;SAAM,IAAI,SAAS,KAAK,QAAQ,EAAE,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,QAAQ,CAAC;IACzB,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,MAAM;YACT,IAAI,CAAC,WAAW,EAAE,MAAM,KAAK,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,MAAM,IAAI,QAAQ,CAAC,CAAC;IAC5F,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC,CAAC","sourcesContent":["import type { CollectionBeforeChangeHook } from \"payload\";\nimport { isInternalRedirectWrite } from \"./access.js\";\n\nexport const createRedirectOriginBeforeChange = (): CollectionBeforeChangeHook => async (args) => {\n const { data, operation, req } = args;\n\n if (isInternalRedirectWrite(req)) {\n data.origin = \"auto\";\n } else if (operation === \"create\") {\n data.origin = \"manual\";\n } else {\n data.origin =\n args.originalDoc?.origin === \"auto\" ? \"manual\" : (args.originalDoc?.origin ?? \"manual\");\n }\n\n return data;\n};\n"]}
@@ -1,5 +1,5 @@
1
- import type { CollectionConfig, Field } from 'payload';
2
- export type RedirectCollectionOverrides = Omit<CollectionConfig, 'fields' | 'slug'> & {
1
+ import type { CollectionConfig, Field } from "payload";
2
+ export type RedirectCollectionOverrides = Omit<CollectionConfig, "fields" | "slug"> & {
3
3
  fields?: (args: {
4
4
  defaultFields: Field[];
5
5
  }) => Field[];
@@ -1 +1,2 @@
1
1
  export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CollectionConfig, Field } from \"payload\";\n\nexport type RedirectCollectionOverrides = Omit<CollectionConfig, \"fields\" | \"slug\"> & {\n fields?: (args: { defaultFields: Field[] }) => Field[];\n slug?: string;\n};\n"]}
@@ -1,4 +1,4 @@
1
1
  export declare const REDIRECT_CONTEXT_KEYS: {
2
- readonly internal: 'payloadRedirectInternal';
3
- readonly skipAuto: 'payloadRedirectSkipAuto';
2
+ readonly internal: "payloadRedirectInternal";
3
+ readonly skipAuto: "payloadRedirectSkipAuto";
4
4
  };
@@ -1,4 +1,5 @@
1
1
  export const REDIRECT_CONTEXT_KEYS = {
2
- internal: 'payloadRedirectInternal',
3
- skipAuto: 'payloadRedirectSkipAuto',
2
+ internal: "payloadRedirectInternal",
3
+ skipAuto: "payloadRedirectSkipAuto",
4
4
  };
5
+ //# sourceMappingURL=context-keys.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context-keys.js","sourceRoot":"","sources":["../../../src/core/redirects/context-keys.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,QAAQ,EAAE,yBAAyB;IACnC,QAAQ,EAAE,yBAAyB;CAC3B,CAAC","sourcesContent":["export const REDIRECT_CONTEXT_KEYS = {\n internal: \"payloadRedirectInternal\",\n skipAuto: \"payloadRedirectSkipAuto\",\n} as const;\n"]}
@@ -1,3 +1,4 @@
1
1
  export class RedirectValidationError extends Error {
2
- name = 'RedirectValidationError';
2
+ name = "RedirectValidationError";
3
3
  }
4
+ //# sourceMappingURL=errors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../../src/core/redirects/model/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,uBAAwB,SAAQ,KAAK;IAC9B,IAAI,GAAG,yBAAyB,CAAC;CACpD","sourcesContent":["export class RedirectValidationError extends Error {\n override readonly name = \"RedirectValidationError\";\n}\n"]}
@@ -1,4 +1,4 @@
1
- export declare const REDIRECT_ORIGIN_VALUES: readonly ['manual', 'auto'];
1
+ export declare const REDIRECT_ORIGIN_VALUES: readonly ["manual", "auto"];
2
2
  export type RedirectOrigin = (typeof REDIRECT_ORIGIN_VALUES)[number];
3
3
  export declare const DEFAULT_REDIRECT_ORIGIN: RedirectOrigin;
4
4
  export declare const isRedirectOrigin: (value: unknown) => value is RedirectOrigin;
@@ -1,3 +1,4 @@
1
- export const REDIRECT_ORIGIN_VALUES = ['manual', 'auto'];
2
- export const DEFAULT_REDIRECT_ORIGIN = 'manual';
3
- export const isRedirectOrigin = (value) => typeof value === 'string' && REDIRECT_ORIGIN_VALUES.includes(value);
1
+ export const REDIRECT_ORIGIN_VALUES = ["manual", "auto"];
2
+ export const DEFAULT_REDIRECT_ORIGIN = "manual";
3
+ export const isRedirectOrigin = (value) => typeof value === "string" && REDIRECT_ORIGIN_VALUES.includes(value);
4
+ //# sourceMappingURL=origin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"origin.js","sourceRoot":"","sources":["../../../../src/core/redirects/model/origin.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,QAAQ,EAAE,MAAM,CAAU,CAAC;AAIlE,MAAM,CAAC,MAAM,uBAAuB,GAAmB,QAAQ,CAAC;AAEhE,MAAM,CAAC,MAAM,gBAAgB,GAAG,CAAC,KAAc,EAA2B,EAAE,CAC1E,OAAO,KAAK,KAAK,QAAQ,IAAK,sBAA4C,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC","sourcesContent":["export const REDIRECT_ORIGIN_VALUES = [\"manual\", \"auto\"] as const;\n\nexport type RedirectOrigin = (typeof REDIRECT_ORIGIN_VALUES)[number];\n\nexport const DEFAULT_REDIRECT_ORIGIN: RedirectOrigin = \"manual\";\n\nexport const isRedirectOrigin = (value: unknown): value is RedirectOrigin =>\n typeof value === \"string\" && (REDIRECT_ORIGIN_VALUES as readonly string[]).includes(value);\n"]}