@klnap/payload-redirect 0.3.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.
- package/CHANGELOG.md +6 -0
- package/README.md +41 -40
- package/dist/core/redirects/auto/create-redirect.d.ts +3 -3
- package/dist/core/redirects/auto/create-redirect.js +6 -5
- package/dist/core/redirects/auto/create-redirect.js.map +1 -0
- package/dist/core/redirects/auto/match-existing-rule.d.ts +1 -1
- package/dist/core/redirects/auto/match-existing-rule.js +3 -2
- package/dist/core/redirects/auto/match-existing-rule.js.map +1 -0
- package/dist/core/redirects/auto/persist-auto-rule.d.ts +2 -2
- package/dist/core/redirects/auto/persist-auto-rule.js +12 -11
- package/dist/core/redirects/auto/persist-auto-rule.js.map +1 -0
- package/dist/core/redirects/auto/publication/get-publication-transition.d.ts +2 -2
- package/dist/core/redirects/auto/publication/get-publication-transition.js +7 -6
- package/dist/core/redirects/auto/publication/get-publication-transition.js.map +1 -0
- package/dist/core/redirects/auto/publication/locales.d.ts +1 -1
- package/dist/core/redirects/auto/publication/locales.js +14 -13
- package/dist/core/redirects/auto/publication/locales.js.map +1 -0
- package/dist/core/redirects/auto/publication/publish-intent.d.ts +1 -1
- package/dist/core/redirects/auto/publication/publish-intent.js +5 -4
- package/dist/core/redirects/auto/publication/publish-intent.js.map +1 -0
- package/dist/core/redirects/auto/publication/versions/document-locale.d.ts +1 -1
- package/dist/core/redirects/auto/publication/versions/document-locale.js +1 -0
- package/dist/core/redirects/auto/publication/versions/document-locale.js.map +1 -0
- package/dist/core/redirects/auto/publication/versions/version-pages.d.ts +2 -2
- package/dist/core/redirects/auto/publication/versions/version-pages.js +3 -2
- package/dist/core/redirects/auto/publication/versions/version-pages.js.map +1 -0
- package/dist/core/redirects/auto/publication/versions/version-rows.js +5 -4
- package/dist/core/redirects/auto/publication/versions/version-rows.js.map +1 -0
- package/dist/core/redirects/auto/types.d.ts +1 -1
- package/dist/core/redirects/auto/types.js +1 -0
- package/dist/core/redirects/auto/types.js.map +1 -0
- package/dist/core/redirects/collection/access.d.ts +1 -1
- package/dist/core/redirects/collection/access.js +3 -2
- package/dist/core/redirects/collection/access.js.map +1 -0
- package/dist/core/redirects/collection/collection.d.ts +2 -2
- package/dist/core/redirects/collection/collection.js +10 -9
- package/dist/core/redirects/collection/collection.js.map +1 -0
- package/dist/core/redirects/collection/duplicate-guard.d.ts +1 -1
- package/dist/core/redirects/collection/duplicate-guard.js +34 -33
- package/dist/core/redirects/collection/duplicate-guard.js.map +1 -0
- package/dist/core/redirects/collection/fields.d.ts +1 -1
- package/dist/core/redirects/collection/fields.js +51 -50
- package/dist/core/redirects/collection/fields.js.map +1 -0
- package/dist/core/redirects/collection/graph-lock.d.ts +1 -1
- package/dist/core/redirects/collection/graph-lock.js +8 -7
- package/dist/core/redirects/collection/graph-lock.js.map +1 -0
- package/dist/core/redirects/collection/origin-hook.d.ts +1 -1
- package/dist/core/redirects/collection/origin-hook.js +6 -5
- package/dist/core/redirects/collection/origin-hook.js.map +1 -0
- package/dist/core/redirects/collection/types.d.ts +2 -2
- package/dist/core/redirects/collection/types.js +1 -0
- package/dist/core/redirects/collection/types.js.map +1 -0
- package/dist/core/redirects/context-keys.d.ts +2 -2
- package/dist/core/redirects/context-keys.js +3 -2
- package/dist/core/redirects/context-keys.js.map +1 -0
- package/dist/core/redirects/model/errors.js +2 -1
- package/dist/core/redirects/model/errors.js.map +1 -0
- package/dist/core/redirects/model/origin.d.ts +1 -1
- package/dist/core/redirects/model/origin.js +4 -3
- package/dist/core/redirects/model/origin.js.map +1 -0
- package/dist/core/redirects/model/status-code.js +5 -4
- package/dist/core/redirects/model/status-code.js.map +1 -0
- package/dist/core/redirects/normalize-path.js +23 -22
- package/dist/core/redirects/normalize-path.js.map +1 -0
- package/dist/core/redirects/queries.d.ts +2 -2
- package/dist/core/redirects/queries.js +1 -0
- package/dist/core/redirects/queries.js.map +1 -0
- package/dist/core/url/published-path.js +20 -19
- package/dist/core/url/published-path.js.map +1 -0
- package/dist/core/url/route-params.js +9 -8
- package/dist/core/url/route-params.js.map +1 -0
- package/dist/exports/index.d.ts +4 -4
- package/dist/exports/index.js +2 -1
- package/dist/exports/index.js.map +1 -0
- package/dist/plugin/payload-plugin.d.ts +2 -2
- package/dist/plugin/payload-plugin.js +22 -21
- package/dist/plugin/payload-plugin.js.map +1 -0
- package/dist/plugin/types.d.ts +4 -4
- package/dist/plugin/types.js +1 -0
- package/dist/plugin/types.js.map +1 -0
- package/docs/FAILURE_SEMANTICS.md +28 -28
- package/package.json +21 -13
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -16,22 +16,23 @@ The plugin owns its Payload collection, so manual redirects need no collection s
|
|
|
16
16
|
bun add @klnap/payload-redirect
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
Requires Payload `>=3.94.1 <4`.
|
|
19
|
+
Requires Node.js `^22.23.5 || ^24.22.3 || >=26.13.1` and Payload `>=3.94.1 <4`.
|
|
20
|
+
PostgreSQL is the supported database adapter.
|
|
20
21
|
|
|
21
22
|
## Manual redirects
|
|
22
23
|
|
|
23
24
|
Register the plugin with no options:
|
|
24
25
|
|
|
25
26
|
```ts
|
|
26
|
-
import { buildConfig } from
|
|
27
|
-
import { postgresAdapter } from
|
|
28
|
-
import { redirects } from
|
|
27
|
+
import { buildConfig } from "payload";
|
|
28
|
+
import { postgresAdapter } from "@payloadcms/db-postgres";
|
|
29
|
+
import { redirects } from "@klnap/payload-redirect";
|
|
29
30
|
|
|
30
31
|
export default buildConfig({
|
|
31
32
|
secret: process.env.PAYLOAD_SECRET!,
|
|
32
33
|
db: postgresAdapter({ pool: { connectionString: process.env.DATABASE_URI! } }),
|
|
33
34
|
plugins: [redirects()],
|
|
34
|
-
})
|
|
35
|
+
});
|
|
35
36
|
```
|
|
36
37
|
|
|
37
38
|
The plugin adds the `redirects` collection. Add, edit, enable, or disable rules in Payload Admin. Manual rules work without automatic redirect configuration.
|
|
@@ -41,52 +42,52 @@ The plugin adds the `redirects` collection. Add, edit, enable, or disable rules
|
|
|
41
42
|
Automatic generation is enabled for each collection configured in `redirects({ collections })`. Those collections must use Payload drafts so the plugin can compare published snapshots.
|
|
42
43
|
|
|
43
44
|
```ts
|
|
44
|
-
import { buildConfig } from
|
|
45
|
-
import { postgresAdapter } from
|
|
46
|
-
import { redirects } from
|
|
45
|
+
import { buildConfig } from "payload";
|
|
46
|
+
import { postgresAdapter } from "@payloadcms/db-postgres";
|
|
47
|
+
import { redirects } from "@klnap/payload-redirect";
|
|
47
48
|
|
|
48
49
|
export default buildConfig({
|
|
49
50
|
secret: process.env.PAYLOAD_SECRET!,
|
|
50
51
|
db: postgresAdapter({ pool: { connectionString: process.env.DATABASE_URI! } }),
|
|
51
52
|
localization: {
|
|
52
|
-
locales: [
|
|
53
|
-
defaultLocale:
|
|
53
|
+
locales: ["pl", "en", "de"],
|
|
54
|
+
defaultLocale: "pl",
|
|
54
55
|
},
|
|
55
56
|
collections: [
|
|
56
57
|
{
|
|
57
|
-
slug:
|
|
58
|
+
slug: "articles",
|
|
58
59
|
versions: { drafts: true },
|
|
59
60
|
fields: [
|
|
60
|
-
{ name:
|
|
61
|
-
{ name:
|
|
61
|
+
{ name: "title", type: "text", required: true },
|
|
62
|
+
{ name: "slug", type: "text", required: true, localized: true },
|
|
62
63
|
],
|
|
63
64
|
},
|
|
64
65
|
{
|
|
65
|
-
slug:
|
|
66
|
+
slug: "projects",
|
|
66
67
|
versions: { drafts: true },
|
|
67
|
-
fields: [{ name:
|
|
68
|
+
fields: [{ name: "slug", type: "text", required: true, localized: true }],
|
|
68
69
|
},
|
|
69
70
|
],
|
|
70
71
|
plugins: [
|
|
71
72
|
redirects({
|
|
72
73
|
localePrefixes: {
|
|
73
|
-
pl:
|
|
74
|
-
en:
|
|
75
|
-
de:
|
|
74
|
+
pl: "",
|
|
75
|
+
en: "/en",
|
|
76
|
+
de: "/de",
|
|
76
77
|
},
|
|
77
78
|
collections: {
|
|
78
|
-
articles: { path:
|
|
79
|
+
articles: { path: "/[slug]" },
|
|
79
80
|
projects: {
|
|
80
81
|
paths: {
|
|
81
|
-
pl:
|
|
82
|
-
en:
|
|
83
|
-
de:
|
|
82
|
+
pl: "/realizacje/[slug]",
|
|
83
|
+
en: "/work/[slug]",
|
|
84
|
+
de: "/projekte/[slug]",
|
|
84
85
|
},
|
|
85
86
|
},
|
|
86
87
|
},
|
|
87
88
|
}),
|
|
88
89
|
],
|
|
89
|
-
})
|
|
90
|
+
});
|
|
90
91
|
```
|
|
91
92
|
|
|
92
93
|
### Reading the configuration
|
|
@@ -112,25 +113,25 @@ The plugin tracks the resolved public URL, not a particular slug field. A change
|
|
|
112
113
|
Use the same options directly on a collection when central configuration is not convenient:
|
|
113
114
|
|
|
114
115
|
```ts
|
|
115
|
-
import type { CollectionConfig } from
|
|
116
|
-
import type { RedirectCollectionOptions } from
|
|
116
|
+
import type { CollectionConfig } from "payload";
|
|
117
|
+
import type { RedirectCollectionOptions } from "@klnap/payload-redirect";
|
|
117
118
|
|
|
118
119
|
const projectRedirect = {
|
|
119
120
|
paths: {
|
|
120
|
-
pl:
|
|
121
|
-
en:
|
|
122
|
-
de:
|
|
121
|
+
pl: "/realizacje/[slug]",
|
|
122
|
+
en: "/work/[slug]",
|
|
123
|
+
de: "/projekte/[slug]",
|
|
123
124
|
},
|
|
124
|
-
} satisfies RedirectCollectionOptions<
|
|
125
|
+
} satisfies RedirectCollectionOptions<"projects">;
|
|
125
126
|
|
|
126
127
|
export const Projects: CollectionConfig = {
|
|
127
|
-
slug:
|
|
128
|
+
slug: "projects",
|
|
128
129
|
versions: { drafts: true },
|
|
129
130
|
custom: {
|
|
130
131
|
redirect: projectRedirect,
|
|
131
132
|
},
|
|
132
|
-
fields: [{ name:
|
|
133
|
-
}
|
|
133
|
+
fields: [{ name: "slug", type: "text", required: true, localized: true }],
|
|
134
|
+
};
|
|
134
135
|
```
|
|
135
136
|
|
|
136
137
|
Central configuration replaces collection-level configuration for that collection. The plugin does not merge path strategies.
|
|
@@ -147,7 +148,7 @@ Use `path` when every locale has the same route shape:
|
|
|
147
148
|
|
|
148
149
|
```ts
|
|
149
150
|
articles: {
|
|
150
|
-
path:
|
|
151
|
+
path: "/articles/[slug]";
|
|
151
152
|
}
|
|
152
153
|
```
|
|
153
154
|
|
|
@@ -155,7 +156,7 @@ Templates use top-level field names in brackets. Use multiple fields when the pu
|
|
|
155
156
|
|
|
156
157
|
```ts
|
|
157
158
|
projects: {
|
|
158
|
-
path:
|
|
159
|
+
path: "/[category]/[slug]";
|
|
159
160
|
}
|
|
160
161
|
```
|
|
161
162
|
|
|
@@ -217,12 +218,12 @@ Pass native Payload collection options through `overrides`:
|
|
|
217
218
|
```ts
|
|
218
219
|
redirects({
|
|
219
220
|
overrides: {
|
|
220
|
-
slug:
|
|
221
|
-
labels: { singular:
|
|
222
|
-
admin: { group:
|
|
221
|
+
slug: "url-rules",
|
|
222
|
+
labels: { singular: "URL rule", plural: "URL rules" },
|
|
223
|
+
admin: { group: "Settings" },
|
|
223
224
|
trash: true,
|
|
224
225
|
},
|
|
225
|
-
})
|
|
226
|
+
});
|
|
226
227
|
```
|
|
227
228
|
|
|
228
229
|
Use `overrides.fields` to customize the plugin fields. Required fields, validation, uniqueness, and indexes remain enforced.
|
|
@@ -244,10 +245,10 @@ The package stores rules. Your application retrieves enabled rules, caches them,
|
|
|
244
245
|
|
|
245
246
|
```ts
|
|
246
247
|
const { docs } = await payload.find({
|
|
247
|
-
collection:
|
|
248
|
+
collection: "redirects",
|
|
248
249
|
where: { enabled: { equals: true } },
|
|
249
250
|
depth: 0,
|
|
250
|
-
})
|
|
251
|
+
});
|
|
251
252
|
|
|
252
253
|
// Match the incoming path and return the selected rule's statusCode and to.
|
|
253
254
|
```
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { CollectionAfterChangeHook } from
|
|
2
|
-
import { type LocalePrefixes } from
|
|
3
|
-
import type { RedirectPathOptions } from
|
|
1
|
+
import type { CollectionAfterChangeHook } from "payload";
|
|
2
|
+
import { type LocalePrefixes } from "../../url/published-path.js";
|
|
3
|
+
import type { RedirectPathOptions } from "./types.js";
|
|
4
4
|
type CreateRedirectOptions = {
|
|
5
5
|
collectionSlug: string;
|
|
6
6
|
pathOptions: RedirectPathOptions;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { ensureAutoRedirect } from
|
|
2
|
-
import { getPublicationTransition } from
|
|
3
|
-
import { REDIRECT_CONTEXT_KEYS } from
|
|
4
|
-
import { normalizePathOrUrl } from
|
|
5
|
-
import { buildPublishedPath } from
|
|
1
|
+
import { ensureAutoRedirect } from "./persist-auto-rule.js";
|
|
2
|
+
import { getPublicationTransition } from "./publication/get-publication-transition.js";
|
|
3
|
+
import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
|
|
4
|
+
import { normalizePathOrUrl } from "../normalize-path.js";
|
|
5
|
+
import { buildPublishedPath } from "../../url/published-path.js";
|
|
6
6
|
export const createRedirect = ({ collectionSlug, pathOptions, localePrefixes, }) => async (args) => {
|
|
7
7
|
if (pathOptions.enabled === false)
|
|
8
8
|
return args.doc;
|
|
@@ -35,3 +35,4 @@ export const createRedirect = ({ collectionSlug, pathOptions, localePrefixes, })
|
|
|
35
35
|
}
|
|
36
36
|
return args.doc;
|
|
37
37
|
};
|
|
38
|
+
//# sourceMappingURL=create-redirect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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,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B,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,7 +1,8 @@
|
|
|
1
|
-
import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, } from
|
|
1
|
+
import { assertRedirectStatusCode, DEFAULT_REDIRECT_STATUS_CODE, } from "../model/status-code.js";
|
|
2
2
|
export const isIdenticalAutoRule = (doc, rule) => doc.from === rule.from &&
|
|
3
3
|
doc.to === rule.to &&
|
|
4
4
|
assertRedirectStatusCode(doc.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE) ===
|
|
5
5
|
DEFAULT_REDIRECT_STATUS_CODE &&
|
|
6
6
|
doc.enabled !== false &&
|
|
7
|
-
doc.origin ===
|
|
7
|
+
doc.origin === "auto";
|
|
8
|
+
//# sourceMappingURL=match-existing-rule.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match-existing-rule.js","sourceRoot":"","sources":["../../../../src/core/redirects/auto/match-existing-rule.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,4BAA4B,GAC7B,MAAM,4CAA4C,CAAC;AAGpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CACjC,GAAsB,EACtB,IAAkC,EACzB,EAAE,CACX,GAAG,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;IACtB,GAAG,CAAC,EAAE,KAAK,IAAI,CAAC,EAAE;IAClB,wBAAwB,CAAC,GAAG,CAAC,UAAU,IAAI,4BAA4B,CAAC;QACtE,4BAA4B;IAC9B,GAAG,CAAC,OAAO,KAAK,KAAK;IACrB,GAAG,CAAC,MAAM,KAAK,MAAM,CAAC","sourcesContent":["import {\n assertRedirectStatusCode,\n DEFAULT_REDIRECT_STATUS_CODE,\n} from \"#redirect/core/redirects/model/status-code\";\nimport type { RedirectLookupDoc } from \"#redirect/core/redirects/queries\";\n\nexport const isIdenticalAutoRule = (\n doc: RedirectLookupDoc,\n rule: { from: string; to: string },\n): boolean =>\n doc.from === rule.from &&\n doc.to === rule.to &&\n assertRedirectStatusCode(doc.statusCode ?? DEFAULT_REDIRECT_STATUS_CODE) ===\n DEFAULT_REDIRECT_STATUS_CODE &&\n doc.enabled !== false &&\n doc.origin === \"auto\";\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PayloadRequest } from
|
|
1
|
+
import type { PayloadRequest } from "payload";
|
|
2
2
|
type AutoRedirectRule = {
|
|
3
3
|
from: string;
|
|
4
4
|
to: string;
|
|
@@ -12,5 +12,5 @@ type EnsureAutoRedirectArgs = {
|
|
|
12
12
|
/**
|
|
13
13
|
* Idempotent create for auto 301 rules. One lookup by unique `from`.
|
|
14
14
|
*/
|
|
15
|
-
export declare const ensureAutoRedirect: ({ req, collectionSlug, rule, context, }: EnsureAutoRedirectArgs) => Promise<
|
|
15
|
+
export declare const ensureAutoRedirect: ({ req, collectionSlug, rule, context, }: EnsureAutoRedirectArgs) => Promise<"created" | "skipped" | "updated">;
|
|
16
16
|
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isIdenticalAutoRule } from
|
|
2
|
-
import { REDIRECT_CONTEXT_KEYS } from
|
|
3
|
-
import { findRedirectByFrom } from
|
|
1
|
+
import { isIdenticalAutoRule } from "./match-existing-rule.js";
|
|
2
|
+
import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
|
|
3
|
+
import { findRedirectByFrom } from "../queries.js";
|
|
4
4
|
/**
|
|
5
5
|
* Idempotent create for auto 301 rules. One lookup by unique `from`.
|
|
6
6
|
*/
|
|
@@ -13,9 +13,9 @@ export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }
|
|
|
13
13
|
const data = {
|
|
14
14
|
from: rule.from,
|
|
15
15
|
to: rule.to,
|
|
16
|
-
statusCode:
|
|
16
|
+
statusCode: "301",
|
|
17
17
|
enabled: true,
|
|
18
|
-
origin:
|
|
18
|
+
origin: "auto",
|
|
19
19
|
};
|
|
20
20
|
const payload = req.payload;
|
|
21
21
|
const existing = await findRedirectByFrom(req.payload, {
|
|
@@ -28,24 +28,24 @@ export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }
|
|
|
28
28
|
const doc = existing.docs[0];
|
|
29
29
|
if (doc) {
|
|
30
30
|
if (isIdenticalAutoRule(doc, rule)) {
|
|
31
|
-
return
|
|
31
|
+
return "skipped";
|
|
32
32
|
}
|
|
33
|
-
if (doc.origin ===
|
|
33
|
+
if (doc.origin === "auto") {
|
|
34
34
|
await payload.update({
|
|
35
35
|
collection: collectionSlug,
|
|
36
36
|
id: doc.id,
|
|
37
37
|
data: {
|
|
38
38
|
to: rule.to,
|
|
39
|
-
statusCode:
|
|
39
|
+
statusCode: "301",
|
|
40
40
|
enabled: true,
|
|
41
41
|
},
|
|
42
42
|
context: internalContext,
|
|
43
43
|
overrideAccess: false,
|
|
44
44
|
req,
|
|
45
45
|
});
|
|
46
|
-
return
|
|
46
|
+
return "updated";
|
|
47
47
|
}
|
|
48
|
-
return
|
|
48
|
+
return "skipped";
|
|
49
49
|
}
|
|
50
50
|
await payload.create({
|
|
51
51
|
collection: collectionSlug,
|
|
@@ -54,5 +54,6 @@ export const ensureAutoRedirect = async ({ req, collectionSlug, rule, context, }
|
|
|
54
54
|
overrideAccess: false,
|
|
55
55
|
req,
|
|
56
56
|
});
|
|
57
|
-
return
|
|
57
|
+
return "created";
|
|
58
58
|
};
|
|
59
|
+
//# sourceMappingURL=persist-auto-rule.js.map
|
|
@@ -0,0 +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,CA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,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,3 +1,3 @@
|
|
|
1
|
-
import type { CollectionAfterChangeHook } from
|
|
2
|
-
import type { PublicationTransition } from
|
|
1
|
+
import type { CollectionAfterChangeHook } from "payload";
|
|
2
|
+
import type { PublicationTransition } from "../types.js";
|
|
3
3
|
export declare const getPublicationTransition: (args: Parameters<CollectionAfterChangeHook>[0]) => Promise<PublicationTransition[]>;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { REDIRECT_CONTEXT_KEYS } from
|
|
2
|
-
import { getRequestLocales, hasLocalizedDraftStatus, resolveDefaultLocale } from
|
|
3
|
-
import { isDraftSave, isLocalePublished } from
|
|
4
|
-
import { fetchLocalePublishedDoc } from
|
|
5
|
-
import { fetchPublishedVersionPages } from
|
|
1
|
+
import { REDIRECT_CONTEXT_KEYS } from "../../context-keys.js";
|
|
2
|
+
import { getRequestLocales, hasLocalizedDraftStatus, resolveDefaultLocale } from "./locales.js";
|
|
3
|
+
import { isDraftSave, isLocalePublished } from "./publish-intent.js";
|
|
4
|
+
import { fetchLocalePublishedDoc } from "./versions/document-locale.js";
|
|
5
|
+
import { fetchPublishedVersionPages } from "./versions/version-pages.js";
|
|
6
6
|
export const getPublicationTransition = async (args) => {
|
|
7
7
|
const { req, doc, collection } = args;
|
|
8
8
|
if (!collection.versions?.drafts)
|
|
@@ -16,7 +16,7 @@ export const getPublicationTransition = async (args) => {
|
|
|
16
16
|
const transitions = [];
|
|
17
17
|
for (const locale of locales) {
|
|
18
18
|
const currentDoc = await fetchLocalePublishedDoc({ req, collection, docId, locale });
|
|
19
|
-
if (!currentDoc || !isLocalePublished(currentDoc._status, locale ??
|
|
19
|
+
if (!currentDoc || !isLocalePublished(currentDoc._status, locale ?? ""))
|
|
20
20
|
continue;
|
|
21
21
|
const publishedDocs = (await fetchPublishedVersionPages({
|
|
22
22
|
req,
|
|
@@ -31,3 +31,4 @@ export const getPublicationTransition = async (args) => {
|
|
|
31
31
|
}
|
|
32
32
|
return transitions;
|
|
33
33
|
};
|
|
34
|
+
//# sourceMappingURL=get-publication-transition.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-publication-transition.js","sourceRoot":"","sources":["../../../../../src/core/redirects/auto/publication/get-publication-transition.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,OAAO,EAAE,iBAAiB,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAChG,OAAO,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACrE,OAAO,EAAE,uBAAuB,EAAE,MAAM,+BAA+B,CAAC;AACxE,OAAO,EAAE,0BAA0B,EAAE,MAAM,6BAA6B,CAAC;AAEzE,MAAM,CAAC,MAAM,wBAAwB,GAAG,KAAK,EAC3C,IAA8C,EACZ,EAAE;IACpC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,GAAG,IAAI,CAAC;IACtC,IAAI,CAAC,UAAU,CAAC,QAAQ,EAAE,MAAM;QAAE,OAAO,EAAE,CAAC;IAC5C,IAAI,WAAW,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,OAAO,EAAE,CAAC,qBAAqB,CAAC,QAAQ,CAAC;QAAE,OAAO,EAAE,CAAC;IAEjF,MAAM,KAAK,GAAG,GAAG,CAAC,EAAE,CAAC;IACrB,MAAM,OAAO,GAAG,iBAAiB,CAAC,GAAG,EAAG,GAA+B,CAAC,OAAO,CAAC,CAAC;IACjF,MAAM,cAAc,GAAG,uBAAuB,CAAC,UAAU,CAAC,CAAC;IAC3D,MAAM,aAAa,GAAG,oBAAoB,CAAC,GAAG,CAAC,CAAC;IAChD,MAAM,WAAW,GAA4B,EAAE,CAAC;IAEhD,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,MAAM,UAAU,GAAG,MAAM,uBAAuB,CAAC,EAAE,GAAG,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,CAAC;QACrF,IAAI,CAAC,UAAU,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,OAAO,EAAE,MAAM,IAAI,EAAE,CAAC;YAAE,SAAS;QAElF,MAAM,aAAa,GAAG,CACpB,MAAM,0BAA0B,CAAC;YAC/B,GAAG;YACH,cAAc,EAAE,UAAU,CAAC,IAAI;YAC/B,KAAK;YACL,MAAM;YACN,aAAa,EAAE,EAAE,cAAc,EAAE,aAAa,EAAE;SACjD,CAAC,CACH;aACE,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,CAAC,OAAO,CAAC;aACzB,MAAM,CAAC,CAAC,OAAO,EAAsC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;QAE7E,WAAW,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,CAAC,CAAC;IAC1D,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC,CAAC","sourcesContent":["import type { CollectionAfterChangeHook } from \"payload\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\nimport type { PublicationTransition } from \"../types.js\";\nimport { getRequestLocales, hasLocalizedDraftStatus, resolveDefaultLocale } from \"./locales.js\";\nimport { isDraftSave, isLocalePublished } from \"./publish-intent.js\";\nimport { fetchLocalePublishedDoc } from \"./versions/document-locale.js\";\nimport { fetchPublishedVersionPages } from \"./versions/version-pages.js\";\n\nexport const getPublicationTransition = async (\n args: Parameters<CollectionAfterChangeHook>[0],\n): Promise<PublicationTransition[]> => {\n const { req, doc, collection } = args;\n if (!collection.versions?.drafts) return [];\n if (isDraftSave(req) || req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto]) return [];\n\n const docId = doc.id;\n const locales = getRequestLocales(req, (doc as Record<string, unknown>)._status);\n const localizeStatus = hasLocalizedDraftStatus(collection);\n const defaultLocale = resolveDefaultLocale(req);\n const transitions: PublicationTransition[] = [];\n\n for (const locale of locales) {\n const currentDoc = await fetchLocalePublishedDoc({ req, collection, docId, locale });\n if (!currentDoc || !isLocalePublished(currentDoc._status, locale ?? \"\")) continue;\n\n const publishedDocs = (\n await fetchPublishedVersionPages({\n req,\n collectionSlug: collection.slug,\n docId,\n locale,\n versionFilter: { localizeStatus, defaultLocale },\n })\n )\n .map((row) => row.version)\n .filter((version): version is Record<string, unknown> => Boolean(version));\n\n transitions.push({ locale, currentDoc, publishedDocs });\n }\n\n return transitions;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { PayloadRequest } from
|
|
1
|
+
import type { PayloadRequest } from "payload";
|
|
2
2
|
export declare const getRequestLocales: (req: PayloadRequest, status: unknown) => Array<string | undefined>;
|
|
3
3
|
export declare const hasLocalizedDraftStatus: (collection: {
|
|
4
4
|
versions?: {
|
|
@@ -2,41 +2,42 @@ const listLocales = (req) => {
|
|
|
2
2
|
const localization = req.payload.config.localization;
|
|
3
3
|
if (localization === false || !localization)
|
|
4
4
|
return [];
|
|
5
|
-
return localization.locales.map((locale) => (typeof locale ===
|
|
5
|
+
return localization.locales.map((locale) => (typeof locale === "string" ? locale : locale.code));
|
|
6
6
|
};
|
|
7
7
|
export const getRequestLocales = (req, status) => {
|
|
8
8
|
const localization = listLocales(req);
|
|
9
9
|
if (localization.length === 0)
|
|
10
10
|
return [undefined];
|
|
11
|
-
const specificLocale = typeof req.query?.publishSpecificLocale ===
|
|
11
|
+
const specificLocale = typeof req.query?.publishSpecificLocale === "string"
|
|
12
12
|
? req.query.publishSpecificLocale
|
|
13
13
|
: undefined;
|
|
14
|
-
if (specificLocale && specificLocale !==
|
|
14
|
+
if (specificLocale && specificLocale !== "all")
|
|
15
15
|
return [specificLocale];
|
|
16
|
-
if (specificLocale ===
|
|
17
|
-
req.query?.publishAllLocales ===
|
|
16
|
+
if (specificLocale === "all" ||
|
|
17
|
+
req.query?.publishAllLocales === "true" ||
|
|
18
18
|
req.query?.publishAllLocales === true) {
|
|
19
19
|
return localization;
|
|
20
20
|
}
|
|
21
|
-
const requestedLocale = typeof req.query?.locale ===
|
|
22
|
-
if (requestedLocale && requestedLocale !==
|
|
21
|
+
const requestedLocale = typeof req.query?.locale === "string" ? req.query.locale : undefined;
|
|
22
|
+
if (requestedLocale && requestedLocale !== "all")
|
|
23
23
|
return [requestedLocale];
|
|
24
|
-
if (requestedLocale ===
|
|
24
|
+
if (requestedLocale === "all")
|
|
25
25
|
return localization;
|
|
26
|
-
if (status && typeof status ===
|
|
26
|
+
if (status && typeof status === "object" && !Array.isArray(status)) {
|
|
27
27
|
return Object.entries(status)
|
|
28
|
-
.filter(([, value]) => value ===
|
|
28
|
+
.filter(([, value]) => value === "published")
|
|
29
29
|
.map(([locale]) => locale);
|
|
30
30
|
}
|
|
31
|
-
if (typeof req.locale ===
|
|
31
|
+
if (typeof req.locale === "string")
|
|
32
32
|
return [req.locale];
|
|
33
|
-
return status ===
|
|
33
|
+
return status === "published" ? localization : [];
|
|
34
34
|
};
|
|
35
35
|
export const hasLocalizedDraftStatus = (collection) => {
|
|
36
36
|
const drafts = collection.versions === false ? undefined : collection.versions?.drafts;
|
|
37
|
-
return Boolean(drafts && typeof drafts ===
|
|
37
|
+
return Boolean(drafts && typeof drafts === "object" && "localizeStatus" in drafts && drafts.localizeStatus);
|
|
38
38
|
};
|
|
39
39
|
export const resolveDefaultLocale = (req) => {
|
|
40
40
|
const localization = req.payload.config.localization;
|
|
41
41
|
return localization ? localization.defaultLocale : undefined;
|
|
42
42
|
};
|
|
43
|
+
//# sourceMappingURL=locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../../../src/core/redirects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esContent":["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,7 +1,8 @@
|
|
|
1
|
-
export const isDraftSave = (req) => req.query?.draft ===
|
|
1
|
+
export const isDraftSave = (req) => req.query?.draft === "true" || req.query?.draft === true;
|
|
2
2
|
export const isLocalePublished = (status, locale) => {
|
|
3
|
-
if (typeof status ===
|
|
4
|
-
return status[locale] ===
|
|
3
|
+
if (typeof status === "object" && status !== null) {
|
|
4
|
+
return status[locale] === "published";
|
|
5
5
|
}
|
|
6
|
-
return status ===
|
|
6
|
+
return status === "published";
|
|
7
7
|
};
|
|
8
|
+
//# sourceMappingURL=publish-intent.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publish-intent.js","sourceRoot":"","sources":["../../../../../src/core/redirects/auto/publication/publish-intent.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,GAAmB,EAAW,EAAE,CAC1D,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAE3D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,MAAe,EAAE,MAAc,EAAW,EAAE;IAC5E,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QAClD,OAAQ,MAAkC,CAAC,MAAM,CAAC,KAAK,WAAW,CAAC;IACrE,CAAC;IACD,OAAO,MAAM,KAAK,WAAW,CAAC;AAChC,CAAC,CAAC","sourcesContent":["import type { PayloadRequest } from \"payload\";\n\nexport const isDraftSave = (req: PayloadRequest): boolean =>\n req.query?.draft === \"true\" || req.query?.draft === true;\n\nexport const isLocalePublished = (status: unknown, locale: string): boolean => {\n if (typeof status === \"object\" && status !== null) {\n return (status as Record<string, unknown>)[locale] === \"published\";\n }\n return status === \"published\";\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionConfig, PayloadRequest } from
|
|
1
|
+
import type { CollectionConfig, PayloadRequest } from "payload";
|
|
2
2
|
export declare const fetchLocalePublishedDoc: ({ req, collection, docId, locale, }: {
|
|
3
3
|
req: PayloadRequest;
|
|
4
4
|
collection: CollectionConfig;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"document-locale.js","sourceRoot":"","sources":["../../../../../../src/core/redirects/auto/publication/versions/document-locale.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,uBAAuB,GAAG,KAAK,EAAE,EAC5C,GAAG,EACH,UAAU,EACV,KAAK,EACL,MAAM,GAMP,EAAoC,EAAE,CACrC,CAAC,MAAM,GAAG,CAAC,OAAO,CAAC,QAAQ,CAAC;IAC1B,UAAU,EAAE,UAAU,CAAC,IAAsB;IAC7C,EAAE,EAAE,KAAK;IACT,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;IACpD,cAAc,EAAE,KAAK;IACrB,KAAK,EAAE,CAAC;IACR,cAAc,EAAE,IAAI;IACpB,GAAG;CACJ,CAAC,CAA4B,CAAC","sourcesContent":["import type { CollectionConfig, CollectionSlug, PayloadRequest, TypedLocale } from \"payload\";\n\nexport const fetchLocalePublishedDoc = async ({\n req,\n collection,\n docId,\n locale,\n}: {\n req: PayloadRequest;\n collection: CollectionConfig;\n docId: string | number;\n locale?: string;\n}): Promise<Record<string, unknown>> =>\n (await req.payload.findByID({\n collection: collection.slug as CollectionSlug,\n id: docId,\n ...(locale ? { locale: locale as TypedLocale } : {}),\n fallbackLocale: false,\n depth: 0,\n overrideAccess: true,\n req,\n })) as Record<string, unknown>;\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { PayloadRequest } from
|
|
2
|
-
import { type VersionRow } from
|
|
1
|
+
import type { PayloadRequest } from "payload";
|
|
2
|
+
import { type VersionRow } from "./version-rows.js";
|
|
3
3
|
export declare const fetchPublishedVersionPages: ({ req, collectionSlug, docId, locale, versionFilter, }: {
|
|
4
4
|
req: PayloadRequest;
|
|
5
5
|
collectionSlug: string;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { isPublishedVersionRow } from
|
|
1
|
+
import { isPublishedVersionRow } from "./version-rows.js";
|
|
2
2
|
export const fetchPublishedVersionPages = async ({ req, collectionSlug, docId, locale, versionFilter, }) => {
|
|
3
3
|
const published = [];
|
|
4
4
|
let page = 1;
|
|
@@ -7,7 +7,7 @@ export const fetchPublishedVersionPages = async ({ req, collectionSlug, docId, l
|
|
|
7
7
|
const result = await req.payload.findVersions({
|
|
8
8
|
collection: collectionSlug,
|
|
9
9
|
where: { parent: { equals: docId } },
|
|
10
|
-
sort:
|
|
10
|
+
sort: "-updatedAt",
|
|
11
11
|
depth: 0,
|
|
12
12
|
page,
|
|
13
13
|
limit,
|
|
@@ -23,3 +23,4 @@ export const fetchPublishedVersionPages = async ({ req, collectionSlug, docId, l
|
|
|
23
23
|
}
|
|
24
24
|
return published;
|
|
25
25
|
};
|
|
26
|
+
//# sourceMappingURL=version-pages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-pages.js","sourceRoot":"","sources":["../../../../../../src/core/redirects/auto/publication/versions/version-pages.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAmB,MAAM,mBAAmB,CAAC;AAE3E,MAAM,CAAC,MAAM,0BAA0B,GAAG,KAAK,EAAE,EAC/C,GAAG,EACH,cAAc,EACd,KAAK,EACL,MAAM,EACN,aAAa,GAOd,EAAyB,EAAE;IAC1B,MAAM,SAAS,GAAiB,EAAE,CAAC;IACnC,IAAI,IAAI,GAAG,CAAC,CAAC;IACb,MAAM,KAAK,GAAG,EAAE,CAAC;IAEjB,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,OAAO,CAAC,YAAY,CAAC;YAC5C,UAAU,EAAE,cAAgC;YAC5C,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE;YACpC,IAAI,EAAE,YAAY;YAClB,KAAK,EAAE,CAAC;YACR,IAAI;YACJ,KAAK;YACL,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,MAAqB,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;YACpD,cAAc,EAAE,KAAK;YACrB,cAAc,EAAE,IAAI;YACpB,GAAG;SACJ,CAAC,CAAC;QAEH,SAAS,CAAC,IAAI,CACZ,GAAI,MAAM,CAAC,IAAqB,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,EAAE,CAC9C,qBAAqB,CAAC,GAAG,EAAE,MAAM,EAAE,aAAa,CAAC,CAClD,CACF,CAAC;QAEF,IAAI,CAAC,MAAM,CAAC,WAAW;YAAE,MAAM;QAC/B,IAAI,IAAI,CAAC,CAAC;IACZ,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC,CAAC","sourcesContent":["import type { CollectionSlug, PayloadRequest, TypedLocale } from \"payload\";\nimport { isPublishedVersionRow, type VersionRow } from \"./version-rows.js\";\n\nexport const fetchPublishedVersionPages = async ({\n req,\n collectionSlug,\n docId,\n locale,\n versionFilter,\n}: {\n req: PayloadRequest;\n collectionSlug: string;\n docId: string | number;\n locale?: string;\n versionFilter?: { localizeStatus?: boolean; defaultLocale?: string };\n}): Promise<VersionRow[]> => {\n const published: VersionRow[] = [];\n let page = 1;\n const limit = 50;\n\n while (true) {\n const result = await req.payload.findVersions({\n collection: collectionSlug as CollectionSlug,\n where: { parent: { equals: docId } },\n sort: \"-updatedAt\",\n depth: 0,\n page,\n limit,\n ...(locale ? { locale: locale as TypedLocale } : {}),\n fallbackLocale: false,\n overrideAccess: true,\n req,\n });\n\n published.push(\n ...(result.docs as VersionRow[]).filter((row) =>\n isPublishedVersionRow(row, locale, versionFilter),\n ),\n );\n\n if (!result.hasNextPage) break;\n page += 1;\n }\n\n return published;\n};\n"]}
|
|
@@ -5,13 +5,14 @@ export const isPublishedVersionRow = (row, locale, options) => {
|
|
|
5
5
|
if (publishedLocale)
|
|
6
6
|
return publishedLocale === locale;
|
|
7
7
|
const status = row.version?._status;
|
|
8
|
-
if (status ===
|
|
8
|
+
if (status === "draft")
|
|
9
9
|
return false;
|
|
10
|
-
if (status && typeof status ===
|
|
11
|
-
return locale !== undefined && status[locale] ===
|
|
10
|
+
if (status && typeof status === "object" && !Array.isArray(status)) {
|
|
11
|
+
return locale !== undefined && status[locale] === "published";
|
|
12
12
|
}
|
|
13
|
-
if (status ===
|
|
13
|
+
if (status === "published") {
|
|
14
14
|
return !options?.localizeStatus || locale !== undefined;
|
|
15
15
|
}
|
|
16
16
|
return false;
|
|
17
17
|
};
|
|
18
|
+
//# sourceMappingURL=version-rows.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"version-rows.js","sourceRoot":"","sources":["../../../../../../src/core/redirects/auto/publication/versions/version-rows.ts"],"names":[],"mappings":"AAUA,MAAM,CAAC,MAAM,qBAAqB,GAAG,CACnC,GAAe,EACf,MAA0B,EAC1B,OAA8D,EACrD,EAAE;IACX,IAAI,GAAG,CAAC,QAAQ,IAAI,GAAG,CAAC,QAAQ;QAAE,OAAO,KAAK,CAAC;IAE/C,MAAM,eAAe,GAAG,GAAG,CAAC,eAAe,IAAI,GAAG,CAAC,gBAAgB,CAAC;IACpE,IAAI,eAAe;QAAE,OAAO,eAAe,KAAK,MAAM,CAAC;IAEvD,MAAM,MAAM,GAAG,GAAG,CAAC,OAAO,EAAE,OAAO,CAAC;IACpC,IAAI,MAAM,KAAK,OAAO;QAAE,OAAO,KAAK,CAAC;IACrC,IAAI,MAAM,IAAI,OAAO,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QACnE,OAAO,MAAM,KAAK,SAAS,IAAK,MAAkC,CAAC,MAAM,CAAC,KAAK,WAAW,CAAC;IAC7F,CAAC;IACD,IAAI,MAAM,KAAK,WAAW,EAAE,CAAC;QAC3B,OAAO,CAAC,OAAO,EAAE,cAAc,IAAI,MAAM,KAAK,SAAS,CAAC;IAC1D,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["export type VersionRow = {\n id?: string | number;\n updatedAt?: string;\n snapshot?: boolean;\n autosave?: boolean;\n publishedLocale?: string;\n published_locale?: string;\n version?: Record<string, unknown>;\n};\n\nexport const isPublishedVersionRow = (\n row: VersionRow,\n locale: string | undefined,\n options?: { localizeStatus?: boolean; defaultLocale?: string },\n): boolean => {\n if (row.snapshot || row.autosave) return false;\n\n const publishedLocale = row.publishedLocale ?? row.published_locale;\n if (publishedLocale) return publishedLocale === locale;\n\n const status = row.version?._status;\n if (status === \"draft\") return false;\n if (status && typeof status === \"object\" && !Array.isArray(status)) {\n return locale !== undefined && (status as Record<string, unknown>)[locale] === \"published\";\n }\n if (status === \"published\") {\n return !options?.localizeStatus || locale !== undefined;\n }\n return false;\n};\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionSlug, DataFromCollectionSlug, TypedLocale } from
|
|
1
|
+
import type { CollectionSlug, DataFromCollectionSlug, TypedLocale } from "payload";
|
|
2
2
|
export type RedirectPathOptions<TSlug extends CollectionSlug = CollectionSlug> = {
|
|
3
3
|
enabled?: true;
|
|
4
4
|
path: string;
|
|
@@ -0,0 +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,9 +1,10 @@
|
|
|
1
|
-
import { REDIRECT_CONTEXT_KEYS } from
|
|
1
|
+
import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
|
|
2
2
|
export const isInternalRedirectWrite = (req) => Boolean(req.context?.[REDIRECT_CONTEXT_KEYS.internal]);
|
|
3
|
-
const isHumanUser = (req) => Boolean(req.user) && req.user.type !==
|
|
3
|
+
const isHumanUser = (req) => Boolean(req.user) && req.user.type !== "service";
|
|
4
4
|
export const defaultRedirectAccess = {
|
|
5
5
|
read: (() => true),
|
|
6
6
|
create: (({ req }) => isInternalRedirectWrite(req) || isHumanUser(req)),
|
|
7
7
|
update: (({ req }) => isInternalRedirectWrite(req) || isHumanUser(req)),
|
|
8
8
|
delete: (({ req }) => isHumanUser(req)),
|
|
9
9
|
};
|
|
10
|
+
//# sourceMappingURL=access.js.map
|