@opengis/fcore 0.0.1-beta.21 → 0.0.1-beta.22
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.js +1 -1
- package/dist/fcore.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.js +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.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.js +1 -1
- package/dist/modules/file/route.js +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.js +1 -1
- package/dist/modules/file/services/upload-file.js +1 -1
- package/dist/modules/resource/route.js +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.js +1 -1
- package/dist/modules/resource/services/get-resource.js +1 -1
- package/dist/modules/resource/services/list-resource-relation.js +1 -1
- package/dist/modules/resource/services/list-resources.js +1 -1
- package/dist/modules/resource/services/search-resource.js +1 -1
- package/dist/modules/resource/services/suggest-resource.js +1 -1
- package/dist/modules/resource/services/update-resource-relation.js +1 -1
- 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.js +1 -1
- package/dist/modules/system/schema.js +1 -1
- package/dist/modules/system/services/check-system.js +1 -1
- package/dist/modules/system/services/get-access.js +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.js +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.js +1 -1
- package/dist/modules/system/services/update-dictionary.js +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/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.js +1 -1
- package/dist/plugins/file.js +1 -1
- package/dist/plugins/jwt.js +1 -1
- package/dist/plugins/logger/index.js +1 -1
- package/dist/plugins/logger/transport.js +1 -1
- package/dist/plugins/pg.js +1 -1
- package/dist/plugins/redis.js +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 +1 -0
- package/dist/plugins/resource/resource.types.d.ts.map +1 -1
- package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
- package/dist/plugins/resource/services/add-file-token.js +1 -1
- package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
- package/dist/plugins/resource/services/create-relation.js +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.js +1 -1
- 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.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.js +1 -1
- package/dist/plugins/resource/services/update.js +1 -1
- package/dist/plugins/resource/utils/auto-index.js +1 -1
- package/dist/plugins/resource/utils/fields.js +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.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 +93 -93
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function d(B,K){B=B-0x81;const T=E();let L=T[B];return L;}import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function E(){const x=['development','true','false','split','map','strict','logger','auth'];E=function(){return x;};return E();}function required(B){const K=process.env[B];if(!K)throw new Error('Missing\x20environment\x20variable:\x20'+B);return K;}export function loadConfig(B={}){const L=d,K={'env':process.env.NODE_ENV??L(0x81),'debug':process.env.DEBUG===L(0x82),'port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT===L(0x83),'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')[L(0x84)](','),'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'](',')[L(0x85)](T=>T-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!==L(0x83),'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??'0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','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||L(0x82)),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'true'),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&['lax',L(0x86),'none']['includes'](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{...K,...B,'logger':{...K['logger'],...B[L(0x87)]},'pg':{...K['pg'],...B['pg']},'redis':{...K['redis'],...B['redis']},'s3':{...K['s3'],...B['s3']},'auth':{...K[L(0x88)],...B['auth']}};}export{required as requireEnv};
|
package/dist/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let defaultContext;function
|
|
1
|
+
let defaultContext;function d(B,K){B=B-0x1b0;const T=E();let L=T[B];return L;}export function setContext(B){defaultContext=B;}export function getContext(){const K=d;if(!defaultContext)throw new Error(K(0x1b0));return defaultContext;}function E(){const L=['Application\x20context\x20is\x20not\x20initialized','allSettled'];E=function(){return L;};return E();}export function createContext(B){return{...B,async 'close'(){const T=d;await Promise[T(0x1b1)]([B['redis']?.['close'](),B['pg']?.['end']()]),await B['logger']['close']();}};}
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var x=d;export class FCoreError extends Error{[x(0xcf)];['statusCode'];['details'];constructor(B,K,T=0x1f4,L){super(K),this['code']=B,this['statusCode']=T,this['details']=L,this['name']=new.target.name;}}export class BadRequestError extends FCoreError{constructor(B,K){var y=x;super(y(0xd0),B,0x190,K);}}function d(B,K){B=B-0xcf;var T=E();var L=T[B];return L;}export class UnauthorizedError extends FCoreError{constructor(B='Authentication\x20required'){super('UNAUTHORIZED',B,0x191);}}export class ForbiddenError extends FCoreError{constructor(B='Access\x20denied'){super('FORBIDDEN',B,0x193);}}export class NotFoundError extends FCoreError{constructor(B='Not\x20found'){var P=x;super(P(0xd1),B,0x194);}}function E(){var p=['code','BAD_REQUEST_ERROR','NOT_FOUND','Conflict','CONFLICT','UNSUPPORTED'];E=function(){return p;};return E();}export class ConflictError extends FCoreError{constructor(B=x(0xd2)){var g=x;super(g(0xd3),B,0x199);}}export class ValidationError extends FCoreError{constructor(B,K){super('VALIDATION_ERROR',B,0x1a6,K);}}export class UnsupportedError extends FCoreError{constructor(B='Operation\x20is\x20not\x20configured'){var j=x;super(j(0xd4),B,0x1f5);}}
|
package/dist/fastify.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import B from'fastify-plugin';function d(B,K){B=B-0xa6;const T=E();let L=T[B];return L;}import{FCoreError}from'./errors.js';import{authRoutes}from'./modules/auth/route.js';import{fileRoutes}from'./modules/file/route.js';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(K,T,L){const r=d,x=decodeURIComponent(T['toString']())['split']('&')[r(0xa6)]((y,P)=>{const u=r,[g,j]=P[u(0xa7)]('=');return{...y,[g]:j};},{});L(null,x);}function E(){const l=['reduce','split','isArray','method','url','package','fcore','access','public','permissions','addHook','user','auth','config','authorization','startsWith','Bearer\x20','type','$resource','params','register','statusCode','logger','send','message','code','Internal\x20server\x20error','includes','resource','application/x-www-form-urlencoded','rateLimit','disabled','max','raw'];E=function(){return l;};return E();}export default function fcoreFastify(K,T){return B(async L=>{const h=d;L['decorate']('ctx',K);const {config:x}=K,y=new Map();L['addHook']('onRoute',g=>{const c=d,j=g['schema'],p=Array[c(0xa8)](g[c(0xa9)])?g['method']:[g['method']];for(const J of p){if(J==='HEAD')continue;const Q={'method':J,'endpoint':g[c(0xaa)],'package':j?.[c(0xab)]??c(0xac),'tags':j?.['tags']??[],'summary':j?.['summary']??'','description':j?.['description']??'','access':j?.[c(0xad)]??c(0xae),'permissions':j?.[c(0xaf)]??[]};y['set'](J+'\x20'+g['url'],Q);}}),L[h(0xb0)]('preHandler',async g=>{const S=h;if(g['routeOptions']['url']==='*')return!![];const j=y['get'](g['method']+'\x20'+g['routeOptions']['url']),p=!g[S(0xb1)]&&process['platform']==='win32'&&K['config']?.[S(0xb2)]?.['user']?K[S(0xb3)]?.['auth']?.[S(0xb1)]:null,J=g['raw']['headers']?.[S(0xb4)],Q=J?.[S(0xb5)](S(0xb6))?J['slice'](0x7):null,G=g['user']??(Q?await jwtVerifyToken(Q):p);!g['user']&&Q&&process.env.AUTH_JWT_SECRET&&(g['user']=await jwtVerifyToken(Q));if(!j?.['access'])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(j['access']==='public')return!![];if(!G)throw new ForbiddenError('User\x20required');if(j[S(0xad)]===S(0xb1)&&!j['permissions']?.['length'])return!![];if(G[S(0xb7)]=='admin')return!![];if(j[S(0xad)]==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const f of j['permissions']){const A=f?.['replace'](S(0xb8),g[S(0xb9)]['resource']??'');if(!G['permissions']?.['includes'](A))throw new ForbiddenError('Missing\x20permission:\x20'+A);}return!![];}),await createSessionStore(L,K),await L[h(0xba)](import('@fastify/multipart'),{'limits':{'fileSize':x['maxFileSize']*0x400*0x400}}),L['setErrorHandler']((g,j,p)=>{const Y=h;if(g instanceof FCoreError||g['code']==='FST_ERR_VALIDATION'||g['statusCode']<0x1f4)return g[Y(0xbb)]<0x1f4&&K[Y(0xbc)]['warn'](g),p['code'](g['statusCode'])[Y(0xbd)]({'error':g['code'],'message':g[Y(0xbe)],'details':g['details']});return K['logger']['error'](g),(x['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console['error'](g),p[Y(0xbf)](0x1f4)[Y(0xbd)]({'error':'INTERNAL_ERROR','message':Y(0xc0)});});const P=g=>!T||T[h(0xc1)](g);if(P('auth'))await L[h(0xba)](authRoutes(K));if(P(h(0xc2)))await L['register'](resourceRoutes(K));if(P('file'))await L[h(0xba)](fileRoutes(K));if(P('system'))await L['register'](systemRoutes(K,y));L['addContentTypeParser'](h(0xc3),{'parseAs':'buffer'},urlencodedContentParser),!x[h(0xc4)]?.[h(0xc5)]?L['register'](import('@fastify/rate-limit'),{'max':x['rateLimit']?.[h(0xc6)]||0x64,'timeWindow':x['rateLimit']?.['timeWindow']||0xea60,'hook':'preHandler','global':!![],'keyGenerator':g=>(g['user']?.['id']||g['ip'])+'-'+g[h(0xc7)]['url']['split']('?')[0x0]}):console['log']('⚠️\x20rate\x20limit\x20is\x20disabled');});}
|
package/dist/fcore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function
|
|
1
|
+
import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function E(){const Q=['config','bucket','secretKey','tokenTtl','length','register'];E=function(){return Q;};return E();}import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function d(B,K){B=B-0x1a6;const T=E();let L=T[B];return L;}export async function createFCore(B={}){const J=d,K=loadConfig(B[J(0x1a6)]),T=createRedis(K['redis']),L=createLogger(),x=createDatabase(K['pg']),y=createFileS3({'endpoint':K['s3']['endpoint'],'region':K['s3']['region'],'bucket':K['s3'][J(0x1a7)],'accessKey':K['s3']['accessKey'],'secretKey':K['s3'][J(0x1a8)],'folder':K['s3']['folder'],'forcePathStyle':K['s3']['forcePathStyle'],'tokenSecret':K['s3']['tokenSecret'],'tokenTtl':K['s3'][J(0x1a9)]}),P=createAudit({'pg':x,'logger':L}),g=createDictionary({'pg':x,'dictionaries':B['dictionaries']}),j=createResource({'pg':x,'logger':L,'audit':P,'dictionary':g,'file':y});B['resources']?.[J(0x1aa)]&&j[J(0x1ab)](B['resources']);const p=createContext({'config':K,'logger':L,'redis':T,'pg':x,'file':y,'resource':j,'audit':P,'dictionary':g});return setContext(p),p;}
|
package/dist/migrations/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const j=d;import{runMigrations}from'./runner.js';function d(B,K){B=B-0x12f;const T=E();let L=T[B];return L;}function E(){const p=['includes','find','resolve','argv','log','****','exitCode'];E=function(){return p;};return E();}import{loadConfig}from'../config.js';import B from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL('../../migrations',import.meta.url));function migrationDirectory(K){const g=d,T=K['indexOf']('--dir');if(T>=0x0){const x=K[T+0x1];if(!x)throw new Error('--dir\x20requires\x20a\x20folder\x20path');return B['resolve'](x);}if(K[g(0x12f)]('--fcore'))return packageMigrations;const L=K[g(0x130)](y=>!y['startsWith']('--'));return B[g(0x131)](L??'migrations');}try{const config=loadConfig(),dir=migrationDirectory(process[j(0x132)]['slice'](0x2));console[j(0x133)]('Loaded\x20configuration:',{...config['pg'],'user':j(0x134),'password':'****'}),console[j(0x133)]('Using\x20migration\x20directory:',dir,process['argv']['slice'](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console['log']((r['status']==='run'?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(P){console['error'](P),process[j(0x135)]=0x1;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import B from'node:fs/promises';function d(B,K){B=B-0x1ba;const T=E();let L=T[B];return L;}function E(){const u=['resolve','database','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','version','readdir','filter','sort','push','join','connect','ROLLBACK','release','run','slice'];E=function(){return u;};return E();}import K from'node:path';import{createDatabase}from'../plugins/pg.js';export async function runMigrations(T={}){const A=d,L=K[A(0x1ba)](T['dir']??'migrations'),x=T[A(0x1bb)]??databaseFromUrl(T['databaseUrl']??process.env.DATABASE_URL);if(!x)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const y=createDatabase(x);if(!y)throw new Error('empty\x20pg');const P=[];try{await y[A(0x1bc)](A(0x1bd));const g=await y[A(0x1bc)]('SELECT\x20version\x20FROM\x20schema_migrations'),j=new Set(g['rows']['map'](J=>J[A(0x1be)])),p=(await B[A(0x1bf)](L))[A(0x1c0)](J=>J['endsWith']('.sql'))[A(0x1c1)]();for(const J of p){if(j['has'](J)){P[A(0x1c2)]({'file':J,'status':'skip'});continue;}const Q=await B['readFile'](K[A(0x1c3)](L,J),'utf8'),G=await y[A(0x1c4)]();try{await G['query']('BEGIN'),await G[A(0x1bc)](Q),await G['query']('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[J]),await G['query']('COMMIT');}catch(f){await G['query'](A(0x1c5));throw f;}finally{G[A(0x1c6)]();}P[A(0x1c2)]({'file':J,'status':A(0x1c7)});}return P;}finally{await y['end']();}}function databaseFromUrl(T){const r=d;if(!T)return undefined;const L=new URL(T);return{'host':L['hostname'],'port':Number(L['port']||0x1538),'database':L['pathname'][r(0x1c8)](0x1),'user':decodeURIComponent(L['username']),'password':decodeURIComponent(L['password'])};}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const T=d;function E(){const L=['error','Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'];E=function(){return L;};return E();}import{loadConfig}from'../../config.js';function d(B,K){B=B-0x1d2;const T=E();let L=T[B];return L;}import{createDatabase}from'../../plugins/pg.js';import B from'./services/registration.js';const [user,password,type]=process['argv']['slice'](0x2);if(!user||!password)console[T(0x1d2)](T(0x1d3)),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await B({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(K){console['error'](K),process['exitCode']=0x1;}finally{await pg['end']();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
function E(){const L=['argv','Usage:\x20fcore-password\x20<login>\x20<password>','exitCode','query','rows','User\x20not\x20found'];E=function(){return L;};return E();}function d(B,K){B=B-0x1c6;const T=E();let L=T[B];return L;}const T=d;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import B from'./services/change-password.js';const [login,password]=process[T(0x1c6)]['slice'](0x2);if(!login||!password)console['error'](T(0x1c7)),process[T(0x1c8)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[T(0x1c9)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result[T(0x1ca)][0x0];if(!user)throw new Error(T(0x1cb));await B({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(K){console['error'](K),process['exitCode']=0x1;}finally{await pg['end']();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
const j=d;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs','audit',j(0x1ee),j(0x1ef),'access','settings','dictionaries'],RESOURCE_ACTIONS=['read','update','create','delete'],[login,permissionArg]=process['argv']['slice'](0x2);function d(B,K){B=B-0x1ee;const T=E();let L=T[B];return L;}function expandPermissions(B){const p=j,K=B['split'](',')['map'](L=>L[p(0x1f0)]())[p(0x1f1)](Boolean),T=new Set();for(const L of K){if(L['includes'](':')){T['add'](L);continue;}const x=L==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const y of x){T['add'](L+':'+y);}}return[...T];}function E(){const J=['list','check','trim','filter','error','exitCode','User\x20not\x20found','get','push','set','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)','release','Granted\x20permissions\x20for\x20','join'];E=function(){return J;};return E();}if(!login||!permissionArg)console[j(0x1f2)]('Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>'),process[j(0x1f3)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query']('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(j(0x1f4));if(permissionArg['trim']()==='clear')await pg['query']('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['split'](':'),actions=byResource[j(0x1f5)](resource)??[];actions[j(0x1f6)](action),byResource[j(0x1f7)](resource,actions);}const client=await pg['connect']();try{await client['query']('BEGIN');for(const [resource,actions]of byResource){const existing=await client[j(0x1f8)]('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['actions']??[],...actions])];await client[j(0x1f8)]('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',[merged,user['id'],row['access_id']]);}else await client['query'](j(0x1f9),[resource,actions,user['id'],user['id']]);}await client[j(0x1f8)]('COMMIT');}catch(P){await client[j(0x1f8)]('ROLLBACK');throw P;}finally{client[j(0x1fa)]();}console['log'](j(0x1fb)+login+':\x20'+permissions[j(0x1fc)](',\x20'));}}catch(g){console[j(0x1f2)](g),process['exitCode']=0x1;}finally{await pg['end']();}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import
|
|
1
|
+
import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import B from'./services/get-current-user.js';import K from'./services/registration.js';import T from'./services/change-password.js';function d(B,K){B=B-0xa8;const T=E();let L=T[B];return L;}import{authSchemas}from'./schema.js';import L from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';function E(){const c=['GET','body','config','auth','redirect','cookie','save','audit','session','login','get','Sign\x20in','admin','user:create','credentials','post','/api/auth/password','password','fcore','Sign\x20out','user','query'];E=function(){return c;};return E();}export function authRoutes(x){return async y=>{const A=d,P=async g=>{const f=d,j=g['method']===f(0xa8)?g['query']:g[f(0xa9)],p=L(g),J=await verifyUser({...j,'ip':p},x);J['permissions']=await getUserPermissions(J['id'],x);const Q=J['twofa']?x[f(0xaa)][f(0xab)]['twoFactorRedirect']:x[f(0xaa)]['auth'][f(0xac)];await g['login'](J);const G=x['config'][f(0xab)]['sessionTimeout']*0x3e8*0x3c;return g['session']?.[f(0xad)]&&(g['session']['cookie']['maxAge']=G),await g['session'][f(0xae)](),await x[f(0xaf)]?.['write']?.({'module':f(0xab),'resource':f(0xb0),'resourceId':g['session']['sessionId'],'action':f(0xb1),'userId':J['id'],'ipAddress':p}),{'user':{'id':J['id'],'type':J['type'],'permissions':J['permissions']},'redirectUrl':Q};};y[A(0xb2)]('/api/auth/login',{'schema':{'tags':['fcore','auth'],'summary':A(0xb3),'description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'querystring':authSchemas['credentials']}},P),y['post']('/api/auth/login',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'body':authSchemas['credentials']}},P),y['post']('/api/auth/registration',{'schema':{'tags':['fcore','auth'],'summary':'Register','description':'Creates\x20a\x20regular\x20user\x20account.','access':A(0xb4),'permissions':[A(0xb5)],'body':authSchemas[A(0xb6)]}},async g=>K(g['body'],x)),y[A(0xb7)](A(0xb8),{'schema':{'tags':['fcore','auth'],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas[A(0xb9)]}},async g=>{const r=A;if(!g['user'])throw new UnauthorizedError('Not\x20authorized');return await T({'userId':g['user']['id'],...g[r(0xa9)]},x),{'success':!![]};}),y['post']('/api/auth/logout',{'schema':{'tags':[A(0xba),'auth'],'summary':A(0xbb),'description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(g,j)=>{const u=A,p={'redirectUrl':'/'};if(!g['user'])return p;return await x['audit']?.['write']?.({'module':'auth','resource':'session','resourceId':g['session']['sessionId'],'action':'logout','userId':g[u(0xbc)]?.['id']}),await g['session']['destroy'](),j['clearCookie'](x['config']['auth']['cookieName']),Object['defineProperty'](g,u(0xb0),{'value':null,'writable':![],'configurable':![]}),p;}),y['get']('/api/auth/user',{'schema':{'tags':[A(0xba),'auth'],'summary':'Get\x20current\x20user','description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas['query']}},async g=>B({'user':g[A(0xbc)],'token':g[A(0xbd)]['token']}));};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
const B=d;import{Type}from'@sinclair/typebox';function d(B,K){B=B-0x1a5;const T=E();let L=T[B];return L;}export const authSchemas={'query':Type[B(0x1a5)]({'token':Type['Optional'](Type[B(0x1a6)]())}),'credentials':Type[B(0x1a5)]({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'password':Type[B(0x1a5)]({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type[B(0x1a7)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type['String']({'minLength':0x1})})};function E(){const K=['Object','Boolean','String'];E=function(){return K;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:B,password:K,userId:T},{pg:L}){const x=await hashPassword(K);await L['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',[x,B||T,T]);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(
|
|
1
|
+
import{safeUser}from'../../utils/safe-user.js';function d(B,K){B=B-0x120;const T=E();let L=T[B];return L;}export default async function getCurrentUser(B){const y=d,{user:K}=B;if(!K)return{};if(B['token']){const {jwtSignToken:T}=await import('../../../plugins/jwt.js'),L=await T(K);K['token']=L;}return K[y(0x120)]=[...new Set(K?.[y(0x121)][y(0x122)](x=>x[y(0x123)](':')[0x0]))],safeUser(K);}function E(){const P=['resources','permissions','map','split'];E=function(){return P;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:
|
|
1
|
+
function d(B,K){B=B-0x99;const T=E();let L=T[B];return L;}function E(){const j=['rows'];E=function(){return j;};return E();}import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:B,password:K,type:T},{pg:L}){const g=d,x=await hashPassword(K),y=await L['query']('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',[B,x,T||'regular']),P=y[g(0x99)][0x0];if(!P)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':P};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(
|
|
1
|
+
import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(B,K){return unsupported('Two-factor\x20provider');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
function E(){var K=['image/jpeg','image/svg+xml','application/vnd.oasis.opendocument.presentation','application/json','application/geo+json','application/zip','application/x-zip-compressed','audio/wav','audio/mp4','video/mp4','video/quicktime'];E=function(){return K;};return E();}var B=d;function d(B,K){B=B-0x6e;var T=E();var L=T[B];return L;}export default new Set([B(0x6e),'image/png','image/gif','image/webp','image/bmp','image/tiff',B(0x6f),'image/x-icon','image/avif','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet',B(0x70),'text/plain','text/csv','text/markdown',B(0x71),'application/xml','text/xml',B(0x72),'application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz',B(0x73),B(0x74),'application/x-7z-compressed','application/x-rar-compressed','application/vnd.rar','application/gzip','application/x-gzip','application/x-tar','audio/mpeg',B(0x75),'audio/ogg','audio/webm',B(0x76),B(0x77),'video/mpeg','video/webm',B(0x78),'video/x-msvideo','application/octet-stream']);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function d(B,K){B=B-0x10f;const T=E();let L=T[B];return L;}function E(){const r=['fcore','file','Get\x20file\x20by\x20token','fileDownloadQuery','params','startsWith','image/','split','type','post','/api/file/upload','File\x20is\x20required','value','resourceId','/api/file/:token/resize','files:read','verify','token'];E=function(){return r;};return E();}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(B){return async K=>{const Q=d;K['get']('/api/file/:token',{'schema':{'tags':[Q(0x10f),Q(0x110)],'summary':Q(0x111),'description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas[Q(0x112)]}},async(T,L)=>{const G=Q,x=B['file']['verify'](T[G(0x113)]['token']),y=await getFile({'pathOrToken':x},B),P=await fileTypeFromBuffer(y),g=P?.['mime']??'application/octet-stream',j=T['query']['download']===!![],p=g[G(0x114)](G(0x115))||g==='application/pdf',J=x[G(0x116)]('/')['pop']()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??'file';return L[G(0x117)](g),L['header']('Content-Disposition',(j||!p?'attachment':'inline')+';\x20filename=\x22'+J+'\x22')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),L['send'](y);}),K[Q(0x118)](Q(0x119),{'schema':{'tags':['fcore','file'],'summary':'Upload\x20file','description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async T=>{const f=Q,L=await T[f(0x110)]();if(!L)throw new Error(f(0x11a));return uploadFile({'file':L,'metadata':{'name':L['filename'],'path':L['fields']['path']?.[f(0x11b)],'resource':L['fields']['resource']?.['value'],'resourceId':L['fields'][f(0x11c)]?.[f(0x11b)]},'user':T['user']},B);}),K['get'](Q(0x11d),{'schema':{'tags':['fcore',Q(0x110)],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':[Q(0x11e)],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(T,L)=>{const A=Q,x=await resizeFile({'pathOrToken':B['file']?.[A(0x11f)](T['params'][A(0x120)]),...T['query']},B),y=await fileTypeFromBuffer(x);return L['type'](y?.['mime']??'image/png'),L['header']('Content-Disposition','inline')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),L['send'](x);});};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function E(){const K=['Object','Boolean','Optional','Integer','Union','cover','Literal'];E=function(){return K;};return E();}function d(B,K){B=B-0x73;const T=E();let L=T[B];return L;}const B=d;import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type[B(0x73)]({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type['String']({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type['Optional'](Type[B(0x74)]())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type[B(0x75)](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type[B(0x75)](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type[B(0x76)]({'minimum':0x1,'default':0xc8})),'height':Type['Optional'](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type[B(0x77)]([Type['Literal'](B(0x78)),Type[B(0x79)]('contain'),Type['Literal']('fill'),Type['Literal']('inside'),Type['Literal']('outside')]))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function d(B,K){B=B-0xe6;var T=E();var L=T[B];return L;}import{NotFoundError}from'../../../errors.js';export async function getFile(B,K){var T=d;if(!K[T(0xe6)])throw new Error(T(0xe7));if(!await K['file']['exists'](B[T(0xe8)]))throw new NotFoundError('File\x20not\x20found'+B['pathOrToken']);return K['file'][T(0xe9)](B[T(0xe8)]);}function E(){var L=['file','empty\x20file','pathOrToken','get'];E=function(){return L;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';function
|
|
1
|
+
import{NotFoundError,ValidationError}from'../../../errors.js';function d(B,K){B=B-0xf7;const T=E();let L=T[B];return L;}import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';function E(){const u=['width','sha256','update','digest','.jpg','ENOENT','file','startsWith','Only\x20image\x20files\x20can\x20be\x20resized','cover','\x20must\x20be\x20a\x20positive\x20integer'];E=function(){return u;};return E();}import{mkdir,readFile,writeFile}from'node:fs/promises';import B from'node:path';import K from'sharp';export async function resizeFile(T,L){const A=d,x=T['pathOrToken']??T['path'];if(!x)throw new ValidationError('File\x20path\x20is\x20required');const y=parseDimension(T[A(0xf7)],A(0xf7))??0xc8,P=parseDimension(T['height'],'height'),g=createHash(A(0xf8))[A(0xf9)](x+':'+y+':'+(P??'auto')+':'+(T['fit']??'cover'))[A(0xfa)]('hex'),j=B['resolve']('logs','resize'),p=B['join'](j,g+A(0xfb));try{return await readFile(p);}catch(f){if(f['code']!==A(0xfc))throw f;}if(!await L[A(0xfd)]['exists'](x))throw new NotFoundError('File\x20not\x20found');const J=await L[A(0xfd)]['get'](x),Q=await fileTypeFromBuffer(J);if(!Q?.['mime'][A(0xfe)]('image/'))throw new ValidationError(A(0xff));const G=await K(J)['resize']({'width':y,'height':P,'fit':T['fit']??A(0x100)})['toBuffer']();return await mkdir(j,{'recursive':!![]}),await writeFile(p,G),G;}function parseDimension(T,L){const r=d;if(T===undefined||T==='')return undefined;const x=Number(T);if(!Number['isInteger'](x)||x<=0x0)throw new ValidationError(L+r(0x101));return x;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';import B from'../mime.js';function E(){const f=['name','replace','padStart','path','resource','uploads/','has','mimetype','put','query','\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20file_type,\x20size,uploaded_name,file_name,ext,created_by)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4,\x20$5,\x20$6,\x20$7,\x20$8,\x20$9)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20','file','metadata','pop'];E=function(){return f;};return E();}import{randomUUID}from'node:crypto';function d(B,K){B=B-0x19d;const T=E();let L=T[B];return L;}export async function uploadFile(K,T){const G=d,L=(K['metadata'][G(0x19d)]??randomUUID())[G(0x19e)](/[^a-zA-Z0-9._-]/g,'_'),x=new Date(),y=String(x['getFullYear']())['slice'](-0x2),P=String(x['getMonth']()+0x1)['padStart'](0x2,'0'),g=String(x['getDate']())[G(0x19f)](0x2,'0'),j=K['metadata'][G(0x1a0)]??(K['metadata'][G(0x1a1)]?K['metadata']['resource']+'/'+(K['metadata']['resourceId']??randomUUID())+'/'+L:null)??G(0x1a2)+y+'/'+P+'-'+g+'/'+L,p=await K['file']['toBuffer'](),J=await fileTypeFromBuffer(p);if(!B[G(0x1a3)](K['file'][G(0x1a4)])&&(J?.['mime']?!B['has'](J['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+K['file']['mimetype']);await T['file'][G(0x1a5)](j,p);const Q=await T['pg'][G(0x1a6)](G(0x1a7),[K['metadata'][G(0x1a1)]??null,K['metadata']['resourceId']??null,j,K[G(0x1a8)]['mimetype'],K['file']['file']['bytesRead'],K[G(0x1a9)][G(0x19d)],L,K['file']['mimetype']['split']('/')[G(0x1aa)]()??null,K['user']?.['id']??null]);return Q['rows'][0x0];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const P=d;import{ForbiddenError}from'../../errors.js';import{listResources}from'./services/list-resources.js';import{getResource}from'./services/get-resource.js';import{createResource}from'./services/create-resource.js';import{updateResource}from'./services/update-resource.js';function E(){const p=['user','fcore','resource','Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','$resource:read','Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','query','auth','Returns\x20records\x20from\x20a\x20registered\x20resource.','params','post','/api/resource/:resource','/api/resource/:resource/:id','Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','put','Update\x20resource\x20record','$resource:update','resourceId','Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','/api/resource/:resource/:id/upload','uploadResourceFile','type','permissions','fields','/api/resource/:resource/:id/:relation','resourceIdRelation','Create\x20resource\x20relation','$resource:create','Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','resourceIdRelationId','Update\x20resource\x20relation'];E=function(){return p;};return E();}import{deleteResource}from'./services/delete-resource.js';import{listResourceRelation}from'./services/list-resource-relation.js';import{createResourceRelation}from'./services/create-resource-relation.js';import{updateResourceRelation}from'./services/update-resource-relation.js';import{deleteResourceRelation}from'./services/delete-resource-relation.js';import{searchResource}from'./services/search-resource.js';import{exportResource}from'./services/export-resource.js';function d(B,K){B=B-0x161;const T=E();let L=T[B];return L;}import{suggestResource}from'./services/suggest-resource.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=B=>B[P(0x161)];export function resourceRoutes(B){return async K=>{const g=d;K['get']('/api/resource/:resource/search',{'schema':{'tags':[g(0x162),'resource'],'summary':'Search\x20resource','description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':g(0x161),'permissions':['$resource:read'],'params':resourceSchemas[g(0x163)]}},async T=>searchResource({...T['query'],...T['params'],'user':user(T)||B['config']?.['auth']?.['user']},B)),K['get']('/api/suggest/:resource/:field',{'schema':{'tags':['fcore','resource'],'summary':'Suggest\x20resource\x20values','description':g(0x164),'access':'user','permissions':[g(0x165)],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas['suggestQuery']}},async T=>suggestResource({...T['query'],...T['params'],'user':user(T)||B['config']?.['auth']?.['user']},B)),K['get']('/api/resource/:resource/export',{'schema':{'tags':['fcore','resource'],'summary':'Export\x20resource\x20records','description':g(0x166),'access':'user','permissions':[g(0x165)],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas['exportResourceQuery']}},async T=>exportResource({...T[g(0x167)],...T['params'],'user':user(T)||B['config']?.[g(0x168)]?.['user']},B)),K['get']('/api/resource/:resource',{'schema':{'tags':[g(0x162),'resource'],'summary':'List\x20resource\x20records','description':g(0x169),'access':'user','permissions':['$resource:read'],'params':resourceSchemas['resource']}},async T=>listResources({...T['query'],...T[g(0x16a)],'user':user(T)||B['config']?.[g(0x168)]?.['user']},B)),K[g(0x16b)](g(0x16c),{'schema':{'tags':[g(0x162),'resource'],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:create'],'params':resourceSchemas['resource']}},async T=>createResource({...T['params'],'data':T['body'],'user':user(T)||B['config']?.['auth']?.['user']},B)),K['get'](g(0x16d),{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':g(0x16e),'access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async T=>getResource({...T['query'],...T[g(0x16a)],'user':user(T)||B['config']?.[g(0x168)]?.['user']},B)),K[g(0x16f)](g(0x16d),{'schema':{'tags':['fcore','resource'],'summary':g(0x170),'description':'Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':g(0x161),'permissions':[g(0x171)],'params':resourceSchemas[g(0x172)]}},async T=>updateResource({...T[g(0x16a)],'patch':T['body'],'user':user(T)||B['config']?.['auth']?.[g(0x161)]},B)),K['delete'](g(0x16d),{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20record','description':g(0x173),'access':'user','permissions':['$resource:delete'],'params':resourceSchemas['resourceId']}},async T=>deleteResource({...T['params'],'user':user(T)||B['config']?.[g(0x168)]?.['user']},B)),K['post'](g(0x174),{'schema':{'tags':['fcore','resource'],'summary':'Upload\x20resource\x20file','description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':[g(0x171)],'params':resourceSchemas[g(0x175)]}},async T=>{const j=g,L=await T['file']();if(!L)throw new Error('File\x20is\x20required');const x=T['params']['resource'],y=T[j(0x16a)]['id'];if(T['user']?.[j(0x176)]!=='admin'&&!T[j(0x161)]?.[j(0x177)]['includes'](x+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+x+':update');return uploadFile({'file':L,'metadata':{'name':L['filename'],'path':L[j(0x178)]['path']?.['value'],'resource':x,'resourceId':y},'user':T[j(0x161)]},B);}),K['get'](g(0x179),{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20relations','description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':'user','params':resourceSchemas[g(0x17a)],'permissions':['$resource:read']}},async T=>listResourceRelation({...T[g(0x167)],...T['params'],'user':user(T)||B['config']?.['auth']?.[g(0x161)]},B)),K['post']('/api/resource/:resource/:id/:relation',{'schema':{'tags':[g(0x162),g(0x163)],'summary':g(0x17b),'description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':'user','permissions':[g(0x17c)],'params':resourceSchemas['resourceIdRelation']}},async T=>createResourceRelation({...T['params'],'data':T['body'],'user':user(T)||B['config']?.[g(0x168)]?.['user']},B)),K['delete']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[g(0x162),g(0x163)],'summary':'Delete\x20resource\x20relation','description':g(0x17d),'access':'user','permissions':['$resource:delete'],'params':resourceSchemas[g(0x17e)]}},async T=>deleteResourceRelation({...T['params'],'user':user(T)||B['config']?.['auth']?.['user']},B)),K['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore',g(0x163)],'summary':g(0x17f),'description':'Updates\x20a\x20related\x20resource\x20record.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['resourceIdRelationId']}},async T=>updateResourceRelation({...T[g(0x16a)],'data':T['body'],'user':user(T)||B['config']?.['auth']?.['user']},B));};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
const B=d;function d(B,K){B=B-0x14e;const T=E();let L=T[B];return L;}import{Type}from'@sinclair/typebox';function E(){const K=['String','Object','Optional','Array'];E=function(){return K;};return E();}export const identifier=Type[B(0x14e)]({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});export const resourceSchemas={'dictionaryName':Type[B(0x14f)]({'name':identifier}),'resource':Type['Object']({'resource':identifier}),'exportResource':Type['Object']({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type['Optional'](Type['String']()),'search':Type[B(0x150)](Type['String']()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type[B(0x14f)]({'include':Type['Optional'](Type[B(0x14e)]({'minLength':0x1}))}),'resourceIdRelation':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type[B(0x14f)]({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'uploadResourceFile':Type[B(0x14f)]({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type[B(0x14f)]({'filter':Type['Optional'](Type['Record'](Type['String'](),Type['Unknown']())),'sort':Type['Optional'](Type[B(0x151)](Type['String']({'minLength':0x1}))),'search':Type['Optional'](Type['String']()),'limit':Type[B(0x150)](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type['Integer']({'minimum':0x0})),'fields':Type[B(0x150)](Type['Array'](identifier))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function d(B,K){B=B-0x138;const T=E();let L=T[B];return L;}function E(){const x=['resource','body'];E=function(){return x;};return E();}export async function addNote(B,K){const L=d,T=await K['pg']['query']('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[B[L(0x138)],String(B['id']),B[L(0x139)]]);return T['rows'][0x0];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export async function addResourceFile(B,K){const T=await K['pg']['query']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20size)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20',[B['resource'],String(B['id']),B['filePath'],B['size']??null]);return T['rows'][0x0];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function createResourceRelation(
|
|
1
|
+
export async function createResourceRelation(B,K){const {resource:T,id:L,relation:x,data:y,user:P}=B;return K['resource']['createRelation']({'name':T,'id':L,'relation':x,'data':y,'user':P});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function createResource(
|
|
1
|
+
function d(B,K){B=B-0x192;var T=E();var L=T[B];return L;}function E(){var L=['resource','data','user'];E=function(){return L;};return E();}export async function createResource(B,K){var T=d;return K['resource']['create']({'name':B[T(0x192)],'data':B[T(0x193)],'user':B[T(0x194)]});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function deleteResourceRelation(
|
|
1
|
+
export async function deleteResourceRelation(B,K){const P=d,{resource:T,id:L,relation:x,relationId:y}=B;return K[P(0x133)]['deleteRelation']({'name':T,'id':L,'relation':x,'relationId':y});}function d(B,K){B=B-0x133;const T=E();let L=T[B];return L;}function E(){const g=['resource'];E=function(){return g;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function deleteResource(
|
|
1
|
+
function E(){var L=['user'];E=function(){return L;};return E();}function d(B,K){B=B-0x1ae;var T=E();var L=T[B];return L;}export async function deleteResource(B,K){var T=d;return K['resource']['delete']({'name':B['resource'],'id':B['id'],'user':B[T(0x1ae)]});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function d(B,K){B=B-0x97;const T=E();let L=T[B];return L;}function E(){const x=['resource','rows'];E=function(){return x;};return E();}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function exportResource(B,K){const L=d,T=await K[L(0x97)]['find']({'name':B[L(0x97)],'query':{'filter':parseFilterQuery(B),'sort':B['sort'],'search':B['search'],'limit':B['limit'],'offset':B['offset'],'fields':B['fields']},'user':B['user']});return T[L(0x98)];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function getResource(
|
|
1
|
+
function d(B,K){B=B-0xfb;var T=E();var L=T[B];return L;}export async function getResource(B,K){var T=d;return K[T(0xfb)][T(0xfc)]({'name':B[T(0xfb)],'id':B['id'],'query':{'include':B['include']},'user':B['user']});}function E(){var L=['resource','findOne'];E=function(){return L;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function listResourceRelation(
|
|
1
|
+
export async function listResourceRelation(B,K){const {resource:T,id:L,relation:x,query:y,user:P}=B;return K['resource']['findRelation']({'name':T,'id':L,'relation':x,'query':y,'user':P});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function
|
|
1
|
+
import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function d(B,K){B=B-0x11e;var T=E();var L=T[B];return L;}export async function listResources(B,K){var T=d;return K['resource']['find']({'name':B['resource'],'query':{'filter':parseFilterQuery(B),'sort':B['sort'],'search':B['search'],'limit':B['limit'],'offset':B['offset']??(B['page']?Math['max'](B['page']-0x1,0x0):0x0)*(B[T(0x11e)]??0x14)},'user':B[T(0x11f)]});}function E(){var L=['limit','user'];E=function(){return L;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(
|
|
1
|
+
import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(B,K){return K['resource']['find']({'name':B['resource'],'query':{...B,'filter':parseFilterQuery(B)},'user':B['user']});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function E(){const u=['min','max','limit','now','table','text','value','query','SELECT\x20','\x20as\x20text\x20FROM\x20','\x20WHERE\x20lower(','toLowerCase','then','field','filter','startsWith'];E=function(){return u;};return E();}import{ValidationError}from'../../../errors.js';function d(B,K){B=B-0x1eb;const T=E();let L=T[B];return L;}import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';export async function suggestResource(B,K){const r=d,T=K['resource']['get'](B['resource']),L=String(B['search']??B['q']??'')['toLowerCase'](),x=Math[r(0x1eb)](Math[r(0x1ec)](Number(B[r(0x1ed)]??0x14),0x1),0xc8),y=Date[r(0x1ee)](),P=T['fields'][B['field']],g=P?.['dictionary'],j=P?.['lookup']?.[r(0x1ef)];if(j){const Q=P['lookup']?.[r(0x1f0)]??'name',G=P['lookup']?.[r(0x1f1)]??'id';autoIndex(j,Q,r(0x1f0),K['pg']);const f=await K['pg'][r(0x1f2)](r(0x1f3)+G+'\x20as\x20id,\x20'+Q+r(0x1f4)+j+r(0x1f5)+Q+')\x20~\x20$1\x20LIMIT\x20$2',[''+L[r(0x1f6)](),x])[r(0x1f7)](A=>A['rows']);return{'limit':x,'count':f['length'],'search':L,'time':Date['now']()-y,'data':f};}if(!g)throw new ValidationError('Field\x20has\x20no\x20lookup\x20dictionary:\x20'+B[r(0x1f8)]);const p=await K['dictionary']['get'](g),J=p[r(0x1f9)](A=>!L||A['code'][r(0x1fa)](L)||A['name'][r(0x1fa)](L))['slice'](0x0,x)['map'](A=>({'id':A['code']||A['id'],'text':A['name']||A[r(0x1f0)]}));return{'search':L,'limit':x,'count':J['length'],'time':Date['now']()-y,'data':J};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export async function updateResourceRelation(B,K){const j=d,{resource:T,id:L,relation:x,relationId:y,data:P,user:g}=B;return K['resource'][j(0xfa)]({'name':T,'id':L,'relation':x,'relationId':y,'data':P,'user':g});}function d(B,K){B=B-0xfa;const T=E();let L=T[B];return L;}function E(){const p=['updateRelation'];E=function(){return p;};return E();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function updateResource(
|
|
1
|
+
export async function updateResource(B,K){var T=d;return K[T(0x196)]['update']({'name':B[T(0x196)],'id':B['id'],'data':B['patch'],'user':B['user']});}function d(B,K){B=B-0x196;var T=E();var L=T[B];return L;}function E(){var L=['resource'];E=function(){return L;};return E();}
|