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,IACX,KAAK,OAAO,OAAM,IAAM,KAAU,IAEtC,OAAO,KAAK,+BACN,KAAK,GAAG,aACd,OAAO,KAAK,kCACN,KAAK,MAAM,aACjB,OAAO,KAAK,iCACN,KAAK,OAAO,iBAClB,MAAM,EAAW,YAAY,MAAQ,EACrC,OAAO,KAAK,kBAAkB,EAAS,QAAQ,QAC/C,KAAK,UAAW,CACpB,CACA,WAAM,SACI,KAAK,OACX,MAAM,GAAM,IAAI,MACX,KAAI,MAAO,EAAK,KACjB,EAAI,IAAI,MAAO,YACT,GAAM,IAEX,MAAM,OAAQ,SACd,MAAM,SAAU,aAChB,MAAM,gBAAgB,IAAI,MAAO,MAAM,IAAK,6BAC3C,KAAK,SAAS,YAAa,GACjC,MAAM,EAAS,KAAK,OAAO,IAAI,UAC/B,GAAI,EACA,IAEI,WADoB,KAAK,IACd,cACP,MAAM,IAAI,MAAM,+BACpB,EAAI,IAAI,IAAK,YAAY,CAAE,KAAM,KAAW,MAAO,GAAQ,EAAI,SAAS,IAAK,OAC7E,OAAO,KAAK,kBAAkB,KAClC,CACA,MAAO,GACH,OAAO,KAAK,YAAY,iBAAsB,IAClD,CAEJ,KAAK,OAAS,MAAM,CAChB,MAAO,EAAI,MACX,KAAM,KAAK,OAAO,IAAI,UAE1B,OAAO,KAAK,4BAA4B,KAAK,OAAO,IAAI,UAC5D,QAEK,KAAK,mBACL,KAAK,uBACL,KAAK,yBACL,KAAK,0BACL,KAAK,8BACL,KAAK,sBACL,KAAK,yBACL,KAAK,0BACL,KAAK,yBACL,KAAK","file":"/npm/@uaaa/server@0.9.0/lib/index.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.39.0.\n * Original file: /npm/@uaaa/server@0.9.0/lib/index.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","import { serve } from '@hono/node-server';\nimport { serveStatic } from '@hono/node-server/serve-static';\nimport { Hono } from 'hono';\nimport { Hookable } from 'hookable';\nimport { stat } from 'node:fs/promises';\nimport { rootApi } from './api/index.js';\nimport { CacheManager } from './cache/index.js';\nimport { ClaimManager } from './claim/index.js';\nimport { ConfigManager } from './config/index.js';\nimport { CredentialManager } from './credential/index.js';\nimport { DbManager } from './db/index.js';\nimport { OAuthManager } from './oauth/_common.js';\nimport { oauthRouter, oauthWellKnownRouter } from './oauth/index.js';\nimport { PluginManager } from './plugin/index.js';\nimport { SessionManager } from './session/index.js';\nimport { TokenManager } from './token/index.js';\nimport { logger } from './util/index.js';\nexport class App extends Hookable {\n    appId;\n    config;\n    db;\n    cache;\n    credential;\n    claim;\n    plugin;\n    token;\n    session;\n    oauth;\n    server;\n    _initialized = false;\n    _stopped = false;\n    constructor(config) {\n        super();\n        this.config = new ConfigManager(this, config);\n        this.appId = this.config.get('appId');\n        this.db = new DbManager(this);\n        this.cache = new CacheManager(this);\n        this.credential = new CredentialManager(this);\n        this.claim = new ClaimManager(this);\n        this.plugin = new PluginManager(this);\n        this.token = new TokenManager(this);\n        this.session = new SessionManager(this);\n        this.oauth = new OAuthManager(this);\n    }\n    async init() {\n        if (this._initialized)\n            return;\n        logger.info(`App initializing...`);\n        const start = performance.now();\n        await this.plugin.loadPlugins();\n        await this.config.validateConfig();\n        await this.plugin.setupPlugins();\n        await this.db.initDatabase();\n        await this.cache.initCache();\n        await this.token.loadTrustedKeys();\n        const duration = performance.now() - start;\n        logger.info(`App initialized in ${duration.toFixed(2)}ms`);\n        this._initialized = true;\n    }\n    async stop() {\n        if (this._stopped)\n            return;\n        logger.info(`App stopping...`);\n        const start = performance.now();\n        logger.info(`Will stop http server...`);\n        await new Promise((resolve) => {\n            if (!this.server)\n                return resolve();\n            this.server.close(() => resolve());\n        });\n        logger.info(`Will disconnect db...`);\n        await this.db.disconnect();\n        logger.info(`Will disconnect cache...`);\n        await this.cache.disconnect();\n        logger.info(`Will cleanup plugins...`);\n        await this.plugin.cleanupPlugins();\n        const duration = performance.now() - start;\n        logger.info(`App stopped in ${duration.toFixed(2)}ms`);\n        this._stopped = true;\n    }\n    async start() {\n        await this.init();\n        const app = new Hono()\n            .use(async (ctx, next) => {\n            ctx.set('app', this);\n            await next();\n        })\n            .route('/api', rootApi)\n            .route('/oauth', oauthRouter)\n            .route('/.well-known', new Hono().route('/', oauthWellKnownRouter));\n        await this.callHook('extendApp', app);\n        const uiPath = this.config.get('uiPath');\n        if (uiPath) {\n            try {\n                const fstat = await stat(uiPath);\n                if (!fstat.isDirectory())\n                    throw new Error('UI path must be a directory');\n                app.use('*', serveStatic({ root: uiPath }), async (ctx) => ctx.redirect('/', 303));\n                logger.info(`Serving UI at '${uiPath}'`);\n            }\n            catch (err) {\n                logger.warn(`UI path '${uiPath}' not valid: ${err}`);\n            }\n        }\n        this.server = serve({\n            fetch: app.fetch,\n            port: this.config.get('port')\n        });\n        logger.info(`Server listening on port ${this.config.get('port')}`);\n    }\n}\nexport * from '@uaaa/core';\nexport * from './api/index.js';\nexport * from './claim/index.js';\nexport * from './config/index.js';\nexport * from './credential/index.js';\nexport * from './db/index.js';\nexport * from './oauth/index.js';\nexport * from './plugin/index.js';\nexport * from './token/index.js';\nexport * from './util/index.js';\n"]}