@klnap/payload-redirect 0.3.1 → 0.4.0
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 +13 -0
- package/README.md +350 -168
- package/dist/core/redirects/auto/create-global-redirect.d.ts +11 -0
- package/dist/core/redirects/auto/create-global-redirect.js +18 -0
- package/dist/core/redirects/auto/create-global-redirect.js.map +1 -0
- package/dist/core/redirects/auto/create-redirect.d.ts +10 -6
- package/dist/core/redirects/auto/create-redirect.js +18 -9
- package/dist/core/redirects/auto/create-redirect.js.map +1 -1
- package/dist/core/redirects/auto/persist-auto-rule.d.ts +1 -1
- package/dist/core/redirects/auto/persist-auto-rule.js +5 -5
- package/dist/core/redirects/auto/persist-auto-rule.js.map +1 -1
- package/dist/core/redirects/auto/publication/global-transition.d.ts +6 -0
- package/dist/core/redirects/auto/publication/global-transition.js +63 -0
- package/dist/core/redirects/auto/publication/global-transition.js.map +1 -0
- package/dist/core/redirects/auto/publication/locales.d.ts +1 -0
- package/dist/core/redirects/auto/publication/locales.js +4 -0
- package/dist/core/redirects/auto/publication/locales.js.map +1 -1
- package/dist/core/redirects/auto/types.d.ts +3 -3
- package/dist/core/redirects/auto/types.js.map +1 -1
- package/dist/core/redirects/collection/collection.js +0 -3
- package/dist/core/redirects/collection/collection.js.map +1 -1
- package/dist/core/redirects/collection/fields.js +0 -6
- package/dist/core/redirects/collection/fields.js.map +1 -1
- package/dist/core/redirects/collection/origin-hook.js +3 -2
- package/dist/core/redirects/collection/origin-hook.js.map +1 -1
- package/dist/core/redirects/context-keys.d.ts +1 -1
- package/dist/core/redirects/context-keys.js +1 -1
- package/dist/core/redirects/context-keys.js.map +1 -1
- package/dist/exports/index.d.ts +1 -1
- package/dist/exports/index.js.map +1 -1
- package/dist/plugin/payload-plugin.js +54 -19
- package/dist/plugin/payload-plugin.js.map +1 -1
- package/dist/plugin/types.d.ts +7 -2
- package/dist/plugin/types.js.map +1 -1
- package/docs/FAILURE_SEMANTICS.md +25 -6
- package/package.json +1 -1
- package/dist/core/redirects/collection/access.d.ts +0 -8
- package/dist/core/redirects/collection/access.js +0 -10
- package/dist/core/redirects/collection/access.js.map +0 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { definePlugin } from "payload";
|
|
1
|
+
import { definePlugin, } from "payload";
|
|
2
|
+
import { createGlobalRedirect } from "../core/redirects/auto/create-global-redirect.js";
|
|
2
3
|
import { createRedirect } from "../core/redirects/auto/create-redirect.js";
|
|
3
4
|
import { createRedirectsCollection } from "../core/redirects/collection/collection.js";
|
|
4
5
|
import { isValidLocalePrefix } from "../core/url/published-path.js";
|
|
@@ -31,7 +32,7 @@ const assertLocaleMap = (value, locales, name) => {
|
|
|
31
32
|
}
|
|
32
33
|
return map;
|
|
33
34
|
};
|
|
34
|
-
const validatePathOptions = (value, slug, locales,
|
|
35
|
+
const validatePathOptions = (value, entityType, slug, locales, versions) => {
|
|
35
36
|
const options = asRecord(value);
|
|
36
37
|
if (!options)
|
|
37
38
|
throw new Error(`payload-redirect: redirect config for "${slug}" must be an object`);
|
|
@@ -50,26 +51,24 @@ const validatePathOptions = (value, slug, locales, collection) => {
|
|
|
50
51
|
throw new Error(`payload-redirect: redirect config for "${slug}" enabled must be a boolean`);
|
|
51
52
|
}
|
|
52
53
|
if (modes.length !== 1) {
|
|
53
|
-
throw new Error(`payload-redirect:
|
|
54
|
+
throw new Error(`payload-redirect: ${entityType} "${slug}" must configure exactly one of path, paths, or getPath`);
|
|
54
55
|
}
|
|
55
|
-
if (!
|
|
56
|
-
typeof collection.versions !== "object" ||
|
|
57
|
-
!collection.versions.drafts) {
|
|
56
|
+
if (!asRecord(versions)?.drafts) {
|
|
58
57
|
throw new Error(`payload-redirect: automatic redirects for "${slug}" require versions.drafts`);
|
|
59
58
|
}
|
|
60
59
|
if (Object.hasOwn(options, "path")) {
|
|
61
60
|
if (typeof options.path !== "string" || !isValidPathTemplate(options.path)) {
|
|
62
|
-
throw new Error(`payload-redirect:
|
|
61
|
+
throw new Error(`payload-redirect: ${entityType}s.${slug}.path must be a valid site-relative template`);
|
|
63
62
|
}
|
|
64
63
|
}
|
|
65
64
|
else if (Object.hasOwn(options, "paths")) {
|
|
66
65
|
if (locales.length === 0) {
|
|
67
|
-
throw new Error(`payload-redirect:
|
|
66
|
+
throw new Error(`payload-redirect: ${entityType}s.${slug}.paths requires Payload localization`);
|
|
68
67
|
}
|
|
69
|
-
const paths = assertLocaleMap(options.paths, locales,
|
|
68
|
+
const paths = assertLocaleMap(options.paths, locales, `${entityType}s.${slug}.paths`);
|
|
70
69
|
for (const [locale, path] of Object.entries(paths)) {
|
|
71
70
|
if (!isValidPathTemplate(path)) {
|
|
72
|
-
throw new Error(`payload-redirect:
|
|
71
|
+
throw new Error(`payload-redirect: ${entityType}s.${slug}.paths.${locale} must be a valid site-relative template`);
|
|
73
72
|
}
|
|
74
73
|
}
|
|
75
74
|
}
|
|
@@ -77,12 +76,12 @@ const validatePathOptions = (value, slug, locales, collection) => {
|
|
|
77
76
|
throw new Error(`payload-redirect: collections.${slug}.getPath must be a function`);
|
|
78
77
|
}
|
|
79
78
|
};
|
|
80
|
-
const
|
|
81
|
-
const central = asRecord(
|
|
82
|
-
if (central && Object.hasOwn(central,
|
|
83
|
-
return central[
|
|
79
|
+
const selectedOptions = (entity, centralOptions) => {
|
|
80
|
+
const central = asRecord(centralOptions);
|
|
81
|
+
if (central && Object.hasOwn(central, entity.slug)) {
|
|
82
|
+
return central[entity.slug];
|
|
84
83
|
}
|
|
85
|
-
return asRecord(
|
|
84
|
+
return asRecord(entity.custom)?.redirect;
|
|
86
85
|
};
|
|
87
86
|
const validateOptions = (config, options) => {
|
|
88
87
|
const locales = localeCodes(config);
|
|
@@ -99,15 +98,26 @@ const validateOptions = (config, options) => {
|
|
|
99
98
|
throw new Error(`payload-redirect: configured collection "${slug}" is not registered`);
|
|
100
99
|
}
|
|
101
100
|
}
|
|
101
|
+
for (const slug of Object.keys(asRecord(options.globals) ?? {})) {
|
|
102
|
+
if (!config.globals?.some((global) => global.slug === slug)) {
|
|
103
|
+
throw new Error(`payload-redirect: configured global "${slug}" is not registered`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
102
106
|
for (const collection of config.collections ?? []) {
|
|
103
|
-
const selected =
|
|
107
|
+
const selected = selectedOptions(collection, options.collections);
|
|
108
|
+
if (selected === undefined)
|
|
109
|
+
continue;
|
|
110
|
+
validatePathOptions(selected, "collection", collection.slug, locales, collection.versions);
|
|
111
|
+
}
|
|
112
|
+
for (const global of config.globals ?? []) {
|
|
113
|
+
const selected = selectedOptions(global, options.globals);
|
|
104
114
|
if (selected === undefined)
|
|
105
115
|
continue;
|
|
106
|
-
validatePathOptions(selected,
|
|
116
|
+
validatePathOptions(selected, "global", global.slug, locales, global.versions);
|
|
107
117
|
}
|
|
108
118
|
};
|
|
109
119
|
const wireCollectionRedirect = (collection, options, collectionSlug) => {
|
|
110
|
-
const selected =
|
|
120
|
+
const selected = selectedOptions(collection, options.collections);
|
|
111
121
|
const record = asRecord(selected);
|
|
112
122
|
if (!record || record.enabled === false)
|
|
113
123
|
return collection;
|
|
@@ -121,7 +131,7 @@ const wireCollectionRedirect = (collection, options, collectionSlug) => {
|
|
|
121
131
|
afterChange: [
|
|
122
132
|
...hooks,
|
|
123
133
|
createRedirect({
|
|
124
|
-
collectionSlug,
|
|
134
|
+
redirectCollectionSlug: collectionSlug,
|
|
125
135
|
pathOptions: redirectOptions,
|
|
126
136
|
localePrefixes: options.localePrefixes,
|
|
127
137
|
}),
|
|
@@ -129,6 +139,30 @@ const wireCollectionRedirect = (collection, options, collectionSlug) => {
|
|
|
129
139
|
},
|
|
130
140
|
};
|
|
131
141
|
};
|
|
142
|
+
const wireGlobalRedirect = (global, options, redirectCollectionSlug) => {
|
|
143
|
+
const selected = selectedOptions(global, options.globals);
|
|
144
|
+
const record = asRecord(selected);
|
|
145
|
+
if (!record || record.enabled === false)
|
|
146
|
+
return global;
|
|
147
|
+
const afterChange = global.hooks?.afterChange;
|
|
148
|
+
const hooks = Array.isArray(afterChange) ? afterChange : afterChange ? [afterChange] : [];
|
|
149
|
+
const pathOptions = selected;
|
|
150
|
+
return {
|
|
151
|
+
...global,
|
|
152
|
+
hooks: {
|
|
153
|
+
...global.hooks,
|
|
154
|
+
afterChange: [
|
|
155
|
+
...hooks,
|
|
156
|
+
createGlobalRedirect({
|
|
157
|
+
globalSlug: global.slug,
|
|
158
|
+
redirectCollectionSlug,
|
|
159
|
+
pathOptions,
|
|
160
|
+
localePrefixes: options.localePrefixes,
|
|
161
|
+
}),
|
|
162
|
+
],
|
|
163
|
+
},
|
|
164
|
+
};
|
|
165
|
+
};
|
|
132
166
|
const definedRedirectsPlugin = definePlugin({
|
|
133
167
|
slug: PLUGIN_SLUG,
|
|
134
168
|
plugin: ({ config, ...options }) => {
|
|
@@ -148,6 +182,7 @@ const definedRedirectsPlugin = definePlugin({
|
|
|
148
182
|
...(config.collections ?? []).map((collection) => wireCollectionRedirect(collection, options, collectionSlug)),
|
|
149
183
|
redirectsCollection,
|
|
150
184
|
],
|
|
185
|
+
globals: (config.globals ?? []).map((global) => wireGlobalRedirect(global, options, collectionSlug)),
|
|
151
186
|
};
|
|
152
187
|
},
|
|
153
188
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"payload-plugin.js","sourceRoot":"","sources":["../../src/plugin/payload-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsC,YAAY,EAAe,MAAM,SAAS,CAAC;AACxF,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAGtE,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAC9C,MAAM,uBAAuB,GAAG,WAAW,CAAC;A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C1K,CAAC;QACJ,CAAC;QAED,OAAO;YACL,GAAG,MAAM;YACT,WAAW,EAAE;gBACX,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAC/C,sBAAsB,CAAC,UAAU,EAAE,OAAO,EAAE,cAAc,CAAC,CAC5D;gBACD,mBAAmB;aACpB;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,GAAqB,EAAE,EAAU,EAAE,CAClE,sBAAsB,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import { type CollectionConfig, type Config, definePlugin, type Plugin } from \"payload\";\nimport { createRedirect } from \"#redirect/core/redirects/auto/create-redirect\";\nimport { createRedirectsCollection } from \"#redirect/core/redirects/collection/collection\";\nimport { isValidLocalePrefix } from \"#redirect/core/url/published-path\";\nimport { isValidPathTemplate } from \"#redirect/core/url/route-params\";\nimport type { RedirectCollectionOptions, RedirectsOptions } from \"./types.js\";\n\nconst PLUGIN_SLUG = \"@klnap/payload-redirect\";\nconst DEFAULT_COLLECTION_SLUG = \"redirects\";\nconst PATH_OPTIONS = new Set([\"enabled\", \"path\", \"paths\", \"getPath\"]);\n\nconst asRecord = (value: unknown): Record<string, unknown> | undefined =>\n value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n\nconst localeCodes = (config: Config): string[] => {\n const locales = config.localization === false ? undefined : config.localization?.locales;\n return Array.isArray(locales)\n ? locales.map((locale) =>\n typeof locale === \"string\" ? locale : (locale as { code: string }).code,\n )\n : [];\n};\n\nconst assertLocaleMap = (\n value: unknown,\n locales: string[],\n name: string,\n): Record<string, string> => {\n const map = asRecord(value);\n if (!map) throw new Error(`payload-redirect: ${name} must be a locale map`);\n const missing = locales.filter((locale) => !Object.hasOwn(map, locale));\n const unknown = Object.keys(map).filter((locale) => !locales.includes(locale));\n if (missing.length || unknown.length) {\n throw new Error(\n `payload-redirect: ${name} has invalid locales (missing: ${missing.join(\", \") || \"none\"}; unknown: ${unknown.join(\", \") || \"none\"})`,\n );\n }\n for (const [locale, path] of Object.entries(map)) {\n if (typeof path !== \"string\") {\n throw new Error(`payload-redirect: ${name}.${locale} must be a string`);\n }\n }\n return map as Record<string, string>;\n};\n\nconst validatePathOptions = (\n value: unknown,\n slug: string,\n locales: string[],\n collection: CollectionConfig,\n): void => {\n const options = asRecord(value);\n if (!options)\n throw new Error(`payload-redirect: redirect config for \"${slug}\" must be an object`);\n\n const unsupported = Object.keys(options).filter((key) => !PATH_OPTIONS.has(key));\n if (unsupported.length) {\n throw new Error(\n `payload-redirect: unsupported redirect option for \"${slug}\": ${unsupported.join(\", \")}`,\n );\n }\n\n const modes = [\"path\", \"paths\", \"getPath\"].filter((key) => Object.hasOwn(options, key));\n if (options.enabled === false) {\n if (modes.length) {\n throw new Error(\n `payload-redirect: disabled redirect config for \"${slug}\" cannot define a path`,\n );\n }\n return;\n }\n if (options.enabled !== undefined && options.enabled !== true) {\n throw new Error(`payload-redirect: redirect config for \"${slug}\" enabled must be a boolean`);\n }\n if (modes.length !== 1) {\n throw new Error(\n `payload-redirect: collection \"${slug}\" must configure exactly one of path, paths, or getPath`,\n );\n }\n if (\n !collection.versions ||\n typeof collection.versions !== \"object\" ||\n !collection.versions.drafts\n ) {\n throw new Error(`payload-redirect: automatic redirects for \"${slug}\" require versions.drafts`);\n }\n\n if (Object.hasOwn(options, \"path\")) {\n if (typeof options.path !== \"string\" || !isValidPathTemplate(options.path)) {\n throw new Error(\n `payload-redirect: collections.${slug}.path must be a valid site-relative template`,\n );\n }\n } else if (Object.hasOwn(options, \"paths\")) {\n if (locales.length === 0) {\n throw new Error(`payload-redirect: collections.${slug}.paths requires Payload localization`);\n }\n const paths = assertLocaleMap(options.paths, locales, `collections.${slug}.paths`);\n for (const [locale, path] of Object.entries(paths)) {\n if (!isValidPathTemplate(path)) {\n throw new Error(\n `payload-redirect: collections.${slug}.paths.${locale} must be a valid site-relative template`,\n );\n }\n }\n } else if (typeof options.getPath !== \"function\") {\n throw new Error(`payload-redirect: collections.${slug}.getPath must be a function`);\n }\n};\n\nconst selectedCollectionOptions = (\n collection: CollectionConfig,\n options: RedirectsOptions,\n): unknown => {\n const central = asRecord(options.collections);\n if (central && Object.hasOwn(central, collection.slug)) {\n return central[collection.slug];\n }\n return asRecord(collection.custom)?.redirect;\n};\n\nconst validateOptions = (config: Config, options: RedirectsOptions): void => {\n const locales = localeCodes(config);\n if (options.localePrefixes !== undefined) {\n const prefixes = assertLocaleMap(options.localePrefixes, locales, \"localePrefixes\");\n for (const [locale, prefix] of Object.entries(prefixes)) {\n if (!isValidLocalePrefix(prefix)) {\n throw new Error(\n `payload-redirect: localePrefixes.${locale} must be a site-relative path prefix`,\n );\n }\n }\n }\n\n for (const slug of Object.keys(asRecord(options.collections) ?? {})) {\n if (!config.collections?.some((collection) => collection.slug === slug)) {\n throw new Error(`payload-redirect: configured collection \"${slug}\" is not registered`);\n }\n }\n\n for (const collection of config.collections ?? []) {\n const selected = selectedCollectionOptions(collection, options);\n if (selected === undefined) continue;\n validatePathOptions(selected, collection.slug, locales, collection);\n }\n};\n\nconst wireCollectionRedirect = (\n collection: CollectionConfig,\n options: RedirectsOptions,\n collectionSlug: string,\n): CollectionConfig => {\n const selected = selectedCollectionOptions(collection, options);\n const record = asRecord(selected);\n if (!record || record.enabled === false) return collection;\n\n const afterChange = collection.hooks?.afterChange;\n const hooks = Array.isArray(afterChange) ? afterChange : afterChange ? [afterChange] : [];\n const redirectOptions = selected as RedirectCollectionOptions;\n\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n afterChange: [\n ...hooks,\n createRedirect({\n collectionSlug,\n pathOptions: redirectOptions,\n localePrefixes: options.localePrefixes,\n }),\n ],\n },\n };\n};\n\nconst definedRedirectsPlugin = definePlugin<RedirectsOptions>({\n slug: PLUGIN_SLUG,\n plugin: ({ config, ...options }) => {\n validateOptions(config, options);\n const registeredCount =\n config.plugins?.filter((plugin) => plugin.slug === PLUGIN_SLUG).length ?? 0;\n if (registeredCount > 1) {\n throw new Error(\"payload-redirect: register redirects() only once in config.plugins\");\n }\n\n const redirectsCollection = createRedirectsCollection(options.overrides);\n const collectionSlug = redirectsCollection.slug || DEFAULT_COLLECTION_SLUG;\n if (config.collections?.some(({ slug }) => slug === collectionSlug)) {\n throw new Error(\n `payload-redirect: collection slug \"${collectionSlug}\" is already registered; configure it with redirects({ overrides: { slug } }) instead of defining a host collection`,\n );\n }\n\n return {\n ...config,\n collections: [\n ...(config.collections ?? []).map((collection) =>\n wireCollectionRedirect(collection, options, collectionSlug),\n ),\n redirectsCollection,\n ],\n };\n },\n});\n\nexport const redirects = (options: RedirectsOptions = {}): Plugin =>\n definedRedirectsPlugin(options);\n"]}
|
|
1
|
+
{"version":3,"file":"payload-plugin.js","sourceRoot":"","sources":["../../src/plugin/payload-plugin.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,YAAY,GAEb,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,oBAAoB,EAAE,MAAM,sDAAsD,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,yBAAyB,EAAE,MAAM,gDAAgD,CAAC;AAC3F,OAAO,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AACxE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC;AAOtE,MAAM,WAAW,GAAG,yBAAyB,CAAC;AAC9C,MAAM,uBAAuB,GAAG,WAAW,CAAC;AAC5C,MAAM,YAAY,GAAG,IAAI,GAAG,CAAC,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,CAAC,CAAC,CAAC;AAEtE,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAuC,EAAE,CACvE,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO,CAA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,EAAE,CAAC,IAAI,KAAK,cAAc,CAAC,EAAE,CAAC;YACpE,MAAM,IAAI,KAAK,CACb,sCAAsC,cAAc,qHAAqH,CAC1K,CAAC;QACJ,CAAC;QAED,OAAO;YACL,GAAG,MAAM;YACT,WAAW,EAAE;gBACX,GAAG,CAAC,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAC/C,sBAAsB,CAAC,UAAU,EAAE,OAAO,EAAE,cAAc,CAAC,CAC5D;gBACD,mBAAmB;aACpB;YACD,OAAO,EAAE,CAAC,MAAM,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAC7C,kBAAkB,CAAC,MAAM,EAAE,OAAO,EAAE,cAAc,CAAC,CACpD;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,SAAS,GAAG,CAAC,OAAO,GAAqB,EAAE,EAAU,EAAE,CAClE,sBAAsB,CAAC,OAAO,CAAC,CAAC","sourcesContent":["import {\n type CollectionConfig,\n type Config,\n type GlobalConfig,\n definePlugin,\n type Plugin,\n} from \"payload\";\nimport { createGlobalRedirect } from \"#redirect/core/redirects/auto/create-global-redirect\";\nimport { createRedirect } from \"#redirect/core/redirects/auto/create-redirect\";\nimport { createRedirectsCollection } from \"#redirect/core/redirects/collection/collection\";\nimport { isValidLocalePrefix } from \"#redirect/core/url/published-path\";\nimport { isValidPathTemplate } from \"#redirect/core/url/route-params\";\nimport type {\n RedirectCollectionOptions,\n RedirectGlobalOptions,\n RedirectsOptions,\n} from \"./types.js\";\n\nconst PLUGIN_SLUG = \"@klnap/payload-redirect\";\nconst DEFAULT_COLLECTION_SLUG = \"redirects\";\nconst PATH_OPTIONS = new Set([\"enabled\", \"path\", \"paths\", \"getPath\"]);\n\nconst asRecord = (value: unknown): Record<string, unknown> | undefined =>\n value && typeof value === \"object\" && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n\nconst localeCodes = (config: Config): string[] => {\n const locales = config.localization === false ? undefined : config.localization?.locales;\n return Array.isArray(locales)\n ? locales.map((locale) =>\n typeof locale === \"string\" ? locale : (locale as { code: string }).code,\n )\n : [];\n};\n\nconst assertLocaleMap = (\n value: unknown,\n locales: string[],\n name: string,\n): Record<string, string> => {\n const map = asRecord(value);\n if (!map) throw new Error(`payload-redirect: ${name} must be a locale map`);\n const missing = locales.filter((locale) => !Object.hasOwn(map, locale));\n const unknown = Object.keys(map).filter((locale) => !locales.includes(locale));\n if (missing.length || unknown.length) {\n throw new Error(\n `payload-redirect: ${name} has invalid locales (missing: ${missing.join(\", \") || \"none\"}; unknown: ${unknown.join(\", \") || \"none\"})`,\n );\n }\n for (const [locale, path] of Object.entries(map)) {\n if (typeof path !== \"string\") {\n throw new Error(`payload-redirect: ${name}.${locale} must be a string`);\n }\n }\n return map as Record<string, string>;\n};\n\nconst validatePathOptions = (\n value: unknown,\n entityType: \"collection\" | \"global\",\n slug: string,\n locales: string[],\n versions: unknown,\n): void => {\n const options = asRecord(value);\n if (!options)\n throw new Error(`payload-redirect: redirect config for \"${slug}\" must be an object`);\n\n const unsupported = Object.keys(options).filter((key) => !PATH_OPTIONS.has(key));\n if (unsupported.length) {\n throw new Error(\n `payload-redirect: unsupported redirect option for \"${slug}\": ${unsupported.join(\", \")}`,\n );\n }\n\n const modes = [\"path\", \"paths\", \"getPath\"].filter((key) => Object.hasOwn(options, key));\n if (options.enabled === false) {\n if (modes.length) {\n throw new Error(\n `payload-redirect: disabled redirect config for \"${slug}\" cannot define a path`,\n );\n }\n return;\n }\n if (options.enabled !== undefined && options.enabled !== true) {\n throw new Error(`payload-redirect: redirect config for \"${slug}\" enabled must be a boolean`);\n }\n if (modes.length !== 1) {\n throw new Error(\n `payload-redirect: ${entityType} \"${slug}\" must configure exactly one of path, paths, or getPath`,\n );\n }\n if (!asRecord(versions)?.drafts) {\n throw new Error(`payload-redirect: automatic redirects for \"${slug}\" require versions.drafts`);\n }\n\n if (Object.hasOwn(options, \"path\")) {\n if (typeof options.path !== \"string\" || !isValidPathTemplate(options.path)) {\n throw new Error(\n `payload-redirect: ${entityType}s.${slug}.path must be a valid site-relative template`,\n );\n }\n } else if (Object.hasOwn(options, \"paths\")) {\n if (locales.length === 0) {\n throw new Error(\n `payload-redirect: ${entityType}s.${slug}.paths requires Payload localization`,\n );\n }\n const paths = assertLocaleMap(options.paths, locales, `${entityType}s.${slug}.paths`);\n for (const [locale, path] of Object.entries(paths)) {\n if (!isValidPathTemplate(path)) {\n throw new Error(\n `payload-redirect: ${entityType}s.${slug}.paths.${locale} must be a valid site-relative template`,\n );\n }\n }\n } else if (typeof options.getPath !== \"function\") {\n throw new Error(`payload-redirect: collections.${slug}.getPath must be a function`);\n }\n};\n\nconst selectedOptions = (\n entity: { slug: string; custom?: unknown },\n centralOptions: unknown,\n): unknown => {\n const central = asRecord(centralOptions);\n if (central && Object.hasOwn(central, entity.slug)) {\n return central[entity.slug];\n }\n return asRecord(entity.custom)?.redirect;\n};\n\nconst validateOptions = (config: Config, options: RedirectsOptions): void => {\n const locales = localeCodes(config);\n if (options.localePrefixes !== undefined) {\n const prefixes = assertLocaleMap(options.localePrefixes, locales, \"localePrefixes\");\n for (const [locale, prefix] of Object.entries(prefixes)) {\n if (!isValidLocalePrefix(prefix)) {\n throw new Error(\n `payload-redirect: localePrefixes.${locale} must be a site-relative path prefix`,\n );\n }\n }\n }\n\n for (const slug of Object.keys(asRecord(options.collections) ?? {})) {\n if (!config.collections?.some((collection) => collection.slug === slug)) {\n throw new Error(`payload-redirect: configured collection \"${slug}\" is not registered`);\n }\n }\n\n for (const slug of Object.keys(asRecord(options.globals) ?? {})) {\n if (!config.globals?.some((global) => global.slug === slug)) {\n throw new Error(`payload-redirect: configured global \"${slug}\" is not registered`);\n }\n }\n\n for (const collection of config.collections ?? []) {\n const selected = selectedOptions(collection, options.collections);\n if (selected === undefined) continue;\n validatePathOptions(selected, \"collection\", collection.slug, locales, collection.versions);\n }\n\n for (const global of config.globals ?? []) {\n const selected = selectedOptions(global, options.globals);\n if (selected === undefined) continue;\n validatePathOptions(selected, \"global\", global.slug, locales, global.versions);\n }\n};\n\nconst wireCollectionRedirect = (\n collection: CollectionConfig,\n options: RedirectsOptions,\n collectionSlug: string,\n): CollectionConfig => {\n const selected = selectedOptions(collection, options.collections);\n const record = asRecord(selected);\n if (!record || record.enabled === false) return collection;\n\n const afterChange = collection.hooks?.afterChange;\n const hooks = Array.isArray(afterChange) ? afterChange : afterChange ? [afterChange] : [];\n const redirectOptions = selected as RedirectCollectionOptions;\n\n return {\n ...collection,\n hooks: {\n ...collection.hooks,\n afterChange: [\n ...hooks,\n createRedirect({\n redirectCollectionSlug: collectionSlug,\n pathOptions: redirectOptions,\n localePrefixes: options.localePrefixes,\n }),\n ],\n },\n };\n};\n\nconst wireGlobalRedirect = (\n global: GlobalConfig,\n options: RedirectsOptions,\n redirectCollectionSlug: string,\n): GlobalConfig => {\n const selected = selectedOptions(global, options.globals);\n const record = asRecord(selected);\n if (!record || record.enabled === false) return global;\n\n const afterChange = global.hooks?.afterChange;\n const hooks = Array.isArray(afterChange) ? afterChange : afterChange ? [afterChange] : [];\n const pathOptions = selected as RedirectGlobalOptions;\n\n return {\n ...global,\n hooks: {\n ...global.hooks,\n afterChange: [\n ...hooks,\n createGlobalRedirect({\n globalSlug: global.slug,\n redirectCollectionSlug,\n pathOptions,\n localePrefixes: options.localePrefixes,\n }),\n ],\n },\n };\n};\n\nconst definedRedirectsPlugin = definePlugin<RedirectsOptions>({\n slug: PLUGIN_SLUG,\n plugin: ({ config, ...options }) => {\n validateOptions(config, options);\n const registeredCount =\n config.plugins?.filter((plugin) => plugin.slug === PLUGIN_SLUG).length ?? 0;\n if (registeredCount > 1) {\n throw new Error(\"payload-redirect: register redirects() only once in config.plugins\");\n }\n\n const redirectsCollection = createRedirectsCollection(options.overrides);\n const collectionSlug = redirectsCollection.slug || DEFAULT_COLLECTION_SLUG;\n if (config.collections?.some(({ slug }) => slug === collectionSlug)) {\n throw new Error(\n `payload-redirect: collection slug \"${collectionSlug}\" is already registered; configure it with redirects({ overrides: { slug } }) instead of defining a host collection`,\n );\n }\n\n return {\n ...config,\n collections: [\n ...(config.collections ?? []).map((collection) =>\n wireCollectionRedirect(collection, options, collectionSlug),\n ),\n redirectsCollection,\n ],\n globals: (config.globals ?? []).map((global) =>\n wireGlobalRedirect(global, options, collectionSlug),\n ),\n };\n },\n});\n\nexport const redirects = (options: RedirectsOptions = {}): Plugin =>\n definedRedirectsPlugin(options);\n"]}
|
package/dist/plugin/types.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import type { CollectionSlug } from "payload";
|
|
1
|
+
import type { CollectionSlug, DataFromCollectionSlug, DataFromGlobalSlug, GlobalSlug } from "payload";
|
|
2
2
|
import type { RedirectPathOptions } from "../core/redirects/auto/types.js";
|
|
3
3
|
import type { RedirectCollectionOverrides } from "../core/redirects/collection/types.js";
|
|
4
4
|
type LocaleCode = Extract<import("payload").TypedLocale, string>;
|
|
5
5
|
type LocaleMap = string extends LocaleCode ? Record<string, string> : Record<LocaleCode, string>;
|
|
6
|
-
export type RedirectCollectionOptions<TSlug extends CollectionSlug = CollectionSlug> = RedirectPathOptions<TSlug
|
|
6
|
+
export type RedirectCollectionOptions<TSlug extends CollectionSlug = CollectionSlug> = RedirectPathOptions<DataFromCollectionSlug<TSlug>>;
|
|
7
|
+
export type RedirectGlobalOptions<TSlug extends GlobalSlug = GlobalSlug> = RedirectPathOptions<DataFromGlobalSlug<TSlug>>;
|
|
7
8
|
export type RedirectsOptions = {
|
|
8
9
|
/** Payload locale codes map to explicit site-relative prefixes; omission means no prefix. */
|
|
9
10
|
localePrefixes?: LocaleMap;
|
|
@@ -11,6 +12,10 @@ export type RedirectsOptions = {
|
|
|
11
12
|
collections?: {
|
|
12
13
|
[TSlug in CollectionSlug]?: RedirectCollectionOptions<TSlug>;
|
|
13
14
|
};
|
|
15
|
+
/** Each entry opts that global into automatic redirects. Central entries replace local config. */
|
|
16
|
+
globals?: {
|
|
17
|
+
[TSlug in GlobalSlug]?: RedirectGlobalOptions<TSlug>;
|
|
18
|
+
};
|
|
14
19
|
/** Native collection overrides for the plugin-owned redirects collection. */
|
|
15
20
|
overrides?: RedirectCollectionOverrides;
|
|
16
21
|
};
|
package/dist/plugin/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/plugin/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n CollectionSlug,\n DataFromCollectionSlug,\n DataFromGlobalSlug,\n GlobalSlug,\n} from \"payload\";\nimport type { RedirectPathOptions } from \"#redirect/core/redirects/auto/types\";\nimport type { RedirectCollectionOverrides } from \"#redirect/core/redirects/collection/types\";\n\ntype LocaleCode = Extract<import(\"payload\").TypedLocale, string>;\ntype LocaleMap = string extends LocaleCode ? Record<string, string> : Record<LocaleCode, string>;\n\nexport type RedirectCollectionOptions<TSlug extends CollectionSlug = CollectionSlug> =\n RedirectPathOptions<DataFromCollectionSlug<TSlug>>;\n\nexport type RedirectGlobalOptions<TSlug extends GlobalSlug = GlobalSlug> = RedirectPathOptions<\n DataFromGlobalSlug<TSlug>\n>;\n\nexport type RedirectsOptions = {\n /** Payload locale codes map to explicit site-relative prefixes; omission means no prefix. */\n localePrefixes?: LocaleMap;\n /** Each entry opts that collection into automatic redirects. Central entries replace local config. */\n collections?: { [TSlug in CollectionSlug]?: RedirectCollectionOptions<TSlug> };\n /** Each entry opts that global into automatic redirects. Central entries replace local config. */\n globals?: { [TSlug in GlobalSlug]?: RedirectGlobalOptions<TSlug> };\n /** Native collection overrides for the plugin-owned redirects collection. */\n overrides?: RedirectCollectionOverrides;\n};\n"]}
|
|
@@ -10,18 +10,24 @@ This document records observable configuration, validation, and publication beha
|
|
|
10
10
|
| The redirects collection slug already exists | Plugin config throws and names the colliding slug. |
|
|
11
11
|
| `redirects()` is registered more than once | Plugin config throws; register it once. |
|
|
12
12
|
| `overrides.fields` changes a required field type | Plugin config throws before Payload builds. Missing required fields are restored from defaults. |
|
|
13
|
-
| A
|
|
14
|
-
| Central
|
|
15
|
-
| A configured
|
|
13
|
+
| A Collection or Global has no redirect configuration | The entity is left unchanged; no publication hook is added. |
|
|
14
|
+
| Central options name an unregistered Collection or Global | Plugin configuration throws and names the entity. |
|
|
15
|
+
| A configured Collection or Global has no `versions.drafts` | Plugin configuration throws and names the entity. |
|
|
16
16
|
| Path config has unsupported options or multiple strategies | Plugin configuration throws before Payload builds. |
|
|
17
17
|
| Locale map omits or adds a Payload locale | Plugin configuration throws and names invalid locales. |
|
|
18
18
|
| Automatic generation is disabled | No automatic hook is added; manual rules remain available. |
|
|
19
|
+
| A Global defines `custom.redirect` | The plugin appends its Global publication hook and preserves existing hooks. |
|
|
19
20
|
|
|
20
21
|
## Redirect collection writes
|
|
21
22
|
|
|
22
23
|
`from` and `to` must be non-empty site-relative paths. The plugin normalizes them before checking
|
|
23
24
|
duplicates and loops.
|
|
24
25
|
|
|
26
|
+
Collection and field authorization use Payload's native defaults and consumer overrides. Trusted
|
|
27
|
+
automatic redirect operations use Local API `overrideAccess: true`; their request-context marker
|
|
28
|
+
tracks rule origin and recursion only. Ordinary REST, GraphQL, and user-scoped Local API operations
|
|
29
|
+
remain subject to their configured access rules.
|
|
30
|
+
|
|
25
31
|
| Condition | Result |
|
|
26
32
|
| --------------------------------------------------- | -------------------------------------------------------------- |
|
|
27
33
|
| Duplicate normalized `from` | Payload validation error on `from`. |
|
|
@@ -42,7 +48,7 @@ Automatic rules use one of `path`, `paths`, or `getPath`, configured centrally o
|
|
|
42
48
|
|
|
43
49
|
| Condition | Result |
|
|
44
50
|
| ----------------------------------------------------------- | ----------------------------------------------------------------------------- |
|
|
45
|
-
| No matching path configuration | Automatic generation is not registered for that
|
|
51
|
+
| No matching path configuration | Automatic generation is not registered for that Collection or Global. |
|
|
46
52
|
| Template value is missing or unsafe | That locale's publication transition is skipped. |
|
|
47
53
|
| `getPath` returns `null` or a non-site-relative path | That locale's transition is skipped. |
|
|
48
54
|
| `getPath` returns a non-string value | That locale's transition is skipped. |
|
|
@@ -50,8 +56,21 @@ Automatic rules use one of `path`, `paths`, or `getPath`, configured centrally o
|
|
|
50
56
|
| Locale is missing from a configured prefix map | Plugin configuration fails before Payload builds. |
|
|
51
57
|
| Generated source and destination normalize to the same path | No redirect is written. |
|
|
52
58
|
|
|
53
|
-
Draft saves, first publications, unpublishes,
|
|
54
|
-
|
|
59
|
+
Draft saves, first publications, unpublishes, and deletions create no automatic rules. Existing
|
|
60
|
+
redirects remain when a document is unpublished or deleted.
|
|
61
|
+
|
|
62
|
+
On an unchanged republish, an enabled identical automatic rule is left alone. A missing rule is
|
|
63
|
+
recreated, and a disabled automatic rule is re-enabled, when an earlier published version resolves
|
|
64
|
+
to a different path. The source is the latest earlier published path that differs from the current
|
|
65
|
+
path.
|
|
66
|
+
|
|
67
|
+
An automatic write skips a source path owned by a manual rule. Editing an automatic rule changes
|
|
68
|
+
its origin to `manual`, so later publications do not update it. A path-template change does not
|
|
69
|
+
migrate historical rules.
|
|
70
|
+
|
|
71
|
+
If a generated rule would close a loop, validation rejects the redirect write and the publication
|
|
72
|
+
fails. The collection has one globally unique `from` field and no locale or hostname scope; two
|
|
73
|
+
localized routes cannot own the same source path with different destinations.
|
|
55
74
|
|
|
56
75
|
## Adapter boundary
|
|
57
76
|
|
package/package.json
CHANGED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { REDIRECT_CONTEXT_KEYS } from "../context-keys.js";
|
|
2
|
-
export const isInternalRedirectWrite = (req) => Boolean(req.context?.[REDIRECT_CONTEXT_KEYS.internal]);
|
|
3
|
-
const isHumanUser = (req) => Boolean(req.user) && req.user.type !== "service";
|
|
4
|
-
export const defaultRedirectAccess = {
|
|
5
|
-
read: (() => true),
|
|
6
|
-
create: (({ req }) => isInternalRedirectWrite(req) || isHumanUser(req)),
|
|
7
|
-
update: (({ req }) => isInternalRedirectWrite(req) || isHumanUser(req)),
|
|
8
|
-
delete: (({ req }) => isHumanUser(req)),
|
|
9
|
-
};
|
|
10
|
-
//# sourceMappingURL=access.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"access.js","sourceRoot":"","sources":["../../../../src/core/redirects/collection/access.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,uCAAuC,CAAC;AAE9E,MAAM,CAAC,MAAM,uBAAuB,GAAG,CAAC,GAAmB,EAAW,EAAE,CACtE,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC,qBAAqB,CAAC,QAAQ,CAAC,CAAC,CAAC;AAEzD,MAAM,WAAW,GAAG,CAAC,GAAmB,EAAW,EAAE,CACnD,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,IAAK,GAAG,CAAC,IAA0B,CAAC,IAAI,KAAK,SAAS,CAAC;AAE1E,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,IAAI,EAAE,CAAC,GAAG,EAAE,CAAC,IAAI,CAAW;IAC5B,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,uBAAuB,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,CAAW;IACjF,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,uBAAuB,CAAC,GAAG,CAAC,IAAI,WAAW,CAAC,GAAG,CAAC,CAAW;IACjF,MAAM,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,CAAW;CAClD,CAAC","sourcesContent":["import type { Access, PayloadRequest } from \"payload\";\nimport { REDIRECT_CONTEXT_KEYS } from \"#redirect/core/redirects/context-keys\";\n\nexport const isInternalRedirectWrite = (req: PayloadRequest): boolean =>\n Boolean(req.context?.[REDIRECT_CONTEXT_KEYS.internal]);\n\nconst isHumanUser = (req: PayloadRequest): boolean =>\n Boolean(req.user) && (req.user as { type?: string }).type !== \"service\";\n\nexport const defaultRedirectAccess = {\n read: (() => true) as Access,\n create: (({ req }) => isInternalRedirectWrite(req) || isHumanUser(req)) as Access,\n update: (({ req }) => isInternalRedirectWrite(req) || isHumanUser(req)) as Access,\n delete: (({ req }) => isHumanUser(req)) as Access,\n};\n"]}
|