@andrewcaires/api 4.4.1 → 4.5.0
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/LICENSE +1 -1
- package/dist/index.cjs.js +3 -3
- package/dist/index.d.ts +132 -160
- package/dist/index.esm.js +3 -3
- package/package.json +16 -16
package/dist/index.esm.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*!
|
|
2
|
-
* @andrewcaires/api v4.
|
|
2
|
+
* @andrewcaires/api v4.5.0
|
|
3
3
|
* Simple api for small applications using express, jsonwebtoken, sequelize and websocket
|
|
4
|
-
* (c)
|
|
4
|
+
* (c) 2026 Andrew Caires
|
|
5
5
|
* @license: MIT
|
|
6
6
|
*/
|
|
7
|
-
import{Env as e,Metadata as t,Log as i,LogColor as r,Hash as s,sha256 as n}from"@andrewcaires/node";import{config as o}from"dotenv";import{EventEmitter as d,isObject as a,noop as u,uuidv4 as p,loop as c,forEachSeries as l,isFunction as y,sleep as g,upperCamelCase as h,Validation as v,isArray as _,isString as m,isUndefined as E,clamp as A,isNumber as O,denied as I,isDef as f,uniqueID as P}from"@andrewcaires/utils.js";import{parameterFactory as R,Application as S,Ctx as T,Headers as D,Query as N,App as b,Context as w,Argument as C,Session as x,Upload as F,Extends as j,Status as k,Post as L,Middleware as U,Get as B,Delete as M,Put as H,Controller as K,Body as q,Params as Y,Files as V}from"@andrewcaires/express";import{Model as $,Connection as G,Id as W,String as z,FullDate as J,CreatedAt as Z,UpdatedAt as X,DeletedAt as Q,BelongsTo as ee,Database as te,ModelName as ie,Boolean as re,Text as se,HasMany as ne,Hooks as oe,DateOnly as de,DefaultScope as ae,Scopes as ue,Enum as pe,Json as ce,BigInt as le,Unique as ye,migrate as ge,Where as he}from"@andrewcaires/sequelize";import ve from"jsonwebtoken";import{readFileSync as _e,existsSync as me,statSync as Ee,readdirSync as Ae,mkdirSync as Oe,lstatSync as Ie,rmSync as fe}from"fs";import{WebSocketServer as Pe}from"ws";import{Store as Re}from"express-session";import{Op as Se}from"sequelize";import{join as Te}from"path";o({quiet:!0});class De extends e{}De.API_BASE_NAME=De.getString("API_BASE_NAME",""),De.API_BODYPARSER_STRICT=De.getBool("API_BODYPARSER_STRICT",!0),De.API_BODYPARSER_INFLATE=De.getBool("API_BODYPARSER_INFLATE",!0),De.API_BODYPARSER_LIMIT=De.getString("API_BODYPARSER_LIMIT","10mb"),De.API_BODYPARSER_TYPE=De.getString("API_BODYPARSER_TYPE","json"),De.API_CONSOLE_ERROR=De.getBool("API_CONSOLE_ERROR",!1),De.API_DB_DATABASE=De.getString("API_DB_DATABASE",""),De.API_DB_HOST=De.getString("API_DB_HOST","127.0.0.1"),De.API_DB_PASSWORD=De.getString("API_DB_PASSWORD",""),De.API_DB_PORT=De.getInt("API_DB_PORT",3306),De.API_DB_TYPE=De.getString("API_DB_TYPE",""),De.API_DB_USERNAME=De.getString("API_DB_USERNAME","root"),De.API_DB_LOG=De.getBool("API_DB_LOG",!1),De.API_DB_AUDIT=De.getBool("API_DB_AUDIT",!0),De.API_DB_PREFIX=De.getString("API_DB_PREFIX",""),De.API_DB_TIMEZONE=De.getString("API_DB_TIMEZONE","+00:00"),De.API_HTTP_CRT=De.getString("API_HTTP_CRT",""),De.API_HTTP_KEY=De.getString("API_HTTP_KEY",""),De.API_HTTP_PORT=De.getInt("API_HTTP_PORT",3e3),De.API_HTTP_PUBLIC=De.getString("API_HTTP_PUBLIC",""),De.API_HTTP_CROSS=De.getBool("API_HTTP_CROSS",!1),De.API_HTTP_HYBRID=De.getBool("API_HTTP_HYBRID",!1),De.API_HTTP_NOTFOUND=De.getString("API_HTTP_NOTFOUND",""),De.API_HTTP_PATH=De.getString("API_HTTP_PATH","/api"),De.API_HTTP_REDIRECT=De.getString("API_HTTP_REDIRECT",""),De.API_KEY_HASH=De.getString("API_KEY_HASH",""),De.API_KEY_HEADER=De.getString("API_KEY_HEADER","x-api-key"),De.API_MODEL_LIMIT=De.getInt("API_MODEL_LIMIT",10),De.API_MODEL_LIMIT_MAX=De.getInt("API_MODEL_LIMIT_MAX",500),De.API_SLEEP_AUTH=De.getMs("API_SLEEP_AUTH","2s"),De.API_SLEEP_FORGOT=De.getMs("API_SLEEP_FORGOT","5s"),De.API_SLEEP_REGISTRY=De.getMs("API_SLEEP_REGISTRY","5s"),De.API_SESSION_NAME=De.getString("API_SESSION_NAME","session.id"),De.API_SESSION_LIFETIME=De.getMs("API_SESSION_LIFETIME","1d"),De.API_SESSION_SECRET=De.getString("API_SESSION_SECRET","yoursecret"),De.API_TOKEN_CRT=De.getString("API_TOKEN_CRT",""),De.API_TOKEN_KEY=De.getString("API_TOKEN_KEY",""),De.API_TOKEN_FORGOT=De.getMs("API_TOKEN_LIFETIME","1d"),De.API_TOKEN_HEADER=De.getString("API_TOKEN_HEADER","authorization"),De.API_TOKEN_HEADER_KEY=De.getString("API_TOKEN_HEADER","bearer"),De.API_TOKEN_LIFETIME=De.getMs("API_TOKEN_LIFETIME","1d"),De.API_TOKEN_RENEW=De.getMs("API_TOKEN_RENEW","1d"),De.API_UPLOAD_COUNT=De.getInt("API_UPLOAD_COUNT",1),De.API_UPLOAD_FIELD=De.getString("API_UPLOAD_FIELD","upload"),De.API_UPLOAD_SIZE=De.getInt("API_UPLOAD_SIZE",2),De.API_UPLOAD_TEMP=De.getString("API_UPLOAD_TEMP","./temp"),De.API_USER_HISTORY=De.getBool("API_USER_HISTORY",!0),De.API_WEBSOCKET_START=De.getBool("API_WEBSOCKET_START",!1);class Ne extends d{}function be(e,t,i,r){var s,n=arguments.length,o=n<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--)(s=e[d])&&(o=(n<3?s(o):n>3?s(t,i,o):s(t,i))||o);return n>3&&o&&Object.defineProperty(t,i,o),o}function we(e,t){return function(i,r){t(i,r,e)}}function Ce(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function xe(e,t,i,r){return new(i||(i=Promise))(function(s,n){function o(e){try{a(r.next(e))}catch(e){n(e)}}function d(e){try{a(r.throw(e))}catch(e){n(e)}}function a(e){var t;e.done?s(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())})}Ne.ATTRIBUTES=Symbol("ATTRIBUTES"),Ne.PERMISSIONS=Symbol("PERMISSIONS"),"function"==typeof SuppressedError&&SuppressedError;const Fe=e=>{var t,i,r,s,n,o,d,a,u;return{audit_client:null!==(t=e.ip())&&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===(s=null==e?void 0:e.req)||void 0===s?void 0:s.originalUrl),audit_user_agent:null!==(o=null===(n=e.req)||void 0===n?void 0:n.headers["user-agent"])&&void 0!==o?o:"",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}},je=R(({ctx:e})=>Fe(e)),ke=R(({ctx:e})=>e.req.auth),Le=R(({ctx:e})=>e.req.user),Ue=e=>t=>{Be.migrations(t).version=e};class Be{static migrations(e){return t(Be.MIGRATE,e,{version:""})}}Be.MIGRATE=Symbol("MIGRATE");class Me extends ${static error(e){i.error(e.message)}}const He=new G({type:De.API_DB_TYPE,database:De.API_DB_DATABASE,username:De.API_DB_USERNAME,password:De.API_DB_PASSWORD,hostname:De.API_DB_HOST,hostport:De.API_DB_PORT,logging:De.API_DB_LOG,prefix:De.API_DB_PREFIX,timezone:De.API_DB_TIMEZONE}),Ke=(e,t,i)=>{var r,s,n,o,d;return{type:e,model:null!==(r=null==t?void 0:t.getTableName())&&void 0!==r?r:null,client:null!==(s=null==i?void 0:i.audit_client)&&void 0!==s?s:null,href:null!==(n=null==i?void 0:i.audit_href)&&void 0!==n?n:null,user_agent:null!==(o=null==i?void 0:i.audit_user_agent)&&void 0!==o?o:null,user_id:null!==(d=null==i?void 0:i.audit_user_id)&&void 0!==d?d:null,state:!0}},qe={afterCreate:(e,t)=>xe(void 0,void 0,void 0,function*(){var i;if(!De.API_DB_AUDIT)return;const r=a(e)?e.constructor:null,s=null!==(i=null==r?void 0:r.primaryKeyAttribute)&&void 0!==i?i:null;yield Je.create(Object.assign(Object.assign({},Ke("CREATE",r,t)),{record:s?e.getDataValue(s):null,data:e.toJSON()})).catch(u)}),afterUpdate:(e,t)=>xe(void 0,void 0,void 0,function*(){var i;if(!De.API_DB_AUDIT)return;const r=a(e)?e.constructor:null,s=null!==(i=null==r?void 0:r.primaryKeyAttribute)&&void 0!==i?i:null,n={},o=e.changed();o&&o.forEach(t=>n[t]=e.getDataValue(t)),yield Je.create(Object.assign(Object.assign({},Ke("UPDATE",r,t)),{record:s?e.getDataValue(s):null,data:n,previously:e.previous()})).catch(u)}),afterDestroy:(e,t)=>xe(void 0,void 0,void 0,function*(){var i;if(!De.API_DB_AUDIT)return;const r=a(e)?e.constructor:null,s=null!==(i=null==r?void 0:r.primaryKeyAttribute)&&void 0!==i?i:null;yield Je.create(Object.assign(Object.assign({},Ke("DELETE",r,t)),{record:s?e.getDataValue(s):null,data:e.toJSON()})).catch(u)})};let Ye=class extends Me{};be([W(),Ce("design:type",Number)],Ye.prototype,"id",void 0),be([z(),Ce("design:type",z)],Ye.prototype,"secret",void 0),be([J(),Ce("design:type",Object)],Ye.prototype,"logout",void 0),be([z(),Ce("design:type",z)],Ye.prototype,"user_agent",void 0),be([Z,Ce("design:type",Date)],Ye.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],Ye.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],Ye.prototype,"deleted_at",void 0),be([ee(()=>ze),Ce("design:type",Number)],Ye.prototype,"user_id",void 0),Ye=be([te(He),ie("auth"),Ue("4.2.0")],Ye);let Ve=class extends Me{};be([W(),Ce("design:type",Number)],Ve.prototype,"id",void 0),be([z(),Ce("design:type",z)],Ve.prototype,"token",void 0),be([re(),Ce("design:type",re)],Ve.prototype,"state",void 0),be([Z,Ce("design:type",Date)],Ve.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],Ve.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],Ve.prototype,"deleted_at",void 0),be([ee(()=>ze),Ce("design:type",Number)],Ve.prototype,"user_id",void 0),Ve=be([te(He),ie("register"),Ue("4.2.0")],Ve);let $e=class extends Me{};be([W(),Ce("design:type",Number)],$e.prototype,"id",void 0),be([z(),Ce("design:type",z)],$e.prototype,"name",void 0),be([se(),Ce("design:type",z)],$e.prototype,"description",void 0),be([re(),Ce("design:type",re)],$e.prototype,"state",void 0),be([Z,Ce("design:type",Date)],$e.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],$e.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],$e.prototype,"deleted_at",void 0),be([ne(()=>Ge,"group_id"),Ce("design:type",Array)],$e.prototype,"groups_routes",void 0),be([ne(()=>Ge,"group_id"),Ce("design:type",Array)],$e.prototype,"users_groups",void 0),$e=be([te(He),ie("group"),oe(qe),Ue("4.2.0")],$e);let Ge=class extends Me{};be([Z,Ce("design:type",Date)],Ge.prototype,"created_at",void 0),be([ee(()=>$e),Ce("design:type",Number)],Ge.prototype,"group_id",void 0),be([ee(()=>ze),Ce("design:type",Number)],Ge.prototype,"user_id",void 0),Ge=be([te(He),ie("users_groups"),oe(qe),Ue("4.2.0")],Ge);let We=class extends Me{};be([z(),Ce("design:type",z)],We.prototype,"password",void 0),be([Z,Ce("design:type",Date)],We.prototype,"created_at",void 0),be([ee(()=>ze),Ce("design:type",Number)],We.prototype,"user_id",void 0),We=be([te(He),ie("users_histories"),Ue("4.2.0")],We);let ze=class extends Me{};be([W(),Ce("design:type",Number)],ze.prototype,"id",void 0),be([z(),Ce("design:type",z)],ze.prototype,"name",void 0),be([z(),Ce("design:type",z)],ze.prototype,"email",void 0),be([z(),Ce("design:type",z)],ze.prototype,"username",void 0),be([z(),Ce("design:type",z)],ze.prototype,"password",void 0),be([z(),Ce("design:type",z)],ze.prototype,"salt",void 0),be([z(),Ce("design:type",z)],ze.prototype,"token",void 0),be([z(),Ce("design:type",z)],ze.prototype,"avatar",void 0),be([de(),Ce("design:type",z)],ze.prototype,"date",void 0),be([se(),Ce("design:type",z)],ze.prototype,"description",void 0),be([re(),Ce("design:type",re)],ze.prototype,"state",void 0),be([Z,Ce("design:type",Date)],ze.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],ze.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],ze.prototype,"deleted_at",void 0),be([ne(()=>Je,"user_id"),Ce("design:type",Array)],ze.prototype,"audits",void 0),be([ne(()=>Ye,"user_id"),Ce("design:type",Array)],ze.prototype,"auths",void 0),be([ne(()=>Ve,"user_id"),Ce("design:type",Array)],ze.prototype,"registers",void 0),be([ne(()=>Ge,"user_id"),Ce("design:type",Array)],ze.prototype,"users_groups",void 0),be([ne(()=>We,"user_id"),Ce("design:type",Array)],ze.prototype,"users_histories",void 0),ze=be([te(He),ie("user"),ae({attributes:{exclude:["password","salt","token"]}}),ue({password:{attributes:{exclude:["token"]}},token:{attributes:{exclude:["password","salt"]}}}),oe(qe),Ue("4.2.0")],ze);let Je=class extends Me{};be([W(),Ce("design:type",Number)],Je.prototype,"id",void 0),be([pe("CREATE","DELETE","UPDATE"),Ce("design:type",z)],Je.prototype,"type",void 0),be([z(),Ce("design:type",z)],Je.prototype,"model",void 0),be([z(),Ce("design:type",z)],Je.prototype,"record",void 0),be([ce(),Ce("design:type",Object)],Je.prototype,"data",void 0),be([ce(),Ce("design:type",Object)],Je.prototype,"previously",void 0),be([z(),Ce("design:type",z)],Je.prototype,"client",void 0),be([se(),Ce("design:type",z)],Je.prototype,"href",void 0),be([z(),Ce("design:type",z)],Je.prototype,"user_agent",void 0),be([re(),Ce("design:type",re)],Je.prototype,"state",void 0),be([Z,Ce("design:type",Date)],Je.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],Je.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],Je.prototype,"deleted_at",void 0),be([ee(()=>ze),Ce("design:type",Number)],Je.prototype,"user_id",void 0),Je=be([te(He),ie("audit"),Ue("4.2.0")],Je);let Ze=class extends Me{static all(){return xe(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 xe(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 xe(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 xe(this,void 0,void 0,function*(){var r;const s=null!==(r=null==i?void 0:i.id)&&void 0!==r?r:null,[n]=(yield this.findOrCreate(Object.assign({where:{key:e}},{user_id:s})).catch(this.error))||[];n&&(n.value=t,yield n.save().catch(this.error))})}};be([z(),Ce("design:type",z)],Ze.prototype,"key",void 0),be([z(),Ce("design:type",z)],Ze.prototype,"value",void 0),be([Z,Ce("design:type",Date)],Ze.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],Ze.prototype,"updated_at",void 0),Ze=be([te(He),ie("configs"),Ue("4.2.0")],Ze);let Xe=class extends Me{};be([W(),Ce("design:type",Number)],Xe.prototype,"id",void 0),be([z(),Ce("design:type",z)],Xe.prototype,"token",void 0),be([le(),Ce("design:type",Number)],Xe.prototype,"timestamp",void 0),be([re(),Ce("design:type",re)],Xe.prototype,"state",void 0),be([Z,Ce("design:type",Date)],Xe.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],Xe.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],Xe.prototype,"deleted_at",void 0),be([ee(()=>ze),Ce("design:type",Number)],Xe.prototype,"user_id",void 0),Xe=be([te(He),ie("forgot"),Ue("4.2.0")],Xe);let Qe=class extends Me{};be([W(),Ce("design:type",Number)],Qe.prototype,"id",void 0),be([z(),Ce("design:type",z)],Qe.prototype,"name",void 0),be([z(),ye(!0),Ce("design:type",z)],Qe.prototype,"route",void 0),be([z(),Ce("design:type",z)],Qe.prototype,"tag",void 0),be([se(),Ce("design:type",z)],Qe.prototype,"description",void 0),be([re(),Ce("design:type",re)],Qe.prototype,"state",void 0),be([Z,Ce("design:type",Date)],Qe.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],Qe.prototype,"updated_at",void 0),be([Q,Ce("design:type",Object)],Qe.prototype,"deleted_at",void 0),be([ne(()=>et,"permission_id"),Ce("design:type",Array)],Qe.prototype,"groups_permissions",void 0),Qe=be([te(He),ie("permission"),oe(qe),Ue("4.3.1")],Qe);let et=class extends Me{};var tt;be([Z,Ce("design:type",Date)],et.prototype,"created_at",void 0),be([ee(()=>$e),Ce("design:type",Number)],et.prototype,"group_id",void 0),be([ee(()=>Qe),Ce("design:type",Number)],et.prototype,"permission_id",void 0),et=be([te(He),ie("groups_permissions"),oe(qe),Ue("4.2.0")],et);let it=tt=class extends Me{static write(e,t,i){return xe(this,void 0,void 0,function*(){yield this.writeRaw(r.White,"",e,t,i)})}static error(e,t,i){return xe(this,void 0,void 0,function*(){yield this.writeRaw(r.Red,"error",e,t,i)})}static info(e,t,i){return xe(this,void 0,void 0,function*(){yield this.writeRaw(r.Cyan,"info",e,t,i)})}static success(e,t,i){return xe(this,void 0,void 0,function*(){yield this.writeRaw(r.Green,"success",e,t,i)})}static warning(e,t,i){return xe(this,void 0,void 0,function*(){yield this.writeRaw(r.Yellow,"warning",e,t,i)})}static writeRaw(e,t,r,s,n){return xe(this,void 0,void 0,function*(){n&&i.console(e,t,r),He&&(yield tt.create({type:t,source:s,message:r}).catch(this.error))})}};be([W(),Ce("design:type",Number)],it.prototype,"id",void 0),be([z(),Ce("design:type",z)],it.prototype,"type",void 0),be([z(),Ce("design:type",z)],it.prototype,"source",void 0),be([se(),Ce("design:type",z)],it.prototype,"message",void 0),be([Z,Ce("design:type",Date)],it.prototype,"created_at",void 0),it=tt=be([te(He),ie("log"),Ue("4.2.0")],it);let rt=class extends Me{};be([z(),Ce("design:type",z)],rt.prototype,"model",void 0),be([z(),Ce("design:type",z)],rt.prototype,"version",void 0),be([Z,Ce("design:type",Date)],rt.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],rt.prototype,"updated_at",void 0),rt=be([te(He),ie("migration"),Ue("4.2.0")],rt);let st=class extends Me{};be([z(),Ce("design:type",z)],st.prototype,"session",void 0),be([se(),Ce("design:type",z)],st.prototype,"json",void 0),be([le(),Ce("design:type",Number)],st.prototype,"expired",void 0),be([Z,Ce("design:type",Date)],st.prototype,"created_at",void 0),be([X,Ce("design:type",Date)],st.prototype,"updated_at",void 0),st=be([te(He),ie("session"),Ue("4.2.0")],st);class nt{static error(e){let t="token";De.API_BASE_NAME&&(t=`${De.API_BASE_NAME}.${t}`),it.error(e.message,t,De.API_CONSOLE_ERROR)}}class ot extends nt{static user(e,t){return xe(this,void 0,void 0,function*(){if(!e)return{error:"INVALID TOKEN"};const i=t.hash.encrypt(e),r=yield ze.findOne({where:{token:i,state:!0}}).catch(this.error);if(r){const t=e.replace(/(-[\w]{4})/g,"-****"),[i]=(yield Ye.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 dt=e=>me(e)?_e(e):void 0,at={http:dt(De.API_HTTP_CRT),token:dt(De.API_TOKEN_CRT)},ut={http:dt(De.API_HTTP_KEY),token:dt(De.API_TOKEN_KEY)};class pt extends nt{static options(){return{algorithm:"RS256",expiresIn:`${De.API_TOKEN_LIFETIME}ms`}}static create(e){return xe(this,void 0,void 0,function*(){if(!ut.token)return{error:"KEY NOT FOUND"};const{id:t}=e,i=p(),r=yield Ye.create({secret:i,user_id:t}).catch(this.error);if(!r)return{error:"INTERNAL SERVER ERROR"};return{auth:r,token:ve.sign({id:t,secret:i},ut.token,this.options())}})}static destroy(e){return xe(this,void 0,void 0,function*(){return!(!e||e.logout)&&(e.logout=new Date,yield e.save(),!0)})}static renew(e){return xe(this,void 0,void 0,function*(){if(!ut.token)return{error:"KEY NOT FOUND"};const{error:t,decode:i}=this.verify(e,De.API_TOKEN_RENEW/1e3);if(t)return{error:t};if(i){const{id:e,secret:t}=i;if(e&&t){const i=yield ze.findOne({where:{id:e,state:!0}}).catch(this.error);if(i){const r=yield Ye.findOne({where:{secret:t,user_id:i.id}}).catch(this.error);if(r&&!r.logout){r.secret=p(),yield r.save().catch(this.error);return{auth:r,token:ve.sign({id:e,secret:r.secret},ut.token,this.options())}}}return{error:"ACCESS DENIED"}}}return{error:"INVALID TOKEN"}})}static user(e){return xe(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 ze.findOne({where:{id:e,state:!0}}).catch(this.error);if(i){const e=yield Ye.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(!at.token)return{error:"CERT NOT FOUND"};if(!e||e.split(".").length<3)return{error:"INVALID TOKEN"};try{return{decode:ve.verify(e,at.token,{clockTolerance:t})}}catch(e){return{error:"INVALID TOKEN"}}}}class ct extends Re{constructor(){super(),this.all=e=>xe(this,void 0,void 0,function*(){e=e||u;const t=yield st.findAll({attributes:["session"],where:{expired:{[Se.gte]:Date.now()}}}).catch(t=>(e(t),null));t&&e(null,t.map(e=>e.session)),e()}),this.clear=e=>xe(this,void 0,void 0,function*(){yield st.destroy().catch(u),e&&e()}),this.destroy=(e,t)=>xe(this,void 0,void 0,function*(){yield st.destroy({where:{session:e}}).catch(u),t&&t()}),this.expired=()=>xe(this,void 0,void 0,function*(){yield st.destroy({where:{expired:{[Se.lt]:Date.now()}}}).catch(u)}),this.get=(e,t)=>xe(this,void 0,void 0,function*(){t=t||u;const i=yield st.findOne({where:{session:e,expired:{[Se.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(u),void t(null)}return void t(null,e)}t(null)}),this.length=e=>xe(this,void 0,void 0,function*(){e&&e(null,(yield st.count().catch(u))||0)}),this.set=(e,t,i)=>xe(this,void 0,void 0,function*(){i=i||u;const r=Date.now()+De.API_SESSION_LIFETIME,s=JSON.stringify(t),[n,o]=(yield st.findOrCreate({where:{session:e},defaults:{session:e,json:s,expired:r}}).catch(u))||[];n&&(o||(n.json=s,n.expired=r,yield n.save().catch(u))),i()}),this.loop=c(this.expired,3e4),this.loop.start()}}class lt extends S{constructor(e){super(e,{cert:at.http,cross:De.API_HTTP_CROSS,hybrid:De.API_HTTP_HYBRID,json:{strict:De.API_BODYPARSER_STRICT,inflate:De.API_BODYPARSER_INFLATE,limit:De.API_BODYPARSER_LIMIT,type:De.API_BODYPARSER_TYPE},key:ut.http,notfound:De.API_HTTP_NOTFOUND,path:De.API_HTTP_PATH,port:De.API_HTTP_PORT,public:De.API_HTTP_PUBLIC,redirect:De.API_HTTP_REDIRECT,session:{store:new ct,name:De.API_SESSION_NAME,secret:De.API_SESSION_SECRET,cookie:{maxAge:De.API_SESSION_LIFETIME},genid:p}}),this.hash=new s(De.API_KEY_HASH)}error(e,t){De.API_BASE_NAME&&(t=t?`${De.API_BASE_NAME}.${t}`:De.API_BASE_NAME),it.error(e.message,t,De.API_CONSOLE_ERROR)}log(e,t){De.API_BASE_NAME&&(t=t?`${De.API_BASE_NAME}.${t}`:De.API_BASE_NAME),it.info(e,t,!0)}listen(){const e=Object.create(null,{listen:{get:()=>super.listen}});return xe(this,void 0,void 0,function*(){yield He.sync(),yield this.migrations(He),yield l(this.controllers,e=>xe(this,void 0,void 0,function*(){y(e.sync)&&(yield e.sync(this))})),yield e.listen.call(this),De.API_WEBSOCKET_START&&this.server&&(this._webSocket=new Pe({server:this.server,verifyClient:(e,t)=>t(De.API_WEBSOCKET_START)}),this._webSocket.on("connection",(e,t)=>xe(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",s=>xe(this,void 0,void 0,function*(){if(r)try{const n=JSON.parse(s);this.emit("ws.message"+i,{data:n,message:s,req:t,user:r,ws:e})}catch(n){this.emit("ws.message"+i,{erro:n,message:s,req:t,user:r,ws:e})}else{const{user:n}=yield pt.user(s.toString());n&&(r=n,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 g(2e3),r||e.close()})))})}migrations(e){return xe(this,void 0,void 0,function*(){const t=[];yield l(Object.keys(e.models),i=>xe(this,void 0,void 0,function*(){var r;const s=e.models[i],{version:n}=Be.migrations(s);if(!n)return;const[o,d]=null!==(r=yield rt.findOrCreate({where:{model:s.tableName},defaults:{model:s.tableName,version:""}}).catch(this.error))&&void 0!==r?r:[];o&&(d||o.version!=n)&&(o.version=n,yield o.save().catch(this.error),t.push(s))})),t.length&&(yield ge(e,t))})}websocket(){return this._webSocket}}var yt,gt,ht;class vt extends Ne{constructor(){super(...arguments),this[yt]=[]}auth(e,t,i,r,s,n){return xe(this,void 0,void 0,function*(){var o;t=null!=t?t:r;const[d,a]=null!==(o=null==i?void 0:i.split(" "))&&void 0!==o?o:["",""];if(!(t||a&&d.toLowerCase()==De.API_TOKEN_HEADER_KEY))return e.error("INVALID TOKEN");const{auth:u,error:p,user:c}=yield t?ot.user(t,n):pt.user(a);return p?e.error(p):u&&c?!t&&u.user_agent&&u.user_agent!=s?e.error("INVALID TOKEN"):(e.req.auth=u,e.req.user=c,void e.next()):e.error("INTERNAL SERVER ERROR")})}canCreate(e,t,i){return xe(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".create",i)})}canDelete(e,t,i){return xe(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".delete",i)})}canRead(e,t,i){return xe(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".read",i)})}canUpdate(e,t,i){return xe(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".update",i)})}error(e){let t="controller_base";De.API_BASE_NAME&&(t=`${De.API_BASE_NAME}.${t}`),it.error(e.message,t,De.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 xe(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 xe(this,void 0,void 0,function*(){var i;return null!==(i=yield Qe.findAll({where:Object.assign(Object.assign({},null!=t?t:{}),{state:!0}),include:[{model:et,required:!0,include:[{model:$e,required:!0,where:{state:!0},include:[{model:Ge,required:!0,where:{user_id:e.id}}]}]}]}).catch(this.error))&&void 0!==i?i:[]})}session(e,t,i){return xe(this,void 0,void 0,function*(){i.auth&&i.user&&(i.user_agent?i.user_agent!=t&&i.regenerate(u):(i.user_agent=t,i.save(u))),e.next()})}sync(){return xe(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield l(this[Ne.PERMISSIONS],i=>xe(this,void 0,void 0,function*(){const r=`${e}.${i}`,s=h(e.replace(/_/g," ")," ");yield Qe.findOrCreate({where:{route:r},defaults:Object.assign({name:`${s} ${h(i," ")}`,route:r,tag:s},t)})}))})}upload(e,t){t.path||(t.path=De.API_UPLOAD_TEMP),t.size||(t.size=De.API_UPLOAD_SIZE),t.field||(t.field=De.API_UPLOAD_FIELD),F.middleware(e,t)}validation(e,t){return xe(this,void 0,void 0,function*(){const{error:i,value:r}=yield v.object(t).parse().validateAsync(e.req.body);if(i)return e.validation(i);e.req.body=r,e.next()})}}yt=Ne.PERMISSIONS,be([we(0,T()),we(1,D(De.API_KEY_HEADER)),we(2,D(De.API_TOKEN_HEADER)),we(3,N(De.API_KEY_HEADER)),we(4,D("user-agent")),we(5,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String,String,String,lt]),Ce("design:returntype",Promise)],vt.prototype,"auth",null),be([we(0,T()),we(1,C()),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],vt.prototype,"canCreate",null),be([we(0,T()),we(1,C()),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],vt.prototype,"canDelete",null),be([we(0,T()),we(1,C()),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],vt.prototype,"canRead",null),be([we(0,T()),we(1,C()),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],vt.prototype,"canUpdate",null),be([we(0,T()),we(1,C()),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],vt.prototype,"permission",null),be([we(0,T()),we(1,D("user-agent")),we(2,x()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,Object]),Ce("design:returntype",Promise)],vt.prototype,"session",null),be([we(0,T()),we(1,C()),Ce("design:type",Function),Ce("design:paramtypes",[w,Object]),Ce("design:returntype",void 0)],vt.prototype,"upload",null),be([we(0,T()),we(1,C()),Ce("design:type",Function),Ce("design:paramtypes",[w,Object]),Ce("design:returntype",Promise)],vt.prototype,"validation",null);let _t=class extends vt{constructor(){super(...arguments),this[gt]=[],this[ht]=["create","read","update","delete"]}attributes(e){if(0==this[vt.ATTRIBUTES].length&&(this[vt.ATTRIBUTES]=Object.keys(this.model().getAttributes())),_(e))return e.length?e.map(e=>m(e)&&-1!=this[vt.ATTRIBUTES].indexOf(e)?e:void 0).filter(m):this[vt.ATTRIBUTES];const{exclude:t,include:i}=e,r=E(i)?this[vt.ATTRIBUTES]:i.map(e=>m(e)&&-1!=this[vt.ATTRIBUTES].indexOf(e)?e:void 0).filter(m),s=null!=t?t:[];return s.length?r.filter(e=>-1==s.indexOf(e)?e:void 0).filter(m):r}create(e){return xe(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||{}),Fe(e))).catch(this.error);if(r){const t=this.key();return e.prepare(k.OK,{[t]:r.getDataValue(t)}),r}e.error("INTERNAL SERVER ERROR")})}delete(e){return xe(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 s=yield this.model().destroy(Object.assign(Object.assign(Object.assign({},t||{}),{where:Object.assign(Object.assign({},(t||{}).where),{[i]:r}),individualHooks:!0}),Fe(e))).catch(this.error);return s?(e.success("OK"),s):(e.notFound("RECORD NOT FOUND"),0)})}error(e){let t="controller_model";De.API_BASE_NAME&&(t=`${De.API_BASE_NAME}.${t}`),(null==e?void 0:e.sql)?it.error((null==e?void 0:e.message)+"\n"+(null==e?void 0:e.sql),t,De.API_CONSOLE_ERROR):super.error(e)}findAll(e){return xe(this,arguments,void 0,function*({ctx:e,options:t,callback:i,scope:r,advanced:s,attributes:n,limited:o}){var d,a,u;const p=this.scope(r),c=Object.assign({},t||{}),{fields:l,limit:y,offset:g,asc:h,desc:v,search:_,where:I}=e.req.query;if(E(c.limit)){let e=De.API_MODEL_LIMIT;m(y)&&(e=parseInt(y)||0),e=A(e,-1,De.API_MODEL_LIMIT_MAX),c.limit=e>0?e:o?De.API_MODEL_LIMIT:void 0}if(O(c.limit)&&(c.limit=c.limit>0?c.limit:void 0),m(g)){const e=parseInt(g)||0;c.offset=e>0?e:void 0}n=null!=n?n:this.attributes(null!==(d=null==c?void 0:c.attributes)&&void 0!==d?d:[]);const f=e=>n.indexOf(e)>=0,P=[];m(l)&&P.push(...l.split(";").filter(f)),P.length&&(c.attributes=P);const R=[];if(m(h)&&h.length&&R.push(...h.split(";").filter(f).map(e=>[e,"ASC"])),m(v)&&v.length&&R.push(...v.split(";").filter(f).map(e=>[e,"DESC"])),R.length&&(c.order=R),c.where=Object.assign({},c.where||{}),m(I)&&(null==s||s)){const t=he.parse(n,I);if(!E(t.error))return e.validation(t.error.join(", ")),{count:0,records:[]};c.where=Object.assign(Object.assign({},c.where),null!==(a=t.value)&&void 0!==a?a:{})}else{const e=[];n.forEach(t=>{m(_)&&_.length&&e.push({[t]:{[Se.like]:`%${_}%`}})}),e.length&&(c.where=Object.assign(Object.assign({},c.where),{[Se.or]:[...e]}))}const S=p.count(Object.assign(Object.assign({},c),{distinct:!!c.include,col:this[vt.ATTRIBUTES].length?this[vt.ATTRIBUTES][0]:void 0})).catch(this.error),T=p.findAll(c).catch(this.error);yield Promise.allSettled([S,T]);const D=null!==(u=yield S)&&void 0!==u?u:0;let N=yield T;const b={count:D};return N?(N=i?yield i(N):N,(O(null==t?void 0:t.limit)||0==D)&&(b.count=N.length),e.prepare(k.OK,Object.assign(Object.assign({},b),{records:N})),Object.assign(Object.assign({},b),{records:N})):(e.error("INTERNAL SERVER ERROR"),Object.assign(Object.assign({},b),{records:[]}))})}findOne(e){return xe(this,arguments,void 0,function*({ctx:e,options:t,callback:i,scope:r}){const s=this.key(),{[s]:n}=e.req.params,o=yield this.scope(r).findOne(Object.assign(Object.assign({},t||{}),{where:Object.assign(Object.assign({},(t||{}).where),{[s]:n})})).catch(this.error);return o?(e.prepare(k.OK,i?yield i(o):o.toJSON()),o):null===o?e.notFound("RECORD NOT FOUND"):void e.error("INTERNAL SERVER ERROR")})}sync(){return xe(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield l(this[vt.PERMISSIONS],i=>xe(this,void 0,void 0,function*(){const r=`${e}.${i}`,s=h(e.replace(/_/g," ")," ");yield Qe.findOrCreate({where:{route:r},defaults:Object.assign({name:`${s} ${h(i," ")}`,route:r,tag:s},t)})}))})}update(e){return xe(this,arguments,void 0,function*({ctx:e,options:t,body:i}){var r;const s=this.key(),{[s]:n}=e.req.params,[o]=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),{[s]:n}),individualHooks:!0}),Fe(e))).catch(this.error))&&void 0!==r?r:[];return o?(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()}};gt=vt.ATTRIBUTES,ht=vt.PERMISSIONS,_t=be([j(vt)],_t);let mt=class extends _t{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 xe(this,void 0,void 0,function*(){yield this.create(this.CrudArgumentsCreate(e))})}all(e){return xe(this,void 0,void 0,function*(){yield this.findAll(this.CrudArgumentsFindAll(e))})}del(e){return xe(this,void 0,void 0,function*(){yield this.delete(this.CrudArgumentsDelete(e))})}get(e){return xe(this,void 0,void 0,function*(){yield this.findOne(this.CrudArgumentsFindOne(e))})}set(e){return xe(this,void 0,void 0,function*(){yield this.update(this.CrudArgumentsUpdate(e))})}validationCreate(e){return xe(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 xe(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)})}};be([L(),U("auth"),U("canCreate"),U("validationCreate"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"add",null),be([B(),U("auth"),U("canRead"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"all",null),be([M("/:id"),U("auth"),U("canDelete"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"del",null),be([B("/:id"),U("auth"),U("canRead"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"get",null),be([H("/:id"),U("auth"),U("canUpdate"),U("validationUpdate"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"set",null),be([we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"validationCreate",null),be([we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],mt.prototype,"validationUpdate",null),mt=be([j(_t)],mt);let Et=class extends _t{model(){return Je}all(e,t,i){return xe(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 xe(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}};be([B(),U("auth"),U("canRead"),we(0,T()),we(1,N("type")),we(2,N("table")),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String]),Ce("design:returntype",Promise)],Et.prototype,"all",null),be([B("/:id"),U("auth"),U("canRead"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],Et.prototype,"get",null),Et=be([K("/audits"),j(_t)],Et);let At=class extends vt{login(e,t,i,r,s){return xe(this,void 0,void 0,function*(){var o;yield g(De.API_SLEEP_AUTH);const d=yield ze.scope("password").findOne({where:{[Se.or]:[{email:i},{username:i}]}}).catch(this.error);if(r+=null!==(o=null==d?void 0:d.salt)&&void 0!==o?o:"",!d||d.password!=n(r))return e.notFound("INVALID USERNAME OR PASSWORD"),s.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e});const a=yield Ve.findOne({where:{state:!0,user_id:d.id}}).catch(this.error);if(a)return e.error("ACTIVATION REQUIRED"),s.emit("auth.activation",{ctx:e,register:a,user:d}),void this.emit("auth.activation",{ctx:e,register:a,user:d});if(!d.state)return e.notFound("INVALID USERNAME OR PASSWORD"),s.emit("auth.failure",{ctx:e,user:d}),void this.emit("auth.failure",{ctx:e,user:d});const{auth:u,error:p,token:c}=yield pt.create(d);return p?(e.error(p),s.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e})):u&&c?(u.user_agent=t,yield u.save().catch(this.error),e.json({token:c}),s.emit("auth.login",{auth:u,ctx:e,user:d}),void this.emit("auth.login",{auth:u,ctx:e,user:d})):(e.error("INTERNAL SERVER ERROR"),s.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e}))})}logout(e,t,i,r){return xe(this,void 0,void 0,function*(){if(yield pt.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 xe(this,void 0,void 0,function*(){const{auth:s,error:n,token:o}=yield pt.renew(i);return n?e.error(n):s?(s.user_agent=t,yield s.save().catch(this.error),e.json({token:o}),r.emit("auth.renew",{auth:s,ctx:e}),void this.emit("auth.renew",{auth:s,ctx:e})):e.error("INTERNAL SERVER ERROR")})}user(e,t){return xe(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({},I(["username","date","description","state","created_at","updated_at","deleted_at"],t.toJSON())),{permissions:i.map(e=>e.route)}))})}};var Ot;be([L("/login"),U("validation",{username:v.string().min(3).required(),password:v.string().min(5).required()}),we(0,T()),we(1,D("user-agent")),we(2,q("username")),we(3,q("password")),we(4,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String,String,lt]),Ce("design:returntype",Promise)],At.prototype,"login",null),be([B("/logout"),U("auth"),we(0,T()),we(1,ke()),we(2,Le()),we(3,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,Ye,ze,lt]),Ce("design:returntype",Promise)],At.prototype,"logout",null),be([L("/renew"),U("validation",{token:v.string().required()}),we(0,T()),we(1,D("user-agent")),we(2,q("token")),we(3,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String,lt]),Ce("design:returntype",Promise)],At.prototype,"renew",null),be([B(),U("auth"),we(0,T()),we(1,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,ze]),Ce("design:returntype",Promise)],At.prototype,"user",null),At=be([K("/auth"),j(vt)],At);let It=class extends vt{constructor(){super(...arguments),this[Ot]=["delete","download","edit","list","read","rename","upload","write"]}directory(){return De.API_HTTP_PUBLIC||"./"}files(e){return xe(this,void 0,void 0,function*(){let{path:t}=e.req;t=t.replace(/(^\/path(\/)?)|([\\.]{1,2}\/)/g,"");const i=Te(this.directory(),t);if(!me(i)||!Ee(i).isDirectory())return e.notFound("RECORD NOT FOUND");let r=[];return r=Ae(i),r=r.map(e=>this.info(Te(i,e))),r=r.filter(f),Object.assign(Object.assign({},this.info(i)),{files:r})})}access(e,t,i){return xe(this,void 0,void 0,function*(){yield this.permission(e,this.name()+"."+t,i)})}info(e){if(!me(e))return null;const t=Ee(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 xe(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t=h(e.replace(/_/g," ")," "),i={description:"",state:!0};yield l(this[vt.PERMISSIONS],r=>xe(this,void 0,void 0,function*(){const s=`${e}.${r}`;yield Qe.findOrCreate({where:{route:s},defaults:Object.assign({name:`${t} ${h(r," ")}`,route:s,tag:t},i)})}))})}};Ot=vt.PERMISSIONS,be([B("/path"),B("/path/*path"),U("auth"),U("access","list"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],It.prototype,"files",null),be([we(0,T()),we(1,C()),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],It.prototype,"access",null),It=be([K("/files"),j(vt)],It);let ft=class extends vt{check(e,t){return xe(this,void 0,void 0,function*(){const i=yield this.find(t);if(!i||!i.user)return e.notFound("RECORD NOT FOUND");i.token=P(),yield i.save(),e.json({token:i.token})})}forgot(e,t,i){return xe(this,void 0,void 0,function*(){yield g(De.API_SLEEP_FORGOT);const r=t,s=yield ze.findOne({where:{[Se.or]:[{email:r},{username:t}]}}).catch(this.error);if(!s)return e.notFound("RECORD NOT FOUND");const n=P(),o=Date.now()+6e4*De.API_TOKEN_FORGOT,d=yield Xe.create({token:n,timestamp:o,state:!0,user_id:s.id});e.success("OK"),i.emit("forgot.send",{ctx:e,forgot:d,user:s}),this.emit("forgot.send",{ctx:e,forgot:d,user:s})})}reset(e,t,i,r){return xe(this,void 0,void 0,function*(){const s=yield this.find(t);if(!s)return e.notFound("RECORD NOT FOUND");s.state=!1,yield s.save().catch(this.error),s.user.password=n(i),yield s.user.save().catch(this.error),e.success("OK"),r.emit("forgot.reset",{ctx:e,user:s.user}),this.emit("forgot.reset",{ctx:e,user:s.user})})}find(e){return xe(this,void 0,void 0,function*(){return yield Xe.findOne({where:{token:e,state:!0},include:[{model:ze,required:!0}]}).catch(this.error)})}};be([B("/check"),U("validation",{token:v.string().required()}),we(0,T()),we(1,q("token")),Ce("design:type",Function),Ce("design:paramtypes",[w,String]),Ce("design:returntype",Promise)],ft.prototype,"check",null),be([L(),U("validation",{username:v.string().min(4).required()}),we(0,T()),we(1,q("username")),we(2,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,lt]),Ce("design:returntype",Promise)],ft.prototype,"forgot",null),be([L("/reset"),U("validation",{token:v.string().required(),password:v.string().min(5).required()}),we(0,T()),we(1,q("token")),we(2,q("password")),we(3,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String,lt]),Ce("design:returntype",Promise)],ft.prototype,"reset",null),ft=be([K("/forgot"),j(vt)],ft);let Pt=class extends mt{constructor(){super(...arguments),this.schemaCreate={name:v.string().required(),description:v.string().empty(""),state:v.boolean().parse().required()},this.schemaUpdate={name:v.string().empty(),description:v.string().empty(),state:v.boolean().parse().empty()}}model(){return $e}CrudArgumentsFindAll(e){return{ctx:e}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};Pt=be([K("/groups"),j(mt)],Pt);let Rt=class extends _t{model(){return et}all(e,t){return xe(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{group_id:t},include:[{model:Qe,required:!0}]},callback:e=>e.map(e=>e.permission)})})}me(e,t){return xe(this,void 0,void 0,function*(){yield this.all(e,t.id.toString())})}set(e,t,i,r){return xe(this,void 0,void 0,function*(){const s=yield $e.findByPk(t,{attributes:["id"]}).catch(this.error);if(!s)return e.notFound("RECORD NOT FOUND");const n=s.id;if(yield et.destroy(Object.assign({where:{group_id:n},individualHooks:!0},r)),i){let e=0;yield g(1e3);for(let t=0;t<i.length;t++)e=yield Qe.count({where:{id:i[t]}}),e&&(yield et.create({group_id:n,permission_id:i[t]},Object.assign({},r)))}e.success("OK")})}};var St;be([B("/:id/permissions"),U("auth"),U("canRead","groups"),we(0,T()),we(1,Y("id")),Ce("design:type",Function),Ce("design:paramtypes",[w,String]),Ce("design:returntype",Promise)],Rt.prototype,"all",null),be([B("/permissions"),U("auth"),U("canRead","users"),we(0,T()),we(1,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,ze]),Ce("design:returntype",Promise)],Rt.prototype,"me",null),be([H("/:id/permissions"),U("auth"),U("canUpdate","groups"),U("validation",{permissions:v.array(v.number().parse())}),we(0,T()),we(1,Y("id")),we(2,q("permissions")),we(3,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,Array,Object]),Ce("design:returntype",Promise)],Rt.prototype,"set",null),Rt=be([K("/groups"),j(_t)],Rt);let Tt=class extends _t{constructor(){super(...arguments),this[St]=["read"]}model(){return it}all(e,t,i){return xe(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})})}};St=_t.PERMISSIONS,be([B(),U("auth"),U("canRead"),we(0,T()),we(1,N("type")),we(2,N("source")),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String]),Ce("design:returntype",Promise)],Tt.prototype,"all",null),Tt=be([K("/logs"),j(_t)],Tt);let Dt=class extends mt{constructor(){super(...arguments),this.schemaCreate={name:v.string().required(),route:v.string().required(),tag:v.string().required(),description:v.string().empty(""),state:v.boolean().parse().required()},this.schemaUpdate={name:v.string().empty(),route:v.string().empty(),tag:v.string().empty(),description:v.string().empty(),state:v.boolean().parse().empty()}}model(){return Qe}CrudArgumentsFindAll(e){return{ctx:e}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};Dt=be([K("/permissions"),j(mt)],Dt);let Nt=class extends vt{register(e,t,i){return xe(this,void 0,void 0,function*(){yield g(De.API_SLEEP_REGISTRY);const{name:r,date:s,email:o,username:d,password:a,confirm:u}=t,p=d||o,c=n(a);if(yield ze.count({where:{[Se.or]:[{email:o},{username:p}]}}).catch(this.error))return e.validation("INVALID EMAIL OR USERNAME");if(c!=n(u))return e.error("INVALID PASSWORD");const l=yield ze.create({name:r,email:o,username:p,password:c,avatar:"",date:s,description:"",state:!1}).catch(this.error);if(!l)return e.error("INTERNAL SERVER ERROR");const y=yield Ve.create({token:yield this.getId(),user_id:l.id,state:!0}).catch(this.error);if(!y)return yield l.destroy().catch(this.error),e.error("INTERNAL SERVER ERROR");e.success("OK"),i.emit("register.user",{ctx:e,register:y,user:l}),this.emit("register.user",{ctx:e,register:y,user:l})})}confirm(e,t,i){return xe(this,void 0,void 0,function*(){const r=yield Ve.findOne({where:{token:t,state:!0},include:[{model:ze,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 xe(this,void 0,void 0,function*(){const r=t,s=yield Ve.findOne({where:{state:!0},include:[{model:ze,required:!0,where:{[Se.or]:[{email:r},{username:t}]}}]}).catch(this.error);if(!s)return e.notFound("RECORD NOT FOUND");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 xe(this,void 0,void 0,function*(){const e=p();return(yield Ve.count({where:{token:e}}))?this.getId():e})}};be([L(),U("validation",{name:v.string().required(),date:v.date().required(),email:v.string().email().required(),username:v.string().min(4).empty(),password:v.string().min(5).required(),confirm:v.string().min(5).required()}),we(0,T()),we(1,q()),we(2,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,Object,lt]),Ce("design:returntype",Promise)],Nt.prototype,"register",null),be([L("/confirm"),U("validation",{token:v.string().required()}),we(0,T()),we(1,q("token")),we(2,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,lt]),Ce("design:returntype",Promise)],Nt.prototype,"confirm",null),be([L("/send"),U("validation",{username:v.string().min(4).required()}),we(0,T()),we(1,q("username")),we(2,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,lt]),Ce("design:returntype",Promise)],Nt.prototype,"send",null),Nt=be([K("/register"),j(vt)],Nt);let bt=class extends vt{setup(e,t){return xe(this,void 0,void 0,function*(){var i;if(yield ze.count())return e.success("OK");const r=P(),s=yield ze.create({name:"Admin",email:"admin@localhost",username:"admin",password:n("admin"+r),salt:r,token:"",avatar:"",date:new Date,description:"DEFAULT",state:!0},Object.assign({},t)),o=yield $e.create(Object.assign({name:"Admin"},{description:"API CORE",state:!0}),Object.assign({},t));yield Ge.create({user_id:s.id,group_id:o.id},Object.assign({},t));const d=null!==(i=yield Qe.findAll({where:{state:!0}}).catch(this.error))&&void 0!==i?i:[];yield l(d,e=>xe(this,void 0,void 0,function*(){yield et.create({group_id:o.id,permission_id:e.id},Object.assign({},t))})),e.success("OK")})}};be([B(),we(0,T()),we(1,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,Object]),Ce("design:returntype",Promise)],bt.prototype,"setup",null),bt=be([K("/setup"),j(vt)],bt);let wt=class extends _t{model(){return ze}constructor(){super(),this.path=De.API_HTTP_PUBLIC+"/avatar",De.API_HTTP_PUBLIC&&me(De.API_HTTP_PUBLIC)&&!me(this.path)&&Oe(this.path)}avatar(e,t,i,r){return xe(this,void 0,void 0,function*(){if(t.length){const s=t[0].filename||"";if(s){const t=this.path+"/"+i.avatar;if(me(t)&&Ie(t).isFile()&&fe(t),i.avatar=s,yield i.save(Object.assign({},r)).catch(this.error))return e.success("OK")}}e.success("RECORD NOT CHANGED")})}avatar_del(e,t,i){return xe(this,void 0,void 0,function*(){const r=this.path+"/"+t.avatar;t.avatar="",(yield t.save(Object.assign({},i)).catch(this.error))&&me(r)&&fe(r),e.success("OK")})}password(e,t,i,r,s){return xe(this,void 0,void 0,function*(){var o;if(De.API_USER_HISTORY){if(yield We.count({where:{password:n(i+r.id)}}).catch(this.error))return e.error("PASSWORD PREVIOUSLY REGISTERED")}const d=yield this.scope("password").findOne({where:{id:r.id,state:!0}}).catch(this.error);return t+=null!==(o=null==d?void 0:d.salt)&&void 0!==o?o:"",d&&d.password==n(t)?(d.salt=P(),d.password=n(i+d.salt),(yield d.save(Object.assign({},s)).catch(this.error))?e.success("OK"):void e.success("RECORD NOT CHANGED")):e.error("INVALID PASSWORD")})}token(e,t,i){return xe(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 xe(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 xe(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 xe(this,void 0,void 0,function*(){const s=yield this.model().findOne({attributes:["id","token"],where:{id:t}}).catch(this.error);if(s){const t=yield this.token_new();return s.token=r.hash.encrypt(t),yield s.save(Object.assign({},i)).catch(this.error),e.json({token:t})}e.notFound("RECORD NOT FOUND")})}token_new(){return xe(this,void 0,void 0,function*(){var e;const t=p();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 xe(this,void 0,void 0,function*(){const i=P(),r=yield this.create({ctx:e,body:{password:n(t+i),salt:i}});De.API_USER_HISTORY&&r&&(yield We.create({password:n(t+r.id),user_id:r.id}))})}all(e){return xe(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{attributes:{exclude:["password","salt","token"]}}})})}del(e,t,i){return xe(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 xe(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}set(e,t,i){return xe(this,void 0,void 0,function*(){if(De.API_USER_HISTORY&&i){const r=n(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?P():"";yield this.update({ctx:e,body:i?{password:n(i+r),salt:r}:{}})})}};be([L("/avatar"),U("auth"),U("upload",e=>({count:1,field:"file",path:e.controller.path,types:["image/bmp","image/jpeg","image/png"],size:32})),we(0,T()),we(1,V()),we(2,Le()),we(3,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,Array,ze,Object]),Ce("design:returntype",Promise)],wt.prototype,"avatar",null),be([M("/avatar"),U("auth"),we(0,T()),we(1,Le()),we(2,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,ze,Object]),Ce("design:returntype",Promise)],wt.prototype,"avatar_del",null),be([L("/password"),U("auth"),U("validation",{oldPassword:v.string().min(5).required(),newPassword:v.string().min(5).required(),confirmPassword:v.string().equal(v.ref("newPassword"))}),we(0,T()),we(1,q("oldPassword")),we(2,q("newPassword")),we(3,Le()),we(4,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String,ze,Object]),Ce("design:returntype",Promise)],wt.prototype,"password",null),be([B("/token"),U("auth"),we(0,T()),we(1,Le()),we(2,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,ze,lt]),Ce("design:returntype",Promise)],wt.prototype,"token",null),be([M("/token/:id"),U("auth"),U("canDelete"),we(0,T()),we(1,Y("id")),we(2,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,Object]),Ce("design:returntype",Promise)],wt.prototype,"token_del",null),be([B("/token/:id"),U("auth"),U("canCreate"),we(0,T()),we(1,Y("id")),we(2,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,lt]),Ce("design:returntype",Promise)],wt.prototype,"token_get",null),be([B("/token/renew/:id"),U("auth"),U("canUpdate"),we(0,T()),we(1,Y("id")),we(2,je()),we(3,b()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,Object,lt]),Ce("design:returntype",Promise)],wt.prototype,"token_renew",null),be([L(),U("auth"),U("canCreate"),U("validation",{name:v.string().required(),email:v.string().email().required(),username:v.string().min(4).required(),password:v.string().min(5).required(),description:v.string().empty(""),state:v.boolean().parse().required()}),we(0,T()),we(1,q("password")),Ce("design:type",Function),Ce("design:paramtypes",[w,String]),Ce("design:returntype",Promise)],wt.prototype,"add",null),be([B(),U("auth"),U("canRead"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],wt.prototype,"all",null),be([M("/:id"),U("auth"),U("canDelete"),we(0,T()),we(1,Y("id")),we(2,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,ze]),Ce("design:returntype",Promise)],wt.prototype,"del",null),be([B("/:id"),U("auth"),U("canRead"),we(0,T()),Ce("design:type",Function),Ce("design:paramtypes",[w]),Ce("design:returntype",Promise)],wt.prototype,"get",null),be([H("/:id"),U("auth"),U("canUpdate"),U("validation",{name:v.string().empty(),email:v.string().email().empty(),username:v.string().min(4).empty(),password:v.string().min(5).empty().filter(""),description:v.string().empty(),state:v.boolean().parse().empty()}),we(0,T()),we(1,Y("id")),we(2,q("password")),Ce("design:type",Function),Ce("design:paramtypes",[w,String,String]),Ce("design:returntype",Promise)],wt.prototype,"set",null),wt=be([K("/users"),j(_t),Ce("design:paramtypes",[])],wt);let Ct=class extends _t{model(){return Ge}all(e,t){return xe(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{user_id:t},include:[{model:$e,required:!0}]},callback:e=>e.map(e=>e.group)})})}me(e,t){return xe(this,void 0,void 0,function*(){yield this.all(e,t.id.toString())})}set(e,t,i,r){return xe(this,void 0,void 0,function*(){const s=yield ze.findByPk(t,{attributes:["id"]}).catch(this.error);if(!s)return e.notFound("RECORD NOT FOUND");if(yield Ge.destroy(Object.assign({where:{user_id:s.id},individualHooks:!0},r)),i){let e=0;yield g(1e3);for(let t=0;t<i.length;t++)e=yield $e.count({where:{id:i[t]}}),e&&(yield Ge.create({user_id:s.id,group_id:i[t]},Object.assign({},r)))}e.success("OK")})}};be([B("/:id/groups"),U("auth"),U("canRead","users"),we(0,T()),we(1,Y("id")),Ce("design:type",Function),Ce("design:paramtypes",[w,String]),Ce("design:returntype",Promise)],Ct.prototype,"all",null),be([B("/groups"),U("auth"),U("canRead","users"),we(0,T()),we(1,Le()),Ce("design:type",Function),Ce("design:paramtypes",[w,ze]),Ce("design:returntype",Promise)],Ct.prototype,"me",null),be([H("/:id/groups"),U("auth"),U("canUpdate","users"),U("validation",{groups:v.array(v.number().parse())}),we(0,T()),we(1,Y("id")),we(2,q("groups")),we(3,je()),Ce("design:type",Function),Ce("design:paramtypes",[w,String,Array,Object]),Ce("design:returntype",Promise)],Ct.prototype,"set",null),Ct=be([K("/users"),j(_t)],Ct);export{lt as Application,Je as Audit,Et as AuditsController,Ye as Auth,nt as AuthBase,At as AuthController,ot as AuthKey,pt as AuthToken,Ze as Config,Ne as Controller,vt as ControllerBase,mt as ControllerCrud,_t as ControllerModel,De as Env,It as FilesController,Xe as Forgot,ft as ForgotController,$e as Group,et as GroupPermission,Pt as GroupsController,Rt as GroupsPermissionsController,it as Log,Tt as LogsController,Be as Metadata,Ue as Migrate,rt as Migration,Me as Model,Qe as Permission,Dt as PermissionsController,Ve as Register,Nt as RegisterController,je as ReqAudit,ke as ReqAuth,Le as ReqUser,st as Session,bt as SetupController,ct as Store,ze as User,Ge as UserGroup,We as UserHistory,wt as UsersController,Ct as UsersGroupsController,Fe as audit,at as crt,He as database,qe as hooks,ut as key};
|
|
7
|
+
import{EventEmitter as e,isObject as t,noop as i,uuidv7 as r,loop as n,forEachSeries as s,isFunction as o,sleep as d,upperCamelCase as a,Validation as u,isArray as p,isString as l,isUndefined as c,clamp as g,isNumber as y,denied as h,isDef as v,uniqueID as _}from"@andrewcaires/utils.js";import{parameterFactory as m,Application as A,Ctx as E,Headers as O,Query as S,App as f,Context as I,Argument as P,Session as R,Upload as T,Extends as D,Status as N,Post as b,Middleware as w,Get as C,Delete as x,Put as F,Controller as j,Body as U,Params as k,Files as L}from"@andrewcaires/express";import{Env as B,LogColor as K,Log as M,Hash as H,sha256 as q}from"@andrewcaires/node";import{config as Y}from"dotenv";import{Sequelize as V,Column as $,BelongsTo as G,Database as W,ModelName as z,Version as J,Model as Z,HasMany as X,Hooks as Q,DefaultScope as ee,Scopes as te,Unique as ie,Op as re,Where as ne}from"@andrewcaires/sequelize";import se from"jsonwebtoken";import{readFileSync as oe,existsSync as de,statSync as ae,readdirSync as ue,mkdirSync as pe,lstatSync as le,rmSync as ce}from"fs";import{WebSocketServer as ge}from"ws";import{Store as ye}from"express-session";import{join as he}from"path";class ve extends e{}function _e(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 me(e,t){return function(i,r){t(i,r,e)}}function Ae(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}function Ee(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())})}ve.ATTRIBUTES=Symbol("ATTRIBUTES"),ve.PERMISSIONS=Symbol("PERMISSIONS"),"function"==typeof SuppressedError&&SuppressedError,Y({quiet:!0});class Oe extends B{}Oe.API_BASE_NAME=Oe.getString("API_BASE_NAME",""),Oe.API_BODYPARSER_STRICT=Oe.getBool("API_BODYPARSER_STRICT",!0),Oe.API_BODYPARSER_INFLATE=Oe.getBool("API_BODYPARSER_INFLATE",!0),Oe.API_BODYPARSER_LIMIT=Oe.getString("API_BODYPARSER_LIMIT","10mb"),Oe.API_BODYPARSER_TYPE=Oe.getString("API_BODYPARSER_TYPE","json"),Oe.API_CONSOLE_ERROR=Oe.getBool("API_CONSOLE_ERROR",!1),Oe.API_DATABASE_URL=Oe.getString("API_DATABASE_URL",""),Oe.API_DATABASE_LOG=Oe.getBool("API_DATABASE_LOG",!1),Oe.API_DATABASE_AUDIT=Oe.getBool("API_DATABASE_AUDIT",!0),Oe.API_DATABASE_PREFIX=Oe.getString("API_DATABASE_PREFIX",""),Oe.API_DATABASE_TIMEZONE=Oe.getString("API_DATABASE_TIMEZONE","+00:00"),Oe.API_HTTP_CRT=Oe.getString("API_HTTP_CRT",""),Oe.API_HTTP_KEY=Oe.getString("API_HTTP_KEY",""),Oe.API_HTTP_PORT=Oe.getInt("API_HTTP_PORT",3e3),Oe.API_HTTP_PUBLIC=Oe.getString("API_HTTP_PUBLIC",""),Oe.API_HTTP_CROSS=Oe.getBool("API_HTTP_CROSS",!1),Oe.API_HTTP_HYBRID=Oe.getBool("API_HTTP_HYBRID",!1),Oe.API_HTTP_NOTFOUND=Oe.getString("API_HTTP_NOTFOUND",""),Oe.API_HTTP_PATH=Oe.getString("API_HTTP_PATH","/api"),Oe.API_HTTP_REDIRECT=Oe.getString("API_HTTP_REDIRECT",""),Oe.API_KEY_HASH=Oe.getString("API_KEY_HASH",""),Oe.API_KEY_HEADER=Oe.getString("API_KEY_HEADER","x-api-key"),Oe.API_MODEL_LIMIT=Oe.getInt("API_MODEL_LIMIT",10),Oe.API_MODEL_LIMIT_MAX=Oe.getInt("API_MODEL_LIMIT_MAX",500),Oe.API_SLEEP_AUTH=Oe.getMs("API_SLEEP_AUTH","2s"),Oe.API_SLEEP_FORGOT=Oe.getMs("API_SLEEP_FORGOT","5s"),Oe.API_SLEEP_REGISTRY=Oe.getMs("API_SLEEP_REGISTRY","5s"),Oe.API_SESSION_NAME=Oe.getString("API_SESSION_NAME","session.id"),Oe.API_SESSION_LIFETIME=Oe.getMs("API_SESSION_LIFETIME","1d"),Oe.API_SESSION_SECRET=Oe.getString("API_SESSION_SECRET","yoursecret"),Oe.API_TOKEN_CRT=Oe.getString("API_TOKEN_CRT",""),Oe.API_TOKEN_KEY=Oe.getString("API_TOKEN_KEY",""),Oe.API_TOKEN_FORGOT=Oe.getMs("API_TOKEN_LIFETIME","1d"),Oe.API_TOKEN_HEADER=Oe.getString("API_TOKEN_HEADER","authorization"),Oe.API_TOKEN_HEADER_KEY=Oe.getString("API_TOKEN_HEADER","bearer"),Oe.API_TOKEN_LIFETIME=Oe.getMs("API_TOKEN_LIFETIME","1d"),Oe.API_TOKEN_RENEW=Oe.getMs("API_TOKEN_RENEW","1d"),Oe.API_UPLOAD_COUNT=Oe.getInt("API_UPLOAD_COUNT",1),Oe.API_UPLOAD_FIELD=Oe.getString("API_UPLOAD_FIELD","upload"),Oe.API_UPLOAD_SIZE=Oe.getInt("API_UPLOAD_SIZE",2),Oe.API_UPLOAD_TEMP=Oe.getString("API_UPLOAD_TEMP","./temp"),Oe.API_USER_HISTORY=Oe.getBool("API_USER_HISTORY",!0),Oe.API_WEBSOCKET_START=Oe.getBool("API_WEBSOCKET_START",!1);const Se=e=>{var t,i,r,n,s,o,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!==(o=null===(s=e.req)||void 0===s?void 0:s.headers["user-agent"])&&void 0!==o?o:"",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}},fe=m(({ctx:e})=>Se(e)),Ie=m(({ctx:e})=>e.req.auth),Pe=m(({ctx:e})=>e.req.user),Re=new V(Oe.API_DATABASE_URL,{logging:Oe.API_DATABASE_LOG,prefix:Oe.API_DATABASE_PREFIX,timezone:Oe.API_DATABASE_TIMEZONE}),Te=(e,t,i)=>{var r,n,s,o,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!==(s=null==i?void 0:i.audit_href)&&void 0!==s?s:null,user_agent:null!==(o=null==i?void 0:i.audit_user_agent)&&void 0!==o?o:null,user_id:null!==(d=null==i?void 0:i.audit_user_id)&&void 0!==d?d:null,state:!0}},De={afterCreate:(e,r)=>Ee(void 0,void 0,void 0,function*(){var n;if(!Oe.API_DATABASE_AUDIT)return;const s=t(e)?e.constructor:null,o=null!==(n=null==s?void 0:s.primaryKeyAttribute)&&void 0!==n?n:null;yield je.create(Object.assign(Object.assign({},Te("CREATE",s,r)),{record:o?e.getDataValue(o):null,data:e.toJSON()})).catch(i)}),afterUpdate:(e,r)=>Ee(void 0,void 0,void 0,function*(){var n;if(!Oe.API_DATABASE_AUDIT)return;const s=t(e)?e.constructor:null,o=null!==(n=null==s?void 0:s.primaryKeyAttribute)&&void 0!==n?n:null,d={},a=e.changed();a&&a.forEach(t=>d[t]=e.getDataValue(t)),yield je.create(Object.assign(Object.assign({},Te("UPDATE",s,r)),{record:o?e.getDataValue(o):null,data:d,previously:e.previous()})).catch(i)}),afterDestroy:(e,r)=>Ee(void 0,void 0,void 0,function*(){var n;if(!Oe.API_DATABASE_AUDIT)return;const s=t(e)?e.constructor:null,o=null!==(n=null==s?void 0:s.primaryKeyAttribute)&&void 0!==n?n:null;yield je.create(Object.assign(Object.assign({},Te("DELETE",s,r)),{record:o?e.getDataValue(o):null,data:e.toJSON()})).catch(i)})};let Ne=class extends Z{};_e([$.Id(),Ae("design:type",Number)],Ne.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],Ne.prototype,"secret",void 0),_e([$.FullDate(),Ae("design:type",Object)],Ne.prototype,"logout",void 0),_e([$.String(),Ae("design:type",String)],Ne.prototype,"user_agent",void 0),_e([$.CreatedAt,Ae("design:type",Date)],Ne.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],Ne.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],Ne.prototype,"deleted_at",void 0),_e([G(()=>Fe),Ae("design:type",Number)],Ne.prototype,"user_id",void 0),Ne=_e([W(Re),z("auth"),J("4.2.0")],Ne);let be=class extends Z{};_e([$.Id(),Ae("design:type",Number)],be.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],be.prototype,"token",void 0),_e([$.Boolean(),Ae("design:type",Boolean)],be.prototype,"state",void 0),_e([$.CreatedAt,Ae("design:type",Date)],be.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],be.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],be.prototype,"deleted_at",void 0),_e([G(()=>Fe),Ae("design:type",Number)],be.prototype,"user_id",void 0),be=_e([W(Re),z("register"),J("4.2.0")],be);let we=class extends Z{};_e([$.Id(),Ae("design:type",Number)],we.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],we.prototype,"name",void 0),_e([$.Text(),Ae("design:type",String)],we.prototype,"description",void 0),_e([$.Boolean(),Ae("design:type",Boolean)],we.prototype,"state",void 0),_e([$.CreatedAt,Ae("design:type",Date)],we.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],we.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],we.prototype,"deleted_at",void 0),_e([X(()=>Ce,"group_id"),Ae("design:type",Array)],we.prototype,"groups_routes",void 0),_e([X(()=>Ce,"group_id"),Ae("design:type",Array)],we.prototype,"users_groups",void 0),we=_e([W(Re),z("group"),Q(De),J("4.2.0")],we);let Ce=class extends Z{};_e([$.CreatedAt,Ae("design:type",Date)],Ce.prototype,"created_at",void 0),_e([G(()=>we),Ae("design:type",Number)],Ce.prototype,"group_id",void 0),_e([G(()=>Fe),Ae("design:type",Number)],Ce.prototype,"user_id",void 0),Ce=_e([W(Re),z("users_groups"),Q(De),J("4.2.0")],Ce);let xe=class extends Z{};_e([$.String(),Ae("design:type",String)],xe.prototype,"password",void 0),_e([$.CreatedAt,Ae("design:type",Date)],xe.prototype,"created_at",void 0),_e([G(()=>Fe),Ae("design:type",Number)],xe.prototype,"user_id",void 0),xe=_e([W(Re),z("users_histories"),J("4.2.0")],xe);let Fe=class extends Z{};_e([$.Id(),Ae("design:type",Number)],Fe.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"name",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"email",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"username",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"password",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"salt",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"token",void 0),_e([$.String(),Ae("design:type",String)],Fe.prototype,"avatar",void 0),_e([$.DateOnly(),Ae("design:type",String)],Fe.prototype,"date",void 0),_e([$.Text(),Ae("design:type",String)],Fe.prototype,"description",void 0),_e([$.Boolean(),Ae("design:type",Boolean)],Fe.prototype,"state",void 0),_e([$.CreatedAt,Ae("design:type",Date)],Fe.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],Fe.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],Fe.prototype,"deleted_at",void 0),_e([X(()=>je,"user_id"),Ae("design:type",Array)],Fe.prototype,"audits",void 0),_e([X(()=>Ne,"user_id"),Ae("design:type",Array)],Fe.prototype,"auths",void 0),_e([X(()=>be,"user_id"),Ae("design:type",Array)],Fe.prototype,"registers",void 0),_e([X(()=>Ce,"user_id"),Ae("design:type",Array)],Fe.prototype,"users_groups",void 0),_e([X(()=>xe,"user_id"),Ae("design:type",Array)],Fe.prototype,"users_histories",void 0),Fe=_e([W(Re),z("user"),ee({attributes:{exclude:["password","salt","token"]}}),te({password:{attributes:{exclude:["token"]}},token:{attributes:{exclude:["password","salt"]}}}),Q(De),J("4.2.0")],Fe);let je=class extends Z{};_e([$.Id(),Ae("design:type",Number)],je.prototype,"id",void 0),_e([$.Enum("CREATE","DELETE","UPDATE"),Ae("design:type",String)],je.prototype,"type",void 0),_e([$.String(),Ae("design:type",String)],je.prototype,"model",void 0),_e([$.String(),Ae("design:type",String)],je.prototype,"record",void 0),_e([$.Json(),Ae("design:type",Object)],je.prototype,"data",void 0),_e([$.Json(),Ae("design:type",Object)],je.prototype,"previously",void 0),_e([$.String(),Ae("design:type",String)],je.prototype,"client",void 0),_e([$.Text(),Ae("design:type",String)],je.prototype,"href",void 0),_e([$.String(),Ae("design:type",String)],je.prototype,"user_agent",void 0),_e([$.Boolean(),Ae("design:type",Boolean)],je.prototype,"state",void 0),_e([$.CreatedAt,Ae("design:type",Date)],je.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],je.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],je.prototype,"deleted_at",void 0),_e([G(()=>Fe),Ae("design:type",Number)],je.prototype,"user_id",void 0),je=_e([W(Re),z("audit"),J("4.2.0")],je);let Ue=class extends Z{static all(){return Ee(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 Ee(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 Ee(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 Ee(this,void 0,void 0,function*(){var r;const n=null!==(r=null==i?void 0:i.id)&&void 0!==r?r:null,[s]=(yield this.findOrCreate(Object.assign({where:{key:e}},{user_id:n})).catch(this.error))||[];s&&(s.value=t,yield s.save().catch(this.error))})}};_e([$.String(),Ae("design:type",String)],Ue.prototype,"key",void 0),_e([$.String(),Ae("design:type",String)],Ue.prototype,"value",void 0),_e([$.CreatedAt,Ae("design:type",Date)],Ue.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],Ue.prototype,"updated_at",void 0),Ue=_e([W(Re),z("configs"),J("4.2.0")],Ue);let ke=class extends Z{};_e([$.Id(),Ae("design:type",Number)],ke.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],ke.prototype,"token",void 0),_e([$.BigInt(),Ae("design:type",Number)],ke.prototype,"timestamp",void 0),_e([$.Boolean(),Ae("design:type",Boolean)],ke.prototype,"state",void 0),_e([$.CreatedAt,Ae("design:type",Date)],ke.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],ke.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],ke.prototype,"deleted_at",void 0),_e([G(()=>Fe),Ae("design:type",Number)],ke.prototype,"user_id",void 0),ke=_e([W(Re),z("forgot"),J("4.2.0")],ke);let Le=class extends Z{};_e([$.Id(),Ae("design:type",Number)],Le.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],Le.prototype,"name",void 0),_e([$.String(),ie(!0),Ae("design:type",String)],Le.prototype,"route",void 0),_e([$.String(),Ae("design:type",String)],Le.prototype,"tag",void 0),_e([$.Text(),Ae("design:type",String)],Le.prototype,"description",void 0),_e([$.Boolean(),Ae("design:type",Boolean)],Le.prototype,"state",void 0),_e([$.CreatedAt,Ae("design:type",Date)],Le.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],Le.prototype,"updated_at",void 0),_e([$.DeletedAt,Ae("design:type",Object)],Le.prototype,"deleted_at",void 0),_e([X(()=>Be,"permission_id"),Ae("design:type",Array)],Le.prototype,"groups_permissions",void 0),Le=_e([W(Re),z("permission"),Q(De),J("4.3.1")],Le);let Be=class extends Z{};_e([$.CreatedAt,Ae("design:type",Date)],Be.prototype,"created_at",void 0),_e([G(()=>we),Ae("design:type",Number)],Be.prototype,"group_id",void 0),_e([G(()=>Le),Ae("design:type",Number)],Be.prototype,"permission_id",void 0),Be=_e([W(Re),z("groups_permissions"),Q(De),J("4.2.0")],Be);let Ke=class extends Z{static write(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.writeRaw(K.White,"",e,t,i)})}static error(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.writeRaw(K.Red,"error",e,t,i)})}static info(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.writeRaw(K.Cyan,"info",e,t,i)})}static success(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.writeRaw(K.Green,"success",e,t,i)})}static warning(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.writeRaw(K.Yellow,"warning",e,t,i)})}static writeRaw(e,t,i,r,n){return Ee(this,void 0,void 0,function*(){n&&M.console(e,t,i),Re&&(yield this.create({type:t,source:r,message:i}).catch(this.error))})}};_e([$.Id(),Ae("design:type",Number)],Ke.prototype,"id",void 0),_e([$.String(),Ae("design:type",String)],Ke.prototype,"type",void 0),_e([$.String(),Ae("design:type",String)],Ke.prototype,"source",void 0),_e([$.Text(),Ae("design:type",String)],Ke.prototype,"message",void 0),_e([$.CreatedAt,Ae("design:type",Date)],Ke.prototype,"created_at",void 0),Ke=_e([W(Re),z("log"),J("4.2.0")],Ke);let Me=class extends Z{};_e([$.String(),Ae("design:type",String)],Me.prototype,"model",void 0),_e([$.String(),Ae("design:type",String)],Me.prototype,"version",void 0),_e([$.CreatedAt,Ae("design:type",Date)],Me.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],Me.prototype,"updated_at",void 0),Me=_e([W(Re),z("migration"),J("4.2.0")],Me);let He=class extends Z{};_e([$.String(),Ae("design:type",String)],He.prototype,"session",void 0),_e([$.Text(),Ae("design:type",String)],He.prototype,"json",void 0),_e([$.BigInt(),Ae("design:type",Number)],He.prototype,"expired",void 0),_e([$.CreatedAt,Ae("design:type",Date)],He.prototype,"created_at",void 0),_e([$.UpdatedAt,Ae("design:type",Date)],He.prototype,"updated_at",void 0),He=_e([W(Re),z("session"),J("4.2.0")],He);class qe{static error(e){let t="token";Oe.API_BASE_NAME&&(t=`${Oe.API_BASE_NAME}.${t}`),Ke.error(e.message,t,Oe.API_CONSOLE_ERROR)}}class Ye extends qe{static user(e,t){return Ee(this,void 0,void 0,function*(){if(!e)return{error:"INVALID TOKEN"};const i=t.hash.encrypt(e),r=yield Fe.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 Ve=e=>de(e)?oe(e):void 0,$e={http:Ve(Oe.API_HTTP_CRT),token:Ve(Oe.API_TOKEN_CRT)},Ge={http:Ve(Oe.API_HTTP_KEY),token:Ve(Oe.API_TOKEN_KEY)};class We extends qe{static options(){return{algorithm:"RS256",expiresIn:`${Oe.API_TOKEN_LIFETIME}ms`}}static create(e){return Ee(this,void 0,void 0,function*(){if(!Ge.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},Ge.token,this.options())}})}static destroy(e){return Ee(this,void 0,void 0,function*(){return!(!e||e.logout)&&(e.logout=new Date,yield e.save(),!0)})}static renew(e){return Ee(this,void 0,void 0,function*(){if(!Ge.token)return{error:"KEY NOT FOUND"};const{error:t,decode:i}=this.verify(e,Oe.API_TOKEN_RENEW/1e3);if(t)return{error:t};if(i){const{id:e,secret:t}=i;if(e&&t){const i=yield Fe.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},Ge.token,this.options())}}}return{error:"ACCESS DENIED"}}}return{error:"INVALID TOKEN"}})}static user(e){return Ee(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 Fe.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(!$e.token)return{error:"CERT NOT FOUND"};if(!e||e.split(".").length<3)return{error:"INVALID TOKEN"};try{return{decode:se.verify(e,$e.token,{clockTolerance:t})}}catch(e){return{error:"INVALID TOKEN"}}}}class ze extends ye{constructor(){super(),this.all=e=>Ee(this,void 0,void 0,function*(){e=e||i;const t=yield He.findAll({attributes:["session"],where:{expired:{[re.gte]:Date.now()}}}).catch(t=>(e(t),null));t&&e(null,t.map(e=>e.session)),e()}),this.clear=e=>Ee(this,void 0,void 0,function*(){yield He.destroy().catch(i),e&&e()}),this.destroy=(e,t)=>Ee(this,void 0,void 0,function*(){yield He.destroy({where:{session:e}}).catch(i),t&&t()}),this.expired=()=>Ee(this,void 0,void 0,function*(){yield He.destroy({where:{expired:{[re.lt]:Date.now()}}}).catch(i)}),this.get=(e,t)=>Ee(this,void 0,void 0,function*(){t=t||i;const r=yield He.findOne({where:{session:e,expired:{[re.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=>Ee(this,void 0,void 0,function*(){e&&e(null,(yield He.count().catch(i))||0)}),this.set=(e,t,r)=>Ee(this,void 0,void 0,function*(){r=r||i;const n=Date.now()+Oe.API_SESSION_LIFETIME,s=JSON.stringify(t),[o,d]=(yield He.findOrCreate({where:{session:e},defaults:{session:e,json:s,expired:n}}).catch(i))||[];o&&(d||(o.json=s,o.expired=n,yield o.save().catch(i))),r()}),this.loop=n(this.expired,3e4),this.loop.start()}}class Je extends A{constructor(e){super(e,{cert:$e.http,cross:Oe.API_HTTP_CROSS,hybrid:Oe.API_HTTP_HYBRID,json:{strict:Oe.API_BODYPARSER_STRICT,inflate:Oe.API_BODYPARSER_INFLATE,limit:Oe.API_BODYPARSER_LIMIT,type:Oe.API_BODYPARSER_TYPE},key:Ge.http,notfound:Oe.API_HTTP_NOTFOUND,path:Oe.API_HTTP_PATH,port:Oe.API_HTTP_PORT,public:Oe.API_HTTP_PUBLIC,redirect:Oe.API_HTTP_REDIRECT,session:{store:new ze,name:Oe.API_SESSION_NAME,secret:Oe.API_SESSION_SECRET,cookie:{maxAge:Oe.API_SESSION_LIFETIME},genid:r}}),this.hash=new H(Oe.API_KEY_HASH)}error(e,t){Oe.API_BASE_NAME&&(t=t?`${Oe.API_BASE_NAME}.${t}`:Oe.API_BASE_NAME),Ke.error(e.message,t,Oe.API_CONSOLE_ERROR)}log(e,t){Oe.API_BASE_NAME&&(t=t?`${Oe.API_BASE_NAME}.${t}`:Oe.API_BASE_NAME),Ke.info(e,t,!0)}listen(){const e=Object.create(null,{listen:{get:()=>super.listen}});return Ee(this,void 0,void 0,function*(){yield Re.sync(),yield this.migrations(Re),yield s(this.controllers,e=>Ee(this,void 0,void 0,function*(){o(e.sync)&&(yield e.sync(this))})),yield e.listen.call(this),Oe.API_WEBSOCKET_START&&this.server&&(this._webSocket=new ge({server:this.server,verifyClient:(e,t)=>t(Oe.API_WEBSOCKET_START)}),this._webSocket.on("connection",(e,t)=>Ee(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=>Ee(this,void 0,void 0,function*(){if(r)try{const s=JSON.parse(n);this.emit("ws.message"+i,{data:s,message:n,req:t,user:r,ws:e})}catch(s){this.emit("ws.message"+i,{erro:s,message:n,req:t,user:r,ws:e})}else{const{user:s}=yield We.user(n.toString());s&&(r=s,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 Ee(this,void 0,void 0,function*(){const t=[];yield s(Object.keys(e.models),i=>Ee(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 Me.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 s(t,e=>Ee(this,void 0,void 0,function*(){return yield e.updateAttributes()}))})}websocket(){return this._webSocket}}var Ze,Xe,Qe;class et extends ve{constructor(){super(...arguments),this[Ze]=[]}auth(e,t,i,r,n,s){return Ee(this,void 0,void 0,function*(){var o;t=null!=t?t:r;const[d,a]=null!==(o=null==i?void 0:i.split(" "))&&void 0!==o?o:["",""];if(!(t||a&&d.toLowerCase()==Oe.API_TOKEN_HEADER_KEY))return e.error("INVALID TOKEN");const{auth:u,error:p,user:l}=yield t?Ye.user(t,s):We.user(a);return p?e.error(p):u&&l?!t&&u.user_agent&&u.user_agent!=n?e.error("INVALID TOKEN"):(e.req.auth=u,e.req.user=l,void e.next()):e.error("INTERNAL SERVER ERROR")})}canCreate(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".create",i)})}canDelete(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".delete",i)})}canRead(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".read",i)})}canUpdate(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.permission(e,(t||this.name())+".update",i)})}error(e){let t="controller_base";Oe.API_BASE_NAME&&(t=`${Oe.API_BASE_NAME}.${t}`),Ke.error(e.message,t,Oe.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 Ee(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 Ee(this,void 0,void 0,function*(){var i;return null!==(i=yield Le.findAll({where:Object.assign(Object.assign({},null!=t?t:{}),{state:!0}),include:[{model:Be,required:!0,include:[{model:we,required:!0,where:{state:!0},include:[{model:Ce,required:!0,where:{user_id:e.id}}]}]}]}).catch(this.error))&&void 0!==i?i:[]})}session(e,t,r){return Ee(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 Ee(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield s(this[ve.PERMISSIONS],i=>Ee(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=a(e.replace(/_/g," ")," ");yield Le.findOrCreate({where:{route:r},defaults:Object.assign({name:`${n} ${a(i," ")}`,route:r,tag:n},t)})}))})}upload(e,t){t.path||(t.path=Oe.API_UPLOAD_TEMP),t.size||(t.size=Oe.API_UPLOAD_SIZE),t.field||(t.field=Oe.API_UPLOAD_FIELD),T.middleware(e,t)}validation(e,t){return Ee(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()})}}Ze=ve.PERMISSIONS,_e([me(0,E()),me(1,O(Oe.API_KEY_HEADER)),me(2,O(Oe.API_TOKEN_HEADER)),me(3,S(Oe.API_KEY_HEADER)),me(4,O("user-agent")),me(5,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String,String,String,Je]),Ae("design:returntype",Promise)],et.prototype,"auth",null),_e([me(0,E()),me(1,P()),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],et.prototype,"canCreate",null),_e([me(0,E()),me(1,P()),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],et.prototype,"canDelete",null),_e([me(0,E()),me(1,P()),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],et.prototype,"canRead",null),_e([me(0,E()),me(1,P()),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],et.prototype,"canUpdate",null),_e([me(0,E()),me(1,P()),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],et.prototype,"permission",null),_e([me(0,E()),me(1,O("user-agent")),me(2,R()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Object]),Ae("design:returntype",Promise)],et.prototype,"session",null),_e([me(0,E()),me(1,P()),Ae("design:type",Function),Ae("design:paramtypes",[I,Object]),Ae("design:returntype",void 0)],et.prototype,"upload",null),_e([me(0,E()),me(1,P()),Ae("design:type",Function),Ae("design:paramtypes",[I,Object]),Ae("design:returntype",Promise)],et.prototype,"validation",null);let tt=class extends et{constructor(){super(...arguments),this[Xe]=[],this[Qe]=["create","read","update","delete"]}attributes(e){if(0==this[et.ATTRIBUTES].length&&(this[et.ATTRIBUTES]=Object.keys(this.model().getAttributes())),p(e))return e.length?e.map(e=>l(e)&&-1!=this[et.ATTRIBUTES].indexOf(e)?e:void 0).filter(l):this[et.ATTRIBUTES];const{exclude:t,include:i}=e,r=c(i)?this[et.ATTRIBUTES]:i.map(e=>l(e)&&-1!=this[et.ATTRIBUTES].indexOf(e)?e:void 0).filter(l),n=null!=t?t:[];return n.length?r.filter(e=>-1==n.indexOf(e)?e:void 0).filter(l):r}create(e){return Ee(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||{}),Se(e))).catch(this.error);if(r){const t=this.key();return e.prepare(N.OK,{[t]:r.getDataValue(t)}),r}e.error("INTERNAL SERVER ERROR")})}delete(e){return Ee(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}),Se(e))).catch(this.error);return n?(e.success("OK"),n):(e.notFound("RECORD NOT FOUND"),0)})}error(e){let t="controller_model";Oe.API_BASE_NAME&&(t=`${Oe.API_BASE_NAME}.${t}`),(null==e?void 0:e.sql)?Ke.error((null==e?void 0:e.message)+"\n"+(null==e?void 0:e.sql),t,Oe.API_CONSOLE_ERROR):super.error(e)}findAll(e){return Ee(this,arguments,void 0,function*({ctx:e,options:t,callback:i,scope:r,advanced:n,attributes:s,limited:o}){var d,a,u;const p=this.scope(r),h=Object.assign({},t||{}),{fields:v,limit:_,offset:m,asc:A,desc:E,search:O,where:S}=e.req.query;if(c(h.limit)){let e=Oe.API_MODEL_LIMIT;l(_)&&(e=parseInt(_)||0),e=g(e,-1,Oe.API_MODEL_LIMIT_MAX),h.limit=e>0?e:o?Oe.API_MODEL_LIMIT:void 0}if(y(h.limit)&&(h.limit=h.limit>0?h.limit:void 0),l(m)){const e=parseInt(m)||0;h.offset=e>0?e:void 0}s=null!=s?s:this.attributes(null!==(d=null==h?void 0:h.attributes)&&void 0!==d?d:[]);const f=e=>s.indexOf(e)>=0,I=[];l(v)&&I.push(...v.split(";").filter(f)),I.length&&(h.attributes=I);const P=[];if(l(A)&&A.length&&P.push(...A.split(";").filter(f).map(e=>[e,"ASC"])),l(E)&&E.length&&P.push(...E.split(";").filter(f).map(e=>[e,"DESC"])),P.length&&(h.order=P),h.where=Object.assign({},h.where||{}),l(S)&&(null==n||n)){const t=ne.parse(s,S);if(!c(t.error))return e.validation(t.error.join(", ")),{count:0,records:[]};h.where=Object.assign(Object.assign({},h.where),null!==(a=t.value)&&void 0!==a?a:{})}else{const e=[];s.forEach(t=>{l(O)&&O.length&&e.push({[t]:{[re.like]:`%${O}%`}})}),e.length&&(h.where=Object.assign(Object.assign({},h.where),{[re.or]:[...e]}))}const R=p.count(Object.assign(Object.assign({},h),{distinct:!!h.include,col:this[et.ATTRIBUTES].length?this[et.ATTRIBUTES][0]:void 0})).catch(this.error),T=p.findAll(h).catch(this.error);yield Promise.allSettled([R,T]);const D=null!==(u=yield R)&&void 0!==u?u:0;let b=yield T;const w={count:D};return b?(b=i?yield i(b):b,(y(null==t?void 0:t.limit)||0==D)&&(w.count=b.length),e.prepare(N.OK,Object.assign(Object.assign({},w),{records:b})),Object.assign(Object.assign({},w),{records:b})):(e.error("INTERNAL SERVER ERROR"),Object.assign(Object.assign({},w),{records:[]}))})}findOne(e){return Ee(this,arguments,void 0,function*({ctx:e,options:t,callback:i,scope:r}){const n=this.key(),{[n]:s}=e.req.params,o=yield this.scope(r).findOne(Object.assign(Object.assign({},t||{}),{where:Object.assign(Object.assign({},(t||{}).where),{[n]:s})})).catch(this.error);return o?(e.prepare(N.OK,i?yield i(o):o.toJSON()),o):null===o?e.notFound("RECORD NOT FOUND"):void e.error("INTERNAL SERVER ERROR")})}sync(){return Ee(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t={description:"",state:!0};yield s(this[et.PERMISSIONS],i=>Ee(this,void 0,void 0,function*(){const r=`${e}.${i}`,n=a(e.replace(/_/g," ")," ");yield Le.findOrCreate({where:{route:r},defaults:Object.assign({name:`${n} ${a(i," ")}`,route:r,tag:n},t)})}))})}update(e){return Ee(this,arguments,void 0,function*({ctx:e,options:t,body:i}){var r;const n=this.key(),{[n]:s}=e.req.params,[o]=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]:s}),individualHooks:!0}),Se(e))).catch(this.error))&&void 0!==r?r:[];return o?(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()}};Xe=et.ATTRIBUTES,Qe=et.PERMISSIONS,tt=_e([D(et)],tt);let it=class extends tt{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 Ee(this,void 0,void 0,function*(){yield this.create(this.CrudArgumentsCreate(e))})}all(e){return Ee(this,void 0,void 0,function*(){yield this.findAll(this.CrudArgumentsFindAll(e))})}del(e){return Ee(this,void 0,void 0,function*(){yield this.delete(this.CrudArgumentsDelete(e))})}get(e){return Ee(this,void 0,void 0,function*(){yield this.findOne(this.CrudArgumentsFindOne(e))})}set(e){return Ee(this,void 0,void 0,function*(){yield this.update(this.CrudArgumentsUpdate(e))})}validationCreate(e){return Ee(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 Ee(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)})}};_e([b(),w("auth"),w("canCreate"),w("validationCreate"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"add",null),_e([C(),w("auth"),w("canRead"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"all",null),_e([x("/:id"),w("auth"),w("canDelete"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"del",null),_e([C("/:id"),w("auth"),w("canRead"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"get",null),_e([F("/:id"),w("auth"),w("canUpdate"),w("validationUpdate"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"set",null),_e([me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"validationCreate",null),_e([me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],it.prototype,"validationUpdate",null),it=_e([D(tt)],it);let rt=class extends tt{model(){return je}all(e,t,i){return Ee(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 Ee(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}};_e([C(),w("auth"),w("canRead"),me(0,E()),me(1,S("type")),me(2,S("table")),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String]),Ae("design:returntype",Promise)],rt.prototype,"all",null),_e([C("/:id"),w("auth"),w("canRead"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],rt.prototype,"get",null),rt=_e([j("/audits"),D(tt)],rt);let nt=class extends et{login(e,t,i,r,n){return Ee(this,void 0,void 0,function*(){var s;yield d(Oe.API_SLEEP_AUTH);const o=yield Fe.scope("password").findOne({where:{[re.or]:[{email:i},{username:i}]}}).catch(this.error);if(r+=null!==(s=null==o?void 0:o.salt)&&void 0!==s?s:"",!o||o.password!=q(r))return e.notFound("INVALID USERNAME OR PASSWORD"),n.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e});const a=yield be.findOne({where:{state:!0,user_id:o.id}}).catch(this.error);if(a)return e.error("ACTIVATION REQUIRED"),n.emit("auth.activation",{ctx:e,register:a,user:o}),void this.emit("auth.activation",{ctx:e,register:a,user:o});if(!o.state)return e.notFound("INVALID USERNAME OR PASSWORD"),n.emit("auth.failure",{ctx:e,user:o}),void this.emit("auth.failure",{ctx:e,user:o});const{auth:u,error:p,token:l}=yield We.create(o);return p?(e.error(p),n.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e})):u&&l?(u.user_agent=t,yield u.save().catch(this.error),e.json({token:l}),n.emit("auth.login",{auth:u,ctx:e,user:o}),void this.emit("auth.login",{auth:u,ctx:e,user:o})):(e.error("INTERNAL SERVER ERROR"),n.emit("auth.failure",{ctx:e}),void this.emit("auth.failure",{ctx:e}))})}logout(e,t,i,r){return Ee(this,void 0,void 0,function*(){if(yield We.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 Ee(this,void 0,void 0,function*(){const{auth:n,error:s,token:o}=yield We.renew(i);return s?e.error(s):n?(n.user_agent=t,yield n.save().catch(this.error),e.json({token:o}),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 Ee(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({},h(["username","date","description","state","created_at","updated_at","deleted_at"],t.toJSON())),{permissions:i.map(e=>e.route)}))})}};var st;_e([b("/login"),w("validation",{username:u.string().min(3).required(),password:u.string().min(5).required()}),me(0,E()),me(1,O("user-agent")),me(2,U("username")),me(3,U("password")),me(4,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String,String,Je]),Ae("design:returntype",Promise)],nt.prototype,"login",null),_e([C("/logout"),w("auth"),me(0,E()),me(1,Ie()),me(2,Pe()),me(3,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,Ne,Fe,Je]),Ae("design:returntype",Promise)],nt.prototype,"logout",null),_e([b("/renew"),w("validation",{token:u.string().required()}),me(0,E()),me(1,O("user-agent")),me(2,U("token")),me(3,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String,Je]),Ae("design:returntype",Promise)],nt.prototype,"renew",null),_e([C(),w("auth"),me(0,E()),me(1,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,Fe]),Ae("design:returntype",Promise)],nt.prototype,"user",null),nt=_e([j("/auth"),D(et)],nt);let ot=class extends et{constructor(){super(...arguments),this[st]=["delete","download","edit","list","read","rename","upload","write"]}directory(){return Oe.API_HTTP_PUBLIC||"./"}files(e){return Ee(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(!de(i)||!ae(i).isDirectory())return e.notFound("RECORD NOT FOUND");let r=[];return r=ue(i),r=r.map(e=>this.info(he(i,e))),r=r.filter(v),Object.assign(Object.assign({},this.info(i)),{files:r})})}access(e,t,i){return Ee(this,void 0,void 0,function*(){yield this.permission(e,this.name()+"."+t,i)})}info(e){if(!de(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 Ee(this,void 0,void 0,function*(){const e=this.name().toLowerCase(),t=a(e.replace(/_/g," ")," "),i={description:"",state:!0};yield s(this[et.PERMISSIONS],r=>Ee(this,void 0,void 0,function*(){const n=`${e}.${r}`;yield Le.findOrCreate({where:{route:n},defaults:Object.assign({name:`${t} ${a(r," ")}`,route:n,tag:t},i)})}))})}};st=et.PERMISSIONS,_e([C("/path"),C("/path/*path"),w("auth"),w("access","list"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],ot.prototype,"files",null),_e([me(0,E()),me(1,P()),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],ot.prototype,"access",null),ot=_e([j("/files"),D(et)],ot);let dt=class extends et{check(e,t){return Ee(this,void 0,void 0,function*(){const i=yield this.find(t);if(!i||!i.user)return e.notFound("RECORD NOT FOUND");i.token=_(),yield i.save(),e.json({token:i.token})})}forgot(e,t,i){return Ee(this,void 0,void 0,function*(){yield d(Oe.API_SLEEP_FORGOT);const r=t,n=yield Fe.findOne({where:{[re.or]:[{email:r},{username:t}]}}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");const s=_(),o=Date.now()+6e4*Oe.API_TOKEN_FORGOT,a=yield ke.create({token:s,timestamp:o,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 Ee(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=q(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 Ee(this,void 0,void 0,function*(){return yield ke.findOne({where:{token:e,state:!0},include:[{model:Fe,required:!0}]}).catch(this.error)})}};_e([C("/check"),w("validation",{token:u.string().required()}),me(0,E()),me(1,U("token")),Ae("design:type",Function),Ae("design:paramtypes",[I,String]),Ae("design:returntype",Promise)],dt.prototype,"check",null),_e([b(),w("validation",{username:u.string().min(4).required()}),me(0,E()),me(1,U("username")),me(2,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Je]),Ae("design:returntype",Promise)],dt.prototype,"forgot",null),_e([b("/reset"),w("validation",{token:u.string().required(),password:u.string().min(5).required()}),me(0,E()),me(1,U("token")),me(2,U("password")),me(3,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String,Je]),Ae("design:returntype",Promise)],dt.prototype,"reset",null),dt=_e([j("/forgot"),D(et)],dt);let at=class extends it{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 we}CrudArgumentsFindAll(e){return{ctx:e}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};at=_e([j("/groups"),D(it)],at);let ut=class extends tt{model(){return Be}all(e,t){return Ee(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{group_id:t},include:[{model:Le,required:!0}]},callback:e=>e.map(e=>e.permission)})})}me(e,t){return Ee(this,void 0,void 0,function*(){yield this.all(e,t.id.toString())})}set(e,t,i,r){return Ee(this,void 0,void 0,function*(){const n=yield we.findByPk(t,{attributes:["id"]}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");const s=n.id;if(yield Be.destroy(Object.assign({where:{group_id:s},individualHooks:!0},r)),i){let e=0;yield d(1e3);for(let t=0;t<i.length;t++)e=yield Le.count({where:{id:i[t]}}),e&&(yield Be.create({group_id:s,permission_id:i[t]},Object.assign({},r)))}e.success("OK")})}};var pt;_e([C("/:id/permissions"),w("auth"),w("canRead","groups"),me(0,E()),me(1,k("id")),Ae("design:type",Function),Ae("design:paramtypes",[I,String]),Ae("design:returntype",Promise)],ut.prototype,"all",null),_e([C("/permissions"),w("auth"),w("canRead","users"),me(0,E()),me(1,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,Fe]),Ae("design:returntype",Promise)],ut.prototype,"me",null),_e([F("/:id/permissions"),w("auth"),w("canUpdate","groups"),w("validation",{permissions:u.array(u.number().parse())}),me(0,E()),me(1,k("id")),me(2,U("permissions")),me(3,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Array,Object]),Ae("design:returntype",Promise)],ut.prototype,"set",null),ut=_e([j("/groups"),D(tt)],ut);let lt=class extends tt{constructor(){super(...arguments),this[pt]=["read"]}model(){return Ke}all(e,t,i){return Ee(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})})}};pt=tt.PERMISSIONS,_e([C(),w("auth"),w("canRead"),me(0,E()),me(1,S("type")),me(2,S("source")),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String]),Ae("design:returntype",Promise)],lt.prototype,"all",null),lt=_e([j("/logs"),D(tt)],lt);let ct=class extends it{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 Le}CrudArgumentsFindAll(e){return{ctx:e}}CrudValidationCreate(){return this.schemaCreate}CrudValidationUpdate(){return this.schemaUpdate}};ct=_e([j("/permissions"),D(it)],ct);let gt=class extends et{register(e,t,i){return Ee(this,void 0,void 0,function*(){yield d(Oe.API_SLEEP_REGISTRY);const{name:r,date:n,email:s,username:o,password:a,confirm:u}=t,p=o||s,l=q(a);if(yield Fe.count({where:{[re.or]:[{email:s},{username:p}]}}).catch(this.error))return e.validation("INVALID EMAIL OR USERNAME");if(l!=q(u))return e.error("INVALID PASSWORD");const c=yield Fe.create({name:r,email:s,username:p,password:l,avatar:"",date:n,description:"",state:!1}).catch(this.error);if(!c)return e.error("INTERNAL SERVER ERROR");const g=yield be.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 Ee(this,void 0,void 0,function*(){const r=yield be.findOne({where:{token:t,state:!0},include:[{model:Fe,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 Ee(this,void 0,void 0,function*(){const r=t,n=yield be.findOne({where:{state:!0},include:[{model:Fe,required:!0,where:{[re.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 Ee(this,void 0,void 0,function*(){const e=r();return(yield be.count({where:{token:e}}))?this.getId():e})}};_e([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()}),me(0,E()),me(1,U()),me(2,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,Object,Je]),Ae("design:returntype",Promise)],gt.prototype,"register",null),_e([b("/confirm"),w("validation",{token:u.string().required()}),me(0,E()),me(1,U("token")),me(2,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Je]),Ae("design:returntype",Promise)],gt.prototype,"confirm",null),_e([b("/send"),w("validation",{username:u.string().min(4).required()}),me(0,E()),me(1,U("username")),me(2,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Je]),Ae("design:returntype",Promise)],gt.prototype,"send",null),gt=_e([j("/register"),D(et)],gt);let yt=class extends et{setup(e,t){return Ee(this,void 0,void 0,function*(){var i;if(yield Fe.count())return e.success("OK");const r=_(),n=yield Fe.create({name:"Admin",email:"admin@localhost",username:"admin",password:q("admin"+r),salt:r,token:"",avatar:"",date:new Date,description:"DEFAULT",state:!0},Object.assign({},t)),o=yield we.create(Object.assign({name:"Admin"},{description:"API CORE",state:!0}),Object.assign({},t));yield Ce.create({user_id:n.id,group_id:o.id},Object.assign({},t));const d=null!==(i=yield Le.findAll({where:{state:!0}}).catch(this.error))&&void 0!==i?i:[];yield s(d,e=>Ee(this,void 0,void 0,function*(){yield Be.create({group_id:o.id,permission_id:e.id},Object.assign({},t))})),e.success("OK")})}};_e([C(),me(0,E()),me(1,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,Object]),Ae("design:returntype",Promise)],yt.prototype,"setup",null),yt=_e([j("/setup"),D(et)],yt);let ht=class extends tt{model(){return Fe}constructor(){super(),this.path=Oe.API_HTTP_PUBLIC+"/avatar",Oe.API_HTTP_PUBLIC&&de(Oe.API_HTTP_PUBLIC)&&!de(this.path)&&pe(this.path)}avatar(e,t,i,r){return Ee(this,void 0,void 0,function*(){if(t.length){const n=t[0].filename||"";if(n){const t=this.path+"/"+i.avatar;if(de(t)&&le(t).isFile()&&ce(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 Ee(this,void 0,void 0,function*(){const r=this.path+"/"+t.avatar;t.avatar="",(yield t.save(Object.assign({},i)).catch(this.error))&&de(r)&&ce(r),e.success("OK")})}password(e,t,i,r,n){return Ee(this,void 0,void 0,function*(){var s;if(Oe.API_USER_HISTORY){if(yield xe.count({where:{password:q(i+r.id)}}).catch(this.error))return e.error("PASSWORD PREVIOUSLY REGISTERED")}const o=yield this.scope("password").findOne({where:{id:r.id,state:!0}}).catch(this.error);return t+=null!==(s=null==o?void 0:o.salt)&&void 0!==s?s:"",o&&o.password==q(t)?(o.salt=_(),o.password=q(i+o.salt),(yield o.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 Ee(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 Ee(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 Ee(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 Ee(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 Ee(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 Ee(this,void 0,void 0,function*(){const i=_(),r=yield this.create({ctx:e,body:{password:q(t+i),salt:i}});Oe.API_USER_HISTORY&&r&&(yield xe.create({password:q(t+r.id),user_id:r.id}))})}all(e){return Ee(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{attributes:{exclude:["password","salt","token"]}}})})}del(e,t,i){return Ee(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 Ee(this,void 0,void 0,function*(){yield this.findOne({ctx:e})})}set(e,t,i){return Ee(this,void 0,void 0,function*(){if(Oe.API_USER_HISTORY&&i){const r=q(i+t);if(yield xe.count({where:{password:r}}).catch(this.error))return e.error("PASSWORD PREVIOUSLY REGISTERED");yield xe.create({password:r,user_id:t}).catch(this.error)}const r=i?_():"";yield this.update({ctx:e,body:i?{password:q(i+r),salt:r}:{}})})}};_e([b("/avatar"),w("auth"),w("upload",e=>({count:1,field:"file",path:e.controller.path,types:["image/bmp","image/jpeg","image/png"],size:32})),me(0,E()),me(1,L()),me(2,Pe()),me(3,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,Array,Fe,Object]),Ae("design:returntype",Promise)],ht.prototype,"avatar",null),_e([x("/avatar"),w("auth"),me(0,E()),me(1,Pe()),me(2,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,Fe,Object]),Ae("design:returntype",Promise)],ht.prototype,"avatar_del",null),_e([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"))}),me(0,E()),me(1,U("oldPassword")),me(2,U("newPassword")),me(3,Pe()),me(4,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String,Fe,Object]),Ae("design:returntype",Promise)],ht.prototype,"password",null),_e([C("/token"),w("auth"),me(0,E()),me(1,Pe()),me(2,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,Fe,Je]),Ae("design:returntype",Promise)],ht.prototype,"token",null),_e([x("/token/:id"),w("auth"),w("canDelete"),me(0,E()),me(1,k("id")),me(2,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Object]),Ae("design:returntype",Promise)],ht.prototype,"token_del",null),_e([C("/token/:id"),w("auth"),w("canCreate"),me(0,E()),me(1,k("id")),me(2,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Je]),Ae("design:returntype",Promise)],ht.prototype,"token_get",null),_e([C("/token/renew/:id"),w("auth"),w("canUpdate"),me(0,E()),me(1,k("id")),me(2,fe()),me(3,f()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Object,Je]),Ae("design:returntype",Promise)],ht.prototype,"token_renew",null),_e([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()}),me(0,E()),me(1,U("password")),Ae("design:type",Function),Ae("design:paramtypes",[I,String]),Ae("design:returntype",Promise)],ht.prototype,"add",null),_e([C(),w("auth"),w("canRead"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],ht.prototype,"all",null),_e([x("/:id"),w("auth"),w("canDelete"),me(0,E()),me(1,k("id")),me(2,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Fe]),Ae("design:returntype",Promise)],ht.prototype,"del",null),_e([C("/:id"),w("auth"),w("canRead"),me(0,E()),Ae("design:type",Function),Ae("design:paramtypes",[I]),Ae("design:returntype",Promise)],ht.prototype,"get",null),_e([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()}),me(0,E()),me(1,k("id")),me(2,U("password")),Ae("design:type",Function),Ae("design:paramtypes",[I,String,String]),Ae("design:returntype",Promise)],ht.prototype,"set",null),ht=_e([j("/users"),D(tt),Ae("design:paramtypes",[])],ht);let vt=class extends tt{model(){return Ce}all(e,t){return Ee(this,void 0,void 0,function*(){yield this.findAll({ctx:e,options:{where:{user_id:t},include:[{model:we,required:!0}]},callback:e=>e.map(e=>e.group)})})}me(e,t){return Ee(this,void 0,void 0,function*(){yield this.all(e,t.id.toString())})}set(e,t,i,r){return Ee(this,void 0,void 0,function*(){const n=yield Fe.findByPk(t,{attributes:["id"]}).catch(this.error);if(!n)return e.notFound("RECORD NOT FOUND");if(yield Ce.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 we.count({where:{id:i[t]}}),e&&(yield Ce.create({user_id:n.id,group_id:i[t]},Object.assign({},r)))}e.success("OK")})}};_e([C("/:id/groups"),w("auth"),w("canRead","users"),me(0,E()),me(1,k("id")),Ae("design:type",Function),Ae("design:paramtypes",[I,String]),Ae("design:returntype",Promise)],vt.prototype,"all",null),_e([C("/groups"),w("auth"),w("canRead","users"),me(0,E()),me(1,Pe()),Ae("design:type",Function),Ae("design:paramtypes",[I,Fe]),Ae("design:returntype",Promise)],vt.prototype,"me",null),_e([F("/:id/groups"),w("auth"),w("canUpdate","users"),w("validation",{groups:u.array(u.number().parse())}),me(0,E()),me(1,k("id")),me(2,U("groups")),me(3,fe()),Ae("design:type",Function),Ae("design:paramtypes",[I,String,Array,Object]),Ae("design:returntype",Promise)],vt.prototype,"set",null),vt=_e([j("/users"),D(tt)],vt);export{Je as Application,je as Audit,rt as AuditsController,Ne as Auth,qe as AuthBase,nt as AuthController,Ye as AuthKey,We as AuthToken,Ue as Config,ve as Controller,et as ControllerBase,it as ControllerCrud,tt as ControllerModel,Oe as Env,ot as FilesController,ke as Forgot,dt as ForgotController,we as Group,Be as GroupPermission,at as GroupsController,ut as GroupsPermissionsController,Ke as Log,lt as LogsController,Me as Migration,Le as Permission,ct as PermissionsController,be as Register,gt as RegisterController,fe as ReqAudit,Ie as ReqAuth,Pe as ReqUser,He as Session,yt as SetupController,ze as Store,Fe as User,Ce as UserGroup,xe as UserHistory,ht as UsersController,vt as UsersGroupsController,Se as audit,$e as crt,Re as database,De as hooks,Ge as key};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@andrewcaires/api",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.5.0",
|
|
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,31 +46,31 @@
|
|
|
46
46
|
},
|
|
47
47
|
"homepage": "https://github.com/andrewcaires/npm/tree/main/api#readme",
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@andrewcaires/express": "^1.2.
|
|
50
|
-
"@andrewcaires/node": "^1.2.
|
|
51
|
-
"@andrewcaires/sequelize": "^
|
|
52
|
-
"@andrewcaires/utils.js": "^0.4.
|
|
49
|
+
"@andrewcaires/express": "^1.2.7",
|
|
50
|
+
"@andrewcaires/node": "^1.2.9",
|
|
51
|
+
"@andrewcaires/sequelize": "^2.0.1",
|
|
52
|
+
"@andrewcaires/utils.js": "^0.4.20",
|
|
53
53
|
"cors": "^2.8.5",
|
|
54
|
-
"dotenv": "^17.2.
|
|
54
|
+
"dotenv": "^17.2.3",
|
|
55
55
|
"express-session": "^1.18.2",
|
|
56
|
-
"jsonwebtoken": "^9.0.
|
|
57
|
-
"tsx": "^4.
|
|
58
|
-
"ws": "^8.
|
|
56
|
+
"jsonwebtoken": "^9.0.3",
|
|
57
|
+
"tsx": "^4.21.0",
|
|
58
|
+
"ws": "^8.19.0"
|
|
59
59
|
},
|
|
60
60
|
"devDependencies": {
|
|
61
|
-
"@rollup/plugin-commonjs": "^
|
|
61
|
+
"@rollup/plugin-commonjs": "^29.0.0",
|
|
62
62
|
"@rollup/plugin-terser": "^0.4.4",
|
|
63
|
-
"@rollup/plugin-typescript": "^12.
|
|
63
|
+
"@rollup/plugin-typescript": "^12.3.0",
|
|
64
64
|
"@types/cors": "^2.8.19",
|
|
65
65
|
"@types/express-session": "^1.18.2",
|
|
66
66
|
"@types/jsonwebtoken": "^9.0.10",
|
|
67
|
-
"@types/node": "^
|
|
67
|
+
"@types/node": "^25.0.7",
|
|
68
68
|
"@types/ws": "^8.18.1",
|
|
69
|
-
"eslint": "^9.
|
|
69
|
+
"eslint": "^9.39.2",
|
|
70
70
|
"mariadb": "^3.4.5",
|
|
71
|
-
"rollup": "^4.
|
|
72
|
-
"rollup-plugin-dts": "^6.
|
|
71
|
+
"rollup": "^4.55.1",
|
|
72
|
+
"rollup-plugin-dts": "^6.3.0",
|
|
73
73
|
"tslib": "^2.8.1",
|
|
74
|
-
"typescript-eslint": "^8.
|
|
74
|
+
"typescript-eslint": "^8.53.0"
|
|
75
75
|
}
|
|
76
76
|
}
|