@opengis/fcore 0.0.1-beta.21 → 0.0.1-beta.23

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 (98) 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.js +1 -1
  5. package/dist/fcore.js +1 -1
  6. package/dist/migrations/cli.js +1 -1
  7. package/dist/migrations/runner.js +1 -1
  8. package/dist/modules/auth/adduser-cli.js +1 -1
  9. package/dist/modules/auth/passwd-cli.js +1 -1
  10. package/dist/modules/auth/permission-cli.js +1 -1
  11. package/dist/modules/auth/route.js +1 -1
  12. package/dist/modules/auth/schema.js +1 -1
  13. package/dist/modules/auth/services/change-password.js +1 -1
  14. package/dist/modules/auth/services/get-current-user.js +1 -1
  15. package/dist/modules/auth/services/registration.js +1 -1
  16. package/dist/modules/auth/services/verify-two-factor.js +1 -1
  17. package/dist/modules/file/mime.js +1 -1
  18. package/dist/modules/file/route.js +1 -1
  19. package/dist/modules/file/schema.js +1 -1
  20. package/dist/modules/file/services/get-file.js +1 -1
  21. package/dist/modules/file/services/resize-file.js +1 -1
  22. package/dist/modules/file/services/upload-file.js +1 -1
  23. package/dist/modules/resource/route.js +1 -1
  24. package/dist/modules/resource/schema.js +1 -1
  25. package/dist/modules/resource/services/add-note.js +1 -1
  26. package/dist/modules/resource/services/add-resource-file.js +1 -1
  27. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  28. package/dist/modules/resource/services/create-resource.js +1 -1
  29. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  30. package/dist/modules/resource/services/delete-resource.js +1 -1
  31. package/dist/modules/resource/services/export-resource.js +1 -1
  32. package/dist/modules/resource/services/get-resource.js +1 -1
  33. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  34. package/dist/modules/resource/services/list-resources.js +1 -1
  35. package/dist/modules/resource/services/search-resource.js +1 -1
  36. package/dist/modules/resource/services/suggest-resource.js +1 -1
  37. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  38. package/dist/modules/resource/services/update-resource.js +1 -1
  39. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  40. package/dist/modules/system/route.js +1 -1
  41. package/dist/modules/system/schema.js +1 -1
  42. package/dist/modules/system/services/check-system.js +1 -1
  43. package/dist/modules/system/services/get-access.js +1 -1
  44. package/dist/modules/system/services/get-api-list.js +1 -1
  45. package/dist/modules/system/services/get-audit-log.d.ts.map +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 +1 -0
  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.js +1 -1
  77. package/dist/plugins/resource/services/create.js +1 -1
  78. package/dist/plugins/resource/services/delete-relation.js +1 -1
  79. package/dist/plugins/resource/services/delete.js +1 -1
  80. package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
  81. package/dist/plugins/resource/services/find-one.js +1 -1
  82. package/dist/plugins/resource/services/find-relation.js +1 -1
  83. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  84. package/dist/plugins/resource/services/find.js +1 -1
  85. package/dist/plugins/resource/services/get-table-columns.d.ts +8 -0
  86. package/dist/plugins/resource/services/get-table-columns.d.ts.map +1 -0
  87. package/dist/plugins/resource/services/get-table-columns.js +1 -0
  88. package/dist/plugins/resource/services/update-relation.js +1 -1
  89. package/dist/plugins/resource/services/update.js +1 -1
  90. package/dist/plugins/resource/utils/auto-index.js +1 -1
  91. package/dist/plugins/resource/utils/fields.js +1 -1
  92. package/dist/plugins/resource/utils/filters.js +1 -1
  93. package/dist/plugins/resource/utils/permissions.js +1 -1
  94. package/dist/plugins/resource/utils/sort.js +1 -1
  95. package/dist/plugins/resource/utils/sql.js +1 -1
  96. package/dist/shared/getIP.js +1 -1
  97. package/migrations/20260903120000_core_schema.sql +1 -1
  98. package/package.json +1 -1
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- import'dotenv/config';function r(n,k){n=n-0x1b3;const Z=g();let K=Z[n];return K;}function g(){const d=['false','password','split','map','us-east-1','session_user_auth','0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','true','logger'];g=function(){return d;};return g();}const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(n){const k=process.env[n];if(!k)throw new Error('Missing\x20environment\x20variable:\x20'+n);return k;}export function loadConfig(n={}){const K=r,k={'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(0x1b3),'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||K(0x1b4))[K(0x1b5)](','),'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'](',')[K(0x1b6)](Z=>Z-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+'/log'},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??K(0x1b7),'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(0x1b8),'jwtSecret':process.env.AUTH_JWT_SECRET??K(0x1b9),'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','strict','none']['includes'](process.env.AUTH_COOKIE_OPTIONS_SAME_SITE)?process.env.AUTH_COOKIE_OPTIONS_SAME_SITE:Boolean(process.env.AUTH_COOKIE_OPTIONS_SAME_SITE||K(0x1ba))}:{'path':'/','httpOnly':!![],'secure':![],'sameSite':!![]}}};return{...k,...n,'logger':{...k[K(0x1bb)],...n['logger']},'pg':{...k['pg'],...n['pg']},'redis':{...k['redis'],...n['redis']},'s3':{...k['s3'],...n['s3']},'auth':{...k['auth'],...n['auth']}};}export{required as requireEnv};
1
+ import'dotenv/config';function S(i,n){i=i-0xce;const x=v();let N=x[i];return N;}const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(i){const n=process.env[i];if(!n)throw new Error('Missing\x20environment\x20variable:\x20'+i);return n;}export function loadConfig(i={}){const N=S,n={'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==='false','max':+(process.env.RATE_LIMIT_MAX||0x64),'timeWindow':+(process.env.RATE_LIMIT_TIME_WINDOW||0xea60)},'storagePath':process.env.STORAGE_PATH??'./storage','redactionList':(process.env.REDACTION_LIST||'password')['split'](','),'logger':{'level':process.env.LOG_LEVEL??N(0xce),'responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES[N(0xcf)](',')[N(0xd0)](x=>x-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process[N(0xd1)]()+N(0xd2)},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??N(0xd3),'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[N(0xd4)](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??'x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','cookieName':process.env.AUTH_COOKIE_NAME??'session_user_auth','jwtSecret':process.env.AUTH_JWT_SECRET??'0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','redirect':process.env.AUTH_REDIRECT??'/','twoFactorRedirect':process.env.AUTH_TWOFACTOR_REDIRECT??'/','cookieOptions':process.env.AUTH_COOKIE_OPTIONS_DOMAIN?{'domain':process.env.AUTH_COOKIE_OPTIONS_DOMAIN,'path':process.env.AUTH_COOKIE_OPTIONS_PATH||'/','httpOnly':Boolean(process.env.AUTH_COOKIE_OPTIONS_HTTP_ONLY||N(0xd5)),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'true'),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&[N(0xd6),'strict','none'][N(0xd7)](process.env.AUTH_COOKIE_OPTIONS_SAME_SITE)?process.env.AUTH_COOKIE_OPTIONS_SAME_SITE:Boolean(process.env.AUTH_COOKIE_OPTIONS_SAME_SITE||'true')}:{'path':'/','httpOnly':!![],'secure':![],'sameSite':!![]}}};return{...n,...i,'logger':{...n[N(0xd8)],...i['logger']},'pg':{...n['pg'],...i['pg']},'redis':{...n['redis'],...i['redis']},'s3':{...n['s3'],...i['s3']},'auth':{...n[N(0xd9)],...i['auth']}};}function v(){const a=['info','split','map','cwd','/log','us-east-1','parse','true','lax','includes','logger','auth'];v=function(){return a;};return v();}export{required as requireEnv};
package/dist/context.js CHANGED
@@ -1 +1 @@
1
- let defaultContext;function g(){const K=['Application\x20context\x20is\x20not\x20initialized','end','logger'];g=function(){return K;};return g();}export function setContext(n){defaultContext=n;}export function getContext(){const k=r;if(!defaultContext)throw new Error(k(0x1e3));return defaultContext;}function r(n,k){n=n-0x1e3;const Z=g();let K=Z[n];return K;}export function createContext(n){return{...n,async 'close'(){const Z=r;await Promise['allSettled']([n['redis']?.['close'](),n['pg']?.[Z(0x1e4)]()]),await n[Z(0x1e5)]['close']();}};}
1
+ let defaultContext;export function setContext(i){defaultContext=i;}function S(i,n){i=i-0x199;const x=v();let N=x[i];return N;}export function getContext(){const n=S;if(!defaultContext)throw new Error(n(0x199));return defaultContext;}function v(){const N=['Application\x20context\x20is\x20not\x20initialized','redis','close'];v=function(){return N;};return v();}export function createContext(i){return{...i,async 'close'(){const x=S;await Promise['allSettled']([i[x(0x19a)]?.[x(0x19b)](),i['pg']?.['end']()]),await i['logger']['close']();}};}
package/dist/errors.js CHANGED
@@ -1 +1 @@
1
- var J=r;export class FCoreError extends Error{['code'];['statusCode'];['details'];constructor(n,k,Z=0x1f4,K){var d=r;super(k),this['code']=n,this['statusCode']=Z,this[d(0x1b8)]=K,this['name']=new.target.name;}}function r(n,k){n=n-0x1b8;var Z=g();var K=Z[n];return K;}export class BadRequestError extends FCoreError{constructor(n,k){super('BAD_REQUEST_ERROR',n,0x190,k);}}export class UnauthorizedError extends FCoreError{constructor(n='Authentication\x20required'){super('UNAUTHORIZED',n,0x191);}}export class ForbiddenError extends FCoreError{constructor(n=J(0x1b9)){super('FORBIDDEN',n,0x193);}}export class NotFoundError extends FCoreError{constructor(n=J(0x1ba)){super('NOT_FOUND',n,0x194);}}export class ConflictError extends FCoreError{constructor(n='Conflict'){super('CONFLICT',n,0x199);}}function g(){var l=['details','Access\x20denied','Not\x20found','Operation\x20is\x20not\x20configured','UNSUPPORTED'];g=function(){return l;};return g();}export class ValidationError extends FCoreError{constructor(n,k){super('VALIDATION_ERROR',n,0x1a6,k);}}export class UnsupportedError extends FCoreError{constructor(n=J(0x1bb)){var B=J;super(B(0x1bc),n,0x1f5);}}
1
+ var a=S;function v(){var A=['code','UNAUTHORIZED','FORBIDDEN','NOT_FOUND','UNSUPPORTED'];v=function(){return A;};return v();}export class FCoreError extends Error{[a(0x12a)];['statusCode'];['details'];constructor(i,n,x=0x1f4,N){super(n),this['code']=i,this['statusCode']=x,this['details']=N,this['name']=new.target.name;}}export class BadRequestError extends FCoreError{constructor(i,n){super('BAD_REQUEST_ERROR',i,0x190,n);}}export class UnauthorizedError extends FCoreError{constructor(i='Authentication\x20required'){var B=a;super(B(0x12b),i,0x191);}}export class ForbiddenError extends FCoreError{constructor(i='Access\x20denied'){var q=a;super(q(0x12c),i,0x193);}}export class NotFoundError extends FCoreError{constructor(i='Not\x20found'){var X=a;super(X(0x12d),i,0x194);}}export class ConflictError extends FCoreError{constructor(i='Conflict'){super('CONFLICT',i,0x199);}}export class ValidationError extends FCoreError{constructor(i,n){super('VALIDATION_ERROR',i,0x1a6,n);}}function S(i,n){i=i-0x12a;var x=v();var N=x[i];return N;}export class UnsupportedError extends FCoreError{constructor(i='Operation\x20is\x20not\x20configured'){var f=a;super(f(0x12e),i,0x1f5);}}
package/dist/fastify.js CHANGED
@@ -1 +1 @@
1
- import n from'fastify-plugin';import{FCoreError}from'./errors.js';import{authRoutes}from'./modules/auth/route.js';import{fileRoutes}from'./modules/file/route.js';import{resourceRoutes}from'./modules/resource/route.js';import{systemRoutes}from'./modules/system/route.js';import{createSessionStore}from'./plugins/auth/index.js';function r(n,k){n=n-0xc0;const Z=g();let K=Z[n];return K;}import{ForbiddenError}from'./errors.js';import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(k,Z,K){const d=decodeURIComponent(Z['toString']())['split']('&')['reduce']((J,B)=>{const [l,f]=B['split']('=');return{...J,[l]:f};},{});K(null,d);}export default function fcoreFastify(k,Z){return n(async K=>{const O=r;K['decorate']('ctx',k);const {config:d}=k,J=new Map();K[O(0xc0)]('onRoute',l=>{const m=O,f=l['schema'],R=Array['isArray'](l['method'])?l['method']:[l['method']];for(const Q of R){if(Q==='HEAD')continue;const a={'method':Q,'endpoint':l['url'],'package':f?.['package']??m(0xc1),'tags':f?.['tags']??[],'summary':f?.['summary']??'','description':f?.['description']??'','access':f?.[m(0xc2)]??m(0xc3),'permissions':f?.['permissions']??[]};J['set'](Q+'\x20'+l['url'],a);}}),K['addHook']('preHandler',async l=>{const p=O;if(l['routeOptions']['url']==='*')return!![];const f=J['get'](l[p(0xc4)]+'\x20'+l['routeOptions']['url']),R=!l['user']&&process[p(0xc5)]==='win32'&&k['config']?.[p(0xc6)]?.['user']?k['config']?.['auth']?.['user']:null,Q=l['raw']['headers']?.['authorization'],a=Q?.['startsWith']('Bearer\x20')?Q['slice'](0x7):null,H=l['user']??(a?await jwtVerifyToken(a):R);!l['user']&&a&&process.env.AUTH_JWT_SECRET&&(l['user']=await jwtVerifyToken(a));if(!f?.['access'])throw new Error(p(0xc7));if(f['access']===p(0xc3))return!![];if(!H)throw new ForbiddenError(p(0xc8));if(f['access']==='user'&&!f['permissions']?.['length'])return!![];if(H['type']=='admin')return!![];if(f[p(0xc2)]==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const A of f[p(0xc9)]){const I=A?.[p(0xca)]('$resource',l['params']['resource']??'');if(!H['permissions']?.['includes'](I))throw new ForbiddenError('Missing\x20permission:\x20'+I);}return!![];}),await createSessionStore(K,k),await K['register'](import('@fastify/multipart'),{'limits':{'fileSize':d['maxFileSize']*0x400*0x400}}),K[O(0xcb)]((l,f,R)=>{const C=O;if(l instanceof FCoreError||l['code']===C(0xcc)||l[C(0xcd)]<0x1f4)return l[C(0xcd)]<0x1f4&&k['logger']['warn'](l),R['code'](l['statusCode'])['send']({'error':l[C(0xce)],'message':l[C(0xcf)],'details':l[C(0xd0)]});return k['logger']['error'](l),(d['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console['error'](l),R[C(0xce)](0x1f4)['send']({'error':'INTERNAL_ERROR','message':C(0xd1)});});const B=l=>!Z||Z[O(0xd2)](l);if(B('auth'))await K['register'](authRoutes(k));if(B('resource'))await K['register'](resourceRoutes(k));if(B('file'))await K[O(0xd3)](fileRoutes(k));if(B('system'))await K['register'](systemRoutes(k,J));K[O(0xd4)]('application/x-www-form-urlencoded',{'parseAs':'buffer'},urlencodedContentParser),!d['rateLimit']?.[O(0xd5)]?K['register'](import(O(0xd6)),{'max':d['rateLimit']?.['max']||0x64,'timeWindow':d[O(0xd7)]?.['timeWindow']||0xea60,'hook':O(0xd8),'global':!![],'keyGenerator':l=>(l['user']?.['id']||l['ip'])+'-'+l['raw']['url'][O(0xd9)]('?')[0x0]}):console['log']('⚠️\x20rate\x20limit\x20is\x20disabled');});}function g(){const T=['addHook','fcore','access','public','method','platform','auth','Route\x20access\x20not\x20defined','User\x20required','permissions','replace','setErrorHandler','FST_ERR_VALIDATION','statusCode','code','message','details','Internal\x20server\x20error','includes','register','addContentTypeParser','disabled','@fastify/rate-limit','rateLimit','preHandler','split'];g=function(){return T;};return g();}
1
+ import i from'fastify-plugin';import{FCoreError}from'./errors.js';import{authRoutes}from'./modules/auth/route.js';import{fileRoutes}from'./modules/file/route.js';import{resourceRoutes}from'./modules/resource/route.js';import{systemRoutes}from'./modules/system/route.js';function S(i,n){i=i-0x14f;const x=v();let N=x[i];return N;}import{createSessionStore}from'./plugins/auth/index.js';import{ForbiddenError}from'./errors.js';import{jwtVerifyToken}from'./plugins/jwt.js';function v(){const m=['toString','decorate','addHook','method','package','fcore','summary','access','url','preHandler','routeOptions','user','win32','config','authorization','permissions','replace','params','Missing\x20permission:\x20','register','FST_ERR_VALIDATION','send','code','details','test','auth','application/x-www-form-urlencoded','disabled','max','split','⚠️\x20rate\x20limit\x20is\x20disabled'];v=function(){return m;};return v();}function urlencodedContentParser(n,x,N){const z=S,a=decodeURIComponent(x[z(0x14f)]())['split']('&')['reduce']((B,q)=>{const [X,f]=q['split']('=');return{...B,[X]:f};},{});N(null,a);}export default function fcoreFastify(n,x){return i(async N=>{const J=S;N[J(0x150)]('ctx',n);const {config:a}=n,B=new Map();N[J(0x151)]('onRoute',X=>{const p=J,f=X['schema'],A=Array['isArray'](X[p(0x152)])?X['method']:[X['method']];for(const u of A){if(u==='HEAD')continue;const V={'method':u,'endpoint':X['url'],'package':f?.[p(0x153)]??p(0x154),'tags':f?.['tags']??[],'summary':f?.[p(0x155)]??'','description':f?.['description']??'','access':f?.[p(0x156)]??'public','permissions':f?.['permissions']??[]};B['set'](u+'\x20'+X[p(0x157)],V);}}),N['addHook'](J(0x158),async X=>{const h=J;if(X[h(0x159)]['url']==='*')return!![];const f=B['get'](X[h(0x152)]+'\x20'+X['routeOptions']['url']),A=!X[h(0x15a)]&&process['platform']===h(0x15b)&&n[h(0x15c)]?.['auth']?.['user']?n[h(0x15c)]?.['auth']?.[h(0x15a)]:null,u=X['raw']['headers']?.[h(0x15d)],V=u?.['startsWith']('Bearer\x20')?u['slice'](0x7):null,M=X['user']??(V?await jwtVerifyToken(V):A);!X[h(0x15a)]&&V&&process.env.AUTH_JWT_SECRET&&(X['user']=await jwtVerifyToken(V));if(!f?.['access'])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(f['access']==='public')return!![];if(!M)throw new ForbiddenError('User\x20required');if(f[h(0x156)]==='user'&&!f[h(0x15e)]?.['length'])return!![];if(M['type']=='admin')return!![];if(f['access']==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const U of f['permissions']){const t=U?.[h(0x15f)]('$resource',X[h(0x160)]['resource']??'');if(!M['permissions']?.['includes'](t))throw new ForbiddenError(h(0x161)+t);}return!![];}),await createSessionStore(N,n),await N[J(0x162)](import('@fastify/multipart'),{'limits':{'fileSize':a['maxFileSize']*0x400*0x400}}),N['setErrorHandler']((X,f,A)=>{const O=J;if(X instanceof FCoreError||X['code']===O(0x163)||X['statusCode']<0x1f4)return X['statusCode']<0x1f4&&n['logger']['warn'](X),A['code'](X['statusCode'])[O(0x164)]({'error':X[O(0x165)],'message':X['message'],'details':X[O(0x166)]});return n['logger']['error'](X),(a['debug']||process.env.NODE_ENV===O(0x167)||process.env.VITEST)&&console['error'](X),A[O(0x165)](0x1f4)['send']({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const q=X=>!x||x['includes'](X);if(q(J(0x168)))await N['register'](authRoutes(n));if(q('resource'))await N['register'](resourceRoutes(n));if(q('file'))await N[J(0x162)](fileRoutes(n));if(q('system'))await N['register'](systemRoutes(n,B));N['addContentTypeParser'](J(0x169),{'parseAs':'buffer'},urlencodedContentParser),!a['rateLimit']?.[J(0x16a)]?N['register'](import('@fastify/rate-limit'),{'max':a['rateLimit']?.[J(0x16b)]||0x64,'timeWindow':a['rateLimit']?.['timeWindow']||0xea60,'hook':'preHandler','global':!![],'keyGenerator':X=>(X['user']?.['id']||X['ip'])+'-'+X['raw'][J(0x157)][J(0x16c)]('?')[0x0]}):console['log'](J(0x16d));});}
package/dist/fcore.js CHANGED
@@ -1 +1 @@
1
- import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function g(){const a=['accessKey','secretKey','tokenSecret','tokenTtl','resources'];g=function(){return a;};return g();}import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function r(n,k){n=n-0x1d7;const Z=g();let K=Z[n];return K;}export async function createFCore(n={}){const Q=r,k=loadConfig(n['config']),Z=createRedis(k['redis']),K=createLogger(),d=createDatabase(k['pg']),J=createFileS3({'endpoint':k['s3']['endpoint'],'region':k['s3']['region'],'bucket':k['s3']['bucket'],'accessKey':k['s3'][Q(0x1d7)],'secretKey':k['s3'][Q(0x1d8)],'folder':k['s3']['folder'],'forcePathStyle':k['s3']['forcePathStyle'],'tokenSecret':k['s3'][Q(0x1d9)],'tokenTtl':k['s3'][Q(0x1da)]}),B=createAudit({'pg':d,'logger':K}),l=createDictionary({'pg':d,'dictionaries':n['dictionaries']}),f=createResource({'pg':d,'logger':K,'audit':B,'dictionary':l,'file':J});n['resources']?.['length']&&f['register'](n[Q(0x1db)]);const R=createContext({'config':k,'logger':K,'redis':Z,'pg':d,'file':J,'resource':f,'audit':B,'dictionary':l});return setContext(R),R;}
1
+ import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function v(){const V=['secretKey','folder','resources','register'];v=function(){return V;};return v();}function S(i,n){i=i-0x1ee;const x=v();let N=x[i];return N;}import{createAudit,createDatabase,createDictionary,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';export async function createFCore(i={}){const u=S,n=loadConfig(i['config']),x=createRedis(n['redis']),N=createLogger(),a=createDatabase(n['pg']),B=createFileS3({'endpoint':n['s3']['endpoint'],'region':n['s3']['region'],'bucket':n['s3']['bucket'],'accessKey':n['s3']['accessKey'],'secretKey':n['s3'][u(0x1ee)],'folder':n['s3'][u(0x1ef)],'forcePathStyle':n['s3']['forcePathStyle'],'tokenSecret':n['s3']['tokenSecret'],'tokenTtl':n['s3']['tokenTtl']}),q=createAudit({'pg':a,'logger':N}),X=createDictionary({'pg':a,'dictionaries':i['dictionaries']}),f=createResource({'pg':a,'logger':N,'audit':q,'dictionary':X,'file':B});i[u(0x1f0)]?.['length']&&f[u(0x1f1)](i[u(0x1f0)]);const A=createContext({'config':n,'logger':N,'redis':x,'pg':a,'file':B,'resource':f,'audit':q,'dictionary':X});return setContext(A),A;}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const R=n;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';function g(){const Q=['--fcore','startsWith','****','log','run'];g=function(){return Q;};return g();}import k from'node:path';function n(r,k){r=r-0x14f;const Z=g();let K=Z[r];return K;}import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL('../../migrations',import.meta.url));function migrationDirectory(Z){const f=n,K=Z['indexOf']('--dir');if(K>=0x0){const J=Z[K+0x1];if(!J)throw new Error('--dir\x20requires\x20a\x20folder\x20path');return k['resolve'](J);}if(Z['includes'](f(0x14f)))return packageMigrations;const d=Z['find'](B=>!B[f(0x150)]('--'));return k['resolve'](d??'migrations');}try{const config=loadConfig(),dir=migrationDirectory(process['argv']['slice'](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':R(0x151),'password':R(0x151)}),console['log']('Using\x20migration\x20directory:',dir,process['argv']['slice'](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console[R(0x152)]((r['status']===R(0x153)?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(l){console['error'](l),process['exitCode']=0x1;}
2
+ function S(i,n){i=i-0xf3;const x=v();let N=x[i];return N;}const f=S;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';function v(){const A=['--dir','--dir\x20requires\x20a\x20folder\x20path','startsWith','****','log','slice','run','OK\x20\x20','SKIP','file'];v=function(){return A;};return v();}import i from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL('../../migrations',import.meta.url));function migrationDirectory(n){const X=S,x=n['indexOf'](X(0xf3));if(x>=0x0){const a=n[x+0x1];if(!a)throw new Error(X(0xf4));return i['resolve'](a);}if(n['includes']('--fcore'))return packageMigrations;const N=n['find'](B=>!B[X(0xf5)]('--'));return i['resolve'](N??'migrations');}try{const config=loadConfig(),dir=migrationDirectory(process['argv']['slice'](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':f(0xf6),'password':'****'}),console[f(0xf7)]('Using\x20migration\x20directory:',dir,process['argv'][f(0xf8)](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console['log']((r['status']===f(0xf9)?f(0xfa):f(0xfb))+'\x20'+r[f(0xfc)]);}catch(q){console['error'](q),process['exitCode']=0x1;}
@@ -1 +1 @@
1
- function g(){const m=['migrations','databaseUrl','query','filter','.sql','skip','readFile','connect','ROLLBACK','push','run','pathname','slice'];g=function(){return m;};return g();}import n from'node:fs/promises';import k from'node:path';import{createDatabase}from'../plugins/pg.js';function r(n,k){n=n-0x19b;const Z=g();let K=Z[n];return K;}export async function runMigrations(Z={}){const I=r,K=k['resolve'](Z['dir']??I(0x19b)),d=Z['database']??databaseFromUrl(Z[I(0x19c)]??process.env.DATABASE_URL);if(!d)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const J=createDatabase(d);if(!J)throw new Error('empty\x20pg');const B=[];try{await J[I(0x19d)]('\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 l=await J['query']('SELECT\x20version\x20FROM\x20schema_migrations'),f=new Set(l['rows']['map'](Q=>Q['version'])),R=(await n['readdir'](K))[I(0x19e)](Q=>Q['endsWith'](I(0x19f)))['sort']();for(const Q of R){if(f['has'](Q)){B['push']({'file':Q,'status':I(0x1a0)});continue;}const a=await n[I(0x1a1)](k['join'](K,Q),'utf8'),H=await J[I(0x1a2)]();try{await H[I(0x19d)]('BEGIN'),await H[I(0x19d)](a),await H['query']('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[Q]),await H[I(0x19d)]('COMMIT');}catch(A){await H[I(0x19d)](I(0x1a3));throw A;}finally{H['release']();}B[I(0x1a4)]({'file':Q,'status':I(0x1a5)});}return B;}finally{await J['end']();}}function databaseFromUrl(Z){const O=r;if(!Z)return undefined;const K=new URL(Z);return{'host':K['hostname'],'port':Number(K['port']||0x1538),'database':K[O(0x1a6)][O(0x1a7)](0x1),'user':decodeURIComponent(K['username']),'password':decodeURIComponent(K['password'])};}
1
+ function S(i,n){i=i-0x134;const x=v();let N=x[i];return N;}import i from'node:fs/promises';import n from'node:path';import{createDatabase}from'../plugins/pg.js';export async function runMigrations(x={}){const t=S,N=n[t(0x134)](x['dir']??t(0x135)),a=x[t(0x136)]??databaseFromUrl(x['databaseUrl']??process.env.DATABASE_URL);if(!a)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const B=createDatabase(a);if(!B)throw new Error('empty\x20pg');const q=[];try{await B['query']('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const X=await B['query']('SELECT\x20version\x20FROM\x20schema_migrations'),f=new Set(X['rows']['map'](u=>u['version'])),A=(await i['readdir'](N))[t(0x137)](u=>u['endsWith'](t(0x138)))[t(0x139)]();for(const u of A){if(f[t(0x13a)](u)){q[t(0x13b)]({'file':u,'status':t(0x13c)});continue;}const V=await i[t(0x13d)](n['join'](N,u),'utf8'),M=await B['connect']();try{await M['query']('BEGIN'),await M['query'](V),await M['query'](t(0x13e),[u]),await M['query']('COMMIT');}catch(U){await M[t(0x13f)]('ROLLBACK');throw U;}finally{M['release']();}q[t(0x13b)]({'file':u,'status':t(0x140)});}return q;}finally{await B['end']();}}function v(){const J=['resolve','migrations','database','filter','.sql','sort','has','push','skip','readFile','INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)','query','run','hostname','username','password'];v=function(){return J;};return v();}function databaseFromUrl(x){const z=S;if(!x)return undefined;const N=new URL(x);return{'host':N[z(0x141)],'port':Number(N['port']||0x1538),'database':N['pathname']['slice'](0x1),'user':decodeURIComponent(N[z(0x142)]),'password':decodeURIComponent(N[z(0x143)])};}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const Z=r;import{loadConfig}from'../../config.js';function g(){const K=['argv','exitCode','end'];g=function(){return K;};return g();}import{createDatabase}from'../../plugins/pg.js';import n from'./services/registration.js';const [user,password,type]=process[Z(0xab)]['slice'](0x2);function r(n,k){n=n-0xab;const Z=g();let K=Z[n];return K;}if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await n({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(k){console['error'](k),process[Z(0xac)]=0x1;}finally{await pg[Z(0xad)]();}}
2
+ const x=S;function v(){const N=['exitCode','log'];v=function(){return N;};return v();}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import i from'./services/registration.js';const [user,password,type]=process['argv']['slice'](0x2);function S(i,n){i=i-0x8b;const x=v();let N=x[i];return N;}if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process[x(0x8b)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await i({'user':user,'password':password,'type':type},{'pg':pg});console[x(0x8c)]('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(n){console['error'](n),process['exitCode']=0x1;}finally{await pg['end']();}}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const Z=r;function g(){const K=['exitCode','SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201','rows','User\x20not\x20found','end'];g=function(){return K;};return g();}import{loadConfig}from'../../config.js';function r(n,k){n=n-0x128;const Z=g();let K=Z[n];return K;}import{createDatabase}from'../../plugins/pg.js';import n 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[Z(0x128)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query'](Z(0x129),[login]),user=result[Z(0x12a)][0x0];if(!user)throw new Error(Z(0x12b));await n({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(k){console['error'](k),process['exitCode']=0x1;}finally{await pg[Z(0x12c)]();}}
2
+ const x=S;import{loadConfig}from'../../config.js';function v(){const N=['argv','exitCode','rows','Password\x20changed\x20for\x20','error'];v=function(){return N;};return v();}function S(i,n){i=i-0xb7;const x=v();let N=x[i];return N;}import{createDatabase}from'../../plugins/pg.js';import i from'./services/change-password.js';const [login,password]=process[x(0xb7)]['slice'](0x2);if(!login||!password)console['error']('Usage:\x20fcore-password\x20<login>\x20<password>'),process[x(0xb8)]=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[x(0xb9)][0x0];if(!user)throw new Error('User\x20not\x20found');await i({'userId':user['id'],'password':password},{'pg':pg}),console['log'](x(0xba)+login);}catch(n){console[x(0xbb)](n),process['exitCode']=0x1;}finally{await pg['end']();}}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function g(){const Q=['list','argv','map','filter','add','system','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','User\x20not\x20found','query','push','set','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','actions','log','error'];g=function(){return Q;};return g();}const f=r;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function r(n,k){n=n-0xe9;const Z=g();let K=Z[n];return K;}const SYSTEM_ACTIONS=['logs','audit',f(0xe9),'check','access','settings','dictionaries'],RESOURCE_ACTIONS=['read','update','create','delete'],[login,permissionArg]=process[f(0xea)]['slice'](0x2);function expandPermissions(n){const R=f,k=n['split'](',')[R(0xeb)](K=>K['trim']())[R(0xec)](Boolean),Z=new Set();for(const K of k){if(K['includes'](':')){Z[R(0xed)](K);continue;}const d=K===R(0xee)?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const J of d){Z[R(0xed)](K+':'+J);}}return[...Z];}if(!login||!permissionArg)console['error'](f(0xef)),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(f(0xf0));if(permissionArg['trim']()==='clear')await pg[f(0xf1)]('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[f(0xf2)](action),byResource[f(0xf3)](resource,actions);}const client=await pg['connect']();try{await client[f(0xf1)]('BEGIN');for(const [resource,actions]of byResource){const existing=await client['query'](f(0xf4),[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row[f(0xf5)]??[],...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[f(0xf1)]('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(B){await client['query']('ROLLBACK');throw B;}finally{client['release']();}console[f(0xf6)]('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions['join'](',\x20'));}}catch(l){console[f(0xf7)](l),process['exitCode']=0x1;}finally{await pg['end']();}}
2
+ const f=S;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=[f(0x1ca),'audit','list','check',f(0x1cb),f(0x1cc),'dictionaries'],RESOURCE_ACTIONS=['read','update','create','delete'],[login,permissionArg]=process[f(0x1cd)]['slice'](0x2);function S(i,n){i=i-0x1ca;const x=v();let N=x[i];return N;}function v(){const u=['logs','access','settings','argv','includes','add','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','rows','User\x20not\x20found','query','log','split','set','BEGIN','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','Granted\x20permissions\x20for\x20','join','end'];v=function(){return u;};return v();}function expandPermissions(i){const A=f,n=i['split'](',')['map'](N=>N['trim']())['filter'](Boolean),x=new Set();for(const N of n){if(N[A(0x1ce)](':')){x['add'](N);continue;}const a=N==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const B of a){x[A(0x1cf)](N+':'+B);}}return[...x];}if(!login||!permissionArg)console['error'](f(0x1d0)),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[f(0x1d1)][0x0];if(!user)throw new Error(f(0x1d2));if(permissionArg['trim']()==='clear')await pg[f(0x1d3)]('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console[f(0x1d4)]('Permissions\x20cleared\x20for\x20'+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission[f(0x1d5)](':'),actions=byResource['get'](resource)??[];actions['push'](action),byResource[f(0x1d6)](resource,actions);}const client=await pg['connect']();try{await client['query'](f(0x1d7));for(const [resource,actions]of byResource){const existing=await client['query']('SELECT\x20access_id,\x20actions\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL\x20AND\x20resource\x20=\x20$2',[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client['query'](f(0x1d8),[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(q){await client['query']('ROLLBACK');throw q;}finally{client['release']();}console['log'](f(0x1d9)+login+':\x20'+permissions[f(0x1da)](',\x20'));}}catch(X){console['error'](X),process['exitCode']=0x1;}finally{await pg[f(0x1db)]();}}
@@ -1 +1 @@
1
- import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import n from'./services/get-current-user.js';import k from'./services/registration.js';function r(n,k){n=n-0x105;const Z=g();let K=Z[n];return K;}import Z from'./services/change-password.js';import{authSchemas}from'./schema.js';function g(){const p=['method','query','body','auth','session','cookie','audit','type','permissions','Sign\x20in','/api/auth/login','public','credentials','/api/auth/registration','fcore','Register','admin','post','password','user','write','sessionId','config','cookieName','Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','token'];g=function(){return p;};return g();}import K from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(d){return async J=>{const I=r,B=async l=>{const A=r,f=l[A(0x105)]==='GET'?l[A(0x106)]:l[A(0x107)],R=K(l),Q=await verifyUser({...f,'ip':R},d);Q['permissions']=await getUserPermissions(Q['id'],d);const a=Q['twofa']?d['config']['auth']['twoFactorRedirect']:d['config'][A(0x108)]['redirect'];await l['login'](Q);const H=d['config'][A(0x108)]['sessionTimeout']*0x3e8*0x3c;return l[A(0x109)]?.['cookie']&&(l['session'][A(0x10a)]['maxAge']=H),await l['session']['save'](),await d[A(0x10b)]?.['write']?.({'module':A(0x108),'resource':'session','resourceId':l['session']['sessionId'],'action':'login','userId':Q['id'],'ipAddress':R}),{'user':{'id':Q['id'],'type':Q[A(0x10c)],'permissions':Q[A(0x10d)]},'redirectUrl':a};};J['get']('/api/auth/login',{'schema':{'tags':['fcore',I(0x108)],'summary':I(0x10e),'description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'querystring':authSchemas['credentials']}},B),J['post'](I(0x10f),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':I(0x110),'permissions':[],'body':authSchemas[I(0x111)]}},B),J['post'](I(0x112),{'schema':{'tags':[I(0x113),'auth'],'summary':I(0x114),'description':'Creates\x20a\x20regular\x20user\x20account.','access':I(0x115),'permissions':['user:create'],'body':authSchemas['credentials']}},async l=>k(l['body'],d)),J[I(0x116)]('/api/auth/password',{'schema':{'tags':[I(0x113),I(0x108)],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas[I(0x117)]}},async l=>{const O=I;if(!l[O(0x118)])throw new UnauthorizedError('Not\x20authorized');return await Z({'userId':l['user']['id'],...l['body']},d),{'success':!![]};}),J['post']('/api/auth/logout',{'schema':{'tags':[I(0x113),'auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':I(0x118),'permissions':[]}},async(l,f)=>{const m=I,R={'redirectUrl':'/'};if(!l['user'])return R;return await d['audit']?.[m(0x119)]?.({'module':'auth','resource':'session','resourceId':l['session'][m(0x11a)],'action':'logout','userId':l[m(0x118)]?.['id']}),await l[m(0x109)]['destroy'](),f['clearCookie'](d[m(0x11b)]['auth'][m(0x11c)]),Object['defineProperty'](l,'session',{'value':null,'writable':![],'configurable':![]}),R;}),J['get']('/api/auth/user',{'schema':{'tags':['fcore','auth'],'summary':'Get\x20current\x20user','description':I(0x11d),'access':I(0x118),'permissions':[],'querystring':authSchemas['query']}},async l=>n({'user':l['user'],'token':l['query'][I(0x11e)]}));};}
1
+ import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import i from'./services/get-current-user.js';import n from'./services/registration.js';function S(i,n){i=i-0xfb;const x=v();let N=x[i];return N;}import x from'./services/change-password.js';function v(){const p=['GET','config','session','audit','write','sessionId','type','auth','credentials','/api/auth/login','fcore','Creates\x20a\x20regular\x20user\x20account.','admin','user:create','Change\x20password','Changes\x20the\x20password\x20for\x20the\x20current\x20user.','password','user','Not\x20authorized','post','clearCookie','query'];v=function(){return p;};return v();}import{authSchemas}from'./schema.js';import N from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(a){return async B=>{const t=S,q=async X=>{const U=S,f=X['method']===U(0xfb)?X['query']:X['body'],A=N(X),u=await verifyUser({...f,'ip':A},a);u['permissions']=await getUserPermissions(u['id'],a);const V=u['twofa']?a[U(0xfc)]['auth']['twoFactorRedirect']:a['config']['auth']['redirect'];await X['login'](u);const M=a[U(0xfc)]['auth']['sessionTimeout']*0x3e8*0x3c;return X['session']?.['cookie']&&(X['session']['cookie']['maxAge']=M),await X[U(0xfd)]['save'](),await a[U(0xfe)]?.[U(0xff)]?.({'module':'auth','resource':'session','resourceId':X[U(0xfd)][U(0x100)],'action':'login','userId':u['id'],'ipAddress':A}),{'user':{'id':u['id'],'type':u[U(0x101)],'permissions':u['permissions']},'redirectUrl':V};};B['get']('/api/auth/login',{'schema':{'tags':['fcore',t(0x102)],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'querystring':authSchemas[t(0x103)]}},q),B['post'](t(0x104),{'schema':{'tags':['fcore',t(0x102)],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'body':authSchemas['credentials']}},q),B['post']('/api/auth/registration',{'schema':{'tags':[t(0x105),'auth'],'summary':'Register','description':t(0x106),'access':t(0x107),'permissions':[t(0x108)],'body':authSchemas['credentials']}},async X=>n(X['body'],a)),B['post']('/api/auth/password',{'schema':{'tags':[t(0x105),'auth'],'summary':t(0x109),'description':t(0x10a),'access':'user','permissions':[],'body':authSchemas[t(0x10b)]}},async X=>{const z=t;if(!X[z(0x10c)])throw new UnauthorizedError(z(0x10d));return await x({'userId':X['user']['id'],...X['body']},a),{'success':!![]};}),B[t(0x10e)]('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(X,f)=>{const J=t,A={'redirectUrl':'/'};if(!X[J(0x10c)])return A;return await a[J(0xfe)]?.['write']?.({'module':J(0x102),'resource':J(0xfd),'resourceId':X['session'][J(0x100)],'action':'logout','userId':X[J(0x10c)]?.['id']}),await X['session']['destroy'](),f[J(0x10f)](a[J(0xfc)]['auth']['cookieName']),Object['defineProperty'](X,J(0xfd),{'value':null,'writable':![],'configurable':![]}),A;}),B['get']('/api/auth/user',{'schema':{'tags':['fcore','auth'],'summary':'Get\x20current\x20user','description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas[t(0x110)]}},async X=>i({'user':X['user'],'token':X['query']['token']}));};}
@@ -1 +1 @@
1
- function r(n,k){n=n-0xee;const Z=g();let K=Z[n];return K;}const n=r;function g(){const k=['Optional','Object','String'];g=function(){return k;};return g();}import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type[n(0xee)](Type['Boolean']())}),'credentials':Type[n(0xef)]({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type[n(0xf0)]({'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[n(0xf0)]({'minLength':0x1})})};
1
+ function S(i,n){i=i-0x1da;const x=v();let N=x[i];return N;}const i=S;function v(){const n=['Boolean','Object','String'];v=function(){return n;};return v();}import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type[i(0x1da)]())}),'credentials':Type[i(0x1db)]({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type[i(0x1dc)]({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type[i(0x1dc)]({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type[i(0x1dc)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type[i(0x1db)]({'code':Type[i(0x1dc)]({'minLength':0x1})})};
@@ -1 +1 @@
1
- function r(n,k){n=n-0xef;const Z=g();let K=Z[n];return K;}function g(){const B=['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'];g=function(){return B;};return g();}import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:n,password:k,userId:Z},{pg:K}){const J=r,d=await hashPassword(k);await K[J(0xef)](J(0xf0),[d,n||Z,Z]);}
1
+ import{hashPassword}from'../../../plugins/auth/index.js';function v(){const q=['query'];v=function(){return q;};return v();}function S(i,n){i=i-0x81;const x=v();let N=x[i];return N;}export default async function changePassword({id:i,password:n,userId:x},{pg:N}){const B=S,a=await hashPassword(n);await N[B(0x81)]('UPDATE\x20admin.users\x0a\x20\x20\x20\x20\x20SET\x20password_hash\x20=\x20$1,\x20updated_at\x20=\x20now(),\x20updated_by\x20=\x20$3\x0a\x20\x20\x20\x20\x20WHERE\x20uid\x20=\x20$2',[a,i||x,x]);}
@@ -1 +1 @@
1
- import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(n){const J=r,{user:k}=n;if(!k)return{};if(n['token']){const {jwtSignToken:Z}=await import(J(0x1d2)),K=await Z(k);k['token']=K;}return k['resources']=[...new Set(k?.['permissions'][J(0x1d3)](d=>d['split'](':')[0x0]))],safeUser(k);}function r(n,k){n=n-0x1d2;const Z=g();let K=Z[n];return K;}function g(){const B=['../../../plugins/jwt.js','map'];g=function(){return B;};return g();}
1
+ function v(){const q=['map'];v=function(){return q;};return v();}function S(i,n){i=i-0xd9;const x=v();let N=x[i];return N;}import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(i){const B=S,{user:n}=i;if(!n)return{};if(i['token']){const {jwtSignToken:x}=await import('../../../plugins/jwt.js'),N=await x(n);n['token']=N;}return n['resources']=[...new Set(n?.['permissions'][B(0xd9)](a=>a['split'](':')[0x0]))],safeUser(n);}
@@ -1 +1 @@
1
- import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:n,password:k,type:Z},{pg:K}){const d=await hashPassword(k),J=await K['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',[n,d,Z||'regular']),B=J['rows'][0x0];if(!B)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':B};}
1
+ function S(i,n){i=i-0x164;const x=v();let N=x[i];return N;}import{ConflictError}from'../../../errors.js';function v(){const f=['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'];v=function(){return f;};return v();}import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:i,password:n,type:x},{pg:N}){const X=S,a=await hashPassword(n),B=await N['query'](X(0x164),[i,a,x||'regular']),q=B['rows'][0x0];if(!q)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':q};}
@@ -1 +1 @@
1
- import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(n,k){return unsupported('Two-factor\x20provider');}
1
+ import{unsupported}from'../../utils/unsupported.js';function v(){var N=['Two-factor\x20provider'];v=function(){return N;};return v();}function S(i,n){i=i-0x1c9;var x=v();var N=x[i];return N;}export default async function verifyTwoFactor(i,n){var x=S;return unsupported(x(0x1c9));}
@@ -1 +1 @@
1
- var n=r;function r(n,k){n=n-0x10f;var Z=g();var K=Z[n];return K;}export default new Set(['image/jpeg','image/png','image/gif','image/webp','image/bmp','image/tiff','image/svg+xml',n(0x10f),'image/avif',n(0x110),'application/msword',n(0x111),'application/vnd.ms-excel',n(0x112),n(0x113),'application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain',n(0x114),n(0x115),'application/json','application/xml','text/xml',n(0x116),'application/vnd.google-earth.kml+xml',n(0x117),n(0x118),'application/x-zip-compressed','application/x-7z-compressed','application/x-rar-compressed','application/vnd.rar','application/gzip',n(0x119),n(0x11a),'audio/mpeg',n(0x11b),'audio/ogg','audio/webm','audio/mp4',n(0x11c),n(0x11d),'video/webm','video/quicktime',n(0x11e),n(0x11f)]);function g(){var k=['image/x-icon','application/pdf','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-powerpoint','text/csv','text/markdown','application/geo+json','application/vnd.google-earth.kmz','application/zip','application/x-gzip','application/x-tar','audio/wav','video/mp4','video/mpeg','video/x-msvideo','application/octet-stream'];g=function(){return k;};return g();}
1
+ function S(i,n){i=i-0x11b;var x=v();var N=x[i];return N;}function v(){var n=['application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.presentationml.presentation','text/csv','application/xml','application/vnd.google-earth.kmz','application/zip','application/x-rar-compressed','application/vnd.rar','application/gzip','video/mp4','video/x-msvideo'];v=function(){return n;};return v();}var i=S;export default new Set(['image/jpeg','image/png','image/gif','image/webp','image/bmp','image/tiff','image/svg+xml','image/x-icon','image/avif','application/pdf',i(0x11b),i(0x11c),i(0x11d),'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet','application/vnd.ms-powerpoint',i(0x11e),'application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain',i(0x11f),'text/markdown','application/json',i(0x120),'text/xml','application/geo+json','application/vnd.google-earth.kml+xml',i(0x121),i(0x122),'application/x-zip-compressed','application/x-7z-compressed',i(0x123),i(0x124),i(0x125),'application/x-gzip','application/x-tar','audio/mpeg','audio/wav','audio/ogg','audio/webm','audio/mp4',i(0x126),'video/mpeg','video/webm','video/quicktime',i(0x127),'application/octet-stream']);
@@ -1 +1 @@
1
- function r(n,k){n=n-0xde;const Z=g();let K=Z[n];return K;}import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function g(){const O=['/api/file/:token','file','fileToken','application/octet-stream','startsWith','split','type','attachment','inline','header','Cache-Control','post','user','value','resource','resourceId','get'];g=function(){return O;};return g();}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(n){return async k=>{const a=r;k['get'](a(0xde),{'schema':{'tags':['fcore',a(0xdf)],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas[a(0xe0)],'querystring':fileSchemas['fileDownloadQuery']}},async(Z,K)=>{const H=a,d=n['file']['verify'](Z['params']['token']),J=await getFile({'pathOrToken':d},n),B=await fileTypeFromBuffer(J),l=B?.['mime']??H(0xe1),f=Z['query']['download']===!![],R=l[H(0xe2)]('image/')||l==='application/pdf',Q=d[H(0xe3)]('/')['pop']()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??'file';return K[H(0xe4)](l),K['header']('Content-Disposition',(f||!R?H(0xe5):H(0xe6))+';\x20filename=\x22'+Q+'\x22')[H(0xe7)](H(0xe8),'public,\x20max-age=86400,\x20immutable'),K['send'](J);}),k[a(0xe9)]('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':'Upload\x20file','description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':a(0xea),'permissions':['files:create']}},async Z=>{const A=a,K=await Z[A(0xdf)]();if(!K)throw new Error('File\x20is\x20required');return uploadFile({'file':K,'metadata':{'name':K['filename'],'path':K['fields']['path']?.[A(0xeb)],'resource':K['fields'][A(0xec)]?.['value'],'resourceId':K['fields'][A(0xed)]?.['value']},'user':Z['user']},n);}),k[a(0xee)]('/api/file/:token/resize',{'schema':{'tags':['fcore',a(0xdf)],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':['files:read'],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(Z,K)=>{const I=a,d=await resizeFile({'pathOrToken':n[I(0xdf)]?.['verify'](Z['params']['token']),...Z['query']},n),J=await fileTypeFromBuffer(d);return K[I(0xe4)](J?.['mime']??'image/png'),K['header']('Content-Disposition',I(0xe6))['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),K['send'](d);});};}
1
+ function v(){const z=['get','file','mime','startsWith','image/','split','replace','inline','Cache-Control','post','fcore','path','fields','resource','value','user','image/png','send'];v=function(){return z;};return v();}import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function S(i,n){i=i-0xae;const x=v();let N=x[i];return N;}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(i){return async n=>{const V=S;n[V(0xae)]('/api/file/:token',{'schema':{'tags':['fcore',V(0xaf)],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas['fileDownloadQuery']}},async(x,N)=>{const M=V,a=i['file']['verify'](x['params']['token']),B=await getFile({'pathOrToken':a},i),q=await fileTypeFromBuffer(B),X=q?.[M(0xb0)]??'application/octet-stream',f=x['query']['download']===!![],A=X[M(0xb1)](M(0xb2))||X==='application/pdf',u=a[M(0xb3)]('/')['pop']()?.[M(0xb4)](/[^A-Za-z0-9._-]/g,'_')??'file';return N['type'](X),N['header']('Content-Disposition',(f||!A?'attachment':M(0xb5))+';\x20filename=\x22'+u+'\x22')['header'](M(0xb6),'public,\x20max-age=86400,\x20immutable'),N['send'](B);}),n[V(0xb7)]('/api/file/upload',{'schema':{'tags':[V(0xb8),V(0xaf)],'summary':'Upload\x20file','description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async x=>{const U=V,N=await x['file']();if(!N)throw new Error('File\x20is\x20required');return uploadFile({'file':N,'metadata':{'name':N['filename'],'path':N['fields'][U(0xb9)]?.['value'],'resource':N[U(0xba)][U(0xbb)]?.['value'],'resourceId':N['fields']['resourceId']?.[U(0xbc)]},'user':x['user']},i);}),n['get']('/api/file/:token/resize',{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':V(0xbd),'permissions':['files:read'],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(x,N)=>{const t=V,a=await resizeFile({'pathOrToken':i['file']?.['verify'](x['params']['token']),...x['query']},i),B=await fileTypeFromBuffer(a);return N['type'](B?.[t(0xb0)]??t(0xbe)),N['header']('Content-Disposition','inline')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),N[t(0xbf)](a);});};}
@@ -1 +1 @@
1
- const n=r;function r(n,k){n=n-0x1b8;const Z=g();let K=Z[n];return K;}function g(){const k=['String','Optional','Boolean','Object','Any','Integer','Union','Literal'];g=function(){return k;};return g();}import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type['Object']({'id':Type[n(0x1b8)]({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type['String']({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type[n(0x1b9)](Type[n(0x1ba)]())}),'filePath':Type[n(0x1bb)]({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type[n(0x1bc)](),'metadata':Type[n(0x1bb)]({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type[n(0x1b9)](Type[n(0x1b8)]({'minLength':0x1})),'entityId':Type[n(0x1b9)](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type[n(0x1b9)](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type[n(0x1b9)](Type[n(0x1bd)]({'minimum':0x1,'default':0xc8})),'height':Type[n(0x1b9)](Type['Integer']({'minimum':0x1})),'fit':Type[n(0x1b9)](Type[n(0x1be)]([Type['Literal']('cover'),Type['Literal']('contain'),Type[n(0x1bf)]('fill'),Type['Literal']('inside'),Type['Literal']('outside')]))})};
1
+ const i=S;function S(i,n){i=i-0x1e1;const x=v();let N=x[i];return N;}function v(){const n=['Object','String','Optional','Boolean','Literal','cover','fill'];v=function(){return n;};return v();}import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type[i(0x1e1)]({'token':Type[i(0x1e2)]({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type[i(0x1e3)](Type[i(0x1e4)]())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type[i(0x1e3)](Type[i(0x1e2)]({'minLength':0x1})),'entityId':Type[i(0x1e3)](Type[i(0x1e2)]({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type['Optional'](Type[i(0x1e2)]({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type['Optional'](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type['Union']([Type[i(0x1e5)](i(0x1e6)),Type['Literal']('contain'),Type['Literal'](i(0x1e7)),Type['Literal']('inside'),Type['Literal']('outside')]))})};
@@ -1 +1 @@
1
- import{NotFoundError}from'../../../errors.js';function r(n,k){n=n-0x174;var Z=g();var K=Z[n];return K;}function g(){var K=['pathOrToken','file'];g=function(){return K;};return g();}export async function getFile(n,k){var Z=r;if(!k['file'])throw new Error('empty\x20file');if(!await k['file']['exists'](n['pathOrToken']))throw new NotFoundError('File\x20not\x20found'+n[Z(0x174)]);return k[Z(0x175)]['get'](n['pathOrToken']);}
1
+ import{NotFoundError}from'../../../errors.js';function S(i,n){i=i-0x197;var x=v();var N=x[i];return N;}function v(){var N=['empty\x20file','file','pathOrToken'];v=function(){return N;};return v();}export async function getFile(i,n){var x=S;if(!n['file'])throw new Error(x(0x197));if(!await n[x(0x198)]['exists'](i[x(0x199)]))throw new NotFoundError('File\x20not\x20found'+i[x(0x199)]);return n[x(0x198)]['get'](i['pathOrToken']);}
@@ -1 +1 @@
1
- import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';function g(){const O=['path','height','digest','logs','code','ENOENT','file','exists','File\x20not\x20found','get','startsWith'];g=function(){return O;};return g();}import{createHash}from'node:crypto';import{mkdir,readFile,writeFile}from'node:fs/promises';import n from'node:path';import k from'sharp';function r(n,k){n=n-0x168;const Z=g();let K=Z[n];return K;}export async function resizeFile(Z,K){const I=r,d=Z['pathOrToken']??Z[I(0x168)];if(!d)throw new ValidationError('File\x20path\x20is\x20required');const J=parseDimension(Z['width'],'width')??0xc8,B=parseDimension(Z['height'],I(0x169)),l=createHash('sha256')['update'](d+':'+J+':'+(B??'auto')+':'+(Z['fit']??'cover'))[I(0x16a)]('hex'),f=n['resolve'](I(0x16b),'resize'),R=n['join'](f,l+'.jpg');try{return await readFile(R);}catch(A){if(A[I(0x16c)]!==I(0x16d))throw A;}if(!await K[I(0x16e)][I(0x16f)](d))throw new NotFoundError(I(0x170));const Q=await K['file'][I(0x171)](d),a=await fileTypeFromBuffer(Q);if(!a?.['mime'][I(0x172)]('image/'))throw new ValidationError('Only\x20image\x20files\x20can\x20be\x20resized');const H=await k(Q)['resize']({'width':J,'height':B,'fit':Z['fit']??'cover'})['toBuffer']();return await mkdir(f,{'recursive':!![]}),await writeFile(R,H),H;}function parseDimension(Z,K){if(Z===undefined||Z==='')return undefined;const d=Number(Z);if(!Number['isInteger'](d)||d<=0x0)throw new ValidationError(K+'\x20must\x20be\x20a\x20positive\x20integer');return d;}
1
+ import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';import{mkdir,readFile,writeFile}from'node:fs/promises';import i from'node:path';function S(i,n){i=i-0x67;const x=v();let N=x[i];return N;}import n from'sharp';export async function resizeFile(x,N){const t=S,a=x[t(0x67)]??x['path'];if(!a)throw new ValidationError('File\x20path\x20is\x20required');const B=parseDimension(x['width'],'width')??0xc8,q=parseDimension(x[t(0x68)],'height'),X=createHash('sha256')[t(0x69)](a+':'+B+':'+(q??'auto')+':'+(x[t(0x6a)]??'cover'))['digest']('hex'),f=i[t(0x6b)](t(0x6c),t(0x6d)),A=i[t(0x6e)](f,X+'.jpg');try{return await readFile(A);}catch(U){if(U[t(0x6f)]!=='ENOENT')throw U;}if(!await N['file']['exists'](a))throw new NotFoundError('File\x20not\x20found');const u=await N['file']['get'](a),V=await fileTypeFromBuffer(u);if(!V?.['mime']['startsWith']('image/'))throw new ValidationError(t(0x70));const M=await n(u)[t(0x6d)]({'width':B,'height':q,'fit':x['fit']??'cover'})['toBuffer']();return await mkdir(f,{'recursive':!![]}),await writeFile(A,M),M;}function v(){const z=['pathOrToken','height','update','fit','resolve','logs','resize','join','code','Only\x20image\x20files\x20can\x20be\x20resized'];v=function(){return z;};return v();}function parseDimension(x,N){if(x===undefined||x==='')return undefined;const a=Number(x);if(!Number['isInteger'](a)||a<=0x0)throw new ValidationError(N+'\x20must\x20be\x20a\x20positive\x20integer');return a;}
@@ -1 +1 @@
1
- function g(){const A=['name','replace','getMonth','padStart','metadata','resource','resourceId','file','mime','bytesRead','split','pop','user'];g=function(){return A;};return g();}import{fileTypeFromBuffer}from'file-type';function r(n,k){n=n-0x124;const Z=g();let K=Z[n];return K;}import n from'../mime.js';import{randomUUID}from'node:crypto';export async function uploadFile(k,Z){const H=r,K=(k['metadata'][H(0x124)]??randomUUID())[H(0x125)](/[^a-zA-Z0-9._-]/g,'_'),d=new Date(),J=String(d['getFullYear']())['slice'](-0x2),B=String(d[H(0x126)]()+0x1)[H(0x127)](0x2,'0'),l=String(d['getDate']())['padStart'](0x2,'0'),f=k['metadata']['path']??(k[H(0x128)][H(0x129)]?k['metadata']['resource']+'/'+(k[H(0x128)][H(0x12a)]??randomUUID())+'/'+K:null)??'uploads/'+J+'/'+B+'-'+l+'/'+K,R=await k[H(0x12b)]['toBuffer'](),Q=await fileTypeFromBuffer(R);if(!n['has'](k['file']['mimetype'])&&(Q?.[H(0x12c)]?!n['has'](Q[H(0x12c)]):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+k['file']['mimetype']);await Z['file']['put'](f,R);const a=await Z['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',[k[H(0x128)]['resource']??null,k['metadata']['resourceId']??null,f,k[H(0x12b)]['mimetype'],k['file']['file'][H(0x12d)],k[H(0x128)]['name'],K,k[H(0x12b)]['mimetype'][H(0x12e)]('/')[H(0x12f)]()??null,k[H(0x130)]?.['id']??null]);return a['rows'][0x0];}
1
+ import{fileTypeFromBuffer}from'file-type';import i from'../mime.js';import{randomUUID}from'node:crypto';export async function uploadFile(n,x){const M=S,N=(n[M(0x18e)]['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),a=new Date(),B=String(a[M(0x18f)]())['slice'](-0x2),q=String(a[M(0x190)]()+0x1)[M(0x191)](0x2,'0'),X=String(a['getDate']())['padStart'](0x2,'0'),f=n['metadata'][M(0x192)]??(n['metadata']['resource']?n[M(0x18e)][M(0x193)]+'/'+(n['metadata'][M(0x194)]??randomUUID())+'/'+N:null)??'uploads/'+B+'/'+q+'-'+X+'/'+N,A=await n['file'][M(0x195)](),u=await fileTypeFromBuffer(A);if(!i['has'](n[M(0x196)]['mimetype'])&&(u?.[M(0x197)]?!i['has'](u[M(0x197)]):!![]))throw new Error(M(0x198)+n['file'][M(0x199)]);await x['file']['put'](f,A);const V=await x['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',[n[M(0x18e)]['resource']??null,n[M(0x18e)]['resourceId']??null,f,n['file'][M(0x199)],n['file']['file'][M(0x19a)],n['metadata']['name'],N,n[M(0x196)]['mimetype'][M(0x19b)]('/')['pop']()??null,n[M(0x19c)]?.['id']??null]);return V['rows'][0x0];}function S(i,n){i=i-0x18e;const x=v();let N=x[i];return N;}function v(){const U=['metadata','getFullYear','getMonth','padStart','path','resource','resourceId','toBuffer','file','mime','Unsupported\x20file\x20type:\x20','mimetype','bytesRead','split','user'];v=function(){return U;};return v();}
@@ -1 +1 @@
1
- const B=r;import{ForbiddenError}from'../../errors.js';import{listResources}from'./services/list-resources.js';function r(n,k){n=n-0x10e;const Z=g();let K=Z[n];return K;}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';function g(){const R=['user','get','Search\x20resource','resource','query','params','/api/suggest/:resource/:field','Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','resourceField','config','/api/resource/:resource/export','fcore','/api/resource/:resource','auth','post','/api/resource/:resource/:id','Update\x20resource\x20record','resourceId','Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','Upload\x20resource\x20file','permissions','includes',':update','Missing\x20permission:\x20','fields','value','List\x20resource\x20relations','Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','$resource:create','resourceIdRelation','body','/api/resource/:resource/:id/:relation/:relationId','put'];g=function(){return R;};return g();}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=n=>n[B(0x10e)];export function resourceRoutes(n){return async k=>{const l=r;k[l(0x10f)]('/api/resource/:resource/search',{'schema':{'tags':['fcore','resource'],'summary':l(0x110),'description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':l(0x10e),'permissions':['$resource:read'],'params':resourceSchemas[l(0x111)]}},async Z=>searchResource({...Z[l(0x112)],...Z[l(0x113)],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k['get'](l(0x114),{'schema':{'tags':['fcore','resource'],'summary':'Suggest\x20resource\x20values','description':l(0x115),'access':l(0x10e),'permissions':['$resource:read'],'params':resourceSchemas[l(0x116)],'querystring':resourceSchemas['suggestQuery']}},async Z=>suggestResource({...Z['query'],...Z['params'],'user':user(Z)||n[l(0x117)]?.['auth']?.['user']},n)),k['get'](l(0x118),{'schema':{'tags':[l(0x119),l(0x111)],'summary':'Export\x20resource\x20records','description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas['exportResourceQuery']}},async Z=>exportResource({...Z['query'],...Z[l(0x113)],'user':user(Z)||n[l(0x117)]?.['auth']?.['user']},n)),k[l(0x10f)](l(0x11a),{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resource']}},async Z=>listResources({...Z['query'],...Z['params'],'user':user(Z)||n[l(0x117)]?.[l(0x11b)]?.['user']},n)),k[l(0x11c)]('/api/resource/:resource',{'schema':{'tags':[l(0x119),'resource'],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:create'],'params':resourceSchemas['resource']}},async Z=>createResource({...Z[l(0x113)],'data':Z['body'],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k[l(0x10f)]('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async Z=>getResource({...Z['query'],...Z['params'],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k['put'](l(0x11d),{'schema':{'tags':['fcore',l(0x111)],'summary':l(0x11e),'description':'Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':l(0x10e),'permissions':['$resource:update'],'params':resourceSchemas[l(0x11f)]}},async Z=>updateResource({...Z['params'],'patch':Z['body'],'user':user(Z)||n[l(0x117)]?.['auth']?.[l(0x10e)]},n)),k['delete']('/api/resource/:resource/:id',{'schema':{'tags':[l(0x119),'resource'],'summary':'Delete\x20resource\x20record','description':l(0x120),'access':l(0x10e),'permissions':['$resource:delete'],'params':resourceSchemas[l(0x11f)]}},async Z=>deleteResource({...Z[l(0x113)],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':[l(0x119),'resource'],'summary':l(0x121),'description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['uploadResourceFile']}},async Z=>{const f=l,K=await Z['file']();if(!K)throw new Error('File\x20is\x20required');const d=Z['params'][f(0x111)],J=Z['params']['id'];if(Z['user']?.['type']!=='admin'&&!Z['user']?.[f(0x122)][f(0x123)](d+f(0x124)))throw new ForbiddenError(f(0x125)+d+':update');return uploadFile({'file':K,'metadata':{'name':K['filename'],'path':K[f(0x126)]['path']?.[f(0x127)],'resource':d,'resourceId':J},'user':Z['user']},n);}),k[l(0x10f)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore','resource'],'summary':l(0x128),'description':l(0x129),'access':'user','params':resourceSchemas['resourceIdRelation'],'permissions':['$resource:read']}},async Z=>listResourceRelation({...Z[l(0x112)],...Z[l(0x113)],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k['post']('/api/resource/:resource/:id/:relation',{'schema':{'tags':[l(0x119),'resource'],'summary':'Create\x20resource\x20relation','description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':l(0x10e),'permissions':[l(0x12a)],'params':resourceSchemas[l(0x12b)]}},async Z=>createResourceRelation({...Z['params'],'data':Z[l(0x12c)],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k['delete'](l(0x12d),{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20relation','description':'Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','access':'user','permissions':['$resource:delete'],'params':resourceSchemas['resourceIdRelationId']}},async Z=>deleteResourceRelation({...Z['params'],'user':user(Z)||n['config']?.['auth']?.['user']},n)),k[l(0x12e)](l(0x12d),{'schema':{'tags':['fcore',l(0x111)],'summary':'Update\x20resource\x20relation','description':'Updates\x20a\x20related\x20resource\x20record.','access':l(0x10e),'permissions':['$resource:update'],'params':resourceSchemas['resourceIdRelationId']}},async Z=>updateResourceRelation({...Z[l(0x113)],'data':Z['body'],'user':user(Z)||n[l(0x117)]?.['auth']?.[l(0x10e)]},n));};}
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';function S(i,n){i=i-0x1c8;const x=v();let N=x[i];return N;}import{searchResource}from'./services/search-resource.js';import{exportResource}from'./services/export-resource.js';function v(){const f=['resource','Searches\x20records\x20in\x20a\x20registered\x20resource.','user','$resource:read','auth','fcore','Suggest\x20resource\x20values','/api/resource/:resource/export','Export\x20resource\x20records','exportResourceQuery','List\x20resource\x20records','params','/api/resource/:resource','$resource:create','query','config','/api/resource/:resource/:id','Delete\x20resource\x20record','$resource:delete','post','Upload\x20resource\x20file','$resource:update','includes','Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','/api/resource/:resource/:id/:relation','body','delete','Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','Updates\x20a\x20related\x20resource\x20record.','resourceIdRelationId'];v=function(){return f;};return v();}import{suggestResource}from'./services/suggest-resource.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=i=>i['user'];export function resourceRoutes(i){return async n=>{const q=S;n['get']('/api/resource/:resource/search',{'schema':{'tags':['fcore',q(0x1c8)],'summary':'Search\x20resource','description':q(0x1c9),'access':q(0x1ca),'permissions':[q(0x1cb)],'params':resourceSchemas['resource']}},async x=>searchResource({...x['query'],...x['params'],'user':user(x)||i['config']?.[q(0x1cc)]?.[q(0x1ca)]},i)),n['get']('/api/suggest/:resource/:field',{'schema':{'tags':[q(0x1cd),'resource'],'summary':q(0x1ce),'description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':q(0x1ca),'permissions':['$resource:read'],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas['suggestQuery']}},async x=>suggestResource({...x['query'],...x['params'],'user':user(x)||i['config']?.[q(0x1cc)]?.['user']},i)),n['get'](q(0x1cf),{'schema':{'tags':['fcore','resource'],'summary':q(0x1d0),'description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas[q(0x1d1)]}},async x=>exportResource({...x['query'],...x['params'],'user':user(x)||i['config']?.['auth']?.['user']},i)),n['get']('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':q(0x1d2),'description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas[q(0x1c8)]}},async x=>listResources({...x['query'],...x[q(0x1d3)],'user':user(x)||i['config']?.['auth']?.['user']},i)),n['post'](q(0x1d4),{'schema':{'tags':['fcore',q(0x1c8)],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[q(0x1d5)],'params':resourceSchemas[q(0x1c8)]}},async x=>createResource({...x['params'],'data':x['body'],'user':user(x)||i['config']?.['auth']?.['user']},i)),n['get']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async x=>getResource({...x[q(0x1d6)],...x[q(0x1d3)],'user':user(x)||i[q(0x1d7)]?.['auth']?.['user']},i)),n['put']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20record','description':'Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['resourceId']}},async x=>updateResource({...x['params'],'patch':x['body'],'user':user(x)||i[q(0x1d7)]?.['auth']?.['user']},i)),n['delete'](q(0x1d8),{'schema':{'tags':['fcore','resource'],'summary':q(0x1d9),'description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[q(0x1da)],'params':resourceSchemas['resourceId']}},async x=>deleteResource({...x['params'],'user':user(x)||i['config']?.[q(0x1cc)]?.['user']},i)),n[q(0x1db)]('/api/resource/:resource/:id/upload',{'schema':{'tags':['fcore','resource'],'summary':q(0x1dc),'description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':[q(0x1dd)],'params':resourceSchemas['uploadResourceFile']}},async x=>{const X=q,N=await x['file']();if(!N)throw new Error('File\x20is\x20required');const a=x[X(0x1d3)]['resource'],B=x['params']['id'];if(x['user']?.['type']!=='admin'&&!x['user']?.['permissions'][X(0x1de)](a+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+a+':update');return uploadFile({'file':N,'metadata':{'name':N['filename'],'path':N['fields']['path']?.['value'],'resource':a,'resourceId':B},'user':x['user']},i);}),n['get']('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore',q(0x1c8)],'summary':'List\x20resource\x20relations','description':q(0x1df),'access':q(0x1ca),'params':resourceSchemas['resourceIdRelation'],'permissions':['$resource:read']}},async x=>listResourceRelation({...x['query'],...x[q(0x1d3)],'user':user(x)||i['config']?.[q(0x1cc)]?.['user']},i)),n[q(0x1db)](q(0x1e0),{'schema':{'tags':['fcore','resource'],'summary':'Create\x20resource\x20relation','description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':'user','permissions':['$resource:create'],'params':resourceSchemas['resourceIdRelation']}},async x=>createResourceRelation({...x['params'],'data':x[q(0x1e1)],'user':user(x)||i['config']?.['auth']?.[q(0x1ca)]},i)),n[q(0x1e2)]('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[q(0x1cd),q(0x1c8)],'summary':'Delete\x20resource\x20relation','description':q(0x1e3),'access':'user','permissions':['$resource:delete'],'params':resourceSchemas['resourceIdRelationId']}},async x=>deleteResourceRelation({...x['params'],'user':user(x)||i['config']?.['auth']?.[q(0x1ca)]},i)),n['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20relation','description':q(0x1e4),'access':q(0x1ca),'permissions':['$resource:update'],'params':resourceSchemas[q(0x1e5)]}},async x=>updateResourceRelation({...x['params'],'data':x[q(0x1e1)],'user':user(x)||i['config']?.['auth']?.['user']},i));};}
@@ -1 +1 @@
1
- const n=r;import{Type}from'@sinclair/typebox';export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':n(0x145)});export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type[n(0x146)]({'resource':identifier}),'exportResource':Type[n(0x146)]({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type[n(0x146)]({'q':Type['Optional'](Type['String']()),'search':Type[n(0x147)](Type['String']()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type[n(0x146)]({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type['Object']({'include':Type[n(0x147)](Type['String']({'minLength':0x1}))}),'resourceIdRelation':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'uploadResourceFile':Type['Object']({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type[n(0x146)]({'file':Type[n(0x148)](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type['Optional'](Type['Record'](Type[n(0x149)](),Type['Unknown']())),'sort':Type['Optional'](Type[n(0x14a)](Type['String']({'minLength':0x1}))),'search':Type['Optional'](Type['String']()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type['Integer']({'minimum':0x0})),'fields':Type[n(0x147)](Type['Array'](identifier))})};function r(n,k){n=n-0x145;const Z=g();let K=Z[n];return K;}function g(){const k=['^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$','Object','Optional','Any','String','Array'];g=function(){return k;};return g();}
1
+ function S(i,n){i=i-0x1d5;const x=v();let N=x[i];return N;}const i=S;import{Type}from'@sinclair/typebox';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['Object']({'resource':identifier}),'exportResource':Type[i(0x1d5)]({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type[i(0x1d5)]({'q':Type['Optional'](Type[i(0x1d6)]()),'search':Type['Optional'](Type['String']()),'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[i(0x1d5)]({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type[i(0x1d5)]({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'uploadResourceFile':Type['Object']({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type[i(0x1d7)](Type['Record'](Type['String'](),Type[i(0x1d8)]())),'sort':Type['Optional'](Type['Array'](Type['String']({'minLength':0x1}))),'search':Type[i(0x1d7)](Type[i(0x1d6)]()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type[i(0x1d9)]({'minimum':0x0})),'fields':Type['Optional'](Type['Array'](identifier))})};function v(){const n=['Object','String','Optional','Unknown','Integer'];v=function(){return n;};return v();}
@@ -1 +1 @@
1
- function g(){const d=['query','rows'];g=function(){return d;};return g();}function r(n,k){n=n-0x191;const Z=g();let K=Z[n];return K;}export async function addNote(n,k){const K=r,Z=await k['pg'][K(0x191)]('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[n['resource'],String(n['id']),n['body']]);return Z[K(0x192)][0x0];}
1
+ function S(i,n){i=i-0x9e;const x=v();let N=x[i];return N;}export async function addNote(i,n){const N=S,x=await n['pg'][N(0x9e)]('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[i['resource'],String(i['id']),i['body']]);return x['rows'][0x0];}function v(){const a=['query'];v=function(){return a;};return v();}
@@ -1 +1 @@
1
- function r(n,k){n=n-0xf7;const Z=g();let K=Z[n];return K;}function g(){const d=['size'];g=function(){return d;};return g();}export async function addResourceFile(n,k){const K=r,Z=await k['pg']['query']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20size)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20',[n['resource'],String(n['id']),n['filePath'],n[K(0xf7)]??null]);return Z['rows'][0x0];}
1
+ function S(i,n){i=i-0x16f;const x=v();let N=x[i];return N;}export async function addResourceFile(i,n){const N=S,x=await n['pg'][N(0x16f)]('\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',[i['resource'],String(i['id']),i['filePath'],i['size']??null]);return x['rows'][0x0];}function v(){const a=['query'];v=function(){return a;};return v();}
@@ -1 +1 @@
1
- export async function createResourceRelation(n,k){const {resource:Z,id:K,relation:d,data:J,user:B}=n;return k['resource']['createRelation']({'name':Z,'id':K,'relation':d,'data':J,'user':B});}
1
+ function S(i,n){i=i-0x130;const x=v();let N=x[i];return N;}export async function createResourceRelation(i,n){const X=S,{resource:x,id:N,relation:a,data:B,user:q}=i;return n[X(0x130)][X(0x131)]({'name':x,'id':N,'relation':a,'data':B,'user':q});}function v(){const f=['resource','createRelation'];v=function(){return f;};return v();}
@@ -1 +1 @@
1
- export async function createResource(n,k){return k['resource']['create']({'name':n['resource'],'data':n['data'],'user':n['user']});}
1
+ function S(i,n){i=i-0xed;var x=v();var N=x[i];return N;}function v(){var N=['resource','user'];v=function(){return N;};return v();}export async function createResource(i,n){var x=S;return n['resource']['create']({'name':i[x(0xed)],'data':i['data'],'user':i[x(0xee)]});}
@@ -1 +1 @@
1
- export async function deleteResourceRelation(n,k){const {resource:Z,id:K,relation:d,relationId:J}=n;return k['resource']['deleteRelation']({'name':Z,'id':K,'relation':d,'relationId':J});}
1
+ export async function deleteResourceRelation(i,n){const {resource:x,id:N,relation:a,relationId:B}=i;return n['resource']['deleteRelation']({'name':x,'id':N,'relation':a,'relationId':B});}
@@ -1 +1 @@
1
- export async function deleteResource(n,k){return k['resource']['delete']({'name':n['resource'],'id':n['id'],'user':n['user']});}
1
+ export async function deleteResource(i,n){return n['resource']['delete']({'name':i['resource'],'id':i['id'],'user':i['user']});}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function r(n,k){n=n-0x127;const Z=g();let K=Z[n];return K;}function g(){const d=['offset','fields','rows'];g=function(){return d;};return g();}export async function exportResource(n,k){const K=r,Z=await k['resource']['find']({'name':n['resource'],'query':{'filter':parseFilterQuery(n),'sort':n['sort'],'search':n['search'],'limit':n['limit'],'offset':n[K(0x127)],'fields':n[K(0x128)]},'user':n['user']});return Z[K(0x129)];}
1
+ function S(i,n){i=i-0x103;const x=v();let N=x[i];return N;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function v(){const a=['user','rows'];v=function(){return a;};return v();}export async function exportResource(i,n){const N=S,x=await n['resource']['find']({'name':i['resource'],'query':{'filter':parseFilterQuery(i),'sort':i['sort'],'search':i['search'],'limit':i['limit'],'offset':i['offset'],'fields':i['fields']},'user':i[N(0x103)]});return x[N(0x104)];}
@@ -1 +1 @@
1
- export async function getResource(n,k){var Z=r;return k['resource'][Z(0x118)]({'name':n[Z(0x119)],'id':n['id'],'query':{'include':n[Z(0x11a)]},'user':n['user']});}function r(n,k){n=n-0x118;var Z=g();var K=Z[n];return K;}function g(){var K=['findOne','resource','include'];g=function(){return K;};return g();}
1
+ export async function getResource(i,n){return n['resource']['findOne']({'name':i['resource'],'id':i['id'],'query':{'include':i['include']},'user':i['user']});}
@@ -1 +1 @@
1
- export async function listResourceRelation(n,k){const {resource:Z,id:K,relation:d,query:J,user:B}=n;return k['resource']['findRelation']({'name':Z,'id':K,'relation':d,'query':J,'user':B});}
1
+ export async function listResourceRelation(i,n){const X=S,{resource:x,id:N,relation:a,query:B,user:q}=i;return n[X(0x102)]['findRelation']({'name':x,'id':N,'relation':a,'query':B,'user':q});}function S(i,n){i=i-0x102;const x=v();let N=x[i];return N;}function v(){const f=['resource'];v=function(){return f;};return v();}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function r(n,k){n=n-0x152;var Z=g();var K=Z[n];return K;}export async function listResources(n,k){var Z=r;return k['resource'][Z(0x152)]({'name':n['resource'],'query':{'filter':parseFilterQuery(n),'sort':n['sort'],'search':n[Z(0x153)],'limit':n[Z(0x154)],'offset':n['offset']??(n['page']?Math['max'](n['page']-0x1,0x0):0x0)*(n['limit']??0x14)},'user':n[Z(0x155)]});}function g(){var K=['find','search','limit','user'];g=function(){return K;};return g();}
1
+ function v(){var N=['find','resource','sort','limit'];v=function(){return N;};return v();}function S(i,n){i=i-0x108;var x=v();var N=x[i];return N;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function listResources(i,n){var x=S;return n['resource'][x(0x108)]({'name':i[x(0x109)],'query':{'filter':parseFilterQuery(i),'sort':i[x(0x10a)],'search':i['search'],'limit':i['limit'],'offset':i['offset']??(i['page']?Math['max'](i['page']-0x1,0x0):0x0)*(i[x(0x10b)]??0x14)},'user':i['user']});}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(n,k){return k['resource']['find']({'name':n['resource'],'query':{...n,'filter':parseFilterQuery(n)},'user':n['user']});}
1
+ function S(i,n){i=i-0x1a8;var x=v();var N=x[i];return N;}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function searchResource(i,n){var x=S;return n['resource']['find']({'name':i[x(0x1a8)],'query':{...i,'filter':parseFilterQuery(i)},'user':i['user']});}function v(){var N=['resource'];v=function(){return N;};return v();}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';function r(n,k){n=n-0x17d;const Z=g();let K=Z[n];return K;}function g(){const m=['resource','field','lookup','value','text','\x20as\x20text\x20FROM\x20','\x20WHERE\x20lower(','then','length','Field\x20has\x20no\x20lookup\x20dictionary:\x20','startsWith','slice','map'];g=function(){return m;};return g();}export async function suggestResource(n,k){const O=r,Z=k[O(0x17d)]['get'](n['resource']),K=String(n['search']??n['q']??'')['toLowerCase'](),d=Math['min'](Math['max'](Number(n['limit']??0x14),0x1),0xc8),J=Date['now'](),B=Z['fields'][n[O(0x17e)]],l=B?.['dictionary'],f=B?.[O(0x17f)]?.['table'];if(f){const a=B['lookup']?.['text']??'name',H=B['lookup']?.[O(0x180)]??'id';autoIndex(f,a,O(0x181),k['pg']);const A=await k['pg']['query']('SELECT\x20'+H+'\x20as\x20id,\x20'+a+O(0x182)+f+O(0x183)+a+')\x20~\x20$1\x20LIMIT\x20$2',[''+K['toLowerCase'](),d])[O(0x184)](I=>I['rows']);return{'limit':d,'count':A[O(0x185)],'search':K,'time':Date['now']()-J,'data':A};}if(!l)throw new ValidationError(O(0x186)+n[O(0x17e)]);const R=await k['dictionary']['get'](l),Q=R['filter'](I=>!K||I['code'][O(0x187)](K)||I['name'][O(0x187)](K))[O(0x188)](0x0,d)[O(0x189)](I=>({'id':I['code']||I['id'],'text':I['name']||I['text']}));return{'search':K,'limit':d,'count':Q['length'],'time':Date['now']()-J,'data':Q};}
1
+ import{ValidationError}from'../../../errors.js';import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';function S(i,n){i=i-0xef;const x=v();let N=x[i];return N;}function v(){const J=['min','now','fields','field','lookup','\x20WHERE\x20lower(','Field\x20has\x20no\x20lookup\x20dictionary:\x20','dictionary','get','filter'];v=function(){return J;};return v();}export async function suggestResource(i,n){const z=S,x=n['resource']['get'](i['resource']),N=String(i['search']??i['q']??'')['toLowerCase'](),a=Math[z(0xef)](Math['max'](Number(i['limit']??0x14),0x1),0xc8),B=Date[z(0xf0)](),q=x[z(0xf1)][i[z(0xf2)]],X=q?.['dictionary'],f=q?.['lookup']?.['table'];if(f){const V=q['lookup']?.['text']??'name',M=q[z(0xf3)]?.['value']??'id';autoIndex(f,V,'text',n['pg']);const U=await n['pg']['query']('SELECT\x20'+M+'\x20as\x20id,\x20'+V+'\x20as\x20text\x20FROM\x20'+f+z(0xf4)+V+')\x20~\x20$1\x20LIMIT\x20$2',[''+N['toLowerCase'](),a])['then'](t=>t['rows']);return{'limit':a,'count':U['length'],'search':N,'time':Date['now']()-B,'data':U};}if(!X)throw new ValidationError(z(0xf5)+i['field']);const A=await n[z(0xf6)][z(0xf7)](X),u=A[z(0xf8)](t=>!N||t['code']['startsWith'](N)||t['name']['startsWith'](N))['slice'](0x0,a)['map'](t=>({'id':t['code']||t['id'],'text':t['name']||t['text']}));return{'search':N,'limit':a,'count':u['length'],'time':Date['now']()-B,'data':u};}
@@ -1 +1 @@
1
- function r(n,k){n=n-0x1e0;const Z=g();let K=Z[n];return K;}export async function updateResourceRelation(n,k){const f=r,{resource:Z,id:K,relation:d,relationId:J,data:B,user:l}=n;return k[f(0x1e0)][f(0x1e1)]({'name':Z,'id':K,'relation':d,'relationId':J,'data':B,'user':l});}function g(){const R=['resource','updateRelation'];g=function(){return R;};return g();}
1
+ export async function updateResourceRelation(i,n){const f=S,{resource:x,id:N,relation:a,relationId:B,data:q,user:X}=i;return n[f(0x120)]['updateRelation']({'name':x,'id':N,'relation':a,'relationId':B,'data':q,'user':X});}function S(i,n){i=i-0x120;const x=v();let N=x[i];return N;}function v(){const A=['resource'];v=function(){return A;};return v();}
@@ -1 +1 @@
1
- export async function updateResource(n,k){var Z=r;return k[Z(0x172)][Z(0x173)]({'name':n['resource'],'id':n['id'],'data':n[Z(0x174)],'user':n[Z(0x175)]});}function r(n,k){n=n-0x172;var Z=g();var K=Z[n];return K;}function g(){var K=['resource','update','patch','user'];g=function(){return K;};return g();}
1
+ export async function updateResource(i,n){var x=S;return n['resource']['update']({'name':i[x(0x188)],'id':i['id'],'data':i['patch'],'user':i['user']});}function S(i,n){i=i-0x188;var x=v();var N=x[i];return N;}function v(){var N=['resource'];v=function(){return N;};return v();}
@@ -1 +1 @@
1
- function g(){const l=['resource','get','access','admin','permission','length','replace','file','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'];g=function(){return l;};return g();}import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';function r(n,k){n=n-0xfb;const Z=g();let K=Z[n];return K;}export async function uploadResourceFile(n,k){const B=r,Z=k[B(0xfb)][B(0xfc)](n[B(0xfb)]);if(Z[B(0xfd)]===B(0xfe)&&n['user']?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(n['user']?.['type']!=='admin'&&!n['user']?.['permissions']?.['includes']((Z[B(0xff)]??Z['name'])+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+(Z['permission']??Z['name'])+':update');if(!Buffer['isBuffer'](n['file'])||n['file'][B(0x100)]===0x0)throw new ValidationError('File\x20is\x20required');const K=n['fileName'][B(0x101)](/[^A-Za-z0-9._-]/g,'_');if(!K)throw new ValidationError('File\x20name\x20is\x20required');const d='files/'+n[B(0xfb)]+'/'+String(n['id'])+'/'+K;await k['file']['put'](d,n[B(0x102)]);if(!await k['file']['exists'](d))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const J=await k['pg'][B(0x103)](B(0x104),[n['resource'],String(n['id']),d,n['file']['length']]);return J['rows'][0x0];}
1
+ import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';function v(){const X=['resource','Admin\x20access\x20required','user','type','name','replace','files/','exists','query'];v=function(){return X;};return v();}function S(i,n){i=i-0x83;const x=v();let N=x[i];return N;}export async function uploadResourceFile(i,n){const q=S,x=n['resource']['get'](i[q(0x83)]);if(x['access']==='admin'&&i['user']?.['type']!=='admin')throw new ForbiddenError(q(0x84));if(i[q(0x85)]?.[q(0x86)]!=='admin'&&!i[q(0x85)]?.['permissions']?.['includes']((x['permission']??x['name'])+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+(x['permission']??x[q(0x87)])+':update');if(!Buffer['isBuffer'](i['file'])||i['file']['length']===0x0)throw new ValidationError('File\x20is\x20required');const N=i['fileName'][q(0x88)](/[^A-Za-z0-9._-]/g,'_');if(!N)throw new ValidationError('File\x20name\x20is\x20required');const a=q(0x89)+i[q(0x83)]+'/'+String(i['id'])+'/'+N;await n['file']['put'](a,i['file']);if(!await n['file'][q(0x8a)](a))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const B=await n['pg'][q(0x8b)]('\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',[i['resource'],String(i['id']),a,i['file']['length']]);return B['rows'][0x0];}