@payloadcms/next 3.0.0-beta.1 → 3.0.0-beta.11
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/cjs/withPayload.cjs +11 -3
- package/dist/cjs/withPayload.cjs.map +1 -1
- package/dist/exports/utilities.d.ts +1 -0
- package/dist/exports/utilities.d.ts.map +1 -1
- package/dist/exports/utilities.js +1 -0
- package/dist/exports/utilities.js.map +1 -1
- package/dist/layouts/Root/index.d.ts.map +1 -1
- package/dist/layouts/Root/index.js +23 -1
- package/dist/layouts/Root/index.js.map +1 -1
- package/dist/prod/styles.css +1 -1
- package/dist/routes/rest/auth/logout.js +1 -1
- package/dist/routes/rest/auth/logout.js.map +1 -1
- package/dist/routes/rest/buildFormState.d.ts.map +1 -1
- package/dist/routes/rest/buildFormState.js +5 -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/routeError.d.ts.map +1 -1
- package/dist/routes/rest/routeError.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/scss/app.scss +2 -3
- package/dist/scss/vars.scss +0 -7
- package/dist/utilities/getDataAndFile.d.ts.map +1 -1
- package/dist/utilities/getDataAndFile.js +5 -1
- package/dist/utilities/getDataAndFile.js.map +1 -1
- 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/API/index.client.js +2 -2
- package/dist/views/API/index.client.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/dist/views/Edit/Default/{SetStepNav → SetDocumentStepNav}/index.d.ts +1 -1
- package/dist/views/Edit/Default/SetDocumentStepNav/index.d.ts.map +1 -0
- package/dist/views/Edit/Default/{SetStepNav → SetDocumentStepNav}/index.js +12 -5
- package/dist/views/Edit/Default/SetDocumentStepNav/index.js.map +1 -0
- package/dist/views/Edit/Default/index.js +2 -2
- package/dist/views/Edit/Default/index.js.map +1 -1
- package/dist/views/List/index.js +2 -2
- package/dist/views/List/index.js.map +1 -1
- package/dist/views/LivePreview/index.client.js +2 -2
- package/dist/views/LivePreview/index.client.js.map +1 -1
- package/dist/views/Versions/index.js +2 -2
- package/dist/views/Versions/index.js.map +1 -1
- package/dist/withPayload.d.ts +1 -6
- package/dist/withPayload.d.ts.map +1 -1
- package/dist/withPayload.js +1 -1
- package/dist/withPayload.js.map +1 -1
- package/package.json +8 -8
- package/dist/prod/payload/SuisseIntl-Bold.woff +0 -0
- package/dist/prod/payload/SuisseIntl-Bold.woff2 +0 -0
- package/dist/prod/payload/SuisseIntl-Medium.woff +0 -0
- package/dist/prod/payload/SuisseIntl-Medium.woff2 +0 -0
- package/dist/prod/payload/SuisseIntl-SemiBold.woff +0 -0
- package/dist/prod/payload/SuisseIntl-SemiBold.woff2 +0 -0
- package/dist/prod/payload/SuisseIntl.woff +0 -0
- package/dist/prod/payload/SuisseIntl.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900italic.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-900italic.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-italic.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-italic.woff2 +0 -0
- package/dist/prod/payload/merriweather-v30-latin-regular.woff +0 -0
- package/dist/prod/payload/merriweather-v30-latin-regular.woff2 +0 -0
- package/dist/scss/fonts.scss +0 -75
- package/dist/views/Edit/Default/SetStepNav/index.d.ts.map +0 -1
- package/dist/views/Edit/Default/SetStepNav/index.js.map +0 -1
|
@@ -2,7 +2,7 @@ import httpStatus from 'http-status';
|
|
|
2
2
|
import { generateExpiredPayloadCookie } from 'payload/auth';
|
|
3
3
|
import { logoutOperation } from 'payload/operations';
|
|
4
4
|
export const logout = async ({ collection, req })=>{
|
|
5
|
-
const result = logoutOperation({
|
|
5
|
+
const result = await logoutOperation({
|
|
6
6
|
collection,
|
|
7
7
|
req
|
|
8
8
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/routes/rest/auth/logout.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generateExpiredPayloadCookie } from 'payload/auth'\nimport { logoutOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const logout: CollectionRouteHandler = async ({ collection, req }) => {\n const result = logoutOperation({\n collection,\n req,\n })\n\n if (!result) {\n return Response.json(\n {\n message: 'Logout failed.',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n const expiredCookie = generateExpiredPayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n })\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Logout successful.',\n },\n {\n headers: new Headers({\n 'Set-Cookie': expiredCookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generateExpiredPayloadCookie","logoutOperation","logout","collection","req","result","Response","json","message","status","BAD_REQUEST","expiredCookie","collectionConfig","config","payload","headers","Headers","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,eAAe,QAAQ,qBAAoB;AAIpD,OAAO,MAAMC,SAAiC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACtE,MAAMC,
|
|
1
|
+
{"version":3,"sources":["../../../../src/routes/rest/auth/logout.ts"],"sourcesContent":["import httpStatus from 'http-status'\nimport { generateExpiredPayloadCookie } from 'payload/auth'\nimport { logoutOperation } from 'payload/operations'\n\nimport type { CollectionRouteHandler } from '../types.js'\n\nexport const logout: CollectionRouteHandler = async ({ collection, req }) => {\n const result = await logoutOperation({\n collection,\n req,\n })\n\n if (!result) {\n return Response.json(\n {\n message: 'Logout failed.',\n },\n {\n status: httpStatus.BAD_REQUEST,\n },\n )\n }\n\n const expiredCookie = generateExpiredPayloadCookie({\n collectionConfig: collection.config,\n payload: req.payload,\n })\n\n return Response.json(\n {\n // TODO(translate)\n message: 'Logout successful.',\n },\n {\n headers: new Headers({\n 'Set-Cookie': expiredCookie,\n }),\n status: httpStatus.OK,\n },\n )\n}\n"],"names":["httpStatus","generateExpiredPayloadCookie","logoutOperation","logout","collection","req","result","Response","json","message","status","BAD_REQUEST","expiredCookie","collectionConfig","config","payload","headers","Headers","OK"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,4BAA4B,QAAQ,eAAc;AAC3D,SAASC,eAAe,QAAQ,qBAAoB;AAIpD,OAAO,MAAMC,SAAiC,OAAO,EAAEC,UAAU,EAAEC,GAAG,EAAE;IACtE,MAAMC,SAAS,MAAMJ,gBAAgB;QACnCE;QACAC;IACF;IAEA,IAAI,CAACC,QAAQ;QACX,OAAOC,SAASC,IAAI,CAClB;YACEC,SAAS;QACX,GACA;YACEC,QAAQV,WAAWW,WAAW;QAChC;IAEJ;IAEA,MAAMC,gBAAgBX,6BAA6B;QACjDY,kBAAkBT,WAAWU,MAAM;QACnCC,SAASV,IAAIU,OAAO;IACtB;IAEA,OAAOR,SAASC,IAAI,CAClB;QACE,kBAAkB;QAClBC,SAAS;IACX,GACA;QACEO,SAAS,IAAIC,QAAQ;YACnB,cAAcL;QAChB;QACAF,QAAQV,WAAWkB,EAAE;IACvB;AAEJ,EAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,cAAc,EAAc,MAAM,eAAe,CAAA;AAM3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAWlF,eAAO,MAAM,iBAAiB,QAAS,cAAc,mBAQpD,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,
|
|
1
|
+
{"version":3,"file":"buildFormState.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/buildFormState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAA8B,cAAc,EAAc,MAAM,eAAe,CAAA;AAM3F,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8CAA8C,CAAA;AAWlF,eAAO,MAAM,iBAAiB,QAAS,cAAc,mBAQpD,CAAA;AAED,eAAO,MAAM,cAAc,YAAmB;IAAE,GAAG,EAAE,cAAc,CAAA;CAAE,sBAwLpE,CAAA"}
|
|
@@ -117,7 +117,7 @@ export const buildFormState = async ({ req })=>{
|
|
|
117
117
|
user: req.user
|
|
118
118
|
});
|
|
119
119
|
}
|
|
120
|
-
if (globalSlug) {
|
|
120
|
+
if (globalSlug && schemaPath === globalSlug) {
|
|
121
121
|
resolvedData = await req.payload.findGlobal({
|
|
122
122
|
slug: globalSlug,
|
|
123
123
|
depth: 0,
|
|
@@ -145,6 +145,10 @@ export const buildFormState = async ({ req })=>{
|
|
|
145
145
|
},
|
|
146
146
|
req
|
|
147
147
|
});
|
|
148
|
+
// Maintain form state of file
|
|
149
|
+
if (collectionSlug && req.payload.collections[collectionSlug]?.config?.upload && formState && formState.file) {
|
|
150
|
+
result.file = formState.file;
|
|
151
|
+
}
|
|
148
152
|
return Response.json(result, {
|
|
149
153
|
status: httpStatus.OK
|
|
150
154
|
});
|
|
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,OAAOC,gBAAgB,cAAa;AAIpC,SAASC,mBAAmB,QAAQ,+CAA8C;AAElF,IAAIC,SAASC,OAAOC,uBAAuB;AAE3C,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,uBAAuB,GAAG;AAC5C;AAEA,OAAO,MAAMC,oBAAoB,CAACC;IAChC,IAAIJ,UAAUK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QACpD,OAAOP;IACT;IAEAA,SAASD,oBAAoBK;IAE7B,OAAOJ;AACT,EAAC;AAED,OAAO,MAAMQ,iBAAiB,OAAO,EAAEJ,GAAG,EAA2B;IACnE,IAAI;QACF,MAAMK,UAA8BL,IAAIM,IAAI;QAC5C,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAEC,UAAU,EAAEC,MAAM,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGP;QAEjF,MAAMQ,mBAAmBb,IAAIc,IAAI,EAAE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I;oBAChB;gBACF;gBAEA,IAAIL,YAAY;oBACdgD,eAAe,MAAMzD,IAAIiB,OAAO,CAAC6C,UAAU,CAAC;wBAC1CxB,MAAM7B;wBACNuC,OAAO;wBACPW,OAAO;wBACPC,gBAAgB;wBAChBlD;wBACAmD,gBAAgB;wBAChB/C,MAAMd,IAAIc,IAAI;oBAChB;gBACF;gBAEAR,OAAOmD;YACT;YAEAb,SAAStC,IAAI,GAAGkD;QAClB;QAEA,IAAIO,OAAOC,IAAI,CAACpB,UAAUV,MAAM,GAAG,GAAG;YACpC,MAAM+B,QAAQC,GAAG,CAACH,OAAOI,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 // Maintain form state of file\n if (\n collectionSlug &&\n req.payload.collections[collectionSlug]?.config?.upload &&\n formState &&\n formState.file\n ) {\n result.file = formState.file\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","upload","file","OK","err"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAGA,SAASA,oBAAoB,QAAQ,4CAA2C;AAChF,SAASC,oBAAoB,QAAQ,gDAA+C;AACpF,OAAOC,gBAAgB,cAAa;AAIpC,SAASC,mBAAmB,QAAQ,+CAA8C;AAElF,IAAIC,SAASC,OAAOC,uBAAuB;AAE3C,IAAI,CAACF,QAAQ;IACX,2CAA2C;IAC3CA,SAASC,OAAOC,uBAAuB,GAAG;AAC5C;AAEA,OAAO,MAAMC,oBAAoB,CAACC;IAChC,IAAIJ,UAAUK,QAAQC,GAAG,CAACC,QAAQ,KAAK,eAAe;QACpD,OAAOP;IACT;IAEAA,SAASD,oBAAoBK;IAE7B,OAAOJ;AACT,EAAC;AAED,OAAO,MAAMQ,iBAAiB,OAAO,EAAEJ,GAAG,EAA2B;IACnE,IAAI;QACF,MAAMK,UAA8BL,IAAIM,IAAI;QAC5C,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAEC,UAAU,EAAEC,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OAAO;wBACPW,OAAO;wBACPC,gBAAgB;wBAChBlD;wBACAmD,gBAAgB;wBAChB/C,MAAMd,IAAIc,IAAI;oBAChB;gBACF;gBAEA,IAAIL,cAAcG,eAAeH,YAAY;oBAC3CgD,eAAe,MAAMzD,IAAIiB,OAAO,CAAC6C,UAAU,CAAC;wBAC1CxB,MAAM7B;wBACNuC,OAAO;wBACPW,OAAO;wBACPC,gBAAgB;wBAChBlD;wBACAmD,gBAAgB;wBAChB/C,MAAMd,IAAIc,IAAI;oBAChB;gBACF;gBAEAR,OAAOmD;YACT;YAEAb,SAAStC,IAAI,GAAGkD;QAClB;QAEA,IAAIO,OAAOC,IAAI,CAACpB,UAAUV,MAAM,GAAG,GAAG;YACpC,MAAM+B,QAAQC,GAAG,CAACH,OAAOI,MAAM,CAACvB;QAClC;QAEA,MAAMwB,SAAS,MAAM5E,qBAAqB;YACxCqC;YACAvB;YACA2B;YACAtB;YACA4C,aAAaZ,kBAAkB;gBAAER,QAAQ,CAAC;YAAE;YAC5CnC;QACF;QAEA,8BAA8B;QAC9B,IACEO,kBACAP,IAAIiB,OAAO,CAACI,WAAW,CAACd,eAAe,EAAEW,QAAQmD,UACjD7D,aACAA,UAAU8D,IAAI,EACd;YACAF,OAAOE,IAAI,GAAG9D,UAAU8D,IAAI;QAC9B;QAEA,OAAO9C,SAASC,IAAI,CAAC2C,QAAQ;YAC3B1C,QAAQhC,WAAW6E,EAAE;QACvB;IACF,EAAE,OAAOC,KAAK;QACZ,OAAOhD,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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"routeError.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/routeError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAG/D,OAAO,EAAE,QAAQ,
|
|
1
|
+
{"version":3,"file":"routeError.d.ts","sourceRoot":"","sources":["../../../src/routes/rest/routeError.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,eAAe,CAAA;AAG/D,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAEzC,MAAM,MAAM,aAAa,GAAG;IAAE,IAAI,CAAC,EAAE,GAAG,CAAC;IAAC,MAAM,EAAE,OAAO,EAAE,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA;AA+D7E,eAAO,MAAM,UAAU,8BAIpB;IACD,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,GAAG,EAAE,QAAQ,CAAA;IACb,GAAG,EAAE,cAAc,CAAA;CACpB,aAmDA,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/routes/rest/routeError.ts"],"sourcesContent":["import type { Collection, PayloadRequest } from 'payload/types'\n\nimport httpStatus from 'http-status'\nimport { APIError
|
|
1
|
+
{"version":3,"sources":["../../../src/routes/rest/routeError.ts"],"sourcesContent":["import type { Collection, PayloadRequest } from 'payload/types'\n\nimport httpStatus from 'http-status'\nimport { APIError } from 'payload/errors'\n\nexport type ErrorResponse = { data?: any; errors: unknown[]; stack?: string }\n\nconst formatErrors = (incoming: { [key: string]: unknown } | APIError): ErrorResponse => {\n if (incoming) {\n // Cannot use `instanceof` to check error type: https://github.com/microsoft/TypeScript/issues/13965\n // Instead, get the prototype of the incoming error and check its constructor name\n const proto = Object.getPrototypeOf(incoming)\n\n // Payload 'ValidationError' and 'APIError'\n if (\n (proto.constructor.name === 'ValidationError' || proto.constructor.name === 'APIError') &&\n incoming.data\n ) {\n return {\n errors: [\n {\n name: incoming.name,\n data: incoming.data,\n message: incoming.message,\n },\n ],\n }\n }\n\n // Mongoose 'ValidationError': https://mongoosejs.com/docs/api/error.html#Error.ValidationError\n if (proto.constructor.name === 'ValidationError' && 'errors' in incoming && incoming.errors) {\n return {\n errors: Object.keys(incoming.errors).reduce((acc, key) => {\n acc.push({\n field: incoming.errors[key].path,\n message: incoming.errors[key].message,\n })\n return acc\n }, []),\n }\n }\n\n if (Array.isArray(incoming.message)) {\n return {\n errors: incoming.message,\n }\n }\n\n if (incoming.name) {\n return {\n errors: [\n {\n message: incoming.message,\n },\n ],\n }\n }\n }\n\n return {\n errors: [\n {\n message: 'An unknown error occurred.',\n },\n ],\n }\n}\n\nexport const routeError = ({\n collection,\n err,\n req,\n}: {\n collection?: Collection\n err: APIError\n req: PayloadRequest\n}) => {\n if (!req?.payload) {\n return Response.json(\n {\n message: err.message,\n stack: err.stack,\n },\n { status: httpStatus.INTERNAL_SERVER_ERROR },\n )\n }\n\n const { config, logger } = req.payload\n\n let response = formatErrors(err)\n\n let status = err.status || httpStatus.INTERNAL_SERVER_ERROR\n\n logger.error(err.stack)\n\n // Internal server errors can contain anything, including potentially sensitive data.\n // Therefore, error details will be hidden from the response unless `config.debug` is `true`\n if (!config.debug && status === httpStatus.INTERNAL_SERVER_ERROR) {\n response = formatErrors(new APIError('Something went wrong.'))\n }\n\n if (config.debug && config.debug === true) {\n response.stack = err.stack\n }\n\n if (collection && typeof collection.config.hooks.afterError === 'function') {\n ;({ response, status } = collection.config.hooks.afterError(\n err,\n response,\n req.context,\n collection.config,\n ) || { response, status })\n }\n\n if (typeof config.hooks.afterError === 'function') {\n ;({ response, status } = config.hooks.afterError(\n err,\n response,\n req.context,\n collection?.config,\n ) || {\n response,\n status,\n })\n }\n\n return Response.json(response, { status })\n}\n"],"names":["httpStatus","APIError","formatErrors","incoming","proto","Object","getPrototypeOf","constructor","name","data","errors","message","keys","reduce","acc","key","push","field","path","Array","isArray","routeError","collection","err","req","payload","Response","json","stack","status","INTERNAL_SERVER_ERROR","config","logger","response","error","debug","hooks","afterError","context"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,OAAOA,gBAAgB,cAAa;AACpC,SAASC,QAAQ,QAAQ,iBAAgB;AAIzC,MAAMC,eAAe,CAACC;IACpB,IAAIA,UAAU;QACZ,oGAAoG;QACpG,kFAAkF;QAClF,MAAMC,QAAQC,OAAOC,cAAc,CAACH;QAEpC,2CAA2C;QAC3C,IACE,AAACC,CAAAA,MAAMG,WAAW,CAACC,IAAI,KAAK,qBAAqBJ,MAAMG,WAAW,CAACC,IAAI,KAAK,UAAS,KACrFL,SAASM,IAAI,EACb;YACA,OAAO;gBACLC,QAAQ;oBACN;wBACEF,MAAML,SAASK,IAAI;wBACnBC,MAAMN,SAASM,IAAI;wBACnBE,SAASR,SAASQ,OAAO;oBAC3B;iBACD;YACH;QACF;QAEA,+FAA+F;QAC/F,IAAIP,MAAMG,WAAW,CAACC,IAAI,KAAK,qBAAqB,YAAYL,YAAYA,SAASO,MAAM,EAAE;YAC3F,OAAO;gBACLA,QAAQL,OAAOO,IAAI,CAACT,SAASO,MAAM,EAAEG,MAAM,CAAC,CAACC,KAAKC;oBAChDD,IAAIE,IAAI,CAAC;wBACPC,OAAOd,SAASO,MAAM,CAACK,IAAI,CAACG,IAAI;wBAChCP,SAASR,SAASO,MAAM,CAACK,IAAI,CAACJ,OAAO;oBACvC;oBACA,OAAOG;gBACT,GAAG,EAAE;YACP;QACF;QAEA,IAAIK,MAAMC,OAAO,CAACjB,SAASQ,OAAO,GAAG;YACnC,OAAO;gBACLD,QAAQP,SAASQ,OAAO;YAC1B;QACF;QAEA,IAAIR,SAASK,IAAI,EAAE;YACjB,OAAO;gBACLE,QAAQ;oBACN;wBACEC,SAASR,SAASQ,OAAO;oBAC3B;iBACD;YACH;QACF;IACF;IAEA,OAAO;QACLD,QAAQ;YACN;gBACE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,CAACM,UAAU;QAAEJ;IAAO;AAC1C,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"}
|
package/dist/scss/app.scss
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
@import './fonts.scss';
|
|
2
1
|
@import './styles.scss';
|
|
3
2
|
@import './toastify.scss';
|
|
4
3
|
@import './colors.scss';
|
|
@@ -20,9 +19,9 @@
|
|
|
20
19
|
--theme-overlay: rgba(5, 5, 5, 0.5);
|
|
21
20
|
--theme-baseline: #{$baseline-px};
|
|
22
21
|
--theme-baseline-body-size: #{$baseline-body-size};
|
|
23
|
-
--font-body: '
|
|
22
|
+
--font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial,
|
|
23
|
+
sans-serif;
|
|
24
24
|
--font-mono: monospace;
|
|
25
|
-
--font-serif: 'Merriweather', serif;
|
|
26
25
|
|
|
27
26
|
--style-radius-s: #{$style-radius-s};
|
|
28
27
|
--style-radius-m: #{$style-radius-m};
|
package/dist/scss/vars.scss
CHANGED
|
@@ -21,13 +21,6 @@ $baseline: math.div($baseline-px, $baseline-body-size) + rem;
|
|
|
21
21
|
@return (math.div($baseline-px, $baseline-body-size) * $multiplier) + rem;
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
//////////////////////////////
|
|
25
|
-
// FONTS (DEPRECATED. DO NOT USE. PREFER CSS VARIABLES)
|
|
26
|
-
//////////////////////////////
|
|
27
|
-
|
|
28
|
-
$font-body: 'Suisse Intl' !default;
|
|
29
|
-
$font-mono: monospace !default;
|
|
30
|
-
|
|
31
24
|
//////////////////////////////
|
|
32
25
|
// COLORS (DEPRECATED. DO NOT USE. PREFER CSS VARIABLES)
|
|
33
26
|
//////////////////////////////
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getDataAndFile.d.ts","sourceRoot":"","sources":["../../src/utilities/getDataAndFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAItF,KAAK,cAAc,GAAG,CAAC,IAAI,EAAE;IAC3B,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAA;CACnC,CAAC,CAAA;AACF,eAAO,MAAM,cAAc,EAAE,
|
|
1
|
+
{"version":3,"file":"getDataAndFile.d.ts","sourceRoot":"","sources":["../../src/utilities/getDataAndFile.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,eAAe,CAAA;AAItF,KAAK,cAAc,GAAG,CAAC,IAAI,EAAE;IAC3B,UAAU,EAAE,UAAU,CAAA;IACtB,MAAM,EAAE,eAAe,CAAA;IACvB,OAAO,EAAE,OAAO,CAAA;CACjB,KAAK,OAAO,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,IAAI,EAAE,oBAAoB,CAAC,MAAM,CAAC,CAAA;CACnC,CAAC,CAAA;AACF,eAAO,MAAM,cAAc,EAAE,cAuE5B,CAAA"}
|
|
@@ -9,7 +9,11 @@ export const getDataAndFile = async ({ collection, config, request })=>{
|
|
|
9
9
|
].includes(request.method.toUpperCase()) && request.body) {
|
|
10
10
|
const [contentType] = (request.headers.get('Content-Type') || '').split(';');
|
|
11
11
|
if (contentType === 'application/json') {
|
|
12
|
-
|
|
12
|
+
try {
|
|
13
|
+
data = await request.json();
|
|
14
|
+
} catch (error) {
|
|
15
|
+
data = {};
|
|
16
|
+
}
|
|
13
17
|
} else if (contentType === 'multipart/form-data') {
|
|
14
18
|
// possible upload request
|
|
15
19
|
if (collection?.config?.upload) {
|