@opengis/fcore 0.0.1-beta.5 → 0.0.1-beta.7
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/config.js +1 -1
- package/dist/context.js +1 -1
- package/dist/errors.js +1 -1
- package/dist/fastify.d.ts +2 -1
- package/dist/fastify.d.ts.map +1 -1
- package/dist/fastify.js +1 -1
- package/dist/fcore.js +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/migrations/cli.js +1 -1
- package/dist/migrations/runner.js +1 -1
- package/dist/modules/auth/adduser-cli.js +1 -1
- package/dist/modules/auth/passwd-cli.js +1 -1
- package/dist/modules/auth/permission-cli.js +1 -1
- package/dist/modules/auth/route.d.ts.map +1 -1
- package/dist/modules/auth/route.js +1 -1
- package/dist/modules/auth/schema.d.ts +3 -0
- package/dist/modules/auth/schema.d.ts.map +1 -1
- package/dist/modules/auth/schema.js +1 -1
- package/dist/modules/auth/services/change-password.js +1 -1
- package/dist/modules/auth/services/get-current-user.d.ts +1 -0
- package/dist/modules/auth/services/get-current-user.d.ts.map +1 -1
- package/dist/modules/auth/services/get-current-user.js +1 -1
- package/dist/modules/auth/services/registration.js +1 -1
- package/dist/modules/auth/services/verify-two-factor.js +1 -1
- package/dist/modules/file/mime.d.ts +3 -0
- package/dist/modules/file/mime.d.ts.map +1 -0
- package/dist/modules/file/mime.js +1 -0
- package/dist/modules/file/route.d.ts.map +1 -1
- package/dist/modules/file/route.js +1 -1
- package/dist/modules/file/schema.d.ts +3 -0
- package/dist/modules/file/schema.d.ts.map +1 -1
- package/dist/modules/file/schema.js +1 -1
- package/dist/modules/file/services/get-file.js +1 -1
- package/dist/modules/file/services/resize-file.d.ts.map +1 -1
- package/dist/modules/file/services/resize-file.js +1 -1
- package/dist/modules/file/services/upload-file.d.ts +4 -6
- package/dist/modules/file/services/upload-file.d.ts.map +1 -1
- package/dist/modules/file/services/upload-file.js +1 -1
- package/dist/modules/resource/route.d.ts +0 -3
- package/dist/modules/resource/route.d.ts.map +1 -1
- package/dist/modules/resource/route.js +1 -1
- package/dist/modules/resource/schema.d.ts +3 -0
- package/dist/modules/resource/schema.d.ts.map +1 -1
- package/dist/modules/resource/schema.js +1 -1
- package/dist/modules/resource/services/add-note.js +1 -1
- package/dist/modules/resource/services/add-resource-file.js +1 -1
- package/dist/modules/resource/services/create-resource-relation.js +1 -1
- package/dist/modules/resource/services/create-resource.js +1 -1
- package/dist/modules/resource/services/delete-resource-relation.js +1 -1
- package/dist/modules/resource/services/delete-resource.js +1 -1
- package/dist/modules/resource/services/export-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/export-resource.js +1 -1
- package/dist/modules/resource/services/get-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/get-resource.js +1 -1
- package/dist/modules/resource/services/list-resource-relation.d.ts +2 -0
- package/dist/modules/resource/services/list-resource-relation.d.ts.map +1 -1
- package/dist/modules/resource/services/list-resource-relation.js +1 -1
- package/dist/modules/resource/services/list-resources.d.ts.map +1 -1
- package/dist/modules/resource/services/list-resources.js +1 -1
- package/dist/modules/resource/services/search-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/search-resource.js +1 -1
- package/dist/modules/resource/services/suggest-resource.d.ts.map +1 -1
- package/dist/modules/resource/services/suggest-resource.js +1 -1
- package/dist/modules/resource/services/update-resource-relation.d.ts +10 -0
- package/dist/modules/resource/services/update-resource-relation.d.ts.map +1 -0
- package/dist/modules/resource/services/update-resource-relation.js +1 -0
- package/dist/modules/resource/services/update-resource.js +1 -1
- package/dist/modules/resource/services/upload-resource-file.js +1 -1
- package/dist/modules/system/route.d.ts.map +1 -1
- package/dist/modules/system/route.js +1 -1
- package/dist/modules/system/schema.js +1 -1
- package/dist/modules/system/services/check-system.d.ts.map +1 -1
- package/dist/modules/system/services/check-system.js +1 -1
- package/dist/modules/system/services/get-access.d.ts.map +1 -1
- package/dist/modules/system/services/get-access.js +1 -1
- package/dist/modules/system/services/get-api-list.d.ts.map +1 -1
- package/dist/modules/system/services/get-api-list.js +1 -1
- package/dist/modules/system/services/get-audit-log.d.ts.map +1 -1
- package/dist/modules/system/services/get-audit-log.js +1 -1
- package/dist/modules/system/services/get-dictionary.js +1 -1
- package/dist/modules/system/services/get-system-log.d.ts.map +1 -1
- package/dist/modules/system/services/get-system-log.js +1 -1
- package/dist/modules/system/services/get-system-settings.d.ts.map +1 -1
- package/dist/modules/system/services/get-system-settings.js +1 -1
- package/dist/modules/system/services/list-dictionaries.js +1 -1
- package/dist/modules/system/services/set-access.d.ts.map +1 -1
- package/dist/modules/system/services/set-access.js +1 -1
- package/dist/modules/system/services/update-dictionary.d.ts.map +1 -1
- package/dist/modules/system/services/update-dictionary.js +1 -1
- package/dist/modules/system/services/update-system-settings.d.ts.map +1 -1
- package/dist/modules/system/services/update-system-settings.js +1 -1
- package/dist/modules/utils/require-admin.js +1 -1
- package/dist/modules/utils/safe-user.js +1 -1
- package/dist/modules/utils/unsupported.js +1 -1
- package/dist/plugins/audit/audit.js +1 -1
- package/dist/plugins/audit/index.js +1 -1
- package/dist/plugins/audit/services/write-audit.js +1 -1
- package/dist/plugins/auth/get-user-permissions.js +1 -1
- package/dist/plugins/auth/index.js +1 -1
- package/dist/plugins/auth/verifyUser.js +1 -1
- package/dist/plugins/dictionary.d.ts +3 -0
- package/dist/plugins/dictionary.d.ts.map +1 -1
- package/dist/plugins/dictionary.js +1 -1
- package/dist/plugins/file.d.ts +3 -6
- package/dist/plugins/file.d.ts.map +1 -1
- package/dist/plugins/file.js +1 -1
- package/dist/plugins/index.d.ts +1 -0
- package/dist/plugins/index.d.ts.map +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/jwt.d.ts +4 -0
- package/dist/plugins/jwt.d.ts.map +1 -0
- package/dist/plugins/jwt.js +1 -0
- package/dist/plugins/logger/index.js +1 -1
- package/dist/plugins/logger/transport.js +1 -1
- package/dist/plugins/pg.d.ts.map +1 -1
- package/dist/plugins/pg.js +1 -1
- package/dist/plugins/redis.js +1 -1
- package/dist/plugins/resource/index.js +1 -1
- package/dist/plugins/resource/resource.d.ts.map +1 -1
- package/dist/plugins/resource/resource.js +1 -1
- package/dist/plugins/resource/resource.registry.js +1 -1
- package/dist/plugins/resource/resource.types.d.ts +18 -3
- package/dist/plugins/resource/resource.types.d.ts.map +1 -1
- package/dist/plugins/resource/services/add-dictionary-lookup-data.d.ts +3 -0
- package/dist/plugins/resource/services/add-dictionary-lookup-data.d.ts.map +1 -0
- package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -0
- package/dist/plugins/resource/services/add-file-token.d.ts +3 -0
- package/dist/plugins/resource/services/add-file-token.d.ts.map +1 -0
- package/dist/plugins/resource/services/add-file-token.js +1 -0
- package/dist/plugins/resource/services/add-table-lookup-data.d.ts +4 -0
- package/dist/plugins/resource/services/add-table-lookup-data.d.ts.map +1 -0
- package/dist/plugins/resource/services/add-table-lookup-data.js +1 -0
- package/dist/plugins/resource/services/create-relation.js +1 -1
- package/dist/plugins/resource/services/create.d.ts.map +1 -1
- package/dist/plugins/resource/services/create.js +1 -1
- package/dist/plugins/resource/services/delete-relation.js +1 -1
- package/dist/plugins/resource/services/delete.d.ts.map +1 -1
- package/dist/plugins/resource/services/delete.js +1 -1
- package/dist/plugins/resource/services/find-one.d.ts +3 -2
- package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
- package/dist/plugins/resource/services/find-one.js +1 -1
- package/dist/plugins/resource/services/find-relation.d.ts +3 -2
- package/dist/plugins/resource/services/find-relation.d.ts.map +1 -1
- package/dist/plugins/resource/services/find-relation.js +1 -1
- package/dist/plugins/resource/services/find.d.ts.map +1 -1
- package/dist/plugins/resource/services/find.js +1 -1
- package/dist/plugins/resource/services/update-relation.d.ts +11 -0
- package/dist/plugins/resource/services/update-relation.d.ts.map +1 -0
- package/dist/plugins/resource/services/update-relation.js +1 -0
- package/dist/plugins/resource/services/update.d.ts.map +1 -1
- package/dist/plugins/resource/services/update.js +1 -1
- package/dist/plugins/resource/utils/auto-index.d.ts +4 -0
- package/dist/plugins/resource/utils/auto-index.d.ts.map +1 -0
- package/dist/plugins/resource/utils/auto-index.js +1 -0
- package/dist/plugins/resource/utils/fields.js +1 -1
- package/dist/plugins/resource/utils/filters.d.ts +3 -2
- package/dist/plugins/resource/utils/filters.d.ts.map +1 -1
- package/dist/plugins/resource/utils/filters.js +1 -1
- package/dist/plugins/resource/utils/permissions.js +1 -1
- package/dist/plugins/resource/utils/sort.d.ts.map +1 -1
- package/dist/plugins/resource/utils/sort.js +1 -1
- package/dist/plugins/resource/utils/sql.js +1 -1
- package/dist/shared/getIP.js +1 -1
- package/migrations/20260905120000_add_user_foreign_keys.sql +42 -42
- package/package.json +3 -2
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function z(C,N){C=C-0x1b7;const r=U();let p=r[C];return p;}import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(C){const N=process.env[C];if(!N)throw new Error('Missing\x20environment\x20variable:\x20'+C);return N;}export function loadConfig(C={}){const p=z,N={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG===p(0x1b7),'port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT==='false','max':+(process.env.RATE_LIMIT_MAX||0x64),'timeWindow':+(process.env.RATE_LIMIT_TIME_WINDOW||0xea60)},'storagePath':process.env.STORAGE_PATH??'./storage','redactionList':(process.env.REDACTION_LIST||'password')['split'](','),'logger':{'level':process.env.LOG_LEVEL??'info','responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')['map'](r=>r-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+'/log'},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??'us-east-1','bucket':process.env.S3_BUCKET??'','accessKey':process.env.S3_ACCESS_KEY,'secretKey':process.env.S3_SECRET_KEY,'folder':process.env.S3_FOLDER,'forcePathStyle':process.env.S3_FORCE_PATH_STYLE!=='false','tokenSecret':process.env.FILE_TOKEN_SECRET,'tokenTtl':Number(process.env.FILE_TOKEN_TTL??0xe10)},'auth':{'accessToken':process.env.AUTH_ACCESS_TOKEN||'Ch7QR4e73Jg0wx0xOjm','user':process.env.AUTH_USER?JSON['parse'](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??'x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','cookieName':process.env.AUTH_COOKIE_NAME??'session_user_auth','jwtSecret':process.env.AUTH_JWT_SECRET??p(0x1b8),'redirect':process.env.AUTH_REDIRECT??'/','twoFactorRedirect':process.env.AUTH_TWOFACTOR_REDIRECT??'/','cookieOptions':process.env.AUTH_COOKIE_OPTIONS_DOMAIN?{'domain':process.env.AUTH_COOKIE_OPTIONS_DOMAIN,'path':process.env.AUTH_COOKIE_OPTIONS_PATH||'/','httpOnly':Boolean(process.env.AUTH_COOKIE_OPTIONS_HTTP_ONLY||p(0x1b7)),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'true'),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&[p(0x1b9),'strict','none'][p(0x1ba)](process.env.AUTH_COOKIE_OPTIONS_SAME_SITE)?process.env.AUTH_COOKIE_OPTIONS_SAME_SITE:Boolean(process.env.AUTH_COOKIE_OPTIONS_SAME_SITE||'true')}:{'path':'/','httpOnly':!![],'secure':![],'sameSite':!![]}}};return{...N,...C,'logger':{...N['logger'],...C['logger']},'pg':{...N['pg'],...C['pg']},'redis':{...N[p(0x1bb)],...C[p(0x1bb)]},'s3':{...N['s3'],...C['s3']},'auth':{...N['auth'],...C[p(0x1bc)]}};}export{required as requireEnv};function U(){const c=['true','0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','lax','includes','redis','auth'];U=function(){return c;};return U();}
|
package/dist/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function z(C,N){C=C-0xbb;const r=U();let p=r[C];return p;}let defaultContext;export function setContext(C){defaultContext=C;}export function getContext(){if(!defaultContext)throw new Error('Application\x20context\x20is\x20not\x20initialized');return defaultContext;}function U(){const r=['redis'];U=function(){return r;};return U();}export function createContext(C){return{...C,async 'close'(){const N=z;await Promise['allSettled']([C[N(0xbb)]?.['close'](),C['pg']?.['end']()]),await C['logger']['close']();}};}
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var c=z;export class FCoreError extends Error{[c(0x10b)];['statusCode'];[c(0x10c)];constructor(C,N,r=0x1f4,p){super(N),this['code']=C,this['statusCode']=r,this['details']=p,this['name']=new.target.name;}}export class BadRequestError extends FCoreError{constructor(C,N){var x=c;super(x(0x10d),C,0x190,N);}}export class UnauthorizedError extends FCoreError{constructor(C='Authentication\x20required'){var m=c;super(m(0x10e),C,0x191);}}export class ForbiddenError extends FCoreError{constructor(C='Access\x20denied'){super('FORBIDDEN',C,0x193);}}function z(C,N){C=C-0x10b;var r=U();var p=r[C];return p;}export class NotFoundError extends FCoreError{constructor(C='Not\x20found'){var Q=c;super(Q(0x10f),C,0x194);}}export class ConflictError extends FCoreError{constructor(C='Conflict'){super('CONFLICT',C,0x199);}}export class ValidationError extends FCoreError{constructor(C,N){var u=c;super(u(0x110),C,0x1a6,N);}}export class UnsupportedError extends FCoreError{constructor(C=c(0x111)){super('UNSUPPORTED',C,0x1f5);}}function U(){var L=['code','details','BAD_REQUEST_ERROR','UNAUTHORIZED','NOT_FOUND','VALIDATION_ERROR','Operation\x20is\x20not\x20configured'];U=function(){return L;};return U();}
|
package/dist/fastify.d.ts
CHANGED
|
@@ -3,5 +3,6 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { type FastifyPluginAsync } from "fastify";
|
|
5
5
|
import type { AppContext } from "./context.js";
|
|
6
|
-
export
|
|
6
|
+
export type FCoreApiModule = "auth" | "resource" | "file" | "system";
|
|
7
|
+
export default function fcoreFastify(ctx: AppContext, modules?: readonly FCoreApiModule[]): FastifyPluginAsync;
|
|
7
8
|
//# sourceMappingURL=fastify.d.ts.map
|
package/dist/fastify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY/C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;AAarE,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,GAClC,kBAAkB,CAgIpB"}
|
package/dist/fastify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{FCoreError}from'./errors.js';function U(){const d=['split','decorate','ctx','onRoute','startsWith','method','package','tags','public','permissions','url','authorization','Route\x20access\x20not\x20defined','access','includes','Missing\x20permission:\x20','@fastify/multipart','message','logger','debug','test','auth','buffer','disabled','register','max','timeWindow','log'];U=function(){return d;};return U();}import{authRoutes}from'./modules/auth/route.js';import{fileRoutes}from'./modules/file/route.js';function z(C,N){C=C-0x6e;const r=U();let p=r[C];return p;}import{resourceRoutes}from'./modules/resource/route.js';import{systemRoutes}from'./modules/system/route.js';import{createSessionStore}from'./plugins/auth/index.js';import{ForbiddenError}from'./errors.js';import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(C,N,r){const p=decodeURIComponent(N['toString']())['split']('&')['reduce']((c,x)=>{const f=z,[m,Q]=x[f(0x6e)]('=');return{...c,[m]:Q};},{});r(null,p);}export default function fcoreFastify(C,N){return async r=>{const F=z;r[F(0x6f)](F(0x70),C);const {config:p}=C,c=new Map();r['addHook'](F(0x71),m=>{const t=F;if(m['url'][t(0x72)]('/api/')){const Q=m['schema'],u=Array['isArray'](m[t(0x73)])?m['method']:[m['method']];for(const L of u){if(L==='HEAD')continue;const T={'method':L,'endpoint':m['url'],'package':Q?.[t(0x74)]??'fcore','tags':Q?.[t(0x75)]??[],'summary':Q?.['summary']??'','description':Q?.['description']??'','access':Q?.['access']??t(0x76),'permissions':Q?.[t(0x77)]??[]};c['set'](L+'\x20'+m[t(0x78)],T);}}}),r['addHook']('preHandler',async m=>{const h=F,Q=c['get'](m['method']+'\x20'+m['routeOptions']['url']),u=m['raw']['headers']?.[h(0x79)],L=u?.['startsWith']('Bearer\x20')?u['slice'](0x7):null,T=m['user']??(L?await jwtVerifyToken(L):null);!m['user']&&L&&process.env.AUTH_JWT_SECRET&&(m['user']=await jwtVerifyToken(L));if(!Q?.['access'])throw new Error(h(0x7a));if(Q['access']==='public')return!![];if(!T)throw new ForbiddenError('User\x20required');if(Q['access']==='user'&&!Q['permissions']?.['length'])return!![];if(T['type']=='admin')return!![];if(Q[h(0x7b)]==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const Y of Q['permissions']){if(!T['permissions']?.[h(0x7c)](Y))throw new ForbiddenError(h(0x7d)+Y);}return!![];}),await createSessionStore(r,C),await r['register'](import(F(0x7e)),{'limits':{'fileSize':p['maxFileSize']*0x400*0x400}}),r['setErrorHandler']((m,Q,u)=>{const D=F;if(m instanceof FCoreError||m['code']==='FST_ERR_VALIDATION')return u['code'](m['statusCode'])['send']({'error':m['code'],'message':m[D(0x7f)],'details':m['details']});return C[D(0x80)]['error'](m),(p[D(0x81)]||process.env.NODE_ENV===D(0x82)||process.env.VITEST)&&console['error'](m),u['code'](0x1f4)['send']({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const x=m=>!N||N[F(0x7c)](m);if(x(F(0x83)))await r['register'](authRoutes(C));if(x('resource'))await r['register'](resourceRoutes(C));if(x('file'))await r['register'](fileRoutes(C));if(x('system'))await r['register'](systemRoutes(C,c));r['addContentTypeParser']('application/x-www-form-urlencoded',{'parseAs':F(0x84)},urlencodedContentParser),!p['rateLimit']?.[F(0x85)]?r[F(0x86)](import('@fastify/rate-limit'),{'max':p['rateLimit']?.[F(0x87)]||0x64,'timeWindow':p['rateLimit']?.[F(0x88)]||0xea60,'hook':'preHandler','global':!![],'keyGenerator':m=>(m['user']?.['id']||m['ip'])+'-'+m['raw'][F(0x78)]['split']('?')[0x0]}):console[F(0x89)]('⚠️\x20rate\x20limit\x20is\x20disabled');};};
|
package/dist/fcore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function z(C,N){C=C-0xc6;const r=U();let p=r[C];return p;}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function U(){const Y=['redis','endpoint','forcePathStyle','resources'];U=function(){return Y;};return U();}export async function createFCore(C={}){const T=z,N=loadConfig(C['config']),r=createRedis(N[T(0xc6)]),p=createLogger(),c=createDatabase(N['pg']),x=createFileS3({'endpoint':N['s3'][T(0xc7)],'region':N['s3']['region'],'bucket':N['s3']['bucket'],'accessKey':N['s3']['accessKey'],'secretKey':N['s3']['secretKey'],'folder':N['s3']['folder'],'forcePathStyle':N['s3'][T(0xc8)],'tokenSecret':N['s3']['tokenSecret'],'tokenTtl':N['s3']['tokenTtl']}),m=createAudit({'pg':c,'logger':p}),Q=createDictionary({'pg':c,'dictionaries':C['dictionaries']}),u=createResource({'pg':c,'logger':p,'audit':m,'dictionary':Q,'file':x});C[T(0xc9)]?.['length']&&u['register'](C['resources']);const L=createContext({'config':N,'logger':p,'redis':r,'pg':c,'file':x,'resource':u,'audit':m,'dictionary':Q});return setContext(L),L;}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,cAAc,aAAa,CAAC;AAC5B,cAAc,aAAa,CAAC;AAC5B,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,cAAc,YAAY,CAAC;AAC3B,cAAc,wBAAwB,CAAC;AACvC,cAAc,WAAW,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export*from'./errors.js';export*from'./config.js';export*from'./context.js';export*from'./plugins/index.js';export*from'./fcore.js';export*from'./migrations/runner.js';export*from'./type.js';
|
package/dist/migrations/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
function U(){const p=['status','error','exitCode'];U=function(){return p;};return U();}const N=z;import{runMigrations}from'./runner.js';function z(C,N){C=C-0x7b;const r=U();let p=r[C];return p;}import{loadConfig}from'../config.js';try{const config=loadConfig();console['log']('Loaded\x20configuration:',config['pg']);for(const r of await runMigrations({'database':config['pg']}))console['log']((r[N(0x7b)]==='run'?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(C){console[N(0x7c)](C),process[N(0x7d)]=0x1;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import C from'node:fs/promises';import N from'node:path';function z(C,N){C=C-0xff;const r=U();let p=r[C];return p;}function U(){const h=['dir','migrations','databaseUrl','rows','map','version','release','push','end'];U=function(){return h;};return U();}import{createDatabase}from'../plugins/pg.js';export async function runMigrations(r={}){const t=z,p=N['resolve'](r[t(0xff)]??t(0x100)),c=r['database']??databaseFromUrl(r[t(0x101)]??process.env.DATABASE_URL);if(!c)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const x=createDatabase(c);if(!x)throw new Error('empty\x20pg');const m=[];try{await x['query']('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const Q=await x['query']('SELECT\x20version\x20FROM\x20schema_migrations'),u=new Set(Q[t(0x102)][t(0x103)](T=>T[t(0x104)])),L=(await C['readdir'](p))['filter'](T=>T['endsWith']('.sql'))['sort']();for(const T of L){if(u['has'](T)){m['push']({'file':T,'status':'skip'});continue;}const Y=await C['readFile'](N['join'](p,T),'utf8'),f=await x['connect']();try{await f['query']('BEGIN'),await f['query'](Y),await f['query']('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[T]),await f['query']('COMMIT');}catch(F){await f['query']('ROLLBACK');throw F;}finally{f[t(0x105)]();}m[t(0x106)]({'file':T,'status':'run'});}return m;}finally{await x[t(0x107)]();}}function databaseFromUrl(r){if(!r)return undefined;const p=new URL(r);return{'host':p['hostname'],'port':Number(p['port']||0x1538),'database':p['pathname']['slice'](0x1),'user':decodeURIComponent(p['username']),'password':decodeURIComponent(p['password'])};}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const r=z;function U(){const p=['argv','Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]','exitCode','log','Registered\x20user\x20'];U=function(){return p;};return U();}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function z(C,N){C=C-0x102;const r=U();let p=r[C];return p;}import C from'./services/registration.js';const [user,password,type]=process[r(0x102)]['slice'](0x2);if(!user||!password)console['error'](r(0x103)),process[r(0x104)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await C({'user':user,'password':password,'type':type},{'pg':pg});console[r(0x105)](r(0x106)+data['id']+'\x20('+data['type']+')');}catch(N){console['error'](N),process[r(0x104)]=0x1;}finally{await pg['end']();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const r=z;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function z(C,N){C=C-0x149;const r=U();let p=r[C];return p;}function U(){const p=['error','Usage:\x20fcore-password\x20<login>\x20<password>','query','User\x20not\x20found','log','Password\x20changed\x20for\x20'];U=function(){return p;};return U();}import C from'./services/change-password.js';const [login,password]=process['argv']['slice'](0x2);if(!login||!password)console[r(0x149)](r(0x14a)),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[r(0x14b)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error(r(0x14c));await C({'userId':user['id'],'password':password},{'pg':pg}),console[r(0x14d)](r(0x14e)+login);}catch(N){console['error'](N),process['exitCode']=0x1;}finally{await pg['end']();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const u=z;function U(){const T=['audit','access','settings','create','slice','add','error','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','query','User\x20not\x20found','trim','split','get','BEGIN','actions','UPDATE\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20actions\x20=\x20$1,\x20updated_by\x20=\x20$2,\x20updated_at\x20=\x20now()\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20access_id\x20=\x20$3','end'];U=function(){return T;};return U();}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs',u(0x13a),'list','check',u(0x13b),u(0x13c),'dictionaries'],RESOURCE_ACTIONS=['read','update',u(0x13d),'delete'],[login,permissionArg]=process['argv'][u(0x13e)](0x2);function z(C,N){C=C-0x13a;const r=U();let p=r[C];return p;}function expandPermissions(C){const L=u,N=C['split'](',')['map'](p=>p['trim']())['filter'](Boolean),r=new Set();for(const p of N){if(p['includes'](':')){r[L(0x13f)](p);continue;}const c=p==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const x of c){r[L(0x13f)](p+':'+x);}}return[...r];}if(!login||!permissionArg)console[u(0x140)](u(0x141)),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[u(0x142)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error(u(0x143));if(permissionArg[u(0x144)]()==='clear')await pg[u(0x142)]('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console['log']('Permissions\x20cleared\x20for\x20'+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission[u(0x145)](':'),actions=byResource[u(0x146)](resource)??[];actions['push'](action),byResource['set'](resource,actions);}const client=await pg['connect']();try{await client[u(0x142)](u(0x147));for(const [resource,actions]of byResource){const existing=await client['query']('SELECT\x20access_id,\x20actions\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL\x20AND\x20resource\x20=\x20$2',[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row[u(0x148)]??[],...actions])];await client['query'](u(0x149),[merged,user['id'],row['access_id']]);}else await client['query']('INSERT\x20INTO\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(\x20resource,\x20actions,\x20user_uid,\x20created_by,\x20updated_by)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4,\x20$4)',[resource,actions,user['id'],user['id']]);}await client[u(0x142)]('COMMIT');}catch(m){await client['query']('ROLLBACK');throw m;}finally{client['release']();}console['log']('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions['join'](',\x20'));}}catch(Q){console['error'](Q),process['exitCode']=0x1;}finally{await pg[u(0x14a)]();}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CAoK9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import C from'./services/get-current-user.js';function z(C,N){C=C-0x1d4;const r=U();let p=r[C];return p;}import N from'./services/registration.js';import r from'./services/change-password.js';import{authSchemas}from'./schema.js';import p from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';function U(){const d=['GET','permissions','config','auth','redirect','cookie','maxAge','Sign\x20in','public','/api/auth/login','credentials','fcore','admin','post','/api/auth/password','Changes\x20the\x20password\x20for\x20the\x20current\x20user.','user','Terminates\x20the\x20current\x20user\x20session.','write','session','cookieName','/api/auth/user','query'];U=function(){return d;};return U();}export function authRoutes(c){return async x=>{const t=z,m=async Q=>{const F=z,u=Q['method']===F(0x1d4)?Q['query']:Q['body'],L=p(Q),T=await verifyUser({...u,'ip':L},c);T[F(0x1d5)]=await getUserPermissions(T['id'],c);const Y=T['twofa']?c[F(0x1d6)][F(0x1d7)]['twoFactorRedirect']:c['config']['auth'][F(0x1d8)];await Q['login'](T);const f=c['config']['auth']['sessionTimeout']*0x3e8*0x3c;return Q['session']?.[F(0x1d9)]&&(Q['session']['cookie'][F(0x1da)]=f),await Q['session']['save'](),await c['audit']?.['write']?.({'module':'auth','resource':'session','resourceId':Q['session']['sessionId'],'action':'login','userId':T['id'],'ipAddress':L}),{'user':{'id':T['id'],'type':T['type'],'permissions':T['permissions']},'redirectUrl':Y};};x['get']('/api/auth/login',{'schema':{'tags':['fcore','auth'],'summary':t(0x1db),'description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':t(0x1dc),'permissions':[],'querystring':authSchemas['credentials']}},m),x['post'](t(0x1dd),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'body':authSchemas[t(0x1de)]}},m),x['post']('/api/auth/registration',{'schema':{'tags':[t(0x1df),'auth'],'summary':'Register','description':'Creates\x20a\x20regular\x20user\x20account.','access':t(0x1e0),'permissions':['user:create'],'body':authSchemas['credentials']}},async Q=>N(Q['body'],c)),x[t(0x1e1)](t(0x1e2),{'schema':{'tags':['fcore','auth'],'summary':'Change\x20password','description':t(0x1e3),'access':'user','permissions':[],'body':authSchemas['password']}},async Q=>{const h=t;if(!Q['user'])throw new UnauthorizedError('Not\x20authorized');return await r({'userId':Q[h(0x1e4)]['id'],...Q['body']},c),{'success':!![]};}),x['post']('/api/auth/logout',{'schema':{'tags':['fcore',t(0x1d7)],'summary':'Sign\x20out','description':t(0x1e5),'access':'user','permissions':[]}},async(Q,u)=>{const D=t,L={'redirectUrl':'/'};if(!Q['user'])return L;return await c['audit']?.[D(0x1e6)]?.({'module':'auth','resource':'session','resourceId':Q['session']['sessionId'],'action':'logout','userId':Q['user']?.['id']}),await Q[D(0x1e7)]['destroy'](),u['clearCookie'](c['config']['auth'][D(0x1e8)]),Object['defineProperty'](Q,'session',{'value':null,'writable':![],'configurable':![]}),L;}),x['get'](t(0x1e9),{'schema':{'tags':['fcore',t(0x1d7)],'summary':'Get\x20current\x20user','description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas['query']}},async Q=>C({'user':Q[t(0x1e4)],'token':Q[t(0x1ea)]['token']}));};}
|
|
@@ -3,6 +3,9 @@
|
|
|
3
3
|
*/
|
|
4
4
|
import { Static } from "@sinclair/typebox";
|
|
5
5
|
export declare const authSchemas: {
|
|
6
|
+
query: import("@sinclair/typebox").TObject<{
|
|
7
|
+
token: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
8
|
+
}>;
|
|
6
9
|
credentials: import("@sinclair/typebox").TObject<{
|
|
7
10
|
user: import("@sinclair/typebox").TString;
|
|
8
11
|
password: import("@sinclair/typebox").TString;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAQ,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,WAAW;IACtB,WAAW;;;;;IAKX,QAAQ;;;;IAIR,SAAS;;;CAGV,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAQ,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEjD,eAAO,MAAM,WAAW;IACtB,KAAK;;;IAGL,WAAW;;;;;IAKX,QAAQ;;;;IAIR,SAAS;;;CAGV,CAAC;AACF,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,WAAW,CAAC,CAAC;AACjE,MAAM,MAAM,QAAQ,GAAG,MAAM,CAAC,OAAO,WAAW,CAAC,QAAQ,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function z(C,N){C=C-0xb8;const r=U();let p=r[C];return p;}const C=z;import{Type}from'@sinclair/typebox';function U(){const N=['Optional','String','Object'];U=function(){return N;};return U();}export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type['Boolean']())}),'credentials':Type['Object']({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type[C(0xb8)](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type[C(0xb9)]({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type[C(0xba)]({'code':Type['String']({'minLength':0x1})})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:C,password:N,userId:r},{pg:p}){const c=await hashPassword(N);await p['query']('UPDATE\x20admin.users\x0a\x20\x20\x20\x20\x20SET\x20password_hash\x20=\x20$1,\x20updated_at\x20=\x20now(),\x20updated_by\x20=\x20$3\x0a\x20\x20\x20\x20\x20WHERE\x20uid\x20=\x20$2',[c,C||r,r]);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/get-current-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAA8B,cAAc,CAAC,MAAM,EAAE;IACnD,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/get-current-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAA8B,cAAc,CAAC,MAAM,EAAE;IACnD,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5B,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAenC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(C){const {user:N}=C;if(!N)return{};if(C['token']){const {jwtSignToken:r}=await import('../../../plugins/jwt.js'),p=await r(N);N['token']=p;}return N['resources']=[...new Set(N?.['permissions']['map'](c=>c['split'](':')[0x0]))],safeUser(N);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function z(C,N){C=C-0x1a6;const r=U();let p=r[C];return p;}import{ConflictError}from'../../../errors.js';function U(){const u=['query','Login\x20is\x20already\x20in\x20use'];U=function(){return u;};return U();}import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:C,password:N,type:r},{pg:p}){const Q=z,c=await hashPassword(N),x=await p[Q(0x1a6)]('INSERT\x20INTO\x20admin.users\x20(login,\x20password_hash,\x20user_type)\x0a\x20\x20\x20\x20\x20SELECT\x20$1,\x20$2,\x20$3\x0a\x20\x20\x20\x20\x20WHERE\x20NOT\x20EXISTS\x20(SELECT\x201\x20FROM\x20admin.users\x20WHERE\x20login\x20=\x20$1)\x0a\x20\x20\x20\x20\x20RETURNING\x20uid\x20AS\x20id,\x20user_type\x20AS\x20type',[C,c,r||'regular']),m=x['rows'][0x0];if(!m)throw new ConflictError(Q(0x1a7));return{'user':m};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(C,N){return unsupported('Two-factor\x20provider');}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mime.d.ts","sourceRoot":"","sources":["../../../src/modules/file/mime.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var C=z;export default new Set(['image/jpeg','image/png','image/gif','image/webp',C(0x1e6),'image/tiff','image/svg+xml',C(0x1e7),C(0x1e8),C(0x1e9),'application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-powerpoint',C(0x1ea),'application/vnd.oasis.opendocument.text',C(0x1eb),'application/vnd.oasis.opendocument.presentation','text/plain',C(0x1ec),'text/markdown','application/json',C(0x1ed),C(0x1ee),'application/geo+json','application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed','application/x-7z-compressed','application/x-rar-compressed','application/vnd.rar','application/gzip',C(0x1ef),'application/x-tar','audio/mpeg','audio/wav',C(0x1f0),'audio/webm','audio/mp4','video/mp4','video/mpeg','video/webm','video/quicktime','video/x-msvideo','application/octet-stream']);function z(C,N){C=C-0x1e6;var r=U();var p=r[C];return p;}function U(){var N=['image/bmp','image/x-icon','image/avif','application/pdf','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.spreadsheet','text/csv','application/xml','text/xml','application/x-gzip','audio/ogg'];U=function(){return N;};return U();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/file/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/file/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAMnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CA8F9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function U(){const h=['fcore','Get\x20file\x20by\x20token','fileDownloadQuery','verify','query','startsWith','split','replace','attachment','Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','filename','resource','Resize\x20file','files:read','resizeQuery','mime','image/png','Cache-Control'];U=function(){return h;};return U();}function z(C,N){C=C-0xa7;const r=U();let p=r[C];return p;}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(C){return async N=>{const Y=z;N['get']('/api/file/:token',{'schema':{'tags':[Y(0xa7),'file'],'summary':Y(0xa8),'description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas[Y(0xa9)]}},async(r,p)=>{const f=Y,c=C['file'][f(0xaa)](r['params']['token']),x=await getFile({'pathOrToken':c},C),m=await fileTypeFromBuffer(x),Q=m?.['mime']??'application/octet-stream',u=r[f(0xab)]['download']===!![],L=Q[f(0xac)]('image/')||Q==='application/pdf',T=c[f(0xad)]('/')['pop']()?.[f(0xae)](/[^A-Za-z0-9._-]/g,'_')??'file';return p['type'](Q),p['header']('Content-Disposition',(u||!L?f(0xaf):'inline')+';\x20filename=\x22'+T+'\x22')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),p['send'](x);}),N['post']('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':'Upload\x20file','description':Y(0xb0),'access':'user','permissions':['files:create']}},async r=>{const F=Y,p=await r['file']();if(!p)throw new Error('File\x20is\x20required');return uploadFile({'file':p,'metadata':{'name':p[F(0xb1)],'path':p['fields']['path']?.['value'],'resource':p['fields'][F(0xb2)]?.['value'],'resourceId':p['fields']['resourceId']?.['value']},'user':r['user']},C);}),N['get']('/api/file/:token/resize',{'schema':{'tags':['fcore','file'],'summary':Y(0xb3),'description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':[Y(0xb4)],'params':fileSchemas['fileToken'],'querystring':fileSchemas[Y(0xb5)]}},async(r,p)=>{const t=Y,c=await resizeFile({'pathOrToken':C['file']?.['verify'](r['params']['token']),...r['query']},C),x=await fileTypeFromBuffer(c);return p['type'](x?.[t(0xb6)]??t(0xb7)),p['header']('Content-Disposition','inline')['header'](t(0xb8),'public,\x20max-age=86400,\x20immutable'),p['send'](c);});};}
|
|
@@ -5,6 +5,9 @@ export declare const fileSchemas: {
|
|
|
5
5
|
fileToken: import("@sinclair/typebox").TObject<{
|
|
6
6
|
token: import("@sinclair/typebox").TString;
|
|
7
7
|
}>;
|
|
8
|
+
fileDownloadQuery: import("@sinclair/typebox").TObject<{
|
|
9
|
+
download: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
10
|
+
}>;
|
|
8
11
|
filePath: import("@sinclair/typebox").TObject<{
|
|
9
12
|
"*": import("@sinclair/typebox").TString;
|
|
10
13
|
}>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/file/schema.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW;IACvB,MAAM;;;IAGN,SAAS;;;IAGT,QAAQ;;;IAGR,MAAM;;;;;;;;;IASN,SAAS;;;;IAIT,WAAW;;;;;CAWX,CAAC"}
|
|
1
|
+
{"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/file/schema.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW;IACvB,MAAM;;;IAGN,SAAS;;;IAGT,iBAAiB;;;IAGjB,QAAQ;;;IAGR,MAAM;;;;;;;;;IASN,SAAS;;;;IAIT,WAAW;;;;;CAWX,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function U(){const N=['Object','String','Optional','Literal','outside'];U=function(){return N;};return U();}function z(C,N){C=C-0xc1;const r=U();let p=r[C];return p;}const C=z;import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type['String']({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type[C(0xc1)]({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type[C(0xc2)]({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type[C(0xc3)](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type[C(0xc1)]({'entityType':Type[C(0xc3)](Type['String']({'minLength':0x1})),'entityId':Type[C(0xc3)](Type['String']({'minLength':0x1}))}),'resizeQuery':Type[C(0xc1)]({'width':Type['Optional'](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type[C(0xc3)](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type['Union']([Type['Literal']('cover'),Type[C(0xc4)]('contain'),Type['Literal']('fill'),Type['Literal']('inside'),Type['Literal'](C(0xc5))]))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{NotFoundError}from'../../../errors.js';export async function getFile(C,N){var r=z;if(!N[r(0x183)])throw new Error('empty\x20file');if(!await N['file']['exists'](C['pathOrToken']))throw new NotFoundError('File\x20not\x20found'+C['pathOrToken']);return N[r(0x183)][r(0x184)](C['pathOrToken']);}function z(C,N){C=C-0x183;var r=U();var p=r[C];return p;}function U(){var p=['file','get'];U=function(){return p;};return U();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resize-file.d.ts","sourceRoot":"","sources":["../../../../src/modules/file/services/resize-file.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"resize-file.d.ts","sourceRoot":"","sources":["../../../../src/modules/file/services/resize-file.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAQtD,MAAM,WAAW,gBAAgB;IAC/B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,GAAG,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAC;CAC3D;AAED,wBAAsB,UAAU,CAC9B,MAAM,EAAE,gBAAgB,EACxB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,MAAM,CAAC,CAuCjB"}
|