@opengis/fcore 0.0.1-beta.25 → 0.0.1-beta.27

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 (142) 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.d.ts.map +1 -1
  12. package/dist/modules/auth/route.js +1 -1
  13. package/dist/modules/auth/schema.js +1 -1
  14. package/dist/modules/auth/services/change-password.js +1 -1
  15. package/dist/modules/auth/services/get-current-user.d.ts +2 -0
  16. package/dist/modules/auth/services/get-current-user.d.ts.map +1 -1
  17. package/dist/modules/auth/services/get-current-user.js +1 -1
  18. package/dist/modules/auth/services/registration.js +1 -1
  19. package/dist/modules/auth/services/verify-two-factor.js +1 -1
  20. package/dist/modules/file/mime.js +1 -1
  21. package/dist/modules/file/route.js +1 -1
  22. package/dist/modules/file/schema.js +1 -1
  23. package/dist/modules/file/services/get-file.js +1 -1
  24. package/dist/modules/file/services/resize-file.js +1 -1
  25. package/dist/modules/file/services/upload-file.js +1 -1
  26. package/dist/modules/resource/route.d.ts.map +1 -1
  27. package/dist/modules/resource/route.js +1 -1
  28. package/dist/modules/resource/schema.d.ts +13 -0
  29. package/dist/modules/resource/schema.d.ts.map +1 -1
  30. package/dist/modules/resource/schema.js +1 -1
  31. package/dist/modules/resource/services/add-note.js +1 -1
  32. package/dist/modules/resource/services/add-resource-file.js +1 -1
  33. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  34. package/dist/modules/resource/services/create-resource.js +1 -1
  35. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  36. package/dist/modules/resource/services/delete-resource.js +1 -1
  37. package/dist/modules/resource/services/export-resource.js +1 -1
  38. package/dist/modules/resource/services/generate-resource-code.d.ts +16 -0
  39. package/dist/modules/resource/services/generate-resource-code.d.ts.map +1 -0
  40. package/dist/modules/resource/services/generate-resource-code.js +1 -0
  41. package/dist/modules/resource/services/get-resource-schema.d.ts +6 -0
  42. package/dist/modules/resource/services/get-resource-schema.d.ts.map +1 -0
  43. package/dist/modules/resource/services/get-resource-schema.js +1 -0
  44. package/dist/modules/resource/services/get-resource.js +1 -1
  45. package/dist/modules/resource/services/list-resource-as-user.d.ts +8 -0
  46. package/dist/modules/resource/services/list-resource-as-user.d.ts.map +1 -0
  47. package/dist/modules/resource/services/list-resource-as-user.js +1 -0
  48. package/dist/modules/resource/services/list-resource-list.d.ts +20 -0
  49. package/dist/modules/resource/services/list-resource-list.d.ts.map +1 -0
  50. package/dist/modules/resource/services/list-resource-list.js +1 -0
  51. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  52. package/dist/modules/resource/services/list-resources.d.ts.map +1 -1
  53. package/dist/modules/resource/services/list-resources.js +1 -1
  54. package/dist/modules/resource/services/search-resource.js +1 -1
  55. package/dist/modules/resource/services/suggest-resource.js +1 -1
  56. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  57. package/dist/modules/resource/services/update-resource.js +1 -1
  58. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  59. package/dist/modules/system/route.d.ts.map +1 -1
  60. package/dist/modules/system/route.js +1 -1
  61. package/dist/modules/system/schema.d.ts +22 -0
  62. package/dist/modules/system/schema.d.ts.map +1 -1
  63. package/dist/modules/system/schema.js +1 -1
  64. package/dist/modules/system/services/check-system.js +1 -1
  65. package/dist/modules/system/services/get-access.js +1 -1
  66. package/dist/modules/system/services/get-api-list.js +1 -1
  67. package/dist/modules/system/services/get-audit-log.js +1 -1
  68. package/dist/modules/system/services/get-dictionary.js +1 -1
  69. package/dist/modules/system/services/get-resource-access.d.ts +23 -0
  70. package/dist/modules/system/services/get-resource-access.d.ts.map +1 -0
  71. package/dist/modules/system/services/get-resource-access.js +1 -0
  72. package/dist/modules/system/services/get-resource-scopes.d.ts +16 -0
  73. package/dist/modules/system/services/get-resource-scopes.d.ts.map +1 -0
  74. package/dist/modules/system/services/get-resource-scopes.js +1 -0
  75. package/dist/modules/system/services/get-system-log.js +1 -1
  76. package/dist/modules/system/services/get-system-settings.js +1 -1
  77. package/dist/modules/system/services/list-dictionaries.js +1 -1
  78. package/dist/modules/system/services/set-access.d.ts +1 -0
  79. package/dist/modules/system/services/set-access.d.ts.map +1 -1
  80. package/dist/modules/system/services/set-access.js +1 -1
  81. package/dist/modules/system/services/set-resource-access.d.ts +18 -0
  82. package/dist/modules/system/services/set-resource-access.d.ts.map +1 -0
  83. package/dist/modules/system/services/set-resource-access.js +1 -0
  84. package/dist/modules/system/services/set-resource-scopes.d.ts +10 -0
  85. package/dist/modules/system/services/set-resource-scopes.d.ts.map +1 -0
  86. package/dist/modules/system/services/set-resource-scopes.js +1 -0
  87. package/dist/modules/system/services/update-dictionary.js +1 -1
  88. package/dist/modules/system/services/update-system-settings.js +1 -1
  89. package/dist/modules/utils/require-admin.js +1 -1
  90. package/dist/modules/utils/safe-user.js +1 -1
  91. package/dist/modules/utils/unsupported.js +1 -1
  92. package/dist/plugins/audit/audit.js +1 -1
  93. package/dist/plugins/audit/services/write-audit.js +1 -1
  94. package/dist/plugins/auth/get-user-permissions.js +1 -1
  95. package/dist/plugins/auth/index.js +1 -1
  96. package/dist/plugins/auth/verifyUser.js +1 -1
  97. package/dist/plugins/dictionary.js +1 -1
  98. package/dist/plugins/file.js +1 -1
  99. package/dist/plugins/jwt.js +1 -1
  100. package/dist/plugins/logger/index.js +1 -1
  101. package/dist/plugins/logger/transport.js +1 -1
  102. package/dist/plugins/pg.js +1 -1
  103. package/dist/plugins/redis.js +1 -1
  104. package/dist/plugins/resource/resource.d.ts +1 -1
  105. package/dist/plugins/resource/resource.d.ts.map +1 -1
  106. package/dist/plugins/resource/resource.js +1 -1
  107. package/dist/plugins/resource/resource.registry.d.ts +3 -2
  108. package/dist/plugins/resource/resource.registry.d.ts.map +1 -1
  109. package/dist/plugins/resource/resource.registry.js +1 -1
  110. package/dist/plugins/resource/resource.types.d.ts +23 -4
  111. package/dist/plugins/resource/resource.types.d.ts.map +1 -1
  112. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  113. package/dist/plugins/resource/services/add-file-token.js +1 -1
  114. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  115. package/dist/plugins/resource/services/create-relation.js +1 -1
  116. package/dist/plugins/resource/services/create.js +1 -1
  117. package/dist/plugins/resource/services/delete-relation.js +1 -1
  118. package/dist/plugins/resource/services/delete.js +1 -1
  119. package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
  120. package/dist/plugins/resource/services/find-one.js +1 -1
  121. package/dist/plugins/resource/services/find-relation.js +1 -1
  122. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  123. package/dist/plugins/resource/services/find.js +1 -1
  124. package/dist/plugins/resource/services/get-table-columns.js +1 -1
  125. package/dist/plugins/resource/services/update-relation.js +1 -1
  126. package/dist/plugins/resource/services/update.js +1 -1
  127. package/dist/plugins/resource/utils/auto-index.js +1 -1
  128. package/dist/plugins/resource/utils/fields.js +1 -1
  129. package/dist/plugins/resource/utils/filters.js +1 -1
  130. package/dist/plugins/resource/utils/permissions.js +1 -1
  131. package/dist/plugins/resource/utils/scope.d.ts +10 -0
  132. package/dist/plugins/resource/utils/scope.d.ts.map +1 -0
  133. package/dist/plugins/resource/utils/scope.js +1 -0
  134. package/dist/plugins/resource/utils/sort.js +1 -1
  135. package/dist/plugins/resource/utils/sql.js +1 -1
  136. package/dist/plugins/resource/utils/summary.d.ts +5 -1
  137. package/dist/plugins/resource/utils/summary.d.ts.map +1 -1
  138. package/dist/plugins/resource/utils/summary.js +1 -1
  139. package/dist/shared/getIP.js +1 -1
  140. package/migrations/20260929120000_allow_user_only_role_scopes.sql +2 -0
  141. package/migrations/20260929_role_scope.sql +32 -0
  142. package/package.json +2 -2
package/dist/config.js CHANGED
@@ -1 +1 @@
1
- function f(){const H=['Missing\x20environment\x20variable:\x20','true','local','split','parse','logger','redis','auth'];f=function(){return H;};return f();}import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(w){const Z=Y,y=process.env[w];if(!y)throw new Error(Z(0xb8)+w);return y;}function Y(w,y){w=w-0xb8;const d=f();let Z=d[w];return Z;}export function loadConfig(w={}){const M=Y,y={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG===M(0xb9),'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']()===M(0xba)||!process.env.S3_ENDPOINT?M(0xba):'s3','storagePath':process.env.STORAGE_PATH??'./storage','redactionList':(process.env.REDACTION_LIST||'password')['split'](','),'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[M(0xbb)](',')['map'](d=>d-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+'/log'},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??'us-east-1','bucket':process.env.S3_BUCKET??'','accessKey':process.env.S3_ACCESS_KEY,'secretKey':process.env.S3_SECRET_KEY,'folder':process.env.S3_FOLDER,'forcePathStyle':process.env.S3_FORCE_PATH_STYLE!=='false','tokenSecret':process.env.FILE_TOKEN_SECRET,'tokenTtl':Number(process.env.FILE_TOKEN_TTL??0xe10)},'auth':{'accessToken':process.env.AUTH_ACCESS_TOKEN||'Ch7QR4e73Jg0wx0xOjm','user':process.env.AUTH_USER?JSON[M(0xbc)](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??'x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','cookieName':process.env.AUTH_COOKIE_NAME??'session_user_auth','jwtSecret':process.env.AUTH_JWT_SECRET??'0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','redirect':process.env.AUTH_REDIRECT??'/','twoFactorRedirect':process.env.AUTH_TWOFACTOR_REDIRECT??'/','cookieOptions':process.env.AUTH_COOKIE_OPTIONS_DOMAIN?{'domain':process.env.AUTH_COOKIE_OPTIONS_DOMAIN,'path':process.env.AUTH_COOKIE_OPTIONS_PATH||'/','httpOnly':Boolean(process.env.AUTH_COOKIE_OPTIONS_HTTP_ONLY||'true'),'secure':Boolean(process.env.AUTH_COOKIE_OPTIONS_SECURE||'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{...y,...w,'logger':{...y[M(0xbd)],...w[M(0xbd)]},'pg':{...y['pg'],...w['pg']},'redis':{...y['redis'],...w[M(0xbe)]},'s3':{...y['s3'],...w['s3']},'auth':{...y['auth'],...w[M(0xbf)]}};}export{required as requireEnv};
1
+ import'dotenv/config';const DEFAULT_LOG_RESPONSE_STATUS_CODES=[0x193,0x199,0x19d,0x19f,0x1ad];function required(h){const n=process.env[h];if(!n)throw new Error('Missing\x20environment\x20variable:\x20'+h);return n;}function Q(){const f=['./storage','split','true','map','parse','x5y30KBsEKCENT04tu6549Vxx3No1ztJ2q2K8r79S59420RaZ5','session_user_auth','0ua4b1Tz21m47z13U3EO0uN9e0WE7hqRFbcZ72cbdWqZBzemf9cAU865xan1s81TdNpUKKfF','strict','auth'];Q=function(){return f;};return Q();}export function loadConfig(h={}){const G=k,n={'env':process.env.NODE_ENV??'development','debug':process.env.DEBUG==='true','port':Number(process.env.PORT??0xbb8),'maxFileSize':+(process.env.MAX_FILE_SIZE||0x200),'rateLimit':{'disabled':process.env.RATE_LIMIT==='false','max':+(process.env.RATE_LIMIT_MAX||0x64),'timeWindow':+(process.env.RATE_LIMIT_TIME_WINDOW||0xea60)},'storageType':(process.env.STORAGE_TYPE??'s3')['toLowerCase']()==='local'||!process.env.S3_ENDPOINT?'local':'s3','storagePath':process.env.STORAGE_PATH??G(0x19c),'redactionList':(process.env.REDACTION_LIST||'password')[G(0x19d)](','),'logger':{'level':process.env.LOG_LEVEL??'info','responses':process.env.LOG_RESPONSES===G(0x19e)?!![]:![],'responseCodes':process.env.LOG_RESPONSE_STATUS_CODES?process.env.LOG_RESPONSE_STATUS_CODES['split'](',')[G(0x19f)](B=>B-0x0):DEFAULT_LOG_RESPONSE_STATUS_CODES,'directory':process.env.LOG_DIRECTORY||process['cwd']()+'/log'},'pg':{'host':process.env.PG_HOST??'localhost','port':Number(process.env.PG_PORT??0x1538),'database':process.env.PG_DATABASE??'','user':process.env.PG_USER??'','password':process.env.PG_PASSWORD??''},'redis':{'host':process.env.REDIS_HOST??'','port':Number(process.env.REDIS_PORT??0x18eb),'password':process.env.REDIS_PASSWORD,'lazyConnect':!![],'db':process.env.REDIS_DB?Number(process.env.REDIS_DB):undefined},'s3':{'endpoint':process.env.S3_ENDPOINT,'region':process.env.S3_REGION??'us-east-1','bucket':process.env.S3_BUCKET??'','accessKey':process.env.S3_ACCESS_KEY,'secretKey':process.env.S3_SECRET_KEY,'folder':process.env.S3_FOLDER,'forcePathStyle':process.env.S3_FORCE_PATH_STYLE!=='false','tokenSecret':process.env.FILE_TOKEN_SECRET,'tokenTtl':Number(process.env.FILE_TOKEN_TTL??0xe10)},'auth':{'accessToken':process.env.AUTH_ACCESS_TOKEN||'Ch7QR4e73Jg0wx0xOjm','user':process.env.AUTH_USER?JSON[G(0x1a0)](process.env.AUTH_USER):undefined,'sessionTimeout':+(process.env.AUTH_SESSION_TIMEOUT||0x258),'secret':process.env.AUTH_SECRET??G(0x1a1),'cookieName':process.env.AUTH_COOKIE_NAME??G(0x1a2),'jwtSecret':process.env.AUTH_JWT_SECRET??G(0x1a3),'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',G(0x1a4),'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{...n,...h,'logger':{...n['logger'],...h['logger']},'pg':{...n['pg'],...h['pg']},'redis':{...n['redis'],...h['redis']},'s3':{...n['s3'],...h['s3']},'auth':{...n[G(0x1a5)],...h['auth']}};}function k(h,n){h=h-0x19c;const B=Q();let G=B[h];return G;}export{required as requireEnv};
package/dist/context.js CHANGED
@@ -1 +1 @@
1
- function f(){const Z=['Application\x20context\x20is\x20not\x20initialized','allSettled','end'];f=function(){return Z;};return f();}let defaultContext;function Y(w,y){w=w-0x1a4;const d=f();let Z=d[w];return Z;}export function setContext(w){defaultContext=w;}export function getContext(){const y=Y;if(!defaultContext)throw new Error(y(0x1a4));return defaultContext;}export function createContext(w){return{...w,async 'close'(){const d=Y;await Promise[d(0x1a5)]([w['redis']?.['close'](),w['pg']?.[d(0x1a6)]()]),await w['logger']['close']();}};}
1
+ let defaultContext;function k(h,n){h=h-0x1e9;const B=Q();let G=B[h];return G;}function Q(){const B=['Application\x20context\x20is\x20not\x20initialized'];Q=function(){return B;};return Q();}export function setContext(h){defaultContext=h;}export function getContext(){const n=k;if(!defaultContext)throw new Error(n(0x1e9));return defaultContext;}export function createContext(h){return{...h,async 'close'(){await Promise['allSettled']([h['redis']?.['close'](),h['pg']?.['end']()]),await h['logger']['close']();}};}
package/dist/errors.js CHANGED
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x189;var d=f();var Z=d[w];return Z;}var M=Y;export class FCoreError extends Error{['code'];['statusCode'];['details'];constructor(w,y,d=0x1f4,Z){super(y),this['code']=w,this['statusCode']=d,this['details']=Z,this['name']=new.target.name;}}export class BadRequestError extends FCoreError{constructor(w,y){super('BAD_REQUEST_ERROR',w,0x190,y);}}export class UnauthorizedError extends FCoreError{constructor(w=M(0x189)){super('UNAUTHORIZED',w,0x191);}}export class ForbiddenError extends FCoreError{constructor(w='Access\x20denied'){super('FORBIDDEN',w,0x193);}}export class NotFoundError extends FCoreError{constructor(w='Not\x20found'){var H=M;super(H(0x18a),w,0x194);}}export class ConflictError extends FCoreError{constructor(w=M(0x18b)){super('CONFLICT',w,0x199);}}export class ValidationError extends FCoreError{constructor(w,y){super('VALIDATION_ERROR',w,0x1a6,y);}}export class UnsupportedError extends FCoreError{constructor(w='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',w,0x1f5);}}function f(){var Q=['Authentication\x20required','NOT_FOUND','Conflict'];f=function(){return Q;};return f();}
1
+ var f=k;export class FCoreError extends Error{[f(0x151)];['statusCode'];['details'];constructor(h,n,B=0x1f4,G){var j=f;super(n),this[j(0x151)]=h,this[j(0x152)]=B,this['details']=G,this[j(0x153)]=new.target.name;}}function Q(){var P=['code','statusCode','name','BAD_REQUEST_ERROR','FORBIDDEN','Not\x20found','Conflict','CONFLICT'];Q=function(){return P;};return Q();}export class BadRequestError extends FCoreError{constructor(h,n){var Z=f;super(Z(0x154),h,0x190,n);}}function k(h,n){h=h-0x151;var B=Q();var G=B[h];return G;}export class UnauthorizedError extends FCoreError{constructor(h='Authentication\x20required'){super('UNAUTHORIZED',h,0x191);}}export class ForbiddenError extends FCoreError{constructor(h='Access\x20denied'){var e=f;super(e(0x155),h,0x193);}}export class NotFoundError extends FCoreError{constructor(h=f(0x156)){super('NOT_FOUND',h,0x194);}}export class ConflictError extends FCoreError{constructor(h=f(0x157)){var b=f;super(b(0x158),h,0x199);}}export class ValidationError extends FCoreError{constructor(h,n){super('VALIDATION_ERROR',h,0x1a6,n);}}export class UnsupportedError extends FCoreError{constructor(h='Operation\x20is\x20not\x20configured'){super('UNSUPPORTED',h,0x1f5);}}
package/dist/fastify.js CHANGED
@@ -1 +1 @@
1
- import w 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';function Y(w,y){w=w-0xd7;const d=f();let Z=d[w];return Z;}import{systemRoutes}from'./modules/system/route.js';import{createSessionStore}from'./plugins/auth/index.js';import{ForbiddenError}from'./errors.js';function f(){const A=['split','decorate','method','fcore','tags','description','set','get','routeOptions','user','startsWith','public','User\x20required','type','Admin\x20access\x20required','replace','$resource','Missing\x20permission:\x20','setErrorHandler','statusCode','code','test','INTERNAL_ERROR','includes','auth','file','system','application/x-www-form-urlencoded','register','@fastify/rate-limit','max','preHandler','log'];f=function(){return A;};return f();}import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(y,d,Z){const G=Y,M=decodeURIComponent(d['toString']())[G(0xd7)]('&')['reduce']((H,Q)=>{const [s,j]=Q['split']('=');return{...H,[s]:j};},{});Z(null,M);}export default function fcoreFastify(y,d){return w(async Z=>{const U=Y;Z[U(0xd8)]('ctx',y);const {config:M}=y,H=new Map();Z['addHook']('onRoute',s=>{const E=U,j=s['schema'],n=Array['isArray'](s[E(0xd9)])?s['method']:[s['method']];for(const t of n){if(t==='HEAD')continue;const K={'method':t,'endpoint':s['url'],'package':j?.['package']??E(0xda),'tags':j?.[E(0xdb)]??[],'summary':j?.['summary']??'','description':j?.[E(0xdc)]??'','access':j?.['access']??'public','permissions':j?.['permissions']??[]};H[E(0xdd)](t+'\x20'+s['url'],K);}}),Z['addHook']('preHandler',async s=>{const e=U;if(s['routeOptions']['url']==='*')return!![];const j=H[e(0xde)](s['method']+'\x20'+s[e(0xdf)]['url']),n=!s['user']&&process['platform']==='win32'&&y['config']?.['auth']?.['user']?y['config']?.['auth']?.[e(0xe0)]:null,t=s['raw']['headers']?.['authorization'],K=t?.[e(0xe1)]('Bearer\x20')?t['slice'](0x7):null,T=s['user']??(K?await jwtVerifyToken(K):n);!s['user']&&K&&process.env.AUTH_JWT_SECRET&&(s[e(0xe0)]=await jwtVerifyToken(K));if(!j?.['access'])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(j['access']===e(0xe2))return!![];if(!T)throw new ForbiddenError(e(0xe3));if(j['access']==='user'&&!j['permissions']?.['length'])return!![];if(T[e(0xe4)]=='admin')return!![];if(j['access']==='admin')throw new ForbiddenError(e(0xe5));for(const h of j['permissions']){const i=h?.[e(0xe6)](e(0xe7),s['params']['resource']??'');if(!T['permissions']?.['includes'](i))throw new ForbiddenError(e(0xe8)+i);}return!![];}),await createSessionStore(Z,y),await Z['register'](import('@fastify/multipart'),{'limits':{'fileSize':M['maxFileSize']*0x400*0x400}}),Z[U(0xe9)]((s,j,n)=>{const l=U;if(s instanceof FCoreError||s['code']==='FST_ERR_VALIDATION'||s[l(0xea)]<0x1f4)return s[l(0xea)]<0x1f4&&y['logger']['warn'](s),n[l(0xeb)](s['statusCode'])['send']({'error':s[l(0xeb)],'message':s['message'],'details':s['details']});return y['logger']['error'](s),(M['debug']||process.env.NODE_ENV===l(0xec)||process.env.VITEST)&&console['error'](s),n['code'](0x1f4)['send']({'error':l(0xed),'message':'Internal\x20server\x20error'});});const Q=s=>!d||d[U(0xee)](s);if(Q(U(0xef)))await Z['register'](authRoutes(y));if(Q('resource'))await Z['register'](resourceRoutes(y));if(Q(U(0xf0)))await Z['register'](fileRoutes(y));if(Q(U(0xf1)))await Z['register'](systemRoutes(y,H));Z['addContentTypeParser'](U(0xf2),{'parseAs':'buffer'},urlencodedContentParser),!M['rateLimit']?.['disabled']?Z[U(0xf3)](import(U(0xf4)),{'max':M['rateLimit']?.[U(0xf5)]||0x64,'timeWindow':M['rateLimit']?.['timeWindow']||0xea60,'hook':U(0xf6),'global':!![],'keyGenerator':s=>(s['user']?.['id']||s['ip'])+'-'+s['raw']['url']['split']('?')[0x0]}):console[U(0xf7)]('⚠️\x20rate\x20limit\x20is\x20disabled');});}
1
+ import h from'fastify-plugin';import{FCoreError}from'./errors.js';function k(h,n){h=h-0x162;const B=Q();let G=B[h];return G;}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 Q(){const O=['reduce','onRoute','method','summary','description','url','win32','user','config','headers','authorization','startsWith','Bearer\x20','length','admin','$resource','maxFileSize','setErrorHandler','logger','message','details','error','code','send','auth','resource','register','application/x-www-form-urlencoded','buffer','disabled','@fastify/rate-limit','rateLimit','timeWindow','split','log'];Q=function(){return O;};return Q();}import{jwtVerifyToken}from'./plugins/jwt.js';function urlencodedContentParser(n,B,G){const z=k,f=decodeURIComponent(B['toString']())['split']('&')[z(0x162)]((j,Z)=>{const [e,b]=Z['split']('=');return{...j,[e]:b};},{});G(null,f);}export default function fcoreFastify(n,B){return h(async G=>{const t=k;G['decorate']('ctx',n);const {config:f}=n,j=new Map();G['addHook'](t(0x163),e=>{const m=t,b=e['schema'],P=Array['isArray'](e['method'])?e[m(0x164)]:[e[m(0x164)]];for(const u of P){if(u==='HEAD')continue;const X={'method':u,'endpoint':e['url'],'package':b?.['package']??'fcore','tags':b?.['tags']??[],'summary':b?.[m(0x165)]??'','description':b?.[m(0x166)]??'','access':b?.['access']??'public','permissions':b?.['permissions']??[]};j['set'](u+'\x20'+e['url'],X);}}),G['addHook']('preHandler',async e=>{const A=t;if(e['routeOptions']['url']==='*')return!![];const b=j['get'](e['method']+'\x20'+e['routeOptions'][A(0x167)]),P=!e['user']&&process['platform']===A(0x168)&&n['config']?.['auth']?.[A(0x169)]?n[A(0x16a)]?.['auth']?.['user']:null,u=e['raw'][A(0x16b)]?.[A(0x16c)],X=u?.[A(0x16d)](A(0x16e))?u['slice'](0x7):null,H=e[A(0x169)]??(X?await jwtVerifyToken(X):P);!e['user']&&X&&process.env.AUTH_JWT_SECRET&&(e[A(0x169)]=await jwtVerifyToken(X));if(!b?.['access'])throw new ForbiddenError('Route\x20access\x20not\x20defined');if(b['access']==='public')return!![];if(!H)throw new ForbiddenError('User\x20required');if(b['access']===A(0x169)&&!b['permissions']?.[A(0x16f)])return!![];if(H['type']==A(0x170))return!![];if(b['access']==='admin')throw new ForbiddenError('Admin\x20access\x20required');for(const i of b['permissions']){const p=i?.['replace'](A(0x171),e['params']['resource']??'');if(!H['permissions']?.['includes'](p))throw new ForbiddenError('Missing\x20permission:\x20'+p);}return!![];}),await createSessionStore(G,n),await G['register'](import('@fastify/multipart'),{'limits':{'fileSize':f[t(0x172)]*0x400*0x400}}),G[t(0x173)]((e,b,P)=>{const U=t;if(e instanceof FCoreError||e['code']==='FST_ERR_VALIDATION'||e['statusCode']<0x1f4)return e['statusCode']<0x1f4&&n[U(0x174)]['warn'](e),P['code'](e['statusCode'])['send']({'error':e['code'],'message':e[U(0x175)],'details':e[U(0x176)]});return n['logger'][U(0x177)](e),(f['debug']||process.env.NODE_ENV==='test'||process.env.VITEST)&&console[U(0x177)](e),P[U(0x178)](0x1f4)[U(0x179)]({'error':'INTERNAL_ERROR','message':'Internal\x20server\x20error'});});const Z=e=>!B||B['includes'](e);if(Z(t(0x17a)))await G['register'](authRoutes(n));if(Z(t(0x17b)))await G['register'](resourceRoutes(n));if(Z('file'))await G[t(0x17c)](fileRoutes(n));if(Z('system'))await G[t(0x17c)](systemRoutes(n,j));G['addContentTypeParser'](t(0x17d),{'parseAs':t(0x17e)},urlencodedContentParser),!f['rateLimit']?.[t(0x17f)]?G['register'](import(t(0x180)),{'max':f[t(0x181)]?.['max']||0x64,'timeWindow':f['rateLimit']?.[t(0x182)]||0xea60,'hook':'preHandler','global':!![],'keyGenerator':e=>(e['user']?.['id']||e['ip'])+'-'+e['raw'][t(0x167)][t(0x183)]('?')[0x0]}):console[t(0x184)]('⚠️\x20rate\x20limit\x20is\x20disabled');});}
package/dist/fcore.js CHANGED
@@ -1 +1 @@
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 Y(w,y){w=w-0x93;const d=f();let Z=d[w];return Z;}function f(){const K=['local','storagePath','tokenSecret','region','bucket','secretKey','folder'];f=function(){return K;};return f();}export async function createFCore(w={}){const t=Y,y=loadConfig(w['config']),d=createRedis(y['redis']),Z=createLogger(),M=createDatabase(y['pg']),H=y['storageType']===t(0x93)?createFileLocal({'storagePath':y[t(0x94)],'folder':y['s3']['folder'],'tokenSecret':y['s3'][t(0x95)],'tokenTtl':y['s3']['tokenTtl']}):createFileS3({'endpoint':y['s3']['endpoint'],'region':y['s3'][t(0x96)],'bucket':y['s3'][t(0x97)],'accessKey':y['s3']['accessKey'],'secretKey':y['s3'][t(0x98)],'folder':y['s3'][t(0x99)],'forcePathStyle':y['s3']['forcePathStyle'],'tokenSecret':y['s3']['tokenSecret'],'tokenTtl':y['s3']['tokenTtl']}),Q=createAudit({'pg':M,'logger':Z}),s=createDictionary({'pg':M,'dictionaries':w['dictionaries']}),j=createResource({'pg':M,'logger':Z,'audit':Q,'dictionary':s,'file':H});w['resources']?.['length']&&j['register'](w['resources']);const n=createContext({'config':y,'logger':Z,'redis':d,'pg':M,'file':H,'resource':j,'audit':Q,'dictionary':s});return setContext(n),n;}
1
+ function k(h,n){h=h-0x156;const B=Q();let G=B[h];return G;}import{loadConfig}from'./config.js';import{createContext,setContext}from'./context.js';function Q(){const X=['folder','tokenTtl','region','tokenSecret','dictionaries','length','register'];Q=function(){return X;};return Q();}import{createAudit,createDatabase,createDictionary,createFileLocal,createFileS3,createLogger,createRedis,createResource}from'./plugins/index.js';export async function createFCore(h={}){const u=k,n=loadConfig(h['config']),B=createRedis(n['redis']),G=createLogger(),f=createDatabase(n['pg']),j=n['storageType']==='local'?createFileLocal({'storagePath':n['storagePath'],'folder':n['s3'][u(0x156)],'tokenSecret':n['s3']['tokenSecret'],'tokenTtl':n['s3'][u(0x157)]}):createFileS3({'endpoint':n['s3']['endpoint'],'region':n['s3'][u(0x158)],'bucket':n['s3']['bucket'],'accessKey':n['s3']['accessKey'],'secretKey':n['s3']['secretKey'],'folder':n['s3']['folder'],'forcePathStyle':n['s3']['forcePathStyle'],'tokenSecret':n['s3'][u(0x159)],'tokenTtl':n['s3'][u(0x157)]}),Z=createAudit({'pg':f,'logger':G}),e=createDictionary({'pg':f,'dictionaries':h[u(0x15a)]}),b=createResource({'pg':f,'logger':G,'audit':Z,'dictionary':e,'file':j});h['resources']?.[u(0x15b)]&&b[u(0x15c)](h['resources']);const P=createContext({'config':n,'logger':G,'redis':B,'pg':f,'file':j,'resource':b,'audit':Z,'dictionary':e});return setContext(P),P;}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function Y(w,y){w=w-0x19e;const d=f();let Z=d[w];return Z;}const j=Y;import{runMigrations}from'./runner.js';import{loadConfig}from'../config.js';import w from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL('../../migrations',import.meta.url));function migrationDirectory(y){const s=Y,d=y['indexOf']('--dir');if(d>=0x0){const M=y[d+0x1];if(!M)throw new Error(s(0x19e));return w[s(0x19f)](M);}if(y['includes']('--fcore'))return packageMigrations;const Z=y[s(0x1a0)](H=>!H['startsWith']('--'));return w['resolve'](Z??s(0x1a1));}function f(){const n=['--dir\x20requires\x20a\x20folder\x20path','resolve','find','migrations','slice','****','log','run','exitCode'];f=function(){return n;};return f();}try{const config=loadConfig(),dir=migrationDirectory(process['argv'][j(0x1a2)](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':'****','password':j(0x1a3)}),console[j(0x1a4)]('Using\x20migration\x20directory:',dir,process['argv']['slice'](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console['log']((r['status']===j(0x1a5)?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(Q){console['error'](Q),process[j(0x1a6)]=0x1;}
2
+ const e=k;function Q(){const P=['../../migrations','--dir','includes','startsWith','slice','log','Using\x20migration\x20directory:','run','error','exitCode'];Q=function(){return P;};return Q();}import{runMigrations}from'./runner.js';function k(h,n){h=h-0x119;const B=Q();let G=B[h];return G;}import{loadConfig}from'../config.js';import h from'node:path';import{fileURLToPath}from'node:url';const packageMigrations=fileURLToPath(new URL(e(0x119),import.meta.url));function migrationDirectory(n){const b=e,B=n['indexOf'](b(0x11a));if(B>=0x0){const f=n[B+0x1];if(!f)throw new Error('--dir\x20requires\x20a\x20folder\x20path');return h['resolve'](f);}if(n[b(0x11b)]('--fcore'))return packageMigrations;const G=n['find'](j=>!j[b(0x11c)]('--'));return h['resolve'](G??'migrations');}try{const config=loadConfig(),dir=migrationDirectory(process['argv'][e(0x11d)](0x2));console['log']('Loaded\x20configuration:',{...config['pg'],'user':'****','password':'****'}),console[e(0x11e)](e(0x11f),dir,process['argv'][e(0x11d)](0x2));for(const r of await runMigrations({'database':config['pg'],'dir':dir}))console['log']((r['status']===e(0x120)?'OK\x20\x20':'SKIP')+'\x20'+r['file']);}catch(Z){console[e(0x121)](Z),process[e(0x122)]=0x1;}
@@ -1 +1 @@
1
- import w from'node:fs/promises';import y from'node:path';function f(){const U=['dir','databaseUrl','query','filter','endsWith','push','skip','readFile','INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)','password'];f=function(){return U;};return f();}function Y(w,y){w=w-0xd2;const d=f();let Z=d[w];return Z;}import{createDatabase}from'../plugins/pg.js';export async function runMigrations(d={}){const i=Y,Z=y['resolve'](d[i(0xd2)]??'migrations'),M=d['database']??databaseFromUrl(d[i(0xd3)]??process.env.DATABASE_URL);if(!M)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const H=createDatabase(M);if(!H)throw new Error('empty\x20pg');const Q=[];try{await H[i(0xd4)]('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const s=await H['query']('SELECT\x20version\x20FROM\x20schema_migrations'),j=new Set(s['rows']['map'](t=>t['version'])),n=(await w['readdir'](Z))[i(0xd5)](t=>t[i(0xd6)]('.sql'))['sort']();for(const t of n){if(j['has'](t)){Q[i(0xd7)]({'file':t,'status':i(0xd8)});continue;}const K=await w[i(0xd9)](y['join'](Z,t),'utf8'),T=await H['connect']();try{await T['query']('BEGIN'),await T[i(0xd4)](K),await T['query'](i(0xda),[t]),await T[i(0xd4)]('COMMIT');}catch(h){await T['query']('ROLLBACK');throw h;}finally{T['release']();}Q[i(0xd7)]({'file':t,'status':'run'});}return Q;}finally{await H['end']();}}function databaseFromUrl(d){const G=Y;if(!d)return undefined;const Z=new URL(d);return{'host':Z['hostname'],'port':Number(Z['port']||0x1538),'database':Z['pathname']['slice'](0x1),'user':decodeURIComponent(Z['username']),'password':decodeURIComponent(Z[G(0xdb)])};}
1
+ function Q(){const t=['resolve','migrations','empty\x20pg','query','rows','map','endsWith','has','readFile','join','connect','run','hostname'];Q=function(){return t;};return Q();}import h from'node:fs/promises';import n from'node:path';import{createDatabase}from'../plugins/pg.js';export async function runMigrations(B={}){const p=k,G=n[p(0x163)](B['dir']??p(0x164)),f=B['database']??databaseFromUrl(B['databaseUrl']??process.env.DATABASE_URL);if(!f)throw new Error('DATABASE_URL\x20or\x20database\x20config\x20is\x20required');const j=createDatabase(f);if(!j)throw new Error(p(0x165));const Z=[];try{await j[p(0x166)]('\x0a\x20\x20\x20\x20\x20\x20CREATE\x20TABLE\x20IF\x20NOT\x20EXISTS\x20schema_migrations\x20(\x0a\x20\x20\x20\x20\x20\x20\x20\x20version\x20varchar(255)\x20PRIMARY\x20KEY,\x0a\x20\x20\x20\x20\x20\x20\x20\x20applied_at\x20timestamptz\x20NOT\x20NULL\x20DEFAULT\x20now()\x0a\x20\x20\x20\x20\x20\x20)\x0a\x20\x20\x20\x20');const e=await j['query']('SELECT\x20version\x20FROM\x20schema_migrations'),b=new Set(e[p(0x167)][p(0x168)](u=>u['version'])),P=(await h['readdir'](G))['filter'](u=>u[p(0x169)]('.sql'))['sort']();for(const u of P){if(b[p(0x16a)](u)){Z['push']({'file':u,'status':'skip'});continue;}const X=await h[p(0x16b)](n[p(0x16c)](G,u),'utf8'),H=await j[p(0x16d)]();try{await H[p(0x166)]('BEGIN'),await H['query'](X),await H['query']('INSERT\x20INTO\x20schema_migrations(version)\x20VALUES\x20($1)',[u]),await H['query']('COMMIT');}catch(i){await H[p(0x166)]('ROLLBACK');throw i;}finally{H['release']();}Z['push']({'file':u,'status':p(0x16e)});}return Z;}finally{await j['end']();}}function k(h,n){h=h-0x163;const B=Q();let G=B[h];return G;}function databaseFromUrl(B){const z=k;if(!B)return undefined;const G=new URL(B);return{'host':G[z(0x16f)],'port':Number(G['port']||0x1538),'database':G['pathname']['slice'](0x1),'user':decodeURIComponent(G['username']),'password':decodeURIComponent(G['password'])};}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const d=Y;import{loadConfig}from'../../config.js';function Y(w,y){w=w-0xa2;const d=f();let Z=d[w];return Z;}import{createDatabase}from'../../plugins/pg.js';function f(){const Z=['argv','Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]','exitCode','Registered\x20user\x20','end'];f=function(){return Z;};return f();}import w from'./services/registration.js';const [user,password,type]=process[d(0xa2)]['slice'](0x2);if(!user||!password)console['error'](d(0xa3)),process[d(0xa4)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await w({'user':user,'password':password,'type':type},{'pg':pg});console['log'](d(0xa5)+data['id']+'\x20('+data['type']+')');}catch(y){console['error'](y),process['exitCode']=0x1;}finally{await pg[d(0xa6)]();}}
2
+ const B=k;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import h from'./services/registration.js';const [user,password,type]=process['argv']['slice'](0x2);if(!user||!password)console['error']('Usage:\x20fcore-registration\x20<login>\x20<password>\x20[type]'),process[B(0xc5)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const {user:data}=await h({'user':user,'password':password,'type':type},{'pg':pg});console['log']('Registered\x20user\x20'+data['id']+'\x20('+data[B(0xc6)]+')');}catch(n){console[B(0xc7)](n),process['exitCode']=0x1;}finally{await pg['end']();}}function k(h,n){h=h-0xc5;const B=Q();let G=B[h];return G;}function Q(){const G=['exitCode','type','error'];Q=function(){return G;};return Q();}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- function Y(w,y){w=w-0x19c;const d=f();let Z=d[w];return Z;}const d=Y;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import w from'./services/change-password.js';function f(){const Z=['argv','error','query','User\x20not\x20found','Password\x20changed\x20for\x20'];f=function(){return Z;};return f();}const [login,password]=process[d(0x19c)]['slice'](0x2);if(!login||!password)console[d(0x19d)]('Usage:\x20fcore-password\x20<login>\x20<password>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[d(0x19e)]('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(d(0x19f));await w({'userId':user['id'],'password':password},{'pg':pg}),console['log'](d(0x1a0)+login);}catch(y){console['error'](y),process['exitCode']=0x1;}finally{await pg['end']();}}
2
+ function Q(){const G=['exitCode','error','end'];Q=function(){return G;};return Q();}function k(h,n){h=h-0x1ec;const B=Q();let G=B[h];return G;}const B=k;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';import h 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[B(0x1ec)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query']('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error('User\x20not\x20found');await h({'userId':user['id'],'password':password},{'pg':pg}),console['log']('Password\x20changed\x20for\x20'+login);}catch(n){console[B(0x1ed)](n),process[B(0x1ec)]=0x1;}finally{await pg[B(0x1ee)]();}}
@@ -1,2 +1,2 @@
1
1
  #!/usr/bin/env node
2
- const j=Y;import{loadConfig}from'../../config.js';function Y(w,y){w=w-0xf8;const d=f();let Z=d[w];return Z;}import{createDatabase}from'../../plugins/pg.js';const SYSTEM_ACTIONS=[j(0xf8),'audit',j(0xf9),'check','access','settings',j(0xfa)],RESOURCE_ACTIONS=[j(0xfb),j(0xfc),j(0xfd),'delete'],[login,permissionArg]=process['argv']['slice'](0x2);function f(){const t=['logs','list','dictionaries','read','update','create','split','map','filter','system','error','Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>','exitCode','User\x20not\x20found','DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL','log','Permissions\x20cleared\x20for\x20','get','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','actions','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)','ROLLBACK'];f=function(){return t;};return f();}function expandPermissions(w){const n=j,y=w[n(0xfe)](',')[n(0xff)](Z=>Z['trim']())[n(0x100)](Boolean),d=new Set();for(const Z of y){if(Z['includes'](':')){d['add'](Z);continue;}const M=Z===n(0x101)?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const H of M){d['add'](Z+':'+H);}}return[...d];}if(!login||!permissionArg)console[j(0x102)](j(0x103)),process[j(0x104)]=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg['query']('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result['rows'][0x0];if(!user)throw new Error(j(0x105));if(permissionArg['trim']()==='clear')await pg['query'](j(0x106),[user['id']]),console[j(0x107)](j(0x108)+login);else{const permissions=expandPermissions(permissionArg),byResource=new Map();for(const permission of permissions){const [resource,action]=permission['split'](':'),actions=byResource[j(0x109)](resource)??[];actions['push'](action),byResource['set'](resource,actions);}const client=await pg[j(0x10a)]();try{await client['query'](j(0x10b));for(const [resource,actions]of byResource){const existing=await client['query'](j(0x10c),[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row[j(0x10d)]??[],...actions])];await client['query']('UPDATE\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20actions\x20=\x20$1,\x20updated_by\x20=\x20$2,\x20updated_at\x20=\x20now()\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20access_id\x20=\x20$3',[merged,user['id'],row['access_id']]);}else await client['query'](j(0x10e),[resource,actions,user['id'],user['id']]);}await client['query']('COMMIT');}catch(Q){await client['query'](j(0x10f));throw Q;}finally{client['release']();}console['log']('Granted\x20permissions\x20for\x20'+login+':\x20'+permissions['join'](',\x20'));}}catch(s){console['error'](s),process[j(0x104)]=0x1;}finally{await pg['end']();}}
2
+ const b=k;import{loadConfig}from'../../config.js';import{createDatabase}from'../../plugins/pg.js';function Q(){const u=['logs','check','settings','dictionaries','read','split','includes','system','query','rows','User\x20not\x20found','trim','log','get','set','BEGIN','UPDATE\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20SET\x20actions\x20=\x20$1,\x20updated_by\x20=\x20$2,\x20updated_at\x20=\x20now()\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20access_id\x20=\x20$3','access_id','Granted\x20permissions\x20for\x20','join','end'];Q=function(){return u;};return Q();}const SYSTEM_ACTIONS=[b(0x13b),'audit','list',b(0x13c),'access',b(0x13d),b(0x13e)],RESOURCE_ACTIONS=[b(0x13f),'update','create','delete'],[login,permissionArg]=process['argv']['slice'](0x2);function expandPermissions(h){const P=b,n=h[P(0x140)](',')['map'](G=>G['trim']())['filter'](Boolean),B=new Set();for(const G of n){if(G[P(0x141)](':')){B['add'](G);continue;}const f=G===P(0x142)?SYSTEM_ACTIONS:RESOURCE_ACTIONS;for(const j of f){B['add'](G+':'+j);}}return[...B];}function k(h,n){h=h-0x13b;const B=Q();let G=B[h];return G;}if(!login||!permissionArg)console['error']('Usage:\x20fcore-permission\x20<login>\x20<system|resource|resource:action[,...]|clear>'),process['exitCode']=0x1;else{const pg=createDatabase(loadConfig()['pg']);try{const result=await pg[b(0x143)]('SELECT\x20uid\x20AS\x20id\x20FROM\x20admin.users\x20WHERE\x20$1\x20IN\x20(login,\x20email,\x20phone)\x20LIMIT\x201',[login]),user=result[b(0x144)][0x0];if(!user)throw new Error(b(0x145));if(permissionArg[b(0x146)]()==='clear')await pg[b(0x143)]('DELETE\x20FROM\x20admin.role_access\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL',[user['id']]),console[b(0x147)]('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[b(0x148)](resource)??[];actions['push'](action),byResource[b(0x149)](resource,actions);}const client=await pg['connect']();try{await client['query'](b(0x14a));for(const [resource,actions]of byResource){const existing=await client['query']('SELECT\x20access_id,\x20actions\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20user_uid\x20=\x20$1\x20AND\x20role_id\x20IS\x20NULL\x20AND\x20resource\x20=\x20$2',[user['id'],resource]),row=existing['rows'][0x0];if(row){const merged=[...new Set([...row['actions']??[],...actions])];await client['query'](b(0x14b),[merged,user['id'],row[b(0x14c)]]);}else await client[b(0x143)]('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(Z){await client['query']('ROLLBACK');throw Z;}finally{client['release']();}console['log'](b(0x14d)+login+':\x20'+permissions[b(0x14e)](',\x20'));}}catch(e){console['error'](e),process['exitCode']=0x1;}finally{await pg[b(0x14f)]();}}
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CAoK9D"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/auth/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAkB,MAAM,SAAS,CAAC;AAClE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAYnD,wBAAgB,UAAU,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CA0K9D"}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x176;const d=f();let Z=d[w];return Z;}import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import w from'./services/get-current-user.js';import y from'./services/registration.js';import d from'./services/change-password.js';function f(){const E=['GET','permissions','redirect','login','config','session','maxAge','save','audit','auth','fcore','Sign\x20in','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','public','Creates\x20a\x20regular\x20user\x20account.','admin','post','Change\x20password','user','body','destroy','cookieName','Get\x20current\x20user'];f=function(){return E;};return f();}import{authSchemas}from'./schema.js';import Z from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(M){return async H=>{const i=Y,Q=async s=>{const h=Y,j=s['method']===h(0x176)?s['query']:s['body'],n=Z(s),t=await verifyUser({...j,'ip':n},M);t[h(0x177)]=await getUserPermissions(t['id'],M);const K=t['twofa']?M['config']['auth']['twoFactorRedirect']:M['config']['auth'][h(0x178)];await s[h(0x179)](t);const T=M[h(0x17a)]['auth']['sessionTimeout']*0x3e8*0x3c;return s['session']?.['cookie']&&(s[h(0x17b)]['cookie'][h(0x17c)]=T),await s['session'][h(0x17d)](),await M[h(0x17e)]?.['write']?.({'module':h(0x17f),'resource':'session','resourceId':s['session']['sessionId'],'action':h(0x179),'userId':t['id'],'ipAddress':n}),{'user':{'id':t['id'],'type':t['type'],'permissions':t['permissions']},'redirectUrl':K};};H['get']('/api/auth/login',{'schema':{'tags':[i(0x180),'auth'],'summary':i(0x181),'description':i(0x182),'access':i(0x183),'permissions':[],'querystring':authSchemas['credentials']}},Q),H['post']('/api/auth/login',{'schema':{'tags':[i(0x180),'auth'],'summary':'Sign\x20in','description':i(0x182),'access':'public','permissions':[],'body':authSchemas['credentials']}},Q),H['post']('/api/auth/registration',{'schema':{'tags':['fcore','auth'],'summary':'Register','description':i(0x184),'access':i(0x185),'permissions':['user:create'],'body':authSchemas['credentials']}},async s=>y(s['body'],M)),H[i(0x186)]('/api/auth/password',{'schema':{'tags':[i(0x180),i(0x17f)],'summary':i(0x187),'description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':i(0x188),'permissions':[],'body':authSchemas['password']}},async s=>{const G=i;if(!s[G(0x188)])throw new UnauthorizedError('Not\x20authorized');return await d({'userId':s[G(0x188)]['id'],...s[G(0x189)]},M),{'success':!![]};}),H['post']('/api/auth/logout',{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':'Terminates\x20the\x20current\x20user\x20session.','access':i(0x188),'permissions':[]}},async(s,j)=>{const U=i,n={'redirectUrl':'/'};if(!s[U(0x188)])return n;return await M['audit']?.['write']?.({'module':U(0x17f),'resource':'session','resourceId':s[U(0x17b)]['sessionId'],'action':'logout','userId':s['user']?.['id']}),await s['session'][U(0x18a)](),j['clearCookie'](M['config']['auth'][U(0x18b)]),Object['defineProperty'](s,'session',{'value':null,'writable':![],'configurable':![]}),n;}),H['get']('/api/auth/user',{'schema':{'tags':['fcore',i(0x17f)],'summary':i(0x18c),'description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':'user','permissions':[],'querystring':authSchemas['query']}},async s=>w({'user':s[i(0x188)],'token':s['query']['token']}));};}
1
+ function k(h,n){h=h-0x112;const B=Q();let G=B[h];return G;}import{getUserPermissions,verifyUser}from'../../plugins/auth/index.js';import h from'./services/get-current-user.js';import n from'./services/registration.js';import B from'./services/change-password.js';import{authSchemas}from'./schema.js';import G from'../../shared/getIP.js';import{UnauthorizedError}from'../../errors.js';export function authRoutes(f){return async j=>{const p=k,Z=async e=>{const i=k,b=e[i(0x112)]==='GET'?e['query']:e['body'],P=G(e),u=await verifyUser({...b,'ip':P},f);u[i(0x113)]=await getUserPermissions(u['id'],f);const X=u[i(0x114)]?f['config'][i(0x115)][i(0x116)]:f['config'][i(0x115)][i(0x117)];await e['login'](u);const H=f['config']['auth']['sessionTimeout']*0x3e8*0x3c;return e[i(0x118)]?.['cookie']&&(e[i(0x118)]['cookie']['maxAge']=H),await e[i(0x118)]['save'](),await f['audit']?.['write']?.({'module':'auth','resource':i(0x118),'resourceId':e[i(0x118)]['sessionId'],'action':i(0x119),'userId':u['id'],'ipAddress':P}),{'user':{'id':u['id'],'type':u[i(0x11a)],'permissions':u[i(0x113)]},'redirectUrl':X};};j[p(0x11b)](p(0x11c),{'schema':{'tags':['fcore',p(0x115)],'summary':'Sign\x20in','description':p(0x11d),'access':'public','permissions':[],'querystring':authSchemas['credentials']}},Z),j[p(0x11e)](p(0x11c),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20in','description':p(0x11d),'access':p(0x11f),'permissions':[],'body':authSchemas['credentials']}},Z),j['post'](p(0x120),{'schema':{'tags':['fcore',p(0x115)],'summary':'Register','description':'Creates\x20a\x20regular\x20user\x20account.','access':'admin','permissions':[p(0x121)],'body':authSchemas['credentials']}},async e=>n(e[p(0x122)],f)),j['post']('/api/auth/password',{'schema':{'tags':['fcore','auth'],'summary':'Change\x20password','description':'Changes\x20the\x20password\x20for\x20the\x20current\x20user.','access':'user','permissions':[],'body':authSchemas['password']}},async e=>{const z=p;if(!e['user'])throw new UnauthorizedError('Not\x20authorized');return await B({'userId':e['user']['id'],...e[z(0x122)]},f),{'success':!![]};}),j['post'](p(0x123),{'schema':{'tags':['fcore','auth'],'summary':'Sign\x20out','description':p(0x124),'access':'user','permissions':[]}},async(e,b)=>{const t=p,P={'redirectUrl':'/'};if(!e['user'])return P;return await f[t(0x125)]?.[t(0x126)]?.({'module':t(0x115),'resource':'session','resourceId':e['session'][t(0x127)],'action':t(0x128),'userId':e[t(0x129)]?.['id']}),await e['session']['destroy'](),b[t(0x12a)](f['config'][t(0x115)][t(0x12b)]),Object['defineProperty'](e,'session',{'value':null,'writable':![],'configurable':![]}),P;}),j['get']('/api/auth/user',{'schema':{'tags':[p(0x12c),p(0x115)],'summary':p(0x12d),'description':'Returns\x20the\x20authenticated\x20user\x27s\x20safe\x20profile.','access':p(0x129),'permissions':[],'querystring':authSchemas['query']}},async e=>{const m=p;return h({'user':e[m(0x129)],'token':e['query'][m(0x12e)],'maxAge':e[m(0x118)]?.['cookie']?.[m(0x12f)],'originalExpires':e[m(0x118)]?.[m(0x130)]?.['originalExpires']?.[m(0x131)]?.()});});};}function Q(){const A=['method','permissions','twofa','auth','twoFactorRedirect','redirect','session','login','type','get','/api/auth/login','Authenticates\x20a\x20user\x20and\x20returns\x20a\x20bearer\x20access\x20token.','post','public','/api/auth/registration','user:create','body','/api/auth/logout','Terminates\x20the\x20current\x20user\x20session.','audit','write','sessionId','logout','user','clearCookie','cookieName','fcore','Get\x20current\x20user','token','maxAge','cookie','toISOString'];Q=function(){return A;};return Q();}
@@ -1 +1 @@
1
- function f(){const y=['Optional','String'];f=function(){return y;};return f();}function Y(w,y){w=w-0x1c5;const d=f();let Z=d[w];return Z;}const w=Y;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['String']({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type[w(0x1c5)](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type[w(0x1c6)]({'minLength':0x1})})};
1
+ const h=k;import{Type}from'@sinclair/typebox';function k(h,n){h=h-0x81;const B=Q();let G=B[h];return G;}function Q(){const n=['Boolean','Object','String','Optional'];Q=function(){return n;};return Q();}export const authSchemas={'query':Type['Object']({'token':Type['Optional'](Type[h(0x81)]())}),'credentials':Type[h(0x82)]({'user':Type[h(0x83)]({'minLength':0x1,'maxLength':0x64}),'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'type':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x64}))}),'password':Type['Object']({'password':Type['String']({'minLength':0x1,'maxLength':0x64}),'id':Type[h(0x84)](Type[h(0x83)]({'minLength':0x1,'maxLength':0x64}))}),'twoFactor':Type['Object']({'code':Type['String']({'minLength':0x1})})};
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x1bd;const d=f();let Z=d[w];return Z;}function f(){const Q=['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'];f=function(){return Q;};return f();}import{hashPassword}from'../../../plugins/auth/index.js';export default async function changePassword({id:w,password:y,userId:d},{pg:Z}){const H=Y,M=await hashPassword(y);await Z[H(0x1bd)](H(0x1be),[M,w||d,d]);}
1
+ import{hashPassword}from'../../../plugins/auth/index.js';function Q(){const Z=['query'];Q=function(){return Z;};return Q();}function k(h,n){h=h-0x1e4;const B=Q();let G=B[h];return G;}export default async function changePassword({id:h,password:n,userId:B},{pg:G}){const j=k,f=await hashPassword(n);await G[j(0x1e4)]('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',[f,h||B,B]);}
@@ -5,5 +5,7 @@ import type { User } from "../../../context.js";
5
5
  export default function getCurrentUser(params: {
6
6
  user: User | undefined;
7
7
  token: boolean | undefined;
8
+ maxAge: number | undefined;
9
+ originalExpires: string | undefined;
8
10
  }): Promise<Record<string, unknown>>;
9
11
  //# sourceMappingURL=get-current-user.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/get-current-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAA8B,cAAc,CAAC,MAAM,EAAE;IACnD,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;CAC5B,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAenC"}
1
+ {"version":3,"file":"get-current-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/auth/services/get-current-user.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAEhD,wBAA8B,cAAc,CAAC,MAAM,EAAE;IACnD,IAAI,EAAE,IAAI,GAAG,SAAS,CAAC;IACvB,KAAK,EAAE,OAAO,GAAG,SAAS,CAAC;IAC3B,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC;CACrC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAkBnC"}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0xa9;const d=f();let Z=d[w];return Z;}function f(){const Q=['token','map'];f=function(){return Q;};return f();}import{safeUser}from'../../utils/safe-user.js';export default async function getCurrentUser(w){const H=Y,{user:y}=w;if(!y)return{};if(w[H(0xa9)]){const {jwtSignToken:d}=await import('../../../plugins/jwt.js'),Z=await d(y);y['token']=Z;}return y['resources']=[...new Set(y?.['permissions'][H(0xaa)](M=>M['split'](':')[0x0]))],safeUser(y);}
1
+ function Q(){const Z=['permissions','map','split'];Q=function(){return Z;};return Q();}import{safeUser}from'../../utils/safe-user.js';function k(h,n){h=h-0x123;const B=Q();let G=B[h];return G;}export default async function getCurrentUser(h){const j=k,{user:n}=h;if(!n)return{};if(h['token']){const {jwtSignToken:B}=await import('../../../plugins/jwt.js'),G=await B(n);n['token']=G;}return n['resources']=[...new Set(n?.[j(0x123)][j(0x124)](f=>f[j(0x125)](':')[0x0]))],{...safeUser(n),'session':{'maxAge':h['maxAge'],'originalExpires':h['maxAge']}};}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x164;const d=f();let Z=d[w];return Z;}import{ConflictError}from'../../../errors.js';function f(){const j=['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'];f=function(){return j;};return f();}import{hashPassword}from'../../../plugins/auth/index.js';export default async function registration({user:w,password:y,type:d},{pg:Z}){const s=Y,M=await hashPassword(y),H=await Z['query'](s(0x164),[w,M,d||'regular']),Q=H['rows'][0x0];if(!Q)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':Q};}
1
+ import{ConflictError}from'../../../errors.js';import{hashPassword}from'../../../plugins/auth/index.js';function k(h,n){h=h-0xc8;const B=Q();let G=B[h];return G;}export default async function registration({user:h,password:n,type:B},{pg:G}){const e=k,f=await hashPassword(n),j=await G['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',[h,f,B||e(0xc8)]),Z=j['rows'][0x0];if(!Z)throw new ConflictError('Login\x20is\x20already\x20in\x20use');return{'user':Z};}function Q(){const b=['regular'];Q=function(){return b;};return Q();}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x7a;var d=f();var Z=d[w];return Z;}import{unsupported}from'../../utils/unsupported.js';function f(){var Z=['Two-factor\x20provider'];f=function(){return Z;};return f();}export default async function verifyTwoFactor(w,y){var d=Y;return unsupported(d(0x7a));}
1
+ import{unsupported}from'../../utils/unsupported.js';export default async function verifyTwoFactor(h,n){return unsupported('Two-factor\x20provider');}
@@ -1 +1 @@
1
- var w=Y;function Y(w,y){w=w-0xfc;var d=f();var Z=d[w];return Z;}function f(){var y=['image/webp','application/json','application/xml','application/zip','application/x-tar','audio/ogg','audio/webm','video/webm'];f=function(){return y;};return f();}export default new Set(['image/jpeg','image/png','image/gif',w(0xfc),'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','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.text','application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain','text/csv','text/markdown',w(0xfd),w(0xfe),'text/xml','application/geo+json','application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz',w(0xff),'application/x-zip-compressed','application/x-7z-compressed','application/x-rar-compressed','application/vnd.rar','application/gzip','application/x-gzip',w(0x100),'audio/mpeg','audio/wav',w(0x101),w(0x102),'audio/mp4','video/mp4','video/mpeg',w(0x103),'video/quicktime','video/x-msvideo','application/octet-stream']);
1
+ function k(h,n){h=h-0x1c0;var B=Q();var G=B[h];return G;}var h=k;function Q(){var n=['image/jpeg','image/png','image/webp','image/tiff','application/pdf','application/vnd.ms-powerpoint','application/vnd.openxmlformats-officedocument.presentationml.presentation','application/vnd.oasis.opendocument.text','text/csv','application/json','application/geo+json','application/x-7z-compressed','application/gzip','application/x-gzip','audio/wav','audio/ogg','audio/webm','video/quicktime'];Q=function(){return n;};return Q();}export default new Set([h(0x1c0),h(0x1c1),'image/gif',h(0x1c2),'image/bmp',h(0x1c3),'image/svg+xml','image/x-icon','image/avif',h(0x1c4),'application/msword','application/vnd.openxmlformats-officedocument.wordprocessingml.document','application/vnd.ms-excel','application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',h(0x1c5),h(0x1c6),h(0x1c7),'application/vnd.oasis.opendocument.spreadsheet','application/vnd.oasis.opendocument.presentation','text/plain',h(0x1c8),'text/markdown',h(0x1c9),'application/xml','text/xml',h(0x1ca),'application/vnd.google-earth.kml+xml','application/vnd.google-earth.kmz','application/zip','application/x-zip-compressed',h(0x1cb),'application/x-rar-compressed','application/vnd.rar',h(0x1cc),h(0x1cd),'application/x-tar','audio/mpeg',h(0x1ce),h(0x1cf),h(0x1d0),'audio/mp4','video/mp4','video/mpeg','video/webm',h(0x1d1),'video/x-msvideo','application/octet-stream']);
@@ -1 +1 @@
1
- import{fileTypeFromBuffer}from'file-type';function f(){const G=['file','public','fileDownloadQuery','token','application/octet-stream','image/','split','pop','header','attachment','inline','public,\x20max-age=86400,\x20immutable','post','File\x20is\x20required','fields','value','get','/api/file/:token/resize','user','fileToken','params','query','Content-Disposition'];f=function(){return G;};return f();}import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';import{resizeFile}from'./services/resize-file.js';function Y(w,y){w=w-0x169;const d=f();let Z=d[w];return Z;}import{fileSchemas}from'./schema.js';export function fileRoutes(w){return async y=>{const K=Y;y['get']('/api/file/:token',{'schema':{'tags':['fcore',K(0x169)],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':K(0x16a),'permissions':[],'params':fileSchemas['fileToken'],'querystring':fileSchemas[K(0x16b)]}},async(d,Z)=>{const T=K,M=w[T(0x169)]['verify'](d['params'][T(0x16c)]),H=await getFile({'pathOrToken':M},w),Q=await fileTypeFromBuffer(H),s=Q?.['mime']??T(0x16d),j=d['query']['download']===!![],n=s['startsWith'](T(0x16e))||s==='application/pdf',t=M[T(0x16f)]('/')[T(0x170)]()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??'file';return Z['type'](s),Z[T(0x171)]('Content-Disposition',(j||!n?T(0x172):T(0x173))+';\x20filename=\x22'+t+'\x22')[T(0x171)]('Cache-Control',T(0x174)),Z['send'](H);}),y[K(0x175)]('/api/file/upload',{'schema':{'tags':['fcore',K(0x169)],'summary':'Upload\x20file','description':'Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['files:create']}},async d=>{const h=K,Z=await d['file']();if(!Z)throw new Error(h(0x176));return uploadFile({'file':Z,'metadata':{'name':Z['filename'],'path':Z[h(0x177)]['path']?.['value'],'resource':Z['fields']['resource']?.[h(0x178)],'resourceId':Z[h(0x177)]['resourceId']?.[h(0x178)]},'user':d['user']},w);}),y[K(0x179)](K(0x17a),{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':K(0x17b),'permissions':['files:read'],'params':fileSchemas[K(0x17c)],'querystring':fileSchemas['resizeQuery']}},async(d,Z)=>{const i=K,M=await resizeFile({'pathOrToken':w[i(0x169)]?.['verify'](d[i(0x17d)]['token']),...d[i(0x17e)]},w),H=await fileTypeFromBuffer(M);return Z['type'](H?.['mime']??'image/png'),Z[i(0x171)](i(0x17f),'inline')[i(0x171)]('Cache-Control','public,\x20max-age=86400,\x20immutable'),Z['send'](M);});};}
1
+ function k(h,n){h=h-0x12a;const B=Q();let G=B[h];return G;}import{fileTypeFromBuffer}from'file-type';function Q(){const z=['fileToken','verify','token','download','startsWith','image/','pop','file','Content-Disposition','header','Cache-Control','fcore','Uploads\x20a\x20file\x20and\x20stores\x20its\x20metadata.','fields','/api/file/:token/resize','user','type'];Q=function(){return z;};return Q();}import{getFile}from'./services/get-file.js';import{uploadFile}from'./services/upload-file.js';import{resizeFile}from'./services/resize-file.js';import{fileSchemas}from'./schema.js';export function fileRoutes(h){return async n=>{const X=k;n['get']('/api/file/:token',{'schema':{'tags':['fcore','file'],'summary':'Get\x20file\x20by\x20token','description':'Returns\x20a\x20file\x20after\x20verifying\x20its\x20signed\x20access\x20token.','access':'public','permissions':[],'params':fileSchemas[X(0x12a)],'querystring':fileSchemas['fileDownloadQuery']}},async(B,G)=>{const H=X,f=h['file'][H(0x12b)](B['params'][H(0x12c)]),j=await getFile({'pathOrToken':f},h),Z=await fileTypeFromBuffer(j),e=Z?.['mime']??'application/octet-stream',b=B['query'][H(0x12d)]===!![],P=e[H(0x12e)](H(0x12f))||e==='application/pdf',u=f['split']('/')[H(0x130)]()?.['replace'](/[^A-Za-z0-9._-]/g,'_')??H(0x131);return G['type'](e),G['header'](H(0x132),(b||!P?'attachment':'inline')+';\x20filename=\x22'+u+'\x22')[H(0x133)](H(0x134),'public,\x20max-age=86400,\x20immutable'),G['send'](j);}),n['post']('/api/file/upload',{'schema':{'tags':[X(0x135),X(0x131)],'summary':'Upload\x20file','description':X(0x136),'access':'user','permissions':['files:create']}},async B=>{const i=X,G=await B['file']();if(!G)throw new Error('File\x20is\x20required');return uploadFile({'file':G,'metadata':{'name':G['filename'],'path':G['fields']['path']?.['value'],'resource':G['fields']['resource']?.['value'],'resourceId':G[i(0x137)]['resourceId']?.['value']},'user':B['user']},h);}),n['get'](X(0x138),{'schema':{'tags':['fcore','file'],'summary':'Resize\x20file','description':'Returns\x20a\x20resized\x20image\x20file.','access':X(0x139),'permissions':['files:read'],'params':fileSchemas['fileToken'],'querystring':fileSchemas['resizeQuery']}},async(B,G)=>{const p=X,f=await resizeFile({'pathOrToken':h[p(0x131)]?.['verify'](B['params']['token']),...B['query']},h),j=await fileTypeFromBuffer(f);return G[p(0x13a)](j?.['mime']??'image/png'),G['header'](p(0x132),'inline')['header'](p(0x134),'public,\x20max-age=86400,\x20immutable'),G['send'](f);});};}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x16b;const d=f();let Z=d[w];return Z;}function f(){const y=['Optional','Boolean','Object','String','contain','fill','Literal'];f=function(){return y;};return f();}const w=Y;import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type['Object']({'token':Type['String']({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type[w(0x16b)](Type[w(0x16c)]())}),'filePath':Type['Object']({'*':Type['String']({'minLength':0x1,'maxLength':0x400})}),'upload':Type[w(0x16d)]({'file':Type['Any'](),'metadata':Type['Object']({'name':Type['Optional'](Type['String']({'minLength':0x1})),'path':Type[w(0x16b)](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type['Optional'](Type[w(0x16e)]({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type['Integer']({'minimum':0x1,'default':0xc8})),'height':Type['Optional'](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type['Union']([Type['Literal']('cover'),Type['Literal'](w(0x16f)),Type['Literal'](w(0x170)),Type[w(0x171)]('inside'),Type['Literal']('outside')]))})};
1
+ const h=k;function Q(){const n=['Object','String','Any','Optional','Integer','Union','cover','Literal','contain','outside'];Q=function(){return n;};return Q();}function k(h,n){h=h-0x146;const B=Q();let G=B[h];return G;}import{Type}from'@sinclair/typebox';export const fileSchemas={'fileId':Type['Object']({'id':Type['String']({'minLength':0x1,'maxLength':0x80})}),'fileToken':Type[h(0x146)]({'token':Type[h(0x147)]({'minLength':0x1,'maxLength':0x800})}),'fileDownloadQuery':Type['Object']({'download':Type['Optional'](Type['Boolean']())}),'filePath':Type[h(0x146)]({'*':Type[h(0x147)]({'minLength':0x1,'maxLength':0x400})}),'upload':Type['Object']({'file':Type[h(0x148)](),'metadata':Type['Object']({'name':Type[h(0x149)](Type['String']({'minLength':0x1})),'path':Type['Optional'](Type['String']({'minLength':0x1})),'entityType':Type['Optional'](Type['String']({'minLength':0x1})),'entityId':Type['Optional'](Type['String']({'minLength':0x1}))})}),'filePatch':Type['Object']({'entityType':Type[h(0x149)](Type['String']({'minLength':0x1})),'entityId':Type[h(0x149)](Type[h(0x147)]({'minLength':0x1}))}),'resizeQuery':Type['Object']({'width':Type['Optional'](Type[h(0x14a)]({'minimum':0x1,'default':0xc8})),'height':Type[h(0x149)](Type['Integer']({'minimum':0x1})),'fit':Type['Optional'](Type[h(0x14b)]([Type['Literal'](h(0x14c)),Type[h(0x14d)](h(0x14e)),Type[h(0x14d)]('fill'),Type['Literal']('inside'),Type['Literal'](h(0x14f))]))})};
@@ -1 +1 @@
1
- import{NotFoundError}from'../../../errors.js';function Y(w,y){w=w-0x191;var d=f();var Z=d[w];return Z;}function f(){var Z=['file'];f=function(){return Z;};return f();}export async function getFile(w,y){var d=Y;if(!y[d(0x191)])throw new Error('empty\x20file');if(!await y['file']['exists'](w['pathOrToken']))throw new NotFoundError('File\x20not\x20found'+w['pathOrToken']);return y['file']['get'](w['pathOrToken']);}
1
+ import{NotFoundError}from'../../../errors.js';function k(h,n){h=h-0x113;var B=Q();var G=B[h];return G;}export async function getFile(h,n){var B=k;if(!n['file'])throw new Error(B(0x113));if(!await n['file'][B(0x114)](h['pathOrToken']))throw new NotFoundError(B(0x115)+h['pathOrToken']);return n['file'][B(0x116)](h['pathOrToken']);}function Q(){var G=['empty\x20file','exists','File\x20not\x20found','get'];Q=function(){return G;};return Q();}
@@ -1 +1 @@
1
- import{NotFoundError,ValidationError}from'../../../errors.js';import{fileTypeFromBuffer}from'file-type';import{createHash}from'node:crypto';import{mkdir,readFile,writeFile}from'node:fs/promises';import w from'node:path';import y from'sharp';export async function resizeFile(d,Z){const i=Y,M=d['pathOrToken']??d[i(0x1b8)];if(!M)throw new ValidationError(i(0x1b9));const H=parseDimension(d['width'],'width')??0xc8,Q=parseDimension(d[i(0x1ba)],'height'),s=createHash('sha256')['update'](M+':'+H+':'+(Q??i(0x1bb))+':'+(d['fit']??i(0x1bc)))[i(0x1bd)]('hex'),j=w[i(0x1be)]('logs','resize'),n=w['join'](j,s+i(0x1bf));try{return await readFile(n);}catch(h){if(h['code']!=='ENOENT')throw h;}if(!await Z['file'][i(0x1c0)](M))throw new NotFoundError('File\x20not\x20found');const t=await Z['file']['get'](M),K=await fileTypeFromBuffer(t);if(!K?.['mime']['startsWith']('image/'))throw new ValidationError('Only\x20image\x20files\x20can\x20be\x20resized');const T=await y(t)['resize']({'width':H,'height':Q,'fit':d['fit']??'cover'})[i(0x1c1)]();return await mkdir(j,{'recursive':!![]}),await writeFile(n,T),T;}function Y(w,y){w=w-0x1b8;const d=f();let Z=d[w];return Z;}function parseDimension(d,Z){const G=Y;if(d===undefined||d==='')return undefined;const M=Number(d);if(!Number['isInteger'](M)||M<=0x0)throw new ValidationError(Z+G(0x1c2));return M;}function f(){const U=['path','File\x20path\x20is\x20required','height','auto','cover','digest','resolve','.jpg','exists','toBuffer','\x20must\x20be\x20a\x20positive\x20integer'];f=function(){return U;};return f();}
1
+ function Q(){const z=['path','height','digest','join','file','mime','Only\x20image\x20files\x20can\x20be\x20resized','resize'];Q=function(){return z;};return Q();}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 h from'node:path';import n from'sharp';export async function resizeFile(B,G){const p=k,f=B['pathOrToken']??B[p(0xc0)];if(!f)throw new ValidationError('File\x20path\x20is\x20required');const j=parseDimension(B['width'],'width')??0xc8,Z=parseDimension(B['height'],p(0xc1)),e=createHash('sha256')['update'](f+':'+j+':'+(Z??'auto')+':'+(B['fit']??'cover'))[p(0xc2)]('hex'),b=h['resolve']('logs','resize'),P=h[p(0xc3)](b,e+'.jpg');try{return await readFile(P);}catch(i){if(i['code']!=='ENOENT')throw i;}if(!await G['file']['exists'](f))throw new NotFoundError('File\x20not\x20found');const u=await G[p(0xc4)]['get'](f),X=await fileTypeFromBuffer(u);if(!X?.[p(0xc5)]['startsWith']('image/'))throw new ValidationError(p(0xc6));const H=await n(u)[p(0xc7)]({'width':j,'height':Z,'fit':B['fit']??'cover'})['toBuffer']();return await mkdir(b,{'recursive':!![]}),await writeFile(P,H),H;}function k(h,n){h=h-0xc0;const B=Q();let G=B[h];return G;}function parseDimension(B,G){if(B===undefined||B==='')return undefined;const f=Number(B);if(!Number['isInteger'](f)||f<=0x0)throw new ValidationError(G+'\x20must\x20be\x20a\x20positive\x20integer');return f;}
@@ -1 +1 @@
1
- import{fileTypeFromBuffer}from'file-type';import w from'../mime.js';import{randomUUID}from'node:crypto';import{ValidationError}from'../../../errors.js';function Y(w,y){w=w-0x89;const d=f();let Z=d[w];return Z;}export async function uploadFile(y,d){const i=Y,Z=(y['metadata']['name']??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),M=new Date(),H=String(M['getFullYear']())['slice'](-0x2),Q=String(M[i(0x89)]()+0x1)[i(0x8a)](0x2,'0'),s=String(M[i(0x8b)]())['padStart'](0x2,'0'),j=y['metadata']['path']??(y['metadata']['resource']?y[i(0x8c)]['resource']+'/'+(y['metadata']['resourceId']??randomUUID())+'/'+Z:null)??i(0x8d)+H+'/'+Q+'-'+s+'/'+Z,n=await y['file'][i(0x8e)](),t=await fileTypeFromBuffer(n);if(!w['has'](y['file'][i(0x8f)])&&(t?.['mime']?!w['has'](t['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+y['file']['mimetype']);const K=Boolean(y['metadata']['resource']&&y['metadata'][i(0x90)]);if(K){const h=await d['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',[y['metadata']['resource'],String(y['metadata'][i(0x90)]),Z]);if((h['rowCount']??0x0)>0x0)throw new ValidationError('File\x20with\x20name\x20\x22'+Z+i(0x91)+y[i(0x8c)][i(0x92)]+'\x22\x20and\x20id\x20\x22'+y[i(0x8c)][i(0x90)]+'\x22');}await d['file'][i(0x93)](j,n);const T=await d['pg'][i(0x94)]('\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',[y[i(0x8c)]['resource']??null,y[i(0x8c)]['resourceId']??null,j,y['file'][i(0x8f)],y['file'][i(0x95)][i(0x96)],y['metadata']['name'],Z,y[i(0x95)]['mimetype'][i(0x97)]('/')['pop']()??null,K?'attached':'pending',y['user']?.['id']??null]);return{...T[i(0x98)][0x0],'token':d['file']['create'](j)};}function f(){const G=['getMonth','padStart','getDate','metadata','uploads/','toBuffer','mimetype','resourceId','\x22\x20already\x20exists\x20for\x20resource\x20\x22','resource','put','query','file','bytesRead','split','rows'];f=function(){return G;};return f();}
1
+ import{fileTypeFromBuffer}from'file-type';import h from'../mime.js';function Q(){const z=['name','slice','path','metadata','toBuffer','mimetype','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','\x22\x20already\x20exists\x20for\x20resource\x20\x22','resource','resourceId','put','file','pop','attached','pending','rows'];Q=function(){return z;};return Q();}import{randomUUID}from'node:crypto';function k(h,n){h=h-0x188;const B=Q();let G=B[h];return G;}import{ValidationError}from'../../../errors.js';export async function uploadFile(n,B){const p=k,G=(n['metadata'][p(0x188)]??randomUUID())['replace'](/[^a-zA-Z0-9._-]/g,'_'),f=new Date(),j=String(f['getFullYear']())[p(0x189)](-0x2),Z=String(f['getMonth']()+0x1)['padStart'](0x2,'0'),e=String(f['getDate']())['padStart'](0x2,'0'),b=n['metadata'][p(0x18a)]??(n['metadata']['resource']?n['metadata']['resource']+'/'+(n[p(0x18b)]['resourceId']??randomUUID())+'/'+G:null)??'uploads/'+j+'/'+Z+'-'+e+'/'+G,P=await n['file'][p(0x18c)](),u=await fileTypeFromBuffer(P);if(!h['has'](n['file']['mimetype'])&&(u?.['mime']?!h['has'](u['mime']):!![]))throw new Error('Unsupported\x20file\x20type:\x20'+n['file'][p(0x18d)]);const X=Boolean(n['metadata']['resource']&&n['metadata']['resourceId']);if(X){const i=await B['pg']['query'](p(0x18e),[n['metadata']['resource'],String(n['metadata']['resourceId']),G]);if((i['rowCount']??0x0)>0x0)throw new ValidationError('File\x20with\x20name\x20\x22'+G+p(0x18f)+n['metadata'][p(0x190)]+'\x22\x20and\x20id\x20\x22'+n['metadata'][p(0x191)]+'\x22');}await B['file'][p(0x192)](b,P);const H=await B['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',[n['metadata']['resource']??null,n[p(0x18b)]['resourceId']??null,b,n['file']['mimetype'],n['file'][p(0x193)]['bytesRead'],n['metadata'][p(0x188)],G,n['file']['mimetype']['split']('/')[p(0x194)]()??null,X?p(0x195):p(0x196),n['user']?.['id']??null]);return{...H[p(0x197)][0x0],'token':B['file']['create'](b)};}
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/resource/route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAoBnD,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CA8VlE"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/resource/route.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAwBnD,wBAAgB,cAAc,CAAC,GAAG,EAAE,UAAU,GAAG,kBAAkB,CAoblE"}
@@ -1 +1 @@
1
- import{listResources}from'./services/list-resources.js';import{getResource}from'./services/get-resource.js';import{createResource}from'./services/create-resource.js';function Y(w,y){w=w-0x93;const d=f();let Z=d[w];return Z;}import{updateResource}from'./services/update-resource.js';import{deleteResource}from'./services/delete-resource.js';import{listResourceRelation}from'./services/list-resource-relation.js';function f(){const T=['get','resource','query','params','/api/suggest/:resource/:field','suggestQuery','/api/resource/:resource/export','exportResource','user','post','Create\x20resource\x20record','config','/api/resource/:resource/:id','Get\x20resource\x20record','Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','$resource:update','fcore','resourceId','uploadResourceFile','delete','rowCount','rows','List\x20resource\x20relations','auth','/api/resource/:resource/:id/:relation/:relationId','Updates\x20a\x20related\x20resource\x20record.','resourceIdRelationId'];f=function(){return T;};return f();}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{resourceSchemas}from'./schema.js';import{uploadFile}from'../file/services/upload-file.js';const user=w=>w['user'];export function resourceRoutes(w){return async y=>{const n=Y;y[n(0x93)]('/api/resource/:resource/search',{'schema':{'tags':['fcore',n(0x94)],'summary':'Search\x20resource','description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas[n(0x94)]}},async d=>searchResource({...d[n(0x95)],...d[n(0x96)],'user':user(d)||w['config']?.['auth']?.['user']},w)),y[n(0x93)](n(0x97),{'schema':{'tags':['fcore','resource'],'summary':'Suggest\x20resource\x20values','description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceField'],'querystring':resourceSchemas[n(0x98)]}},async d=>suggestResource({...d['query'],...d[n(0x96)],'user':user(d)||w['config']?.['auth']?.['user']},w)),y['get'](n(0x99),{'schema':{'tags':['fcore',n(0x94)],'summary':'Export\x20resource\x20records','description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas[n(0x9a)],'querystring':resourceSchemas['exportResourceQuery']}},async d=>exportResource({...d[n(0x95)],...d['params'],'user':user(d)||w['config']?.['auth']?.['user']},w)),y['get']('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':n(0x9b),'permissions':['$resource:read'],'params':resourceSchemas[n(0x94)]}},async d=>listResources({...d['query'],...d['params'],'user':user(d)||w['config']?.['auth']?.[n(0x9b)]},w)),y[n(0x9c)]('/api/resource/:resource',{'schema':{'tags':['fcore','resource'],'summary':n(0x9d),'description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':n(0x9b),'permissions':['$resource:create'],'params':resourceSchemas['resource']}},async d=>createResource({...d['params'],'data':d['body'],'user':user(d)||w[n(0x9e)]?.['auth']?.['user']},w)),y['get'](n(0x9f),{'schema':{'tags':['fcore','resource'],'summary':n(0xa0),'description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async d=>getResource({...d['query'],...d[n(0x96)],'user':user(d)||w['config']?.['auth']?.['user']},w)),y['put']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20record','description':n(0xa1),'access':'user','permissions':[n(0xa2)],'params':resourceSchemas['resourceId']}},async d=>updateResource({...d['params'],'patch':d['body'],'user':user(d)||w['config']?.['auth']?.['user']},w)),y['delete']('/api/resource/:resource/:id',{'schema':{'tags':[n(0xa3),'resource'],'summary':'Delete\x20resource\x20record','description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:delete'],'params':resourceSchemas[n(0xa4)]}},async d=>deleteResource({...d['params'],'user':user(d)||w['config']?.['auth']?.[n(0x9b)]},w)),y['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':['fcore',n(0x94)],'summary':'Upload\x20resource\x20file','description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':[n(0xa2)],'params':resourceSchemas[n(0xa5)]}},async d=>{const t=n,Z=await d['file']();if(!Z)throw new Error('File\x20is\x20required');const M=d[t(0x96)]['resource'],H=d['params']['id'];return uploadFile({'file':Z,'metadata':{'name':Z['filename'],'path':Z['fields']['path']?.['value'],'resource':M,'resourceId':H},'user':d['user']},w);}),y[n(0xa6)]('/api/resource/:resource/:id/file/:fid',{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20file','description':'Deletes\x20a\x20file\x20linked\x20to\x20a\x20resource\x20record\x20after\x20validating\x20it\x20belongs\x20to\x20this\x20resource\x20and\x20record.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['resourceIdFileId']}},async d=>{const K=n,{resource:Z,id:M,fid:H}=d['params'],Q=await w['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',[H,Z,String(M)]);if(!Q[K(0xa7)])throw new Error('File\x20not\x20found\x20for\x20this\x20resource\x20and\x20record');const s=Q[K(0xa8)][0x0]?.['file_path'],j=await w['pg']['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[H,Z,String(M)]);return await w['file'][K(0xa6)](s),{'success':(j['rowCount']??0x0)>0x0,'resource':Z,'resourceId':M,'fileId':H};}),y['get']('/api/resource/:resource/:id/:relation',{'schema':{'tags':[n(0xa3),n(0x94)],'summary':n(0xa9),'description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':'user','params':resourceSchemas['resourceIdRelation'],'permissions':['$resource:read']}},async d=>listResourceRelation({...d[n(0x95)],...d['params'],'user':user(d)||w[n(0x9e)]?.[n(0xaa)]?.['user']},w)),y[n(0x9c)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore','resource'],'summary':'Create\x20resource\x20relation','description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':'user','permissions':['$resource:create'],'params':resourceSchemas['resourceIdRelation']}},async d=>createResourceRelation({...d['params'],'data':d['body'],'user':user(d)||w[n(0x9e)]?.['auth']?.['user']},w)),y[n(0xa6)](n(0xab),{'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 d=>deleteResourceRelation({...d['params'],'user':user(d)||w['config']?.['auth']?.['user']},w)),y['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[n(0xa3),'resource'],'summary':'Update\x20resource\x20relation','description':n(0xac),'access':'user','permissions':[n(0xa2)],'params':resourceSchemas[n(0xad)]}},async d=>updateResourceRelation({...d['params'],'data':d['body'],'user':user(d)||w[n(0x9e)]?.[n(0xaa)]?.['user']},w));};}
1
+ import{listResources}from'./services/list-resources.js';function k(h,n){h=h-0x94;const B=Q();let G=B[h];return G;}import{listResourceAsUser}from'./services/list-resource-as-user.js';import{getResource}from'./services/get-resource.js';import{createResource}from'./services/create-resource.js';import{updateResource}from'./services/update-resource.js';import{deleteResource}from'./services/delete-resource.js';import{listResourceRelation}from'./services/list-resource-relation.js';import{createResourceRelation}from'./services/create-resource-relation.js';import{updateResourceRelation}from'./services/update-resource-relation.js';import{deleteResourceRelation}from'./services/delete-resource-relation.js';import{searchResource}from'./services/search-resource.js';import{exportResource}from'./services/export-resource.js';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=h=>h['user'];function Q(){const H=['get','fcore','params','user','Suggest\x20resource\x20values','resourceField','/api/resource/:resource/export','Export\x20resource\x20records','$resource:read','exportResourceQuery','/api/resource/:resource/code','Generates\x20a\x20code\x20from\x20an\x20explicit\x20template\x20or\x20a\x20field\x20code_template.','resource','auth','post','config','$resource:delete','Upload\x20resource\x20file','delete','rowCount','/api/resource/:resource/:id/:relation','List\x20resource\x20relations','Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','query','$resource:create','body'];Q=function(){return H;};return Q();}export function resourceRoutes(h){return async n=>{const P=k;n[P(0x94)]('/api/resource/:resource/search',{'schema':{'tags':[P(0x95),'resource'],'summary':'Search\x20resource','description':'Searches\x20records\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resource']}},async B=>searchResource({...B['query'],...B[P(0x96)],'user':user(B)||h['config']?.['auth']?.[P(0x97)]},h)),n[P(0x94)]('/api/suggest/:resource/:field',{'schema':{'tags':['fcore','resource'],'summary':P(0x98),'description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':'user','permissions':['$resource:read'],'params':resourceSchemas[P(0x99)],'querystring':resourceSchemas['suggestQuery']}},async B=>suggestResource({...B['query'],...B[P(0x96)],'user':user(B)||h['config']?.['auth']?.['user']},h)),n['get'](P(0x9a),{'schema':{'tags':['fcore','resource'],'summary':P(0x9b),'description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[P(0x9c)],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas[P(0x9d)]}},async B=>exportResource({...B['query'],...B['params'],'user':user(B)||h['config']?.['auth']?.['user']},h)),n['get']('/api/resource/:resource/schema',{'schema':{'tags':['fcore','resource'],'summary':'Get\x20resource\x20schema','description':'Returns\x20the\x20resource\x20variables\x20and\x20nested\x20relation\x20schema.','access':P(0x97),'permissions':['$resource:read'],'params':resourceSchemas['resource']}},async B=>getResourceSchema(B['params'],h)),n[P(0x94)](P(0x9e),{'schema':{'tags':['fcore','resource'],'summary':'Generate\x20a\x20resource\x20code','description':P(0x9f),'access':'user','permissions':['$resource:read'],'params':resourceSchemas['resource'],'querystring':resourceSchemas['resourceCodeQuery']}},async B=>generateResourceCode({...B['params'],...B['query']},h)),n[P(0x94)]('/api/resource/:resource/scope/:user',{'schema':{'tags':[P(0x95),P(0xa0)],'summary':'List\x20resource\x20as\x20a\x20user\x20for\x20scope\x20testing','description':'Returns\x20resource\x20records\x20using\x20the\x20specified\x20user\x27s\x20permissions\x20and\x20access\x20scopes.\x20Admin\x20only.','access':'admin','permissions':['system:access'],'params':resourceSchemas['resourceScopeTarget']}},async B=>listResourceAsUser({...B['params'],...B['query'],'requester':user(B)},h)),n[P(0x94)]('/api/resource/:resource',{'schema':{'tags':[P(0x95),P(0xa0)],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':P(0x97),'permissions':['$resource:read'],'params':resourceSchemas['resource']}},async B=>listResources({...B['query'],...B['params'],'user':user(B)||h['config']?.[P(0xa1)]?.[P(0x97)]},h)),n[P(0xa2)]('/api/resource/:resource',{'schema':{'tags':[P(0x95),'resource'],'summary':'Create\x20resource\x20record','description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:create'],'params':resourceSchemas['resource']}},async B=>createResource({...B[P(0x96)],'data':B['body'],'user':user(B)||h['config']?.['auth']?.[P(0x97)]},h)),n['get']('/api/resource/:resource/:id',{'schema':{'tags':[P(0x95),'resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':P(0x97),'permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async B=>getResource({...B['query'],...B[P(0x96)],'user':user(B)||h[P(0xa3)]?.[P(0xa1)]?.['user']},h)),n['put']('/api/resource/:resource/:id',{'schema':{'tags':['fcore',P(0xa0)],'summary':'Update\x20resource\x20record','description':'Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':P(0x97),'permissions':['$resource:update'],'params':resourceSchemas['resourceId']}},async B=>updateResource({...B[P(0x96)],'patch':B['body'],'user':user(B)||h[P(0xa3)]?.['auth']?.['user']},h)),n['delete']('/api/resource/:resource/:id',{'schema':{'tags':[P(0x95),P(0xa0)],'summary':'Delete\x20resource\x20record','description':'Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':[P(0xa4)],'params':resourceSchemas['resourceId']}},async B=>deleteResource({...B[P(0x96)],'user':user(B)||h['config']?.['auth']?.['user']},h)),n['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':[P(0x95),'resource'],'summary':P(0xa5),'description':'Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['uploadResourceFile']}},async B=>{const u=P,G=await B['file']();if(!G)throw new Error('File\x20is\x20required');const f=B['params'][u(0xa0)],j=B['params']['id'];return uploadFile({'file':G,'metadata':{'name':G['filename'],'path':G['fields']['path']?.['value'],'resource':f,'resourceId':j},'user':B['user']},h);}),n[P(0xa6)]('/api/resource/:resource/:id/file/:fid',{'schema':{'tags':[P(0x95),'resource'],'summary':'Delete\x20resource\x20file','description':'Deletes\x20a\x20file\x20linked\x20to\x20a\x20resource\x20record\x20after\x20validating\x20it\x20belongs\x20to\x20this\x20resource\x20and\x20record.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['resourceIdFileId']}},async B=>{const X=P,{resource:G,id:f,fid:j}=B['params'],Z=await h['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',[j,G,String(f)]);if(!Z[X(0xa7)])throw new Error('File\x20not\x20found\x20for\x20this\x20resource\x20and\x20record');const e=Z['rows'][0x0]?.['file_path'],b=await h['pg']['query']('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[j,G,String(f)]);return await h['file']['delete'](e),{'success':(b['rowCount']??0x0)>0x0,'resource':G,'resourceId':f,'fileId':j};}),n['get']('/api/resource/:resource/list',{'schema':{'tags':['fcore',P(0xa0)],'summary':'List\x20resource\x20items','description':'Returns\x20resource\x20identifiers\x20and\x20display\x20text,\x20optionally\x20filtered\x20by\x20searchable\x20fields.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resource'],'querystring':resourceSchemas['resourceListQuery']}},async B=>listResourceList({...B['params'],...B['query'],'user':user(B)||h['config']?.['auth']?.[P(0x97)]},h)),n['get'](P(0xa8),{'schema':{'tags':['fcore','resource'],'summary':P(0xa9),'description':P(0xaa),'access':'user','params':resourceSchemas['resourceIdRelation'],'permissions':['$resource:read']}},async B=>listResourceRelation({...B[P(0xab)],...B['params'],'user':user(B)||h['config']?.[P(0xa1)]?.[P(0x97)]},h)),n['post'](P(0xa8),{'schema':{'tags':['fcore',P(0xa0)],'summary':'Create\x20resource\x20relation','description':'Creates\x20a\x20relation\x20for\x20a\x20resource\x20record.','access':'user','permissions':[P(0xac)],'params':resourceSchemas['resourceIdRelation']}},async B=>createResourceRelation({...B['params'],'data':B['body'],'user':user(B)||h[P(0xa3)]?.['auth']?.['user']},h)),n[P(0xa6)]('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[P(0x95),'resource'],'summary':'Delete\x20resource\x20relation','description':'Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','access':P(0x97),'permissions':['$resource:delete'],'params':resourceSchemas['resourceIdRelationId']}},async B=>deleteResourceRelation({...B['params'],'user':user(B)||h['config']?.['auth']?.['user']},h)),n['put']('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':'Update\x20resource\x20relation','description':'Updates\x20a\x20related\x20resource\x20record.','access':'user','permissions':['$resource:update'],'params':resourceSchemas['resourceIdRelationId']}},async B=>updateResourceRelation({...B['params'],'data':B[P(0xad)],'user':user(B)||h['config']?.[P(0xa1)]?.[P(0x97)]},h));};}
@@ -20,6 +20,10 @@ export declare const resourceSchemas: {
20
20
  resource: import("@sinclair/typebox").TObject<{
21
21
  resource: import("@sinclair/typebox").TString;
22
22
  }>;
23
+ resourceScopeTarget: import("@sinclair/typebox").TObject<{
24
+ resource: import("@sinclair/typebox").TString;
25
+ user: import("@sinclair/typebox").TString;
26
+ }>;
23
27
  exportResource: import("@sinclair/typebox").TObject<{
24
28
  resource: import("@sinclair/typebox").TString;
25
29
  }>;
@@ -32,6 +36,15 @@ export declare const resourceSchemas: {
32
36
  search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
33
37
  limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
34
38
  }>;
39
+ resourceListQuery: import("@sinclair/typebox").TObject<{
40
+ search: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
41
+ limit: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TInteger>;
42
+ }>;
43
+ resourceCodeQuery: import("@sinclair/typebox").TObject<{
44
+ id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
45
+ field: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
46
+ template: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
47
+ }>;
35
48
  resourceId: import("@sinclair/typebox").TObject<{
36
49
  resource: import("@sinclair/typebox").TString;
37
50
  id: import("@sinclair/typebox").TString;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/resource/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,aAAa;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;QACrC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;KACxB;CACF;AAED,eAAO,MAAM,UAAU,qCAIrB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEnD,eAAO,MAAM,eAAe;IAC1B,cAAc;;;IACd,QAAQ;;;IACR,cAAc;;;IACd,aAAa;;;;IACb,YAAY;;;;;IAKZ,UAAU;;;;IACV,oBAAoB;;;IAGpB,kBAAkB;;;;;IAKlB,oBAAoB;;;;;;IAMpB,gBAAgB;;;;;IAKhB,kBAAkB;;;;IAIlB,sBAAsB;;;;IAItB,mBAAmB;;;;;;;;;CASpB,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/resource/schema.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,EAAQ,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAEtD,OAAO,QAAQ,SAAS,CAAC;IACvB,UAAU,aAAa;QACrB,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;QAChB,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,MAAM,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,OAAO,CAAC;QACrC,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;KACxB;CACF;AAED,eAAO,MAAM,UAAU,qCAIrB,CAAC;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,UAAU,CAAC,CAAC;AAEnD,eAAO,MAAM,eAAe;IAC1B,cAAc;;;IACd,QAAQ;;;IACR,mBAAmB;;;;IACnB,cAAc;;;IACd,aAAa;;;;IACb,YAAY;;;;;IAKZ,iBAAiB;;;;IAIjB,iBAAiB;;;;;IAKjB,UAAU;;;;IACV,oBAAoB;;;IAGpB,kBAAkB;;;;;IAKlB,oBAAoB;;;;;;IAMpB,gBAAgB;;;;;IAKhB,kBAAkB;;;;IAIlB,sBAAsB;;;;IAItB,mBAAmB;;;;;;;;;CASpB,CAAC"}
@@ -1 +1 @@
1
- const w=Y;import{Type}from'@sinclair/typebox';export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':w(0x190)});function Y(w,y){w=w-0x190;const d=f();let Z=d[w];return Z;}export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type[w(0x191)]({'resource':identifier}),'exportResource':Type[w(0x191)]({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type[w(0x192)](Type[w(0x193)]()),'search':Type['Optional'](Type[w(0x193)]()),'limit':Type[w(0x192)](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type[w(0x191)]({'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[w(0x191)]({'resource':identifier,'id':identifier}),'uploadResourceFileBody':Type['Object']({'file':Type['Any'](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type['Optional'](Type['Record'](Type[w(0x193)](),Type['Unknown']())),'sort':Type['Optional'](Type['Array'](Type[w(0x193)]({'minLength':0x1}))),'search':Type['Optional'](Type['String']()),'scope':Type['Optional'](Type['String']()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type[w(0x194)]({'minimum':0x0})),'fields':Type['Optional'](Type['Array'](identifier))})};function f(){const y=['^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$','Object','Optional','String','Integer'];f=function(){return y;};return f();}
1
+ function k(h,n){h=h-0x1cd;const B=Q();let G=B[h];return G;}const h=k;import{Type}from'@sinclair/typebox';export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});function Q(){const n=['Object','String','Optional','Any','Array','Integer'];Q=function(){return n;};return Q();}export const resourceSchemas={'dictionaryName':Type['Object']({'name':identifier}),'resource':Type['Object']({'resource':identifier}),'resourceScopeTarget':Type[h(0x1cd)]({'resource':identifier,'user':identifier}),'exportResource':Type[h(0x1cd)]({'resource':identifier}),'resourceField':Type[h(0x1cd)]({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type['Optional'](Type['String']()),'search':Type['Optional'](Type[h(0x1ce)]()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceListQuery':Type[h(0x1cd)]({'search':Type['Optional'](Type['String']()),'limit':Type[h(0x1cf)](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceCodeQuery':Type[h(0x1cd)]({'id':Type['Optional'](Type['String']({'minLength':0x1,'maxLength':0x80})),'field':Type['Optional'](identifier),'template':Type['Optional'](Type['String']({'maxLength':0x3e8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type[h(0x1cd)]({'include':Type[h(0x1cf)](Type['String']({'minLength':0x1}))}),'resourceIdRelation':Type['Object']({'resource':identifier,'id':identifier,'relation':identifier}),'resourceIdRelationId':Type[h(0x1cd)]({'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[h(0x1d0)](),'fileName':Type['String']({'minLength':0x1,'maxLength':0xff})}),'exportResourceQuery':Type['Object']({'filter':Type[h(0x1cf)](Type['Record'](Type['String'](),Type['Unknown']())),'sort':Type['Optional'](Type[h(0x1d1)](Type['String']({'minLength':0x1}))),'search':Type[h(0x1cf)](Type['String']()),'scope':Type[h(0x1cf)](Type[h(0x1ce)]()),'limit':Type[h(0x1cf)](Type[h(0x1d2)]({'minimum':0x1,'maximum':0xc8})),'offset':Type[h(0x1cf)](Type['Integer']({'minimum':0x0})),'fields':Type[h(0x1cf)](Type['Array'](identifier))})};
@@ -1 +1 @@
1
- function Y(w,y){w=w-0xbb;const d=f();let Z=d[w];return Z;}function f(){const M=['body'];f=function(){return M;};return f();}export async function addNote(w,y){const Z=Y,d=await y['pg']['query']('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[w['resource'],String(w['id']),w[Z(0xbb)]]);return d['rows'][0x0];}
1
+ function Q(){const f=['query'];Q=function(){return f;};return Q();}function k(h,n){h=h-0x11a;const B=Q();let G=B[h];return G;}export async function addNote(h,n){const G=k,B=await n['pg'][G(0x11a)]('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[h['resource'],String(h['id']),h['body']]);return B['rows'][0x0];}
@@ -1 +1 @@
1
- export async function addResourceFile(w,y){const Z=Y,d=await y['pg'][Z(0x85)]('\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',[w['resource'],String(w['id']),w[Z(0x86)],w['size']??null]);return d[Z(0x87)][0x0];}function Y(w,y){w=w-0x85;const d=f();let Z=d[w];return Z;}function f(){const M=['query','filePath','rows'];f=function(){return M;};return f();}
1
+ function k(h,n){h=h-0x1ce;const B=Q();let G=B[h];return G;}export async function addResourceFile(h,n){const G=k,B=await n['pg']['query']('\x0a\x20\x20\x20\x20\x20\x20\x20\x20INSERT\x20INTO\x20admin.files\x20(resource,\x20resource_id,\x20file_path,\x20size)\x0a\x20\x20\x20\x20\x20\x20\x20\x20VALUES\x20($1,\x20$2,\x20$3,\x20$4)\x0a\x20\x20\x20\x20\x20\x20\x20\x20RETURNING\x20*\x0a\x20\x20\x20\x20\x20\x20',[h['resource'],String(h['id']),h['filePath'],h[G(0x1ce)]??null]);return B[G(0x1cf)][0x0];}function Q(){const f=['size','rows'];Q=function(){return f;};return Q();}
@@ -1 +1 @@
1
- function Y(w,y){w=w-0x10e;const d=f();let Z=d[w];return Z;}export async function createResourceRelation(w,y){const s=Y,{resource:d,id:Z,relation:M,data:H,user:Q}=w;return y['resource'][s(0x10e)]({'name':d,'id':Z,'relation':M,'data':H,'user':Q});}function f(){const j=['createRelation'];f=function(){return j;};return f();}
1
+ function k(h,n){h=h-0x169;const B=Q();let G=B[h];return G;}export async function createResourceRelation(h,n){const e=k,{resource:B,id:G,relation:f,data:j,user:Z}=h;return n['resource'][e(0x169)]({'name':B,'id':G,'relation':f,'data':j,'user':Z});}function Q(){const b=['createRelation'];Q=function(){return b;};return Q();}
@@ -1 +1 @@
1
- function f(){var Z=['resource'];f=function(){return Z;};return f();}function Y(w,y){w=w-0x15f;var d=f();var Z=d[w];return Z;}export async function createResource(w,y){var d=Y;return y[d(0x15f)]['create']({'name':w['resource'],'data':w['data'],'user':w['user']});}
1
+ function k(h,n){h=h-0x17c;var B=Q();var G=B[h];return G;}export async function createResource(h,n){var B=k;return n['resource']['create']({'name':h['resource'],'data':h['data'],'user':h[B(0x17c)]});}function Q(){var G=['user'];Q=function(){return G;};return Q();}
@@ -1 +1 @@
1
- function f(){const s=['resource','deleteRelation'];f=function(){return s;};return f();}function Y(w,y){w=w-0xf8;const d=f();let Z=d[w];return Z;}export async function deleteResourceRelation(w,y){const Q=Y,{resource:d,id:Z,relation:M,relationId:H}=w;return y[Q(0xf8)][Q(0xf9)]({'name':d,'id':Z,'relation':M,'relationId':H});}
1
+ export async function deleteResourceRelation(h,n){const {resource:B,id:G,relation:f,relationId:j}=h;return n['resource']['deleteRelation']({'name':B,'id':G,'relation':f,'relationId':j});}