modelence 0.7.2 → 0.9.0-dev.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/authConfig.d.ts +68 -0
- package/dist/app/authConfig.d.ts.map +1 -0
- package/dist/app/authConfig.js +8 -0
- package/dist/app/authConfig.js.map +1 -0
- package/dist/app/backendApi.d.ts +29 -0
- package/dist/app/backendApi.d.ts.map +1 -0
- package/dist/app/backendApi.js +69 -0
- package/dist/app/backendApi.js.map +1 -0
- package/dist/app/email.d.ts +3 -0
- package/dist/app/email.d.ts.map +1 -0
- package/dist/app/email.js +8 -0
- package/dist/app/email.js.map +1 -0
- package/dist/app/emailConfig.d.ts +27 -0
- package/dist/app/emailConfig.d.ts.map +1 -0
- package/dist/app/emailConfig.js +8 -0
- package/dist/app/emailConfig.js.map +1 -0
- package/dist/app/index.d.ts +20 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +258 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/loggerProcess.d.ts +5 -0
- package/dist/app/loggerProcess.d.ts.map +1 -0
- package/dist/app/loggerProcess.js +90 -0
- package/dist/app/loggerProcess.js.map +1 -0
- package/dist/app/metrics.d.ts +6 -0
- package/dist/app/metrics.d.ts.map +1 -0
- package/dist/app/metrics.js +92 -0
- package/dist/app/metrics.js.map +1 -0
- package/dist/app/module.d.ts +77 -0
- package/dist/app/module.d.ts.map +1 -0
- package/dist/app/module.js +46 -0
- package/dist/app/module.js.map +1 -0
- package/dist/app/server.d.ts +37 -0
- package/dist/app/server.d.ts.map +1 -0
- package/dist/app/server.js +198 -0
- package/dist/app/server.js.map +1 -0
- package/dist/app/state.d.ts +19 -0
- package/dist/app/state.d.ts.map +1 -0
- package/dist/app/state.js +27 -0
- package/dist/app/state.js.map +1 -0
- package/dist/app/websocketConfig.d.ts +7 -0
- package/dist/app/websocketConfig.d.ts.map +1 -0
- package/dist/app/websocketConfig.js +8 -0
- package/dist/app/websocketConfig.js.map +1 -0
- package/dist/auth/client/index.d.ts +69 -0
- package/dist/auth/client/index.d.ts.map +1 -0
- package/dist/auth/client/index.js +79 -0
- package/dist/auth/client/index.js.map +1 -0
- package/dist/auth/db.d.ts +176 -0
- package/dist/auth/db.d.ts.map +1 -0
- package/dist/auth/db.js +117 -0
- package/dist/auth/db.js.map +1 -0
- package/dist/auth/deleteUser.d.ts +5 -0
- package/dist/auth/deleteUser.d.ts.map +1 -0
- package/dist/auth/deleteUser.js +34 -0
- package/dist/auth/deleteUser.js.map +1 -0
- package/dist/auth/disposableEmails.d.ts +6 -0
- package/dist/auth/disposableEmails.d.ts.map +1 -0
- package/dist/auth/disposableEmails.js +47 -0
- package/dist/auth/disposableEmails.js.map +1 -0
- package/dist/auth/index.d.ts +7 -0
- package/dist/auth/index.d.ts.map +1 -0
- package/dist/auth/index.js +33 -0
- package/dist/auth/index.js.map +1 -0
- package/dist/auth/login.d.ts +9 -0
- package/dist/auth/login.d.ts.map +1 -0
- package/dist/auth/login.js +100 -0
- package/dist/auth/login.js.map +1 -0
- package/dist/auth/password.d.ts +14 -0
- package/dist/auth/password.d.ts.map +1 -0
- package/dist/auth/password.js +26 -0
- package/dist/auth/password.js.map +1 -0
- package/dist/auth/profile.d.ts +10 -0
- package/dist/auth/profile.d.ts.map +1 -0
- package/dist/auth/profile.js +13 -0
- package/dist/auth/profile.js.map +1 -0
- package/dist/auth/providers/github.d.ts +3 -0
- package/dist/auth/providers/github.d.ts.map +1 -0
- package/dist/auth/providers/github.js +122 -0
- package/dist/auth/providers/github.js.map +1 -0
- package/dist/auth/providers/google.d.ts +3 -0
- package/dist/auth/providers/google.d.ts.map +1 -0
- package/dist/auth/providers/google.js +108 -0
- package/dist/auth/providers/google.js.map +1 -0
- package/dist/auth/providers/oauth-common.d.ts +13 -0
- package/dist/auth/providers/oauth-common.d.ts.map +1 -0
- package/dist/auth/providers/oauth-common.js +109 -0
- package/dist/auth/providers/oauth-common.js.map +1 -0
- package/dist/auth/resetPassword.d.ts +10 -0
- package/dist/auth/resetPassword.d.ts.map +1 -0
- package/dist/auth/resetPassword.js +108 -0
- package/dist/auth/resetPassword.js.map +1 -0
- package/dist/auth/role.d.ts +8 -0
- package/dist/auth/role.d.ts.map +1 -0
- package/dist/auth/role.js +37 -0
- package/dist/auth/role.js.map +1 -0
- package/dist/auth/session.d.ts +24 -0
- package/dist/auth/session.d.ts.map +1 -0
- package/dist/auth/session.js +84 -0
- package/dist/auth/session.js.map +1 -0
- package/dist/auth/signup.d.ts +3 -0
- package/dist/auth/signup.d.ts.map +1 -0
- package/dist/auth/signup.js +89 -0
- package/dist/auth/signup.js.map +1 -0
- package/dist/auth/templates/emailVerficationTemplate.d.ts +6 -0
- package/dist/auth/templates/emailVerficationTemplate.d.ts.map +1 -0
- package/dist/auth/templates/emailVerficationTemplate.js +9 -0
- package/dist/auth/templates/emailVerficationTemplate.js.map +1 -0
- package/dist/auth/types.d.ts +22 -0
- package/dist/auth/types.d.ts.map +1 -0
- package/dist/auth/types.js +2 -0
- package/dist/auth/types.js.map +1 -0
- package/dist/auth/user.d.ts +5 -0
- package/dist/auth/user.d.ts.map +1 -0
- package/dist/auth/user.js +152 -0
- package/dist/auth/user.js.map +1 -0
- package/dist/auth/validators.d.ts +3 -0
- package/dist/auth/validators.d.ts.map +1 -0
- package/dist/auth/validators.js +8 -0
- package/dist/auth/validators.js.map +1 -0
- package/dist/auth/verification.d.ts +8 -0
- package/dist/auth/verification.d.ts.map +1 -0
- package/dist/auth/verification.js +94 -0
- package/dist/auth/verification.js.map +1 -0
- package/dist/bin/auth.d.ts +4 -0
- package/dist/bin/auth.d.ts.map +1 -0
- package/dist/bin/auth.js +48 -0
- package/dist/bin/auth.js.map +1 -0
- package/dist/bin/build.d.ts +2 -0
- package/dist/bin/build.d.ts.map +1 -0
- package/dist/bin/build.js +78 -0
- package/dist/bin/build.js.map +1 -0
- package/dist/bin/config.d.ts +11 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +91 -0
- package/dist/bin/config.js.map +1 -0
- package/dist/bin/deploy.d.ts +6 -0
- package/dist/bin/deploy.d.ts.map +1 -0
- package/dist/bin/deploy.js +129 -0
- package/dist/bin/deploy.js.map +1 -0
- package/dist/bin/dev.d.ts +2 -0
- package/dist/bin/dev.d.ts.map +1 -0
- package/dist/bin/dev.js +14 -0
- package/dist/bin/dev.js.map +1 -0
- package/dist/bin/modelence.d.ts +3 -0
- package/dist/bin/modelence.d.ts.map +1 -0
- package/dist/bin/modelence.js +57 -3
- package/dist/bin/modelence.js.map +1 -1
- package/dist/bin/setup.d.ts +5 -0
- package/dist/bin/setup.d.ts.map +1 -0
- package/dist/bin/setup.js +91 -0
- package/dist/bin/setup.js.map +1 -0
- package/dist/bin/start.d.ts +2 -0
- package/dist/bin/start.d.ts.map +1 -0
- package/dist/bin/start.js +15 -0
- package/dist/bin/start.js.map +1 -0
- package/dist/client/AppProvider.d.ts +8 -0
- package/dist/client/AppProvider.d.ts.map +1 -0
- package/dist/client/AppProvider.js +31 -0
- package/dist/client/AppProvider.js.map +1 -0
- package/dist/client/errorHandler.d.ts +4 -0
- package/dist/client/errorHandler.d.ts.map +1 -0
- package/dist/client/errorHandler.js +10 -0
- package/dist/client/errorHandler.js.map +1 -0
- package/dist/client/localStorage.d.ts +3 -0
- package/dist/client/localStorage.d.ts.map +1 -0
- package/dist/client/localStorage.js +14 -0
- package/dist/client/localStorage.js.map +1 -0
- package/dist/client/method.d.ts +6 -0
- package/dist/client/method.d.ts.map +1 -0
- package/dist/client/method.js +52 -0
- package/dist/client/method.js.map +1 -0
- package/dist/client/renderApp.d.ts +9 -0
- package/dist/client/renderApp.d.ts.map +1 -0
- package/dist/client/renderApp.js +28 -0
- package/dist/client/renderApp.js.map +1 -0
- package/dist/client/session.d.ts +34 -0
- package/dist/client/session.d.ts.map +1 -0
- package/dist/client/session.js +83 -0
- package/dist/client/session.js.map +1 -0
- package/dist/client.d.ts +10 -133
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +14 -1
- package/dist/client.js.map +1 -1
- package/dist/config/client.d.ts +10 -0
- package/dist/config/client.d.ts.map +1 -0
- package/dist/config/client.js +14 -0
- package/dist/config/client.js.map +1 -0
- package/dist/config/server.d.ts +48 -0
- package/dist/config/server.d.ts.map +1 -0
- package/dist/config/server.js +85 -0
- package/dist/config/server.js.map +1 -0
- package/dist/config/sync.d.ts +2 -0
- package/dist/config/sync.d.ts.map +1 -0
- package/dist/config/sync.js +32 -0
- package/dist/config/sync.js.map +1 -0
- package/dist/config/types.d.ts +19 -0
- package/dist/config/types.d.ts.map +1 -0
- package/dist/config/types.js +2 -0
- package/dist/config/types.js.map +1 -0
- package/dist/cron/jobs.d.ts +13 -0
- package/dist/cron/jobs.d.ts.map +1 -0
- package/dist/cron/jobs.js +155 -0
- package/dist/cron/jobs.js.map +1 -0
- package/dist/cron/types.d.ts +29 -0
- package/dist/cron/types.d.ts.map +1 -0
- package/dist/cron/types.js +2 -0
- package/dist/cron/types.js.map +1 -0
- package/dist/data/schemaSerializer.d.ts +37 -0
- package/dist/data/schemaSerializer.d.ts.map +1 -0
- package/dist/data/schemaSerializer.js +104 -0
- package/dist/data/schemaSerializer.js.map +1 -0
- package/dist/{types-WgRbQ-tj.d.ts → data/store.d.ts} +13 -231
- package/dist/data/store.d.ts.map +1 -0
- package/dist/data/store.js +501 -0
- package/dist/data/store.js.map +1 -0
- package/dist/data/types.d.ts +47 -0
- package/dist/data/types.d.ts.map +1 -0
- package/dist/data/types.js +35 -0
- package/dist/data/types.js.map +1 -0
- package/dist/db/client.d.ts +5 -0
- package/dist/db/client.d.ts.map +1 -0
- package/dist/db/client.js +41 -0
- package/dist/db/client.js.map +1 -0
- package/dist/error.d.ts +16 -0
- package/dist/error.d.ts.map +1 -0
- package/dist/error.js +24 -0
- package/dist/error.js.map +1 -0
- package/dist/index.d.ts +6 -31
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/lock/db.d.ts +19 -0
- package/dist/lock/db.d.ts.map +1 -0
- package/dist/lock/db.js +28 -0
- package/dist/lock/db.js.map +1 -0
- package/dist/lock/helpers.d.ts +28 -0
- package/dist/lock/helpers.d.ts.map +1 -0
- package/dist/lock/helpers.js +107 -0
- package/dist/lock/helpers.js.map +1 -0
- package/dist/lock/index.d.ts +4 -0
- package/dist/lock/index.d.ts.map +1 -0
- package/dist/lock/index.js +4 -0
- package/dist/lock/index.js.map +1 -0
- package/dist/lock/module.d.ts +7 -0
- package/dist/lock/module.d.ts.map +1 -0
- package/dist/lock/module.js +9 -0
- package/dist/lock/module.js.map +1 -0
- package/dist/methods/index.d.ts +7 -0
- package/dist/methods/index.d.ts.map +1 -0
- package/dist/methods/index.js +65 -0
- package/dist/methods/index.js.map +1 -0
- package/dist/methods/serialize.d.ts +15 -0
- package/dist/methods/serialize.d.ts.map +1 -0
- package/dist/methods/serialize.js +56 -0
- package/dist/methods/serialize.js.map +1 -0
- package/dist/methods/types.d.ts +37 -0
- package/dist/methods/types.d.ts.map +1 -0
- package/dist/methods/types.js +2 -0
- package/dist/methods/types.js.map +1 -0
- package/dist/migration/db.d.ts +17 -0
- package/dist/migration/db.d.ts.map +1 -0
- package/dist/migration/db.js +13 -0
- package/dist/migration/db.js.map +1 -0
- package/dist/migration/index.d.ts +11 -0
- package/dist/migration/index.d.ts.map +1 -0
- package/dist/migration/index.js +85 -0
- package/dist/migration/index.js.map +1 -0
- package/dist/mongo.d.ts +2 -3
- package/dist/mongo.d.ts.map +1 -0
- package/dist/mongo.js +2 -1
- package/dist/mongo.js.map +1 -1
- package/dist/rate-limit/db.d.ts +29 -0
- package/dist/rate-limit/db.d.ts.map +1 -0
- package/dist/rate-limit/db.js +25 -0
- package/dist/rate-limit/db.js.map +1 -0
- package/dist/rate-limit/index.d.ts +4 -0
- package/dist/rate-limit/index.d.ts.map +1 -0
- package/dist/rate-limit/index.js +6 -0
- package/dist/rate-limit/index.js.map +1 -0
- package/dist/rate-limit/rules.d.ts +22 -0
- package/dist/rate-limit/rules.d.ts.map +1 -0
- package/dist/rate-limit/rules.js +112 -0
- package/dist/rate-limit/rules.js.map +1 -0
- package/dist/rate-limit/types.d.ts +12 -0
- package/dist/rate-limit/types.d.ts.map +1 -0
- package/dist/rate-limit/types.js +2 -0
- package/dist/rate-limit/types.js.map +1 -0
- package/dist/routes/handler.d.ts +4 -0
- package/dist/routes/handler.d.ts.map +1 -0
- package/dist/routes/handler.js +66 -0
- package/dist/routes/handler.js.map +1 -0
- package/dist/routes/types.d.ts +45 -0
- package/dist/routes/types.d.ts.map +1 -0
- package/dist/routes/types.js +2 -0
- package/dist/routes/types.js.map +1 -0
- package/dist/server.d.ts +19 -551
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +15 -18
- package/dist/server.js.map +1 -1
- package/dist/system/index.d.ts +4 -0
- package/dist/system/index.d.ts.map +1 -0
- package/dist/system/index.js +21 -0
- package/dist/system/index.js.map +1 -0
- package/dist/telemetry/index.d.ts +11 -0
- package/dist/telemetry/index.d.ts.map +1 -0
- package/dist/telemetry/index.js +79 -0
- package/dist/telemetry/index.js.map +1 -0
- package/dist/telemetry.d.ts +2 -11
- package/dist/telemetry.d.ts.map +1 -0
- package/dist/telemetry.js +1 -1
- package/dist/telemetry.js.map +1 -1
- package/dist/time.d.ts +8 -0
- package/dist/time.d.ts.map +1 -0
- package/dist/time.js +13 -0
- package/dist/time.js.map +1 -0
- package/dist/types/email.d.ts +25 -0
- package/dist/types/email.d.ts.map +1 -0
- package/dist/types/email.js +2 -0
- package/dist/types/email.js.map +1 -0
- package/dist/types/index.d.ts +14 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types.d.ts +10 -7
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -1
- package/dist/types.js.map +1 -1
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +15 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/viteServer.d.ts +13 -0
- package/dist/viteServer.d.ts.map +1 -0
- package/dist/viteServer.js +132 -0
- package/dist/viteServer.js.map +1 -0
- package/dist/websocket/client.d.ts +9 -0
- package/dist/websocket/client.d.ts.map +1 -0
- package/dist/websocket/client.js +16 -0
- package/dist/websocket/client.js.map +1 -0
- package/dist/websocket/clientChannel.d.ts +9 -0
- package/dist/websocket/clientChannel.d.ts.map +1 -0
- package/dist/websocket/clientChannel.js +26 -0
- package/dist/websocket/clientChannel.js.map +1 -0
- package/dist/websocket/serverChannel.d.ts +14 -0
- package/dist/websocket/serverChannel.d.ts.map +1 -0
- package/dist/websocket/serverChannel.js +21 -0
- package/dist/websocket/serverChannel.js.map +1 -0
- package/dist/websocket/socketio/client.d.ts +4 -0
- package/dist/websocket/socketio/client.d.ts.map +1 -0
- package/dist/websocket/socketio/client.js +48 -0
- package/dist/websocket/socketio/client.js.map +1 -0
- package/dist/websocket/socketio/server.d.ts +10 -0
- package/dist/websocket/socketio/server.d.ts.map +1 -0
- package/dist/websocket/socketio/server.js +80 -0
- package/dist/websocket/socketio/server.js.map +1 -0
- package/dist/websocket/types.d.ts +45 -0
- package/dist/websocket/types.d.ts.map +1 -0
- package/dist/websocket/types.js +2 -0
- package/dist/websocket/types.js.map +1 -0
- package/package.json +5 -6
- package/dist/chunk-3S2FFBNS.js +0 -2
- package/dist/chunk-3S2FFBNS.js.map +0 -1
- package/dist/chunk-55J6XMHW.js +0 -2
- package/dist/chunk-55J6XMHW.js.map +0 -1
- package/dist/chunk-C3UESBRX.js +0 -2
- package/dist/chunk-C3UESBRX.js.map +0 -1
- package/dist/chunk-DO5TZLF5.js +0 -2
- package/dist/chunk-DO5TZLF5.js.map +0 -1
- package/dist/chunk-KUL6YKKP.js +0 -3
- package/dist/chunk-KUL6YKKP.js.map +0 -1
- package/dist/chunk-PB6WQQ4L.js +0 -3
- package/dist/chunk-PB6WQQ4L.js.map +0 -1
- package/dist/index-CwdohC5n.d.ts +0 -15
- package/dist/package-IIELPLTY.js +0 -2
- package/dist/package-IIELPLTY.js.map +0 -1
- package/dist/types-Ds1ESQSs.d.ts +0 -106
package/dist/server.js
CHANGED
|
@@ -1,19 +1,16 @@
|
|
|
1
|
-
import {a as a$2}from'./chunk-3S2FFBNS.js';import {d,a as a$3}from'./chunk-C3UESBRX.js';import {a}from'./chunk-DO5TZLF5.js';import {b as b$1,e,d as d$1,c,f,g,j,a as a$1,i,k as k$1,h,l as l$1}from'./chunk-PB6WQQ4L.js';export{a as getConfig}from'./chunk-PB6WQQ4L.js';import qt from'dotenv';import an from'fs/promises';import To from'os';import ve from'path';import {Server}from'socket.io';import {createAdapter}from'@socket.io/mongo-adapter';import {MongoError,ObjectId,MongoClient}from'mongodb';export{ObjectId}from'mongodb';import {randomBytes,randomUUID}from'crypto';import k,{z as z$1}from'zod';import fo from'bcrypt';import {createServer,defineConfig,loadConfigFromFile,mergeConfig}from'vite';import $o from'@vitejs/plugin-react';import Lo from'fs';import O,{Router}from'express';import tn from'cookie-parser';import on from'http';var S=class{constructor(e,{stores:o=[],queries:n={},mutations:r={},routes:i=[],cronJobs:s={},configSchema:a={},rateLimits:c=[],channels:d=[]}){this.name=e,this.stores=o,this.queries=n,this.mutations=r,this.routes=i,this.cronJobs=s,this.configSchema=a,this.rateLimits=c,this.channels=d;}};function v(t){let e=t._def;if(e.typeName==="ZodString")return {type:"string"};if(e.typeName==="ZodNumber")return {type:"number"};if(e.typeName==="ZodBoolean")return {type:"boolean"};if(e.typeName==="ZodDate")return {type:"date"};if(e.typeName==="ZodArray")return {type:"array",items:v(e.type)};if(e.typeName==="ZodObject"){let n=e.shape(),r={};for(let[i,s]of Object.entries(n))r[i]=v(s);return {type:"object",items:r}}if(e.typeName==="ZodOptional")return {...v(e.innerType),optional:true};if(e.typeName==="ZodNullable")return {...v(e.innerType),optional:true};if(e.typeName==="ZodEnum")return {type:"enum",items:e.values};if(e.typeName==="ZodUnion")return {type:"union",items:e.options.map(v)};if(e.typeName==="ZodEffects"){let o=e;return o.description?{type:"custom",typeName:o.description}:v(o.schema)}return {type:"custom",typeName:e.typeName}}function Y(t){let e={};for(let[o,n]of Object.entries(t))Array.isArray(n)?e[o]=n.map(r=>typeof r=="object"&&"_def"in r?v(r):Y(r)):typeof n=="object"&&"_def"in n?e[o]=v(n):e[o]=Y(n);return e}var w=class t{constructor(e,o){this.name=e,this.schema=o.schema,this.methods=o.methods,this.indexes=o.indexes,this.searchIndexes=o.searchIndexes||[];}getName(){return this.name}getSchema(){return this.schema}getSerializedSchema(){return Y(this.schema)}extend(e){let o={...this.schema,...e.schema||{}},n=[...this.indexes,...e.indexes||[]],r=[...this.searchIndexes,...e.searchIndexes||[]],i={...this.methods||{},...e.methods||{}},s=new t(this.name,{schema:o,methods:i,indexes:n,searchIndexes:r});if(this.client)throw new Error(`Store.extend() must be called before startApp(). Store '${this.name}' has already been initialized and cannot be extended.`);return s}init(e){if(this.collection)throw new Error(`Collection ${this.name} is already initialized`);this.client=e,this.collection=this.client.db().collection(this.name);}async createIndexes(){if(this.indexes.length>0)for(let e of this.indexes)try{await this.requireCollection().createIndexes([e]);}catch(o){if(o instanceof MongoError&&o.code===86&&e.name)await this.requireCollection().dropIndex(e.name),await this.requireCollection().createIndexes([e]);else throw o}if(this.searchIndexes.length>0)for(let e of this.searchIndexes)try{await this.requireCollection().createSearchIndexes([e]);}catch(o){if(o instanceof MongoError&&o.code===68&&e.name)await this.requireCollection().dropSearchIndex(e.name),await this.requireCollection().createSearchIndexes([e]);else throw o}}wrapDocument(e){return this.methods?Object.create(null,Object.getOwnPropertyDescriptors({...e,...this.methods})):e}getSelector(e){return typeof e=="string"?{_id:new ObjectId(e)}:e instanceof ObjectId?{_id:e}:e}requireCollection(){if(!this.collection)throw new Error(`Collection ${this.name} is not provisioned`);return this.collection}requireClient(){if(!this.client)throw new Error("Database is not connected");return this.client}async findOne(e,o){let n=await this.requireCollection().findOne(e,o);return n?this.wrapDocument(n):null}async requireOne(e,o,n){let r=await this.findOne(e,o);if(!r)throw n?n():new Error(`Record not found in ${this.name}`);return r}find(e,o){let n=this.requireCollection().find(e);return o?.sort&&n.sort(o.sort),o?.limit&&n.limit(o.limit),o?.skip&&n.skip(o.skip),n}async findById(e){let o=typeof e=="string"?{_id:new ObjectId(e)}:{_id:e};return await this.findOne(o)}async requireById(e,o){let n=await this.findById(e);if(!n)throw o?o():new Error(`Record with id ${e} not found in ${this.name}`);return n}countDocuments(e){return this.requireCollection().countDocuments(e)}async fetch(e,o){return (await this.find(e,o).toArray()).map(this.wrapDocument.bind(this))}async insertOne(e){return await this.requireCollection().insertOne(e)}async insertMany(e){return await this.requireCollection().insertMany(e)}async updateOne(e,o){return await this.requireCollection().updateOne(this.getSelector(e),o)}async upsertOne(e,o){return await this.requireCollection().updateOne(this.getSelector(e),o,{upsert:true})}async updateMany(e,o,n){return await this.requireCollection().updateMany(e,o,n)}async upsertMany(e,o){return await this.requireCollection().updateMany(e,o,{upsert:true})}async deleteOne(e){return await this.requireCollection().deleteOne(e)}async deleteMany(e){return await this.requireCollection().deleteMany(e)}aggregate(e,o){return this.requireCollection().aggregate(e,o)}bulkWrite(e){return this.requireCollection().bulkWrite(e)}getDatabase(){return this.requireClient().db()}rawCollection(){return this.requireCollection()}async renameFrom(e,o){let n=this.getDatabase();if(!this.collection||!n)throw new Error(`Store ${this.name} is not provisioned`);if((await n.listCollections({name:e}).toArray()).length===0)throw new Error(`Collection ${e} not found`);if((await n.listCollections({name:this.name}).toArray()).length>0)throw new Error(`Collection ${this.name} already exists`);await n.collection(e).rename(this.name,o);}async vectorSearch({field:e,embedding:o,numCandidates:n,limit:r,projection:i,indexName:s}){return this.aggregate([{$vectorSearch:{index:s||e+"VectorSearch",path:e,queryVector:o,numCandidates:n||100,limit:r||10}},{$project:{_id:1,score:{$meta:"vectorSearchScore"},...i}}])}static vectorIndex({field:e,dimensions:o,similarity:n="cosine",indexName:r}){return {type:"vectorSearch",name:r||e+"VectorSearch",definition:{fields:[{type:"vector",path:e,numDimensions:o,similarity:n}]}}}};var Gt=z$1.string.bind(z$1),Ht=z$1.number.bind(z$1),Vt=z$1.date.bind(z$1),Kt=z$1.boolean.bind(z$1),Qt=z$1.array.bind(z$1),Yt=z$1.object.bind(z$1),Xt=z$1.enum.bind(z$1),l={string:Gt,number:Ht,date:Vt,boolean:Kt,array:Qt,object:Yt,enum:Xt,embedding(){return z$1.array(z$1.number())},objectId(){return z$1.instanceof(ObjectId).describe("ObjectId")},userId(){return z$1.instanceof(ObjectId).describe("UserId")},ref(t){return z$1.instanceof(ObjectId).describe("Ref")},union:z$1.union.bind(z$1),infer(t){return {}}};var U=new w("_modelenceSessions",{schema:{authToken:l.string(),createdAt:l.date(),expiresAt:l.date(),userId:l.userId().nullable()},indexes:[{key:{authToken:1},unique:true},{key:{expiresAt:1}}]});async function ze(t){let e=t?await U.findOne({authToken:t}):null;return e?{authToken:String(e.authToken),expiresAt:new Date(e.expiresAt),userId:e.userId??null}:await pe()}async function Fe(t,e){await U.updateOne({authToken:t},{$set:{userId:e}});}async function qe(t){await U.updateOne({authToken:t},{$set:{userId:null}});}async function pe(t=null){let e=randomBytes(32).toString("base64url"),o=Date.now(),n=new Date(o+a.days(7));return await U.insertOne({authToken:e,createdAt:new Date(o),expiresAt:n,userId:t}),{authToken:e,expiresAt:n,userId:t}}async function to(t){let e=Date.now(),o=new Date(e+a.days(7));await U.updateOne({authToken:t.authToken},{$set:{lastActiveDate:new Date(e),expiresAt:o}});}var Ze=new S("_system.session",{stores:[U],mutations:{init:async function(t,{session:e,user:o}){return {session:e,user:o,configs:b$1()}},heartbeat:async function(t,{session:e}){e&&await to(e);}}});var p=new w("_modelenceUsers",{schema:{handle:l.string(),emails:l.array(l.object({address:l.string(),verified:l.boolean()})).optional(),status:l.enum(["active","disabled","deleted"]).optional(),createdAt:l.date(),disabledAt:l.date().optional(),deletedAt:l.date().optional(),roles:l.array(l.string()).optional(),authMethods:l.object({password:l.object({hash:l.string()}).optional(),google:l.object({id:l.string()}).optional(),github:l.object({id:l.string()}).optional()})},indexes:[{key:{handle:1},unique:true,collation:{locale:"en",strength:2}},{key:{"emails.address":1,status:1}},{key:{"authMethods.google.id":1,status:1},sparse:true},{key:{"authMethods.github.id":1,status:1},sparse:true}]}),W=new w("_modelenceDisposableEmailDomains",{schema:{domain:l.string(),addedAt:l.date()},indexes:[{key:{domain:1},unique:true}]}),D=new w("_modelenceEmailVerificationTokens",{schema:{userId:l.objectId(),email:l.string().optional(),token:l.string(),createdAt:l.date(),expiresAt:l.date()},indexes:[{key:{token:1},unique:true},{key:{expiresAt:1},expireAfterSeconds:0}]}),x=new w("_modelenceResetPasswordTokens",{schema:{userId:l.objectId(),token:l.string(),createdAt:l.date(),expiresAt:l.date()},indexes:[{key:{token:1},unique:true},{key:{expiresAt:1},expireAfterSeconds:0}]});var Be=new Map,$={authenticated:null,unauthenticated:null};function We(t,e){$.authenticated=e.authenticated,$.unauthenticated=e.unauthenticated;for(let[o,n]of Object.entries(t))Be.set(o,n);}function X(){return $.unauthenticated?[$.unauthenticated]:[]}function Je(){return $.authenticated?[$.authenticated]:[]}function Ge(t,e){let o=e.find(n=>!oo(t,n));if(o)throw new Error(`Access denied - missing permission: '${o}'`)}function oo(t,e){for(let o of t){let n=Be.get(o);if(n&&n.permissions.includes(e))return true}return false}async function R(t){let e=await ze(t),o=e.userId?await p.findOne({_id:new ObjectId(e.userId),status:{$nin:["deleted","disabled"]}}):null,n=o?{id:o._id.toString(),handle:o.handle,roles:o.roles||[],hasRole:i=>(o.roles||[]).includes(i),requireRole:i=>{if(!(o.roles||[]).includes(i))throw new Error(`Access denied - role '${i}' required`)}}:null,r=n?Je():X();return {user:n,session:e,roles:r}}var _=null;async function He(){if(_)return _;let t=M();if(!t)throw new Error("MongoDB URI is not set");_=new MongoClient(t,{maxPoolSize:20});try{return await _.connect(),await _.db("admin").command({ping:1}),console.log("Pinged your deployment. You successfully connected to MongoDB!"),_}catch(e){throw console.error(e),_=null,e}}function M(){let t=a$1("_system.mongodbUri");return t?String(t):void 0}function ee(){return _}var J=null,ao="_modelenceSocketio";async function co({httpServer:t,channels:e}){let o=ee();console.log("Initializing Socket.IO server...");let n=null;if(o){n=o.db().collection(ao);try{await n.createIndex({createdAt:1},{expireAfterSeconds:3600,background:!0});}catch(r){console.error("Failed to create index on MongoDB collection for Socket.IO:",r);}}J=new Server(t,{cors:{origin:"*",methods:["GET","POST"]},adapter:n?createAdapter(n):void 0,transports:["polling","websocket"],allowUpgrades:true,perMessageDeflate:false}),J.on("error",r=>{console.error("Socket.IO error:",r);}),J.use(async(r,i)=>{let s=r.handshake.auth.token;try{r.data=await R(s);}finally{i();}}),J.on("connection",r=>{console.log("Socket.IO client connected"),r.on("disconnect",()=>{console.log("Socket.IO client disconnected");}),r.on("joinChannel",async i=>{let[s]=i.split(":"),a=false;for(let c of e)if(c.category===s){(!c.canAccessChannel||await c.canAccessChannel(r.data))&&(r.join(i),a=true,console.log(`User ${r.id} joined channel ${i}`),r.emit("joinedChannel",i));break}a||r.emit("joinError",{channel:i,error:"Access denied"});}),r.on("leaveChannel",i=>{r.leave(i),console.log(`User ${r.id} left channel ${i}`),r.emit("leftChannel",i);});}),console.log("Socket.IO server initialized");}function lo({category:t,id:e,data:o}){J?.to(`${t}:${e}`).emit(t,o);}var Ve={init:co,broadcast:lo};async function Ke(t){let e=t.toLowerCase().trim().split("@");if(e.length!==2)return false;let o=e[1];return !!await W.findOne({domain:o})}var Qe={interval:a.days(1),async handler(){let t=await fetch("https://disposable.github.io/disposable-email-domains/domains.txt");if(!t.ok)throw new Error(`HTTP ${t.status}: ${t.statusText}`);let o=(await t.text()).split(`
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[Output truncated - exceeded size limit]`:f;await V.upsertOne({version:s},{$set:{version:s,status:"completed",description:a,output:E,appliedAt:new Date}}),i(`Migration v${s} complete`,{source:"migrations"});}catch(d){d instanceof Error&&(await V.upsertOne({version:s},{$set:{version:s,status:"failed",description:a,output:d.message||"",appliedAt:new Date}}),i(`Migration v${s} is failed: ${d.message}`,{source:"migrations"}));}}await wt("migrations");}}function Rt(t){setTimeout(()=>{Ao(t).catch(e=>{console.error("Error running migrations:",e);});},0);}var Mt=new S("_system.migration",{stores:[V]});var At=new S("_system.rateLimit",{stores:[G]});var It=new S("_system",{configSchema:{mongodbUrl:{type:"string",isPublic:false,default:""},env:{type:"string",isPublic:true,default:""},"site.url":{type:"string",isPublic:true,default:""}}});var De=class{async init(){this.config=await Fo(),this.isDev()&&(console.log("Starting Vite dev server..."),this.viteServer=await createServer(this.config));}middlewares(){if(this.isDev())return this.viteServer?.middlewares??[];let e=[O.static("./.modelence/build/client".replace(/\\/g,"/"))];return this.config?.publicDir&&e.push(O.static(this.config.publicDir)),e}handler(e,o){if(this.isDev())try{o.sendFile("index.html",{root:"./src/client"});}catch(n){console.error("Error serving index.html:",n),o.status(500).send("Internal Server Error");}else o.sendFile("index.html",{root:"./.modelence/build/client".replace(/\\/g,"/")});}isDev(){return process.env.NODE_ENV!=="production"}};async function No(){let t=process.cwd();try{return (await loadConfigFromFile({command:"serve",mode:"development"},void 0,t))?.config||{}}catch(e){return console.warn("Could not load vite config:",e),{}}}function zo(t,e){let o=mergeConfig(t,e);if(o.plugins&&Array.isArray(o.plugins)){let n=new Set;o.plugins=o.plugins.flat().filter(r=>{if(!r||typeof r!="object"||Array.isArray(r))return true;let i=r.name;return !i||n.has(i)?false:(n.add(i),true)}).reverse(),o.plugins.reverse();}return o}async function Fo(){let t=process.cwd(),e=await No(),o=[".eslintrc.js",".eslintrc.json",".eslintrc","eslint.config.js",".eslintrc.yml",".eslintrc.yaml"].find(i=>Lo.existsSync(ve.join(t,i))),n=[$o(),qo()];if(o){let i=(await import('vite-plugin-eslint')).default;n.push(i({failOnError:false,include:["src/**/*.js","src/**/*.jsx","src/**/*.ts","src/**/*.tsx"],cwd:t,overrideConfigFile:ve.resolve(t,o)}));}let r=defineConfig({plugins:n,build:{outDir:".modelence/build/client".replace(/\\/g,"/"),emptyOutDir:true},server:{middlewareMode:true},root:"./src/client",resolve:{alias:{"@":ve.resolve(t,"src").replace(/\\/g,"/")}}});return zo(r,e)}function qo(){return {name:"modelence-asset-handler",async transform(t,e){if(/\.(png|jpe?g|gif|svg|mpwebm|ogg|mp3|wav|flac|aac)$/.test(e))return process.env.NODE_ENV==="development",t}}}var jt=new De;async function Ut(t,e){let{authToken:o}=await pe(e);t.cookie("authToken",o,{httpOnly:true,secure:process.env.NODE_ENV==="production",sameSite:"strict"}),t.status(301),t.redirect("/");}function z(t){return `${a$1("_system.site.url")}/api/_internal/auth/${t}/callback`}async function se(t,e,o){let n=await p.findOne({[`authMethods.${o.providerName}.id`]:o.id}),{session:r,connectionInfo:i}=await _e(t);try{if(n){await Ut(e,n._id),y().onAfterLogin?.({user:n,session:r,connectionInfo:i}),y().login?.onSuccess?.(n);return}}catch(s){throw s instanceof Error&&(y().login?.onError?.(s),y().onLoginError?.({error:s,session:r,connectionInfo:i})),s}try{if(!o.email){e.status(400).json({error:`Email address is required for ${o.providerName} authentication.`});return}if(await p.findOne({"emails.address":o.email},{collation:{locale:"en",strength:2}})){e.status(400).json({error:"User with this email already exists. Please log in instead."});return}let a=await p.insertOne({handle:o.email,status:"active",emails:[{address:o.email,verified:o.emailVerified}],createdAt:new Date,authMethods:{[o.providerName]:{id:o.id}}});await Ut(e,a.insertedId);let c=await p.findOne({_id:a.insertedId},{readPreference:"primary"});c&&(y().onAfterSignup?.({user:c,session:r,connectionInfo:i}),y().signup?.onSuccess?.(c));}catch(s){throw s instanceof Error&&(y().onSignupError?.({error:s,session:r,connectionInfo:i}),y().signup?.onError?.(s)),s}}function ae(t){return !t||typeof t!="string"?null:t}async function Wo(t,e,o,n){let r=await fetch("https://oauth2.googleapis.com/token",{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams({code:t,client_id:e,client_secret:o,redirect_uri:n,grant_type:"authorization_code"})});if(!r.ok)throw new Error(`Failed to exchange code for token: ${r.statusText}`);return r.json()}async function Jo(t){let e=await fetch("https://www.googleapis.com/oauth2/v2/userinfo",{headers:{Authorization:`Bearer ${t}`}});if(!e.ok)throw new Error(`Failed to fetch user info: ${e.statusText}`);return e.json()}async function Go(t,e){let o=ae(t.query.code),n=t.query.state,r=t.cookies.authStateGoogle;if(!o){e.status(400).json({error:"Missing authorization code"});return}if(!n||!r||n!==r){e.status(400).json({error:"Invalid OAuth state - possible CSRF attack"});return}e.clearCookie("authStateGoogle");let i=String(a$1("_system.user.auth.google.clientId")),s=String(a$1("_system.user.auth.google.clientSecret")),a=z("google");try{let c=await Wo(o,i,s,a),d=await Jo(c.access_token),f={id:d.id,email:d.email,emailVerified:d.verified_email,providerName:"google"};await se(t,e,f);}catch(c){console.error("Google OAuth error:",c),e.status(500).json({error:"Authentication failed"});}}function Ho(){let t=Router(),e=(o,n,r)=>{let i=!!a$1("_system.user.auth.google.enabled"),s=String(a$1("_system.user.auth.google.clientId")),a=String(a$1("_system.user.auth.google.clientSecret"));if(!i||!s||!a){n.status(503).json({error:"Google authentication is not configured"});return}r();};return t.get("/api/_internal/auth/google",e,(o,n)=>{let r=String(a$1("_system.user.auth.google.clientId")),i=z("google"),s=randomBytes(32).toString("hex");n.cookie("authStateGoogle",s,{httpOnly:true,secure:process.env.NODE_ENV==="production",sameSite:"lax",maxAge:a.minutes(10)});let a$2=new URL("https://accounts.google.com/o/oauth2/v2/auth");a$2.searchParams.append("client_id",r),a$2.searchParams.append("redirect_uri",i),a$2.searchParams.append("response_type","code"),a$2.searchParams.append("scope","profile email"),a$2.searchParams.append("access_type","online"),a$2.searchParams.append("state",s),n.redirect(a$2.toString());}),t.get("/api/_internal/auth/google/callback",e,Go),t}var $t=Ho;async function Qo(t,e,o,n){let r=await fetch("https://github.com/login/oauth/access_token",{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({client_id:e,client_secret:o,code:t,redirect_uri:n})});if(!r.ok)throw new Error(`Failed to exchange code for token: ${r.statusText}`);return r.json()}async function Yo(t){let e=await fetch("https://api.github.com/user",{headers:{Authorization:`Bearer ${t}`,Accept:"application/vnd.github.v3+json"}});if(!e.ok)throw new Error(`Failed to fetch user info: ${e.statusText}`);return e.json()}async function Xo(t,e){let o=ae(t.query.code),n=t.query.state,r=t.cookies.authStateGithub;if(!o){e.status(400).json({error:"Missing authorization code"});return}if(!n||!r||n!==r){e.status(400).json({error:"Invalid OAuth state - possible CSRF attack"});return}e.clearCookie("authStateGithub");let i=String(a$1("_system.user.auth.github.clientId")),s=String(a$1("_system.user.auth.github.clientSecret")),a=z("github");try{let c=await Qo(o,i,s,a),d=await Yo(c.access_token),f=d.email||"";if(!f){e.status(400).json({error:"Unable to retrieve email from GitHub. Please ensure your email is public or grant email permissions."});return}let u={id:String(d.id),email:f,emailVerified:!0,providerName:"github"};await se(t,e,u);}catch(c){console.error("GitHub OAuth error:",c),e.status(500).json({error:"Authentication failed"});}}function en(){let t=Router(),e=(o,n,r)=>{let i=!!a$1("_system.user.auth.github.enabled"),s=String(a$1("_system.user.auth.github.clientId")),a=String(a$1("_system.user.auth.github.clientSecret"));if(!i||!s||!a){n.status(503).json({error:"GitHub authentication is not configured"});return}r();};return t.get("/api/_internal/auth/github",e,(o,n)=>{let r=String(a$1("_system.user.auth.github.clientId")),i=z("github"),s=a$1("_system.user.auth.github.scopes"),a$2=s?String(s).split(",").map(f=>f.trim()).join(" "):"user:email",c=randomBytes(32).toString("hex");n.cookie("authStateGithub",c,{httpOnly:true,secure:process.env.NODE_ENV==="production",sameSite:"lax",maxAge:a.minutes(10)});let d=new URL("https://github.com/login/oauth/authorize");d.searchParams.append("client_id",r),d.searchParams.append("redirect_uri",i),d.searchParams.append("scope",a$2),d.searchParams.append("state",c),n.redirect(d.toString());}),t.get("/api/_internal/auth/github/callback",e,Xo),t}var Lt=en;function Nt(t,e,o){return async(n,r,i)=>{let s=n.headers["x-modelence-auth-token"],a={session:null,user:null};if(typeof s=="string"&&M())try{let{session:d,user:f}=await R(s);a={session:d,user:f};}catch{}let c=k$1("route",`route:${t.toLowerCase()}:${e}`,{method:t,path:e,query:n.query,body:n.body,params:n.params});try{let d=await o({query:n.query,body:n.body,params:n.params,headers:n.headers,cookies:n.cookies,rawBody:Buffer.isBuffer(n.body)?n.body:void 0,req:n,res:r,next:i},a);c.end(),d&&(r.status(d.status||200),d.redirect&&r.redirect(d.redirect),d.headers&&Object.entries(d.headers).forEach(([f,u])=>{r.setHeader(f,u);}),r.send(d.data));}catch(d){c.end("error"),d instanceof a$3?r.status(d.status).send(d.message):(console.error(`Error in route handler: ${n.path}`),console.error(d),r.status(500).send(String(d)));}}}var ke=Object.freeze({});function zt(t){ke=Object.freeze(Object.assign({},ke,t));}function ce(){return ke}function nn(t){let e=[];if(!t)return e.push(O.json({limit:"16mb"})),e.push(O.urlencoded({extended:true,limit:"16mb"})),e;if(t.json!==false){let o=typeof t.json=="object"?t.json:{limit:"16mb"};e.push(O.json(o));}if(t.urlencoded!==false){let o=typeof t.urlencoded=="object"?t.urlencoded:{extended:true,limit:"16mb"};e.push(O.urlencoded(o));}if(t.raw){let o=typeof t.raw=="object"?t.raw:{},n={limit:o.limit||"16mb",type:o.type||"*/*"};e.push(O.raw(n));}return e}function rn(t,e){for(let o of e)for(let n of o.routes){let{path:r,handlers:i,body:s}=n,a=nn(s);Object.entries(i).forEach(([c,d])=>{t[c](r,...a,Nt(c,r,d));});}}async function Ft(t,{combinedModules:e,channels:o}){let n=O();n.use(tn()),rn(n,e),n.use(O.json({limit:"16mb"})),n.use(O.urlencoded({extended:true,limit:"16mb"})),n.use($t()),n.use(Lt()),n.post("/api/_internal/method/:methodName(*)",async(a,c)=>{let{methodName:d}=a.params,f=await _e(a);try{let u=await Ot(d,a.body.args,f);c.json({data:u,typeMap:a$2(u)});}catch(u){if(console.error(`Error in method ${d}:`,u),u instanceof a$3)c.status(u.status).send(u.message);else if(u instanceof Error&&u?.constructor?.name==="ZodError"&&"errors"in u){let C=u.flatten(),F=Object.entries(C.fieldErrors).map(([q,de])=>`${q}: ${(de??[]).join(", ")}`).join("; "),le=C.formErrors.join("; "),K=[F,le].filter(Boolean).join("; ");c.status(400).send(K);}else c.status(500).send(u instanceof Error?u.message:String(u));}}),await t.init(),t.middlewares&&n.use(t.middlewares()),n.all("*",(a,c)=>t.handler(a,c)),process.on("unhandledRejection",(a,c)=>{console.error("Unhandled Promise Rejection:"),console.error(a instanceof Error?a.stack:a),console.error("Promise:",c);}),process.on("uncaughtException",a=>{console.error("Uncaught Exception:"),console.error(a.stack),console.trace("Full application stack:");});let r=on.createServer(n),i$1=ce()?.provider;i$1&&i$1.init({httpServer:r,channels:o});let s=process.env.MODELENCE_PORT||process.env.PORT||3e3;r.listen(s,()=>{i("Application started",{source:"app"});let a=process.env.MODELENCE_SITE_URL||`http://localhost:${s}`;console.log(`
|
|
16
|
-
Application started on ${a}
|
|
17
|
-
`);});}async function _e(t){let e=k.string().nullish().transform(i=>i??null).parse(t.cookies.authToken||t.body.authToken),o=k.object({screenWidth:k.number(),screenHeight:k.number(),windowWidth:k.number(),windowHeight:k.number(),pixelRatio:k.number(),orientation:k.string().nullable()}).nullish().parse(t.body.clientInfo)??{screenWidth:0,screenHeight:0,windowWidth:0,windowHeight:0,pixelRatio:1,orientation:null},n={ip:sn(t),userAgent:t.get("user-agent"),acceptLanguage:t.get("accept-language"),referrer:t.get("referrer"),baseUrl:t.protocol+"://"+t.get("host")};if(!!M()){let{session:i,user:s,roles:a}=await R(e);return {clientInfo:o,connectionInfo:n,session:i,user:s,roles:a}}return {clientInfo:o,connectionInfo:n,session:null,user:null,roles:X()}}function sn(t){let e=t.headers["x-forwarded-for"];if(e)return (Array.isArray(e)?e[0]:e.split(",")[0]).trim();let o=t.ip||t.socket?.remoteAddress;if(o)return o.startsWith("::ffff:")?o.substring(7):o}async function dn({modules:t=[],roles:e$1={},defaultRoles:o={},server:n=jt,migrations:r=[],email:i={},auth:s={},websocket:a={}}){qt.config(),qt.config({path:".modelence.env"});let c$1=!!process.env.MODELENCE_SERVICE_ENDPOINT,d=process.env.MODELENCE_CRON_ENABLED==="true";Cn().then(()=>{}).catch(()=>{});let f$1=[ut,Ze,xt,Mt,At,It,Te],u=[...f$1,...t];e(),mn(f$1),un(t),We(e$1,o);let E=gn(u);d$1(E);let C=pn(u),F=fn(u);d&&yn(u);let le=hn(u);if(at(le),c$1){let{configs:q,environmentId:de,appAlias:Bt,environmentAlias:Wt,telemetry:Jt}=await mt({configSchema:E,cronJobsMetadata:d?Ct():void 0,stores:C});c(q),f({environmentId:de,appAlias:Bt,environmentAlias:Wt,telemetry:Jt});}else c(En(E));Ye(i),ot(s),zt({...a,provider:a.provider||Ve});let K=M();if(K&&(await He(),wn(C)),d&&Rt(r),K)for(let q of C)q.createIndexes();c$1&&(await g(),ht()),d&&Et().catch(console.error),await Ft(n,{combinedModules:u,channels:F});}function un(t){for(let e of t){for(let[o,n]of Object.entries(e.queries))xe(`${e.name}.${o}`,n);for(let[o,n]of Object.entries(e.mutations))Tt(`${e.name}.${o}`,n);}}function mn(t){for(let e of t){for(let[o,n]of Object.entries(e.queries))vt(`${e.name}.${o}`,n);for(let[o,n]of Object.entries(e.mutations))Dt(`${e.name}.${o}`,n);}}function pn(t){return t.flatMap(e=>e.stores)}function fn(t){return t.flatMap(e=>e.channels)}function hn(t){return t.flatMap(e=>e.rateLimits)}function gn(t){let e={};for(let o of t)for(let[n,r]of Object.entries(o.configSchema)){let i=`${o.name}.${n}`;if(i in e)throw new Error(`Duplicate config schema key: ${i} (${o.name})`);e[i]=r;}return e}function yn(t){for(let e of t)for(let[o,n]of Object.entries(e.cronJobs))St(`${e.name}.${o}`,n);}function wn(t){let e=ee();if(!e)throw new Error("Failed to initialize stores: MongoDB client not initialized");for(let o of t)o.init(e);}var bn={MONGODB_URI:"_system.mongodbUri",MODELENCE_AUTH_GOOGLE_ENABLED:"_system.user.auth.google.enabled",MODELENCE_AUTH_GOOGLE_CLIENT_ID:"_system.user.auth.google.clientId",MODELENCE_AUTH_GOOGLE_CLIENT_SECRET:"_system.user.auth.google.clientSecret",MODELENCE_AUTH_GITHUB_ENABLED:"_system.user.auth.github.enabled",MODELENCE_AUTH_GITHUB_CLIENT_ID:"_system.user.auth.github.clientId",MODELENCE_AUTH_GITHUB_CLIENT_SECRET:"_system.user.auth.github.clientSecret",MODELENCE_AUTH_GITHUB_CLIENT_SCOPES:"_system.user.auth.github.scopes",MODELENCE_EMAIL_RESEND_API_KEY:"_system.email.resend.apiKey",MODELENCE_EMAIL_AWS_SES_REGION:"_system.email.awsSes.region",MODELENCE_EMAIL_AWS_SES_ACCESS_KEY_ID:"_system.email.awsSes.accessKeyId",MODELENCE_EMAIL_AWS_SES_SECRET_ACCESS_KEY:"_system.email.awsSes.secretAccessKey",MODELENCE_EMAIL_SMTP_HOST:"_system.email.smtp.host",MODELENCE_EMAIL_SMTP_PORT:"_system.email.smtp.port",MODELENCE_EMAIL_SMTP_USER:"_system.email.smtp.user",MODELENCE_EMAIL_SMTP_PASS:"_system.email.smtp.pass",MODELENCE_SITE_URL:"_system.site.url",MODELENCE_ENV:"_system.env",GOOGLE_AUTH_ENABLED:"_system.user.auth.google.enabled",GOOGLE_AUTH_CLIENT_ID:"_system.user.auth.google.clientId",GOOGLE_AUTH_CLIENT_SECRET:"_system.user.auth.google.clientSecret"};function Sn(t,e){if(e==="number"){let o=Number(t);if(isNaN(o))throw new Error(`Invalid number value for config: ${t}`);return o}if(e==="boolean"){if(t.toLowerCase()==="true")return true;if(t.toLowerCase()==="false")return false;throw new Error(`Invalid boolean value for config: ${t}`)}return t}function En(t){let e=[];for(let[o,n]of Object.entries(bn)){let r=process.env[o],i=t[n];if(r){let s=i?.type??"string";e.push({key:n,type:s,value:Sn(r,s)});}}return e}async function Cn(){if(process.env.MODELENCE_TRACKING_ENABLED!=="false"){let e=process.env.MODELENCE_SERVICE_ENDPOINT??"https://cloud.modelence.com",o=process.env.MODELENCE_ENVIRONMENT_ID,n=await xn(),r=await import('./package-IIELPLTY.js');await fetch(`${e}/api/track/app-start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({projectName:n.name,version:r.default.version,localHostname:To.hostname(),environmentId:o})});}}async function xn(){try{let t=ve.join(process.cwd(),"package.json"),e=await an.readFile(t,"utf-8");return {name:JSON.parse(e).name||"unknown"}}catch{return {name:"unknown"}}}async function Zt(t){await D.deleteMany({userId:t}),await x.deleteMany({userId:t});}async function vn(t){await Zt(t),await p.updateOne(t,{$set:{status:"disabled",disabledAt:new Date}});}async function Dn(t){await Zt(t),await p.updateOne({_id:t},{$set:{handle:`deleted-${t}-${randomUUID()}`,status:"deleted",deletedAt:new Date,authMethods:{},emails:[]}});}var Oe=class{constructor(e,o){this.category=e,this.canAccessChannel=o||null;}broadcast(e,o){let n=ce().provider;if(!n){j("Websockets provider should be added to startApp",{});return}n.broadcast({category:this.category,id:e,data:o});}};function _n(t){if(!b().provider)throw new Error("Email provider is not configured, see https://docs.modelence.com/email for more details.");return b().provider?.sendEmail(t)}
|
|
18
|
-
export{S as Module,Oe as ServerChannel,w as Store,R as authenticate,I as consumeRateLimit,xe as createQuery,p as dbUsers,Dn as deleteUser,vn as disableUser,l as schema,_n as sendEmail,dn as startApp};//# sourceMappingURL=server.js.map
|
|
1
|
+
export { startApp } from './app';
|
|
2
|
+
export { Module } from './app/module';
|
|
3
|
+
export { ObjectId } from 'mongodb';
|
|
4
|
+
export { createQuery } from './methods';
|
|
5
|
+
// Auth
|
|
6
|
+
export { usersCollection as dbUsers } from './auth/db';
|
|
7
|
+
export { deleteUser, disableUser } from './auth/deleteUser';
|
|
8
|
+
// Database
|
|
9
|
+
export { schema } from './data/types';
|
|
10
|
+
export { Store } from './data/store';
|
|
11
|
+
export { consumeRateLimit } from './rate-limit/rules';
|
|
12
|
+
export { getConfig } from './config/server';
|
|
13
|
+
export { ServerChannel } from './websocket/serverChannel';
|
|
14
|
+
export { authenticate } from './auth';
|
|
15
|
+
export { sendEmail } from './app/email';
|
|
19
16
|
//# sourceMappingURL=server.js.map
|