befly 3.15.7 → 3.15.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/befly.js +13 -2
- package/dist/befly.min.js +3 -3
- package/dist/sync/syncTable.js +18 -2
- package/package.json +2 -2
package/dist/befly.js
CHANGED
|
@@ -10232,6 +10232,9 @@ class SyncTable {
|
|
|
10232
10232
|
}
|
|
10233
10233
|
if (cBase === "varchar" && (nBase === "text" || nBase === "mediumtext" || nBase === "longtext"))
|
|
10234
10234
|
return true;
|
|
10235
|
+
if (cBase === "char" && nBase === "varchar" || cBase === "varchar" && nBase === "char") {
|
|
10236
|
+
return true;
|
|
10237
|
+
}
|
|
10235
10238
|
return false;
|
|
10236
10239
|
}
|
|
10237
10240
|
static compareFieldDefinition(existingColumn, fieldDef) {
|
|
@@ -10458,11 +10461,19 @@ class SyncTable {
|
|
|
10458
10461
|
const typeMapping = SyncTable.getTypeMapping();
|
|
10459
10462
|
const expectedType = typeMapping[fieldDef.type]?.toLowerCase() || "";
|
|
10460
10463
|
if (!SyncTable.isCompatibleTypeChange(currentType, expectedType)) {
|
|
10461
|
-
const errorMsg = [`\u7981\u6B62\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4: ${tableName}.${dbFieldName}`, `\u5F53\u524D\u7C7B\u578B: ${typeChange?.current}`, `\u76EE\u6807\u7C7B\u578B: ${typeChange?.expected}`, "\u8BF4\u660E: \u4EC5\u5141\u8BB8\u5BBD\u5316\u578B\u53D8\u66F4\uFF08\u5982 INT->BIGINT, VARCHAR->TEXT\uFF09\uFF0C\u5176\u4ED6\u7C7B\u578B\u53D8\u66F4\u9700\u8981\u624B\u52A8\u5904\u7406"].join(`
|
|
10464
|
+
const errorMsg = [`\u7981\u6B62\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4: ${tableName}.${dbFieldName}`, `\u5F53\u524D\u7C7B\u578B: ${typeChange?.current}`, `\u76EE\u6807\u7C7B\u578B: ${typeChange?.expected}`, "\u8BF4\u660E: \u4EC5\u5141\u8BB8\u5BBD\u5316\u578B\u53D8\u66F4\uFF08\u5982 INT->BIGINT, VARCHAR->TEXT\uFF09\uFF0C\u4EE5\u53CA CHAR/VARCHAR \u4E92\u8F6C\uFF1B\u5176\u4ED6\u7C7B\u578B\u53D8\u66F4\u9700\u8981\u624B\u52A8\u5904\u7406"].join(`
|
|
10462
10465
|
`);
|
|
10463
10466
|
throw new Error(errorMsg);
|
|
10464
10467
|
}
|
|
10465
|
-
|
|
10468
|
+
let compatLabel = "";
|
|
10469
|
+
if (currentType === "char" && expectedType === "varchar" || currentType === "varchar" && expectedType === "char") {
|
|
10470
|
+
compatLabel = "char/varchar\u4E92\u8F6C";
|
|
10471
|
+
}
|
|
10472
|
+
if (compatLabel) {
|
|
10473
|
+
compatibleTypeChanges.push(`${dbFieldName}: ${currentType} -> ${expectedType} (${compatLabel})`);
|
|
10474
|
+
} else {
|
|
10475
|
+
compatibleTypeChanges.push(`${dbFieldName}: ${currentType} -> ${expectedType}`);
|
|
10476
|
+
}
|
|
10466
10477
|
}
|
|
10467
10478
|
if (defaultChanged) {
|
|
10468
10479
|
const actualDefault = SyncTable.resolveDefaultValue(fieldDef.default ?? null, fieldDef.type);
|
package/dist/befly.min.js
CHANGED
|
@@ -3,11 +3,11 @@ var Z1=Object.create;var{getPrototypeOf:Y1,defineProperty:yY,getOwnPropertyNames
|
|
|
3
3
|
`)}catch{}}function B1($,J){let Z=[],Y=0;while($.length>0){let X=$[0],G=Buffer.byteLength(X);if(Z.length>0&&Y+G>J)break;Z.push(X),Y=Y+G,$.shift()}return{chunk:Z.join(""),bytes:Y}}class qZ{pending;pendingBytes;scheduledTimer;flushing;maxBufferBytes;flushDelayMs;maxBatchBytes;writeChunk;onShutdown;constructor($){this.pending=[],this.pendingBytes=0,this.scheduledTimer=null,this.flushing=!1,this.maxBufferBytes=$.maxBufferBytes,this.flushDelayMs=$.flushDelayMs,this.maxBatchBytes=$.maxBatchBytes,this.writeChunk=$.writeChunk,this.onShutdown=$.onShutdown?$.onShutdown:null}scheduleFlush(){if(this.scheduledTimer)return;this.scheduledTimer=setTimeout(()=>{this.scheduledTimer=null,this.flush()},this.flushDelayMs)}cancelScheduledFlush(){if(!this.scheduledTimer)return;clearTimeout(this.scheduledTimer),this.scheduledTimer=null}enqueue($){let J=Buffer.byteLength($);if(this.pendingBytes+J>this.maxBufferBytes)return;this.pending.push($),this.pendingBytes=this.pendingBytes+J,this.scheduleFlush()}async flushNow(){this.cancelScheduledFlush(),await this.flush()}async shutdown(){if(this.cancelScheduledFlush(),await this.flush(),this.onShutdown)await this.onShutdown()}async flush(){if(this.flushing)return;this.flushing=!0;try{while(this.pending.length>0){let J=B1(this.pending,this.maxBatchBytes).chunk,Z=Buffer.byteLength(J);if(this.pendingBytes=this.pendingBytes-Z,!await this.writeChunk(J,Z)){this.pending=[],this.pendingBytes=0;break}}}finally{if(this.flushing=!1,this.pending.length>0)this.scheduleFlush()}}}function P1($){let J=()=>{return $==="stderr"?process.stderr:process.stdout},Z=new qZ({maxBufferBytes:10485760,flushDelayMs:10,maxBatchBytes:65536,writeChunk:async(Y)=>{try{let X=J();if(!X.write(Y))await new Promise((Q)=>{X.once("drain",()=>Q())});return!0}catch(X){return MJ(`[Logger] stream sink error: ${X?.message||X}`),!1}}});return{enqueue(Y){Z.enqueue(Y)},async flushNow(){await Z.flushNow()},async shutdown(){await Z.shutdown()}}}class RZ{prefix;maxFileBytes;buffer;stream;streamDate;streamIndex;streamSizeBytes;disabled;constructor($){this.prefix=$.prefix,this.maxFileBytes=$.maxFileBytes,this.stream=null,this.streamDate="",this.streamIndex=0,this.streamSizeBytes=0,this.disabled=!1,this.buffer=new qZ({maxBufferBytes:10485760,flushDelayMs:10,maxBatchBytes:65536,writeChunk:async(J,Z)=>{if(this.disabled)return!1;try{if(await this.ensureStreamReady(Z),!this.stream)return!1;if(!this.stream.write(J))await new Promise((X)=>{let G=this.stream;if(!G){X();return}G.once("drain",()=>X())});return this.streamSizeBytes=this.streamSizeBytes+Z,!0}catch(Y){return MJ(`[Logger] file sink flush error (${this.prefix}): ${Y?.message||Y}`),this.disabled=!0,await this.closeStream(),!1}},onShutdown:async()=>{await this.closeStream()}})}enqueue($){if(this.disabled)return;this.buffer.enqueue($)}async flushNow(){await this.buffer.flushNow()}async shutdown(){await this.buffer.shutdown()}async closeStream(){if(!this.stream)return;let $=this.stream;this.stream=null,await new Promise((J)=>{try{$.end(()=>J())}catch{J()}})}openStream($){try{this.stream=O1($,{flags:"a"}),this.stream.on("error",(J)=>{MJ(`[Logger] file sink error (${this.prefix}): ${J?.message||J}`),this.disabled=!0,this.closeStream()})}catch(J){MJ(`[Logger] createWriteStream failed (${this.prefix}): ${J?.message||J}`),this.disabled=!0,this.stream=null}}getFilePath($,J){let Z=J>0?`.${J}`:"",Y=`${this.prefix}.${$}${Z}.log`;return I1(iY(),Y)}async ensureStreamReady($){let J=WZ(new Date,"date");if(this.stream&&this.streamDate&&J!==this.streamDate)await this.closeStream(),this.streamDate="",this.streamIndex=0,this.streamSizeBytes=0;if(!this.stream){let Z=this.getFilePath(J,0),Y=0;try{let X=await K1(Z);Y=typeof X.size==="number"?X.size:0}catch{Y=0}if(this.streamDate=J,this.streamIndex=0,this.streamSizeBytes=Y,this.openStream(Z),!this.stream)return}if(this.stream&&this.maxFileBytes>0&&this.streamSizeBytes+$>this.maxFileBytes){await this.closeStream(),this.streamIndex=this.streamIndex+1;let Z=this.getFilePath(J,this.streamIndex);if(this.streamDate=J,this.streamSizeBytes=0,this.openStream(Z),!this.stream)return}}}async function E1(){if(S$)return;let $=[];if(Y$)$.push({flush:()=>Y$?Y$.flushNow():Promise.resolve()});if(X$)$.push({flush:()=>X$?X$.flushNow():Promise.resolve()});if(G$)$.push({flush:()=>G$?G$.flushNow():Promise.resolve()});for(let J of $)try{await J.flush()}catch{}}async function rY(){if(S$)return;let $=R$,J=I$,Z=Y$,Y=X$,X=G$,G=[];if(Z)G.push({shutdown:()=>Z.shutdown()});if(Y)G.push({shutdown:()=>Y.shutdown()});if(X)G.push({shutdown:()=>X.shutdown()});for(let Q of G)try{await Q.shutdown()}catch{}if(Y$===Z)Y$=null;if(X$===Y)X$=null;if(G$===X)G$=null;if(R$===$)R$=null;if(I$===J)I$=null}function iY(){let $=n0.dir||"./logs";if(R1($))return $;return q1(L1,$)}function C1(){let $=iY();try{if(!M1($))A1($,{recursive:!0})}catch(J){throw Error(`\u521B\u5EFA logs \u76EE\u5F55\u5931\u8D25: ${$}. ${J?.message||J}`)}}function S1($){rY(),n0=Object.assign({debug:0,dir:"./logs",console:1,maxSize:20},$);{let J=n0.maxSize,Z=typeof J==="number"&&Number.isFinite(J)?J:20;if(Z<10)Z=10;if(Z>100)Z=100;n0.maxSize=Z}R$=null,I$=null,Y$=null,X$=null,G$=null,IZ={maxStringLen:k$(n0.maxStringLen,100,20,200000),maxArrayItems:k$(n0.maxArrayItems,100,10,5000),sanitizeDepth:k$(n0.sanitizeDepth,3,1,10),sanitizeNodes:k$(n0.sanitizeNodes,500,50,20000),sanitizeObjectKeys:k$(n0.sanitizeObjectKeys,100,10,5000),sensitiveKeyMatcher:MZ({builtinPatterns:lY,userPatterns:n0.excludeFields})}}function w1($){S$=$}function a$($){if(S$)return S$;if($==="app"){if(R$)return R$}else if(I$)return I$;C1();let J=typeof n0.maxSize==="number"?n0.maxSize:20,Z=Math.floor(J*1024*1024);if($==="app"){if(!Y$)Y$=new RZ({prefix:"app",maxFileBytes:Z});if(n0.console===1&&!G$)G$=P1("stdout");return R$=oY({fileSink:Y$,consoleSink:n0.console===1?G$:null}),R$}if(!X$)X$=new RZ({prefix:"error",maxFileBytes:Z});return I$=oY({fileSink:X$,consoleSink:null}),I$}function T1($,J){let Z=Date.now(),Y={level:$,time:Z,timeFormat:WZ(new Date(Z)),pid:process.pid,hostname:j1};if(J&&n(J)){let X=Object.assign({},J,Y);if(J.msg!==void 0)X.msg=J.msg;else if(X.msg===void 0)X.msg="";return`${sY(X)}
|
|
4
4
|
`}if(Y.msg===void 0)Y.msg="";return`${sY(Y)}
|
|
5
5
|
`}function sY($){try{return JSON.stringify($)}catch{try{return JSON.stringify({level:$.level,time:$.time,pid:$.pid,hostname:$.hostname,msg:"[Unserializable log record]"})}catch{return'{"msg":"[Unserializable log record]"}'}}}function oY($){let{fileSink:J,consoleSink:Z}=$,Y=(X,G)=>{if(X==="debug"&&n0.debug!==1)return;let Q=n(G)?G:{value:G},U=KZ(Q,IZ),z=T1(X,U);if(J.enqueue(z),Z)Z.enqueue(z)};return{info(X){Y("info",X)},warn(X){Y("warn",X)},error(X){Y("error",X)},debug(X){Y("debug",X)}}}function N1(){let $=nY();if(!$)return null;let J=Date.now()-$.now,Z={requestId:$.requestId,method:$.method,route:$.route,ip:$.ip,now:$.now,durationSinceNowMs:J};return Z.userId=$.userId,Z.roleCode=$.roleCode,Z.nickname=$.nickname,Z.roleType=$.roleType,Z}function D1($,J){let Z={};for(let X of Object.keys($))Z[X]=$[X];let Y=["requestId","method","route","ip","now","durationSinceNowMs","userId","roleCode","nickname","roleType"];for(let X of Y)if(Z[X]===void 0)Z[X]=J[X];return Z}function _J($){if(n($))return $;if($ instanceof Error)return{err:$,msg:$.message||$.name||"Error"};if($===void 0)return{msg:""};if($===null)return{msg:"null"};if(typeof $==="object")return{value:$};try{return{msg:String($)}}catch{return{msg:"[Unserializable]"}}}function OJ($){let J=N1();if(!J)return $;return D1($,J)}class tY{maybeSanitizeForMock($){if(!S$)return $;return KZ($,IZ)}info($){let J=OJ(_J($)),Z=this.maybeSanitizeForMock(J);a$("app").info(Z)}warn($){let J=OJ(_J($)),Z=this.maybeSanitizeForMock(J);a$("app").warn(Z)}error($){let J=OJ(_J($)),Z=this.maybeSanitizeForMock(J);if(a$("app").error(Z),S$)return;a$("error").error(Z)}debug($){if(n0.debug!==1)return;let J=OJ(_J($)),Z=this.maybeSanitizeForMock(J);a$("app").debug(Z)}async flush(){await E1()}configure($){S1($)}setMock($){w1($)}async shutdown(){await rY()}}var L1,lY,IZ,j1,R$=null,I$=null,S$=null,Y$=null,X$=null,G$=null,n0,L;var $0=z$(()=>{uY();m0();zJ();L1=process.cwd(),lY=["*password*","pass","pwd","*token*","access_token","refresh_token","accessToken","refreshToken","authorization","cookie","set-cookie","*secret*","apiKey","api_key","privateKey","private_key"],IZ={maxStringLen:100,maxArrayItems:100,sanitizeDepth:3,sanitizeNodes:500,sanitizeObjectKeys:100,sensitiveKeyMatcher:MZ({builtinPatterns:lY,userPatterns:[]})},j1=(()=>{try{return F1()}catch{return"unknown"}})(),n0={debug:0,dir:"./logs",console:1,maxSize:20};L=new tY});import{isAbsolute as v1}from"path";import{pathToFileURL as k1}from"url";function x1($){return/^[a-zA-Z]:[\\/]/.test($)}function f1($){if(v1($)||x1($))return k1($).href;return $}async function q$($,J){try{let X=($.endsWith(".json")?await import(f1($),{with:{type:"json"}}):await import($))?.default;if(X===null||X===void 0)return J;let G=UZ(J),Q=UZ(X);if(G!==Q)return L.warn({file:$,msg:"importDefault \u5BFC\u5165\u7C7B\u578B\u4E0E\u9ED8\u8BA4\u503C\u4E0D\u4E00\u81F4\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u503C",expectedType:G,actualType:Q}),J;return X}catch(Z){return L.warn({err:Z,file:$,msg:"importDefault \u5BFC\u5165\u5931\u8D25\uFF0C\u5DF2\u56DE\u9000\u5230\u9ED8\u8BA4\u503C"}),J}}var AJ=z$(()=>{$0();m0()});function $J($=""){if(!$)return $;return $.replace(/\\/g,"/").replace(u1,(J)=>J.toUpperCase())}function o1(){if(typeof process<"u"&&typeof process.cwd==="function")return process.cwd().replace(/\\/g,"/");return"/"}function BZ($,J){let Z="",Y=0,X=-1,G=0,Q=null;for(let U=0;U<=$.length;++U){if(U<$.length)Q=$[U];else if(Q==="/")break;else Q="/";if(Q==="/"){if(X===U-1||G===1);else if(G===2){if(Z.length<2||Y!==2||Z[Z.length-1]!=="."||Z[Z.length-2]!=="."){if(Z.length>2){let z=Z.lastIndexOf("/");if(z===-1)Z="",Y=0;else Z=Z.slice(0,z),Y=Z.length-1-Z.lastIndexOf("/");X=U,G=0;continue}else if(Z.length>0){Z="",Y=0,X=U,G=0;continue}}if(J)Z+=Z.length>0?"/..":"..",Y=2}else{if(Z.length>0)Z+=`/${$.slice(X+1,U)}`;else Z=$.slice(X+1,U);Y=U-X-1}X=U,G=0}else if(Q==="."&&G!==-1)++G;else G=-1}return Z}var u1,m1,n1,QX,GX,d1,s1,w$=function($){if($.length===0)return".";$=$J($);let J=$.match(m1),Z=f$($),Y=$[$.length-1]==="/";if($=BZ($,!Z),$.length===0){if(Z)return"/";return Y?"./":"."}if(Y)$+="/";if(QX.test($))$+="/";if(J){if(!Z)return`//./${$}`;return`//${$}`}return Z&&!f$($)?`/${$}`:$},s=function(...$){let J="";for(let Z of $){if(!Z)continue;if(J.length>0){let Y=J[J.length-1]==="/",X=Z[0]==="/";if(Y&&X)J+=Z.slice(1);else J+=Y||X?Z:`/${Z}`}else J+=Z}return w$(J)},e$=function(...$){$=$.map((Y)=>$J(Y));let J="",Z=!1;for(let Y=$.length-1;Y>=-1&&!Z;Y--){let X=Y>=0?$[Y]:o1();if(!X||X.length===0)continue;J=`${X}/${J}`,Z=f$(X)}if(J=BZ(J,!Z),Z&&!f$(J))return`/${J}`;return J.length>0?J:"."},f$=function($){return n1.test($)},HX=function($){if($==="..")return"";let J=d1.exec($J($));return J&&J[1]||""},PZ=function($,J){let Z=e$($).replace(GX,"$1").split("/"),Y=e$(J).replace(GX,"$1").split("/");if(Y[0][1]===":"&&Z[0][1]===":"&&Z[0]!==Y[0])return Y.join("/");let X=[...Z];for(let G of X){if(Y[0]!==G)break;Z.shift(),Y.shift()}return[...Z.map(()=>".."),...Y].join("/")},KJ=function($){let J=$J($).replace(/\/$/,"").split("/").slice(0,-1);if(J.length===1&&QX.test(J[0]))J[0]+="/";return J.join("/")||(f$($)?"/":".")},WX=function($,J){let Z=$J($).split("/"),Y="";for(let X=Z.length-1;X>=0;X--){let G=Z[X];if(G){Y=G;break}}return J&&Y.endsWith(J)?Y.slice(0,-J.length):Y},JJ=function($){let J=s1.exec($)?.[0]?.replace(/\\/g,"/")||"",Z=WX($),Y=HX(Z);return{root:J,dir:KJ($),base:Z,ext:Y,name:Z.slice(0,Z.length-Y.length)}};var UX=z$(()=>{u1=/^[A-Za-z]:\//;m1=/^[/\\]{2}/,n1=/^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Za-z]:[/\\]/,QX=/^[A-Za-z]:$/,GX=/^\/([A-Za-z]:)?$/,d1=/.(\.[^./]+|\.)$/,s1=/^[/\\]|^[a-zA-Z]:[/\\]/});var L$=z$(()=>{UX()});import{statSync as l1}from"fs";var FJ=($,J)=>{if(J.isDirectory())return!0;if(!J.isSymbolicLink())return!1;try{return l1(s($,J.name)).isDirectory()}catch{return!1}};var EZ=z$(()=>{L$()});import{existsSync as y$}from"fs";import{readdir as r1}from"fs/promises";function i1($){if(!$||typeof $!=="object")return null;let J=$,Z=J.title;if(typeof Z!=="string"||!Z)return null;let Y=J.order,X=typeof Y==="number"&&Number.isFinite(Y)&&Number.isInteger(Y)&&Y>=0?Y:void 0;if(X===void 0)return{title:Z};return{title:Z,order:X}}async function VX($,J,Z=""){if(!y$($))return[];let Y=[],X=await r1($,{withFileTypes:!0});for(let G of X){if(!FJ($,G)||G.name==="components")continue;let Q=s($,G.name),U=s(Q,"meta.json"),z=s(Q,"index.vue"),O=null;if(!y$(U))continue;if(!y$(z)){L.warn({path:Q,msg:"\u76EE\u5F55\u5B58\u5728 meta.json \u4F46\u7F3A\u5C11 index.vue\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u5F55\u83DC\u5355\u540C\u6B65"});continue}let _=await q$(U,{});if(O=i1(_),!O?.title){L.warn({path:U,msg:"meta.json \u7F3A\u5C11\u6709\u6548\u7684 title\uFF08\u4EE5\u53CA\u53EF\u9009 order:number\uFF09\uFF0C\u5DF2\u8DF3\u8FC7\u8BE5\u76EE\u5F55\u83DC\u5355\u540C\u6B65"});continue}if(!O?.title)continue;let K=String(G.name).replace(/_\d+$/,""),j;if(K==="index")j=Z;else j=Z?`${Z}/${K}`:`/${K}`;let C=J?j?`${J}${j}`:J:j||"/",S={name:O.title,path:C,sort:O.order??999999},v=await VX(Q,J,j);if(v.length>0)S.children=v;Y.push(S)}return Y.sort((G,Q)=>(G.sort??999999)-(Q.sort??999999)),Y}function zX($){let J=$.split("/").filter((Z)=>Boolean(Z));if(J.length<=1)return"";return`/${J.slice(0,-1).join("/")}`}async function _X($){let J=[];for(let Y of $){let X=s(Y.fullPath,"adminViews"),G=s(Y.fullPath,"views","admin"),Q=y$(X)?X:y$(G)?G:null;if(!Q)continue;try{let U=`/${Y.source}/${Y.name}`,z=await VX(Q,U);if(z.length>0)for(let O of z)J.push(O)}catch(U){L.warn({err:U,addon:Y.name,addonSource:Y.source,dir:Q,msg:"\u626B\u63CF addon views \u76EE\u5F55\u5931\u8D25"})}}let Z=s(process.cwd(),"menus.json");if(y$(Z)){let Y=await q$(Z,[]);if(Array.isArray(Y)&&Y.length>0)for(let X of Y)J.push(X)}return J}var CZ=z$(()=>{L$();$0();AJ();EZ()});var u$=l((D5,QG)=>{var GG={invalidType:"FAST_JWT_INVALID_TYPE",invalidOption:"FAST_JWT_INVALID_OPTION",invalidAlgorithm:"FAST_JWT_INVALID_ALGORITHM",invalidClaimType:"FAST_JWT_INVALID_CLAIM_TYPE",invalidClaimValue:"FAST_JWT_INVALID_CLAIM_VALUE",invalidKey:"FAST_JWT_INVALID_KEY",invalidSignature:"FAST_JWT_INVALID_SIGNATURE",invalidPayload:"FAST_JWT_INVALID_PAYLOAD",malformed:"FAST_JWT_MALFORMED",inactive:"FAST_JWT_INACTIVE",expired:"FAST_JWT_EXPIRED",missingKey:"FAST_JWT_MISSING_KEY",keyFetchingError:"FAST_JWT_KEY_FETCHING_ERROR",signError:"FAST_JWT_SIGN_ERROR",verifyError:"FAST_JWT_VERIFY_ERROR",missingRequiredClaim:"FAST_JWT_MISSING_REQUIRED_CLAIM",missingSignature:"FAST_JWT_MISSING_SIGNATURE"};class p$ extends Error{constructor($,J,Z){super(J);if(Error.captureStackTrace(this,this.constructor),this.code=$,Z)for(let Y in Z)this[Y]=Z[Y]}}p$.codes=GG;p$.wrap=function($,J,Z){if($ instanceof p$)return $;return new p$(J,Z,{originalError:$})};QG.exports={TokenError:p$,TOKEN_ERROR_CODES:GG}});var pZ=l((v5,HG)=>{var{TokenError:W$}=u$();function zW({complete:$,checkTyp:J},Z){if(Z instanceof Buffer)Z=Z.toString("utf-8");else if(typeof Z!=="string")throw new W$(W$.codes.invalidType,"The token must be a string or a buffer.");let Y=Z.indexOf("."),X=Z.lastIndexOf(".");if(Y===-1||Y>=X)throw new W$(W$.codes.malformed,"The token is malformed.");let G=!1;try{let Q=JSON.parse(Buffer.from(Z.slice(0,Y),"base64").toString("utf-8"));if(J&&Q.typ!==J)throw new W$(W$.codes.invalidType,`The type must be "${J}".`,{header:Q});G=!0;let U=Buffer.from(Z.slice(Y+1,X),"base64").toString("utf-8");if(U=JSON.parse(U),!U||typeof U!=="object")throw new W$(W$.codes.invalidPayload,"The payload must be an object",{payload:U});return $?{header:Q,payload:U,signature:Z.slice(X+1),input:Z.slice(0,X)}:U}catch(Q){throw W$.wrap(Q,W$.codes.malformed,`The token ${G?"payload":"header"} is not a valid base64url serialized JSON.`)}}HG.exports=function(J={}){let Z=J.complete||!1,Y=J.checkTyp;return zW.bind(null,{complete:Z,checkTyp:Y})}});var UG=l((k5,WG)=>{function U$($){if(typeof $!=="function")throw Error("obliterator/iterator: expecting a function!");this.next=$}if(typeof Symbol<"u")U$.prototype[Symbol.iterator]=function(){return this};U$.of=function(){var $=arguments,J=$.length,Z=0;return new U$(function(){if(Z>=J)return{done:!0};return{done:!1,value:$[Z++]}})};U$.empty=function(){var $=new U$(function(){return{done:!0}});return $};U$.fromSequence=function($){var J=0,Z=$.length;return new U$(function(){if(J>=Z)return{done:!0};return{done:!1,value:$[J++]}})};U$.is=function($){if($ instanceof U$)return!0;return typeof $==="object"&&$!==null&&typeof $.next==="function"};WG.exports=U$});var VG=l((_W)=>{_W.ARRAY_BUFFER_SUPPORT=typeof ArrayBuffer<"u";_W.SYMBOL_SUPPORT=typeof Symbol<"u"});var uZ=l((f5,_G)=>{var zG=VG(),AW=zG.ARRAY_BUFFER_SUPPORT,KW=zG.SYMBOL_SUPPORT;_G.exports=function(J,Z){var Y,X,G,Q,U;if(!J)throw Error("obliterator/forEach: invalid iterable.");if(typeof Z!=="function")throw Error("obliterator/forEach: expecting a callback.");if(Array.isArray(J)||AW&&ArrayBuffer.isView(J)||typeof J==="string"||J.toString()==="[object Arguments]"){for(G=0,Q=J.length;G<Q;G++)Z(J[G],G);return}if(typeof J.forEach==="function"){J.forEach(Z);return}if(KW&&Symbol.iterator in J&&typeof J.next!=="function")J=J[Symbol.iterator]();if(typeof J.next==="function"){Y=J,G=0;while(U=Y.next(),U.done!==!0)Z(U.value,G),G++;return}for(X in J)if(J.hasOwnProperty(X))Z(J[X],X);return}});var mZ=l((PW)=>{var FW=Math.pow(2,8)-1,RW=Math.pow(2,16)-1,IW=Math.pow(2,32)-1,qW=Math.pow(2,7)-1,LW=Math.pow(2,15)-1,jW=Math.pow(2,31)-1;PW.getPointerArray=function($){var J=$-1;if(J<=FW)return Uint8Array;if(J<=RW)return Uint16Array;if(J<=IW)return Uint32Array;throw Error("mnemonist: Pointer Array of size > 4294967295 is not supported.")};PW.getSignedPointerArray=function($){var J=$-1;if(J<=qW)return Int8Array;if(J<=LW)return Int16Array;if(J<=jW)return Int32Array;return Float64Array};PW.getNumberType=function($){if($===($|0))if(Math.sign($)===-1){if($<=127&&$>=-128)return Int8Array;if($<=32767&&$>=-32768)return Int16Array;return Int32Array}else{if($<=255)return Uint8Array;if($<=65535)return Uint16Array;return Uint32Array}return Float64Array};var BW={Uint8Array:1,Int8Array:2,Uint16Array:3,Int16Array:4,Uint32Array:5,Int32Array:6,Float32Array:7,Float64Array:8};PW.getMinimalRepresentation=function($,J){var Z=null,Y=0,X,G,Q,U,z;for(U=0,z=$.length;U<z;U++)if(Q=J?J($[U]):$[U],G=PW.getNumberType(Q),X=BW[G.name],X>Y)Y=X,Z=G;return Z};PW.isTypedArray=function($){return typeof ArrayBuffer<"u"&&ArrayBuffer.isView($)};PW.concat=function(){var $=0,J,Z,Y;for(J=0,Y=arguments.length;J<Y;J++)$+=arguments[J].length;var X=new arguments[0].constructor($);for(J=0,Z=0;J<Y;J++)X.set(arguments[J],Z),Z+=arguments[J].length;return X};PW.indices=function($){var J=PW.getPointerArray($),Z=new J($);for(var Y=0;Y<$;Y++)Z[Y]=Y;return Z}});var FG=l((kW)=>{var AG=uZ(),KG=mZ();function NW($){return Array.isArray($)||KG.isTypedArray($)}function nZ($){if(typeof $.length==="number")return $.length;if(typeof $.size==="number")return $.size;return}function DW($){var J=nZ($),Z=typeof J==="number"?Array(J):[],Y=0;return AG($,function(X){Z[Y++]=X}),Z}function vW($){var J=nZ($),Z=typeof J==="number"?KG.getPointerArray(J):Array,Y=typeof J==="number"?Array(J):[],X=typeof J==="number"?new Z(J):[],G=0;return AG($,function(Q){Y[G]=Q,X[G]=G++}),[Y,X]}kW.isArrayLike=NW;kW.guessLength=nZ;kW.toArray=DW;kW.toArrayWithIndices=vW});var sZ=l((h5,RG)=>{var dZ=UG(),hW=uZ(),bW=mZ(),cW=FG();function u0($,J,Z){if(arguments.length<2)Z=$,$=null,J=null;if(this.capacity=Z,typeof this.capacity!=="number"||this.capacity<=0)throw Error("mnemonist/lru-cache: capacity should be positive number.");else if(!isFinite(this.capacity)||Math.floor(this.capacity)!==this.capacity)throw Error("mnemonist/lru-cache: capacity should be a finite positive integer.");var Y=bW.getPointerArray(Z);this.forward=new Y(Z),this.backward=new Y(Z),this.K=typeof $==="function"?new $(Z):Array(Z),this.V=typeof J==="function"?new J(Z):Array(Z),this.size=0,this.head=0,this.tail=0,this.items={}}u0.prototype.clear=function(){this.size=0,this.head=0,this.tail=0,this.items={}};u0.prototype.splayOnTop=function($){var J=this.head;if(this.head===$)return this;var Z=this.backward[$],Y=this.forward[$];if(this.tail===$)this.tail=Z;else this.backward[Y]=Z;return this.forward[Z]=Y,this.backward[J]=$,this.head=$,this.forward[$]=J,this};u0.prototype.set=function($,J){var Z=this.items[$];if(typeof Z<"u"){this.splayOnTop(Z),this.V[Z]=J;return}if(this.size<this.capacity)Z=this.size++;else Z=this.tail,this.tail=this.backward[Z],delete this.items[this.K[Z]];this.items[$]=Z,this.K[Z]=$,this.V[Z]=J,this.forward[Z]=this.head,this.backward[this.head]=Z,this.head=Z};u0.prototype.setpop=function($,J){var Z=null,Y=null,X=this.items[$];if(typeof X<"u")return this.splayOnTop(X),Z=this.V[X],this.V[X]=J,{evicted:!1,key:$,value:Z};if(this.size<this.capacity)X=this.size++;else X=this.tail,this.tail=this.backward[X],Z=this.V[X],Y=this.K[X],delete this.items[Y];if(this.items[$]=X,this.K[X]=$,this.V[X]=J,this.forward[X]=this.head,this.backward[this.head]=X,this.head=X,Y)return{evicted:!0,key:Y,value:Z};else return null};u0.prototype.has=function($){return $ in this.items};u0.prototype.get=function($){var J=this.items[$];if(typeof J>"u")return;return this.splayOnTop(J),this.V[J]};u0.prototype.peek=function($){var J=this.items[$];if(typeof J>"u")return;return this.V[J]};u0.prototype.forEach=function($,J){J=arguments.length>1?J:this;var Z=0,Y=this.size,X=this.head,G=this.K,Q=this.V,U=this.forward;while(Z<Y)$.call(J,Q[X],G[X],this),X=U[X],Z++};u0.prototype.keys=function(){var $=0,J=this.size,Z=this.head,Y=this.K,X=this.forward;return new dZ(function(){if($>=J)return{done:!0};var G=Y[Z];if($++,$<J)Z=X[Z];return{done:!1,value:G}})};u0.prototype.values=function(){var $=0,J=this.size,Z=this.head,Y=this.V,X=this.forward;return new dZ(function(){if($>=J)return{done:!0};var G=Y[Z];if($++,$<J)Z=X[Z];return{done:!1,value:G}})};u0.prototype.entries=function(){var $=0,J=this.size,Z=this.head,Y=this.K,X=this.V,G=this.forward;return new dZ(function(){if($>=J)return{done:!0};var Q=Y[Z],U=X[Z];if($++,$<J)Z=G[Z];return{done:!1,value:[Q,U]}})};if(typeof Symbol<"u")u0.prototype[Symbol.iterator]=u0.prototype.entries;u0.prototype.inspect=function(){var $=new Map,J=this.entries(),Z;while(Z=J.next(),!Z.done)$.set(Z.value[0],Z.value[1]);return Object.defineProperty($,"constructor",{value:u0,enumerable:!1}),$};if(typeof Symbol<"u")u0.prototype[Symbol.for("nodejs.util.inspect.custom")]=u0.prototype.inspect;u0.from=function($,J,Z,Y){if(arguments.length<2){if(Y=cW.guessLength($),typeof Y!=="number")throw Error("mnemonist/lru-cache.from: could not guess iterable length. Please provide desired capacity as last argument.")}else if(arguments.length===2)Y=J,J=null,Z=null;var X=new u0(J,Z,Y);return hW($,function(G,Q){X.set(Q,G)}),X};RG.exports=u0});var lZ=l((IG,oZ)=>{(function($,J){function Z(q,H){if(!q)throw Error(H||"Assertion failed")}function Y(q,H){q.super_=H;var V=function(){};V.prototype=H.prototype,q.prototype=new V,q.prototype.constructor=q}function X(q,H,V){if(X.isBN(q))return q;if(this.negative=0,this.words=null,this.length=0,this.red=null,q!==null){if(H==="le"||H==="be")V=H,H=10;this._init(q||0,H||10,V||"be")}}if(typeof $==="object")$.exports=X;else J.BN=X;X.BN=X,X.wordSize=26;var G;try{if(typeof window<"u"&&typeof window.Buffer<"u")G=window.Buffer;else G=K$("buffer").Buffer}catch(q){}X.isBN=function(H){if(H instanceof X)return!0;return H!==null&&typeof H==="object"&&H.constructor.wordSize===X.wordSize&&Array.isArray(H.words)},X.max=function(H,V){if(H.cmp(V)>0)return H;return V},X.min=function(H,V){if(H.cmp(V)<0)return H;return V},X.prototype._init=function(H,V,M){if(typeof H==="number")return this._initNumber(H,V,M);if(typeof H==="object")return this._initArray(H,V,M);if(V==="hex")V=16;Z(V===(V|0)&&V>=2&&V<=36),H=H.toString().replace(/\s+/g,"");var A=0;if(H[0]==="-")A++,this.negative=1;if(A<H.length){if(V===16)this._parseHex(H,A,M);else if(this._parseBase(H,V,A),M==="le")this._initArray(this.toArray(),V,M)}},X.prototype._initNumber=function(H,V,M){if(H<0)this.negative=1,H=-H;if(H<67108864)this.words=[H&67108863],this.length=1;else if(H<4503599627370496)this.words=[H&67108863,H/67108864&67108863],this.length=2;else Z(H<9007199254740992),this.words=[H&67108863,H/67108864&67108863,1],this.length=3;if(M!=="le")return;this._initArray(this.toArray(),V,M)},X.prototype._initArray=function(H,V,M){if(Z(typeof H.length==="number"),H.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(H.length/3),this.words=Array(this.length);for(var A=0;A<this.length;A++)this.words[A]=0;var I,B,P=0;if(M==="be"){for(A=H.length-1,I=0;A>=0;A-=3)if(B=H[A]|H[A-1]<<8|H[A-2]<<16,this.words[I]|=B<<P&67108863,this.words[I+1]=B>>>26-P&67108863,P+=24,P>=26)P-=26,I++}else if(M==="le"){for(A=0,I=0;A<H.length;A+=3)if(B=H[A]|H[A+1]<<8|H[A+2]<<16,this.words[I]|=B<<P&67108863,this.words[I+1]=B>>>26-P&67108863,P+=24,P>=26)P-=26,I++}return this.strip()};function Q(q,H){var V=q.charCodeAt(H);if(V>=65&&V<=70)return V-55;else if(V>=97&&V<=102)return V-87;else return V-48&15}function U(q,H,V){var M=Q(q,V);if(V-1>=H)M|=Q(q,V-1)<<4;return M}X.prototype._parseHex=function(H,V,M){this.length=Math.ceil((H.length-V)/6),this.words=Array(this.length);for(var A=0;A<this.length;A++)this.words[A]=0;var I=0,B=0,P;if(M==="be")for(A=H.length-1;A>=V;A-=2)if(P=U(H,V,A)<<I,this.words[B]|=P&67108863,I>=18)I-=18,B+=1,this.words[B]|=P>>>26;else I+=8;else{var F=H.length-V;for(A=F%2===0?V+1:V;A<H.length;A+=2)if(P=U(H,V,A)<<I,this.words[B]|=P&67108863,I>=18)I-=18,B+=1,this.words[B]|=P>>>26;else I+=8}this.strip()};function z(q,H,V,M){var A=0,I=Math.min(q.length,V);for(var B=H;B<I;B++){var P=q.charCodeAt(B)-48;if(A*=M,P>=49)A+=P-49+10;else if(P>=17)A+=P-17+10;else A+=P}return A}X.prototype._parseBase=function(H,V,M){this.words=[0],this.length=1;for(var A=0,I=1;I<=67108863;I*=V)A++;A--,I=I/V|0;var B=H.length-M,P=B%A,F=Math.min(B,B-P)+M,W=0;for(var R=M;R<F;R+=A)if(W=z(H,R,R+A,V),this.imuln(I),this.words[0]+W<67108864)this.words[0]+=W;else this._iaddn(W);if(P!==0){var x=1;W=z(H,R,H.length,V);for(R=0;R<P;R++)x*=V;if(this.imuln(x),this.words[0]+W<67108864)this.words[0]+=W;else this._iaddn(W)}this.strip()},X.prototype.copy=function(H){H.words=Array(this.length);for(var V=0;V<this.length;V++)H.words[V]=this.words[V];H.length=this.length,H.negative=this.negative,H.red=this.red},X.prototype.clone=function(){var H=new X(null);return this.copy(H),H},X.prototype._expand=function(H){while(this.length<H)this.words[this.length++]=0;return this},X.prototype.strip=function(){while(this.length>1&&this.words[this.length-1]===0)this.length--;return this._normSign()},X.prototype._normSign=function(){if(this.length===1&&this.words[0]===0)this.negative=0;return this},X.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var O=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],_=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],K=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64000000,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,24300000,28629151,33554432,39135393,45435424,52521875,60466176];if(X.prototype.toString=function(H,V){H=H||10,V=V|0||1;var M;if(H===16||H==="hex"){M="";var A=0,I=0;for(var B=0;B<this.length;B++){var P=this.words[B],F=((P<<A|I)&16777215).toString(16);if(I=P>>>24-A&16777215,A+=2,A>=26)A-=26,B--;if(I!==0||B!==this.length-1)M=O[6-F.length]+F+M;else M=F+M}if(I!==0)M=I.toString(16)+M;while(M.length%V!==0)M="0"+M;if(this.negative!==0)M="-"+M;return M}if(H===(H|0)&&H>=2&&H<=36){var W=_[H],R=K[H];M="";var x=this.clone();x.negative=0;while(!x.isZero()){var y=x.modn(R).toString(H);if(x=x.idivn(R),!x.isZero())M=O[W-y.length]+y+M;else M=y+M}if(this.isZero())M="0"+M;while(M.length%V!==0)M="0"+M;if(this.negative!==0)M="-"+M;return M}Z(!1,"Base should be between 2 and 36")},X.prototype.toNumber=function(){var H=this.words[0];if(this.length===2)H+=this.words[1]*67108864;else if(this.length===3&&this.words[2]===1)H+=4503599627370496+this.words[1]*67108864;else if(this.length>2)Z(!1,"Number can only safely store up to 53 bits");return this.negative!==0?-H:H},X.prototype.toJSON=function(){return this.toString(16)},X.prototype.toBuffer=function(H,V){return Z(typeof G<"u"),this.toArrayLike(G,H,V)},X.prototype.toArray=function(H,V){return this.toArrayLike(Array,H,V)},X.prototype.toArrayLike=function(H,V,M){var A=this.byteLength(),I=M||Math.max(1,A);Z(A<=I,"byte array longer than desired length"),Z(I>0,"Requested array length <= 0"),this.strip();var B=V==="le",P=new H(I),F,W,R=this.clone();if(!B){for(W=0;W<I-A;W++)P[W]=0;for(W=0;!R.isZero();W++)F=R.andln(255),R.iushrn(8),P[I-W-1]=F}else{for(W=0;!R.isZero();W++)F=R.andln(255),R.iushrn(8),P[W]=F;for(;W<I;W++)P[W]=0}return P},Math.clz32)X.prototype._countBits=function(H){return 32-Math.clz32(H)};else X.prototype._countBits=function(H){var V=H,M=0;if(V>=4096)M+=13,V>>>=13;if(V>=64)M+=7,V>>>=7;if(V>=8)M+=4,V>>>=4;if(V>=2)M+=2,V>>>=2;return M+V};X.prototype._zeroBits=function(H){if(H===0)return 26;var V=H,M=0;if((V&8191)===0)M+=13,V>>>=13;if((V&127)===0)M+=7,V>>>=7;if((V&15)===0)M+=4,V>>>=4;if((V&3)===0)M+=2,V>>>=2;if((V&1)===0)M++;return M},X.prototype.bitLength=function(){var H=this.words[this.length-1],V=this._countBits(H);return(this.length-1)*26+V};function j(q){var H=Array(q.bitLength());for(var V=0;V<H.length;V++){var M=V/26|0,A=V%26;H[V]=(q.words[M]&1<<A)>>>A}return H}X.prototype.zeroBits=function(){if(this.isZero())return 0;var H=0;for(var V=0;V<this.length;V++){var M=this._zeroBits(this.words[V]);if(H+=M,M!==26)break}return H},X.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},X.prototype.toTwos=function(H){if(this.negative!==0)return this.abs().inotn(H).iaddn(1);return this.clone()},X.prototype.fromTwos=function(H){if(this.testn(H-1))return this.notn(H).iaddn(1).ineg();return this.clone()},X.prototype.isNeg=function(){return this.negative!==0},X.prototype.neg=function(){return this.clone().ineg()},X.prototype.ineg=function(){if(!this.isZero())this.negative^=1;return this},X.prototype.iuor=function(H){while(this.length<H.length)this.words[this.length++]=0;for(var V=0;V<H.length;V++)this.words[V]=this.words[V]|H.words[V];return this.strip()},X.prototype.ior=function(H){return Z((this.negative|H.negative)===0),this.iuor(H)},X.prototype.or=function(H){if(this.length>H.length)return this.clone().ior(H);return H.clone().ior(this)},X.prototype.uor=function(H){if(this.length>H.length)return this.clone().iuor(H);return H.clone().iuor(this)},X.prototype.iuand=function(H){var V;if(this.length>H.length)V=H;else V=this;for(var M=0;M<V.length;M++)this.words[M]=this.words[M]&H.words[M];return this.length=V.length,this.strip()},X.prototype.iand=function(H){return Z((this.negative|H.negative)===0),this.iuand(H)},X.prototype.and=function(H){if(this.length>H.length)return this.clone().iand(H);return H.clone().iand(this)},X.prototype.uand=function(H){if(this.length>H.length)return this.clone().iuand(H);return H.clone().iuand(this)},X.prototype.iuxor=function(H){var V,M;if(this.length>H.length)V=this,M=H;else V=H,M=this;for(var A=0;A<M.length;A++)this.words[A]=V.words[A]^M.words[A];if(this!==V)for(;A<V.length;A++)this.words[A]=V.words[A];return this.length=V.length,this.strip()},X.prototype.ixor=function(H){return Z((this.negative|H.negative)===0),this.iuxor(H)},X.prototype.xor=function(H){if(this.length>H.length)return this.clone().ixor(H);return H.clone().ixor(this)},X.prototype.uxor=function(H){if(this.length>H.length)return this.clone().iuxor(H);return H.clone().iuxor(this)},X.prototype.inotn=function(H){Z(typeof H==="number"&&H>=0);var V=Math.ceil(H/26)|0,M=H%26;if(this._expand(V),M>0)V--;for(var A=0;A<V;A++)this.words[A]=~this.words[A]&67108863;if(M>0)this.words[A]=~this.words[A]&67108863>>26-M;return this.strip()},X.prototype.notn=function(H){return this.clone().inotn(H)},X.prototype.setn=function(H,V){Z(typeof H==="number"&&H>=0);var M=H/26|0,A=H%26;if(this._expand(M+1),V)this.words[M]=this.words[M]|1<<A;else this.words[M]=this.words[M]&~(1<<A);return this.strip()},X.prototype.iadd=function(H){var V;if(this.negative!==0&&H.negative===0)return this.negative=0,V=this.isub(H),this.negative^=1,this._normSign();else if(this.negative===0&&H.negative!==0)return H.negative=0,V=this.isub(H),H.negative=1,V._normSign();var M,A;if(this.length>H.length)M=this,A=H;else M=H,A=this;var I=0;for(var B=0;B<A.length;B++)V=(M.words[B]|0)+(A.words[B]|0)+I,this.words[B]=V&67108863,I=V>>>26;for(;I!==0&&B<M.length;B++)V=(M.words[B]|0)+I,this.words[B]=V&67108863,I=V>>>26;if(this.length=M.length,I!==0)this.words[this.length]=I,this.length++;else if(M!==this)for(;B<M.length;B++)this.words[B]=M.words[B];return this},X.prototype.add=function(H){var V;if(H.negative!==0&&this.negative===0)return H.negative=0,V=this.sub(H),H.negative^=1,V;else if(H.negative===0&&this.negative!==0)return this.negative=0,V=H.sub(this),this.negative=1,V;if(this.length>H.length)return this.clone().iadd(H);return H.clone().iadd(this)},X.prototype.isub=function(H){if(H.negative!==0){H.negative=0;var V=this.iadd(H);return H.negative=1,V._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(H),this.negative=1,this._normSign();var M=this.cmp(H);if(M===0)return this.negative=0,this.length=1,this.words[0]=0,this;var A,I;if(M>0)A=this,I=H;else A=H,I=this;var B=0;for(var P=0;P<I.length;P++)V=(A.words[P]|0)-(I.words[P]|0)+B,B=V>>26,this.words[P]=V&67108863;for(;B!==0&&P<A.length;P++)V=(A.words[P]|0)+B,B=V>>26,this.words[P]=V&67108863;if(B===0&&P<A.length&&A!==this)for(;P<A.length;P++)this.words[P]=A.words[P];if(this.length=Math.max(this.length,P),A!==this)this.negative=1;return this.strip()},X.prototype.sub=function(H){return this.clone().isub(H)};function C(q,H,V){V.negative=H.negative^q.negative;var M=q.length+H.length|0;V.length=M,M=M-1|0;var A=q.words[0]|0,I=H.words[0]|0,B=A*I,P=B&67108863,F=B/67108864|0;V.words[0]=P;for(var W=1;W<M;W++){var R=F>>>26,x=F&67108863,y=Math.min(W,H.length-1);for(var g=Math.max(0,W-q.length+1);g<=y;g++){var u=W-g|0;A=q.words[u]|0,I=H.words[g]|0,B=A*I+x,R+=B/67108864|0,x=B&67108863}V.words[W]=x|0,F=R|0}if(F!==0)V.words[W]=F|0;else V.length--;return V.strip()}var S=function(H,V,M){var A=H.words,I=V.words,B=M.words,P=0,F,W,R,x=A[0]|0,y=x&8191,g=x>>>13,u=A[1]|0,t=u&8191,J0=u>>>13,A$=A[2]|0,Z0=A$&8191,G0=A$>>>13,IY=A[3]|0,H0=IY&8191,W0=IY>>>13,qY=A[4]|0,U0=qY&8191,V0=qY>>>13,LY=A[5]|0,z0=LY&8191,_0=LY>>>13,jY=A[6]|0,O0=jY&8191,M0=jY>>>13,BY=A[7]|0,A0=BY&8191,K0=BY>>>13,PY=A[8]|0,F0=PY&8191,R0=PY>>>13,EY=A[9]|0,I0=EY&8191,q0=EY>>>13,CY=I[0]|0,L0=CY&8191,j0=CY>>>13,SY=I[1]|0,B0=SY&8191,P0=SY>>>13,wY=I[2]|0,E0=wY&8191,C0=wY>>>13,TY=I[3]|0,S0=TY&8191,w0=TY>>>13,NY=I[4]|0,T0=NY&8191,N0=NY>>>13,DY=I[5]|0,D0=DY&8191,v0=DY>>>13,vY=I[6]|0,k0=vY&8191,x0=vY>>>13,kY=I[7]|0,f0=kY&8191,y0=kY>>>13,xY=I[8]|0,g0=xY&8191,h0=xY>>>13,fY=I[9]|0,b0=fY&8191,c0=fY>>>13;M.negative=H.negative^V.negative,M.length=19,F=Math.imul(y,L0),W=Math.imul(y,j0),W=W+Math.imul(g,L0)|0,R=Math.imul(g,j0);var mJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(mJ>>>26)|0,mJ&=67108863,F=Math.imul(t,L0),W=Math.imul(t,j0),W=W+Math.imul(J0,L0)|0,R=Math.imul(J0,j0),F=F+Math.imul(y,B0)|0,W=W+Math.imul(y,P0)|0,W=W+Math.imul(g,B0)|0,R=R+Math.imul(g,P0)|0;var nJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(nJ>>>26)|0,nJ&=67108863,F=Math.imul(Z0,L0),W=Math.imul(Z0,j0),W=W+Math.imul(G0,L0)|0,R=Math.imul(G0,j0),F=F+Math.imul(t,B0)|0,W=W+Math.imul(t,P0)|0,W=W+Math.imul(J0,B0)|0,R=R+Math.imul(J0,P0)|0,F=F+Math.imul(y,E0)|0,W=W+Math.imul(y,C0)|0,W=W+Math.imul(g,E0)|0,R=R+Math.imul(g,C0)|0;var dJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(dJ>>>26)|0,dJ&=67108863,F=Math.imul(H0,L0),W=Math.imul(H0,j0),W=W+Math.imul(W0,L0)|0,R=Math.imul(W0,j0),F=F+Math.imul(Z0,B0)|0,W=W+Math.imul(Z0,P0)|0,W=W+Math.imul(G0,B0)|0,R=R+Math.imul(G0,P0)|0,F=F+Math.imul(t,E0)|0,W=W+Math.imul(t,C0)|0,W=W+Math.imul(J0,E0)|0,R=R+Math.imul(J0,C0)|0,F=F+Math.imul(y,S0)|0,W=W+Math.imul(y,w0)|0,W=W+Math.imul(g,S0)|0,R=R+Math.imul(g,w0)|0;var sJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(sJ>>>26)|0,sJ&=67108863,F=Math.imul(U0,L0),W=Math.imul(U0,j0),W=W+Math.imul(V0,L0)|0,R=Math.imul(V0,j0),F=F+Math.imul(H0,B0)|0,W=W+Math.imul(H0,P0)|0,W=W+Math.imul(W0,B0)|0,R=R+Math.imul(W0,P0)|0,F=F+Math.imul(Z0,E0)|0,W=W+Math.imul(Z0,C0)|0,W=W+Math.imul(G0,E0)|0,R=R+Math.imul(G0,C0)|0,F=F+Math.imul(t,S0)|0,W=W+Math.imul(t,w0)|0,W=W+Math.imul(J0,S0)|0,R=R+Math.imul(J0,w0)|0,F=F+Math.imul(y,T0)|0,W=W+Math.imul(y,N0)|0,W=W+Math.imul(g,T0)|0,R=R+Math.imul(g,N0)|0;var oJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(oJ>>>26)|0,oJ&=67108863,F=Math.imul(z0,L0),W=Math.imul(z0,j0),W=W+Math.imul(_0,L0)|0,R=Math.imul(_0,j0),F=F+Math.imul(U0,B0)|0,W=W+Math.imul(U0,P0)|0,W=W+Math.imul(V0,B0)|0,R=R+Math.imul(V0,P0)|0,F=F+Math.imul(H0,E0)|0,W=W+Math.imul(H0,C0)|0,W=W+Math.imul(W0,E0)|0,R=R+Math.imul(W0,C0)|0,F=F+Math.imul(Z0,S0)|0,W=W+Math.imul(Z0,w0)|0,W=W+Math.imul(G0,S0)|0,R=R+Math.imul(G0,w0)|0,F=F+Math.imul(t,T0)|0,W=W+Math.imul(t,N0)|0,W=W+Math.imul(J0,T0)|0,R=R+Math.imul(J0,N0)|0,F=F+Math.imul(y,D0)|0,W=W+Math.imul(y,v0)|0,W=W+Math.imul(g,D0)|0,R=R+Math.imul(g,v0)|0;var lJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(lJ>>>26)|0,lJ&=67108863,F=Math.imul(O0,L0),W=Math.imul(O0,j0),W=W+Math.imul(M0,L0)|0,R=Math.imul(M0,j0),F=F+Math.imul(z0,B0)|0,W=W+Math.imul(z0,P0)|0,W=W+Math.imul(_0,B0)|0,R=R+Math.imul(_0,P0)|0,F=F+Math.imul(U0,E0)|0,W=W+Math.imul(U0,C0)|0,W=W+Math.imul(V0,E0)|0,R=R+Math.imul(V0,C0)|0,F=F+Math.imul(H0,S0)|0,W=W+Math.imul(H0,w0)|0,W=W+Math.imul(W0,S0)|0,R=R+Math.imul(W0,w0)|0,F=F+Math.imul(Z0,T0)|0,W=W+Math.imul(Z0,N0)|0,W=W+Math.imul(G0,T0)|0,R=R+Math.imul(G0,N0)|0,F=F+Math.imul(t,D0)|0,W=W+Math.imul(t,v0)|0,W=W+Math.imul(J0,D0)|0,R=R+Math.imul(J0,v0)|0,F=F+Math.imul(y,k0)|0,W=W+Math.imul(y,x0)|0,W=W+Math.imul(g,k0)|0,R=R+Math.imul(g,x0)|0;var rJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(rJ>>>26)|0,rJ&=67108863,F=Math.imul(A0,L0),W=Math.imul(A0,j0),W=W+Math.imul(K0,L0)|0,R=Math.imul(K0,j0),F=F+Math.imul(O0,B0)|0,W=W+Math.imul(O0,P0)|0,W=W+Math.imul(M0,B0)|0,R=R+Math.imul(M0,P0)|0,F=F+Math.imul(z0,E0)|0,W=W+Math.imul(z0,C0)|0,W=W+Math.imul(_0,E0)|0,R=R+Math.imul(_0,C0)|0,F=F+Math.imul(U0,S0)|0,W=W+Math.imul(U0,w0)|0,W=W+Math.imul(V0,S0)|0,R=R+Math.imul(V0,w0)|0,F=F+Math.imul(H0,T0)|0,W=W+Math.imul(H0,N0)|0,W=W+Math.imul(W0,T0)|0,R=R+Math.imul(W0,N0)|0,F=F+Math.imul(Z0,D0)|0,W=W+Math.imul(Z0,v0)|0,W=W+Math.imul(G0,D0)|0,R=R+Math.imul(G0,v0)|0,F=F+Math.imul(t,k0)|0,W=W+Math.imul(t,x0)|0,W=W+Math.imul(J0,k0)|0,R=R+Math.imul(J0,x0)|0,F=F+Math.imul(y,f0)|0,W=W+Math.imul(y,y0)|0,W=W+Math.imul(g,f0)|0,R=R+Math.imul(g,y0)|0;var iJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(iJ>>>26)|0,iJ&=67108863,F=Math.imul(F0,L0),W=Math.imul(F0,j0),W=W+Math.imul(R0,L0)|0,R=Math.imul(R0,j0),F=F+Math.imul(A0,B0)|0,W=W+Math.imul(A0,P0)|0,W=W+Math.imul(K0,B0)|0,R=R+Math.imul(K0,P0)|0,F=F+Math.imul(O0,E0)|0,W=W+Math.imul(O0,C0)|0,W=W+Math.imul(M0,E0)|0,R=R+Math.imul(M0,C0)|0,F=F+Math.imul(z0,S0)|0,W=W+Math.imul(z0,w0)|0,W=W+Math.imul(_0,S0)|0,R=R+Math.imul(_0,w0)|0,F=F+Math.imul(U0,T0)|0,W=W+Math.imul(U0,N0)|0,W=W+Math.imul(V0,T0)|0,R=R+Math.imul(V0,N0)|0,F=F+Math.imul(H0,D0)|0,W=W+Math.imul(H0,v0)|0,W=W+Math.imul(W0,D0)|0,R=R+Math.imul(W0,v0)|0,F=F+Math.imul(Z0,k0)|0,W=W+Math.imul(Z0,x0)|0,W=W+Math.imul(G0,k0)|0,R=R+Math.imul(G0,x0)|0,F=F+Math.imul(t,f0)|0,W=W+Math.imul(t,y0)|0,W=W+Math.imul(J0,f0)|0,R=R+Math.imul(J0,y0)|0,F=F+Math.imul(y,g0)|0,W=W+Math.imul(y,h0)|0,W=W+Math.imul(g,g0)|0,R=R+Math.imul(g,h0)|0;var tJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(tJ>>>26)|0,tJ&=67108863,F=Math.imul(I0,L0),W=Math.imul(I0,j0),W=W+Math.imul(q0,L0)|0,R=Math.imul(q0,j0),F=F+Math.imul(F0,B0)|0,W=W+Math.imul(F0,P0)|0,W=W+Math.imul(R0,B0)|0,R=R+Math.imul(R0,P0)|0,F=F+Math.imul(A0,E0)|0,W=W+Math.imul(A0,C0)|0,W=W+Math.imul(K0,E0)|0,R=R+Math.imul(K0,C0)|0,F=F+Math.imul(O0,S0)|0,W=W+Math.imul(O0,w0)|0,W=W+Math.imul(M0,S0)|0,R=R+Math.imul(M0,w0)|0,F=F+Math.imul(z0,T0)|0,W=W+Math.imul(z0,N0)|0,W=W+Math.imul(_0,T0)|0,R=R+Math.imul(_0,N0)|0,F=F+Math.imul(U0,D0)|0,W=W+Math.imul(U0,v0)|0,W=W+Math.imul(V0,D0)|0,R=R+Math.imul(V0,v0)|0,F=F+Math.imul(H0,k0)|0,W=W+Math.imul(H0,x0)|0,W=W+Math.imul(W0,k0)|0,R=R+Math.imul(W0,x0)|0,F=F+Math.imul(Z0,f0)|0,W=W+Math.imul(Z0,y0)|0,W=W+Math.imul(G0,f0)|0,R=R+Math.imul(G0,y0)|0,F=F+Math.imul(t,g0)|0,W=W+Math.imul(t,h0)|0,W=W+Math.imul(J0,g0)|0,R=R+Math.imul(J0,h0)|0,F=F+Math.imul(y,b0)|0,W=W+Math.imul(y,c0)|0,W=W+Math.imul(g,b0)|0,R=R+Math.imul(g,c0)|0;var aJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(aJ>>>26)|0,aJ&=67108863,F=Math.imul(I0,B0),W=Math.imul(I0,P0),W=W+Math.imul(q0,B0)|0,R=Math.imul(q0,P0),F=F+Math.imul(F0,E0)|0,W=W+Math.imul(F0,C0)|0,W=W+Math.imul(R0,E0)|0,R=R+Math.imul(R0,C0)|0,F=F+Math.imul(A0,S0)|0,W=W+Math.imul(A0,w0)|0,W=W+Math.imul(K0,S0)|0,R=R+Math.imul(K0,w0)|0,F=F+Math.imul(O0,T0)|0,W=W+Math.imul(O0,N0)|0,W=W+Math.imul(M0,T0)|0,R=R+Math.imul(M0,N0)|0,F=F+Math.imul(z0,D0)|0,W=W+Math.imul(z0,v0)|0,W=W+Math.imul(_0,D0)|0,R=R+Math.imul(_0,v0)|0,F=F+Math.imul(U0,k0)|0,W=W+Math.imul(U0,x0)|0,W=W+Math.imul(V0,k0)|0,R=R+Math.imul(V0,x0)|0,F=F+Math.imul(H0,f0)|0,W=W+Math.imul(H0,y0)|0,W=W+Math.imul(W0,f0)|0,R=R+Math.imul(W0,y0)|0,F=F+Math.imul(Z0,g0)|0,W=W+Math.imul(Z0,h0)|0,W=W+Math.imul(G0,g0)|0,R=R+Math.imul(G0,h0)|0,F=F+Math.imul(t,b0)|0,W=W+Math.imul(t,c0)|0,W=W+Math.imul(J0,b0)|0,R=R+Math.imul(J0,c0)|0;var eJ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(eJ>>>26)|0,eJ&=67108863,F=Math.imul(I0,E0),W=Math.imul(I0,C0),W=W+Math.imul(q0,E0)|0,R=Math.imul(q0,C0),F=F+Math.imul(F0,S0)|0,W=W+Math.imul(F0,w0)|0,W=W+Math.imul(R0,S0)|0,R=R+Math.imul(R0,w0)|0,F=F+Math.imul(A0,T0)|0,W=W+Math.imul(A0,N0)|0,W=W+Math.imul(K0,T0)|0,R=R+Math.imul(K0,N0)|0,F=F+Math.imul(O0,D0)|0,W=W+Math.imul(O0,v0)|0,W=W+Math.imul(M0,D0)|0,R=R+Math.imul(M0,v0)|0,F=F+Math.imul(z0,k0)|0,W=W+Math.imul(z0,x0)|0,W=W+Math.imul(_0,k0)|0,R=R+Math.imul(_0,x0)|0,F=F+Math.imul(U0,f0)|0,W=W+Math.imul(U0,y0)|0,W=W+Math.imul(V0,f0)|0,R=R+Math.imul(V0,y0)|0,F=F+Math.imul(H0,g0)|0,W=W+Math.imul(H0,h0)|0,W=W+Math.imul(W0,g0)|0,R=R+Math.imul(W0,h0)|0,F=F+Math.imul(Z0,b0)|0,W=W+Math.imul(Z0,c0)|0,W=W+Math.imul(G0,b0)|0,R=R+Math.imul(G0,c0)|0;var $Z=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+($Z>>>26)|0,$Z&=67108863,F=Math.imul(I0,S0),W=Math.imul(I0,w0),W=W+Math.imul(q0,S0)|0,R=Math.imul(q0,w0),F=F+Math.imul(F0,T0)|0,W=W+Math.imul(F0,N0)|0,W=W+Math.imul(R0,T0)|0,R=R+Math.imul(R0,N0)|0,F=F+Math.imul(A0,D0)|0,W=W+Math.imul(A0,v0)|0,W=W+Math.imul(K0,D0)|0,R=R+Math.imul(K0,v0)|0,F=F+Math.imul(O0,k0)|0,W=W+Math.imul(O0,x0)|0,W=W+Math.imul(M0,k0)|0,R=R+Math.imul(M0,x0)|0,F=F+Math.imul(z0,f0)|0,W=W+Math.imul(z0,y0)|0,W=W+Math.imul(_0,f0)|0,R=R+Math.imul(_0,y0)|0,F=F+Math.imul(U0,g0)|0,W=W+Math.imul(U0,h0)|0,W=W+Math.imul(V0,g0)|0,R=R+Math.imul(V0,h0)|0,F=F+Math.imul(H0,b0)|0,W=W+Math.imul(H0,c0)|0,W=W+Math.imul(W0,b0)|0,R=R+Math.imul(W0,c0)|0;var JZ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(JZ>>>26)|0,JZ&=67108863,F=Math.imul(I0,T0),W=Math.imul(I0,N0),W=W+Math.imul(q0,T0)|0,R=Math.imul(q0,N0),F=F+Math.imul(F0,D0)|0,W=W+Math.imul(F0,v0)|0,W=W+Math.imul(R0,D0)|0,R=R+Math.imul(R0,v0)|0,F=F+Math.imul(A0,k0)|0,W=W+Math.imul(A0,x0)|0,W=W+Math.imul(K0,k0)|0,R=R+Math.imul(K0,x0)|0,F=F+Math.imul(O0,f0)|0,W=W+Math.imul(O0,y0)|0,W=W+Math.imul(M0,f0)|0,R=R+Math.imul(M0,y0)|0,F=F+Math.imul(z0,g0)|0,W=W+Math.imul(z0,h0)|0,W=W+Math.imul(_0,g0)|0,R=R+Math.imul(_0,h0)|0,F=F+Math.imul(U0,b0)|0,W=W+Math.imul(U0,c0)|0,W=W+Math.imul(V0,b0)|0,R=R+Math.imul(V0,c0)|0;var ZZ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(ZZ>>>26)|0,ZZ&=67108863,F=Math.imul(I0,D0),W=Math.imul(I0,v0),W=W+Math.imul(q0,D0)|0,R=Math.imul(q0,v0),F=F+Math.imul(F0,k0)|0,W=W+Math.imul(F0,x0)|0,W=W+Math.imul(R0,k0)|0,R=R+Math.imul(R0,x0)|0,F=F+Math.imul(A0,f0)|0,W=W+Math.imul(A0,y0)|0,W=W+Math.imul(K0,f0)|0,R=R+Math.imul(K0,y0)|0,F=F+Math.imul(O0,g0)|0,W=W+Math.imul(O0,h0)|0,W=W+Math.imul(M0,g0)|0,R=R+Math.imul(M0,h0)|0,F=F+Math.imul(z0,b0)|0,W=W+Math.imul(z0,c0)|0,W=W+Math.imul(_0,b0)|0,R=R+Math.imul(_0,c0)|0;var YZ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(YZ>>>26)|0,YZ&=67108863,F=Math.imul(I0,k0),W=Math.imul(I0,x0),W=W+Math.imul(q0,k0)|0,R=Math.imul(q0,x0),F=F+Math.imul(F0,f0)|0,W=W+Math.imul(F0,y0)|0,W=W+Math.imul(R0,f0)|0,R=R+Math.imul(R0,y0)|0,F=F+Math.imul(A0,g0)|0,W=W+Math.imul(A0,h0)|0,W=W+Math.imul(K0,g0)|0,R=R+Math.imul(K0,h0)|0,F=F+Math.imul(O0,b0)|0,W=W+Math.imul(O0,c0)|0,W=W+Math.imul(M0,b0)|0,R=R+Math.imul(M0,c0)|0;var XZ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(XZ>>>26)|0,XZ&=67108863,F=Math.imul(I0,f0),W=Math.imul(I0,y0),W=W+Math.imul(q0,f0)|0,R=Math.imul(q0,y0),F=F+Math.imul(F0,g0)|0,W=W+Math.imul(F0,h0)|0,W=W+Math.imul(R0,g0)|0,R=R+Math.imul(R0,h0)|0,F=F+Math.imul(A0,b0)|0,W=W+Math.imul(A0,c0)|0,W=W+Math.imul(K0,b0)|0,R=R+Math.imul(K0,c0)|0;var GZ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(GZ>>>26)|0,GZ&=67108863,F=Math.imul(I0,g0),W=Math.imul(I0,h0),W=W+Math.imul(q0,g0)|0,R=Math.imul(q0,h0),F=F+Math.imul(F0,b0)|0,W=W+Math.imul(F0,c0)|0,W=W+Math.imul(R0,b0)|0,R=R+Math.imul(R0,c0)|0;var QZ=(P+F|0)+((W&8191)<<13)|0;P=(R+(W>>>13)|0)+(QZ>>>26)|0,QZ&=67108863,F=Math.imul(I0,b0),W=Math.imul(I0,c0),W=W+Math.imul(q0,b0)|0,R=Math.imul(q0,c0);var HZ=(P+F|0)+((W&8191)<<13)|0;if(P=(R+(W>>>13)|0)+(HZ>>>26)|0,HZ&=67108863,B[0]=mJ,B[1]=nJ,B[2]=dJ,B[3]=sJ,B[4]=oJ,B[5]=lJ,B[6]=rJ,B[7]=iJ,B[8]=tJ,B[9]=aJ,B[10]=eJ,B[11]=$Z,B[12]=JZ,B[13]=ZZ,B[14]=YZ,B[15]=XZ,B[16]=GZ,B[17]=QZ,B[18]=HZ,P!==0)B[19]=P,M.length++;return M};if(!Math.imul)S=C;function v(q,H,V){V.negative=H.negative^q.negative,V.length=q.length+H.length;var M=0,A=0;for(var I=0;I<V.length-1;I++){var B=A;A=0;var P=M&67108863,F=Math.min(I,H.length-1);for(var W=Math.max(0,I-q.length+1);W<=F;W++){var R=I-W,x=q.words[R]|0,y=H.words[W]|0,g=x*y,u=g&67108863;B=B+(g/67108864|0)|0,u=u+P|0,P=u&67108863,B=B+(u>>>26)|0,A+=B>>>26,B&=67108863}V.words[I]=P,M=B,B=A}if(M!==0)V.words[I]=M;else V.length--;return V.strip()}function T(q,H,V){var M=new k;return M.mulp(q,H,V)}X.prototype.mulTo=function(H,V){var M,A=this.length+H.length;if(this.length===10&&H.length===10)M=S(this,H,V);else if(A<63)M=C(this,H,V);else if(A<1024)M=v(this,H,V);else M=T(this,H,V);return M};function k(q,H){this.x=q,this.y=H}k.prototype.makeRBT=function(H){var V=Array(H),M=X.prototype._countBits(H)-1;for(var A=0;A<H;A++)V[A]=this.revBin(A,M,H);return V},k.prototype.revBin=function(H,V,M){if(H===0||H===M-1)return H;var A=0;for(var I=0;I<V;I++)A|=(H&1)<<V-I-1,H>>=1;return A},k.prototype.permute=function(H,V,M,A,I,B){for(var P=0;P<B;P++)A[P]=V[H[P]],I[P]=M[H[P]]},k.prototype.transform=function(H,V,M,A,I,B){this.permute(B,H,V,M,A,I);for(var P=1;P<I;P<<=1){var F=P<<1,W=Math.cos(2*Math.PI/F),R=Math.sin(2*Math.PI/F);for(var x=0;x<I;x+=F){var y=W,g=R;for(var u=0;u<P;u++){var t=M[x+u],J0=A[x+u],A$=M[x+u+P],Z0=A[x+u+P],G0=y*A$-g*Z0;if(Z0=y*Z0+g*A$,A$=G0,M[x+u]=t+A$,A[x+u]=J0+Z0,M[x+u+P]=t-A$,A[x+u+P]=J0-Z0,u!==F)G0=W*y-R*g,g=W*g+R*y,y=G0}}}},k.prototype.guessLen13b=function(H,V){var M=Math.max(V,H)|1,A=M&1,I=0;for(M=M/2|0;M;M=M>>>1)I++;return 1<<I+1+A},k.prototype.conjugate=function(H,V,M){if(M<=1)return;for(var A=0;A<M/2;A++){var I=H[A];H[A]=H[M-A-1],H[M-A-1]=I,I=V[A],V[A]=-V[M-A-1],V[M-A-1]=-I}},k.prototype.normalize13b=function(H,V){var M=0;for(var A=0;A<V/2;A++){var I=Math.round(H[2*A+1]/V)*8192+Math.round(H[2*A]/V)+M;if(H[A]=I&67108863,I<67108864)M=0;else M=I/67108864|0}return H},k.prototype.convert13b=function(H,V,M,A){var I=0;for(var B=0;B<V;B++)I=I+(H[B]|0),M[2*B]=I&8191,I=I>>>13,M[2*B+1]=I&8191,I=I>>>13;for(B=2*V;B<A;++B)M[B]=0;Z(I===0),Z((I&-8192)===0)},k.prototype.stub=function(H){var V=Array(H);for(var M=0;M<H;M++)V[M]=0;return V},k.prototype.mulp=function(H,V,M){var A=2*this.guessLen13b(H.length,V.length),I=this.makeRBT(A),B=this.stub(A),P=Array(A),F=Array(A),W=Array(A),R=Array(A),x=Array(A),y=Array(A),g=M.words;g.length=A,this.convert13b(H.words,H.length,P,A),this.convert13b(V.words,V.length,R,A),this.transform(P,B,F,W,A,I),this.transform(R,B,x,y,A,I);for(var u=0;u<A;u++){var t=F[u]*x[u]-W[u]*y[u];W[u]=F[u]*y[u]+W[u]*x[u],F[u]=t}return this.conjugate(F,W,A),this.transform(F,W,g,B,A,I),this.conjugate(g,B,A),this.normalize13b(g,A),M.negative=H.negative^V.negative,M.length=H.length+V.length,M.strip()},X.prototype.mul=function(H){var V=new X(null);return V.words=Array(this.length+H.length),this.mulTo(H,V)},X.prototype.mulf=function(H){var V=new X(null);return V.words=Array(this.length+H.length),T(this,H,V)},X.prototype.imul=function(H){return this.clone().mulTo(H,this)},X.prototype.imuln=function(H){Z(typeof H==="number"),Z(H<67108864);var V=0;for(var M=0;M<this.length;M++){var A=(this.words[M]|0)*H,I=(A&67108863)+(V&67108863);V>>=26,V+=A/67108864|0,V+=I>>>26,this.words[M]=I&67108863}if(V!==0)this.words[M]=V,this.length++;return this.length=H===0?1:this.length,this},X.prototype.muln=function(H){return this.clone().imuln(H)},X.prototype.sqr=function(){return this.mul(this)},X.prototype.isqr=function(){return this.imul(this.clone())},X.prototype.pow=function(H){var V=j(H);if(V.length===0)return new X(1);var M=this;for(var A=0;A<V.length;A++,M=M.sqr())if(V[A]!==0)break;if(++A<V.length)for(var I=M.sqr();A<V.length;A++,I=I.sqr()){if(V[A]===0)continue;M=M.mul(I)}return M},X.prototype.iushln=function(H){Z(typeof H==="number"&&H>=0);var V=H%26,M=(H-V)/26,A=67108863>>>26-V<<26-V,I;if(V!==0){var B=0;for(I=0;I<this.length;I++){var P=this.words[I]&A,F=(this.words[I]|0)-P<<V;this.words[I]=F|B,B=P>>>26-V}if(B)this.words[I]=B,this.length++}if(M!==0){for(I=this.length-1;I>=0;I--)this.words[I+M]=this.words[I];for(I=0;I<M;I++)this.words[I]=0;this.length+=M}return this.strip()},X.prototype.ishln=function(H){return Z(this.negative===0),this.iushln(H)},X.prototype.iushrn=function(H,V,M){Z(typeof H==="number"&&H>=0);var A;if(V)A=(V-V%26)/26;else A=0;var I=H%26,B=Math.min((H-I)/26,this.length),P=67108863^67108863>>>I<<I,F=M;if(A-=B,A=Math.max(0,A),F){for(var W=0;W<B;W++)F.words[W]=this.words[W];F.length=B}if(B===0);else if(this.length>B){this.length-=B;for(W=0;W<this.length;W++)this.words[W]=this.words[W+B]}else this.words[0]=0,this.length=1;var R=0;for(W=this.length-1;W>=0&&(R!==0||W>=A);W--){var x=this.words[W]|0;this.words[W]=R<<26-I|x>>>I,R=x&P}if(F&&R!==0)F.words[F.length++]=R;if(this.length===0)this.words[0]=0,this.length=1;return this.strip()},X.prototype.ishrn=function(H,V,M){return Z(this.negative===0),this.iushrn(H,V,M)},X.prototype.shln=function(H){return this.clone().ishln(H)},X.prototype.ushln=function(H){return this.clone().iushln(H)},X.prototype.shrn=function(H){return this.clone().ishrn(H)},X.prototype.ushrn=function(H){return this.clone().iushrn(H)},X.prototype.testn=function(H){Z(typeof H==="number"&&H>=0);var V=H%26,M=(H-V)/26,A=1<<V;if(this.length<=M)return!1;var I=this.words[M];return!!(I&A)},X.prototype.imaskn=function(H){Z(typeof H==="number"&&H>=0);var V=H%26,M=(H-V)/26;if(Z(this.negative===0,"imaskn works only with positive numbers"),this.length<=M)return this;if(V!==0)M++;if(this.length=Math.min(M,this.length),V!==0){var A=67108863^67108863>>>V<<V;this.words[this.length-1]&=A}return this.strip()},X.prototype.maskn=function(H){return this.clone().imaskn(H)},X.prototype.iaddn=function(H){if(Z(typeof H==="number"),Z(H<67108864),H<0)return this.isubn(-H);if(this.negative!==0){if(this.length===1&&(this.words[0]|0)<H)return this.words[0]=H-(this.words[0]|0),this.negative=0,this;return this.negative=0,this.isubn(H),this.negative=1,this}return this._iaddn(H)},X.prototype._iaddn=function(H){this.words[0]+=H;for(var V=0;V<this.length&&this.words[V]>=67108864;V++)if(this.words[V]-=67108864,V===this.length-1)this.words[V+1]=1;else this.words[V+1]++;return this.length=Math.max(this.length,V+1),this},X.prototype.isubn=function(H){if(Z(typeof H==="number"),Z(H<67108864),H<0)return this.iaddn(-H);if(this.negative!==0)return this.negative=0,this.iaddn(H),this.negative=1,this;if(this.words[0]-=H,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var V=0;V<this.length&&this.words[V]<0;V++)this.words[V]+=67108864,this.words[V+1]-=1;return this.strip()},X.prototype.addn=function(H){return this.clone().iaddn(H)},X.prototype.subn=function(H){return this.clone().isubn(H)},X.prototype.iabs=function(){return this.negative=0,this},X.prototype.abs=function(){return this.clone().iabs()},X.prototype._ishlnsubmul=function(H,V,M){var A=H.length+M,I;this._expand(A);var B,P=0;for(I=0;I<H.length;I++){B=(this.words[I+M]|0)+P;var F=(H.words[I]|0)*V;B-=F&67108863,P=(B>>26)-(F/67108864|0),this.words[I+M]=B&67108863}for(;I<this.length-M;I++)B=(this.words[I+M]|0)+P,P=B>>26,this.words[I+M]=B&67108863;if(P===0)return this.strip();Z(P===-1),P=0;for(I=0;I<this.length;I++)B=-(this.words[I]|0)+P,P=B>>26,this.words[I]=B&67108863;return this.negative=1,this.strip()},X.prototype._wordDiv=function(H,V){var M=this.length-H.length,A=this.clone(),I=H,B=I.words[I.length-1]|0,P=this._countBits(B);if(M=26-P,M!==0)I=I.ushln(M),A.iushln(M),B=I.words[I.length-1]|0;var F=A.length-I.length,W;if(V!=="mod"){W=new X(null),W.length=F+1,W.words=Array(W.length);for(var R=0;R<W.length;R++)W.words[R]=0}var x=A.clone()._ishlnsubmul(I,1,F);if(x.negative===0){if(A=x,W)W.words[F]=1}for(var y=F-1;y>=0;y--){var g=(A.words[I.length+y]|0)*67108864+(A.words[I.length+y-1]|0);g=Math.min(g/B|0,67108863),A._ishlnsubmul(I,g,y);while(A.negative!==0)if(g--,A.negative=0,A._ishlnsubmul(I,1,y),!A.isZero())A.negative^=1;if(W)W.words[y]=g}if(W)W.strip();if(A.strip(),V!=="div"&&M!==0)A.iushrn(M);return{div:W||null,mod:A}},X.prototype.divmod=function(H,V,M){if(Z(!H.isZero()),this.isZero())return{div:new X(0),mod:new X(0)};var A,I,B;if(this.negative!==0&&H.negative===0){if(B=this.neg().divmod(H,V),V!=="mod")A=B.div.neg();if(V!=="div"){if(I=B.mod.neg(),M&&I.negative!==0)I.iadd(H)}return{div:A,mod:I}}if(this.negative===0&&H.negative!==0){if(B=this.divmod(H.neg(),V),V!=="mod")A=B.div.neg();return{div:A,mod:B.mod}}if((this.negative&H.negative)!==0){if(B=this.neg().divmod(H.neg(),V),V!=="div"){if(I=B.mod.neg(),M&&I.negative!==0)I.isub(H)}return{div:B.div,mod:I}}if(H.length>this.length||this.cmp(H)<0)return{div:new X(0),mod:this};if(H.length===1){if(V==="div")return{div:this.divn(H.words[0]),mod:null};if(V==="mod")return{div:null,mod:new X(this.modn(H.words[0]))};return{div:this.divn(H.words[0]),mod:new X(this.modn(H.words[0]))}}return this._wordDiv(H,V)},X.prototype.div=function(H){return this.divmod(H,"div",!1).div},X.prototype.mod=function(H){return this.divmod(H,"mod",!1).mod},X.prototype.umod=function(H){return this.divmod(H,"mod",!0).mod},X.prototype.divRound=function(H){var V=this.divmod(H);if(V.mod.isZero())return V.div;var M=V.div.negative!==0?V.mod.isub(H):V.mod,A=H.ushrn(1),I=H.andln(1),B=M.cmp(A);if(B<0||I===1&&B===0)return V.div;return V.div.negative!==0?V.div.isubn(1):V.div.iaddn(1)},X.prototype.modn=function(H){Z(H<=67108863);var V=67108864%H,M=0;for(var A=this.length-1;A>=0;A--)M=(V*M+(this.words[A]|0))%H;return M},X.prototype.idivn=function(H){Z(H<=67108863);var V=0;for(var M=this.length-1;M>=0;M--){var A=(this.words[M]|0)+V*67108864;this.words[M]=A/H|0,V=A%H}return this.strip()},X.prototype.divn=function(H){return this.clone().idivn(H)},X.prototype.egcd=function(H){Z(H.negative===0),Z(!H.isZero());var V=this,M=H.clone();if(V.negative!==0)V=V.umod(H);else V=V.clone();var A=new X(1),I=new X(0),B=new X(0),P=new X(1),F=0;while(V.isEven()&&M.isEven())V.iushrn(1),M.iushrn(1),++F;var W=M.clone(),R=V.clone();while(!V.isZero()){for(var x=0,y=1;(V.words[0]&y)===0&&x<26;++x,y<<=1);if(x>0){V.iushrn(x);while(x-- >0){if(A.isOdd()||I.isOdd())A.iadd(W),I.isub(R);A.iushrn(1),I.iushrn(1)}}for(var g=0,u=1;(M.words[0]&u)===0&&g<26;++g,u<<=1);if(g>0){M.iushrn(g);while(g-- >0){if(B.isOdd()||P.isOdd())B.iadd(W),P.isub(R);B.iushrn(1),P.iushrn(1)}}if(V.cmp(M)>=0)V.isub(M),A.isub(B),I.isub(P);else M.isub(V),B.isub(A),P.isub(I)}return{a:B,b:P,gcd:M.iushln(F)}},X.prototype._invmp=function(H){Z(H.negative===0),Z(!H.isZero());var V=this,M=H.clone();if(V.negative!==0)V=V.umod(H);else V=V.clone();var A=new X(1),I=new X(0),B=M.clone();while(V.cmpn(1)>0&&M.cmpn(1)>0){for(var P=0,F=1;(V.words[0]&F)===0&&P<26;++P,F<<=1);if(P>0){V.iushrn(P);while(P-- >0){if(A.isOdd())A.iadd(B);A.iushrn(1)}}for(var W=0,R=1;(M.words[0]&R)===0&&W<26;++W,R<<=1);if(W>0){M.iushrn(W);while(W-- >0){if(I.isOdd())I.iadd(B);I.iushrn(1)}}if(V.cmp(M)>=0)V.isub(M),A.isub(I);else M.isub(V),I.isub(A)}var x;if(V.cmpn(1)===0)x=A;else x=I;if(x.cmpn(0)<0)x.iadd(H);return x},X.prototype.gcd=function(H){if(this.isZero())return H.abs();if(H.isZero())return this.abs();var V=this.clone(),M=H.clone();V.negative=0,M.negative=0;for(var A=0;V.isEven()&&M.isEven();A++)V.iushrn(1),M.iushrn(1);do{while(V.isEven())V.iushrn(1);while(M.isEven())M.iushrn(1);var I=V.cmp(M);if(I<0){var B=V;V=M,M=B}else if(I===0||M.cmpn(1)===0)break;V.isub(M)}while(!0);return M.iushln(A)},X.prototype.invm=function(H){return this.egcd(H).a.umod(H)},X.prototype.isEven=function(){return(this.words[0]&1)===0},X.prototype.isOdd=function(){return(this.words[0]&1)===1},X.prototype.andln=function(H){return this.words[0]&H},X.prototype.bincn=function(H){Z(typeof H==="number");var V=H%26,M=(H-V)/26,A=1<<V;if(this.length<=M)return this._expand(M+1),this.words[M]|=A,this;var I=A;for(var B=M;I!==0&&B<this.length;B++){var P=this.words[B]|0;P+=I,I=P>>>26,P&=67108863,this.words[B]=P}if(I!==0)this.words[B]=I,this.length++;return this},X.prototype.isZero=function(){return this.length===1&&this.words[0]===0},X.prototype.cmpn=function(H){var V=H<0;if(this.negative!==0&&!V)return-1;if(this.negative===0&&V)return 1;this.strip();var M;if(this.length>1)M=1;else{if(V)H=-H;Z(H<=67108863,"Number is too big");var A=this.words[0]|0;M=A===H?0:A<H?-1:1}if(this.negative!==0)return-M|0;return M},X.prototype.cmp=function(H){if(this.negative!==0&&H.negative===0)return-1;if(this.negative===0&&H.negative!==0)return 1;var V=this.ucmp(H);if(this.negative!==0)return-V|0;return V},X.prototype.ucmp=function(H){if(this.length>H.length)return 1;if(this.length<H.length)return-1;var V=0;for(var M=this.length-1;M>=0;M--){var A=this.words[M]|0,I=H.words[M]|0;if(A===I)continue;if(A<I)V=-1;else if(A>I)V=1;break}return V},X.prototype.gtn=function(H){return this.cmpn(H)===1},X.prototype.gt=function(H){return this.cmp(H)===1},X.prototype.gten=function(H){return this.cmpn(H)>=0},X.prototype.gte=function(H){return this.cmp(H)>=0},X.prototype.ltn=function(H){return this.cmpn(H)===-1},X.prototype.lt=function(H){return this.cmp(H)===-1},X.prototype.lten=function(H){return this.cmpn(H)<=0},X.prototype.lte=function(H){return this.cmp(H)<=0},X.prototype.eqn=function(H){return this.cmpn(H)===0},X.prototype.eq=function(H){return this.cmp(H)===0},X.red=function(H){return new r(H)},X.prototype.toRed=function(H){return Z(!this.red,"Already a number in reduction context"),Z(this.negative===0,"red works only with positives"),H.convertTo(this)._forceRed(H)},X.prototype.fromRed=function(){return Z(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},X.prototype._forceRed=function(H){return this.red=H,this},X.prototype.forceRed=function(H){return Z(!this.red,"Already a number in reduction context"),this._forceRed(H)},X.prototype.redAdd=function(H){return Z(this.red,"redAdd works only with red numbers"),this.red.add(this,H)},X.prototype.redIAdd=function(H){return Z(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,H)},X.prototype.redSub=function(H){return Z(this.red,"redSub works only with red numbers"),this.red.sub(this,H)},X.prototype.redISub=function(H){return Z(this.red,"redISub works only with red numbers"),this.red.isub(this,H)},X.prototype.redShl=function(H){return Z(this.red,"redShl works only with red numbers"),this.red.shl(this,H)},X.prototype.redMul=function(H){return Z(this.red,"redMul works only with red numbers"),this.red._verify2(this,H),this.red.mul(this,H)},X.prototype.redIMul=function(H){return Z(this.red,"redMul works only with red numbers"),this.red._verify2(this,H),this.red.imul(this,H)},X.prototype.redSqr=function(){return Z(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},X.prototype.redISqr=function(){return Z(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},X.prototype.redSqrt=function(){return Z(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},X.prototype.redInvm=function(){return Z(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},X.prototype.redNeg=function(){return Z(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},X.prototype.redPow=function(H){return Z(this.red&&!H.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,H)};var E={k256:null,p224:null,p192:null,p25519:null};function w(q,H){this.name=q,this.p=new X(H,16),this.n=this.p.bitLength(),this.k=new X(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}w.prototype._tmp=function(){var H=new X(null);return H.words=Array(Math.ceil(this.n/13)),H},w.prototype.ireduce=function(H){var V=H,M;do this.split(V,this.tmp),V=this.imulK(V),V=V.iadd(this.tmp),M=V.bitLength();while(M>this.n);var A=M<this.n?-1:V.ucmp(this.p);if(A===0)V.words[0]=0,V.length=1;else if(A>0)V.isub(this.p);else if(V.strip!==void 0)V.strip();else V._strip();return V},w.prototype.split=function(H,V){H.iushrn(this.n,0,V)},w.prototype.imulK=function(H){return H.imul(this.k)};function f(){w.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}Y(f,w),f.prototype.split=function(H,V){var M=4194303,A=Math.min(H.length,9);for(var I=0;I<A;I++)V.words[I]=H.words[I];if(V.length=A,H.length<=9){H.words[0]=0,H.length=1;return}var B=H.words[9];V.words[V.length++]=B&M;for(I=10;I<H.length;I++){var P=H.words[I]|0;H.words[I-10]=(P&M)<<4|B>>>22,B=P}if(B>>>=22,H.words[I-10]=B,B===0&&H.length>10)H.length-=10;else H.length-=9},f.prototype.imulK=function(H){H.words[H.length]=0,H.words[H.length+1]=0,H.length+=2;var V=0;for(var M=0;M<H.length;M++){var A=H.words[M]|0;V+=A*977,H.words[M]=V&67108863,V=A*64+(V/67108864|0)}if(H.words[H.length-1]===0){if(H.length--,H.words[H.length-1]===0)H.length--}return H};function D(){w.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}Y(D,w);function m(){w.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}Y(m,w);function a(){w.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}Y(a,w),a.prototype.imulK=function(H){var V=0;for(var M=0;M<H.length;M++){var A=(H.words[M]|0)*19+V,I=A&67108863;A>>>=26,H.words[M]=I,V=A}if(V!==0)H.words[H.length++]=V;return H},X._prime=function(H){if(E[H])return E[H];var V;if(H==="k256")V=new f;else if(H==="p224")V=new D;else if(H==="p192")V=new m;else if(H==="p25519")V=new a;else throw Error("Unknown prime "+H);return E[H]=V,V};function r(q){if(typeof q==="string"){var H=X._prime(q);this.m=H.p,this.prime=H}else Z(q.gtn(1),"modulus must be greater than 1"),this.m=q,this.prime=null}r.prototype._verify1=function(H){Z(H.negative===0,"red works only with positives"),Z(H.red,"red works only with red numbers")},r.prototype._verify2=function(H,V){Z((H.negative|V.negative)===0,"red works only with positives"),Z(H.red&&H.red===V.red,"red works only with red numbers")},r.prototype.imod=function(H){if(this.prime)return this.prime.ireduce(H)._forceRed(this);return H.umod(this.m)._forceRed(this)},r.prototype.neg=function(H){if(H.isZero())return H.clone();return this.m.sub(H)._forceRed(this)},r.prototype.add=function(H,V){this._verify2(H,V);var M=H.add(V);if(M.cmp(this.m)>=0)M.isub(this.m);return M._forceRed(this)},r.prototype.iadd=function(H,V){this._verify2(H,V);var M=H.iadd(V);if(M.cmp(this.m)>=0)M.isub(this.m);return M},r.prototype.sub=function(H,V){this._verify2(H,V);var M=H.sub(V);if(M.cmpn(0)<0)M.iadd(this.m);return M._forceRed(this)},r.prototype.isub=function(H,V){this._verify2(H,V);var M=H.isub(V);if(M.cmpn(0)<0)M.iadd(this.m);return M},r.prototype.shl=function(H,V){return this._verify1(H),this.imod(H.ushln(V))},r.prototype.imul=function(H,V){return this._verify2(H,V),this.imod(H.imul(V))},r.prototype.mul=function(H,V){return this._verify2(H,V),this.imod(H.mul(V))},r.prototype.isqr=function(H){return this.imul(H,H.clone())},r.prototype.sqr=function(H){return this.mul(H,H)},r.prototype.sqrt=function(H){if(H.isZero())return H.clone();var V=this.m.andln(3);if(Z(V%2===1),V===3){var M=this.m.add(new X(1)).iushrn(2);return this.pow(H,M)}var A=this.m.subn(1),I=0;while(!A.isZero()&&A.andln(1)===0)I++,A.iushrn(1);Z(!A.isZero());var B=new X(1).toRed(this),P=B.redNeg(),F=this.m.subn(1).iushrn(1),W=this.m.bitLength();W=new X(2*W*W).toRed(this);while(this.pow(W,F).cmp(P)!==0)W.redIAdd(P);var R=this.pow(W,A),x=this.pow(H,A.addn(1).iushrn(1)),y=this.pow(H,A),g=I;while(y.cmp(B)!==0){var u=y;for(var t=0;u.cmp(B)!==0;t++)u=u.redSqr();Z(t<g);var J0=this.pow(R,new X(1).iushln(g-t-1));x=x.redMul(J0),R=J0.redSqr(),y=y.redMul(R),g=t}return x},r.prototype.invm=function(H){var V=H._invmp(this.m);if(V.negative!==0)return V.negative=0,this.imod(V).redNeg();else return this.imod(V)},r.prototype.pow=function(H,V){if(V.isZero())return new X(1).toRed(this);if(V.cmpn(1)===0)return H.clone();var M=4,A=Array(1<<M);A[0]=new X(1).toRed(this),A[1]=H;for(var I=2;I<A.length;I++)A[I]=this.mul(A[I-1],H);var B=A[0],P=0,F=0,W=V.bitLength()%26;if(W===0)W=26;for(I=V.length-1;I>=0;I--){var R=V.words[I];for(var x=W-1;x>=0;x--){var y=R>>x&1;if(B!==A[0])B=this.sqr(B);if(y===0&&P===0){F=0;continue}if(P<<=1,P|=y,F++,F!==M&&(I!==0||x!==0))continue;B=this.mul(B,A[P]),F=0,P=0}W=26}return B},r.prototype.convertTo=function(H){var V=H.umod(this.m);return V===H?V.clone():V},r.prototype.convertFrom=function(H){var V=H.clone();return V.red=null,V},X.mont=function(H){return new i(H)};function i(q){if(r.call(this,q),this.shift=this.m.bitLength(),this.shift%26!==0)this.shift+=26-this.shift%26;this.r=new X(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}Y(i,r),i.prototype.convertTo=function(H){return this.imod(H.ushln(this.shift))},i.prototype.convertFrom=function(H){var V=this.imod(H.mul(this.rinv));return V.red=null,V},i.prototype.imul=function(H,V){if(H.isZero()||V.isZero())return H.words[0]=0,H.length=1,H;var M=H.imul(V),A=M.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),I=M.isub(A).iushrn(this.shift),B=I;if(I.cmp(this.m)>=0)B=I.isub(this.m);else if(I.cmpn(0)<0)B=I.iadd(this.m);return B._forceRed(this)},i.prototype.mul=function(H,V){if(H.isZero()||V.isZero())return new X(0)._forceRed(this);var M=H.mul(V),A=M.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),I=M.isub(A).iushrn(this.shift),B=I;if(I.cmp(this.m)>=0)B=I.isub(this.m);else if(I.cmpn(0)<0)B=I.iadd(this.m);return B._forceRed(this)},i.prototype.invm=function(H){var V=this.imod(H._invmp(this.m).mul(this.r2));return V._forceRed(this)}})(typeof oZ>"u"||oZ,IG)});var qG=l((b5,rZ)=>{if(typeof Object.create==="function")rZ.exports=function(J,Z){if(Z)J.super_=Z,J.prototype=Object.create(Z.prototype,{constructor:{value:J,enumerable:!1,writable:!0,configurable:!0}})};else rZ.exports=function(J,Z){if(Z){J.super_=Z;var Y=function(){};Y.prototype=Z.prototype,J.prototype=new Y,J.prototype.constructor=J}}});var C$=l((c5,iZ)=>{try{if(SJ=K$("util"),typeof SJ.inherits!=="function")throw"";iZ.exports=SJ.inherits}catch($){iZ.exports=qG()}var SJ});var TJ=l((p5,LG)=>{var wJ=K$("buffer"),m$=wJ.Buffer,t0={},a0;for(a0 in wJ){if(!wJ.hasOwnProperty(a0))continue;if(a0==="SlowBuffer"||a0==="Buffer")continue;t0[a0]=wJ[a0]}var n$=t0.Buffer={};for(a0 in m$){if(!m$.hasOwnProperty(a0))continue;if(a0==="allocUnsafe"||a0==="allocUnsafeSlow")continue;n$[a0]=m$[a0]}t0.Buffer.prototype=m$.prototype;if(!n$.from||n$.from===Uint8Array.from)n$.from=function($,J,Z){if(typeof $==="number")throw TypeError('The "value" argument must not be of type number. Received type '+typeof $);if($&&typeof $.length>"u")throw TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof $);return m$($,J,Z)};if(!n$.alloc)n$.alloc=function($,J,Z){if(typeof $!=="number")throw TypeError('The "size" argument must be of type number. Received type '+typeof $);if($<0||$>=2147483648)throw RangeError('The value "'+$+'" is invalid for option "size"');var Y=m$($);if(!J||J.length===0)Y.fill(0);else if(typeof Z==="string")Y.fill(J,Z);else Y.fill(J);return Y};if(!t0.kStringMaxLength)try{t0.kStringMaxLength=process.binding("buffer").kStringMaxLength}catch($){}if(!t0.constants){if(t0.constants={MAX_LENGTH:t0.kMaxLength},t0.kStringMaxLength)t0.constants.MAX_STRING_LENGTH=t0.kStringMaxLength}LG.exports=t0});var NJ=l((uW)=>{var pW=C$();function e0($){this._reporterState={obj:null,path:[],options:$||{},errors:[]}}uW.Reporter=e0;e0.prototype.isError=function(J){return J instanceof d$};e0.prototype.save=function(){let J=this._reporterState;return{obj:J.obj,pathLen:J.path.length}};e0.prototype.restore=function(J){let Z=this._reporterState;Z.obj=J.obj,Z.path=Z.path.slice(0,J.pathLen)};e0.prototype.enterKey=function(J){return this._reporterState.path.push(J)};e0.prototype.exitKey=function(J){let Z=this._reporterState;Z.path=Z.path.slice(0,J-1)};e0.prototype.leaveKey=function(J,Z,Y){let X=this._reporterState;if(this.exitKey(J),X.obj!==null)X.obj[Z]=Y};e0.prototype.path=function(){return this._reporterState.path.join("/")};e0.prototype.enterObject=function(){let J=this._reporterState,Z=J.obj;return J.obj={},Z};e0.prototype.leaveObject=function(J){let Z=this._reporterState,Y=Z.obj;return Z.obj=J,Y};e0.prototype.error=function(J){let Z,Y=this._reporterState,X=J instanceof d$;if(X)Z=J;else Z=new d$(Y.path.map(function(G){return"["+JSON.stringify(G)+"]"}).join(""),J.message||J,J.stack);if(!Y.options.partial)throw Z;if(!X)Y.errors.push(Z);return Z};e0.prototype.wrapResult=function(J){let Z=this._reporterState;if(!Z.options.partial)return J;return{result:this.isError(J)?null:J,errors:Z.errors}};function d$($,J){this.path=$,this.rethrow(J)}pW(d$,Error);d$.prototype.rethrow=function(J){if(this.message=J+" at: "+(this.path||"(shallow)"),Error.captureStackTrace)Error.captureStackTrace(this,d$);if(!this.stack)try{throw Error(this.message)}catch(Z){this.stack=Z.stack}return this}});var l$=l((dW)=>{var nW=C$(),DJ=NJ().Reporter,s$=TJ().Buffer;function $$($,J){if(DJ.call(this,J),!s$.isBuffer($)){this.error("Input not Buffer");return}this.base=$,this.offset=0,this.length=$.length}nW($$,DJ);dW.DecoderBuffer=$$;$$.isDecoderBuffer=function(J){if(J instanceof $$)return!0;return typeof J==="object"&&s$.isBuffer(J.base)&&J.constructor.name==="DecoderBuffer"&&typeof J.offset==="number"&&typeof J.length==="number"&&typeof J.save==="function"&&typeof J.restore==="function"&&typeof J.isEmpty==="function"&&typeof J.readUInt8==="function"&&typeof J.skip==="function"&&typeof J.raw==="function"};$$.prototype.save=function(){return{offset:this.offset,reporter:DJ.prototype.save.call(this)}};$$.prototype.restore=function(J){let Z=new $$(this.base);return Z.offset=J.offset,Z.length=this.offset,this.offset=J.offset,DJ.prototype.restore.call(this,J.reporter),Z};$$.prototype.isEmpty=function(){return this.offset===this.length};$$.prototype.readUInt8=function(J){if(this.offset+1<=this.length)return this.base.readUInt8(this.offset++,!0);else return this.error(J||"DecoderBuffer overrun")};$$.prototype.skip=function(J,Z){if(!(this.offset+J<=this.length))return this.error(Z||"DecoderBuffer overrun");let Y=new $$(this.base);return Y._reporterState=this._reporterState,Y.offset=this.offset,Y.length=this.offset+J,this.offset+=J,Y};$$.prototype.raw=function(J){return this.base.slice(J?J.offset:this.offset,this.length)};function o$($,J){if(Array.isArray($))this.length=0,this.value=$.map(function(Z){if(!o$.isEncoderBuffer(Z))Z=new o$(Z,J);return this.length+=Z.length,Z},this);else if(typeof $==="number"){if(!(0<=$&&$<=255))return J.error("non-byte EncoderBuffer value");this.value=$,this.length=1}else if(typeof $==="string")this.value=$,this.length=s$.byteLength($);else if(s$.isBuffer($))this.value=$,this.length=$.length;else return J.error("Unsupported type: "+typeof $)}dW.EncoderBuffer=o$;o$.isEncoderBuffer=function(J){if(J instanceof o$)return!0;return typeof J==="object"&&J.constructor.name==="EncoderBuffer"&&typeof J.length==="number"&&typeof J.join==="function"};o$.prototype.join=function(J,Z){if(!J)J=s$.alloc(this.length);if(!Z)Z=0;if(this.length===0)return J;if(Array.isArray(this.value))this.value.forEach(function(Y){Y.join(J,Z),Z+=Y.length});else{if(typeof this.value==="number")J[Z]=this.value;else if(typeof this.value==="string")J.write(this.value,Z);else if(s$.isBuffer(this.value))this.value.copy(J,Z);Z+=this.length}return J}});var PG=l((n5,BG)=>{BG.exports=jG;function jG($,J){if(!$)throw Error(J||"Assertion failed")}jG.equal=function(J,Z,Y){if(J!=Z)throw Error(Y||"Assertion failed: "+J+" != "+Z)}});var vJ=l((d5,CG)=>{var lW=NJ().Reporter,rW=l$().EncoderBuffer,iW=l$().DecoderBuffer,o0=PG(),EG=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],tW=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(EG),aW=["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"];function e($,J,Z){let Y={};if(this._baseState=Y,Y.name=Z,Y.enc=$,Y.parent=J||null,Y.children=null,Y.tag=null,Y.args=null,Y.reverseArgs=null,Y.choice=null,Y.optional=!1,Y.any=!1,Y.obj=!1,Y.use=null,Y.useDecoder=null,Y.key=null,Y.default=null,Y.explicit=null,Y.implicit=null,Y.contains=null,!Y.parent)Y.children=[],this._wrap()}CG.exports=e;var eW=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];e.prototype.clone=function(){let J=this._baseState,Z={};eW.forEach(function(X){Z[X]=J[X]});let Y=new this.constructor(Z.parent);return Y._baseState=Z,Y};e.prototype._wrap=function(){let J=this._baseState;tW.forEach(function(Z){this[Z]=function(){let X=new this.constructor(this);return J.children.push(X),X[Z].apply(X,arguments)}},this)};e.prototype._init=function(J){let Z=this._baseState;o0(Z.parent===null),J.call(this),Z.children=Z.children.filter(function(Y){return Y._baseState.parent===this},this),o0.equal(Z.children.length,1,"Root node can have only one child")};e.prototype._useArgs=function(J){let Z=this._baseState,Y=J.filter(function(X){return X instanceof this.constructor},this);if(J=J.filter(function(X){return!(X instanceof this.constructor)},this),Y.length!==0)o0(Z.children===null),Z.children=Y,Y.forEach(function(X){X._baseState.parent=this},this);if(J.length!==0)o0(Z.args===null),Z.args=J,Z.reverseArgs=J.map(function(X){if(typeof X!=="object"||X.constructor!==Object)return X;let G={};return Object.keys(X).forEach(function(Q){if(Q==(Q|0))Q|=0;let U=X[Q];G[U]=Q}),G})};aW.forEach(function($){e.prototype[$]=function(){let Z=this._baseState;throw Error($+" not implemented for encoding: "+Z.enc)}});EG.forEach(function($){e.prototype[$]=function(){let Z=this._baseState,Y=Array.prototype.slice.call(arguments);return o0(Z.tag===null),Z.tag=$,this._useArgs(Y),this}});e.prototype.use=function(J){o0(J);let Z=this._baseState;return o0(Z.use===null),Z.use=J,this};e.prototype.optional=function(){let J=this._baseState;return J.optional=!0,this};e.prototype.def=function(J){let Z=this._baseState;return o0(Z.default===null),Z.default=J,Z.optional=!0,this};e.prototype.explicit=function(J){let Z=this._baseState;return o0(Z.explicit===null&&Z.implicit===null),Z.explicit=J,this};e.prototype.implicit=function(J){let Z=this._baseState;return o0(Z.explicit===null&&Z.implicit===null),Z.implicit=J,this};e.prototype.obj=function(){let J=this._baseState,Z=Array.prototype.slice.call(arguments);if(J.obj=!0,Z.length!==0)this._useArgs(Z);return this};e.prototype.key=function(J){let Z=this._baseState;return o0(Z.key===null),Z.key=J,this};e.prototype.any=function(){let J=this._baseState;return J.any=!0,this};e.prototype.choice=function(J){let Z=this._baseState;return o0(Z.choice===null),Z.choice=J,this._useArgs(Object.keys(J).map(function(Y){return J[Y]})),this};e.prototype.contains=function(J){let Z=this._baseState;return o0(Z.use===null),Z.contains=J,this};e.prototype._decode=function(J,Z){let Y=this._baseState;if(Y.parent===null)return J.wrapResult(Y.children[0]._decode(J,Z));let X=Y.default,G=!0,Q=null;if(Y.key!==null)Q=J.enterKey(Y.key);if(Y.optional){let z=null;if(Y.explicit!==null)z=Y.explicit;else if(Y.implicit!==null)z=Y.implicit;else if(Y.tag!==null)z=Y.tag;if(z===null&&!Y.any){let O=J.save();try{if(Y.choice===null)this._decodeGeneric(Y.tag,J,Z);else this._decodeChoice(J,Z);G=!0}catch(_){G=!1}J.restore(O)}else if(G=this._peekTag(J,z,Y.any),J.isError(G))return G}let U;if(Y.obj&&G)U=J.enterObject();if(G){if(Y.explicit!==null){let O=this._decodeTag(J,Y.explicit);if(J.isError(O))return O;J=O}let z=J.offset;if(Y.use===null&&Y.choice===null){let O;if(Y.any)O=J.save();let _=this._decodeTag(J,Y.implicit!==null?Y.implicit:Y.tag,Y.any);if(J.isError(_))return _;if(Y.any)X=J.raw(O);else J=_}if(Z&&Z.track&&Y.tag!==null)Z.track(J.path(),z,J.length,"tagged");if(Z&&Z.track&&Y.tag!==null)Z.track(J.path(),J.offset,J.length,"content");if(Y.any);else if(Y.choice===null)X=this._decodeGeneric(Y.tag,J,Z);else X=this._decodeChoice(J,Z);if(J.isError(X))return X;if(!Y.any&&Y.choice===null&&Y.children!==null)Y.children.forEach(function(_){_._decode(J,Z)});if(Y.contains&&(Y.tag==="octstr"||Y.tag==="bitstr")){let O=new iW(X);X=this._getUse(Y.contains,J._reporterState.obj)._decode(O,Z)}}if(Y.obj&&G)X=J.leaveObject(U);if(Y.key!==null&&(X!==null||G===!0))J.leaveKey(Q,Y.key,X);else if(Q!==null)J.exitKey(Q);return X};e.prototype._decodeGeneric=function(J,Z,Y){let X=this._baseState;if(J==="seq"||J==="set")return null;if(J==="seqof"||J==="setof")return this._decodeList(Z,J,X.args[0],Y);else if(/str$/.test(J))return this._decodeStr(Z,J,Y);else if(J==="objid"&&X.args)return this._decodeObjid(Z,X.args[0],X.args[1],Y);else if(J==="objid")return this._decodeObjid(Z,null,null,Y);else if(J==="gentime"||J==="utctime")return this._decodeTime(Z,J,Y);else if(J==="null_")return this._decodeNull(Z,Y);else if(J==="bool")return this._decodeBool(Z,Y);else if(J==="objDesc")return this._decodeStr(Z,J,Y);else if(J==="int"||J==="enum")return this._decodeInt(Z,X.args&&X.args[0],Y);if(X.use!==null)return this._getUse(X.use,Z._reporterState.obj)._decode(Z,Y);else return Z.error("unknown tag: "+J)};e.prototype._getUse=function(J,Z){let Y=this._baseState;if(Y.useDecoder=this._use(J,Z),o0(Y.useDecoder._baseState.parent===null),Y.useDecoder=Y.useDecoder._baseState.children[0],Y.implicit!==Y.useDecoder._baseState.implicit)Y.useDecoder=Y.useDecoder.clone(),Y.useDecoder._baseState.implicit=Y.implicit;return Y.useDecoder};e.prototype._decodeChoice=function(J,Z){let Y=this._baseState,X=null,G=!1;if(Object.keys(Y.choice).some(function(Q){let U=J.save(),z=Y.choice[Q];try{let O=z._decode(J,Z);if(J.isError(O))return!1;X={type:Q,value:O},G=!0}catch(O){return J.restore(U),!1}return!0},this),!G)return J.error("Choice not matched");return X};e.prototype._createEncoderBuffer=function(J){return new rW(J,this.reporter)};e.prototype._encode=function(J,Z,Y){let X=this._baseState;if(X.default!==null&&X.default===J)return;let G=this._encodeValue(J,Z,Y);if(G===void 0)return;if(this._skipDefault(G,Z,Y))return;return G};e.prototype._encodeValue=function(J,Z,Y){let X=this._baseState;if(X.parent===null)return X.children[0]._encode(J,Z||new lW);let G=null;if(this.reporter=Z,X.optional&&J===void 0)if(X.default!==null)J=X.default;else return;let Q=null,U=!1;if(X.any)G=this._createEncoderBuffer(J);else if(X.choice)G=this._encodeChoice(J,Z);else if(X.contains)Q=this._getUse(X.contains,Y)._encode(J,Z),U=!0;else if(X.children)Q=X.children.map(function(z){if(z._baseState.tag==="null_")return z._encode(null,Z,J);if(z._baseState.key===null)return Z.error("Child should have a key");let O=Z.enterKey(z._baseState.key);if(typeof J!=="object")return Z.error("Child expected, but input is not object");let _=z._encode(J[z._baseState.key],Z,J);return Z.leaveKey(O),_},this).filter(function(z){return z}),Q=this._createEncoderBuffer(Q);else if(X.tag==="seqof"||X.tag==="setof"){if(!(X.args&&X.args.length===1))return Z.error("Too many args for : "+X.tag);if(!Array.isArray(J))return Z.error("seqof/setof, but data is not Array");let z=this.clone();z._baseState.implicit=null,Q=this._createEncoderBuffer(J.map(function(O){let _=this._baseState;return this._getUse(_.args[0],J)._encode(O,Z)},z))}else if(X.use!==null)G=this._getUse(X.use,Y)._encode(J,Z);else Q=this._encodePrimitive(X.tag,J),U=!0;if(!X.any&&X.choice===null){let z=X.implicit!==null?X.implicit:X.tag,O=X.implicit===null?"universal":"context";if(z===null){if(X.use===null)Z.error("Tag could be omitted only for .use()")}else if(X.use===null)G=this._encodeComposite(z,U,O,Q)}if(X.explicit!==null)G=this._encodeComposite(X.explicit,!1,"context",G);return G};e.prototype._encodeChoice=function(J,Z){let Y=this._baseState,X=Y.choice[J.type];if(!X)o0(!1,J.type+" not found in "+JSON.stringify(Object.keys(Y.choice)));return X._encode(J.value,Z)};e.prototype._encodePrimitive=function(J,Z){let Y=this._baseState;if(/str$/.test(J))return this._encodeStr(Z,J);else if(J==="objid"&&Y.args)return this._encodeObjid(Z,Y.reverseArgs[0],Y.args[1]);else if(J==="objid")return this._encodeObjid(Z,null,null);else if(J==="gentime"||J==="utctime")return this._encodeTime(Z,J);else if(J==="null_")return this._encodeNull();else if(J==="int"||J==="enum")return this._encodeInt(Z,Y.args&&Y.reverseArgs[0]);else if(J==="bool")return this._encodeBool(Z);else if(J==="objDesc")return this._encodeStr(Z,J);else throw Error("Unsupported tag: "+J)};e.prototype._isNumstr=function(J){return/^[0-9 ]*$/.test(J)};e.prototype._isPrintstr=function(J){return/^[A-Za-z0-9 '()+,-./:=?]*$/.test(J)}});var kJ=l(($9)=>{function SG($){let J={};return Object.keys($).forEach(function(Z){if((Z|0)==Z)Z=Z|0;let Y=$[Z];J[Y]=Z}),J}$9.tagClass={0:"universal",1:"application",2:"context",3:"private"};$9.tagClassByName=SG($9.tagClass);$9.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"};$9.tagByName=SG($9.tag)});var aZ=l((o5,vG)=>{var Y9=C$(),O$=TJ().Buffer,NG=vJ(),tZ=kJ();function DG($){this.enc="der",this.name=$.name,this.entity=$,this.tree=new Z$,this.tree._init($.body)}vG.exports=DG;DG.prototype.encode=function(J,Z){return this.tree._encode(J,Z).join()};function Z$($){NG.call(this,"der",$)}Y9(Z$,NG);Z$.prototype._encodeComposite=function(J,Z,Y,X){let G=X9(J,Z,Y,this.reporter);if(X.length<128){let z=O$.alloc(2);return z[0]=G,z[1]=X.length,this._createEncoderBuffer([z,X])}let Q=1;for(let z=X.length;z>=256;z>>=8)Q++;let U=O$.alloc(2+Q);U[0]=G,U[1]=128|Q;for(let z=1+Q,O=X.length;O>0;z--,O>>=8)U[z]=O&255;return this._createEncoderBuffer([U,X])};Z$.prototype._encodeStr=function(J,Z){if(Z==="bitstr")return this._createEncoderBuffer([J.unused|0,J.data]);else if(Z==="bmpstr"){let Y=O$.alloc(J.length*2);for(let X=0;X<J.length;X++)Y.writeUInt16BE(J.charCodeAt(X),X*2);return this._createEncoderBuffer(Y)}else if(Z==="numstr"){if(!this._isNumstr(J))return this.reporter.error("Encoding of string type: numstr supports only digits and space");return this._createEncoderBuffer(J)}else if(Z==="printstr"){if(!this._isPrintstr(J))return this.reporter.error("Encoding of string type: printstr supports only latin upper and lower case letters, digits, space, apostrophe, left and rigth parenthesis, plus sign, comma, hyphen, dot, slash, colon, equal sign, question mark");return this._createEncoderBuffer(J)}else if(/str$/.test(Z))return this._createEncoderBuffer(J);else if(Z==="objDesc")return this._createEncoderBuffer(J);else return this.reporter.error("Encoding of string type: "+Z+" unsupported")};Z$.prototype._encodeObjid=function(J,Z,Y){if(typeof J==="string"){if(!Z)return this.reporter.error("string objid given, but no values map found");if(!Z.hasOwnProperty(J))return this.reporter.error("objid not found in values map");J=Z[J].split(/[\s.]+/g);for(let U=0;U<J.length;U++)J[U]|=0}else if(Array.isArray(J)){J=J.slice();for(let U=0;U<J.length;U++)J[U]|=0}if(!Array.isArray(J))return this.reporter.error("objid() should be either array or string, got: "+JSON.stringify(J));if(!Y){if(J[1]>=40)return this.reporter.error("Second objid identifier OOB");J.splice(0,2,J[0]*40+J[1])}let X=0;for(let U=0;U<J.length;U++){let z=J[U];for(X++;z>=128;z>>=7)X++}let G=O$.alloc(X),Q=G.length-1;for(let U=J.length-1;U>=0;U--){let z=J[U];G[Q--]=z&127;while((z>>=7)>0)G[Q--]=128|z&127}return this._createEncoderBuffer(G)};function J$($){if($<10)return"0"+$;else return $}Z$.prototype._encodeTime=function(J,Z){let Y,X=new Date(J);if(Z==="gentime")Y=[J$(X.getUTCFullYear()),J$(X.getUTCMonth()+1),J$(X.getUTCDate()),J$(X.getUTCHours()),J$(X.getUTCMinutes()),J$(X.getUTCSeconds()),"Z"].join("");else if(Z==="utctime")Y=[J$(X.getUTCFullYear()%100),J$(X.getUTCMonth()+1),J$(X.getUTCDate()),J$(X.getUTCHours()),J$(X.getUTCMinutes()),J$(X.getUTCSeconds()),"Z"].join("");else this.reporter.error("Encoding "+Z+" time is not supported yet");return this._encodeStr(Y,"octstr")};Z$.prototype._encodeNull=function(){return this._createEncoderBuffer("")};Z$.prototype._encodeInt=function(J,Z){if(typeof J==="string"){if(!Z)return this.reporter.error("String int or enum given, but no values map");if(!Z.hasOwnProperty(J))return this.reporter.error("Values map doesn't contain: "+JSON.stringify(J));J=Z[J]}if(typeof J!=="number"&&!O$.isBuffer(J)){let G=J.toArray();if(!J.sign&&G[0]&128)G.unshift(0);J=O$.from(G)}if(O$.isBuffer(J)){let G=J.length;if(J.length===0)G++;let Q=O$.alloc(G);if(J.copy(Q),J.length===0)Q[0]=0;return this._createEncoderBuffer(Q)}if(J<128)return this._createEncoderBuffer(J);if(J<256)return this._createEncoderBuffer([0,J]);let Y=1;for(let G=J;G>=256;G>>=8)Y++;let X=Array(Y);for(let G=X.length-1;G>=0;G--)X[G]=J&255,J>>=8;if(X[0]&128)X.unshift(0);return this._createEncoderBuffer(O$.from(X))};Z$.prototype._encodeBool=function(J){return this._createEncoderBuffer(J?255:0)};Z$.prototype._use=function(J,Z){if(typeof J==="function")J=J(Z);return J._getEncoder("der").tree};Z$.prototype._skipDefault=function(J,Z,Y){let X=this._baseState,G;if(X.default===null)return!1;let Q=J.join();if(X.defaultBuffer===void 0)X.defaultBuffer=this._encodeValue(X.default,Z,Y).join();if(Q.length!==X.defaultBuffer.length)return!1;for(G=0;G<Q.length;G++)if(Q[G]!==X.defaultBuffer[G])return!1;return!0};function X9($,J,Z,Y){let X;if($==="seqof")$="seq";else if($==="setof")$="set";if(tZ.tagByName.hasOwnProperty($))X=tZ.tagByName[$];else if(typeof $==="number"&&($|0)===$)X=$;else return Y.error("Unknown tag: "+$);if(X>=31)return Y.error("Multi-octet tag encoding unsupported");if(!J)X|=32;return X|=tZ.tagClassByName[Z||"universal"]<<6,X}});var xG=l((l5,kG)=>{var G9=C$(),eZ=aZ();function $Y($){eZ.call(this,$),this.enc="pem"}G9($Y,eZ);kG.exports=$Y;$Y.prototype.encode=function(J,Z){let X=eZ.prototype.encode.call(this,J).toString("base64"),G=["-----BEGIN "+Z.label+"-----"];for(let Q=0;Q<X.length;Q+=64)G.push(X.slice(Q,Q+64));return G.push("-----END "+Z.label+"-----"),G.join(`
|
|
6
|
-
`)}});var JY=l((yG)=>{var fG=yG;fG.der=aZ();fG.pem=xG()});var YY=l((i5,uG)=>{var Q9=C$(),H9=lZ(),gG=l$().DecoderBuffer,bG=vJ(),hG=kJ();function cG($){this.enc="der",this.name=$.name,this.entity=$,this.tree=new r0,this.tree._init($.body)}uG.exports=cG;cG.prototype.decode=function(J,Z){if(!gG.isDecoderBuffer(J))J=new gG(J,Z);return this.tree._decode(J,Z)};function r0($){bG.call(this,"der",$)}Q9(r0,bG);r0.prototype._peekTag=function(J,Z,Y){if(J.isEmpty())return!1;let X=J.save(),G=ZY(J,'Failed to peek tag: "'+Z+'"');if(J.isError(G))return G;return J.restore(X),G.tag===Z||G.tagStr===Z||G.tagStr+"of"===Z||Y};r0.prototype._decodeTag=function(J,Z,Y){let X=ZY(J,'Failed to decode tag of "'+Z+'"');if(J.isError(X))return X;let G=pG(J,X.primitive,'Failed to get length of "'+Z+'"');if(J.isError(G))return G;if(!Y&&X.tag!==Z&&X.tagStr!==Z&&X.tagStr+"of"!==Z)return J.error('Failed to match tag: "'+Z+'"');if(X.primitive||G!==null)return J.skip(G,'Failed to match body of: "'+Z+'"');let Q=J.save(),U=this._skipUntilEnd(J,'Failed to skip indefinite length body: "'+this.tag+'"');if(J.isError(U))return U;return G=J.offset-Q.offset,J.restore(Q),J.skip(G,'Failed to match body of: "'+Z+'"')};r0.prototype._skipUntilEnd=function(J,Z){for(;;){let Y=ZY(J,Z);if(J.isError(Y))return Y;let X=pG(J,Y.primitive,Z);if(J.isError(X))return X;let G;if(Y.primitive||X!==null)G=J.skip(X);else G=this._skipUntilEnd(J,Z);if(J.isError(G))return G;if(Y.tagStr==="end")break}};r0.prototype._decodeList=function(J,Z,Y,X){let G=[];while(!J.isEmpty()){let Q=this._peekTag(J,"end");if(J.isError(Q))return Q;let U=Y.decode(J,"der",X);if(J.isError(U)&&Q)break;G.push(U)}return G};r0.prototype._decodeStr=function(J,Z){if(Z==="bitstr"){let Y=J.readUInt8();if(J.isError(Y))return Y;return{unused:Y,data:J.raw()}}else if(Z==="bmpstr"){let Y=J.raw();if(Y.length%2===1)return J.error("Decoding of string type: bmpstr length mismatch");let X="";for(let G=0;G<Y.length/2;G++)X+=String.fromCharCode(Y.readUInt16BE(G*2));return X}else if(Z==="numstr"){let Y=J.raw().toString("ascii");if(!this._isNumstr(Y))return J.error("Decoding of string type: numstr unsupported characters");return Y}else if(Z==="octstr")return J.raw();else if(Z==="objDesc")return J.raw();else if(Z==="printstr"){let Y=J.raw().toString("ascii");if(!this._isPrintstr(Y))return J.error("Decoding of string type: printstr unsupported characters");return Y}else if(/str$/.test(Z))return J.raw().toString();else return J.error("Decoding of string type: "+Z+" unsupported")};r0.prototype._decodeObjid=function(J,Z,Y){let X,G=[],Q=0,U=0;while(!J.isEmpty())if(U=J.readUInt8(),Q<<=7,Q|=U&127,(U&128)===0)G.push(Q),Q=0;if(U&128)G.push(Q);let z=G[0]/40|0,O=G[0]%40;if(Y)X=G;else X=[z,O].concat(G.slice(1));if(Z){let _=Z[X.join(" ")];if(_===void 0)_=Z[X.join(".")];if(_!==void 0)X=_}return X};r0.prototype._decodeTime=function(J,Z){let Y=J.raw().toString(),X,G,Q,U,z,O;if(Z==="gentime")X=Y.slice(0,4)|0,G=Y.slice(4,6)|0,Q=Y.slice(6,8)|0,U=Y.slice(8,10)|0,z=Y.slice(10,12)|0,O=Y.slice(12,14)|0;else if(Z==="utctime")if(X=Y.slice(0,2)|0,G=Y.slice(2,4)|0,Q=Y.slice(4,6)|0,U=Y.slice(6,8)|0,z=Y.slice(8,10)|0,O=Y.slice(10,12)|0,X<70)X=2000+X;else X=1900+X;else return J.error("Decoding "+Z+" time is not supported yet");return Date.UTC(X,G-1,Q,U,z,O,0)};r0.prototype._decodeNull=function(){return null};r0.prototype._decodeBool=function(J){let Z=J.readUInt8();if(J.isError(Z))return Z;else return Z!==0};r0.prototype._decodeInt=function(J,Z){let Y=J.raw(),X=new H9(Y);if(Z)X=Z[X.toString(10)]||X;return X};r0.prototype._use=function(J,Z){if(typeof J==="function")J=J(Z);return J._getDecoder("der").tree};function ZY($,J){let Z=$.readUInt8(J);if($.isError(Z))return Z;let Y=hG.tagClass[Z>>6],X=(Z&32)===0;if((Z&31)===31){let Q=Z;Z=0;while((Q&128)===128){if(Q=$.readUInt8(J),$.isError(Q))return Q;Z<<=7,Z|=Q&127}}else Z&=31;let G=hG.tag[Z];return{cls:Y,primitive:X,tag:Z,tagStr:G}}function pG($,J,Z){let Y=$.readUInt8(Z);if($.isError(Y))return Y;if(!J&&Y===128)return null;if((Y&128)===0)return Y;let X=Y&127;if(X>4)return $.error("length octect is too long");Y=0;for(let G=0;G<X;G++){Y<<=8;let Q=$.readUInt8(Z);if($.isError(Q))return Q;Y|=Q}return Y}});var nG=l((t5,mG)=>{var W9=C$(),U9=TJ().Buffer,XY=YY();function GY($){XY.call(this,$),this.enc="pem"}W9(GY,XY);mG.exports=GY;GY.prototype.decode=function(J,Z){let Y=J.toString().split(/[\r\n]+/g),X=Z.label.toUpperCase(),G=/^-----(BEGIN|END) ([^-]+)-----$/,Q=-1,U=-1;for(let _=0;_<Y.length;_++){let K=Y[_].match(G);if(K===null)continue;if(K[2]!==X)continue;if(Q===-1){if(K[1]!=="BEGIN")break;Q=_}else{if(K[1]!=="END")break;U=_;break}}if(Q===-1||U===-1)throw Error("PEM section not found for: "+X);let z=Y.slice(Q+1,U).join("");z.replace(/[^a-z0-9+/=]+/gi,"");let O=U9.from(z,"base64");return XY.prototype.decode.call(this,O,Z)}});var QY=l((sG)=>{var dG=sG;dG.der=YY();dG.pem=nG()});var lG=l((oG)=>{var V9=JY(),z9=QY(),_9=C$(),O9=oG;O9.define=function(J,Z){return new r$(J,Z)};function r$($,J){this.name=$,this.body=J,this.decoders={},this.encoders={}}r$.prototype._createNamed=function(J){let Z=this.name;function Y(X){this._initNamed(X,Z)}return _9(Y,J),Y.prototype._initNamed=function(G,Q){J.call(this,G,Q)},new Y(this)};r$.prototype._getDecoder=function(J){if(J=J||"der",!this.decoders.hasOwnProperty(J))this.decoders[J]=this._createNamed(z9[J]);return this.decoders[J]};r$.prototype.decode=function(J,Z,Y){return this._getDecoder(Z).decode(J,Y)};r$.prototype._getEncoder=function(J){if(J=J||"der",!this.encoders.hasOwnProperty(J))this.encoders[J]=this._createNamed(V9[J]);return this.encoders[J]};r$.prototype.encode=function(J,Z,Y){return this._getEncoder(Z).encode(J,Y)}});var iG=l((rG)=>{var xJ=rG;xJ.Reporter=NJ().Reporter;xJ.DecoderBuffer=l$().DecoderBuffer;xJ.EncoderBuffer=l$().EncoderBuffer;xJ.Node=vJ()});var eG=l((aG)=>{var tG=aG;tG._reverse=function(J){let Z={};return Object.keys(J).forEach(function(Y){if((Y|0)==Y)Y=Y|0;let X=J[Y];Z[X]=Y}),Z};tG.der=kJ()});var JQ=l(($Q)=>{var i$=$Q;i$.bignum=lZ();i$.define=lG().define;i$.base=iG();i$.constants=eG();i$.decoders=QY();i$.encoders=JY()});var XQ=l((HY,YQ)=>{/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var fJ=K$("buffer"),V$=fJ.Buffer;function ZQ($,J){for(var Z in $)J[Z]=$[Z]}if(V$.from&&V$.alloc&&V$.allocUnsafe&&V$.allocUnsafeSlow)YQ.exports=fJ;else ZQ(fJ,HY),HY.Buffer=D$;function D$($,J,Z){return V$($,J,Z)}D$.prototype=Object.create(V$.prototype);ZQ(V$,D$);D$.from=function($,J,Z){if(typeof $==="number")throw TypeError("Argument must not be a number");return V$($,J,Z)};D$.alloc=function($,J,Z){if(typeof $!=="number")throw TypeError("Argument must be a number");var Y=V$($);if(J!==void 0)if(typeof Z==="string")Y.fill(J,Z);else Y.fill(J);else Y.fill(0);return Y};D$.allocUnsafe=function($){if(typeof $!=="number")throw TypeError("Argument must be a number");return V$($)};D$.allocUnsafeSlow=function($){if(typeof $!=="number")throw TypeError("Argument must be a number");return fJ.SlowBuffer($)}});var QQ=l((Y7,GQ)=>{function WY($){var J=($/8|0)+($%8===0?0:1);return J}var M9={ES256:WY(256),ES384:WY(384),ES512:WY(521)};function A9($){var J=M9[$];if(J)return J;throw Error('Unknown algorithm "'+$+'"')}GQ.exports=A9});var OQ=l((X7,_Q)=>{var yJ=XQ().Buffer,WQ=QQ(),gJ=128,UQ=0,K9=32,F9=16,R9=2,VQ=F9|K9|UQ<<6,hJ=R9|UQ<<6;function I9($){return $.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function zQ($){if(yJ.isBuffer($))return $;else if(typeof $==="string")return yJ.from($,"base64");throw TypeError("ECDSA signature must be a Base64 string or a Buffer")}function q9($,J){$=zQ($);var Z=WQ(J),Y=Z+1,X=$.length,G=0;if($[G++]!==VQ)throw Error('Could not find expected "seq"');var Q=$[G++];if(Q===(gJ|1))Q=$[G++];if(X-G<Q)throw Error('"seq" specified length of "'+Q+'", only "'+(X-G)+'" remaining');if($[G++]!==hJ)throw Error('Could not find expected "int" for "r"');var U=$[G++];if(X-G-2<U)throw Error('"r" specified length of "'+U+'", only "'+(X-G-2)+'" available');if(Y<U)throw Error('"r" specified length of "'+U+'", max of "'+Y+'" is acceptable');var z=G;if(G+=U,$[G++]!==hJ)throw Error('Could not find expected "int" for "s"');var O=$[G++];if(X-G!==O)throw Error('"s" specified length of "'+O+'", expected "'+(X-G)+'"');if(Y<O)throw Error('"s" specified length of "'+O+'", max of "'+Y+'" is acceptable');var _=G;if(G+=O,G!==X)throw Error('Expected to consume entire buffer, but "'+(X-G)+'" bytes remain');var K=Z-U,j=Z-O,C=yJ.allocUnsafe(K+U+j+O);for(G=0;G<K;++G)C[G]=0;$.copy(C,G,z+Math.max(-K,0),z+U),G=Z;for(var S=G;G<S+j;++G)C[G]=0;return $.copy(C,G,_+Math.max(-j,0),_+O),C=C.toString("base64"),C=I9(C),C}function HQ($,J,Z){var Y=0;while(J+Y<Z&&$[J+Y]===0)++Y;var X=$[J+Y]>=gJ;if(X)--Y;return Y}function L9($,J){$=zQ($);var Z=WQ(J),Y=$.length;if(Y!==Z*2)throw TypeError('"'+J+'" signatures must be "'+Z*2+'" bytes, saw "'+Y+'"');var X=HQ($,0,Z),G=HQ($,Z,$.length),Q=Z-X,U=Z-G,z=2+Q+1+1+U,O=z<gJ,_=yJ.allocUnsafe((O?2:3)+z),K=0;if(_[K++]=VQ,O)_[K++]=z;else _[K++]=gJ|1,_[K++]=z&255;if(_[K++]=hJ,_[K++]=Q,X<0)_[K++]=0,K+=$.copy(_,K,0,Z);else K+=$.copy(_,K,X,Z);if(_[K++]=hJ,_[K++]=U,G<0)_[K++]=0,$.copy(_,K,Z);else $.copy(_,K,Z+G);return _}_Q.exports={derToJose:q9,joseToDer:L9}});var _Y=l((G7,SQ)=>{var zY=JQ(),{createHmac:KQ,createVerify:j9,createSign:B9,timingSafeEqual:P9,createPublicKey:E9,constants:{RSA_PKCS1_PSS_PADDING:FQ,RSA_PSS_SALTLEN_DIGEST:RQ,RSA_PKCS1_PADDING:IQ,RSA_PSS_SALTLEN_MAX_SIGN:C9,RSA_PSS_SALTLEN_AUTO:S9},sign:MQ,verify:AQ}=K$("crypto"),{joseToDer:w9,derToJose:T9}=OQ(),qQ=sZ(),{TokenError:X0}=u$(),LQ=/[=+/]/g,N9={"=":"","+":"-","/":"_"},jQ=/^-----BEGIN(?: (RSA|EC|ENCRYPTED))? PRIVATE KEY-----/,BQ=/^-----BEGIN(?: (RSA))? PUBLIC KEY-----/,bJ=new qQ(1000),UY=new qQ(1000),PQ=["HS256","HS384","HS512"],D9=["ES256","ES384","ES512"],VY=["RS256","RS384","RS512","PS256","PS384","PS512"],v9=["EdDSA"],EQ={"1.2.840.10045.3.1.7":{bits:"256",names:["P-256","prime256v1"]},"1.3.132.0.10":{bits:"256",names:["secp256k1"]},"1.3.132.0.34":{bits:"384",names:["P-384","secp384r1"]},"1.3.132.0.35":{bits:"512",names:["P-521","secp521r1"]}},k9=zY.define("PrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().objid()))}),x9=zY.define("PublicKey",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().objid()))}),f9=zY.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).optional().choice({namedCurve:this.objid()}))});function CQ($){return N9[$]}function QJ($,J,Z,Y){return $.set(J,[Z,Y]),Z||Y}function y9($){if($.match(BQ)||$.includes("-----BEGIN CERTIFICATE-----"))throw new X0(X0.codes.invalidKey,"Public keys are not supported for signing.");let J=$.trim().match(jQ);if(!J)return"HS256";let Z,Y,X;switch(J[1]){case"RSA":return"RS256";case"EC":Z=f9.decode($,"pem",{label:"EC PRIVATE KEY"}),X=Z.parameters.value.join(".");break;case"ENCRYPTED":return"ENCRYPTED";default:switch(Z=k9.decode($,"pem",{label:"PRIVATE KEY"}),Y=Z.algorithm.algorithm.join("."),Y){case"1.2.840.113549.1.1.1":return"RS256";case"1.2.840.10045.2.1":X=Z.algorithm.parameters.join(".");break;case"1.3.101.112":case"1.3.101.113":return"EdDSA";default:throw new X0(X0.codes.invalidKey,`Unsupported PEM PCKS8 private key with OID ${Y}.`)}}let G=EQ[X];if(!G)throw new X0(X0.codes.invalidKey,`Unsupported EC private key with curve ${X}.`);return`ES${G.bits}`}function g9($){let J=$.match(BQ);if($.match(jQ))throw new X0(X0.codes.invalidKey,"Private keys are not supported for verifying.");else if(J&&J[1]==="RSA")return VY;else if(!J&&!$.includes("-----BEGIN CERTIFICATE-----"))return PQ;if($.includes("-----BEGIN CERTIFICATE-----"))$=E9($).export({type:"spki",format:"pem"});let Z=x9.decode($,"pem",{label:"PUBLIC KEY"}),Y=Z.algorithm.algorithm.join("."),X;switch(Y){case"1.2.840.113549.1.1.1":return VY;case"1.2.840.10045.2.1":X=Z.algorithm.parameters.join(".");break;case"1.3.101.112":case"1.3.101.113":return["EdDSA"];default:throw new X0(X0.codes.invalidKey,`Unsupported PEM PCKS8 public key with OID ${Y}.`)}let G=EQ[X];if(!G)throw new X0(X0.codes.invalidKey,`Unsupported EC public key with curve ${X}.`);return[`ES${G.bits}`]}function h9($,J){if($ instanceof Buffer)$=$.toString("utf-8");else if(typeof $!=="string")throw new X0(X0.codes.invalidKey,"The private key must be a string or a buffer.");let[Z,Y]=bJ.get($)||[];if(Z)return Z;else if(Y)throw Y;try{let X=y9($);if(X==="ENCRYPTED")return QJ(bJ,$,J);return QJ(bJ,$,X)}catch(X){throw QJ(bJ,$,null,X0.wrap(X,X0.codes.invalidKey,"Unsupported PEM private key."))}}function b9($){if(!$)return"none";let[J,Z]=UY.get($)||[];if(J)return J;else if(Z)throw Z;try{if($ instanceof Buffer)$=$.toString("utf-8");else if(typeof $!=="string")throw new X0(X0.codes.invalidKey,"The public key must be a string or a buffer.");return QJ(UY,$,g9($))}catch(Y){throw QJ(UY,$,null,X0.wrap(Y,X0.codes.invalidKey,"Unsupported PEM public key."))}}function c9($,J,Z){try{let Y=$.slice(0,2),X=`sha${$.slice(2)}`,G,Q;switch(Y){case"HS":G=KQ(X,J).update(Z).digest("base64");break;case"ES":G=T9(MQ(X,Buffer.from(Z,"utf-8"),J),$).toString("base64");break;case"RS":case"PS":if(Q={key:J,padding:IQ,saltLength:C9},Y==="PS")Q.padding=FQ,Q.saltLength=RQ;G=B9(X).update(Z).sign(Q).toString("base64");break;case"Ed":G=MQ(void 0,Buffer.from(Z,"utf-8"),J).toString("base64")}return G.replace(LQ,CQ)}catch(Y){throw new X0(X0.codes.signError,"Cannot create the signature.",{originalError:Y})}}function p9($,J,Z,Y){try{let X=$.slice(0,2),G=`SHA${$.slice(2)}`;if(Y=Buffer.from(Y,"base64"),X==="HS")try{return P9(KQ(G,J).update(Z).digest(),Y)}catch{return!1}else if(X==="Ed")if(typeof AQ==="function")return AQ(void 0,Buffer.from(Z,"utf-8"),J,Y);else throw new X0(X0.codes.signError,"EdDSA algorithms are not supported by your Node.js version.");let Q={key:J,padding:IQ,saltLength:S9};if(X==="PS")Q.padding=FQ,Q.saltLength=RQ;else if(X==="ES")Y=w9(Y,$);return j9("RSA-"+G).update(Z).verify(Q,Y)}catch(X){throw new X0(X0.codes.verifyError,"Cannot verify the signature.",{originalError:X})}}SQ.exports={base64UrlMatcher:LQ,base64UrlReplacer:CQ,hsAlgorithms:PQ,rsaAlgorithms:VY,esAlgorithms:D9,edAlgorithms:v9,detectPrivateKeyAlgorithm:h9,detectPublicKeyAlgorithms:b9,createSignature:c9,verifySignature:p9}});var OY=l((Q7,TQ)=>{var{createHash:wQ}=K$("crypto"),u9=/"alg"\s*:\s*"[HERP]S(256|384)"/m,m9=/"alg"\s*:\s*"EdDSA"/m,n9=/"crv"\s*:\s*"Ed448"/m;function d9($,J,Z){let Y=$(J,Z);if(Y&&typeof Y.then==="function")Y.then((X)=>{process.nextTick(()=>Z(null,X))}).catch(Z)}function s9($){if(typeof $==="function")return[$];let J,Z,Y=new Promise((X,G)=>{J=X,Z=G});return[function(X,G){if(X)return Z(X);return J(G)},Y]}function o9($){let J=$.split(".",1)[0],Z=Buffer.from(J,"base64").toString("utf-8"),Y=null;if(Z.match(m9)&&Z.match(n9))Y=wQ("shake256",{outputLength:114});else{let X=Z.match(u9);Y=wQ(`sha${X?X[1]:"512"}`)}return Y.update($).digest("hex")}TQ.exports={getAsyncKey:d9,ensurePromiseCallback:s9,hashToken:o9}});var yQ=l((H7,fQ)=>{var{createPublicKey:l9,createSecretKey:r9}=K$("crypto"),i9=sZ(),{hsAlgorithms:DQ,verifySignature:t9,detectPublicKeyAlgorithms:vQ}=_Y(),a9=pZ(),{TokenError:d}=u$(),{getAsyncKey:e9,ensurePromiseCallback:$8,hashToken:J8}=OY();function Z8($,J){return $===J}function kQ($,J){for(let Z of $)if(J.includes(Z))return;throw new d(d.codes.invalidKey,`Invalid public key provided for algorithms ${$.join(", ")}.`)}function xQ($,J){if(typeof $==="string")$=Buffer.from($,"utf-8");return J?r9($):l9($)}function HJ($){if(!Array.isArray($))$=[$];return $.filter((J)=>J).map((J)=>{if(J&&typeof J.test==="function")return J;return{test:Z8.bind(null,J)}})}function Y8($){let J=parseInt($===!0?1000:$,10);return J>0?new i9(J):null}function t$({cache:$,token:J,cacheTTL:Z,payload:Y,ignoreExpiration:X,ignoreNotBefore:G,maxAge:Q,clockTimestamp:U=Date.now(),clockTolerance:z,errorCacheTTL:O,cacheKeyBuilder:_},K){if(!$)return K;let j=[K,0,0];if(K instanceof d){let v=typeof O==="function"?O(K):O;return j[2]=U+z+v,$.set(_(J),j),K}if(Y&&typeof Y.iat==="number"){if(j[1]=!G&&typeof Y.nbf==="number"?Y.nbf*1000-z:0,!X){if(typeof Y.exp==="number")j[2]=Y.exp*1000+z;else if(Q)j[2]=Y.iat*1000+Q+z}}let S=U+z+Z;return j[2]=j[2]===0?S:Math.min(j[2],S),$.set(_(J),j),K}function X8($,J,Z){if($ instanceof d){if(!J)throw $;J($)}else{if(!J)return $;J(null,$)}return Z}function G8($,J,Z,Y,X){if(!X.includes(J.alg))throw new d(d.codes.invalidAlgorithm,"The token algorithm is invalid.");if(Z&&!t9(J.alg,Y,$,Z))throw new d(d.codes.invalidSignature,"The token signature is invalid.")}function Q8($,J,Z,Y,X){let G=Z?`The ${J} claim must be a ${X} or an array of ${X}s.`:`The ${J} claim must be a ${X}.`;if(Y&&!Z)throw new d(d.codes.invalidClaimValue,G);if($.map((Q)=>typeof Q).some((Q)=>Q!==X))throw new d(d.codes.invalidClaimType,G)}function H8($,J,Z,Y){let X=Y?`None of ${J} claim values are allowed.`:`The ${J} claim value is not allowed.`;if(!$.some((G)=>Z.some((Q)=>Q.test(G))))throw new d(d.codes.invalidClaimValue,X)}function W8($,J,Z,Y,X,G){let Q=$*1000+(J||0);if(!(Y?Z>=Q:Z<=Q))throw new d(d.codes[X],`The token ${G} at ${new Date(Q).toISOString()}.`)}function NQ($,{input:J,header:Z,payload:Y,signature:X},{validators:G,allowedAlgorithms:Q,checkTyp:U,clockTimestamp:z,requiredClaims:O}){let _=$ instanceof Buffer?$.length:!!$;if(_&&!X)throw new d(d.codes.missingSignature,"The token signature is missing.");else if(!_&&X)throw new d(d.codes.missingKey,"The key option is missing.");if(G8(J,Z,X,$,Q),U&&(typeof Z.typ!=="string"||U!==Z.typ.toLowerCase().replace(/^application\//,"")))throw new d(d.codes.invalidType,"Invalid typ.");if(O){for(let j of O)if(!(j in Y))throw new d(d.codes.missingRequiredClaim,`The ${j} claim is required.`)}let K=z||Date.now();for(let{type:j,claim:C,allowed:S,array:v,modifier:T,greater:k,errorCode:E,errorVerb:w}of G){let f=Y[C],D=Array.isArray(f),m=D?f:[f];if(!(C in Y))continue;if(Q8(m,C,v,D,j==="date"?"number":"string"),j==="date")W8(f,T,K,k,E,w);else H8(m,C,S,D)}}function U8({key:$,allowedAlgorithms:J,complete:Z,cacheTTL:Y,checkTyp:X,clockTimestamp:G,clockTolerance:Q,ignoreExpiration:U,ignoreNotBefore:z,maxAge:O,isAsync:_,validators:K,decode:j,cache:C,requiredClaims:S,errorCacheTTL:v,cacheKeyBuilder:T},k,E){let[w,f]=_?$8(E):[];if(C){let[V,M,A]=C.get(T(k))||[void 0,0,0],I=G||Date.now();if(typeof V<"u"&&(M===0||I<M&&V.code==="FAST_JWT_INACTIVE"||I>=M&&V.code!=="FAST_JWT_INACTIVE")&&(A===0||I<=A))return X8(V,w,f)}let D;try{D=j(k)}catch(V){if(w)return w(V),f;throw V}let{header:m,payload:a,signature:r,input:i}=D,q={cache:C,token:k,cacheTTL:Y,errorCacheTTL:v,ignoreExpiration:U,ignoreNotBefore:z,maxAge:O,clockTimestamp:G,clockTolerance:Q,payload:a,cacheKeyBuilder:T},H={validators:K,allowedAlgorithms:J,checkTyp:X,clockTimestamp:G,clockTolerance:Q,requiredClaims:S};if(!w)try{return NQ($,D,H),t$(q,Z?{header:m,payload:a,signature:r,input:i}:a)}catch(V){throw t$(q,V)}return e9($,{header:m,payload:a,signature:r},(V,M)=>{if(V)return w(t$(q,d.wrap(V,d.codes.keyFetchingError,"Cannot fetch key.")));if(typeof M==="string")M=Buffer.from(M,"utf-8");else if(!(M instanceof Buffer))return w(t$(q,new d(d.codes.keyFetchingError,"The key returned from the callback must be a string or a buffer containing a secret or a public key.")));try{let A=vQ(M);if(H.allowedAlgorithms.length)kQ(J,A);else H.allowedAlgorithms=A;M=xQ(M,A[0]===DQ[0]),NQ(M,D,H)}catch(A){return w(t$(q,A))}w(null,t$(q,Z?{header:m,payload:a,signature:r,input:k}:a))}),f}fQ.exports=function(J){let{key:Z,algorithms:Y,complete:X,cache:G,cacheTTL:Q,errorCacheTTL:U,checkTyp:z,clockTimestamp:O,clockTolerance:_,ignoreExpiration:K,ignoreNotBefore:j,maxAge:C,allowedJti:S,allowedAud:v,allowedIss:T,allowedSub:k,allowedNonce:E,requiredClaims:w,cacheKeyBuilder:f}={cacheTTL:600000,clockTolerance:0,errorCacheTTL:-1,cacheKeyBuilder:J8,...J};if(!Array.isArray(Y))Y=[];let D=typeof Z;if(D!=="string"&&D!=="object"&&D!=="function")throw new d(d.codes.INVALID_OPTION,"The key option must be a string, a buffer or a function returning the algorithm secret or public key.");if(Z&&D!=="function"){let q=vQ(Z);if(Y.length)kQ(Y,q);else Y=q;Z=xQ(Z,q[0]===DQ[0])}if(O&&(typeof O!=="number"||O<0))throw new d(d.codes.invalidOption,"The clockTimestamp option must be a positive number.");if(_&&(typeof _!=="number"||_<0))throw new d(d.codes.invalidOption,"The clockTolerance option must be a positive number.");if(Q&&(typeof Q!=="number"||Q<0))throw new d(d.codes.invalidOption,"The cacheTTL option must be a positive number.");if(U&&typeof U!=="function"&&typeof U!=="number"||U<-1)throw new d(d.codes.invalidOption,"The errorCacheTTL option must be a number greater than -1 or a function.");if(w&&!Array.isArray(w))throw new d(d.codes.invalidOption,"The requiredClaims option must be an array.");let m=[];if(!j)m.push({type:"date",claim:"nbf",errorCode:"inactive",errorVerb:"will be active",greater:!0,modifier:-_});if(!K)m.push({type:"date",claim:"exp",errorCode:"expired",errorVerb:"has expired",modifier:+_});if(typeof C==="number")m.push({type:"date",claim:"iat",errorCode:"expired",errorVerb:"has expired",modifier:C});if(S)m.push({type:"string",claim:"jti",allowed:HJ(S)});if(v)m.push({type:"string",claim:"aud",allowed:HJ(v),array:!0});if(T)m.push({type:"string",claim:"iss",allowed:HJ(T)});if(k)m.push({type:"string",claim:"sub",allowed:HJ(k)});if(E)m.push({type:"string",claim:"nonce",allowed:HJ(E)});let a=z?z.toLowerCase().replace(/^application\//,""):null,r={key:Z,allowedAlgorithms:Y,complete:X,cacheTTL:Q,errorCacheTTL:U,checkTyp:a,clockTimestamp:O,clockTolerance:_,ignoreExpiration:K,ignoreNotBefore:j,maxAge:C,isAsync:D==="function",validators:m,decode:a9({complete:!0}),cache:Y8(G),requiredClaims:w,cacheKeyBuilder:f},i=U8.bind(null,r);return i.cache=r.cache,i}});var gQ=l((O8)=>{var V8=/^(-?(?:\d+)?\.?\d+) *(m(?:illiseconds?|s(?:ecs?)?))?(s(?:ec(?:onds?|s)?)?)?(m(?:in(?:utes?|s)?)?)?(h(?:ours?|rs?)?)?(d(?:ays?)?)?(w(?:eeks?|ks?)?)?(y(?:ears?|rs?)?)?$/,cJ=1000,pJ=cJ*60,uJ=pJ*60,UJ=uJ*24,MY=UJ*365.25;function z8($){var J,Z=$.toLowerCase().match(V8);if(Z!=null&&(J=parseFloat(Z[1]))){if(Z[3]!=null)return J*cJ;if(Z[4]!=null)return J*pJ;if(Z[5]!=null)return J*uJ;if(Z[6]!=null)return J*UJ;if(Z[7]!=null)return J*UJ*7;if(Z[8]!=null)return J*MY;return J}}function WJ($,J,Z,Y){var X=($|0)===$?$:~~($+0.5);return J+X+(Y?" "+Z+(X!=1?"s":""):Z[0])}function _8($,J){var Z=$<0?"-":"",Y=$<0?-$:$;if(Y<cJ)return $+(J?" ms":"ms");if(Y<pJ)return WJ(Y/cJ,Z,"second",J);if(Y<uJ)return WJ(Y/pJ,Z,"minute",J);if(Y<UJ)return WJ(Y/uJ,Z,"hour",J);if(Y<MY)return WJ(Y/UJ,Z,"day",J);return WJ(Y/MY,Z,"year",J)}O8.format=_8;O8.parse=z8});var dQ=l((U7,nQ)=>{var{base64UrlMatcher:AY,base64UrlReplacer:KY,hsAlgorithms:K8,esAlgorithms:F8,rsaAlgorithms:R8,edAlgorithms:I8,detectPrivateKeyAlgorithm:cQ,createSignature:hQ}=_Y(),{TokenError:o}=u$(),{getAsyncKey:q8,ensurePromiseCallback:L8}=OY(),{createPrivateKey:j8,createSecretKey:B8}=K$("crypto"),{parse:bQ}=gQ(),pQ=new Set([...K8,...F8,...R8,...I8,"none"]),P8=Array.from(pQ).join(", ");function uQ($,J){let Z=$.slice(0,2),Y=J.slice(0,2),X=!0;if(Z==="RS"||Z==="PS")X=Y==="RS"||Z==="RS"&&J==="ENCRYPTED";else if(Z==="ES"||Z==="Ed")X=Z===Y||Z==="ES"&&J==="ENCRYPTED";if(!X)throw new o(o.codes.invalidKey,`Invalid private key provided for algorithm ${$}.`)}function mQ($,J){if(typeof $==="string")$=Buffer.from($,"utf-8");return J[0]==="H"?B8($):j8($)}function E8({key:$,algorithm:J,noTimestamp:Z,mutatePayload:Y,clockTimestamp:X,expiresIn:G,notBefore:Q,kid:U,typ:z,isAsync:O,additionalHeader:_,fixedPayload:K},j,C){let[S,v]=O?L8(C):[];if(typeof j!=="object")throw new o(o.codes.invalidType,"The payload must be an object.");if(j.exp&&(!Number.isInteger(j.exp)||j.exp<0))throw new o(o.codes.invalidClaimValue,"The exp claim must be a positive integer.");let T={alg:J,typ:z||"JWT",kid:U,..._},k="",E=j.iat*1000||X||Date.now(),w={...j,...K,iat:Z?void 0:Math.floor(E/1000),exp:j.exp?j.exp:G?Math.floor((E+G)/1000):void 0,nbf:j.nbf?j.nbf:Q?Math.floor((E+Q)/1000):void 0};if(Y)Object.assign(j,w);if(k=Buffer.from(JSON.stringify(w),"utf-8").toString("base64").replace(AY,KY),!S){let D=Buffer.from(JSON.stringify(T),"utf-8").toString("base64").replace(AY,KY)+"."+k,m=J==="none"?"":hQ(J,$,D);return D+"."+m}return q8($,{header:T,payload:j},(f,D)=>{if(f){let a=o.wrap(f,o.codes.keyFetchingError,"Cannot fetch key.");return S(a)}if(typeof D==="string")D=Buffer.from(D,"utf-8");else if(!(D instanceof Buffer))return S(new o(o.codes.keyFetchingError,"The key returned from the callback must be a string or a buffer containing a secret or a private key."));let m;try{let a=cQ(D,J);if(J)uQ(J,a);else T.alg=J=a;D=mQ(D,J);let i=Buffer.from(JSON.stringify(T),"utf-8").toString("base64").replace(AY,KY)+"."+k;m=i+"."+hQ(J,D,i)}catch(a){return S(a)}S(null,m)}),v}nQ.exports=function(J){let{key:Z,algorithm:Y,noTimestamp:X,mutatePayload:G,clockTimestamp:Q,expiresIn:U,notBefore:z,jti:O,aud:_,iss:K,sub:j,nonce:C,kid:S,typ:v,header:T}={clockTimestamp:0,...J};if(Y&&!pQ.has(Y))throw new o(o.codes.invalidOption,`The algorithm option must be one of the following values: ${P8}.`);let k=typeof Z,E=k==="object"&&Z&&Z.key&&Z.passphrase;if(Y==="none"){if(Z)throw new o(o.codes.invalidOption,'The key option must not be provided when the algorithm option is "none".')}else if(!Z||k!=="string"&&!(Z instanceof Buffer)&&k!=="function"&&!E)throw new o(o.codes.invalidOption,"The key option must be a string, a buffer, an object containing key/passphrase properties or a function returning the algorithm secret or private key.");else if(E&&!Y)throw new o(o.codes.invalidAlgorithm,"When using password protected key you must provide the algorithm option.");if(Z&&k!=="function"){let D=cQ(E?Z.key:Z,Y);if(Y)uQ(Y,D);else Y=D;Z=mQ(Z,Y)}if(U){if(typeof U==="string")U=bQ(U);if(typeof U!=="number")throw new o(o.codes.invalidOption,"The expiresIn option must be a positive number or a valid string.")}if(z){if(typeof z==="string")z=bQ(z);if(typeof z!=="number"||z<0)throw new o(o.codes.invalidOption,"The notBefore option must be a positive number or a valid string.")}if(Q&&(typeof Q!=="number"||Q<0))throw new o(o.codes.invalidOption,"The clockTimestamp option must be a positive number.");if(O&&typeof O!=="string")throw new o(o.codes.invalidOption,"The jti option must be a string.");if(_&&typeof _!=="string"&&!Array.isArray(_))throw new o(o.codes.invalidOption,"The aud option must be a string or an array of strings.");if(K&&typeof K!=="string")throw new o(o.codes.invalidOption,"The iss option must be a string.");if(j&&typeof j!=="string")throw new o(o.codes.invalidOption,"The sub option must be a string.");if(C&&typeof C!=="string")throw new o(o.codes.invalidOption,"The nonce option must be a string.");if(S&&typeof S!=="string")throw new o(o.codes.invalidOption,"The kid option must be a string.");if(T&&typeof T!=="object")throw new o(o.codes.invalidOption,"The header option must be a object.");let f=Object.entries({jti:O,aud:_,iss:K,sub:j,nonce:C}).reduce((D,[m,a])=>{if(a!==void 0)D[m]=a;return D},{});return E8.bind(null,{key:Z,algorithm:Y,noTimestamp:X,mutatePayload:G,clockTimestamp:Q,expiresIn:U,notBefore:z,kid:S,typ:v,isAsync:k==="function",additionalHeader:T,fixedPayload:f})}});var oQ=l((V7,sQ)=>{var{TokenError:C8,TOKEN_ERROR_CODES:S8}=u$(),w8=pZ(),T8=yQ(),N8=dQ();sQ.exports={TokenError:C8,TOKEN_ERROR_CODES:S8,createDecoder:w8,createVerifier:T8,createSigner:N8}});AJ();import{join as LZ}from"path";m0();function Q$($){if(Array.isArray($)){let J=[];for(let Z of $)J.push(Q$(Z));return J}if(n($)){let J={},Z=$;for(let Y of Object.keys(Z))J[Y]=Q$(Z[Y]);return J}return $}function aY($,J){if(J===void 0)return $;if(Array.isArray($)&&Array.isArray(J)){let Z=[];for(let Y of $)Z.push(Q$(Y));for(let Y of J)Z.push(Q$(Y));return Z}if(n($)&&n(J)){let Z=$,Y=J,X={};for(let G of Object.keys(Z))X[G]=Q$(Z[G]);for(let G of Object.keys(Y)){let Q=Y[G];if(Q===void 0)continue;let U=X[G];if(Array.isArray(U)&&Array.isArray(Q)){let z=[];for(let O of U)z.push(Q$(O));for(let O of Q)z.push(Q$(O));X[G]=z;continue}if(n(U)&&n(Q)){X[G]=aY(Q$(U),Q);continue}X[G]=Q$(Q)}return X}return Q$(J)}function eY(...$){let J={};for(let Z of $){if(Z===void 0)continue;J=aY(J,Z)}return J}var y1={nodeEnv:"development",appName:"\u91CE\u8702\u98DE\u821E",appPort:3000,appHost:"127.0.0.1",devEmail:"dev@qq.com",devPassword:"beflydev123456",bodyLimit:1048576,tz:"Asia/Shanghai",strict:!0,logger:{debug:1,excludeFields:["password","token","secret"],dir:"./logs",console:1,maxSize:20,maxStringLen:100,maxArrayItems:100},db:{idMode:"timeId",host:"127.0.0.1",port:3306,username:"root",password:"root",database:"befly_demo",poolMax:10},redis:{host:"127.0.0.1",port:6379,username:"",password:"",db:0,prefix:"befly_demo"},auth:{secret:"befly-secret",expiresIn:"7d",algorithm:"HS256"},cors:{origin:"*",methods:"GET,HEAD,PUT,PATCH,POST,DELETE",allowedHeaders:"Content-Type,Authorization",exposedHeaders:"",maxAge:86400,credentials:"true"},rateLimit:{enable:1,defaultLimit:1000,defaultWindow:60,key:"ip",skipRoutes:[],rules:[]},disableMenus:["**/404","**/403","**/500","/addon/admin/login"],addons:{}};async function $X($){if($!=="development"&&$!=="production")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1ANODE_ENV \u53EA\u80FD\u662F 'development' \u6216 'production'\uFF0C\u5F53\u524D\u503C=${String($)}`);let J=LZ(process.cwd(),"configs"),Z=await q$(LZ(J,"befly.common.json"),{}),Y=await q$(LZ(J,`befly.${$}.json`),{}),X=eY(y1,Z,Y);X.nodeEnv=$;let G=X.redis?.prefix;if(typeof G==="string"){if(G.trim().includes(":"))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.prefix \u4E0D\u5141\u8BB8\u5305\u542B ':'\uFF08RedisHelper \u4F1A\u81EA\u52A8\u62FC\u63A5\u5206\u9694\u7B26 ':'\uFF09\uFF0C\u8BF7\u6539\u4E3A\u4E0D\u5E26\u5192\u53F7\u7684\u524D\u7F00\uFF0C\u4F8B\u5982 'befly_demo'\uFF0C\u5F53\u524D\u503C=${G}`)}let Q=X.db?.idMode;if(Q!==void 0&&Q!=="timeId"&&Q!=="autoId")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.idMode \u53EA\u80FD\u662F 'timeId' \u6216 'autoId'\uFF0C\u5F53\u524D\u503C=${String(Q)}`);let U=X.strict;if(U!==void 0&&typeof U!=="boolean")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Astrict \u5FC5\u987B\u4E3A boolean\uFF0C\u5F53\u524D\u503C=${String(U)}`);let z=X.checkTable;if(z!==void 0)throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AcheckTable \u914D\u7F6E\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528\u6839\u5C5E\u6027 strict\uFF08\u4F8B\u5982 { "strict": false }\uFF09\uFF0C\u5F53\u524D\u503C=${String(z)}`);return X}$0();m0();async function JX($){let J=!1,Z=new Set;for(let Y of $)try{if(!n(Y)){L.warn({item:Y,msg:"\u63A5\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61"}),J=!0;continue}let X=Y,G=X.name;if(typeof G!=="string"||G.trim()===""){L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 name \u5C5E\u6027\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32"})),J=!0;continue}if(typeof X.handler!=="function"){L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570"})),J=!0;continue}let U=X.path;if(typeof U!=="string"||U.trim()==="")L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u5C5E\u6027\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;else{let S=U.trim();if(Z.has(S))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u91CD\u590D\uFF08\u4E25\u683C\u6A21\u5F0F\u7981\u6B62\u91CD\u590D path\uFF09"})),J=!0;else Z.add(S);if(/^(GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD)\b/i.test(S))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u4E0D\u5141\u8BB8\u5305\u542B method \u524D\u7F00\uFF0C\u5E94\u4E3A url.pathname\uFF08\u4F8B\u5982 /api/app/xxx\uFF09"})),J=!0;if(!S.startsWith("/api/"))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u5FC5\u987B\u4EE5 /api/ \u5F00\u5934"})),J=!0;if(S.includes(" "))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u4E0D\u5141\u8BB8\u5305\u542B\u7A7A\u683C"})),J=!0;if(S.includes("/api//"))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u4E0D\u5141\u8BB8\u51FA\u73B0 /api//\uFF08\u91CD\u590D\u659C\u6760\uFF09"})),J=!0}let z=X.routePrefix,O=typeof z==="string"?z.trim():"";if(O==="")L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 routePrefix \u5C5E\u6027\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;else{if(!(O==="/app"||O.startsWith("/addon/")))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 routePrefix \u5FC5\u987B\u662F /app \u6216 /addon/<name>\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;if(typeof U==="string"&&U.trim()!==""){let S=U.trim(),v=`/api${O}/`;if(!S.startsWith(v))L.warn(Object.assign({},p(X,["handler"]),{expectedPrefix:v,msg:"\u63A5\u53E3\u7684 path \u4E0E routePrefix \u4E0D\u4E00\u81F4\uFF1A\u5E94\u4EE5 /api${routePrefix}/ \u5F00\u5934\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0}}let _=X.method;if(_!==void 0&&!["GET","POST","GET,POST"].includes(String(_).toUpperCase()))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 method \u5C5E\u6027\u5FC5\u987B\u662F\u6709\u6548\u7684 HTTP \u65B9\u6CD5 (GET, POST, GET,POST)"})),J=!0;let K=X.auth;if(K!==void 0&&typeof K!=="boolean")L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 auth \u5C5E\u6027\u5FC5\u987B\u662F\u5E03\u5C14\u503C (true=\u9700\u767B\u5F55, false=\u516C\u5F00)"})),J=!0;let j=X.fields;if(j!==void 0&&j!==null&&!n(j))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 fields \u5C5E\u6027\u5FC5\u987B\u662F\u5BF9\u8C61"})),J=!0;let C=X.required;if(C!==void 0&&!Array.isArray(C))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 required \u5C5E\u6027\u5FC5\u987B\u662F\u6570\u7EC4"})),J=!0;if(Array.isArray(C)){if(C.some((S)=>typeof S!=="string"))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 required \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0}}catch(X){L.error({err:X,item:Y,msg:"\u63A5\u53E3\u89E3\u6790\u5931\u8D25"}),J=!0}if(J)throw Error("\u63A5\u53E3\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}function x$($){return typeof $==="string"&&$.trim().length>0}function jZ($){return typeof $==="number"&&Number.isFinite($)&&$>=1&&$<=65535}function g1($){return typeof $==="number"&&Number.isFinite($)&&$>=0&&Math.floor($)===$}function h1($){return typeof $==="number"&&Number.isFinite($)&&$>=1&&Math.floor($)===$}function b1($){if(!x$($))return!1;try{return new Intl.DateTimeFormat("en-US",{timeZone:$}).format(0),!0}catch{return!1}}function c1($){if(!$)throw Error("\u914D\u7F6E\u9519\u8BEF\uFF1A\u7F3A\u5C11 db \u914D\u7F6E\uFF08config.db\uFF09");if(!x$($.host))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.host \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.host)}`);if(!jZ($.port))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.port \u5FC5\u987B\u4E3A 1..65535 \u7684\u6570\u5B57\uFF0C\u5F53\u524D\u503C=${String($.port)}`);if(!x$($.username))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.username \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.username)}`);if($.password!==void 0&&typeof $.password!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.password \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF08\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u5F53\u524D\u503C=${String($.password)}`);if(!x$($.database))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.database \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.database)}`);if($.poolMax!==void 0){if(typeof $.poolMax!=="number"||!Number.isFinite($.poolMax)||$.poolMax<=0)throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.poolMax \u5FC5\u987B\u4E3A\u6B63\u6570\uFF0C\u5F53\u524D\u503C=${String($.poolMax)}`)}}function p1($){if(!$)throw Error("\u914D\u7F6E\u9519\u8BEF\uFF1A\u7F3A\u5C11 redis \u914D\u7F6E\uFF08config.redis\uFF09");if($.host!==void 0&&typeof $.host!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.host \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.host)}`);if($.port!==void 0&&!jZ($.port))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.port \u5FC5\u987B\u4E3A 1..65535 \u7684\u6570\u5B57\uFF0C\u5F53\u524D\u503C=${String($.port)}`);if($.db!==void 0&&!g1($.db))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.db \u5FC5\u987B\u4E3A\u975E\u8D1F\u6574\u6570\uFF0C\u5F53\u524D\u503C=${String($.db)}`);let J=$.prefix;if(J!==void 0){if(typeof J!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.prefix \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String(J)}`);if(J.includes(":"))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.prefix \u4E0D\u5141\u8BB8\u5305\u542B ':'\uFF08RedisHelper \u4F1A\u81EA\u52A8\u62FC\u63A5\u5206\u9694\u7B26 ':'\uFF09\uFF0C\u5F53\u524D\u503C=${String(J)}`)}}async function ZX($){if(!$||typeof $!=="object")throw Error("\u914D\u7F6E\u9519\u8BEF\uFF1Aconfig \u5FC5\u987B\u4E3A\u5BF9\u8C61");if($.nodeEnv!=="development"&&$.nodeEnv!=="production")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AnodeEnv \u53EA\u80FD\u662F development/production\uFF0C\u5F53\u524D\u503C=${String($.nodeEnv)}`);if($.appName!==void 0){if(!x$($.appName))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AappName \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.appName)}`)}if($.appPort!==void 0){if(!jZ($.appPort))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AappPort \u5FC5\u987B\u4E3A 1..65535 \u7684\u6570\u5B57\uFF0C\u5F53\u524D\u503C=${String($.appPort)}`)}if($.appHost!==void 0){if(!x$($.appHost))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AappHost \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.appHost)}`)}if($.devEmail!==void 0){if(typeof $.devEmail!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AdevEmail \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF08\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u5F53\u524D\u503C=${String($.devEmail)}`);let J=$.devEmail.trim();if(J.length>0&&!J.includes("@"))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AdevEmail \u683C\u5F0F\u9519\u8BEF\uFF08\u5FC5\u987B\u5305\u542B '@'\uFF0C\u6216\u7F6E\u4E3A\u7A7A\u5B57\u7B26\u4E32\u4EE5\u7981\u7528 syncDev\uFF09\uFF0C\u5F53\u524D\u503C=${String($.devEmail)}`)}if($.devPassword!==void 0){if(typeof $.devPassword!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AdevPassword \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF08\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u5F53\u524D\u503C=${String($.devPassword)}`)}if($.bodyLimit!==void 0){if(!h1($.bodyLimit))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AbodyLimit \u5FC5\u987B\u4E3A\u6B63\u6574\u6570\uFF08\u5B57\u8282\uFF09\uFF0C\u5F53\u524D\u503C=${String($.bodyLimit)}`)}if($.tz!==void 0){if(!b1($.tz))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Atz \u5FC5\u987B\u4E3A\u6709\u6548\u7684 IANA \u65F6\u533A\u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 'Asia/Shanghai'\uFF09\uFF0C\u5F53\u524D\u503C=${String($.tz)}`)}if(typeof $.strict!=="boolean")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Astrict \u5FC5\u987B\u4E3A true \u6216 false\uFF0C\u5F53\u524D\u503C=${String($.strict)}`);c1($.db),p1($.redis)}$0();m0();var YX=["name","enable","deps","handler"];async function XX($){let J=!1,Z=/^[a-z]+(?:_[a-z]+)*$/;for(let Y of $)try{if(!n(Y)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u5BFC\u51FA\u5FC5\u987B\u662F\u5BF9\u8C61\uFF08export default { deps, handler }\uFF09"})),J=!0;continue}let X=Y,G=X.moduleName;if(typeof G!=="string"||G.trim()===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 moduleName \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u7528\u4E8E deps \u4E0E\u8FD0\u884C\u65F6\u6302\u8F7D\uFF09"})),J=!0;continue}let Q=X.customKeys;if(!Array.isArray(Q)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u626B\u63CF\u7ED3\u679C\u7F3A\u5C11 customKeys\uFF08\u65E0\u6CD5\u5224\u65AD\u7528\u6237\u5BFC\u51FA\u7684\u5B57\u6BB5\u662F\u5426\u5408\u6CD5\uFF09"})),J=!0;continue}if(Q.some((_)=>typeof _!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 customKeys \u5FC5\u987B\u662F string[]\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;continue}let U=Q.filter((_)=>!YX.includes(_));if(U.length>0){L.warn(Object.assign({},p(Y,["handler"]),{msg:`\u94A9\u5B50\u5BFC\u51FA\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5C5E\u6027\uFF1A${U.join(", ")}\uFF1B\u4EC5\u5141\u8BB8\uFF1A${YX.join(", ")}\uFF1B\u5F53\u524D customKeys\uFF1A${Q.join(", ")}`})),J=!0;continue}let z=Q.includes("enable"),O=Q.includes("deps");if(z){if(typeof X.enable!=="boolean"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 enable \u5C5E\u6027\u5FC5\u987B\u662F boolean\uFF08true/false\uFF09\uFF0C\u4E0D\u5141\u8BB8 0/1 \u7B49\u5176\u4ED6\u7C7B\u578B"})),J=!0;continue}}else X.enable=!0;if(X.source==="core"){let _=typeof X.name==="string"?X.name:"";if(_===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u5FC5\u987B\u663E\u5F0F\u8BBE\u7F6E name\uFF08string\uFF09\uFF0C\u7528\u4E8E\u786E\u5B9A\u94A9\u5B50\u540D\u79F0"})),J=!0;continue}if(!Z.test(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u7684 name \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u4F8B\u5982 auth / rate_limit\uFF09\uFF0C\u4E0D\u5141\u8BB8\u7A7A\u683C\u3001\u9A7C\u5CF0\u6216\u5176\u4ED6\u5B57\u7B26"})),J=!0;continue}if(!Z.test(String(X.moduleName))){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u7684 moduleName \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u4E14\u5FC5\u987B\u4E0E name \u4E00\u81F4\uFF09"})),J=!0;continue}if(_!==String(X.moduleName)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u7684 name \u5FC5\u987B\u4E0E moduleName \u5B8C\u5168\u4E00\u81F4"})),J=!0;continue}let K=X.filePath;if(typeof K!=="string"||!K.startsWith(`core:hook:${_}`)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u5FC5\u987B\u6765\u81EA\u9759\u6001\u6CE8\u518C\uFF08filePath \u5FC5\u987B\u4EE5 core:hook:<name> \u5F00\u5934\uFF09\uFF0C\u4E0D\u5141\u8BB8\u901A\u8FC7\u626B\u63CF\u76EE\u5F55\u52A0\u8F7D"})),J=!0;continue}}if(O){let _=X.deps;if(!Array.isArray(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}if(_.some((K)=>typeof K!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}}else{let _=X.deps;if(!Array.isArray(_))X.deps=[]}if(typeof X.handler!=="function"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570"})),J=!0;continue}}catch(X){L.error({err:X,item:Y,msg:"\u94A9\u5B50\u89E3\u6790\u5931\u8D25"}),J=!0}if(J)throw Error("\u94A9\u5B50\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}$0();CZ();function t1($){if(!$)return{ok:!1,reason:"path \u4E0D\u80FD\u4E3A\u7A7A"};if(!$.startsWith("/"))return{ok:!1,reason:"path \u5FC5\u987B\u4EE5 / \u5F00\u5934"};if($.length>1&&$.endsWith("/"))return{ok:!1,reason:"path \u672B\u5C3E\u4E0D\u80FD\u662F /\uFF08\u6839\u8DEF\u5F84 / \u9664\u5916\uFF09"};if($.includes("//"))return{ok:!1,reason:"path \u4E0D\u80FD\u5305\u542B //"};if($.includes(".."))return{ok:!1,reason:"path \u4E0D\u80FD\u5305\u542B .."};return{ok:!0,reason:""}}var OX=async($)=>{let J=!1,Z=await _X($),Y=[];for(let G of Z)Y.push({menu:G,depth:1});let X=new Set;while(Y.length>0){let G=Y.pop(),Q=G?.menu,U=typeof G?.depth==="number"?G.depth:0;if(Q===null||typeof Q!=="object"){J=!0,L.warn({menu:Q,msg:"\u83DC\u5355\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61"});continue}if(U>3){J=!0,L.warn({path:Q?.path,depth:U,msg:"\u83DC\u5355\u5C42\u7EA7\u8D85\u8FC7 3 \u7EA7\uFF08\u6700\u591A\u4E09\u7EA7\uFF09"});continue}let z=Q.children;if(typeof z<"u"&&!Array.isArray(z)){J=!0,L.warn({path:Q?.path,childrenType:typeof z,msg:"\u83DC\u5355 children \u5FC5\u987B\u662F\u6570\u7EC4"});continue}if(Array.isArray(z)&&z.length>0)if(U>=3)J=!0,L.warn({path:Q?.path,depth:U,msg:"\u83DC\u5355\u5C42\u7EA7\u8D85\u8FC7 3 \u7EA7\uFF08\u6700\u591A\u4E09\u7EA7\uFF09"});else for(let C of z)Y.push({menu:C,depth:U+1});let O=typeof Q.path==="string"?Q.path.trim():"",_=typeof Q.name==="string"?Q.name.trim():"",K=typeof Q.sort==="number"?Q.sort:999999;if(typeof Q.path==="string")Q.path=O;if(typeof Q.name==="string")Q.name=_;if(typeof Q.sort>"u")Q.sort=K;if(!O){J=!0,L.warn({menu:Q,msg:"\u83DC\u5355\u7F3A\u5C11 path\uFF08\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF09"});continue}let j=t1(O);if(!j.ok)J=!0,L.warn({path:O,reason:j.reason,msg:"\u83DC\u5355 path \u4E0D\u5408\u6CD5"});if(!_)J=!0,L.warn({path:O,menu:Q,msg:"\u83DC\u5355\u7F3A\u5C11 name\uFF08\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF09"});if(typeof Q.sort<"u"&&typeof Q.sort!=="number")J=!0,L.warn({path:O,sort:Q.sort,msg:"\u83DC\u5355 sort \u5FC5\u987B\u662F number"});if(typeof Q.sort==="number"&&(!Number.isFinite(Q.sort)||Q.sort<1))J=!0,L.warn({path:O,sort:Q.sort,msg:"\u83DC\u5355 sort \u6700\u5C0F\u503C\u4E3A 1"});if(X.has(O)){J=!0,L.warn({path:O,msg:"\u83DC\u5355 path \u91CD\u590D\uFF08\u4E25\u683C\u6A21\u5F0F\u7981\u6B62\u91CD\u590D path\uFF09"});continue}X.add(O)}if(J)throw Error("\u83DC\u5355\u7ED3\u6784\u68C0\u67E5\u5931\u8D25");return Z};$0();m0();var MX=["name","enable","deps","handler"];async function AX($){let J=!1,Z=/^[a-z]+(?:_[a-z]+)*$/;for(let Y of $)try{if(!n(Y)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u5BFC\u51FA\u5FC5\u987B\u662F\u5BF9\u8C61\uFF08export default { deps, handler }\uFF09"})),J=!0;continue}let X=Y,G=X.moduleName;if(typeof G!=="string"||G.trim()===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 moduleName \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u7528\u4E8E deps \u4E0E\u8FD0\u884C\u65F6\u6302\u8F7D\uFF09"})),J=!0;continue}let Q=X.customKeys;if(!Array.isArray(Q)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u626B\u63CF\u7ED3\u679C\u7F3A\u5C11 customKeys\uFF08\u65E0\u6CD5\u5224\u65AD\u7528\u6237\u5BFC\u51FA\u7684\u5B57\u6BB5\u662F\u5426\u5408\u6CD5\uFF09"})),J=!0;continue}if(Q.some((_)=>typeof _!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 customKeys \u5FC5\u987B\u662F string[]\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;continue}let U=Q.filter((_)=>!MX.includes(_));if(U.length>0){L.warn(Object.assign({},p(Y,["handler"]),{msg:`\u63D2\u4EF6\u5BFC\u51FA\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5C5E\u6027\uFF1A${U.join(", ")}\uFF1B\u4EC5\u5141\u8BB8\uFF1A${MX.join(", ")}\uFF1B\u5F53\u524D customKeys\uFF1A${Q.join(", ")}`})),J=!0;continue}let z=Q.includes("enable"),O=Q.includes("deps");if(z){if(typeof X.enable!=="boolean"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 enable \u5C5E\u6027\u5FC5\u987B\u662F boolean\uFF08true/false\uFF09\uFF0C\u4E0D\u5141\u8BB8 0/1 \u7B49\u5176\u4ED6\u7C7B\u578B"})),J=!0;continue}}else X.enable=!0;if(X.source==="core"){let _=typeof X.name==="string"?X.name:"";if(_===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u5FC5\u987B\u663E\u5F0F\u8BBE\u7F6E name\uFF08string\uFF09\uFF0C\u7528\u4E8E\u786E\u5B9A\u63D2\u4EF6\u540D\u79F0"})),J=!0;continue}if(!Z.test(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u7684 name \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u4F8B\u5982 logger / redis_cache\uFF09\uFF0C\u4E0D\u5141\u8BB8\u7A7A\u683C\u3001\u9A7C\u5CF0\u6216\u5176\u4ED6\u5B57\u7B26"})),J=!0;continue}if(!Z.test(String(X.moduleName))){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u7684 moduleName \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u4E14\u5FC5\u987B\u4E0E name \u4E00\u81F4\uFF09"})),J=!0;continue}if(_!==String(X.moduleName)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u7684 name \u5FC5\u987B\u4E0E moduleName \u5B8C\u5168\u4E00\u81F4"})),J=!0;continue}let K=X.filePath;if(typeof K!=="string"||!K.startsWith(`core:plugin:${_}`)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u5FC5\u987B\u6765\u81EA\u9759\u6001\u6CE8\u518C\uFF08filePath \u5FC5\u987B\u4EE5 core:plugin:<name> \u5F00\u5934\uFF09\uFF0C\u4E0D\u5141\u8BB8\u901A\u8FC7\u626B\u63CF\u76EE\u5F55\u52A0\u8F7D"})),J=!0;continue}}if(O){let _=X.deps;if(!Array.isArray(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}if(_.some((K)=>typeof K!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}}else{let _=X.deps;if(!Array.isArray(_))X.deps=[]}if(typeof X.handler!=="function"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570"})),J=!0;continue}}catch(X){L.error({err:X,item:Y,msg:"\u63D2\u4EF6\u89E3\u6790\u5931\u8D25"}),J=!0}if(J)throw Error("\u63D2\u4EF6\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}$0();function a1($){if($===null)return!0;return typeof $==="string"||typeof $==="number"||typeof $==="boolean"}function e1($){if(!$||typeof $!=="object")return!1;if($ instanceof Date)return!1;if(Array.isArray($))return!1;return!0}function SZ($){if(a1($))return!0;if(Array.isArray($)){for(let J of $)if(!SZ(J))return!1;return!0}if(e1($)){for(let J of Object.values($)){if(J===void 0)continue;if(!SZ(J))return!1}return!0}return!1}function ZJ($){if($===null)return"null";if($===void 0)return"undefined";if(typeof $==="string"){let Z=$.length>80?`${$.slice(0,80)}...`:$;return JSON.stringify(Z)}if(typeof $==="number"||typeof $==="boolean"||typeof $==="bigint")return String($);if(typeof $==="function")return"[Function]";try{let Z=JSON.stringify($);if(typeof Z==="string")return Z.length>120?`${Z.slice(0,120)}...`:Z}catch{}let J=String($);return J.length>120?`${J.slice(0,120)}...`:J}var IX=["id","created_at","updated_at","deleted_at","state"],$H=new Set(IX),qX=["string","number","text","array_string","array_text","array_number_string","array_number_text"],JH=new Set(qX),LX=["name","type","min","max","default","detail","index","unique","nullable","unsigned","regexp"],ZH=new Set(LX),YH=/^_?[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/,XH=/^[\u4e00-\u9fa5a-zA-Z0-9 _-]+$/,KX=16383,FX=500,RX=180;async function jX($,J){let Z=!1;for(let Y of $){if(Y.type!=="table")continue;let X=typeof Y.sourceName==="string"?Y.sourceName:"",G=X?`${X}\u8868 `:"\u8868 ";try{let Q=Y.fileName;if(Y.source==="addon"&&String(Y.addonName).trim()===""){L.warn(`${G}${Q} addon \u8868\u7F3A\u5C11 addonName`),Z=!0;continue}let U=Y.content;if(typeof U!=="object"||U===null||Array.isArray(U)){L.warn(`${G}${Q} \u8868\u5B9A\u4E49\u65E0\u6548\uFF1A\u5FC5\u987B\u4E3A\u5BF9\u8C61`),Z=!0;continue}if(!YH.test(Q)){L.warn(`${G}${Q} \u6587\u4EF6\u540D\u5FC5\u987B\u4F7F\u7528\u5C0F\u9A7C\u5CF0\u547D\u540D\uFF08\u4F8B\u5982 testCustomers.json\uFF09`),Z=!0;continue}for(let[z,O]of Object.entries(U)){if(typeof O!=="object"||O===null||Array.isArray(O)){L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u89C4\u5219\u5FC5\u987B\u4E3A\u5BF9\u8C61`),Z=!0;continue}if($H.has(z))L.warn(`${G}${Q} \u6587\u4EF6\u5305\u542B\u4FDD\u7559\u5B57\u6BB5 ${z}\uFF0C`+`\u4E0D\u80FD\u5728\u8868\u5B9A\u4E49\u4E2D\u4F7F\u7528\u4EE5\u4E0B\u5B57\u6BB5: ${IX.join(", ")}`),Z=!0;let _=O,j=Object.keys(_).filter((C)=>!ZH.has(C));if(j.length>0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5305\u542B\u975E\u6CD5\u5C5E\u6027: ${j.join(", ")}\uFF0C`+`\u5141\u8BB8\u7684\u5C5E\u6027\u4E3A: ${LX.join(", ")}`),Z=!0;if(!_.name||typeof _.name!=="string"){L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 name \u6216\u7C7B\u578B\u9519\u8BEF`),Z=!0;continue}if(!_.type||typeof _.type!=="string"){L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 type \u6216\u7C7B\u578B\u9519\u8BEF`),Z=!0;continue}if(_.min!==void 0&&!(_.min===null||typeof _.min==="number"))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 min \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A null \u6216\u6570\u5B57`),Z=!0;if(_.max!==void 0&&!(_.max===null||typeof _.max==="number"))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 max \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A null \u6216\u6570\u5B57`),Z=!0;if(_.detail!==void 0&&typeof _.detail!=="string")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 detail \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32`),Z=!0;if(_.index!==void 0&&typeof _.index!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 index \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.unique!==void 0&&typeof _.unique!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 unique \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.nullable!==void 0&&typeof _.nullable!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 nullable \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.unsigned!==void 0&&typeof _.unsigned!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 unsigned \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.regexp!==void 0&&_.regexp!==null&&typeof _.regexp!=="string")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 regexp \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A null \u6216\u5B57\u7B26\u4E32`),Z=!0;if(_.default!==void 0&&_.default!==null&&!SZ(_.default))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 default \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u53EF JSON \u5E8F\u5217\u5316\u7684\u503C\u6216 null`+`\uFF08typeof=${typeof _.default}\uFF0Cvalue=${ZJ(_.default)}\uFF09`),Z=!0;if(J.strict){if(!XH.test(_.name))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5\u540D\u79F0 "${_.name}" \u683C\u5F0F\u9519\u8BEF\uFF0C`+"\u5FC5\u987B\u4E3A\u4E2D\u6587\u3001\u6570\u5B57\u3001\u5B57\u6BCD\u3001\u4E0B\u5212\u7EBF\u3001\u77ED\u6A2A\u7EBF\u3001\u7A7A\u683C"),Z=!0}if(!JH.has(_.type))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5\u7C7B\u578B "${_.type}" \u683C\u5F0F\u9519\u8BEF\uFF0C`+`\u5FC5\u987B\u4E3A${qX.join("\u3001")}\u4E4B\u4E00`),Z=!0;if(_.type!=="number"&&_.unsigned!==void 0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5\u7C7B\u578B\u4E3A ${_.type}\uFF0C\u4E0D\u5141\u8BB8\u8BBE\u7F6E unsigned\uFF08\u4EC5 number \u7C7B\u578B\u6709\u6548\uFF09`),Z=!0;if(_.unique===!0&&_.index===!0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u540C\u65F6\u8BBE\u7F6E\u4E86 unique=true \u548C index=true\uFF0C`+"unique \u548C index \u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E\uFF0C\u8BF7\u5220\u9664\u5176\u4E00\uFF08\u5426\u5219\u4F1A\u521B\u5EFA\u91CD\u590D\u7D22\u5F15\uFF09"),Z=!0;if(_.min!==void 0&&_.max!==void 0&&_.min!==null&&_.max!==null){if(_.min>_.max)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u6700\u5C0F\u503C "${_.min}" \u4E0D\u80FD\u5927\u4E8E\u6700\u5927\u503C "${_.max}"`),Z=!0}if(_.type==="text"||_.type==="array_text"||_.type==="array_number_text"){if(_.min!==void 0&&_.min!==null)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7684 ${_.type} \u7C7B\u578B\u6700\u5C0F\u503C\u5E94\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${_.min}"`),Z=!0;if(_.max!==void 0&&_.max!==null)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7684 ${_.type} \u7C7B\u578B\u6700\u5927\u957F\u5EA6\u5E94\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${_.max}"`),Z=!0;if(_.default!==void 0&&_.default!==null)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${_.default}"`),Z=!0;if(_.index===!0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u4E0D\u652F\u6301\u521B\u5EFA\u7D22\u5F15\uFF08index=true \u65E0\u6548\uFF09`),Z=!0;if(_.unique===!0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u4E0D\u652F\u6301\u552F\u4E00\u7EA6\u675F\uFF08unique=true \u65E0\u6548\uFF09`),Z=!0}else if(_.type==="string"||_.type==="array_string"||_.type==="array_number_string"){if(_.max===void 0||_.max===null||typeof _.max!=="number")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C`+`\u5FC5\u987B\u8BBE\u7F6E max \u4E14\u7C7B\u578B\u4E3A\u6570\u5B57\uFF1B\u5176\u4E2D array_*_string \u7684 max \u8868\u793A\u5355\u4E2A\u5143\u7D20\u957F\u5EA6\uFF0C\u5F53\u524D\u4E3A "${_.max}"`),Z=!0;else if(_.max>KX)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u6700\u5927\u957F\u5EA6 ${_.max} \u8D8A\u754C\uFF0C`+`${_.type} \u7C7B\u578B\u957F\u5EA6\u5FC5\u987B\u5728 1..${KX} \u8303\u56F4\u5185`),Z=!0;else{if(_.index===!0&&_.max>FX)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u8BBE\u7F6E\u4E86 index=true\uFF0C`+`\u4F46 max=${_.max} \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u8981\u6C42 <= ${FX}\uFF09`),Z=!0;if(_.unique===!0&&_.max>RX)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u8BBE\u7F6E\u4E86 unique=true\uFF0C`+`\u4F46 max=${_.max} \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u8981\u6C42 <= ${RX}\uFF09`),Z=!0}if(_.default!==void 0&&_.default!==null){if(typeof _.default!=="string")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\u6216 null`+`\uFF08typeof=${typeof _.default}\uFF0Cvalue=${ZJ(_.default)}\uFF09`),Z=!0;else if(_.type!=="string")try{let C=JSON.parse(_.default);if(!Array.isArray(C))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5E94\u4E3A JSON \u6570\u7EC4\u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 "[]"\uFF09`+`\uFF08value=${ZJ(_.default)}\uFF09`),Z=!0}catch{L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5E94\u4E3A JSON \u6570\u7EC4\u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 "[]"\uFF09`+`\uFF08value=${ZJ(_.default)}\uFF09`),Z=!0}}}else if(_.type==="number"){if(_.default!==void 0&&_.default!==null&&typeof _.default!=="number")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A number \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A\u6570\u5B57\u6216 null`+`\uFF08typeof=${typeof _.default}\uFF0Cvalue=${ZJ(_.default)}\uFF09`),Z=!0}}}catch(Q){L.error({msg:`${G}${Y.fileName} \u89E3\u6790\u5931\u8D25`,err:Q}),Z=!0}}if(Z)throw Error("\u8868\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}$0();var{SQL:GH,RedisClient:QH}=globalThis.Bun;class _${static sqlClient=null;static redisClient=null;static sqlConnectedAt=null;static redisConnectedAt=null;static sqlPoolMax=1;static mysqlVersionText=null;static mysqlVersionMajor=null;static async connectSql($){let J=$||{},Z=typeof J.host==="string"?J.host.trim():"",Y=typeof J.port==="number"?J.port:NaN,X=typeof J.username==="string"?J.username.trim():"",G=J.password===void 0?"":typeof J.password==="string"?J.password:"",Q=typeof J.database==="string"?J.database.trim():"";if(!Z)throw Error("\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.host \u7F3A\u5931");if(!Number.isFinite(Y)||Y<1||Y>65535)throw Error(`\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.port \u975E\u6CD5\uFF08\u5F53\u524D\u503C\uFF1A${String(J.port)}\uFF09`);if(!X)throw Error("\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.username \u7F3A\u5931");if(!Q)throw Error("\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.database \u7F3A\u5931");let U=encodeURIComponent(X),z=encodeURIComponent(G),O=encodeURIComponent(Q),_=`mysql://${U}:${z}@${Z}:${Y}/${O}`,K=new GH({url:_,max:J.poolMax??1,bigint:!1});try{let C=(async()=>{let v=await K`SELECT VERSION() AS version`,T=typeof v?.[0]?.version==="string"?v?.[0]?.version:String(v?.[0]?.version||""),k=T.split(".")[0],E=Number(k);if(!Number.isFinite(E))throw Error(`\u65E0\u6CD5\u89E3\u6790 MySQL \u7248\u672C\u4FE1\u606F: ${T}`);if(E<8)throw Error(`\u4EC5\u652F\u6301 MySQL 8.0+\uFF0C\u5F53\u524D\u7248\u672C\uFF1A${T}`);return this.mysqlVersionText=T,this.mysqlVersionMajor=E,T})(),S=new Promise((v,T)=>{setTimeout(()=>{T(Error(`\u6570\u636E\u5E93\u8FDE\u63A5\u8D85\u65F6 (${30000}ms)`))},30000)});return await Promise.race([C,S]),this.sqlClient=K,this.sqlConnectedAt=Date.now(),this.sqlPoolMax=J.poolMax??1,K}catch(j){L.error({err:j,msg:"[Connect] SQL \u8FDE\u63A5\u5931\u8D25"});try{await K?.close()}catch{}throw j}}static async disconnectSql(){if(this.sqlClient){try{await this.sqlClient.close()}catch($){L.error({err:$,msg:"[Connect] \u5173\u95ED SQL \u8FDE\u63A5\u65F6\u51FA\u9519"})}this.sqlClient=null,this.sqlConnectedAt=null}}static getSql(){if(!this.sqlClient)throw Error("SQL \u5BA2\u6237\u7AEF\u672A\u8FDE\u63A5\uFF0C\u8BF7\u5148\u8C03\u7528 Connect.connectSql()");return this.sqlClient}static async connectRedis($){let J=$||{};try{let Z=J.host||"127.0.0.1",Y=J.port||6379,X=J.username||"",G=J.password||"",Q=J.db||0,U="",z=X?encodeURIComponent(X):"",O=G?encodeURIComponent(G):"";if(z&&O)U=`${z}:${O}@`;else if(O)U=`:${O}@`;let _=`redis://${U}${Z}:${Y}/${Q}`,K=new QH(_,{connectionTimeout:30000,idleTimeout:0,autoReconnect:!0,maxRetries:3,enableOfflineQueue:!0,enableAutoPipelining:!0});return await K.ping(),this.redisClient=K,this.redisConnectedAt=Date.now(),K}catch(Z){throw L.error({err:Z,msg:"[Connect] Redis \u8FDE\u63A5\u5931\u8D25"}),Error(`Redis \u8FDE\u63A5\u5931\u8D25: ${Z.message}`)}}static async disconnectRedis(){if(this.redisClient){try{this.redisClient.close(),this.redisConnectedAt=null}catch($){L.error({err:$,msg:"[Connect] \u5173\u95ED Redis \u8FDE\u63A5\u65F6\u51FA\u9519"})}this.redisClient=null}}static getRedis(){if(!this.redisClient)throw Error("Redis \u5BA2\u6237\u7AEF\u672A\u8FDE\u63A5\uFF0C\u8BF7\u5148\u8C03\u7528 Connect.connectRedis()");return this.redisClient}static async connect($){try{await this.connectSql($.db||{}),await this.connectRedis($.redis||{})}catch(J){let Z=typeof process?.env?.NODE_ENV==="string"?"development":"";throw L.error({env:Z,err:J,msg:"\u6570\u636E\u5E93\u8FDE\u63A5\u521D\u59CB\u5316\u5931\u8D25"}),await this.disconnect(),J}}static async disconnect(){await this.disconnectSql(),await this.disconnectRedis()}static isConnected(){return{sql:this.sqlClient!==null,redis:this.redisClient!==null}}static getStatus(){let $=Date.now();return{sql:{connected:this.sqlClient!==null,connectedAt:this.sqlConnectedAt,uptime:this.sqlConnectedAt?$-this.sqlConnectedAt:null,poolMax:this.sqlPoolMax,mysqlVersionText:this.mysqlVersionText,mysqlVersionMajor:this.mysqlVersionMajor},redis:{connected:this.redisClient!==null,connectedAt:this.redisConnectedAt,uptime:this.redisConnectedAt?$-this.redisConnectedAt:null}}}static __setMockSql($){this.sqlClient=$}static __setMockRedis($){this.redisClient=$}static __reset(){this.sqlClient=null,this.redisClient=null,this.sqlConnectedAt=null,this.redisConnectedAt=null,this.sqlPoolMax=1,this.mysqlVersionText=null,this.mysqlVersionMajor=null}}$0();$0();async function BX($){let J=new Map;for(let Z of $)try{if(Object.hasOwn(Z,"type")&&Z.type!=="api")continue;let Y=Z,X=Y.path,G={name:Y.name,handler:Y.handler,route:X},Q=Y.method;if(typeof Q==="string"){let K=Q.toUpperCase(),j=K==="POST,GET"?"GET,POST":K;G.method=["GET","POST","GET,POST"].includes(j)?j:"POST"}else G.method="POST";let U=Y.auth;if(U!==void 0)G.auth=U;let z=Y.fields;if(z!==void 0)G.fields=z;let O=Y.required;if(O!==void 0)G.required=O;let _=Y.rawBody;if(_!==void 0)G.rawBody=_;J.set(X,G)}catch(Y){throw L.error({err:Y,api:Z.relativePath,file:Z.filePath,msg:"\u63A5\u53E3\u52A0\u8F7D\u5931\u8D25"}),Y}return J}$0();m0();function RJ($,J={}){let Z=J.moduleLabel||"\u6A21\u5757",Y=J.getName||((K)=>{let j=K.moduleName;if(typeof j==="string"&&j.trim()!=="")return j;return F$(K.fileName)}),X=J.getDeps||((K)=>{let j=K.deps;if(!Array.isArray(j))return[];return j.filter((C)=>typeof C==="string")}),G=[],Q=new Set,U=new Set,z={},O=!0;for(let K of $){let j=Y(K);if(typeof j!=="string"||j.trim()===""){L.error({item:K,msg:`${Z} \u540D\u79F0\u89E3\u6790\u5931\u8D25\uFF08getName \u8FD4\u56DE\u7A7A\u5B57\u7B26\u4E32\uFF09`}),O=!1;continue}if(z[j]){L.error({name:j,first:z[j],second:K,msg:`${Z} \u540D\u79F0\u91CD\u590D\uFF0C\u65E0\u6CD5\u6839\u636E deps \u552F\u4E00\u5B9A\u4F4D`}),O=!1;continue}z[j]=K}if(!O)return!1;for(let K of $){let j=Y(K),C=X(K);if(!Array.isArray(C)){L.error({module:j,item:K,msg:`${Z} \u7684 deps \u5FC5\u987B\u662F\u6570\u7EC4`}),O=!1;continue}for(let S of C){if(typeof S!=="string"){L.error({module:j,dependency:S,item:K,msg:`${Z} \u7684 deps \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4`}),O=!1;continue}if(!z[S])L.error({module:j,dependency:S,msg:`${Z} \u4F9D\u8D56\u672A\u627E\u5230`}),O=!1}}if(!O)return!1;let _=(K)=>{if(Q.has(K))return;if(U.has(K)){L.error({module:K,msg:`${Z} \u5FAA\u73AF\u4F9D\u8D56`}),O=!1;return}let j=z[K];if(!j)return;let C=X(j);U.add(K);for(let S of C)_(S);U.delete(K),Q.add(K),G.push(j)};for(let K of $){let j=Y(K);_(j)}return O?G:!1}async function PX($){let J=[],Z=$.filter((X)=>{let G=X.moduleName;if(typeof G!=="string"||G.trim()==="")return!1;if((Object.hasOwn(X,"enable")?X.enable:void 0)===!1)return!1;return!0}),Y=RJ(Z,{moduleLabel:"\u94A9\u5B50"});if(Y===!1)throw Error("\u94A9\u5B50\u4F9D\u8D56\u5173\u7CFB\u9519\u8BEF");for(let X of Y){let G=X.moduleName,Q=Object.hasOwn(X,"deps")?X.deps:void 0,U=Array.isArray(Q)?Q.filter((_)=>typeof _==="string"):[],z=Object.hasOwn(X,"handler")?X.handler:void 0;if(typeof z!=="function")throw Error(`Hook '${G}' handler \u5FC5\u987B\u662F\u51FD\u6570`);let O=z;J.push({name:G,enable:!0,deps:U,handler:O})}return J}$0();async function EX($,J){let Z=[],Y=$.filter((G)=>{let Q=G.moduleName;if(typeof Q!=="string"||Q.trim()==="")return!1;if((Object.hasOwn(G,"enable")?G.enable:void 0)===!1)return!1;return!0}),X=RJ(Y,{moduleLabel:"\u63D2\u4EF6"});if(X===!1)throw Error("\u63D2\u4EF6\u4F9D\u8D56\u5173\u7CFB\u9519\u8BEF");for(let G of X){let Q=G.moduleName,U=Object.hasOwn(G,"deps")?G.deps:void 0,z=Array.isArray(U)?U.filter((K)=>typeof K==="string"):[],O=Object.hasOwn(G,"handler")?G.handler:void 0;if(typeof O!=="function")throw Error(`\u63D2\u4EF6 '${Q}' handler \u5FC5\u987B\u662F\u51FD\u6570`);let _=O;try{let K=await _(J);J[Q]=K,Z.push({name:Q,enable:!0,deps:z,handler:_})}catch(K){throw L.error({err:K,plugin:Q,msg:"\u63D2\u4EF6\u521D\u59CB\u5316\u5931\u8D25"}),K}}return Z}zJ();$0();function CX($,J){let Z=$.headers.get("x-forwarded-for");if(typeof Z==="string"&&Z.trim()){let U=Z.split(",")[0];if(typeof U==="string"&&U.trim())return U.trim()}let Y=$.headers.get("x-real-ip");if(typeof Y==="string"&&Y.trim())return Y.trim();let X=$.headers.get("cf-connecting-ip");if(typeof X==="string"&&X.trim())return X.trim();let G=$.headers.get("x-client-ip");if(typeof G==="string"&&G.trim())return G.trim();let Q=$.headers.get("true-client-ip");if(typeof Q==="string"&&Q.trim())return Q.trim();if(J&&typeof J.requestIP==="function"){let U=J.requestIP($);if(U&&typeof U.address==="string"&&U.address.trim())return U.address.trim()}return"unknown"}$0();function j$($,J,Z=1,Y=null,X=null,G=null){if($.requestId)L.info({event:"request_blocked",reason:J,reasonCode:G,code:Z,detail:X,msg:"request blocked"});return Response.json({code:Z,msg:J,data:Y,detail:X},{headers:$.corsHeaders})}function wZ($){if($.api&&$.requestId)L.info({event:"request_done",msg:"request done"});if($.response)return $.response;if($.result!==void 0){let J=$.result;if(typeof J==="string")J={code:0,msg:J};else if(J&&typeof J==="object"){if(!("code"in J))J={code:0,...J}}if(J&&typeof J==="object"){let Z=JSON.stringify(J,(Y,X)=>typeof X==="bigint"?X.toString():X);return new Response(Z,{headers:{...$.corsHeaders,"Content-Type":"application/json"}})}else return Response.json(J,{headers:$.corsHeaders})}return Response.json({code:1,msg:"\u672A\u751F\u6210\u54CD\u5E94"},{headers:$.corsHeaders})}m0();function SX($,J,Z){return async(Y,X)=>{let G=cY(),U=new URL(Y.url).pathname||"/",z=CX(Y,X),O=Date.now(),_={method:Y.method,body:{},user:{},req:Y,now:O,ip:z,headers:Y.headers,route:U,requestId:G,corsHeaders:{"X-Request-ID":G}},K=$.get(U);if(K)_.api=K;return mY({requestId:G,method:Y.method,route:U,ip:z,now:O},async()=>{try{for(let j of J)if(await j.handler(Z,_),_.response)return _.response;if(_.api&&Y.method!=="OPTIONS"){let j={event:"request",apiName:_.api.name};if(_.body&&Object.keys(_.body).length>0)j.body=_.body;j.msg="request",L.info(j)}if(!_.api){if(Y.method!=="OPTIONS")_.response=Response.json({code:1,msg:"\u63A5\u53E3\u4E0D\u5B58\u5728"},{headers:_.corsHeaders})}else if(_.api.handler){let j=await _.api.handler(Z,_);if(j instanceof Response)_.response=j;else _.result=j}return wZ(_)}catch(j){let C=_.api?U:Y.url;return L.error({err:j,path:C,msg:"\u8BF7\u6C42\u9519\u8BEF"}),_.result={code:1,msg:"\u5185\u90E8\u670D\u52A1\u9519\u8BEF"},wZ(_)}})}}L$();$0();L$();import{fileURLToPath as HH}from"url";var WH=HH(import.meta.url),B$=KJ(WH);var F4=w$(B$).endsWith("/dist")?B$:s(B$,"dist"),R4=s(B$,"checks"),I4=s(B$,"plugins"),q4=s(B$,"hooks"),L4=s(B$,"apis"),j4=s(B$,"tables"),d0=process.cwd(),B4=s(d0,"checks"),P4=s(d0,"plugins"),E4=s(d0,"hooks"),C4=s(d0,"apis"),S4=s(d0,"tables"),wX=s(d0,"addons");function IJ($,J={}){let Z=J.origin||"*";return{"Access-Control-Allow-Origin":Z==="*"?$.headers.get("origin")||"*":Z,"Access-Control-Allow-Methods":J.methods||"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":J.allowedHeaders||"Content-Type, Authorization, authorization, token","Access-Control-Expose-Headers":J.exposedHeaders||"Content-Range, X-Content-Range, Authorization, authorization, token","Access-Control-Max-Age":String(J.maxAge||86400),"Access-Control-Allow-Credentials":J.credentials||"true"}}function TX($=void 0){return async(J)=>{let Z=IJ(J,$),Y=new URL(J.url),X=s(d0,"public",Y.pathname);try{if(J.method==="OPTIONS")return new Response(null,{status:204,headers:Z});let G=Bun.file(X);if(await G.exists())return new Response(G,{headers:{"Content-Type":G.type||"application/octet-stream",...Z}});else return Response.json({code:1,msg:"\u6587\u4EF6\u672A\u627E\u5230"},{headers:Z})}catch(G){return L.error({err:G,msg:"\u9759\u6001\u6587\u4EF6\u5904\u7406\u5931\u8D25"}),Response.json({code:1,msg:"\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25"},{headers:Z})}}}$0();m0();var UH=($)=>{let J=$.split("/").map((G)=>G.trim()).filter((G)=>G.length>0),Y=(J[1]||"")==="addon"?4:3,X=J.slice(0,Math.min(Y,J.length));if(X.length===0)return"";return`/${X.join("/")}`};async function NX($,J){if(!$.db)throw Error("\u540C\u6B65\u63A5\u53E3\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.cache)throw Error("\u540C\u6B65\u63A5\u53E3\uFF1Actx.cache \u672A\u521D\u59CB\u5316");if(!(await $.db.tableExists("addon_admin_api")).data){L.debug(`${"addon_admin_api"} \u8868\u4E0D\u5B58\u5728`);return}let X=(await $.db.getAll({table:"addon_admin_api",fields:["id","path","parentPath","name","addonName","auth","state"],where:{state$gte:0}})).data.lists||[],G=bY(X,(_)=>_.path),Q=[],U=[],z=[],O=new Set;for(let _ of J){if(_.type!=="api")continue;let K=_,j=K.path,C=K.name,S=K.addonName;if(typeof j!=="string"||j.trim()==="")continue;if(typeof C!=="string"||C.trim()==="")continue;let v=typeof S==="string"?S:"",T=K.auth,k=T===!1||T===0?0:1,E=UH(j);O.add(j);let w=G[j];if(w){if(C!==w.name||j!==w.path||v!==w.addonName||E!==w.parentPath||k!==w.auth)U.push({id:w.id,name:C,path:j,parentPath:E,addonName:v,auth:k})}else Q.push({name:C,path:j,parentPath:E,addonName:v,auth:k})}for(let _ of X)if(!O.has(_.path))z.push(_.id);if(U.length>0)try{await $.db.updBatch("addon_admin_api",U.map((_)=>{return{id:_.id,data:{name:_.name,path:_.path,parentPath:_.parentPath,addonName:_.addonName,auth:_.auth}}}))}catch(_){L.error({err:_,msg:"\u540C\u6B65\u63A5\u53E3\u6279\u91CF\u66F4\u65B0\u5931\u8D25"})}if(Q.length>0)try{await $.db.insBatch("addon_admin_api",Q.map((_)=>{return{name:_.name,path:_.path,parentPath:_.parentPath,addonName:_.addonName,auth:_.auth}}))}catch(_){L.error({err:_,msg:"\u540C\u6B65\u63A5\u53E3\u6279\u91CF\u65B0\u589E\u5931\u8D25"})}if(z.length>0)try{await $.db.delForceBatch("addon_admin_api",z)}catch(_){L.error({err:_,msg:"\u540C\u6B65\u63A5\u53E3\u6279\u91CF\u5220\u9664\u5931\u8D25"})}}async function DX($){if(!$.cache)throw Error("\u540C\u6B65\u7F13\u5B58\uFF1Actx.cache \u672A\u521D\u59CB\u5316");await $.cache.cacheApis(),await $.cache.cacheMenus(),await $.cache.rebuildRoleApiPermissions()}import{createSign as VH}from"crypto";class g${static md5($,J="hex"){let Z=new Bun.CryptoHasher("md5");return Z.update($),Z.digest(J)}static hmacMd5($,J,Z="hex"){let Y=new Bun.CryptoHasher("md5",$);return Y.update(J),Y.digest(Z)}static sha1($,J="hex"){let Z=new Bun.CryptoHasher("sha1");return Z.update($),Z.digest(J)}static hmacSha1($,J,Z="hex"){let Y=new Bun.CryptoHasher("sha1",$);return Y.update(J),Y.digest(Z)}static sha256($,J="hex"){let Z=new Bun.CryptoHasher("sha256");return Z.update($),Z.digest(J)}static rsaSha256($,J,Z="hex"){let Y=VH("RSA-SHA256");return Y.update($),Y.sign(J,Z)}static hmacSha256($,J,Z="hex"){let Y=new Bun.CryptoHasher("sha256",$);return Y.update(J),Y.digest(Z)}static sha512($,J="hex"){let Z=new Bun.CryptoHasher("sha512");return Z.update($),Z.digest(J)}static hmacSha512($,J,Z="hex"){let Y=new Bun.CryptoHasher("sha512",$);return Y.update(J),Y.digest(Z)}static hash($,J,Z="hex"){let Y=new Bun.CryptoHasher($);return Y.update(J),Y.digest(Z)}static hmac($,J,Z,Y="hex"){let X=new Bun.CryptoHasher($,J);return X.update(Z),X.digest(Y)}static async hashFile($,J="sha256",Z="hex"){let Y=Bun.file($),X=new Bun.CryptoHasher(J),Q=Y.stream().getReader();try{while(!0){let{done:U,value:z}=await Q.read();if(U)break;X.update(z)}return X.digest(Z)}finally{Q.releaseLock()}}static async hashPassword($,J={}){let Z=Object.assign({},J,{algorithm:"bcrypt"});return await Bun.password.hash($,Z)}static async verifyPassword($,J){return await Bun.password.verify($,J)}static base64Encode($){return Buffer.from($,"utf8").toString("base64")}static base64Decode($){return Buffer.from($,"base64").toString("utf8")}static randomString($){let J=Math.ceil($/2),Z=crypto.getRandomValues(new Uint8Array(J)),Y="";for(let X=0;X<Z.length;X++)Y+=Z[X].toString(16).padStart(2,"0");return Y.slice(0,$)}static fastHash($,J=0){let Z=Bun.hash($,J);return typeof Z==="bigint"?Number(Z):Z}}$0();async function vX($,J={}){if(!J.devPassword)return;if(!$.db)throw Error("\u540C\u6B65\u5F00\u53D1\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.cache)throw Error("\u540C\u6B65\u5F00\u53D1\uFF1Actx.cache \u672A\u521D\u59CB\u5316");if(!(await $.db.tableExists("addon_admin_admin")).data){L.debug("addon_admin_admin \u8868\u4E0D\u5B58\u5728");return}if(!(await $.db.tableExists("addon_admin_role")).data){L.debug("addon_admin_role \u8868\u4E0D\u5B58\u5728");return}if(!(await $.db.tableExists("addon_admin_menu")).data){L.debug("addon_admin_menu \u8868\u4E0D\u5B58\u5728");return}if(!(await $.db.tableExists("addon_admin_api")).data){L.debug("addon_admin_api \u8868\u4E0D\u5B58\u5728");return}let Z=await $.db.getAll({table:"addon_admin_menu",fields:["path"],where:{state$gte:0},orderBy:["id#ASC"]}),Y=await $.db.getAll({table:"addon_admin_api",fields:["path"],where:{state$gte:0},orderBy:["id#ASC"]}),X=await $.db.getOne({table:"addon_admin_role",where:{code:"dev"}}),G={code:"dev",name:"\u5F00\u53D1\u8005\u89D2\u8272",description:"\u62E5\u6709\u6240\u6709\u83DC\u5355\u548C\u63A5\u53E3\u6743\u9650\u7684\u5F00\u53D1\u8005\u89D2\u8272",menus:Z.data.lists.map((O)=>O.path).filter((O)=>typeof O==="string"&&O.length>0),apis:Y.data.lists.map((O)=>O.path).filter((O)=>typeof O==="string"&&O.length>0),sort:0};if(typeof X.data.id==="number")await $.db.updData({table:"addon_admin_role",where:{code:"dev"},data:{name:G.name,description:G.description,menus:G.menus,apis:G.apis,sort:G.sort}});else await $.db.insData({table:"addon_admin_role",data:G});let Q={nickname:"\u5F00\u53D1\u8005",email:J.devEmail||"dev@qq.com",username:"dev",password:await g$.hashPassword(g$.sha256(J.devPassword+"befly")),roleCode:"dev",roleType:"admin"};if(typeof(await $.db.getOne({table:"addon_admin_admin",where:{username:"dev"}})).data.id==="number")await $.db.updData({table:"addon_admin_admin",where:{username:"dev"},data:{nickname:Q.nickname,email:Q.email,username:Q.username,password:Q.password,roleCode:Q.roleCode,roleType:Q.roleType}});else await $.db.insData({table:"addon_admin_admin",data:Q});let z=[{code:"user",name:"\u7528\u6237\u89D2\u8272",description:"\u666E\u901A\u7528\u6237\u89D2\u8272",sort:1},{code:"admin",name:"\u7BA1\u7406\u5458\u89D2\u8272",description:"\u7BA1\u7406\u5458\u89D2\u8272",sort:2},{code:"guest",name:"\u8BBF\u5BA2\u89D2\u8272",description:"\u8BBF\u5BA2\u89D2\u8272",sort:3}];for(let O of z)if((await $.db.getOne({table:"addon_admin_role",where:{code:O.code}})).data?.id)await $.db.updData({table:"addon_admin_role",where:{code:O.code},data:{name:O.name,description:O.description,sort:O.sort}});else await $.db.insData({table:"addon_admin_role",data:{code:O.code,name:O.name,description:O.description,menus:[],apis:[],sort:O.sort}})}$0();CZ();function zH($){let J=$.config?.disableMenus,Z=Array.isArray(J)?J:[],Y=[];for(let G of Z){if(typeof G!=="string")continue;let Q=G.trim();if(!Q)continue;Y.push(Q)}if(Y.length===0)return()=>!1;let X=Y.map((G)=>new Bun.Glob(G));return(G)=>{if(typeof G!=="string")return!1;let Q=G.trim();if(!Q)return!1;let U=[];if(U.push(Q),Q.startsWith("/"))U.push(Q.slice(1));else U.push(`/${Q}`);for(let z of X){let O=typeof z==="object"&&z!==null&&"match"in z?z.match:void 0;if(typeof O!=="function")throw Error("\u540C\u6B65\u83DC\u5355\uFF1A\u5F53\u524D Bun \u7248\u672C\u4E0D\u652F\u6301 Bun.Glob.match\uFF0C\u65E0\u6CD5\u6309 disableMenus \u505A glob \u5339\u914D");let _=O;for(let K of U)if(_.call(z,K))return!0}return!1}}function kX($,J){let Z=[];for(let Y of $){if(Y===null||typeof Y!=="object")continue;let X=typeof Y.path==="string"?String(Y.path).trim():"";if(X&&J(X))continue;let G=Y.children,Q=Array.isArray(G)&&G.length>0?kX(G,J):[],U={};if(typeof Y.name==="string")U.name=Y.name;if(typeof Y.path==="string")U.path=Y.path;if(typeof Y.sort==="number")U.sort=Y.sort;if(typeof Y.parentPath==="string")U.parentPath=Y.parentPath;if(Q.length>0)U.children=Q;Z.push(U)}return Z}function _H($){let J=new Map,Z=[];for(let Y of $)Z.push({menu:Y,parentPathFromTree:""});while(Z.length>0){let Y=Z.pop(),X=Y?Y.menu:null;if(!X)continue;let G=typeof X.path==="string"?X.path:"",Q=X.children;if(Q&&Array.isArray(Q)&&Q.length>0){let K=typeof G==="string"?G:"";for(let j of Q)Z.push({menu:j,parentPathFromTree:K})}if(!G)continue;let U=typeof X.name==="string"?X.name:"";if(!U)continue;let z=typeof X.sort==="number"?X.sort:999999,_=typeof X.parentPath==="string"?X.parentPath:typeof Y?.parentPathFromTree==="string"?Y.parentPathFromTree:zX(G);J.set(G,{path:G,name:U,sort:z,parentPath:_})}return J}async function xX($,J){if(!$.db)throw Error("\u540C\u6B65\u83DC\u5355\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.cache)throw Error("\u540C\u6B65\u83DC\u5355\uFF1Actx.cache \u672A\u521D\u59CB\u5316");if(!$.config)throw Error("\u540C\u6B65\u83DC\u5355\uFF1Actx.config \u672A\u521D\u59CB\u5316");if(!(await $.db.tableExists("addon_admin_menu")).data){L.debug("addon_admin_menu \u8868\u4E0D\u5B58\u5728");return}let Z=zH($),Y=kX(J,Z),X=_H(Y),G=new Set;for(let U of X.keys())G.add(U);let Q="addon_admin_menu";await $.db.trans(async(U)=>{let O=(await U.getAll({table:Q,fields:["id","name","path","parentPath","sort","state"]})).data.lists||[],_=O.filter((E)=>typeof E?.state==="number"&&E.state>=0),K=new Map,j=new Set,C=new Map;for(let E of _){if(typeof E?.path!=="string"||!E.path)continue;if(typeof E?.id!=="number")continue;if(Z(E.path))continue;let w=K.get(E.path);if(!w){K.set(E.path,E);continue}let f=typeof w?.id==="number"?w.id:0,D=E.id;if(D>f){if(K.set(E.path,E),f>0)j.add(f);let m=C.get(E.path)||{keptId:D,removedIds:[]};if(m.keptId=D,f>0)m.removedIds.push(f);C.set(E.path,m)}else{if(D>0)j.add(D);let m=C.get(E.path)||{keptId:f,removedIds:[]};if(m.keptId=f,D>0)m.removedIds.push(D);C.set(E.path,m)}}if(C.size>0){let E=[];for(let w of C.entries()){let f=w[0],D=w[1];if(E.push({path:f,keptId:D.keptId,removedIds:D.removedIds}),E.length>=10)break}L.warn({table:Q,duplicatePaths:C.size,duplicateIds:j.size,examples:E,msg:"addon_admin_menu \u68C0\u6D4B\u5230\u91CD\u590D path \u8BB0\u5F55\uFF1A\u5DF2\u4FDD\u7559 id \u6700\u5927\u7684\u4E00\u6761\u5E76\u5220\u9664\u5176\u4F59\u8BB0\u5F55"})}let S=[],v=[];for(let E of X.values()){let w=K.get(E.path);if(w){let f=typeof w.parentPath==="string"?w.parentPath:"";if(w.name!==E.name||w.sort!==E.sort||f!==E.parentPath)S.push({id:w.id,data:{name:E.name,path:E.path,parentPath:E.parentPath,sort:E.sort}})}else v.push({name:E.name,path:E.path,parentPath:E.parentPath,sort:E.sort})}if(S.length>0)await U.updBatch(Q,S);if(v.length>0)await U.insBatch(Q,v);let T=new Set;for(let E of _){if(typeof E?.path!=="string"||!E.path)continue;if(!G.has(E.path)){if(typeof E?.id==="number")T.add(E.id)}}for(let E of j)if(typeof E==="number"&&E>0)T.add(E);for(let E of O){if(typeof E?.path!=="string"||!E.path)continue;if(!Z(E.path))continue;if(typeof E?.id==="number"&&E.id>0)T.add(E.id)}let k=Array.from(T);if(k.length>0)await U.delForceBatch(Q,k)})}$0();function H$($){return{name:$.name,type:$.type,detail:$.detail??"",min:$.min??null,max:$.max??null,default:$.default??null,index:$.index??!1,unique:$.unique??!1,nullable:$.nullable??!1,unsigned:$.unsigned??!1,regexp:$.regexp??null}}function qJ($){return String($).replace(/"/g,"\\\"")}function NZ($){if($===null)return null;if(typeof $==="string"||typeof $==="number"||typeof $==="boolean")return $;if(Array.isArray($)){let J=[];for(let Z of $)J.push(NZ(Z));return J}return String($)}function OH($){if($===null)return!0;return typeof $==="string"||typeof $==="number"||typeof $==="boolean"}function MH($){if(!$||typeof $!=="object")return!1;if($ instanceof Date)return!1;if(Array.isArray($))return!1;return!0}function TZ($){if(OH($))return $;if(Array.isArray($)){let J=[];for(let Z of $){let Y=TZ(Z);if(Y===null)return null;J.push(Y)}return J}if(MH($)){let J={};for(let[Z,Y]of Object.entries($)){if(Y===void 0)continue;let X=TZ(Y);if(X===null)return null;J[Z]=X}return J}return null}function fX($){if(!Array.isArray($))return[];let J=[];for(let Z of $){if(Z===null){J.push(null);continue}if(typeof Z==="string"||typeof Z==="number"||typeof Z==="boolean"){J.push(Z);continue}if(typeof Z==="bigint"){J.push(String(Z));continue}if(Z instanceof Date){J.push(Z);continue}let Y=TZ(Z);if(Y!==null){J.push(Y);continue}J.push(String(Z))}return J}function P$($){if(typeof $==="number")return $;if(typeof $==="bigint")return Number($);return 0}m0();class N{static DB_VERSION_REQUIREMENTS={MYSQL_MIN_MAJOR:8};static CHANGE_TYPE_LABELS={length:"\u957F\u5EA6",datatype:"\u7C7B\u578B",comment:"\u6CE8\u91CA",default:"\u9ED8\u8BA4\u503C",nullable:"\u53EF\u7A7A\u7EA6\u675F",unique:"\u552F\u4E00\u7EA6\u675F"};static MYSQL_TABLE_CONFIG={ENGINE:"InnoDB",CHARSET:"utf8mb4",COLLATE:"utf8mb4_0900_ai_ci"};static SYSTEM_FIELDS=[{name:"id",comment:"\u4E3B\u952EID",needsIndex:!1,mysqlDdl:"BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT"},{name:"created_at",comment:"\u521B\u5EFA\u65F6\u95F4",needsIndex:!0,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 0"},{name:"updated_at",comment:"\u66F4\u65B0\u65F6\u95F4",needsIndex:!0,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 0"},{name:"deleted_at",comment:"\u5220\u9664\u65F6\u95F4",needsIndex:!1,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 0"},{name:"state",comment:"\u72B6\u6001\u5B57\u6BB5",needsIndex:!0,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 1"}];static SYSTEM_INDEX_FIELDS=["created_at","updated_at","state"];db;dbName;constructor($){if(!$?.db)throw Error("\u540C\u6B65\u8868\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.config)throw Error("\u540C\u6B65\u8868\uFF1Actx.config \u672A\u521D\u59CB\u5316");this.dbName=String($.config.db?.database||""),this.db=$.db}async run($){try{if(!Array.isArray($))throw Error("\u540C\u6B65\u8868\uFF1A\u8BF7\u4F20\u5165\u591A\u4E2A\u8868\u5B9A\u4E49\u7EC4\u6210\u7684\u6570\u7EC4");await N.ensureDbVersion(this.db);for(let J of $){if(!J||J.type!=="table")continue;let Z=J.source==="addon"?`addon_${c(J.addonName)}_${c(J.fileName)}`:c(J.fileName),Y=J.content;for(let G of Object.values(Y))N.normalizeFieldDefinitionInPlace(G);if(await N.tableExists(this.db,this.dbName,Z))await N.modifyTable(this.db,this.dbName,Z,Y);else await N.createTable(this.db,Z,Y)}}catch(J){throw L.error({err:J,msg:"\u6570\u636E\u5E93\u540C\u6B65\u5931\u8D25"}),J}}static buildRuntimeIoError($,J,Z){let Y=String(Z?.message||Z),X=Error(`\u540C\u6B65\u8868\uFF1A\u8BFB\u53D6\u5143\u4FE1\u606F\u5931\u8D25\uFF0C\u64CD\u4F5C=${$}\uFF0C\u8868=${J}\uFF0C\u9519\u8BEF=${Y}`);if(Z?.sqlInfo)X.sqlInfo=Z.sqlInfo;return X}static getTypeMapping(){return{number:"BIGINT",string:"VARCHAR",text:"MEDIUMTEXT",array_string:"VARCHAR",array_text:"MEDIUMTEXT",array_number_string:"VARCHAR",array_number_text:"MEDIUMTEXT"}}static normalizeFieldDefinitionInPlace($){let J=H$($);$.detail=J.detail,$.min=J.min,$.max=J.max,$.default=J.default,$.index=J.index,$.unique=J.unique,$.nullable=J.nullable,$.unsigned=J.unsigned,$.regexp=J.regexp}static isStringOrArrayType($){return $==="string"||$==="array_string"||$==="array_number_string"}static quoteIdentifier($){if(typeof $!=="string")throw Error(`quoteIdentifier \u9700\u8981\u5B57\u7B26\u4E32\u7C7B\u578B\u6807\u8BC6\u7B26 (identifier: ${String($)})`);let J=$.trim();if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(J))throw Error(`\u65E0\u6548\u7684 SQL \u6807\u8BC6\u7B26: ${J}`);return`\`${J}\``}static getSqlType($,J,Z=!1){let Y=N.getTypeMapping();if(N.isStringOrArrayType($)){if(typeof J!=="number")throw Error(`\u540C\u6B65\u8868\uFF1A\u5185\u90E8\u9519\u8BEF\uFF1A${$} \u7C7B\u578B\u7F3A\u5931 max\uFF08\u5E94\u7531 checkTable \u963B\u65AD\uFF09`);return`${Y[$]}(${J})`}let X=Y[$]||"TEXT";if($==="number"&&Z)return`${X} UNSIGNED`;return X}static resolveDefaultValue($,J){if($!==null&&$!=="null")return $;switch(J){case"number":return 0;case"string":return"";case"array_string":case"array_number_string":return"[]";case"text":case"array_text":case"array_number_text":return"null";default:return $}}static generateDefaultSql($,J){if(J==="text"||J==="array_text"||$==="null")return"";if(J==="number"||J==="string"||J==="array_string"||J==="array_number_string")if(typeof $==="number"&&!Number.isNaN($))return` DEFAULT ${$}`;else return` DEFAULT '${String($).replace(/'/g,"''")}'`;return""}static buildIndexClause($,J,Z){let Y=N.quoteIdentifier($);if(Z==="create"){let X=N.quoteIdentifier(J);return`ADD INDEX ${Y} (${X})`}return`DROP INDEX ${Y}`}static buildIndexSQL($,J,Z,Y){let X=N.quoteIdentifier($),G=N.buildIndexClause(J,Z,Y);return`ALTER TABLE ${X} ALGORITHM=INPLACE, LOCK=NONE, ${G}`}static getSystemColumnDef($){let J=null;for(let Y of N.SYSTEM_FIELDS)if(Y.name===$){J=Y;break}if(!J)return null;return`${N.quoteIdentifier(J.name)} ${J.mysqlDdl} COMMENT "${qJ(J.comment)}"`}static buildSystemColumnDefs(){let $=[];for(let J of N.SYSTEM_FIELDS){let Z=N.getSystemColumnDef(J.name);if(Z)$.push(Z)}return $}static buildBusinessColumnDefs($){let J=[];for(let[Z,Y]of Object.entries($)){let X=H$(Y),G=c(Z),Q=N.quoteIdentifier(G),U=N.getSqlType(X.type,X.max,X.unsigned),z=N.resolveDefaultValue(X.default,X.type),O=N.generateDefaultSql(z,X.type),_=X.unique?" UNIQUE":"",K=X.nullable?" NULL":" NOT NULL";J.push(`${Q} ${U}${_}${K}${O} COMMENT "${qJ(X.name)}"`)}return J}static generateDDLClause($,J,Z=!1){let Y=c($),X=N.quoteIdentifier(Y),G=H$(J),Q=N.getSqlType(G.type,G.max,G.unsigned),U=N.resolveDefaultValue(G.default,G.type),z=N.generateDefaultSql(U,G.type),O=G.unique?" UNIQUE":"",_=G.nullable?" NULL":" NOT NULL";return`${Z?"ADD COLUMN":"MODIFY COLUMN"} ${X} ${Q}${O}${_}${z} COMMENT "${qJ(G.name)}"`}static stripAlgorithmAndLock($){let J=String($);return J=J.replace(/\bALGORITHM\s*=\s*(INPLACE|INSTANT|COPY)\b\s*,?\s*/gi,"").replace(/\bLOCK\s*=\s*(NONE|SHARED|EXCLUSIVE)\b\s*,?\s*/gi,""),J=J.replace(/,\s*,/g,", ").replace(/,\s*$/g,"").replace(/\s{2,}/g," ").trim(),J}static buildDdlFallbackCandidates($){let J=String($),Z=[];if(/\bALGORITHM\s*=\s*INSTANT\b/i.test(J))Z.push({stmt:J.replace(/\bALGORITHM\s*=\s*INSTANT\b/gi,"ALGORITHM=INPLACE"),reason:"ALGORITHM=INSTANT \u2192 INPLACE"});let Y=N.stripAlgorithmAndLock(J);if(Y!==J)Z.push({stmt:Y,reason:"\u79FB\u9664 ALGORITHM/LOCK"});let X=[];for(let G of Z){if(!G.stmt||G.stmt.trim()==="")continue;if(G.stmt===J)continue;if(X.some((Q)=>Q.stmt===G.stmt))continue;X.push(G)}return X}static async executeDDLSafely($,J){try{return await $.unsafe(J),!0}catch(Z){let Y=N.buildDdlFallbackCandidates(J);for(let X of Y)try{return await $.unsafe(X.stmt),L.debug(`[DDL\u964D\u7EA7] ${X.reason}\uFF08\u5DF2\u6210\u529F\uFF09`),!0}catch{}throw Z}}static isCompatibleTypeChange($,J){let Z=String($||"").toLowerCase(),Y=String(J||"").toLowerCase();if(Z===Y)return!1;let X=Z.replace(/\s*unsigned/gi,"").replace(/\([^)]*\)/g,"").trim(),G=Y.replace(/\s*unsigned/gi,"").replace(/\([^)]*\)/g,"").trim(),Q=["tinytext","text","mediumtext","longtext"];if(Q.includes(X)&&Q.includes(G))return!0;let U=["tinyint","smallint","mediumint","int","integer","bigint"],z=U.indexOf(X),O=U.indexOf(G);if(z!==-1&&O!==-1&&O>z)return!0;if(X==="varchar"&&(G==="text"||G==="mediumtext"||G==="longtext"))return!0;return!1}static compareFieldDefinition($,J){let Z=[],Y=H$(J);if(N.isStringOrArrayType(Y.type)){let j=Y.max;if(j!==null&&$.max!==j)Z.push({type:"length",current:$.max,expected:j})}let X=$.comment===null||$.comment===void 0?"":String($.comment);if(X!==Y.name)Z.push({type:"comment",current:X,expected:Y.name});let Q=N.getTypeMapping()[Y.type];if(typeof Q!=="string")throw Error(`\u540C\u6B65\u8868\uFF1A\u672A\u77E5\u5B57\u6BB5\u7C7B\u578B\u6620\u5C04\uFF08\u7C7B\u578B=${String(Y.type)}\uFF09`);let U=Q.toLowerCase(),z="";if(typeof $.type==="string"&&$.type.trim()!=="")z=$.type;else if(typeof $.columnType==="string"&&$.columnType.trim()!=="")z=$.columnType;else z=String($.type??"");let O=z.toLowerCase().replace(/\s*unsigned/gi,"").replace(/\([^)]*\)/g,"").trim();if(O!==U)Z.push({type:"datatype",current:O,expected:U});let _=Y.nullable;if($.nullable!==_)Z.push({type:"nullable",current:$.nullable,expected:_});let K=N.resolveDefaultValue(Y.default,Y.type);if(String($.defaultValue)!==String(K))Z.push({type:"default",current:$.defaultValue,expected:K});return Z}static async tableExists($,J,Z){try{return((await $.unsafe("SELECT COUNT(*) as count FROM information_schema.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?",[J,Z])).data?.[0]?.count||0)>0}catch(Y){throw N.buildRuntimeIoError("\u68C0\u67E5\u8868\u662F\u5426\u5B58\u5728",Z,Y)}}static async getTableColumns($,J,Z){let Y={};try{let X=await $.unsafe("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT, COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION",[J,Z]);for(let G of X.data){let Q=NZ(G.COLUMN_DEFAULT);Y[G.COLUMN_NAME]={type:String(G.DATA_TYPE??""),columnType:String(G.COLUMN_TYPE??""),length:G.CHARACTER_MAXIMUM_LENGTH,max:G.CHARACTER_MAXIMUM_LENGTH,nullable:G.IS_NULLABLE==="YES",defaultValue:Q,comment:G.COLUMN_COMMENT===null?null:String(G.COLUMN_COMMENT)}}return Y}catch(X){throw N.buildRuntimeIoError("\u8BFB\u53D6\u5217\u4FE1\u606F",Z,X)}}static async getTableIndexes($,J,Z){let Y={};try{let X=await $.unsafe("SELECT INDEX_NAME, COLUMN_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND INDEX_NAME != 'PRIMARY' ORDER BY INDEX_NAME",[J,Z]);for(let G of X.data){let Q=G.INDEX_NAME,U=Y[Q];if(Array.isArray(U))U.push(G.COLUMN_NAME);else Y[Q]=[G.COLUMN_NAME]}return Y}catch(X){throw N.buildRuntimeIoError("\u8BFB\u53D6\u7D22\u5F15\u4FE1\u606F",Z,X)}}static async ensureDbVersion($){let J=await $.unsafe("SELECT VERSION() AS version");if(!J.data||J.data.length===0||!J.data[0]?.version)throw Error("\u540C\u6B65\u8868\uFF1A\u65E0\u6CD5\u83B7\u53D6 MySQL \u7248\u672C\u4FE1\u606F");let Z=J.data[0].version,Y=String(Z).split(".")[0]||"0",X=parseInt(Y,10);if(!Number.isFinite(X)||X<N.DB_VERSION_REQUIREMENTS.MYSQL_MIN_MAJOR)throw Error(`\u540C\u6B65\u8868\uFF1A\u4EC5\u652F\u6301 MySQL ${N.DB_VERSION_REQUIREMENTS.MYSQL_MIN_MAJOR}.0+\uFF08\u5F53\u524D\u7248\u672C\uFF1A${Z}\uFF09`)}static async applyTablePlan($,J,Z){if(!Z||!Z.changed)return;let Y=Z.indexActions.filter((Q)=>Q.action==="drop"),X=Z.indexActions.filter((Q)=>Q.action==="create");if(Y.length>0){let Q=[];for(let O of Y)Q.push(N.buildIndexClause(O.indexName,O.fieldName,"drop"));let z=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INPLACE, LOCK=NONE, ${Q.join(", ")}`;try{await N.executeDDLSafely($,z)}catch(O){throw L.error({err:O,table:J,msg:"\u6279\u91CF\u5220\u9664\u7D22\u5F15\u5931\u8D25"}),O}}let G=[...Z.addClauses,...Z.modifyClauses];if(G.length>0){let U=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INSTANT, LOCK=NONE, ${G.join(", ")}`;await N.executeDDLSafely($,U)}if(Z.defaultClauses.length>0){let U=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INSTANT, LOCK=NONE, ${Z.defaultClauses.join(", ")}`;await N.executeDDLSafely($,U)}if(X.length>0){let Q=[];for(let O of X)Q.push(N.buildIndexClause(O.indexName,O.fieldName,"create"));let z=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INPLACE, LOCK=NONE, ${Q.join(", ")}`;try{await N.executeDDLSafely($,z)}catch(O){throw L.error({err:O,table:J,msg:"\u6279\u91CF\u521B\u5EFA\u7D22\u5F15\u5931\u8D25"}),O}}}static async createTable($,J,Z,Y=N.SYSTEM_INDEX_FIELDS){let G=[...N.buildSystemColumnDefs(),...N.buildBusinessColumnDefs(Z)].join(`,
|
|
6
|
+
`)}});var JY=l((yG)=>{var fG=yG;fG.der=aZ();fG.pem=xG()});var YY=l((i5,uG)=>{var Q9=C$(),H9=lZ(),gG=l$().DecoderBuffer,bG=vJ(),hG=kJ();function cG($){this.enc="der",this.name=$.name,this.entity=$,this.tree=new r0,this.tree._init($.body)}uG.exports=cG;cG.prototype.decode=function(J,Z){if(!gG.isDecoderBuffer(J))J=new gG(J,Z);return this.tree._decode(J,Z)};function r0($){bG.call(this,"der",$)}Q9(r0,bG);r0.prototype._peekTag=function(J,Z,Y){if(J.isEmpty())return!1;let X=J.save(),G=ZY(J,'Failed to peek tag: "'+Z+'"');if(J.isError(G))return G;return J.restore(X),G.tag===Z||G.tagStr===Z||G.tagStr+"of"===Z||Y};r0.prototype._decodeTag=function(J,Z,Y){let X=ZY(J,'Failed to decode tag of "'+Z+'"');if(J.isError(X))return X;let G=pG(J,X.primitive,'Failed to get length of "'+Z+'"');if(J.isError(G))return G;if(!Y&&X.tag!==Z&&X.tagStr!==Z&&X.tagStr+"of"!==Z)return J.error('Failed to match tag: "'+Z+'"');if(X.primitive||G!==null)return J.skip(G,'Failed to match body of: "'+Z+'"');let Q=J.save(),U=this._skipUntilEnd(J,'Failed to skip indefinite length body: "'+this.tag+'"');if(J.isError(U))return U;return G=J.offset-Q.offset,J.restore(Q),J.skip(G,'Failed to match body of: "'+Z+'"')};r0.prototype._skipUntilEnd=function(J,Z){for(;;){let Y=ZY(J,Z);if(J.isError(Y))return Y;let X=pG(J,Y.primitive,Z);if(J.isError(X))return X;let G;if(Y.primitive||X!==null)G=J.skip(X);else G=this._skipUntilEnd(J,Z);if(J.isError(G))return G;if(Y.tagStr==="end")break}};r0.prototype._decodeList=function(J,Z,Y,X){let G=[];while(!J.isEmpty()){let Q=this._peekTag(J,"end");if(J.isError(Q))return Q;let U=Y.decode(J,"der",X);if(J.isError(U)&&Q)break;G.push(U)}return G};r0.prototype._decodeStr=function(J,Z){if(Z==="bitstr"){let Y=J.readUInt8();if(J.isError(Y))return Y;return{unused:Y,data:J.raw()}}else if(Z==="bmpstr"){let Y=J.raw();if(Y.length%2===1)return J.error("Decoding of string type: bmpstr length mismatch");let X="";for(let G=0;G<Y.length/2;G++)X+=String.fromCharCode(Y.readUInt16BE(G*2));return X}else if(Z==="numstr"){let Y=J.raw().toString("ascii");if(!this._isNumstr(Y))return J.error("Decoding of string type: numstr unsupported characters");return Y}else if(Z==="octstr")return J.raw();else if(Z==="objDesc")return J.raw();else if(Z==="printstr"){let Y=J.raw().toString("ascii");if(!this._isPrintstr(Y))return J.error("Decoding of string type: printstr unsupported characters");return Y}else if(/str$/.test(Z))return J.raw().toString();else return J.error("Decoding of string type: "+Z+" unsupported")};r0.prototype._decodeObjid=function(J,Z,Y){let X,G=[],Q=0,U=0;while(!J.isEmpty())if(U=J.readUInt8(),Q<<=7,Q|=U&127,(U&128)===0)G.push(Q),Q=0;if(U&128)G.push(Q);let z=G[0]/40|0,O=G[0]%40;if(Y)X=G;else X=[z,O].concat(G.slice(1));if(Z){let _=Z[X.join(" ")];if(_===void 0)_=Z[X.join(".")];if(_!==void 0)X=_}return X};r0.prototype._decodeTime=function(J,Z){let Y=J.raw().toString(),X,G,Q,U,z,O;if(Z==="gentime")X=Y.slice(0,4)|0,G=Y.slice(4,6)|0,Q=Y.slice(6,8)|0,U=Y.slice(8,10)|0,z=Y.slice(10,12)|0,O=Y.slice(12,14)|0;else if(Z==="utctime")if(X=Y.slice(0,2)|0,G=Y.slice(2,4)|0,Q=Y.slice(4,6)|0,U=Y.slice(6,8)|0,z=Y.slice(8,10)|0,O=Y.slice(10,12)|0,X<70)X=2000+X;else X=1900+X;else return J.error("Decoding "+Z+" time is not supported yet");return Date.UTC(X,G-1,Q,U,z,O,0)};r0.prototype._decodeNull=function(){return null};r0.prototype._decodeBool=function(J){let Z=J.readUInt8();if(J.isError(Z))return Z;else return Z!==0};r0.prototype._decodeInt=function(J,Z){let Y=J.raw(),X=new H9(Y);if(Z)X=Z[X.toString(10)]||X;return X};r0.prototype._use=function(J,Z){if(typeof J==="function")J=J(Z);return J._getDecoder("der").tree};function ZY($,J){let Z=$.readUInt8(J);if($.isError(Z))return Z;let Y=hG.tagClass[Z>>6],X=(Z&32)===0;if((Z&31)===31){let Q=Z;Z=0;while((Q&128)===128){if(Q=$.readUInt8(J),$.isError(Q))return Q;Z<<=7,Z|=Q&127}}else Z&=31;let G=hG.tag[Z];return{cls:Y,primitive:X,tag:Z,tagStr:G}}function pG($,J,Z){let Y=$.readUInt8(Z);if($.isError(Y))return Y;if(!J&&Y===128)return null;if((Y&128)===0)return Y;let X=Y&127;if(X>4)return $.error("length octect is too long");Y=0;for(let G=0;G<X;G++){Y<<=8;let Q=$.readUInt8(Z);if($.isError(Q))return Q;Y|=Q}return Y}});var nG=l((t5,mG)=>{var W9=C$(),U9=TJ().Buffer,XY=YY();function GY($){XY.call(this,$),this.enc="pem"}W9(GY,XY);mG.exports=GY;GY.prototype.decode=function(J,Z){let Y=J.toString().split(/[\r\n]+/g),X=Z.label.toUpperCase(),G=/^-----(BEGIN|END) ([^-]+)-----$/,Q=-1,U=-1;for(let _=0;_<Y.length;_++){let K=Y[_].match(G);if(K===null)continue;if(K[2]!==X)continue;if(Q===-1){if(K[1]!=="BEGIN")break;Q=_}else{if(K[1]!=="END")break;U=_;break}}if(Q===-1||U===-1)throw Error("PEM section not found for: "+X);let z=Y.slice(Q+1,U).join("");z.replace(/[^a-z0-9+/=]+/gi,"");let O=U9.from(z,"base64");return XY.prototype.decode.call(this,O,Z)}});var QY=l((sG)=>{var dG=sG;dG.der=YY();dG.pem=nG()});var lG=l((oG)=>{var V9=JY(),z9=QY(),_9=C$(),O9=oG;O9.define=function(J,Z){return new r$(J,Z)};function r$($,J){this.name=$,this.body=J,this.decoders={},this.encoders={}}r$.prototype._createNamed=function(J){let Z=this.name;function Y(X){this._initNamed(X,Z)}return _9(Y,J),Y.prototype._initNamed=function(G,Q){J.call(this,G,Q)},new Y(this)};r$.prototype._getDecoder=function(J){if(J=J||"der",!this.decoders.hasOwnProperty(J))this.decoders[J]=this._createNamed(z9[J]);return this.decoders[J]};r$.prototype.decode=function(J,Z,Y){return this._getDecoder(Z).decode(J,Y)};r$.prototype._getEncoder=function(J){if(J=J||"der",!this.encoders.hasOwnProperty(J))this.encoders[J]=this._createNamed(V9[J]);return this.encoders[J]};r$.prototype.encode=function(J,Z,Y){return this._getEncoder(Z).encode(J,Y)}});var iG=l((rG)=>{var xJ=rG;xJ.Reporter=NJ().Reporter;xJ.DecoderBuffer=l$().DecoderBuffer;xJ.EncoderBuffer=l$().EncoderBuffer;xJ.Node=vJ()});var eG=l((aG)=>{var tG=aG;tG._reverse=function(J){let Z={};return Object.keys(J).forEach(function(Y){if((Y|0)==Y)Y=Y|0;let X=J[Y];Z[X]=Y}),Z};tG.der=kJ()});var JQ=l(($Q)=>{var i$=$Q;i$.bignum=lZ();i$.define=lG().define;i$.base=iG();i$.constants=eG();i$.decoders=QY();i$.encoders=JY()});var XQ=l((HY,YQ)=>{/*! safe-buffer. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */var fJ=K$("buffer"),V$=fJ.Buffer;function ZQ($,J){for(var Z in $)J[Z]=$[Z]}if(V$.from&&V$.alloc&&V$.allocUnsafe&&V$.allocUnsafeSlow)YQ.exports=fJ;else ZQ(fJ,HY),HY.Buffer=D$;function D$($,J,Z){return V$($,J,Z)}D$.prototype=Object.create(V$.prototype);ZQ(V$,D$);D$.from=function($,J,Z){if(typeof $==="number")throw TypeError("Argument must not be a number");return V$($,J,Z)};D$.alloc=function($,J,Z){if(typeof $!=="number")throw TypeError("Argument must be a number");var Y=V$($);if(J!==void 0)if(typeof Z==="string")Y.fill(J,Z);else Y.fill(J);else Y.fill(0);return Y};D$.allocUnsafe=function($){if(typeof $!=="number")throw TypeError("Argument must be a number");return V$($)};D$.allocUnsafeSlow=function($){if(typeof $!=="number")throw TypeError("Argument must be a number");return fJ.SlowBuffer($)}});var QQ=l((Y7,GQ)=>{function WY($){var J=($/8|0)+($%8===0?0:1);return J}var M9={ES256:WY(256),ES384:WY(384),ES512:WY(521)};function A9($){var J=M9[$];if(J)return J;throw Error('Unknown algorithm "'+$+'"')}GQ.exports=A9});var OQ=l((X7,_Q)=>{var yJ=XQ().Buffer,WQ=QQ(),gJ=128,UQ=0,K9=32,F9=16,R9=2,VQ=F9|K9|UQ<<6,hJ=R9|UQ<<6;function I9($){return $.replace(/=/g,"").replace(/\+/g,"-").replace(/\//g,"_")}function zQ($){if(yJ.isBuffer($))return $;else if(typeof $==="string")return yJ.from($,"base64");throw TypeError("ECDSA signature must be a Base64 string or a Buffer")}function q9($,J){$=zQ($);var Z=WQ(J),Y=Z+1,X=$.length,G=0;if($[G++]!==VQ)throw Error('Could not find expected "seq"');var Q=$[G++];if(Q===(gJ|1))Q=$[G++];if(X-G<Q)throw Error('"seq" specified length of "'+Q+'", only "'+(X-G)+'" remaining');if($[G++]!==hJ)throw Error('Could not find expected "int" for "r"');var U=$[G++];if(X-G-2<U)throw Error('"r" specified length of "'+U+'", only "'+(X-G-2)+'" available');if(Y<U)throw Error('"r" specified length of "'+U+'", max of "'+Y+'" is acceptable');var z=G;if(G+=U,$[G++]!==hJ)throw Error('Could not find expected "int" for "s"');var O=$[G++];if(X-G!==O)throw Error('"s" specified length of "'+O+'", expected "'+(X-G)+'"');if(Y<O)throw Error('"s" specified length of "'+O+'", max of "'+Y+'" is acceptable');var _=G;if(G+=O,G!==X)throw Error('Expected to consume entire buffer, but "'+(X-G)+'" bytes remain');var K=Z-U,j=Z-O,C=yJ.allocUnsafe(K+U+j+O);for(G=0;G<K;++G)C[G]=0;$.copy(C,G,z+Math.max(-K,0),z+U),G=Z;for(var S=G;G<S+j;++G)C[G]=0;return $.copy(C,G,_+Math.max(-j,0),_+O),C=C.toString("base64"),C=I9(C),C}function HQ($,J,Z){var Y=0;while(J+Y<Z&&$[J+Y]===0)++Y;var X=$[J+Y]>=gJ;if(X)--Y;return Y}function L9($,J){$=zQ($);var Z=WQ(J),Y=$.length;if(Y!==Z*2)throw TypeError('"'+J+'" signatures must be "'+Z*2+'" bytes, saw "'+Y+'"');var X=HQ($,0,Z),G=HQ($,Z,$.length),Q=Z-X,U=Z-G,z=2+Q+1+1+U,O=z<gJ,_=yJ.allocUnsafe((O?2:3)+z),K=0;if(_[K++]=VQ,O)_[K++]=z;else _[K++]=gJ|1,_[K++]=z&255;if(_[K++]=hJ,_[K++]=Q,X<0)_[K++]=0,K+=$.copy(_,K,0,Z);else K+=$.copy(_,K,X,Z);if(_[K++]=hJ,_[K++]=U,G<0)_[K++]=0,$.copy(_,K,Z);else $.copy(_,K,Z+G);return _}_Q.exports={derToJose:q9,joseToDer:L9}});var _Y=l((G7,SQ)=>{var zY=JQ(),{createHmac:KQ,createVerify:j9,createSign:B9,timingSafeEqual:P9,createPublicKey:E9,constants:{RSA_PKCS1_PSS_PADDING:FQ,RSA_PSS_SALTLEN_DIGEST:RQ,RSA_PKCS1_PADDING:IQ,RSA_PSS_SALTLEN_MAX_SIGN:C9,RSA_PSS_SALTLEN_AUTO:S9},sign:MQ,verify:AQ}=K$("crypto"),{joseToDer:w9,derToJose:T9}=OQ(),qQ=sZ(),{TokenError:X0}=u$(),LQ=/[=+/]/g,N9={"=":"","+":"-","/":"_"},jQ=/^-----BEGIN(?: (RSA|EC|ENCRYPTED))? PRIVATE KEY-----/,BQ=/^-----BEGIN(?: (RSA))? PUBLIC KEY-----/,bJ=new qQ(1000),UY=new qQ(1000),PQ=["HS256","HS384","HS512"],D9=["ES256","ES384","ES512"],VY=["RS256","RS384","RS512","PS256","PS384","PS512"],v9=["EdDSA"],EQ={"1.2.840.10045.3.1.7":{bits:"256",names:["P-256","prime256v1"]},"1.3.132.0.10":{bits:"256",names:["secp256k1"]},"1.3.132.0.34":{bits:"384",names:["P-384","secp384r1"]},"1.3.132.0.35":{bits:"512",names:["P-521","secp521r1"]}},k9=zY.define("PrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("algorithm").seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().objid()))}),x9=zY.define("PublicKey",function(){this.seq().obj(this.key("algorithm").seq().obj(this.key("algorithm").objid(),this.key("parameters").optional().objid()))}),f9=zY.define("ECPrivateKey",function(){this.seq().obj(this.key("version").int(),this.key("privateKey").octstr(),this.key("parameters").explicit(0).optional().choice({namedCurve:this.objid()}))});function CQ($){return N9[$]}function QJ($,J,Z,Y){return $.set(J,[Z,Y]),Z||Y}function y9($){if($.match(BQ)||$.includes("-----BEGIN CERTIFICATE-----"))throw new X0(X0.codes.invalidKey,"Public keys are not supported for signing.");let J=$.trim().match(jQ);if(!J)return"HS256";let Z,Y,X;switch(J[1]){case"RSA":return"RS256";case"EC":Z=f9.decode($,"pem",{label:"EC PRIVATE KEY"}),X=Z.parameters.value.join(".");break;case"ENCRYPTED":return"ENCRYPTED";default:switch(Z=k9.decode($,"pem",{label:"PRIVATE KEY"}),Y=Z.algorithm.algorithm.join("."),Y){case"1.2.840.113549.1.1.1":return"RS256";case"1.2.840.10045.2.1":X=Z.algorithm.parameters.join(".");break;case"1.3.101.112":case"1.3.101.113":return"EdDSA";default:throw new X0(X0.codes.invalidKey,`Unsupported PEM PCKS8 private key with OID ${Y}.`)}}let G=EQ[X];if(!G)throw new X0(X0.codes.invalidKey,`Unsupported EC private key with curve ${X}.`);return`ES${G.bits}`}function g9($){let J=$.match(BQ);if($.match(jQ))throw new X0(X0.codes.invalidKey,"Private keys are not supported for verifying.");else if(J&&J[1]==="RSA")return VY;else if(!J&&!$.includes("-----BEGIN CERTIFICATE-----"))return PQ;if($.includes("-----BEGIN CERTIFICATE-----"))$=E9($).export({type:"spki",format:"pem"});let Z=x9.decode($,"pem",{label:"PUBLIC KEY"}),Y=Z.algorithm.algorithm.join("."),X;switch(Y){case"1.2.840.113549.1.1.1":return VY;case"1.2.840.10045.2.1":X=Z.algorithm.parameters.join(".");break;case"1.3.101.112":case"1.3.101.113":return["EdDSA"];default:throw new X0(X0.codes.invalidKey,`Unsupported PEM PCKS8 public key with OID ${Y}.`)}let G=EQ[X];if(!G)throw new X0(X0.codes.invalidKey,`Unsupported EC public key with curve ${X}.`);return[`ES${G.bits}`]}function h9($,J){if($ instanceof Buffer)$=$.toString("utf-8");else if(typeof $!=="string")throw new X0(X0.codes.invalidKey,"The private key must be a string or a buffer.");let[Z,Y]=bJ.get($)||[];if(Z)return Z;else if(Y)throw Y;try{let X=y9($);if(X==="ENCRYPTED")return QJ(bJ,$,J);return QJ(bJ,$,X)}catch(X){throw QJ(bJ,$,null,X0.wrap(X,X0.codes.invalidKey,"Unsupported PEM private key."))}}function b9($){if(!$)return"none";let[J,Z]=UY.get($)||[];if(J)return J;else if(Z)throw Z;try{if($ instanceof Buffer)$=$.toString("utf-8");else if(typeof $!=="string")throw new X0(X0.codes.invalidKey,"The public key must be a string or a buffer.");return QJ(UY,$,g9($))}catch(Y){throw QJ(UY,$,null,X0.wrap(Y,X0.codes.invalidKey,"Unsupported PEM public key."))}}function c9($,J,Z){try{let Y=$.slice(0,2),X=`sha${$.slice(2)}`,G,Q;switch(Y){case"HS":G=KQ(X,J).update(Z).digest("base64");break;case"ES":G=T9(MQ(X,Buffer.from(Z,"utf-8"),J),$).toString("base64");break;case"RS":case"PS":if(Q={key:J,padding:IQ,saltLength:C9},Y==="PS")Q.padding=FQ,Q.saltLength=RQ;G=B9(X).update(Z).sign(Q).toString("base64");break;case"Ed":G=MQ(void 0,Buffer.from(Z,"utf-8"),J).toString("base64")}return G.replace(LQ,CQ)}catch(Y){throw new X0(X0.codes.signError,"Cannot create the signature.",{originalError:Y})}}function p9($,J,Z,Y){try{let X=$.slice(0,2),G=`SHA${$.slice(2)}`;if(Y=Buffer.from(Y,"base64"),X==="HS")try{return P9(KQ(G,J).update(Z).digest(),Y)}catch{return!1}else if(X==="Ed")if(typeof AQ==="function")return AQ(void 0,Buffer.from(Z,"utf-8"),J,Y);else throw new X0(X0.codes.signError,"EdDSA algorithms are not supported by your Node.js version.");let Q={key:J,padding:IQ,saltLength:S9};if(X==="PS")Q.padding=FQ,Q.saltLength=RQ;else if(X==="ES")Y=w9(Y,$);return j9("RSA-"+G).update(Z).verify(Q,Y)}catch(X){throw new X0(X0.codes.verifyError,"Cannot verify the signature.",{originalError:X})}}SQ.exports={base64UrlMatcher:LQ,base64UrlReplacer:CQ,hsAlgorithms:PQ,rsaAlgorithms:VY,esAlgorithms:D9,edAlgorithms:v9,detectPrivateKeyAlgorithm:h9,detectPublicKeyAlgorithms:b9,createSignature:c9,verifySignature:p9}});var OY=l((Q7,TQ)=>{var{createHash:wQ}=K$("crypto"),u9=/"alg"\s*:\s*"[HERP]S(256|384)"/m,m9=/"alg"\s*:\s*"EdDSA"/m,n9=/"crv"\s*:\s*"Ed448"/m;function d9($,J,Z){let Y=$(J,Z);if(Y&&typeof Y.then==="function")Y.then((X)=>{process.nextTick(()=>Z(null,X))}).catch(Z)}function s9($){if(typeof $==="function")return[$];let J,Z,Y=new Promise((X,G)=>{J=X,Z=G});return[function(X,G){if(X)return Z(X);return J(G)},Y]}function o9($){let J=$.split(".",1)[0],Z=Buffer.from(J,"base64").toString("utf-8"),Y=null;if(Z.match(m9)&&Z.match(n9))Y=wQ("shake256",{outputLength:114});else{let X=Z.match(u9);Y=wQ(`sha${X?X[1]:"512"}`)}return Y.update($).digest("hex")}TQ.exports={getAsyncKey:d9,ensurePromiseCallback:s9,hashToken:o9}});var yQ=l((H7,fQ)=>{var{createPublicKey:l9,createSecretKey:r9}=K$("crypto"),i9=sZ(),{hsAlgorithms:DQ,verifySignature:t9,detectPublicKeyAlgorithms:vQ}=_Y(),a9=pZ(),{TokenError:d}=u$(),{getAsyncKey:e9,ensurePromiseCallback:$8,hashToken:J8}=OY();function Z8($,J){return $===J}function kQ($,J){for(let Z of $)if(J.includes(Z))return;throw new d(d.codes.invalidKey,`Invalid public key provided for algorithms ${$.join(", ")}.`)}function xQ($,J){if(typeof $==="string")$=Buffer.from($,"utf-8");return J?r9($):l9($)}function HJ($){if(!Array.isArray($))$=[$];return $.filter((J)=>J).map((J)=>{if(J&&typeof J.test==="function")return J;return{test:Z8.bind(null,J)}})}function Y8($){let J=parseInt($===!0?1000:$,10);return J>0?new i9(J):null}function t$({cache:$,token:J,cacheTTL:Z,payload:Y,ignoreExpiration:X,ignoreNotBefore:G,maxAge:Q,clockTimestamp:U=Date.now(),clockTolerance:z,errorCacheTTL:O,cacheKeyBuilder:_},K){if(!$)return K;let j=[K,0,0];if(K instanceof d){let v=typeof O==="function"?O(K):O;return j[2]=U+z+v,$.set(_(J),j),K}if(Y&&typeof Y.iat==="number"){if(j[1]=!G&&typeof Y.nbf==="number"?Y.nbf*1000-z:0,!X){if(typeof Y.exp==="number")j[2]=Y.exp*1000+z;else if(Q)j[2]=Y.iat*1000+Q+z}}let S=U+z+Z;return j[2]=j[2]===0?S:Math.min(j[2],S),$.set(_(J),j),K}function X8($,J,Z){if($ instanceof d){if(!J)throw $;J($)}else{if(!J)return $;J(null,$)}return Z}function G8($,J,Z,Y,X){if(!X.includes(J.alg))throw new d(d.codes.invalidAlgorithm,"The token algorithm is invalid.");if(Z&&!t9(J.alg,Y,$,Z))throw new d(d.codes.invalidSignature,"The token signature is invalid.")}function Q8($,J,Z,Y,X){let G=Z?`The ${J} claim must be a ${X} or an array of ${X}s.`:`The ${J} claim must be a ${X}.`;if(Y&&!Z)throw new d(d.codes.invalidClaimValue,G);if($.map((Q)=>typeof Q).some((Q)=>Q!==X))throw new d(d.codes.invalidClaimType,G)}function H8($,J,Z,Y){let X=Y?`None of ${J} claim values are allowed.`:`The ${J} claim value is not allowed.`;if(!$.some((G)=>Z.some((Q)=>Q.test(G))))throw new d(d.codes.invalidClaimValue,X)}function W8($,J,Z,Y,X,G){let Q=$*1000+(J||0);if(!(Y?Z>=Q:Z<=Q))throw new d(d.codes[X],`The token ${G} at ${new Date(Q).toISOString()}.`)}function NQ($,{input:J,header:Z,payload:Y,signature:X},{validators:G,allowedAlgorithms:Q,checkTyp:U,clockTimestamp:z,requiredClaims:O}){let _=$ instanceof Buffer?$.length:!!$;if(_&&!X)throw new d(d.codes.missingSignature,"The token signature is missing.");else if(!_&&X)throw new d(d.codes.missingKey,"The key option is missing.");if(G8(J,Z,X,$,Q),U&&(typeof Z.typ!=="string"||U!==Z.typ.toLowerCase().replace(/^application\//,"")))throw new d(d.codes.invalidType,"Invalid typ.");if(O){for(let j of O)if(!(j in Y))throw new d(d.codes.missingRequiredClaim,`The ${j} claim is required.`)}let K=z||Date.now();for(let{type:j,claim:C,allowed:S,array:v,modifier:T,greater:k,errorCode:E,errorVerb:w}of G){let f=Y[C],D=Array.isArray(f),m=D?f:[f];if(!(C in Y))continue;if(Q8(m,C,v,D,j==="date"?"number":"string"),j==="date")W8(f,T,K,k,E,w);else H8(m,C,S,D)}}function U8({key:$,allowedAlgorithms:J,complete:Z,cacheTTL:Y,checkTyp:X,clockTimestamp:G,clockTolerance:Q,ignoreExpiration:U,ignoreNotBefore:z,maxAge:O,isAsync:_,validators:K,decode:j,cache:C,requiredClaims:S,errorCacheTTL:v,cacheKeyBuilder:T},k,E){let[w,f]=_?$8(E):[];if(C){let[V,M,A]=C.get(T(k))||[void 0,0,0],I=G||Date.now();if(typeof V<"u"&&(M===0||I<M&&V.code==="FAST_JWT_INACTIVE"||I>=M&&V.code!=="FAST_JWT_INACTIVE")&&(A===0||I<=A))return X8(V,w,f)}let D;try{D=j(k)}catch(V){if(w)return w(V),f;throw V}let{header:m,payload:a,signature:r,input:i}=D,q={cache:C,token:k,cacheTTL:Y,errorCacheTTL:v,ignoreExpiration:U,ignoreNotBefore:z,maxAge:O,clockTimestamp:G,clockTolerance:Q,payload:a,cacheKeyBuilder:T},H={validators:K,allowedAlgorithms:J,checkTyp:X,clockTimestamp:G,clockTolerance:Q,requiredClaims:S};if(!w)try{return NQ($,D,H),t$(q,Z?{header:m,payload:a,signature:r,input:i}:a)}catch(V){throw t$(q,V)}return e9($,{header:m,payload:a,signature:r},(V,M)=>{if(V)return w(t$(q,d.wrap(V,d.codes.keyFetchingError,"Cannot fetch key.")));if(typeof M==="string")M=Buffer.from(M,"utf-8");else if(!(M instanceof Buffer))return w(t$(q,new d(d.codes.keyFetchingError,"The key returned from the callback must be a string or a buffer containing a secret or a public key.")));try{let A=vQ(M);if(H.allowedAlgorithms.length)kQ(J,A);else H.allowedAlgorithms=A;M=xQ(M,A[0]===DQ[0]),NQ(M,D,H)}catch(A){return w(t$(q,A))}w(null,t$(q,Z?{header:m,payload:a,signature:r,input:k}:a))}),f}fQ.exports=function(J){let{key:Z,algorithms:Y,complete:X,cache:G,cacheTTL:Q,errorCacheTTL:U,checkTyp:z,clockTimestamp:O,clockTolerance:_,ignoreExpiration:K,ignoreNotBefore:j,maxAge:C,allowedJti:S,allowedAud:v,allowedIss:T,allowedSub:k,allowedNonce:E,requiredClaims:w,cacheKeyBuilder:f}={cacheTTL:600000,clockTolerance:0,errorCacheTTL:-1,cacheKeyBuilder:J8,...J};if(!Array.isArray(Y))Y=[];let D=typeof Z;if(D!=="string"&&D!=="object"&&D!=="function")throw new d(d.codes.INVALID_OPTION,"The key option must be a string, a buffer or a function returning the algorithm secret or public key.");if(Z&&D!=="function"){let q=vQ(Z);if(Y.length)kQ(Y,q);else Y=q;Z=xQ(Z,q[0]===DQ[0])}if(O&&(typeof O!=="number"||O<0))throw new d(d.codes.invalidOption,"The clockTimestamp option must be a positive number.");if(_&&(typeof _!=="number"||_<0))throw new d(d.codes.invalidOption,"The clockTolerance option must be a positive number.");if(Q&&(typeof Q!=="number"||Q<0))throw new d(d.codes.invalidOption,"The cacheTTL option must be a positive number.");if(U&&typeof U!=="function"&&typeof U!=="number"||U<-1)throw new d(d.codes.invalidOption,"The errorCacheTTL option must be a number greater than -1 or a function.");if(w&&!Array.isArray(w))throw new d(d.codes.invalidOption,"The requiredClaims option must be an array.");let m=[];if(!j)m.push({type:"date",claim:"nbf",errorCode:"inactive",errorVerb:"will be active",greater:!0,modifier:-_});if(!K)m.push({type:"date",claim:"exp",errorCode:"expired",errorVerb:"has expired",modifier:+_});if(typeof C==="number")m.push({type:"date",claim:"iat",errorCode:"expired",errorVerb:"has expired",modifier:C});if(S)m.push({type:"string",claim:"jti",allowed:HJ(S)});if(v)m.push({type:"string",claim:"aud",allowed:HJ(v),array:!0});if(T)m.push({type:"string",claim:"iss",allowed:HJ(T)});if(k)m.push({type:"string",claim:"sub",allowed:HJ(k)});if(E)m.push({type:"string",claim:"nonce",allowed:HJ(E)});let a=z?z.toLowerCase().replace(/^application\//,""):null,r={key:Z,allowedAlgorithms:Y,complete:X,cacheTTL:Q,errorCacheTTL:U,checkTyp:a,clockTimestamp:O,clockTolerance:_,ignoreExpiration:K,ignoreNotBefore:j,maxAge:C,isAsync:D==="function",validators:m,decode:a9({complete:!0}),cache:Y8(G),requiredClaims:w,cacheKeyBuilder:f},i=U8.bind(null,r);return i.cache=r.cache,i}});var gQ=l((O8)=>{var V8=/^(-?(?:\d+)?\.?\d+) *(m(?:illiseconds?|s(?:ecs?)?))?(s(?:ec(?:onds?|s)?)?)?(m(?:in(?:utes?|s)?)?)?(h(?:ours?|rs?)?)?(d(?:ays?)?)?(w(?:eeks?|ks?)?)?(y(?:ears?|rs?)?)?$/,cJ=1000,pJ=cJ*60,uJ=pJ*60,UJ=uJ*24,MY=UJ*365.25;function z8($){var J,Z=$.toLowerCase().match(V8);if(Z!=null&&(J=parseFloat(Z[1]))){if(Z[3]!=null)return J*cJ;if(Z[4]!=null)return J*pJ;if(Z[5]!=null)return J*uJ;if(Z[6]!=null)return J*UJ;if(Z[7]!=null)return J*UJ*7;if(Z[8]!=null)return J*MY;return J}}function WJ($,J,Z,Y){var X=($|0)===$?$:~~($+0.5);return J+X+(Y?" "+Z+(X!=1?"s":""):Z[0])}function _8($,J){var Z=$<0?"-":"",Y=$<0?-$:$;if(Y<cJ)return $+(J?" ms":"ms");if(Y<pJ)return WJ(Y/cJ,Z,"second",J);if(Y<uJ)return WJ(Y/pJ,Z,"minute",J);if(Y<UJ)return WJ(Y/uJ,Z,"hour",J);if(Y<MY)return WJ(Y/UJ,Z,"day",J);return WJ(Y/MY,Z,"year",J)}O8.format=_8;O8.parse=z8});var dQ=l((U7,nQ)=>{var{base64UrlMatcher:AY,base64UrlReplacer:KY,hsAlgorithms:K8,esAlgorithms:F8,rsaAlgorithms:R8,edAlgorithms:I8,detectPrivateKeyAlgorithm:cQ,createSignature:hQ}=_Y(),{TokenError:o}=u$(),{getAsyncKey:q8,ensurePromiseCallback:L8}=OY(),{createPrivateKey:j8,createSecretKey:B8}=K$("crypto"),{parse:bQ}=gQ(),pQ=new Set([...K8,...F8,...R8,...I8,"none"]),P8=Array.from(pQ).join(", ");function uQ($,J){let Z=$.slice(0,2),Y=J.slice(0,2),X=!0;if(Z==="RS"||Z==="PS")X=Y==="RS"||Z==="RS"&&J==="ENCRYPTED";else if(Z==="ES"||Z==="Ed")X=Z===Y||Z==="ES"&&J==="ENCRYPTED";if(!X)throw new o(o.codes.invalidKey,`Invalid private key provided for algorithm ${$}.`)}function mQ($,J){if(typeof $==="string")$=Buffer.from($,"utf-8");return J[0]==="H"?B8($):j8($)}function E8({key:$,algorithm:J,noTimestamp:Z,mutatePayload:Y,clockTimestamp:X,expiresIn:G,notBefore:Q,kid:U,typ:z,isAsync:O,additionalHeader:_,fixedPayload:K},j,C){let[S,v]=O?L8(C):[];if(typeof j!=="object")throw new o(o.codes.invalidType,"The payload must be an object.");if(j.exp&&(!Number.isInteger(j.exp)||j.exp<0))throw new o(o.codes.invalidClaimValue,"The exp claim must be a positive integer.");let T={alg:J,typ:z||"JWT",kid:U,..._},k="",E=j.iat*1000||X||Date.now(),w={...j,...K,iat:Z?void 0:Math.floor(E/1000),exp:j.exp?j.exp:G?Math.floor((E+G)/1000):void 0,nbf:j.nbf?j.nbf:Q?Math.floor((E+Q)/1000):void 0};if(Y)Object.assign(j,w);if(k=Buffer.from(JSON.stringify(w),"utf-8").toString("base64").replace(AY,KY),!S){let D=Buffer.from(JSON.stringify(T),"utf-8").toString("base64").replace(AY,KY)+"."+k,m=J==="none"?"":hQ(J,$,D);return D+"."+m}return q8($,{header:T,payload:j},(f,D)=>{if(f){let a=o.wrap(f,o.codes.keyFetchingError,"Cannot fetch key.");return S(a)}if(typeof D==="string")D=Buffer.from(D,"utf-8");else if(!(D instanceof Buffer))return S(new o(o.codes.keyFetchingError,"The key returned from the callback must be a string or a buffer containing a secret or a private key."));let m;try{let a=cQ(D,J);if(J)uQ(J,a);else T.alg=J=a;D=mQ(D,J);let i=Buffer.from(JSON.stringify(T),"utf-8").toString("base64").replace(AY,KY)+"."+k;m=i+"."+hQ(J,D,i)}catch(a){return S(a)}S(null,m)}),v}nQ.exports=function(J){let{key:Z,algorithm:Y,noTimestamp:X,mutatePayload:G,clockTimestamp:Q,expiresIn:U,notBefore:z,jti:O,aud:_,iss:K,sub:j,nonce:C,kid:S,typ:v,header:T}={clockTimestamp:0,...J};if(Y&&!pQ.has(Y))throw new o(o.codes.invalidOption,`The algorithm option must be one of the following values: ${P8}.`);let k=typeof Z,E=k==="object"&&Z&&Z.key&&Z.passphrase;if(Y==="none"){if(Z)throw new o(o.codes.invalidOption,'The key option must not be provided when the algorithm option is "none".')}else if(!Z||k!=="string"&&!(Z instanceof Buffer)&&k!=="function"&&!E)throw new o(o.codes.invalidOption,"The key option must be a string, a buffer, an object containing key/passphrase properties or a function returning the algorithm secret or private key.");else if(E&&!Y)throw new o(o.codes.invalidAlgorithm,"When using password protected key you must provide the algorithm option.");if(Z&&k!=="function"){let D=cQ(E?Z.key:Z,Y);if(Y)uQ(Y,D);else Y=D;Z=mQ(Z,Y)}if(U){if(typeof U==="string")U=bQ(U);if(typeof U!=="number")throw new o(o.codes.invalidOption,"The expiresIn option must be a positive number or a valid string.")}if(z){if(typeof z==="string")z=bQ(z);if(typeof z!=="number"||z<0)throw new o(o.codes.invalidOption,"The notBefore option must be a positive number or a valid string.")}if(Q&&(typeof Q!=="number"||Q<0))throw new o(o.codes.invalidOption,"The clockTimestamp option must be a positive number.");if(O&&typeof O!=="string")throw new o(o.codes.invalidOption,"The jti option must be a string.");if(_&&typeof _!=="string"&&!Array.isArray(_))throw new o(o.codes.invalidOption,"The aud option must be a string or an array of strings.");if(K&&typeof K!=="string")throw new o(o.codes.invalidOption,"The iss option must be a string.");if(j&&typeof j!=="string")throw new o(o.codes.invalidOption,"The sub option must be a string.");if(C&&typeof C!=="string")throw new o(o.codes.invalidOption,"The nonce option must be a string.");if(S&&typeof S!=="string")throw new o(o.codes.invalidOption,"The kid option must be a string.");if(T&&typeof T!=="object")throw new o(o.codes.invalidOption,"The header option must be a object.");let f=Object.entries({jti:O,aud:_,iss:K,sub:j,nonce:C}).reduce((D,[m,a])=>{if(a!==void 0)D[m]=a;return D},{});return E8.bind(null,{key:Z,algorithm:Y,noTimestamp:X,mutatePayload:G,clockTimestamp:Q,expiresIn:U,notBefore:z,kid:S,typ:v,isAsync:k==="function",additionalHeader:T,fixedPayload:f})}});var oQ=l((V7,sQ)=>{var{TokenError:C8,TOKEN_ERROR_CODES:S8}=u$(),w8=pZ(),T8=yQ(),N8=dQ();sQ.exports={TokenError:C8,TOKEN_ERROR_CODES:S8,createDecoder:w8,createVerifier:T8,createSigner:N8}});AJ();import{join as LZ}from"path";m0();function Q$($){if(Array.isArray($)){let J=[];for(let Z of $)J.push(Q$(Z));return J}if(n($)){let J={},Z=$;for(let Y of Object.keys(Z))J[Y]=Q$(Z[Y]);return J}return $}function aY($,J){if(J===void 0)return $;if(Array.isArray($)&&Array.isArray(J)){let Z=[];for(let Y of $)Z.push(Q$(Y));for(let Y of J)Z.push(Q$(Y));return Z}if(n($)&&n(J)){let Z=$,Y=J,X={};for(let G of Object.keys(Z))X[G]=Q$(Z[G]);for(let G of Object.keys(Y)){let Q=Y[G];if(Q===void 0)continue;let U=X[G];if(Array.isArray(U)&&Array.isArray(Q)){let z=[];for(let O of U)z.push(Q$(O));for(let O of Q)z.push(Q$(O));X[G]=z;continue}if(n(U)&&n(Q)){X[G]=aY(Q$(U),Q);continue}X[G]=Q$(Q)}return X}return Q$(J)}function eY(...$){let J={};for(let Z of $){if(Z===void 0)continue;J=aY(J,Z)}return J}var y1={nodeEnv:"development",appName:"\u91CE\u8702\u98DE\u821E",appPort:3000,appHost:"127.0.0.1",devEmail:"dev@qq.com",devPassword:"beflydev123456",bodyLimit:1048576,tz:"Asia/Shanghai",strict:!0,logger:{debug:1,excludeFields:["password","token","secret"],dir:"./logs",console:1,maxSize:20,maxStringLen:100,maxArrayItems:100},db:{idMode:"timeId",host:"127.0.0.1",port:3306,username:"root",password:"root",database:"befly_demo",poolMax:10},redis:{host:"127.0.0.1",port:6379,username:"",password:"",db:0,prefix:"befly_demo"},auth:{secret:"befly-secret",expiresIn:"7d",algorithm:"HS256"},cors:{origin:"*",methods:"GET,HEAD,PUT,PATCH,POST,DELETE",allowedHeaders:"Content-Type,Authorization",exposedHeaders:"",maxAge:86400,credentials:"true"},rateLimit:{enable:1,defaultLimit:1000,defaultWindow:60,key:"ip",skipRoutes:[],rules:[]},disableMenus:["**/404","**/403","**/500","/addon/admin/login"],addons:{}};async function $X($){if($!=="development"&&$!=="production")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1ANODE_ENV \u53EA\u80FD\u662F 'development' \u6216 'production'\uFF0C\u5F53\u524D\u503C=${String($)}`);let J=LZ(process.cwd(),"configs"),Z=await q$(LZ(J,"befly.common.json"),{}),Y=await q$(LZ(J,`befly.${$}.json`),{}),X=eY(y1,Z,Y);X.nodeEnv=$;let G=X.redis?.prefix;if(typeof G==="string"){if(G.trim().includes(":"))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.prefix \u4E0D\u5141\u8BB8\u5305\u542B ':'\uFF08RedisHelper \u4F1A\u81EA\u52A8\u62FC\u63A5\u5206\u9694\u7B26 ':'\uFF09\uFF0C\u8BF7\u6539\u4E3A\u4E0D\u5E26\u5192\u53F7\u7684\u524D\u7F00\uFF0C\u4F8B\u5982 'befly_demo'\uFF0C\u5F53\u524D\u503C=${G}`)}let Q=X.db?.idMode;if(Q!==void 0&&Q!=="timeId"&&Q!=="autoId")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.idMode \u53EA\u80FD\u662F 'timeId' \u6216 'autoId'\uFF0C\u5F53\u524D\u503C=${String(Q)}`);let U=X.strict;if(U!==void 0&&typeof U!=="boolean")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Astrict \u5FC5\u987B\u4E3A boolean\uFF0C\u5F53\u524D\u503C=${String(U)}`);let z=X.checkTable;if(z!==void 0)throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AcheckTable \u914D\u7F6E\u5DF2\u5E9F\u5F03\uFF0C\u8BF7\u4F7F\u7528\u6839\u5C5E\u6027 strict\uFF08\u4F8B\u5982 { "strict": false }\uFF09\uFF0C\u5F53\u524D\u503C=${String(z)}`);return X}$0();m0();async function JX($){let J=!1,Z=new Set;for(let Y of $)try{if(!n(Y)){L.warn({item:Y,msg:"\u63A5\u53E3\u5FC5\u987B\u662F\u5BF9\u8C61"}),J=!0;continue}let X=Y,G=X.name;if(typeof G!=="string"||G.trim()===""){L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 name \u5C5E\u6027\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32"})),J=!0;continue}if(typeof X.handler!=="function"){L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570"})),J=!0;continue}let U=X.path;if(typeof U!=="string"||U.trim()==="")L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u5C5E\u6027\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;else{let S=U.trim();if(Z.has(S))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u91CD\u590D\uFF08\u4E25\u683C\u6A21\u5F0F\u7981\u6B62\u91CD\u590D path\uFF09"})),J=!0;else Z.add(S);if(/^(GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD)\b/i.test(S))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u4E0D\u5141\u8BB8\u5305\u542B method \u524D\u7F00\uFF0C\u5E94\u4E3A url.pathname\uFF08\u4F8B\u5982 /api/app/xxx\uFF09"})),J=!0;if(!S.startsWith("/api/"))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u5FC5\u987B\u4EE5 /api/ \u5F00\u5934"})),J=!0;if(S.includes(" "))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u4E0D\u5141\u8BB8\u5305\u542B\u7A7A\u683C"})),J=!0;if(S.includes("/api//"))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 path \u4E0D\u5141\u8BB8\u51FA\u73B0 /api//\uFF08\u91CD\u590D\u659C\u6760\uFF09"})),J=!0}let z=X.routePrefix,O=typeof z==="string"?z.trim():"";if(O==="")L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 routePrefix \u5C5E\u6027\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;else{if(!(O==="/app"||O.startsWith("/addon/")))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 routePrefix \u5FC5\u987B\u662F /app \u6216 /addon/<name>\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;if(typeof U==="string"&&U.trim()!==""){let S=U.trim(),v=`/api${O}/`;if(!S.startsWith(v))L.warn(Object.assign({},p(X,["handler"]),{expectedPrefix:v,msg:"\u63A5\u53E3\u7684 path \u4E0E routePrefix \u4E0D\u4E00\u81F4\uFF1A\u5E94\u4EE5 /api${routePrefix}/ \u5F00\u5934\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0}}let _=X.method;if(_!==void 0&&!["GET","POST","GET,POST"].includes(String(_).toUpperCase()))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 method \u5C5E\u6027\u5FC5\u987B\u662F\u6709\u6548\u7684 HTTP \u65B9\u6CD5 (GET, POST, GET,POST)"})),J=!0;let K=X.auth;if(K!==void 0&&typeof K!=="boolean")L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 auth \u5C5E\u6027\u5FC5\u987B\u662F\u5E03\u5C14\u503C (true=\u9700\u767B\u5F55, false=\u516C\u5F00)"})),J=!0;let j=X.fields;if(j!==void 0&&j!==null&&!n(j))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 fields \u5C5E\u6027\u5FC5\u987B\u662F\u5BF9\u8C61"})),J=!0;let C=X.required;if(C!==void 0&&!Array.isArray(C))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 required \u5C5E\u6027\u5FC5\u987B\u662F\u6570\u7EC4"})),J=!0;if(Array.isArray(C)){if(C.some((S)=>typeof S!=="string"))L.warn(Object.assign({},p(X,["handler"]),{msg:"\u63A5\u53E3\u7684 required \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0}}catch(X){L.error({err:X,item:Y,msg:"\u63A5\u53E3\u89E3\u6790\u5931\u8D25"}),J=!0}if(J)throw Error("\u63A5\u53E3\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}function x$($){return typeof $==="string"&&$.trim().length>0}function jZ($){return typeof $==="number"&&Number.isFinite($)&&$>=1&&$<=65535}function g1($){return typeof $==="number"&&Number.isFinite($)&&$>=0&&Math.floor($)===$}function h1($){return typeof $==="number"&&Number.isFinite($)&&$>=1&&Math.floor($)===$}function b1($){if(!x$($))return!1;try{return new Intl.DateTimeFormat("en-US",{timeZone:$}).format(0),!0}catch{return!1}}function c1($){if(!$)throw Error("\u914D\u7F6E\u9519\u8BEF\uFF1A\u7F3A\u5C11 db \u914D\u7F6E\uFF08config.db\uFF09");if(!x$($.host))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.host \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.host)}`);if(!jZ($.port))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.port \u5FC5\u987B\u4E3A 1..65535 \u7684\u6570\u5B57\uFF0C\u5F53\u524D\u503C=${String($.port)}`);if(!x$($.username))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.username \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.username)}`);if($.password!==void 0&&typeof $.password!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.password \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF08\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u5F53\u524D\u503C=${String($.password)}`);if(!x$($.database))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.database \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.database)}`);if($.poolMax!==void 0){if(typeof $.poolMax!=="number"||!Number.isFinite($.poolMax)||$.poolMax<=0)throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Adb.poolMax \u5FC5\u987B\u4E3A\u6B63\u6570\uFF0C\u5F53\u524D\u503C=${String($.poolMax)}`)}}function p1($){if(!$)throw Error("\u914D\u7F6E\u9519\u8BEF\uFF1A\u7F3A\u5C11 redis \u914D\u7F6E\uFF08config.redis\uFF09");if($.host!==void 0&&typeof $.host!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.host \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.host)}`);if($.port!==void 0&&!jZ($.port))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.port \u5FC5\u987B\u4E3A 1..65535 \u7684\u6570\u5B57\uFF0C\u5F53\u524D\u503C=${String($.port)}`);if($.db!==void 0&&!g1($.db))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.db \u5FC5\u987B\u4E3A\u975E\u8D1F\u6574\u6570\uFF0C\u5F53\u524D\u503C=${String($.db)}`);let J=$.prefix;if(J!==void 0){if(typeof J!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.prefix \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String(J)}`);if(J.includes(":"))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Aredis.prefix \u4E0D\u5141\u8BB8\u5305\u542B ':'\uFF08RedisHelper \u4F1A\u81EA\u52A8\u62FC\u63A5\u5206\u9694\u7B26 ':'\uFF09\uFF0C\u5F53\u524D\u503C=${String(J)}`)}}async function ZX($){if(!$||typeof $!=="object")throw Error("\u914D\u7F6E\u9519\u8BEF\uFF1Aconfig \u5FC5\u987B\u4E3A\u5BF9\u8C61");if($.nodeEnv!=="development"&&$.nodeEnv!=="production")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AnodeEnv \u53EA\u80FD\u662F development/production\uFF0C\u5F53\u524D\u503C=${String($.nodeEnv)}`);if($.appName!==void 0){if(!x$($.appName))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AappName \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.appName)}`)}if($.appPort!==void 0){if(!jZ($.appPort))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AappPort \u5FC5\u987B\u4E3A 1..65535 \u7684\u6570\u5B57\uFF0C\u5F53\u524D\u503C=${String($.appPort)}`)}if($.appHost!==void 0){if(!x$($.appHost))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AappHost \u5FC5\u987B\u4E3A\u975E\u7A7A\u5B57\u7B26\u4E32\uFF0C\u5F53\u524D\u503C=${String($.appHost)}`)}if($.devEmail!==void 0){if(typeof $.devEmail!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AdevEmail \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF08\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u5F53\u524D\u503C=${String($.devEmail)}`);let J=$.devEmail.trim();if(J.length>0&&!J.includes("@"))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AdevEmail \u683C\u5F0F\u9519\u8BEF\uFF08\u5FC5\u987B\u5305\u542B '@'\uFF0C\u6216\u7F6E\u4E3A\u7A7A\u5B57\u7B26\u4E32\u4EE5\u7981\u7528 syncDev\uFF09\uFF0C\u5F53\u524D\u503C=${String($.devEmail)}`)}if($.devPassword!==void 0){if(typeof $.devPassword!=="string")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AdevPassword \u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\uFF08\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32\uFF09\uFF0C\u5F53\u524D\u503C=${String($.devPassword)}`)}if($.bodyLimit!==void 0){if(!h1($.bodyLimit))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1AbodyLimit \u5FC5\u987B\u4E3A\u6B63\u6574\u6570\uFF08\u5B57\u8282\uFF09\uFF0C\u5F53\u524D\u503C=${String($.bodyLimit)}`)}if($.tz!==void 0){if(!b1($.tz))throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Atz \u5FC5\u987B\u4E3A\u6709\u6548\u7684 IANA \u65F6\u533A\u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 'Asia/Shanghai'\uFF09\uFF0C\u5F53\u524D\u503C=${String($.tz)}`)}if(typeof $.strict!=="boolean")throw Error(`\u914D\u7F6E\u9519\u8BEF\uFF1Astrict \u5FC5\u987B\u4E3A true \u6216 false\uFF0C\u5F53\u524D\u503C=${String($.strict)}`);c1($.db),p1($.redis)}$0();m0();var YX=["name","enable","deps","handler"];async function XX($){let J=!1,Z=/^[a-z]+(?:_[a-z]+)*$/;for(let Y of $)try{if(!n(Y)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u5BFC\u51FA\u5FC5\u987B\u662F\u5BF9\u8C61\uFF08export default { deps, handler }\uFF09"})),J=!0;continue}let X=Y,G=X.moduleName;if(typeof G!=="string"||G.trim()===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 moduleName \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u7528\u4E8E deps \u4E0E\u8FD0\u884C\u65F6\u6302\u8F7D\uFF09"})),J=!0;continue}let Q=X.customKeys;if(!Array.isArray(Q)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u626B\u63CF\u7ED3\u679C\u7F3A\u5C11 customKeys\uFF08\u65E0\u6CD5\u5224\u65AD\u7528\u6237\u5BFC\u51FA\u7684\u5B57\u6BB5\u662F\u5426\u5408\u6CD5\uFF09"})),J=!0;continue}if(Q.some((_)=>typeof _!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 customKeys \u5FC5\u987B\u662F string[]\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;continue}let U=Q.filter((_)=>!YX.includes(_));if(U.length>0){L.warn(Object.assign({},p(Y,["handler"]),{msg:`\u94A9\u5B50\u5BFC\u51FA\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5C5E\u6027\uFF1A${U.join(", ")}\uFF1B\u4EC5\u5141\u8BB8\uFF1A${YX.join(", ")}\uFF1B\u5F53\u524D customKeys\uFF1A${Q.join(", ")}`})),J=!0;continue}let z=Q.includes("enable"),O=Q.includes("deps");if(z){if(typeof X.enable!=="boolean"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 enable \u5C5E\u6027\u5FC5\u987B\u662F boolean\uFF08true/false\uFF09\uFF0C\u4E0D\u5141\u8BB8 0/1 \u7B49\u5176\u4ED6\u7C7B\u578B"})),J=!0;continue}}else X.enable=!0;if(X.source==="core"){let _=typeof X.name==="string"?X.name:"";if(_===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u5FC5\u987B\u663E\u5F0F\u8BBE\u7F6E name\uFF08string\uFF09\uFF0C\u7528\u4E8E\u786E\u5B9A\u94A9\u5B50\u540D\u79F0"})),J=!0;continue}if(!Z.test(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u7684 name \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u4F8B\u5982 auth / rate_limit\uFF09\uFF0C\u4E0D\u5141\u8BB8\u7A7A\u683C\u3001\u9A7C\u5CF0\u6216\u5176\u4ED6\u5B57\u7B26"})),J=!0;continue}if(!Z.test(String(X.moduleName))){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u7684 moduleName \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u4E14\u5FC5\u987B\u4E0E name \u4E00\u81F4\uFF09"})),J=!0;continue}if(_!==String(X.moduleName)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u7684 name \u5FC5\u987B\u4E0E moduleName \u5B8C\u5168\u4E00\u81F4"})),J=!0;continue}let K=X.filePath;if(typeof K!=="string"||!K.startsWith(`core:hook:${_}`)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u94A9\u5B50\u5FC5\u987B\u6765\u81EA\u9759\u6001\u6CE8\u518C\uFF08filePath \u5FC5\u987B\u4EE5 core:hook:<name> \u5F00\u5934\uFF09\uFF0C\u4E0D\u5141\u8BB8\u901A\u8FC7\u626B\u63CF\u76EE\u5F55\u52A0\u8F7D"})),J=!0;continue}}if(O){let _=X.deps;if(!Array.isArray(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}if(_.some((K)=>typeof K!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}}else{let _=X.deps;if(!Array.isArray(_))X.deps=[]}if(typeof X.handler!=="function"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u94A9\u5B50\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570"})),J=!0;continue}}catch(X){L.error({err:X,item:Y,msg:"\u94A9\u5B50\u89E3\u6790\u5931\u8D25"}),J=!0}if(J)throw Error("\u94A9\u5B50\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}$0();CZ();function t1($){if(!$)return{ok:!1,reason:"path \u4E0D\u80FD\u4E3A\u7A7A"};if(!$.startsWith("/"))return{ok:!1,reason:"path \u5FC5\u987B\u4EE5 / \u5F00\u5934"};if($.length>1&&$.endsWith("/"))return{ok:!1,reason:"path \u672B\u5C3E\u4E0D\u80FD\u662F /\uFF08\u6839\u8DEF\u5F84 / \u9664\u5916\uFF09"};if($.includes("//"))return{ok:!1,reason:"path \u4E0D\u80FD\u5305\u542B //"};if($.includes(".."))return{ok:!1,reason:"path \u4E0D\u80FD\u5305\u542B .."};return{ok:!0,reason:""}}var OX=async($)=>{let J=!1,Z=await _X($),Y=[];for(let G of Z)Y.push({menu:G,depth:1});let X=new Set;while(Y.length>0){let G=Y.pop(),Q=G?.menu,U=typeof G?.depth==="number"?G.depth:0;if(Q===null||typeof Q!=="object"){J=!0,L.warn({menu:Q,msg:"\u83DC\u5355\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61"});continue}if(U>3){J=!0,L.warn({path:Q?.path,depth:U,msg:"\u83DC\u5355\u5C42\u7EA7\u8D85\u8FC7 3 \u7EA7\uFF08\u6700\u591A\u4E09\u7EA7\uFF09"});continue}let z=Q.children;if(typeof z<"u"&&!Array.isArray(z)){J=!0,L.warn({path:Q?.path,childrenType:typeof z,msg:"\u83DC\u5355 children \u5FC5\u987B\u662F\u6570\u7EC4"});continue}if(Array.isArray(z)&&z.length>0)if(U>=3)J=!0,L.warn({path:Q?.path,depth:U,msg:"\u83DC\u5355\u5C42\u7EA7\u8D85\u8FC7 3 \u7EA7\uFF08\u6700\u591A\u4E09\u7EA7\uFF09"});else for(let C of z)Y.push({menu:C,depth:U+1});let O=typeof Q.path==="string"?Q.path.trim():"",_=typeof Q.name==="string"?Q.name.trim():"",K=typeof Q.sort==="number"?Q.sort:999999;if(typeof Q.path==="string")Q.path=O;if(typeof Q.name==="string")Q.name=_;if(typeof Q.sort>"u")Q.sort=K;if(!O){J=!0,L.warn({menu:Q,msg:"\u83DC\u5355\u7F3A\u5C11 path\uFF08\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF09"});continue}let j=t1(O);if(!j.ok)J=!0,L.warn({path:O,reason:j.reason,msg:"\u83DC\u5355 path \u4E0D\u5408\u6CD5"});if(!_)J=!0,L.warn({path:O,menu:Q,msg:"\u83DC\u5355\u7F3A\u5C11 name\uFF08\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF09"});if(typeof Q.sort<"u"&&typeof Q.sort!=="number")J=!0,L.warn({path:O,sort:Q.sort,msg:"\u83DC\u5355 sort \u5FC5\u987B\u662F number"});if(typeof Q.sort==="number"&&(!Number.isFinite(Q.sort)||Q.sort<1))J=!0,L.warn({path:O,sort:Q.sort,msg:"\u83DC\u5355 sort \u6700\u5C0F\u503C\u4E3A 1"});if(X.has(O)){J=!0,L.warn({path:O,msg:"\u83DC\u5355 path \u91CD\u590D\uFF08\u4E25\u683C\u6A21\u5F0F\u7981\u6B62\u91CD\u590D path\uFF09"});continue}X.add(O)}if(J)throw Error("\u83DC\u5355\u7ED3\u6784\u68C0\u67E5\u5931\u8D25");return Z};$0();m0();var MX=["name","enable","deps","handler"];async function AX($){let J=!1,Z=/^[a-z]+(?:_[a-z]+)*$/;for(let Y of $)try{if(!n(Y)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u5BFC\u51FA\u5FC5\u987B\u662F\u5BF9\u8C61\uFF08export default { deps, handler }\uFF09"})),J=!0;continue}let X=Y,G=X.moduleName;if(typeof G!=="string"||G.trim()===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 moduleName \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u7528\u4E8E deps \u4E0E\u8FD0\u884C\u65F6\u6302\u8F7D\uFF09"})),J=!0;continue}let Q=X.customKeys;if(!Array.isArray(Q)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u626B\u63CF\u7ED3\u679C\u7F3A\u5C11 customKeys\uFF08\u65E0\u6CD5\u5224\u65AD\u7528\u6237\u5BFC\u51FA\u7684\u5B57\u6BB5\u662F\u5426\u5408\u6CD5\uFF09"})),J=!0;continue}if(Q.some((_)=>typeof _!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 customKeys \u5FC5\u987B\u662F string[]\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF09"})),J=!0;continue}let U=Q.filter((_)=>!MX.includes(_));if(U.length>0){L.warn(Object.assign({},p(Y,["handler"]),{msg:`\u63D2\u4EF6\u5BFC\u51FA\u5B58\u5728\u4E0D\u652F\u6301\u7684\u5C5E\u6027\uFF1A${U.join(", ")}\uFF1B\u4EC5\u5141\u8BB8\uFF1A${MX.join(", ")}\uFF1B\u5F53\u524D customKeys\uFF1A${Q.join(", ")}`})),J=!0;continue}let z=Q.includes("enable"),O=Q.includes("deps");if(z){if(typeof X.enable!=="boolean"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 enable \u5C5E\u6027\u5FC5\u987B\u662F boolean\uFF08true/false\uFF09\uFF0C\u4E0D\u5141\u8BB8 0/1 \u7B49\u5176\u4ED6\u7C7B\u578B"})),J=!0;continue}}else X.enable=!0;if(X.source==="core"){let _=typeof X.name==="string"?X.name:"";if(_===""){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u5FC5\u987B\u663E\u5F0F\u8BBE\u7F6E name\uFF08string\uFF09\uFF0C\u7528\u4E8E\u786E\u5B9A\u63D2\u4EF6\u540D\u79F0"})),J=!0;continue}if(!Z.test(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u7684 name \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u4F8B\u5982 logger / redis_cache\uFF09\uFF0C\u4E0D\u5141\u8BB8\u7A7A\u683C\u3001\u9A7C\u5CF0\u6216\u5176\u4ED6\u5B57\u7B26"})),J=!0;continue}if(!Z.test(String(X.moduleName))){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u7684 moduleName \u5FC5\u987B\u6EE1\u8DB3\u5C0F\u5199\u5B57\u6BCD+\u4E0B\u5212\u7EBF\u683C\u5F0F\uFF08\u7531\u7CFB\u7EDF\u751F\u6210\uFF0C\u4E14\u5FC5\u987B\u4E0E name \u4E00\u81F4\uFF09"})),J=!0;continue}if(_!==String(X.moduleName)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u7684 name \u5FC5\u987B\u4E0E moduleName \u5B8C\u5168\u4E00\u81F4"})),J=!0;continue}let K=X.filePath;if(typeof K!=="string"||!K.startsWith(`core:plugin:${_}`)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"core \u5185\u7F6E\u63D2\u4EF6\u5FC5\u987B\u6765\u81EA\u9759\u6001\u6CE8\u518C\uFF08filePath \u5FC5\u987B\u4EE5 core:plugin:<name> \u5F00\u5934\uFF09\uFF0C\u4E0D\u5141\u8BB8\u901A\u8FC7\u626B\u63CF\u76EE\u5F55\u52A0\u8F7D"})),J=!0;continue}}if(O){let _=X.deps;if(!Array.isArray(_)){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}if(_.some((K)=>typeof K!=="string")){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 deps \u5C5E\u6027\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4"})),J=!0;continue}}else{let _=X.deps;if(!Array.isArray(_))X.deps=[]}if(typeof X.handler!=="function"){L.warn(Object.assign({},p(Y,["handler"]),{msg:"\u63D2\u4EF6\u7684 handler \u5C5E\u6027\u5FC5\u987B\u662F\u51FD\u6570"})),J=!0;continue}}catch(X){L.error({err:X,item:Y,msg:"\u63D2\u4EF6\u89E3\u6790\u5931\u8D25"}),J=!0}if(J)throw Error("\u63D2\u4EF6\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}$0();function a1($){if($===null)return!0;return typeof $==="string"||typeof $==="number"||typeof $==="boolean"}function e1($){if(!$||typeof $!=="object")return!1;if($ instanceof Date)return!1;if(Array.isArray($))return!1;return!0}function SZ($){if(a1($))return!0;if(Array.isArray($)){for(let J of $)if(!SZ(J))return!1;return!0}if(e1($)){for(let J of Object.values($)){if(J===void 0)continue;if(!SZ(J))return!1}return!0}return!1}function ZJ($){if($===null)return"null";if($===void 0)return"undefined";if(typeof $==="string"){let Z=$.length>80?`${$.slice(0,80)}...`:$;return JSON.stringify(Z)}if(typeof $==="number"||typeof $==="boolean"||typeof $==="bigint")return String($);if(typeof $==="function")return"[Function]";try{let Z=JSON.stringify($);if(typeof Z==="string")return Z.length>120?`${Z.slice(0,120)}...`:Z}catch{}let J=String($);return J.length>120?`${J.slice(0,120)}...`:J}var IX=["id","created_at","updated_at","deleted_at","state"],$H=new Set(IX),qX=["string","number","text","array_string","array_text","array_number_string","array_number_text"],JH=new Set(qX),LX=["name","type","min","max","default","detail","index","unique","nullable","unsigned","regexp"],ZH=new Set(LX),YH=/^_?[a-z][a-z0-9]*(?:[A-Z][a-z0-9]*)*$/,XH=/^[\u4e00-\u9fa5a-zA-Z0-9 _-]+$/,KX=16383,FX=500,RX=180;async function jX($,J){let Z=!1;for(let Y of $){if(Y.type!=="table")continue;let X=typeof Y.sourceName==="string"?Y.sourceName:"",G=X?`${X}\u8868 `:"\u8868 ";try{let Q=Y.fileName;if(Y.source==="addon"&&String(Y.addonName).trim()===""){L.warn(`${G}${Q} addon \u8868\u7F3A\u5C11 addonName`),Z=!0;continue}let U=Y.content;if(typeof U!=="object"||U===null||Array.isArray(U)){L.warn(`${G}${Q} \u8868\u5B9A\u4E49\u65E0\u6548\uFF1A\u5FC5\u987B\u4E3A\u5BF9\u8C61`),Z=!0;continue}if(!YH.test(Q)){L.warn(`${G}${Q} \u6587\u4EF6\u540D\u5FC5\u987B\u4F7F\u7528\u5C0F\u9A7C\u5CF0\u547D\u540D\uFF08\u4F8B\u5982 testCustomers.json\uFF09`),Z=!0;continue}for(let[z,O]of Object.entries(U)){if(typeof O!=="object"||O===null||Array.isArray(O)){L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u89C4\u5219\u5FC5\u987B\u4E3A\u5BF9\u8C61`),Z=!0;continue}if($H.has(z))L.warn(`${G}${Q} \u6587\u4EF6\u5305\u542B\u4FDD\u7559\u5B57\u6BB5 ${z}\uFF0C`+`\u4E0D\u80FD\u5728\u8868\u5B9A\u4E49\u4E2D\u4F7F\u7528\u4EE5\u4E0B\u5B57\u6BB5: ${IX.join(", ")}`),Z=!0;let _=O,j=Object.keys(_).filter((C)=>!ZH.has(C));if(j.length>0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5305\u542B\u975E\u6CD5\u5C5E\u6027: ${j.join(", ")}\uFF0C`+`\u5141\u8BB8\u7684\u5C5E\u6027\u4E3A: ${LX.join(", ")}`),Z=!0;if(!_.name||typeof _.name!=="string"){L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 name \u6216\u7C7B\u578B\u9519\u8BEF`),Z=!0;continue}if(!_.type||typeof _.type!=="string"){L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7F3A\u5C11\u5FC5\u586B\u5B57\u6BB5 type \u6216\u7C7B\u578B\u9519\u8BEF`),Z=!0;continue}if(_.min!==void 0&&!(_.min===null||typeof _.min==="number"))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 min \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A null \u6216\u6570\u5B57`),Z=!0;if(_.max!==void 0&&!(_.max===null||typeof _.max==="number"))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 max \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A null \u6216\u6570\u5B57`),Z=!0;if(_.detail!==void 0&&typeof _.detail!=="string")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 detail \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32`),Z=!0;if(_.index!==void 0&&typeof _.index!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 index \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.unique!==void 0&&typeof _.unique!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 unique \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.nullable!==void 0&&typeof _.nullable!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 nullable \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.unsigned!==void 0&&typeof _.unsigned!=="boolean")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 unsigned \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u5E03\u5C14\u503C`),Z=!0;if(_.regexp!==void 0&&_.regexp!==null&&typeof _.regexp!=="string")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 regexp \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A null \u6216\u5B57\u7B26\u4E32`),Z=!0;if(_.default!==void 0&&_.default!==null&&!SZ(_.default))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5 default \u7C7B\u578B\u9519\u8BEF\uFF0C\u5FC5\u987B\u4E3A\u53EF JSON \u5E8F\u5217\u5316\u7684\u503C\u6216 null`+`\uFF08typeof=${typeof _.default}\uFF0Cvalue=${ZJ(_.default)}\uFF09`),Z=!0;if(J.strict){if(!XH.test(_.name))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5\u540D\u79F0 "${_.name}" \u683C\u5F0F\u9519\u8BEF\uFF0C`+"\u5FC5\u987B\u4E3A\u4E2D\u6587\u3001\u6570\u5B57\u3001\u5B57\u6BCD\u3001\u4E0B\u5212\u7EBF\u3001\u77ED\u6A2A\u7EBF\u3001\u7A7A\u683C"),Z=!0}if(!JH.has(_.type))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5\u7C7B\u578B "${_.type}" \u683C\u5F0F\u9519\u8BEF\uFF0C`+`\u5FC5\u987B\u4E3A${qX.join("\u3001")}\u4E4B\u4E00`),Z=!0;if(_.type!=="number"&&_.unsigned!==void 0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u5B57\u6BB5\u7C7B\u578B\u4E3A ${_.type}\uFF0C\u4E0D\u5141\u8BB8\u8BBE\u7F6E unsigned\uFF08\u4EC5 number \u7C7B\u578B\u6709\u6548\uFF09`),Z=!0;if(_.unique===!0&&_.index===!0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u540C\u65F6\u8BBE\u7F6E\u4E86 unique=true \u548C index=true\uFF0C`+"unique \u548C index \u4E0D\u80FD\u540C\u65F6\u8BBE\u7F6E\uFF0C\u8BF7\u5220\u9664\u5176\u4E00\uFF08\u5426\u5219\u4F1A\u521B\u5EFA\u91CD\u590D\u7D22\u5F15\uFF09"),Z=!0;if(_.min!==void 0&&_.max!==void 0&&_.min!==null&&_.max!==null){if(_.min>_.max)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u6700\u5C0F\u503C "${_.min}" \u4E0D\u80FD\u5927\u4E8E\u6700\u5927\u503C "${_.max}"`),Z=!0}if(_.type==="text"||_.type==="array_text"||_.type==="array_number_text"){if(_.min!==void 0&&_.min!==null)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7684 ${_.type} \u7C7B\u578B\u6700\u5C0F\u503C\u5E94\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${_.min}"`),Z=!0;if(_.max!==void 0&&_.max!==null)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u7684 ${_.type} \u7C7B\u578B\u6700\u5927\u957F\u5EA6\u5E94\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${_.max}"`),Z=!0;if(_.default!==void 0&&_.default!==null)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A null\uFF0C\u5F53\u524D\u4E3A "${_.default}"`),Z=!0;if(_.index===!0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u4E0D\u652F\u6301\u521B\u5EFA\u7D22\u5F15\uFF08index=true \u65E0\u6548\uFF09`),Z=!0;if(_.unique===!0)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u4E0D\u652F\u6301\u552F\u4E00\u7EA6\u675F\uFF08unique=true \u65E0\u6548\uFF09`),Z=!0}else if(_.type==="string"||_.type==="array_string"||_.type==="array_number_string"){if(_.max===void 0||_.max===null||typeof _.max!=="number")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C`+`\u5FC5\u987B\u8BBE\u7F6E max \u4E14\u7C7B\u578B\u4E3A\u6570\u5B57\uFF1B\u5176\u4E2D array_*_string \u7684 max \u8868\u793A\u5355\u4E2A\u5143\u7D20\u957F\u5EA6\uFF0C\u5F53\u524D\u4E3A "${_.max}"`),Z=!0;else if(_.max>KX)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u6700\u5927\u957F\u5EA6 ${_.max} \u8D8A\u754C\uFF0C`+`${_.type} \u7C7B\u578B\u957F\u5EA6\u5FC5\u987B\u5728 1..${KX} \u8303\u56F4\u5185`),Z=!0;else{if(_.index===!0&&_.max>FX)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u8BBE\u7F6E\u4E86 index=true\uFF0C`+`\u4F46 max=${_.max} \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u8981\u6C42 <= ${FX}\uFF09`),Z=!0;if(_.unique===!0&&_.max>RX)L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u8BBE\u7F6E\u4E86 unique=true\uFF0C`+`\u4F46 max=${_.max} \u8D85\u51FA\u5141\u8BB8\u8303\u56F4\uFF08\u8981\u6C42 <= ${RX}\uFF09`),Z=!0}if(_.default!==void 0&&_.default!==null){if(typeof _.default!=="string")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A\u5B57\u7B26\u4E32\u6216 null`+`\uFF08typeof=${typeof _.default}\uFF0Cvalue=${ZJ(_.default)}\uFF09`),Z=!0;else if(_.type!=="string")try{let C=JSON.parse(_.default);if(!Array.isArray(C))L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5E94\u4E3A JSON \u6570\u7EC4\u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 "[]"\uFF09`+`\uFF08value=${ZJ(_.default)}\uFF09`),Z=!0}catch{L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A ${_.type} \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5E94\u4E3A JSON \u6570\u7EC4\u5B57\u7B26\u4E32\uFF08\u4F8B\u5982 "[]"\uFF09`+`\uFF08value=${ZJ(_.default)}\uFF09`),Z=!0}}}else if(_.type==="number"){if(_.default!==void 0&&_.default!==null&&typeof _.default!=="number")L.warn(`${G}${Q} \u6587\u4EF6 ${z} \u4E3A number \u7C7B\u578B\uFF0C\u9ED8\u8BA4\u503C\u5FC5\u987B\u4E3A\u6570\u5B57\u6216 null`+`\uFF08typeof=${typeof _.default}\uFF0Cvalue=${ZJ(_.default)}\uFF09`),Z=!0}}}catch(Q){L.error({msg:`${G}${Y.fileName} \u89E3\u6790\u5931\u8D25`,err:Q}),Z=!0}}if(Z)throw Error("\u8868\u7ED3\u6784\u68C0\u67E5\u5931\u8D25")}$0();var{SQL:GH,RedisClient:QH}=globalThis.Bun;class _${static sqlClient=null;static redisClient=null;static sqlConnectedAt=null;static redisConnectedAt=null;static sqlPoolMax=1;static mysqlVersionText=null;static mysqlVersionMajor=null;static async connectSql($){let J=$||{},Z=typeof J.host==="string"?J.host.trim():"",Y=typeof J.port==="number"?J.port:NaN,X=typeof J.username==="string"?J.username.trim():"",G=J.password===void 0?"":typeof J.password==="string"?J.password:"",Q=typeof J.database==="string"?J.database.trim():"";if(!Z)throw Error("\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.host \u7F3A\u5931");if(!Number.isFinite(Y)||Y<1||Y>65535)throw Error(`\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.port \u975E\u6CD5\uFF08\u5F53\u524D\u503C\uFF1A${String(J.port)}\uFF09`);if(!X)throw Error("\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.username \u7F3A\u5931");if(!Q)throw Error("\u6570\u636E\u5E93\u914D\u7F6E\u4E0D\u5B8C\u6574\uFF1Adb.database \u7F3A\u5931");let U=encodeURIComponent(X),z=encodeURIComponent(G),O=encodeURIComponent(Q),_=`mysql://${U}:${z}@${Z}:${Y}/${O}`,K=new GH({url:_,max:J.poolMax??1,bigint:!1});try{let C=(async()=>{let v=await K`SELECT VERSION() AS version`,T=typeof v?.[0]?.version==="string"?v?.[0]?.version:String(v?.[0]?.version||""),k=T.split(".")[0],E=Number(k);if(!Number.isFinite(E))throw Error(`\u65E0\u6CD5\u89E3\u6790 MySQL \u7248\u672C\u4FE1\u606F: ${T}`);if(E<8)throw Error(`\u4EC5\u652F\u6301 MySQL 8.0+\uFF0C\u5F53\u524D\u7248\u672C\uFF1A${T}`);return this.mysqlVersionText=T,this.mysqlVersionMajor=E,T})(),S=new Promise((v,T)=>{setTimeout(()=>{T(Error(`\u6570\u636E\u5E93\u8FDE\u63A5\u8D85\u65F6 (${30000}ms)`))},30000)});return await Promise.race([C,S]),this.sqlClient=K,this.sqlConnectedAt=Date.now(),this.sqlPoolMax=J.poolMax??1,K}catch(j){L.error({err:j,msg:"[Connect] SQL \u8FDE\u63A5\u5931\u8D25"});try{await K?.close()}catch{}throw j}}static async disconnectSql(){if(this.sqlClient){try{await this.sqlClient.close()}catch($){L.error({err:$,msg:"[Connect] \u5173\u95ED SQL \u8FDE\u63A5\u65F6\u51FA\u9519"})}this.sqlClient=null,this.sqlConnectedAt=null}}static getSql(){if(!this.sqlClient)throw Error("SQL \u5BA2\u6237\u7AEF\u672A\u8FDE\u63A5\uFF0C\u8BF7\u5148\u8C03\u7528 Connect.connectSql()");return this.sqlClient}static async connectRedis($){let J=$||{};try{let Z=J.host||"127.0.0.1",Y=J.port||6379,X=J.username||"",G=J.password||"",Q=J.db||0,U="",z=X?encodeURIComponent(X):"",O=G?encodeURIComponent(G):"";if(z&&O)U=`${z}:${O}@`;else if(O)U=`:${O}@`;let _=`redis://${U}${Z}:${Y}/${Q}`,K=new QH(_,{connectionTimeout:30000,idleTimeout:0,autoReconnect:!0,maxRetries:3,enableOfflineQueue:!0,enableAutoPipelining:!0});return await K.ping(),this.redisClient=K,this.redisConnectedAt=Date.now(),K}catch(Z){throw L.error({err:Z,msg:"[Connect] Redis \u8FDE\u63A5\u5931\u8D25"}),Error(`Redis \u8FDE\u63A5\u5931\u8D25: ${Z.message}`)}}static async disconnectRedis(){if(this.redisClient){try{this.redisClient.close(),this.redisConnectedAt=null}catch($){L.error({err:$,msg:"[Connect] \u5173\u95ED Redis \u8FDE\u63A5\u65F6\u51FA\u9519"})}this.redisClient=null}}static getRedis(){if(!this.redisClient)throw Error("Redis \u5BA2\u6237\u7AEF\u672A\u8FDE\u63A5\uFF0C\u8BF7\u5148\u8C03\u7528 Connect.connectRedis()");return this.redisClient}static async connect($){try{await this.connectSql($.db||{}),await this.connectRedis($.redis||{})}catch(J){let Z=typeof process?.env?.NODE_ENV==="string"?"development":"";throw L.error({env:Z,err:J,msg:"\u6570\u636E\u5E93\u8FDE\u63A5\u521D\u59CB\u5316\u5931\u8D25"}),await this.disconnect(),J}}static async disconnect(){await this.disconnectSql(),await this.disconnectRedis()}static isConnected(){return{sql:this.sqlClient!==null,redis:this.redisClient!==null}}static getStatus(){let $=Date.now();return{sql:{connected:this.sqlClient!==null,connectedAt:this.sqlConnectedAt,uptime:this.sqlConnectedAt?$-this.sqlConnectedAt:null,poolMax:this.sqlPoolMax,mysqlVersionText:this.mysqlVersionText,mysqlVersionMajor:this.mysqlVersionMajor},redis:{connected:this.redisClient!==null,connectedAt:this.redisConnectedAt,uptime:this.redisConnectedAt?$-this.redisConnectedAt:null}}}static __setMockSql($){this.sqlClient=$}static __setMockRedis($){this.redisClient=$}static __reset(){this.sqlClient=null,this.redisClient=null,this.sqlConnectedAt=null,this.redisConnectedAt=null,this.sqlPoolMax=1,this.mysqlVersionText=null,this.mysqlVersionMajor=null}}$0();$0();async function BX($){let J=new Map;for(let Z of $)try{if(Object.hasOwn(Z,"type")&&Z.type!=="api")continue;let Y=Z,X=Y.path,G={name:Y.name,handler:Y.handler,route:X},Q=Y.method;if(typeof Q==="string"){let K=Q.toUpperCase(),j=K==="POST,GET"?"GET,POST":K;G.method=["GET","POST","GET,POST"].includes(j)?j:"POST"}else G.method="POST";let U=Y.auth;if(U!==void 0)G.auth=U;let z=Y.fields;if(z!==void 0)G.fields=z;let O=Y.required;if(O!==void 0)G.required=O;let _=Y.rawBody;if(_!==void 0)G.rawBody=_;J.set(X,G)}catch(Y){throw L.error({err:Y,api:Z.relativePath,file:Z.filePath,msg:"\u63A5\u53E3\u52A0\u8F7D\u5931\u8D25"}),Y}return J}$0();m0();function RJ($,J={}){let Z=J.moduleLabel||"\u6A21\u5757",Y=J.getName||((K)=>{let j=K.moduleName;if(typeof j==="string"&&j.trim()!=="")return j;return F$(K.fileName)}),X=J.getDeps||((K)=>{let j=K.deps;if(!Array.isArray(j))return[];return j.filter((C)=>typeof C==="string")}),G=[],Q=new Set,U=new Set,z={},O=!0;for(let K of $){let j=Y(K);if(typeof j!=="string"||j.trim()===""){L.error({item:K,msg:`${Z} \u540D\u79F0\u89E3\u6790\u5931\u8D25\uFF08getName \u8FD4\u56DE\u7A7A\u5B57\u7B26\u4E32\uFF09`}),O=!1;continue}if(z[j]){L.error({name:j,first:z[j],second:K,msg:`${Z} \u540D\u79F0\u91CD\u590D\uFF0C\u65E0\u6CD5\u6839\u636E deps \u552F\u4E00\u5B9A\u4F4D`}),O=!1;continue}z[j]=K}if(!O)return!1;for(let K of $){let j=Y(K),C=X(K);if(!Array.isArray(C)){L.error({module:j,item:K,msg:`${Z} \u7684 deps \u5FC5\u987B\u662F\u6570\u7EC4`}),O=!1;continue}for(let S of C){if(typeof S!=="string"){L.error({module:j,dependency:S,item:K,msg:`${Z} \u7684 deps \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4`}),O=!1;continue}if(!z[S])L.error({module:j,dependency:S,msg:`${Z} \u4F9D\u8D56\u672A\u627E\u5230`}),O=!1}}if(!O)return!1;let _=(K)=>{if(Q.has(K))return;if(U.has(K)){L.error({module:K,msg:`${Z} \u5FAA\u73AF\u4F9D\u8D56`}),O=!1;return}let j=z[K];if(!j)return;let C=X(j);U.add(K);for(let S of C)_(S);U.delete(K),Q.add(K),G.push(j)};for(let K of $){let j=Y(K);_(j)}return O?G:!1}async function PX($){let J=[],Z=$.filter((X)=>{let G=X.moduleName;if(typeof G!=="string"||G.trim()==="")return!1;if((Object.hasOwn(X,"enable")?X.enable:void 0)===!1)return!1;return!0}),Y=RJ(Z,{moduleLabel:"\u94A9\u5B50"});if(Y===!1)throw Error("\u94A9\u5B50\u4F9D\u8D56\u5173\u7CFB\u9519\u8BEF");for(let X of Y){let G=X.moduleName,Q=Object.hasOwn(X,"deps")?X.deps:void 0,U=Array.isArray(Q)?Q.filter((_)=>typeof _==="string"):[],z=Object.hasOwn(X,"handler")?X.handler:void 0;if(typeof z!=="function")throw Error(`Hook '${G}' handler \u5FC5\u987B\u662F\u51FD\u6570`);let O=z;J.push({name:G,enable:!0,deps:U,handler:O})}return J}$0();async function EX($,J){let Z=[],Y=$.filter((G)=>{let Q=G.moduleName;if(typeof Q!=="string"||Q.trim()==="")return!1;if((Object.hasOwn(G,"enable")?G.enable:void 0)===!1)return!1;return!0}),X=RJ(Y,{moduleLabel:"\u63D2\u4EF6"});if(X===!1)throw Error("\u63D2\u4EF6\u4F9D\u8D56\u5173\u7CFB\u9519\u8BEF");for(let G of X){let Q=G.moduleName,U=Object.hasOwn(G,"deps")?G.deps:void 0,z=Array.isArray(U)?U.filter((K)=>typeof K==="string"):[],O=Object.hasOwn(G,"handler")?G.handler:void 0;if(typeof O!=="function")throw Error(`\u63D2\u4EF6 '${Q}' handler \u5FC5\u987B\u662F\u51FD\u6570`);let _=O;try{let K=await _(J);J[Q]=K,Z.push({name:Q,enable:!0,deps:z,handler:_})}catch(K){throw L.error({err:K,plugin:Q,msg:"\u63D2\u4EF6\u521D\u59CB\u5316\u5931\u8D25"}),K}}return Z}zJ();$0();function CX($,J){let Z=$.headers.get("x-forwarded-for");if(typeof Z==="string"&&Z.trim()){let U=Z.split(",")[0];if(typeof U==="string"&&U.trim())return U.trim()}let Y=$.headers.get("x-real-ip");if(typeof Y==="string"&&Y.trim())return Y.trim();let X=$.headers.get("cf-connecting-ip");if(typeof X==="string"&&X.trim())return X.trim();let G=$.headers.get("x-client-ip");if(typeof G==="string"&&G.trim())return G.trim();let Q=$.headers.get("true-client-ip");if(typeof Q==="string"&&Q.trim())return Q.trim();if(J&&typeof J.requestIP==="function"){let U=J.requestIP($);if(U&&typeof U.address==="string"&&U.address.trim())return U.address.trim()}return"unknown"}$0();function j$($,J,Z=1,Y=null,X=null,G=null){if($.requestId)L.info({event:"request_blocked",reason:J,reasonCode:G,code:Z,detail:X,msg:"request blocked"});return Response.json({code:Z,msg:J,data:Y,detail:X},{headers:$.corsHeaders})}function wZ($){if($.api&&$.requestId)L.info({event:"request_done",msg:"request done"});if($.response)return $.response;if($.result!==void 0){let J=$.result;if(typeof J==="string")J={code:0,msg:J};else if(J&&typeof J==="object"){if(!("code"in J))J={code:0,...J}}if(J&&typeof J==="object"){let Z=JSON.stringify(J,(Y,X)=>typeof X==="bigint"?X.toString():X);return new Response(Z,{headers:{...$.corsHeaders,"Content-Type":"application/json"}})}else return Response.json(J,{headers:$.corsHeaders})}return Response.json({code:1,msg:"\u672A\u751F\u6210\u54CD\u5E94"},{headers:$.corsHeaders})}m0();function SX($,J,Z){return async(Y,X)=>{let G=cY(),U=new URL(Y.url).pathname||"/",z=CX(Y,X),O=Date.now(),_={method:Y.method,body:{},user:{},req:Y,now:O,ip:z,headers:Y.headers,route:U,requestId:G,corsHeaders:{"X-Request-ID":G}},K=$.get(U);if(K)_.api=K;return mY({requestId:G,method:Y.method,route:U,ip:z,now:O},async()=>{try{for(let j of J)if(await j.handler(Z,_),_.response)return _.response;if(_.api&&Y.method!=="OPTIONS"){let j={event:"request",apiName:_.api.name};if(_.body&&Object.keys(_.body).length>0)j.body=_.body;j.msg="request",L.info(j)}if(!_.api){if(Y.method!=="OPTIONS")_.response=Response.json({code:1,msg:"\u63A5\u53E3\u4E0D\u5B58\u5728"},{headers:_.corsHeaders})}else if(_.api.handler){let j=await _.api.handler(Z,_);if(j instanceof Response)_.response=j;else _.result=j}return wZ(_)}catch(j){let C=_.api?U:Y.url;return L.error({err:j,path:C,msg:"\u8BF7\u6C42\u9519\u8BEF"}),_.result={code:1,msg:"\u5185\u90E8\u670D\u52A1\u9519\u8BEF"},wZ(_)}})}}L$();$0();L$();import{fileURLToPath as HH}from"url";var WH=HH(import.meta.url),B$=KJ(WH);var F4=w$(B$).endsWith("/dist")?B$:s(B$,"dist"),R4=s(B$,"checks"),I4=s(B$,"plugins"),q4=s(B$,"hooks"),L4=s(B$,"apis"),j4=s(B$,"tables"),d0=process.cwd(),B4=s(d0,"checks"),P4=s(d0,"plugins"),E4=s(d0,"hooks"),C4=s(d0,"apis"),S4=s(d0,"tables"),wX=s(d0,"addons");function IJ($,J={}){let Z=J.origin||"*";return{"Access-Control-Allow-Origin":Z==="*"?$.headers.get("origin")||"*":Z,"Access-Control-Allow-Methods":J.methods||"GET, POST, PUT, DELETE, OPTIONS","Access-Control-Allow-Headers":J.allowedHeaders||"Content-Type, Authorization, authorization, token","Access-Control-Expose-Headers":J.exposedHeaders||"Content-Range, X-Content-Range, Authorization, authorization, token","Access-Control-Max-Age":String(J.maxAge||86400),"Access-Control-Allow-Credentials":J.credentials||"true"}}function TX($=void 0){return async(J)=>{let Z=IJ(J,$),Y=new URL(J.url),X=s(d0,"public",Y.pathname);try{if(J.method==="OPTIONS")return new Response(null,{status:204,headers:Z});let G=Bun.file(X);if(await G.exists())return new Response(G,{headers:{"Content-Type":G.type||"application/octet-stream",...Z}});else return Response.json({code:1,msg:"\u6587\u4EF6\u672A\u627E\u5230"},{headers:Z})}catch(G){return L.error({err:G,msg:"\u9759\u6001\u6587\u4EF6\u5904\u7406\u5931\u8D25"}),Response.json({code:1,msg:"\u6587\u4EF6\u8BFB\u53D6\u5931\u8D25"},{headers:Z})}}}$0();m0();var UH=($)=>{let J=$.split("/").map((G)=>G.trim()).filter((G)=>G.length>0),Y=(J[1]||"")==="addon"?4:3,X=J.slice(0,Math.min(Y,J.length));if(X.length===0)return"";return`/${X.join("/")}`};async function NX($,J){if(!$.db)throw Error("\u540C\u6B65\u63A5\u53E3\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.cache)throw Error("\u540C\u6B65\u63A5\u53E3\uFF1Actx.cache \u672A\u521D\u59CB\u5316");if(!(await $.db.tableExists("addon_admin_api")).data){L.debug(`${"addon_admin_api"} \u8868\u4E0D\u5B58\u5728`);return}let X=(await $.db.getAll({table:"addon_admin_api",fields:["id","path","parentPath","name","addonName","auth","state"],where:{state$gte:0}})).data.lists||[],G=bY(X,(_)=>_.path),Q=[],U=[],z=[],O=new Set;for(let _ of J){if(_.type!=="api")continue;let K=_,j=K.path,C=K.name,S=K.addonName;if(typeof j!=="string"||j.trim()==="")continue;if(typeof C!=="string"||C.trim()==="")continue;let v=typeof S==="string"?S:"",T=K.auth,k=T===!1||T===0?0:1,E=UH(j);O.add(j);let w=G[j];if(w){if(C!==w.name||j!==w.path||v!==w.addonName||E!==w.parentPath||k!==w.auth)U.push({id:w.id,name:C,path:j,parentPath:E,addonName:v,auth:k})}else Q.push({name:C,path:j,parentPath:E,addonName:v,auth:k})}for(let _ of X)if(!O.has(_.path))z.push(_.id);if(U.length>0)try{await $.db.updBatch("addon_admin_api",U.map((_)=>{return{id:_.id,data:{name:_.name,path:_.path,parentPath:_.parentPath,addonName:_.addonName,auth:_.auth}}}))}catch(_){L.error({err:_,msg:"\u540C\u6B65\u63A5\u53E3\u6279\u91CF\u66F4\u65B0\u5931\u8D25"})}if(Q.length>0)try{await $.db.insBatch("addon_admin_api",Q.map((_)=>{return{name:_.name,path:_.path,parentPath:_.parentPath,addonName:_.addonName,auth:_.auth}}))}catch(_){L.error({err:_,msg:"\u540C\u6B65\u63A5\u53E3\u6279\u91CF\u65B0\u589E\u5931\u8D25"})}if(z.length>0)try{await $.db.delForceBatch("addon_admin_api",z)}catch(_){L.error({err:_,msg:"\u540C\u6B65\u63A5\u53E3\u6279\u91CF\u5220\u9664\u5931\u8D25"})}}async function DX($){if(!$.cache)throw Error("\u540C\u6B65\u7F13\u5B58\uFF1Actx.cache \u672A\u521D\u59CB\u5316");await $.cache.cacheApis(),await $.cache.cacheMenus(),await $.cache.rebuildRoleApiPermissions()}import{createSign as VH}from"crypto";class g${static md5($,J="hex"){let Z=new Bun.CryptoHasher("md5");return Z.update($),Z.digest(J)}static hmacMd5($,J,Z="hex"){let Y=new Bun.CryptoHasher("md5",$);return Y.update(J),Y.digest(Z)}static sha1($,J="hex"){let Z=new Bun.CryptoHasher("sha1");return Z.update($),Z.digest(J)}static hmacSha1($,J,Z="hex"){let Y=new Bun.CryptoHasher("sha1",$);return Y.update(J),Y.digest(Z)}static sha256($,J="hex"){let Z=new Bun.CryptoHasher("sha256");return Z.update($),Z.digest(J)}static rsaSha256($,J,Z="hex"){let Y=VH("RSA-SHA256");return Y.update($),Y.sign(J,Z)}static hmacSha256($,J,Z="hex"){let Y=new Bun.CryptoHasher("sha256",$);return Y.update(J),Y.digest(Z)}static sha512($,J="hex"){let Z=new Bun.CryptoHasher("sha512");return Z.update($),Z.digest(J)}static hmacSha512($,J,Z="hex"){let Y=new Bun.CryptoHasher("sha512",$);return Y.update(J),Y.digest(Z)}static hash($,J,Z="hex"){let Y=new Bun.CryptoHasher($);return Y.update(J),Y.digest(Z)}static hmac($,J,Z,Y="hex"){let X=new Bun.CryptoHasher($,J);return X.update(Z),X.digest(Y)}static async hashFile($,J="sha256",Z="hex"){let Y=Bun.file($),X=new Bun.CryptoHasher(J),Q=Y.stream().getReader();try{while(!0){let{done:U,value:z}=await Q.read();if(U)break;X.update(z)}return X.digest(Z)}finally{Q.releaseLock()}}static async hashPassword($,J={}){let Z=Object.assign({},J,{algorithm:"bcrypt"});return await Bun.password.hash($,Z)}static async verifyPassword($,J){return await Bun.password.verify($,J)}static base64Encode($){return Buffer.from($,"utf8").toString("base64")}static base64Decode($){return Buffer.from($,"base64").toString("utf8")}static randomString($){let J=Math.ceil($/2),Z=crypto.getRandomValues(new Uint8Array(J)),Y="";for(let X=0;X<Z.length;X++)Y+=Z[X].toString(16).padStart(2,"0");return Y.slice(0,$)}static fastHash($,J=0){let Z=Bun.hash($,J);return typeof Z==="bigint"?Number(Z):Z}}$0();async function vX($,J={}){if(!J.devPassword)return;if(!$.db)throw Error("\u540C\u6B65\u5F00\u53D1\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.cache)throw Error("\u540C\u6B65\u5F00\u53D1\uFF1Actx.cache \u672A\u521D\u59CB\u5316");if(!(await $.db.tableExists("addon_admin_admin")).data){L.debug("addon_admin_admin \u8868\u4E0D\u5B58\u5728");return}if(!(await $.db.tableExists("addon_admin_role")).data){L.debug("addon_admin_role \u8868\u4E0D\u5B58\u5728");return}if(!(await $.db.tableExists("addon_admin_menu")).data){L.debug("addon_admin_menu \u8868\u4E0D\u5B58\u5728");return}if(!(await $.db.tableExists("addon_admin_api")).data){L.debug("addon_admin_api \u8868\u4E0D\u5B58\u5728");return}let Z=await $.db.getAll({table:"addon_admin_menu",fields:["path"],where:{state$gte:0},orderBy:["id#ASC"]}),Y=await $.db.getAll({table:"addon_admin_api",fields:["path"],where:{state$gte:0},orderBy:["id#ASC"]}),X=await $.db.getOne({table:"addon_admin_role",where:{code:"dev"}}),G={code:"dev",name:"\u5F00\u53D1\u8005\u89D2\u8272",description:"\u62E5\u6709\u6240\u6709\u83DC\u5355\u548C\u63A5\u53E3\u6743\u9650\u7684\u5F00\u53D1\u8005\u89D2\u8272",menus:Z.data.lists.map((O)=>O.path).filter((O)=>typeof O==="string"&&O.length>0),apis:Y.data.lists.map((O)=>O.path).filter((O)=>typeof O==="string"&&O.length>0),sort:0};if(typeof X.data.id==="number")await $.db.updData({table:"addon_admin_role",where:{code:"dev"},data:{name:G.name,description:G.description,menus:G.menus,apis:G.apis,sort:G.sort}});else await $.db.insData({table:"addon_admin_role",data:G});let Q={nickname:"\u5F00\u53D1\u8005",email:J.devEmail||"dev@qq.com",username:"dev",password:await g$.hashPassword(g$.sha256(J.devPassword+"befly")),roleCode:"dev",roleType:"admin"};if(typeof(await $.db.getOne({table:"addon_admin_admin",where:{username:"dev"}})).data.id==="number")await $.db.updData({table:"addon_admin_admin",where:{username:"dev"},data:{nickname:Q.nickname,email:Q.email,username:Q.username,password:Q.password,roleCode:Q.roleCode,roleType:Q.roleType}});else await $.db.insData({table:"addon_admin_admin",data:Q});let z=[{code:"user",name:"\u7528\u6237\u89D2\u8272",description:"\u666E\u901A\u7528\u6237\u89D2\u8272",sort:1},{code:"admin",name:"\u7BA1\u7406\u5458\u89D2\u8272",description:"\u7BA1\u7406\u5458\u89D2\u8272",sort:2},{code:"guest",name:"\u8BBF\u5BA2\u89D2\u8272",description:"\u8BBF\u5BA2\u89D2\u8272",sort:3}];for(let O of z)if((await $.db.getOne({table:"addon_admin_role",where:{code:O.code}})).data?.id)await $.db.updData({table:"addon_admin_role",where:{code:O.code},data:{name:O.name,description:O.description,sort:O.sort}});else await $.db.insData({table:"addon_admin_role",data:{code:O.code,name:O.name,description:O.description,menus:[],apis:[],sort:O.sort}})}$0();CZ();function zH($){let J=$.config?.disableMenus,Z=Array.isArray(J)?J:[],Y=[];for(let G of Z){if(typeof G!=="string")continue;let Q=G.trim();if(!Q)continue;Y.push(Q)}if(Y.length===0)return()=>!1;let X=Y.map((G)=>new Bun.Glob(G));return(G)=>{if(typeof G!=="string")return!1;let Q=G.trim();if(!Q)return!1;let U=[];if(U.push(Q),Q.startsWith("/"))U.push(Q.slice(1));else U.push(`/${Q}`);for(let z of X){let O=typeof z==="object"&&z!==null&&"match"in z?z.match:void 0;if(typeof O!=="function")throw Error("\u540C\u6B65\u83DC\u5355\uFF1A\u5F53\u524D Bun \u7248\u672C\u4E0D\u652F\u6301 Bun.Glob.match\uFF0C\u65E0\u6CD5\u6309 disableMenus \u505A glob \u5339\u914D");let _=O;for(let K of U)if(_.call(z,K))return!0}return!1}}function kX($,J){let Z=[];for(let Y of $){if(Y===null||typeof Y!=="object")continue;let X=typeof Y.path==="string"?String(Y.path).trim():"";if(X&&J(X))continue;let G=Y.children,Q=Array.isArray(G)&&G.length>0?kX(G,J):[],U={};if(typeof Y.name==="string")U.name=Y.name;if(typeof Y.path==="string")U.path=Y.path;if(typeof Y.sort==="number")U.sort=Y.sort;if(typeof Y.parentPath==="string")U.parentPath=Y.parentPath;if(Q.length>0)U.children=Q;Z.push(U)}return Z}function _H($){let J=new Map,Z=[];for(let Y of $)Z.push({menu:Y,parentPathFromTree:""});while(Z.length>0){let Y=Z.pop(),X=Y?Y.menu:null;if(!X)continue;let G=typeof X.path==="string"?X.path:"",Q=X.children;if(Q&&Array.isArray(Q)&&Q.length>0){let K=typeof G==="string"?G:"";for(let j of Q)Z.push({menu:j,parentPathFromTree:K})}if(!G)continue;let U=typeof X.name==="string"?X.name:"";if(!U)continue;let z=typeof X.sort==="number"?X.sort:999999,_=typeof X.parentPath==="string"?X.parentPath:typeof Y?.parentPathFromTree==="string"?Y.parentPathFromTree:zX(G);J.set(G,{path:G,name:U,sort:z,parentPath:_})}return J}async function xX($,J){if(!$.db)throw Error("\u540C\u6B65\u83DC\u5355\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.cache)throw Error("\u540C\u6B65\u83DC\u5355\uFF1Actx.cache \u672A\u521D\u59CB\u5316");if(!$.config)throw Error("\u540C\u6B65\u83DC\u5355\uFF1Actx.config \u672A\u521D\u59CB\u5316");if(!(await $.db.tableExists("addon_admin_menu")).data){L.debug("addon_admin_menu \u8868\u4E0D\u5B58\u5728");return}let Z=zH($),Y=kX(J,Z),X=_H(Y),G=new Set;for(let U of X.keys())G.add(U);let Q="addon_admin_menu";await $.db.trans(async(U)=>{let O=(await U.getAll({table:Q,fields:["id","name","path","parentPath","sort","state"]})).data.lists||[],_=O.filter((E)=>typeof E?.state==="number"&&E.state>=0),K=new Map,j=new Set,C=new Map;for(let E of _){if(typeof E?.path!=="string"||!E.path)continue;if(typeof E?.id!=="number")continue;if(Z(E.path))continue;let w=K.get(E.path);if(!w){K.set(E.path,E);continue}let f=typeof w?.id==="number"?w.id:0,D=E.id;if(D>f){if(K.set(E.path,E),f>0)j.add(f);let m=C.get(E.path)||{keptId:D,removedIds:[]};if(m.keptId=D,f>0)m.removedIds.push(f);C.set(E.path,m)}else{if(D>0)j.add(D);let m=C.get(E.path)||{keptId:f,removedIds:[]};if(m.keptId=f,D>0)m.removedIds.push(D);C.set(E.path,m)}}if(C.size>0){let E=[];for(let w of C.entries()){let f=w[0],D=w[1];if(E.push({path:f,keptId:D.keptId,removedIds:D.removedIds}),E.length>=10)break}L.warn({table:Q,duplicatePaths:C.size,duplicateIds:j.size,examples:E,msg:"addon_admin_menu \u68C0\u6D4B\u5230\u91CD\u590D path \u8BB0\u5F55\uFF1A\u5DF2\u4FDD\u7559 id \u6700\u5927\u7684\u4E00\u6761\u5E76\u5220\u9664\u5176\u4F59\u8BB0\u5F55"})}let S=[],v=[];for(let E of X.values()){let w=K.get(E.path);if(w){let f=typeof w.parentPath==="string"?w.parentPath:"";if(w.name!==E.name||w.sort!==E.sort||f!==E.parentPath)S.push({id:w.id,data:{name:E.name,path:E.path,parentPath:E.parentPath,sort:E.sort}})}else v.push({name:E.name,path:E.path,parentPath:E.parentPath,sort:E.sort})}if(S.length>0)await U.updBatch(Q,S);if(v.length>0)await U.insBatch(Q,v);let T=new Set;for(let E of _){if(typeof E?.path!=="string"||!E.path)continue;if(!G.has(E.path)){if(typeof E?.id==="number")T.add(E.id)}}for(let E of j)if(typeof E==="number"&&E>0)T.add(E);for(let E of O){if(typeof E?.path!=="string"||!E.path)continue;if(!Z(E.path))continue;if(typeof E?.id==="number"&&E.id>0)T.add(E.id)}let k=Array.from(T);if(k.length>0)await U.delForceBatch(Q,k)})}$0();function H$($){return{name:$.name,type:$.type,detail:$.detail??"",min:$.min??null,max:$.max??null,default:$.default??null,index:$.index??!1,unique:$.unique??!1,nullable:$.nullable??!1,unsigned:$.unsigned??!1,regexp:$.regexp??null}}function qJ($){return String($).replace(/"/g,"\\\"")}function NZ($){if($===null)return null;if(typeof $==="string"||typeof $==="number"||typeof $==="boolean")return $;if(Array.isArray($)){let J=[];for(let Z of $)J.push(NZ(Z));return J}return String($)}function OH($){if($===null)return!0;return typeof $==="string"||typeof $==="number"||typeof $==="boolean"}function MH($){if(!$||typeof $!=="object")return!1;if($ instanceof Date)return!1;if(Array.isArray($))return!1;return!0}function TZ($){if(OH($))return $;if(Array.isArray($)){let J=[];for(let Z of $){let Y=TZ(Z);if(Y===null)return null;J.push(Y)}return J}if(MH($)){let J={};for(let[Z,Y]of Object.entries($)){if(Y===void 0)continue;let X=TZ(Y);if(X===null)return null;J[Z]=X}return J}return null}function fX($){if(!Array.isArray($))return[];let J=[];for(let Z of $){if(Z===null){J.push(null);continue}if(typeof Z==="string"||typeof Z==="number"||typeof Z==="boolean"){J.push(Z);continue}if(typeof Z==="bigint"){J.push(String(Z));continue}if(Z instanceof Date){J.push(Z);continue}let Y=TZ(Z);if(Y!==null){J.push(Y);continue}J.push(String(Z))}return J}function P$($){if(typeof $==="number")return $;if(typeof $==="bigint")return Number($);return 0}m0();class N{static DB_VERSION_REQUIREMENTS={MYSQL_MIN_MAJOR:8};static CHANGE_TYPE_LABELS={length:"\u957F\u5EA6",datatype:"\u7C7B\u578B",comment:"\u6CE8\u91CA",default:"\u9ED8\u8BA4\u503C",nullable:"\u53EF\u7A7A\u7EA6\u675F",unique:"\u552F\u4E00\u7EA6\u675F"};static MYSQL_TABLE_CONFIG={ENGINE:"InnoDB",CHARSET:"utf8mb4",COLLATE:"utf8mb4_0900_ai_ci"};static SYSTEM_FIELDS=[{name:"id",comment:"\u4E3B\u952EID",needsIndex:!1,mysqlDdl:"BIGINT UNSIGNED PRIMARY KEY AUTO_INCREMENT"},{name:"created_at",comment:"\u521B\u5EFA\u65F6\u95F4",needsIndex:!0,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 0"},{name:"updated_at",comment:"\u66F4\u65B0\u65F6\u95F4",needsIndex:!0,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 0"},{name:"deleted_at",comment:"\u5220\u9664\u65F6\u95F4",needsIndex:!1,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 0"},{name:"state",comment:"\u72B6\u6001\u5B57\u6BB5",needsIndex:!0,mysqlDdl:"BIGINT UNSIGNED NOT NULL DEFAULT 1"}];static SYSTEM_INDEX_FIELDS=["created_at","updated_at","state"];db;dbName;constructor($){if(!$?.db)throw Error("\u540C\u6B65\u8868\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.config)throw Error("\u540C\u6B65\u8868\uFF1Actx.config \u672A\u521D\u59CB\u5316");this.dbName=String($.config.db?.database||""),this.db=$.db}async run($){try{if(!Array.isArray($))throw Error("\u540C\u6B65\u8868\uFF1A\u8BF7\u4F20\u5165\u591A\u4E2A\u8868\u5B9A\u4E49\u7EC4\u6210\u7684\u6570\u7EC4");await N.ensureDbVersion(this.db);for(let J of $){if(!J||J.type!=="table")continue;let Z=J.source==="addon"?`addon_${c(J.addonName)}_${c(J.fileName)}`:c(J.fileName),Y=J.content;for(let G of Object.values(Y))N.normalizeFieldDefinitionInPlace(G);if(await N.tableExists(this.db,this.dbName,Z))await N.modifyTable(this.db,this.dbName,Z,Y);else await N.createTable(this.db,Z,Y)}}catch(J){throw L.error({err:J,msg:"\u6570\u636E\u5E93\u540C\u6B65\u5931\u8D25"}),J}}static buildRuntimeIoError($,J,Z){let Y=String(Z?.message||Z),X=Error(`\u540C\u6B65\u8868\uFF1A\u8BFB\u53D6\u5143\u4FE1\u606F\u5931\u8D25\uFF0C\u64CD\u4F5C=${$}\uFF0C\u8868=${J}\uFF0C\u9519\u8BEF=${Y}`);if(Z?.sqlInfo)X.sqlInfo=Z.sqlInfo;return X}static getTypeMapping(){return{number:"BIGINT",string:"VARCHAR",text:"MEDIUMTEXT",array_string:"VARCHAR",array_text:"MEDIUMTEXT",array_number_string:"VARCHAR",array_number_text:"MEDIUMTEXT"}}static normalizeFieldDefinitionInPlace($){let J=H$($);$.detail=J.detail,$.min=J.min,$.max=J.max,$.default=J.default,$.index=J.index,$.unique=J.unique,$.nullable=J.nullable,$.unsigned=J.unsigned,$.regexp=J.regexp}static isStringOrArrayType($){return $==="string"||$==="array_string"||$==="array_number_string"}static quoteIdentifier($){if(typeof $!=="string")throw Error(`quoteIdentifier \u9700\u8981\u5B57\u7B26\u4E32\u7C7B\u578B\u6807\u8BC6\u7B26 (identifier: ${String($)})`);let J=$.trim();if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(J))throw Error(`\u65E0\u6548\u7684 SQL \u6807\u8BC6\u7B26: ${J}`);return`\`${J}\``}static getSqlType($,J,Z=!1){let Y=N.getTypeMapping();if(N.isStringOrArrayType($)){if(typeof J!=="number")throw Error(`\u540C\u6B65\u8868\uFF1A\u5185\u90E8\u9519\u8BEF\uFF1A${$} \u7C7B\u578B\u7F3A\u5931 max\uFF08\u5E94\u7531 checkTable \u963B\u65AD\uFF09`);return`${Y[$]}(${J})`}let X=Y[$]||"TEXT";if($==="number"&&Z)return`${X} UNSIGNED`;return X}static resolveDefaultValue($,J){if($!==null&&$!=="null")return $;switch(J){case"number":return 0;case"string":return"";case"array_string":case"array_number_string":return"[]";case"text":case"array_text":case"array_number_text":return"null";default:return $}}static generateDefaultSql($,J){if(J==="text"||J==="array_text"||$==="null")return"";if(J==="number"||J==="string"||J==="array_string"||J==="array_number_string")if(typeof $==="number"&&!Number.isNaN($))return` DEFAULT ${$}`;else return` DEFAULT '${String($).replace(/'/g,"''")}'`;return""}static buildIndexClause($,J,Z){let Y=N.quoteIdentifier($);if(Z==="create"){let X=N.quoteIdentifier(J);return`ADD INDEX ${Y} (${X})`}return`DROP INDEX ${Y}`}static buildIndexSQL($,J,Z,Y){let X=N.quoteIdentifier($),G=N.buildIndexClause(J,Z,Y);return`ALTER TABLE ${X} ALGORITHM=INPLACE, LOCK=NONE, ${G}`}static getSystemColumnDef($){let J=null;for(let Y of N.SYSTEM_FIELDS)if(Y.name===$){J=Y;break}if(!J)return null;return`${N.quoteIdentifier(J.name)} ${J.mysqlDdl} COMMENT "${qJ(J.comment)}"`}static buildSystemColumnDefs(){let $=[];for(let J of N.SYSTEM_FIELDS){let Z=N.getSystemColumnDef(J.name);if(Z)$.push(Z)}return $}static buildBusinessColumnDefs($){let J=[];for(let[Z,Y]of Object.entries($)){let X=H$(Y),G=c(Z),Q=N.quoteIdentifier(G),U=N.getSqlType(X.type,X.max,X.unsigned),z=N.resolveDefaultValue(X.default,X.type),O=N.generateDefaultSql(z,X.type),_=X.unique?" UNIQUE":"",K=X.nullable?" NULL":" NOT NULL";J.push(`${Q} ${U}${_}${K}${O} COMMENT "${qJ(X.name)}"`)}return J}static generateDDLClause($,J,Z=!1){let Y=c($),X=N.quoteIdentifier(Y),G=H$(J),Q=N.getSqlType(G.type,G.max,G.unsigned),U=N.resolveDefaultValue(G.default,G.type),z=N.generateDefaultSql(U,G.type),O=G.unique?" UNIQUE":"",_=G.nullable?" NULL":" NOT NULL";return`${Z?"ADD COLUMN":"MODIFY COLUMN"} ${X} ${Q}${O}${_}${z} COMMENT "${qJ(G.name)}"`}static stripAlgorithmAndLock($){let J=String($);return J=J.replace(/\bALGORITHM\s*=\s*(INPLACE|INSTANT|COPY)\b\s*,?\s*/gi,"").replace(/\bLOCK\s*=\s*(NONE|SHARED|EXCLUSIVE)\b\s*,?\s*/gi,""),J=J.replace(/,\s*,/g,", ").replace(/,\s*$/g,"").replace(/\s{2,}/g," ").trim(),J}static buildDdlFallbackCandidates($){let J=String($),Z=[];if(/\bALGORITHM\s*=\s*INSTANT\b/i.test(J))Z.push({stmt:J.replace(/\bALGORITHM\s*=\s*INSTANT\b/gi,"ALGORITHM=INPLACE"),reason:"ALGORITHM=INSTANT \u2192 INPLACE"});let Y=N.stripAlgorithmAndLock(J);if(Y!==J)Z.push({stmt:Y,reason:"\u79FB\u9664 ALGORITHM/LOCK"});let X=[];for(let G of Z){if(!G.stmt||G.stmt.trim()==="")continue;if(G.stmt===J)continue;if(X.some((Q)=>Q.stmt===G.stmt))continue;X.push(G)}return X}static async executeDDLSafely($,J){try{return await $.unsafe(J),!0}catch(Z){let Y=N.buildDdlFallbackCandidates(J);for(let X of Y)try{return await $.unsafe(X.stmt),L.debug(`[DDL\u964D\u7EA7] ${X.reason}\uFF08\u5DF2\u6210\u529F\uFF09`),!0}catch{}throw Z}}static isCompatibleTypeChange($,J){let Z=String($||"").toLowerCase(),Y=String(J||"").toLowerCase();if(Z===Y)return!1;let X=Z.replace(/\s*unsigned/gi,"").replace(/\([^)]*\)/g,"").trim(),G=Y.replace(/\s*unsigned/gi,"").replace(/\([^)]*\)/g,"").trim(),Q=["tinytext","text","mediumtext","longtext"];if(Q.includes(X)&&Q.includes(G))return!0;let U=["tinyint","smallint","mediumint","int","integer","bigint"],z=U.indexOf(X),O=U.indexOf(G);if(z!==-1&&O!==-1&&O>z)return!0;if(X==="varchar"&&(G==="text"||G==="mediumtext"||G==="longtext"))return!0;if(X==="char"&&G==="varchar"||X==="varchar"&&G==="char")return!0;return!1}static compareFieldDefinition($,J){let Z=[],Y=H$(J);if(N.isStringOrArrayType(Y.type)){let j=Y.max;if(j!==null&&$.max!==j)Z.push({type:"length",current:$.max,expected:j})}let X=$.comment===null||$.comment===void 0?"":String($.comment);if(X!==Y.name)Z.push({type:"comment",current:X,expected:Y.name});let Q=N.getTypeMapping()[Y.type];if(typeof Q!=="string")throw Error(`\u540C\u6B65\u8868\uFF1A\u672A\u77E5\u5B57\u6BB5\u7C7B\u578B\u6620\u5C04\uFF08\u7C7B\u578B=${String(Y.type)}\uFF09`);let U=Q.toLowerCase(),z="";if(typeof $.type==="string"&&$.type.trim()!=="")z=$.type;else if(typeof $.columnType==="string"&&$.columnType.trim()!=="")z=$.columnType;else z=String($.type??"");let O=z.toLowerCase().replace(/\s*unsigned/gi,"").replace(/\([^)]*\)/g,"").trim();if(O!==U)Z.push({type:"datatype",current:O,expected:U});let _=Y.nullable;if($.nullable!==_)Z.push({type:"nullable",current:$.nullable,expected:_});let K=N.resolveDefaultValue(Y.default,Y.type);if(String($.defaultValue)!==String(K))Z.push({type:"default",current:$.defaultValue,expected:K});return Z}static async tableExists($,J,Z){try{return((await $.unsafe("SELECT COUNT(*) as count FROM information_schema.TABLES WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ?",[J,Z])).data?.[0]?.count||0)>0}catch(Y){throw N.buildRuntimeIoError("\u68C0\u67E5\u8868\u662F\u5426\u5B58\u5728",Z,Y)}}static async getTableColumns($,J,Z){let Y={};try{let X=await $.unsafe("SELECT COLUMN_NAME, DATA_TYPE, CHARACTER_MAXIMUM_LENGTH, IS_NULLABLE, COLUMN_DEFAULT, COLUMN_COMMENT, COLUMN_TYPE FROM information_schema.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION",[J,Z]);for(let G of X.data){let Q=NZ(G.COLUMN_DEFAULT);Y[G.COLUMN_NAME]={type:String(G.DATA_TYPE??""),columnType:String(G.COLUMN_TYPE??""),length:G.CHARACTER_MAXIMUM_LENGTH,max:G.CHARACTER_MAXIMUM_LENGTH,nullable:G.IS_NULLABLE==="YES",defaultValue:Q,comment:G.COLUMN_COMMENT===null?null:String(G.COLUMN_COMMENT)}}return Y}catch(X){throw N.buildRuntimeIoError("\u8BFB\u53D6\u5217\u4FE1\u606F",Z,X)}}static async getTableIndexes($,J,Z){let Y={};try{let X=await $.unsafe("SELECT INDEX_NAME, COLUMN_NAME FROM information_schema.STATISTICS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? AND INDEX_NAME != 'PRIMARY' ORDER BY INDEX_NAME",[J,Z]);for(let G of X.data){let Q=G.INDEX_NAME,U=Y[Q];if(Array.isArray(U))U.push(G.COLUMN_NAME);else Y[Q]=[G.COLUMN_NAME]}return Y}catch(X){throw N.buildRuntimeIoError("\u8BFB\u53D6\u7D22\u5F15\u4FE1\u606F",Z,X)}}static async ensureDbVersion($){let J=await $.unsafe("SELECT VERSION() AS version");if(!J.data||J.data.length===0||!J.data[0]?.version)throw Error("\u540C\u6B65\u8868\uFF1A\u65E0\u6CD5\u83B7\u53D6 MySQL \u7248\u672C\u4FE1\u606F");let Z=J.data[0].version,Y=String(Z).split(".")[0]||"0",X=parseInt(Y,10);if(!Number.isFinite(X)||X<N.DB_VERSION_REQUIREMENTS.MYSQL_MIN_MAJOR)throw Error(`\u540C\u6B65\u8868\uFF1A\u4EC5\u652F\u6301 MySQL ${N.DB_VERSION_REQUIREMENTS.MYSQL_MIN_MAJOR}.0+\uFF08\u5F53\u524D\u7248\u672C\uFF1A${Z}\uFF09`)}static async applyTablePlan($,J,Z){if(!Z||!Z.changed)return;let Y=Z.indexActions.filter((Q)=>Q.action==="drop"),X=Z.indexActions.filter((Q)=>Q.action==="create");if(Y.length>0){let Q=[];for(let O of Y)Q.push(N.buildIndexClause(O.indexName,O.fieldName,"drop"));let z=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INPLACE, LOCK=NONE, ${Q.join(", ")}`;try{await N.executeDDLSafely($,z)}catch(O){throw L.error({err:O,table:J,msg:"\u6279\u91CF\u5220\u9664\u7D22\u5F15\u5931\u8D25"}),O}}let G=[...Z.addClauses,...Z.modifyClauses];if(G.length>0){let U=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INSTANT, LOCK=NONE, ${G.join(", ")}`;await N.executeDDLSafely($,U)}if(Z.defaultClauses.length>0){let U=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INSTANT, LOCK=NONE, ${Z.defaultClauses.join(", ")}`;await N.executeDDLSafely($,U)}if(X.length>0){let Q=[];for(let O of X)Q.push(N.buildIndexClause(O.indexName,O.fieldName,"create"));let z=`ALTER TABLE ${N.quoteIdentifier(J)} ALGORITHM=INPLACE, LOCK=NONE, ${Q.join(", ")}`;try{await N.executeDDLSafely($,z)}catch(O){throw L.error({err:O,table:J,msg:"\u6279\u91CF\u521B\u5EFA\u7D22\u5F15\u5931\u8D25"}),O}}}static async createTable($,J,Z,Y=N.SYSTEM_INDEX_FIELDS){let G=[...N.buildSystemColumnDefs(),...N.buildBusinessColumnDefs(Z)].join(`,
|
|
7
7
|
`),Q=N.quoteIdentifier(J),{ENGINE:U,CHARSET:z,COLLATE:O}=N.MYSQL_TABLE_CONFIG,_=`CREATE TABLE ${Q} (
|
|
8
8
|
${G}
|
|
9
|
-
) ENGINE=${U} DEFAULT CHARSET=${z} COLLATE=${O}`;await $.unsafe(_),L.debug(`[\u8868 ${J}] + \u521B\u5EFA\u8868\uFF08\u7CFB\u7EDF\u5B57\u6BB5 + \u4E1A\u52A1\u5B57\u6BB5\uFF09`);let K=[];for(let j of Y){let C=`idx_${j}`;K.push(N.buildIndexClause(C,j,"create"))}for(let[j,C]of Object.entries(Z)){let S=c(j);if(C.index===!0&&C.unique!==!0){let v=`idx_${S}`;K.push(N.buildIndexClause(v,S,"create"))}}if(K.length>0){let j=`ALTER TABLE ${Q} ALGORITHM=INPLACE, LOCK=NONE, ${K.join(", ")}`;await N.executeDDLSafely($,j)}}static async modifyTable($,J,Z,Y){let X=await N.getTableColumns($,J,Z),G=await N.getTableIndexes($,J,Z),Q=!1,U=[],z=[],O=[],_=[],K=[],j=[],C=[],S=[],v=[];for(let[E,w]of Object.entries(Y)){let f=c(E);if(X[f]){let D=N.compareFieldDefinition(X[f],w);if(D.length>0){C.push(f);let m=D.some((i)=>i.type==="datatype"),a=D.every((i)=>i.type==="default"),r=D.some((i)=>i.type==="default");if(m){let i=D.find((
|
|
10
|
-
`);throw Error(M)}v.push(`${f}: ${q} -> ${V}`)}if(r){let i=N.resolveDefaultValue(w.default??null,w.type),q=null;if(i!=="null")q=N.generateDefaultSql(i,w.type).trim().replace(/^DEFAULT\s+/,"");if(q!==null&&q!==""&&a){if(w.type!=="text"){let H=N.quoteIdentifier(f);O.push(`ALTER COLUMN ${H} SET DEFAULT ${q}`),S.push(f)}}}if(!a)z.push(N.generateDDLClause(E,w,!1));Q=!0}}else K.push(f),U.push(N.generateDDLClause(E,w,!0)),Q=!0}let T=N.SYSTEM_FIELDS.filter((E)=>E.name!=="id").map((E)=>E.name);for(let E of T)if(!X[E]){let w=N.getSystemColumnDef(E);if(w)j.push(E),U.push(`ADD COLUMN ${w}`),Q=!0}for(let E of N.SYSTEM_INDEX_FIELDS){let w=`idx_${E}`;if((X[E]||T.includes(E))&&!G[w])_.push({action:"create",indexName:w,fieldName:E}),Q=!0}for(let[E,w]of Object.entries(Y)){let f=c(E),D=`idx_${f}`;if(w.index&&!w.unique&&!G[D])_.push({action:"create",indexName:D,fieldName:f}),Q=!0;else if(!w.index&&G[D]&&G[D].length===1)_.push({action:"drop",indexName:D,fieldName:f}),Q=!0}Q=U.length>0||z.length>0||O.length>0||_.length>0;let k={changed:Q,addClauses:U,modifyClauses:z,defaultClauses:O,indexActions:_};if(k.changed){let E=[];E.push(`[\u8868 ${Z}] \u53D8\u66F4\u6C47\u603B`),E.push(`\u65B0\u589E\u5B57\u6BB5=${K.length}`),E.push(`\u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5=${j.length}`),E.push(`\u4FEE\u6539\u5B57\u6BB5=${C.length}`),E.push(`\u9ED8\u8BA4\u503C\u66F4\u65B0=${S.length}`),E.push(`\u7D22\u5F15\u53D8\u66F4=${_.length}`);let w=[];if(K.length>0)w.push(`\u65B0\u589E\u5B57\u6BB5:${K.join(",")}`);if(j.length>0)w.push(`\u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5:${j.join(",")}`);if(C.length>0)w.push(`\u4FEE\u6539\u5B57\u6BB5:${C.join(",")}`);if(S.length>0)w.push(`\u9ED8\u8BA4\u503C\u66F4\u65B0:${S.join(",")}`);if(v.length>0)w.push(`\u517C\u5BB9\u7C7B\u578B\u53D8\u66F4:${v.join(";")}`);if(_.length>0){let D=[],m=[];for(let r of _){let i=`${r.indexName}(${r.fieldName})`;if(r.action==="create")D.push(`+${i}`);else m.push(`-${i}`)}let a=[];if(m.length>0)a.push(m.join(","));if(D.length>0)a.push(D.join(","));w.push(`\u7D22\u5F15:${a.join(",")}`)}let f=w.length>0?`${E.join("\uFF0C")}\uFF1B${w.join("\uFF0C")}`:E.join("\uFF0C");L.debug(f),await N.applyTablePlan($,Z,k)}return k}}var yX=($,J=Bun.nanoseconds())=>{let Z=(J-$)/1e6;if(Z<1000)return`${Z.toFixed(2)} \u6BEB\u79D2`;else return`${(Z/1000).toFixed(2)} \u79D2`};function gX($){let J=$||{},Z=J.BUN_WORKER_ID,Y=J.PM2_INSTANCE_ID;if(Z!==void 0)return{role:Z===""?"primary":"worker",instanceId:Z||"0",env:"bun-cluster"};if(Y!==void 0)return{role:Y==="0"?"primary":"worker",instanceId:Y,env:"pm2-cluster"};return{role:"primary",instanceId:null,env:"standalone"}}L$();L$();import{existsSync as AH,readdirSync as KH}from"fs";EZ();m0();var hX=()=>{let $=new Map,J=(Z,Y,X)=>{if(!AH(Z))return;let G=KH(Z,{withFileTypes:!0});for(let Q of G){if(Q.name.startsWith("_"))continue;if(!FJ(Z,Q))continue;let U=e$(Z,Q.name),z={source:Y,sourceName:X,name:Q.name,camelName:F$(Q.name),rootDir:U,fullPath:U};$.set(Q.name,z)}};return J(s(d0,"node_modules","@befly-addon"),"addon","\u7EC4\u4EF6"),J(wX,"app","\u9879\u76EE"),Array.from($.values())};zJ();var FH={name:"auth",enable:!0,deps:["cors"],handler:async($,J)=>{let Z=J.req.headers.get("authorization");if(Z&&Z.startsWith("Bearer ")){let Y=Z.substring(7);try{let X=await $.jwt.verify(Y);J.user=X,dY(X.id,X.roleCode,X.nickname,X.roleType)}catch{J.user={}}}else J.user={}}},bX=FH;var RH={name:"cors",enable:!0,deps:[],handler:async($,J)=>{let Z=J.req,X=Object.assign({},{origin:"*",methods:"GET, POST, OPTIONS",allowedHeaders:"Content-Type, Authorization, authorization, token",exposedHeaders:"Content-Range, X-Content-Range, Authorization, authorization, token",maxAge:86400,credentials:"true"},$.config&&$.config.cors?$.config.cors:{}),G=IJ(Z,X);if(J.corsHeaders=G,Z.method==="OPTIONS"){J.response=new Response(null,{status:204,headers:G});return}}},cX=RH;var IH=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",qH="[:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]["+IH+"]*",LH=new RegExp("^"+qH+"$");function LJ($,J){let Z=[],Y=J.exec($);while(Y){let X=[];X.startIndex=J.lastIndex-Y[0].length;let G=Y.length;for(let Q=0;Q<G;Q++)X.push(Y[Q]);Z.push(X),Y=J.exec($)}return Z}var h$=function($){let J=LH.exec($);return!(J===null||typeof J>"u")};function pX($){return typeof $<"u"}var jH={allowBooleanAttributes:!1,unpairedTags:[]};function sX($,J){J=Object.assign({},jH,J);let Z=[],Y=!1,X=!1;if($[0]==="\uFEFF")$=$.substr(1);for(let G=0;G<$.length;G++)if($[G]==="<"&&$[G+1]==="?"){if(G+=2,G=mX($,G),G.err)return G}else if($[G]==="<"){let Q=G;if(G++,$[G]==="!"){G=nX($,G);continue}else{let U=!1;if($[G]==="/")U=!0,G++;let z="";for(;G<$.length&&$[G]!==">"&&$[G]!==" "&&$[G]!=="\t"&&$[G]!==`
|
|
9
|
+
) ENGINE=${U} DEFAULT CHARSET=${z} COLLATE=${O}`;await $.unsafe(_),L.debug(`[\u8868 ${J}] + \u521B\u5EFA\u8868\uFF08\u7CFB\u7EDF\u5B57\u6BB5 + \u4E1A\u52A1\u5B57\u6BB5\uFF09`);let K=[];for(let j of Y){let C=`idx_${j}`;K.push(N.buildIndexClause(C,j,"create"))}for(let[j,C]of Object.entries(Z)){let S=c(j);if(C.index===!0&&C.unique!==!0){let v=`idx_${S}`;K.push(N.buildIndexClause(v,S,"create"))}}if(K.length>0){let j=`ALTER TABLE ${Q} ALGORITHM=INPLACE, LOCK=NONE, ${K.join(", ")}`;await N.executeDDLSafely($,j)}}static async modifyTable($,J,Z,Y){let X=await N.getTableColumns($,J,Z),G=await N.getTableIndexes($,J,Z),Q=!1,U=[],z=[],O=[],_=[],K=[],j=[],C=[],S=[],v=[];for(let[E,w]of Object.entries(Y)){let f=c(E);if(X[f]){let D=N.compareFieldDefinition(X[f],w);if(D.length>0){C.push(f);let m=D.some((i)=>i.type==="datatype"),a=D.every((i)=>i.type==="default"),r=D.some((i)=>i.type==="default");if(m){let i=D.find((A)=>A.type==="datatype"),q=String(i?.current||"").toLowerCase(),V=N.getTypeMapping()[w.type]?.toLowerCase()||"";if(!N.isCompatibleTypeChange(q,V)){let A=[`\u7981\u6B62\u5B57\u6BB5\u7C7B\u578B\u53D8\u66F4: ${Z}.${f}`,`\u5F53\u524D\u7C7B\u578B: ${i?.current}`,`\u76EE\u6807\u7C7B\u578B: ${i?.expected}`,"\u8BF4\u660E: \u4EC5\u5141\u8BB8\u5BBD\u5316\u578B\u53D8\u66F4\uFF08\u5982 INT->BIGINT, VARCHAR->TEXT\uFF09\uFF0C\u4EE5\u53CA CHAR/VARCHAR \u4E92\u8F6C\uFF1B\u5176\u4ED6\u7C7B\u578B\u53D8\u66F4\u9700\u8981\u624B\u52A8\u5904\u7406"].join(`
|
|
10
|
+
`);throw Error(A)}let M="";if(q==="char"&&V==="varchar"||q==="varchar"&&V==="char")M="char/varchar\u4E92\u8F6C";if(M)v.push(`${f}: ${q} -> ${V} (${M})`);else v.push(`${f}: ${q} -> ${V}`)}if(r){let i=N.resolveDefaultValue(w.default??null,w.type),q=null;if(i!=="null")q=N.generateDefaultSql(i,w.type).trim().replace(/^DEFAULT\s+/,"");if(q!==null&&q!==""&&a){if(w.type!=="text"){let H=N.quoteIdentifier(f);O.push(`ALTER COLUMN ${H} SET DEFAULT ${q}`),S.push(f)}}}if(!a)z.push(N.generateDDLClause(E,w,!1));Q=!0}}else K.push(f),U.push(N.generateDDLClause(E,w,!0)),Q=!0}let T=N.SYSTEM_FIELDS.filter((E)=>E.name!=="id").map((E)=>E.name);for(let E of T)if(!X[E]){let w=N.getSystemColumnDef(E);if(w)j.push(E),U.push(`ADD COLUMN ${w}`),Q=!0}for(let E of N.SYSTEM_INDEX_FIELDS){let w=`idx_${E}`;if((X[E]||T.includes(E))&&!G[w])_.push({action:"create",indexName:w,fieldName:E}),Q=!0}for(let[E,w]of Object.entries(Y)){let f=c(E),D=`idx_${f}`;if(w.index&&!w.unique&&!G[D])_.push({action:"create",indexName:D,fieldName:f}),Q=!0;else if(!w.index&&G[D]&&G[D].length===1)_.push({action:"drop",indexName:D,fieldName:f}),Q=!0}Q=U.length>0||z.length>0||O.length>0||_.length>0;let k={changed:Q,addClauses:U,modifyClauses:z,defaultClauses:O,indexActions:_};if(k.changed){let E=[];E.push(`[\u8868 ${Z}] \u53D8\u66F4\u6C47\u603B`),E.push(`\u65B0\u589E\u5B57\u6BB5=${K.length}`),E.push(`\u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5=${j.length}`),E.push(`\u4FEE\u6539\u5B57\u6BB5=${C.length}`),E.push(`\u9ED8\u8BA4\u503C\u66F4\u65B0=${S.length}`),E.push(`\u7D22\u5F15\u53D8\u66F4=${_.length}`);let w=[];if(K.length>0)w.push(`\u65B0\u589E\u5B57\u6BB5:${K.join(",")}`);if(j.length>0)w.push(`\u65B0\u589E\u7CFB\u7EDF\u5B57\u6BB5:${j.join(",")}`);if(C.length>0)w.push(`\u4FEE\u6539\u5B57\u6BB5:${C.join(",")}`);if(S.length>0)w.push(`\u9ED8\u8BA4\u503C\u66F4\u65B0:${S.join(",")}`);if(v.length>0)w.push(`\u517C\u5BB9\u7C7B\u578B\u53D8\u66F4:${v.join(";")}`);if(_.length>0){let D=[],m=[];for(let r of _){let i=`${r.indexName}(${r.fieldName})`;if(r.action==="create")D.push(`+${i}`);else m.push(`-${i}`)}let a=[];if(m.length>0)a.push(m.join(","));if(D.length>0)a.push(D.join(","));w.push(`\u7D22\u5F15:${a.join(",")}`)}let f=w.length>0?`${E.join("\uFF0C")}\uFF1B${w.join("\uFF0C")}`:E.join("\uFF0C");L.debug(f),await N.applyTablePlan($,Z,k)}return k}}var yX=($,J=Bun.nanoseconds())=>{let Z=(J-$)/1e6;if(Z<1000)return`${Z.toFixed(2)} \u6BEB\u79D2`;else return`${(Z/1000).toFixed(2)} \u79D2`};function gX($){let J=$||{},Z=J.BUN_WORKER_ID,Y=J.PM2_INSTANCE_ID;if(Z!==void 0)return{role:Z===""?"primary":"worker",instanceId:Z||"0",env:"bun-cluster"};if(Y!==void 0)return{role:Y==="0"?"primary":"worker",instanceId:Y,env:"pm2-cluster"};return{role:"primary",instanceId:null,env:"standalone"}}L$();L$();import{existsSync as AH,readdirSync as KH}from"fs";EZ();m0();var hX=()=>{let $=new Map,J=(Z,Y,X)=>{if(!AH(Z))return;let G=KH(Z,{withFileTypes:!0});for(let Q of G){if(Q.name.startsWith("_"))continue;if(!FJ(Z,Q))continue;let U=e$(Z,Q.name),z={source:Y,sourceName:X,name:Q.name,camelName:F$(Q.name),rootDir:U,fullPath:U};$.set(Q.name,z)}};return J(s(d0,"node_modules","@befly-addon"),"addon","\u7EC4\u4EF6"),J(wX,"app","\u9879\u76EE"),Array.from($.values())};zJ();var FH={name:"auth",enable:!0,deps:["cors"],handler:async($,J)=>{let Z=J.req.headers.get("authorization");if(Z&&Z.startsWith("Bearer ")){let Y=Z.substring(7);try{let X=await $.jwt.verify(Y);J.user=X,dY(X.id,X.roleCode,X.nickname,X.roleType)}catch{J.user={}}}else J.user={}}},bX=FH;var RH={name:"cors",enable:!0,deps:[],handler:async($,J)=>{let Z=J.req,X=Object.assign({},{origin:"*",methods:"GET, POST, OPTIONS",allowedHeaders:"Content-Type, Authorization, authorization, token",exposedHeaders:"Content-Range, X-Content-Range, Authorization, authorization, token",maxAge:86400,credentials:"true"},$.config&&$.config.cors?$.config.cors:{}),G=IJ(Z,X);if(J.corsHeaders=G,Z.method==="OPTIONS"){J.response=new Response(null,{status:204,headers:G});return}}},cX=RH;var IH=":A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD\\-.\\d\\u00B7\\u0300-\\u036F\\u203F-\\u2040",qH="[:A-Za-z_\\u00C0-\\u00D6\\u00D8-\\u00F6\\u00F8-\\u02FF\\u0370-\\u037D\\u037F-\\u1FFF\\u200C-\\u200D\\u2070-\\u218F\\u2C00-\\u2FEF\\u3001-\\uD7FF\\uF900-\\uFDCF\\uFDF0-\\uFFFD]["+IH+"]*",LH=new RegExp("^"+qH+"$");function LJ($,J){let Z=[],Y=J.exec($);while(Y){let X=[];X.startIndex=J.lastIndex-Y[0].length;let G=Y.length;for(let Q=0;Q<G;Q++)X.push(Y[Q]);Z.push(X),Y=J.exec($)}return Z}var h$=function($){let J=LH.exec($);return!(J===null||typeof J>"u")};function pX($){return typeof $<"u"}var jH={allowBooleanAttributes:!1,unpairedTags:[]};function sX($,J){J=Object.assign({},jH,J);let Z=[],Y=!1,X=!1;if($[0]==="\uFEFF")$=$.substr(1);for(let G=0;G<$.length;G++)if($[G]==="<"&&$[G+1]==="?"){if(G+=2,G=mX($,G),G.err)return G}else if($[G]==="<"){let Q=G;if(G++,$[G]==="!"){G=nX($,G);continue}else{let U=!1;if($[G]==="/")U=!0,G++;let z="";for(;G<$.length&&$[G]!==">"&&$[G]!==" "&&$[G]!=="\t"&&$[G]!==`
|
|
11
11
|
`&&$[G]!=="\r";G++)z+=$[G];if(z=z.trim(),z[z.length-1]==="/")z=z.substring(0,z.length-1),G--;if(!NH(z)){let K;if(z.trim().length===0)K="Invalid space after '<'.";else K="Tag '"+z+"' is an invalid name.";return Q0("InvalidTag",K,s0($,G))}let O=EH($,G);if(O===!1)return Q0("InvalidAttr","Attributes for '"+z+"' have open quote.",s0($,G));let _=O.value;if(G=O.index,_[_.length-1]==="/"){let K=G-_.length;_=_.substring(0,_.length-1);let j=dX(_,J);if(j===!0)Y=!0;else return Q0(j.err.code,j.err.msg,s0($,K+j.err.line))}else if(U)if(!O.tagClosed)return Q0("InvalidTag","Closing tag '"+z+"' doesn't have proper closing.",s0($,G));else if(_.trim().length>0)return Q0("InvalidTag","Closing tag '"+z+"' can't have attributes or invalid starting.",s0($,Q));else if(Z.length===0)return Q0("InvalidTag","Closing tag '"+z+"' has not been opened.",s0($,Q));else{let K=Z.pop();if(z!==K.tagName){let j=s0($,K.tagStartPos);return Q0("InvalidTag","Expected closing tag '"+K.tagName+"' (opened in line "+j.line+", col "+j.col+") instead of closing tag '"+z+"'.",s0($,Q))}if(Z.length==0)X=!0}else{let K=dX(_,J);if(K!==!0)return Q0(K.err.code,K.err.msg,s0($,G-_.length+K.err.line));if(X===!0)return Q0("InvalidXml","Multiple possible root nodes found.",s0($,G));else if(J.unpairedTags.indexOf(z)!==-1);else Z.push({tagName:z,tagStartPos:Q});Y=!0}for(G++;G<$.length;G++)if($[G]==="<")if($[G+1]==="!"){G++,G=nX($,G);continue}else if($[G+1]==="?"){if(G=mX($,++G),G.err)return G}else break;else if($[G]==="&"){let K=wH($,G);if(K==-1)return Q0("InvalidChar","char '&' is not expected.",s0($,G));G=K}else if(X===!0&&!uX($[G]))return Q0("InvalidXml","Extra text at the end",s0($,G));if($[G]==="<")G--}}else{if(uX($[G]))continue;return Q0("InvalidChar","char '"+$[G]+"' is not expected.",s0($,G))}if(!Y)return Q0("InvalidXml","Start tag expected.",1);else if(Z.length==1)return Q0("InvalidTag","Unclosed tag '"+Z[0].tagName+"'.",s0($,Z[0].tagStartPos));else if(Z.length>0)return Q0("InvalidXml","Invalid '"+JSON.stringify(Z.map((G)=>G.tagName),null,4).replace(/\r?\n/g,"")+"' found.",{line:1,col:1});return!0}function uX($){return $===" "||$==="\t"||$===`
|
|
12
12
|
`||$==="\r"}function mX($,J){let Z=J;for(;J<$.length;J++)if($[J]=="?"||$[J]==" "){let Y=$.substr(Z,J-Z);if(J>5&&Y==="xml")return Q0("InvalidXml","XML declaration allowed only at the start of the document.",s0($,J));else if($[J]=="?"&&$[J+1]==">"){J++;break}else continue}return J}function nX($,J){if($.length>J+5&&$[J+1]==="-"&&$[J+2]==="-"){for(J+=3;J<$.length;J++)if($[J]==="-"&&$[J+1]==="-"&&$[J+2]===">"){J+=2;break}}else if($.length>J+8&&$[J+1]==="D"&&$[J+2]==="O"&&$[J+3]==="C"&&$[J+4]==="T"&&$[J+5]==="Y"&&$[J+6]==="P"&&$[J+7]==="E"){let Z=1;for(J+=8;J<$.length;J++)if($[J]==="<")Z++;else if($[J]===">"){if(Z--,Z===0)break}}else if($.length>J+9&&$[J+1]==="["&&$[J+2]==="C"&&$[J+3]==="D"&&$[J+4]==="A"&&$[J+5]==="T"&&$[J+6]==="A"&&$[J+7]==="["){for(J+=8;J<$.length;J++)if($[J]==="]"&&$[J+1]==="]"&&$[J+2]===">"){J+=2;break}}return J}var BH='"',PH="'";function EH($,J){let Z="",Y="",X=!1;for(;J<$.length;J++){if($[J]===BH||$[J]===PH)if(Y==="")Y=$[J];else if(Y!==$[J]);else Y="";else if($[J]===">"){if(Y===""){X=!0;break}}Z+=$[J]}if(Y!=="")return!1;return{value:Z,index:J,tagClosed:X}}var CH=new RegExp(`(\\s*)([^\\s=]+)(\\s*=)?(\\s*(['"])(([\\s\\S])*?)\\5)?`,"g");function dX($,J){let Z=LJ($,CH),Y={};for(let X=0;X<Z.length;X++){if(Z[X][1].length===0)return Q0("InvalidAttr","Attribute '"+Z[X][2]+"' has no space in starting.",YJ(Z[X]));else if(Z[X][3]!==void 0&&Z[X][4]===void 0)return Q0("InvalidAttr","Attribute '"+Z[X][2]+"' is without value.",YJ(Z[X]));else if(Z[X][3]===void 0&&!J.allowBooleanAttributes)return Q0("InvalidAttr","boolean attribute '"+Z[X][2]+"' is not allowed.",YJ(Z[X]));let G=Z[X][2];if(!TH(G))return Q0("InvalidAttr","Attribute '"+G+"' is an invalid name.",YJ(Z[X]));if(!Y.hasOwnProperty(G))Y[G]=1;else return Q0("InvalidAttr","Attribute '"+G+"' is repeated.",YJ(Z[X]))}return!0}function SH($,J){let Z=/\d/;if($[J]==="x")J++,Z=/[\da-fA-F]/;for(;J<$.length;J++){if($[J]===";")return J;if(!$[J].match(Z))break}return-1}function wH($,J){if(J++,$[J]===";")return-1;if($[J]==="#")return J++,SH($,J);let Z=0;for(;J<$.length;J++,Z++){if($[J].match(/\w/)&&Z<20)continue;if($[J]===";")break;return-1}return J}function Q0($,J,Z){return{err:{code:$,msg:J,line:Z.line||Z,col:Z.col}}}function TH($){return h$($)}function NH($){return h$($)}function s0($,J){let Z=$.substring(0,J).split(/\r?\n/);return{line:Z.length,col:Z[Z.length-1].length+1}}function YJ($){return $.startIndex+$[1].length}var DH={preserveOrder:!1,attributeNamePrefix:"@_",attributesGroupName:!1,textNodeName:"#text",ignoreAttributes:!0,removeNSPrefix:!1,allowBooleanAttributes:!1,parseTagValue:!0,parseAttributeValue:!1,trimValues:!0,cdataPropName:!1,numberParseOptions:{hex:!0,leadingZeros:!0,eNotation:!0},tagValueProcessor:function($,J){return J},attributeValueProcessor:function($,J){return J},stopNodes:[],alwaysCreateTextNode:!1,isArray:()=>!1,commentPropName:!1,unpairedTags:[],processEntities:!0,htmlEntities:!1,ignoreDeclaration:!1,ignorePiTags:!1,transformTagName:!1,transformAttributeName:!1,updateTag:function($,J,Z){return $},captureMetaData:!1},oX=function($){return Object.assign({},DH,$)};var jJ;if(typeof Symbol!=="function")jJ="@@xmlMetadata";else jJ=Symbol("XML Node Metadata");class i0{constructor($){this.tagname=$,this.child=[],this[":@"]={}}add($,J){if($==="__proto__")$="#__proto__";this.child.push({[$]:J})}addChild($,J){if($.tagname==="__proto__")$.tagname="#__proto__";if($[":@"]&&Object.keys($[":@"]).length>0)this.child.push({[$.tagname]:$.child,[":@"]:$[":@"]});else this.child.push({[$.tagname]:$.child});if(J!==void 0)this.child[this.child.length-1][jJ]={startIndex:J}}static getMetaDataSymbol(){return jJ}}class BJ{constructor($){this.suppressValidationErr=!$}readDocType($,J){let Z={};if($[J+3]==="O"&&$[J+4]==="C"&&$[J+5]==="T"&&$[J+6]==="Y"&&$[J+7]==="P"&&$[J+8]==="E"){J=J+9;let Y=1,X=!1,G=!1,Q="";for(;J<$.length;J++)if($[J]==="<"&&!G){if(X&&T$($,"!ENTITY",J)){J+=7;let U,z;if([U,z,J]=this.readEntityExp($,J+1,this.suppressValidationErr),z.indexOf("&")===-1)Z[U]={regx:RegExp(`&${U};`,"g"),val:z}}else if(X&&T$($,"!ELEMENT",J)){J+=8;let{index:U}=this.readElementExp($,J+1);J=U}else if(X&&T$($,"!ATTLIST",J))J+=8;else if(X&&T$($,"!NOTATION",J)){J+=9;let{index:U}=this.readNotationExp($,J+1,this.suppressValidationErr);J=U}else if(T$($,"!--",J))G=!0;else throw Error("Invalid DOCTYPE");Y++,Q=""}else if($[J]===">"){if(G){if($[J-1]==="-"&&$[J-2]==="-")G=!1,Y--}else Y--;if(Y===0)break}else if($[J]==="[")X=!0;else Q+=$[J];if(Y!==0)throw Error("Unclosed DOCTYPE")}else throw Error("Invalid Tag instead of DOCTYPE");return{entities:Z,i:J}}readEntityExp($,J){J=l0($,J);let Z="";while(J<$.length&&!/\s/.test($[J])&&$[J]!=='"'&&$[J]!=="'")Z+=$[J],J++;if(XJ(Z),J=l0($,J),!this.suppressValidationErr){if($.substring(J,J+6).toUpperCase()==="SYSTEM")throw Error("External entities are not supported");else if($[J]==="%")throw Error("Parameter entities are not supported")}let Y="";return[J,Y]=this.readIdentifierVal($,J,"entity"),J--,[Z,Y,J]}readNotationExp($,J){J=l0($,J);let Z="";while(J<$.length&&!/\s/.test($[J]))Z+=$[J],J++;!this.suppressValidationErr&&XJ(Z),J=l0($,J);let Y=$.substring(J,J+6).toUpperCase();if(!this.suppressValidationErr&&Y!=="SYSTEM"&&Y!=="PUBLIC")throw Error(`Expected SYSTEM or PUBLIC, found "${Y}"`);J+=Y.length,J=l0($,J);let X=null,G=null;if(Y==="PUBLIC"){if([J,X]=this.readIdentifierVal($,J,"publicIdentifier"),J=l0($,J),$[J]==='"'||$[J]==="'")[J,G]=this.readIdentifierVal($,J,"systemIdentifier")}else if(Y==="SYSTEM"){if([J,G]=this.readIdentifierVal($,J,"systemIdentifier"),!this.suppressValidationErr&&!G)throw Error("Missing mandatory system identifier for SYSTEM notation")}return{notationName:Z,publicIdentifier:X,systemIdentifier:G,index:--J}}readIdentifierVal($,J,Z){let Y="",X=$[J];if(X!=='"'&&X!=="'")throw Error(`Expected quoted string, found "${X}"`);J++;while(J<$.length&&$[J]!==X)Y+=$[J],J++;if($[J]!==X)throw Error(`Unterminated ${Z} value`);return J++,[J,Y]}readElementExp($,J){J=l0($,J);let Z="";while(J<$.length&&!/\s/.test($[J]))Z+=$[J],J++;if(!this.suppressValidationErr&&!h$(Z))throw Error(`Invalid element name: "${Z}"`);J=l0($,J);let Y="";if($[J]==="E"&&T$($,"MPTY",J))J+=4;else if($[J]==="A"&&T$($,"NY",J))J+=2;else if($[J]==="("){J++;while(J<$.length&&$[J]!==")")Y+=$[J],J++;if($[J]!==")")throw Error("Unterminated content model")}else if(!this.suppressValidationErr)throw Error(`Invalid Element Expression, found "${$[J]}"`);return{elementName:Z,contentModel:Y.trim(),index:J}}readAttlistExp($,J){J=l0($,J);let Z="";while(J<$.length&&!/\s/.test($[J]))Z+=$[J],J++;XJ(Z),J=l0($,J);let Y="";while(J<$.length&&!/\s/.test($[J]))Y+=$[J],J++;if(!XJ(Y))throw Error(`Invalid attribute name: "${Y}"`);J=l0($,J);let X="";if($.substring(J,J+8).toUpperCase()==="NOTATION"){if(X="NOTATION",J+=8,J=l0($,J),$[J]!=="(")throw Error(`Expected '(', found "${$[J]}"`);J++;let Q=[];while(J<$.length&&$[J]!==")"){let U="";while(J<$.length&&$[J]!=="|"&&$[J]!==")")U+=$[J],J++;if(U=U.trim(),!XJ(U))throw Error(`Invalid notation name: "${U}"`);if(Q.push(U),$[J]==="|")J++,J=l0($,J)}if($[J]!==")")throw Error("Unterminated list of notations");J++,X+=" ("+Q.join("|")+")"}else{while(J<$.length&&!/\s/.test($[J]))X+=$[J],J++;let Q=["CDATA","ID","IDREF","IDREFS","ENTITY","ENTITIES","NMTOKEN","NMTOKENS"];if(!this.suppressValidationErr&&!Q.includes(X.toUpperCase()))throw Error(`Invalid attribute type: "${X}"`)}J=l0($,J);let G="";if($.substring(J,J+8).toUpperCase()==="#REQUIRED")G="#REQUIRED",J+=8;else if($.substring(J,J+7).toUpperCase()==="#IMPLIED")G="#IMPLIED",J+=7;else[J,G]=this.readIdentifierVal($,J,"ATTLIST");return{elementName:Z,attributeName:Y,attributeType:X,defaultValue:G,index:J}}}var l0=($,J)=>{while(J<$.length&&/\s/.test($[J]))J++;return J};function T$($,J,Z){for(let Y=0;Y<J.length;Y++)if(J[Y]!==$[Z+Y+1])return!1;return!0}function XJ($){if(h$($))return $;else throw Error(`Invalid entity name ${$}`)}var vH=/^[-+]?0x[a-fA-F0-9]+$/,kH=/^([\-\+])?(0*)([0-9]*(\.[0-9]*)?)$/,xH={hex:!0,leadingZeros:!0,decimalPoint:".",eNotation:!0};function DZ($,J={}){if(J=Object.assign({},xH,J),!$||typeof $!=="string")return $;let Z=$.trim();if(J.skipLike!==void 0&&J.skipLike.test(Z))return $;else if($==="0")return 0;else if(J.hex&&vH.test(Z))return hH(Z,16);else if(Z.includes("e")||Z.includes("E"))return yH($,Z,J);else{let Y=kH.exec(Z);if(Y){let X=Y[1]||"",G=Y[2],Q=gH(Y[3]),U=X?$[G.length+1]===".":$[G.length]===".";if(!J.leadingZeros&&(G.length>1||G.length===1&&!U))return $;else{let z=Number(Z),O=String(z);if(z===0)return z;if(O.search(/[eE]/)!==-1)if(J.eNotation)return z;else return $;else if(Z.indexOf(".")!==-1)if(O==="0")return z;else if(O===Q)return z;else if(O===`${X}${Q}`)return z;else return $;let _=G?Q:Z;if(G)return _===O||X+_===O?z:$;else return _===O||_===X+O?z:$}}else return $}}var fH=/^([-+])?(0*)(\d*(\.\d*)?[eE][-\+]?\d+)$/;function yH($,J,Z){if(!Z.eNotation)return $;let Y=J.match(fH);if(Y){let X=Y[1]||"",G=Y[3].indexOf("e")===-1?"E":"e",Q=Y[2],U=X?$[Q.length+1]===G:$[Q.length]===G;if(Q.length>1&&U)return $;else if(Q.length===1&&(Y[3].startsWith(`.${G}`)||Y[3][0]===G))return Number(J);else if(Z.leadingZeros&&!U)return J=(Y[1]||"")+Y[3],Number(J);else return $}else return $}function gH($){if($&&$.indexOf(".")!==-1){if($=$.replace(/0+$/,""),$===".")$="0";else if($[0]===".")$="0"+$;else if($[$.length-1]===".")$=$.substring(0,$.length-1);return $}return $}function hH($,J){if(parseInt)return parseInt($,J);else if(Number.parseInt)return Number.parseInt($,J);else if(window&&window.parseInt)return window.parseInt($,J);else throw Error("parseInt, Number.parseInt, window.parseInt are not supported")}function vZ($){if(typeof $==="function")return $;if(Array.isArray($))return(J)=>{for(let Z of $){if(typeof Z==="string"&&J===Z)return!0;if(Z instanceof RegExp&&Z.test(J))return!0}};return()=>!1}class PJ{constructor($){if(this.options=$,this.currentNode=null,this.tagsNodeStack=[],this.docTypeEntities={},this.lastEntities={apos:{regex:/&(apos|#39|#x27);/g,val:"'"},gt:{regex:/&(gt|#62|#x3E);/g,val:">"},lt:{regex:/&(lt|#60|#x3C);/g,val:"<"},quot:{regex:/&(quot|#34|#x22);/g,val:'"'}},this.ampEntity={regex:/&(amp|#38|#x26);/g,val:"&"},this.htmlEntities={space:{regex:/&(nbsp|#160);/g,val:" "},cent:{regex:/&(cent|#162);/g,val:"\xA2"},pound:{regex:/&(pound|#163);/g,val:"\xA3"},yen:{regex:/&(yen|#165);/g,val:"\xA5"},euro:{regex:/&(euro|#8364);/g,val:"\u20AC"},copyright:{regex:/&(copy|#169);/g,val:"\xA9"},reg:{regex:/&(reg|#174);/g,val:"\xAE"},inr:{regex:/&(inr|#8377);/g,val:"\u20B9"},num_dec:{regex:/&#([0-9]{1,7});/g,val:(J,Z)=>String.fromCodePoint(Number.parseInt(Z,10))},num_hex:{regex:/&#x([0-9a-fA-F]{1,6});/g,val:(J,Z)=>String.fromCodePoint(Number.parseInt(Z,16))}},this.addExternalEntities=bH,this.parseXml=nH,this.parseTextData=cH,this.resolveNameSpace=pH,this.buildAttributesMap=mH,this.isItStopNode=lH,this.replaceEntitiesValue=sH,this.readStopNodeData=iH,this.saveTextToParentTag=oH,this.addChild=dH,this.ignoreAttributesFn=vZ(this.options.ignoreAttributes),this.options.stopNodes&&this.options.stopNodes.length>0){this.stopNodesExact=new Set,this.stopNodesWildcard=new Set;for(let J=0;J<this.options.stopNodes.length;J++){let Z=this.options.stopNodes[J];if(typeof Z!=="string")continue;if(Z.startsWith("*."))this.stopNodesWildcard.add(Z.substring(2));else this.stopNodesExact.add(Z)}}}}function bH($){let J=Object.keys($);for(let Z=0;Z<J.length;Z++){let Y=J[Z];this.lastEntities[Y]={regex:new RegExp("&"+Y+";","g"),val:$[Y]}}}function cH($,J,Z,Y,X,G,Q){if($!==void 0){if(this.options.trimValues&&!Y)$=$.trim();if($.length>0){if(!Q)$=this.replaceEntitiesValue($);let U=this.options.tagValueProcessor(J,$,Z,X,G);if(U===null||U===void 0)return $;else if(typeof U!==typeof $||U!==$)return U;else if(this.options.trimValues)return xZ($,this.options.parseTagValue,this.options.numberParseOptions);else if($.trim()===$)return xZ($,this.options.parseTagValue,this.options.numberParseOptions);else return $}}}function pH($){if(this.options.removeNSPrefix){let J=$.split(":"),Z=$.charAt(0)==="/"?"/":"";if(J[0]==="xmlns")return"";if(J.length===2)$=Z+J[1]}return $}var uH=new RegExp(`([^\\s=]+)\\s*(=\\s*(['"])([\\s\\S]*?)\\3)?`,"gm");function mH($,J){if(this.options.ignoreAttributes!==!0&&typeof $==="string"){let Z=LJ($,uH),Y=Z.length,X={};for(let G=0;G<Y;G++){let Q=this.resolveNameSpace(Z[G][1]);if(this.ignoreAttributesFn(Q,J))continue;let U=Z[G][4],z=this.options.attributeNamePrefix+Q;if(Q.length){if(this.options.transformAttributeName)z=this.options.transformAttributeName(z);if(z==="__proto__")z="#__proto__";if(U!==void 0){if(this.options.trimValues)U=U.trim();U=this.replaceEntitiesValue(U);let O=this.options.attributeValueProcessor(Q,U,J);if(O===null||O===void 0)X[z]=U;else if(typeof O!==typeof U||O!==U)X[z]=O;else X[z]=xZ(U,this.options.parseAttributeValue,this.options.numberParseOptions)}else if(this.options.allowBooleanAttributes)X[z]=!0}}if(!Object.keys(X).length)return;if(this.options.attributesGroupName){let G={};return G[this.options.attributesGroupName]=X,G}return X}}var nH=function($){$=$.replace(/\r\n?/g,`
|
|
13
13
|
`);let J=new i0("!xml"),Z=J,Y="",X="",G=new BJ(this.options.processEntities);for(let Q=0;Q<$.length;Q++)if($[Q]==="<")if($[Q+1]==="/"){let z=N$($,">",Q,"Closing Tag is not closed."),O=$.substring(Q+2,z).trim();if(this.options.removeNSPrefix){let j=O.indexOf(":");if(j!==-1)O=O.substr(j+1)}if(this.options.transformTagName)O=this.options.transformTagName(O);if(Z)Y=this.saveTextToParentTag(Y,Z,X);let _=X.substring(X.lastIndexOf(".")+1);if(O&&this.options.unpairedTags.indexOf(O)!==-1)throw Error(`Unpaired tag can not be used as closing tag: </${O}>`);let K=0;if(_&&this.options.unpairedTags.indexOf(_)!==-1)K=X.lastIndexOf(".",X.lastIndexOf(".")-1),this.tagsNodeStack.pop();else K=X.lastIndexOf(".");X=X.substring(0,K),Z=this.tagsNodeStack.pop(),Y="",Q=z}else if($[Q+1]==="?"){let z=kZ($,Q,!1,"?>");if(!z)throw Error("Pi Tag is not closed.");if(Y=this.saveTextToParentTag(Y,Z,X),this.options.ignoreDeclaration&&z.tagName==="?xml"||this.options.ignorePiTags);else{let O=new i0(z.tagName);if(O.add(this.options.textNodeName,""),z.tagName!==z.tagExp&&z.attrExpPresent)O[":@"]=this.buildAttributesMap(z.tagExp,X);this.addChild(Z,O,X,Q)}Q=z.closeIndex+1}else if($.substr(Q+1,3)==="!--"){let z=N$($,"-->",Q+4,"Comment is not closed.");if(this.options.commentPropName){let O=$.substring(Q+4,z-2);Y=this.saveTextToParentTag(Y,Z,X),Z.add(this.options.commentPropName,[{[this.options.textNodeName]:O}])}Q=z}else if($.substr(Q+1,2)==="!D"){let z=G.readDocType($,Q);this.docTypeEntities=z.entities,Q=z.i}else if($.substr(Q+1,2)==="!["){let z=N$($,"]]>",Q,"CDATA is not closed.")-2,O=$.substring(Q+9,z);Y=this.saveTextToParentTag(Y,Z,X);let _=this.parseTextData(O,Z.tagname,X,!0,!1,!0,!0);if(_==null)_="";if(this.options.cdataPropName)Z.add(this.options.cdataPropName,[{[this.options.textNodeName]:O}]);else Z.add(this.options.textNodeName,_);Q=z+2}else{let z=kZ($,Q,this.options.removeNSPrefix),O=z.tagName,_=z.rawTagName,K=z.tagExp,j=z.attrExpPresent,C=z.closeIndex;if(this.options.transformTagName){let T=this.options.transformTagName(O);if(K===O)K=T;O=T}if(Z&&Y){if(Z.tagname!=="!xml")Y=this.saveTextToParentTag(Y,Z,X,!1)}let S=Z;if(S&&this.options.unpairedTags.indexOf(S.tagname)!==-1)Z=this.tagsNodeStack.pop(),X=X.substring(0,X.lastIndexOf("."));if(O!==J.tagname)X+=X?"."+O:O;let v=Q;if(this.isItStopNode(this.stopNodesExact,this.stopNodesWildcard,X,O)){let T="";if(K.length>0&&K.lastIndexOf("/")===K.length-1){if(O[O.length-1]==="/")O=O.substr(0,O.length-1),X=X.substr(0,X.length-1),K=O;else K=K.substr(0,K.length-1);Q=z.closeIndex}else if(this.options.unpairedTags.indexOf(O)!==-1)Q=z.closeIndex;else{let E=this.readStopNodeData($,_,C+1);if(!E)throw Error(`Unexpected end of ${_}`);Q=E.i,T=E.tagContent}let k=new i0(O);if(O!==K&&j)k[":@"]=this.buildAttributesMap(K,X);if(T)T=this.parseTextData(T,O,X,!0,j,!0,!0);X=X.substr(0,X.lastIndexOf(".")),k.add(this.options.textNodeName,T),this.addChild(Z,k,X,v)}else{if(K.length>0&&K.lastIndexOf("/")===K.length-1){if(O[O.length-1]==="/")O=O.substr(0,O.length-1),X=X.substr(0,X.length-1),K=O;else K=K.substr(0,K.length-1);if(this.options.transformTagName){let k=this.options.transformTagName(O);if(K===O)K=k;O=k}let T=new i0(O);if(O!==K&&j)T[":@"]=this.buildAttributesMap(K,X);this.addChild(Z,T,X,v),X=X.substr(0,X.lastIndexOf("."))}else{let T=new i0(O);if(this.tagsNodeStack.push(Z),O!==K&&j)T[":@"]=this.buildAttributesMap(K,X);this.addChild(Z,T,X,v),Z=T}Y="",Q=C}}else Y+=$[Q];return J.child};function dH($,J,Z,Y){if(!this.options.captureMetaData)Y=void 0;let X=this.options.updateTag(J.tagname,Z,J[":@"]);if(X===!1);else if(typeof X==="string")J.tagname=X,$.addChild(J,Y);else $.addChild(J,Y)}var sH=function($){if(this.options.processEntities){for(let J in this.docTypeEntities){let Z=this.docTypeEntities[J];$=$.replace(Z.regx,Z.val)}for(let J in this.lastEntities){let Z=this.lastEntities[J];$=$.replace(Z.regex,Z.val)}if(this.options.htmlEntities)for(let J in this.htmlEntities){let Z=this.htmlEntities[J];$=$.replace(Z.regex,Z.val)}$=$.replace(this.ampEntity.regex,this.ampEntity.val)}return $};function oH($,J,Z,Y){if($){if(Y===void 0)Y=J.child.length===0;if($=this.parseTextData($,J.tagname,Z,!1,J[":@"]?Object.keys(J[":@"]).length!==0:!1,Y),$!==void 0&&$!=="")J.add(this.options.textNodeName,$);$=""}return $}function lH($,J,Z,Y){if(J&&J.has(Y))return!0;if($&&$.has(Z))return!0;return!1}function rH($,J,Z=">"){let Y,X="";for(let G=J;G<$.length;G++){let Q=$[G];if(Y){if(Q===Y)Y=""}else if(Q==='"'||Q==="'")Y=Q;else if(Q===Z[0])if(Z[1]){if($[G+1]===Z[1])return{data:X,index:G}}else return{data:X,index:G};else if(Q==="\t")Q=" ";X+=Q}}function N$($,J,Z,Y){let X=$.indexOf(J,Z);if(X===-1)throw Error(Y);else return X+J.length-1}function kZ($,J,Z,Y=">"){let X=rH($,J+1,Y);if(!X)return;let{data:G,index:Q}=X,U=G.search(/\s/),z=G,O=!0;if(U!==-1)z=G.substring(0,U),G=G.substring(U+1).trimStart();let _=z;if(Z){let K=z.indexOf(":");if(K!==-1)z=z.substr(K+1),O=z!==X.data.substr(K+1)}return{tagName:z,tagExp:G,closeIndex:Q,attrExpPresent:O,rawTagName:_}}function iH($,J,Z){let Y=Z,X=1;for(;Z<$.length;Z++)if($[Z]==="<")if($[Z+1]==="/"){let G=N$($,">",Z,`${J} is not closed`);if($.substring(Z+2,G).trim()===J){if(X--,X===0)return{tagContent:$.substring(Y,Z),i:G}}Z=G}else if($[Z+1]==="?")Z=N$($,"?>",Z+1,"StopNode is not closed.");else if($.substr(Z+1,3)==="!--")Z=N$($,"-->",Z+3,"StopNode is not closed.");else if($.substr(Z+1,2)==="![")Z=N$($,"]]>",Z,"StopNode is not closed.")-2;else{let G=kZ($,Z,">");if(G){if((G&&G.tagName)===J&&G.tagExp[G.tagExp.length-1]!=="/")X++;Z=G.closeIndex}}}function xZ($,J,Z){if(J&&typeof $==="string"){let Y=$.trim();if(Y==="true")return!0;else if(Y==="false")return!1;else return DZ($,Z)}else if(pX($))return $;else return""}var fZ=i0.getMetaDataSymbol();function yZ($,J){return lX($,J)}function lX($,J,Z){let Y,X={};for(let G=0;G<$.length;G++){let Q=$[G],U=tH(Q),z="";if(Z===void 0)z=U;else z=Z+"."+U;if(U===J.textNodeName)if(Y===void 0)Y=Q[U];else Y+=""+Q[U];else if(U===void 0)continue;else if(Q[U]){let O=lX(Q[U],J,z),_=eH(O,J);if(Q[fZ]!==void 0)O[fZ]=Q[fZ];if(Q[":@"])aH(O,Q[":@"],z,J);else if(Object.keys(O).length===1&&O[J.textNodeName]!==void 0&&!J.alwaysCreateTextNode)O=O[J.textNodeName];else if(Object.keys(O).length===0)if(J.alwaysCreateTextNode)O[J.textNodeName]="";else O="";if(X[U]!==void 0&&X.hasOwnProperty(U)){if(!Array.isArray(X[U]))X[U]=[X[U]];X[U].push(O)}else if(J.isArray(U,z,_))X[U]=[O];else X[U]=O}}if(typeof Y==="string"){if(Y.length>0)X[J.textNodeName]=Y}else if(Y!==void 0)X[J.textNodeName]=Y;return X}function tH($){let J=Object.keys($);for(let Z=0;Z<J.length;Z++){let Y=J[Z];if(Y!==":@")return Y}}function aH($,J,Z,Y){if(J){let X=Object.keys(J),G=X.length;for(let Q=0;Q<G;Q++){let U=X[Q];if(Y.isArray(U,Z+"."+U,!0,!0))$[U]=[J[U]];else $[U]=J[U]}}}function eH($,J){let{textNodeName:Z}=J,Y=Object.keys($).length;if(Y===0)return!0;if(Y===1&&($[Z]||typeof $[Z]==="boolean"||$[Z]===0))return!0;return!1}class GJ{constructor($){this.externalEntities={},this.options=oX($)}parse($,J){if(typeof $!=="string"&&$.toString)$=$.toString();else if(typeof $!=="string")throw Error("XML data is accepted in String or Bytes[] form.");if(J){if(J===!0)J={};let X=sX($,J);if(X!==!0)throw Error(`${X.err.msg}:${X.err.line}:${X.err.col}`)}let Z=new PJ(this.options);Z.addExternalEntities(this.externalEntities);let Y=Z.parseXml($);if(this.options.preserveOrder||Y===void 0)return Y;else return yZ(Y,this.options)}addEntity($,J){if(J.indexOf("&")!==-1)throw Error("Entity value can't have '&'");else if($.indexOf("&")!==-1||$.indexOf(";")!==-1)throw Error("An entity must be set without '&' and ';'. Eg. use '#xD' for '
'");else if(J==="&")throw Error("An entity with value '&' is not permitted");else this.externalEntities[$]=J}static getMetaDataSymbol(){return i0.getMetaDataSymbol()}}var $W=new GJ,JW={name:"parser",enable:!0,deps:["auth"],handler:async($,J)=>{if(!J.api)return;if(J.api.rawBody){J.body={};return}if(J.req.method==="GET"){let Z=new URL(J.req.url),Y=Object.fromEntries(Z.searchParams);J.body=Y}else if(J.req.method==="POST"){let Z=J.req.headers.get("content-type")||"",Y=new URL(J.req.url),X=Object.fromEntries(Y.searchParams);try{if(Z.includes("application/json")){let G=await J.req.json(),Q={...X,...G};J.body=Q}else if(Z.includes("application/xml")||Z.includes("text/xml")){let G=await J.req.text(),Q=$W.parse(G),U=Object.keys(Q)[0],z=U&&typeof Q[U]==="object"?Q[U]:Q,O={...X,...z};J.body=O}else{J.response=j$(J,"\u65E0\u6548\u7684\u8BF7\u6C42\u53C2\u6570\u683C\u5F0F",1,null,{location:"content-type",value:Z},"parser");return}}catch{J.response=j$(J,"\u65E0\u6548\u7684\u8BF7\u6C42\u53C2\u6570\u683C\u5F0F",1,null,{location:"body",reason:Z.includes("application/json")?"invalid_json":Z.includes("xml")?"invalid_xml":"invalid_body"},"parser");return}}}},rX=JW;class p0{static apisAll(){return"apis:all"}static menusAll(){return"menus:all"}static roleInfo($){return`role:info:${$}`}static roleApis($){return`role:apis:${$}`}}$0();var ZW={name:"permission",enable:!0,deps:["validator"],handler:async($,J)=>{if(!J.api)return;if(J.api.auth===!1)return;if(typeof J.user.id!=="number"){J.response=j$(J,"\u672A\u767B\u5F55",1,null,null,"auth");return}if(J.user.roleCode==="dev")return;let Z=J.route,Y=J.user.roleCode,X=!1;if(Y&&$.redis)try{let G=p0.roleApis(Y);X=await $.redis.sismember(G,Z)}catch(G){L.error({event:"hook_permission_redis_error",apiPath:Z,roleCode:Y,err:G,msg:"hook permission redis error"}),X=!1}if(!X){let G=typeof J.api.name==="string"&&J.api.name.length>0?J.api.name:null,Q=typeof Z==="string"&&Z.length>0?Z:null,U=G?G:Q?Q:"\u672A\u77E5\u63A5\u53E3";J.response=j$(J,`\u65E0\u6743\u8BBF\u95EE ${U} \u63A5\u53E3`,1,null,{apiLabel:U},"permission");return}}},iX=ZW;var gZ={number:"^\\d+$",integer:"^-?\\d+$",float:"^-?\\d+(\\.\\d+)?$",positive:"^[1-9]\\d*$",negative:"^-\\d+$",zero:"^0$",word:"^[a-zA-Z]+$",alphanumeric:"^[a-zA-Z0-9]+$",alphanumeric_:"^[a-zA-Z0-9_]+$",alphanumericDash_:"^[a-zA-Z0-9_-]+$",lowercase:"^[a-z]+$",uppercase:"^[A-Z]+$",chinese:"^[\\u4e00-\\u9fa5]+$",chineseWord:"^[\\u4e00-\\u9fa5a-zA-Z]+$",email:"^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$",phone:"^1[3-9]\\d{9}$",telephone:"^0\\d{2,3}-?\\d{7,8}$",url:"^https?://",ip:"^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$",ipv6:"^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$",domain:"^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}$",uuid:"^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",hex:"^[0-9a-fA-F]+$",base64:"^[A-Za-z0-9+/=]+$",md5:"^[a-f0-9]{32}$",sha1:"^[a-f0-9]{40}$",sha256:"^[a-f0-9]{64}$",date:"^\\d{4}-\\d{2}-\\d{2}$",time:"^\\d{2}:\\d{2}:\\d{2}$",datetime:"^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}",year:"^\\d{4}$",month:"^(0[1-9]|1[0-2])$",day:"^(0[1-9]|[12]\\d|3[01])$",variable:"^[a-zA-Z_][a-zA-Z0-9_]*$",constant:"^[A-Z][A-Z0-9_]*$",package:"^[a-z][a-z0-9-]*$",idCard:"^\\d{17}[\\dXx]$",passport:"^[a-zA-Z0-9]{5,17}$",bankCard:"^\\d{16,19}$",wechat:"^[a-zA-Z][a-zA-Z0-9_-]{5,19}$",qq:"^[1-9]\\d{4,10}$",alipay:"^(1[3-9]\\d{9}|[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$",username:"^[a-zA-Z][a-zA-Z0-9_]{3,19}$",nickname:"^[\\u4e00-\\u9fa5a-zA-Z0-9]{2,20}$",passwordWeak:"^.{6,}$",passwordMedium:"^(?=.*[a-zA-Z])(?=.*\\d).{8,}$",passwordStrong:"^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$",licensePlate:"^[\u4EAC\u6D25\u6CAA\u6E1D\u5180\u8C6B\u4E91\u8FBD\u9ED1\u6E58\u7696\u9C81\u65B0\u82CF\u6D59\u8D63\u9102\u6842\u7518\u664B\u8499\u9655\u5409\u95FD\u8D35\u7CA4\u9752\u85CF\u5DDD\u5B81\u743C\u4F7F\u9886][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9\u6302\u5B66\u8B66\u6E2F\u6FB3]$",postalCode:"^\\d{6}$",semver:"^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.]+)?(\\+[a-zA-Z0-9.]+)?$",colorHex:"^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$",empty:"^$",notempty:".+"},tX=new Map;function YW($){if($.startsWith("@")){let J=$.slice(1);return gZ[J]||$}return $}function aX($,J){let Z=YW($),Y=`${Z}:${J||""}`,X=tX.get(Y);if(!X)X=new RegExp(Z,J),tX.set(Y,X);return X}m0();class hZ{static validate($,J,Z=[]){let Y={};if(!n($))return this.buildResult({_error:"\u6570\u636E\u5FC5\u987B\u662F\u5BF9\u8C61\u683C\u5F0F"});if(!n(J))return this.buildResult({_error:"\u9A8C\u8BC1\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61\u683C\u5F0F"});let X=$,G=J;for(let Q of Z){let U=X[Q];if(U===void 0||U===null){let z=G[Q],O=n(z)&&typeof z.name==="string"?z.name:Q;Y[Q]=`${O}\u4E3A\u5FC5\u586B\u9879`}}for(let[Q,U]of Object.entries(G)){if(Y[Q])continue;if(X[Q]===void 0&&!Z.includes(Q))continue;if(!n(U)){Y[Q]=`${Q}\u9A8C\u8BC1\u89C4\u5219\u5FC5\u987B\u662F\u5BF9\u8C61\u683C\u5F0F`;continue}let{name:z,type:O}=U;if(typeof z!=="string"||typeof O!=="string"){Y[Q]=`${Q}\u9A8C\u8BC1\u89C4\u5219\u65E0\u6548`;continue}let _={name:z,type:O},K=U.min;if(typeof K==="number"||K===null)_.min=K;let j=U.max;if(typeof j==="number"||j===null)_.max=j;let C=U.default;if(C===null||typeof C==="string"||typeof C==="number"||typeof C==="boolean"||Array.isArray(C)||n(C))_.default=C;let S=U.detail;if(typeof S==="string")_.detail=S;let v=U.index;if(typeof v==="boolean")_.index=v;let T=U.unique;if(typeof T==="boolean")_.unique=T;let k=U.nullable;if(typeof k==="boolean")_.nullable=k;let E=U.unsigned;if(typeof E==="boolean")_.unsigned=E;let w=U.regexp;if(typeof w==="string"||w===null)_.regexp=w;let f=this.checkField(X[Q],_,Q);if(f)Y[Q]=f}return this.buildResult(Y)}static single($,J){let Z=H$(J),Y=Z.type,X=Z.default;if($===void 0||$===null||$==="")return{value:this.defaultFor(Y,X),error:null};let G=this.convert($,Y);if(G.error)return{value:null,error:G.error};let Q=this.checkRule(G.value,J);if(Q)return{value:null,error:Q};return{value:G.value,error:null}}static buildResult($){let J=Object.values($),Z=Object.keys($),Y=J.length>0;return{code:Y?1:0,failed:Y,firstError:Y?J[0]??null:null,errors:J,errorFields:Z,fieldErrors:$}}static checkField($,J,Z){let Y=J.name||Z,X=this.convert($,J.type);if(X.error)return`${Y}${X.error}`;let G=this.checkRule(X.value,J);return G?`${Y}${G}`:null}static convert($,J){switch(J.toLowerCase()){case"number":if(typeof $==="number")return Number.isNaN($)||!isFinite($)?{value:null,error:"\u5FC5\u987B\u662F\u6709\u6548\u6570\u5B57"}:{value:$,error:null};if(typeof $==="string"){let Z=Number($);return Number.isNaN(Z)||!isFinite(Z)?{value:null,error:"\u5FC5\u987B\u662F\u6570\u5B57"}:{value:Z,error:null}}return{value:null,error:"\u5FC5\u987B\u662F\u6570\u5B57"};case"string":case"text":return typeof $==="string"?{value:$,error:null}:{value:null,error:"\u5FC5\u987B\u662F\u5B57\u7B26\u4E32"};case"array_string":case"array_text":return Array.isArray($)?{value:$,error:null}:{value:null,error:"\u5FC5\u987B\u662F\u6570\u7EC4"};case"array_number_string":case"array_number_text":if(!Array.isArray($))return{value:null,error:"\u5FC5\u987B\u662F\u6570\u7EC4"};for(let Z of $)if(typeof Z!=="number"||!isFinite(Z))return{value:null,error:"\u6570\u7EC4\u5143\u7D20\u5FC5\u987B\u662F\u6570\u5B57"};return{value:$,error:null};default:return{value:$,error:null}}}static checkRule($,J){let Z=H$(J),Y=Z.type,X=Z.min,G=Z.max,Q=Z.regexp,U=this.resolveRegex(Q);switch(Y.toLowerCase()){case"number":if(typeof $!=="number")return"\u5FC5\u987B\u662F\u6570\u5B57";if(X!==null&&$<X)return`\u4E0D\u80FD\u5C0F\u4E8E${X}`;if(G!==null&&G>0&&$>G)return`\u4E0D\u80FD\u5927\u4E8E${G}`;if(U&&!this.testRegex(U,String($)))return"\u683C\u5F0F\u4E0D\u6B63\u786E";break;case"string":case"text":if(typeof $!=="string")return"\u5FC5\u987B\u662F\u5B57\u7B26\u4E32";if(X!==null&&$.length<X)return`\u957F\u5EA6\u4E0D\u80FD\u5C11\u4E8E${X}\u4E2A\u5B57\u7B26`;if(G!==null&&G>0&&$.length>G)return`\u957F\u5EA6\u4E0D\u80FD\u8D85\u8FC7${G}\u4E2A\u5B57\u7B26`;if(U&&!this.testRegex(U,$))return"\u683C\u5F0F\u4E0D\u6B63\u786E";break;case"array_string":case"array_text":case"array_number_string":case"array_number_text":if(!Array.isArray($))return"\u5FC5\u987B\u662F\u6570\u7EC4";if(X!==null&&$.length<X)return`\u81F3\u5C11\u9700\u8981${X}\u4E2A\u5143\u7D20`;if(G!==null&&G>0&&$.length>G)return`\u6700\u591A\u53EA\u80FD\u6709${G}\u4E2A\u5143\u7D20`;if(U){for(let z of $)if(!this.testRegex(U,String(z)))return"\u5143\u7D20\u683C\u5F0F\u4E0D\u6B63\u786E"}break}return null}static resolveRegex($){if(!$)return null;if($.startsWith("@")){let J=$.substring(1);return gZ[J]||$}return $}static testRegex($,J){try{return aX($).test(J)}catch{return!1}}static defaultFor($,J){if(J!==null&&J!==void 0){if(($==="array_string"||$==="array_text"||$==="array_number_string"||$==="array_number_text")&&typeof J==="string"){if(J==="[]")return[];try{let Z=JSON.parse(J);return Array.isArray(Z)?Z:[]}catch{return[]}}if($==="number"&&typeof J==="string"){let Z=Number(J);return isNaN(Z)?0:Z}return J}switch($.toLowerCase()){case"number":return 0;case"array_string":case"array_text":case"array_number_string":case"array_number_text":return[];default:return""}}}m0();var XW={name:"validator",enable:!0,deps:["parser"],handler:async($,J)=>{if(!J.api)return;if(!J.api.fields)return;if(n(J.api.fields)){let Y=n(J.body)?J.body:{},X={};for(let[G,Q]of Object.entries(J.api.fields)){let U=H$(Q),z=Y[G];if(z===void 0){let O=c(G);if(Y[O]!==void 0)z=Y[O]}if(z===void 0&&U.default!==null)z=U.default;if(z!==void 0)X[G]=z}J.body=X}let Z=hZ.validate(J.body,J.api.fields,J.api.required||[]);if(Z.code!==0){J.response=j$(J,Z.firstError||"\u53C2\u6570\u9A8C\u8BC1\u5931\u8D25",1,null,Z.fieldErrors,"validator");return}}},eX=XW;$0();class bZ{db;redis;constructor($){this.db=$.db,this.redis=$.redis}assertApiPathname($,J){if(typeof $!=="string")throw Error(`${J} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32`);let Z=$.trim();if(!Z)throw Error(`${J} \u4E0D\u5141\u8BB8\u4E3A\u7A7A\u5B57\u7B26\u4E32`);if(/^(GET|POST|PUT|PATCH|DELETE|OPTIONS|HEAD)\b/i.test(Z))throw Error(`${J} \u4E0D\u5141\u8BB8\u5305\u542B method \u524D\u7F00\uFF0C\u5E94\u4E3A url.pathname\uFF08\u4F8B\u5982 /api/app/xxx\uFF09`);if(!Z.startsWith("/"))throw Error(`${J} \u5FC5\u987B\u662F pathname\uFF08\u4EE5 / \u5F00\u5934\uFF09`);if(Z.includes(" "))throw Error(`${J} \u4E0D\u5141\u8BB8\u5305\u542B\u7A7A\u683C`);return Z}assertApiPathList($,J){if($===null||$===void 0)return[];let Z=$;if(typeof Z==="string"){let X=Z.trim();if(X===""||X==="null")return[];if(X.startsWith("[")&&X.endsWith("]"))try{Z=JSON.parse(X)}catch{throw Error(`\u89D2\u8272\u6743\u9650\u6570\u636E\u4E0D\u5408\u6CD5\uFF1Aaddon_admin_role.apis JSON \u89E3\u6790\u5931\u8D25\uFF0CroleCode=${J}`)}}if(!Array.isArray(Z))throw Error(`\u89D2\u8272\u6743\u9650\u6570\u636E\u4E0D\u5408\u6CD5\uFF1Aaddon_admin_role.apis \u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u6570\u7EC4\u6216 JSON \u6570\u7EC4\u5B57\u7B26\u4E32\uFF0CroleCode=${J}\uFF0Ctype=${typeof Z}`);let Y=[];for(let X of Z)Y.push(this.assertApiPathname(X,`\u89D2\u8272\u6743\u9650\u6570\u636E\u4E0D\u5408\u6CD5\uFF1Aaddon_admin_role.apis \u5143\u7D20\uFF0CroleCode=${J}`));return Y}async cacheApis(){try{if(!(await this.db.tableExists("addon_admin_api")).data){L.warn("\u26A0\uFE0F \u63A5\u53E3\u8868\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u63A5\u53E3\u7F13\u5B58");return}let J=await this.db.getAll({table:"addon_admin_api"});if(await this.redis.setObject(p0.apisAll(),J.data.lists)===null)L.warn("\u26A0\uFE0F \u63A5\u53E3\u7F13\u5B58\u5931\u8D25")}catch($){L.error({err:$,msg:"\u26A0\uFE0F \u63A5\u53E3\u7F13\u5B58\u5F02\u5E38"})}}async cacheMenus(){try{if(!(await this.db.tableExists("addon_admin_menu")).data){L.warn("\u26A0\uFE0F \u83DC\u5355\u8868\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u83DC\u5355\u7F13\u5B58");return}let J=await this.db.getAll({table:"addon_admin_menu"});if(await this.redis.setObject(p0.menusAll(),J.data.lists)===null)L.warn("\u26A0\uFE0F \u83DC\u5355\u7F13\u5B58\u5931\u8D25")}catch($){L.warn({err:$,msg:"\u26A0\uFE0F \u83DC\u5355\u7F13\u5B58\u5F02\u5E38"})}}async rebuildRoleApiPermissions(){try{if(!(await this.db.tableExists("addon_admin_role")).data){L.warn("\u26A0\uFE0F \u89D2\u8272\u8868\u4E0D\u5B58\u5728\uFF0C\u8DF3\u8FC7\u89D2\u8272\u6743\u9650\u7F13\u5B58");return}let J=await this.db.getAll({table:"addon_admin_role",fields:["code","apis"]}),Z=new Map;for(let Q of J.data.lists){if(!Q?.code)continue;let U=this.assertApiPathList(Q.apis,Q.code);Z.set(Q.code,U)}let Y=Array.from(Z.keys());if(Y.length===0){L.info("\u2705 \u6CA1\u6709\u9700\u8981\u7F13\u5B58\u7684\u89D2\u8272\u6743\u9650");return}let X=Y.map((Q)=>p0.roleApis(Q));await this.redis.delBatch(X);let G=[];for(let Q of Y){let U=Z.get(Q)||[],z=Array.from(new Set(U)).sort();if(z.length>0)G.push({key:p0.roleApis(Q),members:z})}if(G.length>0)await this.redis.saddBatch(G)}catch($){throw L.error({err:$,msg:"\u26A0\uFE0F \u89D2\u8272\u6743\u9650\u7F13\u5B58\u5F02\u5E38\uFF08\u5C06\u963B\u65AD\u542F\u52A8\uFF09"}),$}}async refreshRoleApiPermissions($,J){if(!$||typeof $!=="string")throw Error("roleCode \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32");if(!Array.isArray(J))throw Error("apiPaths \u5FC5\u987B\u662F\u6570\u7EC4");let Z=J.map((G)=>this.assertApiPathname(G,`refreshRoleApiPermissions: apiPaths \u5143\u7D20\uFF0CroleCode=${$}`)),Y=p0.roleApis($);if(Z.length===0){await this.redis.del(Y);return}let X=Array.from(new Set(Z));if(await this.redis.del(Y),X.length>0)await this.redis.sadd(Y,X)}async cacheAll(){await this.cacheApis(),await this.cacheMenus(),await this.rebuildRoleApiPermissions()}async getApis(){try{return await this.redis.getObject(p0.apisAll())||[]}catch($){return L.error({err:$,msg:"\u83B7\u53D6\u63A5\u53E3\u7F13\u5B58\u5931\u8D25"}),[]}}async getMenus(){try{return await this.redis.getObject(p0.menusAll())||[]}catch($){return L.error({err:$,msg:"\u83B7\u53D6\u83DC\u5355\u7F13\u5B58\u5931\u8D25"}),[]}}async getRolePermissions($){try{return await this.redis.smembers(p0.roleApis($))||[]}catch(J){return L.error({err:J,roleCode:$,msg:"\u83B7\u53D6\u89D2\u8272\u6743\u9650\u7F13\u5B58\u5931\u8D25"}),[]}}async checkRolePermission($,J){try{let Z=this.assertApiPathname(J,"checkRolePermission: apiPath");return await this.redis.sismember(p0.roleApis($),Z)}catch(Z){return L.error({err:Z,roleCode:$,msg:"\u68C0\u67E5\u89D2\u8272\u6743\u9650\u5931\u8D25"}),!1}}async deleteRolePermissions($){try{if(await this.redis.del(p0.roleApis($))>0)return L.info(`\u2705 \u5DF2\u5220\u9664\u89D2\u8272 ${$} \u7684\u6743\u9650\u7F13\u5B58`),!0;return!1}catch(J){return L.error({err:J,roleCode:$,msg:"\u5220\u9664\u89D2\u8272\u6743\u9650\u7F13\u5B58\u5931\u8D25"}),!1}}}var GW={name:"cache",enable:!0,deps:["logger","redis","db"],async handler($){if(!$.db)throw Error("\u7F13\u5B58\u521D\u59CB\u5316\u5931\u8D25\uFF1Actx.db \u672A\u521D\u59CB\u5316");if(!$.redis)throw Error("\u7F13\u5B58\u521D\u59CB\u5316\u5931\u8D25\uFF1Actx.redis \u672A\u521D\u59CB\u5316");return new bZ({db:$.db,redis:$.redis})}},$G=GW;var QW={name:"cipher",enable:!0,deps:[],handler:()=>{return g$}},JG=QW;var HW={name:"config",enable:!0,deps:[],handler:($)=>{return $.config}},ZG=HW;function EJ($,J=["id","pid","sort"]){if($===null||$===void 0)return $;let Z=BigInt(Number.MAX_SAFE_INTEGER),Y=BigInt(Number.MIN_SAFE_INTEGER),X=(G)=>{let Q={};for(let[U,z]of Object.entries(G))Q[U]=z;for(let[U,z]of Object.entries(Q)){if(z===void 0||z===null)continue;if(!(J.includes(U)||U.endsWith("Id")||U.endsWith("_id")||U.endsWith("At")||U.endsWith("_at")))continue;let _=null;if(typeof z==="bigint")_=z;else if(typeof z==="string"){if(!/^-?\d+$/.test(z))continue;try{_=BigInt(z)}catch{continue}}else continue;if(_>Z||_<Y)throw Error(`BIGINT \u5B57\u6BB5\u8D85\u51FA JS \u5B89\u5168\u6574\u6570\u8303\u56F4\uFF0C\u8BF7\u6539\u7528 bigint/string \u6216\u8C03\u6574\u5B57\u6BB5\u8BBE\u8BA1 (field: ${U}, value: ${String(z)})`);Q[U]=Number(_)}return Q};if(Array.isArray($))return $.map((G)=>X(G));if(typeof $==="object")return X($);return $}function cZ($){return $!==null&&typeof $==="object"&&!Array.isArray($)}function WW($){return Array.isArray($)}function E$($,J={}){let{pickKeys:Z,omitKeys:Y,keepValues:X,excludeValues:G,keepMap:Q}=J,U=(z)=>{let O={},_=Object.keys(z);if(Z&&Z.length)_=_.filter((K)=>Z.includes(K));if(Y&&Y.length)_=_.filter((K)=>!Y.includes(K));for(let K of _){let j=z[K];if(Q&&K in Q){if(Object.is(Q[K],j)){O[K]=j;continue}}if(X&&X.length&&!X.includes(j))continue;if(G&&G.length&&G.includes(j))continue;O[K]=j}return O};if(WW($))return $.map((z)=>cZ(z)?U(z):z).filter((z)=>{if(cZ(z))return Object.keys(z).length>0;return!0});if(cZ($))return U($);return $}m0();m0();class Y0{static SAFE_IDENTIFIER_RE=/^[a-zA-Z_][a-zA-Z0-9_]*$/;static assertNonEmptyString($,J){if(typeof $!=="string")throw Error(`${J} \u5FC5\u987B\u662F\u5B57\u7B26\u4E32 (value: ${String($)})`);if(!$.trim())throw Error(`${J} \u4E0D\u80FD\u4E3A\u7A7A`)}static assertNoUndefinedParam($,J){if($===void 0)throw Error(`${J} \u4E0D\u80FD\u4E3A undefined`)}static startsWithQuote($){let J=$.trim();return J.startsWith("`")||J.startsWith('"')}static isQuotedIdentPaired($){let J=$.trim();if(J.length<2)return!1;let Z=J[0],Y=J[J.length-1];if(Z==="`"&&Y==="`")return!0;if(Z==='"'&&Y==='"')return!0;return!1}static assertPairedQuotedIdentIfStartsWithQuote($,J){if(Y0.startsWithQuote($)&&!Y0.isQuotedIdentPaired($))throw Error(`${J} \u5F15\u7528\u4E0D\u5B8C\u6574\uFF0C\u8BF7\u4F7F\u7528\u6210\u5BF9\u7684 \`...\` \u6216 "..." (value: ${$})`)}static assertSafeIdentifierPart($,J){if(!Y0.SAFE_IDENTIFIER_RE.test($))throw Error(`\u65E0\u6548\u7684 ${J} \u6807\u8BC6\u7B26: ${$}`)}static assertSafeAlias($){if(Y0.isQuotedIdentPaired($))return;if(!Y0.SAFE_IDENTIFIER_RE.test($))throw Error(`\u65E0\u6548\u7684\u5B57\u6BB5\u522B\u540D: ${$}`)}static assertNoExprField($){if(typeof $!=="string")return;let J=$.trim();if(!J)return;if(J.includes("(")||J.includes(")"))throw Error(`\u5B57\u6BB5\u5305\u542B\u51FD\u6570/\u8868\u8FBE\u5F0F\uFF0C\u8BF7\u4F7F\u7528 selectRaw/whereRaw (field: ${J})`)}static assertNoUndefinedInRecord($,J){for(let[Z,Y]of Object.entries($))if(Y===void 0)throw Error(`${J} \u5B58\u5728 undefined \u5B57\u6BB5\u503C (field: ${Z})`)}static assertBatchInsertRowsConsistent($,J){if(!Array.isArray($))throw Error("\u6279\u91CF\u63D2\u5165 rows \u5FC5\u987B\u662F\u6570\u7EC4");if($.length===0)throw Error(`\u63D2\u5165\u6570\u636E\u4E0D\u80FD\u4E3A\u7A7A (table: ${J.table})`);let Z=$[0];if(!Z||typeof Z!=="object"||Array.isArray(Z))throw Error(`\u6279\u91CF\u63D2\u5165\u7684\u6BCF\u4E00\u884C\u5FC5\u987B\u662F\u5BF9\u8C61 (table: ${J.table}, rowIndex: 0)`);let Y=Object.keys(Z);if(Y.length===0)throw Error(`\u63D2\u5165\u6570\u636E\u5FC5\u987B\u81F3\u5C11\u6709\u4E00\u4E2A\u5B57\u6BB5 (table: ${J.table})`);let X=new Set(Y);for(let G=0;G<$.length;G++){let Q=$[G];if(!Q||typeof Q!=="object"||Array.isArray(Q))throw Error(`\u6279\u91CF\u63D2\u5165\u7684\u6BCF\u4E00\u884C\u5FC5\u987B\u662F\u5BF9\u8C61 (table: ${J.table}, rowIndex: ${G})`);let U=Object.keys(Q);if(U.length!==Y.length)throw Error(`\u6279\u91CF\u63D2\u5165\u6BCF\u884C\u5B57\u6BB5\u5FC5\u987B\u4E00\u81F4 (table: ${J.table}, rowIndex: ${G})`);for(let z of U)if(!X.has(z))throw Error(`\u6279\u91CF\u63D2\u5165\u6BCF\u884C\u5B57\u6BB5\u5FC5\u987B\u4E00\u81F4 (table: ${J.table}, rowIndex: ${G}, extraField: ${z})`);for(let z of Y){if(!(z in Q))throw Error(`\u6279\u91CF\u63D2\u5165\u7F3A\u5C11\u5B57\u6BB5 (table: ${J.table}, rowIndex: ${G}, field: ${z})`);Y0.assertNoUndefinedParam(Q[z],`\u6279\u91CF\u63D2\u5165\u5B57\u6BB5\u503C (table: ${J.table}, rowIndex: ${G}, field: ${z})`)}}return Y}}class h{static parseTableRef($){if(typeof $!=="string")throw Error(`tableRef \u5FC5\u987B\u662F\u5B57\u7B26\u4E32 (tableRef: ${String($)})`);let J=$.trim();if(!J)throw Error("tableRef \u4E0D\u80FD\u4E3A\u7A7A");let Z=J.split(/\s+/).filter((U)=>U.length>0);if(Z.length===0)throw Error("tableRef \u4E0D\u80FD\u4E3A\u7A7A");if(Z.length>2)throw Error(`\u4E0D\u652F\u6301\u7684\u8868\u5F15\u7528\u683C\u5F0F\uFF08\u5305\u542B\u8FC7\u591A\u7247\u6BB5\uFF09\u3002\u8BF7\u4F7F\u7528\u6700\u7B80\u5F62\u5F0F\uFF1Atable \u6216 table alias \u6216 schema.table \u6216 schema.table alias (tableRef: ${J})`);let Y=Z[0];if(typeof Y!=="string"||Y.trim()==="")throw Error(`tableRef \u89E3\u6790\u5931\u8D25\uFF1A\u7F3A\u5C11\u8868\u540D (tableRef: ${J})`);let X=null;if(Z.length===2){let U=Z[1];if(typeof U!=="string"||U.trim()==="")throw Error(`tableRef \u89E3\u6790\u5931\u8D25\uFF1A\u7F3A\u5C11 alias (tableRef: ${J})`);X=U}let G=Y.split(".");if(G.length>2)throw Error(`\u4E0D\u652F\u6301\u7684\u8868\u5F15\u7528\u683C\u5F0F\uFF08schema \u5C42\u7EA7\u8FC7\u6DF1\uFF09 (tableRef: ${J})`);if(G.length===2){let U=G[0],z=G[1];if(typeof U!=="string"||U.trim()==="")throw Error(`tableRef \u89E3\u6790\u5931\u8D25\uFF1Aschema \u4E3A\u7A7A (tableRef: ${J})`);if(typeof z!=="string"||z.trim()==="")throw Error(`tableRef \u89E3\u6790\u5931\u8D25\uFF1Atable \u4E3A\u7A7A (tableRef: ${J})`);return{schema:U,table:z,alias:X}}let Q=G[0];if(typeof Q!=="string"||Q.trim()==="")throw Error(`tableRef \u89E3\u6790\u5931\u8D25\uFF1Atable \u4E3A\u7A7A (tableRef: ${J})`);return{schema:null,table:Q,alias:X}}static normalizeTableRef($){let J=h.parseTableRef($),Z=J.schema?c(J.schema):null,Y=c(J.table),X=Z?`${Z}.${Y}`:Y;if(J.alias)X=`${X} ${J.alias}`;return X}static getJoinMainQualifier($){let J=h.parseTableRef($);if(J.alias)return J.alias;return c(J.table)}static async fieldsToSnake($,J,Z){if(!J||!Array.isArray(J))return["*"];let Y=h.validateAndClassifyFields(J);if(Y.type==="all")return["*"];if(Y.type==="include")return Y.fields.map((X)=>{return h.processJoinField(X)});if(Y.type==="exclude"){let X=await Z($),G=Y.fields.map((U)=>c(U)),Q=X.filter((U)=>!G.includes(U));if(Q.length===0)throw Error(`\u6392\u9664\u5B57\u6BB5\u540E\u6CA1\u6709\u5269\u4F59\u5B57\u6BB5\u53EF\u67E5\u8BE2\u3002\u8868: ${$}, \u6392\u9664: ${G.join(", ")}`);return Q}return["*"]}static validateAndClassifyFields($){if(!$||$.length===0)return{type:"all",fields:[]};if($.some((Y)=>Y==="*"))throw Error("fields \u4E0D\u652F\u6301 * \u661F\u53F7\uFF0C\u8BF7\u4F7F\u7528\u7A7A\u6570\u7EC4 [] \u6216\u4E0D\u4F20\u53C2\u6570\u8868\u793A\u67E5\u8BE2\u6240\u6709\u5B57\u6BB5");if($.some((Y)=>!Y||typeof Y!=="string"||Y.trim()===""))throw Error("fields \u4E0D\u80FD\u5305\u542B\u7A7A\u5B57\u7B26\u4E32\u6216\u65E0\u6548\u503C");for(let Y of $){let X=Y.startsWith("!")?Y.substring(1):Y;Y0.assertNoExprField(X)}let J=$.filter((Y)=>!Y.startsWith("!")),Z=$.filter((Y)=>Y.startsWith("!"));if(J.length>0&&Z.length===0)return{type:"include",fields:J};if(Z.length>0&&J.length===0)return{type:"exclude",fields:Z.map((X)=>X.substring(1))};throw Error(`fields \u4E0D\u80FD\u540C\u65F6\u5305\u542B\u666E\u901A\u5B57\u6BB5\u548C\u6392\u9664\u5B57\u6BB5\uFF08! \u5F00\u5934\uFF09\u3002\u53EA\u80FD\u4F7F\u7528\u4EE5\u4E0B3\u79CD\u65B9\u5F0F\u4E4B\u4E00\uFF1A
|
package/dist/sync/syncTable.js
CHANGED
|
@@ -385,6 +385,13 @@ export class SyncTable {
|
|
|
385
385
|
}
|
|
386
386
|
if (cBase === "varchar" && (nBase === "text" || nBase === "mediumtext" || nBase === "longtext"))
|
|
387
387
|
return true;
|
|
388
|
+
// CHAR <-> VARCHAR:允许互转。
|
|
389
|
+
// 说明:
|
|
390
|
+
// - 该变更通常属于“等价/轻微变更”(尤其是相同长度时),但仍可能受字符集/排序规则/长度等影响。
|
|
391
|
+
// - 是否会截断、是否会填充空格等,交由 MySQL 自身规则处理(可能成功,也可能失败)。
|
|
392
|
+
if ((cBase === "char" && nBase === "varchar") || (cBase === "varchar" && nBase === "char")) {
|
|
393
|
+
return true;
|
|
394
|
+
}
|
|
388
395
|
return false;
|
|
389
396
|
}
|
|
390
397
|
static compareFieldDefinition(existingColumn, fieldDef) {
|
|
@@ -646,10 +653,19 @@ export class SyncTable {
|
|
|
646
653
|
const typeMapping = SyncTable.getTypeMapping();
|
|
647
654
|
const expectedType = typeMapping[fieldDef.type]?.toLowerCase() || "";
|
|
648
655
|
if (!SyncTable.isCompatibleTypeChange(currentType, expectedType)) {
|
|
649
|
-
const errorMsg = [`禁止字段类型变更: ${tableName}.${dbFieldName}`, `当前类型: ${typeChange?.current}`, `目标类型: ${typeChange?.expected}`, "说明: 仅允许宽化型变更(如 INT->BIGINT, VARCHAR->TEXT
|
|
656
|
+
const errorMsg = [`禁止字段类型变更: ${tableName}.${dbFieldName}`, `当前类型: ${typeChange?.current}`, `目标类型: ${typeChange?.expected}`, "说明: 仅允许宽化型变更(如 INT->BIGINT, VARCHAR->TEXT),以及 CHAR/VARCHAR 互转;其他类型变更需要手动处理"].join("\n");
|
|
650
657
|
throw new Error(errorMsg);
|
|
651
658
|
}
|
|
652
|
-
|
|
659
|
+
let compatLabel = "";
|
|
660
|
+
if ((currentType === "char" && expectedType === "varchar") || (currentType === "varchar" && expectedType === "char")) {
|
|
661
|
+
compatLabel = "char/varchar互转";
|
|
662
|
+
}
|
|
663
|
+
if (compatLabel) {
|
|
664
|
+
compatibleTypeChanges.push(`${dbFieldName}: ${currentType} -> ${expectedType} (${compatLabel})`);
|
|
665
|
+
}
|
|
666
|
+
else {
|
|
667
|
+
compatibleTypeChanges.push(`${dbFieldName}: ${currentType} -> ${expectedType}`);
|
|
668
|
+
}
|
|
653
669
|
}
|
|
654
670
|
if (defaultChanged) {
|
|
655
671
|
const actualDefault = SyncTable.resolveDefaultValue(fieldDef.default ?? null, fieldDef.type);
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.15.
|
|
4
|
-
"gitHead": "
|
|
3
|
+
"version": "3.15.8",
|
|
4
|
+
"gitHead": "2782f6b8da3a8c58ab2a6208226083c21a230c7e",
|
|
5
5
|
"private": false,
|
|
6
6
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
7
7
|
"keywords": [
|