@klnap/payload-redirect 0.3.1 → 0.4.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 (44) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/README.md +368 -168
  3. package/dist/core/redirects/auto/create-global-redirect.d.ts +11 -0
  4. package/dist/core/redirects/auto/create-global-redirect.js +18 -0
  5. package/dist/core/redirects/auto/create-global-redirect.js.map +1 -0
  6. package/dist/core/redirects/auto/create-redirect.d.ts +10 -6
  7. package/dist/core/redirects/auto/create-redirect.js +18 -9
  8. package/dist/core/redirects/auto/create-redirect.js.map +1 -1
  9. package/dist/core/redirects/auto/persist-auto-rule.d.ts +1 -1
  10. package/dist/core/redirects/auto/persist-auto-rule.js +8 -5
  11. package/dist/core/redirects/auto/persist-auto-rule.js.map +1 -1
  12. package/dist/core/redirects/auto/publication/global-transition.d.ts +6 -0
  13. package/dist/core/redirects/auto/publication/global-transition.js +63 -0
  14. package/dist/core/redirects/auto/publication/global-transition.js.map +1 -0
  15. package/dist/core/redirects/auto/publication/locales.d.ts +1 -0
  16. package/dist/core/redirects/auto/publication/locales.js +4 -0
  17. package/dist/core/redirects/auto/publication/locales.js.map +1 -1
  18. package/dist/core/redirects/auto/types.d.ts +3 -3
  19. package/dist/core/redirects/auto/types.js.map +1 -1
  20. package/dist/core/redirects/collection/collection.js +5 -3
  21. package/dist/core/redirects/collection/collection.js.map +1 -1
  22. package/dist/core/redirects/collection/duplicate-guard.js +0 -4
  23. package/dist/core/redirects/collection/duplicate-guard.js.map +1 -1
  24. package/dist/core/redirects/collection/fields.js +0 -6
  25. package/dist/core/redirects/collection/fields.js.map +1 -1
  26. package/dist/core/redirects/collection/graph-lock.d.ts +6 -1
  27. package/dist/core/redirects/collection/graph-lock.js +11 -0
  28. package/dist/core/redirects/collection/graph-lock.js.map +1 -1
  29. package/dist/core/redirects/collection/origin-hook.js +3 -2
  30. package/dist/core/redirects/collection/origin-hook.js.map +1 -1
  31. package/dist/core/redirects/context-keys.d.ts +1 -1
  32. package/dist/core/redirects/context-keys.js +1 -1
  33. package/dist/core/redirects/context-keys.js.map +1 -1
  34. package/dist/exports/index.d.ts +1 -1
  35. package/dist/exports/index.js.map +1 -1
  36. package/dist/plugin/payload-plugin.js +54 -19
  37. package/dist/plugin/payload-plugin.js.map +1 -1
  38. package/dist/plugin/types.d.ts +7 -2
  39. package/dist/plugin/types.js.map +1 -1
  40. package/docs/FAILURE_SEMANTICS.md +25 -6
  41. package/package.json +1 -1
  42. package/dist/core/redirects/collection/access.d.ts +0 -8
  43. package/dist/core/redirects/collection/access.js +0 -10
  44. package/dist/core/redirects/collection/access.js.map +0 -1
@@ -0,0 +1,11 @@
1
+ import type { DataFromGlobalSlug, GlobalAfterChangeHook, GlobalSlug } from "payload";
2
+ import type { LocalePrefixes } from "../../url/published-path.js";
3
+ import type { RedirectPathOptions } from "./types.js";
4
+ type CreateGlobalRedirectOptions<TSlug extends GlobalSlug = GlobalSlug> = {
5
+ globalSlug: TSlug;
6
+ redirectCollectionSlug: string;
7
+ pathOptions: RedirectPathOptions<DataFromGlobalSlug<TSlug>>;
8
+ localePrefixes?: LocalePrefixes;
9
+ };
10
+ export declare const createGlobalRedirect: <TSlug extends GlobalSlug>({ globalSlug, redirectCollectionSlug, pathOptions, localePrefixes, }: CreateGlobalRedirectOptions<TSlug>) => GlobalAfterChangeHook;
11
+ export {};
@@ -0,0 +1,18 @@
1
+ import { createRedirectsFromTransitions } from "./create-redirect.js";
2
+ import { getGlobalPublicationTransition } from "./publication/global-transition.js";
3
+ import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
4
+ export const createGlobalRedirect = ({ globalSlug, redirectCollectionSlug, pathOptions, localePrefixes, }) => async (args) => {
5
+ if (pathOptions.enabled === false || args.req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]) {
6
+ return args.doc;
7
+ }
8
+ const transitions = await getGlobalPublicationTransition({ req: args.req, globalSlug });
9
+ await createRedirectsFromTransitions({
10
+ req: args.req,
11
+ redirectCollectionSlug,
12
+ pathOptions,
13
+ localePrefixes,
14
+ transitions,
15
+ });
16
+ return args.doc;
17
+ };
18
+ //# sourceMappingURL=create-global-redirect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create-global-redirect.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/create-global-redirect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,8BAA8B,EAAE,MAAM,+CAA+C,CAAC;AAC/F,OAAO,EAAE,8BAA8B,EAAE,MAAM,6DAA6D,CAAC;AAC7G,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAW9E,MAAM,CAAC,MAAM,oBAAoB,GAC/B,CAA2B,EACzB,UAAU,EACV,sBAAsB,EACtB,WAAW,EACX,cAAc,GACqB,EAAyB,EAAE,CAChE,KAAK,EAAE,IAAI,EAAE,EAAE;IACb,IAAI,WAAW,CAAC,OAAO,KAAK,KAAK,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,CAAC;QACxF,OAAO,IAAI,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,MAAM,WAAW,GAAG,MAAM,8BAA8B,CAAC,EAAE,GAAG,EAAE,IAAI,CAAC,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;IACxF,MAAM,8BAA8B,CAAC;QACnC,GAAG,EAAE,IAAI,CAAC,GAAG;QACb,sBAAsB;QACtB,WAAW;QACX,cAAc;QACd,WAAW;KACZ,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import type { DataFromGlobalSlug, GlobalAfterChangeHook, GlobalSlug } from \"payload\";\nimport { createRedirectsFromTransitions } from \"#redirect/core/redirects/auto/create-redirect\";\nimport { getGlobalPublicationTransition } from \"#redirect/core/redirects/auto/publication/global-transition\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport type { LocalePrefixes } from \"#redirect/core/url/published-path\";\nimport type { RedirectPathOptions } from \"#redirect/core/redirects/auto/types\";\n\ntype CreateGlobalRedirectOptions<TSlug extends GlobalSlug = GlobalSlug> = {\n globalSlug: TSlug;\n redirectCollectionSlug: string;\n pathOptions: RedirectPathOptions<DataFromGlobalSlug<TSlug>>;\n localePrefixes?: LocalePrefixes;\n};\n\nexport const createGlobalRedirect =\n <TSlug extends GlobalSlug>({\n globalSlug,\n redirectCollectionSlug,\n pathOptions,\n localePrefixes,\n }: CreateGlobalRedirectOptions<TSlug>): GlobalAfterChangeHook =>\n async (args) => {\n if (pathOptions.enabled === false || args.req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]) {\n return args.doc;\n }\n\n const transitions = await getGlobalPublicationTransition({ req: args.req, globalSlug });\n await createRedirectsFromTransitions({\n req: args.req,\n redirectCollectionSlug,\n pathOptions,\n localePrefixes,\n transitions,\n });\n\n return args.doc;\n };\n"]}
@@ -1,10 +1,14 @@
1
- import type { CollectionAfterChangeHook } from "payload";
1
+ import type { CollectionAfterChangeHook, PayloadRequest } from "payload";
2
2
  import { type LocalePrefixes } from "../../url/published-path.js";
3
- import type { RedirectPathOptions } from "./types.js";
4
- type CreateRedirectOptions = {
5
- collectionSlug: string;
6
- pathOptions: RedirectPathOptions;
3
+ import type { PublicationTransition, RedirectPathOptions } from "./types.js";
4
+ type CreateRedirectOptions<TDocument = Record<string, unknown>> = {
5
+ redirectCollectionSlug: string;
6
+ pathOptions: RedirectPathOptions<TDocument>;
7
7
  localePrefixes?: LocalePrefixes;
8
8
  };
9
- export declare const createRedirect: ({ collectionSlug, pathOptions, localePrefixes, }: CreateRedirectOptions) => CollectionAfterChangeHook;
9
+ export declare const createRedirectsFromTransitions: <TDocument>({ req, redirectCollectionSlug, pathOptions, localePrefixes, transitions, }: CreateRedirectOptions<TDocument> & {
10
+ req: PayloadRequest;
11
+ transitions: PublicationTransition[];
12
+ }) => Promise<void>;
13
+ export declare const createRedirect: <TDocument = Record<string, unknown>>({ redirectCollectionSlug, pathOptions, localePrefixes, }: CreateRedirectOptions<TDocument>) => CollectionAfterChangeHook;
10
14
  export {};
@@ -3,12 +3,7 @@ import { getPublicationTransition } from "./publication/get-publication-transiti
3
3
  import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
4
4
  import { normalizePathOrUrl } from "../normalize-path.js";
5
5
  import { buildPublishedPath } from "../../url/published-path.js";
6
- export const createRedirect = ({ collectionSlug, pathOptions, localePrefixes, }) => async (args) => {
7
- if (pathOptions.enabled === false)
8
- return args.doc;
9
- if (args.req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto])
10
- return args.doc;
11
- const transitions = await getPublicationTransition(args);
6
+ export const createRedirectsFromTransitions = async ({ req, redirectCollectionSlug, pathOptions, localePrefixes, transitions, }) => {
12
7
  for (const { currentDoc, publishedDocs, locale } of transitions) {
13
8
  const currentPath = buildPublishedPath(pathOptions, currentDoc, locale, localePrefixes);
14
9
  if (!currentPath)
@@ -27,12 +22,26 @@ export const createRedirect = ({ collectionSlug, pathOptions, localePrefixes, })
27
22
  if (from === to)
28
23
  continue;
29
24
  await ensureAutoRedirect({
30
- req: args.req,
31
- collectionSlug,
25
+ req,
26
+ collectionSlug: redirectCollectionSlug,
32
27
  rule: { from, to },
33
- context: args.req.context,
28
+ context: req.context,
34
29
  });
35
30
  }
31
+ };
32
+ export const createRedirect = ({ redirectCollectionSlug, pathOptions, localePrefixes, }) => async (args) => {
33
+ if (pathOptions.enabled === false)
34
+ return args.doc;
35
+ if (args.req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto])
36
+ return args.doc;
37
+ const transitions = await getPublicationTransition(args);
38
+ await createRedirectsFromTransitions({
39
+ req: args.req,
40
+ redirectCollectionSlug,
41
+ pathOptions,
42
+ localePrefixes,
43
+ transitions,
44
+ });
36
45
  return args.doc;
37
46
  };
38
47
  //# sourceMappingURL=create-redirect.js.map
@@ -1 +1 @@
1
- {"version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AAK,EAAE,CAAC;QAClD,CAAC,CAAC,CAAC;QACH,IAAI,CAAC,oBAAoB;YAAE,SAAS;QAEpC,MAAM,YAAY,GAAG,kBAAkB,CACrC,WAAW,EACX,oBAAoB,EACpB,MAAM,EACN,cAAc,CACf,CAAC;QACF,IAAI,CAAC,YAAY;YAAE,SAAS;QAE5B,MAAM,IAAI,GAAG,kBAAkB,CAAC,YAAY,CAAC,CAAC;QAC9C,IAAI,IAAI,KAAK,EAAE;YAAE,SAAS;QAE1B,MAAM,kBAAkB,CAAC;YACvB,GAAG,EAAE,IAAI,CAAC,GAAG;YACb,cAAc;YACd,IAAI,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;YAClB,OAAO,EAAE,IAAI,CAAC,GAAG,CAAC,OAAO;SAC1B,CAAC,CAAC;IACL,CAAC;IAED,OAAO,IAAI,CAAC,GAAG,CAAC;AAClB,CAAC,CAAC","sourcesContent":["import type { CollectionAfterChangeHook } from \"payload\";\nimport { ensureAutoRedirect } from \"#redirect/core/redirects/auto/persist-auto-rule\";\nimport { getPublicationTransition } from \"#redirect/core/redirects/auto/publication/get-publication-transition\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport { normalizePathOrUrl } from \"#redirect/core/redirects/normalize-path\";\nimport { buildPublishedPath, type LocalePrefixes } from \"#redirect/core/url/published-path\";\nimport type { RedirectPathOptions } from \"./types.js\";\n\ntype CreateRedirectOptions = {\n collectionSlug: string;\n pathOptions: RedirectPathOptions;\n localePrefixes?: LocalePrefixes;\n};\n\nexport const createRedirect =\n ({\n collectionSlug,\n pathOptions,\n localePrefixes,\n }: CreateRedirectOptions): CollectionAfterChangeHook =>\n async (args) => {\n if (pathOptions.enabled === false) return args.doc;\n if (args.req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]) return args.doc;\n\n const transitions = await getPublicationTransition(args);\n\n for (const { currentDoc, publishedDocs, locale } of transitions) {\n const currentPath = buildPublishedPath(pathOptions, currentDoc, locale, localePrefixes);\n if (!currentPath) continue;\n\n const to = normalizePathOrUrl(currentPath);\n const previousPublishedDoc = publishedDocs.find((publishedDoc) => {\n const path = buildPublishedPath(pathOptions, publishedDoc, locale, localePrefixes);\n return !path || normalizePathOrUrl(path) !== to;\n });\n if (!previousPublishedDoc) continue;\n\n const previousPath = buildPublishedPath(\n pathOptions,\n previousPublishedDoc,\n locale,\n localePrefixes,\n );\n if (!previousPath) continue;\n\n const from = normalizePathOrUrl(previousPath);\n if (from === to) continue;\n\n await ensureAutoRedirect({\n req: args.req,\n collectionSlug,\n rule: { from, to },\n context: args.req.context,\n });\n }\n\n return args.doc;\n };\n"]}
1
+ {"version":3,"file":"create-redirect.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/create-redirect.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,kBAAkB,EAAE,MAAM,iDAAiD,CAAC;AACrF,OAAO,EAAE,wBAAwB,EAAE,MAAM,sEAAsE,CAAC;AAChH,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,kBAAkB,EAAuB,MAAM,mCAAmC,CAAC;AAS5F,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EAAa,EAC9D,GAAG,EACH,sBAAsB,EACtB,WAAW,EACX,cAAc,EACd,WAAW,GAIZ,EAAiB,EAAE;IAClB,KAAK,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,EAAE,IAAI,WAAW,EAAE,CAAC;QAChE,MAAM,WAAW,GAAG,kBAAkB,CAAC,WAAW,EAAE,UAAU,EAAE,MAAM,EAAE,cAAc,CAAC,CAAC;QACxF,IAAI,CAAC,WAAW;YAAE,SAAS;QAE3B,MAAM,EAAE,GAAG,kBAAkB,CAAC,WAAW,CAAC,CAAC;QAC3C,MAAM,oBAAoB,GAAG,aAAa,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE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AC","sourcesContent":["import type { CollectionAfterChangeHook, PayloadRequest } from \"payload\";\nimport { ensureAutoRedirect } from \"#redirect/core/redirects/auto/persist-auto-rule\";\nimport { getPublicationTransition } from \"#redirect/core/redirects/auto/publication/get-publication-transition\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport { normalizePathOrUrl } from \"#redirect/core/redirects/normalize-path\";\nimport { buildPublishedPath, type LocalePrefixes } from \"#redirect/core/url/published-path\";\nimport type { PublicationTransition, RedirectPathOptions } from \"./types.js\";\n\ntype CreateRedirectOptions<TDocument = Record<string, unknown>> = {\n redirectCollectionSlug: string;\n pathOptions: RedirectPathOptions<TDocument>;\n localePrefixes?: LocalePrefixes;\n};\n\nexport const createRedirectsFromTransitions = async <TDocument>({\n req,\n redirectCollectionSlug,\n pathOptions,\n localePrefixes,\n transitions,\n}: CreateRedirectOptions<TDocument> & {\n req: PayloadRequest;\n transitions: PublicationTransition[];\n}): Promise<void> => {\n for (const { currentDoc, publishedDocs, locale } of transitions) {\n const currentPath = buildPublishedPath(pathOptions, currentDoc, locale, localePrefixes);\n if (!currentPath) continue;\n\n const to = normalizePathOrUrl(currentPath);\n const previousPublishedDoc = publishedDocs.find((publishedDoc) => {\n const path = buildPublishedPath(pathOptions, publishedDoc, locale, localePrefixes);\n return !path || normalizePathOrUrl(path) !== to;\n });\n if (!previousPublishedDoc) continue;\n\n const previousPath = buildPublishedPath(\n pathOptions,\n previousPublishedDoc,\n locale,\n localePrefixes,\n );\n if (!previousPath) continue;\n\n const from = normalizePathOrUrl(previousPath);\n if (from === to) continue;\n\n await ensureAutoRedirect({\n req,\n collectionSlug: redirectCollectionSlug,\n rule: { from, to },\n context: req.context,\n });\n }\n};\n\nexport const createRedirect =\n <TDocument = Record<string, unknown>>({\n redirectCollectionSlug,\n pathOptions,\n localePrefixes,\n }: CreateRedirectOptions<TDocument>): CollectionAfterChangeHook =>\n async (args) => {\n if (pathOptions.enabled === false) return args.doc;\n if (args.req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]) return args.doc;\n\n const transitions = await getPublicationTransition(args);\n await createRedirectsFromTransitions({\n req: args.req,\n redirectCollectionSlug,\n pathOptions,\n localePrefixes,\n transitions,\n });\n\n return args.doc;\n };\n"]}
@@ -10,7 +10,7 @@ type EnsureAutoRedirectArgs = {
10
10
  context?: Record<string, unknown>;
11
11
  };
12
12
  /**
13
- * Idempotent create for auto 301 rules. One lookup by unique `from`.
13
+ * Idempotent create for auto 301 rules. Plugin-owned integrity operations use trusted Local API access.
14
14
  */
15
15
  export declare const ensureAutoRedirect: ({ req, collectionSlug, rule, context, }: EnsureAutoRedirectArgs) => Promise<"created" | "skipped" | "updated">;
16
16
  export {};
@@ -1,13 +1,14 @@
1
1
  import { isIdenticalAutoRule } from "./match-existing-rule.js";
2
+ import { lockRedirectRuleGraph } from "../collection/graph-lock.js";
2
3
  import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
3
4
  import { findRedirectByFrom } from "../queries.js";
4
5
  /**
5
- * Idempotent create for auto 301 rules. One lookup by unique `from`.
6
+ * Idempotent create for auto 301 rules. Plugin-owned integrity operations use trusted Local API access.
6
7
  */
7
8
  export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }) => {
8
9
  const internalContext = {
9
10
  ...context,
10
- [REDIRECT_CONTEXT_KEYS.internal]: true,
11
+ [REDIRECT_CONTEXT_KEYS.autoWrite]: true,
11
12
  [REDIRECT_CONTEXT_KEYS.skipAuto]: true,
12
13
  };
13
14
  const data = {
@@ -18,11 +19,13 @@ export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }
18
19
  origin: "auto",
19
20
  };
20
21
  const payload = req.payload;
22
+ // Lock before the lookup: the ownership decision must read rows committed before this write.
23
+ await lockRedirectRuleGraph(req);
21
24
  const existing = await findRedirectByFrom(req.payload, {
22
25
  collectionSlug,
23
26
  from: rule.from,
24
27
  req,
25
- overrideAccess: false,
28
+ overrideAccess: true,
26
29
  context: internalContext,
27
30
  });
28
31
  const doc = existing.docs[0];
@@ -40,7 +43,7 @@ export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }
40
43
  enabled: true,
41
44
  },
42
45
  context: internalContext,
43
- overrideAccess: false,
46
+ overrideAccess: true,
44
47
  req,
45
48
  });
46
49
  return "updated";
@@ -51,7 +54,7 @@ export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }
51
54
  collection: collectionSlug,
52
55
  data,
53
56
  context: internalContext,
54
- overrideAccess: false,
57
+ overrideAccess: true,
55
58
  req,
56
59
  });
57
60
  return "created";
@@ -1 +1 @@
1
- {"version":3,"file":"persist-auto-rule.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/persist-auto-rule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAA0B,MAAM,kCAAkC,CAAC;AAc9F;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,GAAG,EACH,cAAc,EACd,IAAI,EACJ,OAAO,GACgB,EAA8C,EAAE;IACvE,MAAM,eAAe,GAAG;QACtB,GAAG,OAAO;QACV,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,IAAI;QACtC,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,IAAI;KACvC,CAAC;IAEF,MAAM,IAAI,GAAG;QACX,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,EAAE,EAAE,IAAI,CAAC,EAAE;QACX,UAAU,EAAE,KAAK;QACjB,OAAO,EAAE,IAAI;QACb,MAAM,EAAE,MAAe;KACxB,CAAC;IACF,MAAM,OAAO,GAAG,GAAG,CAAC,OAGnB,CAAC;IAEF,MAAM,QAAQ,GAAG,MAAM,kBAAkB,CAAC,GAAG,CAAC,OAAO,EAAE;QACrD,cAAc;QACd,IAAI,EAAE,IAAI,CAAC,IAAI;QACf,GAAG;QACH,cAAc,EAAE,KAAK;QACrB,OAAO,EAAE,eAAe;KACzB,CAAC,CAAC;IAEH,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAkC,CAAC;IAC9D,IAAI,GAAG,EAAE,CAAC;QACR,IAAI,mBAAmB,CAAC,GAAG,EAAE,IAAI,CAAC,EAAE,CAAC;YACnC,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;YAC1B,MAAM,OAAO,CAAC,MAAM,CAAC;gBACnB,UAAU,EAAE,cAAc;gBAC1B,EAAE,EAAE,GAAG,CAAC,EAAE;gBACV,IAAI,EAAE;oBACJ,EAAE,EAAE,IAAI,CAAC,EAAE;oBACX,UAAU,EAAE,KAAK;oBACjB,OAAO,EAAE,IAAI;iBACd;gBACD,OAAO,EAAE,eAAe;gBACxB,cAAc,EAAE,KAAK;gBACrB,GAAG;aACJ,CAAC,CAAC;YACH,OAAO,SAAS,CAAC;QACnB,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,CAAC,MAAM,CAAC;QACnB,UAAU,EAAE,cAAc;QAC1B,IAAI;QACJ,OAAO,EAAE,eAAe;QACxB,cAAc,EAAE,KAAK;QACrB,GAAG;KACJ,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { PayloadRequest } from \"payload\";\nimport { isIdenticalAutoRule } from \"#redirect/core/redirects/auto/match-existing-rule\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport { findRedirectByFrom, type RedirectLookupDoc } from \"#redirect/core/redirects/queries\";\n\ntype AutoRedirectRule = {\n from: string;\n to: string;\n};\n\ntype EnsureAutoRedirectArgs = {\n req: PayloadRequest;\n collectionSlug: string;\n rule: AutoRedirectRule;\n context?: Record<string, unknown>;\n};\n\n/**\n * Idempotent create for auto 301 rules. One lookup by unique `from`.\n */\nexport const ensureAutoRedirect = async ({\n req,\n collectionSlug,\n rule,\n context,\n}: EnsureAutoRedirectArgs): Promise<\"created\" | \"skipped\" | \"updated\"> => {\n const internalContext = {\n ...context,\n [REDIRECT_CONTEXT_KEYS.internal]: true,\n [REDIRECT_CONTEXT_KEYS.skipAuto]: true,\n };\n\n const data = {\n from: rule.from,\n to: rule.to,\n statusCode: \"301\",\n enabled: true,\n origin: \"auto\" as const,\n };\n const payload = req.payload as unknown as {\n create: (args: Record<string, unknown>) => Promise<unknown>;\n update: (args: Record<string, unknown>) => Promise<unknown>;\n };\n\n const existing = await findRedirectByFrom(req.payload, {\n collectionSlug,\n from: rule.from,\n req,\n overrideAccess: false,\n context: internalContext,\n });\n\n const doc = existing.docs[0] as RedirectLookupDoc | undefined;\n if (doc) {\n if (isIdenticalAutoRule(doc, rule)) {\n return \"skipped\";\n }\n if (doc.origin === \"auto\") {\n await payload.update({\n collection: collectionSlug,\n id: doc.id,\n data: {\n to: rule.to,\n statusCode: \"301\",\n enabled: true,\n },\n context: internalContext,\n overrideAccess: false,\n req,\n });\n return \"updated\";\n }\n return \"skipped\";\n }\n\n await payload.create({\n collection: collectionSlug,\n data,\n context: internalContext,\n overrideAccess: false,\n req,\n });\n\n return \"created\";\n};\n"]}
1
+ {"version":3,"file":"persist-auto-rule.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/persist-auto-rule.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,mDAAmD,CAAC;AACxF,OAAO,EAAE,qBAAqB,EAAE,MAAM,gDAAgD,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAC9E,OAAO,EAAE,kBAAkB,EAA0B,MAAM,kCAAkC,CAAC;AAc9F;;GAEG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,KAAK,EAAE,EACvC,GAAG,EACH,cAAc,EACd,IAAI,EACJ,O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;QACD,OAAO,SAAS,CAAC;IACnB,CAAC;IAED,MAAM,OAAO,CAAC,MAAM,CAAC;QACnB,UAAU,EAAE,cAAc;QAC1B,IAAI;QACJ,OAAO,EAAE,eAAe;QACxB,cAAc,EAAE,IAAI;QACpB,GAAG;KACJ,CAAC,CAAC;IAEH,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { PayloadRequest } from \"payload\";\nimport { isIdenticalAutoRule } from \"#redirect/core/redirects/auto/match-existing-rule\";\nimport { lockRedirectRuleGraph } from \"#redirect/core/redirects/collection/graph-lock\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport { findRedirectByFrom, type RedirectLookupDoc } from \"#redirect/core/redirects/queries\";\n\ntype AutoRedirectRule = {\n from: string;\n to: string;\n};\n\ntype EnsureAutoRedirectArgs = {\n req: PayloadRequest;\n collectionSlug: string;\n rule: AutoRedirectRule;\n context?: Record<string, unknown>;\n};\n\n/**\n * Idempotent create for auto 301 rules. Plugin-owned integrity operations use trusted Local API access.\n */\nexport const ensureAutoRedirect = async ({\n req,\n collectionSlug,\n rule,\n context,\n}: EnsureAutoRedirectArgs): Promise<\"created\" | \"skipped\" | \"updated\"> => {\n const internalContext = {\n ...context,\n [REDIRECT_CONTEXT_KEYS.autoWrite]: true,\n [REDIRECT_CONTEXT_KEYS.skipAuto]: true,\n };\n\n const data = {\n from: rule.from,\n to: rule.to,\n statusCode: \"301\",\n enabled: true,\n origin: \"auto\" as const,\n };\n const payload = req.payload as unknown as {\n create: (args: Record<string, unknown>) => Promise<unknown>;\n update: (args: Record<string, unknown>) => Promise<unknown>;\n };\n\n // Lock before the lookup: the ownership decision must read rows committed before this write.\n await lockRedirectRuleGraph(req);\n const existing = await findRedirectByFrom(req.payload, {\n collectionSlug,\n from: rule.from,\n req,\n overrideAccess: true,\n context: internalContext,\n });\n\n const doc = existing.docs[0] as RedirectLookupDoc | undefined;\n if (doc) {\n if (isIdenticalAutoRule(doc, rule)) {\n return \"skipped\";\n }\n if (doc.origin === \"auto\") {\n await payload.update({\n collection: collectionSlug,\n id: doc.id,\n data: {\n to: rule.to,\n statusCode: \"301\",\n enabled: true,\n },\n context: internalContext,\n overrideAccess: true,\n req,\n });\n return \"updated\";\n }\n return \"skipped\";\n }\n\n await payload.create({\n collection: collectionSlug,\n data,\n context: internalContext,\n overrideAccess: true,\n req,\n });\n\n return \"created\";\n};\n"]}
@@ -0,0 +1,6 @@
1
+ import type { PayloadRequest } from "payload";
2
+ import type { PublicationTransition } from "../types.js";
3
+ export declare const getGlobalPublicationTransition: ({ req, globalSlug, }: {
4
+ req: PayloadRequest;
5
+ globalSlug: string;
6
+ }) => Promise<PublicationTransition[]>;
@@ -0,0 +1,63 @@
1
+ import { REDIRECT_CONTEXT_KEYS } from "../../context-keys.js";
2
+ import { getConfiguredLocales, hasLocalizedDraftStatus, resolveDefaultLocale } from "./locales.js";
3
+ import { isDraftSave, isLocalePublished } from "./publish-intent.js";
4
+ import { isPublishedVersionRow } from "./versions/version-rows.js";
5
+ const VERSION_PAGE_SIZE = 50;
6
+ export const getGlobalPublicationTransition = async ({ req, globalSlug, }) => {
7
+ if (isDraftSave(req) ||
8
+ req.query?.autosave === "true" ||
9
+ req.query?.autosave === true ||
10
+ req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]) {
11
+ return [];
12
+ }
13
+ const global = req.payload.globals.config.find(({ slug }) => slug === globalSlug);
14
+ if (!global?.versions?.drafts)
15
+ return [];
16
+ const slug = globalSlug;
17
+ const localizeStatus = hasLocalizedDraftStatus(global);
18
+ const defaultLocale = resolveDefaultLocale(req);
19
+ const transitions = [];
20
+ for (const locale of getConfiguredLocales(req)) {
21
+ const currentDoc = await req.payload.findGlobal({
22
+ slug,
23
+ ...(locale ? { locale: locale } : {}),
24
+ fallbackLocale: false,
25
+ depth: 0,
26
+ overrideAccess: true,
27
+ req,
28
+ });
29
+ if (!currentDoc || Object.keys(currentDoc).length === 0)
30
+ continue;
31
+ if (!isLocalePublished(currentDoc._status, locale ?? ""))
32
+ continue;
33
+ const publishedDocs = [];
34
+ let page = 1;
35
+ while (true) {
36
+ const result = await req.payload.findGlobalVersions({
37
+ slug,
38
+ ...(locale ? { locale: locale } : {}),
39
+ sort: "-updatedAt",
40
+ page,
41
+ limit: VERSION_PAGE_SIZE,
42
+ depth: 0,
43
+ fallbackLocale: false,
44
+ overrideAccess: true,
45
+ req,
46
+ });
47
+ publishedDocs.push(...result.docs
48
+ .filter((row) => isPublishedVersionRow(row, locale, { localizeStatus, defaultLocale }))
49
+ .map((row) => row.version)
50
+ .filter((version) => Boolean(version)));
51
+ if (!result.hasNextPage)
52
+ break;
53
+ page += 1;
54
+ }
55
+ transitions.push({
56
+ locale,
57
+ currentDoc: currentDoc,
58
+ publishedDocs,
59
+ });
60
+ }
61
+ return transitions;
62
+ };
63
+ //# sourceMappingURL=global-transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"global-transition.js","sourceRoot":"","sources":["../../../../../src/core/redirects/auto/publication/global-transition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,OAAO,EAAE,oBAAoB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AACnG,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,qBAAqB,EAAmB,MAAM,4BAA4B,CAAC;AAEpF,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B,MAAM,CAAC,MAAM,8BAA8B,GAAG,KAAK,EAAE,EACnD,GAAG,EACH,UAAU,GAIX,EAAoC,EAAE;IACrC,IACE,WAAW,CAAC,GAAG,CAAC;QAChB,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,MAAM;QAC9B,GAAG,CAAC,KAAK,EAAE,QAAQ,KAAK,IAAI;QAC5B,GAAG,CAAC,OAAO,EAAE,CAAC,qBAAqB,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CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpD,IAAI,EAAE,YAAY;gBAClB,IAAI;gBACJ,KAAK,EAAE,iBAAiB;gBACxB,KAAK,EAAE,CAAC;gBACR,cAAc,EAAE,KAAK;gBACrB,cAAc,EAAE,IAAI;gBACpB,GAAG;aACJ,CAAC,CAAC;YAEH,aAAa,CAAC,IAAI,CAChB,GAAI,MAAM,CAAC,IAAqB;iBAC7B,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,cAAc,EAAE,aAAa,EAAE,CAAC,CAAC;iBACtF,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;iBACzB,MAAM,CAAC,CAAC,OAAO,EAAsC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAC7E,CAAC;YACF,IAAI,CAAC,MAAM,CAAC,WAAW;gBAAE,MAAM;YAC/B,IAAI,IAAI,CAAC,CAAC;QACZ,CAAC;QAED,WAAW,CAAC,IAAI,CAAC;YACf,MAAM;YACN,UAAU,EAAE,UAAqC;YACjD,aAAa;SACd,CAAC,CAAC;IACL,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["import type { GlobalSlug, PayloadRequest, TypedLocale } from \"payload\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport type { PublicationTransition } from \"../types.js\";\nimport { getConfiguredLocales, hasLocalizedDraftStatus, resolveDefaultLocale } from \"./locales.js\";\nimport { isDraftSave, isLocalePublished } from \"./publish-intent.js\";\nimport { isPublishedVersionRow, type VersionRow } from \"./versions/version-rows.js\";\n\nconst VERSION_PAGE_SIZE = 50;\n\nexport const getGlobalPublicationTransition = async ({\n req,\n globalSlug,\n}: {\n req: PayloadRequest;\n globalSlug: string;\n}): Promise<PublicationTransition[]> => {\n if (\n isDraftSave(req) ||\n req.query?.autosave === \"true\" ||\n req.query?.autosave === true ||\n req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]\n ) {\n return [];\n }\n\n const global = req.payload.globals.config.find(({ slug }) => slug === globalSlug);\n if (!global?.versions?.drafts) return [];\n\n const slug = globalSlug as GlobalSlug;\n const localizeStatus = hasLocalizedDraftStatus(global);\n const defaultLocale = resolveDefaultLocale(req);\n const transitions: PublicationTransition[] = [];\n\n for (const locale of getConfiguredLocales(req)) {\n const currentDoc = await req.payload.findGlobal({\n slug,\n ...(locale ? { locale: locale as TypedLocale } : {}),\n fallbackLocale: false,\n depth: 0,\n overrideAccess: true,\n req,\n });\n if (!currentDoc || Object.keys(currentDoc).length === 0) continue;\n if (!isLocalePublished(currentDoc._status, locale ?? \"\")) continue;\n\n const publishedDocs: Record<string, unknown>[] = [];\n let page = 1;\n while (true) {\n const result = await req.payload.findGlobalVersions({\n slug,\n ...(locale ? { locale: locale as TypedLocale } : {}),\n sort: \"-updatedAt\",\n page,\n limit: VERSION_PAGE_SIZE,\n depth: 0,\n fallbackLocale: false,\n overrideAccess: true,\n req,\n });\n\n publishedDocs.push(\n ...(result.docs as VersionRow[])\n .filter((row) => isPublishedVersionRow(row, locale, { localizeStatus, defaultLocale }))\n .map((row) => row.version)\n .filter((version): version is Record<string, unknown> => Boolean(version)),\n );\n if (!result.hasNextPage) break;\n page += 1;\n }\n\n transitions.push({\n locale,\n currentDoc: currentDoc as Record<string, unknown>,\n publishedDocs,\n });\n }\n\n return transitions;\n};\n"]}
@@ -1,5 +1,6 @@
1
1
  import type { PayloadRequest } from "payload";
2
2
  export declare const getRequestLocales: (req: PayloadRequest, status: unknown) => Array<string | undefined>;
3
+ export declare const getConfiguredLocales: (req: PayloadRequest) => Array<string | undefined>;
3
4
  export declare const hasLocalizedDraftStatus: (collection: {
4
5
  versions?: {
5
6
  drafts?: unknown;
@@ -32,6 +32,10 @@ export const getRequestLocales = (req, status) => {
32
32
  return [req.locale];
33
33
  return status === "published" ? localization : [];
34
34
  };
35
+ export const getConfiguredLocales = (req) => {
36
+ const locales = listLocales(req);
37
+ return locales.length > 0 ? locales : [undefined];
38
+ };
35
39
  export const hasLocalizedDraftStatus = (collection) => {
36
40
  const drafts = collection.versions === false ? undefined : collection.versions?.drafts;
37
41
  return Boolean(drafts && typeof drafts === "object" && "localizeStatus" in drafts && drafts.localizeStatus);
@@ -1 +1 @@
1
- {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../../../src/core/redirects/auto/publication/locales.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,CAAC,GAAmB,EAAY,EAAE;IACpD,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACrD,IAAI,YAAY,KAAK,KAAK,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IACvD,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACnG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,GAAmB,EACnB,MAAe,EACY,EAAE;IAC7B,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAElD,MAAM,cAAc,GAClB,OAAO,GAAG,CAAC,KAAK,EAAE,qBAAqB,KAAK,QAAQ;QAClD,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,qBAAqB;QACjC,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,cAAc,IAAI,cAAc,KAAK,KAAK;QAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAExE,IACE,cA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AAM,KAAK,QAAQ,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAC5F,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAmB,EAAsB,EAAE;IAC9E,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACrD,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC,CAAC","sourcesContent":["import type { PayloadRequest } from \"payload\";\n\nconst listLocales = (req: PayloadRequest): string[] => {\n const localization = req.payload.config.localization;\n if (localization === false || !localization) return [];\n return localization.locales.map((locale) => (typeof locale === \"string\" ? locale : locale.code));\n};\n\nexport const getRequestLocales = (\n req: PayloadRequest,\n status: unknown,\n): Array<string | undefined> => {\n const localization = listLocales(req);\n if (localization.length === 0) return [undefined];\n\n const specificLocale =\n typeof req.query?.publishSpecificLocale === \"string\"\n ? req.query.publishSpecificLocale\n : undefined;\n if (specificLocale && specificLocale !== \"all\") return [specificLocale];\n\n if (\n specificLocale === \"all\" ||\n req.query?.publishAllLocales === \"true\" ||\n req.query?.publishAllLocales === true\n ) {\n return localization;\n }\n\n const requestedLocale = typeof req.query?.locale === \"string\" ? req.query.locale : undefined;\n if (requestedLocale && requestedLocale !== \"all\") return [requestedLocale];\n if (requestedLocale === \"all\") return localization;\n\n if (status && typeof status === \"object\" && !Array.isArray(status)) {\n return Object.entries(status as Record<string, unknown>)\n .filter(([, value]) => value === \"published\")\n .map(([locale]) => locale);\n }\n\n if (typeof req.locale === \"string\") return [req.locale];\n\n return status === \"published\" ? localization : [];\n};\n\nexport const hasLocalizedDraftStatus = (collection: {\n versions?: { drafts?: unknown } | false;\n}): boolean => {\n const drafts = collection.versions === false ? undefined : collection.versions?.drafts;\n return Boolean(\n drafts && typeof drafts === \"object\" && \"localizeStatus\" in drafts && drafts.localizeStatus,\n );\n};\n\nexport const resolveDefaultLocale = (req: PayloadRequest): string | undefined => {\n const localization = req.payload.config.localization;\n return localization ? localization.defaultLocale : undefined;\n};\n"]}
1
+ {"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../../../src/core/redirects/auto/publication/locales.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,GAAG,CAAC,GAAmB,EAAY,EAAE;IACpD,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACrD,IAAI,YAAY,KAAK,KAAK,IAAI,CAAC,YAAY;QAAE,OAAO,EAAE,CAAC;IACvD,OAAO,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;AACnG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAC/B,GAAmB,EACnB,MAAe,EACY,EAAE;IAC7B,MAAM,YAAY,GAAG,WAAW,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,CAAC,SAAS,CAAC,CAAC;IAElD,MAAM,cAAc,GAClB,OAAO,GAAG,CAAC,KAAK,EAAE,qBAAqB,KAAK,QAAQ;QAClD,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,qBAAqB;QACjC,CAAC,CAAC,SAAS,CAAC;IAChB,IAAI,cAAc,IAAI,cAAc,KAAK,KAAK;QAAE,OAAO,CAAC,cAAc,CAAC,CAAC;IAExE,IACE,cAAc,KAAK,KAAK;QACxB,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,MAAM;QACvC,GAAG,CAAC,KAAK,EAAE,iBAAiB,KAAK,IAAI,EACrC,CAAC;QACD,OAAO,YAAY,CAAC;IACtB,CAAC;IAED,MAAM,eAAe,GAAG,OAA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MAAM,CAAC;IACvF,OAAO,OAAO,CACZ,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,gBAAgB,IAAI,MAAM,IAAI,MAAM,CAAC,cAAc,CAC5F,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,GAAmB,EAAsB,EAAE;IAC9E,MAAM,YAAY,GAAG,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC;IACrD,OAAO,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/D,CAAC,CAAC","sourcesContent":["import type { PayloadRequest } from \"payload\";\n\nconst listLocales = (req: PayloadRequest): string[] => {\n const localization = req.payload.config.localization;\n if (localization === false || !localization) return [];\n return localization.locales.map((locale) => (typeof locale === \"string\" ? locale : locale.code));\n};\n\nexport const getRequestLocales = (\n req: PayloadRequest,\n status: unknown,\n): Array<string | undefined> => {\n const localization = listLocales(req);\n if (localization.length === 0) return [undefined];\n\n const specificLocale =\n typeof req.query?.publishSpecificLocale === \"string\"\n ? req.query.publishSpecificLocale\n : undefined;\n if (specificLocale && specificLocale !== \"all\") return [specificLocale];\n\n if (\n specificLocale === \"all\" ||\n req.query?.publishAllLocales === \"true\" ||\n req.query?.publishAllLocales === true\n ) {\n return localization;\n }\n\n const requestedLocale = typeof req.query?.locale === \"string\" ? req.query.locale : undefined;\n if (requestedLocale && requestedLocale !== \"all\") return [requestedLocale];\n if (requestedLocale === \"all\") return localization;\n\n if (status && typeof status === \"object\" && !Array.isArray(status)) {\n return Object.entries(status as Record<string, unknown>)\n .filter(([, value]) => value === \"published\")\n .map(([locale]) => locale);\n }\n\n if (typeof req.locale === \"string\") return [req.locale];\n\n return status === \"published\" ? localization : [];\n};\n\nexport const getConfiguredLocales = (req: PayloadRequest): Array<string | undefined> => {\n const locales = listLocales(req);\n return locales.length > 0 ? locales : [undefined];\n};\n\nexport const hasLocalizedDraftStatus = (collection: {\n versions?: { drafts?: unknown } | false;\n}): boolean => {\n const drafts = collection.versions === false ? undefined : collection.versions?.drafts;\n return Boolean(\n drafts && typeof drafts === \"object\" && \"localizeStatus\" in drafts && drafts.localizeStatus,\n );\n};\n\nexport const resolveDefaultLocale = (req: PayloadRequest): string | undefined => {\n const localization = req.payload.config.localization;\n return localization ? localization.defaultLocale : undefined;\n};\n"]}
@@ -1,5 +1,5 @@
1
- import type { CollectionSlug, DataFromCollectionSlug, TypedLocale } from "payload";
2
- export type RedirectPathOptions<TSlug extends CollectionSlug = CollectionSlug> = {
1
+ import type { TypedLocale } from "payload";
2
+ export type RedirectPathOptions<TDocument = Record<string, unknown>> = {
3
3
  enabled?: true;
4
4
  path: string;
5
5
  paths?: never;
@@ -14,7 +14,7 @@ export type RedirectPathOptions<TSlug extends CollectionSlug = CollectionSlug> =
14
14
  path?: never;
15
15
  paths?: never;
16
16
  getPath: (args: {
17
- doc: DataFromCollectionSlug<TSlug>;
17
+ doc: TDocument;
18
18
  locale: TypedLocale | undefined;
19
19
  }) => string | null;
20
20
  } | {
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { CollectionSlug, DataFromCollectionSlug, TypedLocale } from \"payload\";\n\nexport type RedirectPathOptions<TSlug extends CollectionSlug = CollectionSlug> =\n | {\n enabled?: true;\n path: string;\n paths?: never;\n getPath?: never;\n }\n | {\n enabled?: true;\n path?: never;\n paths: string extends Extract<TypedLocale, string>\n ? Record<string, string>\n : Record<Extract<TypedLocale, string>, string>;\n getPath?: never;\n }\n | {\n enabled?: true;\n path?: never;\n paths?: never;\n getPath: (args: {\n doc: DataFromCollectionSlug<TSlug>;\n locale: TypedLocale | undefined;\n }) => string | null;\n }\n | {\n enabled: false;\n path?: never;\n paths?: never;\n getPath?: never;\n };\n\nexport type PublicationTransition = {\n locale?: string;\n currentDoc: Record<string, unknown>;\n publishedDocs: Record<string, unknown>[];\n};\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TypedLocale } from \"payload\";\n\nexport type RedirectPathOptions<TDocument = Record<string, unknown>> =\n | {\n enabled?: true;\n path: string;\n paths?: never;\n getPath?: never;\n }\n | {\n enabled?: true;\n path?: never;\n paths: string extends Extract<TypedLocale, string>\n ? Record<string, string>\n : Record<Extract<TypedLocale, string>, string>;\n getPath?: never;\n }\n | {\n enabled?: true;\n path?: never;\n paths?: never;\n getPath: (args: { doc: TDocument; locale: TypedLocale | undefined }) => string | null;\n }\n | {\n enabled: false;\n path?: never;\n paths?: never;\n getPath?: never;\n };\n\nexport type PublicationTransition = {\n locale?: string;\n currentDoc: Record<string, unknown>;\n publishedDocs: Record<string, unknown>[];\n};\n"]}
@@ -1,5 +1,5 @@
1
- import { defaultRedirectAccess } from "./access.js";
2
1
  import { createDuplicateBeforeChange } from "./duplicate-guard.js";
2
+ import { createRedirectGraphLockBeforeOperation } from "./graph-lock.js";
3
3
  import { assertRedirectFields, buildRedirectFields, mergeRedirectFields } from "./fields.js";
4
4
  import { createRedirectOriginBeforeChange } from "./origin-hook.js";
5
5
  const DEFAULT_SLUG = "redirects";
@@ -11,7 +11,6 @@ export const createRedirectsCollection = (overrides = {}) => {
11
11
  assertRedirectFields(fields);
12
12
  const slug = overrides.slug ?? DEFAULT_SLUG;
13
13
  const existingHooks = overrides.hooks ?? {};
14
- const access = { ...defaultRedirectAccess, ...overrides.access };
15
14
  return {
16
15
  ...overrides,
17
16
  slug,
@@ -25,10 +24,13 @@ export const createRedirectsCollection = (overrides = {}) => {
25
24
  ...overrides.admin,
26
25
  },
27
26
  defaultSort: overrides.defaultSort ?? "from",
28
- access,
29
27
  fields,
30
28
  hooks: {
31
29
  ...existingHooks,
30
+ beforeOperation: [
31
+ ...(existingHooks.beforeOperation ?? []),
32
+ createRedirectGraphLockBeforeOperation(),
33
+ ],
32
34
  beforeChange: [
33
35
  ...(existingHooks.beforeChange ?? []),
34
36
  createRedirectOriginBeforeChange(),
@@ -1 +1 @@
1
- {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,aAAa,CAAC;AACpD,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAGpE,MAAM,YAAY,GAAG,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,SAAS,GAAgC,EAAE,EACzB,EAAE;IACpB,MAAM,aAAa,GAAG,mBAAmB,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAY,SAAS,CAAC,MAAM;QACtC,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC;QAC1D,CAAC,CAAC,aAAa,CAAC;IAElB,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAE7B,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,YAAY,CAAC;IAC5C,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAG,EAAE,GAAG,qBAAqB,EAAE,GAAG,SAAS,CAAC,MAAM,EAAE,CAAC;IAEjE,OAAO;QACL,GAAG,SAAS;QACZ,IAAI;QACJ,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,IAAI;QAC9B,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,KAAK;QACrC,UAAU,EAAE,SAAS,CAAC,UAAU,IAAI,IAAI;QACxC,KAAK,EAAE;YACL,UAAU,EAAE,MAAM;YAClB,cAAc,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC;YAC9E,oBAAoB,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC;YACpC,GAAG,SAAS,CAAC,KAAK;SACnB;QACD,WAAW,EAAE,SAAS,CAAC,WAAW,IAAI,MAAM;QAC5C,MAAM;QACN,MAAM;QACN,KAAK,EAAE;YACL,GAAG,aAAa;YAChB,YAAY,EAAE;gBACZ,GAAG,CAAC,aAAa,CAAC,YAAY,IAAI,EAAE,CAAC;gBACrC,gCAAgC,EAAE;gBAClC,2BAA2B,CAAC,IAAI,CAAC;aAClC;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { CollectionConfig, Field } from \"payload\";\nimport { defaultRedirectAccess } from \"./access.js\";\nimport { createDuplicateBeforeChange } from \"./duplicate-guard.js\";\nimport { assertRedirectFields, buildRedirectFields, mergeRedirectFields } from \"./fields.js\";\nimport { createRedirectOriginBeforeChange } from \"./origin-hook.js\";\nimport type { RedirectCollectionOverrides } from \"./types.js\";\n\nconst DEFAULT_SLUG = \"redirects\";\n\nexport const createRedirectsCollection = (\n overrides: RedirectCollectionOverrides = {},\n): CollectionConfig => {\n const defaultFields = buildRedirectFields();\n const fields: Field[] = overrides.fields\n ? mergeRedirectFields(overrides.fields({ defaultFields }))\n : defaultFields;\n\n assertRedirectFields(fields);\n\n const slug = overrides.slug ?? DEFAULT_SLUG;\n const existingHooks = overrides.hooks ?? {};\n const access = { ...defaultRedirectAccess, ...overrides.access };\n\n return {\n ...overrides,\n slug,\n trash: overrides.trash ?? true,\n versions: overrides.versions ?? false,\n timestamps: overrides.timestamps ?? true,\n admin: {\n useAsTitle: \"from\",\n defaultColumns: [\"from\", \"to\", \"statusCode\", \"origin\", \"enabled\", \"updatedAt\"],\n listSearchableFields: [\"from\", \"to\"],\n ...overrides.admin,\n },\n defaultSort: overrides.defaultSort ?? \"from\",\n access,\n fields,\n hooks: {\n ...existingHooks,\n beforeChange: [\n ...(existingHooks.beforeChange ?? []),\n createRedirectOriginBeforeChange(),\n createDuplicateBeforeChange(slug),\n ],\n },\n };\n};\n"]}
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/collection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,sCAAsC,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAE,oBAAoB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAC7F,OAAO,EAAE,gCAAgC,EAAE,MAAM,kBAAkB,CAAC;AAGpE,MAAM,YAAY,GAAG,WAAW,CAAC;AAEjC,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,SAAS,GAAgC,EAAE,EACzB,EAAE;IACpB,MAAM,aAAa,GAAG,mBAAmB,EAAE,CAAC;IAC5C,MAAM,MAAM,GAAY,SAAS,CAAC,MAAM;QACtC,CAAC,CAAC,mBAAmB,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,aAAa,EAAE,CAAC,CAAC;QAC1D,CAAC,CAAC,aAAa,CAAC;IAElB,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAE7B,MAAM,IAAI,GAAG,SAAS,CAAC,IAAI,IAAI,YAAY,CAAC;IAC5C,MAAM,aAAa,GAAG,SAAS,CAAC,KAAK,IAAI,EAAE,CAAC;IAE5C,OAAO;QACL,GAAG,SAAS;QACZ,IAAI;QACJ,KAAK,EAAE,SAAS,CAAC,KAAK,IAAI,IAAI;QAC9B,QAAQ,EAAE,SAAS,CAAC,QAAQ,IAAI,KAAK;QACrC,UAAU,EAAE,SAAS,CAAC,UAAU,IAAI,IAAI;QACxC,KAAK,EAAE;YACL,UAAU,EAAE,MAAM;YAClB,cAAc,EAAE,CAAC,MAAM,EAAE,IAAI,EAAE,YAAY,EAAE,QAAQ,EAAE,SAAS,EAAE,WAAW,CAAC;YAC9E,oBAAoB,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC;YACpC,GAAG,SAAS,CAAC,KAAK;SACnB;QACD,WAAW,EAAE,SAAS,CAAC,WAAW,IAAI,MAAM;QAC5C,MAAM;QACN,KAAK,EAAE;YACL,GAAG,aAAa;YAChB,eAAe,EAAE;gBACf,GAAG,CAAC,aAAa,CAAC,eAAe,IAAI,EAAE,CAAC;gBACxC,sCAAsC,EAAE;aACzC;YACD,YAAY,EAAE;gBACZ,GAAG,CAAC,aAAa,CAAC,YAAY,IAAI,EAAE,CAAC;gBACrC,gCAAgC,EAAE;gBAClC,2BAA2B,CAAC,IAAI,CAAC;aAClC;SACF;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { CollectionConfig, Field } from \"payload\";\nimport { createDuplicateBeforeChange } from \"./duplicate-guard.js\";\nimport { createRedirectGraphLockBeforeOperation } from \"./graph-lock.js\";\nimport { assertRedirectFields, buildRedirectFields, mergeRedirectFields } from \"./fields.js\";\nimport { createRedirectOriginBeforeChange } from \"./origin-hook.js\";\nimport type { RedirectCollectionOverrides } from \"./types.js\";\n\nconst DEFAULT_SLUG = \"redirects\";\n\nexport const createRedirectsCollection = (\n overrides: RedirectCollectionOverrides = {},\n): CollectionConfig => {\n const defaultFields = buildRedirectFields();\n const fields: Field[] = overrides.fields\n ? mergeRedirectFields(overrides.fields({ defaultFields }))\n : defaultFields;\n\n assertRedirectFields(fields);\n\n const slug = overrides.slug ?? DEFAULT_SLUG;\n const existingHooks = overrides.hooks ?? {};\n\n return {\n ...overrides,\n slug,\n trash: overrides.trash ?? true,\n versions: overrides.versions ?? false,\n timestamps: overrides.timestamps ?? true,\n admin: {\n useAsTitle: \"from\",\n defaultColumns: [\"from\", \"to\", \"statusCode\", \"origin\", \"enabled\", \"updatedAt\"],\n listSearchableFields: [\"from\", \"to\"],\n ...overrides.admin,\n },\n defaultSort: overrides.defaultSort ?? \"from\",\n fields,\n hooks: {\n ...existingHooks,\n beforeOperation: [\n ...(existingHooks.beforeOperation ?? []),\n createRedirectGraphLockBeforeOperation(),\n ],\n beforeChange: [\n ...(existingHooks.beforeChange ?? []),\n createRedirectOriginBeforeChange(),\n createDuplicateBeforeChange(slug),\n ],\n },\n };\n};\n"]}
@@ -1,5 +1,4 @@
1
1
  import { ValidationError } from "payload";
2
- import { lockRedirectRuleGraph } from "./graph-lock.js";
3
2
  import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, validateDestinationForStatus, } from "../model/status-code.js";
4
3
  import { normalizeRedirectSourcePath, normalizeRelativeRedirectPath, } from "../normalize-path.js";
5
4
  import { findRedirectByFrom } from "../queries.js";
@@ -162,9 +161,6 @@ export const effectiveRuleData = (operation, data, originalDoc) => {
162
161
  export const createDuplicateBeforeChange = (collectionSlug = "redirects") => {
163
162
  return async (args) => {
164
163
  const { data, req, operation, originalDoc } = args;
165
- if (operation === "create" || operation === "update") {
166
- await lockRedirectRuleGraph(req);
167
- }
168
164
  const effective = effectiveRuleData(operation, data, originalDoc);
169
165
  if (effective && (operation === "create" || operation === "update")) {
170
166
  normalizeRulePaths(effective);
@@ -1 +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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AC;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
+ {"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,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,GA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I,CAAC;IACd,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import type { CollectionBeforeChangeHook, PayloadRequest } from \"payload\";\nimport { ValidationError } from \"payload\";\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 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,7 +1,6 @@
1
1
  import { DEFAULT_REDIRECT_ORIGIN, isRedirectOrigin, REDIRECT_ORIGIN_VALUES, } from "../model/origin.js";
2
2
  import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, validateDestinationForStatus, } from "../model/status-code.js";
3
3
  import { normalizeRedirectSourcePath, normalizeRelativeRedirectPath } from "../normalize-path.js";
4
- const publicFieldRead = { read: () => true };
5
4
  const normalizeSiblingFrom = (value) => {
6
5
  if (typeof value !== "string")
7
6
  return undefined;
@@ -18,7 +17,6 @@ export const buildRedirectFields = () => [
18
17
  type: "text",
19
18
  required: true,
20
19
  unique: true,
21
- access: publicFieldRead,
22
20
  validate: (value) => {
23
21
  if (typeof value !== "string")
24
22
  return "from is required";
@@ -37,7 +35,6 @@ export const buildRedirectFields = () => [
37
35
  name: "to",
38
36
  type: "text",
39
37
  required: true,
40
- access: publicFieldRead,
41
38
  validate: (value, { siblingData }) => {
42
39
  try {
43
40
  const statusCode = assertRedirectStatusCode(siblingData?.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE);
@@ -59,7 +56,6 @@ export const buildRedirectFields = () => [
59
56
  label: "Type",
60
57
  defaultValue: String(DEFAULT_REDIRECT_STATUS_CODE),
61
58
  required: true,
62
- access: publicFieldRead,
63
59
  options: [
64
60
  { label: "Permanent", value: "301" },
65
61
  { label: "Temporary", value: "302" },
@@ -80,7 +76,6 @@ export const buildRedirectFields = () => [
80
76
  type: "checkbox",
81
77
  defaultValue: true,
82
78
  index: true,
83
- access: publicFieldRead,
84
79
  admin: { position: "sidebar" },
85
80
  },
86
81
  {
@@ -88,7 +83,6 @@ export const buildRedirectFields = () => [
88
83
  type: "select",
89
84
  required: true,
90
85
  defaultValue: DEFAULT_REDIRECT_ORIGIN,
91
- access: publicFieldRead,
92
86
  options: [
93
87
  { label: "Manual", value: "manual" },
94
88
  { label: "Auto", value: "auto" },