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.28 kB
import{copy as e}from"../../libs/i18n/copy.mjs";import t from"../../constants/constants.mjs";import n from"../../utils/helpers/generate-secret.mjs";import r from"../../libs/repositories/options.mjs";import i from"../../libs/repositories/users.mjs";import{normalizeEmailInput as a}from"../../utils/helpers/normalize-input.mjs";import o from"../../libs/formatters/index.mjs";import{scrypt as s}from"@noble/hashes/scrypt.js";const c=async(c,l)=>{let u=new i(c.db.client,c.config.db),d=new r(c.db.client,c.config.db),f=a(l.email),p=await u.count({where:[]});if(p.error)return p;if(o.parseCount(p.data?.count)>0)return{error:{type:`basic`,message:e(`server:core.setup.already.completed`),status:400},data:void 0};let{secret:m,encryptSecret:h}=n(c.config.secrets.encryption),g=Buffer.from(s(l.password,m,t.scrypt)).toString(`base64`),[_,v]=await Promise.all([u.createSingle({data:{email:f,username:l.username,first_name:l.firstName,last_name:l.lastName,super_admin:!0,triggered_password_reset:!1,is_locked:!1,password:g,secret:h,invitation_accepted:!0},returning:[`id`],validation:{enabled:!0}}),d.upsertSingle({data:{name:`system_alert_email`,value_text:f}})]);return _.error?_:v.error?v:{error:void 0,data:_.data.id}};export{c as default}; //# sourceMappingURL=create-initial-admin.mjs.map