@klnap/payload-redirect 0.2.0 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -0
- package/README.md +212 -79
- package/dist/core/redirects/auto/create-redirect.d.ts +9 -4
- package/dist/core/redirects/auto/create-redirect.js +26 -66
- 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 +4 -3
- package/dist/core/redirects/auto/match-existing-rule.js.map +1 -0
- package/dist/core/redirects/auto/persist-auto-rule.d.ts +5 -4
- 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 +3 -3
- package/dist/core/redirects/auto/publication/get-publication-transition.js +22 -37
- package/dist/core/redirects/auto/publication/get-publication-transition.js.map +1 -0
- package/dist/core/redirects/auto/publication/locales.d.ts +7 -5
- package/dist/core/redirects/auto/publication/locales.js +33 -28
- package/dist/core/redirects/auto/publication/locales.js.map +1 -0
- package/dist/core/redirects/auto/publication/publish-intent.d.ts +2 -4
- package/dist/core/redirects/auto/publication/publish-intent.js +6 -29
- package/dist/core/redirects/auto/publication/publish-intent.js.map +1 -0
- package/dist/core/redirects/auto/publication/versions/document-locale.d.ts +4 -6
- package/dist/core/redirects/auto/publication/versions/document-locale.js +10 -18
- package/dist/core/redirects/auto/publication/versions/document-locale.js.map +1 -0
- package/dist/core/redirects/auto/publication/versions/version-pages.d.ts +4 -12
- package/dist/core/redirects/auto/publication/versions/version-pages.js +7 -32
- package/dist/core/redirects/auto/publication/versions/version-pages.js.map +1 -0
- package/dist/core/redirects/auto/publication/versions/version-rows.d.ts +1 -7
- package/dist/core/redirects/auto/publication/versions/version-rows.js +7 -30
- package/dist/core/redirects/auto/publication/versions/version-rows.js.map +1 -0
- package/dist/core/redirects/auto/types.d.ts +27 -8
- 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 +35 -34
- 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 +52 -51
- 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 +3 -12
- package/dist/core/redirects/queries.js +3 -2
- package/dist/core/redirects/queries.js.map +1 -0
- package/dist/core/url/published-path.d.ts +4 -16
- package/dist/core/url/published-path.js +40 -121
- package/dist/core/url/published-path.js.map +1 -0
- package/dist/core/url/route-params.d.ts +3 -11
- package/dist/core/url/route-params.js +32 -99
- 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 -3
- package/dist/plugin/payload-plugin.js +94 -91
- package/dist/plugin/payload-plugin.js.map +1 -0
- package/dist/plugin/types.d.ts +9 -35
- package/dist/plugin/types.js +1 -0
- package/dist/plugin/types.js.map +1 -0
- package/docs/FAILURE_SEMANTICS.md +31 -27
- package/package.json +29 -20
- package/dist/core/redirects/auto/publication/identifier-snapshot.d.ts +0 -2
- package/dist/core/redirects/auto/publication/identifier-snapshot.js +0 -27
- package/dist/core/redirects/auto/publication/identifier-transitions.d.ts +0 -18
- package/dist/core/redirects/auto/publication/identifier-transitions.js +0 -36
- package/dist/core/redirects/auto/publication/transition-for-locale.d.ts +0 -12
- package/dist/core/redirects/auto/publication/transition-for-locale.js +0 -167
- package/dist/core/redirects/auto/publication/transitions-to-pairs.d.ts +0 -9
- package/dist/core/redirects/auto/publication/transitions-to-pairs.js +0 -22
- package/dist/core/redirects/auto/published-link-config.d.ts +0 -6
- package/dist/core/redirects/auto/published-link-config.js +0 -53
- package/dist/core/redirects/auto/published-path.d.ts +0 -6
- package/dist/core/redirects/auto/published-path.js +0 -28
- package/dist/core/redirects/auto/redirect-custom.d.ts +0 -7
- package/dist/core/redirects/auto/redirect-custom.js +0 -19
- package/dist/core/redirects/identifier-field-path.d.ts +0 -14
- package/dist/core/redirects/identifier-field-path.js +0 -94
- package/dist/core/redirects/runtime.d.ts +0 -9
- package/dist/core/redirects/runtime.js +0 -13
- package/dist/core/url/preview-path.d.ts +0 -1
- package/dist/core/url/preview-path.js +0 -9
- package/dist/core/url/preview-routes.d.ts +0 -3
- package/dist/core/url/preview-routes.js +0 -31
- package/docs/RELEASING.md +0 -41
- package/docs/adr/0002-database-indexes.md +0 -44
|
@@ -1,49 +1,34 @@
|
|
|
1
|
-
import { REDIRECT_CONTEXT_KEYS } from
|
|
2
|
-
import { getRequestLocales, hasLocalizedDraftStatus,
|
|
3
|
-
import { isDraftSave,
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
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
|
+
export const getPublicationTransition = async (args) => {
|
|
7
|
+
const { req, doc, collection } = args;
|
|
8
8
|
if (!collection.versions?.drafts)
|
|
9
9
|
return [];
|
|
10
|
-
if (isDraftSave(req))
|
|
10
|
+
if (isDraftSave(req) || req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto])
|
|
11
11
|
return [];
|
|
12
|
-
if (req.context?.[REDIRECT_CONTEXT_KEYS.skipAuto])
|
|
13
|
-
return [];
|
|
14
|
-
const docRecord = doc;
|
|
15
|
-
if (isUnpublishedStatus(docRecord._status) && !hasLocalizedDraftStatus(collection)) {
|
|
16
|
-
return [];
|
|
17
|
-
}
|
|
18
|
-
let locales = getRequestLocales(req);
|
|
19
|
-
const localizedField = isIdentifierLocalized(collection, options.identifier);
|
|
20
12
|
const docId = doc.id;
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
25
|
-
if (locales.length === 0 &&
|
|
26
|
-
localizedField &&
|
|
27
|
-
hasLocalizedDraftStatus(collection) &&
|
|
28
|
-
docRecord._status &&
|
|
29
|
-
typeof docRecord._status === 'object') {
|
|
30
|
-
locales = Object.entries(docRecord._status)
|
|
31
|
-
.filter(([, value]) => value === 'published')
|
|
32
|
-
.map(([code]) => code);
|
|
33
|
-
}
|
|
13
|
+
const locales = getRequestLocales(req, doc._status);
|
|
14
|
+
const localizeStatus = hasLocalizedDraftStatus(collection);
|
|
15
|
+
const defaultLocale = resolveDefaultLocale(req);
|
|
34
16
|
const transitions = [];
|
|
35
17
|
for (const locale of locales) {
|
|
36
|
-
const
|
|
18
|
+
const currentDoc = await fetchLocalePublishedDoc({ req, collection, docId, locale });
|
|
19
|
+
if (!currentDoc || !isLocalePublished(currentDoc._status, locale ?? ""))
|
|
20
|
+
continue;
|
|
21
|
+
const publishedDocs = (await fetchPublishedVersionPages({
|
|
37
22
|
req,
|
|
38
|
-
collection,
|
|
23
|
+
collectionSlug: collection.slug,
|
|
39
24
|
docId,
|
|
40
25
|
locale,
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
});
|
|
46
|
-
transitions.push(t);
|
|
26
|
+
versionFilter: { localizeStatus, defaultLocale },
|
|
27
|
+
}))
|
|
28
|
+
.map((row) => row.version)
|
|
29
|
+
.filter((version) => Boolean(version));
|
|
30
|
+
transitions.push({ locale, currentDoc, publishedDocs });
|
|
47
31
|
}
|
|
48
32
|
return transitions;
|
|
49
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,6 +1,8 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
import type { PayloadRequest } from "payload";
|
|
2
|
+
export declare const getRequestLocales: (req: PayloadRequest, status: unknown) => Array<string | undefined>;
|
|
3
|
+
export declare const hasLocalizedDraftStatus: (collection: {
|
|
4
|
+
versions?: {
|
|
5
|
+
drafts?: unknown;
|
|
6
|
+
} | false;
|
|
7
|
+
}) => boolean;
|
|
6
8
|
export declare const resolveDefaultLocale: (req: PayloadRequest) => string | undefined;
|
|
@@ -1,38 +1,43 @@
|
|
|
1
|
-
|
|
2
|
-
export const listLocales = (req) => {
|
|
1
|
+
const listLocales = (req) => {
|
|
3
2
|
const localization = req.payload.config.localization;
|
|
4
|
-
if (!localization)
|
|
3
|
+
if (localization === false || !localization)
|
|
5
4
|
return [];
|
|
6
|
-
return localization.locales.map((
|
|
5
|
+
return localization.locales.map((locale) => (typeof locale === "string" ? locale : locale.code));
|
|
7
6
|
};
|
|
8
|
-
export const getRequestLocales = (req) => {
|
|
9
|
-
|
|
10
|
-
|
|
7
|
+
export const getRequestLocales = (req, status) => {
|
|
8
|
+
const localization = listLocales(req);
|
|
9
|
+
if (localization.length === 0)
|
|
10
|
+
return [undefined];
|
|
11
|
+
const specificLocale = typeof req.query?.publishSpecificLocale === "string"
|
|
12
|
+
? req.query.publishSpecificLocale
|
|
13
|
+
: undefined;
|
|
14
|
+
if (specificLocale && specificLocale !== "all")
|
|
15
|
+
return [specificLocale];
|
|
16
|
+
if (specificLocale === "all" ||
|
|
17
|
+
req.query?.publishAllLocales === "true" ||
|
|
18
|
+
req.query?.publishAllLocales === true) {
|
|
19
|
+
return localization;
|
|
11
20
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
return
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
+
const requestedLocale = typeof req.query?.locale === "string" ? req.query.locale : undefined;
|
|
22
|
+
if (requestedLocale && requestedLocale !== "all")
|
|
23
|
+
return [requestedLocale];
|
|
24
|
+
if (requestedLocale === "all")
|
|
25
|
+
return localization;
|
|
26
|
+
if (status && typeof status === "object" && !Array.isArray(status)) {
|
|
27
|
+
return Object.entries(status)
|
|
28
|
+
.filter(([, value]) => value === "published")
|
|
29
|
+
.map(([locale]) => locale);
|
|
30
|
+
}
|
|
31
|
+
if (typeof req.locale === "string")
|
|
32
|
+
return [req.locale];
|
|
33
|
+
return status === "published" ? localization : [];
|
|
21
34
|
};
|
|
22
35
|
export const hasLocalizedDraftStatus = (collection) => {
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
return false;
|
|
26
|
-
const drafts = versions.drafts;
|
|
27
|
-
return typeof drafts === 'object' && drafts !== null && drafts.localizeStatus === true;
|
|
28
|
-
};
|
|
29
|
-
export const isIdentifierLocalized = (collection, identifier) => {
|
|
30
|
-
return isIdentifierPathLocalized(collection.fields, identifier);
|
|
36
|
+
const drafts = collection.versions === false ? undefined : collection.versions?.drafts;
|
|
37
|
+
return Boolean(drafts && typeof drafts === "object" && "localizeStatus" in drafts && drafts.localizeStatus);
|
|
31
38
|
};
|
|
32
39
|
export const resolveDefaultLocale = (req) => {
|
|
33
40
|
const localization = req.payload.config.localization;
|
|
34
|
-
|
|
35
|
-
return String(localization.defaultLocale);
|
|
36
|
-
}
|
|
37
|
-
return undefined;
|
|
41
|
+
return localization ? localization.defaultLocale : undefined;
|
|
38
42
|
};
|
|
43
|
+
//# sourceMappingURL=locales.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locales.js","sourceRoot":"","sources":["../../../../../src/core/redirects/auto/publication/locales.ts"],"names":[],"mappings":"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","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,5 +1,3 @@
|
|
|
1
|
-
import type { PayloadRequest } from
|
|
1
|
+
import type { PayloadRequest } from "payload";
|
|
2
2
|
export declare const isDraftSave: (req: PayloadRequest) => boolean;
|
|
3
|
-
export declare const
|
|
4
|
-
export declare const isPublishIntent: (data: unknown) => boolean;
|
|
5
|
-
export declare const isLocalePublished: (status: unknown, locale: string, localizeStatus: boolean) => boolean;
|
|
3
|
+
export declare const isLocalePublished: (status: unknown, locale: string) => boolean;
|
|
@@ -1,31 +1,8 @@
|
|
|
1
|
-
export const isDraftSave = (req) => req.query?.draft ===
|
|
2
|
-
export const
|
|
3
|
-
if (status ===
|
|
4
|
-
return
|
|
5
|
-
if (status === 'draft' || status == null)
|
|
6
|
-
return true;
|
|
7
|
-
if (typeof status === 'object') {
|
|
8
|
-
return !Object.values(status).includes('published');
|
|
1
|
+
export const isDraftSave = (req) => req.query?.draft === "true" || req.query?.draft === true;
|
|
2
|
+
export const isLocalePublished = (status, locale) => {
|
|
3
|
+
if (typeof status === "object" && status !== null) {
|
|
4
|
+
return status[locale] === "published";
|
|
9
5
|
}
|
|
10
|
-
return
|
|
11
|
-
};
|
|
12
|
-
export const isPublishIntent = (data) => {
|
|
13
|
-
if (!data || typeof data !== 'object')
|
|
14
|
-
return false;
|
|
15
|
-
const status = data._status;
|
|
16
|
-
if (status === 'published')
|
|
17
|
-
return true;
|
|
18
|
-
if (status && typeof status === 'object') {
|
|
19
|
-
return Object.values(status).includes('published');
|
|
20
|
-
}
|
|
21
|
-
return false;
|
|
22
|
-
};
|
|
23
|
-
export const isLocalePublished = (status, locale, localizeStatus) => {
|
|
24
|
-
if (typeof status === 'object' && status !== null) {
|
|
25
|
-
return status[locale] === 'published';
|
|
26
|
-
}
|
|
27
|
-
if (status === 'published') {
|
|
28
|
-
return !localizeStatus;
|
|
29
|
-
}
|
|
30
|
-
return false;
|
|
6
|
+
return status === "published";
|
|
31
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,9 +1,7 @@
|
|
|
1
|
-
import type { CollectionConfig, PayloadRequest
|
|
2
|
-
export declare const
|
|
3
|
-
export declare const fetchLocalePublishedDoc: ({ req, collection, docId, locale, draft, }: {
|
|
1
|
+
import type { CollectionConfig, PayloadRequest } from "payload";
|
|
2
|
+
export declare const fetchLocalePublishedDoc: ({ req, collection, docId, locale, }: {
|
|
4
3
|
req: PayloadRequest;
|
|
5
4
|
collection: CollectionConfig;
|
|
6
5
|
docId: string | number;
|
|
7
|
-
locale
|
|
8
|
-
|
|
9
|
-
}) => Promise<Record<string, unknown> | undefined>;
|
|
6
|
+
locale?: string;
|
|
7
|
+
}) => Promise<Record<string, unknown>>;
|
|
@@ -1,18 +1,10 @@
|
|
|
1
|
-
export const
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
overrideAccess: true,
|
|
12
|
-
req,
|
|
13
|
-
}));
|
|
14
|
-
}
|
|
15
|
-
catch {
|
|
16
|
-
return undefined;
|
|
17
|
-
}
|
|
18
|
-
};
|
|
1
|
+
export const fetchLocalePublishedDoc = async ({ req, collection, docId, locale, }) => (await req.payload.findByID({
|
|
2
|
+
collection: collection.slug,
|
|
3
|
+
id: docId,
|
|
4
|
+
...(locale ? { locale: locale } : {}),
|
|
5
|
+
fallbackLocale: false,
|
|
6
|
+
depth: 0,
|
|
7
|
+
overrideAccess: true,
|
|
8
|
+
req,
|
|
9
|
+
}));
|
|
10
|
+
//# sourceMappingURL=document-locale.js.map
|
|
@@ -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,20 +1,12 @@
|
|
|
1
|
-
import type { PayloadRequest } from
|
|
2
|
-
import { type VersionRow } from
|
|
3
|
-
export declare const fetchPublishedVersionPages: ({ req, collectionSlug, docId, locale,
|
|
1
|
+
import type { PayloadRequest } from "payload";
|
|
2
|
+
import { type VersionRow } from "./version-rows.js";
|
|
3
|
+
export declare const fetchPublishedVersionPages: ({ req, collectionSlug, docId, locale, versionFilter, }: {
|
|
4
4
|
req: PayloadRequest;
|
|
5
5
|
collectionSlug: string;
|
|
6
6
|
docId: string | number;
|
|
7
|
-
locale
|
|
8
|
-
versionLocale?: string;
|
|
7
|
+
locale?: string;
|
|
9
8
|
versionFilter?: {
|
|
10
9
|
localizeStatus?: boolean;
|
|
11
10
|
defaultLocale?: string;
|
|
12
|
-
identifier?: string;
|
|
13
11
|
};
|
|
14
12
|
}) => Promise<VersionRow[]>;
|
|
15
|
-
export declare const fetchVersionHistoryPages: ({ req, collectionSlug, docId, versionLocale, }: {
|
|
16
|
-
req: PayloadRequest;
|
|
17
|
-
collectionSlug: string;
|
|
18
|
-
docId: string | number;
|
|
19
|
-
versionLocale?: string;
|
|
20
|
-
}) => Promise<VersionRow[]>;
|
|
@@ -1,51 +1,26 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export const fetchPublishedVersionPages = async ({ req, collectionSlug, docId, locale, versionLocale, versionFilter, }) => {
|
|
1
|
+
import { isPublishedVersionRow } from "./version-rows.js";
|
|
2
|
+
export const fetchPublishedVersionPages = async ({ req, collectionSlug, docId, locale, versionFilter, }) => {
|
|
4
3
|
const published = [];
|
|
5
4
|
let page = 1;
|
|
6
5
|
const limit = 50;
|
|
7
|
-
const queryLocale = versionLocale ?? locale;
|
|
8
6
|
while (true) {
|
|
9
7
|
const result = await req.payload.findVersions({
|
|
10
8
|
collection: collectionSlug,
|
|
11
9
|
where: { parent: { equals: docId } },
|
|
12
|
-
sort:
|
|
10
|
+
sort: "-updatedAt",
|
|
13
11
|
depth: 0,
|
|
14
12
|
page,
|
|
15
13
|
limit,
|
|
16
|
-
...(
|
|
14
|
+
...(locale ? { locale: locale } : {}),
|
|
15
|
+
fallbackLocale: false,
|
|
17
16
|
overrideAccess: true,
|
|
18
17
|
req,
|
|
19
18
|
});
|
|
20
|
-
|
|
21
|
-
published.push(...rows);
|
|
19
|
+
published.push(...result.docs.filter((row) => isPublishedVersionRow(row, locale, versionFilter)));
|
|
22
20
|
if (!result.hasNextPage)
|
|
23
21
|
break;
|
|
24
22
|
page += 1;
|
|
25
23
|
}
|
|
26
24
|
return published;
|
|
27
25
|
};
|
|
28
|
-
|
|
29
|
-
const rows = [];
|
|
30
|
-
let page = 1;
|
|
31
|
-
const limit = 50;
|
|
32
|
-
while (true) {
|
|
33
|
-
const result = await req.payload.findVersions({
|
|
34
|
-
collection: collectionSlug,
|
|
35
|
-
where: { parent: { equals: docId } },
|
|
36
|
-
sort: '-updatedAt',
|
|
37
|
-
depth: 0,
|
|
38
|
-
page,
|
|
39
|
-
limit,
|
|
40
|
-
...(versionLocale === undefined ? undefined : { locale: toTypedLocale(versionLocale) }),
|
|
41
|
-
overrideAccess: true,
|
|
42
|
-
req,
|
|
43
|
-
});
|
|
44
|
-
const docs = result.docs.filter((row) => !row.snapshot && !row.autosave);
|
|
45
|
-
rows.push(...docs);
|
|
46
|
-
if (!result.hasNextPage)
|
|
47
|
-
break;
|
|
48
|
-
page += 1;
|
|
49
|
-
}
|
|
50
|
-
return rows;
|
|
51
|
-
};
|
|
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"]}
|
|
@@ -7,13 +7,7 @@ export type VersionRow = {
|
|
|
7
7
|
published_locale?: string;
|
|
8
8
|
version?: Record<string, unknown>;
|
|
9
9
|
};
|
|
10
|
-
export declare const isPublishedVersionRow: (row: VersionRow, locale: string, options?: {
|
|
10
|
+
export declare const isPublishedVersionRow: (row: VersionRow, locale: string | undefined, options?: {
|
|
11
11
|
localizeStatus?: boolean;
|
|
12
12
|
defaultLocale?: string;
|
|
13
|
-
identifier?: string;
|
|
14
13
|
}) => boolean;
|
|
15
|
-
export declare const pickPublishedVersions: (rows: VersionRow[], locale: string, options?: {
|
|
16
|
-
localizeStatus?: boolean;
|
|
17
|
-
defaultLocale?: string;
|
|
18
|
-
identifier?: string;
|
|
19
|
-
}) => VersionRow[];
|
|
@@ -2,40 +2,17 @@ export const isPublishedVersionRow = (row, locale, options) => {
|
|
|
2
2
|
if (row.snapshot || row.autosave)
|
|
3
3
|
return false;
|
|
4
4
|
const publishedLocale = row.publishedLocale ?? row.published_locale;
|
|
5
|
-
if (publishedLocale)
|
|
5
|
+
if (publishedLocale)
|
|
6
6
|
return publishedLocale === locale;
|
|
7
|
-
}
|
|
8
7
|
const status = row.version?._status;
|
|
9
|
-
if (status ===
|
|
8
|
+
if (status === "draft")
|
|
10
9
|
return false;
|
|
11
|
-
if (
|
|
12
|
-
|
|
13
|
-
if (typeof field === 'string') {
|
|
14
|
-
if (typeof status === 'object' && status !== null) {
|
|
15
|
-
return status[locale] === 'published';
|
|
16
|
-
}
|
|
17
|
-
return status === 'published';
|
|
18
|
-
}
|
|
19
|
-
if (field && typeof field === 'object' && !Array.isArray(field)) {
|
|
20
|
-
if (!(locale in field))
|
|
21
|
-
return false;
|
|
22
|
-
if (typeof status === 'object' && status !== null) {
|
|
23
|
-
return status[locale] === 'published';
|
|
24
|
-
}
|
|
25
|
-
if (status === 'published')
|
|
26
|
-
return true;
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
if (status && typeof status === 'object') {
|
|
31
|
-
return status[locale] === 'published';
|
|
10
|
+
if (status && typeof status === "object" && !Array.isArray(status)) {
|
|
11
|
+
return locale !== undefined && status[locale] === "published";
|
|
32
12
|
}
|
|
33
|
-
if (status ===
|
|
34
|
-
|
|
35
|
-
return locale === options.defaultLocale;
|
|
36
|
-
}
|
|
37
|
-
return true;
|
|
13
|
+
if (status === "published") {
|
|
14
|
+
return !options?.localizeStatus || locale !== undefined;
|
|
38
15
|
}
|
|
39
16
|
return false;
|
|
40
17
|
};
|
|
41
|
-
|
|
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,11 +1,30 @@
|
|
|
1
|
+
import type { CollectionSlug, DataFromCollectionSlug, TypedLocale } from "payload";
|
|
2
|
+
export type RedirectPathOptions<TSlug extends CollectionSlug = CollectionSlug> = {
|
|
3
|
+
enabled?: true;
|
|
4
|
+
path: string;
|
|
5
|
+
paths?: never;
|
|
6
|
+
getPath?: never;
|
|
7
|
+
} | {
|
|
8
|
+
enabled?: true;
|
|
9
|
+
path?: never;
|
|
10
|
+
paths: string extends Extract<TypedLocale, string> ? Record<string, string> : Record<Extract<TypedLocale, string>, string>;
|
|
11
|
+
getPath?: never;
|
|
12
|
+
} | {
|
|
13
|
+
enabled?: true;
|
|
14
|
+
path?: never;
|
|
15
|
+
paths?: never;
|
|
16
|
+
getPath: (args: {
|
|
17
|
+
doc: DataFromCollectionSlug<TSlug>;
|
|
18
|
+
locale: TypedLocale | undefined;
|
|
19
|
+
}) => string | null;
|
|
20
|
+
} | {
|
|
21
|
+
enabled: false;
|
|
22
|
+
path?: never;
|
|
23
|
+
paths?: never;
|
|
24
|
+
getPath?: never;
|
|
25
|
+
};
|
|
1
26
|
export type PublicationTransition = {
|
|
2
|
-
published: boolean;
|
|
3
27
|
locale?: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
previousDoc?: Record<string, unknown>;
|
|
7
|
-
currentDoc?: Record<string, unknown>;
|
|
8
|
-
};
|
|
9
|
-
export type GetPublicationTransitionOptions = {
|
|
10
|
-
identifier: string;
|
|
28
|
+
currentDoc: Record<string, unknown>;
|
|
29
|
+
publishedDocs: Record<string, unknown>[];
|
|
11
30
|
};
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import type { CollectionConfig } from
|
|
2
|
-
import type { RedirectCollectionOverrides } from
|
|
1
|
+
import type { CollectionConfig } from "payload";
|
|
2
|
+
import type { RedirectCollectionOverrides } from "./types.js";
|
|
3
3
|
export declare const createRedirectsCollection: (overrides?: RedirectCollectionOverrides) => CollectionConfig;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { defaultRedirectAccess } from
|
|
2
|
-
import { createDuplicateBeforeChange } from
|
|
3
|
-
import { assertRedirectFields, buildRedirectFields, mergeRedirectFields } from
|
|
4
|
-
import { createRedirectOriginBeforeChange } from
|
|
5
|
-
const DEFAULT_SLUG =
|
|
1
|
+
import { defaultRedirectAccess } from "./access.js";
|
|
2
|
+
import { createDuplicateBeforeChange } from "./duplicate-guard.js";
|
|
3
|
+
import { assertRedirectFields, buildRedirectFields, mergeRedirectFields } from "./fields.js";
|
|
4
|
+
import { createRedirectOriginBeforeChange } from "./origin-hook.js";
|
|
5
|
+
const DEFAULT_SLUG = "redirects";
|
|
6
6
|
export const createRedirectsCollection = (overrides = {}) => {
|
|
7
7
|
const defaultFields = buildRedirectFields();
|
|
8
8
|
const fields = overrides.fields
|
|
@@ -19,12 +19,12 @@ export const createRedirectsCollection = (overrides = {}) => {
|
|
|
19
19
|
versions: overrides.versions ?? false,
|
|
20
20
|
timestamps: overrides.timestamps ?? true,
|
|
21
21
|
admin: {
|
|
22
|
-
useAsTitle:
|
|
23
|
-
defaultColumns: [
|
|
24
|
-
listSearchableFields: [
|
|
22
|
+
useAsTitle: "from",
|
|
23
|
+
defaultColumns: ["from", "to", "statusCode", "origin", "enabled", "updatedAt"],
|
|
24
|
+
listSearchableFields: ["from", "to"],
|
|
25
25
|
...overrides.admin,
|
|
26
26
|
},
|
|
27
|
-
defaultSort: overrides.defaultSort ??
|
|
27
|
+
defaultSort: overrides.defaultSort ?? "from",
|
|
28
28
|
access,
|
|
29
29
|
fields,
|
|
30
30
|
hooks: {
|
|
@@ -37,3 +37,4 @@ export const createRedirectsCollection = (overrides = {}) => {
|
|
|
37
37
|
},
|
|
38
38
|
};
|
|
39
39
|
};
|
|
40
|
+
//# sourceMappingURL=collection.js.map
|
|
@@ -0,0 +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,4 +1,4 @@
|
|
|
1
|
-
import type { CollectionBeforeChangeHook, PayloadRequest } from
|
|
1
|
+
import type { CollectionBeforeChangeHook, PayloadRequest } from "payload";
|
|
2
2
|
/** Enabled rules followed from `to` before a write is refused as unverifiable. Bounds the lookups per write. */
|
|
3
3
|
export declare const MAX_REDIRECT_CHAIN_HOPS = 1000;
|
|
4
4
|
export declare const resolveNormalizedFrom: (data: Record<string, unknown>) => string | undefined;
|