@opengis/fcore 0.0.1-beta.26 → 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 (139) hide show
  1. package/LICENSE +3 -3
  2. package/README.md +71 -71
  3. package/dist/config.js +1 -1
  4. package/dist/context.js +1 -1
  5. package/dist/errors.js +1 -1
  6. package/dist/fastify.js +1 -1
  7. package/dist/fcore.js +1 -1
  8. package/dist/migrations/cli.js +1 -1
  9. package/dist/migrations/runner.js +1 -1
  10. package/dist/modules/auth/adduser-cli.js +1 -1
  11. package/dist/modules/auth/passwd-cli.js +1 -1
  12. package/dist/modules/auth/permission-cli.js +1 -1
  13. package/dist/modules/auth/route.js +1 -1
  14. package/dist/modules/auth/schema.js +1 -1
  15. package/dist/modules/auth/services/change-password.js +1 -1
  16. package/dist/modules/auth/services/get-current-user.js +1 -1
  17. package/dist/modules/auth/services/registration.js +1 -1
  18. package/dist/modules/auth/services/verify-two-factor.js +1 -1
  19. package/dist/modules/file/mime.js +1 -1
  20. package/dist/modules/file/route.js +1 -1
  21. package/dist/modules/file/schema.js +1 -1
  22. package/dist/modules/file/services/get-file.js +1 -1
  23. package/dist/modules/file/services/resize-file.js +1 -1
  24. package/dist/modules/file/services/upload-file.js +1 -1
  25. package/dist/modules/resource/route.d.ts.map +1 -1
  26. package/dist/modules/resource/route.js +1 -1
  27. package/dist/modules/resource/schema.d.ts +13 -0
  28. package/dist/modules/resource/schema.d.ts.map +1 -1
  29. package/dist/modules/resource/schema.js +1 -1
  30. package/dist/modules/resource/services/add-note.js +1 -1
  31. package/dist/modules/resource/services/add-resource-file.js +1 -1
  32. package/dist/modules/resource/services/create-resource-relation.js +1 -1
  33. package/dist/modules/resource/services/create-resource.js +1 -1
  34. package/dist/modules/resource/services/delete-resource-relation.js +1 -1
  35. package/dist/modules/resource/services/delete-resource.js +1 -1
  36. package/dist/modules/resource/services/export-resource.js +1 -1
  37. package/dist/modules/resource/services/generate-resource-code.d.ts +16 -0
  38. package/dist/modules/resource/services/generate-resource-code.d.ts.map +1 -0
  39. package/dist/modules/resource/services/generate-resource-code.js +1 -0
  40. package/dist/modules/resource/services/get-resource-schema.d.ts +6 -0
  41. package/dist/modules/resource/services/get-resource-schema.d.ts.map +1 -0
  42. package/dist/modules/resource/services/get-resource-schema.js +1 -0
  43. package/dist/modules/resource/services/get-resource.js +1 -1
  44. package/dist/modules/resource/services/list-resource-as-user.d.ts +8 -0
  45. package/dist/modules/resource/services/list-resource-as-user.d.ts.map +1 -0
  46. package/dist/modules/resource/services/list-resource-as-user.js +1 -0
  47. package/dist/modules/resource/services/list-resource-list.d.ts +20 -0
  48. package/dist/modules/resource/services/list-resource-list.d.ts.map +1 -0
  49. package/dist/modules/resource/services/list-resource-list.js +1 -0
  50. package/dist/modules/resource/services/list-resource-relation.js +1 -1
  51. package/dist/modules/resource/services/list-resources.d.ts.map +1 -1
  52. package/dist/modules/resource/services/list-resources.js +1 -1
  53. package/dist/modules/resource/services/search-resource.js +1 -1
  54. package/dist/modules/resource/services/suggest-resource.js +1 -1
  55. package/dist/modules/resource/services/update-resource-relation.js +1 -1
  56. package/dist/modules/resource/services/update-resource.js +1 -1
  57. package/dist/modules/resource/services/upload-resource-file.js +1 -1
  58. package/dist/modules/system/route.d.ts.map +1 -1
  59. package/dist/modules/system/route.js +1 -1
  60. package/dist/modules/system/schema.d.ts +22 -0
  61. package/dist/modules/system/schema.d.ts.map +1 -1
  62. package/dist/modules/system/schema.js +1 -1
  63. package/dist/modules/system/services/check-system.js +1 -1
  64. package/dist/modules/system/services/get-access.js +1 -1
  65. package/dist/modules/system/services/get-api-list.js +1 -1
  66. package/dist/modules/system/services/get-audit-log.js +1 -1
  67. package/dist/modules/system/services/get-dictionary.js +1 -1
  68. package/dist/modules/system/services/get-resource-access.d.ts +23 -0
  69. package/dist/modules/system/services/get-resource-access.d.ts.map +1 -0
  70. package/dist/modules/system/services/get-resource-access.js +1 -0
  71. package/dist/modules/system/services/get-resource-scopes.d.ts +16 -0
  72. package/dist/modules/system/services/get-resource-scopes.d.ts.map +1 -0
  73. package/dist/modules/system/services/get-resource-scopes.js +1 -0
  74. package/dist/modules/system/services/get-system-log.js +1 -1
  75. package/dist/modules/system/services/get-system-settings.js +1 -1
  76. package/dist/modules/system/services/list-dictionaries.js +1 -1
  77. package/dist/modules/system/services/set-access.d.ts +1 -0
  78. package/dist/modules/system/services/set-access.d.ts.map +1 -1
  79. package/dist/modules/system/services/set-access.js +1 -1
  80. package/dist/modules/system/services/set-resource-access.d.ts +18 -0
  81. package/dist/modules/system/services/set-resource-access.d.ts.map +1 -0
  82. package/dist/modules/system/services/set-resource-access.js +1 -0
  83. package/dist/modules/system/services/set-resource-scopes.d.ts +10 -0
  84. package/dist/modules/system/services/set-resource-scopes.d.ts.map +1 -0
  85. package/dist/modules/system/services/set-resource-scopes.js +1 -0
  86. package/dist/modules/system/services/update-dictionary.js +1 -1
  87. package/dist/modules/system/services/update-system-settings.js +1 -1
  88. package/dist/modules/utils/require-admin.js +1 -1
  89. package/dist/modules/utils/safe-user.js +1 -1
  90. package/dist/modules/utils/unsupported.js +1 -1
  91. package/dist/plugins/audit/audit.js +1 -1
  92. package/dist/plugins/audit/services/write-audit.js +1 -1
  93. package/dist/plugins/auth/get-user-permissions.js +1 -1
  94. package/dist/plugins/auth/index.js +1 -1
  95. package/dist/plugins/auth/verifyUser.js +1 -1
  96. package/dist/plugins/dictionary.js +1 -1
  97. package/dist/plugins/file.js +1 -1
  98. package/dist/plugins/jwt.js +1 -1
  99. package/dist/plugins/logger/index.js +1 -1
  100. package/dist/plugins/logger/transport.js +1 -1
  101. package/dist/plugins/pg.js +1 -1
  102. package/dist/plugins/redis.js +1 -1
  103. package/dist/plugins/resource/resource.js +1 -1
  104. package/dist/plugins/resource/resource.registry.js +1 -1
  105. package/dist/plugins/resource/resource.types.d.ts +18 -0
  106. package/dist/plugins/resource/resource.types.d.ts.map +1 -1
  107. package/dist/plugins/resource/services/add-dictionary-lookup-data.js +1 -1
  108. package/dist/plugins/resource/services/add-file-token.js +1 -1
  109. package/dist/plugins/resource/services/add-table-lookup-data.js +1 -1
  110. package/dist/plugins/resource/services/create-relation.js +1 -1
  111. package/dist/plugins/resource/services/create.js +1 -1
  112. package/dist/plugins/resource/services/delete-relation.js +1 -1
  113. package/dist/plugins/resource/services/delete.js +1 -1
  114. package/dist/plugins/resource/services/find-one.d.ts.map +1 -1
  115. package/dist/plugins/resource/services/find-one.js +1 -1
  116. package/dist/plugins/resource/services/find-relation.js +1 -1
  117. package/dist/plugins/resource/services/find.d.ts.map +1 -1
  118. package/dist/plugins/resource/services/find.js +1 -1
  119. package/dist/plugins/resource/services/get-table-columns.js +1 -1
  120. package/dist/plugins/resource/services/update-relation.js +1 -1
  121. package/dist/plugins/resource/services/update.js +1 -1
  122. package/dist/plugins/resource/utils/auto-index.js +1 -1
  123. package/dist/plugins/resource/utils/fields.js +1 -1
  124. package/dist/plugins/resource/utils/filters.js +1 -1
  125. package/dist/plugins/resource/utils/permissions.js +1 -1
  126. package/dist/plugins/resource/utils/scope.d.ts +10 -0
  127. package/dist/plugins/resource/utils/scope.d.ts.map +1 -0
  128. package/dist/plugins/resource/utils/scope.js +1 -0
  129. package/dist/plugins/resource/utils/sort.js +1 -1
  130. package/dist/plugins/resource/utils/sql.js +1 -1
  131. package/dist/plugins/resource/utils/summary.d.ts +5 -1
  132. package/dist/plugins/resource/utils/summary.d.ts.map +1 -1
  133. package/dist/plugins/resource/utils/summary.js +1 -1
  134. package/dist/shared/getIP.js +1 -1
  135. package/migrations/20260903130000_move_notes_files_to_admin.sql +17 -17
  136. package/migrations/20260903140000_settings_nulls_not_distinct.sql +18 -18
  137. package/migrations/20260929120000_allow_user_only_role_scopes.sql +2 -0
  138. package/migrations/20260929_role_scope.sql +32 -0
  139. package/package.json +92 -92
@@ -1 +1 @@
1
- import{listResources}from'./services/list-resources.js';import{getResource}from'./services/get-resource.js';function G(w,h){w=w-0x12b;const S=z();let X=S[w];return X;}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';function z(){const y=['/api/resource/:resource/search','resource','Searches\x20records\x20in\x20a\x20registered\x20resource.','$resource:read','config','get','/api/suggest/:resource/:field','fcore','user','resourceField','suggestQuery','/api/resource/:resource/export','auth','params','post','Create\x20resource\x20record','$resource:create','Update\x20resource\x20record','Updates\x20a\x20record\x20in\x20a\x20registered\x20resource.','Delete\x20resource\x20record','Deletes\x20a\x20record\x20from\x20a\x20registered\x20resource.','resourceId','Upload\x20resource\x20file','Uploads\x20a\x20file\x20to\x20a\x20Resource\x20record\x20and\x20stores\x20its\x20metadata.','$resource:update','/api/resource/:resource/:id/file/:fid','File\x20not\x20found\x20for\x20this\x20resource\x20and\x20record','rows','query','delete','$resource:delete','resourceIdRelationId','put','Updates\x20a\x20related\x20resource\x20record.'];z=function(){return y;};return z();}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 h=>{const e=G;h['get'](e(0x12b),{'schema':{'tags':['fcore',e(0x12c)],'summary':'Search\x20resource','description':e(0x12d),'access':'user','permissions':[e(0x12e)],'params':resourceSchemas['resource']}},async S=>searchResource({...S['query'],...S['params'],'user':user(S)||w[e(0x12f)]?.['auth']?.['user']},w)),h[e(0x130)](e(0x131),{'schema':{'tags':[e(0x132),'resource'],'summary':'Suggest\x20resource\x20values','description':'Returns\x20suggested\x20values\x20for\x20a\x20resource\x20field.','access':e(0x133),'permissions':['$resource:read'],'params':resourceSchemas[e(0x134)],'querystring':resourceSchemas[e(0x135)]}},async S=>suggestResource({...S['query'],...S['params'],'user':user(S)||w['config']?.['auth']?.['user']},w)),h[e(0x130)](e(0x136),{'schema':{'tags':['fcore','resource'],'summary':'Export\x20resource\x20records','description':'Exports\x20readable\x20records\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['exportResource'],'querystring':resourceSchemas['exportResourceQuery']}},async S=>exportResource({...S['query'],...S['params'],'user':user(S)||w['config']?.[e(0x137)]?.['user']},w)),h[e(0x130)]('/api/resource/:resource',{'schema':{'tags':[e(0x132),'resource'],'summary':'List\x20resource\x20records','description':'Returns\x20records\x20from\x20a\x20registered\x20resource.','access':e(0x133),'permissions':['$resource:read'],'params':resourceSchemas['resource']}},async S=>listResources({...S['query'],...S[e(0x138)],'user':user(S)||w['config']?.['auth']?.['user']},w)),h[e(0x139)]('/api/resource/:resource',{'schema':{'tags':[e(0x132),'resource'],'summary':e(0x13a),'description':'Creates\x20a\x20record\x20in\x20a\x20registered\x20resource.','access':'user','permissions':[e(0x13b)],'params':resourceSchemas[e(0x12c)]}},async S=>createResource({...S['params'],'data':S['body'],'user':user(S)||w['config']?.[e(0x137)]?.[e(0x133)]},w)),h['get']('/api/resource/:resource/:id',{'schema':{'tags':[e(0x132),'resource'],'summary':'Get\x20resource\x20record','description':'Returns\x20one\x20record\x20from\x20a\x20registered\x20resource.','access':'user','permissions':['$resource:read'],'params':resourceSchemas['resourceId'],'querystring':resourceSchemas['resourceIncludeQuery']}},async S=>getResource({...S['query'],...S['params'],'user':user(S)||w['config']?.['auth']?.[e(0x133)]},w)),h['put']('/api/resource/:resource/:id',{'schema':{'tags':['fcore','resource'],'summary':e(0x13c),'description':e(0x13d),'access':e(0x133),'permissions':['$resource:update'],'params':resourceSchemas['resourceId']}},async S=>updateResource({...S['params'],'patch':S['body'],'user':user(S)||w[e(0x12f)]?.[e(0x137)]?.['user']},w)),h['delete']('/api/resource/:resource/:id',{'schema':{'tags':['fcore',e(0x12c)],'summary':e(0x13e),'description':e(0x13f),'access':'user','permissions':['$resource:delete'],'params':resourceSchemas[e(0x140)]}},async S=>deleteResource({...S[e(0x138)],'user':user(S)||w[e(0x12f)]?.['auth']?.['user']},w)),h['post']('/api/resource/:resource/:id/upload',{'schema':{'tags':[e(0x132),'resource'],'summary':e(0x141),'description':e(0x142),'access':e(0x133),'permissions':[e(0x143)],'params':resourceSchemas['uploadResourceFile']}},async S=>{const Z=e,X=await S['file']();if(!X)throw new Error('File\x20is\x20required');const Y=S['params'][Z(0x12c)],v=S['params']['id'];return uploadFile({'file':X,'metadata':{'name':X['filename'],'path':X['fields']['path']?.['value'],'resource':Y,'resourceId':v},'user':S[Z(0x133)]},w);}),h['delete'](e(0x144),{'schema':{'tags':['fcore',e(0x12c)],'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':[e(0x143)],'params':resourceSchemas['resourceIdFileId']}},async S=>{const K=e,{resource:X,id:Y,fid:v}=S['params'],D=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',[v,X,String(Y)]);if(!D['rowCount'])throw new Error(K(0x145));const o=D[K(0x146)][0x0]?.['file_path'],q=await w['pg'][K(0x147)]('DELETE\x20FROM\x20admin.files\x20WHERE\x20file_id\x20=\x20$1\x20AND\x20resource\x20=\x20$2\x20AND\x20resource_id\x20=\x20$3',[v,X,String(Y)]);return await w['file'][K(0x148)](o),{'success':(q['rowCount']??0x0)>0x0,'resource':X,'resourceId':Y,'fileId':v};}),h[e(0x130)]('/api/resource/:resource/:id/:relation',{'schema':{'tags':['fcore','resource'],'summary':'List\x20resource\x20relations','description':'Returns\x20related\x20records\x20for\x20a\x20resource\x20record.','access':'user','params':resourceSchemas['resourceIdRelation'],'permissions':['$resource:read']}},async S=>listResourceRelation({...S[e(0x147)],...S[e(0x138)],'user':user(S)||w['config']?.[e(0x137)]?.['user']},w)),h['post']('/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 S=>createResourceRelation({...S[e(0x138)],'data':S['body'],'user':user(S)||w['config']?.['auth']?.[e(0x133)]},w)),h[e(0x148)]('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':['fcore','resource'],'summary':'Delete\x20resource\x20relation','description':'Deletes\x20a\x20relation\x20from\x20a\x20resource\x20record.','access':'user','permissions':[e(0x149)],'params':resourceSchemas[e(0x14a)]}},async S=>deleteResourceRelation({...S['params'],'user':user(S)||w['config']?.['auth']?.['user']},w)),h[e(0x14b)]('/api/resource/:resource/:id/:relation/:relationId',{'schema':{'tags':[e(0x132),'resource'],'summary':'Update\x20resource\x20relation','description':e(0x14c),'access':e(0x133),'permissions':['$resource:update'],'params':resourceSchemas['resourceIdRelationId']}},async S=>updateResourceRelation({...S['params'],'data':S['body'],'user':user(S)||w['config']?.['auth']?.['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
- function G(w,h){w=w-0x111;const S=z();let X=S[w];return X;}const w=G;import{Type}from'@sinclair/typebox';export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':w(0x111)});export const resourceSchemas={'dictionaryName':Type[w(0x112)]({'name':identifier}),'resource':Type['Object']({'resource':identifier}),'exportResource':Type[w(0x112)]({'resource':identifier}),'resourceField':Type['Object']({'resource':identifier,'field':identifier}),'suggestQuery':Type['Object']({'q':Type['Optional'](Type['String']()),'search':Type[w(0x113)](Type[w(0x114)]()),'limit':Type['Optional'](Type['Integer']({'minimum':0x1,'maximum':0xc8}))}),'resourceId':Type['Object']({'resource':identifier,'id':identifier}),'resourceIncludeQuery':Type[w(0x112)]({'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['Object']({'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(0x114)](),Type['Unknown']())),'sort':Type[w(0x113)](Type[w(0x115)](Type['String']({'minLength':0x1}))),'search':Type[w(0x113)](Type['String']()),'scope':Type[w(0x113)](Type['String']()),'limit':Type['Optional'](Type[w(0x116)]({'minimum':0x1,'maximum':0xc8})),'offset':Type['Optional'](Type[w(0x116)]({'minimum':0x0})),'fields':Type['Optional'](Type[w(0x115)](identifier))})};function z(){const h=['^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$','Object','Optional','String','Array','Integer'];z=function(){return h;};return z();}
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
- export async function addNote(w,h){const X=G,S=await h['pg'][X(0x7c)]('INSERT\x20INTO\x20admin.notes(resource,resource_id,body)\x20VALUES\x20($1,$2,$3)\x20RETURNING\x20*',[w['resource'],String(w['id']),w['body']]);return S['rows'][0x0];}function G(w,h){w=w-0x7c;const S=z();let X=S[w];return X;}function z(){const Y=['query'];z=function(){return Y;};return z();}
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
- function G(w,h){w=w-0x155;const S=z();let X=S[w];return X;}export async function addResourceFile(w,h){const X=G,S=await h['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',[w[X(0x155)],String(w['id']),w[X(0x156)],w['size']??null]);return S['rows'][0x0];}function z(){const Y=['resource','filePath'];z=function(){return Y;};return z();}
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
- export async function createResourceRelation(w,h){const {resource:S,id:X,relation:Y,data:v,user:D}=w;return h['resource']['createRelation']({'name':S,'id':X,'relation':Y,'data':v,'user':D});}
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 z(){var X=['create','data'];z=function(){return X;};return z();}function G(w,h){w=w-0x1d4;var S=z();var X=S[w];return X;}export async function createResource(w,h){var S=G;return h['resource'][S(0x1d4)]({'name':w['resource'],'data':w[S(0x1d5)],'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 G(w,h){w=w-0xe6;const S=z();let X=S[w];return X;}function z(){const o=['deleteRelation'];z=function(){return o;};return z();}export async function deleteResourceRelation(w,h){const D=G,{resource:S,id:X,relation:Y,relationId:v}=w;return h['resource'][D(0xe6)]({'name':S,'id':X,'relation':Y,'relationId':v});}
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});}
@@ -1 +1 @@
1
- function z(){var X=['resource'];z=function(){return X;};return z();}function G(w,h){w=w-0x1b5;var S=z();var X=S[w];return X;}export async function deleteResource(w,h){var S=G;return h[S(0x1b5)]['delete']({'name':w['resource'],'id':w['id'],'user':w['user']});}
1
+ function k(h,n){h=h-0x95;var B=Q();var G=B[h];return G;}export async function deleteResource(h,n){var B=k;return n['resource'][B(0x95)]({'name':h['resource'],'id':h['id'],'user':h['user']});}function Q(){var G=['delete'];Q=function(){return G;};return Q();}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function exportResource(w,h){const X=G,S=await h['resource'][X(0x1f4)]({'name':w[X(0x1f5)],'query':{'filter':parseFilterQuery(w),'sort':w['sort'],'search':w['search'],'limit':w['limit'],'offset':w['offset'],'fields':w[X(0x1f6)]},'user':w['user']});return S['rows'];}function G(w,h){w=w-0x1f4;const S=z();let X=S[w];return X;}function z(){const Y=['find','resource','fields'];z=function(){return Y;};return z();}
1
+ import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function k(h,n){h=h-0x189;const B=Q();let G=B[h];return G;}export async function exportResource(h,n){const G=k,B=await n[G(0x189)][G(0x18a)]({'name':h[G(0x189)],'query':{'filter':parseFilterQuery(h),'sort':h['sort'],'search':h['search'],'limit':h[G(0x18b)],'offset':h[G(0x18c)],'fields':h['fields']},'user':h['user']});return B[G(0x18d)];}function Q(){const f=['resource','find','limit','offset','rows'];Q=function(){return f;};return Q();}
@@ -0,0 +1,16 @@
1
+ import type { AppContext } from "../../../context.js";
2
+ type CodeParams = {
3
+ resource: string;
4
+ id?: string;
5
+ field?: string;
6
+ template?: string;
7
+ };
8
+ export declare function generateResourceCode(params: CodeParams, ctx: AppContext): Promise<{
9
+ resource: string;
10
+ id?: string;
11
+ field?: string;
12
+ template: string | null;
13
+ code: string | null;
14
+ }>;
15
+ export {};
16
+ //# sourceMappingURL=generate-resource-code.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-resource-code.d.ts","sourceRoot":"","sources":["../../../../src/modules/resource/services/generate-resource-code.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKtD,KAAK,UAAU,GAAG;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAAC;AA2GF,wBAAsB,oBAAoB,CACxC,MAAM,EAAE,UAAU,EAClB,GAAG,EAAE,UAAU,GACd,OAAO,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB,CAAC,CAyED"}
@@ -0,0 +1 @@
1
+ import{ValidationError}from'../../../errors.js';import{qi,qt}from'../../../plugins/resource/utils/sql.js';function k(h,n){h=h-0x16d;const B=Q();let G=B[h];return G;}function relationValue(h,n,B){const G=n['fields'][B]?.['column']??B;return h[G]??h[B];}async function resolvePath(h,n,B,G){const m=k,[f,...j]=h['split']('.');if(!f)return undefined;const Z=B['relations']?.[f];if(!Z||!j['length']||!Z['resource'])return relationValue(n,B,h);const e=G['resource']['get'](Z['resource']),b=e[m(0x16d)];let P,u;if(Z[m(0x16e)])P=relationValue(n,B,Z['localKey']),u=b;else{if(Z['foreignKey'])P=relationValue(n,B,B['key']),u=Z['foreignKey'];else return undefined;}if(P===null||P===undefined)return undefined;const X=e[m(0x16f)][u]?.['column']??u,H=await G['pg'][m(0x170)]('SELECT\x20*\x20FROM\x20'+qt(e[m(0x171)])+'\x20t\x20WHERE\x20t.'+qi(X)+'\x20=\x20$1'+(Z[m(0x172)]?m(0x173)+Z['where']+')':'')+m(0x174),[P]),i=H['rows'][0x0];if(!i)return undefined;const p=j[0x0];if(!p)return undefined;if(j[m(0x175)]===0x1)return relationValue(i,e,p);return resolvePath(j['join']('.'),i,e,G);}function Q(){const O=['key','localKey','fields','query','table','where','\x20AND\x20(','\x20LIMIT\x201','length','push','WHERE\x20','created_at','SELECT\x20count(*)::int\x20+\x201\x20AS\x20num,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(*)\x20FILTER\x20(WHERE\x20','\x20>=\x20',')::int\x20+\x201\x20AS\x20mnum\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20','mnum','Unknown\x20resource\x20field:\x20','name','field','rows','has','ynum','getMonth','padStart','replace'];Q=function(){return O;};return Q();}async function countValues(h,n,B,G){const A=k,f=[],j=h['where']?['('+h['where']+')']:[];n!==undefined&&(f[A(0x176)](n),j['push']('t.'+qi(h['key'])+'\x20<>\x20$'+f['length']));const Z=j['length']?A(0x177)+j['join']('\x20AND\x20'):'',e=h[A(0x16f)]['created_at'],b=e?'t.'+qi(e['column']??A(0x178)):undefined,P=new Date(G['getFullYear'](),0x0,0x1),u=new Date(G['getFullYear'](),G['getMonth'](),0x1);if(b){f[A(0x176)](P,u);const i='$'+(f[A(0x175)]-0x1),p='$'+f['length'],z=await B['pg'][A(0x170)](A(0x179)+b+'\x20>=\x20'+i+')::int\x20+\x201\x20AS\x20ynum,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(*)\x20FILTER\x20(WHERE\x20'+b+A(0x17a)+p+A(0x17b)+qt(h['table'])+'\x20t\x20'+Z,f),t=z['rows'][0x0];return{'num':Number(t?.['num']??0x1),'ynum':Number(t?.['ynum']??0x1),'mnum':Number(t?.[A(0x17c)]??0x1)};}const X=await B['pg']['query']('SELECT\x20count(*)::int\x20+\x201\x20AS\x20num\x20FROM\x20'+qt(h[A(0x171)])+'\x20t\x20'+Z,f),H=Number(X['rows'][0x0]?.['num']??0x1);return{'num':H,'ynum':H,'mnum':H};}export async function generateResourceCode(h,n){const U=k,B=n['resource']['get'](h['resource']);if(h['field']&&!B[U(0x16f)][h['field']])throw new ValidationError(U(0x17d)+h['field']);const G=h['template']??(h['field']?B[U(0x16f)][h['field']]?.['code_template']:undefined);if(!G)return{'resource':B[U(0x17e)],...h['id']!==undefined?{'id':h['id']}:{},...h['field']?{'field':h[U(0x17f)]}:{},'template':null,'code':null};const f=new Date(),j=await countValues(B,h['id'],n,f);let Z={};if(h['id']!==undefined){const u=await n['pg']['query']('SELECT\x20*\x20FROM\x20'+qt(B[U(0x171)])+'\x20t\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20t.'+qi(B[U(0x16d)])+'\x20=\x20$1'+(B['where']?'\x20AND\x20('+B[U(0x172)]+')':'')+'\x0a\x20\x20\x20\x20\x20\x20\x20LIMIT\x201',[h['id']]);Z=u[U(0x180)][0x0]??{};}const e=[...G['matchAll'](/\{([A-Za-z_][A-Za-z0-9_.]*)(?::(\d+))?\}/g)],b=new Map();for(const X of e){const H=X[0x1];if(!H||b[U(0x181)](X[0x0]))continue;const i=Number(X[0x2]??0x0);let p;switch(H){case'num':p=j['num'];break;case U(0x182):p=j[U(0x182)];break;case U(0x17c):p=j['mnum'];break;case'yyyy':p=String(f['getFullYear']());break;case'yy':p=String(f['getFullYear']())['slice'](-0x2);break;case'mm':p=String(f[U(0x183)]()+0x1)[U(0x184)](0x2,'0');break;case'dd':p=String(f['getDate']())['padStart'](0x2,'0');break;case'resource':p=B['name'];break;case'resource_id':p=h['id'];break;default:p=h['id']===undefined?undefined:await resolvePath(H,Z,B,n);}if(p===null||p===undefined||p==='')throw new ValidationError('Cannot\x20resolve\x20code\x20template\x20variable:\x20{'+H+'}');const z=String(p);b['set'](X[0x0],i&&/^\d+$/['test'](z)?z[U(0x184)](i,'0'):z);}const P=G[U(0x185)](/\{([A-Za-z_][A-Za-z0-9_.]*)(?::(\d+))?\}/g,t=>b['get'](t)??t);return{'resource':B['name'],...h['id']!==undefined?{'id':h['id']}:{},...h['field']?{'field':h['field']}:{},'template':G,'code':P};}
@@ -0,0 +1,6 @@
1
+ import type { AppContext } from "../../../context.js";
2
+ import type { ResourceSchemaDto } from "../../../plugins/resource/resource.types.js";
3
+ export declare function getResourceSchema(params: {
4
+ resource: string;
5
+ }, ctx: AppContext): ResourceSchemaDto;
6
+ //# sourceMappingURL=get-resource-schema.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-resource-schema.d.ts","sourceRoot":"","sources":["../../../../src/modules/resource/services/get-resource-schema.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AACtD,OAAO,KAAK,EAEV,iBAAiB,EAElB,MAAM,6CAA6C,CAAC;AAyDrD,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC5B,GAAG,EAAE,UAAU,GACd,iBAAiB,CAOnB"}
@@ -0,0 +1 @@
1
+ function variableType(h){const p=k;switch(h){case p(0x157):case p(0x158):return'number';case'boolean':return p(0x159);case p(0x15a):case p(0x15b):case'geom':return p(0x15c);default:return p(0x15d);}}function buildVariables(h,n,B='',G=new Set()){const z=k,f=new Set(G)[z(0x15e)](h['name']),j=[];for(const [Z,e]of Object['entries'](h['fields'])){if(e[z(0x15f)]===![]||e['readable']===![])continue;j['push']({'key':Z,'path':B?B+'.'+Z:Z,'type':variableType(e['type'])});}for(const [b,P]of Object[z(0x160)](h['relations']??{})){if(!P['resource']||!n['resource'][z(0x161)](P['resource']))continue;const u=n['resource'][z(0x162)](P[z(0x163)]),X=B?B+'.'+b:b,H=P['type']==='many',i={'key':b,'path':X,'type':H?'array':z(0x15c),'resource':P['resource'],'variables':f['has'](u[z(0x164)])?[]:buildVariables(u,n,X,f)};j['push'](i);}return j;}function k(h,n){h=h-0x157;const B=Q();let G=B[h];return G;}export function getResourceSchema(h,n){const t=k,B=n[t(0x163)]['get'](h[t(0x163)]);return{'resource':B[t(0x164)],...B[t(0x165)]?{'title':B['title']}:{},'variables':buildVariables(B,n)};}function Q(){const m=['number','integer','boolean','json','geometry','object','string','add','read','entries','has','get','resource','name','title'];Q=function(){return m;};return Q();}
@@ -1 +1 @@
1
- function G(w,h){w=w-0x72;var S=z();var X=S[w];return X;}export async function getResource(w,h){var S=G;return h['resource']['findOne']({'name':w[S(0x72)],'id':w['id'],'query':{'include':w[S(0x73)]},'user':w[S(0x74)]});}function z(){var X=['resource','include','user'];z=function(){return X;};return z();}
1
+ function k(h,n){h=h-0x11a;var B=Q();var G=B[h];return G;}function Q(){var G=['resource','findOne','user'];Q=function(){return G;};return Q();}export async function getResource(h,n){var B=k;return n[B(0x11a)][B(0x11b)]({'name':h[B(0x11a)],'id':h['id'],'query':{'include':h['include']},'user':h[B(0x11c)]});}
@@ -0,0 +1,8 @@
1
+ import type { AppContext, User } from "../../../context.js";
2
+ export declare function listResourceAsUser(params: {
3
+ resource: string;
4
+ user: string;
5
+ requester?: User;
6
+ [key: string]: unknown;
7
+ }, ctx: AppContext): Promise<unknown>;
8
+ //# sourceMappingURL=list-resource-as-user.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-resource-as-user.d.ts","sourceRoot":"","sources":["../../../../src/modules/resource/services/list-resource-as-user.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAM5D,wBAAsB,kBAAkB,CACtC,MAAM,EAAE;IACN,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,IAAI,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB,EACD,GAAG,EAAE,UAAU,GACd,OAAO,CAAC,OAAO,CAAC,CAyClB"}
@@ -0,0 +1 @@
1
+ import{ForbiddenError,NotFoundError}from'../../../errors.js';import{getUserPermissions}from'../../../plugins/auth/get-user-permissions.js';function k(h,n){h=h-0x132;const B=Q();let G=B[h];return G;}function Q(){const b=['requester','query','rows','User\x20not\x20found:\x20','find','search','offset'];Q=function(){return b;};return Q();}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';import{getUserResourceScopes}from'../../../plugins/resource/utils/scope.js';export async function listResourceAsUser(h,n){const e=k;if(h[e(0x132)]?.['type']!=='admin')throw new ForbiddenError('Only\x20admins\x20can\x20test\x20resource\x20scopes\x20for\x20another\x20user');const B=await n['pg'][e(0x133)]('SELECT\x20uid,\x20user_type\x20AS\x20type\x20FROM\x20admin.users\x20WHERE\x20uid\x20=\x20$1\x20OR\x20login\x20=\x20$1\x20LIMIT\x201',[h['user']]),G=B[e(0x134)][0x0];if(!G)throw new NotFoundError(e(0x135)+h['user']);const f={'id':G['uid'],'type':G['type'],'permissions':await getUserPermissions(G['uid'],n)},[j,Z]=await Promise['all']([n['resource'][e(0x136)]({'name':h['resource'],'query':{'filter':parseFilterQuery(h),'sort':h['sort'],'search':h[e(0x137)],'include':h['include'],'scope':h['scope'],'limit':h['limit'],'offset':h[e(0x138)]??(h['page']?Math['max'](Number(h['page'])-0x1,0x0):0x0)*Number(h['limit']??0x14)},'user':f}),getUserResourceScopes(f['id'],h['resource'],n['pg'])]);return{...j,'scopes':Z};}
@@ -0,0 +1,20 @@
1
+ import type { AppContext } from "../../../context.js";
2
+ import type { ResourceUser } from "../../../plugins/resource/resource.types.js";
3
+ type ResourceListItem = {
4
+ id: unknown;
5
+ text: string;
6
+ };
7
+ export declare function listResourceList(params: {
8
+ resource: string;
9
+ search?: string;
10
+ limit?: number;
11
+ user?: ResourceUser;
12
+ }, ctx: AppContext): Promise<{
13
+ search: string;
14
+ limit: number;
15
+ count: number;
16
+ time: number;
17
+ data: ResourceListItem[];
18
+ }>;
19
+ export {};
20
+ //# sourceMappingURL=list-resource-list.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"list-resource-list.d.ts","sourceRoot":"","sources":["../../../../src/modules/resource/services/list-resource-list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAItD,OAAO,KAAK,EAAoB,YAAY,EAAE,MAAM,6CAA6C,CAAC;AAElG,KAAK,gBAAgB,GAAG;IAAE,EAAE,EAAE,OAAO,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAkDtD,wBAAsB,gBAAgB,CACpC,MAAM,EAAE;IACN,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,YAAY,CAAC;CACrB,EACD,GAAG,EAAE,UAAU,GACd,OAAO,CAAC;IACT,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,gBAAgB,EAAE,CAAC;CAC1B,CAAC,CA2CD"}
@@ -0,0 +1 @@
1
+ import{ValidationError}from'../../../errors.js';import{assertOperation}from'../../../plugins/resource/utils/permissions.js';function k(h,n){h=h-0xd1;const B=Q();let G=B[h];return G;}function Q(){const A=['key','fields','join','display','name','COALESCE(','::text,\x20\x27\x27)','index','push','length','resource','get','read','max','searchable','\x20OR\x20','WHERE\x20','\x20AND\x20','joins','SELECT\x20','\x20AS\x20id,\x20','table','\x20t\x20','\x0a\x20\x20\x20\x20\x20'];Q=function(){return A;};return Q();}import{quoteIdentifier,quoteTable}from'../../../plugins/resource/utils/sql.js';function columnExpression(h,n){const z=k;if(n!==h[z(0xd1)]&&!h['fields'][n])throw new ValidationError('Unknown\x20display/search\x20field:\x20'+n);const B=h[z(0xd2)][n]?.['column']??n;return B['split']('.')['map'](G=>quoteIdentifier(G))[z(0xd3)]('.');}function displayExpression(h){const t=k,n=h[t(0xd4)];if(!n||Array['isArray'](n)&&n['length']===0x0)throw new ValidationError('Resource\x20has\x20no\x20display\x20fields:\x20'+h[t(0xd5)]);if(Array['isArray'](n))return'concat_ws(\x27\x20\x27,\x20'+n['map'](j=>t(0xd6)+columnExpression(h,j)+t(0xd7))[t(0xd3)](',\x20')+')';const B=[],G=/\{([^{}]+)\}/g;let f=0x0;for(const j of n['matchAll'](G)){const Z=j[t(0xd8)]??0x0,e=j[0x1];if(!e)throw new ValidationError('Invalid\x20display\x20template\x20for\x20resource:\x20'+h[t(0xd5)]);Z>f&&B[t(0xd9)]('\x27'+n['slice'](f,Z)['replace'](/'/g,'\x27\x27')+'\x27'),B['push']('COALESCE('+columnExpression(h,e)+'::text,\x20\x27\x27)'),f=Z+j[0x0]['length'];}f<n[t(0xda)]&&B['push']('\x27'+n['slice'](f)['replace'](/'/g,'\x27\x27')+'\x27');if(B['length']===0x0)throw new ValidationError('Invalid\x20display\x20template\x20for\x20resource:\x20'+h['name']);return'concat('+B['join'](',\x20')+')';}export async function listResourceList(h,n){const m=k,B=Date['now'](),G=n[m(0xdb)][m(0xdc)](h[m(0xdb)]);assertOperation(G,m(0xdd),h['user']);const f=h['search']??'',j=Math['min'](Math[m(0xde)](Number(h['limit']??0x14),0x1),0xc8),Z=G['searchable']??Object['entries'](G['fields'])['filter'](([,i])=>i[m(0xdf)])['map'](([i])=>i);if(f&&Z['length']===0x0)throw new ValidationError('Resource\x20has\x20no\x20searchable\x20fields:\x20'+G['name']);const e=displayExpression(G),b=[],P=[];if(G['where'])b[m(0xd9)]('('+G['where']+')');if(f){const i=Z['map'](p=>columnExpression(G,p)+'::text\x20ILIKE\x20$1');b[m(0xd9)]('('+i[m(0xd3)](m(0xe0))+')'),P[m(0xd9)]('%'+f+'%');}P['push'](j);const u=b['length']?m(0xe1)+b['join'](m(0xe2)):'',X=G[m(0xe3)]?.['map'](p=>p['sql'])['join']('\x20')??'',H=await n['pg']['query'](m(0xe4)+quoteIdentifier(G[m(0xd1)])+m(0xe5)+e+'\x20AS\x20text\x0a\x20\x20\x20\x20\x20FROM\x20'+quoteTable(G[m(0xe6)])+m(0xe7)+X+m(0xe8)+u+'\x0a\x20\x20\x20\x20\x20LIMIT\x20$'+P['length'],P);return{'search':f,'limit':j,'count':H['rows']['length'],'time':Date['now']()-B,'data':H['rows']};}
@@ -1 +1 @@
1
- export async function listResourceRelation(w,h){const {resource:S,id:X,relation:Y,query:v,user:D}=w;return h['resource']['findRelation']({'name':S,'id':X,'relation':Y,'query':v,'user':D});}
1
+ function Q(){const b=['findRelation'];Q=function(){return b;};return Q();}function k(h,n){h=h-0x75;const B=Q();let G=B[h];return G;}export async function listResourceRelation(h,n){const e=k,{resource:B,id:G,relation:f,query:j,user:Z}=h;return n['resource'][e(0x75)]({'name':B,'id':G,'relation':f,'query':j,'user':Z});}
@@ -1 +1 @@
1
- {"version":3,"file":"list-resources.d.ts","sourceRoot":"","sources":["../../../../src/modules/resource/services/list-resources.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,wBAAsB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAa9E"}
1
+ {"version":3,"file":"list-resources.d.ts","sourceRoot":"","sources":["../../../../src/modules/resource/services/list-resources.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,wBAAsB,aAAa,CAAC,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,UAAU,GAAG,OAAO,CAAC,GAAG,CAAC,CAgB9E"}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function G(w,h){w=w-0x1a2;var S=z();var X=S[w];return X;}function z(){var X=['scope','offset'];z=function(){return X;};return z();}export async function listResources(w,h){var S=G;return h['resource']['find']({'name':w['resource'],'query':{'filter':parseFilterQuery(w),'sort':w['sort'],'search':w['search'],'scope':w[S(0x1a2)],'limit':w['limit'],'offset':w[S(0x1a3)]??(w['page']?Math['max'](w['page']-0x1,0x0):0x0)*(w['limit']??0x14)},'user':w['user']});}
1
+ function k(h,n){h=h-0x1df;const B=Q();let G=B[h];return G;}function Q(){const f=['resource','find','sort','limit'];Q=function(){return f;};return Q();}import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';export async function listResources(h,n){const G=k,B=h['user'];return n[G(0x1df)][G(0x1e0)]({'name':h['resource'],'query':{'filter':parseFilterQuery(h),'sort':h[G(0x1e1)],'search':h['search'],'include':h['include'],'scope':h['scope'],'limit':h[G(0x1e2)],'offset':h['offset']??(h['page']?Math['max'](h['page']-0x1,0x0):0x0)*(h['limit']??0x14)},'user':B});}
@@ -1 +1 @@
1
- import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function z(){var X=['resource','find'];z=function(){return X;};return z();}function G(w,h){w=w-0x10b;var S=z();var X=S[w];return X;}export async function searchResource(w,h){var S=G;return h[S(0x10b)][S(0x10c)]({'name':w['resource'],'query':{...w,'filter':parseFilterQuery(w)},'user':w['user']});}
1
+ import{parseFilterQuery}from'../../../plugins/resource/utils/filters.js';function k(h,n){h=h-0x13f;var B=Q();var G=B[h];return G;}function Q(){var G=['resource'];Q=function(){return G;};return Q();}export async function searchResource(h,n){var B=k;return n[B(0x13f)]['find']({'name':h[B(0x13f)],'query':{...h,'filter':parseFilterQuery(h)},'user':h['user']});}
@@ -1 +1 @@
1
- import{ValidationError}from'../../../errors.js';function G(w,h){w=w-0xdf;const S=z();let X=S[w];return X;}import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';export async function suggestResource(w,h){const H=G,S=h['resource']['get'](w[H(0xdf)]),X=String(w['search']??w['q']??'')['toLowerCase'](),Y=Math['min'](Math['max'](Number(w['limit']??0x14),0x1),0xc8),v=Date[H(0xe0)](),D=S['fields'][w[H(0xe1)]],o=D?.[H(0xe2)],q=D?.[H(0xe3)]?.['table'];if(q){const K=D['lookup']?.['text']??'name',y=D['lookup']?.[H(0xe4)]??'id';autoIndex(q,K,H(0xe5),h['pg']);const V=await h['pg'][H(0xe6)]('SELECT\x20'+y+'\x20as\x20id,\x20'+K+H(0xe7)+q+'\x20WHERE\x20lower('+K+')\x20~\x20$1\x20LIMIT\x20$2',[''+X['toLowerCase'](),Y])[H(0xe8)](O=>O[H(0xe9)]);return{'limit':Y,'count':V['length'],'search':X,'time':Date['now']()-v,'data':V};}if(!o)throw new ValidationError('Field\x20has\x20no\x20lookup\x20dictionary:\x20'+w['field']);const e=await h[H(0xe2)]['get'](o),Z=e['filter'](O=>!X||O['code'][H(0xea)](X)||O[H(0xeb)][H(0xea)](X))['slice'](0x0,Y)[H(0xec)](O=>({'id':O[H(0xed)]||O['id'],'text':O[H(0xeb)]||O['text']}));return{'search':X,'limit':Y,'count':Z['length'],'time':Date[H(0xe0)]()-v,'data':Z};}function z(){const R=['resource','now','field','dictionary','lookup','value','text','query','\x20as\x20text\x20FROM\x20','then','rows','startsWith','name','map','code'];z=function(){return R;};return z();}
1
+ function Q(){const t=['resource','get','min','max','limit','field','value','query',')\x20~\x20$1\x20LIMIT\x20$2','toLowerCase','length','dictionary','startsWith','code','text','now'];Q=function(){return t;};return Q();}import{ValidationError}from'../../../errors.js';import{autoIndex}from'../../../plugins/resource/utils/auto-index.js';function k(h,n){h=h-0x169;const B=Q();let G=B[h];return G;}export async function suggestResource(h,n){const z=k,B=n[z(0x169)][z(0x16a)](h['resource']),G=String(h['search']??h['q']??'')['toLowerCase'](),f=Math[z(0x16b)](Math[z(0x16c)](Number(h[z(0x16d)]??0x14),0x1),0xc8),j=Date['now'](),Z=B['fields'][h[z(0x16e)]],e=Z?.['dictionary'],b=Z?.['lookup']?.['table'];if(b){const X=Z['lookup']?.['text']??'name',H=Z['lookup']?.[z(0x16f)]??'id';autoIndex(b,X,'text',n['pg']);const i=await n['pg'][z(0x170)]('SELECT\x20'+H+'\x20as\x20id,\x20'+X+'\x20as\x20text\x20FROM\x20'+b+'\x20WHERE\x20lower('+X+z(0x171),[''+G[z(0x172)](),f])['then'](p=>p['rows']);return{'limit':f,'count':i[z(0x173)],'search':G,'time':Date['now']()-j,'data':i};}if(!e)throw new ValidationError('Field\x20has\x20no\x20lookup\x20dictionary:\x20'+h['field']);const P=await n[z(0x174)]['get'](e),u=P['filter'](p=>!G||p['code']['startsWith'](G)||p['name'][z(0x175)](G))['slice'](0x0,f)['map'](p=>({'id':p[z(0x176)]||p['id'],'text':p['name']||p[z(0x177)]}));return{'search':G,'limit':f,'count':u['length'],'time':Date[z(0x178)]()-j,'data':u};}
@@ -1 +1 @@
1
- export async function updateResourceRelation(w,h){const {resource:S,id:X,relation:Y,relationId:v,data:D,user:o}=w;return h['resource']['updateRelation']({'name':S,'id':X,'relation':Y,'relationId':v,'data':D,'user':o});}
1
+ function k(h,n){h=h-0x1c9;const B=Q();let G=B[h];return G;}export async function updateResourceRelation(h,n){const b=k,{resource:B,id:G,relation:f,relationId:j,data:Z,user:e}=h;return n[b(0x1c9)]['updateRelation']({'name':B,'id':G,'relation':f,'relationId':j,'data':Z,'user':e});}function Q(){const P=['resource'];Q=function(){return P;};return Q();}
@@ -1 +1 @@
1
- function G(w,h){w=w-0x7d;var S=z();var X=S[w];return X;}function z(){var X=['resource','patch'];z=function(){return X;};return z();}export async function updateResource(w,h){var S=G;return h[S(0x7d)]['update']({'name':w['resource'],'id':w['id'],'data':w[S(0x7e)],'user':w['user']});}
1
+ export async function updateResource(h,n){return n['resource']['update']({'name':h['resource'],'id':h['id'],'data':h['patch'],'user':h['user']});}
@@ -1 +1 @@
1
- import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';export async function uploadResourceFile(w,h){const D=G,S=h['resource'][D(0xad)](w[D(0xae)]);if(S['access']===D(0xaf)&&w['user']?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(w['user']?.[D(0xb0)]!=='admin'&&!w[D(0xb1)]?.[D(0xb2)]?.[D(0xb3)]((S['permission']??S['name'])+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+(S['permission']??S['name'])+':update');if(!Buffer['isBuffer'](w['file'])||w[D(0xb4)][D(0xb5)]===0x0)throw new ValidationError('File\x20is\x20required');const X=w[D(0xb6)][D(0xb7)](/[^A-Za-z0-9._-]/g,'_');if(!X)throw new ValidationError(D(0xb8));const Y='files/'+w['resource']+'/'+String(w['id'])+'/'+X;await h[D(0xb4)]['put'](Y,w['file']);if(!await h['file'][D(0xb9)](Y))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const v=await h['pg'][D(0xba)]('\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',[w['resource'],String(w['id']),Y,w['file']['length']]);return v['rows'][0x0];}function G(w,h){w=w-0xad;const S=z();let X=S[w];return X;}function z(){const o=['get','resource','admin','type','user','permissions','includes','file','length','fileName','replace','File\x20name\x20is\x20required','exists','query'];z=function(){return o;};return z();}
1
+ import{ForbiddenError,NotFoundError,ValidationError}from'../../../errors.js';function Q(){const e=['resource','admin','user','fileName','exists','file'];Q=function(){return e;};return Q();}function k(h,n){h=h-0xac;const B=Q();let G=B[h];return G;}export async function uploadResourceFile(h,n){const Z=k,B=n[Z(0xac)]['get'](h['resource']);if(B['access']===Z(0xad)&&h['user']?.['type']!=='admin')throw new ForbiddenError('Admin\x20access\x20required');if(h[Z(0xae)]?.['type']!==Z(0xad)&&!h['user']?.['permissions']?.['includes']((B['permission']??B['name'])+':update'))throw new ForbiddenError('Missing\x20permission:\x20'+(B['permission']??B['name'])+':update');if(!Buffer['isBuffer'](h['file'])||h['file']['length']===0x0)throw new ValidationError('File\x20is\x20required');const G=h[Z(0xaf)]['replace'](/[^A-Za-z0-9._-]/g,'_');if(!G)throw new ValidationError('File\x20name\x20is\x20required');const f='files/'+h['resource']+'/'+String(h['id'])+'/'+G;await n['file']['put'](f,h['file']);if(!await n['file'][Z(0xb0)](f))throw new NotFoundError('Uploaded\x20file\x20not\x20found');const j=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',[h[Z(0xac)],String(h['id']),f,h[Z(0xb1)]['length']]);return j['rows'][0x0];}
@@ -1 +1 @@
1
- {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/system/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAanD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,UAAU,EACf,SAAS,GAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAa,GACnD,kBAAkB,CA8JpB"}
1
+ {"version":3,"file":"route.d.ts","sourceRoot":"","sources":["../../../src/modules/system/route.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAC;AAClD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAiBnD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAG9C,wBAAgB,YAAY,CAC1B,GAAG,EAAE,UAAU,EACf,SAAS,GAAE,WAAW,CAAC,MAAM,EAAE,QAAQ,CAAa,GACnD,kBAAkB,CAsOpB"}
@@ -1 +1 @@
1
- const q=G;function z(){const Z=['user','/api/dictionary/:name','fcore','Returns\x20a\x20registered\x20platform\x20dictionary\x20by\x20name.','system','Update\x20platform\x20dictionary','dictionaryName','params','body','get','system:access','post','/api/access/:type/:id','accessTarget','Get\x20system\x20settings','Returns\x20system\x20settings\x20as\x20nested\x20JSON.','admin','system:settings','settings','system:logs','/api/system/audit','Returns\x20the\x20system\x20audit\x20log\x20entries.','system:audit','Check\x20system\x20health'];z=function(){return Z;};return z();}import{getSystemSettings}from'./services/get-system-settings.js';import{updateSystemSettings}from'./services/update-system-settings.js';import{getAuditLog}from'./services/get-audit-log.js';import{checkSystem}from'./services/check-system.js';import{getApiList}from'./services/get-api-list.js';import{getSystemLog}from'./services/get-system-log.js';import{getDictionary}from'./services/get-dictionary.js';import{updateDictionary}from'./services/update-dictionary.js';function G(w,h){w=w-0x69;const S=z();let X=S[w];return X;}import{getAccess}from'./services/get-access.js';import{setAccess}from'./services/set-access.js';import{systemSchemas}from'./schema.js';const u=w=>w[q(0x69)];export function systemRoutes(w,h=new Map()){return async S=>{const e=G;S['get'](e(0x6a),{'schema':{'tags':[e(0x6b),'system'],'summary':'Get\x20platform\x20dictionary','description':e(0x6c),'access':e(0x69),'permissions':['system:dictionaries'],'params':systemSchemas['dictionaryName']}},async Y=>({'items':await getDictionary({...Y['params'],'user':u(Y)},w)})),S['post'](e(0x6a),{'schema':{'tags':[e(0x6b),e(0x6d)],'summary':e(0x6e),'description':'Replaces\x20the\x20items\x20of\x20a\x20registered\x20platform\x20dictionary.','access':'user','permissions':['system:dictionaries'],'params':systemSchemas[e(0x6f)],'body':systemSchemas['dictionaryItems']}},async Y=>updateDictionary({...Y[e(0x70)],...Y[e(0x71)],'user':u(Y)},w));const X=async Y=>getAccess({...Y['params'],'user':u(Y)},w);S[e(0x72)]('/api/access/:type/:id',{'schema':{'tags':['fcore','system'],'summary':'Get\x20access\x20rules','description':'Returns\x20direct\x20and\x20role-based\x20access\x20rules\x20for\x20a\x20user\x20or\x20role.','access':'admin','permissions':[e(0x73)],'params':systemSchemas['accessTarget']}},X),S[e(0x74)](e(0x75),{'schema':{'tags':['fcore','system'],'summary':'Set\x20access\x20rules','description':'Replaces\x20direct\x20access\x20rules\x20for\x20a\x20user\x20or\x20role.','access':'admin','permissions':['system:access'],'params':systemSchemas[e(0x76)],'body':systemSchemas['access']}},async Y=>setAccess({...Y['params'],...Y['body'],'user':u(Y)},w)),S['get']('/api/system/settings',{'schema':{'tags':[e(0x6b),'system'],'summary':e(0x77),'description':e(0x78),'access':e(0x79),'permissions':[e(0x7a)]}},async Y=>getSystemSettings({...Y['params'],'user':u(Y)},w)),S['post']('/api/system/settings',{'schema':{'tags':['fcore',e(0x6d)],'summary':'Update\x20system\x20settings','description':'Updates\x20system\x20settings\x20using\x20flat\x20dot-notation\x20keys.','access':'admin','permissions':['system:settings'],'body':systemSchemas[e(0x7b)]}},async Y=>updateSystemSettings({...Y[e(0x70)],'patch':Y[e(0x71)],'user':u(Y)},w)),S['get']('/api/system/logger',{'schema':{'tags':['fcore',e(0x6d)],'summary':'Get\x20system\x20log','description':'Returns\x20system\x20logger\x20entries\x20for\x20the\x20requested\x20path.','access':'user','permissions':[e(0x7c)],'querystring':systemSchemas['logger']}},async(Y,v)=>{const {contentType:D,body:o}=await getSystemLog({...Y['query'],'user':u(Y)},w);return v['type'](D)['send'](o);}),S['get'](e(0x7d),{'schema':{'tags':[e(0x6b),'system'],'summary':'Get\x20audit\x20log','description':e(0x7e),'access':'user','permissions':[e(0x7f)]}},async Y=>getAuditLog({...Y['query'],'user':u(Y)},w)),S[e(0x72)]('/api/system/check',{'schema':{'tags':['fcore',e(0x6d)],'summary':e(0x80),'description':'Checks\x20the\x20availability\x20of\x20system\x20dependencies.','access':e(0x69),'permissions':['system:check']}},async Y=>checkSystem({'user':u(Y)},w)),S['get']('/api/system/list',{'schema':{'tags':['fcore','system'],'summary':'List\x20APIs','description':'Returns\x20the\x20list\x20of\x20registered\x20platform\x20APIs.','access':'admin','permissions':[],'querystring':systemSchemas['apiListQuery']}},async Y=>getApiList({'user':u(Y),'apiRoutes':h,...Y['query']},w));};}
1
+ import{getSystemSettings}from'./services/get-system-settings.js';import{updateSystemSettings}from'./services/update-system-settings.js';import{getAuditLog}from'./services/get-audit-log.js';function Q(){const P=['/api/dictionary/:name','params','system','Replaces\x20the\x20items\x20of\x20a\x20registered\x20platform\x20dictionary.','dictionaryName','fcore','Returns\x20user-specific\x20and\x20role-level\x20scopes\x20for\x20a\x20resource.','system:access','Replaces\x20scopes\x20for\x20a\x20role,\x20optionally\x20for\x20a\x20specific\x20user.','resourceScope','body','accessResourceParams','post','/api/access/resource/:resource','get','/api/access/:type/:id','Get\x20access\x20rules','admin','Set\x20access\x20rules','Get\x20audit\x20log','/api/system/check','Check\x20system\x20health','user','apiListQuery','query'];Q=function(){return P;};return Q();}import{checkSystem}from'./services/check-system.js';function k(h,n){h=h-0x160;const B=Q();let G=B[h];return G;}import{getApiList}from'./services/get-api-list.js';import{getSystemLog}from'./services/get-system-log.js';import{getDictionary}from'./services/get-dictionary.js';import{updateDictionary}from'./services/update-dictionary.js';import{getAccess}from'./services/get-access.js';import{getResourceAccess}from'./services/get-resource-access.js';import{setAccess}from'./services/set-access.js';import{setResourceAccess}from'./services/set-resource-access.js';import{getResourceScopes}from'./services/get-resource-scopes.js';import{setResourceScopes}from'./services/set-resource-scopes.js';import{systemSchemas}from'./schema.js';const u=h=>h['user'];export function systemRoutes(h,n=new Map()){return async B=>{const b=k;B['get'](b(0x160),{'schema':{'tags':['fcore','system'],'summary':'Get\x20platform\x20dictionary','description':'Returns\x20a\x20registered\x20platform\x20dictionary\x20by\x20name.','access':'user','permissions':['system:dictionaries'],'params':systemSchemas['dictionaryName']}},async f=>({'items':await getDictionary({...f[b(0x161)],'user':u(f)},h)})),B['post']('/api/dictionary/:name',{'schema':{'tags':['fcore',b(0x162)],'summary':'Update\x20platform\x20dictionary','description':b(0x163),'access':'user','permissions':['system:dictionaries'],'params':systemSchemas[b(0x164)],'body':systemSchemas['dictionaryItems']}},async f=>updateDictionary({...f[b(0x161)],...f['body'],'user':u(f)},h));const G=async f=>getAccess({...f['params'],'user':u(f)},h);B['get']('/api/access/scope/:resource',{'schema':{'tags':[b(0x165),b(0x162)],'summary':'Get\x20resource\x20access\x20scopes','description':b(0x166),'access':'admin','permissions':[b(0x167)],'params':systemSchemas['resourceScope']}},async f=>getResourceScopes(f[b(0x161)],h)),B['post']('/api/access/scope/:resource',{'schema':{'tags':[b(0x165),b(0x162)],'summary':'Set\x20resource\x20access\x20scopes','description':b(0x168),'access':'admin','permissions':['system:access'],'params':systemSchemas[b(0x169)],'body':systemSchemas['resourceScopeBody']}},async f=>setResourceScopes({...f['params'],...f[b(0x16a)],'user':u(f)},h)),B['get']('/api/access/resource/:resource',{'schema':{'tags':[b(0x165),b(0x162)],'summary':'Get\x20user\x20access\x20for\x20a\x20resource','description':'Returns\x20direct\x20user\x20access\x20rules\x20for\x20the\x20specified\x20resource.','access':'admin','permissions':['system:access'],'params':systemSchemas[b(0x16b)]}},async f=>getResourceAccess(f[b(0x161)],h)),B[b(0x16c)](b(0x16d),{'schema':{'tags':['fcore','system'],'summary':'Set\x20user\x20access\x20for\x20a\x20resource','description':'Replaces\x20direct\x20user\x20access\x20rules\x20for\x20the\x20specified\x20resource.','access':'admin','permissions':['system:access'],'params':systemSchemas[b(0x16b)],'body':systemSchemas['resourceAccess']}},async f=>setResourceAccess({...f['params'],...f['body'],'user':u(f)},h)),B[b(0x16e)](b(0x16f),{'schema':{'tags':[b(0x165),b(0x162)],'summary':b(0x170),'description':'Returns\x20direct\x20and\x20role-based\x20access\x20rules\x20for\x20a\x20user\x20or\x20role.','access':b(0x171),'permissions':['system:access'],'params':systemSchemas['accessTarget']}},G),B['post']('/api/access/:type/:id',{'schema':{'tags':[b(0x165),'system'],'summary':b(0x172),'description':'Replaces\x20direct\x20access\x20rules\x20for\x20a\x20user\x20or\x20role.','access':'admin','permissions':['system:access'],'params':systemSchemas['accessTarget'],'body':systemSchemas['access']}},async f=>setAccess({...f[b(0x161)],...f['body'],'user':u(f)},h)),B['get']('/api/system/settings',{'schema':{'tags':[b(0x165),'system'],'summary':'Get\x20system\x20settings','description':'Returns\x20system\x20settings\x20as\x20nested\x20JSON.','access':b(0x171),'permissions':['system:settings']}},async f=>getSystemSettings({...f['params'],'user':u(f)},h)),B[b(0x16c)]('/api/system/settings',{'schema':{'tags':['fcore','system'],'summary':'Update\x20system\x20settings','description':'Updates\x20system\x20settings\x20using\x20flat\x20dot-notation\x20keys.','access':'admin','permissions':['system:settings'],'body':systemSchemas['settings']}},async f=>updateSystemSettings({...f['params'],'patch':f['body'],'user':u(f)},h)),B['get']('/api/system/logger',{'schema':{'tags':['fcore','system'],'summary':'Get\x20system\x20log','description':'Returns\x20system\x20logger\x20entries\x20for\x20the\x20requested\x20path.','access':'user','permissions':['system:logs'],'querystring':systemSchemas['logger']}},async(f,j)=>{const {contentType:Z,body:e}=await getSystemLog({...f['query'],'user':u(f)},h);return j['type'](Z)['send'](e);}),B['get']('/api/system/audit',{'schema':{'tags':[b(0x165),'system'],'summary':b(0x173),'description':'Returns\x20the\x20system\x20audit\x20log\x20entries.','access':'user','permissions':['system:audit']}},async f=>getAuditLog({...f['query'],'user':u(f)},h)),B[b(0x16e)](b(0x174),{'schema':{'tags':['fcore','system'],'summary':b(0x175),'description':'Checks\x20the\x20availability\x20of\x20system\x20dependencies.','access':b(0x176),'permissions':['system:check']}},async f=>checkSystem({'user':u(f)},h)),B[b(0x16e)]('/api/system/list',{'schema':{'tags':[b(0x165),b(0x162)],'summary':'List\x20APIs','description':'Returns\x20the\x20list\x20of\x20registered\x20platform\x20APIs.','access':'admin','permissions':[],'querystring':systemSchemas[b(0x177)]}},async f=>getApiList({'user':u(f),'apiRoutes':n,...f[b(0x178)]},h));};}
@@ -15,7 +15,29 @@ export declare const systemSchemas: {
15
15
  type: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"user">, import("@sinclair/typebox").TLiteral<"role">]>;
16
16
  id: import("@sinclair/typebox").TString;
17
17
  }>;
18
+ accessResourceParams: import("@sinclair/typebox").TObject<{
19
+ resource: import("@sinclair/typebox").TString;
20
+ }>;
21
+ resourceScope: import("@sinclair/typebox").TObject<{
22
+ resource: import("@sinclair/typebox").TString;
23
+ }>;
24
+ resourceScopeBody: import("@sinclair/typebox").TObject<{
25
+ user_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
26
+ role_id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
27
+ scopes: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TArray<import("@sinclair/typebox").TUnknown>, import("@sinclair/typebox").TString, import("@sinclair/typebox").TNumber, import("@sinclair/typebox").TBoolean, import("@sinclair/typebox").TNull]>>;
28
+ }>;
29
+ resourceAccess: import("@sinclair/typebox").TObject<{
30
+ users: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
31
+ uid: import("@sinclair/typebox").TString;
32
+ actions: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
33
+ }>>>;
34
+ roles: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
35
+ role_id: import("@sinclair/typebox").TString;
36
+ actions: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>;
37
+ }>>>;
38
+ }>;
18
39
  access: import("@sinclair/typebox").TObject<{
40
+ roles: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
19
41
  permissions: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TString>>;
20
42
  access: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
21
43
  resource: import("@sinclair/typebox").TString;
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/system/schema.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,qCAIrB,CAAC;AAEH,eAAO,MAAM,aAAa;IACxB,cAAc;;;IAGd,eAAe;;;;;;;;IAef,YAAY;;;;IAIZ,MAAM;;;;;;;IAaN,YAAY;;;IAGZ,cAAc;;;IACd,QAAQ;IACR,MAAM;;;CAKP,CAAC"}
1
+ {"version":3,"file":"schema.d.ts","sourceRoot":"","sources":["../../../src/modules/system/schema.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,UAAU,qCAIrB,CAAC;AAEH,eAAO,MAAM,aAAa;IACxB,cAAc;;;IAGd,eAAe;;;;;;;;IAef,YAAY;;;;IAIZ,oBAAoB;;;IAGpB,aAAa;;;IAGb,iBAAiB;;;;;IAcjB,cAAc;;;;;;;;;;IAcd,MAAM;;;;;;;;IAcN,YAAY;;;IAGZ,cAAc;;;IACd,QAAQ;IACR,MAAM;;;CAKP,CAAC"}
@@ -1 +1 @@
1
- const w=G;import{Type}from'@sinclair/typebox';function G(w,h){w=w-0x162;const S=z();let X=S[w];return X;}export const identifier=Type['String']({'minLength':0x1,'maxLength':0x80,'pattern':w(0x162)});export const systemSchemas={'dictionaryName':Type['Object']({'name':identifier}),'dictionaryItems':Type[w(0x163)]({'items':Type[w(0x164)](Type['Object']({'id':Type['Optional'](Type['Union']([Type[w(0x165)](),Type[w(0x166)]()])),'code':Type[w(0x165)]({'minLength':0x1}),'name':Type[w(0x165)]({'minLength':0x1}),'parentId':Type[w(0x167)](Type[w(0x168)]([Type['String'](),Type['Number'](),Type[w(0x169)]()]))},{'additionalProperties':!![]}))}),'accessTarget':Type['Object']({'type':Type['Union']([Type['Literal']('user'),Type['Literal'](w(0x16a))]),'id':identifier}),'access':Type['Object']({'permissions':Type['Optional'](Type['Array'](Type[w(0x165)]({'minLength':0x1,'maxLength':0x80,'pattern':w(0x16b)}))),'access':Type['Optional'](Type['Array'](Type['Object']({'resource':Type['String']({'minLength':0x1,'maxLength':0x80}),'actions':Type['Array'](Type['String']({'minLength':0x1,'maxLength':0x80}),{'minItems':0x1})})))}),'apiListQuery':Type['Object']({'format':Type['Optional'](Type[w(0x168)]([Type['Literal']('short'),Type[w(0x16c)](w(0x16d))]))}),'settingsEntity':Type['Object']({'entity':Type['Optional'](identifier)}),'settings':Type['Record'](Type['String']({'minLength':0x1}),Type['Unknown']()),'logger':Type[w(0x163)]({'path':Type['Optional'](Type['String']({'maxLength':0x100,'pattern':'^[A-Za-z0-9_.\x5c-/]*$'}))})};function z(){const h=['^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$','Object','Array','String','Number','Optional','Union','Null','role','^[A-Za-z0-9_-]+(?::[A-Za-z0-9_-]+)?$','Literal','extended'];z=function(){return h;};return z();}
1
+ function Q(){const n=['String','Union','Optional','Object','Array','extended'];Q=function(){return n;};return Q();}const h=k;function k(h,n){h=h-0x1f2;const B=Q();let G=B[h];return G;}import{Type}from'@sinclair/typebox';export const identifier=Type[h(0x1f2)]({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9][A-Za-z0-9_-]{0,127}$'});export const systemSchemas={'dictionaryName':Type['Object']({'name':identifier}),'dictionaryItems':Type['Object']({'items':Type['Array'](Type['Object']({'id':Type['Optional'](Type[h(0x1f3)]([Type[h(0x1f2)](),Type['Number']()])),'code':Type['String']({'minLength':0x1}),'name':Type['String']({'minLength':0x1}),'parentId':Type[h(0x1f4)](Type['Union']([Type[h(0x1f2)](),Type['Number'](),Type['Null']()]))},{'additionalProperties':!![]}))}),'accessTarget':Type['Object']({'type':Type['Union']([Type['Literal']('user'),Type['Literal']('role')]),'id':identifier}),'accessResourceParams':Type['Object']({'resource':identifier}),'resourceScope':Type['Object']({'resource':identifier}),'resourceScopeBody':Type['Object']({'user_id':Type['Optional'](identifier),'role_id':Type[h(0x1f4)](identifier),'scopes':Type['Record'](identifier,Type['Union']([Type['Array'](Type['Unknown']()),Type['String'](),Type['Number'](),Type['Boolean'](),Type['Null']()]))}),'resourceAccess':Type['Object']({'users':Type['Optional'](Type['Array'](Type['Object']({'uid':identifier,'actions':Type['Array'](Type['String']({'minLength':0x1,'maxLength':0x80}))}))),'roles':Type['Optional'](Type['Array'](Type[h(0x1f5)]({'role_id':identifier,'actions':Type['Array'](Type[h(0x1f2)]({'minLength':0x1,'maxLength':0x80}))})))},{'minProperties':0x1}),'access':Type['Object']({'roles':Type[h(0x1f4)](Type['Array'](identifier)),'permissions':Type['Optional'](Type[h(0x1f6)](Type[h(0x1f2)]({'minLength':0x1,'maxLength':0x80,'pattern':'^[A-Za-z0-9_-]+(?::[A-Za-z0-9_-]+)?$'}))),'access':Type['Optional'](Type[h(0x1f6)](Type['Object']({'resource':Type['String']({'minLength':0x1,'maxLength':0x80}),'actions':Type['Array'](Type['String']({'minLength':0x1,'maxLength':0x80}),{'minItems':0x1})})))}),'apiListQuery':Type['Object']({'format':Type['Optional'](Type[h(0x1f3)]([Type['Literal']('short'),Type['Literal'](h(0x1f7))]))}),'settingsEntity':Type[h(0x1f5)]({'entity':Type['Optional'](identifier)}),'settings':Type['Record'](Type['String']({'minLength':0x1}),Type['Unknown']()),'logger':Type[h(0x1f5)]({'path':Type[h(0x1f4)](Type['String']({'maxLength':0x100,'pattern':'^[A-Za-z0-9_.\x5c-/]*$'}))})};
@@ -1 +1 @@
1
- export async function checkSystem(w,h){const Y=G,[S,X]=await Promise['allSettled']([h['pg'][Y(0xcd)]('SELECT\x201'),h['redis']['ping']()]);return{'status':S['status']==='fulfilled'&&X['status']==='fulfilled'?'ok':'degraded','pg':S['status'],'redis':X['status']};}function G(w,h){w=w-0xcd;const S=z();let X=S[w];return X;}function z(){const v=['query'];z=function(){return v;};return z();}
1
+ export async function checkSystem(h,n){const f=k,[B,G]=await Promise['allSettled']([n['pg'][f(0x104)]('SELECT\x201'),n[f(0x105)][f(0x106)]()]);return{'status':B['status']==='fulfilled'&&G[f(0x107)]==='fulfilled'?'ok':f(0x108),'pg':B['status'],'redis':G['status']};}function k(h,n){h=h-0x104;const B=Q();let G=B[h];return G;}function Q(){const j=['query','redis','ping','status','degraded'];Q=function(){return j;};return Q();}
@@ -1 +1 @@
1
- export async function getAccess(w,h){const D=G,S=w[D(0xef)]===D(0xf0)?'\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20ra.resource,\x20ra.actions,\x20ra.role_id\x20AS\x20role\x0a\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.role_access\x20ra\x0a\x20\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20admin.user_roles\x20ur\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20ur.role_id\x20=\x20ra.role_id\x20AND\x20ur.user_uid\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20ra.user_uid\x20=\x20$1\x20OR\x20ur.user_uid\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20':D(0xf1),X=await h['pg'][D(0xf2)](S,[w['id']]),Y=[...new Set(X['rows']['map'](v=>v['resource'])['filter'](v=>v!==null))];return{'access':X['rows'],'resources':Y};}function G(w,h){w=w-0xef;const S=z();let X=S[w];return X;}function z(){const o=['type','user','\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20ra.resource,\x20ra.actions,\x20ra.role_id\x20AS\x20role\x0a\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.role_access\x20ra\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20ra.role_id\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20','query'];z=function(){return o;};return z();}
1
+ function k(h,n){h=h-0x82;const B=Q();let G=B[h];return G;}export async function getAccess(h,n){const Z=k,B=h['type']==='user'?'\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20ra.resource,\x20ra.actions,\x20ra.role_id\x20AS\x20role\x0a\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.role_access\x20ra\x0a\x20\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20admin.user_roles\x20ur\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20ON\x20ur.role_id\x20=\x20ra.role_id\x20AND\x20ur.user_uid\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20ra.user_uid\x20=\x20$1\x20OR\x20ur.user_uid\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20':Z(0x82),G=await n['pg']['query'](B,[h['id']]),f=[...new Set(G['rows']['map'](j=>j['resource'])['filter'](j=>j!==null))];return{'access':G[Z(0x83)],'resources':f};}function Q(){const e=['\x0a\x20\x20\x20\x20\x20\x20\x20\x20SELECT\x20ra.resource,\x20ra.actions,\x20ra.role_id\x20AS\x20role\x0a\x20\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.role_access\x20ra\x0a\x20\x20\x20\x20\x20\x20\x20\x20WHERE\x20ra.role_id\x20=\x20$1\x0a\x20\x20\x20\x20\x20\x20','rows'];Q=function(){return e;};return Q();}
@@ -1 +1 @@
1
- export async function getApiList(w,h){const o=G,S=[...w['apiRoutes'][o(0x1a0)]()]['sort']((X,Y)=>(X[o(0x1a1)]+'\x20'+X['method'])['localeCompare'](Y['endpoint']+'\x20'+Y['method']));if(w['format']!==o(0x1a2))return S;return S[o(0x1a3)](({method:X,endpoint:Y,access:v,permissions:D})=>X+'\x20'+Y);}function G(w,h){w=w-0x1a0;const S=z();let X=S[w];return X;}function z(){const q=['values','endpoint','short','map'];z=function(){return q;};return z();}
1
+ function Q(){const b=['apiRoutes','sort','localeCompare','endpoint','method'];Q=function(){return b;};return Q();}function k(h,n){h=h-0x1e0;const B=Q();let G=B[h];return G;}export async function getApiList(h,n){const e=k,B=[...h[e(0x1e0)]['values']()][e(0x1e1)]((G,f)=>(G['endpoint']+'\x20'+G['method'])[e(0x1e2)](f[e(0x1e3)]+'\x20'+f[e(0x1e4)]));if(h['format']!=='short')return B;return B['map'](({method:G,endpoint:f,access:j,permissions:Z})=>G+'\x20'+f);}
@@ -1 +1 @@
1
- function G(w,h){w=w-0x18f;const S=z();let X=S[w];return X;}export async function getAuditLog(w,h){const v=G,S=Math['min'](Math['max'](w['limit']??0x32,0x1),0xc8),X=Math['max']((w['page']??0x1)-0x1,0x0)*S,Y=await h['pg'][v(0x18f)]('SELECT\x0a\x20\x20\x20\x20\x20\x20l.*,\x0a\x20\x20\x20\x20\x20\x20case\x20when\x20u.first_name\x20is\x20not\x20null\x20then\x20coalesce(u.last_name,\x27\x27)||coalesce(\x27\x20\x27||u.first_name,\x27\x27)\x20else\x20coalesce(u.login,\x20u.email,\x27\x27)\x20end\x20as\x20user_id_text\x0a\x20\x20\x20\x20FROM\x20admin.audit_log\x20l\x0a\x20\x20\x20\x20JOIN\x20admin.users\x20u\x20ON\x20l.user_id=u.uid\x0a\x20\x20\x20\x20ORDER\x20BY\x20id\x20DESC\x20LIMIT\x20$1\x20OFFSET\x20$2',[S,X]);return{'rows':Y['rows'],'page':w['page']??0x1,'limit':S};}function z(){const D=['query'];z=function(){return D;};return z();}
1
+ export async function getAuditLog(h,n){const B=Math['min'](Math['max'](h['limit']??0x32,0x1),0xc8),G=Math['max']((h['page']??0x1)-0x1,0x0)*B,f=await n['pg']['query']('SELECT\x0a\x20\x20\x20\x20\x20\x20l.*,\x0a\x20\x20\x20\x20\x20\x20case\x20when\x20u.first_name\x20is\x20not\x20null\x20then\x20coalesce(u.last_name,\x27\x27)||coalesce(\x27\x20\x27||u.first_name,\x27\x27)\x20else\x20coalesce(u.login,\x20u.email,\x27\x27)\x20end\x20as\x20user_id_text\x0a\x20\x20\x20\x20FROM\x20admin.audit_log\x20l\x0a\x20\x20\x20\x20JOIN\x20admin.users\x20u\x20ON\x20l.user_id=u.uid\x0a\x20\x20\x20\x20ORDER\x20BY\x20id\x20DESC\x20LIMIT\x20$1\x20OFFSET\x20$2',[B,G]);return{'rows':f['rows'],'page':h['page']??0x1,'limit':B};}
@@ -1 +1 @@
1
- function G(w,h){w=w-0xcd;var S=z();var X=S[w];return X;}export async function getDictionary(w,h){var S=G;return h['dictionary'][S(0xcd)](w['name']);}function z(){var X=['get'];z=function(){return X;};return z();}
1
+ function k(h,n){h=h-0x159;var B=Q();var G=B[h];return G;}export async function getDictionary(h,n){var B=k;return n['dictionary']['get'](h[B(0x159)]);}function Q(){var G=['name'];Q=function(){return G;};return Q();}
@@ -0,0 +1,23 @@
1
+ import type { AppContext } from "../../../context.js";
2
+ export interface ResourceUserAccess {
3
+ type: "user";
4
+ uid: string;
5
+ actions: string[];
6
+ scopes?: Record<string, unknown>;
7
+ }
8
+ export interface ResourceRoleAccess {
9
+ type: "role";
10
+ role_id: string;
11
+ name: string | null;
12
+ actions: string[];
13
+ users_count: number;
14
+ scopes?: Record<string, unknown>;
15
+ }
16
+ export declare function getResourceAccess(params: {
17
+ resource: string;
18
+ }, ctx: AppContext): Promise<{
19
+ resource: string;
20
+ users: ResourceUserAccess[];
21
+ roles: ResourceRoleAccess[];
22
+ }>;
23
+ //# sourceMappingURL=get-resource-access.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"get-resource-access.d.ts","sourceRoot":"","sources":["../../../../src/modules/system/services/get-resource-access.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEtD,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE,MAAM,CAAC;IACZ,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,kBAAkB;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AASD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,EAC5B,GAAG,EAAE,UAAU,GACd,OAAO,CAAC;IACT,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,kBAAkB,EAAE,CAAC;IAC5B,KAAK,EAAE,kBAAkB,EAAE,CAAC;CAC7B,CAAC,CA0ED"}
@@ -0,0 +1 @@
1
+ function k(h,n){h=h-0x156;const B=Q();let G=B[h];return G;}export async function getResourceAccess(h,n){const m=k,[B,G,f]=await Promise['all']([n['pg']['query']('SELECT\x20\x27user\x27::text\x20AS\x20type,\x20user_uid\x20AS\x20uid,\x20actions\x0a\x20\x20\x20\x20\x20FROM\x20admin.role_access\x0a\x20\x20\x20\x20\x20WHERE\x20resource\x20=\x20$1\x20AND\x20user_uid\x20IS\x20NOT\x20NULL\x20AND\x20role_id\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20ORDER\x20BY\x20user_uid',[h['resource']]),n['pg']['query']('SELECT\x20\x27role\x27::text\x20AS\x20type,\x20ra.role_id,\x20r.name,\x20ra.actions,\x0a\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20count(DISTINCT\x20ur.user_uid)::int\x20AS\x20users_count\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.role_access\x20ra\x0a\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20admin.roles\x20r\x20ON\x20r.role_id\x20=\x20ra.role_id\x0a\x20\x20\x20\x20\x20\x20\x20LEFT\x20JOIN\x20admin.user_roles\x20ur\x20ON\x20ur.role_id\x20=\x20ra.role_id\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20ra.resource\x20=\x20$1\x20AND\x20ra.role_id\x20IS\x20NOT\x20NULL\x20AND\x20ra.user_uid\x20IS\x20NULL\x0a\x20\x20\x20\x20\x20\x20\x20GROUP\x20BY\x20ra.role_id,\x20r.name,\x20ra.actions\x0a\x20\x20\x20\x20\x20\x20\x20ORDER\x20BY\x20r.name,\x20ra.role_id',[h['resource']]),n['pg'][m(0x156)]('SELECT\x20user_id,\x20role_id,\x20scope,\x20value\x0a\x20\x20\x20\x20\x20\x20\x20FROM\x20admin.role_access_scope\x0a\x20\x20\x20\x20\x20\x20\x20WHERE\x20resource\x20=\x20$1\x20AND\x20enabled\x20=\x20TRUE',[h[m(0x157)]])]),j=new Map(),Z=new Map();for(const P of f['rows']){if(P['user_id']!==null){const u=j['get'](P['user_id'])??{};u[P[m(0x158)]]=P['value'],j['set'](P[m(0x159)],u);}else{if(P['role_id']!==null){const X=Z['get'](P['role_id'])??{};X[P['scope']]=P['value'],Z[m(0x15a)](P[m(0x15b)],X);}}}const e=B['rows']['map'](H=>({...H,...j['has'](H['uid'])?{'scopes':j['get'](H['uid'])}:{}}));for(const [H,i]of j){!e['some'](p=>p[m(0x15c)]===H)&&e['push']({'type':m(0x15d),'uid':H,'actions':[],'scopes':i});}const b=G['rows']['map'](p=>({...p,...Z['has'](p[m(0x15b)])?{'scopes':Z[m(0x15e)](p['role_id'])}:{}}));for(const [p,z]of Z){!b['some'](t=>t['role_id']===p)&&b['push']({'type':'role','role_id':p,'name':null,'actions':[],'users_count':0x0,'scopes':z});}return{'resource':h['resource'],'users':e,'roles':b};}function Q(){const A=['query','resource','scope','user_id','set','role_id','uid','user','get'];Q=function(){return A;};return Q();}