@opengis/fcore 0.0.1-beta.10 → 0.0.1-beta.12

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.
Files changed (104) hide show
  1. package/dist/config.js +1 -1
  2. package/dist/context.js +1 -1
  3. package/dist/errors.js +1 -1
  4. package/dist/fastify.d.ts.map +1 -1
  5. package/dist/fastify.js +1 -1
  6. package/dist/fcore.js +1 -1
  7. package/dist/migrations/cli.js +1 -1
  8. package/dist/migrations/runner.js +1 -1
  9. package/dist/modules/auth/adduser-cli.js +1 -1
  10. package/dist/modules/auth/passwd-cli.js +1 -1
  11. package/dist/modules/auth/permission-cli.js +1 -1
  12. package/dist/modules/auth/route.js +1 -1
  13. package/dist/modules/auth/schema.js +1 -1
  14. package/dist/modules/auth/services/change-password.js +1 -1
  15. package/dist/modules/auth/services/get-current-user.js +1 -1
  16. package/dist/modules/auth/services/registration.js +1 -1
  17. package/dist/modules/auth/services/verify-two-factor.js +1 -1
  18. package/dist/modules/file/mime.js +1 -1
  19. package/dist/modules/file/route.js +1 -1
  20. package/dist/modules/file/schema.js +1 -1
  21. package/dist/modules/file/services/get-file.js +1 -1
  22. package/dist/modules/file/services/resize-file.js +1 -1
  23. package/dist/modules/file/services/upload-file.js +1 -1
  24. package/dist/modules/resource/route.js +1 -1
  25. package/dist/modules/resource/schema.js +1 -1
  26. package/dist/modules/resource/services/add-note.js +1 -1
  27. package/dist/modules/resource/services/add-resource-file.js +1 -1
  28. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  29. package/dist/modules/resource/services/create-resource.js +1 -1
  30. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  31. package/dist/modules/resource/services/delete-resource.js +1 -1
  32. package/dist/modules/resource/services/export-resource.js +1 -1
  33. package/dist/modules/resource/services/get-resource.js +1 -1
  34. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  35. package/dist/modules/resource/services/list-resources.js +1 -1
  36. package/dist/modules/resource/services/search-resource.js +1 -1
  37. package/dist/modules/resource/services/suggest-resource.js +1 -1
  38. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  39. package/dist/modules/resource/services/update-resource.js +1 -1
  40. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  41. package/dist/modules/system/route.js +1 -1
  42. package/dist/modules/system/schema.js +1 -1
  43. package/dist/modules/system/services/check-system.js +1 -1
  44. package/dist/modules/system/services/get-access.js +1 -1
  45. package/dist/modules/system/services/get-api-list.js +1 -1
  46. package/dist/modules/system/services/get-audit-log.js +1 -1
  47. package/dist/modules/system/services/get-dictionary.js +1 -1
  48. package/dist/modules/system/services/get-system-log.js +1 -1
  49. package/dist/modules/system/services/get-system-settings.js +1 -1
  50. package/dist/modules/system/services/list-dictionaries.js +1 -1
  51. package/dist/modules/system/services/set-access.js +1 -1
  52. package/dist/modules/system/services/update-dictionary.js +1 -1
  53. package/dist/modules/system/services/update-system-settings.js +1 -1
  54. package/dist/modules/utils/require-admin.js +1 -1
  55. package/dist/modules/utils/safe-user.js +1 -1
  56. package/dist/modules/utils/unsupported.js +1 -1
  57. package/dist/plugins/audit/audit.js +1 -1
  58. package/dist/plugins/audit/services/write-audit.js +1 -1
  59. package/dist/plugins/auth/get-user-permissions.js +1 -1
  60. package/dist/plugins/auth/index.js +1 -1
  61. package/dist/plugins/auth/verifyUser.js +1 -1
  62. package/dist/plugins/dictionary.js +1 -1
  63. package/dist/plugins/file.js +1 -1
  64. package/dist/plugins/jwt.js +1 -1
  65. package/dist/plugins/logger/index.js +1 -1
  66. package/dist/plugins/logger/transport.js +1 -1
  67. package/dist/plugins/pg.js +1 -1
  68. package/dist/plugins/redis.js +1 -1
  69. package/dist/plugins/resource/resource.js +1 -1
  70. package/dist/plugins/resource/resource.registry.js +1 -1
  71. package/dist/plugins/resource/resource.types.d.ts +5 -2
  72. package/dist/plugins/resource/resource.types.d.ts.map +1 -1
  73. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  74. package/dist/plugins/resource/services/add-file-token.js +1 -1
  75. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  76. package/dist/plugins/resource/services/create-relation.d.ts.map +1 -1
  77. package/dist/plugins/resource/services/create-relation.js +1 -1
  78. package/dist/plugins/resource/services/create.d.ts.map +1 -1
  79. package/dist/plugins/resource/services/create.js +1 -1
  80. package/dist/plugins/resource/services/delete-relation.d.ts.map +1 -1
  81. package/dist/plugins/resource/services/delete-relation.js +1 -1
  82. package/dist/plugins/resource/services/delete.d.ts +5 -1
  83. package/dist/plugins/resource/services/delete.d.ts.map +1 -1
  84. package/dist/plugins/resource/services/delete.js +1 -1
  85. package/dist/plugins/resource/services/find-one.js +1 -1
  86. package/dist/plugins/resource/services/find-relation.d.ts.map +1 -1
  87. package/dist/plugins/resource/services/find-relation.js +1 -1
  88. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  89. package/dist/plugins/resource/services/find.js +1 -1
  90. package/dist/plugins/resource/services/update-relation.d.ts.map +1 -1
  91. package/dist/plugins/resource/services/update-relation.js +1 -1
  92. package/dist/plugins/resource/services/update.d.ts +5 -1
  93. package/dist/plugins/resource/services/update.d.ts.map +1 -1
  94. package/dist/plugins/resource/services/update.js +1 -1
  95. package/dist/plugins/resource/utils/auto-index.js +1 -1
  96. package/dist/plugins/resource/utils/fields.js +1 -1
  97. package/dist/plugins/resource/utils/filters.js +1 -1
  98. package/dist/plugins/resource/utils/permissions.js +1 -1
  99. package/dist/plugins/resource/utils/sort.js +1 -1
  100. package/dist/plugins/resource/utils/sql.js +1 -1
  101. package/dist/shared/getIP.js +1 -1
  102. package/migrations/20260903120000_core_schema.sql +5 -2
  103. package/migrations/20260903130001_add_file_fields.sql +5 -0
  104. package/package.json +2 -2
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(d){const h=process.env[d];if(!h)throw new Error('Missing\x20environment\x20variable:\x20'+d);return h;}export function loadConfig(d={}){const Z=S,h={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG===Z(0xfb),'port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT==='false','max':+(process.env.RATE_LIMIT_MAX||0x64),'timeWindow':+(process.env.RATE_LIMIT_TIME_WINDOW||0xea60)},'storagePath':process.env.STORAGE_PATH??Z(0xfc),'redactionList':(process.env.REDACTION_LIST||'password')['split'](','),'logger':{'level':process.env.LOG_LEVEL??Z(0xfd),'responses':process.env.LOG_RESPONSES===Z(0xfb)?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')[Z(0xfe)](p=>p-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+Z(0xff)},'pg':{'host':process.env.PG_HOST??Z(0x100),'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??Z(0x101),'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||'true'),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&['lax',Z(0x102),'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{...h,...d,'logger':{...h['logger'],...d['logger']},'pg':{...h['pg'],...d['pg']},'redis':{...h['redis'],...d[Z(0x103)]},'s3':{...h['s3'],...d['s3']},'auth':{...h[Z(0x104)],...d['auth']}};}function S(d,h){d=d-0xfb;const p=v();let Z=p[d];return Z;}function v(){const D=['true','./storage','info','map','/log','localhost','0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','strict','redis','auth'];v=function(){return D;};return v();}export{required as requireEnv};
1
+ function A(x,q){x=x-0x1a5;const C=g();let J=C[x];return J;}import'dotenv/config';function g(){const Z=['Missing\x20environment\x20variable:\x20','false','split','localhost','session_user_auth','true','includes'];g=function(){return Z;};return g();}const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(x){const J=A,q=process.env[x];if(!q)throw new Error(J(0x1a5)+x);return q;}export function loadConfig(x={}){const K=A,q={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG==='true','port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT===K(0x1a6),'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')[K(0x1a7)](','),'logger':{'level':process.env.LOG_LEVEL??'info','responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')['map'](C=>C-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+'/log'},'pg':{'host':process.env.PG_HOST??K(0x1a8),'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??K(0x1a9),'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||K(0x1aa)),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||K(0x1aa)),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&['lax','strict','none'][K(0x1ab)](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{...q,...x,'logger':{...q['logger'],...x['logger']},'pg':{...q['pg'],...x['pg']},'redis':{...q['redis'],...x['redis']},'s3':{...q['s3'],...x['s3']},'auth':{...q['auth'],...x['auth']}};}export{required as requireEnv};
package/dist/context.js CHANGED
@@ -1 +1 @@
1
- let defaultContext;function S(d,h){d=d-0xee;const p=v();let Z=p[d];return Z;}export function setContext(d){defaultContext=d;}export function getContext(){if(!defaultContext)throw new Error('Application\x20context\x20is\x20not\x20initialized');return defaultContext;}function v(){const p=['allSettled','close','logger'];v=function(){return p;};return v();}export function createContext(d){return{...d,async 'close'(){const h=S;await Promise[h(0xee)]([d['redis']?.[h(0xef)](),d['pg']?.['end']()]),await d[h(0xf0)][h(0xef)]();}};}
1
+ let defaultContext;export function setContext(x){defaultContext=x;}function A(x,q){x=x-0x167;const C=g();let J=C[x];return J;}export function getContext(){const q=A;if(!defaultContext)throw new Error(q(0x167));return defaultContext;}export function createContext(x){return{...x,async 'close'(){await Promise['allSettled']([x['redis']?.['close'](),x['pg']?.['end']()]),await x['logger']['close']();}};}function g(){const C=['Application\x20context\x20is\x20not\x20initialized'];g=function(){return C;};return g();}
package/dist/errors.js CHANGED
@@ -1 +1 @@
1
- function S(d,h){d=d-0x8f;var p=v();var Z=p[d];return Z;}function v(){var X=['details','name','Authentication\x20required','CONFLICT'];v=function(){return X;};return v();}var D=S;export class FCoreError extends Error{['code'];['statusCode'];[D(0x8f)];constructor(d,h,p=0x1f4,Z){var u=D;super(h),this['code']=d,this['statusCode']=p,this['details']=Z,this[u(0x90)]=new.target.name;}}export class BadRequestError extends FCoreError{constructor(d,h){super('BAD_REQUEST_ERROR',d,0x190,h);}}export class UnauthorizedError extends FCoreError{constructor(d=D(0x91)){super('UNAUTHORIZED',d,0x191);}}export class ForbiddenError extends FCoreError{constructor(d='Access\x20denied'){super('FORBIDDEN',d,0x193);}}export class NotFoundError extends FCoreError{constructor(d='Not\x20found'){super('NOT_FOUND',d,0x194);}}export class ConflictError extends FCoreError{constructor(d='Conflict'){var n=D;super(n(0x92),d,0x199);}}export class ValidationError extends FCoreError{constructor(d,h){super('VALIDATION_ERROR',d,0x1a6,h);}}export class UnsupportedError extends FCoreError{constructor(d='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',d,0x1f5);}}
1
+ var Y=A;export class FCoreError extends Error{['code'];['statusCode'];['details'];constructor(x,q,C=0x1f4,J){var K=A;super(q),this[K(0x16e)]=x,this['statusCode']=C,this['details']=J,this['name']=new.target.name;}}export class BadRequestError extends FCoreError{constructor(x,q){var Z=A;super(Z(0x16f),x,0x190,q);}}function g(){var k=['code','BAD_REQUEST_ERROR','Authentication\x20required','Access\x20denied','Operation\x20is\x20not\x20configured','UNSUPPORTED'];g=function(){return k;};return g();}export class UnauthorizedError extends FCoreError{constructor(x=Y(0x170)){super('UNAUTHORIZED',x,0x191);}}function A(x,q){x=x-0x16e;var C=g();var J=C[x];return J;}export class ForbiddenError extends FCoreError{constructor(x=Y(0x171)){super('FORBIDDEN',x,0x193);}}export class NotFoundError extends FCoreError{constructor(x='Not\x20found'){super('NOT_FOUND',x,0x194);}}export class ConflictError extends FCoreError{constructor(x='Conflict'){super('CONFLICT',x,0x199);}}export class ValidationError extends FCoreError{constructor(x,q){super('VALIDATION_ERROR',x,0x1a6,q);}}export class UnsupportedError extends FCoreError{constructor(x=Y(0x172)){var b=Y;super(b(0x173),x,0x1f5);}}
@@ -1 +1 @@
1
- {"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;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"}
1
+ {"version":3,"file":"fastify.d.ts","sourceRoot":"","sources":["../src/fastify.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,KAAK,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAY/C,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC;AAarE,MAAM,CAAC,OAAO,UAAU,YAAY,CAClC,GAAG,EAAE,UAAU,EACf,OAAO,CAAC,EAAE,SAAS,cAAc,EAAE,GAClC,kBAAkB,CAiIpB"}
package/dist/fastify.js CHANGED
@@ -1 +1 @@
1
- import{FCoreError}from'./errors.js';function v(){const M=['split','reduce','ctx','onRoute','isArray','package','set','addHook','routeOptions','raw','headers','slice','user','access','User\x20required','length','permissions','includes','Missing\x20permission:\x20','setErrorHandler','send','code','test','INTERNAL_ERROR','Internal\x20server\x20error','auth','addContentTypeParser','application/x-www-form-urlencoded','disabled','rateLimit','preHandler'];v=function(){return M;};return v();}import{authRoutes}from'./modules/auth/route.js';function S(d,h){d=d-0x14a;const p=v();let Z=p[d];return Z;}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(d,h,p){const F=S,Z=decodeURIComponent(h['toString']())[F(0x14a)]('&')[F(0x14b)]((D,u)=>{const [n,X]=u['split']('=');return{...D,[n]:X};},{});p(null,Z);}export default function fcoreFastify(d,h){return async p=>{const B=S;p['decorate'](B(0x14c),d);const {config:Z}=d,D=new Map();p['addHook'](B(0x14d),n=>{const K=B;if(n['url']['startsWith']('/api/')){const X=n['schema'],Y=Array[K(0x14e)](n['method'])?n['method']:[n['method']];for(const w of Y){if(w==='HEAD')continue;const y={'method':w,'endpoint':n['url'],'package':X?.[K(0x14f)]??'fcore','tags':X?.['tags']??[],'summary':X?.['summary']??'','description':X?.['description']??'','access':X?.['access']??'public','permissions':X?.['permissions']??[]};D[K(0x150)](w+'\x20'+n['url'],y);}}}),p[B(0x151)]('preHandler',async n=>{const g=B,X=D['get'](n['method']+'\x20'+n[g(0x152)]['url']),Y=n[g(0x153)][g(0x154)]?.['authorization'],w=Y?.['startsWith']('Bearer\x20')?Y[g(0x155)](0x7):null,y=n[g(0x156)]??(w?await jwtVerifyToken(w):null);!n['user']&&w&&process.env.AUTH_JWT_SECRET&&(n['user']=await jwtVerifyToken(w));if(!X?.[g(0x157)])throw new Error('Route\x20access\x20not\x20defined');if(X['access']==='public')return!![];if(!y)throw new ForbiddenError(g(0x158));if(X['access']==='user'&&!X['permissions']?.[g(0x159)])return!![];if(y['type']=='admin')return!![];if(X['access']==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const Q of X[g(0x15a)]){if(!y[g(0x15a)]?.[g(0x15b)](Q))throw new ForbiddenError(g(0x15c)+Q);}return!![];}),await createSessionStore(p,d),await p['register'](import('@fastify/multipart'),{'limits':{'fileSize':Z['maxFileSize']*0x400*0x400}}),p[B(0x15d)]((n,X,Y)=>{const s=B;if(n instanceof FCoreError||n['code']==='FST_ERR_VALIDATION')return Y['code'](n['statusCode'])[s(0x15e)]({'error':n[s(0x15f)],'message':n['message'],'details':n['details']});return d['logger']['error'](n),(Z['debug']||process.env.NODE_ENV===s(0x160)||process.env.VITEST)&&console['error'](n),Y['code'](0x1f4)['send']({'error':s(0x161),'message':s(0x162)});});const u=n=>!h||h['includes'](n);if(u(B(0x163)))await p['register'](authRoutes(d));if(u('resource'))await p['register'](resourceRoutes(d));if(u('file'))await p['register'](fileRoutes(d));if(u('system'))await p['register'](systemRoutes(d,D));p[B(0x164)](B(0x165),{'parseAs':'buffer'},urlencodedContentParser),!Z['rateLimit']?.[B(0x166)]?p['register'](import('@fastify/rate-limit'),{'max':Z[B(0x167)]?.['max']||0x64,'timeWindow':Z['rateLimit']?.['timeWindow']||0xea60,'hook':B(0x168),'global':!![],'keyGenerator':n=>(n[B(0x156)]?.['id']||n['ip'])+'-'+n[B(0x153)]['url']['split']('?')[0x0]}):console['log']('⚠️\x20rate\x20limit\x20is\x20disabled');};};
1
+ import{FCoreError}from'./errors.js';function g(){const w=['decorate','addHook','onRoute','/api/','HEAD','access','public','permissions','get','url','raw','startsWith','user','admin','Admin\x20access\x20required','statusCode','details','error','auth','file','addContentTypeParser','disabled','rateLimit','preHandler'];g=function(){return w;};return g();}function A(x,q){x=x-0x144;const C=g();let J=C[x];return J;}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(x,q,C){const J=decodeURIComponent(q['toString']())['split']('&')['reduce']((K,Z)=>{const [Y,b]=Z['split']('=');return{...K,[Y]:b};},{});C(null,J);}export default function fcoreFastify(x,q){return async C=>{const r=A;C[r(0x144)]('ctx',x);const {config:J}=x,K=new Map();C[r(0x145)](r(0x146),Y=>{const B=r;if(Y['url']['startsWith'](B(0x147))){const b=Y['schema'],k=Array['isArray'](Y['method'])?Y['method']:[Y['method']];for(const H of k){if(H===B(0x148))continue;const F={'method':H,'endpoint':Y['url'],'package':b?.['package']??'fcore','tags':b?.['tags']??[],'summary':b?.['summary']??'','description':b?.['description']??'','access':b?.[B(0x149)]??B(0x14a),'permissions':b?.[B(0x14b)]??[]};K['set'](H+'\x20'+Y['url'],F);}}}),C['addHook']('preHandler',async Y=>{const t=r,b=K[t(0x14c)](Y['method']+'\x20'+Y['routeOptions'][t(0x14d)]),k=Y[t(0x14e)]['headers']?.['authorization'],H=k?.[t(0x14f)]('Bearer\x20')?k['slice'](0x7):null,F=Y['user']??(H?await jwtVerifyToken(H):null);!Y['user']&&H&&process.env.AUTH_JWT_SECRET&&(Y[t(0x150)]=await jwtVerifyToken(H));if(!b?.['access'])throw new Error('Route\x20access\x20not\x20defined');if(b['access']===t(0x14a))return!![];if(!F)throw new ForbiddenError('User\x20required');if(b[t(0x149)]==='user'&&!b['permissions']?.['length'])return!![];if(F['type']=='admin')return!![];if(b[t(0x149)]===t(0x151))throw new ForbiddenError(t(0x152));for(const y of b[t(0x14b)]){if(!F['permissions']?.['includes'](y))throw new ForbiddenError('Missing\x20permission:\x20'+y);}return!![];}),await createSessionStore(C,x),await C['register'](import('@fastify/multipart'),{'limits':{'fileSize':J['maxFileSize']*0x400*0x400}}),C['setErrorHandler']((Y,b,k)=>{const p=r;if(Y instanceof FCoreError||Y['code']==='FST_ERR_VALIDATION'||Y['statusCode']<0x1f4)return Y['statusCode']<0x1f4&&x['logger']['warn'](Y),k['code'](Y[p(0x153)])['send']({'error':Y['code'],'message':Y['message'],'details':Y[p(0x154)]});return x['logger'][p(0x155)](Y),(J['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console['error'](Y),k['code'](0x1f4)['send']({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const Z=Y=>!q||q['includes'](Y);if(Z(r(0x156)))await C['register'](authRoutes(x));if(Z('resource'))await C['register'](resourceRoutes(x));if(Z(r(0x157)))await C['register'](fileRoutes(x));if(Z('system'))await C['register'](systemRoutes(x,K));C[r(0x158)]('application/x-www-form-urlencoded',{'parseAs':'buffer'},urlencodedContentParser),!J['rateLimit']?.[r(0x159)]?C['register'](import('@fastify/rate-limit'),{'max':J[r(0x15a)]?.['max']||0x64,'timeWindow':J['rateLimit']?.['timeWindow']||0xea60,'hook':r(0x15b),'global':!![],'keyGenerator':Y=>(Y['user']?.['id']||Y['ip'])+'-'+Y['raw'][r(0x14d)]['split']('?')[0x0]}):console['log']('⚠️\x20rate\x20limit\x20is\x20disabled');};};
package/dist/fcore.js CHANGED
@@ -1 +1 @@
1
- import{loadConfig}from'./config.js';function S(d,h){d=d-0x1d9;const p=v();let Z=p[d];return Z;}import{createContext,setContext}from'./context.js';import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function v(){const Q=['config','redis','region','accessKey','folder','forcePathStyle'];v=function(){return Q;};return v();}export async function createFCore(d={}){const y=S,h=loadConfig(d[y(0x1d9)]),p=createRedis(h[y(0x1da)]),Z=createLogger(),D=createDatabase(h['pg']),u=createFileS3({'endpoint':h['s3']['endpoint'],'region':h['s3'][y(0x1db)],'bucket':h['s3']['bucket'],'accessKey':h['s3'][y(0x1dc)],'secretKey':h['s3']['secretKey'],'folder':h['s3'][y(0x1dd)],'forcePathStyle':h['s3'][y(0x1de)],'tokenSecret':h['s3']['tokenSecret'],'tokenTtl':h['s3']['tokenTtl']}),n=createAudit({'pg':D,'logger':Z}),X=createDictionary({'pg':D,'dictionaries':d['dictionaries']}),Y=createResource({'pg':D,'logger':Z,'audit':n,'dictionary':X,'file':u});d['resources']?.['length']&&Y['register'](d['resources']);const w=createContext({'config':h,'logger':Z,'redis':p,'pg':D,'file':u,'resource':Y,'audit':n,'dictionary':X});return setContext(w),w;}
1
+ function A(x,q){x=x-0xff;const C=g();let J=C[x];return J;}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function g(){const y=['secretKey','length'];g=function(){return y;};return g();}import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';export async function createFCore(x={}){const F=A,q=loadConfig(x['config']),C=createRedis(q['redis']),J=createLogger(),K=createDatabase(q['pg']),Z=createFileS3({'endpoint':q['s3']['endpoint'],'region':q['s3']['region'],'bucket':q['s3']['bucket'],'accessKey':q['s3']['accessKey'],'secretKey':q['s3'][F(0xff)],'folder':q['s3']['folder'],'forcePathStyle':q['s3']['forcePathStyle'],'tokenSecret':q['s3']['tokenSecret'],'tokenTtl':q['s3']['tokenTtl']}),Y=createAudit({'pg':K,'logger':J}),b=createDictionary({'pg':K,'dictionaries':x['dictionaries']}),k=createResource({'pg':K,'logger':J,'audit':Y,'dictionary':b,'file':Z});x['resources']?.[F(0x100)]&&k['register'](x['resources']);const H=createContext({'config':q,'logger':J,'redis':C,'pg':K,'file':Z,'resource':k,'audit':Y,'dictionary':b});return setContext(H),H;}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function S(d,h){d=d-0x1b0;const p=v();let Z=p[d];return Z;}const h=S;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';try{const config=loadConfig();console[h(0x1b0)]('Loaded\x20configuration:',config['pg']);for(const r of await runMigrations({'database':config['pg']}))console[h(0x1b0)]((r['status']===h(0x1b1)?h(0x1b2):'SKIP')+'\x20'+r[h(0x1b3)]);}catch(d){console[h(0x1b4)](d),process[h(0x1b5)]=0x1;}function v(){const p=['log','run','OK\x20\x20','file','error','exitCode'];v=function(){return p;};return v();}
2
+ function A(x,q){x=x-0x19c;const C=g();let J=C[x];return J;}const q=A;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';try{const config=loadConfig();console[q(0x19c)](q(0x19d),config['pg']);for(const r of await runMigrations({'database':config['pg']}))console['log']((r['status']==='run'?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(x){console['error'](x),process['exitCode']=0x1;}function g(){const C=['log','Loaded\x20configuration:'];g=function(){return C;};return g();}
@@ -1 +1 @@
1
- import d from'node:fs/promises';import h from'node:path';function v(){const s=['query','rows','endsWith','join','INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)','push','slice','username'];v=function(){return s;};return v();}import{createDatabase}from'../plugins/pg.js';function S(d,h){d=d-0x195;const p=v();let Z=p[d];return Z;}export async function runMigrations(p={}){const K=S,Z=h['resolve'](p['dir']??'migrations'),D=p['database']??databaseFromUrl(p['databaseUrl']??process.env.DATABASE_URL);if(!D)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const u=createDatabase(D);if(!u)throw new Error('empty\x20pg');const n=[];try{await u[K(0x195)]('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const X=await u['query']('SELECT\x20version\x20FROM\x20schema_migrations'),Y=new Set(X[K(0x196)]['map'](y=>y['version'])),w=(await d['readdir'](Z))['filter'](y=>y[K(0x197)]('.sql'))['sort']();for(const y of w){if(Y['has'](y)){n['push']({'file':y,'status':'skip'});continue;}const Q=await d['readFile'](h[K(0x198)](Z,y),'utf8'),F=await u['connect']();try{await F['query']('BEGIN'),await F['query'](Q),await F[K(0x195)](K(0x199),[y]),await F['query']('COMMIT');}catch(B){await F[K(0x195)]('ROLLBACK');throw B;}finally{F['release']();}n[K(0x19a)]({'file':y,'status':'run'});}return n;}finally{await u['end']();}}function databaseFromUrl(p){const g=S;if(!p)return undefined;const Z=new URL(p);return{'host':Z['hostname'],'port':Number(Z['port']||0x1538),'database':Z['pathname'][g(0x19b)](0x1),'user':decodeURIComponent(Z[g(0x19c)]),'password':decodeURIComponent(Z['password'])};}
1
+ import x from'node:fs/promises';import q from'node:path';function A(x,q){x=x-0x1f0;const C=g();let J=C[x];return J;}function g(){const w=['resolve','dir','query','SELECT\x20version\x20FROM\x20schema_migrations','map','version','readdir','has','join','BEGIN','ROLLBACK','push','end','hostname','username'];g=function(){return w;};return g();}import{createDatabase}from'../plugins/pg.js';export async function runMigrations(C={}){const t=A,J=q[t(0x1f0)](C[t(0x1f1)]??'migrations'),K=C['database']??databaseFromUrl(C['databaseUrl']??process.env.DATABASE_URL);if(!K)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const Z=createDatabase(K);if(!Z)throw new Error('empty\x20pg');const Y=[];try{await Z[t(0x1f2)]('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const b=await Z['query'](t(0x1f3)),k=new Set(b['rows'][t(0x1f4)](F=>F[t(0x1f5)])),H=(await x[t(0x1f6)](J))['filter'](F=>F['endsWith']('.sql'))['sort']();for(const F of H){if(k[t(0x1f7)](F)){Y['push']({'file':F,'status':'skip'});continue;}const y=await x['readFile'](q[t(0x1f8)](J,F),'utf8'),r=await Z['connect']();try{await r['query'](t(0x1f9)),await r[t(0x1f2)](y),await r[t(0x1f2)]('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[F]),await r['query']('COMMIT');}catch(B){await r['query'](t(0x1fa));throw B;}finally{r['release']();}Y[t(0x1fb)]({'file':F,'status':'run'});}return Y;}finally{await Z[t(0x1fc)]();}}function databaseFromUrl(C){const p=A;if(!C)return undefined;const J=new URL(C);return{'host':J[p(0x1fd)],'port':Number(J['port']||0x1538),'database':J['pathname']['slice'](0x1),'user':decodeURIComponent(J[p(0x1fe)]),'password':decodeURIComponent(J['password'])};}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function v(){const Z=['error','Registered\x20user\x20','exitCode','end'];v=function(){return Z;};return v();}const p=S;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function S(d,h){d=d-0x10d;const p=v();let Z=p[d];return Z;}import d from'./services/registration.js';const [user,password,type]=process['argv']['slice'](0x2);if(!user||!password)console[p(0x10d)]('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await d({'user':user,'password':password,'type':type},{'pg':pg});console['log'](p(0x10e)+data['id']+'\x20('+data['type']+')');}catch(h){console['error'](h),process[p(0x10f)]=0x1;}finally{await pg[p(0x110)]();}}
2
+ const C=A;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function A(x,q){x=x-0x144;const C=g();let J=C[x];return J;}function g(){const J=['error','exitCode'];g=function(){return J;};return g();}import x from'./services/registration.js';const [user,password,type]=process['argv']['slice'](0x2);if(!user||!password)console[C(0x144)]('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process[C(0x145)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await x({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(q){console['error'](q),process['exitCode']=0x1;}finally{await pg['end']();}}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import d from'./services/change-password.js';const [login,password]=process['argv']['slice'](0x2);if(!login||!password)console['error']('Usage:\x20fcore-password\x20<login>\x20<password>'),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('User\x20not\x20found');await d({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(h){console['error'](h),process['exitCode']=0x1;}finally{await pg['end']();}}
2
+ const C=A;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function A(x,q){x=x-0x1bc;const C=g();let J=C[x];return J;}import x from'./services/change-password.js';const [login,password]=process['argv']['slice'](0x2);function g(){const J=['error','User\x20not\x20found','Password\x20changed\x20for\x20','end'];g=function(){return J;};return g();}if(!login||!password)console[C(0x1bc)]('Usage:\x20fcore-password\x20<login>\x20<password>'),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(C(0x1bd));await x({'userId':user['id'],'password':password},{'pg':pg}),console['log'](C(0x1be)+login);}catch(q){console['error'](q),process['exitCode']=0x1;}finally{await pg[C(0x1bf)]();}}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const Y=S;function v(){const y=['list','access','create','trim','add','system','query','SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201','rows','connect','BEGIN','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','release','join','exitCode'];v=function(){return y;};return v();}function S(d,h){d=d-0x119;const p=v();let Z=p[d];return Z;}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs','audit',Y(0x119),'check',Y(0x11a),'settings','dictionaries'],RESOURCE_ACTIONS=['read','update',Y(0x11b),'delete'],[login,permissionArg]=process['argv']['slice'](0x2);function expandPermissions(d){const w=Y,h=d['split'](',')['map'](Z=>Z[w(0x11c)]())['filter'](Boolean),p=new Set();for(const Z of h){if(Z['includes'](':')){p[w(0x11d)](Z);continue;}const D=Z===w(0x11e)?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const u of D){p['add'](Z+':'+u);}}return[...p];}if(!login||!permissionArg)console['error']('Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[Y(0x11f)](Y(0x120),[login]),user=result[Y(0x121)][0x0];if(!user)throw new Error('User\x20not\x20found');if(permissionArg['trim']()==='clear')await pg[Y(0x11f)]('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['get'](resource)??[];actions['push'](action),byResource['set'](resource,actions);}const client=await pg[Y(0x122)]();try{await client['query'](Y(0x123));for(const [resource,actions]of byResource){const existing=await client['query'](Y(0x124),[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client['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',[merged,user['id'],row['access_id']]);}else await client['query']('INSERT\x20INTO\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(\x20resource,\x20actions,\x20user_uid,\x20created_by,\x20updated_by)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4,\x20$4)',[resource,actions,user['id'],user['id']]);}await client['query']('COMMIT');}catch(n){await client['query']('ROLLBACK');throw n;}finally{client[Y(0x125)]();}console['log']('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions[Y(0x126)](',\x20'));}}catch(X){console['error'](X),process[Y(0x127)]=0x1;}finally{await pg['end']();}}
2
+ function g(){const F=['check','create','add','error','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','exitCode','query','SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201','rows','trim','clear','Permissions\x20cleared\x20for\x20','push','connect','BEGIN','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','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','COMMIT','ROLLBACK','log'];g=function(){return F;};return g();}const k=A;function A(x,q){x=x-0x17c;const C=g();let J=C[x];return J;}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs','audit','list',k(0x17c),'access','settings','dictionaries'],RESOURCE_ACTIONS=['read','update',k(0x17d),'delete'],[login,permissionArg]=process['argv']['slice'](0x2);function expandPermissions(x){const H=k,q=x['split'](',')['map'](J=>J['trim']())['filter'](Boolean),C=new Set();for(const J of q){if(J['includes'](':')){C[H(0x17e)](J);continue;}const K=J==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const Z of K){C['add'](J+':'+Z);}}return[...C];}if(!login||!permissionArg)console[k(0x17f)](k(0x180)),process[k(0x181)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[k(0x182)](k(0x183),[login]),user=result[k(0x184)][0x0];if(!user)throw new Error('User\x20not\x20found');if(permissionArg[k(0x185)]()===k(0x186))await pg['query']('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console['log'](k(0x187)+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission['split'](':'),actions=byResource['get'](resource)??[];actions[k(0x188)](action),byResource['set'](resource,actions);}const client=await pg[k(0x189)]();try{await client[k(0x182)](k(0x18a));for(const [resource,actions]of byResource){const existing=await client['query'](k(0x18b),[user['id'],resource]),row=existing[k(0x184)][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client['query'](k(0x18c),[merged,user['id'],row['access_id']]);}else await client['query']('INSERT\x20INTO\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20(\x20resource,\x20actions,\x20user_uid,\x20created_by,\x20updated_by)\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4,\x20$4)',[resource,actions,user['id'],user['id']]);}await client['query'](k(0x18d));}catch(Y){await client['query'](k(0x18e));throw Y;}finally{client['release']();}console[k(0x18f)]('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions['join'](',\x20'));}}catch(b){console['error'](b),process['exitCode']=0x1;}finally{await pg['end']();}}
@@ -1 +1 @@
1
- import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import d from'./services/get-current-user.js';import h from'./services/registration.js';import p from'./services/change-password.js';function S(d,h){d=d-0x154;const p=v();let Z=p[d];return Z;}import{authSchemas}from'./schema.js';import Z from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';function v(){const M=['query','body','permissions','auth','redirect','config','sessionTimeout','cookie','maxAge','session','login','Sign\x20in','credentials','post','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','public','/api/auth/registration','user','Not\x20authorized','fcore','clearCookie','defineProperty','/api/auth/user','Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.'];v=function(){return M;};return v();}export function authRoutes(D){return async u=>{const K=S,n=async X=>{const B=S,Y=X['method']==='GET'?X[B(0x154)]:X[B(0x155)],w=Z(X),y=await verifyUser({...Y,'ip':w},D);y[B(0x156)]=await getUserPermissions(y['id'],D);const Q=y['twofa']?D['config']['auth']['twoFactorRedirect']:D['config'][B(0x157)][B(0x158)];await X['login'](y);const F=D[B(0x159)]['auth'][B(0x15a)]*0x3e8*0x3c;return X['session']?.[B(0x15b)]&&(X['session']['cookie'][B(0x15c)]=F),await X['session']['save'](),await D['audit']?.['write']?.({'module':B(0x157),'resource':B(0x15d),'resourceId':X[B(0x15d)]['sessionId'],'action':B(0x15e),'userId':y['id'],'ipAddress':w}),{'user':{'id':y['id'],'type':y['type'],'permissions':y[B(0x156)]},'redirectUrl':Q};};u['get']('/api/auth/login',{'schema':{'tags':['fcore',K(0x157)],'summary':K(0x15f),'description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'querystring':authSchemas[K(0x160)]}},n),u[K(0x161)]('/api/auth/login',{'schema':{'tags':['fcore',K(0x157)],'summary':'Sign\x20in','description':K(0x162),'access':K(0x163),'permissions':[],'body':authSchemas['credentials']}},n),u['post'](K(0x164),{'schema':{'tags':['fcore',K(0x157)],'summary':'Register','description':'Creates\x20a\x20regular\x20user\x20account.','access':'admin','permissions':['user:create'],'body':authSchemas['credentials']}},async X=>h(X['body'],D)),u['post']('/api/auth/password',{'schema':{'tags':['fcore',K(0x157)],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas['password']}},async X=>{const g=K;if(!X[g(0x165)])throw new UnauthorizedError(g(0x166));return await p({'userId':X[g(0x165)]['id'],...X['body']},D),{'success':!![]};}),u[K(0x161)]('/api/auth/logout',{'schema':{'tags':[K(0x167),K(0x157)],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(X,Y)=>{const s=K,w={'redirectUrl':'/'};if(!X[s(0x165)])return w;return await D['audit']?.['write']?.({'module':'auth','resource':s(0x15d),'resourceId':X[s(0x15d)]['sessionId'],'action':'logout','userId':X['user']?.['id']}),await X[s(0x15d)]['destroy'](),Y[s(0x168)](D['config']['auth']['cookieName']),Object[s(0x169)](X,s(0x15d),{'value':null,'writable':![],'configurable':![]}),w;}),u['get'](K(0x16a),{'schema':{'tags':['fcore','auth'],'summary':'Get\x20current\x20user','description':K(0x16b),'access':K(0x165),'permissions':[],'querystring':authSchemas[K(0x154)]}},async X=>d({'user':X['user'],'token':X['query']['token']}));};}
1
+ import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import x from'./services/get-current-user.js';import q from'./services/registration.js';function g(){const R=['method','body','config','redirect','cookie','session','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','auth','credentials','fcore','Register','user','sessionId','destroy','defineProperty','/api/auth/user','query','token'];g=function(){return R;};return g();}import C from'./services/change-password.js';import{authSchemas}from'./schema.js';function A(x,q){x=x-0x68;const C=g();let J=C[x];return J;}import J from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(K){return async Z=>{const t=A,Y=async b=>{const B=A,k=b[B(0x68)]==='GET'?b['query']:b[B(0x69)],H=J(b),F=await verifyUser({...k,'ip':H},K);F['permissions']=await getUserPermissions(F['id'],K);const y=F['twofa']?K['config']['auth']['twoFactorRedirect']:K[B(0x6a)]['auth'][B(0x6b)];await b['login'](F);const r=K['config']['auth']['sessionTimeout']*0x3e8*0x3c;return b['session']?.['cookie']&&(b['session'][B(0x6c)]['maxAge']=r),await b['session']['save'](),await K['audit']?.['write']?.({'module':'auth','resource':'session','resourceId':b[B(0x6d)]['sessionId'],'action':'login','userId':F['id'],'ipAddress':H}),{'user':{'id':F['id'],'type':F['type'],'permissions':F['permissions']},'redirectUrl':y};};Z['get']('/api/auth/login',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':t(0x6e),'access':'public','permissions':[],'querystring':authSchemas['credentials']}},Y),Z['post']('/api/auth/login',{'schema':{'tags':['fcore',t(0x6f)],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'body':authSchemas[t(0x70)]}},Y),Z['post']('/api/auth/registration',{'schema':{'tags':[t(0x71),'auth'],'summary':t(0x72),'description':'Creates\x20a\x20regular\x20user\x20account.','access':'admin','permissions':['user:create'],'body':authSchemas['credentials']}},async b=>q(b[t(0x69)],K)),Z['post']('/api/auth/password',{'schema':{'tags':[t(0x71),'auth'],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas['password']}},async b=>{const p=t;if(!b[p(0x73)])throw new UnauthorizedError('Not\x20authorized');return await C({'userId':b['user']['id'],...b['body']},K),{'success':!![]};}),Z['post']('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(b,k)=>{const w=t,H={'redirectUrl':'/'};if(!b['user'])return H;return await K['audit']?.['write']?.({'module':'auth','resource':'session','resourceId':b['session'][w(0x74)],'action':'logout','userId':b['user']?.['id']}),await b['session'][w(0x75)](),k['clearCookie'](K[w(0x6a)]['auth']['cookieName']),Object[w(0x76)](b,'session',{'value':null,'writable':![],'configurable':![]}),H;}),Z['get'](t(0x77),{'schema':{'tags':['fcore',t(0x6f)],'summary':'Get\x20current\x20user','description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas['query']}},async b=>x({'user':b['user'],'token':b[t(0x78)][t(0x79)]}));};}
@@ -1 +1 @@
1
- const d=S;function S(d,h){d=d-0x81;const p=v();let Z=p[d];return Z;}import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type[d(0x81)](Type['Boolean']())}),'credentials':Type['Object']({'user':Type[d(0x82)]({'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['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type['String']({'minLength':0x1})})};function v(){const h=['Optional','String'];v=function(){return h;};return v();}
1
+ const x=A;import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type[x(0x1d7)]())}),'credentials':Type[x(0x1d8)]({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type[x(0x1d9)]({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type[x(0x1d9)]({'minLength':0x1})})};function A(x,q){x=x-0x1d7;const C=g();let J=C[x];return J;}function g(){const q=['Boolean','Object','String'];g=function(){return q;};return g();}
@@ -1 +1 @@
1
- import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:d,password:h,userId:p},{pg:Z}){const D=await hashPassword(h);await Z['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',[D,d||p,p]);}
1
+ import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:x,password:q,userId:C},{pg:J}){const K=await hashPassword(q);await J['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',[K,x||C,C]);}
@@ -1 +1 @@
1
- function S(d,h){d=d-0x1dc;const p=v();let Z=p[d];return Z;}import{safeUser}from'../../utils/safe-user.js';function v(){const n=['split'];v=function(){return n;};return v();}export default async function getCurrentUser(d){const u=S,{user:h}=d;if(!h)return{};if(d['token']){const {jwtSignToken:p}=await import('../../../plugins/jwt.js'),Z=await p(h);h['token']=Z;}return h['resources']=[...new Set(h?.['permissions']['map'](D=>D[u(0x1dc)](':')[0x0]))],safeUser(h);}
1
+ import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(x){const Z=A,{user:q}=x;if(!q)return{};if(x[Z(0x99)]){const {jwtSignToken:C}=await import('../../../plugins/jwt.js'),J=await C(q);q['token']=J;}return q['resources']=[...new Set(q?.['permissions']['map'](K=>K['split'](':')[0x0]))],safeUser(q);}function A(x,q){x=x-0x99;const C=g();let J=C[x];return J;}function g(){const Y=['token'];g=function(){return Y;};return g();}
@@ -1 +1 @@
1
- function v(){const Y=['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','Login\x20is\x20already\x20in\x20use'];v=function(){return Y;};return v();}import{ConflictError}from'../../../errors.js';function S(d,h){d=d-0x140;const p=v();let Z=p[d];return Z;}import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:d,password:h,type:p},{pg:Z}){const X=S,D=await hashPassword(h),u=await Z['query'](X(0x140),[d,D,p||'regular']),n=u['rows'][0x0];if(!n)throw new ConflictError(X(0x141));return{'user':n};}
1
+ function g(){const k=['regular'];g=function(){return k;};return g();}function A(x,q){x=x-0x17f;const C=g();let J=C[x];return J;}import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:x,password:q,type:C},{pg:J}){const b=A,K=await hashPassword(q),Z=await J['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',[x,K,C||b(0x17f)]),Y=Z['rows'][0x0];if(!Y)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':Y};}
@@ -1 +1 @@
1
- import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(d,h){return unsupported('Two-factor\x20provider');}
1
+ import{unsupported}from'../../utils/unsupported.js';function A(x,q){x=x-0x192;var C=g();var J=C[x];return J;}export default async function verifyTwoFactor(x,q){var C=A;return unsupported(C(0x192));}function g(){var J=['Two-factor\x20provider'];g=function(){return J;};return g();}
@@ -1 +1 @@
1
- var d=S;export default new Set([d(0xcc),'image/png','image/gif','image/webp','image/bmp','image/tiff','image/svg+xml','image/x-icon','image/avif','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document',d(0xcd),'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-powerpoint',d(0xce),'application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet',d(0xcf),'text/plain','text/csv','text/markdown',d(0xd0),d(0xd1),d(0xd2),'application/geo+json','application/vnd.google-earth.kml+xml',d(0xd3),'application/zip','application/x-zip-compressed',d(0xd4),'application/x-rar-compressed','application/vnd.rar',d(0xd5),d(0xd6),d(0xd7),d(0xd8),'audio/wav',d(0xd9),'audio/webm','audio/mp4',d(0xda),d(0xdb),d(0xdc),'video/quicktime','video/x-msvideo','application/octet-stream']);function S(d,h){d=d-0xcc;var p=v();var Z=p[d];return Z;}function v(){var h=['image/jpeg','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.presentation','application/json','application/xml','text/xml','application/vnd.google-earth.kmz','application/x-7z-compressed','application/gzip','application/x-gzip','application/x-tar','audio/mpeg','audio/ogg','video/mp4','video/mpeg','video/webm'];v=function(){return h;};return v();}
1
+ var x=A;function A(x,q){x=x-0xff;var C=g();var J=C[x];return J;}export default new Set([x(0xff),x(0x100),'image/gif','image/webp','image/bmp','image/tiff',x(0x101),x(0x102),x(0x103),'application/pdf',x(0x104),'application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel',x(0x105),'application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation',x(0x106),'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain','text/csv',x(0x107),'application/json','application/xml','text/xml','application/geo+json',x(0x108),'application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed','application/x-7z-compressed',x(0x109),'application/vnd.rar',x(0x10a),'application/x-gzip',x(0x10b),'audio/mpeg',x(0x10c),'audio/ogg','audio/webm','audio/mp4','video/mp4','video/mpeg','video/webm','video/quicktime','video/x-msvideo','application/octet-stream']);function g(){var q=['image/jpeg','image/png','image/svg+xml','image/x-icon','image/avif','application/msword','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.oasis.opendocument.text','text/markdown','application/vnd.google-earth.kml+xml','application/x-rar-compressed','application/gzip','application/x-tar','audio/wav'];g=function(){return q;};return g();}
@@ -1 +1 @@
1
- function S(d,h){d=d-0x1da;const p=v();let Z=p[d];return Z;}import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function v(){const g=['file','Get\x20file\x20by\x20token','public','params','token','mime','query','Content-Disposition','attachment','Upload\x20file','resource','fields','user','/api/file/:token/resize','Returns\x20a\x20resized\x20image\x20file.','verify','image/png','header','inline','public,\x20max-age=86400,\x20immutable'];v=function(){return g;};return v();}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(d){return async h=>{const Q=S;h['get']('/api/file/:token',{'schema':{'tags':['fcore',Q(0x1da)],'summary':Q(0x1db),'description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':Q(0x1dc),'permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas['fileDownloadQuery']}},async(p,Z)=>{const F=Q,D=d['file']['verify'](p[F(0x1dd)][F(0x1de)]),u=await getFile({'pathOrToken':D},d),n=await fileTypeFromBuffer(u),X=n?.[F(0x1df)]??'application/octet-stream',Y=p[F(0x1e0)]['download']===!![],w=X['startsWith']('image/')||X==='application/pdf',y=D['split']('/')['pop']()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??'file';return Z['type'](X),Z['header'](F(0x1e1),(Y||!w?F(0x1e2):'inline')+';\x20filename=\x22'+y+'\x22')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),Z['send'](u);}),h['post']('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':Q(0x1e3),'description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async p=>{const B=Q,Z=await p['file']();if(!Z)throw new Error('File\x20is\x20required');return uploadFile({'file':Z,'metadata':{'name':Z['filename'],'path':Z['fields']['path']?.['value'],'resource':Z['fields'][B(0x1e4)]?.['value'],'resourceId':Z[B(0x1e5)]['resourceId']?.['value']},'user':p[B(0x1e6)]},d);}),h['get'](Q(0x1e7),{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':Q(0x1e8),'access':Q(0x1e6),'permissions':['files:read'],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(p,Z)=>{const K=Q,D=await resizeFile({'pathOrToken':d['file']?.[K(0x1e9)](p[K(0x1dd)]['token']),...p[K(0x1e0)]},d),u=await fileTypeFromBuffer(D);return Z['type'](u?.['mime']??K(0x1ea)),Z[K(0x1eb)]('Content-Disposition',K(0x1ec))['header']('Cache-Control',K(0x1ed)),Z['send'](D);});};}
1
+ import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function A(x,q){x=x-0x153;const C=g();let J=C[x];return J;}import{resizeFile}from'./services/resize-file.js';function g(){const p=['file','fileToken','token','download','pop','replace','header','Content-Disposition','attachment','send','post','/api/file/upload','fcore','fields','value','get','/api/file/:token/resize','files:read','params','type','image/png'];g=function(){return p;};return g();}import{fileSchemas}from'./schema.js';export function fileRoutes(x){return async q=>{const y=A;q['get']('/api/file/:token',{'schema':{'tags':['fcore',y(0x153)],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas[y(0x154)],'querystring':fileSchemas['fileDownloadQuery']}},async(C,J)=>{const r=y,K=x[r(0x153)]['verify'](C['params'][r(0x155)]),Z=await getFile({'pathOrToken':K},x),Y=await fileTypeFromBuffer(Z),b=Y?.['mime']??'application/octet-stream',k=C['query'][r(0x156)]===!![],H=b['startsWith']('image/')||b==='application/pdf',F=K['split']('/')[r(0x157)]()?.[r(0x158)](/[^A-Za-z0-9._-]/g,'_')??'file';return J['type'](b),J[r(0x159)](r(0x15a),(k||!H?r(0x15b):'inline')+';\x20filename=\x22'+F+'\x22')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),J[r(0x15c)](Z);}),q[y(0x15d)](y(0x15e),{'schema':{'tags':[y(0x15f),y(0x153)],'summary':'Upload\x20file','description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async C=>{const B=y,J=await C[B(0x153)]();if(!J)throw new Error('File\x20is\x20required');return uploadFile({'file':J,'metadata':{'name':J['filename'],'path':J[B(0x160)]['path']?.[B(0x161)],'resource':J[B(0x160)]['resource']?.['value'],'resourceId':J['fields']['resourceId']?.['value']},'user':C['user']},x);}),q[y(0x162)](y(0x163),{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':[y(0x164)],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(C,J)=>{const t=y,K=await resizeFile({'pathOrToken':x['file']?.['verify'](C[t(0x165)][t(0x155)]),...C['query']},x),Z=await fileTypeFromBuffer(K);return J[t(0x166)](Z?.['mime']??t(0x167)),J['header'](t(0x15a),'inline')[t(0x159)]('Cache-Control','public,\x20max-age=86400,\x20immutable'),J['send'](K);});};}
@@ -1 +1 @@
1
- const d=S;import{Type}from'@sinclair/typebox';function S(d,h){d=d-0x17e;const p=v();let Z=p[d];return Z;}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[d(0x17e)]({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type[d(0x17f)](),'metadata':Type['Object']({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type[d(0x180)]({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type[d(0x181)](Type['String']({'minLength':0x1}))}),'resizeQuery':Type[d(0x17e)]({'width':Type['Optional'](Type[d(0x182)]({'minimum':0x1,'default':0xc8})),'height':Type[d(0x181)](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type['Union']([Type['Literal']('cover'),Type['Literal']('contain'),Type[d(0x183)](d(0x184)),Type['Literal']('inside'),Type['Literal'](d(0x185))]))})};function v(){const h=['Object','Any','String','Optional','Integer','Literal','fill','outside'];v=function(){return h;};return v();}
1
+ const x=A;import{Type}from'@sinclair/typebox';function A(x,q){x=x-0x161;const C=g();let J=C[x];return J;}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['Optional'](Type['Boolean']())}),'filePath':Type[x(0x161)]({'*':Type[x(0x162)]({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type[x(0x163)](),'metadata':Type['Object']({'name':Type['Optional'](Type[x(0x162)]({'minLength':0x1})),'path':Type['Optional'](Type[x(0x162)]({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type[x(0x164)](Type['String']({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type[x(0x165)]({'minimum':0x1,'default':0xc8})),'height':Type['Optional'](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type['Union']([Type[x(0x166)]('cover'),Type['Literal']('contain'),Type['Literal']('fill'),Type['Literal'](x(0x167)),Type['Literal']('outside')]))})};function g(){const q=['Object','String','Any','Optional','Integer','Literal','inside'];g=function(){return q;};return g();}
@@ -1 +1 @@
1
- function v(){var Z=['File\x20not\x20found','pathOrToken','file'];v=function(){return Z;};return v();}function S(d,h){d=d-0x1de;var p=v();var Z=p[d];return Z;}import{NotFoundError}from'../../../errors.js';export async function getFile(d,h){var p=S;if(!h['file'])throw new Error('empty\x20file');if(!await h['file']['exists'](d['pathOrToken']))throw new NotFoundError(p(0x1de)+d[p(0x1df)]);return h[p(0x1e0)]['get'](d['pathOrToken']);}
1
+ function A(x,q){x=x-0x1a5;var C=g();var J=C[x];return J;}function g(){var J=['exists','pathOrToken'];g=function(){return J;};return g();}import{NotFoundError}from'../../../errors.js';export async function getFile(x,q){var C=A;if(!q['file'])throw new Error('empty\x20file');if(!await q['file'][C(0x1a5)](x[C(0x1a6)]))throw new NotFoundError('File\x20not\x20found'+x['pathOrToken']);return q['file']['get'](x[C(0x1a6)]);}
@@ -1 +1 @@
1
- import{NotFoundError,ValidationError}from'../../../errors.js';function S(d,h){d=d-0x19e;const p=v();let Z=p[d];return Z;}import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';import{mkdir,readFile,writeFile}from'node:fs/promises';import d from'node:path';import h from'sharp';export async function resizeFile(p,Z){const K=S,D=p['pathOrToken']??p['path'];if(!D)throw new ValidationError('File\x20path\x20is\x20required');const u=parseDimension(p['width'],K(0x19e))??0xc8,n=parseDimension(p[K(0x19f)],K(0x19f)),X=createHash('sha256')['update'](D+':'+u+':'+(n??'auto')+':'+(p['fit']??K(0x1a0)))['digest']('hex'),Y=d['resolve'](K(0x1a1),'resize'),w=d['join'](Y,X+'.jpg');try{return await readFile(w);}catch(B){if(B[K(0x1a2)]!=='ENOENT')throw B;}if(!await Z[K(0x1a3)][K(0x1a4)](D))throw new NotFoundError(K(0x1a5));const y=await Z['file']['get'](D),Q=await fileTypeFromBuffer(y);if(!Q?.[K(0x1a6)]['startsWith']('image/'))throw new ValidationError(K(0x1a7));const F=await h(y)[K(0x1a8)]({'width':u,'height':n,'fit':p['fit']??K(0x1a0)})['toBuffer']();return await mkdir(Y,{'recursive':!![]}),await writeFile(w,F),F;}function v(){const s=['width','height','cover','logs','code','file','exists','File\x20not\x20found','mime','Only\x20image\x20files\x20can\x20be\x20resized','resize','\x20must\x20be\x20a\x20positive\x20integer'];v=function(){return s;};return v();}function parseDimension(p,Z){const g=S;if(p===undefined||p==='')return undefined;const D=Number(p);if(!Number['isInteger'](D)||D<=0x0)throw new ValidationError(Z+g(0x1a9));return D;}
1
+ import{NotFoundError,ValidationError}from'../../../errors.js';function g(){const p=['update','auto','cover','digest','logs','code','File\x20not\x20found','get','startsWith','Only\x20image\x20files\x20can\x20be\x20resized','resize','fit'];g=function(){return p;};return g();}import{fileTypeFromBuffer}from'file-type';function A(x,q){x=x-0x1d1;const C=g();let J=C[x];return J;}import{createHash}from'node:crypto';import{mkdir,readFile,writeFile}from'node:fs/promises';import x from'node:path';import q from'sharp';export async function resizeFile(C,J){const t=A,K=C['pathOrToken']??C['path'];if(!K)throw new ValidationError('File\x20path\x20is\x20required');const Z=parseDimension(C['width'],'width')??0xc8,Y=parseDimension(C['height'],'height'),b=createHash('sha256')[t(0x1d1)](K+':'+Z+':'+(Y??t(0x1d2))+':'+(C['fit']??t(0x1d3)))[t(0x1d4)]('hex'),k=x['resolve'](t(0x1d5),'resize'),H=x['join'](k,b+'.jpg');try{return await readFile(H);}catch(B){if(B[t(0x1d6)]!=='ENOENT')throw B;}if(!await J['file']['exists'](K))throw new NotFoundError(t(0x1d7));const F=await J['file'][t(0x1d8)](K),y=await fileTypeFromBuffer(F);if(!y?.['mime'][t(0x1d9)]('image/'))throw new ValidationError(t(0x1da));const r=await q(F)[t(0x1db)]({'width':Z,'height':Y,'fit':C[t(0x1dc)]??'cover'})['toBuffer']();return await mkdir(k,{'recursive':!![]}),await writeFile(H,r),r;}function parseDimension(C,J){if(C===undefined||C==='')return undefined;const K=Number(C);if(!Number['isInteger'](K)||K<=0x0)throw new ValidationError(J+'\x20must\x20be\x20a\x20positive\x20integer');return K;}
@@ -1 +1 @@
1
- function S(d,h){d=d-0x170;const p=v();let Z=p[d];return Z;}import{fileTypeFromBuffer}from'file-type';import d from'../mime.js';function v(){const B=['metadata','path','resource','has','mimetype','\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','pop','user','rows'];v=function(){return B;};return v();}import{randomUUID}from'node:crypto';export async function uploadFile(h,p){const F=S,Z=(h['metadata']['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),D=new Date(),u=String(D['getFullYear']())['slice'](-0x2),n=String(D['getMonth']()+0x1)['padStart'](0x2,'0'),X=String(D['getDate']())['padStart'](0x2,'0'),Y=h[F(0x170)][F(0x171)]??(h[F(0x170)]['resource']?h['metadata'][F(0x172)]+'/'+(h['metadata']['resourceId']??randomUUID())+'/'+Z:null)??'uploads/'+u+'/'+n+'-'+X+'/'+Z,w=await h['file']['toBuffer'](),y=await fileTypeFromBuffer(w);if(!d[F(0x173)](h['file'][F(0x174)])&&(y?.['mime']?!d['has'](y['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+h['file'][F(0x174)]);await p['file']['put'](Y,w);const Q=await p['pg']['query'](F(0x175),[h['metadata']['resource']??null,h['metadata']['resourceId']??null,Y,h['file'][F(0x174)],h['file']['file']['bytesRead'],h['metadata']['name'],Z,h['file'][F(0x174)]['split']('/')[F(0x176)]()??null,h[F(0x177)]?.['id']??null]);return Q[F(0x178)][0x0];}
1
+ import{fileTypeFromBuffer}from'file-type';import x from'../mime.js';function g(){const B=['replace','getFullYear','padStart','path','resource','metadata','mimetype','mime','put','file','pop'];g=function(){return B;};return g();}function A(x,q){x=x-0x9b;const C=g();let J=C[x];return J;}import{randomUUID}from'node:crypto';export async function uploadFile(q,C){const r=A,J=(q['metadata']['name']??randomUUID())[r(0x9b)](/[^a-zA-Z0-9._-]/g,'_'),K=new Date(),Z=String(K[r(0x9c)]())['slice'](-0x2),Y=String(K['getMonth']()+0x1)[r(0x9d)](0x2,'0'),b=String(K['getDate']())['padStart'](0x2,'0'),k=q['metadata'][r(0x9e)]??(q['metadata'][r(0x9f)]?q['metadata'][r(0x9f)]+'/'+(q[r(0xa0)]['resourceId']??randomUUID())+'/'+J:null)??'uploads/'+Z+'/'+Y+'-'+b+'/'+J,H=await q['file']['toBuffer'](),F=await fileTypeFromBuffer(H);if(!x['has'](q['file'][r(0xa1)])&&(F?.[r(0xa2)]?!x['has'](F[r(0xa2)]):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+q['file']['mimetype']);await C['file'][r(0xa3)](k,H);const y=await C['pg']['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',[q['metadata']['resource']??null,q[r(0xa0)]['resourceId']??null,k,q['file']['mimetype'],q['file'][r(0xa4)]['bytesRead'],q[r(0xa0)]['name'],J,q['file']['mimetype']['split']('/')[r(0xa5)]()??null,q['user']?.['id']??null]);return y['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';function S(d,h){d=d-0xbc;const p=v();let Z=p[d];return Z;}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';function v(){const Y=['get','/api/resource/:resource/search','resource','user','fcore','Suggest\x20resource\x20values','suggestQuery','query','params','/api/resource/:resource/export','resourceId','delete','/api/resource/:resource/:id','uploadResourceFile','file',':update','/api/resource/:resource/:id/:relation','post','Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','resourceIdRelationId'];v=function(){return Y;};return v();}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';import{suggestResource}from'./services/suggest-resource.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=d=>d['user'];export function resourceRoutes(d){return async h=>{const n=S;h[n(0xbc)](n(0xbd),{'schema':{'tags':['fcore',n(0xbe)],'summary':'Search\x20resource','description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':n(0xbf),'permissions':[],'params':resourceSchemas[n(0xbe)]}},async p=>searchResource({...p['query'],...p['params'],'user':user(p)},d)),h['get']('/api/suggest/:resource/:field',{'schema':{'tags':[n(0xc0),'resource'],'summary':n(0xc1),'description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':'user','permissions':[],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas[n(0xc2)]}},async p=>suggestResource({...p[n(0xc3)],...p[n(0xc4)],'user':user(p)},d)),h['get'](n(0xc5),{'schema':{'tags':[n(0xc0),'resource'],'summary':'Export\x20resource\x20records','description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':n(0xbf),'permissions':['*:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas['exportResourceQuery']}},async p=>exportResource({...p['query'],...p['params'],'user':user(p)},d)),h['get']('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas['resource']}},async p=>listResources({...p[n(0xc3)],...p[n(0xc4)],'user':user(p)},d)),h['post']('/api/resource/:resource',{'schema':{'tags':[n(0xc0),'resource'],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas['resource']}},async p=>createResource({...p['params'],'data':p['body'],'user':user(p)},d)),h[n(0xbc)]('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':n(0xbf),'permissions':[],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async p=>getResource({...p['query'],...p['params'],'user':user(p)},d)),h['put']('/api/resource/:resource/:id',{'schema':{'tags':[n(0xc0),n(0xbe)],'summary':'Update\x20resource\x20record','description':'Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas[n(0xc6)]}},async p=>updateResource({...p['params'],'patch':p['body'],'user':user(p)},d)),h[n(0xc7)](n(0xc8),{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20record','description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':n(0xbf),'permissions':[],'params':resourceSchemas['resourceId']}},async p=>deleteResource({...p['params'],'user':user(p)},d)),h['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':['fcore','resource'],'summary':'Upload\x20resource\x20file','description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':[],'params':resourceSchemas[n(0xc9)]}},async p=>{const X=n,Z=await p[X(0xca)]();if(!Z)throw new Error('File\x20is\x20required');const D=p[X(0xc4)][X(0xbe)],u=p[X(0xc4)]['id'];if(p[X(0xbf)]?.['type']!=='admin'&&!p['user']?.['permissions']['includes'](D+X(0xcb)))throw new ForbiddenError('Missing\x20permission:\x20'+D+':update');return uploadFile({'file':Z,'metadata':{'name':Z['filename'],'path':Z['fields']['path']?.['value'],'resource':D,'resourceId':u},'user':p[X(0xbf)]},d);}),h['get'](n(0xcc),{'schema':{'tags':[n(0xc0),'resource'],'summary':'List\x20resource\x20relations','description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':'user','permissions':[],'schema':{'params':resourceSchemas['resourceIdRelation']}}},async p=>listResourceRelation({...p['query'],...p['params'],'user':user(p)},d)),h[n(0xcd)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore','resource'],'summary':'Create\x20resource\x20relation','description':n(0xce),'access':'user','permissions':[],'params':resourceSchemas['resourceIdRelation']}},async p=>createResourceRelation({...p['params'],'data':p['body'],'user':user(p)},d)),h['delete']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore',n(0xbe)],'summary':'Delete\x20resource\x20relation','description':'Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','access':'user','permissions':[],'params':resourceSchemas[n(0xcf)]}},async p=>deleteResourceRelation({...p['params'],'user':user(p)},d)),h['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[n(0xc0),n(0xbe)],'summary':'Update\x20resource\x20relation','description':'Updates\x20a\x20related\x20resource\x20record.','access':'user','permissions':[],'params':resourceSchemas['resourceIdRelationId']}},async p=>updateResourceRelation({...p['params'],'data':p['body'],'user':user(p)},d));};}
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';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 A(x,q){x=x-0x16b;const C=g();let J=C[x];return J;}function g(){const k=['fcore','Search\x20resource','resource','suggestQuery','query','params','get','Returns\x20records\x20from\x20a\x20registered\x20resource.','body','resourceIncludeQuery','Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','user','resourceId','Upload\x20resource\x20file','permissions','includes','fields','path','value','List\x20resource\x20relations','resourceIdRelation','delete','/api/resource/:resource/:id/:relation/:relationId','Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','resourceIdRelationId'];g=function(){return k;};return g();}import{suggestResource}from'./services/suggest-resource.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=x=>x['user'];export function resourceRoutes(x){return async q=>{const Y=A;q['get']('/api/resource/:resource/search',{'schema':{'tags':[Y(0x16b),'resource'],'summary':Y(0x16c),'description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas['resource']}},async C=>searchResource({...C['query'],...C['params'],'user':user(C)},x)),q['get']('/api/suggest/:resource/:field',{'schema':{'tags':[Y(0x16b),Y(0x16d)],'summary':'Suggest\x20resource\x20values','description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':'user','permissions':[],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas[Y(0x16e)]}},async C=>suggestResource({...C[Y(0x16f)],...C[Y(0x170)],'user':user(C)},x)),q[Y(0x171)]('/api/resource/:resource/export',{'schema':{'tags':['fcore','resource'],'summary':'Export\x20resource\x20records','description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['*:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas['exportResourceQuery']}},async C=>exportResource({...C['query'],...C['params'],'user':user(C)},x)),q['get']('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20records','description':Y(0x172),'access':'user','permissions':[],'params':resourceSchemas['resource']}},async C=>listResources({...C['query'],...C['params'],'user':user(C)},x)),q['post']('/api/resource/:resource',{'schema':{'tags':['fcore',Y(0x16d)],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas['resource']}},async C=>createResource({...C['params'],'data':C[Y(0x173)],'user':user(C)},x)),q['get']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas[Y(0x174)]}},async C=>getResource({...C[Y(0x16f)],...C[Y(0x170)],'user':user(C)},x)),q['put']('/api/resource/:resource/:id',{'schema':{'tags':['fcore',Y(0x16d)],'summary':'Update\x20resource\x20record','description':Y(0x175),'access':Y(0x176),'permissions':[],'params':resourceSchemas[Y(0x177)]}},async C=>updateResource({...C['params'],'patch':C['body'],'user':user(C)},x)),q['delete']('/api/resource/:resource/:id',{'schema':{'tags':[Y(0x16b),'resource'],'summary':'Delete\x20resource\x20record','description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':Y(0x176),'permissions':[],'params':resourceSchemas['resourceId']}},async C=>deleteResource({...C['params'],'user':user(C)},x)),q['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':['fcore','resource'],'summary':Y(0x178),'description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':[],'params':resourceSchemas['uploadResourceFile']}},async C=>{const b=Y,J=await C['file']();if(!J)throw new Error('File\x20is\x20required');const K=C['params']['resource'],Z=C['params']['id'];if(C['user']?.['type']!=='admin'&&!C[b(0x176)]?.[b(0x179)][b(0x17a)](K+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+K+':update');return uploadFile({'file':J,'metadata':{'name':J['filename'],'path':J[b(0x17b)][b(0x17c)]?.[b(0x17d)],'resource':K,'resourceId':Z},'user':C['user']},x);}),q['get']('/api/resource/:resource/:id/:relation',{'schema':{'tags':[Y(0x16b),Y(0x16d)],'summary':Y(0x17e),'description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':'user','permissions':[],'schema':{'params':resourceSchemas['resourceIdRelation']}}},async C=>listResourceRelation({...C['query'],...C['params'],'user':user(C)},x)),q['post']('/api/resource/:resource/:id/:relation',{'schema':{'tags':[Y(0x16b),Y(0x16d)],'summary':'Create\x20resource\x20relation','description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':'user','permissions':[],'params':resourceSchemas[Y(0x17f)]}},async C=>createResourceRelation({...C[Y(0x170)],'data':C[Y(0x173)],'user':user(C)},x)),q[Y(0x180)](Y(0x181),{'schema':{'tags':['fcore',Y(0x16d)],'summary':'Delete\x20resource\x20relation','description':Y(0x182),'access':Y(0x176),'permissions':[],'params':resourceSchemas[Y(0x183)]}},async C=>deleteResourceRelation({...C[Y(0x170)],'user':user(C)},x)),q['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[Y(0x16b),'resource'],'summary':'Update\x20resource\x20relation','description':'Updates\x20a\x20related\x20resource\x20record.','access':'user','permissions':[],'params':resourceSchemas[Y(0x183)]}},async C=>updateResourceRelation({...C[Y(0x170)],'data':C['body'],'user':user(C)},x));};}
@@ -1 +1 @@
1
- const d=S;import{Type}from'@sinclair/typebox';function S(d,h){d=d-0x13b;const p=v();let Z=p[d];return Z;}export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type[d(0x13b)]({'resource':identifier}),'exportResource':Type['Object']({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type[d(0x13c)](Type[d(0x13d)]()),'search':Type[d(0x13c)](Type[d(0x13d)]()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type[d(0x13b)]({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type['Object']({'include':Type['Optional'](Type['String']({'minLength':0x1}))}),'resourceIdRelation':Type[d(0x13b)]({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'uploadResourceFile':Type[d(0x13b)]({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type['Optional'](Type['Record'](Type[d(0x13d)](),Type[d(0x13e)]())),'sort':Type['Optional'](Type['Array'](Type['String']({'minLength':0x1}))),'search':Type['Optional'](Type[d(0x13d)]()),'limit':Type['Optional'](Type[d(0x13f)]({'minimum':0x1,'maximum':0xc8})),'offset':Type[d(0x13c)](Type[d(0x13f)]({'minimum':0x0})),'fields':Type['Optional'](Type['Array'](identifier))})};function v(){const h=['Object','Optional','String','Unknown','Integer'];v=function(){return h;};return v();}
1
+ const x=A;import{Type}from'@sinclair/typebox';function g(){const q=['String','Object','Record','Unknown','Optional','Array'];g=function(){return q;};return g();}export const identifier=Type[x(0x77)]({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});function A(x,q){x=x-0x77;const C=g();let J=C[x];return J;}export const resourceSchemas={'dictionaryName':Type['Object']({'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['Optional'](Type[x(0x77)]()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type['Object']({'include':Type['Optional'](Type['String']({'minLength':0x1}))}),'resourceIdRelation':Type[x(0x78)]({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'uploadResourceFile':Type['Object']({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type[x(0x78)]({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type['Optional'](Type[x(0x79)](Type['String'](),Type[x(0x7a)]())),'sort':Type[x(0x7b)](Type[x(0x7c)](Type['String']({'minLength':0x1}))),'search':Type['Optional'](Type['String']()),'limit':Type[x(0x7b)](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type['Integer']({'minimum':0x0})),'fields':Type['Optional'](Type['Array'](identifier))})};
@@ -1 +1 @@
1
- function S(d,h){d=d-0x167;const p=v();let Z=p[d];return Z;}function v(){const D=['resource'];v=function(){return D;};return v();}export async function addNote(d,h){const Z=S,p=await h['pg']['query']('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[d[Z(0x167)],String(d['id']),d['body']]);return p['rows'][0x0];}
1
+ function A(x,q){x=x-0xa3;const C=g();let J=C[x];return J;}export async function addNote(x,q){const J=A,C=await q['pg'][J(0xa3)](J(0xa4),[x[J(0xa5)],String(x['id']),x['body']]);return C['rows'][0x0];}function g(){const K=['query','INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*','resource'];g=function(){return K;};return g();}
@@ -1 +1 @@
1
- function v(){const D=['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','size'];v=function(){return D;};return v();}function S(d,h){d=d-0x180;const p=v();let Z=p[d];return Z;}export async function addResourceFile(d,h){const Z=S,p=await h['pg'][Z(0x180)](Z(0x181),[d['resource'],String(d['id']),d['filePath'],d[Z(0x182)]??null]);return p['rows'][0x0];}
1
+ function A(x,q){x=x-0x1ad;const C=g();let J=C[x];return J;}function g(){const K=['size'];g=function(){return K;};return g();}export async function addResourceFile(x,q){const J=A,C=await q['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',[x['resource'],String(x['id']),x['filePath'],x[J(0x1ad)]??null]);return C['rows'][0x0];}
@@ -1 +1 @@
1
- export async function createResourceRelation(d,h){const {resource:p,id:Z,relation:D,data:u,user:n}=d;return h['resource']['createRelation']({'name':p,'id':Z,'relation':D,'data':u,'user':n});}
1
+ export async function createResourceRelation(x,q){const {resource:C,id:J,relation:K,data:Z,user:Y}=x;return q['resource']['createRelation']({'name':C,'id':J,'relation':K,'data':Z,'user':Y});}
@@ -1 +1 @@
1
- function v(){var Z=['create','data'];v=function(){return Z;};return v();}function S(d,h){d=d-0x6e;var p=v();var Z=p[d];return Z;}export async function createResource(d,h){var p=S;return h['resource'][p(0x6e)]({'name':d['resource'],'data':d[p(0x6f)],'user':d['user']});}
1
+ export async function createResource(x,q){var C=A;return q['resource']['create']({'name':x[C(0xd8)],'data':x['data'],'user':x['user']});}function A(x,q){x=x-0xd8;var C=g();var J=C[x];return J;}function g(){var J=['resource'];g=function(){return J;};return g();}
@@ -1 +1 @@
1
- export async function deleteResourceRelation(d,h){const {resource:p,id:Z,relation:D,relationId:u}=d;return h['resource']['deleteRelation']({'name':p,'id':Z,'relation':D,'relationId':u});}
1
+ function g(){const b=['resource'];g=function(){return b;};return g();}function A(x,q){x=x-0x8e;const C=g();let J=C[x];return J;}export async function deleteResourceRelation(x,q){const Y=A,{resource:C,id:J,relation:K,relationId:Z}=x;return q[Y(0x8e)]['deleteRelation']({'name':C,'id':J,'relation':K,'relationId':Z});}
@@ -1 +1 @@
1
- export async function deleteResource(d,h){var p=S;return h[p(0x159)]['delete']({'name':d['resource'],'id':d['id'],'user':d['user']});}function S(d,h){d=d-0x159;var p=v();var Z=p[d];return Z;}function v(){var Z=['resource'];v=function(){return Z;};return v();}
1
+ export async function deleteResource(x,q){return q['resource']['delete']({'name':x['resource'],'id':x['id'],'user':x['user']});}
@@ -1 +1 @@
1
- function S(d,h){d=d-0x1b6;const p=v();let Z=p[d];return Z;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function exportResource(d,h){const Z=S,p=await h['resource']['find']({'name':d['resource'],'query':{'filter':parseFilterQuery(d),'sort':d['sort'],'search':d[Z(0x1b6)],'limit':d['limit'],'offset':d[Z(0x1b7)],'fields':d['fields']},'user':d['user']});return p['rows'];}function v(){const D=['search','offset'];v=function(){return D;};return v();}
1
+ function A(x,q){x=x-0x17f;const C=g();let J=C[x];return J;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function g(){const K=['resource','fields'];g=function(){return K;};return g();}export async function exportResource(x,q){const J=A,C=await q[J(0x17f)]['find']({'name':x['resource'],'query':{'filter':parseFilterQuery(x),'sort':x['sort'],'search':x['search'],'limit':x['limit'],'offset':x['offset'],'fields':x[J(0x180)]},'user':x['user']});return C['rows'];}
@@ -1 +1 @@
1
- function S(d,h){d=d-0xd0;var p=v();var Z=p[d];return Z;}export async function getResource(d,h){var p=S;return h['resource']['findOne']({'name':d[p(0xd0)],'id':d['id'],'query':{'include':d[p(0xd1)]},'user':d['user']});}function v(){var Z=['resource','include'];v=function(){return Z;};return v();}
1
+ export async function getResource(x,q){return q['resource']['findOne']({'name':x['resource'],'id':x['id'],'query':{'include':x['include']},'user':x['user']});}
@@ -1 +1 @@
1
- export async function listResourceRelation(d,h){const {resource:p,id:Z,relation:D,query:u,user:n}=d;return h['resource']['findRelation']({'name':p,'id':Z,'relation':D,'query':u,'user':n});}
1
+ export async function listResourceRelation(x,q){const {resource:C,id:J,relation:K,query:Z,user:Y}=x;return q['resource']['findRelation']({'name':C,'id':J,'relation':K,'query':Z,'user':Y});}
@@ -1 +1 @@
1
- function v(){var Z=['find','resource','sort','search','page','max'];v=function(){return Z;};return v();}function S(d,h){d=d-0x16b;var p=v();var Z=p[d];return Z;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function listResources(d,h){var p=S;return h['resource'][p(0x16b)]({'name':d[p(0x16c)],'query':{'filter':parseFilterQuery(d),'sort':d[p(0x16d)],'search':d[p(0x16e)],'limit':d['limit'],'offset':d['offset']??(d[p(0x16f)]?Math[p(0x170)](d['page']-0x1,0x0):0x0)*(d['limit']??0x14)},'user':d['user']});}
1
+ import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function A(x,q){x=x-0xcc;var C=g();var J=C[x];return J;}export async function listResources(x,q){var C=A;return q[C(0xcc)]['find']({'name':x[C(0xcc)],'query':{'filter':parseFilterQuery(x),'sort':x['sort'],'search':x[C(0xcd)],'limit':x['limit'],'offset':x['offset']??(x['page']?Math['max'](x[C(0xce)]-0x1,0x0):0x0)*(x['limit']??0x14)},'user':x[C(0xcf)]});}function g(){var J=['resource','search','page','user'];g=function(){return J;};return g();}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(d,h){return h['resource']['find']({'name':d['resource'],'query':{...d,'filter':parseFilterQuery(d)},'user':d['user']});}
1
+ import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(x,q){return q['resource']['find']({'name':x['resource'],'query':{...x,'filter':parseFilterQuery(x)},'user':x['user']});}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';function S(d,h){d=d-0x93;const p=v();let Z=p[d];return Z;}function v(){const s=['toLowerCase','fields','dictionary','name','SELECT\x20','\x20as\x20id,\x20','field','get','slice','now'];v=function(){return s;};return v();}export async function suggestResource(d,h){const g=S,p=h['resource']['get'](d['resource']),Z=String(d['search']??d['q']??'')[g(0x93)](),D=Math['min'](Math['max'](Number(d['limit']??0x14),0x1),0xc8),u=Date['now'](),n=p[g(0x94)][d['field']],X=n?.[g(0x95)],Y=n?.['lookup']?.['table'];if(Y){const Q=n['lookup']?.['text']??g(0x96),F=n['lookup']?.['value']??'id';autoIndex(Y,Q,'text',h['pg']);const B=await h['pg']['query'](g(0x97)+F+g(0x98)+Q+'\x20as\x20text\x20FROM\x20'+Y+'\x20WHERE\x20lower('+Q+')\x20~\x20$1\x20LIMIT\x20$2',[''+Z[g(0x93)](),D])['then'](K=>K['rows']);return{'limit':D,'count':B['length'],'search':Z,'time':Date['now']()-u,'data':B};}if(!X)throw new ValidationError('Field\x20has\x20no\x20lookup\x20dictionary:\x20'+d[g(0x99)]);const w=await h[g(0x95)][g(0x9a)](X),y=w['filter'](K=>!Z||K['code']['startsWith'](Z)||K[g(0x96)]['startsWith'](Z))[g(0x9b)](0x0,D)['map'](K=>({'id':K['code']||K['id'],'text':K['name']||K['text']}));return{'search':Z,'limit':D,'count':y['length'],'time':Date[g(0x9c)]()-u,'data':y};}
1
+ import{ValidationError}from'../../../errors.js';import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';function A(x,q){x=x-0xc9;const C=g();let J=C[x];return J;}export async function suggestResource(x,q){const p=A,C=q[p(0xc9)]['get'](x['resource']),J=String(x['search']??x['q']??'')['toLowerCase'](),K=Math['min'](Math['max'](Number(x['limit']??0x14),0x1),0xc8),Z=Date['now'](),Y=C['fields'][x['field']],b=Y?.[p(0xca)],k=Y?.['lookup']?.['table'];if(k){const y=Y[p(0xcb)]?.['text']??'name',r=Y['lookup']?.[p(0xcc)]??'id';autoIndex(k,y,p(0xcd),q['pg']);const B=await q['pg'][p(0xce)](p(0xcf)+r+'\x20as\x20id,\x20'+y+'\x20as\x20text\x20FROM\x20'+k+'\x20WHERE\x20lower('+y+p(0xd0),[''+J['toLowerCase'](),K])[p(0xd1)](t=>t['rows']);return{'limit':K,'count':B[p(0xd2)],'search':J,'time':Date['now']()-Z,'data':B};}if(!b)throw new ValidationError('Field\x20has\x20no\x20lookup\x20dictionary:\x20'+x['field']);const H=await q['dictionary']['get'](b),F=H['filter'](t=>!J||t['code']['startsWith'](J)||t['name']['startsWith'](J))['slice'](0x0,K)[p(0xd3)](t=>({'id':t['code']||t['id'],'text':t['name']||t['text']}));return{'search':J,'limit':K,'count':F[p(0xd2)],'time':Date['now']()-Z,'data':F};}function g(){const w=['resource','dictionary','lookup','value','text','query','SELECT\x20',')\x20~\x20$1\x20LIMIT\x20$2','then','length','map'];g=function(){return w;};return g();}
@@ -1 +1 @@
1
- function S(d,h){d=d-0x15d;const p=v();let Z=p[d];return Z;}export async function updateResourceRelation(d,h){const Y=S,{resource:p,id:Z,relation:D,relationId:u,data:n,user:X}=d;return h[Y(0x15d)]['updateRelation']({'name':p,'id':Z,'relation':D,'relationId':u,'data':n,'user':X});}function v(){const w=['resource'];v=function(){return w;};return v();}
1
+ function g(){const H=['resource','updateRelation'];g=function(){return H;};return g();}function A(x,q){x=x-0x111;const C=g();let J=C[x];return J;}export async function updateResourceRelation(x,q){const k=A,{resource:C,id:J,relation:K,relationId:Z,data:Y,user:b}=x;return q[k(0x111)][k(0x112)]({'name':C,'id':J,'relation':K,'relationId':Z,'data':Y,'user':b});}
@@ -1 +1 @@
1
- export async function updateResource(d,h){return h['resource']['update']({'name':d['resource'],'id':d['id'],'data':d['patch'],'user':d['user']});}
1
+ function A(x,q){x=x-0x1e2;var C=g();var J=C[x];return J;}function g(){var J=['resource','update','patch'];g=function(){return J;};return g();}export async function updateResource(x,q){var C=A;return q[C(0x1e2)][C(0x1e3)]({'name':x[C(0x1e2)],'id':x['id'],'data':x[C(0x1e4)],'user':x['user']});}
@@ -1 +1 @@
1
- function S(d,h){d=d-0x111;const p=v();let Z=p[d];return Z;}import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';export async function uploadResourceFile(d,h){const n=S,p=h['resource'][n(0x111)](d['resource']);if(p['access']==='admin'&&d['user']?.[n(0x112)]!==n(0x113))throw new ForbiddenError(n(0x114));if(d['user']?.['type']!=='admin'&&!d['user']?.['permissions']?.['includes']((p['permission']??p['name'])+':update'))throw new ForbiddenError(n(0x115)+(p['permission']??p['name'])+':update');if(!Buffer['isBuffer'](d['file'])||d['file']['length']===0x0)throw new ValidationError('File\x20is\x20required');const Z=d['fileName']['replace'](/[^A-Za-z0-9._-]/g,'_');if(!Z)throw new ValidationError('File\x20name\x20is\x20required');const D='files/'+d[n(0x116)]+'/'+String(d['id'])+'/'+Z;await h['file']['put'](D,d[n(0x117)]);if(!await h['file']['exists'](D))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const u=await h['pg']['query'](n(0x118),[d[n(0x116)],String(d['id']),D,d['file']['length']]);return u['rows'][0x0];}function v(){const X=['get','type','admin','Admin\x20access\x20required','Missing\x20permission:\x20','resource','file','\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'];v=function(){return X;};return v();}
1
+ function g(){const b=['admin','user','Admin\x20access\x20required','permissions','includes',':update','Missing\x20permission:\x20','permission','isBuffer','put','exists','length'];g=function(){return b;};return g();}function A(x,q){x=x-0xbf;const C=g();let J=C[x];return J;}import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';export async function uploadResourceFile(x,q){const Y=A,C=q['resource']['get'](x['resource']);if(C['access']===Y(0xbf)&&x[Y(0xc0)]?.['type']!=='admin')throw new ForbiddenError(Y(0xc1));if(x['user']?.['type']!==Y(0xbf)&&!x['user']?.[Y(0xc2)]?.[Y(0xc3)]((C['permission']??C['name'])+Y(0xc4)))throw new ForbiddenError(Y(0xc5)+(C[Y(0xc6)]??C['name'])+Y(0xc4));if(!Buffer[Y(0xc7)](x['file'])||x['file']['length']===0x0)throw new ValidationError('File\x20is\x20required');const J=x['fileName']['replace'](/[^A-Za-z0-9._-]/g,'_');if(!J)throw new ValidationError('File\x20name\x20is\x20required');const K='files/'+x['resource']+'/'+String(x['id'])+'/'+J;await q['file'][Y(0xc8)](K,x['file']);if(!await q['file'][Y(0xc9)](K))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const Z=await q['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',[x['resource'],String(x['id']),K,x['file'][Y(0xca)]]);return Z['rows'][0x0];}