Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@sumor/app

Package Overview
Dependencies
Maintainers
1
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@sumor/app - npm Package Compare versions

Comparing version 11.0.4 to 11.0.5

2

index.js

@@ -1,1 +0,1 @@

!function(t){var e={};function n(i){if(e[i])return e[i].exports;var s=e[i]={i:i,l:!1,exports:{}};return t[i].call(s.exports,s,s.exports,n),s.l=!0,s.exports}n.m=t,n.c=e,n.d=function(t,e,i){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:i})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=10)}([function(t,e){t.exports=require("@sumor/utils")},function(t,e){t.exports=require("koa")},function(t,e){t.exports=require("http")},function(t,e){t.exports=require("https")},function(t,e,n){const i=n(19),s=n(20);t.exports=class{constructor(t){if(t)switch(this.config=t,t.type=t.type||"mysql",t.type){case"mysql":this._instance=new i(t)}}open(){if(this._instance){const t=this._instance.new();return new s(t,this.config.metadata)}}}},function(t,e){t.exports=require("mysql")},function(t,e,n){const i=n(21),s=n(28);t.exports=class{constructor(t,e){switch(this.appid=t,this.config=e||{},this.config.type){case"redis":this.connection=new s(this.config);break;default:this.connection=new i(this.config)}}_namespace(t,e){return e=e&&""!==e?":"+e:"",`${this.appid}:${t}${e}`}async delete(t,e){return await this.connection.delete(this._namespace(t,e))}async setVariable(t,e,n){return await this.connection.setVariable(this._namespace(t,e),n)}async getVariable(t,e){return await this.connection.getVariable(this._namespace(t,e))}async setObject(t,e,n){return await this.connection.setObject(this._namespace(t,e),n)}async getObject(t,e){return await this.connection.getObject(this._namespace(t,e))}async setObjectAttribute(t,e,n,i){return await this.connection.setObjectAttribute(this._namespace(t,e),n,i)}async getObjectAttribute(t,e,n){return await this.connection.getObjectAttribute(this._namespace(t,e),n)}}},function(t,e,n){const i=n(30);t.exports=class{constructor(t){if(t)switch(t.type){case"aliyunOSS":this._instance=new class{constructor(t){this.aliyunOSS=new i(t)}async put(t,e){return await this.aliyunOSS.put(t,e)}async get(t){return await this.aliyunOSS.put(t)}}(t)}}async put(t,e){if(this._instance)return await this._instance.put(t,e);throw{code:"STORAGE_NOT_CONNECTED",message:"未配置存储服务器连接"}}async get(t){if(this._instance)return await this._instance.get(t);throw{code:"STORAGE_NOT_CONNECTED",message:"未配置存储服务器连接"}}}},function(t,e){t.exports=((t,e)=>{let n=e.notNull?" NOT NULL":"",i=" DEFAULT NULL";return"number"==typeof e.default&&(i=` DEFAULT ${e.default}`),"string"==typeof e.default&&(i=` DEFAULT '${e.default}'`),`\`${t}\` ${e.type}${e.length?"("+e.length+")":""}${n}${i}`})},function(t,e){t.exports=((t,e)=>{for(let n in t)t[n]&&"__proto__"!==n&&e(n,t[n])})},function(t,e,n){t.exports=n(11)},function(t,e,n){global.sumor_output=n(12)},function(t,e,n){t.exports={Service:n(13),Site:n(32),SqlDB:n(4),CacheDB:n(6),Storage:n(7),DataNuts:n(36)}},function(t,e,n){const i=n(1),s=n(14),o=n(15),a=n(16),r=n(17),c=n(0),l=n(2),u=n(3),h=n(18),f=n(4),p=n(6),d=n(7),y=n(31);t.exports=class{constructor(t){this.config=t,this.config.serviceRoot=this.config.serviceRoot||"/service",this.config.port=this.config.port||(this.config.certs?443:80),this.init()}async callExit(t,e,n){n=n||{};const i=(this.config.exit||{})[t]||[];for(let t in i)await this.config.program[i[t]](e,n)}async init(){const t=new i;let e;if(this.config.certs){const n={key:this.config.certs.key,cert:this.config.certs.crt};e=u.createServer(n,t.callback())}else e=l.createServer(t.callback());const n=`${process.cwd()}/instanceid`;if(await c.file.exist(n)){let t=await c.file.readFile(n,"utf-8");this.instanceid=t.split("\n")[0]}console.log("正在初始化框架服务"),await this.listenService(t),console.log("初始化框架服务完成"),e.listen(this.config.port,()=>{console.log(`服务运行在端口: ${this.config.port}`)})}async initContext(){const t=process.cwd()+"/config.json";let e={};await c.file.exist(t)&&(e=await c.file.readJson(t)),e.SumorSqlDB&&await c.file.exist(`${process.cwd()}/db.json`)&&(e.SumorSqlDB.metadata=await c.file.readJson(`${process.cwd()}/db.json`)),this.db=new f(e.SumorSqlDB);const n=new d(e.SumorStorage),i=new p(this.config.appid,e.SumorCacheDB);this.context={appid:this.config.appid,config:e,storage:n,cacheDB:i,utils:c}}getContext(t){const e={};for(let t in this.context)e[t]=this.context[t];if(t)for(let n in t)e[n]=t[n];return e}async listenService(t){await this.initContext(),t.use(async(t,e)=>{this.instanceid&&t.set("sumor-instance",this.instanceid),await e()}),t.use(a()),t.use(r());const e=new o;e.get(this.config.serviceRoot+"/sumor/ping",t=>{t.body="OK"});for(let t in this.config.service){const n=this.config.service[t];e.all(`${this.config.serviceRoot}/${n.id}`,async t=>{const e=this.db.open(),i=t.request.headers["accept-language"].split(","),s=i[0],o=[];for(let t in i)o.push(i[t].split(";")[0]);const a=parseInt(t.request.headers["sumor-timezone"]),r=new y,l=this.getContext({db:e,service:n,language:s,languages:o,timezone:a,token:r,http:t}),u={};for(let e in t.query)u[e]=t.query[e];switch(t.method){case"POST":for(let e in t.request.body)u[e]=t.request.body[e]}const f={code:"OK"};try{await h(u,n),await this.callExit("beforeCall",u,l),r.check(n.permission);const t=await this.config.program[n.id](u,l);f.data=t,e&&await e.commit()}catch(t){console.error(t),e&&await e.rollback(),f.code=t.code||"ERROR",f.message=t.message}const p=Math.floor(c.basic.getTimestamp()-process.uptime());t.set("sumor-uptime",c.basic.formatTime(p,"yyyy-MM-dd hh:mm:ss",a)),t.body=f})}e.get(this.config.serviceRoot+"/*",t=>{t.body="找不到该服务"}),t.use(e.routes()).use(e.allowedMethods()),t.use(s({rootDir:process.cwd()+"/static",rootPath:"/",notFoundFile:"index.html",maxage:31536e6}));const n=this.db.open();await this.callExit("init",{},this.getContext({context:this.context,db:n}))}}},function(t,e){t.exports=require("koa-static-server")},function(t,e){t.exports=require("@koa/router")},function(t,e){t.exports=require("koa-logger")},function(t,e){t.exports=require("koa-bodyparser")},function(t,e){t.exports=((t,e)=>{const n=e.parameter;for(let e in n)switch(void 0===t[e]&&(t[e]=n[e].default),n[e].type){case"number":if("string"==typeof t[e])t[e]=parseFloat(t[e]);else if(null!==t[e]&&"number"!=typeof t[e])throw{code:"PARAMETER_INVALID",message:`参数${e}类型错误`};break;case"string":if("string"!=typeof t[e])throw{code:"PARAMETER_INVALID",message:`参数${e}类型错误`};break;case"array":case"object":if("string"==typeof t[e])try{t[e]=JSON.parse(t[e])}catch(t){throw{code:"PARAMETER_INVALID",message:`参数${e}数据格式异常`}}}})},function(t,e,n){const i=n(5);t.exports=class{constructor(t){if(!t)throw{code:"INVALID_MYSQL_CONFIG",message:"数据库配置不正确"};this.config=JSON.parse(JSON.stringify(t))}new(){return this.pool||(this.pool=i.createPool(this.config)),new class{constructor(t){this._pool=t}async connect(){this._connection=await new Promise((t,e)=>{this._pool.getConnection(function(n,i){n?e(n):t(i)})})}async query(t,e){return await new Promise((n,i)=>{this._connection.query(t,e,function(t,e){t?i(t):n(e)})})}escape(t){return i.escape(t)}async release(){this._connection.release()}async rollback(){return await new Promise(t=>{this._connection.rollback(function(){t()})})}async beginTransaction(){return await new Promise(t=>{this._connection.beginTransaction(function(){t()})})}async commit(){return await new Promise(t=>{this._connection.commit(function(){t()})})}}(this.pool)}}},function(t,e,n){const i=n(0);t.exports=class{constructor(t,e){this.connection=t,this.metadata=e,this.connected=!1,this.operator=""}setOperator(t){this.operator=t||""}async sql(t,e){return this.connected||await this._connect(),await this.connection.query(t,e)}async select(t){(t=t||{}).table=t.table||i.basic.fromCamelCase(t.entity,"_"),t.field=t.field||[],t.parameter=t.parameter||{},t.sort=t.sort||"",void 0===t.top&&(t.top=0),void 0===t.skip&&(t.skip=100);const e=e=>{let n=i.basic.fromCamelCase(e,"_");if(n.indexOf(".")<0)n=`${t.table}.\`${n}\``;else{const t=n.split(".");n=`\`${t[0]}\`.\`${t[1]}\``}return n};let n,s="";if(t.entity){const e=this.metadata.entity[t.entity];for(let n in t.field)if(t.field[n].indexOf(".")>=0){const o=t.field[n].split(".")[0],a=e.join[o];if(a){s=` LEFT JOIN ${i.basic.fromCamelCase(a,"_")} AS ${o} ON ${o}.id = ${t.table}.${o} `}}}if(t.count)n="count(*)";else if(0===t.field.length)n="*";else{let i=[];for(let n in t.field){let s=e(t.field[n]);i.push(s)}n=i.join(",")}const o=[];let a="";if(t.term&&""!==t.term&&t.termRange){const e=[];for(let n in t.termRange)e.push(`\`${t.termRange[n]}\``);let n=this.connection.escape(`%${t.term}%`);a+=` WHERE CONCAT(${e.join(",")}) LIKE ${n}`}for(let n in t.parameter){let i=e(n);a+=""===a?` WHERE ${i} = ?`:` AND ${i} = ?`,o.push(t.parameter[n])}""===t.sort&&t.entity&&(t.sort=`${t.table}.createtime DESC`);let r=this.connection.escape(t.sort),c=""!==t.sort?` ORDER BY ${r.substr(1,r.length-2)}`:"";const l=t.count?"":` LIMIT ${t.top}, ${t.skip}`;let u=`SELECT ${n} FROM ${t.table}${s}${a}${c}${l}`,h=await this.sql(u,o);return t.count&&(h=h[0]?h[0]["count(*)"]:0),h}async insert({entity:t,table:e,data:n}){e=e||i.basic.fromCamelCase(t,"_"),n.id=n.id||i.basic.uuid(),n.createby=this.operator,n.createtime=i.basic.getTimestamp(),n.updateby=this.operator,n.updatetime=i.basic.getTimestamp();const s=[],o=[],a=[];for(let t in n){const e=i.basic.fromCamelCase(t,"_");s.push("`"+e+"`"),o.push("?"),a.push(n[t])}return await this.sql(`INSERT INTO ${e}(${s.join(",")}) VALUES(${o.join(",")})`,a),n.id}async update({entity:t,table:e,data:n}){e=e||i.basic.fromCamelCase(t,"_"),n.updateby=this.operator,n.updatetime=i.basic.getTimestamp();const s=[],o=[];let a;for(let t in n)if("id"===t)a=n[t];else{const e=i.basic.fromCamelCase(t,"_");s.push("`"+e+"` = ?"),o.push(n[t])}if(!a)throw{code:"DB_UPDATE_MISSING_ID",message:"数据库更新操作需要输入ID"};o.push(a),await this.sql(`UPDATE ${e} SET ${s} WHERE id = ?`,o)}async modify({entity:t,table:e,check:n,data:s}){e=e||i.basic.fromCamelCase(t,"_");const o={};for(let t in n)o[n[t]]=s[n[t]];const a=await this.select({table:e,field:["id"],parameter:o});let r;return a[0]?(r=a[0].id,s.id=r,await this.update({table:e,data:s})):r=await this.insert({table:e,data:s}),r}async ensure({entity:t,table:e,check:n,data:s}){e=e||i.basic.fromCamelCase(t,"_");const o={};for(let t in n)o[n[t]]=s[n[t]];const a=await this.select({table:e,field:["id"],parameter:o});let r;return r=a[0]?a[0].id:await this.insert({table:e,data:s})}async delete({entity:t,table:e,data:n}){e=e||i.basic.fromCamelCase(t,"_");const s=[];let o="";for(let t in n){o+=""===o?" WHERE":" AND",o+=` ${i.basic.fromCamelCase(t,"_")} = ?`,s.push(n[t])}await this.sql(`DELETE FROM ${e}${o}`,s)}async _connect(){this.connected=!0,await this.connection.connect(),await this.connection.beginTransaction()}async _disconnect(){this.connected&&(this.connected=!1,this.connection.release())}async rollback(){this.connected&&(await this.connection.rollback(),await this._disconnect())}async commit(){this.connected&&(await this.connection.commit(),await this._disconnect())}}},function(t,e,n){const i=n(22),s=n(23),o=n(27);t.exports=class{constructor(t){t.path=t.path||process.cwd()+"/cache.db";const e={serialize:e=>(function(t,e){const n=o.createCipher("aes192",e);var i=n.update(t,"utf8","hex");return i+=n.final("hex")})(JSON.stringify(e),t.password),deserialize:e=>JSON.parse(function(t,e){const n=o.createDecipher("aes192",e);var i=n.update(t,"hex","utf8");return i+=n.final("utf8")}(e,t.password))};let n;n=t.password?new s(t.path,e):new s(t.path),this.db=i(n)}async delete(t){this.db.unset(t).write()}async setVariable(t,e){this.db.set(t,e).write()}async getVariable(t){return this.db.get(t).value()}async setObject(t,e){this.db.set(t,e).write()}async getObject(t){return this.db.get(t).value()}async setObjectAttribute(t,e,n){this.db.set(t+"."+e,n).write()}async getObjectAttribute(t,e){return this.db.get(t+"."+e).value()}}},function(t,e){t.exports=require("lowdb")},function(t,e,n){"use strict";var i=function(){function t(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}return function(e,n,i){return n&&t(e.prototype,n),i&&t(e,i),e}}();var s=n(24),o=n(25),a=s.readFileSync,r=s.writeFileSync,c=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o),i(e,[{key:"read",value:function(){if(!s.existsSync(this.source))return r(this.source,this.serialize(this.defaultValue)),this.defaultValue;try{var t=a(this.source,"utf-8").trim();return t?this.deserialize(t):this.defaultValue}catch(t){throw t instanceof SyntaxError&&(t.message=`Malformed JSON in file: ${this.source}\n${t.message}`),t}}},{key:"write",value:function(t){return r(this.source,this.serialize(t))}}]),e}();t.exports=c},function(t,e){t.exports=require("graceful-fs")},function(t,e,n){"use strict";var i=n(26);t.exports=function t(e){var n=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=n.defaultValue,o=void 0===s?{}:s,a=n.serialize,r=void 0===a?i:a,c=n.deserialize,l=void 0===c?JSON.parse:c;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.source=e,this.defaultValue=o,this.serialize=r,this.deserialize=l}},function(t,e,n){"use strict";t.exports=function(t){return JSON.stringify(t,null,2)}},function(t,e){t.exports=require("crypto")},function(t,e,n){const i=n(29);t.exports=class{constructor(t){this.config=t||{}}async check(){if(!this.connection)try{this.connection=i.createClient({port:this.config.port,host:this.config.host,password:this.config.password}),await new Promise((t,e)=>{this.connection.on("connect",function(n,i){n?e(n):t(i)})}),this.connection.on("error",function(t){console.log("Redis db error: "+t)})}catch(t){console.log("cacheDB connect failed",t)}}async delete(t){return await this.check(),new Promise((e,n)=>{this.connection.del(t,function(t,i){t?n(t):e(i)})})}async setVariable(t,e){return await this.check(),new Promise((n,i)=>{this.connection.set(t,e,function(t,e){t?i(t):n(e)})})}async getVariable(t){return await this.check(),new Promise((e,n)=>{this.connection.get(t,function(t,i){t?n(t):e(i)})})}async setObject(t,e){await this.check();let n=[];for(let t in e)n.push(t),n.push(e[t]);return new Promise((e,i)=>{this.connection.hset(t,n,function(t,n){t?i(t):e(n)})})}async getObject(t){return await this.check(),new Promise((e,n)=>{this.connection.hgetall(t,function(t,i){t?n(t):e(i)})})}async setObjectAttribute(t,e,n){return await this.check(),new Promise((i,s)=>{this.connection.hset(t,[e,n],function(t,e){t?s(t):i(e)})})}async getObjectAttribute(t,e){return await this.check(),new Promise((n,i)=>{this.connection.hget(t,e,function(t,e){t?i(t):n(e)})})}}},function(t,e){t.exports=require("redis")},function(t,e){t.exports=require("ali-oss")},function(t,e){t.exports=class{constructor(){this.set({})}set({appId:t,userId:e,permission:n}){this.appId=t||"",this.userId=e||"",this.login=""!==this.appId||""!==this.userId,this.permission=n||[]}isUser(){return""!==this.userId}isApp(){return""!==this.appId}check(t,e){let n,i=!0,s="";const o=(t,e)=>{i=!1,""!==s&&(s+=","),s+=`${t} ${e}`};if("string"==typeof t)(n=this.has(t,e))||o(t,e);else for(let e in t){const i=t[e];"string"==typeof i?(n=this.has(i,""))||o(i,""):(n=this.has(i.key,i.value))||o(i.key,i.value)}if(!i)throw this.login?{code:"PERMISSION_DENIED",message:`没有访问该功能权限,请联系管理员。缺少权限:${s}`}:{code:"LOGIN_EXPIRED",message:"登陆授权失效,请重新登陆"};return i}has(t,e){e=e||"";let n=!1;for(let i in this.permission)this.permission[i].key===t&&this.permission[i].value===e&&(n=!0);return n}}},function(t,e,n){const i=n(2),s=n(3),o=n(33),a=n(34),r=new(n(1)),c=n(35).createProxyServer({changeOrigin:!0,xfwd:!0,toProxy:!0});c.on("error",(t,e,n)=>{n?"ECONNREFUSED"===t.code?n.finished||(n.writeHead(502,{"Content-Type":"text/html"}),n.end("网关错误")):n.finished||(n.writeHead(500,{"Content-Type":"text/html"}),n.end("内部错误")):console.log(t)}),t.exports=(async()=>{const t={},e={};let n={sites:[]};const l=()=>{let i;try{i=o.readFileSync(`${process.cwd()}/sites.json`,"utf8"),i=JSON.parse(i)}catch(t){return void console.log("配置文件读取异常")}n=i;for(let i in n.sites){const s=n.sites[i].domain;(!e[s]||(new Date).getTime()-e[s].updatetime>6e4)&&(e[s]={key:o.readFileSync(`./certs/${s}/${s}.key`,"utf8"),cert:o.readFileSync(`./certs/${s}/${s}.cer`,"utf8"),ca:o.readFileSync(`./certs/${s}/ca.cer`,"utf8"),updatetime:(new Date).getTime()}),t[s]=a.createSecureContext({key:e[s].key,cert:e[s].cert,ca:e[s].ca})}};l(),setInterval(()=>{l()},1e3);const u={SNICallback:function(e,n){const i=t[e]?t[e]:t.default;if(i){if(!n)return i;n(null,i)}else console.log("cert not found")}};r.use(async(t,e)=>{let n=(new Date).getTime();await e();let i=(new Date).getTime()-n;console.log(`[${t.method.toUpperCase()}] https://${t.header.host}${t.url} ${i}ms`)});const h={},f=(t,e)=>{h[t]=h[t]||0;const n=h[t];return h[t]++,e[n%e.length]};r.use(async(t,e)=>{for(let i in n.sites){let s=`https://${t.header.host}${t.url}`,o=`https://${n.sites[i].domain}`;if(s.length>=o.length&&o===s.substr(0,o.length))return t.respond=!1,void c.web(t.req,t.res,{target:f(i,n.sites[i].instance),ws:!0},e)}await e()}),r.use(t=>{t.body="找不到该应用,请确认访问地址是否正确"}),s.createServer(u,r.callback()).listen(443),i.createServer(function(t,e){let n=`https://${t.headers.host}${t.url}`;e.writeHead(301,{Location:n}),e.end()}).listen(80),console.log("站点服务器开始运行")})},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("tls")},function(t,e){t.exports=require("http-proxy")},function(t,e,n){const i=n(37),s=n(38),o=n(42);t.exports={Builder:class{constructor(t){this.root=t,this.history=new i(this.root)}async save(){const t=await this.history.list(),e=await this.history.load();let n=!1;if(0===t.length)n=!0;else{const i=await this.history.read(t[t.length-1]);JSON.stringify(e)!==JSON.stringify(i)&&(n=!0)}n&&await this.history.create(e)}async load(){return await this.history.load()}async generateSQL(){const t=await this.history.list();if(t.length>0)for(let e=0;e<t.length;e++){let n;0!==e&&(n=await this.history.read(t[e-1]));const i=await this.history.read(t[e]),o=s({pervious:n,current:i});t[e].sql=o}return t}async upgrade(t){const e=await this.generateSQL();await o(this.root,t,e)}}}},function(t,e,n){const i=n(0);t.exports=class{constructor(t){this.root=t,this.historyPath=`${t}/history`}async read(t){return await i.file.readJson(`${this.historyPath}/${t.filename}`)}async create(t){const e=i.basic.getTimestamp(),n=`${this.historyPath}/${e}.json`;await i.file.ensureFile(n),await i.file.writeFile(n,JSON.stringify(t))}async load(){return await i.file.readJson(`${this.root}/current.json`)}async list(){let t=[],e=await i.file.find("*",{cwd:this.historyPath});for(let n of e){let e=n.split(".");if(e.length>=2){let i=e[e.length-2];if("json"===e[e.length-1]){let e=parseInt(i);t.push({id:e,filename:n})}}}return t.sort(function(t,e){return t.id>e.id?1:-1}),t}}},function(t,e,n){const i=n(39),s=n(40),o=n(41);t.exports=(({pervious:t,current:e})=>{const n=i(t),a=i(e);let r="",c={};for(let t in a)"string"==typeof a[t]&&(c[a[t]]=t,r+=`ALTER TABLE ${t} RENAME TO ${a[t]};`+"\n");for(let t in n){let e;for(let n in c)c[n]===t&&(e=n);let n=e||t;a[n]||(r+=`DROP TABLE \`${n}\`;`+"\n")}for(let t in a)if("string"!=typeof a[t]){let e;(e=c[t]?n[c[t]]:n[t])?JSON.stringify(e)!==JSON.stringify(a[t])&&(r+=o(t,e,a[t])+"\n"):r+=s(t,a[t])+"\n"}return r})},function(t,e){const n=(t,e)=>{let n=[],i={};for(let t in e)if("string"==typeof e[t])i[t]=e[t];else{let s,o="",a=e[t].length||0,r=!0;void 0!==e[t].notNull&&(r=e[t].notNull);let c=e[t].default;switch(e[t].type){case"number":o="TINYINT",a>2&&(o="SMALLINT"),a>4&&(o="INT"),a>9&&(o="BIGINT"),e[t].decimal&&(o="DOUBLE"),a>19?(o="VARCHAR",s=e[t].length,void 0!==c&&null!==c||(c="")):void 0!==c&&null!==c||(c=0);break;case"string":o="CHAR",a>10&&(o="VARCHAR"),a>=1e3&&(o="TEXT"),a>=65535&&(o="MEDIUMTEXT"),a>=4294967295&&(o="LONGTEXT"),0===a&&(o="TEXT"),void 0!==c&&null!==c||(c=""),"CHAR"!==o&&"VARCHAR"!==o||(s=e[t].length)}i[t]={type:o,length:s,notNull:r,default:c},e[t].key&&n.push(t)}t.pk=n,t.column=i};t.exports=(t=>{let e={};if(t){if("string"==typeof t)try{t=JSON.parse(t)}catch(e){t={}}let i=t||{};for(let t in i)if("string"==typeof i[t])e[t]=i[t];else{let s;n(s={pk:[],column:{},engine:"InnoDB",charset:"utf8mb4"},i[t]),e[t]=s}}return e})},function(t,e,n){const i=n(8),s=n(9);t.exports=((t,e)=>{let n="",o="";s(e.column,(t,e)=>{""!==n&&(n+="\n"),n+=i(t,e)+","});for(let t in e.pk)""!==o&&(o+=","),o+="`"+e.pk[t]+"`";return`CREATE TABLE \`${t}\` (\n${n}\nPRIMARY KEY (${o}) USING BTREE\n) ENGINE=${e.engine} DEFAULT CHARSET=${e.charset};\n`})},function(t,e,n){const i=n(8),s=n(9);t.exports=((t,e,n)=>{let o="",a={};for(let s in n.column)if("string"==typeof n.column[s])if("string"==typeof e.column[s]);else{a[n.column[s]]=s;let e=n.column[n.column[s]];o+=`ALTER TABLE \`${t}\` CHANGE ${s} ${i(n.column[s],e)};`+"\n"}return s(e.column,(e,i)=>{if("string"!=typeof i){n.column[e]||(o+=`ALTER TABLE \`${t}\` DROP COLUMN ${e};`+"\n")}}),s(n.column,(n,s)=>{if("string"!=typeof s){let r=a[n]||n,c=e.column[r];c?s.type===c.type&&s.length===c.length||(o+=`ALTER TABLE \`${t}\` MODIFY ${i(n,s)};`+"\n"):o+=`ALTER TABLE \`${t}\` ADD COLUMN ${i(n,s)};`+"\n"}}),o})},function(t,e,n){const i=n(43),s=n(46);t.exports=(async(t,e,n)=>{const o=new i(e);if(await o.check()||await o.install(),n.length>0){let i=0,a=await o.getDB(),r=await a.connection();await r.query(`CREATE TABLE IF NOT EXISTS ${e.database}.__db ( name VARCHAR(32), value VARCHAR(100), primary key(name));`,[]);let c=await r.query("SELECT * FROM __db WHERE name = 'version'",[]);(c=c[0])&&(i=parseInt(c.value));let l=n[n.length-1].id;if(i>=l)console.log(`数据库已升级到最新版,当前版本:${i}`);else{0===i?console.log("数据库初始化中"):console.log(`数据库升级中,当前版本:${i}`);for(let t in n)if(n[t].id>i)if(""!==n[t].sql){let e=await o.execSQL(r,n[t].sql);if(e){console.log("升级失败,原因: "+e.message);break}await r.query("INSERT INTO __db(name,value) VALUES (?,?) ON DUPLICATE KEY UPDATE value = ?;",["version",n[t].id,n[t].id]),console.log(`成功升级版本${i}到${n[t].id},最新版为${l}`),i=n[t].id}else console.log(`该版本无升级项,跳过版本:${n[t].id}`);console.log(`数据库已升级到最新版,当前版本:${i}`)}let u=await s(t+"/view"),h=0;for(let t in u){let e=u[t].sql,n=await o.execSQL(r,e);n&&(console.log(`更新视图${u[t].name}失败,原因:${n.message}`),h++)}h>0?console.log(`更新视图失败数量:${h}`):u.length>0&&console.log(`更新视图完成,数量:${u.length}`),await r.release()}})},function(t,e,n){const i=n(44);n(0);t.exports=class{constructor(t){this.config=t}async check(){if(this.config){await this.getDB();let t=!0,e=await this.schemaDB.ping();if(e)switch(e.code){case"ER_BAD_DB_ERROR":t=!1;break;default:throw e}return t}throw"DB_CONNECT_FAILED"}async getDB(){return this.schemaDB||(this.schemaDB=new i(this.config)),this.schemaDB}async getRootDB(t){let e=JSON.parse(JSON.stringify(t));return delete e.database,new i(e)}async install(){let t=await this.getRootDB(this.config),e=await t.connection();await e.query(`CREATE DATABASE IF NOT EXISTS ${this.config.database} default charset utf8mb4 COLLATE utf8mb4_general_ci;`,[]),await e.release()}async uninstall(){let t=await this.getRootDB(this.config),e=await t.connection();await e.query(`DROP DATABASE IF EXISTS ${this.config.database};`,[]),await e.release()}async execSQL(t,e){let n;await t.beginTransaction();try{await t.query(e,[])}catch(t){n={code:t.code,message:t.sqlMessage}}return n?await t.rollback():await t.commit(),n}}},function(t,e,n){"use strict";const i=n(5),s=n(45);t.exports=class{constructor(t){if(!t)throw{code:"INVALID_MYSQL_CONFIG",message:"数据库配置不正确"};this.config=JSON.parse(JSON.stringify(t))}async queryTrace(t,e){let n=await this.connection(),i=await n.queryTrace(t,e);return await n.release(),i}async query(t,e){let n=await this.connection(),i=await n.query(t,e);return await n.release(),i}async ping(){try{await this.connection()}catch(t){return t}}async connection(){this.pool||(this.config.multipleStatements=!0,this.pool=i.createPool(this.config));let t=new s(this.pool);return await t.connect(),t}}},function(t,e){t.exports=class{constructor(t){this.pool=t}async connect(){this.session=await new Promise((t,e)=>{this.pool.getConnection(function(n,i){n?e(n):t(i)})})}async queryTrace(t,e){let n=(new Date).getTime(),i=await this.query(t,e),s=(new Date).getTime();return console.log(`[SQL Trace] ${t} ${s-n} ms`),console.log(JSON.stringify(i,null,4)),console.log(""),i}async query(t,e){return await new Promise((n,i)=>{this.session.query(t,e,function(t,e){t?i(t):n(e)})})}async release(){this.session.release()}async rollback(){return await new Promise(t=>{this.session.rollback(function(){t()})})}async beginTransaction(){return await new Promise(t=>{this.session.beginTransaction(function(){t()})})}async commit(){return await new Promise(t=>{this.session.commit(function(){t()})})}}},function(t,e,n){const i=n(0);t.exports=(async t=>{let e=[],n=await i.file.find("*",{cwd:t});for(let s of n){let n=s.split(".");if(n.length>=2){let o=n[n.length-2];"sql"===n[n.length-1]&&e.push({name:o,sql:await i.file.readFile(`${t}/${s}`,"utf-8")})}}return e})}]),global.dynamicRequire=require;var sumor_output=global.sumor_output;delete global.sumor_output,module.exports=sumor_output;
!function(t){var e={};function i(n){if(e[n])return e[n].exports;var s=e[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,i),s.l=!0,s.exports}i.m=t,i.c=e,i.d=function(t,e,n){i.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:n})},i.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return i.d(e,"a",e),e},i.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},i.p="",i(i.s=7)}([function(t,e){t.exports=require("koa")},function(t,e){t.exports=require("@sumor/utils")},function(t,e){t.exports=require("http")},function(t,e){t.exports=require("https")},function(t,e,i){const n=i(16),s=i(18);t.exports=class{constructor(t){if(t)switch(this.config=t,t.type=t.type||"mysql",t.type){case"mysql":this._instance=new n(t)}}open(){if(this._instance){const t=this._instance.new();return new s(t,this.config.metadata)}}}},function(t,e,i){const n=i(19),s=i(26);t.exports=class{constructor(t,e){switch(this.appid=t,this.config=e||{},this.config.type){case"redis":this.connection=new s(this.config);break;default:this.connection=new n(this.config)}}_namespace(t,e){return e=e&&""!==e?":"+e:"",`${this.appid}:${t}${e}`}async delete(t,e){return await this.connection.delete(this._namespace(t,e))}async setVariable(t,e,i){return await this.connection.setVariable(this._namespace(t,e),i)}async getVariable(t,e){return await this.connection.getVariable(this._namespace(t,e))}async setObject(t,e,i){return await this.connection.setObject(this._namespace(t,e),i)}async getObject(t,e){return await this.connection.getObject(this._namespace(t,e))}async setObjectAttribute(t,e,i,n){return await this.connection.setObjectAttribute(this._namespace(t,e),i,n)}async getObjectAttribute(t,e,i){return await this.connection.getObjectAttribute(this._namespace(t,e),i)}}},function(t,e,i){const n=i(28);t.exports=class{constructor(t){if(t)switch(t.type){case"aliyunOSS":this._instance=new class{constructor(t){this.aliyunOSS=new n(t)}async put(t,e){return await this.aliyunOSS.put(t,e)}async get(t){return await this.aliyunOSS.put(t)}}(t)}}async put(t,e){if(this._instance)return await this._instance.put(t,e);throw{code:"STORAGE_NOT_CONNECTED",message:"未配置存储服务器连接"}}async get(t){if(this._instance)return await this._instance.get(t);throw{code:"STORAGE_NOT_CONNECTED",message:"未配置存储服务器连接"}}}},function(t,e,i){t.exports=i(8)},function(t,e,i){global.sumor_output=i(9)},function(t,e,i){t.exports={Service:i(10),Site:i(30),SqlDB:i(4),CacheDB:i(5),Storage:i(6)}},function(t,e,i){const n=i(0),s=i(11),o=i(12),c=i(13),r=i(14),a=i(1),u=i(2),l=i(3),h=i(15),f=i(4),p=i(5),d=i(6),m=i(29);t.exports=class{constructor(t){this.config=t,this.config.serviceRoot=this.config.serviceRoot||"/service",this.config.port=this.config.port||(this.config.certs?443:80),this.init()}async callExit(t,e,i){i=i||{};const n=(this.config.exit||{})[t]||[];for(let t in n)await this.config.program[n[t]](e,i)}async init(){const t=new n;let e;if(this.config.certs){const i={key:this.config.certs.key,cert:this.config.certs.crt};e=l.createServer(i,t.callback())}else e=u.createServer(t.callback());const i=`${process.cwd()}/instanceid`;if(await a.file.exist(i)){let t=await a.file.readFile(i,"utf-8");this.instanceid=t.split("\n")[0]}console.log("正在初始化框架服务"),await this.listenService(t),console.log("初始化框架服务完成"),e.listen(this.config.port,()=>{console.log(`服务运行在端口: ${this.config.port}`)})}async initContext(){const t=process.cwd()+"/config.json";let e={};await a.file.exist(t)&&(e=await a.file.readJson(t)),e.SumorSqlDB&&await a.file.exist(`${process.cwd()}/db/entity.json`)&&(e.SumorSqlDB.metadata=await a.file.readJson(`${process.cwd()}/db/entity.json`)),this.db=new f(e.SumorSqlDB);const i=new d(e.SumorStorage),n=new p(this.config.appid,e.SumorCacheDB);this.context={appid:this.config.appid,config:e,storage:i,cacheDB:n,utils:a}}getContext(t){const e={};for(let t in this.context)e[t]=this.context[t];if(t)for(let i in t)e[i]=t[i];return e}async listenService(t){await this.initContext(),t.use(async(t,e)=>{this.instanceid&&t.set("sumor-instance",this.instanceid),await e()}),t.use(c()),t.use(r());const e=new o;e.get(this.config.serviceRoot+"/sumor/ping",t=>{t.body="OK"});for(let t in this.config.service){const i=this.config.service[t];e.all(`${this.config.serviceRoot}/${i.id}`,async t=>{const e=this.db.open(),n=t.request.headers["accept-language"].split(","),s=n[0],o=[];for(let t in n)o.push(n[t].split(";")[0]);const c=parseInt(t.request.headers["sumor-timezone"]),r=new m,u=this.getContext({db:e,service:i,language:s,languages:o,timezone:c,token:r,http:t}),l={};for(let e in t.query)l[e]=t.query[e];switch(t.method){case"POST":for(let e in t.request.body)l[e]=t.request.body[e]}const f={code:"OK"};try{await h(l,i),await this.callExit("beforeCall",l,u),r.check(i.permission);const t=await this.config.program[i.id](l,u);f.data=t,e&&await e.commit()}catch(t){console.error(t),e&&await e.rollback(),f.code=t.code||"ERROR",f.message=t.message}const p=Math.floor(a.basic.getTimestamp()-process.uptime());t.set("sumor-uptime",a.basic.formatTime(p,"yyyy-MM-dd hh:mm:ss",c)),t.body=f})}e.get(this.config.serviceRoot+"/*",t=>{t.body="找不到该服务"}),t.use(e.routes()).use(e.allowedMethods()),t.use(s({rootDir:process.cwd()+"/static",rootPath:"/",notFoundFile:"index.html",maxage:31536e6}));const i=this.db.open();await this.callExit("init",{},this.getContext({context:this.context,db:i}))}}},function(t,e){t.exports=require("koa-static-server")},function(t,e){t.exports=require("@koa/router")},function(t,e){t.exports=require("koa-logger")},function(t,e){t.exports=require("koa-bodyparser")},function(t,e){t.exports=((t,e)=>{const i=e.parameter;for(let e in i)switch(void 0===t[e]&&(t[e]=i[e].default),i[e].type){case"number":if("string"==typeof t[e])t[e]=parseFloat(t[e]);else if(null!==t[e]&&"number"!=typeof t[e])throw{code:"PARAMETER_INVALID",message:`参数${e}类型错误`};break;case"string":if("string"!=typeof t[e])throw{code:"PARAMETER_INVALID",message:`参数${e}类型错误`};break;case"array":case"object":if("string"==typeof t[e])try{t[e]=JSON.parse(t[e])}catch(t){throw{code:"PARAMETER_INVALID",message:`参数${e}数据格式异常`}}}})},function(t,e,i){const n=i(17);t.exports=class{constructor(t){if(!t)throw{code:"INVALID_MYSQL_CONFIG",message:"数据库配置不正确"};this.config=JSON.parse(JSON.stringify(t))}new(){return this.pool||(this.pool=n.createPool(this.config)),new class{constructor(t){this._pool=t}async connect(){this._connection=await new Promise((t,e)=>{this._pool.getConnection(function(i,n){i?e(i):t(n)})})}async query(t,e){return await new Promise((i,n)=>{this._connection.query(t,e,function(t,e){t?n(t):i(e)})})}escape(t){return n.escape(t)}async release(){this._connection.release()}async rollback(){return await new Promise(t=>{this._connection.rollback(function(){t()})})}async beginTransaction(){return await new Promise(t=>{this._connection.beginTransaction(function(){t()})})}async commit(){return await new Promise(t=>{this._connection.commit(function(){t()})})}}(this.pool)}}},function(t,e){t.exports=require("mysql")},function(t,e,i){const n=i(1);t.exports=class{constructor(t,e){this.connection=t,this.metadata=e,this.connected=!1,this.operator=""}setOperator(t){this.operator=t||""}async sql(t,e){return this.connected||await this._connect(),await this.connection.query(t,e)}async select(t){(t=t||{}).table=t.table||n.basic.fromCamelCase(t.entity,"_"),t.field=t.field||[],t.parameter=t.parameter||{},t.sort=t.sort||"",void 0===t.top&&(t.top=0),void 0===t.skip&&(t.skip=100);const e=e=>{let i=n.basic.fromCamelCase(e,"_");if(i.indexOf(".")<0)i=`${t.table}.\`${i}\``;else{const t=i.split(".");i=`\`${t[0]}\`.\`${t[1]}\``}return i};let i,s="";if(t.entity){const e=this.metadata[t.entity];for(let i in t.field)if(t.field[i].indexOf(".")>=0){const o=t.field[i].split(".")[0],c=e.join[o];if(c){s=` LEFT JOIN ${n.basic.fromCamelCase(c,"_")} AS ${o} ON ${o}.id = ${t.table}.${o} `}}}if(t.count)i="count(*)";else if(0===t.field.length)i="*";else{let n=[];for(let i in t.field){let s=e(t.field[i]);n.push(s)}i=n.join(",")}const o=[];let c="";if(t.term&&""!==t.term&&t.termRange){const e=[];for(let i in t.termRange)e.push(`\`${t.termRange[i]}\``);let i=this.connection.escape(`%${t.term}%`);c+=` WHERE CONCAT(${e.join(",")}) LIKE ${i}`}for(let i in t.parameter){let n=e(i);c+=""===c?` WHERE ${n} = ?`:` AND ${n} = ?`,o.push(t.parameter[i])}""===t.sort&&t.entity&&(t.sort=`${t.table}.createtime DESC`);let r=this.connection.escape(t.sort),a=""!==t.sort?` ORDER BY ${r.substr(1,r.length-2)}`:"";const u=t.count?"":` LIMIT ${t.top}, ${t.skip}`;let l=`SELECT ${i} FROM ${t.table}${s}${c}${a}${u}`,h=await this.sql(l,o);return t.count&&(h=h[0]?h[0]["count(*)"]:0),h}async insert({entity:t,table:e,data:i}){e=e||n.basic.fromCamelCase(t,"_"),i.id=i.id||n.basic.uuid(),i.createby=this.operator,i.createtime=n.basic.getTimestamp(),i.updateby=this.operator,i.updatetime=n.basic.getTimestamp();const s=[],o=[],c=[];for(let t in i){const e=n.basic.fromCamelCase(t,"_");s.push("`"+e+"`"),o.push("?"),c.push(i[t])}return await this.sql(`INSERT INTO ${e}(${s.join(",")}) VALUES(${o.join(",")})`,c),i.id}async update({entity:t,table:e,data:i}){e=e||n.basic.fromCamelCase(t,"_"),i.updateby=this.operator,i.updatetime=n.basic.getTimestamp();const s=[],o=[];let c;for(let t in i)if("id"===t)c=i[t];else{const e=n.basic.fromCamelCase(t,"_");s.push("`"+e+"` = ?"),o.push(i[t])}if(!c)throw{code:"DB_UPDATE_MISSING_ID",message:"数据库更新操作需要输入ID"};o.push(c),await this.sql(`UPDATE ${e} SET ${s} WHERE id = ?`,o)}async modify({entity:t,table:e,check:i,data:s}){e=e||n.basic.fromCamelCase(t,"_");const o={};for(let t in i)o[i[t]]=s[i[t]];const c=await this.select({table:e,field:["id"],parameter:o});let r;return c[0]?(r=c[0].id,s.id=r,await this.update({table:e,data:s})):r=await this.insert({table:e,data:s}),r}async ensure({entity:t,table:e,check:i,data:s}){e=e||n.basic.fromCamelCase(t,"_");const o={};for(let t in i)o[i[t]]=s[i[t]];const c=await this.select({table:e,field:["id"],parameter:o});let r;return r=c[0]?c[0].id:await this.insert({table:e,data:s})}async delete({entity:t,table:e,data:i}){e=e||n.basic.fromCamelCase(t,"_");const s=[];let o="";for(let t in i){o+=""===o?" WHERE":" AND",o+=` ${n.basic.fromCamelCase(t,"_")} = ?`,s.push(i[t])}await this.sql(`DELETE FROM ${e}${o}`,s)}async _connect(){this.connected=!0,await this.connection.connect(),await this.connection.beginTransaction()}async _disconnect(){this.connected&&(this.connected=!1,this.connection.release())}async rollback(){this.connected&&(await this.connection.rollback(),await this._disconnect())}async commit(){this.connected&&(await this.connection.commit(),await this._disconnect())}}},function(t,e,i){const n=i(20),s=i(21),o=i(25);t.exports=class{constructor(t){t.path=t.path||process.cwd()+"/cache.db";const e={serialize:e=>(function(t,e){const i=o.createCipher("aes192",e);var n=i.update(t,"utf8","hex");return n+=i.final("hex")})(JSON.stringify(e),t.password),deserialize:e=>JSON.parse(function(t,e){const i=o.createDecipher("aes192",e);var n=i.update(t,"hex","utf8");return n+=i.final("utf8")}(e,t.password))};let i;i=t.password?new s(t.path,e):new s(t.path),this.db=n(i)}async delete(t){this.db.unset(t).write()}async setVariable(t,e){this.db.set(t,e).write()}async getVariable(t){return this.db.get(t).value()}async setObject(t,e){this.db.set(t,e).write()}async getObject(t){return this.db.get(t).value()}async setObjectAttribute(t,e,i){this.db.set(t+"."+e,i).write()}async getObjectAttribute(t,e){return this.db.get(t+"."+e).value()}}},function(t,e){t.exports=require("lowdb")},function(t,e,i){"use strict";var n=function(){function t(t,e){for(var i=0;i<e.length;i++){var n=e[i];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,i,n){return i&&t(e.prototype,i),n&&t(e,n),e}}();var s=i(22),o=i(23),c=s.readFileSync,r=s.writeFileSync,a=function(t){function e(){return function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,e),function(t,e){if(!t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return!e||"object"!=typeof e&&"function"!=typeof e?t:e}(this,(e.__proto__||Object.getPrototypeOf(e)).apply(this,arguments))}return function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function, not "+typeof e);t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}),e&&(Object.setPrototypeOf?Object.setPrototypeOf(t,e):t.__proto__=e)}(e,o),n(e,[{key:"read",value:function(){if(!s.existsSync(this.source))return r(this.source,this.serialize(this.defaultValue)),this.defaultValue;try{var t=c(this.source,"utf-8").trim();return t?this.deserialize(t):this.defaultValue}catch(t){throw t instanceof SyntaxError&&(t.message=`Malformed JSON in file: ${this.source}\n${t.message}`),t}}},{key:"write",value:function(t){return r(this.source,this.serialize(t))}}]),e}();t.exports=a},function(t,e){t.exports=require("graceful-fs")},function(t,e,i){"use strict";var n=i(24);t.exports=function t(e){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},s=i.defaultValue,o=void 0===s?{}:s,c=i.serialize,r=void 0===c?n:c,a=i.deserialize,u=void 0===a?JSON.parse:a;!function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,t),this.source=e,this.defaultValue=o,this.serialize=r,this.deserialize=u}},function(t,e,i){"use strict";t.exports=function(t){return JSON.stringify(t,null,2)}},function(t,e){t.exports=require("crypto")},function(t,e,i){const n=i(27);t.exports=class{constructor(t){this.config=t||{}}async check(){if(!this.connection)try{this.connection=n.createClient({port:this.config.port,host:this.config.host,password:this.config.password}),await new Promise((t,e)=>{this.connection.on("connect",function(i,n){i?e(i):t(n)})}),this.connection.on("error",function(t){console.log("Redis db error: "+t)})}catch(t){console.log("cacheDB connect failed",t)}}async delete(t){return await this.check(),new Promise((e,i)=>{this.connection.del(t,function(t,n){t?i(t):e(n)})})}async setVariable(t,e){return await this.check(),new Promise((i,n)=>{this.connection.set(t,e,function(t,e){t?n(t):i(e)})})}async getVariable(t){return await this.check(),new Promise((e,i)=>{this.connection.get(t,function(t,n){t?i(t):e(n)})})}async setObject(t,e){await this.check();let i=[];for(let t in e)i.push(t),i.push(e[t]);return new Promise((e,n)=>{this.connection.hset(t,i,function(t,i){t?n(t):e(i)})})}async getObject(t){return await this.check(),new Promise((e,i)=>{this.connection.hgetall(t,function(t,n){t?i(t):e(n)})})}async setObjectAttribute(t,e,i){return await this.check(),new Promise((n,s)=>{this.connection.hset(t,[e,i],function(t,e){t?s(t):n(e)})})}async getObjectAttribute(t,e){return await this.check(),new Promise((i,n)=>{this.connection.hget(t,e,function(t,e){t?n(t):i(e)})})}}},function(t,e){t.exports=require("redis")},function(t,e){t.exports=require("ali-oss")},function(t,e){t.exports=class{constructor(){this.set({})}set({appId:t,userId:e,permission:i}){this.appId=t||"",this.userId=e||"",this.login=""!==this.appId||""!==this.userId,this.permission=i||[]}isUser(){return""!==this.userId}isApp(){return""!==this.appId}check(t,e){let i,n=!0,s="";const o=(t,e)=>{n=!1,""!==s&&(s+=","),s+=`${t} ${e}`};if("string"==typeof t)(i=this.has(t,e))||o(t,e);else for(let e in t){const n=t[e];"string"==typeof n?(i=this.has(n,""))||o(n,""):(i=this.has(n.key,n.value))||o(n.key,n.value)}if(!n)throw this.login?{code:"PERMISSION_DENIED",message:`没有访问该功能权限,请联系管理员。缺少权限:${s}`}:{code:"LOGIN_EXPIRED",message:"登陆授权失效,请重新登陆"};return n}has(t,e){e=e||"";let i=!1;for(let n in this.permission)this.permission[n].key===t&&this.permission[n].value===e&&(i=!0);return i}}},function(t,e,i){const n=i(2),s=i(3),o=i(31),c=i(32),r=new(i(0)),a=i(33).createProxyServer({changeOrigin:!0,xfwd:!0,toProxy:!0});a.on("error",(t,e,i)=>{i?"ECONNREFUSED"===t.code?i.finished||(i.writeHead(502,{"Content-Type":"text/html"}),i.end("网关错误")):i.finished||(i.writeHead(500,{"Content-Type":"text/html"}),i.end("内部错误")):console.log(t)}),t.exports=(async()=>{const t={},e={};let i={sites:[]};const u=()=>{let n;try{n=o.readFileSync(`${process.cwd()}/sites.json`,"utf8"),n=JSON.parse(n)}catch(t){return void console.log("配置文件读取异常")}i=n;for(let n in i.sites){const s=i.sites[n].domain;(!e[s]||(new Date).getTime()-e[s].updatetime>6e4)&&(e[s]={key:o.readFileSync(`./certs/${s}/${s}.key`,"utf8"),cert:o.readFileSync(`./certs/${s}/${s}.cer`,"utf8"),ca:o.readFileSync(`./certs/${s}/ca.cer`,"utf8"),updatetime:(new Date).getTime()}),t[s]=c.createSecureContext({key:e[s].key,cert:e[s].cert,ca:e[s].ca})}};u(),setInterval(()=>{u()},1e3);const l={SNICallback:function(e,i){const n=t[e]?t[e]:t.default;if(n){if(!i)return n;i(null,n)}else console.log("cert not found")}};r.use(async(t,e)=>{let i=(new Date).getTime();await e();let n=(new Date).getTime()-i;console.log(`[${t.method.toUpperCase()}] https://${t.header.host}${t.url} ${n}ms`)});const h={},f=(t,e)=>{h[t]=h[t]||0;const i=h[t];return h[t]++,e[i%e.length]};r.use(async(t,e)=>{for(let n in i.sites){let s=`https://${t.header.host}${t.url}`,o=`https://${i.sites[n].domain}`;if(s.length>=o.length&&o===s.substr(0,o.length))return t.respond=!1,void a.web(t.req,t.res,{target:f(n,i.sites[n].instance),ws:!0},e)}await e()}),r.use(t=>{t.body="找不到该应用,请确认访问地址是否正确"}),s.createServer(l,r.callback()).listen(443),n.createServer(function(t,e){let i=`https://${t.headers.host}${t.url}`;e.writeHead(301,{Location:i}),e.end()}).listen(80),console.log("站点服务器开始运行")})},function(t,e){t.exports=require("fs")},function(t,e){t.exports=require("tls")},function(t,e){t.exports=require("http-proxy")}]),global.dynamicRequire=require;var sumor_output=global.sumor_output;delete global.sumor_output,module.exports=sumor_output;
{
"name": "@sumor/app",
"version": "11.0.4",
"version": "11.0.5",
"description": "",

@@ -8,3 +8,3 @@ "main": "index.js",

"@koa/router": "^8.0.0",
"@sumor/utils": "11.0.4",
"@sumor/utils": "11.0.5",
"axios": "^0.19.0",

@@ -11,0 +11,0 @@ "koa": "^2.8.1",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc