@opengis/fcore 0.0.1-beta.13 → 0.0.1-beta.14
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 +0 -3
- package/dist/fastify.d.ts.map +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.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/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.js +1 -1
- package/dist/plugins/resource/services/find-relation.js +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/package.json +1 -1
package/dist/config.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function k
|
|
1
|
+
import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function y(k,f){k=k-0xfd;const C=F();let p=C[k];return p;}function required(k){const p=y,f=process.env[k];if(!f)throw new Error(p(0xfd)+k);return f;}function F(){const N=['Missing\x20environment\x20variable:\x20','development','false','info','true','auth'];F=function(){return N;};return F();}export function loadConfig(k={}){const a=y,f={'env':process.env.NODE_ENV??a(0xfe),'debug':process.env.DEBUG==='true','port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT===a(0xff),'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??a(0x100),'responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')['map'](C=>C-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??'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||'true'),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||a(0x101)),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&['lax','strict','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{...f,...k,'logger':{...f['logger'],...k['logger']},'pg':{...f['pg'],...k['pg']},'redis':{...f['redis'],...k['redis']},'s3':{...f['s3'],...k['s3']},'auth':{...f['auth'],...k[a(0x102)]}};}export{required as requireEnv};
|
package/dist/context.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let defaultContext;export function setContext(
|
|
1
|
+
function F(){const C=['redis'];F=function(){return C;};return F();}function y(k,f){k=k-0x9a;const C=F();let p=C[k];return p;}let defaultContext;export function setContext(k){defaultContext=k;}export function getContext(){if(!defaultContext)throw new Error('Application\x20context\x20is\x20not\x20initialized');return defaultContext;}export function createContext(k){return{...k,async 'close'(){const f=y;await Promise['allSettled']([k[f(0x9a)]?.['close'](),k['pg']?.['end']()]),await k['logger']['close']();}};}
|
package/dist/errors.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
var a=y;export class FCoreError extends Error{['code'];[a(0x180)];['details'];constructor(k,f,C=0x1f4,p){var N=a;super(f),this[N(0x181)]=k,this['statusCode']=C,this['details']=p,this['name']=new.target.name;}}export class BadRequestError extends FCoreError{constructor(k,f){var W=a;super(W(0x182),k,0x190,f);}}export class UnauthorizedError extends FCoreError{constructor(k='Authentication\x20required'){var n=a;super(n(0x183),k,0x191);}}export class ForbiddenError extends FCoreError{constructor(k=a(0x184)){var A=a;super(A(0x185),k,0x193);}}function F(){var R=['statusCode','code','BAD_REQUEST_ERROR','UNAUTHORIZED','Access\x20denied','FORBIDDEN','Not\x20found','VALIDATION_ERROR'];F=function(){return R;};return F();}export class NotFoundError extends FCoreError{constructor(k=a(0x186)){super('NOT_FOUND',k,0x194);}}export class ConflictError extends FCoreError{constructor(k='Conflict'){super('CONFLICT',k,0x199);}}export class ValidationError extends FCoreError{constructor(k,f){var H=a;super(H(0x187),k,0x1a6,f);}}function y(k,f){k=k-0x180;var C=F();var p=C[k];return p;}export class UnsupportedError extends FCoreError{constructor(k='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',k,0x1f5);}}
|
package/dist/fastify.d.ts
CHANGED
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Integrates FCore modules with Fastify without coupling infrastructure plugins to HTTP.
|
|
3
|
-
*/
|
|
4
1
|
import { type FastifyPluginAsync } from "fastify";
|
|
5
2
|
import type { AppContext } from "./context.js";
|
|
6
3
|
export type FCoreApiModule = "auth" | "resource" | "file" | "system";
|
package/dist/fastify.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAKA,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
|
-
import
|
|
1
|
+
import k from'fastify-plugin';function y(k,f){k=k-0x1e3;const C=F();let p=C[k];return p;}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(f,C,p){const a=decodeURIComponent(C['toString']())['split']('&')['reduce']((N,W)=>{const [n,A]=W['split']('=');return{...N,[n]:A};},{});p(null,a);}export default function fcoreFastify(f,C){return k(async p=>{const z=y;p['decorate']('ctx',f);const {config:a}=f,N=new Map();p['addHook']('onRoute',n=>{const j=y;if(n[j(0x1e3)]['startsWith'](j(0x1e4))){const A=n['schema'],H=Array['isArray'](n['method'])?n['method']:[n['method']];for(const R of H){if(R===j(0x1e5))continue;const u={'method':R,'endpoint':n[j(0x1e3)],'package':A?.['package']??j(0x1e6),'tags':A?.['tags']??[],'summary':A?.['summary']??'','description':A?.['description']??'','access':A?.['access']??'public','permissions':A?.[j(0x1e7)]??[]};N['set'](R+'\x20'+n['url'],u);}}}),p['addHook'](z(0x1e8),async n=>{const T=z,A=N['get'](n['method']+'\x20'+n[T(0x1e9)]['url']),H=n['raw']['headers']?.['authorization'],R=H?.['startsWith'](T(0x1ea))?H['slice'](0x7):null,u=n['user']??(R?await jwtVerifyToken(R):null);!n['user']&&R&&process.env.AUTH_JWT_SECRET&&(n[T(0x1eb)]=await jwtVerifyToken(R));if(!A?.[T(0x1ec)])throw new Error(T(0x1ed));if(A['access']==='public')return!![];if(!u)throw new ForbiddenError('User\x20required');if(A[T(0x1ec)]===T(0x1eb)&&!A['permissions']?.['length'])return!![];if(u[T(0x1ee)]=='admin')return!![];if(A[T(0x1ec)]==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const d of A['permissions']){if(!u['permissions']?.['includes'](d))throw new ForbiddenError(T(0x1ef)+d);}return!![];}),await createSessionStore(p,f),await p['register'](import(z(0x1f0)),{'limits':{'fileSize':a['maxFileSize']*0x400*0x400}}),p['setErrorHandler']((n,A,H)=>{const S=z;if(n instanceof FCoreError||n['code']==='FST_ERR_VALIDATION'||n['statusCode']<0x1f4)return n['statusCode']<0x1f4&&f[S(0x1f1)][S(0x1f2)](n),H['code'](n['statusCode'])[S(0x1f3)]({'error':n[S(0x1f4)],'message':n['message'],'details':n[S(0x1f5)]});return f['logger'][S(0x1f6)](n),(a['debug']||process.env.NODE_ENV===S(0x1f7)||process.env.VITEST)&&console['error'](n),H[S(0x1f4)](0x1f4)['send']({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const W=n=>!C||C['includes'](n);if(W('auth'))await p['register'](authRoutes(f));if(W('resource'))await p['register'](resourceRoutes(f));if(W(z(0x1f8)))await p['register'](fileRoutes(f));if(W('system'))await p[z(0x1f9)](systemRoutes(f,N));p[z(0x1fa)]('application/x-www-form-urlencoded',{'parseAs':'buffer'},urlencodedContentParser),!a['rateLimit']?.['disabled']?p[z(0x1f9)](import('@fastify/rate-limit'),{'max':a['rateLimit']?.[z(0x1fb)]||0x64,'timeWindow':a['rateLimit']?.['timeWindow']||0xea60,'hook':z(0x1e8),'global':!![],'keyGenerator':n=>(n[z(0x1eb)]?.['id']||n['ip'])+'-'+n['raw']['url']['split']('?')[0x0]}):console[z(0x1fc)]('⚠️\x20rate\x20limit\x20is\x20disabled');});}function F(){const i=['url','/api/','HEAD','fcore','permissions','preHandler','routeOptions','Bearer\x20','user','access','Route\x20access\x20not\x20defined','type','Missing\x20permission:\x20','@fastify/multipart','logger','warn','send','code','details','error','test','file','register','addContentTypeParser','max','log'];F=function(){return i;};return F();};
|
package/dist/fcore.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{loadConfig}from'./config.js';function k
|
|
1
|
+
function F(){const u=['accessKey','secretKey'];F=function(){return u;};return F();}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function y(k,f){k=k-0x110;const C=F();let p=C[k];return p;}import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';export async function createFCore(k={}){const R=y,f=loadConfig(k['config']),C=createRedis(f['redis']),p=createLogger(),a=createDatabase(f['pg']),N=createFileS3({'endpoint':f['s3']['endpoint'],'region':f['s3']['region'],'bucket':f['s3']['bucket'],'accessKey':f['s3'][R(0x110)],'secretKey':f['s3'][R(0x111)],'folder':f['s3']['folder'],'forcePathStyle':f['s3']['forcePathStyle'],'tokenSecret':f['s3']['tokenSecret'],'tokenTtl':f['s3']['tokenTtl']}),W=createAudit({'pg':a,'logger':p}),n=createDictionary({'pg':a,'dictionaries':k['dictionaries']}),A=createResource({'pg':a,'logger':p,'audit':W,'dictionary':n,'file':N});k['resources']?.['length']&&A['register'](k['resources']);const H=createContext({'config':f,'logger':p,'redis':C,'pg':a,'file':N,'resource':A,'audit':W,'dictionary':n});return setContext(H),H;}
|
package/dist/migrations/cli.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
function k
|
|
2
|
+
const f=y;import{runMigrations}from'./runner.js';function y(k,f){k=k-0x11d;const C=F();let p=C[k];return p;}function F(){const C=['OK\x20\x20'];F=function(){return C;};return F();}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['status']==='run'?f(0x11d):'SKIP')+'\x20'+r['file']);}catch(k){console['error'](k),process['exitCode']=0x1;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import k from'node:fs/promises';import f from'node:path';import{createDatabase}from'../plugins/pg.js';function y(k,f){k=k-0x152;const C=F();let p=C[k];return p;}export async function runMigrations(C={}){const z=y,p=f['resolve'](C['dir']??'migrations'),a=C['database']??databaseFromUrl(C['databaseUrl']??process.env.DATABASE_URL);if(!a)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const N=createDatabase(a);if(!N)throw new Error(z(0x152));const W=[];try{await N[z(0x153)](z(0x154));const n=await N['query']('SELECT\x20version\x20FROM\x20schema_migrations'),A=new Set(n[z(0x155)][z(0x156)](R=>R[z(0x157)])),H=(await k[z(0x158)](p))['filter'](R=>R['endsWith']('.sql'))['sort']();for(const R of H){if(A['has'](R)){W[z(0x159)]({'file':R,'status':'skip'});continue;}const u=await k[z(0x15a)](f['join'](p,R),'utf8'),d=await N['connect']();try{await d['query'](z(0x15b)),await d[z(0x153)](u),await d['query']('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[R]),await d['query']('COMMIT');}catch(j){await d['query']('ROLLBACK');throw j;}finally{d['release']();}W[z(0x159)]({'file':R,'status':'run'});}return W;}finally{await N['end']();}}function databaseFromUrl(C){const T=y;if(!C)return undefined;const p=new URL(C);return{'host':p['hostname'],'port':Number(p['port']||0x1538),'database':p['pathname'][T(0x15c)](0x1),'user':decodeURIComponent(p['username']),'password':decodeURIComponent(p[T(0x15d)])};}function F(){const S=['empty\x20pg','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','rows','map','version','readdir','push','readFile','BEGIN','slice','password'];F=function(){return S;};return F();}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
|
|
2
|
+
const C=y;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import k from'./services/registration.js';function y(k,f){k=k-0x1e3;const C=F();let p=C[k];return p;}const [user,password,type]=process['argv'][C(0x1e3)](0x2);if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await k({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(f){console['error'](f),process['exitCode']=0x1;}finally{await pg['end']();}}function F(){const p=['slice'];F=function(){return p;};return F();}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
const C=y;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function F(){const p=['argv','slice','error','query','rows','User\x20not\x20found'];F=function(){return p;};return F();}function y(k,f){k=k-0xe8;const C=F();let p=C[k];return p;}import k from'./services/change-password.js';const [login,password]=process[C(0xe8)][C(0xe9)](0x2);if(!login||!password)console[C(0xea)]('Usage:\x20fcore-password\x20<login>\x20<password>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[C(0xeb)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result[C(0xec)][0x0];if(!user)throw new Error(C(0xed));await k({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(f){console['error'](f),process['exitCode']=0x1;}finally{await pg['end']();}}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
const
|
|
2
|
+
function y(k,f){k=k-0xee;const C=F();let p=C[k];return p;}const A=y;function F(){const R=['audit','check','settings','update','create','slice','filter','add','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','User\x20not\x20found','DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL','log','push','query','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','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)'];F=function(){return R;};return F();}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs',A(0xee),'list',A(0xef),'access',A(0xf0),'dictionaries'],RESOURCE_ACTIONS=['read',A(0xf1),A(0xf2),'delete'],[login,permissionArg]=process['argv'][A(0xf3)](0x2);function expandPermissions(k){const H=A,f=k['split'](',')['map'](p=>p['trim']())[H(0xf4)](Boolean),C=new Set();for(const p of f){if(p['includes'](':')){C[H(0xf5)](p);continue;}const a=p==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const N of a){C[H(0xf5)](p+':'+N);}}return[...C];}if(!login||!permissionArg)console['error'](A(0xf6)),process['exitCode']=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(A(0xf7));if(permissionArg['trim']()==='clear')await pg['query'](A(0xf8),[user['id']]),console[A(0xf9)]('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['get'](resource)??[];actions[A(0xfa)](action),byResource['set'](resource,actions);}const client=await pg['connect']();try{await client['query']('BEGIN');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['actions']??[],...actions])];await client[A(0xfb)](A(0xfc),[merged,user['id'],row['access_id']]);}else await client['query'](A(0xfd),[resource,actions,user['id'],user['id']]);}await client['query']('COMMIT');}catch(W){await client['query']('ROLLBACK');throw W;}finally{client['release']();}console[A(0xf9)]('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions['join'](',\x20'));}}catch(n){console['error'](n),process['exitCode']=0x1;}finally{await pg['end']();}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function F(){const i=['method','permissions','config','audit','session','sessionId','login','type','fcore','Sign\x20in','credentials','post','auth','public','Creates\x20a\x20regular\x20user\x20account.','body','/api/auth/password','Not\x20authorized','user','query','token'];F=function(){return i;};return F();}import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import k from'./services/get-current-user.js';import f from'./services/registration.js';import C from'./services/change-password.js';import{authSchemas}from'./schema.js';import p from'../../shared/getIP.js';function y(k,f){k=k-0x1ba;const C=F();let p=C[k];return p;}import{UnauthorizedError}from'../../errors.js';export function authRoutes(a){return async N=>{const z=y,W=async n=>{const j=y,A=n[j(0x1ba)]==='GET'?n['query']:n['body'],H=p(n),R=await verifyUser({...A,'ip':H},a);R[j(0x1bb)]=await getUserPermissions(R['id'],a);const u=R['twofa']?a['config']['auth']['twoFactorRedirect']:a[j(0x1bc)]['auth']['redirect'];await n['login'](R);const d=a[j(0x1bc)]['auth']['sessionTimeout']*0x3e8*0x3c;return n['session']?.['cookie']&&(n['session']['cookie']['maxAge']=d),await n['session']['save'](),await a[j(0x1bd)]?.['write']?.({'module':'auth','resource':'session','resourceId':n[j(0x1be)][j(0x1bf)],'action':j(0x1c0),'userId':R['id'],'ipAddress':H}),{'user':{'id':R['id'],'type':R[j(0x1c1)],'permissions':R[j(0x1bb)]},'redirectUrl':u};};N['get']('/api/auth/login',{'schema':{'tags':[z(0x1c2),'auth'],'summary':z(0x1c3),'description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'querystring':authSchemas[z(0x1c4)]}},W),N[z(0x1c5)]('/api/auth/login',{'schema':{'tags':[z(0x1c2),z(0x1c6)],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':z(0x1c7),'permissions':[],'body':authSchemas['credentials']}},W),N['post']('/api/auth/registration',{'schema':{'tags':['fcore','auth'],'summary':'Register','description':z(0x1c8),'access':'admin','permissions':['user:create'],'body':authSchemas['credentials']}},async n=>f(n[z(0x1c9)],a)),N['post'](z(0x1ca),{'schema':{'tags':['fcore','auth'],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas['password']}},async n=>{const T=z;if(!n['user'])throw new UnauthorizedError(T(0x1cb));return await C({'userId':n['user']['id'],...n[T(0x1c9)]},a),{'success':!![]};}),N[z(0x1c5)]('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(n,A)=>{const S=z,H={'redirectUrl':'/'};if(!n[S(0x1cc)])return H;return await a['audit']?.['write']?.({'module':'auth','resource':'session','resourceId':n['session']['sessionId'],'action':'logout','userId':n['user']?.['id']}),await n['session']['destroy'](),A['clearCookie'](a[S(0x1bc)]['auth']['cookieName']),Object['defineProperty'](n,'session',{'value':null,'writable':![],'configurable':![]}),H;}),N['get']('/api/auth/user',{'schema':{'tags':['fcore','auth'],'summary':'Get\x20current\x20user','description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas[z(0x1cd)]}},async n=>k({'user':n[z(0x1cc)],'token':n[z(0x1cd)][z(0x1ce)]}));};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
const
|
|
1
|
+
function F(){const f=['Object','Optional','String'];F=function(){return f;};return F();}const k=y;import{Type}from'@sinclair/typebox';function y(k,f){k=k-0xf9;const C=F();let p=C[k];return p;}export const authSchemas={'query':Type[k(0xf9)]({'token':Type[k(0xfa)](Type['Boolean']())}),'credentials':Type['Object']({'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['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type[k(0xfa)](Type[k(0xfb)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type['String']({'minLength':0x1})})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:k,password:f,userId:C},{pg:p}){const a=await hashPassword(f);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',[a,k||C,C]);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{safeUser}from'../../utils/safe-user.js';function k
|
|
1
|
+
import{safeUser}from'../../utils/safe-user.js';function y(k,f){k=k-0x1f0;const C=F();let p=C[k];return p;}export default async function getCurrentUser(k){const N=y,{user:f}=k;if(!f)return{};if(k[N(0x1f0)]){const {jwtSignToken:C}=await import('../../../plugins/jwt.js'),p=await C(f);f['token']=p;}return f['resources']=[...new Set(f?.['permissions']['map'](a=>a['split'](':')[0x0]))],safeUser(f);}function F(){const W=['token'];F=function(){return W;};return F();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function k
|
|
1
|
+
function y(k,f){k=k-0xab;const C=F();let p=C[k];return p;}import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:k,password:f,type:C},{pg:p}){const n=y,a=await hashPassword(f),N=await p['query'](n(0xab),[k,a,C||n(0xac)]),W=N[n(0xad)][0x0];if(!W)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':W};}function F(){const A=['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','regular','rows'];F=function(){return A;};return F();}
|
|
@@ -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(k,f){return unsupported('Two-factor\x20provider');}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
function y(k,f){k=k-0x124;var C=F();var p=C[k];return p;}var k=y;export default new Set([k(0x124),'image/png',k(0x125),'image/webp','image/bmp','image/tiff','image/svg+xml','image/x-icon',k(0x126),'application/pdf','application/msword',k(0x127),'application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',k(0x128),'application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain','text/csv','text/markdown','application/json','application/xml',k(0x129),k(0x12a),k(0x12b),k(0x12c),'application/zip','application/x-zip-compressed',k(0x12d),'application/x-rar-compressed','application/vnd.rar','application/gzip','application/x-gzip',k(0x12e),'audio/mpeg',k(0x12f),'audio/ogg',k(0x130),'audio/mp4','video/mp4',k(0x131),k(0x132),'video/quicktime',k(0x133),'application/octet-stream']);function F(){var f=['image/jpeg','image/gif','image/avif','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-powerpoint','text/xml','application/geo+json','application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/x-7z-compressed','application/x-tar','audio/wav','audio/webm','video/mpeg','video/webm','video/x-msvideo'];F=function(){return f;};return F();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileTypeFromBuffer}from'file-type';function
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';function y(k,f){k=k-0x1ac;const C=F();let p=C[k];return p;}import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function F(){const T=['/api/file/:token','file','params','mime','download','startsWith','header','inline','Cache-Control','public,\x20max-age=86400,\x20immutable','send','Upload\x20file','filename','fields','path','resource','value','/api/file/:token/resize','resizeQuery','verify','type'];F=function(){return T;};return F();}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(k){return async f=>{const u=y;f['get'](u(0x1ac),{'schema':{'tags':['fcore',u(0x1ad)],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas['fileDownloadQuery']}},async(C,p)=>{const d=u,a=k['file']['verify'](C[d(0x1ae)]['token']),N=await getFile({'pathOrToken':a},k),W=await fileTypeFromBuffer(N),n=W?.[d(0x1af)]??'application/octet-stream',A=C['query'][d(0x1b0)]===!![],H=n[d(0x1b1)]('image/')||n==='application/pdf',R=a['split']('/')['pop']()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??'file';return p['type'](n),p[d(0x1b2)]('Content-Disposition',(A||!H?'attachment':d(0x1b3))+';\x20filename=\x22'+R+'\x22')['header'](d(0x1b4),d(0x1b5)),p[d(0x1b6)](N);}),f['post']('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':u(0x1b7),'description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async C=>{const j=u,p=await C['file']();if(!p)throw new Error('File\x20is\x20required');return uploadFile({'file':p,'metadata':{'name':p[j(0x1b8)],'path':p[j(0x1b9)][j(0x1ba)]?.['value'],'resource':p['fields'][j(0x1bb)]?.[j(0x1bc)],'resourceId':p[j(0x1b9)]['resourceId']?.['value']},'user':C['user']},k);}),f['get'](u(0x1bd),{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':['files:read'],'params':fileSchemas['fileToken'],'querystring':fileSchemas[u(0x1be)]}},async(C,p)=>{const z=u,a=await resizeFile({'pathOrToken':k['file']?.[z(0x1bf)](C['params']['token']),...C['query']},k),N=await fileTypeFromBuffer(a);return p[z(0x1c0)](N?.['mime']??'image/png'),p['header']('Content-Disposition','inline')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),p[z(0x1b6)](a);});};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function y(k,f){k=k-0xe9;const C=F();let p=C[k];return p;}function F(){const f=['Optional','String','Object','Literal','fill'];F=function(){return f;};return F();}const k=y;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['Object']({'download':Type[k(0xe9)](Type['Boolean']())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type[k(0xea)]({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type[k(0xe9)](Type['String']({'minLength':0x1}))})}),'filePatch':Type[k(0xeb)]({'entityType':Type[k(0xe9)](Type[k(0xea)]({'minLength':0x1})),'entityId':Type['Optional'](Type[k(0xea)]({'minLength':0x1}))}),'resizeQuery':Type[k(0xeb)]({'width':Type[k(0xe9)](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type[k(0xe9)](Type['Integer']({'minimum':0x1})),'fit':Type[k(0xe9)](Type['Union']([Type['Literal']('cover'),Type[k(0xec)]('contain'),Type['Literal'](k(0xed)),Type['Literal']('inside'),Type['Literal']('outside')]))})};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
function F(){var p=['empty\x20file','File\x20not\x20found'];F=function(){return p;};return F();}function y(k,f){k=k-0x1de;var C=F();var p=C[k];return p;}import{NotFoundError}from'../../../errors.js';export async function getFile(k,f){var C=y;if(!f['file'])throw new Error(C(0x1de));if(!await f['file']['exists'](k['pathOrToken']))throw new NotFoundError(C(0x1df)+k['pathOrToken']);return f['file']['get'](k['pathOrToken']);}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';function F(){const T=['resolve','file','get','startsWith','image/'];F=function(){return T;};return F();}import{mkdir,readFile,writeFile}from'node:fs/promises';function y(k,f){k=k-0x1d2;const C=F();let p=C[k];return p;}import k from'node:path';import f from'sharp';export async function resizeFile(C,p){const z=y,a=C['pathOrToken']??C['path'];if(!a)throw new ValidationError('File\x20path\x20is\x20required');const N=parseDimension(C['width'],'width')??0xc8,W=parseDimension(C['height'],'height'),n=createHash('sha256')['update'](a+':'+N+':'+(W??'auto')+':'+(C['fit']??'cover'))['digest']('hex'),A=k[z(0x1d2)]('logs','resize'),H=k['join'](A,n+'.jpg');try{return await readFile(H);}catch(j){if(j['code']!=='ENOENT')throw j;}if(!await p['file']['exists'](a))throw new NotFoundError('File\x20not\x20found');const R=await p[z(0x1d3)][z(0x1d4)](a),u=await fileTypeFromBuffer(R);if(!u?.['mime'][z(0x1d5)](z(0x1d6)))throw new ValidationError('Only\x20image\x20files\x20can\x20be\x20resized');const d=await f(R)['resize']({'width':N,'height':W,'fit':C['fit']??'cover'})['toBuffer']();return await mkdir(A,{'recursive':!![]}),await writeFile(H,d),d;}function parseDimension(C,p){if(C===undefined||C==='')return undefined;const a=Number(C);if(!Number['isInteger'](a)||a<=0x0)throw new ValidationError(p+'\x20must\x20be\x20a\x20positive\x20integer');return a;}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{fileTypeFromBuffer}from'file-type';
|
|
1
|
+
import{fileTypeFromBuffer}from'file-type';function y(k,f){k=k-0x1b9;const C=F();let p=C[k];return p;}function F(){const j=['getDate','path','metadata','resource','uploads/','mime','\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','mimetype','pop'];F=function(){return j;};return F();}import k from'../mime.js';import{randomUUID}from'node:crypto';export async function uploadFile(f,C){const d=y,p=(f['metadata']['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),a=new Date(),N=String(a['getFullYear']())['slice'](-0x2),W=String(a['getMonth']()+0x1)['padStart'](0x2,'0'),n=String(a[d(0x1b9)]())['padStart'](0x2,'0'),A=f['metadata'][d(0x1ba)]??(f[d(0x1bb)]['resource']?f[d(0x1bb)][d(0x1bc)]+'/'+(f['metadata']['resourceId']??randomUUID())+'/'+p:null)??d(0x1bd)+N+'/'+W+'-'+n+'/'+p,H=await f['file']['toBuffer'](),R=await fileTypeFromBuffer(H);if(!k['has'](f['file']['mimetype'])&&(R?.[d(0x1be)]?!k['has'](R['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+f['file']['mimetype']);await C['file']['put'](A,H);const u=await C['pg']['query'](d(0x1bf),[f['metadata'][d(0x1bc)]??null,f['metadata']['resourceId']??null,A,f[d(0x1c0)][d(0x1c1)],f['file'][d(0x1c0)]['bytesRead'],f['metadata']['name'],p,f['file']['mimetype']['split']('/')[d(0x1c2)]()??null,f['user']?.['id']??null]);return u['rows'][0x0];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
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';
|
|
1
|
+
const W=y;import{ForbiddenError}from'../../errors.js';import{listResources}from'./services/list-resources.js';function y(k,f){k=k-0x1d8;const C=F();let p=C[k];return p;}import{getResource}from'./services/get-resource.js';import{createResource}from'./services/create-resource.js';import{updateResource}from'./services/update-resource.js';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 F(){const H=['user','get','resource','query','params','/api/suggest/:resource/:field','Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','resourceField','/api/resource/:resource/export','fcore','Export\x20resource\x20records','Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','/api/resource/:resource','Create\x20resource\x20record','/api/resource/:resource/:id','Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','body','Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','uploadResourceFile','File\x20is\x20required','type','includes','filename','Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','Delete\x20resource\x20relation','Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.'];F=function(){return H;};return F();}import{suggestResource}from'./services/suggest-resource.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=k=>k[W(0x1d8)];export function resourceRoutes(k){return async f=>{const n=y;f[n(0x1d9)]('/api/resource/:resource/search',{'schema':{'tags':['fcore',n(0x1da)],'summary':'Search\x20resource','description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':n(0x1d8),'permissions':[],'params':resourceSchemas['resource']}},async C=>searchResource({...C[n(0x1db)],...C[n(0x1dc)],'user':user(C)},k)),f['get'](n(0x1dd),{'schema':{'tags':['fcore','resource'],'summary':'Suggest\x20resource\x20values','description':n(0x1de),'access':'user','permissions':[],'params':resourceSchemas[n(0x1df)],'querystring':resourceSchemas['suggestQuery']}},async C=>suggestResource({...C['query'],...C['params'],'user':user(C)},k)),f['get'](n(0x1e0),{'schema':{'tags':[n(0x1e1),'resource'],'summary':n(0x1e2),'description':n(0x1e3),'access':'user','permissions':['*:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas['exportResourceQuery']}},async C=>exportResource({...C['query'],...C[n(0x1dc)],'user':user(C)},k)),f['get'](n(0x1e4),{'schema':{'tags':['fcore',n(0x1da)],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':n(0x1d8),'permissions':[],'params':resourceSchemas['resource']}},async C=>listResources({...C[n(0x1db)],...C['params'],'user':user(C)},k)),f['post'](n(0x1e4),{'schema':{'tags':['fcore','resource'],'summary':n(0x1e5),'description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas['resource']}},async C=>createResource({...C[n(0x1dc)],'data':C['body'],'user':user(C)},k)),f['get']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':n(0x1d8),'permissions':[],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async C=>getResource({...C['query'],...C['params'],'user':user(C)},k)),f['put'](n(0x1e6),{'schema':{'tags':[n(0x1e1),'resource'],'summary':'Update\x20resource\x20record','description':n(0x1e7),'access':'user','permissions':[],'params':resourceSchemas['resourceId']}},async C=>updateResource({...C['params'],'patch':C[n(0x1e8)],'user':user(C)},k)),f['delete']('/api/resource/:resource/:id',{'schema':{'tags':['fcore',n(0x1da)],'summary':'Delete\x20resource\x20record','description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':n(0x1d8),'permissions':[],'params':resourceSchemas['resourceId']}},async C=>deleteResource({...C['params'],'user':user(C)},k)),f['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':['fcore','resource'],'summary':'Upload\x20resource\x20file','description':n(0x1e9),'access':n(0x1d8),'permissions':[],'params':resourceSchemas[n(0x1ea)]}},async C=>{const A=n,p=await C['file']();if(!p)throw new Error(A(0x1eb));const a=C[A(0x1dc)][A(0x1da)],N=C['params']['id'];if(C[A(0x1d8)]?.[A(0x1ec)]!=='admin'&&!C['user']?.['permissions'][A(0x1ed)](a+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+a+':update');return uploadFile({'file':p,'metadata':{'name':p[A(0x1ee)],'path':p['fields']['path']?.['value'],'resource':a,'resourceId':N},'user':C['user']},k);}),f[n(0x1d9)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore',n(0x1da)],'summary':'List\x20resource\x20relations','description':n(0x1ef),'access':'user','permissions':[],'schema':{'params':resourceSchemas['resourceIdRelation']}}},async C=>listResourceRelation({...C['query'],...C[n(0x1dc)],'user':user(C)},k)),f['post']('/api/resource/:resource/:id/:relation',{'schema':{'tags':[n(0x1e1),'resource'],'summary':'Create\x20resource\x20relation','description':n(0x1f0),'access':'user','permissions':[],'params':resourceSchemas['resourceIdRelation']}},async C=>createResourceRelation({...C['params'],'data':C['body'],'user':user(C)},k)),f['delete']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':n(0x1f1),'description':n(0x1f2),'access':'user','permissions':[],'params':resourceSchemas['resourceIdRelationId']}},async C=>deleteResourceRelation({...C[n(0x1dc)],'user':user(C)},k)),f['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20relation','description':'Updates\x20a\x20related\x20resource\x20record.','access':'user','permissions':[],'params':resourceSchemas['resourceIdRelationId']}},async C=>updateResourceRelation({...C['params'],'data':C['body'],'user':user(C)},k));};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
const k=y;import{Type}from'@sinclair/typebox';export const identifier=Type[k(0x132)]({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});function y(k,f){k=k-0x132;const C=F();let p=C[k];return p;}export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type['Object']({'resource':identifier}),'exportResource':Type[k(0x133)]({'resource':identifier}),'resourceField':Type[k(0x133)]({'resource':identifier,'field':identifier}),'suggestQuery':Type[k(0x133)]({'q':Type['Optional'](Type['String']()),'search':Type['Optional'](Type['String']()),'limit':Type[k(0x134)](Type[k(0x135)]({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type['Object']({'include':Type[k(0x134)](Type['String']({'minLength':0x1}))}),'resourceIdRelation':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'uploadResourceFile':Type[k(0x133)]({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type[k(0x136)](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type[k(0x134)](Type['Record'](Type[k(0x132)](),Type['Unknown']())),'sort':Type['Optional'](Type['Array'](Type['String']({'minLength':0x1}))),'search':Type[k(0x134)](Type['String']()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type['Integer']({'minimum':0x0})),'fields':Type['Optional'](Type['Array'](identifier))})};function F(){const f=['String','Object','Optional','Integer','Any'];F=function(){return f;};return F();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export async function addNote(k,f){const C=await f['pg']['query']('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[k['resource'],String(k['id']),k['body']]);return C['rows'][0x0];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function k
|
|
1
|
+
function y(k,f){k=k-0xdb;const C=F();let p=C[k];return p;}function F(){const a=['rows'];F=function(){return a;};return F();}export async function addResourceFile(k,f){const p=y,C=await f['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',[k['resource'],String(k['id']),k['filePath'],k['size']??null]);return C[p(0xdb)][0x0];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function createResourceRelation(
|
|
1
|
+
function y(k,f){k=k-0x172;const C=F();let p=C[k];return p;}export async function createResourceRelation(k,f){const n=y,{resource:C,id:p,relation:a,data:N,user:W}=k;return f[n(0x172)]['createRelation']({'name':C,'id':p,'relation':a,'data':N,'user':W});}function F(){const A=['resource'];F=function(){return A;};return F();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function y(k,f){k=k-0x117;var C=F();var p=C[k];return p;}export async function createResource(k,f){var C=y;return f['resource']['create']({'name':k[C(0x117)],'data':k[C(0x118)],'user':k['user']});}function F(){var p=['resource','data'];F=function(){return p;};return F();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function deleteResourceRelation(
|
|
1
|
+
export async function deleteResourceRelation(k,f){const {resource:C,id:p,relation:a,relationId:N}=k;return f['resource']['deleteRelation']({'name':C,'id':p,'relation':a,'relationId':N});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function deleteResource(
|
|
1
|
+
export async function deleteResource(k,f){return f['resource']['delete']({'name':k['resource'],'id':k['id'],'user':k['user']});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function F(){const a=['resource','sort','limit','fields'];F=function(){return a;};return F();}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function y(k,f){k=k-0x18e;const C=F();let p=C[k];return p;}export async function exportResource(k,f){const p=y,C=await f[p(0x18e)]['find']({'name':k['resource'],'query':{'filter':parseFilterQuery(k),'sort':k[p(0x18f)],'search':k['search'],'limit':k[p(0x190)],'offset':k['offset'],'fields':k[p(0x191)]},'user':k['user']});return C['rows'];}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function k
|
|
1
|
+
function y(k,f){k=k-0x128;var C=F();var p=C[k];return p;}export async function getResource(k,f){var C=y;return f[C(0x128)]['findOne']({'name':k['resource'],'id':k['id'],'query':{'include':k['include']},'user':k['user']});}function F(){var p=['resource'];F=function(){return p;};return F();}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export async function listResourceRelation(
|
|
1
|
+
function F(){const A=['findRelation'];F=function(){return A;};return F();}function y(k,f){k=k-0x11f;const C=F();let p=C[k];return p;}export async function listResourceRelation(k,f){const n=y,{resource:C,id:p,relation:a,query:N,user:W}=k;return f['resource'][n(0x11f)]({'name':C,'id':p,'relation':a,'query':N,'user':W});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function listResources(k,f){return f['resource']['find']({'name':k['resource'],'query':{'filter':parseFilterQuery(k),'sort':k['sort'],'search':k['search'],'limit':k['limit'],'offset':k['offset']??(k['page']?Math['max'](k['page']-0x1,0x0):0x0)*(k['limit']??0x14)},'user':k['user']});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function
|
|
1
|
+
function F(){var p=['resource','user'];F=function(){return p;};return F();}function y(k,f){k=k-0x65;var C=F();var p=C[k];return p;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(k,f){var C=y;return f['resource']['find']({'name':k[C(0x65)],'query':{...k,'filter':parseFilterQuery(k)},'user':k[C(0x66)]});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ValidationError}from'../../../errors.js';import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';export async function suggestResource(
|
|
1
|
+
import{ValidationError}from'../../../errors.js';function F(){const S=['resource','min','fields','text','name','SELECT\x20','\x20as\x20id,\x20','\x20WHERE\x20lower(','startsWith','slice','map'];F=function(){return S;};return F();}function y(k,f){k=k-0x1cc;const C=F();let p=C[k];return p;}import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';export async function suggestResource(k,f){const T=y,C=f['resource']['get'](k[T(0x1cc)]),p=String(k['search']??k['q']??'')['toLowerCase'](),a=Math[T(0x1cd)](Math['max'](Number(k['limit']??0x14),0x1),0xc8),N=Date['now'](),W=C[T(0x1ce)][k['field']],n=W?.['dictionary'],A=W?.['lookup']?.['table'];if(A){const u=W['lookup']?.[T(0x1cf)]??T(0x1d0),d=W['lookup']?.['value']??'id';autoIndex(A,u,'text',f['pg']);const j=await f['pg']['query'](T(0x1d1)+d+T(0x1d2)+u+'\x20as\x20text\x20FROM\x20'+A+T(0x1d3)+u+')\x20~\x20$1\x20LIMIT\x20$2',[''+p['toLowerCase'](),a])['then'](z=>z['rows']);return{'limit':a,'count':j['length'],'search':p,'time':Date['now']()-N,'data':j};}if(!n)throw new ValidationError('Field\x20has\x20no\x20lookup\x20dictionary:\x20'+k['field']);const H=await f['dictionary']['get'](n),R=H['filter'](z=>!p||z['code'][T(0x1d4)](p)||z['name']['startsWith'](p))[T(0x1d5)](0x0,a)[T(0x1d6)](z=>({'id':z['code']||z['id'],'text':z['name']||z['text']}));return{'search':p,'limit':a,'count':R['length'],'time':Date['now']()-N,'data':R};}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export async function updateResourceRelation(k,f){const {resource:C,id:p,relation:a,relationId:N,data:W,user:n}=k;return f['resource']['updateRelation']({'name':C,'id':p,'relation':a,'relationId':N,'data':W,'user':n});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function k
|
|
1
|
+
function y(k,f){k=k-0xe9;var C=F();var p=C[k];return p;}function F(){var p=['update'];F=function(){return p;};return F();}export async function updateResource(k,f){var C=y;return f['resource'][C(0xe9)]({'name':k['resource'],'id':k['id'],'data':k['patch'],'user':k['user']});}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function k
|
|
1
|
+
import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';function y(k,f){k=k-0x17c;const C=F();let p=C[k];return p;}export async function uploadResourceFile(k,f){const W=y,C=f['resource']['get'](k[W(0x17c)]);if(C['access']===W(0x17d)&&k['user']?.[W(0x17e)]!==W(0x17d))throw new ForbiddenError('Admin\x20access\x20required');if(k[W(0x17f)]?.[W(0x17e)]!==W(0x17d)&&!k[W(0x17f)]?.['permissions']?.['includes']((C['permission']??C['name'])+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+(C['permission']??C['name'])+W(0x180));if(!Buffer['isBuffer'](k[W(0x181)])||k[W(0x181)]['length']===0x0)throw new ValidationError('File\x20is\x20required');const p=k['fileName'][W(0x182)](/[^A-Za-z0-9._-]/g,'_');if(!p)throw new ValidationError('File\x20name\x20is\x20required');const a=W(0x183)+k['resource']+'/'+String(k['id'])+'/'+p;await f['file']['put'](a,k['file']);if(!await f[W(0x181)]['exists'](a))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const N=await f['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',[k['resource'],String(k['id']),a,k['file']['length']]);return N['rows'][0x0];}function F(){const n=['resource','admin','type','user',':update','file','replace','files/'];F=function(){return n;};return F();}
|