UNPKG

@lucidcms/core

Version:

The core of the Lucid CMS. It's responsible for spinning up the API and serving the CMS.

2 lines 1.42 kB
import{copy as e}from"../../../libs/i18n/copy.mjs";import t from"../../../libs/repositories/preview-sessions.mjs";import{requiresPinnedPreviewVersion as n}from"./resolve-preview-mode.mjs";import r from"../../../utils/helpers/hash-preview-token.mjs";const i=/^[A-Za-z0-9_-]{43}$/,a=async(a,o)=>{if(!i.test(o.token))return{error:{type:`authorisation`,code:`preview_invalid`,message:e(`server:core.documents.preview.invalid.message`),status:401},data:void 0};let s=await new t(a.db.client,a.config.db).selectSingle({select:[`id`,`entry_collection_key`,`entry_document_id`,`entry_version_type`,`mode`,`entry_version_id`,`expires_at`],where:[{key:`token_hash`,operator:`=`,value:r(o.token)}],validation:{enabled:!1}});if(s.error)return s;if(!s.data)return{error:{type:`authorisation`,code:`preview_invalid`,message:e(`server:core.documents.preview.invalid.message`),status:401},data:void 0};let c=s.data,l=n(c.entry_version_type);return l&&(c.mode!==`scoped`||c.entry_version_id===null)||!l&&c.entry_version_id!==null?{error:{type:`authorisation`,code:`preview_invalid`,message:e(`server:core.documents.preview.invalid.message`),status:401},data:void 0}:new Date(c.expires_at).getTime()<=Date.now()?{error:{type:`authorisation`,code:`preview_expired`,message:e(`server:core.documents.preview.expired.message`),status:401},data:void 0}:{error:void 0,data:c}};export{a as default}; //# sourceMappingURL=resolve-session.mjs.map