@opengis/fcore 0.0.28 → 0.0.29

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 (102) 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/generate-resource-code.js +1 -1
  33. package/dist/modules/resource/services/get-resource-schema.js +1 -1
  34. package/dist/modules/resource/services/get-resource.js +1 -1
  35. package/dist/modules/resource/services/list-resource-as-user.js +1 -1
  36. package/dist/modules/resource/services/list-resource-list.js +1 -1
  37. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  38. package/dist/modules/resource/services/list-resources.js +1 -1
  39. package/dist/modules/resource/services/search-resource.js +1 -1
  40. package/dist/modules/resource/services/suggest-resource.js +1 -1
  41. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  42. package/dist/modules/resource/services/update-resource.js +1 -1
  43. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  44. package/dist/modules/system/route.js +1 -1
  45. package/dist/modules/system/schema.js +1 -1
  46. package/dist/modules/system/services/check-system.js +1 -1
  47. package/dist/modules/system/services/get-access.js +1 -1
  48. package/dist/modules/system/services/get-api-list.js +1 -1
  49. package/dist/modules/system/services/get-audit-log.js +1 -1
  50. package/dist/modules/system/services/get-dictionary.js +1 -1
  51. package/dist/modules/system/services/get-resource-access.js +1 -1
  52. package/dist/modules/system/services/get-resource-scopes.js +1 -1
  53. package/dist/modules/system/services/get-system-log.js +1 -1
  54. package/dist/modules/system/services/get-system-settings.js +1 -1
  55. package/dist/modules/system/services/list-dictionaries.js +1 -1
  56. package/dist/modules/system/services/set-access.js +1 -1
  57. package/dist/modules/system/services/set-resource-access.js +1 -1
  58. package/dist/modules/system/services/set-resource-scopes.js +1 -1
  59. package/dist/modules/system/services/update-dictionary.js +1 -1
  60. package/dist/modules/system/services/update-system-settings.js +1 -1
  61. package/dist/modules/utils/require-admin.js +1 -1
  62. package/dist/modules/utils/safe-user.js +1 -1
  63. package/dist/modules/utils/unsupported.js +1 -1
  64. package/dist/plugins/audit/audit.js +1 -1
  65. package/dist/plugins/audit/services/write-audit.js +1 -1
  66. package/dist/plugins/auth/get-user-permissions.js +1 -1
  67. package/dist/plugins/auth/index.js +1 -1
  68. package/dist/plugins/auth/verifyUser.js +1 -1
  69. package/dist/plugins/dictionary.js +1 -1
  70. package/dist/plugins/file.js +1 -1
  71. package/dist/plugins/jwt.js +1 -1
  72. package/dist/plugins/logger/index.js +1 -1
  73. package/dist/plugins/logger/transport.js +1 -1
  74. package/dist/plugins/pg.js +1 -1
  75. package/dist/plugins/redis.js +1 -1
  76. package/dist/plugins/resource/resource.js +1 -1
  77. package/dist/plugins/resource/resource.registry.js +1 -1
  78. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  79. package/dist/plugins/resource/services/add-file-token.js +1 -1
  80. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  81. package/dist/plugins/resource/services/create-relation.js +1 -1
  82. package/dist/plugins/resource/services/create.js +1 -1
  83. package/dist/plugins/resource/services/delete-relation.js +1 -1
  84. package/dist/plugins/resource/services/delete.js +1 -1
  85. package/dist/plugins/resource/services/find-one.js +1 -1
  86. package/dist/plugins/resource/services/find-relation.js +1 -1
  87. package/dist/plugins/resource/services/find.js +1 -1
  88. package/dist/plugins/resource/services/get-table-columns.js +1 -1
  89. package/dist/plugins/resource/services/update-relation.js +1 -1
  90. package/dist/plugins/resource/services/update.js +1 -1
  91. package/dist/plugins/resource/utils/auto-index.js +1 -1
  92. package/dist/plugins/resource/utils/fields.js +1 -1
  93. package/dist/plugins/resource/utils/filters.js +1 -1
  94. package/dist/plugins/resource/utils/permissions.js +1 -1
  95. package/dist/plugins/resource/utils/scope.js +1 -1
  96. package/dist/plugins/resource/utils/sort.js +1 -1
  97. package/dist/plugins/resource/utils/sql.js +1 -1
  98. package/dist/plugins/resource/utils/summary.js +1 -1
  99. package/dist/shared/getIP.js +1 -1
  100. package/migrations/20260903140000_settings_nulls_not_distinct.sql +1 -1
  101. package/migrations/20260905120000_add_user_foreign_keys.sql +15 -0
  102. package/package.json +1 -1
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(p){const I=f,Z=process.env[p];if(!Z)throw new Error(I(0x163)+p);return Z;}function f(p,Z){p=p-0x163;const A=s();let I=A[p];return I;}export function loadConfig(p={}){const j=f,Z={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG===j(0x164),'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)},'storageType':(process.env.STORAGE_TYPE??'s3')['toLowerCase']()===j(0x165)||!process.env.S3_ENDPOINT?'local':'s3','storagePath':process.env.STORAGE_PATH??j(0x166),'redactionList':(process.env.REDACTION_LIST||'password')[j(0x167)](','),'logger':{'level':process.env.LOG_LEVEL??'info','responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')['map'](A=>A-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process[j(0x168)]()+'/log'},'pg':{'host':process.env.PG_HOST??j(0x169),'port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??'us-east-1','bucket':process.env.S3_BUCKET??'','accessKey':process.env.S3_ACCESS_KEY,'secretKey':process.env.S3_SECRET_KEY,'folder':process.env.S3_FOLDER,'forcePathStyle':process.env.S3_FORCE_PATH_STYLE!=='false','tokenSecret':process.env.FILE_TOKEN_SECRET,'tokenTtl':Number(process.env.FILE_TOKEN_TTL??0xe10)},'auth':{'accessToken':process.env.AUTH_ACCESS_TOKEN||'Ch7QR4e73Jg0wx0xOjm','user':process.env.AUTH_USER?JSON['parse'](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??'x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','cookieName':process.env.AUTH_COOKIE_NAME??j(0x16a),'jwtSecret':process.env.AUTH_JWT_SECRET??'0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','redirect':process.env.AUTH_REDIRECT??'/','twoFactorRedirect':process.env.AUTH_TWOFACTOR_REDIRECT??'/','cookieOptions':process.env.AUTH_COOKIE_OPTIONS_DOMAIN?{'domain':process.env.AUTH_COOKIE_OPTIONS_DOMAIN,'path':process.env.AUTH_COOKIE_OPTIONS_PATH||'/','httpOnly':Boolean(process.env.AUTH_COOKIE_OPTIONS_HTTP_ONLY||'true'),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'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||'true')}:{'path':'/','httpOnly':!![],'secure':![],'sameSite':!![]}}};return{...Z,...p,'logger':{...Z['logger'],...p['logger']},'pg':{...Z['pg'],...p['pg']},'redis':{...Z[j(0x16b)],...p['redis']},'s3':{...Z['s3'],...p['s3']},'auth':{...Z['auth'],...p[j(0x16c)]}};}function s(){const D=['Missing\x20environment\x20variable:\x20','true','local','./storage','split','cwd','localhost','session_user_auth','redis','auth'];s=function(){return D;};return s();}export{required as requireEnv};
1
+ function O(){const u=['Missing\x20environment\x20variable:\x20','toLowerCase','./storage','password','info','split','map','cwd','/log','false','0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','true','lax','none','auth'];O=function(){return u;};return O();}import'dotenv/config';function c(S,Z){S=S-0x139;const h=O();let U=h[S];return U;}const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(S){const U=c,Z=process.env[S];if(!Z)throw new Error(U(0x139)+S);return Z;}export function loadConfig(S={}){const D=c,Z={'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)},'storageType':(process.env.STORAGE_TYPE??'s3')[D(0x13a)]()==='local'||!process.env.S3_ENDPOINT?'local':'s3','storagePath':process.env.STORAGE_PATH??D(0x13b),'redactionList':(process.env.REDACTION_LIST||D(0x13c))['split'](','),'logger':{'level':process.env.LOG_LEVEL??D(0x13d),'responses':process.env.LOG_RESPONSES==='true'?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES[D(0x13e)](',')[D(0x13f)](h=>h-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process[D(0x140)]()+D(0x141)},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??'us-east-1','bucket':process.env.S3_BUCKET??'','accessKey':process.env.S3_ACCESS_KEY,'secretKey':process.env.S3_SECRET_KEY,'folder':process.env.S3_FOLDER,'forcePathStyle':process.env.S3_FORCE_PATH_STYLE!==D(0x142),'tokenSecret':process.env.FILE_TOKEN_SECRET,'tokenTtl':Number(process.env.FILE_TOKEN_TTL??0xe10)},'auth':{'accessToken':process.env.AUTH_ACCESS_TOKEN||'Ch7QR4e73Jg0wx0xOjm','user':process.env.AUTH_USER?JSON['parse'](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??'x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','cookieName':process.env.AUTH_COOKIE_NAME??'session_user_auth','jwtSecret':process.env.AUTH_JWT_SECRET??D(0x143),'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||D(0x144)),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'true'),'sameSite':process.env.AUTH_COOKIE_OPTIONS_SAME_SITE&&[D(0x145),'strict',D(0x146)]['includes'](process.env.AUTH_COOKIE_OPTIONS_SAME_SITE)?process.env.AUTH_COOKIE_OPTIONS_SAME_SITE:Boolean(process.env.AUTH_COOKIE_OPTIONS_SAME_SITE||'true')}:{'path':'/','httpOnly':!![],'secure':![],'sameSite':!![]}}};return{...Z,...S,'logger':{...Z['logger'],...S['logger']},'pg':{...Z['pg'],...S['pg']},'redis':{...Z['redis'],...S['redis']},'s3':{...Z['s3'],...S['s3']},'auth':{...Z['auth'],...S[D(0x147)]}};}export{required as requireEnv};
package/dist/context.js CHANGED
@@ -1 +1 @@
1
- let defaultContext;export function setContext(p){defaultContext=p;}export function getContext(){if(!defaultContext)throw new Error('Application\x20context\x20is\x20not\x20initialized');return defaultContext;}function f(p,Z){p=p-0xd7;const A=s();let I=A[p];return I;}function s(){const A=['allSettled','logger'];s=function(){return A;};return s();}export function createContext(p){return{...p,async 'close'(){const Z=f;await Promise[Z(0xd7)]([p['redis']?.['close'](),p['pg']?.['end']()]),await p[Z(0xd8)]['close']();}};}
1
+ let defaultContext;function c(S,Z){S=S-0x12c;const h=O();let U=h[S];return U;}export function setContext(S){defaultContext=S;}function O(){const h=['redis'];O=function(){return h;};return O();}export function getContext(){if(!defaultContext)throw new Error('Application\x20context\x20is\x20not\x20initialized');return defaultContext;}export function createContext(S){return{...S,async 'close'(){const Z=c;await Promise['allSettled']([S[Z(0x12c)]?.['close'](),S['pg']?.['end']()]),await S['logger']['close']();}};}
package/dist/errors.js CHANGED
@@ -1 +1 @@
1
- var j=f;export class FCoreError extends Error{[j(0x7f)];[j(0x80)];['details'];constructor(p,Z,A=0x1f4,I){var D=j;super(Z),this['code']=p,this[D(0x80)]=A,this[D(0x81)]=I,this['name']=new.target.name;}}function f(p,Z){p=p-0x7f;var A=s();var I=A[p];return I;}export class BadRequestError extends FCoreError{constructor(p,Z){super('BAD_REQUEST_ERROR',p,0x190,Z);}}export class UnauthorizedError extends FCoreError{constructor(p='Authentication\x20required'){super('UNAUTHORIZED',p,0x191);}}export class ForbiddenError extends FCoreError{constructor(p=j(0x82)){super('FORBIDDEN',p,0x193);}}function s(){var R=['code','statusCode','details','Access\x20denied','Conflict','VALIDATION_ERROR'];s=function(){return R;};return s();}export class NotFoundError extends FCoreError{constructor(p='Not\x20found'){super('NOT_FOUND',p,0x194);}}export class ConflictError extends FCoreError{constructor(p=j(0x83)){super('CONFLICT',p,0x199);}}export class ValidationError extends FCoreError{constructor(p,Z){var o=j;super(o(0x84),p,0x1a6,Z);}}export class UnsupportedError extends FCoreError{constructor(p='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',p,0x1f5);}}
1
+ var u=c;export class FCoreError extends Error{['code'];['statusCode'];['details'];constructor(S,Z,h=0x1f4,U){var D=c;super(Z),this[D(0x139)]=S,this['statusCode']=h,this[D(0x13a)]=U,this['name']=new.target.name;}}function O(){var q=['code','details','Access\x20denied','Not\x20found','Conflict','VALIDATION_ERROR','Operation\x20is\x20not\x20configured'];O=function(){return q;};return O();}export class BadRequestError extends FCoreError{constructor(S,Z){super('BAD_REQUEST_ERROR',S,0x190,Z);}}export class UnauthorizedError extends FCoreError{constructor(S='Authentication\x20required'){super('UNAUTHORIZED',S,0x191);}}export class ForbiddenError extends FCoreError{constructor(S=u(0x13b)){super('FORBIDDEN',S,0x193);}}export class NotFoundError extends FCoreError{constructor(S=u(0x13c)){super('NOT_FOUND',S,0x194);}}export class ConflictError extends FCoreError{constructor(S=u(0x13d)){super('CONFLICT',S,0x199);}}export class ValidationError extends FCoreError{constructor(S,Z){var e=u;super(e(0x13e),S,0x1a6,Z);}}function c(S,Z){S=S-0x139;var h=O();var U=h[S];return U;}export class UnsupportedError extends FCoreError{constructor(S=u(0x13f)){super('UNSUPPORTED',S,0x1f5);}}
package/dist/fastify.js CHANGED
@@ -1 +1 @@
1
- import p from'fastify-plugin';import{FCoreError}from'./errors.js';function s(){const V=['split','ctx','schema','tags','access','routeOptions','url','platform','win32','config','user','raw','permissions','type','admin','Admin\x20access\x20required','replace','includes','logger','warn','code','statusCode','message','send','@fastify/rate-limit','rateLimit'];s=function(){return V;};return s();}import{authRoutes}from'./modules/auth/route.js';function f(p,Z){p=p-0x128;const A=s();let I=A[p];return I;}import{fileRoutes}from'./modules/file/route.js';import{resourceRoutes}from'./modules/resource/route.js';import{systemRoutes}from'./modules/system/route.js';import{createSessionStore}from'./plugins/auth/index.js';import{ForbiddenError}from'./errors.js';import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(Z,A,I){const a=f,j=decodeURIComponent(A['toString']())[a(0x128)]('&')['reduce']((D,o)=>{const [R,B]=o['split']('=');return{...D,[R]:B};},{});I(null,j);}export default function fcoreFastify(Z,A){return p(async I=>{const X=f;I['decorate'](X(0x129),Z);const {config:j}=Z,D=new Map();I['addHook']('onRoute',R=>{const K=X,B=R[K(0x12a)],H=Array['isArray'](R['method'])?R['method']:[R['method']];for(const e of H){if(e==='HEAD')continue;const g={'method':e,'endpoint':R['url'],'package':B?.['package']??'fcore','tags':B?.[K(0x12b)]??[],'summary':B?.['summary']??'','description':B?.['description']??'','access':B?.[K(0x12c)]??'public','permissions':B?.['permissions']??[]};D['set'](e+'\x20'+R['url'],g);}}),I['addHook']('preHandler',async R=>{const Q=X;if(R[Q(0x12d)]['url']==='*')return!![];const B=D['get'](R['method']+'\x20'+R[Q(0x12d)][Q(0x12e)]),H=!R['user']&&process[Q(0x12f)]===Q(0x130)&&Z[Q(0x131)]?.['auth']?.['user']?Z['config']?.['auth']?.[Q(0x132)]:null,e=R[Q(0x133)]['headers']?.['authorization'],g=e?.['startsWith']('Bearer\x20')?e['slice'](0x7):null,N=R['user']??(g?await jwtVerifyToken(g):H);!R[Q(0x132)]&&g&&process.env.AUTH_JWT_SECRET&&(R['user']=await jwtVerifyToken(g));if(!B?.[Q(0x12c)])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(B['access']==='public')return!![];if(!N)throw new ForbiddenError('User\x20required');if(B[Q(0x12c)]===Q(0x132)&&!B[Q(0x134)]?.['length'])return!![];if(N[Q(0x135)]=='admin')return!![];if(B[Q(0x12c)]===Q(0x136))throw new ForbiddenError(Q(0x137));for(const h of B['permissions']){const E=h?.[Q(0x138)]('$resource',R['params']['resource']??'');if(!N[Q(0x134)]?.[Q(0x139)](E))throw new ForbiddenError('Missing\x20permission:\x20'+E);}return!![];}),await createSessionStore(I,Z),await I['register'](import('@fastify/multipart'),{'limits':{'fileSize':j['maxFileSize']*0x400*0x400}}),I['setErrorHandler']((R,B,H)=>{const G=X;if(R instanceof FCoreError||R['code']==='FST_ERR_VALIDATION'||R['statusCode']<0x1f4)return R['statusCode']<0x1f4&&Z[G(0x13a)][G(0x13b)](R),H[G(0x13c)](R[G(0x13d)])['send']({'error':R['code'],'message':R[G(0x13e)],'details':R['details']});return Z[G(0x13a)]['error'](R),(j['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console['error'](R),H['code'](0x1f4)[G(0x13f)]({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const o=R=>!A||A['includes'](R);if(o('auth'))await I['register'](authRoutes(Z));if(o('resource'))await I['register'](resourceRoutes(Z));if(o('file'))await I['register'](fileRoutes(Z));if(o('system'))await I['register'](systemRoutes(Z,D));I['addContentTypeParser']('application/x-www-form-urlencoded',{'parseAs':'buffer'},urlencodedContentParser),!j['rateLimit']?.['disabled']?I['register'](import(X(0x140)),{'max':j[X(0x141)]?.['max']||0x64,'timeWindow':j[X(0x141)]?.['timeWindow']||0xea60,'hook':'preHandler','global':!![],'keyGenerator':R=>(R[X(0x132)]?.['id']||R['ip'])+'-'+R['raw']['url']['split']('?')[0x0]}):console['log']('⚠️\x20rate\x20limit\x20is\x20disabled');});}
1
+ import S 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';import{ForbiddenError}from'./errors.js';function c(S,Z){S=S-0x1d5;const h=O();let U=h[S];return U;}import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(Z,h,U){const l=c,D=decodeURIComponent(h['toString']())['split']('&')[l(0x1d5)]((u,e)=>{const [q,x]=e['split']('=');return{...u,[q]:x};},{});U(null,D);}export default function fcoreFastify(Z,h){return S(async U=>{const b=c;U['decorate'](b(0x1d6),Z);const {config:D}=Z,u=new Map();U['addHook']('onRoute',q=>{const Y=b,x=q['schema'],n=Array[Y(0x1d7)](q[Y(0x1d8)])?q['method']:[q[Y(0x1d8)]];for(const N of n){if(N==='HEAD')continue;const o={'method':N,'endpoint':q['url'],'package':x?.['package']??'fcore','tags':x?.['tags']??[],'summary':x?.[Y(0x1d9)]??'','description':x?.['description']??'','access':x?.['access']??'public','permissions':x?.[Y(0x1da)]??[]};u['set'](N+'\x20'+q['url'],o);}}),U['addHook']('preHandler',async q=>{const r=b;if(q['routeOptions'][r(0x1db)]==='*')return!![];const x=u['get'](q[r(0x1d8)]+'\x20'+q['routeOptions'][r(0x1db)]),n=!q['user']&&process['platform']==='win32'&&Z['config']?.[r(0x1dc)]?.['user']?Z['config']?.['auth']?.['user']:null,N=q[r(0x1dd)]['headers']?.[r(0x1de)],o=N?.['startsWith'](r(0x1df))?N['slice'](0x7):null,j=q['user']??(o?await jwtVerifyToken(o):n);!q['user']&&o&&process.env.AUTH_JWT_SECRET&&(q['user']=await jwtVerifyToken(o));if(!x?.['access'])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(x['access']===r(0x1e0))return!![];if(!j)throw new ForbiddenError(r(0x1e1));if(x[r(0x1e2)]==='user'&&!x[r(0x1da)]?.['length'])return!![];if(j['type']=='admin')return!![];if(x['access']==='admin')throw new ForbiddenError(r(0x1e3));for(const X of x[r(0x1da)]){const i=X?.['replace']('$resource',q['params'][r(0x1e4)]??'');if(!j[r(0x1da)]?.[r(0x1e5)](i))throw new ForbiddenError('Missing\x20permission:\x20'+i);}return!![];}),await createSessionStore(U,Z),await U['register'](import(b(0x1e6)),{'limits':{'fileSize':D['maxFileSize']*0x400*0x400}}),U['setErrorHandler']((q,x,n)=>{const E=b;if(q instanceof FCoreError||q[E(0x1e7)]==='FST_ERR_VALIDATION'||q['statusCode']<0x1f4)return q['statusCode']<0x1f4&&Z['logger']['warn'](q),n[E(0x1e7)](q['statusCode'])['send']({'error':q['code'],'message':q[E(0x1e8)],'details':q['details']});return Z[E(0x1e9)]['error'](q),(D[E(0x1ea)]||process.env.NODE_ENV===E(0x1eb)||process.env.VITEST)&&console['error'](q),n[E(0x1e7)](0x1f4)[E(0x1ec)]({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const e=q=>!h||h['includes'](q);if(e('auth'))await U['register'](authRoutes(Z));if(e('resource'))await U['register'](resourceRoutes(Z));if(e('file'))await U['register'](fileRoutes(Z));if(e('system'))await U['register'](systemRoutes(Z,u));U['addContentTypeParser']('application/x-www-form-urlencoded',{'parseAs':'buffer'},urlencodedContentParser),!D['rateLimit']?.['disabled']?U['register'](import(b(0x1ed)),{'max':D['rateLimit']?.['max']||0x64,'timeWindow':D['rateLimit']?.['timeWindow']||0xea60,'hook':b(0x1ee),'global':!![],'keyGenerator':q=>(q['user']?.['id']||q['ip'])+'-'+q[b(0x1dd)]['url']['split']('?')[0x0]}):console['log'](b(0x1ef));});}function O(){const L=['reduce','ctx','isArray','method','summary','permissions','url','auth','raw','authorization','Bearer\x20','public','User\x20required','access','Admin\x20access\x20required','resource','includes','@fastify/multipart','code','message','logger','debug','test','send','@fastify/rate-limit','preHandler','⚠️\x20rate\x20limit\x20is\x20disabled'];O=function(){return L;};return O();}
package/dist/fcore.js CHANGED
@@ -1 +1 @@
1
- function s(){const g=['storageType','tokenSecret','secretKey','register'];s=function(){return g;};return s();}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';import{createAudit,createDatabase,createDictionary,createFileLocal,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function f(p,Z){p=p-0x193;const A=s();let I=A[p];return I;}export async function createFCore(p={}){const e=f,Z=loadConfig(p['config']),A=createRedis(Z['redis']),I=createLogger(),j=createDatabase(Z['pg']),D=Z[e(0x193)]==='local'?createFileLocal({'storagePath':Z['storagePath'],'folder':Z['s3']['folder'],'tokenSecret':Z['s3'][e(0x194)],'tokenTtl':Z['s3']['tokenTtl']}):createFileS3({'endpoint':Z['s3']['endpoint'],'region':Z['s3']['region'],'bucket':Z['s3']['bucket'],'accessKey':Z['s3']['accessKey'],'secretKey':Z['s3'][e(0x195)],'folder':Z['s3']['folder'],'forcePathStyle':Z['s3']['forcePathStyle'],'tokenSecret':Z['s3']['tokenSecret'],'tokenTtl':Z['s3']['tokenTtl']}),o=createAudit({'pg':j,'logger':I}),R=createDictionary({'pg':j,'dictionaries':p['dictionaries']}),B=createResource({'pg':j,'logger':I,'audit':o,'dictionary':R,'file':D});p['resources']?.['length']&&B[e(0x196)](p['resources']);const H=createContext({'config':Z,'logger':I,'redis':A,'pg':j,'file':D,'resource':B,'audit':o,'dictionary':R});return setContext(H),H;}
1
+ import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';import{createAudit,createDatabase,createDictionary,createFileLocal,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';function c(S,Z){S=S-0xb7;const h=O();let U=h[S];return U;}export async function createFCore(S={}){const N=c,Z=loadConfig(S[N(0xb7)]),h=createRedis(Z['redis']),U=createLogger(),D=createDatabase(Z['pg']),u=Z[N(0xb8)]==='local'?createFileLocal({'storagePath':Z[N(0xb9)],'folder':Z['s3']['folder'],'tokenSecret':Z['s3']['tokenSecret'],'tokenTtl':Z['s3']['tokenTtl']}):createFileS3({'endpoint':Z['s3']['endpoint'],'region':Z['s3']['region'],'bucket':Z['s3']['bucket'],'accessKey':Z['s3']['accessKey'],'secretKey':Z['s3']['secretKey'],'folder':Z['s3']['folder'],'forcePathStyle':Z['s3']['forcePathStyle'],'tokenSecret':Z['s3'][N(0xba)],'tokenTtl':Z['s3']['tokenTtl']}),e=createAudit({'pg':D,'logger':U}),q=createDictionary({'pg':D,'dictionaries':S['dictionaries']}),x=createResource({'pg':D,'logger':U,'audit':e,'dictionary':q,'file':u});S['resources']?.['length']&&x['register'](S['resources']);const n=createContext({'config':Z,'logger':U,'redis':h,'pg':D,'file':u,'resource':x,'audit':e,'dictionary':q});return setContext(n),n;}function O(){const o=['config','storageType','storagePath','tokenSecret'];O=function(){return o;};return O();}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function f(p,Z){p=p-0x6f;const A=s();let I=A[p];return I;}const B=f;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';import p from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL('../../migrations',import.meta.url));function migrationDirectory(Z){const R=f,A=Z['indexOf'](R(0x6f));if(A>=0x0){const j=Z[A+0x1];if(!j)throw new Error('--dir\x20requires\x20a\x20folder\x20path');return p['resolve'](j);}if(Z['includes'](R(0x70)))return packageMigrations;const I=Z['find'](D=>!D[R(0x71)]('--'));return p['resolve'](I??R(0x72));}function s(){const H=['--dir','--fcore','startsWith','migrations','argv','log','slice','OK\x20\x20'];s=function(){return H;};return s();}try{const config=loadConfig(),dir=migrationDirectory(process[B(0x73)]['slice'](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':'****','password':'****'}),console[B(0x74)]('Using\x20migration\x20directory:',dir,process[B(0x73)][B(0x75)](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console[B(0x74)]((r['status']==='run'?B(0x76):'SKIP')+'\x20'+r['file']);}catch(o){console['error'](o),process['exitCode']=0x1;}
2
+ const q=c;import{runMigrations}from'./runner.js';function O(){const n=['../../migrations','--dir','--dir\x20requires\x20a\x20folder\x20path','--fcore','find','resolve','log','****','slice','OK\x20\x20','exitCode'];O=function(){return n;};return O();}import{loadConfig}from'../config.js';import S from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL(q(0xe4),import.meta.url));function migrationDirectory(Z){const x=q,h=Z['indexOf'](x(0xe5));if(h>=0x0){const D=Z[h+0x1];if(!D)throw new Error(x(0xe6));return S['resolve'](D);}if(Z['includes'](x(0xe7)))return packageMigrations;const U=Z[x(0xe8)](u=>!u['startsWith']('--'));return S[x(0xe9)](U??'migrations');}function c(S,Z){S=S-0xe4;const h=O();let U=h[S];return U;}try{const config=loadConfig(),dir=migrationDirectory(process['argv']['slice'](0x2));console[q(0xea)]('Loaded\x20configuration:',{...config['pg'],'user':q(0xeb),'password':'****'}),console['log']('Using\x20migration\x20directory:',dir,process['argv'][q(0xec)](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console[q(0xea)]((r['status']==='run'?q(0xed):'SKIP')+'\x20'+r['file']);}catch(e){console['error'](e),process[q(0xee)]=0x1;}
@@ -1 +1 @@
1
- import p from'node:fs/promises';import Z from'node:path';function f(p,Z){p=p-0x95;const A=s();let I=A[p];return I;}import{createDatabase}from'../plugins/pg.js';export async function runMigrations(A={}){const E=f,I=Z['resolve'](A['dir']??E(0x95)),j=A[E(0x96)]??databaseFromUrl(A[E(0x97)]??process.env.DATABASE_URL);if(!j)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const D=createDatabase(j);if(!D)throw new Error('empty\x20pg');const o=[];try{await D[E(0x98)](E(0x99));const R=await D[E(0x98)]('SELECT\x20version\x20FROM\x20schema_migrations'),B=new Set(R['rows']['map'](e=>e[E(0x9a)])),H=(await p['readdir'](I))['filter'](e=>e['endsWith']('.sql'))['sort']();for(const e of H){if(B['has'](e)){o['push']({'file':e,'status':'skip'});continue;}const g=await p['readFile'](Z['join'](I,e),'utf8'),N=await D[E(0x9b)]();try{await N[E(0x98)]('BEGIN'),await N['query'](g),await N['query'](E(0x9c),[e]),await N['query'](E(0x9d));}catch(h){await N['query'](E(0x9e));throw h;}finally{N['release']();}o['push']({'file':e,'status':'run'});}return o;}finally{await D[E(0x9f)]();}}function databaseFromUrl(A){const a=f;if(!A)return undefined;const I=new URL(A);return{'host':I['hostname'],'port':Number(I['port']||0x1538),'database':I['pathname'][a(0xa0)](0x1),'user':decodeURIComponent(I['username']),'password':decodeURIComponent(I['password'])};}function s(){const X=['migrations','database','databaseUrl','query','\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20','version','connect','INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)','COMMIT','ROLLBACK','end','slice'];s=function(){return X;};return s();}
1
+ import S from'node:fs/promises';import Z from'node:path';function O(){const l=['dir','migrations','DATABASE_URL\x20or\x20database\x20config\x20is\x20required','query','\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20','rows','readdir','endsWith','join','connect','INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)','end'];O=function(){return l;};return O();}import{createDatabase}from'../plugins/pg.js';export async function runMigrations(h={}){const i=c,U=Z['resolve'](h[i(0x6e)]??i(0x6f)),D=h['database']??databaseFromUrl(h['databaseUrl']??process.env.DATABASE_URL);if(!D)throw new Error(i(0x70));const u=createDatabase(D);if(!u)throw new Error('empty\x20pg');const e=[];try{await u[i(0x71)](i(0x72));const q=await u['query']('SELECT\x20version\x20FROM\x20schema_migrations'),x=new Set(q[i(0x73)]['map'](N=>N['version'])),n=(await S[i(0x74)](U))['filter'](N=>N[i(0x75)]('.sql'))['sort']();for(const N of n){if(x['has'](N)){e['push']({'file':N,'status':'skip'});continue;}const o=await S['readFile'](Z[i(0x76)](U,N),'utf8'),j=await u[i(0x77)]();try{await j['query']('BEGIN'),await j['query'](o),await j['query'](i(0x78),[N]),await j[i(0x71)]('COMMIT');}catch(X){await j['query']('ROLLBACK');throw X;}finally{j['release']();}e['push']({'file':N,'status':'run'});}return e;}finally{await u[i(0x79)]();}}function c(S,Z){S=S-0x6e;const h=O();let U=h[S];return U;}function databaseFromUrl(h){if(!h)return undefined;const U=new URL(h);return{'host':U['hostname'],'port':Number(U['port']||0x1538),'database':U['pathname']['slice'](0x1),'user':decodeURIComponent(U['username']),'password':decodeURIComponent(U['password'])};}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const A=f;function f(p,Z){p=p-0x17d;const A=s();let I=A[p];return I;}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function s(){const I=['argv','exitCode','end'];s=function(){return I;};return s();}import p from'./services/registration.js';const [user,password,type]=process[A(0x17d)]['slice'](0x2);if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process[A(0x17e)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await p({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(Z){console['error'](Z),process['exitCode']=0x1;}finally{await pg[A(0x17f)]();}}
2
+ const h=c;import{loadConfig}from'../../config.js';function O(){const U=['Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]','log','exitCode','end'];O=function(){return U;};return O();}import{createDatabase}from'../../plugins/pg.js';import S from'./services/registration.js';function c(S,Z){S=S-0x164;const h=O();let U=h[S];return U;}const [user,password,type]=process['argv']['slice'](0x2);if(!user||!password)console['error'](h(0x164)),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await S({'user':user,'password':password,'type':type},{'pg':pg});console[h(0x165)]('Registered\x20user\x20'+data['id']+'\x20('+data['type']+')');}catch(Z){console['error'](Z),process[h(0x166)]=0x1;}finally{await pg[h(0x167)]();}}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const A=f;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import p from'./services/change-password.js';const [login,password]=process['argv'][A(0x140)](0x2);function f(p,Z){p=p-0x140;const A=s();let I=A[p];return I;}if(!login||!password)console['error']('Usage:\x20fcore-password\x20<login>\x20<password>'),process[A(0x141)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query']('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error(A(0x142));await p({'userId':user['id'],'password':password},{'pg':pg}),console['log'](A(0x143)+login);}catch(Z){console['error'](Z),process['exitCode']=0x1;}finally{await pg['end']();}}function s(){const I=['slice','exitCode','User\x20not\x20found','Password\x20changed\x20for\x20'];s=function(){return I;};return s();}
2
+ const h=c;function c(S,Z){S=S-0x10c;const h=O();let U=h[S];return U;}import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import S from'./services/change-password.js';const [login,password]=process['argv']['slice'](0x2);if(!login||!password)console['error']('Usage:\x20fcore-password\x20<login>\x20<password>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query'](h(0x10c),[login]),user=result['rows'][0x0];if(!user)throw new Error(h(0x10d));await S({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(Z){console[h(0x10e)](Z),process[h(0x10f)]=0x1;}finally{await pg['end']();}}function O(){const U=['SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201','User\x20not\x20found','error','exitCode'];O=function(){return U;};return O();}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function s(){const e=['settings','dictionaries','read','slice','trim','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','exitCode','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','access_id','release','Granted\x20permissions\x20for\x20','end'];s=function(){return e;};return s();}const B=f;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs','audit','list','check','access',B(0x14e),B(0x14f)],RESOURCE_ACTIONS=[B(0x150),'update','create','delete'],[login,permissionArg]=process['argv'][B(0x151)](0x2);function expandPermissions(p){const H=B,Z=p['split'](',')['map'](I=>I[H(0x152)]())['filter'](Boolean),A=new Set();for(const I of Z){if(I['includes'](':')){A['add'](I);continue;}const j=I==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const D of j){A['add'](I+':'+D);}}return[...A];}function f(p,Z){p=p-0x14e;const A=s();let I=A[p];return I;}if(!login||!permissionArg)console['error'](B(0x153)),process[B(0x154)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[B(0x155)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error('User\x20not\x20found');if(permissionArg['trim']()==='clear')await pg['query']('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console['log']('Permissions\x20cleared\x20for\x20'+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission['split'](':'),actions=byResource['get'](resource)??[];actions['push'](action),byResource['set'](resource,actions);}const client=await pg['connect']();try{await client['query']('BEGIN');for(const [resource,actions]of byResource){const existing=await client['query']('SELECT\x20access_id,\x20actions\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL\x20AND\x20resource\x20=\x20$2',[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client[B(0x155)](B(0x156),[merged,user['id'],row[B(0x157)]]);}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(o){await client['query']('ROLLBACK');throw o;}finally{client[B(0x158)]();}console['log'](B(0x159)+login+':\x20'+permissions['join'](',\x20'));}}catch(R){console['error'](R),process['exitCode']=0x1;}finally{await pg[B(0x15a)]();}}
2
+ const x=c;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=['logs','audit','list',x(0xf8),x(0xf9),x(0xfa),'dictionaries'],RESOURCE_ACTIONS=['read',x(0xfb),x(0xfc),'delete'],[login,permissionArg]=process['argv'][x(0xfd)](0x2);function expandPermissions(S){const n=x,Z=S[n(0xfe)](',')['map'](U=>U['trim']())['filter'](Boolean),h=new Set();for(const U of Z){if(U[n(0xff)](':')){h[n(0x100)](U);continue;}const D=U==='system'?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const u of D){h['add'](U+':'+u);}}return[...h];}function c(S,Z){S=S-0xf8;const h=O();let U=h[S];return U;}function O(){const N=['check','access','settings','update','create','slice','split','includes','add','error','query','SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201','rows','trim','clear','push','set','connect','BEGIN','SELECT\x20access_id,\x20actions\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL\x20AND\x20resource\x20=\x20$2','UPDATE\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20actions\x20=\x20$1,\x20updated_by\x20=\x20$2,\x20updated_at\x20=\x20now()\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20access_id\x20=\x20$3','exitCode'];O=function(){return N;};return O();}if(!login||!permissionArg)console[x(0x101)]('Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[x(0x102)](x(0x103),[login]),user=result[x(0x104)][0x0];if(!user)throw new Error('User\x20not\x20found');if(permissionArg[x(0x105)]()===x(0x106))await pg['query']('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console['log']('Permissions\x20cleared\x20for\x20'+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission['split'](':'),actions=byResource['get'](resource)??[];actions[x(0x107)](action),byResource[x(0x108)](resource,actions);}const client=await pg[x(0x109)]();try{await client['query'](x(0x10a));for(const [resource,actions]of byResource){const existing=await client[x(0x102)](x(0x10b),[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client['query'](x(0x10c),[merged,user['id'],row['access_id']]);}else await client[x(0x102)]('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[x(0x102)]('COMMIT');}catch(e){await client[x(0x102)]('ROLLBACK');throw e;}finally{client['release']();}console['log']('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions['join'](',\x20'));}}catch(q){console['error'](q),process[x(0x10d)]=0x1;}finally{await pg['end']();}}
@@ -1 +1 @@
1
- import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';function s(){const Q=['permissions','auth','login','config','session','maxAge','audit','write','sessionId','type','fcore','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','credentials','Creates\x20a\x20regular\x20user\x20account.','Changes\x20the\x20password\x20for\x20the\x20current\x20user.','Not\x20authorized','user','logout','cookieName','Get\x20current\x20user','query','toISOString'];s=function(){return Q;};return s();}import p from'./services/get-current-user.js';import Z from'./services/registration.js';import A from'./services/change-password.js';import{authSchemas}from'./schema.js';import I from'../../shared/getIP.js';function f(p,Z){p=p-0x1ac;const A=s();let I=A[p];return I;}import{UnauthorizedError}from'../../errors.js';export function authRoutes(j){return async D=>{const E=f,o=async R=>{const h=f,B=R['method']==='GET'?R['query']:R['body'],H=I(R),e=await verifyUser({...B,'ip':H},j);e[h(0x1ac)]=await getUserPermissions(e['id'],j);const g=e['twofa']?j['config']['auth']['twoFactorRedirect']:j['config'][h(0x1ad)]['redirect'];await R[h(0x1ae)](e);const N=j[h(0x1af)]['auth']['sessionTimeout']*0x3e8*0x3c;return R[h(0x1b0)]?.['cookie']&&(R['session']['cookie'][h(0x1b1)]=N),await R['session']['save'](),await j[h(0x1b2)]?.[h(0x1b3)]?.({'module':h(0x1ad),'resource':'session','resourceId':R[h(0x1b0)][h(0x1b4)],'action':'login','userId':e['id'],'ipAddress':H}),{'user':{'id':e['id'],'type':e[h(0x1b5)],'permissions':e['permissions']},'redirectUrl':g};};D['get']('/api/auth/login',{'schema':{'tags':[E(0x1b6),E(0x1ad)],'summary':'Sign\x20in','description':E(0x1b7),'access':'public','permissions':[],'querystring':authSchemas[E(0x1b8)]}},o),D['post']('/api/auth/login',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'body':authSchemas['credentials']}},o),D['post']('/api/auth/registration',{'schema':{'tags':['fcore',E(0x1ad)],'summary':'Register','description':E(0x1b9),'access':'admin','permissions':['user:create'],'body':authSchemas[E(0x1b8)]}},async R=>Z(R['body'],j)),D['post']('/api/auth/password',{'schema':{'tags':[E(0x1b6),E(0x1ad)],'summary':'Change\x20password','description':E(0x1ba),'access':'user','permissions':[],'body':authSchemas['password']}},async R=>{const a=E;if(!R['user'])throw new UnauthorizedError(a(0x1bb));return await A({'userId':R[a(0x1bc)]['id'],...R['body']},j),{'success':!![]};}),D['post']('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(R,B)=>{const X=E,H={'redirectUrl':'/'};if(!R['user'])return H;return await j['audit']?.[X(0x1b3)]?.({'module':'auth','resource':'session','resourceId':R['session']['sessionId'],'action':X(0x1bd),'userId':R['user']?.['id']}),await R['session']['destroy'](),B['clearCookie'](j['config'][X(0x1ad)][X(0x1be)]),Object['defineProperty'](R,'session',{'value':null,'writable':![],'configurable':![]}),H;}),D['get']('/api/auth/user',{'schema':{'tags':['fcore','auth'],'summary':E(0x1bf),'description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas[E(0x1c0)]}},async R=>{const K=E;return p({'user':R['user'],'token':R['query']['token'],'maxAge':R[K(0x1b0)]?.['cookie']?.['maxAge'],'originalExpires':R[K(0x1b0)]?.['cookie']?.['originalExpires']?.[K(0x1c1)]?.()});});};}
1
+ import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import S from'./services/get-current-user.js';import Z from'./services/registration.js';import h from'./services/change-password.js';function c(S,Z){S=S-0x97;const h=O();let U=h[S];return U;}import{authSchemas}from'./schema.js';function O(){const r=['GET','query','auth','twoFactorRedirect','login','sessionTimeout','session','save','audit','type','permissions','/api/auth/login','credentials','fcore','public','Register','user:create','body','Change\x20password','user','password','destroy','clearCookie','defineProperty','/api/auth/user','cookie','toISOString'];O=function(){return r;};return O();}import U from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(D){return async u=>{const i=c,e=async q=>{const X=c,x=q['method']===X(0x97)?q[X(0x98)]:q['body'],n=U(q),N=await verifyUser({...x,'ip':n},D);N['permissions']=await getUserPermissions(N['id'],D);const o=N['twofa']?D['config'][X(0x99)][X(0x9a)]:D['config']['auth']['redirect'];await q[X(0x9b)](N);const j=D['config'][X(0x99)][X(0x9c)]*0x3e8*0x3c;return q[X(0x9d)]?.['cookie']&&(q['session']['cookie']['maxAge']=j),await q['session'][X(0x9e)](),await D[X(0x9f)]?.['write']?.({'module':'auth','resource':'session','resourceId':q['session']['sessionId'],'action':'login','userId':N['id'],'ipAddress':n}),{'user':{'id':N['id'],'type':N[X(0xa0)],'permissions':N[X(0xa1)]},'redirectUrl':o};};u['get'](i(0xa2),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':'public','permissions':[],'querystring':authSchemas[i(0xa3)]}},e),u['post'](i(0xa2),{'schema':{'tags':[i(0xa4),i(0x99)],'summary':'Sign\x20in','description':'Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','access':i(0xa5),'permissions':[],'body':authSchemas['credentials']}},e),u['post']('/api/auth/registration',{'schema':{'tags':['fcore','auth'],'summary':i(0xa6),'description':'Creates\x20a\x20regular\x20user\x20account.','access':'admin','permissions':[i(0xa7)],'body':authSchemas['credentials']}},async q=>Z(q[i(0xa8)],D)),u['post']('/api/auth/password',{'schema':{'tags':['fcore','auth'],'summary':i(0xa9),'description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':i(0xaa),'permissions':[],'body':authSchemas[i(0xab)]}},async q=>{const l=i;if(!q['user'])throw new UnauthorizedError('Not\x20authorized');return await h({'userId':q[l(0xaa)]['id'],...q['body']},D),{'success':!![]};}),u['post']('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':'user','permissions':[]}},async(q,x)=>{const b=i,n={'redirectUrl':'/'};if(!q['user'])return n;return await D[b(0x9f)]?.['write']?.({'module':'auth','resource':b(0x9d),'resourceId':q['session']['sessionId'],'action':'logout','userId':q[b(0xaa)]?.['id']}),await q['session'][b(0xac)](),x[b(0xad)](D['config']['auth']['cookieName']),Object[b(0xae)](q,'session',{'value':null,'writable':![],'configurable':![]}),n;}),u['get'](i(0xaf),{'schema':{'tags':['fcore','auth'],'summary':'Get\x20current\x20user','description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas[i(0x98)]}},async q=>{const Y=i;return S({'user':q['user'],'token':q['query']['token'],'maxAge':q['session']?.[Y(0xb0)]?.['maxAge'],'originalExpires':q['session']?.['cookie']?.['originalExpires']?.[Y(0xb1)]?.()});});};}
@@ -1 +1 @@
1
- function s(){const Z=['String'];s=function(){return Z;};return s();}function f(p,Z){p=p-0x1cc;const A=s();let I=A[p];return I;}const p=f;import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type['Boolean']())}),'credentials':Type['Object']({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type[p(0x1cc)]({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type[p(0x1cc)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type[p(0x1cc)]({'minLength':0x1})})};
1
+ const S=c;function c(S,Z){S=S-0x6e;const h=O();let U=h[S];return U;}function O(){const Z=['Object','Optional','String'];O=function(){return Z;};return O();}import{Type}from'@sinclair/typebox';export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type['Boolean']())}),'credentials':Type[S(0x6e)]({'user':Type['String']({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type[S(0x6f)](Type[S(0x70)]({'minLength':0x1,'maxLength':0x64}))}),'password':Type[S(0x6e)]({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type[S(0x70)]({'minLength':0x1})})};
@@ -1 +1 @@
1
- import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:p,password:Z,userId:A},{pg:I}){const j=await hashPassword(Z);await I['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',[j,p||A,A]);}
1
+ import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:S,password:Z,userId:h},{pg:U}){const u=c,D=await hashPassword(Z);await U[u(0x17c)]('UPDATE\x20admin.users\x0a\x20\x20\x20\x20\x20SET\x20password_hash\x20=\x20$1,\x20updated_at\x20=\x20now(),\x20updated_by\x20=\x20$3\x0a\x20\x20\x20\x20\x20WHERE\x20uid\x20=\x20$2',[D,S||h,h]);}function c(S,Z){S=S-0x17c;const h=O();let U=h[S];return U;}function O(){const e=['query'];O=function(){return e;};return O();}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0xf8;const A=s();let I=A[p];return I;}import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(p){const D=f,{user:Z}=p;if(!Z)return{};if(p[D(0xf8)]){const {jwtSignToken:A}=await import('../../../plugins/jwt.js'),I=await A(Z);Z['token']=I;}return Z['resources']=[...new Set(Z?.['permissions']['map'](j=>j['split'](':')[0x0]))],{...safeUser(Z),'session':{'maxAge':p[D(0xf9)],'originalExpires':p[D(0xf9)]}};}function s(){const o=['token','maxAge'];s=function(){return o;};return s();}
1
+ import{safeUser}from'../../utils/safe-user.js';function O(){const e=['../../../plugins/jwt.js','token','maxAge'];O=function(){return e;};return O();}function c(S,Z){S=S-0x1d5;const h=O();let U=h[S];return U;}export default async function getCurrentUser(S){const u=c,{user:Z}=S;if(!Z)return{};if(S['token']){const {jwtSignToken:h}=await import(u(0x1d5)),U=await h(Z);Z[u(0x1d6)]=U;}return Z['resources']=[...new Set(Z?.['permissions']['map'](D=>D['split'](':')[0x0]))],{...safeUser(Z),'session':{'maxAge':S['maxAge'],'originalExpires':S[u(0x1d7)]}};}
@@ -1 +1 @@
1
- function s(){const B=['query','rows','Login\x20is\x20already\x20in\x20use'];s=function(){return B;};return s();}function f(p,Z){p=p-0x188;const A=s();let I=A[p];return I;}import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:p,password:Z,type:A},{pg:I}){const R=f,j=await hashPassword(Z),D=await I[R(0x188)]('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',[p,j,A||'regular']),o=D[R(0x189)][0x0];if(!o)throw new ConflictError(R(0x18a));return{'user':o};}
1
+ import{ConflictError}from'../../../errors.js';function c(S,Z){S=S-0x144;const h=O();let U=h[S];return U;}import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:S,password:Z,type:h},{pg:U}){const q=c,D=await hashPassword(Z),u=await U['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',[S,D,h||q(0x144)]),e=u['rows'][0x0];if(!e)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':e};}function O(){const x=['regular'];O=function(){return x;};return O();}
@@ -1 +1 @@
1
- import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(p,Z){return unsupported('Two-factor\x20provider');}
1
+ function O(){var U=['Two-factor\x20provider'];O=function(){return U;};return O();}function c(S,Z){S=S-0xb5;var h=O();var U=h[S];return U;}import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(S,Z){var h=c;return unsupported(h(0xb5));}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0x1cb;var A=s();var I=A[p];return I;}var p=f;export default new Set([p(0x1cb),p(0x1cc),'image/gif','image/webp','image/bmp','image/tiff','image/svg+xml','image/x-icon','image/avif','application/pdf','application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',p(0x1cd),p(0x1ce),'application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet',p(0x1cf),'text/plain',p(0x1d0),p(0x1d1),p(0x1d2),'application/xml','text/xml','application/geo+json','application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed','application/x-7z-compressed',p(0x1d3),p(0x1d4),'application/gzip','application/x-gzip',p(0x1d5),'audio/mpeg',p(0x1d6),'audio/ogg',p(0x1d7),p(0x1d8),'video/mp4','video/mpeg',p(0x1d9),'video/quicktime','video/x-msvideo','application/octet-stream']);function s(){var Z=['image/jpeg','image/png','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.presentation','text/csv','text/markdown','application/json','application/x-rar-compressed','application/vnd.rar','application/x-tar','audio/wav','audio/webm','audio/mp4','video/webm'];s=function(){return Z;};return s();}
1
+ function O(){var Z=['image/webp','application/pdf','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.ms-powerpoint','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet','text/markdown','application/x-7z-compressed','audio/mpeg','audio/ogg','audio/mp4','video/quicktime','video/x-msvideo'];O=function(){return Z;};return O();}function c(S,Z){S=S-0xed;var h=O();var U=h[S];return U;}var S=c;export default new Set(['image/jpeg','image/png','image/gif',S(0xed),'image/bmp','image/tiff','image/svg+xml','image/x-icon','image/avif',S(0xee),'application/msword',S(0xef),S(0xf0),'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',S(0xf1),'application/vnd.openxmlformats-officedocument.presentationml.presentation',S(0xf2),S(0xf3),'application/vnd.oasis.opendocument.presentation','text/plain','text/csv',S(0xf4),'application/json','application/xml','text/xml','application/geo+json','application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed',S(0xf5),'application/x-rar-compressed','application/vnd.rar','application/gzip','application/x-gzip','application/x-tar',S(0xf6),'audio/wav',S(0xf7),'audio/webm',S(0xf8),'video/mp4','video/mpeg','video/webm',S(0xf9),S(0xfa),'application/octet-stream']);
@@ -1 +1 @@
1
- import{fileTypeFromBuffer}from'file-type';function s(){const a=['get','public','fileToken','params','token','mime','query','download','image/','split','replace','file','Content-Disposition','attachment','inline','public,\x20max-age=86400,\x20immutable','Upload\x20file','resource','fields','resourceId','value','image/png','send'];s=function(){return a;};return s();}import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function f(p,Z){p=p-0x90;const A=s();let I=A[p];return I;}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(p){return async Z=>{const g=f;Z[g(0x90)]('/api/file/:token',{'schema':{'tags':['fcore','file'],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':g(0x91),'permissions':[],'params':fileSchemas[g(0x92)],'querystring':fileSchemas['fileDownloadQuery']}},async(A,I)=>{const N=g,j=p['file']['verify'](A[N(0x93)][N(0x94)]),D=await getFile({'pathOrToken':j},p),o=await fileTypeFromBuffer(D),R=o?.[N(0x95)]??'application/octet-stream',B=A[N(0x96)][N(0x97)]===!![],H=R['startsWith'](N(0x98))||R==='application/pdf',e=j[N(0x99)]('/')['pop']()?.[N(0x9a)](/[^A-Za-z0-9._-]/g,'_')??N(0x9b);return I['type'](R),I['header'](N(0x9c),(B||!H?N(0x9d):N(0x9e))+';\x20filename=\x22'+e+'\x22')['header']('Cache-Control',N(0x9f)),I['send'](D);}),Z['post']('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':g(0xa0),'description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async A=>{const h=g,I=await A['file']();if(!I)throw new Error('File\x20is\x20required');return uploadFile({'file':I,'metadata':{'name':I['filename'],'path':I['fields']['path']?.['value'],'resource':I['fields'][h(0xa1)]?.['value'],'resourceId':I[h(0xa2)][h(0xa3)]?.[h(0xa4)]},'user':A['user']},p);}),Z['get']('/api/file/:token/resize',{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':'user','permissions':['files:read'],'params':fileSchemas[g(0x92)],'querystring':fileSchemas['resizeQuery']}},async(A,I)=>{const E=g,j=await resizeFile({'pathOrToken':p['file']?.['verify'](A['params']['token']),...A['query']},p),D=await fileTypeFromBuffer(j);return I['type'](D?.[E(0x95)]??E(0xa5)),I['header'](E(0x9c),'inline')['header']('Cache-Control','public,\x20max-age=86400,\x20immutable'),I[E(0xa6)](j);});};}
1
+ import{fileTypeFromBuffer}from'file-type';import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';function c(S,Z){S=S-0x88;const h=O();let U=h[S];return U;}function O(){const l=['Get\x20file\x20by\x20token','fileDownloadQuery','download','application/pdf','pop','attachment','Cache-Control','public,\x20max-age=86400,\x20immutable','post','Upload\x20file','files:create','value','Resize\x20file','Returns\x20a\x20resized\x20image\x20file.','fileToken','file','token'];O=function(){return l;};return O();}import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(S){return async Z=>{const o=c;Z['get']('/api/file/:token',{'schema':{'tags':['fcore','file'],'summary':o(0x88),'description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas[o(0x89)]}},async(h,U)=>{const j=o,D=S['file']['verify'](h['params']['token']),u=await getFile({'pathOrToken':D},S),e=await fileTypeFromBuffer(u),q=e?.['mime']??'application/octet-stream',x=h['query'][j(0x8a)]===!![],n=q['startsWith']('image/')||q===j(0x8b),N=D['split']('/')[j(0x8c)]()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??'file';return U['type'](q),U['header']('Content-Disposition',(x||!n?j(0x8d):'inline')+';\x20filename=\x22'+N+'\x22')['header'](j(0x8e),j(0x8f)),U['send'](u);}),Z[o(0x90)]('/api/file/upload',{'schema':{'tags':['fcore','file'],'summary':o(0x91),'description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':[o(0x92)]}},async h=>{const X=o,U=await h['file']();if(!U)throw new Error('File\x20is\x20required');return uploadFile({'file':U,'metadata':{'name':U['filename'],'path':U['fields']['path']?.['value'],'resource':U['fields']['resource']?.[X(0x93)],'resourceId':U['fields']['resourceId']?.[X(0x93)]},'user':h['user']},S);}),Z['get']('/api/file/:token/resize',{'schema':{'tags':['fcore','file'],'summary':o(0x94),'description':o(0x95),'access':'user','permissions':['files:read'],'params':fileSchemas[o(0x96)],'querystring':fileSchemas['resizeQuery']}},async(h,U)=>{const i=o,D=await resizeFile({'pathOrToken':S[i(0x97)]?.['verify'](h['params'][i(0x98)]),...h['query']},S),u=await fileTypeFromBuffer(D);return U['type'](u?.['mime']??'image/png'),U['header']('Content-Disposition','inline')['header']('Cache-Control',i(0x8f)),U['send'](D);});};}
@@ -1 +1 @@
1
- const p=f;function s(){const Z=['String','Optional','Object','Integer','Union','Literal','fill','inside'];s=function(){return Z;};return s();}import{Type}from'@sinclair/typebox';function f(p,Z){p=p-0xcf;const A=s();let I=A[p];return I;}export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type[p(0xcf)]({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type[p(0xd0)](Type[p(0xcf)]({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type[p(0xd1)]({'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))}),'resizeQuery':Type[p(0xd1)]({'width':Type['Optional'](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type[p(0xd0)](Type[p(0xd2)]({'minimum':0x1})),'fit':Type['Optional'](Type[p(0xd3)]([Type['Literal']('cover'),Type[p(0xd4)]('contain'),Type['Literal'](p(0xd5)),Type['Literal'](p(0xd6)),Type['Literal']('outside')]))})};
1
+ const S=c;function c(S,Z){S=S-0x1aa;const h=O();let U=h[S];return U;}import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type[S(0x1aa)]({'id':Type[S(0x1ab)]({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type[S(0x1ab)]({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type[S(0x1aa)]({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type[S(0x1aa)]({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type[S(0x1aa)]({'file':Type[S(0x1ac)](),'metadata':Type['Object']({'name':Type[S(0x1ad)](Type[S(0x1ab)]({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type[S(0x1ab)]({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type[S(0x1aa)]({'entityType':Type[S(0x1ad)](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type[S(0x1ab)]({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type[S(0x1ad)](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type[S(0x1ae)]([Type['Literal']('cover'),Type['Literal'](S(0x1af)),Type[S(0x1b0)]('fill'),Type['Literal'](S(0x1b1)),Type['Literal']('outside')]))})};function O(){const Z=['Object','String','Any','Optional','Union','contain','Literal','inside'];O=function(){return Z;};return O();}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0x93;var A=s();var I=A[p];return I;}function s(){var I=['file','File\x20not\x20found','pathOrToken'];s=function(){return I;};return s();}import{NotFoundError}from'../../../errors.js';export async function getFile(p,Z){var A=f;if(!Z['file'])throw new Error('empty\x20file');if(!await Z[A(0x93)]['exists'](p['pathOrToken']))throw new NotFoundError(A(0x94)+p['pathOrToken']);return Z['file']['get'](p[A(0x95)]);}
1
+ function O(){var U=['pathOrToken','File\x20not\x20found'];O=function(){return U;};return O();}import{NotFoundError}from'../../../errors.js';function c(S,Z){S=S-0x1c9;var h=O();var U=h[S];return U;}export async function getFile(S,Z){var h=c;if(!Z['file'])throw new Error('empty\x20file');if(!await Z['file']['exists'](S[h(0x1c9)]))throw new NotFoundError(h(0x1ca)+S['pathOrToken']);return Z['file']['get'](S['pathOrToken']);}
@@ -1 +1 @@
1
- function s(){const X=['pathOrToken','height','fit','.jpg','code','ENOENT','exists','File\x20not\x20found','mime','startsWith','toBuffer','isInteger','\x20must\x20be\x20a\x20positive\x20integer'];s=function(){return X;};return s();}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 p from'node:path';import Z from'sharp';function f(p,Z){p=p-0xfb;const A=s();let I=A[p];return I;}export async function resizeFile(A,I){const E=f,j=A[E(0xfb)]??A['path'];if(!j)throw new ValidationError('File\x20path\x20is\x20required');const D=parseDimension(A['width'],'width')??0xc8,o=parseDimension(A[E(0xfc)],'height'),R=createHash('sha256')['update'](j+':'+D+':'+(o??'auto')+':'+(A[E(0xfd)]??'cover'))['digest']('hex'),B=p['resolve']('logs','resize'),H=p['join'](B,R+E(0xfe));try{return await readFile(H);}catch(h){if(h[E(0xff)]!==E(0x100))throw h;}if(!await I['file'][E(0x101)](j))throw new NotFoundError(E(0x102));const e=await I['file']['get'](j),g=await fileTypeFromBuffer(e);if(!g?.[E(0x103)][E(0x104)]('image/'))throw new ValidationError('Only\x20image\x20files\x20can\x20be\x20resized');const N=await Z(e)['resize']({'width':D,'height':o,'fit':A['fit']??'cover'})[E(0x105)]();return await mkdir(B,{'recursive':!![]}),await writeFile(H,N),N;}function parseDimension(A,I){const a=f;if(A===undefined||A==='')return undefined;const j=Number(A);if(!Number[a(0x106)](j)||j<=0x0)throw new ValidationError(I+a(0x107));return j;}
1
+ import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';function c(S,Z){S=S-0xb6;const h=O();let U=h[S];return U;}import{mkdir,readFile,writeFile}from'node:fs/promises';import S from'node:path';import Z from'sharp';function O(){const b=['width','sha256','auto','join','file','get','isInteger'];O=function(){return b;};return O();}export async function resizeFile(h,U){const i=c,D=h['pathOrToken']??h['path'];if(!D)throw new ValidationError('File\x20path\x20is\x20required');const u=parseDimension(h[i(0xb6)],'width')??0xc8,e=parseDimension(h['height'],'height'),q=createHash(i(0xb7))['update'](D+':'+u+':'+(e??i(0xb8))+':'+(h['fit']??'cover'))['digest']('hex'),x=S['resolve']('logs','resize'),n=S[i(0xb9)](x,q+'.jpg');try{return await readFile(n);}catch(X){if(X['code']!=='ENOENT')throw X;}if(!await U[i(0xba)]['exists'](D))throw new NotFoundError('File\x20not\x20found');const N=await U['file'][i(0xbb)](D),o=await fileTypeFromBuffer(N);if(!o?.['mime']['startsWith']('image/'))throw new ValidationError('Only\x20image\x20files\x20can\x20be\x20resized');const j=await Z(N)['resize']({'width':u,'height':e,'fit':h['fit']??'cover'})['toBuffer']();return await mkdir(x,{'recursive':!![]}),await writeFile(n,j),j;}function parseDimension(h,U){const l=c;if(h===undefined||h==='')return undefined;const D=Number(h);if(!Number[l(0xbc)](D)||D<=0x0)throw new ValidationError(U+'\x20must\x20be\x20a\x20positive\x20integer');return D;}
@@ -1 +1 @@
1
- import{fileTypeFromBuffer}from'file-type';import p from'../mime.js';import{randomUUID}from'node:crypto';import{ValidationError}from'../../../errors.js';export async function uploadFile(Z,A){const E=f,I=(Z[E(0x1db)]['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),j=new Date(),D=String(j['getFullYear']())['slice'](-0x2),o=String(j['getMonth']()+0x1)['padStart'](0x2,'0'),R=String(j[E(0x1dc)]())['padStart'](0x2,'0'),B=Z[E(0x1db)][E(0x1dd)]??(Z['metadata'][E(0x1de)]?Z['metadata'][E(0x1de)]+'/'+(Z[E(0x1db)]['resourceId']??randomUUID())+'/'+I:null)??'uploads/'+D+'/'+o+'-'+R+'/'+I,H=await Z['file'][E(0x1df)](),e=await fileTypeFromBuffer(H);if(!p['has'](Z['file'][E(0x1e0)])&&(e?.['mime']?!p[E(0x1e1)](e['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+Z['file']['mimetype']);const g=Boolean(Z['metadata']['resource']&&Z[E(0x1db)][E(0x1e2)]);if(g){const h=await A['pg']['query']('SELECT\x20file_id\x20FROM\x20admin.files\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20AND\x20file_name\x20=\x20$3\x0a\x20\x20\x20\x20\x20\x20\x20LIMIT\x201',[Z['metadata'][E(0x1de)],String(Z['metadata']['resourceId']),I]);if((h['rowCount']??0x0)>0x0)throw new ValidationError('File\x20with\x20name\x20\x22'+I+E(0x1e3)+Z[E(0x1db)]['resource']+E(0x1e4)+Z['metadata'][E(0x1e2)]+'\x22');}await A[E(0x1e5)][E(0x1e6)](B,H);const N=await A['pg'][E(0x1e7)]('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20file_type,\x20size,\x20uploaded_name,\x20file_name,\x20ext,\x20status,\x20created_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,\x20$10)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20',[Z[E(0x1db)][E(0x1de)]??null,Z['metadata'][E(0x1e2)]??null,B,Z[E(0x1e5)]['mimetype'],Z['file']['file']['bytesRead'],Z['metadata'][E(0x1e8)],I,Z['file']['mimetype']['split']('/')['pop']()??null,g?'attached':'pending',Z['user']?.['id']??null]);return{...N['rows'][0x0],'token':A['file'][E(0x1e9)](B)};}function f(p,Z){p=p-0x1db;const A=s();let I=A[p];return I;}function s(){const a=['metadata','getDate','path','resource','toBuffer','mimetype','has','resourceId','\x22\x20already\x20exists\x20for\x20resource\x20\x22','\x22\x20and\x20id\x20\x22','file','put','query','name','create'];s=function(){return a;};return s();}
1
+ function O(){const l=['metadata','slice','getMonth','padStart','getDate','resource','mime','Unsupported\x20file\x20type:\x20','resourceId','put','mimetype','file','name','attached','rows'];O=function(){return l;};return O();}import{fileTypeFromBuffer}from'file-type';import S from'../mime.js';import{randomUUID}from'node:crypto';function c(S,Z){S=S-0x125;const h=O();let U=h[S];return U;}import{ValidationError}from'../../../errors.js';export async function uploadFile(Z,h){const i=c,U=(Z[i(0x125)]['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),D=new Date(),u=String(D['getFullYear']())[i(0x126)](-0x2),e=String(D[i(0x127)]()+0x1)[i(0x128)](0x2,'0'),q=String(D[i(0x129)]())[i(0x128)](0x2,'0'),x=Z[i(0x125)]['path']??(Z['metadata']['resource']?Z['metadata'][i(0x12a)]+'/'+(Z['metadata']['resourceId']??randomUUID())+'/'+U:null)??'uploads/'+u+'/'+e+'-'+q+'/'+U,n=await Z['file']['toBuffer'](),N=await fileTypeFromBuffer(n);if(!S['has'](Z['file']['mimetype'])&&(N?.[i(0x12b)]?!S['has'](N[i(0x12b)]):!![]))throw new Error(i(0x12c)+Z['file']['mimetype']);const o=Boolean(Z[i(0x125)][i(0x12a)]&&Z['metadata']['resourceId']);if(o){const X=await h['pg']['query']('SELECT\x20file_id\x20FROM\x20admin.files\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20resource\x20=\x20$1\x20AND\x20resource_id\x20=\x20$2\x20AND\x20file_name\x20=\x20$3\x0a\x20\x20\x20\x20\x20\x20\x20LIMIT\x201',[Z[i(0x125)][i(0x12a)],String(Z['metadata']['resourceId']),U]);if((X['rowCount']??0x0)>0x0)throw new ValidationError('File\x20with\x20name\x20\x22'+U+'\x22\x20already\x20exists\x20for\x20resource\x20\x22'+Z['metadata'][i(0x12a)]+'\x22\x20and\x20id\x20\x22'+Z['metadata'][i(0x12d)]+'\x22');}await h['file'][i(0x12e)](x,n);const j=await h['pg']['query']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20file_type,\x20size,\x20uploaded_name,\x20file_name,\x20ext,\x20status,\x20created_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,\x20$10)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20',[Z['metadata']['resource']??null,Z['metadata']['resourceId']??null,x,Z['file'][i(0x12f)],Z[i(0x130)]['file']['bytesRead'],Z['metadata'][i(0x131)],U,Z['file'][i(0x12f)]['split']('/')['pop']()??null,o?i(0x132):'pending',Z['user']?.['id']??null]);return{...j[i(0x133)][0x0],'token':h['file']['create'](x)};}
@@ -1 +1 @@
1
- import{listResources}from'./services/list-resources.js';import{listResourceAsUser}from'./services/list-resource-as-user.js';import{getResource}from'./services/get-resource.js';import{createResource}from'./services/create-resource.js';function s(){const N=['Search\x20resource','user','query','/api/suggest/:resource/:field','fcore','Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','$resource:read','config','resource','Export\x20resource\x20records','exportResourceQuery','params','Returns\x20the\x20resource\x20variables\x20and\x20nested\x20relation\x20schema.','Generates\x20a\x20code\x20from\x20an\x20explicit\x20template\x20or\x20a\x20field\x20code_template.','/api/resource/:resource/scope/:user','List\x20resource\x20as\x20a\x20user\x20for\x20scope\x20testing','system:access','get','/api/resource/:resource','List\x20resource\x20records','auth','post','Create\x20resource\x20record','$resource:create','resourceIncludeQuery','Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','resourceId','body','/api/resource/:resource/:id','Delete\x20resource\x20record','Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','$resource:update','uploadResourceFile','fields','value','Deletes\x20a\x20file\x20linked\x20to\x20a\x20resource\x20record\x20after\x20validating\x20it\x20belongs\x20to\x20this\x20resource\x20and\x20record.','rowCount','file','delete','resourceIdRelation','/api/resource/:resource/:id/:relation','Create\x20resource\x20relation','Updates\x20a\x20related\x20resource\x20record.','resourceIdRelationId'];s=function(){return N;};return s();}import{updateResource}from'./services/update-resource.js';import{deleteResource}from'./services/delete-resource.js';import{listResourceRelation}from'./services/list-resource-relation.js';import{createResourceRelation}from'./services/create-resource-relation.js';import{updateResourceRelation}from'./services/update-resource-relation.js';import{deleteResourceRelation}from'./services/delete-resource-relation.js';import{searchResource}from'./services/search-resource.js';import{exportResource}from'./services/export-resource.js';import{suggestResource}from'./services/suggest-resource.js';import{listResourceList}from'./services/list-resource-list.js';function f(p,Z){p=p-0x1a2;const A=s();let I=A[p];return I;}import{getResourceSchema}from'./services/get-resource-schema.js';import{generateResourceCode}from'./services/generate-resource-code.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=p=>p['user'];export function resourceRoutes(p){return async Z=>{const H=f;Z['get']('/api/resource/:resource/search',{'schema':{'tags':['fcore','resource'],'summary':H(0x1a2),'description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':H(0x1a3),'permissions':['$resource:read'],'params':resourceSchemas['resource']}},async A=>searchResource({...A[H(0x1a4)],...A['params'],'user':user(A)||p['config']?.['auth']?.['user']},p)),Z['get'](H(0x1a5),{'schema':{'tags':[H(0x1a6),'resource'],'summary':'Suggest\x20resource\x20values','description':H(0x1a7),'access':'user','permissions':[H(0x1a8)],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas['suggestQuery']}},async A=>suggestResource({...A['query'],...A['params'],'user':user(A)||p[H(0x1a9)]?.['auth']?.['user']},p)),Z['get']('/api/resource/:resource/export',{'schema':{'tags':[H(0x1a6),H(0x1aa)],'summary':H(0x1ab),'description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':H(0x1a3),'permissions':['$resource:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas[H(0x1ac)]}},async A=>exportResource({...A[H(0x1a4)],...A[H(0x1ad)],'user':user(A)||p['config']?.['auth']?.[H(0x1a3)]},p)),Z['get']('/api/resource/:resource/schema',{'schema':{'tags':['fcore',H(0x1aa)],'summary':'Get\x20resource\x20schema','description':H(0x1ae),'access':'user','permissions':[H(0x1a8)],'params':resourceSchemas[H(0x1aa)]}},async A=>getResourceSchema(A[H(0x1ad)],p)),Z['get']('/api/resource/:resource/code',{'schema':{'tags':['fcore','resource'],'summary':'Generate\x20a\x20resource\x20code','description':H(0x1af),'access':'user','permissions':['$resource:read'],'params':resourceSchemas[H(0x1aa)],'querystring':resourceSchemas['resourceCodeQuery']}},async A=>generateResourceCode({...A['params'],...A[H(0x1a4)]},p)),Z['get'](H(0x1b0),{'schema':{'tags':['fcore','resource'],'summary':H(0x1b1),'description':'Returns\x20resource\x20records\x20using\x20the\x20specified\x20user\x27s\x20permissions\x20and\x20access\x20scopes.\x20Admin\x20only.','access':'admin','permissions':[H(0x1b2)],'params':resourceSchemas['resourceScopeTarget']}},async A=>listResourceAsUser({...A['params'],...A['query'],'requester':user(A)},p)),Z[H(0x1b3)](H(0x1b4),{'schema':{'tags':['fcore',H(0x1aa)],'summary':H(0x1b5),'description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas[H(0x1aa)]}},async A=>listResources({...A['query'],...A[H(0x1ad)],'user':user(A)||p['config']?.[H(0x1b6)]?.['user']},p)),Z[H(0x1b7)](H(0x1b4),{'schema':{'tags':[H(0x1a6),'resource'],'summary':H(0x1b8),'description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':H(0x1a3),'permissions':[H(0x1b9)],'params':resourceSchemas['resource']}},async A=>createResource({...A[H(0x1ad)],'data':A['body'],'user':user(A)||p['config']?.['auth']?.['user']},p)),Z['get']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[H(0x1a8)],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas[H(0x1ba)]}},async A=>getResource({...A['query'],...A[H(0x1ad)],'user':user(A)||p['config']?.['auth']?.[H(0x1a3)]},p)),Z['put']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20record','description':H(0x1bb),'access':H(0x1a3),'permissions':['$resource:update'],'params':resourceSchemas[H(0x1bc)]}},async A=>updateResource({...A['params'],'patch':A[H(0x1bd)],'user':user(A)||p[H(0x1a9)]?.['auth']?.['user']},p)),Z['delete'](H(0x1be),{'schema':{'tags':['fcore',H(0x1aa)],'summary':H(0x1bf),'description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':H(0x1a3),'permissions':['$resource:delete'],'params':resourceSchemas['resourceId']}},async A=>deleteResource({...A['params'],'user':user(A)||p[H(0x1a9)]?.[H(0x1b6)]?.['user']},p)),Z['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':[H(0x1a6),H(0x1aa)],'summary':'Upload\x20resource\x20file','description':H(0x1c0),'access':'user','permissions':[H(0x1c1)],'params':resourceSchemas[H(0x1c2)]}},async A=>{const e=H,I=await A['file']();if(!I)throw new Error('File\x20is\x20required');const j=A['params']['resource'],D=A['params']['id'];return uploadFile({'file':I,'metadata':{'name':I['filename'],'path':I[e(0x1c3)]['path']?.[e(0x1c4)],'resource':j,'resourceId':D},'user':A['user']},p);}),Z['delete']('/api/resource/:resource/:id/file/:fid',{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20file','description':H(0x1c5),'access':H(0x1a3),'permissions':['$resource:update'],'params':resourceSchemas['resourceIdFileId']}},async A=>{const g=H,{resource:I,id:j,fid:D}=A['params'],o=await p['pg']['query']('SELECT\x20file_path\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3\x20LIMIT\x201',[D,I,String(j)]);if(!o[g(0x1c6)])throw new Error('File\x20not\x20found\x20for\x20this\x20resource\x20and\x20record');const R=o['rows'][0x0]?.['file_path'],B=await p['pg']['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[D,I,String(j)]);return await p[g(0x1c7)][g(0x1c8)](R),{'success':(B['rowCount']??0x0)>0x0,'resource':I,'resourceId':j,'fileId':D};}),Z['get']('/api/resource/:resource/list',{'schema':{'tags':['fcore',H(0x1aa)],'summary':'List\x20resource\x20items','description':'Returns\x20resource\x20identifiers\x20and\x20display\x20text,\x20optionally\x20filtered\x20by\x20searchable\x20fields.','access':H(0x1a3),'permissions':['$resource:read'],'params':resourceSchemas['resource'],'querystring':resourceSchemas['resourceListQuery']}},async A=>listResourceList({...A['params'],...A[H(0x1a4)],'user':user(A)||p['config']?.['auth']?.['user']},p)),Z[H(0x1b3)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20relations','description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':H(0x1a3),'params':resourceSchemas[H(0x1c9)],'permissions':['$resource:read']}},async A=>listResourceRelation({...A[H(0x1a4)],...A['params'],'user':user(A)||p['config']?.['auth']?.['user']},p)),Z['post'](H(0x1ca),{'schema':{'tags':[H(0x1a6),'resource'],'summary':H(0x1cb),'description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':H(0x1a3),'permissions':['$resource:create'],'params':resourceSchemas[H(0x1c9)]}},async A=>createResourceRelation({...A['params'],'data':A[H(0x1bd)],'user':user(A)||p[H(0x1a9)]?.['auth']?.[H(0x1a3)]},p)),Z[H(0x1c8)]('/api/resource/:resource/:id/:relation/:relationId',{'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 A=>deleteResourceRelation({...A['params'],'user':user(A)||p[H(0x1a9)]?.['auth']?.['user']},p)),Z['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20relation','description':H(0x1cc),'access':'user','permissions':[H(0x1c1)],'params':resourceSchemas[H(0x1cd)]}},async A=>updateResourceRelation({...A['params'],'data':A[H(0x1bd)],'user':user(A)||p[H(0x1a9)]?.['auth']?.[H(0x1a3)]},p));};}
1
+ import{listResources}from'./services/list-resources.js';import{listResourceAsUser}from'./services/list-resource-as-user.js';import{getResource}from'./services/get-resource.js';function O(){const j=['fcore','Search\x20resource','resource','config','auth','get','/api/suggest/:resource/:field','$resource:read','params','exportResource','user','Get\x20resource\x20schema','/api/resource/:resource/code','resourceCodeQuery','query','Returns\x20resource\x20records\x20using\x20the\x20specified\x20user\x27s\x20permissions\x20and\x20access\x20scopes.\x20Admin\x20only.','admin','system:access','/api/resource/:resource/:id','Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','put','body','post','/api/resource/:resource/:id/upload','Upload\x20resource\x20file','Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','$resource:update','File\x20is\x20required','/api/resource/:resource/:id/file/:fid','Delete\x20resource\x20file','Deletes\x20a\x20file\x20linked\x20to\x20a\x20resource\x20record\x20after\x20validating\x20it\x20belongs\x20to\x20this\x20resource\x20and\x20record.','File\x20not\x20found\x20for\x20this\x20resource\x20and\x20record','delete','Returns\x20resource\x20identifiers\x20and\x20display\x20text,\x20optionally\x20filtered\x20by\x20searchable\x20fields.','List\x20resource\x20relations','/api/resource/:resource/:id/:relation','Create\x20resource\x20relation','resourceIdRelation','Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','resourceIdRelationId'];O=function(){return j;};return O();}function c(S,Z){S=S-0x105;const h=O();let U=h[S];return U;}import{createResource}from'./services/create-resource.js';import{updateResource}from'./services/update-resource.js';import{deleteResource}from'./services/delete-resource.js';import{listResourceRelation}from'./services/list-resource-relation.js';import{createResourceRelation}from'./services/create-resource-relation.js';import{updateResourceRelation}from'./services/update-resource-relation.js';import{deleteResourceRelation}from'./services/delete-resource-relation.js';import{searchResource}from'./services/search-resource.js';import{exportResource}from'./services/export-resource.js';import{suggestResource}from'./services/suggest-resource.js';import{listResourceList}from'./services/list-resource-list.js';import{getResourceSchema}from'./services/get-resource-schema.js';import{generateResourceCode}from'./services/generate-resource-code.js';import{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=S=>S['user'];export function resourceRoutes(S){return async Z=>{const n=c;Z['get']('/api/resource/:resource/search',{'schema':{'tags':[n(0x105),'resource'],'summary':n(0x106),'description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas[n(0x107)]}},async h=>searchResource({...h['query'],...h['params'],'user':user(h)||S[n(0x108)]?.[n(0x109)]?.['user']},S)),Z[n(0x10a)](n(0x10b),{'schema':{'tags':[n(0x105),'resource'],'summary':'Suggest\x20resource\x20values','description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':'user','permissions':[n(0x10c)],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas['suggestQuery']}},async h=>suggestResource({...h['query'],...h[n(0x10d)],'user':user(h)||S['config']?.[n(0x109)]?.['user']},S)),Z['get']('/api/resource/:resource/export',{'schema':{'tags':['fcore',n(0x107)],'summary':'Export\x20resource\x20records','description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[n(0x10c)],'params':resourceSchemas[n(0x10e)],'querystring':resourceSchemas['exportResourceQuery']}},async h=>exportResource({...h['query'],...h['params'],'user':user(h)||S[n(0x108)]?.['auth']?.[n(0x10f)]},S)),Z[n(0x10a)]('/api/resource/:resource/schema',{'schema':{'tags':['fcore','resource'],'summary':n(0x110),'description':'Returns\x20the\x20resource\x20variables\x20and\x20nested\x20relation\x20schema.','access':n(0x10f),'permissions':[n(0x10c)],'params':resourceSchemas['resource']}},async h=>getResourceSchema(h[n(0x10d)],S)),Z['get'](n(0x111),{'schema':{'tags':['fcore','resource'],'summary':'Generate\x20a\x20resource\x20code','description':'Generates\x20a\x20code\x20from\x20an\x20explicit\x20template\x20or\x20a\x20field\x20code_template.','access':n(0x10f),'permissions':[n(0x10c)],'params':resourceSchemas['resource'],'querystring':resourceSchemas[n(0x112)]}},async h=>generateResourceCode({...h['params'],...h[n(0x113)]},S)),Z['get']('/api/resource/:resource/scope/:user',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20as\x20a\x20user\x20for\x20scope\x20testing','description':n(0x114),'access':n(0x115),'permissions':[n(0x116)],'params':resourceSchemas['resourceScopeTarget']}},async h=>listResourceAsUser({...h[n(0x10d)],...h['query'],'requester':user(h)},S)),Z['get']('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resource']}},async h=>listResources({...h['query'],...h[n(0x10d)],'user':user(h)||S['config']?.[n(0x109)]?.['user']},S)),Z['post']('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:create'],'params':resourceSchemas['resource']}},async h=>createResource({...h['params'],'data':h['body'],'user':user(h)||S['config']?.['auth']?.['user']},S)),Z['get'](n(0x117),{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20record','description':n(0x118),'access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async h=>getResource({...h['query'],...h[n(0x10d)],'user':user(h)||S[n(0x108)]?.[n(0x109)]?.['user']},S)),Z[n(0x119)]('/api/resource/:resource/:id',{'schema':{'tags':['fcore',n(0x107)],'summary':'Update\x20resource\x20record','description':'Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['resourceId']}},async h=>updateResource({...h['params'],'patch':h[n(0x11a)],'user':user(h)||S[n(0x108)]?.['auth']?.['user']},S)),Z['delete']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20record','description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:delete'],'params':resourceSchemas['resourceId']}},async h=>deleteResource({...h['params'],'user':user(h)||S['config']?.['auth']?.['user']},S)),Z[n(0x11b)](n(0x11c),{'schema':{'tags':['fcore',n(0x107)],'summary':n(0x11d),'description':n(0x11e),'access':'user','permissions':[n(0x11f)],'params':resourceSchemas['uploadResourceFile']}},async h=>{const N=n,U=await h['file']();if(!U)throw new Error(N(0x120));const D=h['params']['resource'],u=h['params']['id'];return uploadFile({'file':U,'metadata':{'name':U['filename'],'path':U['fields']['path']?.['value'],'resource':D,'resourceId':u},'user':h[N(0x10f)]},S);}),Z['delete'](n(0x121),{'schema':{'tags':['fcore','resource'],'summary':n(0x122),'description':n(0x123),'access':n(0x10f),'permissions':['$resource:update'],'params':resourceSchemas['resourceIdFileId']}},async h=>{const o=n,{resource:U,id:D,fid:u}=h['params'],e=await S['pg']['query']('SELECT\x20file_path\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3\x20LIMIT\x201',[u,U,String(D)]);if(!e['rowCount'])throw new Error(o(0x124));const q=e['rows'][0x0]?.['file_path'],x=await S['pg']['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[u,U,String(D)]);return await S['file'][o(0x125)](q),{'success':(x['rowCount']??0x0)>0x0,'resource':U,'resourceId':D,'fileId':u};}),Z['get']('/api/resource/:resource/list',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20items','description':n(0x126),'access':n(0x10f),'permissions':['$resource:read'],'params':resourceSchemas['resource'],'querystring':resourceSchemas['resourceListQuery']}},async h=>listResourceList({...h[n(0x10d)],...h['query'],'user':user(h)||S['config']?.['auth']?.['user']},S)),Z[n(0x10a)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore',n(0x107)],'summary':n(0x127),'description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':'user','params':resourceSchemas['resourceIdRelation'],'permissions':[n(0x10c)]}},async h=>listResourceRelation({...h['query'],...h['params'],'user':user(h)||S['config']?.['auth']?.['user']},S)),Z['post'](n(0x128),{'schema':{'tags':[n(0x105),'resource'],'summary':n(0x129),'description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':'user','permissions':['$resource:create'],'params':resourceSchemas[n(0x12a)]}},async h=>createResourceRelation({...h['params'],'data':h['body'],'user':user(h)||S['config']?.[n(0x109)]?.['user']},S)),Z[n(0x125)]('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[n(0x105),'resource'],'summary':'Delete\x20resource\x20relation','description':n(0x12b),'access':'user','permissions':['$resource:delete'],'params':resourceSchemas[n(0x12c)]}},async h=>deleteResourceRelation({...h['params'],'user':user(h)||S['config']?.['auth']?.[n(0x10f)]},S)),Z['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20relation','description':'Updates\x20a\x20related\x20resource\x20record.','access':n(0x10f),'permissions':['$resource:update'],'params':resourceSchemas[n(0x12c)]}},async h=>updateResourceRelation({...h['params'],'data':h['body'],'user':user(h)||S['config']?.['auth']?.[n(0x10f)]},S));};}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0x15b;const A=s();let I=A[p];return I;}function s(){const Z=['String','^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$','Object','Integer','Optional','Array'];s=function(){return Z;};return s();}const p=f;import{Type}from'@sinclair/typebox';export const identifier=Type[p(0x15b)]({'minLength':0x1,'maxLength':0x80,'pattern':p(0x15c)});export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type[p(0x15d)]({'resource':identifier}),'resourceScopeTarget':Type['Object']({'resource':identifier,'user':identifier}),'exportResource':Type['Object']({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type['Optional'](Type['String']()),'search':Type['Optional'](Type[p(0x15b)]()),'limit':Type['Optional'](Type[p(0x15e)]({'minimum':0x1,'maximum':0xc8}))}),'resourceListQuery':Type['Object']({'search':Type['Optional'](Type['String']()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceCodeQuery':Type['Object']({'id':Type[p(0x15f)](Type[p(0x15b)]({'minLength':0x1,'maxLength':0x80})),'field':Type[p(0x15f)](identifier),'template':Type['Optional'](Type['String']({'maxLength':0x3e8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type['Object']({'include':Type['Optional'](Type['String']({'minLength':0x1}))}),'resourceIdRelation':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'resourceIdFileId':Type['Object']({'resource':identifier,'id':identifier,'fid':identifier}),'uploadResourceFile':Type[p(0x15d)]({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type[p(0x15d)]({'filter':Type['Optional'](Type['Record'](Type[p(0x15b)](),Type['Unknown']())),'sort':Type[p(0x15f)](Type['Array'](Type['String']({'minLength':0x1}))),'search':Type[p(0x15f)](Type['String']()),'scope':Type['Optional'](Type['String']()),'limit':Type[p(0x15f)](Type[p(0x15e)]({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type['Integer']({'minimum':0x0})),'fields':Type[p(0x15f)](Type[p(0x160)](identifier))})};
1
+ const S=c;import{Type}from'@sinclair/typebox';function c(S,Z){S=S-0x12d;const h=O();let U=h[S];return U;}export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});function O(){const Z=['Object','Optional','String','Integer','Array'];O=function(){return Z;};return O();}export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type[S(0x12d)]({'resource':identifier}),'resourceScopeTarget':Type['Object']({'resource':identifier,'user':identifier}),'exportResource':Type[S(0x12d)]({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type[S(0x12e)](Type['String']()),'search':Type['Optional'](Type[S(0x12f)]()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceListQuery':Type[S(0x12d)]({'search':Type[S(0x12e)](Type[S(0x12f)]()),'limit':Type[S(0x12e)](Type[S(0x130)]({'minimum':0x1,'maximum':0xc8}))}),'resourceCodeQuery':Type['Object']({'id':Type[S(0x12e)](Type['String']({'minLength':0x1,'maxLength':0x80})),'field':Type[S(0x12e)](identifier),'template':Type['Optional'](Type['String']({'maxLength':0x3e8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type['Object']({'include':Type['Optional'](Type[S(0x12f)]({'minLength':0x1}))}),'resourceIdRelation':Type[S(0x12d)]({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier,'relationId':identifier}),'resourceIdFileId':Type['Object']({'resource':identifier,'id':identifier,'fid':identifier}),'uploadResourceFile':Type['Object']({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type[S(0x12d)]({'filter':Type['Optional'](Type['Record'](Type[S(0x12f)](),Type['Unknown']())),'sort':Type['Optional'](Type['Array'](Type['String']({'minLength':0x1}))),'search':Type['Optional'](Type['String']()),'scope':Type['Optional'](Type['String']()),'limit':Type[S(0x12e)](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type['Integer']({'minimum':0x0})),'fields':Type['Optional'](Type[S(0x131)](identifier))})};
@@ -1 +1 @@
1
- export async function addNote(p,Z){const A=await Z['pg']['query']('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[p['resource'],String(p['id']),p['body']]);return A['rows'][0x0];}
1
+ function c(S,Z){S=S-0x145;const h=O();let U=h[S];return U;}export async function addNote(S,Z){const U=c,h=await Z['pg'][U(0x145)]('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[S['resource'],String(S['id']),S['body']]);return h['rows'][0x0];}function O(){const D=['query'];O=function(){return D;};return O();}
@@ -1 +1 @@
1
- export async function addResourceFile(p,Z){const I=f,A=await Z['pg'][I(0xe1)]('\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',[p[I(0xe2)],String(p['id']),p[I(0xe3)],p['size']??null]);return A['rows'][0x0];}function f(p,Z){p=p-0xe1;const A=s();let I=A[p];return I;}function s(){const j=['query','resource','filePath'];s=function(){return j;};return s();}
1
+ export async function addResourceFile(S,Z){const U=c,h=await Z['pg'][U(0x84)]('\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',[S['resource'],String(S['id']),S['filePath'],S[U(0x85)]??null]);return h[U(0x86)][0x0];}function c(S,Z){S=S-0x84;const h=O();let U=h[S];return U;}function O(){const D=['query','size','rows'];O=function(){return D;};return O();}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0x1c8;const A=s();let I=A[p];return I;}export async function createResourceRelation(p,Z){const R=f,{resource:A,id:I,relation:j,data:D,user:o}=p;return Z[R(0x1c8)][R(0x1c9)]({'name':A,'id':I,'relation':j,'data':D,'user':o});}function s(){const B=['resource','createRelation'];s=function(){return B;};return s();}
1
+ function O(){const x=['createRelation'];O=function(){return x;};return O();}function c(S,Z){S=S-0x1b9;const h=O();let U=h[S];return U;}export async function createResourceRelation(S,Z){const q=c,{resource:h,id:U,relation:D,data:u,user:e}=S;return Z['resource'][q(0x1b9)]({'name':h,'id':U,'relation':D,'data':u,'user':e});}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0xae;var A=s();var I=A[p];return I;}export async function createResource(p,Z){var A=f;return Z[A(0xae)]['create']({'name':p[A(0xae)],'data':p['data'],'user':p['user']});}function s(){var I=['resource'];s=function(){return I;};return s();}
1
+ function c(S,Z){S=S-0x179;var h=O();var U=h[S];return U;}export async function createResource(S,Z){var h=c;return Z[h(0x179)]['create']({'name':S['resource'],'data':S[h(0x17a)],'user':S['user']});}function O(){var U=['resource','data'];O=function(){return U;};return O();}
@@ -1 +1 @@
1
- export async function deleteResourceRelation(p,Z){const {resource:A,id:I,relation:j,relationId:D}=p;return Z['resource']['deleteRelation']({'name':A,'id':I,'relation':j,'relationId':D});}
1
+ export async function deleteResourceRelation(S,Z){const {resource:h,id:U,relation:D,relationId:u}=S;return Z['resource']['deleteRelation']({'name':h,'id':U,'relation':D,'relationId':u});}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0x13b;var A=s();var I=A[p];return I;}function s(){var I=['resource'];s=function(){return I;};return s();}export async function deleteResource(p,Z){var A=f;return Z['resource']['delete']({'name':p[A(0x13b)],'id':p['id'],'user':p['user']});}
1
+ function c(S,Z){S=S-0x165;var h=O();var U=h[S];return U;}function O(){var U=['resource','user'];O=function(){return U;};return O();}export async function deleteResource(S,Z){var h=c;return Z[h(0x165)]['delete']({'name':S['resource'],'id':S['id'],'user':S[h(0x166)]});}
@@ -1 +1 @@
1
- function f(p,Z){p=p-0x8e;const A=s();let I=A[p];return I;}function s(){const j=['resource','limit','offset','rows'];s=function(){return j;};return s();}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function exportResource(p,Z){const I=f,A=await Z[I(0x8e)]['find']({'name':p[I(0x8e)],'query':{'filter':parseFilterQuery(p),'sort':p['sort'],'search':p['search'],'limit':p[I(0x8f)],'offset':p[I(0x90)],'fields':p['fields']},'user':p['user']});return A[I(0x91)];}
1
+ function c(S,Z){S=S-0x1ba;const h=O();let U=h[S];return U;}function O(){const D=['sort','search'];O=function(){return D;};return O();}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function exportResource(S,Z){const U=c,h=await Z['resource']['find']({'name':S['resource'],'query':{'filter':parseFilterQuery(S),'sort':S[U(0x1ba)],'search':S[U(0x1bb)],'limit':S['limit'],'offset':S['offset'],'fields':S['fields']},'user':S['user']});return h['rows'];}
@@ -1 +1 @@
1
- function s(){const V=['key','column','query','SELECT\x20*\x20FROM\x20','table','where','\x20<>\x20$','length','\x20AND\x20','created_at','SELECT\x20count(*)::int\x20+\x201\x20AS\x20num,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(*)\x20FILTER\x20(WHERE\x20','\x20>=\x20',')::int\x20+\x201\x20AS\x20ynum,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(*)\x20FILTER\x20(WHERE\x20','\x20t\x20','rows','mnum','num','field','code_template','has','resource','set'];s=function(){return V;};return s();}function f(p,Z){p=p-0xfb;const A=s();let I=A[p];return I;}import{ValidationError}from'../../../errors.js';import{qi,qt}from'../../../plugins/resource/utils/sql.js';function relationValue(p,Z,A){const I=Z['fields'][A]?.['column']??A;return p[I]??p[A];}async function resolvePath(p,Z,A,I){const K=f,[j,...D]=p['split']('.');if(!j)return undefined;const o=A['relations']?.[j];if(!o||!D['length']||!o['resource'])return relationValue(Z,A,p);const R=I['resource']['get'](o['resource']),B=R[K(0xfb)];let H,e;if(o['localKey'])H=relationValue(Z,A,o['localKey']),e=B;else{if(o['foreignKey'])H=relationValue(Z,A,A['key']),e=o['foreignKey'];else return undefined;}if(H===null||H===undefined)return undefined;const g=R['fields'][e]?.[K(0xfc)]??e,N=await I['pg'][K(0xfd)](K(0xfe)+qt(R[K(0xff)])+'\x20t\x20WHERE\x20t.'+qi(g)+'\x20=\x20$1'+(o['where']?'\x20AND\x20('+o['where']+')':'')+'\x20LIMIT\x201',[H]),h=N['rows'][0x0];if(!h)return undefined;const E=D[0x0];if(!E)return undefined;if(D['length']===0x1)return relationValue(h,R,E);return resolvePath(D['join']('.'),h,R,I);}async function countValues(p,Z,A,I){const Q=f,j=[],D=p['where']?['('+p[Q(0x100)]+')']:[];Z!==undefined&&(j['push'](Z),D['push']('t.'+qi(p[Q(0xfb)])+Q(0x101)+j['length']));const o=D[Q(0x102)]?'WHERE\x20'+D['join'](Q(0x103)):'',R=p['fields'][Q(0x104)],B=R?'t.'+qi(R['column']??'created_at'):undefined,H=new Date(I['getFullYear'](),0x0,0x1),e=new Date(I['getFullYear'](),I['getMonth'](),0x1);if(B){j['push'](H,e);const h='$'+(j['length']-0x1),E='$'+j['length'],a=await A['pg']['query'](Q(0x105)+B+Q(0x106)+h+Q(0x107)+B+'\x20>=\x20'+E+')::int\x20+\x201\x20AS\x20mnum\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20'+qt(p['table'])+Q(0x108)+o,j),X=a[Q(0x109)][0x0];return{'num':Number(X?.['num']??0x1),'ynum':Number(X?.['ynum']??0x1),'mnum':Number(X?.[Q(0x10a)]??0x1)};}const g=await A['pg']['query']('SELECT\x20count(*)::int\x20+\x201\x20AS\x20num\x20FROM\x20'+qt(p['table'])+'\x20t\x20'+o,j),N=Number(g['rows'][0x0]?.[Q(0x10b)]??0x1);return{'num':N,'ynum':N,'mnum':N};}export async function generateResourceCode(p,Z){const G=f,A=Z['resource']['get'](p['resource']);if(p['field']&&!A['fields'][p['field']])throw new ValidationError('Unknown\x20resource\x20field:\x20'+p[G(0x10c)]);const I=p['template']??(p['field']?A['fields'][p['field']]?.[G(0x10d)]:undefined);if(!I)return{'resource':A['name'],...p['id']!==undefined?{'id':p['id']}:{},...p['field']?{'field':p[G(0x10c)]}:{},'template':null,'code':null};const j=new Date(),D=await countValues(A,p['id'],Z,j);let o={};if(p['id']!==undefined){const e=await Z['pg']['query'](G(0xfe)+qt(A[G(0xff)])+'\x20t\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20t.'+qi(A['key'])+'\x20=\x20$1'+(A['where']?'\x20AND\x20('+A[G(0x100)]+')':'')+'\x0a\x20\x20\x20\x20\x20\x20\x20LIMIT\x201',[p['id']]);o=e[G(0x109)][0x0]??{};}const R=[...I['matchAll'](/\{([A-Za-z_][A-Za-z0-9_.]*)(?::(\d+))?\}/g)],B=new Map();for(const g of R){const N=g[0x1];if(!N||B[G(0x10e)](g[0x0]))continue;const h=Number(g[0x2]??0x0);let E;switch(N){case G(0x10b):E=D['num'];break;case'ynum':E=D['ynum'];break;case G(0x10a):E=D['mnum'];break;case'yyyy':E=String(j['getFullYear']());break;case'yy':E=String(j['getFullYear']())['slice'](-0x2);break;case'mm':E=String(j['getMonth']()+0x1)['padStart'](0x2,'0');break;case'dd':E=String(j['getDate']())['padStart'](0x2,'0');break;case G(0x10f):E=A['name'];break;case'resource_id':E=p['id'];break;default:E=p['id']===undefined?undefined:await resolvePath(N,o,A,Z);}if(E===null||E===undefined||E==='')throw new ValidationError('Cannot\x20resolve\x20code\x20template\x20variable:\x20{'+N+'}');const a=String(E);B[G(0x110)](g[0x0],h&&/^\d+$/['test'](a)?a['padStart'](h,'0'):a);}const H=I['replace'](/\{([A-Za-z_][A-Za-z0-9_.]*)(?::(\d+))?\}/g,X=>B['get'](X)??X);return{'resource':A['name'],...p['id']!==undefined?{'id':p['id']}:{},...p['field']?{'field':p['field']}:{},'template':I,'code':H};}
1
+ function c(S,Z){S=S-0x11f;const h=O();let U=h[S];return U;}import{ValidationError}from'../../../errors.js';import{qi,qt}from'../../../plugins/resource/utils/sql.js';function O(){const L=['split','length','resource','localKey','key','rows','column','getMonth','SELECT\x20count(*)::int\x20+\x201\x20AS\x20num,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(*)\x20FILTER\x20(WHERE\x20',')::int\x20+\x201\x20AS\x20mnum\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20','\x20t\x20','num','field','fields','where','\x0a\x20\x20\x20\x20\x20\x20\x20LIMIT\x201','matchAll','has','ynum','mnum','yyyy','getFullYear','slice','padStart','replace','name'];O=function(){return L;};return O();}function relationValue(S,Z,h){const U=Z['fields'][h]?.['column']??h;return S[U]??S[h];}async function resolvePath(S,Z,h,U){const Y=c,[D,...u]=S[Y(0x11f)]('.');if(!D)return undefined;const e=h['relations']?.[D];if(!e||!u[Y(0x120)]||!e['resource'])return relationValue(Z,h,S);const q=U['resource']['get'](e[Y(0x121)]),x=q['key'];let n,N;if(e[Y(0x122)])n=relationValue(Z,h,e['localKey']),N=x;else{if(e['foreignKey'])n=relationValue(Z,h,h[Y(0x123)]),N=e['foreignKey'];else return undefined;}if(n===null||n===undefined)return undefined;const o=q['fields'][N]?.['column']??N,j=await U['pg']['query']('SELECT\x20*\x20FROM\x20'+qt(q['table'])+'\x20t\x20WHERE\x20t.'+qi(o)+'\x20=\x20$1'+(e['where']?'\x20AND\x20('+e['where']+')':'')+'\x20LIMIT\x201',[n]),X=j[Y(0x124)][0x0];if(!X)return undefined;const i=u[0x0];if(!i)return undefined;if(u['length']===0x1)return relationValue(X,q,i);return resolvePath(u['join']('.'),X,q,U);}async function countValues(S,Z,h,U){const r=c,D=[],u=S['where']?['('+S['where']+')']:[];Z!==undefined&&(D['push'](Z),u['push']('t.'+qi(S['key'])+'\x20<>\x20$'+D[r(0x120)]));const e=u['length']?'WHERE\x20'+u['join']('\x20AND\x20'):'',q=S['fields']['created_at'],x=q?'t.'+qi(q[r(0x125)]??'created_at'):undefined,n=new Date(U['getFullYear'](),0x0,0x1),N=new Date(U['getFullYear'](),U[r(0x126)](),0x1);if(x){D['push'](n,N);const X='$'+(D['length']-0x1),i='$'+D['length'],l=await h['pg']['query'](r(0x127)+x+'\x20>=\x20'+X+')::int\x20+\x201\x20AS\x20ynum,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(*)\x20FILTER\x20(WHERE\x20'+x+'\x20>=\x20'+i+r(0x128)+qt(S['table'])+'\x20t\x20'+e,D),b=l[r(0x124)][0x0];return{'num':Number(b?.['num']??0x1),'ynum':Number(b?.['ynum']??0x1),'mnum':Number(b?.['mnum']??0x1)};}const o=await h['pg']['query']('SELECT\x20count(*)::int\x20+\x201\x20AS\x20num\x20FROM\x20'+qt(S['table'])+r(0x129)+e,D),j=Number(o['rows'][0x0]?.[r(0x12a)]??0x1);return{'num':j,'ynum':j,'mnum':j};}export async function generateResourceCode(S,Z){const E=c,h=Z['resource']['get'](S[E(0x121)]);if(S['field']&&!h['fields'][S['field']])throw new ValidationError('Unknown\x20resource\x20field:\x20'+S['field']);const U=S['template']??(S[E(0x12b)]?h[E(0x12c)][S[E(0x12b)]]?.['code_template']:undefined);if(!U)return{'resource':h['name'],...S['id']!==undefined?{'id':S['id']}:{},...S[E(0x12b)]?{'field':S['field']}:{},'template':null,'code':null};const D=new Date(),u=await countValues(h,S['id'],Z,D);let e={};if(S['id']!==undefined){const N=await Z['pg']['query']('SELECT\x20*\x20FROM\x20'+qt(h['table'])+'\x20t\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20t.'+qi(h[E(0x123)])+'\x20=\x20$1'+(h['where']?'\x20AND\x20('+h[E(0x12d)]+')':'')+E(0x12e),[S['id']]);e=N[E(0x124)][0x0]??{};}const q=[...U[E(0x12f)](/\{([A-Za-z_][A-Za-z0-9_.]*)(?::(\d+))?\}/g)],x=new Map();for(const o of q){const j=o[0x1];if(!j||x[E(0x130)](o[0x0]))continue;const X=Number(o[0x2]??0x0);let i;switch(j){case E(0x12a):i=u['num'];break;case E(0x131):i=u['ynum'];break;case E(0x132):i=u[E(0x132)];break;case E(0x133):i=String(D[E(0x134)]());break;case'yy':i=String(D['getFullYear']())[E(0x135)](-0x2);break;case'mm':i=String(D['getMonth']()+0x1)['padStart'](0x2,'0');break;case'dd':i=String(D['getDate']())['padStart'](0x2,'0');break;case'resource':i=h['name'];break;case'resource_id':i=S['id'];break;default:i=S['id']===undefined?undefined:await resolvePath(j,e,h,Z);}if(i===null||i===undefined||i==='')throw new ValidationError('Cannot\x20resolve\x20code\x20template\x20variable:\x20{'+j+'}');const l=String(i);x['set'](o[0x0],X&&/^\d+$/['test'](l)?l[E(0x136)](X,'0'):l);}const n=U[E(0x137)](/\{([A-Za-z_][A-Za-z0-9_.]*)(?::(\d+))?\}/g,b=>x['get'](b)??b);return{'resource':h[E(0x138)],...S['id']!==undefined?{'id':S['id']}:{},...S['field']?{'field':S['field']}:{},'template':U,'code':n};}