@payloadcms/next 3.0.0-beta.3 → 3.0.0-beta.5
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/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +6 -1
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/routes/rest/buildFormState.js +1 -1
- package/dist/routes/rest/buildFormState.js.map +1 -1
- package/dist/routes/rest/collections/deleteByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/deleteByID.js +7 -1
- package/dist/routes/rest/collections/deleteByID.js.map +1 -1
- package/dist/routes/rest/collections/duplicate.d.ts.map +1 -1
- package/dist/routes/rest/collections/duplicate.js +7 -1
- package/dist/routes/rest/collections/duplicate.js.map +1 -1
- package/dist/routes/rest/collections/findByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findByID.js +7 -1
- package/dist/routes/rest/collections/findByID.js.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/findVersionByID.js +7 -1
- package/dist/routes/rest/collections/findVersionByID.js.map +1 -1
- package/dist/routes/rest/collections/preview.d.ts.map +1 -1
- package/dist/routes/rest/collections/preview.js +4 -1
- package/dist/routes/rest/collections/preview.js.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.d.ts.map +1 -1
- package/dist/routes/rest/collections/restoreVersion.js +7 -1
- package/dist/routes/rest/collections/restoreVersion.js.map +1 -1
- package/dist/routes/rest/collections/updateByID.d.ts.map +1 -1
- package/dist/routes/rest/collections/updateByID.js +7 -1
- package/dist/routes/rest/collections/updateByID.js.map +1 -1
- package/dist/routes/rest/globals/preview.d.ts.map +1 -1
- package/dist/routes/rest/globals/preview.js +4 -1
- package/dist/routes/rest/globals/preview.js.map +1 -1
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts +9 -0
- package/dist/routes/rest/utilities/sanitizeCollectionID.d.ts.map +1 -0
- package/dist/routes/rest/utilities/sanitizeCollectionID.js +13 -0
- package/dist/routes/rest/utilities/sanitizeCollectionID.js.map +1 -0
- package/dist/utilities/getPayloadHMR.d.ts.map +1 -1
- package/dist/utilities/getPayloadHMR.js +2 -1
- package/dist/utilities/getPayloadHMR.js.map +1 -1
- package/dist/views/CreateFirstUser/index.d.ts.map +1 -1
- package/dist/views/CreateFirstUser/index.js +10 -1
- package/dist/views/CreateFirstUser/index.js.map +1 -1
- package/package.json +6 -6
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/layouts/Root/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAKpD,OAAO,8BAA8B,CAAA;AAKrC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,uCAAuC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/layouts/Root/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAKpD,OAAO,8BAA8B,CAAA;AAKrC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,uCAAuC,CAAA;AAO9C,eAAO,MAAM,QAAQ;;;CAGpB,CAAA;AAED,eAAO,MAAM,UAAU,yCAGpB;IACD,QAAQ,EAAE,MAAM,SAAS,CAAA;IACzB,MAAM,EAAE,QAAQ,eAAe,CAAC,CAAA;CACjC,+BAyEA,CAAA"}
|
|
@@ -6,6 +6,7 @@ import { headers as getHeaders, cookies as nextCookies } from 'next/headers.js';
|
|
|
6
6
|
import { parseCookies } from 'payload/auth';
|
|
7
7
|
import { createClientConfig } from 'payload/config';
|
|
8
8
|
import React from 'react';
|
|
9
|
+
import { getPayloadHMR } from '../../utilities/getPayloadHMR.js';
|
|
9
10
|
import { getRequestLanguage } from '../../utilities/getRequestLanguage.js';
|
|
10
11
|
import { DefaultEditView } from '../../views/Edit/Default/index.js';
|
|
11
12
|
import { DefaultListView } from '../../views/List/Default/index.js';
|
|
@@ -22,6 +23,9 @@ export const RootLayout = async ({ children, config: configPromise })=>{
|
|
|
22
23
|
cookies,
|
|
23
24
|
headers
|
|
24
25
|
});
|
|
26
|
+
const payload = await getPayloadHMR({
|
|
27
|
+
config
|
|
28
|
+
});
|
|
25
29
|
const i18n = await initI18n({
|
|
26
30
|
config: config.i18n,
|
|
27
31
|
context: 'client',
|
|
@@ -55,7 +59,8 @@ export const RootLayout = async ({ children, config: configPromise })=>{
|
|
|
55
59
|
DefaultListView,
|
|
56
60
|
children,
|
|
57
61
|
config,
|
|
58
|
-
i18n
|
|
62
|
+
i18n,
|
|
63
|
+
payload
|
|
59
64
|
});
|
|
60
65
|
return /*#__PURE__*/ React.createElement("html", {
|
|
61
66
|
dir: dir,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/layouts/Root/index.tsx"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { SanitizedConfig } from 'payload/types'\n\nimport { rtlLanguages } from '@payloadcms/translations'\nimport { initI18n } from '@payloadcms/translations'\nimport { RootProvider } from '@payloadcms/ui/providers/Root'\nimport '@payloadcms/ui/scss/app.scss'\nimport { buildComponentMap } from '@payloadcms/ui/utilities/buildComponentMap'\nimport { headers as getHeaders, cookies as nextCookies } from 'next/headers.js'\nimport { parseCookies } from 'payload/auth'\nimport { createClientConfig } from 'payload/config'\nimport React from 'react'\nimport 'react-toastify/dist/ReactToastify.css'\n\nimport { getRequestLanguage } from '../../utilities/getRequestLanguage.js'\nimport { DefaultEditView } from '../../views/Edit/Default/index.js'\nimport { DefaultListView } from '../../views/List/Default/index.js'\n\nexport const metadata = {\n description: 'Generated by Next.js',\n title: 'Next.js',\n}\n\nexport const RootLayout = async ({\n children,\n config: configPromise,\n}: {\n children: React.ReactNode\n config: Promise<SanitizedConfig>\n}) => {\n const config = await configPromise\n\n const headers = getHeaders()\n const cookies = parseCookies(headers)\n\n const languageCode = getRequestLanguage({\n config,\n cookies,\n headers,\n })\n\n const i18n = await initI18n({ config: config.i18n, context: 'client', language: languageCode })\n const clientConfig = await createClientConfig({ config, t: i18n.t })\n\n const dir = (rtlLanguages as unknown as AcceptedLanguages[]).includes(languageCode)\n ? 'RTL'\n : 'LTR'\n\n const languageOptions = Object.entries(config.i18n.supportedLanguages || {}).reduce(\n (acc, [language, languageConfig]) => {\n if (Object.keys(config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language,\n })\n }\n\n return acc\n },\n [],\n )\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async function switchLanguageServerAction(lang: string): Promise<void> {\n 'use server'\n nextCookies().set({\n name: `${config.cookiePrefix || 'payload'}-lng`,\n path: '/',\n value: lang,\n })\n }\n\n const { componentMap, wrappedChildren } = buildComponentMap({\n DefaultEditView,\n DefaultListView,\n children,\n config,\n i18n,\n })\n\n return (\n <html dir={dir} lang={languageCode}>\n <body>\n <RootProvider\n componentMap={componentMap}\n config={clientConfig}\n dateFNSKey={i18n.dateFNSKey}\n fallbackLang={clientConfig.i18n.fallbackLanguage}\n languageCode={languageCode}\n languageOptions={languageOptions}\n // eslint-disable-next-line react/jsx-no-bind\n switchLanguageServerAction={switchLanguageServerAction}\n translations={i18n.translations}\n >\n {wrappedChildren}\n </RootProvider>\n <div id=\"portal\" />\n </body>\n </html>\n )\n}\n"],"names":["rtlLanguages","initI18n","RootProvider","buildComponentMap","headers","getHeaders","cookies","nextCookies","parseCookies","createClientConfig","React","getRequestLanguage","DefaultEditView","DefaultListView","metadata","description","title","RootLayout","children","config","configPromise","languageCode","i18n","context","language","clientConfig","t","dir","includes","languageOptions","Object","entries","supportedLanguages","reduce","acc","languageConfig","keys","push","label","translations","general","thisLanguage","value","switchLanguageServerAction","lang","set","name","cookiePrefix","path","componentMap","wrappedChildren","html","body","dateFNSKey","fallbackLang","fallbackLanguage","div","id"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/layouts/Root/index.tsx"],"sourcesContent":["import type { AcceptedLanguages } from '@payloadcms/translations'\nimport type { SanitizedConfig } from 'payload/types'\n\nimport { rtlLanguages } from '@payloadcms/translations'\nimport { initI18n } from '@payloadcms/translations'\nimport { RootProvider } from '@payloadcms/ui/providers/Root'\nimport '@payloadcms/ui/scss/app.scss'\nimport { buildComponentMap } from '@payloadcms/ui/utilities/buildComponentMap'\nimport { headers as getHeaders, cookies as nextCookies } from 'next/headers.js'\nimport { parseCookies } from 'payload/auth'\nimport { createClientConfig } from 'payload/config'\nimport React from 'react'\nimport 'react-toastify/dist/ReactToastify.css'\n\nimport { getPayloadHMR } from '../../utilities/getPayloadHMR.js'\nimport { getRequestLanguage } from '../../utilities/getRequestLanguage.js'\nimport { DefaultEditView } from '../../views/Edit/Default/index.js'\nimport { DefaultListView } from '../../views/List/Default/index.js'\n\nexport const metadata = {\n description: 'Generated by Next.js',\n title: 'Next.js',\n}\n\nexport const RootLayout = async ({\n children,\n config: configPromise,\n}: {\n children: React.ReactNode\n config: Promise<SanitizedConfig>\n}) => {\n const config = await configPromise\n\n const headers = getHeaders()\n const cookies = parseCookies(headers)\n\n const languageCode = getRequestLanguage({\n config,\n cookies,\n headers,\n })\n\n const payload = await getPayloadHMR({ config })\n const i18n = await initI18n({ config: config.i18n, context: 'client', language: languageCode })\n const clientConfig = await createClientConfig({ config, t: i18n.t })\n\n const dir = (rtlLanguages as unknown as AcceptedLanguages[]).includes(languageCode)\n ? 'RTL'\n : 'LTR'\n\n const languageOptions = Object.entries(config.i18n.supportedLanguages || {}).reduce(\n (acc, [language, languageConfig]) => {\n if (Object.keys(config.i18n.supportedLanguages).includes(language)) {\n acc.push({\n label: languageConfig.translations.general.thisLanguage,\n value: language,\n })\n }\n\n return acc\n },\n [],\n )\n\n // eslint-disable-next-line @typescript-eslint/require-await\n async function switchLanguageServerAction(lang: string): Promise<void> {\n 'use server'\n nextCookies().set({\n name: `${config.cookiePrefix || 'payload'}-lng`,\n path: '/',\n value: lang,\n })\n }\n\n const { componentMap, wrappedChildren } = buildComponentMap({\n DefaultEditView,\n DefaultListView,\n children,\n config,\n i18n,\n payload,\n })\n\n return (\n <html dir={dir} lang={languageCode}>\n <body>\n <RootProvider\n componentMap={componentMap}\n config={clientConfig}\n dateFNSKey={i18n.dateFNSKey}\n fallbackLang={clientConfig.i18n.fallbackLanguage}\n languageCode={languageCode}\n languageOptions={languageOptions}\n // eslint-disable-next-line react/jsx-no-bind\n switchLanguageServerAction={switchLanguageServerAction}\n translations={i18n.translations}\n >\n {wrappedChildren}\n </RootProvider>\n <div id=\"portal\" />\n </body>\n </html>\n )\n}\n"],"names":["rtlLanguages","initI18n","RootProvider","buildComponentMap","headers","getHeaders","cookies","nextCookies","parseCookies","createClientConfig","React","getPayloadHMR","getRequestLanguage","DefaultEditView","DefaultListView","metadata","description","title","RootLayout","children","config","configPromise","languageCode","payload","i18n","context","language","clientConfig","t","dir","includes","languageOptions","Object","entries","supportedLanguages","reduce","acc","languageConfig","keys","push","label","translations","general","thisLanguage","value","switchLanguageServerAction","lang","set","name","cookiePrefix","path","componentMap","wrappedChildren","html","body","dateFNSKey","fallbackLang","fallbackLanguage","div","id"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,YAAY,QAAQ,2BAA0B;AACvD,SAASC,QAAQ,QAAQ,2BAA0B;AACnD,SAASC,YAAY,QAAQ,gCAA+B;AAE5D,SAASC,iBAAiB,QAAQ,6CAA4C;AAC9E,SAASC,WAAWC,UAAU,EAAEC,WAAWC,WAAW,QAAQ,kBAAiB;AAC/E,SAASC,YAAY,QAAQ,eAAc;AAC3C,SAASC,kBAAkB,QAAQ,iBAAgB;AACnD,OAAOC,WAAW,QAAO;AAGzB,SAASC,aAAa,QAAQ,mCAAkC;AAChE,SAASC,kBAAkB,QAAQ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kB;QAC1DU;QACAC;QACAK;QACAC;QACAI;QACAD;IACF;IAEA,qBACE,oBAAC8B;QAAKxB,KAAKA;QAAKiB,MAAMxB;qBACpB,oBAACgC,4BACC,oBAACpD;QACCiD,cAAcA;QACd/B,QAAQO;QACR4B,YAAY/B,KAAK+B,UAAU;QAC3BC,cAAc7B,aAAaH,IAAI,CAACiC,gBAAgB;QAChDnC,cAAcA;QACdS,iBAAiBA;QACjB,6CAA6C;QAC7Cc,4BAA4BA;QAC5BJ,cAAcjB,KAAKiB,YAAY;OAE9BW,gCAEH,oBAACM;QAAIC,IAAG;;AAIhB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequest }) => {\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n } catch (err) {\n return Response.json(\n {\n message: 'There was an error building form state',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","length","fields","globals","find","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","depth","limit","where","key","equals","docs","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","OK","err"],"rangeMappings":";;;;;;;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AOI,MAAM,CAACvB;QAClC;QAEA,MAAMwB,SAAS,MAAM5E,qBAAqB;YACxCqC;YACAvB;YACA2B;YACAtB;YACA4C,aAAaZ,kBAAkB;gBAAER,QAAQ,CAAC;YAAE;YAC5CnC;QACF;QAEA,OAAOwB,SAASC,IAAI,CAAC2C,QAAQ;YAC3B1C,QAAQhC,WAAW2E,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAO9C,SAASC,IAAI,CAClB;YACEgB,SAAS;QACX,GACA;YACEf,QAAQhC,WAAWgD,WAAW;QAChC;IAEJ;AACF,EAAC"}
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/rest/buildFormState.ts"],"sourcesContent":["import type { BuildFormStateArgs } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport type { DocumentPreferences, Field, PayloadRequest, TypeWithID } from 'payload/types'\n\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { reduceFieldsToValues } from '@payloadcms/ui/utilities/reduceFieldsToValues'\nimport httpStatus from 'http-status'\n\nimport type { FieldSchemaMap } from '../../utilities/buildFieldSchemaMap/types.js'\n\nimport { buildFieldSchemaMap } from '../../utilities/buildFieldSchemaMap/index.js'\n\nlet cached = global._payload_fieldSchemaMap\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload_fieldSchemaMap = null\n}\n\nexport const getFieldSchemaMap = (req: PayloadRequest): FieldSchemaMap => {\n if (cached && process.env.NODE_ENV !== 'development') {\n return cached\n }\n\n cached = buildFieldSchemaMap(req)\n\n return cached\n}\n\nexport const buildFormState = async ({ req }: { req: PayloadRequest }) => {\n try {\n const reqData: BuildFormStateArgs = req.data as BuildFormStateArgs\n const { collectionSlug, formState, globalSlug, locale, operation, schemaPath } = reqData\n\n const incomingUserSlug = req.user?.collection\n const adminUserSlug = req.payload.config.admin.user\n\n // If we have a user slug, test it against the functions\n if (incomingUserSlug) {\n const adminAccessFunction = req.payload.collections[incomingUserSlug].config.access?.admin\n\n // Run the admin access function from the config if it exists\n if (adminAccessFunction) {\n const canAccessAdmin = await adminAccessFunction({ req })\n\n if (!canAccessAdmin) {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n // Match the user collection to the global admin config\n } else if (adminUserSlug !== incomingUserSlug) {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n } else {\n return Response.json(null, {\n status: httpStatus.UNAUTHORIZED,\n })\n }\n\n const fieldSchemaMap = getFieldSchemaMap(req)\n\n const id = collectionSlug ? reqData.id : undefined\n const schemaPathSegments = schemaPath.split('.')\n\n let fieldSchema: Field[]\n\n if (schemaPathSegments.length === 1) {\n if (req.payload.collections[schemaPath]) {\n fieldSchema = req.payload.collections[schemaPath].config.fields\n } else {\n fieldSchema = req.payload.config.globals.find(\n (global) => global.slug === schemaPath,\n )?.fields\n }\n } else if (fieldSchemaMap.has(schemaPath)) {\n fieldSchema = fieldSchemaMap.get(schemaPath)\n }\n\n if (!fieldSchema) {\n return Response.json(\n {\n message: 'Could not find field schema for given path',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n let docPreferences = reqData.docPreferences\n let data = reqData.data\n\n const promises: {\n data?: Promise<void>\n preferences?: Promise<void>\n } = {}\n\n // If the request does not include doc preferences,\n // we should fetch them. This is useful for DocumentInfoProvider\n // as it reduces the amount of client-side fetches necessary\n // when we fetch data for the Edit view\n if (!docPreferences) {\n let preferencesKey\n\n if (collectionSlug && id) {\n preferencesKey = `collection-${collectionSlug}-${id}`\n }\n\n if (globalSlug) {\n preferencesKey = `global-${globalSlug}`\n }\n\n if (preferencesKey) {\n const fetchPreferences = async () => {\n const preferencesResult = (await req.payload.find({\n collection: 'payload-preferences',\n depth: 0,\n limit: 1,\n where: {\n key: {\n equals: preferencesKey,\n },\n },\n })) as unknown as { docs: { value: DocumentPreferences }[] }\n\n if (preferencesResult?.docs?.[0]?.value) docPreferences = preferencesResult.docs[0].value\n }\n\n promises.preferences = fetchPreferences()\n }\n }\n\n // If there is a form state,\n // then we can deduce data from that form state\n if (formState) data = reduceFieldsToValues(formState, true)\n\n // If we do not have data at this point,\n // we can fetch it. This is useful for DocumentInfoProvider\n // to reduce the amount of fetches required\n if (!data) {\n const fetchData = async () => {\n let resolvedData: TypeWithID\n\n if (collectionSlug && id) {\n resolvedData = await req.payload.findByID({\n id,\n collection: collectionSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n if (globalSlug && schemaPath === globalSlug) {\n resolvedData = await req.payload.findGlobal({\n slug: globalSlug,\n depth: 0,\n draft: true,\n fallbackLocale: null,\n locale,\n overrideAccess: false,\n user: req.user,\n })\n }\n\n data = resolvedData\n }\n\n promises.data = fetchData()\n }\n\n if (Object.keys(promises).length > 0) {\n await Promise.all(Object.values(promises))\n }\n\n const result = await buildStateFromSchema({\n id,\n data,\n fieldSchema,\n operation,\n preferences: docPreferences || { fields: {} },\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n } catch (err) {\n return Response.json(\n {\n message: 'There was an error building form state',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n}\n"],"names":["buildStateFromSchema","reduceFieldsToValues","httpStatus","buildFieldSchemaMap","cached","global","_payload_fieldSchemaMap","getFieldSchemaMap","req","process","env","NODE_ENV","buildFormState","reqData","data","collectionSlug","formState","globalSlug","locale","operation","schemaPath","incomingUserSlug","user","collection","adminUserSlug","payload","config","admin","adminAccessFunction","collections","access","canAccessAdmin","Response","json","status","UNAUTHORIZED","fieldSchemaMap","id","undefined","schemaPathSegments","split","fieldSchema","length","fields","globals","find","slug","has","get","message","BAD_REQUEST","docPreferences","promises","preferencesKey","fetchPreferences","preferencesResult","depth","limit","where","key","equals","docs","value","preferences","fetchData","resolvedData","findByID","draft","fallbackLocale","overrideAccess","findGlobal","Object","keys","Promise","all","values","result","OK","err"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;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MAAM,CAACvB;QAClC;QAEA,MAAMwB,SAAS,MAAM5E,qBAAqB;YACxCqC;YACAvB;YACA2B;YACAtB;YACA4C,aAAaZ,kBAAkB;gBAAER,QAAQ,CAAC;YAAE;YAC5CnC;QACF;QAEA,OAAOwB,SAASC,IAAI,CAAC2C,QAAQ;YAC3B1C,QAAQhC,WAAW2E,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAO9C,SAASC,IAAI,CAClB;YACEgB,SAAS;QACX,GACA;YACEf,QAAQhC,WAAWgD,WAAW;QAChC;IAEJ;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/deleteByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"deleteByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/deleteByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,UAAU,EAAE,4BAyCxB,CAAA"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { deleteByIDOperation } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
-
|
|
4
|
+
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
5
|
+
export const deleteByID = async ({ id: incomingID, collection, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
8
|
+
const id = sanitizeCollectionID({
|
|
9
|
+
id: incomingID,
|
|
10
|
+
collectionSlug: collection.config.slug,
|
|
11
|
+
payload: req.payload
|
|
12
|
+
});
|
|
7
13
|
const doc = await deleteByIDOperation({
|
|
8
14
|
id,
|
|
9
15
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/deleteByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { deleteByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const deleteByID: CollectionRouteHandlerWithID = async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/deleteByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { deleteByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const deleteByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const doc = await deleteByIDOperation({\n id,\n collection,\n depth: isNumber(depth) ? depth : undefined,\n req,\n })\n\n if (!doc) {\n return Response.json(\n {\n message: req.t('general:notFound'),\n },\n {\n status: httpStatus.NOT_FOUND,\n },\n )\n }\n\n return Response.json(\n {\n doc,\n message: req.t('general:deletedSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","deleteByIDOperation","isNumber","sanitizeCollectionID","deleteByID","id","incomingID","collection","req","searchParams","depth","get","collectionSlug","config","slug","payload","doc","undefined","Response","json","message","t","status","NOT_FOUND","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,mBAAmB,QAAQ,qBAAoB;AACxD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,aAA2C,OAAO,EAC7DC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJM,gBAAgBL,WAAWM,MAAM,CAACC,IAAI;QACtCC,SAASP,IAAIO,OAAO;IACtB;IAEA,MAAMC,MAAM,MAAMf,oBAAoB;QACpCI;QACAE;QACAG,OAAOR,SAASQ,SAASA,QAAQO;QACjCT;IACF;IAEA,IAAI,CAACQ,KAAK;QACR,OAAOE,SAASC,IAAI,CAClB;YACEC,SAASZ,IAAIa,CAAC,CAAC;QACjB,GACA;YACEC,QAAQtB,WAAWuB,SAAS;QAC9B;IAEJ;IAEA,OAAOL,SAASC,IAAI,CAClB;QACEH;QACAI,SAASZ,IAAIa,CAAC,CAAC;IACjB,GACA;QACEC,QAAQtB,WAAWwB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/duplicate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"duplicate.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/duplicate.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,SAAS,EAAE,4BAqCvB,CAAA"}
|
|
@@ -2,11 +2,17 @@ import { getTranslation } from '@payloadcms/translations';
|
|
|
2
2
|
import httpStatus from 'http-status';
|
|
3
3
|
import { duplicateOperation } from 'payload/operations';
|
|
4
4
|
import { isNumber } from 'payload/utilities';
|
|
5
|
-
|
|
5
|
+
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
6
|
+
export const duplicate = async ({ id: incomingID, collection, req })=>{
|
|
6
7
|
const { searchParams } = req;
|
|
7
8
|
const depth = searchParams.get('depth');
|
|
8
9
|
// draft defaults to true, unless explicitly set requested as false to prevent the newly duplicated document from being published
|
|
9
10
|
const draft = searchParams.get('draft') !== 'false';
|
|
11
|
+
const id = sanitizeCollectionID({
|
|
12
|
+
id: incomingID,
|
|
13
|
+
collectionSlug: collection.config.slug,
|
|
14
|
+
payload: req.payload
|
|
15
|
+
});
|
|
10
16
|
const doc = await duplicateOperation({
|
|
11
17
|
id,
|
|
12
18
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/duplicate.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport httpStatus from 'http-status'\nimport { duplicateOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const duplicate: CollectionRouteHandlerWithID = async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/duplicate.ts"],"sourcesContent":["import { getTranslation } from '@payloadcms/translations'\nimport httpStatus from 'http-status'\nimport { duplicateOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const duplicate: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n // draft defaults to true, unless explicitly set requested as false to prevent the newly duplicated document from being published\n const draft = searchParams.get('draft') !== 'false'\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const doc = await duplicateOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n req,\n })\n\n const message = req.t('general:successfullyDuplicated', {\n label: getTranslation(collection.config.labels.singular, req.i18n),\n })\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["getTranslation","httpStatus","duplicateOperation","isNumber","sanitizeCollectionID","duplicate","id","incomingID","collection","req","searchParams","depth","get","draft","collectionSlug","config","slug","payload","doc","Number","undefined","message","t","label","labels","singular","i18n","Response","json","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,cAAc,QAAQ,2BAA0B;AACzD,OAAOC,gBAAgB,cAAa;AACpC,SAASC,kBAAkB,QAAQ,qBAAoB;AACvD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,YAA0C,OAAO,EAC5DC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAC/B,iIAAiI;IACjI,MAAMC,QAAQH,aAAaE,GAAG,CAAC,aAAa;IAE5C,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJO,gBAAgBN,WAAWO,MAAM,CAACC,IAAI;QACtCC,SAASR,IAAIQ,OAAO;IACtB;IAEA,MAAMC,MAAM,MAAMhB,mBAAmB;QACnCI;QACAE;QACAG,OAAOR,SAASQ,SAASQ,OAAOR,SAASS;QACzCP;QACAJ;IACF;IAEA,MAAMY,UAAUZ,IAAIa,CAAC,CAAC,kCAAkC;QACtDC,OAAOvB,eAAeQ,WAAWO,MAAM,CAACS,MAAM,CAACC,QAAQ,EAAEhB,IAAIiB,IAAI;IACnE;IAEA,OAAOC,SAASC,IAAI,CAClB;QACEV;QACAG;IACF,GACA;QACEQ,QAAQ5B,WAAW6B,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/findByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"findByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/findByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,QAAQ,EAAE,4BAyBtB,CAAA"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { findByIDOperation } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
-
|
|
4
|
+
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
5
|
+
export const findByID = async ({ id: incomingID, collection, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
8
|
+
const id = sanitizeCollectionID({
|
|
9
|
+
id: incomingID,
|
|
10
|
+
collectionSlug: collection.config.slug,
|
|
11
|
+
payload: req.payload
|
|
12
|
+
});
|
|
7
13
|
const result = await findByIDOperation({
|
|
8
14
|
id,
|
|
9
15
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/findByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const findByID: CollectionRouteHandlerWithID = async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/findByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const findByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const result = await findByIDOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findByIDOperation","isNumber","sanitizeCollectionID","findByID","id","incomingID","collection","req","searchParams","depth","get","collectionSlug","config","slug","payload","result","Number","undefined","draft","Response","json","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,iBAAiB,QAAQ,qBAAoB;AACtD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,WAAyC,OAAO,EAC3DC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJM,gBAAgBL,WAAWM,MAAM,CAACC,IAAI;QACtCC,SAASP,IAAIO,OAAO;IACtB;IAEA,MAAMC,SAAS,MAAMf,kBAAkB;QACrCI;QACAE;QACAG,OAAOR,SAASQ,SAASO,OAAOP,SAASQ;QACzCC,OAAOV,aAAaE,GAAG,CAAC,aAAa;QACrCH;IACF;IAEA,OAAOY,SAASC,IAAI,CAACL,QAAQ;QAC3BM,QAAQtB,WAAWuB,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/findVersionByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"findVersionByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/findVersionByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,eAAe,EAAE,4BAwB7B,CAAA"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { findVersionByIDOperation } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
-
|
|
4
|
+
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
5
|
+
export const findVersionByID = async ({ id: incomingID, collection, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
8
|
+
const id = sanitizeCollectionID({
|
|
9
|
+
id: incomingID,
|
|
10
|
+
collectionSlug: collection.config.slug,
|
|
11
|
+
payload: req.payload
|
|
12
|
+
});
|
|
7
13
|
const result = await findVersionByIDOperation({
|
|
8
14
|
id,
|
|
9
15
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findVersionByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const findVersionByID: CollectionRouteHandlerWithID = async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/findVersionByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findVersionByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const findVersionByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const result = await findVersionByIDOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n req,\n })\n\n return Response.json(result, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","findVersionByIDOperation","isNumber","sanitizeCollectionID","findVersionByID","id","incomingID","collection","req","searchParams","depth","get","collectionSlug","config","slug","payload","result","Number","undefined","Response","json","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,wBAAwB,QAAQ,qBAAoB;AAC7D,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,kBAAgD,OAAO,EAClEC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJM,gBAAgBL,WAAWM,MAAM,CAACC,IAAI;QACtCC,SAASP,IAAIO,OAAO;IACtB;IAEA,MAAMC,SAAS,MAAMf,yBAAyB;QAC5CI;QACAE;QACAG,OAAOR,SAASQ,SAASO,OAAOP,SAASQ;QACzCV;IACF;IAEA,OAAOW,SAASC,IAAI,CAACJ,QAAQ;QAC3BK,QAAQrB,WAAWsB,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/preview.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/preview.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,OAAO,EAAE,4BAuCrB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
|
+
import { extractJWT } from 'payload/auth';
|
|
2
3
|
import { findByIDOperation } from 'payload/operations';
|
|
3
4
|
import { isNumber } from 'payload/utilities';
|
|
4
5
|
import { routeError } from '../routeError.js';
|
|
@@ -14,11 +15,13 @@ export const preview = async ({ id, collection, req })=>{
|
|
|
14
15
|
});
|
|
15
16
|
let previewURL;
|
|
16
17
|
const generatePreviewURL = req.payload.config.collections.find((config)=>config.slug === collection.config.slug)?.admin?.preview;
|
|
18
|
+
const token = extractJWT(req);
|
|
17
19
|
if (typeof generatePreviewURL === 'function') {
|
|
18
20
|
try {
|
|
19
21
|
previewURL = await generatePreviewURL(result, {
|
|
20
22
|
locale: req.locale,
|
|
21
|
-
|
|
23
|
+
req,
|
|
24
|
+
token
|
|
22
25
|
});
|
|
23
26
|
} catch (err) {
|
|
24
27
|
routeError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { routeError } from '../routeError.js'\n\nexport const preview: CollectionRouteHandlerWithID = async ({ id, collection, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findByIDOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.collections.find(\n (config) => config.slug === collection.config.slug,\n )?.admin?.preview\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(result, {\n locale: req.locale,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { findByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { routeError } from '../routeError.js'\n\nexport const preview: CollectionRouteHandlerWithID = async ({ id, collection, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findByIDOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.collections.find(\n (config) => config.slug === collection.config.slug,\n )?.admin?.preview\n\n const token = extractJWT(req)\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(result, {\n locale: req.locale,\n req,\n token,\n })\n } catch (err) {\n routeError({\n collection,\n err,\n req,\n })\n }\n }\n\n return Response.json(previewURL, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","extractJWT","findByIDOperation","isNumber","routeError","preview","id","collection","req","searchParams","depth","get","result","Number","undefined","draft","previewURL","generatePreviewURL","payload","config","collections","find","slug","admin","token","locale","err","Response","json","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,iBAAiB,QAAQ,qBAAoB;AACtD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,UAAU,QAAQ,mBAAkB;AAE7C,OAAO,MAAMC,UAAwC,OAAO,EAAEC,EAAE,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACjF,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMV,kBAAkB;QACrCI;QACAC;QACAG,OAAOP,SAASO,SAASG,OAAOH,SAASI;QACzCC,OAAON,aAAaE,GAAG,CAAC,aAAa;QACrCH;IACF;IAEA,IAAIQ;IAEJ,MAAMC,qBAAqBT,IAAIU,OAAO,CAACC,MAAM,CAACC,WAAW,CAACC,IAAI,CAC5D,CAACF,SAAWA,OAAOG,IAAI,KAAKf,WAAWY,MAAM,CAACG,IAAI,GACjDC,OAAOlB;IAEV,MAAMmB,QAAQvB,WAAWO;IAEzB,IAAI,OAAOS,uBAAuB,YAAY;QAC5C,IAAI;YACFD,aAAa,MAAMC,mBAAmBL,QAAQ;gBAC5Ca,QAAQjB,IAAIiB,MAAM;gBAClBjB;gBACAgB;YACF;QACF,EAAE,OAAOE,KAAK;YACZtB,WAAW;gBACTG;gBACAmB;gBACAlB;YACF;QACF;IACF;IAEA,OAAOmB,SAASC,IAAI,CAACZ,YAAY;QAC/Ba,QAAQ7B,WAAW8B,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/restoreVersion.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"restoreVersion.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/restoreVersion.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,cAAc,EAAE,4BA8B5B,CAAA"}
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { restoreVersionOperation } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
-
|
|
4
|
+
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
5
|
+
export const restoreVersion = async ({ id: incomingID, collection, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
8
|
+
const id = sanitizeCollectionID({
|
|
9
|
+
id: incomingID,
|
|
10
|
+
collectionSlug: collection.config.slug,
|
|
11
|
+
payload: req.payload
|
|
12
|
+
});
|
|
7
13
|
const result = await restoreVersionOperation({
|
|
8
14
|
id,
|
|
9
15
|
collection,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/restoreVersion.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { restoreVersionOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const restoreVersion: CollectionRouteHandlerWithID = async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/restoreVersion.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { restoreVersionOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const restoreVersion: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const result = await restoreVersionOperation({\n id,\n collection,\n depth: isNumber(depth) ? Number(depth) : undefined,\n req,\n })\n\n return Response.json(\n {\n ...result,\n message: req.t('version:restoredSuccessfully'),\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","restoreVersionOperation","isNumber","sanitizeCollectionID","restoreVersion","id","incomingID","collection","req","searchParams","depth","get","collectionSlug","config","slug","payload","result","Number","undefined","Response","json","message","t","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,uBAAuB,QAAQ,qBAAoB;AAC5D,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,iBAA+C,OAAO,EACjEC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJM,gBAAgBL,WAAWM,MAAM,CAACC,IAAI;QACtCC,SAASP,IAAIO,OAAO;IACtB;IAEA,MAAMC,SAAS,MAAMf,wBAAwB;QAC3CI;QACAE;QACAG,OAAOR,SAASQ,SAASO,OAAOP,SAASQ;QACzCV;IACF;IAEA,OAAOW,SAASC,IAAI,CAClB;QACE,GAAGJ,MAAM;QACTK,SAASb,IAAIc,CAAC,CAAC;IACjB,GACA;QACEC,QAAQvB,WAAWwB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/updateByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"updateByID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/collections/updateByID.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,4BAA4B,EAAE,MAAM,aAAa,CAAA;AAI/D,eAAO,MAAM,UAAU,EAAE,4BAwCxB,CAAA"}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
2
|
import { updateByIDOperation } from 'payload/operations';
|
|
3
3
|
import { isNumber } from 'payload/utilities';
|
|
4
|
-
|
|
4
|
+
import { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js';
|
|
5
|
+
export const updateByID = async ({ id: incomingID, collection, req })=>{
|
|
5
6
|
const { searchParams } = req;
|
|
6
7
|
const depth = searchParams.get('depth');
|
|
7
8
|
const autosave = searchParams.get('autosave') === 'true';
|
|
8
9
|
const draft = searchParams.get('draft') === 'true';
|
|
10
|
+
const id = sanitizeCollectionID({
|
|
11
|
+
id: incomingID,
|
|
12
|
+
collectionSlug: collection.config.slug,
|
|
13
|
+
payload: req.payload
|
|
14
|
+
});
|
|
9
15
|
const doc = await updateByIDOperation({
|
|
10
16
|
id,
|
|
11
17
|
autosave,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/collections/updateByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nexport const updateByID: CollectionRouteHandlerWithID = async ({
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/collections/updateByID.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { updateByIDOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { CollectionRouteHandlerWithID } from '../types.js'\n\nimport { sanitizeCollectionID } from '../utilities/sanitizeCollectionID.js'\n\nexport const updateByID: CollectionRouteHandlerWithID = async ({\n id: incomingID,\n collection,\n req,\n}) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n const autosave = searchParams.get('autosave') === 'true'\n const draft = searchParams.get('draft') === 'true'\n\n const id = sanitizeCollectionID({\n id: incomingID,\n collectionSlug: collection.config.slug,\n payload: req.payload,\n })\n\n const doc = await updateByIDOperation({\n id,\n autosave,\n collection,\n data: req.data,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft,\n req,\n })\n\n let message = req.t('general:updatedSuccessfully')\n\n if (draft) message = req.t('version:draftSavedSuccessfully')\n if (autosave) message = req.t('version:autosavedSuccessfully')\n\n return Response.json(\n {\n doc,\n message,\n },\n {\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","updateByIDOperation","isNumber","sanitizeCollectionID","updateByID","id","incomingID","collection","req","searchParams","depth","get","autosave","draft","collectionSlug","config","slug","payload","doc","data","Number","undefined","message","t","Response","json","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,mBAAmB,QAAQ,qBAAoB;AACxD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,oBAAoB,QAAQ,uCAAsC;AAE3E,OAAO,MAAMC,aAA2C,OAAO,EAC7DC,IAAIC,UAAU,EACdC,UAAU,EACVC,GAAG,EACJ;IACC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAC/B,MAAMC,WAAWH,aAAaE,GAAG,CAAC,gBAAgB;IAClD,MAAME,QAAQJ,aAAaE,GAAG,CAAC,aAAa;IAE5C,MAAMN,KAAKF,qBAAqB;QAC9BE,IAAIC;QACJQ,gBAAgBP,WAAWQ,MAAM,CAACC,IAAI;QACtCC,SAAST,IAAIS,OAAO;IACtB;IAEA,MAAMC,MAAM,MAAMjB,oBAAoB;QACpCI;QACAO;QACAL;QACAY,MAAMX,IAAIW,IAAI;QACdT,OAAOR,SAASQ,SAASU,OAAOV,SAASW;QACzCR;QACAL;IACF;IAEA,IAAIc,UAAUd,IAAIe,CAAC,CAAC;IAEpB,IAAIV,OAAOS,UAAUd,IAAIe,CAAC,CAAC;IAC3B,IAAIX,UAAUU,UAAUd,IAAIe,CAAC,CAAC;IAE9B,OAAOC,SAASC,IAAI,CAClB;QACEP;QACAI;IACF,GACA;QACEI,QAAQ1B,WAAW2B,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/preview.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"preview.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/globals/preview.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAIrD,eAAO,MAAM,OAAO,EAAE,kBAsCrB,CAAA"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import httpStatus from 'http-status';
|
|
2
|
+
import { extractJWT } from 'payload/auth';
|
|
2
3
|
import { findOneOperation } from 'payload/operations';
|
|
3
4
|
import { isNumber } from 'payload/utilities';
|
|
4
5
|
import { routeError } from '../routeError.js';
|
|
@@ -14,11 +15,13 @@ export const preview = async ({ globalConfig, req })=>{
|
|
|
14
15
|
});
|
|
15
16
|
let previewURL;
|
|
16
17
|
const generatePreviewURL = req.payload.config.globals.find((config)=>config.slug === globalConfig.slug)?.admin?.preview;
|
|
18
|
+
const token = extractJWT(req);
|
|
17
19
|
if (typeof generatePreviewURL === 'function') {
|
|
18
20
|
try {
|
|
19
21
|
previewURL = await generatePreviewURL(result, {
|
|
20
22
|
locale: req.locale,
|
|
21
|
-
|
|
23
|
+
req,
|
|
24
|
+
token
|
|
22
25
|
});
|
|
23
26
|
} catch (err) {
|
|
24
27
|
routeError({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/globals/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { findOneOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { routeError } from '../routeError.js'\n\nexport const preview: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.globals.find(\n (config) => config.slug === globalConfig.slug,\n )?.admin?.preview\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(result, {\n locale: req.locale,\n
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/globals/preview.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { extractJWT } from 'payload/auth'\nimport { findOneOperation } from 'payload/operations'\nimport { isNumber } from 'payload/utilities'\n\nimport type { GlobalRouteHandler } from '../types.js'\n\nimport { routeError } from '../routeError.js'\n\nexport const preview: GlobalRouteHandler = async ({ globalConfig, req }) => {\n const { searchParams } = req\n const depth = searchParams.get('depth')\n\n const result = await findOneOperation({\n slug: globalConfig.slug,\n depth: isNumber(depth) ? Number(depth) : undefined,\n draft: searchParams.get('draft') === 'true',\n globalConfig,\n req,\n })\n\n let previewURL: string\n\n const generatePreviewURL = req.payload.config.globals.find(\n (config) => config.slug === globalConfig.slug,\n )?.admin?.preview\n\n const token = extractJWT(req)\n\n if (typeof generatePreviewURL === 'function') {\n try {\n previewURL = await generatePreviewURL(result, {\n locale: req.locale,\n req,\n token,\n })\n } catch (err) {\n routeError({\n err,\n req,\n })\n }\n }\n\n return Response.json(previewURL, {\n status: httpStatus.OK,\n })\n}\n"],"names":["httpStatus","extractJWT","findOneOperation","isNumber","routeError","preview","globalConfig","req","searchParams","depth","get","result","slug","Number","undefined","draft","previewURL","generatePreviewURL","payload","config","globals","find","admin","token","locale","err","Response","json","status","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,UAAU,QAAQ,eAAc;AACzC,SAASC,gBAAgB,QAAQ,qBAAoB;AACrD,SAASC,QAAQ,QAAQ,oBAAmB;AAI5C,SAASC,UAAU,QAAQ,mBAAkB;AAE7C,OAAO,MAAMC,UAA8B,OAAO,EAAEC,YAAY,EAAEC,GAAG,EAAE;IACrE,MAAM,EAAEC,YAAY,EAAE,GAAGD;IACzB,MAAME,QAAQD,aAAaE,GAAG,CAAC;IAE/B,MAAMC,SAAS,MAAMT,iBAAiB;QACpCU,MAAMN,aAAaM,IAAI;QACvBH,OAAON,SAASM,SAASI,OAAOJ,SAASK;QACzCC,OAAOP,aAAaE,GAAG,CAAC,aAAa;QACrCJ;QACAC;IACF;IAEA,IAAIS;IAEJ,MAAMC,qBAAqBV,IAAIW,OAAO,CAACC,MAAM,CAACC,OAAO,CAACC,IAAI,CACxD,CAACF,SAAWA,OAAOP,IAAI,KAAKN,aAAaM,IAAI,GAC5CU,OAAOjB;IAEV,MAAMkB,QAAQtB,WAAWM;IAEzB,IAAI,OAAOU,uBAAuB,YAAY;QAC5C,IAAI;YACFD,aAAa,MAAMC,mBAAmBN,QAAQ;gBAC5Ca,QAAQjB,IAAIiB,MAAM;gBAClBjB;gBACAgB;YACF;QACF,EAAE,OAAOE,KAAK;YACZrB,WAAW;gBACTqB;gBACAlB;YACF;QACF;IACF;IAEA,OAAOmB,SAASC,IAAI,CAACX,YAAY;QAC/BY,QAAQ5B,WAAW6B,EAAE;IACvB;AACF,EAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Payload } from 'payload/types';
|
|
2
|
+
type Args = {
|
|
3
|
+
collectionSlug: string;
|
|
4
|
+
id: string;
|
|
5
|
+
payload: Payload;
|
|
6
|
+
};
|
|
7
|
+
export declare const sanitizeCollectionID: ({ id, collectionSlug, payload }: Args) => number | string;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=sanitizeCollectionID.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanitizeCollectionID.d.ts","sourceRoot":"","sources":["../../../../src/routes/rest/utilities/sanitizeCollectionID.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,KAAK,IAAI,GAAG;IACV,cAAc,EAAE,MAAM,CAAA;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,OAAO,EAAE,OAAO,CAAA;CACjB,CAAA;AAED,eAAO,MAAM,oBAAoB,oCAAqC,IAAI,KAAG,MAAM,GAAG,MAcrF,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const sanitizeCollectionID = ({ id, collectionSlug, payload })=>{
|
|
2
|
+
let sanitizedID = id;
|
|
3
|
+
const collection = payload.collections[collectionSlug];
|
|
4
|
+
// If default db ID type is a number, we should sanitize
|
|
5
|
+
let shouldSanitize = Boolean(payload.db.defaultIDType === 'number');
|
|
6
|
+
// UNLESS the customIDType for this collection is text.... then we leave it
|
|
7
|
+
if (shouldSanitize && collection.customIDType === 'text') shouldSanitize = false;
|
|
8
|
+
// If we still should sanitize, parse float
|
|
9
|
+
if (shouldSanitize) sanitizedID = parseFloat(sanitizedID);
|
|
10
|
+
return sanitizedID;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=sanitizeCollectionID.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/utilities/sanitizeCollectionID.ts"],"sourcesContent":["import type { Payload } from 'payload/types'\n\ntype Args = {\n collectionSlug: string\n id: string\n payload: Payload\n}\n\nexport const sanitizeCollectionID = ({ id, collectionSlug, payload }: Args): number | string => {\n let sanitizedID: number | string = id\n const collection = payload.collections[collectionSlug]\n\n // If default db ID type is a number, we should sanitize\n let shouldSanitize = Boolean(payload.db.defaultIDType === 'number')\n\n // UNLESS the customIDType for this collection is text.... then we leave it\n if (shouldSanitize && collection.customIDType === 'text') shouldSanitize = false\n\n // If we still should sanitize, parse float\n if (shouldSanitize) sanitizedID = parseFloat(sanitizedID)\n\n return sanitizedID\n}\n"],"names":["sanitizeCollectionID","id","collectionSlug","payload","sanitizedID","collection","collections","shouldSanitize","Boolean","db","defaultIDType","customIDType","parseFloat"],"rangeMappings":";;;;;;;;;;","mappings":"AAQA,OAAO,MAAMA,uBAAuB,CAAC,EAAEC,EAAE,EAAEC,cAAc,EAAEC,OAAO,EAAQ;IACxE,IAAIC,cAA+BH;IACnC,MAAMI,aAAaF,QAAQG,WAAW,CAACJ,eAAe;IAEtD,wDAAwD;IACxD,IAAIK,iBAAiBC,QAAQL,QAAQM,EAAE,CAACC,aAAa,KAAK;IAE1D,2EAA2E;IAC3E,IAAIH,kBAAkBF,WAAWM,YAAY,KAAK,QAAQJ,iBAAiB;IAE3E,2CAA2C;IAC3C,IAAIA,gBAAgBH,cAAcQ,WAAWR;IAE7C,OAAOA;AACT,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPayloadHMR.d.ts","sourceRoot":"","sources":["../../src/utilities/getPayloadHMR.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,OAAO,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAgBjD,eAAO,MAAM,aAAa,YAAmB,WAAW,KAAG,QAAQ,OAAO,
|
|
1
|
+
{"version":3,"file":"getPayloadHMR.d.ts","sourceRoot":"","sources":["../../src/utilities/getPayloadHMR.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,OAAO,EAAE,MAAM,SAAS,CAAA;AACtD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAA;AAgBjD,eAAO,MAAM,aAAa,YAAmB,WAAW,KAAG,QAAQ,OAAO,CAgFzE,CAAA"}
|
|
@@ -25,7 +25,8 @@ export const getPayloadHMR = async (options)=>{
|
|
|
25
25
|
cached.payload.config = config;
|
|
26
26
|
cached.payload.collections = config.collections.reduce((collections, collection)=>{
|
|
27
27
|
collections[collection.slug] = {
|
|
28
|
-
config: collection
|
|
28
|
+
config: collection,
|
|
29
|
+
customIDType: cached.payload.collections[collection.slug]?.customIDType
|
|
29
30
|
};
|
|
30
31
|
return collections;
|
|
31
32
|
}, {});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utilities/getPayloadHMR.ts"],"sourcesContent":["import type { GeneratedTypes, Payload } from 'payload'\nimport type { InitOptions } from 'payload/config'\n\nimport { BasePayload } from 'payload'\nimport WebSocket from 'ws'\n\nlet cached: {\n payload: Payload | null\n promise: Promise<Payload> | null\n reload: Promise<boolean> | boolean\n} = global._payload\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload = { payload: null, promise: null, reload: false }\n}\n\nexport const getPayloadHMR = async (options: InitOptions): Promise<Payload> => {\n if (!options?.config) {\n throw new Error('Error: the payload config is required for getPayload to work.')\n }\n\n if (cached.payload) {\n const config = await options.config // TODO: check if we can move this inside the cached.reload === true condition\n\n if (cached.reload === true) {\n let resolve\n\n cached.reload = new Promise((res) => (resolve = res))\n\n if (typeof cached.payload.db.destroy === 'function') {\n await cached.payload.db.destroy()\n }\n\n cached.payload.config = config\n\n cached.payload.collections = config.collections.reduce((collections, collection) => {\n collections[collection.slug] = {
|
|
1
|
+
{"version":3,"sources":["../../src/utilities/getPayloadHMR.ts"],"sourcesContent":["import type { GeneratedTypes, Payload } from 'payload'\nimport type { InitOptions } from 'payload/config'\n\nimport { BasePayload } from 'payload'\nimport WebSocket from 'ws'\n\nlet cached: {\n payload: Payload | null\n promise: Promise<Payload> | null\n reload: Promise<boolean> | boolean\n} = global._payload\n\nif (!cached) {\n // eslint-disable-next-line no-multi-assign\n cached = global._payload = { payload: null, promise: null, reload: false }\n}\n\nexport const getPayloadHMR = async (options: InitOptions): Promise<Payload> => {\n if (!options?.config) {\n throw new Error('Error: the payload config is required for getPayload to work.')\n }\n\n if (cached.payload) {\n const config = await options.config // TODO: check if we can move this inside the cached.reload === true condition\n\n if (cached.reload === true) {\n let resolve\n\n cached.reload = new Promise((res) => (resolve = res))\n\n if (typeof cached.payload.db.destroy === 'function') {\n await cached.payload.db.destroy()\n }\n\n cached.payload.config = config\n\n cached.payload.collections = config.collections.reduce((collections, collection) => {\n collections[collection.slug] = {\n config: collection,\n customIDType: cached.payload.collections[collection.slug]?.customIDType,\n }\n return collections\n }, {})\n\n cached.payload.globals = {\n config: config.globals,\n }\n\n // TODO: support HMR for other props in the future (see payload/src/index init()) hat may change on Payload singleton\n\n await cached.payload.db.init()\n await cached.payload.db.connect({ hotReload: true })\n resolve()\n }\n\n if (cached.reload instanceof Promise) {\n await cached.reload\n }\n\n return cached.payload\n }\n\n if (!cached.promise) {\n cached.promise = new BasePayload<GeneratedTypes>().init(options)\n }\n\n try {\n cached.payload = await cached.promise\n\n if (\n process.env.NODE_ENV !== 'production' &&\n process.env.NODE_ENV !== 'test' &&\n process.env.DISABLE_PAYLOAD_HMR !== 'true'\n ) {\n try {\n const port = process.env.PORT || '3000'\n const ws = new WebSocket(`ws://localhost:${port}/_next/webpack-hmr`)\n\n ws.onmessage = (event) => {\n if (typeof event.data === 'string') {\n const data = JSON.parse(event.data)\n\n if ('action' in data && data.action === 'serverComponentChanges') {\n cached.reload = true\n }\n }\n }\n } catch (_) {\n // swallow e\n }\n }\n } catch (e) {\n cached.promise = null\n throw e\n }\n\n return cached.payload\n}\n"],"names":["BasePayload","WebSocket","cached","global","_payload","payload","promise","reload","getPayloadHMR","options","config","Error","resolve","Promise","res","db","destroy","collections","reduce","collection","slug","customIDType","globals","init","connect","hotReload","process","env","NODE_ENV","DISABLE_PAYLOAD_HMR","port","PORT","ws","onmessage","event","data","JSON","parse","action","_","e"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,WAAW,QAAQ,UAAS;AACrC,OAAOC,eAAe,KAAI;AAE1B,IAAIC,SAIAC,OAAOC,QAAQ;AAEnB,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,QAAQ,GAAG;QAAEC,SAAS;QAAMC,SAAS;QAAMC,QAAQ;IAAM;AAC3E;AAEA,OAAO,MAAMC,gBAAgB,OAAOC;IAClC,IAAI,CAACA,SAASC,QAAQ;QACpB,MAAM,IAAIC,MAAM;IAClB;IAEA,IAAIT,OAAOG,OAAO,EAAE;QAClB,MAAMK,SAAS,MAAMD,QAAQC,MAAM,CAAC,8EAA8E;;QAElH,IAAIR,OAAOK,MAAM,KAAK,MAAM;YAC1B,IAAIK;YAEJV,OAAOK,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BAAkB,CAAC;gBAEnEE,GAAGC,SAAS,GAAG,CAACC;oBACd,IAAI,OAAOA,MAAMC,IAAI,KAAK,UAAU;wBAClC,MAAMA,OAAOC,KAAKC,KAAK,CAACH,MAAMC,IAAI;wBAElC,IAAI,YAAYA,QAAQA,KAAKG,MAAM,KAAK,0BAA0B;4BAChEpC,OAAOK,MAAM,GAAG;wBAClB;oBACF;gBACF;YACF,EAAE,OAAOgC,GAAG;YACV,YAAY;YACd;QACF;IACF,EAAE,OAAOC,GAAG;QACVtC,OAAOI,OAAO,GAAG;QACjB,MAAMkC;IACR;IAEA,OAAOtC,OAAOG,OAAO;AACvB,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/CreateFirstUser/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/views/CreateFirstUser/index.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAOnD,OAAO,KAAK,MAAM,OAAO,CAAA;AAGzB,OAAO,cAAc,CAAA;AAErB,OAAO,EAAE,+BAA+B,EAAE,MAAM,WAAW,CAAA;AAE3D,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,cAAc,CA4ExD,CAAA"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { Form } from '@payloadcms/ui/forms/Form';
|
|
2
2
|
import { FormSubmit } from '@payloadcms/ui/forms/Submit';
|
|
3
3
|
import { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema';
|
|
4
|
+
import { WithServerSideProps as WithServerSidePropsGeneric } from '@payloadcms/ui/providers/ComponentMap';
|
|
4
5
|
import { mapFields } from '@payloadcms/ui/utilities/buildComponentMap';
|
|
5
6
|
import React from 'react';
|
|
6
7
|
import { CreateFirstUserFields } from './index.client.js';
|
|
7
8
|
export { generateCreateFirstUserMetadata } from './meta.js';
|
|
8
9
|
export const CreateFirstUserView = async ({ initPageResult })=>{
|
|
9
|
-
const { req, req: { i18n, payload: { config, config: { admin: { user: userSlug }, routes: { admin: adminRoute, api: apiRoute }, serverURL } } } } = initPageResult;
|
|
10
|
+
const { req, req: { i18n, payload, payload: { config, config: { admin: { user: userSlug }, routes: { admin: adminRoute, api: apiRoute }, serverURL } } } } = initPageResult;
|
|
10
11
|
const fields = [
|
|
11
12
|
{
|
|
12
13
|
name: 'email',
|
|
@@ -27,7 +28,15 @@ export const CreateFirstUserView = async ({ initPageResult })=>{
|
|
|
27
28
|
required: true
|
|
28
29
|
}
|
|
29
30
|
];
|
|
31
|
+
const WithServerSideProps = ({ Component, ...rest })=>{
|
|
32
|
+
return /*#__PURE__*/ React.createElement(WithServerSidePropsGeneric, {
|
|
33
|
+
Component: Component,
|
|
34
|
+
payload: payload,
|
|
35
|
+
...rest
|
|
36
|
+
});
|
|
37
|
+
};
|
|
30
38
|
const createFirstUserFieldMap = mapFields({
|
|
39
|
+
WithServerSideProps,
|
|
31
40
|
config,
|
|
32
41
|
fieldSchema: fields,
|
|
33
42
|
i18n,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/views/CreateFirstUser/index.tsx"],"sourcesContent":["import type { Field } from 'payload/types'\nimport type { AdminViewProps } from 'payload/types'\n\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport { FormSubmit } from '@payloadcms/ui/forms/Submit'\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { mapFields } from '@payloadcms/ui/utilities/buildComponentMap'\nimport React from 'react'\n\nimport { CreateFirstUserFields } from './index.client.js'\nimport './index.scss'\n\nexport { generateCreateFirstUserMetadata } from './meta.js'\n\nexport const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageResult }) => {\n const {\n req,\n req: {\n i18n,\n payload: {\n config,\n config: {\n admin: { user: userSlug },\n routes: { admin: adminRoute, api: apiRoute },\n serverURL,\n },\n },\n },\n } = initPageResult\n\n const fields: Field[] = [\n {\n name: 'email',\n type: 'email',\n label: req.t('general:emailAddress'),\n required: true,\n },\n {\n name: 'password',\n type: 'text',\n label: req.t('general:password'),\n required: true,\n },\n {\n name: 'confirm-password',\n type: 'text',\n label: req.t('authentication:confirmPassword'),\n required: true,\n },\n ]\n\n const createFirstUserFieldMap = mapFields({\n config,\n fieldSchema: fields,\n i18n,\n parentPath: userSlug,\n })\n\n const formState = await buildStateFromSchema({\n fieldSchema: fields,\n operation: 'create',\n preferences: {},\n req,\n })\n\n return (\n <React.Fragment>\n <h1>{req.t('general:welcome')}</h1>\n <p>{req.t('authentication:beginCreateFirstUser')}</p>\n <Form\n action={`${serverURL}${apiRoute}/${userSlug}/first-register`}\n initialState={formState}\n method=\"POST\"\n redirect={adminRoute}\n validationOperation=\"create\"\n >\n <CreateFirstUserFields\n createFirstUserFieldMap={createFirstUserFieldMap}\n userSlug={userSlug}\n />\n <FormSubmit>{req.t('general:create')}</FormSubmit>\n </Form>\n </React.Fragment>\n )\n}\n"],"names":["Form","FormSubmit","buildStateFromSchema","mapFields","React","CreateFirstUserFields","generateCreateFirstUserMetadata","CreateFirstUserView","initPageResult","req","i18n","payload","config","admin","user","userSlug","routes","adminRoute","api","apiRoute","serverURL","fields","name","type","label","t","required","createFirstUserFieldMap","fieldSchema","parentPath","formState","operation","preferences","Fragment","h1","p","action","initialState","method","redirect","validationOperation"],"rangeMappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/views/CreateFirstUser/index.tsx"],"sourcesContent":["import type { Field, WithServerSideProps as WithServerSidePropsType } from 'payload/types'\nimport type { AdminViewProps } from 'payload/types'\n\nimport { Form } from '@payloadcms/ui/forms/Form'\nimport { FormSubmit } from '@payloadcms/ui/forms/Submit'\nimport { buildStateFromSchema } from '@payloadcms/ui/forms/buildStateFromSchema'\nimport { WithServerSideProps as WithServerSidePropsGeneric } from '@payloadcms/ui/providers/ComponentMap'\nimport { mapFields } from '@payloadcms/ui/utilities/buildComponentMap'\nimport React from 'react'\n\nimport { CreateFirstUserFields } from './index.client.js'\nimport './index.scss'\n\nexport { generateCreateFirstUserMetadata } from './meta.js'\n\nexport const CreateFirstUserView: React.FC<AdminViewProps> = async ({ initPageResult }) => {\n const {\n req,\n req: {\n i18n,\n payload,\n payload: {\n config,\n config: {\n admin: { user: userSlug },\n routes: { admin: adminRoute, api: apiRoute },\n serverURL,\n },\n },\n },\n } = initPageResult\n\n const fields: Field[] = [\n {\n name: 'email',\n type: 'email',\n label: req.t('general:emailAddress'),\n required: true,\n },\n {\n name: 'password',\n type: 'text',\n label: req.t('general:password'),\n required: true,\n },\n {\n name: 'confirm-password',\n type: 'text',\n label: req.t('authentication:confirmPassword'),\n required: true,\n },\n ]\n\n const WithServerSideProps: WithServerSidePropsType = ({ Component, ...rest }) => {\n return <WithServerSidePropsGeneric Component={Component} payload={payload} {...rest} />\n }\n\n const createFirstUserFieldMap = mapFields({\n WithServerSideProps,\n config,\n fieldSchema: fields,\n i18n,\n parentPath: userSlug,\n })\n\n const formState = await buildStateFromSchema({\n fieldSchema: fields,\n operation: 'create',\n preferences: {},\n req,\n })\n\n return (\n <React.Fragment>\n <h1>{req.t('general:welcome')}</h1>\n <p>{req.t('authentication:beginCreateFirstUser')}</p>\n <Form\n action={`${serverURL}${apiRoute}/${userSlug}/first-register`}\n initialState={formState}\n method=\"POST\"\n redirect={adminRoute}\n validationOperation=\"create\"\n >\n <CreateFirstUserFields\n createFirstUserFieldMap={createFirstUserFieldMap}\n userSlug={userSlug}\n />\n <FormSubmit>{req.t('general:create')}</FormSubmit>\n </Form>\n </React.Fragment>\n )\n}\n"],"names":["Form","FormSubmit","buildStateFromSchema","WithServerSideProps","WithServerSidePropsGeneric","mapFields","React","CreateFirstUserFields","generateCreateFirstUserMetadata","CreateFirstUserView","initPageResult","req","i18n","payload","config","admin","user","userSlug","routes","adminRoute","api","apiRoute","serverURL","fields","name","type","label","t","required","Component","rest","createFirstUserFieldMap","fieldSchema","parentPath","formState","operation","preferences","Fragment","h1","p","action","initialState","method","redirect","validationOperation"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,IAAI,QAAQ,4BAA2B;AAChD,SAASC,UAAU,QAAQ,8BAA6B;AACxD,SAASC,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,uBAAuBC,0BAA0B,QAAQ,wCAAuC;AACzG,SAASC,SAAS,QAAQ,6CAA4C;AACtE,OAAOC,WAAW,QAAO;AAEzB,SAASC,qBAAqB,QAAQ,oBAAmB;AAGzD,SAASC,+BAA+B,QAAQ,YAAW;AAE3D,OAAO,MAAMC,sBAAgD,OAAO,EAAEC,cAAc,EAAE;IACpF,MAAM,EACJC,GAAG,EACHA,KAAK,EACHC,IAAI,EACJC,OAAO,EACPA,SAAS,EACPC,MAAM,EACNA,QAAQ,EACNC,OAAO,EAAEC,MAAMC,QAAQ,EAAE,EACzBC,QAAQ,EAAEH,OAAOI,UAAU,EAAEC,KAAKC,QAAQ,EAAE,EAC5CC,SAAS,EACV,EACF,EACF,EACF,GAAGZ;IAEJ,MAAMa,SAAkB;QACtB;YACEC,MAAM;YACNC,MAAM;YACNC,OAAOf,IAAIgB,CAAC,CAAC;YACbC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAOf,IAAIgB,CAAC,CAAC;YACbC,UAAU;QACZ;QACA;YACEJ,MAAM;YACNC,MAAM;YACNC,OAAOf,IAAIgB,CAAC,CAAC;YACbC,UAAU;QACZ;KACD;IAED,MAAMzB,sBAA+C,CAAC,EAAE0B,SAAS,EAAE,GAAGC,MAAM;QAC1E,qBAAO,oBAAC1B;YAA2ByB,WAAWA;YAAWhB,SAASA;YAAU,GAAGiB,IAAI;;IACrF;IAEA,MAAMC,0BAA0B1B,UAAU;QACxCF;QACAW;QACAkB,aAAaT;QACbX;QACAqB,YAAYhB;IACd;IAEA,MAAMiB,YAAY,MAAMhC,qBAAqB;QAC3C8B,aAAaT;QACbY,WAAW;QACXC,aAAa,CAAC;QACdzB;IACF;IAEA,qBACE,oBAACL,MAAM+B,QAAQ,sBACb,oBAACC,YAAI3B,IAAIgB,CAAC,CAAC,mCACX,oBAACY,WAAG5B,IAAIgB,CAAC,CAAC,uDACV,oBAAC3B;QACCwC,QAAQ,CAAC,EAAElB,UAAU,EAAED,SAAS,CAAC,EAAEJ,SAAS,eAAe,CAAC;QAC5DwB,cAAcP;QACdQ,QAAO;QACPC,UAAUxB;QACVyB,qBAAoB;qBAEpB,oBAACrC;QACCwB,yBAAyBA;QACzBd,UAAUA;sBAEZ,oBAAChB,kBAAYU,IAAIgB,CAAC,CAAC;AAI3B,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/next",
|
|
3
|
-
"version": "3.0.0-beta.
|
|
3
|
+
"version": "3.0.0-beta.5",
|
|
4
4
|
"main": "./dist/index.js",
|
|
5
5
|
"types": "./dist/index.d.ts",
|
|
6
6
|
"type": "module",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
"terser-webpack-plugin": "^5.3.10",
|
|
43
43
|
"webpack": "^5.78.0",
|
|
44
44
|
"webpack-cli": "^5.1.4",
|
|
45
|
-
"payload": "3.0.0-beta.
|
|
45
|
+
"payload": "3.0.0-beta.5",
|
|
46
46
|
"@payloadcms/eslint-config": "1.1.1"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
@@ -59,14 +59,14 @@
|
|
|
59
59
|
"react-toastify": "8.2.0",
|
|
60
60
|
"sass": "^1.71.1",
|
|
61
61
|
"ws": "^8.16.0",
|
|
62
|
-
"@payloadcms/graphql": "3.0.0-beta.
|
|
63
|
-
"@payloadcms/translations": "3.0.0-beta.
|
|
64
|
-
"@payloadcms/ui": "3.0.0-beta.
|
|
62
|
+
"@payloadcms/graphql": "3.0.0-beta.5",
|
|
63
|
+
"@payloadcms/translations": "3.0.0-beta.5",
|
|
64
|
+
"@payloadcms/ui": "3.0.0-beta.5"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"http-status": "1.6.2",
|
|
68
68
|
"next": "14.2.0-canary.23",
|
|
69
|
-
"payload": "3.0.0-beta.
|
|
69
|
+
"payload": "3.0.0-beta.5"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
72
72
|
"registry": "https://registry.npmjs.org/"
|