@lucidcms/core
Version:
The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.
1 lines • 3.5 kB
Source Map (JSON)
{"version":3,"file":"resolve.mjs","names":["previewSessionServices.resolve"],"sources":["../../../../../../src/libs/http/controllers/previews/client/resolve.ts"],"sourcesContent":["import { createFactory } from \"hono/factory\";\nimport { describeRoute } from \"hono-openapi\";\nimport z from \"zod\";\nimport { controllerSchemas } from \"../../../../../schemas/previews.js\";\nimport { previewSessionServices } from \"../../../../../services/index.js\";\nimport { LucidAPIError } from \"../../../../../utils/errors/index.js\";\nimport serviceWrapper from \"../../../../../utils/services/service-wrapper.js\";\nimport { copy } from \"../../../../i18n/index.js\";\nimport { getCollectionClientScope } from \"../../../../permission/client-scopes.js\";\nimport clientAuthentication from \"../../../middleware/client-authenticate.js\";\nimport { clientScopeCheck } from \"../../../middleware/client-scopes.js\";\nimport validate from \"../../../middleware/validate.js\";\nimport openAPI from \"../../../openapi/index.js\";\nimport formatAPIResponse from \"../../../utils/build-response.js\";\nimport createServiceContext from \"../../../utils/create-service-context.js\";\n\nconst factory = createFactory();\n\nconst resolvePreviewController = factory.createHandlers(\n\tdescribeRoute({\n\t\tdescription: \"Validate a preview token for use by a browser application.\",\n\t\ttags: [\"client-previews\"],\n\t\tsummary: \"Resolve Preview\",\n\t\tresponses: openAPI.responses({\n\t\t\tschema: z.toJSONSchema(controllerSchemas.resolve.response),\n\t\t}),\n\t\tparameters: openAPI.parameters({\n\t\t\tparams: controllerSchemas.resolve.params,\n\t\t\theaders: { authorization: true },\n\t\t}),\n\t}),\n\tclientAuthentication,\n\tvalidate(\"param\", controllerSchemas.resolve.params),\n\tasync (c) => {\n\t\tconst { token } = c.req.valid(\"param\");\n\t\tconst context = createServiceContext(c);\n\n\t\tconst preview = await serviceWrapper(previewSessionServices.resolve, {\n\t\t\ttransaction: false,\n\t\t\tdefaultError: {\n\t\t\t\ttype: \"basic\",\n\t\t\t\tname: copy(\"server:core.routes.preview.resolve.error.name\"),\n\t\t\t\tmessage: copy(\"server:core.routes.preview.resolve.error.message\"),\n\t\t\t},\n\t\t})(context, { token });\n\t\tif (preview.error) throw new LucidAPIError(preview.error);\n\n\t\tclientScopeCheck(c, [\n\t\t\tgetCollectionClientScope(preview.data.entry.collectionKey),\n\t\t]);\n\n\t\tc.header(\"Cache-Control\", \"private, no-store\");\n\t\tc.header(\"Pragma\", \"no-cache\");\n\t\tc.header(\"Referrer-Policy\", \"no-referrer\");\n\n\t\tc.status(200);\n\t\treturn c.json(formatAPIResponse(c, { data: preview.data }));\n\t},\n);\n\nexport default resolvePreviewController;\n"],"mappings":"s0BAkBA,MAAM,EAFU,EAEuB,CAAC,CAAC,eACxC,EAAc,CACb,YAAa,6DACb,KAAM,CAAC,iBAAiB,EACxB,QAAS,kBACT,UAAW,EAAQ,UAAU,CAC5B,OAAQ,EAAE,aAAa,EAAkB,QAAQ,QAAQ,CAC1D,CAAC,EACD,WAAY,EAAQ,WAAW,CAC9B,OAAQ,EAAkB,QAAQ,OAClC,QAAS,CAAE,cAAe,EAAK,CAChC,CAAC,CACF,CAAC,EACD,EACA,EAAS,QAAS,EAAkB,QAAQ,MAAM,EAClD,KAAO,IAAM,CACZ,GAAM,CAAE,SAAU,EAAE,IAAI,MAAM,OAAO,EAC/B,EAAU,EAAqB,CAAC,EAEhC,EAAU,MAAM,EAAeA,EAAgC,CACpE,YAAa,GACb,aAAc,CACb,KAAM,QACN,KAAM,EAAK,+CAA+C,EAC1D,QAAS,EAAK,kDAAkD,CACjE,CACD,CAAC,CAAC,CAAC,EAAS,CAAE,OAAM,CAAC,EACrB,GAAI,EAAQ,MAAO,MAAM,IAAI,EAAc,EAAQ,KAAK,EAWxD,OATA,EAAiB,EAAG,CACnB,EAAyB,EAAQ,KAAK,MAAM,aAAa,CAC1D,CAAC,EAED,EAAE,OAAO,gBAAiB,mBAAmB,EAC7C,EAAE,OAAO,SAAU,UAAU,EAC7B,EAAE,OAAO,kBAAmB,aAAa,EAEzC,EAAE,OAAO,GAAG,EACL,EAAE,KAAK,EAAkB,EAAG,CAAE,KAAM,EAAQ,IAAK,CAAC,CAAC,CAC3D,CACD"}