@andrewcaires/api 4.5.2 → 5.0.1

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/index.esm.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /*!
2
- * @andrewcaires/api v4.5.2
2
+ * @andrewcaires/api v5.0.1
3
3
  * Simple api for small applications using express, jsonwebtoken, sequelize and websocket
4
4
  * (c) 2026 Andrew Caires
5
5
  * @license: MIT
6
6
  */
7
- import{EventEmitter as e,isObject as t,noop as i,uuidv7 as r,loop as n,forEachSeries as o,isFunction as s,sleep as d,upperCamelCase as a,Validation as u,isArray as l,isString as p,isUndefined as c,clamp as g,isNumber as y,denied as v,isDef as h,uniqueID as E}from"@andrewcaires/utils.js";import{parameterFactory as A,Application as _,Ctx as m,Headers as O,Cookies as S,Query as I,App as f,Context as P,Argument as T,Session as R,Upload as N,Extends as C,Status as D,Post as b,Middleware as w,Get as B,Delete as x,Put as F,Controller as k,Body as U,Params as j,Files as L}from"@andrewcaires/express";import{Env as K,LogColor as M,Log as H,Hash as q,sha256 as Y}from"@andrewcaires/node";import{config as V}from"dotenv";import{Sequelize as $,Column as G,BelongsTo as W,Database as z,ModelName as J,Version as Z,Model as X,HasMany as Q,Hooks as ee,DefaultScope as te,Scopes as ie,Unique as re,Op as ne,Where as oe}from"@andrewcaires/sequelize";import se from"jsonwebtoken";import{readFileSync as de,existsSync as ae,statSync as ue,readdirSync as le,mkdirSync as pe,lstatSync as ce,rmSync as ge}from"fs";import{WebSocketServer as ye}from"ws";import{Store as ve}from"express-session";import{join as he}from"path";class Controller extends e{}function Ee(e,t,i,r){var n,o=arguments.length,s=o<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,i,r);else for(var d=e.length-1;d>=0;d--)(n=e[d])&&(s=(o<3?n(s):o>3?n(t,i,s):n(t,i))||s);return o>3&&s&&Object.defineProperty(t,i,s),s}function Ae(e,t){return function(i,r){t(i,r,e)}}function _e(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function me(e,t,i,r){return new(i||(i=Promise))(function(n,o){function s(e){try{a(r.next(e))}catch(e){o(e)}}function d(e){try{a(r.throw(e))}catch(e){o(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(s,d)}a((r=r.apply(e,t||[])).next())})}Controller.ATTRIBUTES=Symbol("ATTRIBUTES"),Controller.PERMISSIONS=Symbol("PERMISSIONS"),"function"==typeof SuppressedError&&SuppressedError,V({quiet:!0});class Env extends K{}Env.API_BASE_NAME=Env.getString("API_BASE_NAME",""),Env.API_BODYPARSER_STRICT=Env.getBool("API_BODYPARSER_STRICT",!0),Env.API_BODYPARSER_INFLATE=Env.getBool("API_BODYPARSER_INFLATE",!0),Env.API_BODYPARSER_LIMIT=Env.getString("API_BODYPARSER_LIMIT","10mb"),Env.API_BODYPARSER_TYPE=Env.getString("API_BODYPARSER_TYPE","json"),Env.API_CONSOLE_ERROR=Env.getBool("API_CONSOLE_ERROR",!1),Env.API_DATABASE_URL=Env.getString("API_DATABASE_URL",""),Env.API_DATABASE_LOG=Env.getBool("API_DATABASE_LOG",!1),Env.API_DATABASE_AUDIT=Env.getBool("API_DATABASE_AUDIT",!0),Env.API_DATABASE_PREFIX=Env.getString("API_DATABASE_PREFIX",""),Env.API_DATABASE_TIMEZONE=Env.getString("API_DATABASE_TIMEZONE","+00:00"),Env.API_HTTP_CRT=Env.getString("API_HTTP_CRT",""),Env.API_HTTP_KEY=Env.getString("API_HTTP_KEY",""),Env.API_HTTP_PORT=Env.getInt("API_HTTP_PORT",3e3),Env.API_HTTP_PUBLIC=Env.getString("API_HTTP_PUBLIC",""),Env.API_HTTP_CROSS=Env.getBool("API_HTTP_CROSS",!1),Env.API_HTTP_HYBRID=Env.getBool("API_HTTP_HYBRID",!1),Env.API_HTTP_NOTFOUND=Env.getString("API_HTTP_NOTFOUND",""),Env.API_HTTP_PATH=Env.getString("API_HTTP_PATH","/api"),Env.API_HTTP_REDIRECT=Env.getString("API_HTTP_REDIRECT",""),Env.API_KEY_HASH=Env.getString("API_KEY_HASH",""),Env.API_KEY_HEADER=Env.getString("API_KEY_HEADER","x-api-key"),Env.API_MODEL_LIMIT=Env.getInt("API_MODEL_LIMIT",10),Env.API_MODEL_LIMIT_MAX=Env.getInt("API_MODEL_LIMIT_MAX",500),Env.API_SLEEP_AUTH=Env.getMs("API_SLEEP_AUTH","2s"),Env.API_SLEEP_FORGOT=Env.getMs("API_SLEEP_FORGOT","5s"),Env.API_SLEEP_REGISTRY=Env.getMs("API_SLEEP_REGISTRY","5s"),Env.API_SESSION_NAME=Env.getString("API_SESSION_NAME","session.id"),Env.API_SESSION_LIFETIME=Env.getMs("API_SESSION_LIFETIME","1d"),Env.API_SESSION_SECRET=Env.getString("API_SESSION_SECRET","yoursecret"),Env.API_TOKEN_COOKIE=Env.getString("API_TOKEN_COOKIE","authorization"),Env.API_TOKEN_COOKIE_SET=Env.getBool("API_TOKEN_COOKIE_SET",!0),Env.API_TOKEN_CRT=Env.getString("API_TOKEN_CRT",""),Env.API_TOKEN_KEY=Env.getString("API_TOKEN_KEY",""),Env.API_TOKEN_FORGOT=Env.getMs("API_TOKEN_FORGOT","1d"),Env.API_TOKEN_HEADER=Env.getString("API_TOKEN_HEADER","authorization"),Env.API_TOKEN_HEADER_KEY=Env.getString("API_TOKEN_HEADER","bearer"),Env.API_TOKEN_LIFETIME=Env.getMs("API_TOKEN_LIFETIME","1d"),Env.API_TOKEN_RENEW=Env.getMs("API_TOKEN_RENEW","1d"),Env.API_UPLOAD_COUNT=Env.getInt("API_UPLOAD_COUNT",1),Env.API_UPLOAD_FIELD=Env.getString("API_UPLOAD_FIELD","upload"),Env.API_UPLOAD_SIZE=Env.getInt("API_UPLOAD_SIZE",2),Env.API_UPLOAD_TEMP=Env.getString("API_UPLOAD_TEMP","./temp"),Env.API_USER_HISTORY=Env.getBool("API_USER_HISTORY",!0),Env.API_WEBSOCKET_START=Env.getBool("API_WEBSOCKET_START",!1);const Oe=e=>{var t,i,r,n,o,s,d,a,u;return{audit_client:null!==(t=e.getIp())&&void 0!==t?t:"0.0.0.0",audit_href:(null===(i=null==e?void 0:e.req)||void 0===i?void 0:i.protocol)+"://"+(null===(r=null==e?void 0:e.req)||void 0===r?void 0:r.get("host"))+(null===(n=null==e?void 0:e.req)||void 0===n?void 0:n.originalUrl),audit_user_agent:null!==(s=null===(o=e.req)||void 0===o?void 0:o.headers["user-agent"])&&void 0!==s?s:"",audit_user_id:null!==(u=null===(a=null===(d=null==e?void 0:e.req)||void 0===d?void 0:d.user)||void 0===a?void 0:a.id)&&void 0!==u?u:null}},Se=A(({ctx:e})=>Oe(e)),Ie=A(({ctx:e})=>e.req.auth),fe=A(({ctx:e})=>e.req.user),Pe=new $(Env.API_DATABASE_URL,{logging:Env.API_DATABASE_LOG,prefix:Env.API_DATABASE_PREFIX,timezone:Env.API_DATABASE_TIMEZONE}),Te=(e,t,i)=>{var r,n,o,s,d;return{type:e,model:null!==(r=null==t?void 0:t.getTableName())&&void 0!==r?r:null,client:null!==(n=null==i?void 0:i.audit_client)&&void 0!==n?n:null,href:null!==(o=null==i?void 0:i.audit_href)&&void 0!==o?o:null,user_agent:null!==(s=null==i?void 0:i.audit_user_agent)&&void 0!==s?s:null,user_id:null!==(d=null==i?void 0:i.audit_user_id)&&void 0!==d?d:null,state:!0}},Re={afterCreate:(e,r)=>me(void 0,void 0,void 0,function*(){var n;if(!Env.API_DATABASE_AUDIT)return;const o=t(e)?e.constructor:null,s=null!==(n=null==o?void 0:o.primaryKeyAttribute)&&void 0!==n?n:null;yield xe.create(Object.assign(Object.assign({},Te("CREATE",o,r)),{record:s?e.getDataValue(s):null,data:e.toJSON()})).catch(i)}),afterUpdate:(e,r)=>me(void 0,void 0,void 0,function*(){var n;if(!Env.API_DATABASE_AUDIT)return;const o=t(e)?e.constructor:null,s=null!==(n=null==o?void 0:o.primaryKeyAttribute)&&void 0!==n?n:null,d={},a=e.changed();a&&a.forEach(t=>d[t]=e.getDataValue(t)),yield xe.create(Object.assign(Object.assign({},Te("UPDATE",o,r)),{record:s?e.getDataValue(s):null,data:d,previously:e.previous()})).catch(i)}),afterDestroy:(e,r)=>me(void 0,void 0,void 0,function*(){var n;if(!Env.API_DATABASE_AUDIT)return;const o=t(e)?e.constructor:null,s=null!==(n=null==o?void 0:o.primaryKeyAttribute)&&void 0!==n?n:null;yield xe.create(Object.assign(Object.assign({},Te("DELETE",o,r)),{record:s?e.getDataValue(s):null,data:e.toJSON()})).catch(i)})};let Ne=class Auth extends X{};Ee([G.Id(),_e("design:type",Number)],Ne.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],Ne.prototype,"secret",void 0),Ee([G.FullDate(),_e("design:type",Object)],Ne.prototype,"logout",void 0),Ee([G.String(),_e("design:type",String)],Ne.prototype,"user_agent",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Ne.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Ne.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],Ne.prototype,"deleted_at",void 0),Ee([W(()=>Be),_e("design:type",Number)],Ne.prototype,"user_id",void 0),Ne=Ee([z(Pe),J("auth"),Z("4.2.0")],Ne);let Ce=class Register extends X{};Ee([G.Id(),_e("design:type",Number)],Ce.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],Ce.prototype,"token",void 0),Ee([G.Boolean(),_e("design:type",Boolean)],Ce.prototype,"state",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Ce.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Ce.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],Ce.prototype,"deleted_at",void 0),Ee([W(()=>Be),_e("design:type",Number)],Ce.prototype,"user_id",void 0),Ce=Ee([z(Pe),J("register"),Z("4.2.0")],Ce);let De=class Group extends X{};Ee([G.Id(),_e("design:type",Number)],De.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],De.prototype,"name",void 0),Ee([G.Text(),_e("design:type",String)],De.prototype,"description",void 0),Ee([G.Boolean(),_e("design:type",Boolean)],De.prototype,"state",void 0),Ee([G.CreatedAt,_e("design:type",Date)],De.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],De.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],De.prototype,"deleted_at",void 0),Ee([Q(()=>be,"group_id"),_e("design:type",Array)],De.prototype,"groups_routes",void 0),Ee([Q(()=>be,"group_id"),_e("design:type",Array)],De.prototype,"users_groups",void 0),De=Ee([z(Pe),J("group"),ee(Re),Z("4.2.0")],De);let be=class UserGroup extends X{};Ee([G.CreatedAt,_e("design:type",Date)],be.prototype,"created_at",void 0),Ee([W(()=>De),_e("design:type",Number)],be.prototype,"group_id",void 0),Ee([W(()=>Be),_e("design:type",Number)],be.prototype,"user_id",void 0),be=Ee([z(Pe),J("users_groups"),ee(Re),Z("4.2.0")],be);let we=class UserHistory extends X{};Ee([G.String(),_e("design:type",String)],we.prototype,"password",void 0),Ee([G.CreatedAt,_e("design:type",Date)],we.prototype,"created_at",void 0),Ee([W(()=>Be),_e("design:type",Number)],we.prototype,"user_id",void 0),we=Ee([z(Pe),J("users_histories"),Z("4.2.0")],we);let Be=class User extends X{};Ee([G.Id(),_e("design:type",Number)],Be.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"name",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"email",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"username",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"password",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"salt",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"token",void 0),Ee([G.String(),_e("design:type",String)],Be.prototype,"avatar",void 0),Ee([G.DateOnly(),_e("design:type",String)],Be.prototype,"date",void 0),Ee([G.Text(),_e("design:type",String)],Be.prototype,"description",void 0),Ee([G.Boolean(),_e("design:type",Boolean)],Be.prototype,"state",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Be.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Be.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],Be.prototype,"deleted_at",void 0),Ee([Q(()=>xe,"user_id"),_e("design:type",Array)],Be.prototype,"audits",void 0),Ee([Q(()=>Ne,"user_id"),_e("design:type",Array)],Be.prototype,"auths",void 0),Ee([Q(()=>Ce,"user_id"),_e("design:type",Array)],Be.prototype,"registers",void 0),Ee([Q(()=>be,"user_id"),_e("design:type",Array)],Be.prototype,"users_groups",void 0),Ee([Q(()=>we,"user_id"),_e("design:type",Array)],Be.prototype,"users_histories",void 0),Be=Ee([z(Pe),J("user"),te({attributes:{exclude:["password","salt","token"]}}),ie({password:{attributes:{exclude:["token"]}},token:{attributes:{exclude:["password","salt"]}}}),ee(Re),Z("4.2.0")],Be);let xe=class Audit extends X{};Ee([G.Id(),_e("design:type",Number)],xe.prototype,"id",void 0),Ee([G.Enum("CREATE","DELETE","UPDATE"),_e("design:type",String)],xe.prototype,"type",void 0),Ee([G.String(),_e("design:type",String)],xe.prototype,"model",void 0),Ee([G.String(),_e("design:type",String)],xe.prototype,"record",void 0),Ee([G.Json(),_e("design:type",Object)],xe.prototype,"data",void 0),Ee([G.Json(),_e("design:type",Object)],xe.prototype,"previously",void 0),Ee([G.String(),_e("design:type",String)],xe.prototype,"client",void 0),Ee([G.Text(),_e("design:type",String)],xe.prototype,"href",void 0),Ee([G.String(),_e("design:type",String)],xe.prototype,"user_agent",void 0),Ee([G.Boolean(),_e("design:type",Boolean)],xe.prototype,"state",void 0),Ee([G.CreatedAt,_e("design:type",Date)],xe.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],xe.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],xe.prototype,"deleted_at",void 0),Ee([W(()=>Be),_e("design:type",Number)],xe.prototype,"user_id",void 0),xe=Ee([z(Pe),J("audit"),Z("4.2.0")],xe);let Fe=class Config extends X{static all(){return me(this,void 0,void 0,function*(){const e=yield this.findAll().catch(this.error),t={};return e&&e.forEach(e=>t[e.key]=e.value),t})}static del(e,t){return me(this,void 0,void 0,function*(){var i;const r=null!==(i=null==t?void 0:t.id)&&void 0!==i?i:null;return((yield this.destroy(Object.assign({where:{key:e},individualHooks:!0},{user_id:r})).catch(this.error))||0)>0})}static get(e){return me(this,arguments,void 0,function*(e,t=""){const[i]=(yield this.findOrCreate({where:{key:e},defaults:{key:e,value:t}}).catch(this.error))||[];return i?i.value:t})}static set(e,t,i){return me(this,void 0,void 0,function*(){var r;const n=null!==(r=null==i?void 0:i.id)&&void 0!==r?r:null,[o]=(yield this.findOrCreate(Object.assign({where:{key:e}},{user_id:n})).catch(this.error))||[];o&&(o.value=t,yield o.save().catch(this.error))})}};Ee([G.String(),_e("design:type",String)],Fe.prototype,"key",void 0),Ee([G.String(),_e("design:type",String)],Fe.prototype,"value",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Fe.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Fe.prototype,"updated_at",void 0),Fe=Ee([z(Pe),J("configs"),Z("4.2.0")],Fe);let ke=class Forgot extends X{};Ee([G.Id(),_e("design:type",Number)],ke.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],ke.prototype,"token",void 0),Ee([G.BigInt(),_e("design:type",Number)],ke.prototype,"timestamp",void 0),Ee([G.Boolean(),_e("design:type",Boolean)],ke.prototype,"state",void 0),Ee([G.CreatedAt,_e("design:type",Date)],ke.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],ke.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],ke.prototype,"deleted_at",void 0),Ee([W(()=>Be),_e("design:type",Number)],ke.prototype,"user_id",void 0),ke=Ee([z(Pe),J("forgot"),Z("4.2.0")],ke);let Ue=class Permission extends X{};Ee([G.Id(),_e("design:type",Number)],Ue.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],Ue.prototype,"name",void 0),Ee([G.String(),re(!0),_e("design:type",String)],Ue.prototype,"route",void 0),Ee([G.String(),_e("design:type",String)],Ue.prototype,"tag",void 0),Ee([G.Text(),_e("design:type",String)],Ue.prototype,"description",void 0),Ee([G.Boolean(),_e("design:type",Boolean)],Ue.prototype,"state",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Ue.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Ue.prototype,"updated_at",void 0),Ee([G.DeletedAt,_e("design:type",Object)],Ue.prototype,"deleted_at",void 0),Ee([Q(()=>je,"permission_id"),_e("design:type",Array)],Ue.prototype,"groups_permissions",void 0),Ue=Ee([z(Pe),J("permission"),ee(Re),Z("4.3.1")],Ue);let je=class GroupPermission extends X{};Ee([G.CreatedAt,_e("design:type",Date)],je.prototype,"created_at",void 0),Ee([W(()=>De),_e("design:type",Number)],je.prototype,"group_id",void 0),Ee([W(()=>Ue),_e("design:type",Number)],je.prototype,"permission_id",void 0),je=Ee([z(Pe),J("groups_permissions"),ee(Re),Z("4.2.0")],je);let Le=class Log extends X{static write(e,t,i){return me(this,void 0,void 0,function*(){yield this.writeRaw(M.White,"",e,t,i)})}static error(e,t,i){return me(this,void 0,void 0,function*(){yield this.writeRaw(M.Red,"error",e,t,i)})}static info(e,t,i){return me(this,void 0,void 0,function*(){yield this.writeRaw(M.Cyan,"info",e,t,i)})}static success(e,t,i){return me(this,void 0,void 0,function*(){yield this.writeRaw(M.Green,"success",e,t,i)})}static warning(e,t,i){return me(this,void 0,void 0,function*(){yield this.writeRaw(M.Yellow,"warning",e,t,i)})}static writeRaw(e,t,i,r,n){return me(this,void 0,void 0,function*(){n&&H.console(e,t,i),Pe&&(yield this.create({type:t,source:r,message:i}).catch(this.error))})}};Ee([G.Id(),_e("design:type",Number)],Le.prototype,"id",void 0),Ee([G.String(),_e("design:type",String)],Le.prototype,"type",void 0),Ee([G.String(),_e("design:type",String)],Le.prototype,"source",void 0),Ee([G.Text(),_e("design:type",String)],Le.prototype,"message",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Le.prototype,"created_at",void 0),Le=Ee([z(Pe),J("log"),Z("4.2.0")],Le);let Ke=class Migration extends X{};Ee([G.String(),_e("design:type",String)],Ke.prototype,"model",void 0),Ee([G.String(),_e("design:type",String)],Ke.prototype,"version",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Ke.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Ke.prototype,"updated_at",void 0),Ke=Ee([z(Pe),J("migration"),Z("4.2.0")],Ke);let Me=class Session extends X{};Ee([G.String(),_e("design:type",String)],Me.prototype,"session",void 0),Ee([G.Text(),_e("design:type",String)],Me.prototype,"json",void 0),Ee([G.BigInt(),_e("design:type",Number)],Me.prototype,"expired",void 0),Ee([G.CreatedAt,_e("design:type",Date)],Me.prototype,"created_at",void 0),Ee([G.UpdatedAt,_e("design:type",Date)],Me.prototype,"updated_at",void 0),Me=Ee([z(Pe),J("session"),Z("4.2.0")],Me);class AuthBase{static error(e){let t="token";Env.API_BASE_NAME&&(t=`${Env.API_BASE_NAME}.${t}`),Le.error(e.message,t,Env.API_CONSOLE_ERROR)}}class AuthKey extends AuthBase{static user(e,t){return me(this,void 0,void 0,function*(){if(!e)return{error:"INVALID TOKEN"};const i=t.hash.encrypt(e),r=yield Be.findOne({where:{token:i,state:!0}}).catch(this.error);if(r){const t=e.replace(/(-[\w]{4})/g,"-****"),[i]=(yield Ne.findOrCreate({where:{secret:t,user_id:r.id},defaults:{secret:t,user_id:r.id}}).catch(this.error))||[];if(i)return i.logout&&(i.logout=null,yield i.save().catch(this.error)),{auth:i,user:r}}return{error:"ACCESS DENIED"}})}}const He=e=>ae(e)?de(e):void 0,qe={http:He(Env.API_HTTP_CRT),token:He(Env.API_TOKEN_CRT)},Ye={http:He(Env.API_HTTP_KEY),token:He(Env.API_TOKEN_KEY)};class AuthToken extends AuthBase{static options(){return{algorithm:"RS256",expiresIn:`${Env.API_TOKEN_LIFETIME}ms`}}static create(e){return me(this,void 0,void 0,function*(){if(!Ye.token)return{error:"KEY NOT FOUND"};const{id:t}=e,i=r(),n=yield Ne.create({secret:i,user_id:t}).catch(this.error);if(!n)return{error:"INTERNAL SERVER ERROR"};return{auth:n,token:se.sign({id:t,secret:i},Ye.token,this.options())}})}static destroy(e){return me(this,void 0,void 0,function*(){return!(!e||e.logout)&&(e.logout=new Date,yield e.save(),!0)})}static renew(e){return me(this,void 0,void 0,function*(){if(!Ye.token)return{error:"KEY NOT FOUND"};const{error:t,decode:i}=this.verify(e,Env.API_TOKEN_RENEW/1e3);if(t)return{error:t};if(i){const{id:e,secret:t}=i;if(e&&t){const i=yield Be.findOne({where:{id:e,state:!0}}).catch(this.error);if(i){const n=yield Ne.findOne({where:{secret:t,user_id:i.id}}).catch(this.error);if(n&&!n.logout){n.secret=r(),yield n.save().catch(this.error);return{auth:n,token:se.sign({id:e,secret:n.secret},Ye.token,this.options())}}}return{error:"ACCESS DENIED"}}}return{error:"INVALID TOKEN"}})}static user(e){return me(this,void 0,void 0,function*(){const{error:t,decode:i}=this.verify(e);if(t)return{error:t};if(i){const{id:e,secret:t}=i;if(e&&t){const i=yield Be.findOne({where:{id:e,state:!0}}).catch(this.error);if(i){const e=yield Ne.findOne({where:{secret:t,user_id:i.id}}).catch(this.error);if(e&&!e.logout)return{auth:e,user:i}}return{error:"ACCESS DENIED"}}}return{error:"INVALID TOKEN"}})}static verify(e,t){if(!qe.token)return{error:"CERT NOT FOUND"};if(!e||e.split(".").length<3)return{error:"INVALID TOKEN"};try{return{decode:se.verify(e,qe.token,{clockTolerance:t})}}catch(e){return{error:"INVALID TOKEN"}}}}class Store extends ve{constructor(){super(),this.all=e=>me(this,void 0,void 0,function*(){e=e||i;const t=yield Me.findAll({attributes:["session"],where:{expired:{[ne.gte]:Date.now()}}}).catch(t=>(e(t),null));t&&e(null,t.map(e=>e.session)),e()}),this.clear=e=>me(this,void 0,void 0,function*(){yield Me.destroy().catch(i),e&&e()}),this.destroy=(e,t)=>me(this,void 0,void 0,function*(){yield Me.destroy({where:{session:e}}).catch(i),t&&t()}),this.expired=()=>me(this,void 0,void 0,function*(){yield Me.destroy({where:{expired:{[ne.lt]:Date.now()}}}).catch(i)}),this.get=(e,t)=>me(this,void 0,void 0,function*(){t=t||i;const r=yield Me.findOne({where:{session:e,expired:{[ne.gte]:Date.now()}}}).catch(e=>(t(e),null));if(r){const e=JSON.parse(r.json);if(e.cookie){if(new Date(e.cookie.expires).getTime()<=Date.now())return yield r.destroy().catch(i),void t(null)}return void t(null,e)}t(null)}),this.length=e=>me(this,void 0,void 0,function*(){e&&e(null,(yield Me.count().catch(i))||0)}),this.set=(e,t,r)=>me(this,void 0,void 0,function*(){r=r||i;const n=Date.now()+Env.API_SESSION_LIFETIME,o=JSON.stringify(t),[s,d]=(yield Me.findOrCreate({where:{session:e},defaults:{session:e,json:o,expired:n}}).catch(i))||[];s&&(d||(s.json=o,s.expired=n,yield s.save().catch(i))),r()}),this.loop=n(this.expired,3e4),this.loop.start()}}class Application extends _{constructor(e){super(e,{cert:qe.http,cross:Env.API_HTTP_CROSS,hybrid:Env.API_HTTP_HYBRID,json:{strict:Env.API_BODYPARSER_STRICT,inflate:Env.API_BODYPARSER_INFLATE,limit:Env.API_BODYPARSER_LIMIT,type:Env.API_BODYPARSER_TYPE},key:Ye.http,notfound:Env.API_HTTP_NOTFOUND,path:Env.API_HTTP_PATH,port:Env.API_HTTP_PORT,public:Env.API_HTTP_PUBLIC,redirect:Env.API_HTTP_REDIRECT,session:{store:new Store,name:Env.API_SESSION_NAME,secret:Env.API_SESSION_SECRET,cookie:{maxAge:Env.API_SESSION_LIFETIME},genid:r}}),this.hash=new q(Env.API_KEY_HASH)}error(e,t){Env.API_BASE_NAME&&(t=t?`${Env.API_BASE_NAME}.${t}`:Env.API_BASE_NAME),Le.error(e.message,t,Env.API_CONSOLE_ERROR)}log(e,t){Env.API_BASE_NAME&&(t=t?`${Env.API_BASE_NAME}.${t}`:Env.API_BASE_NAME),Le.info(e,t,!0)}listen(){const e=Object.create(null,{listen:{get:()=>super.listen}});return me(this,void 0,void 0,function*(){yield Pe.sync(),yield this.migrations(Pe),yield o(this.controllers,e=>me(this,void 0,void 0,function*(){s(e.sync)&&(yield e.sync(this))})),yield e.listen.call(this),Env.API_WEBSOCKET_START&&this.server&&(this._webSocket=new ye({server:this.server,verifyClient:(e,t)=>t(Env.API_WEBSOCKET_START)}),this._webSocket.on("connection",(e,t)=>me(this,void 0,void 0,function*(){t.url||(t.url="");const i=t.url.length<=1?"":t.url.replace(/\//g,".");let r;e.on("message",n=>me(this,void 0,void 0,function*(){if(r)try{const o=JSON.parse(n);this.emit("ws.message"+i,{data:o,message:n,req:t,user:r,ws:e})}catch(o){this.emit("ws.message"+i,{erro:o,message:n,req:t,user:r,ws:e})}else{const{user:o}=yield AuthToken.user(n.toString());o&&(r=o,this.emit("ws.connection"+i,{req:t,user:r,ws:e}))}r||e.close()})),e.on("close",()=>{r&&this.emit("ws.close"+i,{user:r,ws:e})}),yield d(2e3),r||e.close()})))})}migrations(e){return me(this,void 0,void 0,function*(){const t=[];yield o(Object.keys(e.models),i=>me(this,void 0,void 0,function*(){var r;const n=e.models[i],o=n.version();if(!o)return;const[s,d]=null!==(r=yield Ke.findOrCreate({where:{model:n.tableName},defaults:{model:n.tableName,version:""}}).catch(this.error))&&void 0!==r?r:[];s&&(d||s.version!=o)&&(s.version=o,yield s.save().catch(this.error),t.push(n))})),yield o(t,e=>me(this,void 0,void 0,function*(){return yield e.updateAttributes()}))})}websocket(){return this._webSocket}}var Ve,$e,Ge;class ControllerBase extends Controller{constructor(){super(...arguments),this[Ve]=[]}auth(e,t,i,r,n,o,s){return me(this,void 0,void 0,function*(){var d,a;t=null!=t?t:n,r=`${Env.API_TOKEN_HEADER_KEY} ${r}`;const[u,l]=null!==(a=null===(d=null!=i?i:r)||void 0===d?void 0:d.split(" "))&&void 0!==a?a:["",""];if(!(t||l&&u.toLowerCase()==Env.API_TOKEN_HEADER_KEY))return e.error("INVALID TOKEN");const{auth:p,error:c,user:g}=yield t?AuthKey.user(t,s):AuthToken.user(l);return c?e.error(c):p&&g?!t&&p.user_agent&&p.user_agent!=o?e.error("INVALID TOKEN"):(e.req.auth=p,e.req.user=g,void e.next()):e.error("INTERNAL SERVER ERROR")})}canCreate(e,t,i){return me(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".create",i)})}canDelete(e,t,i){return me(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".delete",i)})}canRead(e,t,i){return me(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".read",i)})}canUpdate(e,t,i){return me(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".update",i)})}error(e){let t="controller_base";Env.API_BASE_NAME&&(t=`${Env.API_BASE_NAME}.${t}`),Le.error(e.message,t,Env.API_CONSOLE_ERROR)}name(){var e,t;return(null!==(t=null===(e=this.constructor)||void 0===e?void 0:e.name)&&void 0!==t?t:"api").replace(/(([a-z])([A-Z]))/g,"$2_$3")}permission(e,t,i){return me(this,void 0,void 0,function*(){if(i){if((yield this.permissions(i,{route:t})).length>0)return e.next()}e.unauthorized("ACCESS DENIED")})}permissions(e,t){return me(this,void 0,void 0,function*(){var i;return null!==(i=yield Ue.findAll({where:Object.assign(Object.assign({},null!=t?t:{}),{state:!0}),include:[{model:je,required:!0,include:[{model:De,required:!0,where:{state:!0},include:[{model:be,required:!0,where:{user_id:e.id}}]}]}]}).catch(this.error))&&void 0!==i?i:[]})}session(e,t,r){return me(this,void 0,void 0,function*(){r.auth&&r.user&&(r.user_agent?r.user_agent!=t&&r.regenerate(i):(r.user_agent=t,r.save(i))),e.next()})}sync(){return me(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield o(this[Controller.PERMISSIONS],i=>me(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=a(e.replace(/_/g," ")," ");yield Ue.findOrCreate({where:{route:r},defaults:Object.assign({name:`${n} ${a(i," ")}`,route:r,tag:n},t)})}))})}upload(e,t){t.path||(t.path=Env.API_UPLOAD_TEMP),t.size||(t.size=Env.API_UPLOAD_SIZE),t.field||(t.field=Env.API_UPLOAD_FIELD),N.middleware(e,t)}validation(e,t){return me(this,void 0,void 0,function*(){const{error:i,value:r}=yield u.object(t).parse().validateAsync(e.req.body);if(i)return e.validation(i);e.req.body=r,e.next()})}}Ve=Controller.PERMISSIONS,Ee([Ae(0,m()),Ae(1,O(Env.API_KEY_HEADER)),Ae(2,O(Env.API_TOKEN_HEADER)),Ae(3,S(Env.API_TOKEN_COOKIE)),Ae(4,I(Env.API_KEY_HEADER)),Ae(5,O("user-agent")),Ae(6,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,String,String,String,String,Application]),_e("design:returntype",Promise)],ControllerBase.prototype,"auth",null),Ee([Ae(0,m()),Ae(1,T()),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],ControllerBase.prototype,"canCreate",null),Ee([Ae(0,m()),Ae(1,T()),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],ControllerBase.prototype,"canDelete",null),Ee([Ae(0,m()),Ae(1,T()),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],ControllerBase.prototype,"canRead",null),Ee([Ae(0,m()),Ae(1,T()),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],ControllerBase.prototype,"canUpdate",null),Ee([Ae(0,m()),Ae(1,T()),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],ControllerBase.prototype,"permission",null),Ee([Ae(0,m()),Ae(1,O("user-agent")),Ae(2,R()),_e("design:type",Function),_e("design:paramtypes",[P,String,Object]),_e("design:returntype",Promise)],ControllerBase.prototype,"session",null),Ee([Ae(0,m()),Ae(1,T()),_e("design:type",Function),_e("design:paramtypes",[P,Object]),_e("design:returntype",void 0)],ControllerBase.prototype,"upload",null),Ee([Ae(0,m()),Ae(1,T()),_e("design:type",Function),_e("design:paramtypes",[P,Object]),_e("design:returntype",Promise)],ControllerBase.prototype,"validation",null);let We=class ControllerModel extends ControllerBase{constructor(){super(...arguments),this[$e]=[],this[Ge]=["create","read","update","delete"]}attributes(e){if(0==this[ControllerBase.ATTRIBUTES].length&&(this[ControllerBase.ATTRIBUTES]=Object.keys(this.model().getAttributes())),l(e))return e.length?e.map(e=>p(e)&&-1!=this[ControllerBase.ATTRIBUTES].indexOf(e)?e:void 0).filter(p):this[ControllerBase.ATTRIBUTES];const{exclude:t,include:i}=e,r=c(i)?this[ControllerBase.ATTRIBUTES]:i.map(e=>p(e)&&-1!=this[ControllerBase.ATTRIBUTES].indexOf(e)?e:void 0).filter(p),n=null!=t?t:[];return n.length?r.filter(e=>-1==n.indexOf(e)?e:void 0).filter(p):r}create(e){return me(this,arguments,void 0,function*({ctx:e,options:t,body:i}){const r=yield this.model().create(Object.assign(Object.assign({},e.req.body),i||{}),Object.assign(Object.assign({},t||{}),Oe(e))).catch(this.error);if(r){const t=this.key();return e.prepare(D.OK,{[t]:r.getDataValue(t)}),r}e.error("INTERNAL SERVER ERROR")})}delete(e){return me(this,arguments,void 0,function*({ctx:e,options:t}){const i=this.key(),{[i]:r}=e.req.params;if(!r)return e.error("INTERNAL SERVER ERROR"),0;const n=yield this.model().destroy(Object.assign(Object.assign(Object.assign({},t||{}),{where:Object.assign(Object.assign({},(t||{}).where),{[i]:r}),individualHooks:!0}),Oe(e))).catch(this.error);return n?(e.success("OK"),n):(e.notFound("RECORD NOT FOUND"),0)})}error(e){let t="controller_model";Env.API_BASE_NAME&&(t=`${Env.API_BASE_NAME}.${t}`),(null==e?void 0:e.sql)?Le.error((null==e?void 0:e.message)+"\n"+(null==e?void 0:e.sql),t,Env.API_CONSOLE_ERROR):super.error(e)}findAll(e){return me(this,arguments,void 0,function*({ctx:e,options:t,callback:i,scope:r,advanced:n,attributes:o,limited:s}){var d,a,u;const l=this.scope(r),v=Object.assign({},t||{}),{fields:h,limit:E,offset:A,asc:_,desc:m,search:O,where:S}=e.req.query;if(c(v.limit)){let e=Env.API_MODEL_LIMIT;p(E)&&(e=parseInt(E)||0),e=g(e,-1,Env.API_MODEL_LIMIT_MAX),v.limit=e>0?e:s?Env.API_MODEL_LIMIT:void 0}if(y(v.limit)&&(v.limit=v.limit>0?v.limit:void 0),p(A)){const e=parseInt(A)||0;v.offset=e>0?e:void 0}o=null!=o?o:this.attributes(null!==(d=null==v?void 0:v.attributes)&&void 0!==d?d:[]);const I=e=>o.indexOf(e)>=0,f=[];p(h)&&f.push(...h.split(";").filter(I)),f.length&&(v.attributes=f);const P=[];if(p(_)&&_.length&&P.push(..._.split(";").filter(I).map(e=>[e,"ASC"])),p(m)&&m.length&&P.push(...m.split(";").filter(I).map(e=>[e,"DESC"])),P.length&&(v.order=P),v.where=Object.assign({},v.where||{}),p(S)&&(null==n||n)){const t=oe.parse(o,S);if(!c(t.error))return e.validation(t.error.join(", ")),{count:0,records:[]};v.where=Object.assign(Object.assign({},v.where),null!==(a=t.value)&&void 0!==a?a:{})}else{const e=[];o.forEach(t=>{p(O)&&O.length&&e.push({[t]:{[ne.like]:`%${O}%`}})}),e.length&&(v.where=Object.assign(Object.assign({},v.where),{[ne.or]:[...e]}))}const T=l.count(Object.assign(Object.assign({},v),{distinct:!!v.include,col:this[ControllerBase.ATTRIBUTES].length?this[ControllerBase.ATTRIBUTES][0]:void 0})).catch(this.error),R=l.findAll(v).catch(this.error);yield Promise.allSettled([T,R]);const N=null!==(u=yield T)&&void 0!==u?u:0;let C=yield R;const b={count:N};return C?(C=i?yield i(C):C,(y(null==t?void 0:t.limit)||0==N)&&(b.count=C.length),e.prepare(D.OK,Object.assign(Object.assign({},b),{records:C})),Object.assign(Object.assign({},b),{records:C})):(e.error("INTERNAL SERVER ERROR"),Object.assign(Object.assign({},b),{records:[]}))})}findOne(e){return me(this,arguments,void 0,function*({ctx:e,options:t,callback:i,scope:r}){const n=this.key(),{[n]:o}=e.req.params,s=yield this.scope(r).findOne(Object.assign(Object.assign({},t||{}),{where:Object.assign(Object.assign({},(t||{}).where),{[n]:o})})).catch(this.error);return s?(e.prepare(D.OK,i?yield i(s):s.toJSON()),s):null===s?e.notFound("RECORD NOT FOUND"):void e.error("INTERNAL SERVER ERROR")})}sync(){return me(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield o(this[ControllerBase.PERMISSIONS],i=>me(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=a(e.replace(/_/g," ")," ");yield Ue.findOrCreate({where:{route:r},defaults:Object.assign({name:`${n} ${a(i," ")}`,route:r,tag:n},t)})}))})}update(e){return me(this,arguments,void 0,function*({ctx:e,options:t,body:i}){var r;const n=this.key(),{[n]:o}=e.req.params,[s]=null!==(r=yield this.model().update(Object.assign(Object.assign({},e.req.body),i||{}),Object.assign(Object.assign(Object.assign({},t||{}),{where:Object.assign(Object.assign({},(t||{}).where),{[n]:o}),individualHooks:!0}),Oe(e))).catch(this.error))&&void 0!==r?r:[];return s?(e.success("OK"),!0):(e.success("RECORD NOT CHANGED"),!1)})}key(){return this.model().primaryKeyAttribute}name(){return this.model().tableName}scope(e){return e?this.model().scope(e):this.model()}};$e=ControllerBase.ATTRIBUTES,Ge=ControllerBase.PERMISSIONS,We=Ee([C(ControllerBase)],We);let ze=class ControllerCrud extends We{constructor(){super(...arguments),this._crud={}}CrudArgumentsCreate(e){return{ctx:e}}CrudArgumentsFindAll(e){return{ctx:e}}CrudArgumentsFindOne(e){return{ctx:e}}CrudArgumentsDelete(e){return{ctx:e}}CrudArgumentsUpdate(e){return{ctx:e}}CrudValidationCreate(){return this._crud}CrudValidationUpdate(){return this._crud}add(e){return me(this,void 0,void 0,function*(){yield this.create(this.CrudArgumentsCreate(e))})}all(e){return me(this,void 0,void 0,function*(){yield this.findAll(this.CrudArgumentsFindAll(e))})}del(e){return me(this,void 0,void 0,function*(){yield this.delete(this.CrudArgumentsDelete(e))})}get(e){return me(this,void 0,void 0,function*(){yield this.findOne(this.CrudArgumentsFindOne(e))})}set(e){return me(this,void 0,void 0,function*(){yield this.update(this.CrudArgumentsUpdate(e))})}validationCreate(e){return me(this,void 0,void 0,function*(){const t=this.CrudValidationCreate();if(t==this._crud)return e.error("INTERNAL SERVER ERROR");yield this.validation(e,t)})}validationUpdate(e){return me(this,void 0,void 0,function*(){const t=this.CrudValidationUpdate();if(t==this._crud)return e.error("INTERNAL SERVER ERROR");yield this.validation(e,t)})}};Ee([b(),w("auth"),w("canCreate"),w("validationCreate"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"add",null),Ee([B(),w("auth"),w("canRead"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"all",null),Ee([x("/:id"),w("auth"),w("canDelete"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"del",null),Ee([B("/:id"),w("auth"),w("canRead"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"get",null),Ee([F("/:id"),w("auth"),w("canUpdate"),w("validationUpdate"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"set",null),Ee([Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"validationCreate",null),Ee([Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],ze.prototype,"validationUpdate",null),ze=Ee([C(We)],ze);let Je=class AuditsController extends We{model(){return xe}all(e,t,i){return me(this,void 0,void 0,function*(){const r={};t&&(r.type=t),i&&(r.table=i),yield this.findAll({ctx:e,options:{attributes:{exclude:["data","previously"]},where:r,order:[["created_at","DESC"]]},limited:!0})})}get(e){return me(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}};Ee([B(),w("auth"),w("canRead"),Ae(0,m()),Ae(1,I("type")),Ae(2,I("table")),_e("design:type",Function),_e("design:paramtypes",[P,String,String]),_e("design:returntype",Promise)],Je.prototype,"all",null),Ee([B("/:id"),w("auth"),w("canRead"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],Je.prototype,"get",null),Je=Ee([k("/audits"),C(We)],Je);let Ze=class AuthController extends ControllerBase{login(e,t,i,r,n,o){return me(this,void 0,void 0,function*(){var s;yield d(Env.API_SLEEP_AUTH);const a=yield Be.scope("password").findOne({where:{[ne.or]:[{email:i},{username:i}]}}).catch(this.error);if(r+=null!==(s=null==a?void 0:a.salt)&&void 0!==s?s:"",!a||a.password!=Y(r))return e.notFound("INVALID USERNAME OR PASSWORD"),o.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e});const u=yield Ce.findOne({where:{state:!0,user_id:a.id}}).catch(this.error);if(u)return e.error("ACTIVATION REQUIRED"),o.emit("auth.activation",{ctx:e,register:u,user:a}),void this.emit("auth.activation",{ctx:e,register:u,user:a});if(!a.state)return e.notFound("INVALID USERNAME OR PASSWORD"),o.emit("auth.failure",{ctx:e,user:a}),void this.emit("auth.failure",{ctx:e,user:a});const{auth:l,error:p,token:c}=yield AuthToken.create(a);return p?(e.error(p),o.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e})):l&&c?(l.user_agent=t,yield l.save().catch(this.error),Env.API_TOKEN_COOKIE_SET&&e.res.cookie(Env.API_TOKEN_COOKIE,c,{maxAge:n?Env.API_TOKEN_LIFETIME:void 0}),e.json({token:c}),o.emit("auth.login",{auth:l,ctx:e,user:a}),void this.emit("auth.login",{auth:l,ctx:e,user:a})):(e.error("INTERNAL SERVER ERROR"),o.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e}))})}logout(e,t,i,r){return me(this,void 0,void 0,function*(){if(yield AuthToken.destroy(t))return e.success("OK"),r.emit("auth.logout",{auth:t,ctx:e,user:i}),void this.emit("auth.logout",{auth:t,ctx:e,user:i});e.unauthorized("ACCESS DENIED")})}renew(e,t,i,r){return me(this,void 0,void 0,function*(){const{auth:n,error:o,token:s}=yield AuthToken.renew(i);return o?e.error(o):n?(n.user_agent=t,yield n.save().catch(this.error),e.json({token:s}),r.emit("auth.renew",{auth:n,ctx:e}),void this.emit("auth.renew",{auth:n,ctx:e})):e.error("INTERNAL SERVER ERROR")})}user(e,t){return me(this,void 0,void 0,function*(){const i=yield this.permissions(t);if(!i)return e.error("INTERNAL SERVER ERROR");e.json(Object.assign(Object.assign({},v(["username","date","description","state","created_at","updated_at","deleted_at"],t.toJSON())),{permissions:i.map(e=>e.route)}))})}};var Xe;Ee([b("/login"),w("validation",{username:u.string().min(3).required(),password:u.string().min(5).required(),remember:u.boolean().empty(!1)}),Ae(0,m()),Ae(1,O("user-agent")),Ae(2,U("username")),Ae(3,U("password")),Ae(4,U("remember")),Ae(5,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,String,String,Boolean,Application]),_e("design:returntype",Promise)],Ze.prototype,"login",null),Ee([B("/logout"),w("auth"),Ae(0,m()),Ae(1,Ie()),Ae(2,fe()),Ae(3,f()),_e("design:type",Function),_e("design:paramtypes",[P,Ne,Be,Application]),_e("design:returntype",Promise)],Ze.prototype,"logout",null),Ee([b("/renew"),w("validation",{token:u.string().required()}),Ae(0,m()),Ae(1,O("user-agent")),Ae(2,U("token")),Ae(3,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,String,Application]),_e("design:returntype",Promise)],Ze.prototype,"renew",null),Ee([B(),w("auth"),Ae(0,m()),Ae(1,fe()),_e("design:type",Function),_e("design:paramtypes",[P,Be]),_e("design:returntype",Promise)],Ze.prototype,"user",null),Ze=Ee([k("/auth"),C(ControllerBase)],Ze);let Qe=class FilesController extends ControllerBase{constructor(){super(...arguments),this[Xe]=["delete","download","edit","list","read","rename","upload","write"]}directory(){return Env.API_HTTP_PUBLIC||"./"}files(e){return me(this,void 0,void 0,function*(){let{path:t}=e.req;t=t.replace(/(^\/path(\/)?)|([\\.]{1,2}\/)/g,"");const i=he(this.directory(),t);if(!ae(i)||!ue(i).isDirectory())return e.notFound("RECORD NOT FOUND");let r=[];return r=le(i),r=r.map(e=>this.info(he(i,e))),r=r.filter(h),Object.assign(Object.assign({},this.info(i)),{files:r})})}access(e,t,i){return me(this,void 0,void 0,function*(){yield this.permission(e,this.name()+"."+t,i)})}info(e){if(!ae(e))return null;const t=ue(e),i=e.split("/").pop();e=e.replace(this.directory(),"/").replace(/^\/\//,"/");const r=t.isDirectory();return{name:i,path:e.replace(/^\/\//,"/"),size:t.size,extension:r?"":"."+e.split(".").pop(),created:t.birthtime,modified:t.mtime,directory:r,symlink:t.isSymbolicLink()}}name(){return"files"}sync(){return me(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t=a(e.replace(/_/g," ")," "),i={description:"",state:!0};yield o(this[ControllerBase.PERMISSIONS],r=>me(this,void 0,void 0,function*(){const n=`${e}.${r}`;yield Ue.findOrCreate({where:{route:n},defaults:Object.assign({name:`${t} ${a(r," ")}`,route:n,tag:t},i)})}))})}};Xe=ControllerBase.PERMISSIONS,Ee([B("/path"),B("/path/*path"),w("auth"),w("access","list"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],Qe.prototype,"files",null),Ee([Ae(0,m()),Ae(1,T()),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],Qe.prototype,"access",null),Qe=Ee([k("/files"),C(ControllerBase)],Qe);let et=class ForgotController extends ControllerBase{check(e,t){return me(this,void 0,void 0,function*(){const i=yield this.find(t);if(!i||!i.user)return e.notFound("RECORD NOT FOUND");i.token=E(),yield i.save(),e.json({token:i.token})})}forgot(e,t,i){return me(this,void 0,void 0,function*(){yield d(Env.API_SLEEP_FORGOT);const r=t,n=yield Be.findOne({where:{[ne.or]:[{email:r},{username:t}]}}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");const o=E(),s=Date.now()+6e4*Env.API_TOKEN_FORGOT,a=yield ke.create({token:o,timestamp:s,state:!0,user_id:n.id});e.success("OK"),i.emit("forgot.send",{ctx:e,forgot:a,user:n}),this.emit("forgot.send",{ctx:e,forgot:a,user:n})})}reset(e,t,i,r){return me(this,void 0,void 0,function*(){const n=yield this.find(t);if(!n)return e.notFound("RECORD NOT FOUND");n.state=!1,yield n.save().catch(this.error),n.user.password=Y(i),yield n.user.save().catch(this.error),e.success("OK"),r.emit("forgot.reset",{ctx:e,user:n.user}),this.emit("forgot.reset",{ctx:e,user:n.user})})}find(e){return me(this,void 0,void 0,function*(){return yield ke.findOne({where:{token:e,state:!0},include:[{model:Be,required:!0}]}).catch(this.error)})}};Ee([B("/check"),w("validation",{token:u.string().required()}),Ae(0,m()),Ae(1,U("token")),_e("design:type",Function),_e("design:paramtypes",[P,String]),_e("design:returntype",Promise)],et.prototype,"check",null),Ee([b(),w("validation",{username:u.string().min(4).required()}),Ae(0,m()),Ae(1,U("username")),Ae(2,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,Application]),_e("design:returntype",Promise)],et.prototype,"forgot",null),Ee([b("/reset"),w("validation",{token:u.string().required(),password:u.string().min(5).required()}),Ae(0,m()),Ae(1,U("token")),Ae(2,U("password")),Ae(3,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,String,Application]),_e("design:returntype",Promise)],et.prototype,"reset",null),et=Ee([k("/forgot"),C(ControllerBase)],et);let tt=class GroupsController extends ze{constructor(){super(...arguments),this.schemaCreate={name:u.string().required(),description:u.string().empty(""),state:u.boolean().parse().required()},this.schemaUpdate={name:u.string().empty(),description:u.string().empty(),state:u.boolean().parse().empty()}}model(){return De}CrudArgumentsFindAll(e){return{ctx:e}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};tt=Ee([k("/groups"),C(ze)],tt);let it=class GroupsPermissionsController extends We{model(){return je}all(e,t){return me(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{group_id:t},include:[{model:Ue,required:!0}]},callback:e=>e.map(e=>e.permission)})})}me(e,t){return me(this,void 0,void 0,function*(){yield this.all(e,t.id.toString())})}set(e,t,i,r){return me(this,void 0,void 0,function*(){const n=yield De.findByPk(t,{attributes:["id"]}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");const o=n.id;if(yield je.destroy(Object.assign({where:{group_id:o},individualHooks:!0},r)),i){let e=0;yield d(1e3);for(let t=0;t<i.length;t++)e=yield Ue.count({where:{id:i[t]}}),e&&(yield je.create({group_id:o,permission_id:i[t]},Object.assign({},r)))}e.success("OK")})}};var rt;Ee([B("/:id/permissions"),w("auth"),w("canRead","groups"),Ae(0,m()),Ae(1,j("id")),_e("design:type",Function),_e("design:paramtypes",[P,String]),_e("design:returntype",Promise)],it.prototype,"all",null),Ee([B("/permissions"),w("auth"),w("canRead","users"),Ae(0,m()),Ae(1,fe()),_e("design:type",Function),_e("design:paramtypes",[P,Be]),_e("design:returntype",Promise)],it.prototype,"me",null),Ee([F("/:id/permissions"),w("auth"),w("canUpdate","groups"),w("validation",{permissions:u.array(u.number().parse())}),Ae(0,m()),Ae(1,j("id")),Ae(2,U("permissions")),Ae(3,Se()),_e("design:type",Function),_e("design:paramtypes",[P,String,Array,Object]),_e("design:returntype",Promise)],it.prototype,"set",null),it=Ee([k("/groups"),C(We)],it);let nt=class LogsController extends We{constructor(){super(...arguments),this[rt]=["read"]}model(){return Le}all(e,t,i){return me(this,void 0,void 0,function*(){const r={};t&&(r.type=t),i&&(r.source=i),yield this.findAll({ctx:e,options:{where:r,order:[["created_at","DESC"]]},limited:!0})})}};rt=We.PERMISSIONS,Ee([B(),w("auth"),w("canRead"),Ae(0,m()),Ae(1,I("type")),Ae(2,I("source")),_e("design:type",Function),_e("design:paramtypes",[P,String,String]),_e("design:returntype",Promise)],nt.prototype,"all",null),nt=Ee([k("/logs"),C(We)],nt);let ot=class PermissionsController extends ze{constructor(){super(...arguments),this.schemaCreate={name:u.string().required(),route:u.string().required(),tag:u.string().required(),description:u.string().empty(""),state:u.boolean().parse().required()},this.schemaUpdate={name:u.string().empty(),route:u.string().empty(),tag:u.string().empty(),description:u.string().empty(),state:u.boolean().parse().empty()}}model(){return Ue}CrudArgumentsFindAll(e){return{ctx:e}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};ot=Ee([k("/permissions"),C(ze)],ot);let st=class RegisterController extends ControllerBase{register(e,t,i){return me(this,void 0,void 0,function*(){yield d(Env.API_SLEEP_REGISTRY);const{name:r,date:n,email:o,username:s,password:a,confirm:u}=t,l=s||o,p=Y(a);if(yield Be.count({where:{[ne.or]:[{email:o},{username:l}]}}).catch(this.error))return e.validation("INVALID EMAIL OR USERNAME");if(p!=Y(u))return e.error("INVALID PASSWORD");const c=yield Be.create({name:r,email:o,username:l,password:p,avatar:"",date:n,description:"",state:!1}).catch(this.error);if(!c)return e.error("INTERNAL SERVER ERROR");const g=yield Ce.create({token:yield this.getId(),user_id:c.id,state:!0}).catch(this.error);if(!g)return yield c.destroy().catch(this.error),e.error("INTERNAL SERVER ERROR");e.success("OK"),i.emit("register.user",{ctx:e,register:g,user:c}),this.emit("register.user",{ctx:e,register:g,user:c})})}confirm(e,t,i){return me(this,void 0,void 0,function*(){const r=yield Ce.findOne({where:{token:t,state:!0},include:[{model:Be,required:!0}]}).catch(this.error);if(!r)return e.notFound("RECORD NOT FOUND");r.state=!1,yield r.save().catch(this.error),r.user.state=!0,yield r.user.save().catch(this.error),e.success("OK"),i.emit("register.confirm",{ctx:e,register:r,user:r.user}),this.emit("register.confirm",{ctx:e,register:r,user:r.user})})}send(e,t,i){return me(this,void 0,void 0,function*(){const r=t,n=yield Ce.findOne({where:{state:!0},include:[{model:Be,required:!0,where:{[ne.or]:[{email:r},{username:t}]}}]}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");e.success("OK"),i.emit("register.send",{ctx:e,register:n,user:n.user}),this.emit("register.send",{ctx:e,register:n,user:n.user})})}getId(){return me(this,void 0,void 0,function*(){const e=r();return(yield Ce.count({where:{token:e}}))?this.getId():e})}};Ee([b(),w("validation",{name:u.string().required(),date:u.date().required(),email:u.string().email().required(),username:u.string().min(4).empty(),password:u.string().min(5).required(),confirm:u.string().min(5).required()}),Ae(0,m()),Ae(1,U()),Ae(2,f()),_e("design:type",Function),_e("design:paramtypes",[P,Object,Application]),_e("design:returntype",Promise)],st.prototype,"register",null),Ee([b("/confirm"),w("validation",{token:u.string().required()}),Ae(0,m()),Ae(1,U("token")),Ae(2,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,Application]),_e("design:returntype",Promise)],st.prototype,"confirm",null),Ee([b("/send"),w("validation",{username:u.string().min(4).required()}),Ae(0,m()),Ae(1,U("username")),Ae(2,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,Application]),_e("design:returntype",Promise)],st.prototype,"send",null),st=Ee([k("/register"),C(ControllerBase)],st);let dt=class SetupController extends ControllerBase{setup(e,t){return me(this,void 0,void 0,function*(){var i;if(yield Be.count())return e.success("OK");const r=E(),n=yield Be.create({name:"Admin",email:"admin@localhost",username:"admin",password:Y("admin"+r),salt:r,token:"",avatar:"",date:new Date,description:"DEFAULT",state:!0},Object.assign({},t)),s=yield De.create(Object.assign({name:"Admin"},{description:"API CORE",state:!0}),Object.assign({},t));yield be.create({user_id:n.id,group_id:s.id},Object.assign({},t));const d=null!==(i=yield Ue.findAll({where:{state:!0}}).catch(this.error))&&void 0!==i?i:[];yield o(d,e=>me(this,void 0,void 0,function*(){yield je.create({group_id:s.id,permission_id:e.id},Object.assign({},t))})),e.success("OK")})}};Ee([B(),Ae(0,m()),Ae(1,Se()),_e("design:type",Function),_e("design:paramtypes",[P,Object]),_e("design:returntype",Promise)],dt.prototype,"setup",null),dt=Ee([k("/setup"),C(ControllerBase)],dt);let at=class UsersController extends We{model(){return Be}constructor(){super(),this.path=Env.API_HTTP_PUBLIC+"/avatar",Env.API_HTTP_PUBLIC&&ae(Env.API_HTTP_PUBLIC)&&!ae(this.path)&&pe(this.path)}avatar(e,t,i,r){return me(this,void 0,void 0,function*(){if(t.length){const n=t[0].filename||"";if(n){const t=this.path+"/"+i.avatar;if(ae(t)&&ce(t).isFile()&&ge(t),i.avatar=n,yield i.save(Object.assign({},r)).catch(this.error))return e.success("OK")}}e.success("RECORD NOT CHANGED")})}avatar_del(e,t,i){return me(this,void 0,void 0,function*(){const r=this.path+"/"+t.avatar;t.avatar="",(yield t.save(Object.assign({},i)).catch(this.error))&&ae(r)&&ge(r),e.success("OK")})}password(e,t,i,r,n){return me(this,void 0,void 0,function*(){var o;if(Env.API_USER_HISTORY){if(yield we.count({where:{password:Y(i+r.id)}}).catch(this.error))return e.error("PASSWORD PREVIOUSLY REGISTERED")}const s=yield this.scope("password").findOne({where:{id:r.id,state:!0}}).catch(this.error);return t+=null!==(o=null==s?void 0:s.salt)&&void 0!==o?o:"",s&&s.password==Y(t)?(s.salt=E(),s.password=Y(i+s.salt),(yield s.save(Object.assign({},n)).catch(this.error))?e.success("OK"):void e.success("RECORD NOT CHANGED")):e.error("INVALID PASSWORD")})}token(e,t,i){return me(this,void 0,void 0,function*(){const r=yield this.model().findOne({attributes:["token"],where:{id:t.id}}).catch(this.error);if(r)return e.json({token:i.hash.decrypt(r.token)});e.notFound("RECORD NOT FOUND")})}token_del(e,t,i){return me(this,void 0,void 0,function*(){const r=yield this.model().findOne({attributes:["id","token"],where:{id:t}}).catch(this.error);if(r)return r.token="",yield r.save(Object.assign({},i)).catch(this.error),e.success("OK");e.notFound("RECORD NOT FOUND")})}token_get(e,t,i){return me(this,void 0,void 0,function*(){const r=yield this.scope("token").findOne({where:{id:t}}).catch(this.error);if(r)return e.json({token:i.hash.decrypt(r.token)});e.notFound("RECORD NOT FOUND")})}token_renew(e,t,i,r){return me(this,void 0,void 0,function*(){const n=yield this.model().findOne({attributes:["id","token"],where:{id:t}}).catch(this.error);if(n){const t=yield this.token_new();return n.token=r.hash.encrypt(t),yield n.save(Object.assign({},i)).catch(this.error),e.json({token:t})}e.notFound("RECORD NOT FOUND")})}token_new(){return me(this,void 0,void 0,function*(){var e;const t=r();return(null!==(e=yield this.model().count({where:{token:t}}).catch(this.error))&&void 0!==e?e:0)?this.token_new():t})}add(e,t){return me(this,void 0,void 0,function*(){const i=E(),r=yield this.create({ctx:e,body:{password:Y(t+i),salt:i}});Env.API_USER_HISTORY&&r&&(yield we.create({password:Y(t+r.id),user_id:r.id}))})}all(e){return me(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{attributes:{exclude:["password","salt","token"]}}})})}del(e,t,i){return me(this,void 0,void 0,function*(){if(i.id.toString()==t)return e.notFound("RECORD NOT FOUND");yield this.delete({ctx:e})})}get(e){return me(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}set(e,t,i){return me(this,void 0,void 0,function*(){if(Env.API_USER_HISTORY&&i){const r=Y(i+t);if(yield we.count({where:{password:r}}).catch(this.error))return e.error("PASSWORD PREVIOUSLY REGISTERED");yield we.create({password:r,user_id:t}).catch(this.error)}const r=i?E():"";yield this.update({ctx:e,body:i?{password:Y(i+r),salt:r}:{}})})}};Ee([b("/avatar"),w("auth"),w("upload",e=>({count:1,field:"file",path:e.controller.path,types:["image/bmp","image/jpeg","image/png"],size:32})),Ae(0,m()),Ae(1,L()),Ae(2,fe()),Ae(3,Se()),_e("design:type",Function),_e("design:paramtypes",[P,Array,Be,Object]),_e("design:returntype",Promise)],at.prototype,"avatar",null),Ee([x("/avatar"),w("auth"),Ae(0,m()),Ae(1,fe()),Ae(2,Se()),_e("design:type",Function),_e("design:paramtypes",[P,Be,Object]),_e("design:returntype",Promise)],at.prototype,"avatar_del",null),Ee([b("/password"),w("auth"),w("validation",{oldPassword:u.string().min(5).required(),newPassword:u.string().min(5).required(),confirmPassword:u.string().equal(u.ref("newPassword"))}),Ae(0,m()),Ae(1,U("oldPassword")),Ae(2,U("newPassword")),Ae(3,fe()),Ae(4,Se()),_e("design:type",Function),_e("design:paramtypes",[P,String,String,Be,Object]),_e("design:returntype",Promise)],at.prototype,"password",null),Ee([B("/token"),w("auth"),Ae(0,m()),Ae(1,fe()),Ae(2,f()),_e("design:type",Function),_e("design:paramtypes",[P,Be,Application]),_e("design:returntype",Promise)],at.prototype,"token",null),Ee([x("/token/:id"),w("auth"),w("canDelete"),Ae(0,m()),Ae(1,j("id")),Ae(2,Se()),_e("design:type",Function),_e("design:paramtypes",[P,String,Object]),_e("design:returntype",Promise)],at.prototype,"token_del",null),Ee([B("/token/:id"),w("auth"),w("canCreate"),Ae(0,m()),Ae(1,j("id")),Ae(2,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,Application]),_e("design:returntype",Promise)],at.prototype,"token_get",null),Ee([B("/token/renew/:id"),w("auth"),w("canUpdate"),Ae(0,m()),Ae(1,j("id")),Ae(2,Se()),Ae(3,f()),_e("design:type",Function),_e("design:paramtypes",[P,String,Object,Application]),_e("design:returntype",Promise)],at.prototype,"token_renew",null),Ee([b(),w("auth"),w("canCreate"),w("validation",{name:u.string().required(),email:u.string().email().required(),username:u.string().min(4).required(),password:u.string().min(5).required(),description:u.string().empty(""),state:u.boolean().parse().required()}),Ae(0,m()),Ae(1,U("password")),_e("design:type",Function),_e("design:paramtypes",[P,String]),_e("design:returntype",Promise)],at.prototype,"add",null),Ee([B(),w("auth"),w("canRead"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],at.prototype,"all",null),Ee([x("/:id"),w("auth"),w("canDelete"),Ae(0,m()),Ae(1,j("id")),Ae(2,fe()),_e("design:type",Function),_e("design:paramtypes",[P,String,Be]),_e("design:returntype",Promise)],at.prototype,"del",null),Ee([B("/:id"),w("auth"),w("canRead"),Ae(0,m()),_e("design:type",Function),_e("design:paramtypes",[P]),_e("design:returntype",Promise)],at.prototype,"get",null),Ee([F("/:id"),w("auth"),w("canUpdate"),w("validation",{name:u.string().empty(),email:u.string().email().empty(),username:u.string().min(4).empty(),password:u.string().min(5).empty().filter(""),description:u.string().empty(),state:u.boolean().parse().empty()}),Ae(0,m()),Ae(1,j("id")),Ae(2,U("password")),_e("design:type",Function),_e("design:paramtypes",[P,String,String]),_e("design:returntype",Promise)],at.prototype,"set",null),at=Ee([k("/users"),C(We),_e("design:paramtypes",[])],at);let ut=class UsersGroupsController extends We{model(){return be}all(e,t){return me(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{user_id:t},include:[{model:De,required:!0}]},callback:e=>e.map(e=>e.group)})})}me(e,t){return me(this,void 0,void 0,function*(){yield this.all(e,t.id.toString())})}set(e,t,i,r){return me(this,void 0,void 0,function*(){const n=yield Be.findByPk(t,{attributes:["id"]}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");if(yield be.destroy(Object.assign({where:{user_id:n.id},individualHooks:!0},r)),i){let e=0;yield d(1e3);for(let t=0;t<i.length;t++)e=yield De.count({where:{id:i[t]}}),e&&(yield be.create({user_id:n.id,group_id:i[t]},Object.assign({},r)))}e.success("OK")})}};Ee([B("/:id/groups"),w("auth"),w("canRead","users"),Ae(0,m()),Ae(1,j("id")),_e("design:type",Function),_e("design:paramtypes",[P,String]),_e("design:returntype",Promise)],ut.prototype,"all",null),Ee([B("/groups"),w("auth"),w("canRead","users"),Ae(0,m()),Ae(1,fe()),_e("design:type",Function),_e("design:paramtypes",[P,Be]),_e("design:returntype",Promise)],ut.prototype,"me",null),Ee([F("/:id/groups"),w("auth"),w("canUpdate","users"),w("validation",{groups:u.array(u.number().parse())}),Ae(0,m()),Ae(1,j("id")),Ae(2,U("groups")),Ae(3,Se()),_e("design:type",Function),_e("design:paramtypes",[P,String,Array,Object]),_e("design:returntype",Promise)],ut.prototype,"set",null),ut=Ee([k("/users"),C(We)],ut);export{Application,xe as Audit,Je as AuditsController,Ne as Auth,AuthBase,Ze as AuthController,AuthKey,AuthToken,Fe as Config,Controller,ControllerBase,ze as ControllerCrud,We as ControllerModel,Env,Qe as FilesController,ke as Forgot,et as ForgotController,De as Group,je as GroupPermission,tt as GroupsController,it as GroupsPermissionsController,Le as Log,nt as LogsController,Ke as Migration,Ue as Permission,ot as PermissionsController,Ce as Register,st as RegisterController,Se as ReqAudit,Ie as ReqAuth,fe as ReqUser,Me as Session,dt as SetupController,Store,Be as User,be as UserGroup,we as UserHistory,at as UsersController,ut as UsersGroupsController,Oe as audit,qe as crt,Pe as database,Re as hooks,Ye as key};
7
+ import{Use as e,UnauthorizedError as t,parameterFactory as i,Context as r,NotFoundError as n,InternalServerError as s,ValidationError as o,Status as d,Application as a,Ctx as l,Headers as u,Session as c,Extends as p,Get as g,Query as v,Controller as y,Post as h,Validate as m,Body as _,App as f,Middleware as E,Delete as A,Put as O,Params as S,Upload as T}from"@andrewcaires/express";import{Env as P,Log as I,LogColor as w,Hash as b,sha256 as x}from"@andrewcaires/node";import{isUndefined as C,isFunction as D,includesArray as R,getConstructor as j,noop as k,loop as N,uuidv7 as B,isString as K,merge as U,isArray as L,clamp as M,isNumber as F,forEachSeries as H,upperCamelCase as q,sleep as Y,EventEmitter as $,denied as G,isDef as V,uniqueID as J,Validation as W,uniqueArray as z,map as X}from"@andrewcaires/utils.js";import{WebSocketServer as Z}from"ws";import{Sequelize as Q,Hooks as ee,Column as te,Association as ie,Database as re,ModelName as ne,Version as se,Model as oe,Unique as de,HasMany as ae,Value as le,DefaultValue as ue,Op as ce,Where as pe}from"@andrewcaires/sequelize";import{config as ge}from"dotenv";import{hashSync as ve,compareSync as ye}from"bcrypt";import{Store as he}from"express-session";import me from"jsonwebtoken";import{Trait as _e,Inject as fe}from"@andrewcaires/decorator";import{existsSync as Ee,statSync as Ae,readdirSync as Oe,mkdirSync as Se,lstatSync as Te,rmSync as Pe}from"fs";import{join as Ie}from"path";function we(e,t,i,r){var n,s=arguments.length,o=s<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,r);else for(var d=e.length-1;d>=0;d--)(n=e[d])&&(o=(s<3?n(o):s>3?n(t,i,o):n(t,i))||o);return s>3&&o&&Object.defineProperty(t,i,o),o}function be(e,t){return function(i,r){t(i,r,e)}}function xe(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function Ce(e,t,i,r){return new(i||(i=Promise))(function(n,s){function o(e){try{a(r.next(e))}catch(e){s(e)}}function d(e){try{a(r.throw(e))}catch(e){s(e)}}function a(e){var t;e.done?n(e.value):(t=e.value,t instanceof i?t:new i(function(e){e(t)})).then(o,d)}a((r=r.apply(e,t||[])).next())})}var De;"function"==typeof SuppressedError&&SuppressedError,ge({quiet:!0});class Env extends P{}De=Env,Env.BASE_NAME=De.getString("BASE_NAME",""),Env.CONSOLE_ERROR=De.getBool("CONSOLE_ERROR",!1),Env.DATABASE_URI=De.getString("DATABASE_URI","",!0),Env.DATABASE_LOG=De.getBool("DATABASE_LOG",!1),Env.DATABASE_AUDIT=De.getBool("DATABASE_AUDIT",!0),Env.DATABASE_PREFIX=De.getString("DATABASE_PREFIX",""),Env.DATABASE_TIMEZONE=De.getString("DATABASE_TIMEZONE","+00:00"),Env.HTTP_CRT=De.getFile("HTTP_CRT"),Env.HTTP_KEY=De.getFile("HTTP_KEY"),Env.SLEEP_AUTH=De.getMs("SLEEP_AUTH","2s"),Env.SLEEP_FORGOT=De.getMs("SLEEP_FORGOT","5s"),Env.SLEEP_REGISTRY=De.getMs("SLEEP_REGISTRY","5s"),Env.TOKEN_CRT=De.getFile("TOKEN_CRT"),Env.TOKEN_KEY=De.getFile("TOKEN_KEY"),Env.TOKEN_TTL=De.getMs("TOKEN_TTL","1d"),Env.API_BODYPARSER_STRICT=De.getBool("API_BODYPARSER_STRICT",!0),Env.API_BODYPARSER_INFLATE=De.getBool("API_BODYPARSER_INFLATE",!0),Env.API_BODYPARSER_LIMIT=De.getString("API_BODYPARSER_LIMIT","10mb"),Env.API_BODYPARSER_TYPE=De.getString("API_BODYPARSER_TYPE","json"),Env.API_HTTP_PORT=De.getInt("API_HTTP_PORT",3e3),Env.API_HTTP_PUBLIC=De.getString("API_HTTP_PUBLIC",""),Env.API_HTTP_CROSS=De.getBool("API_HTTP_CROSS",!1),Env.API_HTTP_HYBRID=De.getBool("API_HTTP_HYBRID",!1),Env.API_HTTP_NOTFOUND=De.getString("API_HTTP_NOTFOUND",""),Env.API_HTTP_PATH=De.getString("API_HTTP_PATH","/api"),Env.API_HTTP_REDIRECT=De.getString("API_HTTP_REDIRECT",""),Env.API_KEY_HASH=De.getString("API_KEY_HASH",""),Env.API_KEY_HEADER=De.getString("API_KEY_HEADER","x-api-key"),Env.API_MODEL_LIMIT=De.getInt("API_MODEL_LIMIT",10),Env.API_MODEL_LIMIT_MAX=De.getInt("API_MODEL_LIMIT_MAX",500),Env.API_SESSION_NAME=De.getString("API_SESSION_NAME","session.id"),Env.API_SESSION_LIFETIME=De.getMs("API_SESSION_LIFETIME","1d"),Env.API_SESSION_SECRET=De.getString("API_SESSION_SECRET","yoursecret"),Env.API_TOKEN_COOKIE=De.getString("API_TOKEN_COOKIE","authorization"),Env.API_TOKEN_COOKIE_SET=De.getBool("API_TOKEN_COOKIE_SET",!0),Env.API_TOKEN_FORGOT=De.getMs("API_TOKEN_FORGOT","1d"),Env.API_TOKEN_HEADER=De.getString("API_TOKEN_HEADER","authorization"),Env.API_TOKEN_HEADER_KEY=De.getString("API_TOKEN_HEADER","bearer"),Env.API_TOKEN_RENEW=De.getMs("API_TOKEN_RENEW","1d"),Env.API_USER_HISTORY=De.getBool("API_USER_HISTORY",!0),Env.API_WEBSOCKET_START=De.getBool("API_WEBSOCKET_START",!1);const Re=new Q({uri:Env.DATABASE_URI,logging:!!Env.DATABASE_LOG&&(e=>I.console(w.Magenta,"sql",e)),prefix:Env.DATABASE_PREFIX,timezone:Env.DATABASE_TIMEZONE}),je=i=>r=>(n,s,o)=>{e(e=>Ce(void 0,void 0,void 0,function*(){var n;let s=null!=r?r:"";C(r)&&(s=D(e.controller.name)?e.controller.name():null===(n=e.controller.constructor)||void 0===n?void 0:n.name);const{permissions:o}=e.req;if((null!=o?o:[]).includes(`${s}.${i}`))return e.next();e.error(new t("Access Denied"))}))(n,s,o)},ke=je("create"),Ne=je("delete"),Be=je("read"),Ke=je("update"),Ue=(...i)=>(r,n,s)=>{e(e=>Ce(void 0,void 0,void 0,function*(){const{groups:r}=e.req;if(R(i,null!=r?r:[]))return e.next();e.error(new t("Access Denied"))}))(r,n,s)},Le=(...i)=>(r,n,s)=>{e(e=>Ce(void 0,void 0,void 0,function*(){const{permissions:r}=e.req;if(R(i,null!=r?r:[]))return e.next();e.error(new t("Access Denied"))}))(r,n,s)},Me=()=>(i,r,n)=>{e(e=>Ce(void 0,void 0,void 0,function*(){yield(e=>Ce(void 0,void 0,void 0,function*(){var i,r,n,s;if(e.req.auth&&e.req.user)return e.next();const{[Env.API_KEY_HEADER]:o,[Env.API_TOKEN_HEADER]:d,"user-agent":a}=e.getHeaders(),l=e.getQuery(Env.API_KEY_HEADER),u=(null===(i=o||l)||void 0===i?void 0:i.toString())||"";let c=e.getCookie(Env.API_TOKEN_COOKIE);c=`${Env.API_TOKEN_HEADER_KEY} ${c}`;const[p,g]=null!==(n=null===(r=d||c)||void 0===r?void 0:r.split(" "))&&void 0!==n?n:["",""];if(!(u||g&&p.toLowerCase()==Env.API_TOKEN_HEADER_KEY))return e.error(new t("Invalid token"));const{authService:v,userService:y}=e.app,{auth:h,user:m}=null!==(s=yield(u?v.key(u.toString()):v.user(g)).catch(t=>{e.error(t)}))&&void 0!==s?s:{};if(h&&m){if(!u&&h.user_agent&&h.user_agent!=a)return e.error(new t("Invalid token"));e.req.auth=h,e.req.user=m,e.req.groups=yield y.getGroups(m.id),e.req.permissions=yield y.getPermissions(m.id),e.req.profile=yield y.getProfile(m.id),e.next()}}))(e)}))(i,r,n)},Fe=i(({ctx:e})=>{var t;return null===(t=e.req)||void 0===t?void 0:t.auth}),He=i(({ctx:e,key:t})=>{var i,r;return(null!==(r=null===(i=e.req)||void 0===i?void 0:i.groups)&&void 0!==r?r:[]).includes(t)}),qe=i(({ctx:e})=>{var t,i;return null!==(i=null===(t=e.req)||void 0===t?void 0:t.groups)&&void 0!==i?i:[]}),Ye=i(({ctx:e,key:t})=>{var i,r;return(null!==(r=null===(i=e.req)||void 0===i?void 0:i.permissions)&&void 0!==r?r:[]).includes(t)}),$e=i(({ctx:e})=>{var t,i;return null!==(i=null===(t=e.req)||void 0===t?void 0:t.permissions)&&void 0!==i?i:[]}),Ge=i(({ctx:e})=>{var t;return null===(t=e.req)||void 0===t?void 0:t.user}),Ve=(e,t,i)=>{var n,s,o,d,a,l,u,c,p,g;const v=i.ctx instanceof r?i.ctx:null,y=null!==(d=null!==(o=null===(s=null===(n=null==v?void 0:v.req)||void 0===n?void 0:n.user)||void 0===s?void 0:s.id)&&void 0!==o?o:i.user_id)&&void 0!==d?d:null,h={type:e,model:null!==(a=null==t?void 0:t.getTableName())&&void 0!==a?a:null,app_name:null!==(l=Env.BASE_NAME)&&void 0!==l?l:"",state:!0,user_id:y};return v?Object.assign(Object.assign({},h),{full_url:null!==(u=null==v?void 0:v.getUrl())&&void 0!==u?u:"",ip_address:null!==(c=null==v?void 0:v.getIp())&&void 0!==c?c:"",user_agent:null!==(g=null===(p=null==v?void 0:v.req)||void 0===p?void 0:p.headers["user-agent"])&&void 0!==g?g:""}):h},Je={afterCreate:(e,t)=>Ce(void 0,void 0,void 0,function*(){const i=j(e),{primaryKeyAttribute:r}=null!=i?i:{};yield st.create(Object.assign(Object.assign({},Ve("CREATE",i,t)),{record:r?e.getDataValue(r):null,data:e.toJSON()})).catch(I.catch)}),afterUpdate:(e,t)=>Ce(void 0,void 0,void 0,function*(){const i=j(e),{primaryKeyAttribute:r}=null!=i?i:{},n={},s=e.changed();s&&s.forEach(t=>n[t]=e.getDataValue(t)),yield st.create(Object.assign(Object.assign({},Ve("UPDATE",i,t)),{record:r?e.getDataValue(r):null,data:n,previously:e.previous()})).catch(I.catch)}),afterDestroy:(e,t)=>Ce(void 0,void 0,void 0,function*(){const i=j(e),{primaryKeyAttribute:r}=null!=i?i:{};yield st.create(Object.assign(Object.assign({},Ve("DELETE",i,t)),{record:r?e.getDataValue(r):null,data:e.toJSON()})).catch(I.catch)})},We=e=>(C(e)&&(e=Env.DATABASE_AUDIT),ee(e?Je:{}));let ze=class RegisterModel extends oe{};we([te.UUID(7),xe("design:type",String)],ze.prototype,"id",void 0),we([te.String(),xe("design:type",String)],ze.prototype,"secret",void 0),we([te.FullDate(),xe("design:type",Number)],ze.prototype,"expired_at",void 0),we([te.Boolean(),xe("design:type",Boolean)],ze.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],ze.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],ze.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],ze.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],ze.prototype,"user_id",void 0),ze=we([re(Re),ne("register"),se("5.0.0")],ze);let Xe=class UserAuthModel extends oe{};we([te.UUID(7),xe("design:type",String)],Xe.prototype,"id",void 0),we([te.String(),xe("design:type",String)],Xe.prototype,"secret",void 0),we([te.String(),xe("design:type",String)],Xe.prototype,"ip_address",void 0),we([te.String(),xe("design:type",String)],Xe.prototype,"user_agent",void 0),we([te.FullDate(),xe("design:type",Object)],Xe.prototype,"revoked_at",void 0),we([te.CreatedAt(),xe("design:type",Date)],Xe.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],Xe.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],Xe.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],Xe.prototype,"user_id",void 0),Xe=we([re(Re),ne("users_auth"),se("5.0.0")],Xe);let Ze=class PermissionModel extends oe{};we([te.UUID(7),xe("design:type",String)],Ze.prototype,"id",void 0),we([te.String(),xe("design:type",String)],Ze.prototype,"name",void 0),we([te.String(),de(!0),xe("design:type",String)],Ze.prototype,"key",void 0),we([te.String(),xe("design:type",String)],Ze.prototype,"tags",void 0),we([te.Text(),xe("design:type",String)],Ze.prototype,"description",void 0),we([te.Boolean(),xe("design:type",Boolean)],Ze.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],Ze.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],Ze.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],Ze.prototype,"deleted_at",void 0),we([ae(()=>Qe,"permission_id"),xe("design:type",Array)],Ze.prototype,"groups_permissions",void 0),Ze=we([re(Re),ne("permission"),We(),se("5.0.1")],Ze);let Qe=class GroupPermissionModel extends oe{};we([te.CreatedAt(),xe("design:type",Date)],Qe.prototype,"created_at",void 0),we([ie.BelongsTo(()=>et),xe("design:type",String)],Qe.prototype,"group_id",void 0),we([ie.BelongsTo(()=>Ze),xe("design:type",String)],Qe.prototype,"permission_id",void 0),Qe=we([re(Re),ne("groups_permissions"),We(),se("5.0.0")],Qe);let et=class GroupModel extends oe{};we([te.UUID(7),xe("design:type",String)],et.prototype,"id",void 0),we([te.String(),xe("design:type",String)],et.prototype,"name",void 0),we([te.String(),xe("design:type",String)],et.prototype,"key",void 0),we([te.String(),xe("design:type",String)],et.prototype,"tags",void 0),we([te.Text(),xe("design:type",String)],et.prototype,"description",void 0),we([te.Boolean(),xe("design:type",Boolean)],et.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],et.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],et.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],et.prototype,"deleted_at",void 0),we([ie.HasMany(()=>tt,"group_id"),xe("design:type",Array)],et.prototype,"users_groups",void 0),we([ie.HasMany(()=>Qe,"group_id"),xe("design:type",Array)],et.prototype,"groups_Permission",void 0),et=we([re(Re),ne("group"),We(),se("5.0.1")],et);let tt=class UserGroupModel extends oe{};we([te.CreatedAt(),xe("design:type",Date)],tt.prototype,"created_at",void 0),we([ie.BelongsTo(()=>et),xe("design:type",String)],tt.prototype,"group_id",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],tt.prototype,"user_id",void 0),tt=we([re(Re),ne("users_groups"),We(),se("5.0.0")],tt);let it=class UserPasswordModel extends oe{};we([te.UUID(7),xe("design:type",String)],it.prototype,"id",void 0),we([te.String(),le(e=>ve(e.value,12)),xe("design:type",String)],it.prototype,"value",void 0),we([te.Boolean(),xe("design:type",Boolean)],it.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],it.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],it.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],it.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],it.prototype,"user_id",void 0),it=we([re(Re),ne("users_password"),We(),se("5.0.0")],it);let rt=class UserProfileModel extends oe{};we([te.UUID(7),xe("design:type",String)],rt.prototype,"id",void 0),we([te.Json(),ue({}),xe("design:type",Object)],rt.prototype,"data",void 0),we([te.CreatedAt(),xe("design:type",Date)],rt.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],rt.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],rt.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],rt.prototype,"user_id",void 0),rt=we([re(Re),ne("users_profile"),We(),se("5.0.1")],rt);let nt=class UserModel extends oe{};we([te.UUID(7),xe("design:type",String)],nt.prototype,"id",void 0),we([te.String(),xe("design:type",String)],nt.prototype,"name",void 0),we([te.String(),xe("design:type",String)],nt.prototype,"email",void 0),we([te.String(),xe("design:type",String)],nt.prototype,"username",void 0),we([te.Text(),xe("design:type",String)],nt.prototype,"description",void 0),we([te.Boolean(),xe("design:type",Boolean)],nt.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],nt.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],nt.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],nt.prototype,"deleted_at",void 0),we([ie.HasMany(()=>st,"user_id"),xe("design:type",Array)],nt.prototype,"audits",void 0),we([ie.HasMany(()=>Xe,"user_id"),xe("design:type",Array)],nt.prototype,"users_auths",void 0),we([ie.HasMany(()=>ze,"user_id"),xe("design:type",Array)],nt.prototype,"registers",void 0),we([ie.HasMany(()=>tt,"user_id"),xe("design:type",Array)],nt.prototype,"users_groups",void 0),we([ie.HasMany(()=>it,"user_id"),xe("design:type",Array)],nt.prototype,"users_passwords",void 0),we([ie.HasMany(()=>rt,"user_id"),xe("design:type",Array)],nt.prototype,"users_profiles",void 0),nt=we([re(Re),ne("user"),We(),se("5.0.0")],nt);let st=class AuditModel extends oe{};we([te.UUID(7),xe("design:type",String)],st.prototype,"id",void 0),we([te.Enum("CREATE","DELETE","UPDATE"),xe("design:type",String)],st.prototype,"type",void 0),we([te.String(),xe("design:type",String)],st.prototype,"model",void 0),we([te.String(),xe("design:type",String)],st.prototype,"record",void 0),we([te.Json(),xe("design:type",Object)],st.prototype,"data",void 0),we([te.Json(),xe("design:type",Object)],st.prototype,"previously",void 0),we([te.Text(),xe("design:type",String)],st.prototype,"full_url",void 0),we([te.String(),xe("design:type",String)],st.prototype,"ip_address",void 0),we([te.String(),xe("design:type",String)],st.prototype,"user_agent",void 0),we([te.String(),xe("design:type",String)],st.prototype,"app_name",void 0),we([te.Boolean(),xe("design:type",Boolean)],st.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],st.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],st.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],st.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],st.prototype,"user_id",void 0),st=we([re(Re),ne("audit"),se("5.0.1")],st);let ot=class ConfigModel extends oe{};we([te.UUID(7),xe("design:type",String)],ot.prototype,"id",void 0),we([te.String(),xe("design:type",String)],ot.prototype,"key",void 0),we([te.String(),xe("design:type",String)],ot.prototype,"value",void 0),we([te.CreatedAt(),xe("design:type",Date)],ot.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],ot.prototype,"updated_at",void 0),ot=we([re(Re),ne("configs"),se("5.0.0")],ot);let dt=class ForgotModel extends oe{};we([te.UUID(7),xe("design:type",String)],dt.prototype,"id",void 0),we([te.String(),xe("design:type",String)],dt.prototype,"secret",void 0),we([te.FullDate(),xe("design:type",Number)],dt.prototype,"expired_at",void 0),we([te.Boolean(),xe("design:type",Boolean)],dt.prototype,"state",void 0),we([te.CreatedAt(),xe("design:type",Date)],dt.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],dt.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],dt.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],dt.prototype,"user_id",void 0),dt=we([re(Re),ne("forgot"),se("5.0.0")],dt);let at=class LogModel extends oe{};we([te.UUID(7),xe("design:type",String)],at.prototype,"id",void 0),we([te.Enum("info","warn","error"),ue("info"),xe("design:type",String)],at.prototype,"level",void 0),we([te.Text(),xe("design:type",String)],at.prototype,"message",void 0),we([te.String(),xe("design:type",String)],at.prototype,"source",void 0),we([te.CreatedAt(),xe("design:type",Date)],at.prototype,"created_at",void 0),at=we([re(Re),ne("log"),se("5.0.0")],at);let lt=class MigrationModel extends oe{};we([te.String(),xe("design:type",String)],lt.prototype,"model",void 0),we([te.String(),xe("design:type",String)],lt.prototype,"version",void 0),we([te.CreatedAt(),xe("design:type",Date)],lt.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],lt.prototype,"updated_at",void 0),lt=we([re(Re),ne("migration"),se("5.0.0")],lt);let ut=class SessionModel extends oe{};we([te.String(),xe("design:type",String)],ut.prototype,"session",void 0),we([te.Text(),xe("design:type",String)],ut.prototype,"json",void 0),we([te.BigInt(),xe("design:type",Number)],ut.prototype,"expired",void 0),we([te.CreatedAt(),xe("design:type",Date)],ut.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],ut.prototype,"updated_at",void 0),ut=we([re(Re),ne("session"),se("5.0.0")],ut);let ct=class UserMetadataModel extends oe{};we([te.UUID(7),xe("design:type",String)],ct.prototype,"id",void 0),we([te.Json(),ue({}),xe("design:type",Object)],ct.prototype,"data",void 0),we([te.CreatedAt(),xe("design:type",Date)],ct.prototype,"created_at",void 0),we([te.UpdatedAt(),xe("design:type",Date)],ct.prototype,"updated_at",void 0),we([te.DeletedAt(),xe("design:type",Object)],ct.prototype,"deleted_at",void 0),we([ie.BelongsTo(()=>nt),xe("design:type",String)],ct.prototype,"user_id",void 0),ct=we([re(Re),ne("users_metadata"),We(),se("5.0.1")],ct);class Log{static error(e,t,i){return Ce(this,void 0,void 0,function*(){yield this.writeRaw("error",e,t,i)})}static info(e,t,i){return Ce(this,void 0,void 0,function*(){yield this.writeRaw("info",e,t,i)})}static warn(e,t,i){return Ce(this,void 0,void 0,function*(){yield this.writeRaw("warn",e,t,i)})}static writeRaw(e,t,i,r){return Ce(this,void 0,void 0,function*(){var n;r&&I.console(null!==(n=this.colors[e])&&void 0!==n?n:w.White,e,t),Re&&(yield at.create({level:e,message:t,source:null!=i?i:""}).catch(I.catch))})}}Log.colors={error:w.Red,info:w.Cyan,warn:w.Yellow};class Loggable{get log(){return e=>Loggable.logInfo(this,e)}static get log(){return e=>this.logInfo(this,e)}get error(){return e=>Loggable.logError(this,e)}static get error(){return e=>this.logError(this,e)}static logError(e,t){var i,r;Log.error(null!==(r=null!==(i=null==t?void 0:t.message)&&void 0!==i?i:t)&&void 0!==r?r:"",this.source(e),Env.CONSOLE_ERROR)}static logInfo(e,t){Log.info(null!=t?t:"",this.source(e),Env.CONSOLE_ERROR)}static source(e){var t,i,r;const n=null!==(r=null!==(i=null===(t=null==e?void 0:e.constructor)||void 0===t?void 0:t.name)&&void 0!==i?i:null==e?void 0:e.name)&&void 0!==r?r:"null";return Env.BASE_NAME?`${Env.BASE_NAME}.${n}`:n}}class Config extends Loggable{static all(e){return Ce(this,void 0,void 0,function*(){var t;const i=null!==(t=yield ot.findAll({where:(null==e?void 0:e.length)?{key:{[ce.in]:e}}:{}}).catch(this.error))&&void 0!==t?t:[];return Object.fromEntries(i.map(e=>[e.key,e.value]))})}static del(e){return Ce(this,void 0,void 0,function*(){return((yield ot.destroy({where:{key:e}}).catch(this.error))||0)>0})}static get(e){return Ce(this,arguments,void 0,function*(e,t=""){const[i]=(yield ot.findOrCreate({where:{key:e},defaults:{key:e,value:t}}).catch(this.error))||[];return i?i.value:t})}static set(e,t){return Ce(this,void 0,void 0,function*(){const[i,r]=(yield ot.findOrCreate({where:{key:e},defaults:{key:e,value:t}}).catch(this.error))||[];i&&!r&&(i.value=t,yield i.save().catch(this.error))})}}class SessionStore extends he{constructor(){super(),this.all=e=>Ce(this,void 0,void 0,function*(){e=e||k;const t=yield ut.findAll({attributes:["session"],where:{expired:{[ce.gte]:Date.now()}}}).catch(t=>(e(t),null));t&&e(null,t.map(e=>e.session)),e()}),this.clear=e=>Ce(this,void 0,void 0,function*(){yield ut.destroy().catch(k),e&&e()}),this.destroy=(e,t)=>Ce(this,void 0,void 0,function*(){yield ut.destroy({where:{session:e}}).catch(k),t&&t()}),this.expired=()=>Ce(this,void 0,void 0,function*(){yield ut.destroy({where:{expired:{[ce.lt]:Date.now()}}}).catch(k)}),this.get=(e,t)=>Ce(this,void 0,void 0,function*(){t=t||k;const i=yield ut.findOne({where:{session:e,expired:{[ce.gte]:Date.now()}}}).catch(e=>(t(e),null));if(i){const e=JSON.parse(i.json);if(e.cookie){if(new Date(e.cookie.expires).getTime()<=Date.now())return yield i.destroy().catch(k),void t(null)}return void t(null,e)}t(null)}),this.length=e=>Ce(this,void 0,void 0,function*(){e&&e(null,(yield ut.count().catch(k))||0)}),this.set=(e,t,i)=>Ce(this,void 0,void 0,function*(){i=i||k;const r=Date.now()+Env.API_SESSION_LIFETIME,n=JSON.stringify(t),[s,o]=(yield ut.findOrCreate({where:{session:e},defaults:{session:e,json:n,expired:r}}).catch(k))||[];s&&(o||(s.json=n,s.expired=r,yield s.save().catch(k))),i()}),this.loop=N(this.expired,3e4),this.loop.start()}}let pt=class Service{};pt=we([_e(Loggable)],pt);class AuthService extends pt{create(e){return Ce(this,void 0,void 0,function*(){if(!Env.TOKEN_KEY)throw new n("TOKEN_KEY not found");const{id:t}=e,i=B(),r=yield Xe.create({secret:i,user_id:t}).catch(this.error);if(!r)throw new s;return{auth:r,token:me.sign({id:t,secret:i},Env.TOKEN_KEY,this.options())}})}destroy(e){return Ce(this,void 0,void 0,function*(){return!(!e||e.revoked_at)&&(e.revoked_at=new Date,yield e.save(),!0)})}renew(e){return Ce(this,void 0,void 0,function*(){if(!Env.TOKEN_KEY)throw new n("TOKEN_KEY not found");const{decode:i}=yield this.verify(e,Env.API_TOKEN_RENEW/1e3);if(!i)throw new t("Invalid token");const{id:r,secret:s}=i;if(r&&s){const e=yield nt.findOne({where:{id:r,state:!0}}).catch(this.error);if(e){const t=yield Xe.findOne({where:{secret:s,user_id:e.id}}).catch(this.error);if(t&&!t.revoked_at){t.secret=B(),yield t.save().catch(this.error);return{auth:t,token:me.sign({id:r,secret:t.secret},Env.TOKEN_KEY,this.options())}}}}throw new t("Invalid token")})}user(e){return Ce(this,void 0,void 0,function*(){const{decode:i}=yield this.verify(e);if(!i)throw new t("Invalid token");const{id:r,secret:n}=i;if(r&&n){const e=yield nt.findOne({where:{id:r,state:!0}}).catch(this.error);if(e){const t=yield Xe.findOne({where:{secret:n,user_id:e.id}}).catch(this.error);if(t&&!t.revoked_at)return{auth:t,user:e}}}throw new t("Invalid token")})}options(){return{algorithm:"RS256",expiresIn:`${Env.TOKEN_TTL}ms`}}verify(e,i){return Ce(this,void 0,void 0,function*(){if(!Env.TOKEN_CRT)throw new n("TOKEN_CRT not found");if(!e||e.split(".").length<3)throw new t("Invalid token");try{return{decode:me.verify(e,Env.TOKEN_CRT,{clockTolerance:i})}}catch(e){throw new t("Invalid token")}})}key(e){return Ce(this,void 0,void 0,function*(){if(!e)throw new t("Invalid token");const i=yield nt.findOne({where:{token:e,state:!0}}).catch(this.error);if(i){const t=e.replace(/(-[\w]{4})/g,"-****"),[r]=(yield Xe.findOrCreate({where:{secret:t,user_id:i.id},defaults:{secret:t,user_id:i.id}}).catch(this.error))||[];if(r)return r.revoked_at&&(r.revoked_at=null,yield r.save().catch(this.error)),{auth:r,user:i}}throw new t("Invalid token")})}}class ModelService extends pt{constructor(e,t){super(),this.attributes=[],this.filter=[],this.permissions=[],this.model=e,(null==t?void 0:t.attributes)&&(this.filter=t.attributes),(null==t?void 0:t.permissions)&&(this.filter=t.permissions)}countAll(e){return Ce(this,arguments,void 0,function*({ctx:e,options:t}){var i,r,n,s,a;const l=Object.assign({},t||{}),{search:u,where:c}=null!==(r=null===(i=null==e?void 0:e.req)||void 0===i?void 0:i.query)&&void 0!==r?r:{};l.attributes=[];const p=[];p.length&&(l.order=p),l.where=Object.assign({},l.where||{});const g=this.getAttributes(null!==(n=null==l?void 0:l.attributes)&&void 0!==n?n:[]);if(K(c)){const t=pe.parse(g,c);if(!C(t.error))return null==e||e.error(new o(t.error.join(", "))),0;l.where=Object.assign(Object.assign({},l.where),null!==(s=t.value)&&void 0!==s?s:{})}else{const e=[];g.forEach(t=>{K(u)&&u.length&&e.push({[t]:{[ce.like]:`%${u}%`}})}),e.length&&(l.where=Object.assign(Object.assign({},l.where),{[ce.or]:[...e]}))}const v=null!==(a=yield this.model.count(Object.assign(Object.assign({},l),{distinct:!!l.include,col:this.attributes.length?this.attributes[0]:void 0})).catch(this.error))&&void 0!==a?a:0;return null==e||e.prepare(d.OK,{count:v}),v})}create(e){return Ce(this,arguments,void 0,function*({ctx:e,options:t,body:i}){var r,n;const o=Object.assign({},t||{}),a=yield this.model.create(Object.assign({},U({},null!==(n=null===(r=null==e?void 0:e.req)||void 0===r?void 0:r.body)&&void 0!==n?n:{},null!=i?i:{})),Object.assign(Object.assign({},o),{ctx:e})).catch(this.error);if(a){const{primaryKeyAttribute:t}=this.model;return null==e||e.prepare(d.OK,{[t]:a.getDataValue(t)}),a}return null==e||e.error(new s),null})}delete(e){return Ce(this,arguments,void 0,function*({ctx:e,options:t,id:i}){var r,o,d;const a=Object.assign({},t||{}),{primaryKeyAttribute:l}=this.model,{[l]:u}=null!==(o=null===(r=null==e?void 0:e.req)||void 0===r?void 0:r.params)&&void 0!==o?o:{[l]:null!=i?i:0};if(!u)return null==e||e.error(new s),0;const c=yield this.model.destroy(Object.assign(Object.assign(Object.assign({},a),{where:Object.assign(Object.assign({},null!==(d=a.where)&&void 0!==d?d:{}),{[l]:u}),individualHooks:!0}),{ctx:e})).catch(this.error);return c?(null==e||e.success("OK"),c):(null==e||e.error(new n),0)})}filterAttributes(e,t){if(L(t))return t.length?t.map(t=>K(t)&&-1!=e.indexOf(t)?t:void 0).filter(K):e;const{exclude:i,include:r}=t,n=C(r)?e:r.map(t=>K(t)&&-1!=e.indexOf(t)?t:void 0).filter(K),s=null!=i?i:[];return s.length?n.filter(e=>-1==s.indexOf(e)):n}findAll(e){return Ce(this,arguments,void 0,function*({ctx:e,options:t,callback:i,limited:r}){var n,a,l,u,c,p,g;const v=Object.assign({},t||{}),{limit:y,offset:h,asc:m,desc:_,search:f,select:E,where:A}=null!==(a=null===(n=null==e?void 0:e.req)||void 0===n?void 0:n.query)&&void 0!==a?a:{};if(C(v.limit)){let e=Env.API_MODEL_LIMIT;K(y)&&(e=parseInt(y)||0),e=M(e,-1,Env.API_MODEL_LIMIT_MAX),v.limit=e>0?e:r?Env.API_MODEL_LIMIT:void 0}if(F(v.limit)&&(v.limit=v.limit>0?v.limit:void 0),K(h)){const e=parseInt(h)||0;v.offset=e>0?e:void 0}const O=this.getAttributes(null!==(l=null==v?void 0:v.attributes)&&void 0!==l?l:[]),S=e=>O.indexOf(e)>=0;v.attributes=[],K(E)&&E.length&&v.attributes.push(...E.split(";").filter(S)),v.attributes.length||(v.attributes=O);const T=[];if(K(m)&&m.length&&T.push(...m.split(";").filter(S).map(e=>[e,"ASC"])),K(_)&&_.length&&T.push(..._.split(";").filter(S).map(e=>[e,"DESC"])),T.length&&(v.order=T),v.where=Object.assign({},v.where||{}),K(A)){const t=pe.parse(O,A);if(!C(t.error))return null==e||e.error(new o(t.error.join(", "))),{count:0,records:[]};v.where=Object.assign(Object.assign({},v.where),null!==(u=t.value)&&void 0!==u?u:{})}else{const e=[];O.forEach(t=>{K(f)&&f.length&&e.push({[t]:{[ce.like]:`%${f}%`}})}),e.length&&(v.where=Object.assign(Object.assign({},v.where),{[ce.or]:[...e]}))}const P=this.model.count(Object.assign(Object.assign({},v),{distinct:!!v.include,col:this.attributes.length?this.attributes[0]:void 0})).catch(this.error),I=this.model.findAll(v).catch(this.error);yield Promise.allSettled([P,I]);const w=null!==(c=yield P)&&void 0!==c?c:0;let b=null!==(p=yield I)&&void 0!==p?p:[];const x={count:w};return b?(b=i?yield i(b):b,(F(null==t?void 0:t.limit)||0==w)&&(x.count=null!==(g=null==b?void 0:b.length)&&void 0!==g?g:0),null==e||e.prepare(d.OK,Object.assign(Object.assign({},x),{records:b})),Object.assign(Object.assign({},x),{records:b})):(null==e||e.error(new s),Object.assign(Object.assign({},x),{records:[]}))})}findOne(e){return Ce(this,arguments,void 0,function*({ctx:e,options:t,callback:i}){var r,o,a,l,u;const c=Object.assign({},t||{}),{primaryKeyAttribute:p}=this.model,{[p]:g}=null!==(r=null==e?void 0:e.req.params)&&void 0!==r?r:{},v=this.getAttributes(null!==(o=null==c?void 0:c.attributes)&&void 0!==o?o:[]),y=e=>v.indexOf(e)>=0,{select:h}=null!==(l=null===(a=null==e?void 0:e.req)||void 0===a?void 0:a.query)&&void 0!==l?l:{};K(h)&&(c.attributes=h.split(";").filter(y));const m=yield this.model.findOne(Object.assign(Object.assign({},c),{where:Object.assign(Object.assign({},null!==(u=null==c?void 0:c.where)&&void 0!==u?u:{}),{[p]:g})})).catch(this.error);return m?(null==e||e.prepare(d.OK,i?yield i(m):m.toJSON()),m):m?(null==e||e.error(new s),null):(null==e||e.error(new n),null)})}getAttributes(e){return 0==this.attributes.length&&(this.attributes=this.filterAttributes(Object.keys(this.model.getAttributes()),this.filter)),this.filterAttributes(this.attributes,e)}sync(){return Ce(this,void 0,void 0,function*(){if(!this.permissions.length)return;const e=this.name().toLowerCase(),t={description:"",state:!0};yield H(this.permissions,i=>Ce(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=q(e.replace(/_/g," ")," ");yield Ze.findOrCreate({where:{key:r},defaults:Object.assign({name:`${n} ${q(i," ")}`,key:r,tags:n},t)})}))})}update(e){return Ce(this,arguments,void 0,function*({ctx:e,options:t,body:i,id:r}){var n,s,o,d,a,l;const u=Object.assign({},t||{}),{primaryKeyAttribute:c}=this.model,{[c]:p}=null!==(s=null===(n=null==e?void 0:e.req)||void 0===n?void 0:n.params)&&void 0!==s?s:{[c]:null!=r?r:0},[g]=null!==(l=yield this.model.update(Object.assign({},U({},null!==(d=null===(o=null==e?void 0:e.req)||void 0===o?void 0:o.body)&&void 0!==d?d:{},null!=i?i:{})),Object.assign(Object.assign(Object.assign({},u),{where:Object.assign(Object.assign({},null!==(a=null==u?void 0:u.where)&&void 0!==a?a:{}),{[c]:p}),individualHooks:!0}),{ctx:e})).catch(this.error))&&void 0!==l?l:[];return g?(null==e||e.success("OK"),!0):(null==e||e.success("Record not changed"),!1)})}name(){return this.model.tableName}}class UserService extends pt{getMetadata(e){return Ce(this,void 0,void 0,function*(){var t,i;const[r]=null!==(t=yield ct.findOrCreate({where:{user_id:e},defaults:{user_id:e}}).catch(this.error))&&void 0!==t?t:[];return null!==(i=null==r?void 0:r.data)&&void 0!==i?i:{}})}getProfile(e){return Ce(this,void 0,void 0,function*(){var t,i;const[r]=null!==(t=yield rt.findOrCreate({where:{user_id:e},defaults:{user_id:e}}).catch(this.error))&&void 0!==t?t:[];return null!==(i=null==r?void 0:r.data)&&void 0!==i?i:{}})}getGroups(e){return Ce(this,void 0,void 0,function*(){var t;return(null!==(t=yield et.findAll({attributes:["key"],where:{state:!0},include:[{model:tt,required:!0,where:{user_id:e}}]}).catch(this.error))&&void 0!==t?t:[]).map(e=>e.key)})}getPermissions(e){return Ce(this,void 0,void 0,function*(){var t;return(null!==(t=yield Ze.findAll({attributes:["key"],where:{state:!0},include:[{model:Qe,required:!0,include:[{model:et,required:!0,attributes:["id"],where:{state:!0},include:[{model:tt,required:!0,where:{user_id:e}}]}]}]}).catch(this.error))&&void 0!==t?t:[]).map(e=>e.key)})}}class Application extends a{constructor(e,t){super(e,U({},{cert:Env.HTTP_CRT,cross:Env.API_HTTP_CROSS,hybrid:Env.API_HTTP_HYBRID,json:{strict:Env.API_BODYPARSER_STRICT,inflate:Env.API_BODYPARSER_INFLATE,limit:Env.API_BODYPARSER_LIMIT,type:Env.API_BODYPARSER_TYPE},key:Env.HTTP_KEY,notfound:Env.API_HTTP_NOTFOUND,path:Env.API_HTTP_PATH,port:Env.API_HTTP_PORT,public:Env.API_HTTP_PUBLIC,redirect:Env.API_HTTP_REDIRECT,session:{store:new SessionStore,name:Env.API_SESSION_NAME,secret:Env.API_SESSION_SECRET,cookie:{maxAge:Env.API_SESSION_LIFETIME},genid:B}},null!=t?t:{})),this.hash=new b(Env.API_KEY_HASH)}error(e,t){Env.BASE_NAME&&(t=t?`${Env.BASE_NAME}.${t}`:Env.BASE_NAME),Log.error(e.message,t,Env.CONSOLE_ERROR)}log(e,t){Env.BASE_NAME&&(t=t?`${Env.BASE_NAME}.${t}`:Env.BASE_NAME),Log.info(e,t,!0)}listen(){const e=Object.create(null,{listen:{get:()=>super.listen}});return Ce(this,void 0,void 0,function*(){yield Re.sync(),yield this.migrations(Re),yield H(this.controllers,e=>Ce(this,void 0,void 0,function*(){D(e.sync)&&(yield e.sync(this))})),this.authService=new AuthService,this.userService=new UserService,yield e.listen.call(this),Env.API_WEBSOCKET_START&&this.server&&(this._webSocket=new Z({server:this.server,verifyClient:(e,t)=>t(Env.API_WEBSOCKET_START)}),this._webSocket.on("connection",(e,t)=>Ce(this,void 0,void 0,function*(){t.url||(t.url=""),e.on("close",()=>{}),yield Y(2e3),e.close()})))})}migrations(e){return Ce(this,void 0,void 0,function*(){const t=[];yield H(Object.keys(e.models),i=>Ce(this,void 0,void 0,function*(){var r;const n=e.models[i],s=n.version();if(!s)return;const[o,d]=null!==(r=yield lt.findOrCreate({where:{model:n.tableName},defaults:{model:n.tableName,version:""}}).catch(this.error))&&void 0!==r?r:[];o&&(d||o.version!=s)&&(o.version=s,yield o.save().catch(this.error),t.push(n))})),yield H(t,e=>Ce(this,void 0,void 0,function*(){return yield e.updateAttributes()}))})}websocket(){return this._webSocket}}let gt=class BaseController extends ${constructor(){super(...arguments),this.permissions=[]}name(){var e,t;return(null!==(t=null===(e=this.constructor)||void 0===e?void 0:e.name)&&void 0!==t?t:"api").replace(/(([a-z])([A-Z]))/g,"$2_$3")}session(e,t,i){return Ce(this,void 0,void 0,function*(){i.auth&&i.user&&(i.user_agent?i.user_agent!=t&&i.regenerate(k):(i.user_agent=t,i.save(k))),e.next()})}sync(){return Ce(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield H(this.permissions,i=>Ce(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=q(e.replace(/_/g," ")," ");yield Ze.findOrCreate({where:{key:r},defaults:Object.assign({name:`${n} ${q(i," ")}`,key:r,tags:n},t)})}))})}};we([be(0,l()),be(1,u("user-agent")),be(2,c()),xe("design:type",Function),xe("design:paramtypes",[r,String,Object]),xe("design:returntype",Promise)],gt.prototype,"session",null),gt=we([_e(Loggable)],gt);let vt=class ModelController extends gt{constructor(){super(...arguments),this.attributes=[],this.permissions=["create","read","update","delete"]}countAll(e){return Ce(this,void 0,void 0,function*(){return yield this.service.countAll(e)})}create(e){return Ce(this,void 0,void 0,function*(){return yield this.service.create(e)})}delete(e){return Ce(this,void 0,void 0,function*(){return yield this.service.delete(e)})}findAll(e){return Ce(this,void 0,void 0,function*(){return yield this.service.findAll(e)})}findOne(e){return Ce(this,void 0,void 0,function*(){return yield this.service.findOne(e)})}sync(){return Ce(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield H(this.permissions,i=>Ce(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=q(e.replace(/_/g," ")," ");yield Ze.findOrCreate({where:{key:r},defaults:Object.assign({name:`${n} ${q(i," ")}`,key:r,tags:n},t)})})),this.service=new ModelService(this.model)})}update(e){return Ce(this,void 0,void 0,function*(){return yield this.service.update(e)})}name(){return this.model.tableName}};vt=we([p(gt)],vt);let yt=class AuditsController extends vt{constructor(){super(...arguments),this.model=st,this.permissions=["read"]}all(e,t,i){return Ce(this,void 0,void 0,function*(){const r={};t&&(r.type=t),i&&(r.table=i),yield this.findAll({ctx:e,options:{attributes:{exclude:["data","previously"]},where:r,order:[["created_at","DESC"]]},limited:!0})})}get(e){return Ce(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}};we([g(),Me(),Be(),be(0,l()),be(1,v("type")),be(2,v("table")),xe("design:type",Function),xe("design:paramtypes",[r,String,String]),xe("design:returntype",Promise)],yt.prototype,"all",null),we([g("/:id"),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],yt.prototype,"get",null),yt=we([y("/audits"),p(vt)],yt);let ht=class AuthController extends gt{constructor(e){super(),this.authService=e}login(e,i,r,n,s,o){return Ce(this,void 0,void 0,function*(){var d;yield Y(Env.SLEEP_AUTH);const a=yield nt.findOne({where:{[ce.or]:[{email:r},{username:r}]}}).catch(this.error);if(!a)return e.error(new t("Invalid credentials")),o.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e});const l=yield it.findOne({where:{user_id:a.id,state:!0}}).catch(this.error);if(!l||!ye(n,l.value))return e.error(new t("Invalid credentials")),o.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e});const u=yield ze.findOne({where:{state:!0,user_id:a.id}}).catch(this.error);if(u)return e.error("ACTIVATION REQUIRED"),o.emit("auth.activation",{ctx:e,register:u,user:a}),void this.emit("auth.activation",{ctx:e,register:u,user:a});if(!a.state)return e.error(new t("Invalid credentials")),o.emit("auth.failure",{ctx:e,user:a}),void this.emit("auth.failure",{ctx:e,user:a});const{auth:c,token:p}=null!==(d=yield this.authService.create(a).catch(t=>{e.error(t),o.emit("auth.failure",{ctx:e}),this.emit("auth.failure",{ctx:e})}))&&void 0!==d?d:{};c&&p&&(c.user_agent=i,c.ip_address=e.getIp(),yield c.save().catch(this.error),Env.API_TOKEN_COOKIE_SET&&e.cookie(Env.API_TOKEN_COOKIE,p,{maxAge:s?Env.TOKEN_TTL:void 0}),e.json({token:p}),o.emit("auth.login",{ctx:e,auth:c,user:a}),this.emit("auth.login",{ctx:e,auth:c,user:a}))})}logout(e,i,r,n){return Ce(this,void 0,void 0,function*(){if(yield this.authService.destroy(i))return e.success("OK"),n.emit("auth.logout",{auth:i,ctx:e,user:r}),void this.emit("auth.logout",{auth:i,ctx:e,user:r});e.error(new t("Access Denied"))})}renew(e,t,i,r){return Ce(this,void 0,void 0,function*(){var n;const{auth:s,token:o}=null!==(n=yield this.authService.renew(i).catch(t=>{e.error(t)}))&&void 0!==n?n:{};s&&o&&(s.user_agent=t,yield s.save().catch(this.error),e.json({token:o}),r.emit("auth.renew",{auth:s,ctx:e}),this.emit("auth.renew",{auth:s,ctx:e}))})}user(e,t){return Ce(this,void 0,void 0,function*(){const{groups:i,permissions:r,profile:n}=e.req;if(!i||!r)return e.error(new s);e.json(Object.assign(Object.assign({},G(t.toJSON(),["username","description"])),{groups:i,permissions:r,profile:n}))})}};we([h("/login"),m(e=>({username:e.string().min(3).required(),password:e.string().min(5).required(),remember:e.boolean().parse().empty(!1)})),be(0,l()),be(1,u("user-agent")),be(2,_("username")),be(3,_("password")),be(4,_("remember")),be(5,f()),xe("design:type",Function),xe("design:paramtypes",[r,String,String,String,Boolean,Application]),xe("design:returntype",Promise)],ht.prototype,"login",null),we([g("/logout"),Me(),be(0,l()),be(1,Fe()),be(2,Ge()),be(3,f()),xe("design:type",Function),xe("design:paramtypes",[r,Xe,nt,Application]),xe("design:returntype",Promise)],ht.prototype,"logout",null),we([h("/renew"),m(e=>({token:e.string().required()})),be(0,l()),be(1,u("user-agent")),be(2,_("token")),be(3,f()),xe("design:type",Function),xe("design:paramtypes",[r,String,String,Application]),xe("design:returntype",Promise)],ht.prototype,"renew",null),we([g(),g("/me"),Me(),be(0,l()),be(1,Ge()),xe("design:type",Function),xe("design:paramtypes",[r,nt]),xe("design:returntype",Promise)],ht.prototype,"user",null),ht=we([y("/auth"),p(gt),be(0,fe(AuthService)),xe("design:paramtypes",[AuthService])],ht);let mt=class CrudController extends vt{constructor(){super(...arguments),this._crud={}}CrudArgumentscountAll(e){return{ctx:e}}CrudArgumentsCreate(e){return{ctx:e}}CrudArgumentsFindAll(e){return{ctx:e}}CrudArgumentsFindOne(e){return{ctx:e}}CrudArgumentsDelete(e){return{ctx:e}}CrudArgumentsUpdate(e){return{ctx:e}}CrudValidationCreate(){return this._crud}CrudValidationUpdate(){return this._crud}add(e){return Ce(this,void 0,void 0,function*(){yield this.create(this.CrudArgumentsCreate(e))})}all(e){return Ce(this,void 0,void 0,function*(){yield this.findAll(this.CrudArgumentsFindAll(e))})}number(e){return Ce(this,void 0,void 0,function*(){yield this.countAll(this.CrudArgumentsFindAll(e))})}del(e){return Ce(this,void 0,void 0,function*(){yield this.delete(this.CrudArgumentsDelete(e))})}get(e){return Ce(this,void 0,void 0,function*(){yield this.findOne(this.CrudArgumentsFindOne(e))})}set(e){return Ce(this,void 0,void 0,function*(){yield this.update(this.CrudArgumentsUpdate(e))})}validationCreate(e){return Ce(this,void 0,void 0,function*(){if(this.CrudValidationCreate()==this._crud)return e.error(new s)})}validationUpdate(e){return Ce(this,void 0,void 0,function*(){if(this.CrudValidationUpdate()==this._crud)return e.error(new s)})}};we([h(),Me(),ke(),E("validationCreate"),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"add",null),we([g(),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"all",null),we([g("/count"),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"number",null),we([A("/:id"),Me(),Ne(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"del",null),we([g("/:id"),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"get",null),we([O("/:id"),Me(),Ke(),E("validationUpdate"),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"set",null),we([be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"validationCreate",null),we([be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],mt.prototype,"validationUpdate",null),mt=we([p(vt)],mt);let _t=class FilesController extends gt{constructor(){super(...arguments),this.directory=Env.API_HTTP_PUBLIC||"./",this.permissions=["delete","download","edit","list","read","rename","upload","write"]}files(e){return Ce(this,void 0,void 0,function*(){let{path:t}=e.req;t=t.replace(/(^\/path(\/)?)|([\\.]{1,2}\/)/g,"");const i=Ie(this.directory,t);if(!Ee(i)||!Ae(i).isDirectory())return e.error(new n);let r=[];return r=Oe(i),r=r.map(e=>this.info(Ie(i,e))),r=r.filter(V),Object.assign(Object.assign({},this.info(i)),{files:r})})}info(e){if(!Ee(e))return null;const t=Ae(e),i=e.split("/").pop();e=e.replace(this.directory,"/").replace(/^\/\//,"/");const r=t.isDirectory();return{name:i,path:e.replace(/^\/\//,"/"),size:t.size,extension:r?"":"."+e.split(".").pop(),created:t.birthtime,modified:t.mtime,directory:r,symlink:t.isSymbolicLink()}}name(){return"files"}sync(){return Ce(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t=q(e.replace(/_/g," ")," "),i={description:"",state:!0};yield H(this.permissions,r=>Ce(this,void 0,void 0,function*(){const n=`${e}.${r}`;yield Ze.findOrCreate({where:{key:n},defaults:Object.assign({name:`${t} ${q(r," ")}`,key:n,tags:t},i)})}))})}};we([g("/path"),g("/path/*path"),Me(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],_t.prototype,"files",null),_t=we([y("/files"),p(gt)],_t);let ft=class ForgotController extends gt{check(e,t){return Ce(this,void 0,void 0,function*(){const i=yield this.find(t);if(!i||!i.user)return e.error(new n);i.secret=J(),yield i.save(),e.json({token:i.secret})})}forgot(e,t,i){return Ce(this,void 0,void 0,function*(){yield Y(Env.SLEEP_FORGOT);const r=t,s=yield nt.findOne({where:{[ce.or]:[{email:r},{username:t}]}}).catch(this.error);if(!s)return e.error(new n);const o=J(),d=Date.now()+6e4*Env.API_TOKEN_FORGOT,a=yield dt.create({token:o,timestamp:d,state:!0,user_id:s.id});e.success("OK"),i.emit("forgot.send",{ctx:e,forgot:a,user:s}),this.emit("forgot.send",{ctx:e,forgot:a,user:s})})}reset(e,t,i,r){return Ce(this,void 0,void 0,function*(){const i=yield this.find(t);if(!i)return e.error(new n);i.state=!1,yield i.save().catch(this.error),yield i.user.save().catch(this.error),e.success("OK"),r.emit("forgot.reset",{ctx:e,user:i.user}),this.emit("forgot.reset",{ctx:e,user:i.user})})}find(e){return Ce(this,void 0,void 0,function*(){return yield dt.findOne({where:{token:e,state:!0},include:[{model:nt,required:!0}]}).catch(this.error)})}};we([g("/check"),m(e=>({token:e.string().required()})),be(0,l()),be(1,_("token")),xe("design:type",Function),xe("design:paramtypes",[r,String]),xe("design:returntype",Promise)],ft.prototype,"check",null),we([h(),m(e=>({username:e.string().min(4).required()})),be(0,l()),be(1,_("username")),be(2,f()),xe("design:type",Function),xe("design:paramtypes",[r,String,Application]),xe("design:returntype",Promise)],ft.prototype,"forgot",null),we([h("/reset"),m(e=>({token:e.string().required(),password:e.string().min(5).required()})),be(0,l()),be(1,_("token")),be(2,_("password")),be(3,f()),xe("design:type",Function),xe("design:paramtypes",[r,String,String,Application]),xe("design:returntype",Promise)],ft.prototype,"reset",null),ft=we([y("/forgot"),p(gt)],ft);let Et=class GroupsController extends mt{constructor(){super(...arguments),this.model=et,this.schemaCreate={name:W.string().required(),key:W.string().required(),tags:W.string().empty(""),description:W.string().empty(""),state:W.boolean().parse().required()},this.schemaUpdate={name:W.string().empty(),tags:W.string().empty(),description:W.string().empty(),state:W.boolean().parse().empty()}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};Et=we([y("/groups"),p(mt)],Et);let At=class GroupsPermissionsController extends vt{constructor(){super(...arguments),this.model=Qe,this.permissions=[]}all(e,t){return Ce(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{group_id:t},include:[{model:Ze,required:!0}]},callback:e=>e.map(e=>e.permission)})})}set(e,t,i){return Ce(this,void 0,void 0,function*(){const r=yield et.findByPk(t,{attributes:["id"]}).catch(this.error);if(!r)return e.error(new n);const s=r.id,o=[];yield H(z(i),t=>Ce(this,void 0,void 0,function*(){var i;if(!(yield Ze.count({where:{id:t}})))return;const[r]=null!==(i=yield Qe.findOrCreate(Object.assign({where:{group_id:s,permission_id:t},defaults:{group_id:s,permission_id:t}},{ctx:e})).catch(this.error))&&void 0!==i?i:[];r&&o.push(t)})),yield Qe.destroy(Object.assign({where:{group_id:s,permission_id:{[ce.notIn]:o}},individualHooks:!0},{ctx:e})).catch(this.error),e.success("OK")})}};we([g("/:id/permissions"),Me(),Be("groups"),be(0,l()),be(1,S("id")),xe("design:type",Function),xe("design:paramtypes",[r,String]),xe("design:returntype",Promise)],At.prototype,"all",null),we([O("/:id/permissions"),Me(),Ke("groups"),m(e=>({permissions:e.array(e.string())})),be(0,l()),be(1,S("id")),be(2,_("permissions")),xe("design:type",Function),xe("design:paramtypes",[r,String,Array]),xe("design:returntype",Promise)],At.prototype,"set",null),At=we([y("/groups"),p(vt)],At);let Ot=class LogsController extends vt{constructor(){super(...arguments),this.model=at,this.permissions=["read"]}all(e){return Ce(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{order:[["created_at","DESC"]]},limited:!0})})}};we([g(),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],Ot.prototype,"all",null),Ot=we([y("/logs"),p(vt)],Ot);let St=class PermissionsController extends mt{constructor(){super(...arguments),this.model=Ze,this.schemaCreate={name:W.string().required(),key:W.string().required(),tags:W.string().empty(""),description:W.string().empty(""),state:W.boolean().parse().required()},this.schemaUpdate={name:W.string().empty(),tags:W.string().empty(),description:W.string().empty(),state:W.boolean().parse().empty()}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};St=we([y("/permissions"),p(mt)],St);let Tt=class RegisterController extends gt{register(e,t,i){return Ce(this,void 0,void 0,function*(){yield Y(Env.SLEEP_REGISTRY);const{name:r,date:n,email:o,username:d,password:a,confirm:l}=t,u=d||o,c=x(a);if(yield nt.count({where:{[ce.or]:[{email:o},{username:u}]}}).catch(this.error))return e.error("INVALID EMAIL OR USERNAME");if(c!=x(l))return e.error("INVALID PASSWORD");const p=yield nt.create({name:r,email:o,username:u,password:c,avatar:"",date:n,description:"",state:!1}).catch(this.error);if(!p)return e.error(new s);const g=yield ze.create({token:yield this.getId(),user_id:p.id,state:!0}).catch(this.error);if(!g)return yield p.destroy().catch(this.error),e.error(new s);e.success("OK"),i.emit("register.user",{ctx:e,register:g,user:p}),this.emit("register.user",{ctx:e,register:g,user:p})})}confirm(e,t,i){return Ce(this,void 0,void 0,function*(){const r=yield ze.findOne({where:{token:t,state:!0},include:[{model:nt,required:!0}]}).catch(this.error);if(!r)return e.error(new n);r.state=!1,yield r.save().catch(this.error),r.user.state=!0,yield r.user.save().catch(this.error),e.success("OK"),i.emit("register.confirm",{ctx:e,register:r,user:r.user}),this.emit("register.confirm",{ctx:e,register:r,user:r.user})})}send(e,t,i){return Ce(this,void 0,void 0,function*(){const r=t,s=yield ze.findOne({where:{state:!0},include:[{model:nt,required:!0,where:{[ce.or]:[{email:r},{username:t}]}}]}).catch(this.error);if(!s)return e.error(new n);e.success("OK"),i.emit("register.send",{ctx:e,register:s,user:s.user}),this.emit("register.send",{ctx:e,register:s,user:s.user})})}getId(){return Ce(this,void 0,void 0,function*(){const e=B();return(yield ze.count({where:{token:e}}))?this.getId():e})}};we([h(),m(e=>({name:e.string().required(),date:e.date().required(),email:e.string().email().required(),username:e.string().min(4).empty(),password:e.string().min(5).required(),confirm:e.string().min(5).required()})),be(0,l()),be(1,_()),be(2,f()),xe("design:type",Function),xe("design:paramtypes",[r,Object,Application]),xe("design:returntype",Promise)],Tt.prototype,"register",null),we([h("/confirm"),m(e=>({token:e.string().required()})),be(0,l()),be(1,_("token")),be(2,f()),xe("design:type",Function),xe("design:paramtypes",[r,String,Application]),xe("design:returntype",Promise)],Tt.prototype,"confirm",null),we([h("/send"),m(e=>({username:e.string().min(4).required()})),be(0,l()),be(1,_("username")),be(2,f()),xe("design:type",Function),xe("design:paramtypes",[r,String,Application]),xe("design:returntype",Promise)],Tt.prototype,"send",null),Tt=we([y("/register"),p(gt)],Tt);let Pt=class SetupController extends gt{setup(e){return Ce(this,void 0,void 0,function*(){var t;if(yield nt.count())return e.success("OK");const i=yield nt.create({name:"Admin",email:"admin@localhost.com",username:"admin",description:"DEFAULT",state:!0},Object.assign({},{ctx:e}));yield it.create({value:"admin",state:!0,user_id:i.id});const r=yield et.create(Object.assign({name:"Admin",key:"admin",tags:"Admin"},{description:"API CORE",state:!0}),Object.assign({},{ctx:e}));yield tt.create({user_id:i.id,group_id:r.id},Object.assign({},{ctx:e}));const n=null!==(t=yield Ze.findAll({where:{state:!0}}).catch(this.error))&&void 0!==t?t:[];yield H(n,t=>Ce(this,void 0,void 0,function*(){yield Qe.create({group_id:r.id,permission_id:t.id},Object.assign({},{ctx:e}))})),e.success("OK")})}};we([g(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],Pt.prototype,"setup",null),Pt=we([y("/setup"),p(gt)],Pt);let It=class UsersController extends vt{constructor(){super(),this.model=nt,this.path=Env.API_HTTP_PUBLIC+"/avatar",Env.API_HTTP_PUBLIC&&Ee(Env.API_HTTP_PUBLIC)&&!Ee(this.path)&&Se(this.path)}avatar(e,t){return Ce(this,void 0,void 0,function*(){var i,r;const n=e.getFiles();if(n.file&&n.file.length){const{filename:o,path:d}=null!==(i=n.file[0])&&void 0!==i?i:{};if(o){const[i]=null!==(r=yield rt.findOrCreate(Object.assign({where:{user_id:t.id},defaults:{user_id:t.id}},{ctx:e})).catch(this.error))&&void 0!==r?r:[];if(!i)return Te(d).isFile()&&Pe(d),e.error(new s);const n=this.path+"/"+i.data.avatar;if(Ee(n)&&Te(n).isFile()&&Pe(n),i.changed("data",!0),i.data.avatar=o,yield i.save(Object.assign({},{ctx:e})).catch(this.error))return e.success("OK")}}e.success("Record not Changed")})}token_new(){return Ce(this,void 0,void 0,function*(){var e;const t=B();return(null!==(e=yield this.model.count({where:{token:t}}).catch(this.error))&&void 0!==e?e:0)?this.token_new():t})}add(e){return Ce(this,void 0,void 0,function*(){yield this.create({ctx:e})})}all(e){return Ce(this,void 0,void 0,function*(){yield this.findAll({ctx:e})})}number(e){return Ce(this,void 0,void 0,function*(){yield this.countAll({ctx:e})})}del(e,t,i){return Ce(this,void 0,void 0,function*(){if(i.id==t)return e.error(new n);yield this.delete({ctx:e})})}get(e){return Ce(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}set(e){return Ce(this,void 0,void 0,function*(){yield this.update({ctx:e})})}};we([h("/avatar"),Me(),T({file:{count:1,path:`${Env.API_HTTP_PUBLIC}/avatar`,types:["image/bmp","image/jpeg","image/png"],size:32}}),be(0,l()),be(1,Ge()),xe("design:type",Function),xe("design:paramtypes",[r,nt]),xe("design:returntype",Promise)],It.prototype,"avatar",null),we([h(),Me(),ke(),m(e=>({name:e.string().required(),email:e.string().email().required(),username:e.string().min(3).required(),description:e.string().empty(""),state:e.boolean().parse().empty(!0)})),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],It.prototype,"add",null),we([g(),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],It.prototype,"all",null),we([g("/count"),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],It.prototype,"number",null),we([A("/:id"),Me(),Ne(),be(0,l()),be(1,S("id")),be(2,Ge()),xe("design:type",Function),xe("design:paramtypes",[r,String,nt]),xe("design:returntype",Promise)],It.prototype,"del",null),we([g("/:id"),Me(),Be(),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],It.prototype,"get",null),we([O("/:id"),Me(),Ke(),m(e=>({name:e.string().empty(),email:e.string().email().empty(),username:e.string().min(3).empty(),description:e.string().empty(),state:e.boolean().parse().empty()})),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],It.prototype,"set",null),It=we([y("/users"),p(vt),xe("design:paramtypes",[])],It);let wt=class UsersGroupsController extends vt{constructor(){super(...arguments),this.model=tt,this.permissions=[]}all(e,t){return Ce(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{user_id:t},include:[{model:et,required:!0}]},callback:e=>e.map(e=>e.group)})})}set(e,t,i){return Ce(this,void 0,void 0,function*(){const r=yield nt.findByPk(t,{attributes:["id"]}).catch(this.error);if(!r)return e.error(new n);const s=r.id,o=[];yield H(z(i),t=>Ce(this,void 0,void 0,function*(){var i;if(!(yield et.count({where:{id:t}})))return;const[r]=null!==(i=yield tt.findOrCreate(Object.assign({where:{user_id:s,group_id:t},defaults:{user_id:s,group_id:t}},{ctx:e})).catch(this.error))&&void 0!==i?i:[];r&&o.push(t)})),yield tt.destroy(Object.assign({where:{user_id:s,group_id:{[ce.notIn]:o}},individualHooks:!0},{ctx:e})).catch(this.error),e.success("OK")})}};we([g("/:id/groups"),Me(),Be("users"),be(0,l()),be(1,S("id")),xe("design:type",Function),xe("design:paramtypes",[r,String]),xe("design:returntype",Promise)],wt.prototype,"all",null),we([O("/:id/groups"),Me(),Ke("users"),m(e=>({groups:e.array(e.string())})),be(0,l()),be(1,S("id")),be(2,_("groups")),xe("design:type",Function),xe("design:paramtypes",[r,String,Array]),xe("design:returntype",Promise)],wt.prototype,"set",null),wt=we([y("/users"),p(vt)],wt);let bt=class UsersProfilesController extends vt{constructor(){super(...arguments),this.model=rt,this.permissions=[]}all(e){return Ce(this,void 0,void 0,function*(){yield this.findAll({ctx:e})})}get(e,t){return Ce(this,void 0,void 0,function*(){var i;const[r]=null!==(i=yield rt.findOrCreate(Object.assign({where:{user_id:t},defaults:{user_id:t}},{ctx:e})).catch(this.error))&&void 0!==i?i:[];if(!r)return e.error(new n);e.json(r.data)})}set(e,t,i){return Ce(this,void 0,void 0,function*(){var r;const s=yield nt.findByPk(t,{attributes:["id"]}).catch(this.error);if(!s)return e.error(new n);const o=s.id,d=X(i,e=>String(e)),[a,l]=null!==(r=yield rt.findOrCreate(Object.assign({where:{user_id:o},defaults:{data:d,user_id:o}},{ctx:e})).catch(this.error))&&void 0!==r?r:[];a&&!l&&(a.changed("data",!0),a.data=U(a.data,d),yield a.save(Object.assign({},{ctx:e})).catch(this.error)),e.success("OK")})}};we([g("/profiles"),Me(),Be("users"),be(0,l()),xe("design:type",Function),xe("design:paramtypes",[r]),xe("design:returntype",Promise)],bt.prototype,"all",null),we([g("/:id/profiles"),Me(),Be("users"),be(0,l()),be(1,S("id")),xe("design:type",Function),xe("design:paramtypes",[r,String]),xe("design:returntype",Promise)],bt.prototype,"get",null),we([O("/:id/profiles"),Me(),Ke("users"),be(0,l()),be(1,S("id")),be(2,_()),xe("design:type",Function),xe("design:paramtypes",[r,String,Object]),xe("design:returntype",Promise)],bt.prototype,"set",null),bt=we([y("/users"),p(vt)],bt);export{Application,We as Audit,st as AuditModel,yt as AuditsController,ht as AuthController,AuthService,gt as BaseController,ke as CanCreate,Ne as CanDelete,Be as CanRead,Ke as CanUpdate,Config,ot as ConfigModel,mt as CrudController,Env,_t as FilesController,ft as ForgotController,dt as ForgotModel,et as GroupModel,Qe as GroupPermissionModel,Et as GroupsController,At as GroupsPermissionsController,Ue as HasGroups,Le as HasPermissions,Me as IsAuthenticated,Log,at as LogModel,Loggable,Ot as LogsController,lt as MigrationModel,vt as ModelController,ModelService,Ze as PermissionModel,St as PermissionsController,Tt as RegisterController,ze as RegisterModel,Fe as ReqAuth,He as ReqGroup,qe as ReqGroups,Ye as ReqPermission,$e as ReqPermissions,Ge as ReqUser,pt as Service,ut as SessionModel,SessionStore,Pt as SetupController,Xe as UserAuthModel,tt as UserGroupModel,ct as UserMetadataModel,nt as UserModel,it as UserPasswordModel,rt as UserProfileModel,UserService,It as UsersController,wt as UsersGroupsController,bt as UsersProfilesController,je as canFactory,Re as sequelize};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@andrewcaires/api",
3
- "version": "4.5.2",
3
+ "version": "5.0.1",
4
4
  "description": "Simple api for small applications using express, jsonwebtoken, sequelize and websocket",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs.js",
@@ -46,13 +46,15 @@
46
46
  },
47
47
  "homepage": "https://github.com/andrewcaires/npm/tree/main/api#readme",
48
48
  "dependencies": {
49
- "@andrewcaires/express": "^1.2.7",
50
- "@andrewcaires/node": "^1.2.9",
51
- "@andrewcaires/sequelize": "^2.0.2",
52
- "@andrewcaires/utils.js": "^0.4.20",
53
- "cors": "^2.8.5",
54
- "dotenv": "^17.2.3",
55
- "express-session": "^1.18.2",
49
+ "@andrewcaires/decorator": "^1.1.1",
50
+ "@andrewcaires/express": "^2.0.5",
51
+ "@andrewcaires/node": "^1.3.1",
52
+ "@andrewcaires/sequelize": "^3.0.0",
53
+ "@andrewcaires/utils.js": "^0.4.29",
54
+ "bcrypt": "^6.0.0",
55
+ "cors": "^2.8.6",
56
+ "dotenv": "^17.3.1",
57
+ "express-session": "^1.19.0",
56
58
  "jsonwebtoken": "^9.0.3",
57
59
  "tsx": "^4.21.0",
58
60
  "ws": "^8.19.0"
@@ -61,16 +63,17 @@
61
63
  "@rollup/plugin-commonjs": "^29.0.0",
62
64
  "@rollup/plugin-terser": "^0.4.4",
63
65
  "@rollup/plugin-typescript": "^12.3.0",
66
+ "@types/bcrypt": "^6.0.0",
64
67
  "@types/cors": "^2.8.19",
65
68
  "@types/express-session": "^1.18.2",
66
69
  "@types/jsonwebtoken": "^9.0.10",
67
- "@types/node": "^25.0.8",
70
+ "@types/node": "^25.2.3",
68
71
  "@types/ws": "^8.18.1",
69
- "eslint": "^9.39.2",
72
+ "eslint": "^10.0.0",
70
73
  "mariadb": "^3.4.5",
71
- "rollup": "^4.55.1",
74
+ "rollup": "^4.57.1",
72
75
  "rollup-plugin-dts": "^6.3.0",
73
76
  "tslib": "^2.8.1",
74
- "typescript-eslint": "^8.53.0"
77
+ "typescript-eslint": "^8.56.0"
75
78
  }
76
79
  }