@next-vibe/checker 1.0.11 → 1.0.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (394) hide show
  1. package/.dist/bin/vibe-runtime.js +10 -19
  2. package/.dist/bin/vibe-runtime.js.map +3 -3
  3. package/check.config.ts +4 -4
  4. package/package.json +2 -9
  5. package/src/app/api/[locale]/LICENSE +674 -0
  6. package/src/app/api/[locale]/i18n/de/index.ts +13 -0
  7. package/src/app/api/[locale]/i18n/en/index.ts +12 -0
  8. package/src/app/api/[locale]/i18n/pl/index.ts +11 -0
  9. package/src/app/api/[locale]/shared/i18n/de/index.ts +85 -0
  10. package/src/app/api/[locale]/shared/i18n/en/index.ts +83 -0
  11. package/src/app/api/[locale]/shared/i18n/pl/index.ts +85 -0
  12. package/src/app/api/[locale]/shared/stats-filtering.ts +202 -0
  13. package/src/app/api/[locale]/shared/types/common.schema.ts +55 -0
  14. package/src/app/api/[locale]/shared/types/response.schema.ts +372 -0
  15. package/src/app/api/[locale]/shared/types/stats-filtering.schema.ts +375 -0
  16. package/src/app/api/[locale]/shared/types/utils.ts +190 -0
  17. package/src/app/api/[locale]/shared/utils/base64.ts +49 -0
  18. package/src/app/api/[locale]/shared/utils/env-util.ts +40 -0
  19. package/src/app/api/[locale]/shared/utils/i18n/de/index.ts +21 -0
  20. package/src/app/api/[locale]/shared/utils/i18n/en/index.ts +19 -0
  21. package/src/app/api/[locale]/shared/utils/i18n/pl/index.ts +21 -0
  22. package/src/app/api/[locale]/shared/utils/index.ts +11 -0
  23. package/src/app/api/[locale]/shared/utils/object-path.ts +41 -0
  24. package/src/app/api/[locale]/shared/utils/object.test.ts +82 -0
  25. package/src/app/api/[locale]/shared/utils/object.ts +75 -0
  26. package/src/app/api/[locale]/shared/utils/parse-error.ts +134 -0
  27. package/src/app/api/[locale]/shared/utils/parse-json.ts +70 -0
  28. package/src/app/api/[locale]/shared/utils/time.ts +53 -0
  29. package/src/app/api/[locale]/shared/utils/validation.ts +127 -0
  30. package/src/app/api/[locale]/shared/utils/zod-required-fields.ts +116 -0
  31. package/src/app/api/[locale]/system/builder/definition.ts +1942 -0
  32. package/src/app/api/[locale]/system/builder/enum.ts +77 -0
  33. package/src/app/api/[locale]/system/builder/i18n/de/index.ts +677 -0
  34. package/src/app/api/[locale]/system/builder/i18n/en/index.ts +665 -0
  35. package/src/app/api/[locale]/system/builder/i18n/pl/index.ts +668 -0
  36. package/src/app/api/[locale]/system/builder/repository/build-executor.test.ts +182 -0
  37. package/src/app/api/[locale]/system/builder/repository/build-executor.ts +583 -0
  38. package/src/app/api/[locale]/system/builder/repository/bun-compiler.ts +261 -0
  39. package/src/app/api/[locale]/system/builder/repository/bundle-analyzer.ts +197 -0
  40. package/src/app/api/[locale]/system/builder/repository/config-loader.ts +159 -0
  41. package/src/app/api/[locale]/system/builder/repository/config-validator.ts +97 -0
  42. package/src/app/api/[locale]/system/builder/repository/constants.ts +125 -0
  43. package/src/app/api/[locale]/system/builder/repository/error-suggester.ts +75 -0
  44. package/src/app/api/[locale]/system/builder/repository/file-copier.ts +98 -0
  45. package/src/app/api/[locale]/system/builder/repository/folder-cleaner.ts +80 -0
  46. package/src/app/api/[locale]/system/builder/repository/index.ts +2 -0
  47. package/src/app/api/[locale]/system/builder/repository/npm-package-generator.ts +146 -0
  48. package/src/app/api/[locale]/system/builder/repository/output-formatter.ts +104 -0
  49. package/src/app/api/[locale]/system/builder/repository/profile-service.ts +79 -0
  50. package/src/app/api/[locale]/system/builder/repository/report-generator.ts +125 -0
  51. package/src/app/api/[locale]/system/builder/repository/vite-compiler.ts +291 -0
  52. package/src/app/api/[locale]/system/builder/route.ts +21 -0
  53. package/src/app/api/[locale]/system/builder/test-files/file1.ts +2 -0
  54. package/src/app/api/[locale]/system/builder/test-files/file2.tsx +10 -0
  55. package/src/app/api/[locale]/system/builder/test-files/file3.tsx +16 -0
  56. package/src/app/api/[locale]/system/builder/test-files/folderToCopy/fileInFolder.ts +2 -0
  57. package/src/app/api/[locale]/system/builder/test-files/test-config.ts +38 -0
  58. package/src/app/api/[locale]/system/builder/test-files/test-delete-config.ts +8 -0
  59. package/src/app/api/[locale]/system/builder/test-files/test-project/package.json +24 -0
  60. package/src/app/api/[locale]/system/builder/test-files/test-project/src/constants.ts +6 -0
  61. package/src/app/api/[locale]/system/builder/test-files/test-project/src/greet.ts +18 -0
  62. package/src/app/api/[locale]/system/builder/test-files/test-project/src/index.ts +7 -0
  63. package/src/app/api/[locale]/system/builder/test-files/test-project/src/utils/calculate.ts +27 -0
  64. package/src/app/api/[locale]/system/builder/test-files/test-project/tsconfig.json +19 -0
  65. package/src/app/api/[locale]/system/builder/test-files/test-project/tsconfig.tsbuildinfo +1 -0
  66. package/src/app/api/[locale]/system/builder/test-files/test3.css +1 -0
  67. package/src/app/api/[locale]/system/check/config/repository.ts +819 -0
  68. package/src/app/api/[locale]/system/check/config/shared.ts +396 -0
  69. package/src/app/api/[locale]/system/check/config/types.ts +616 -0
  70. package/src/app/api/[locale]/system/check/config/utils.ts +171 -0
  71. package/src/app/api/[locale]/system/check/i18n/de/index.ts +15 -0
  72. package/src/app/api/[locale]/system/check/i18n/en/index.ts +14 -0
  73. package/src/app/api/[locale]/system/check/i18n/pl/index.ts +15 -0
  74. package/src/app/api/[locale]/system/check/lint/definition.ts +414 -0
  75. package/src/app/api/[locale]/system/check/lint/enum.ts +37 -0
  76. package/src/app/api/[locale]/system/check/lint/i18n/de/index.ts +164 -0
  77. package/src/app/api/[locale]/system/check/lint/i18n/en/index.ts +162 -0
  78. package/src/app/api/[locale]/system/check/lint/i18n/pl/index.ts +164 -0
  79. package/src/app/api/[locale]/system/check/lint/repository.ts +753 -0
  80. package/src/app/api/[locale]/system/check/lint/route.ts +21 -0
  81. package/src/app/api/[locale]/system/check/oxlint/README.md +190 -0
  82. package/src/app/api/[locale]/system/check/oxlint/definition.ts +414 -0
  83. package/src/app/api/[locale]/system/check/oxlint/enum.ts +37 -0
  84. package/src/app/api/[locale]/system/check/oxlint/i18n/de/index.ts +171 -0
  85. package/src/app/api/[locale]/system/check/oxlint/i18n/en/index.ts +168 -0
  86. package/src/app/api/[locale]/system/check/oxlint/i18n/pl/index.ts +172 -0
  87. package/src/app/api/[locale]/system/check/oxlint/plugins/i18n/src/index.ts +372 -0
  88. package/src/app/api/[locale]/system/check/oxlint/plugins/jsx-capitalization/README.md +246 -0
  89. package/src/app/api/[locale]/system/check/oxlint/plugins/jsx-capitalization/src/index.ts +583 -0
  90. package/src/app/api/[locale]/system/check/oxlint/plugins/restricted-syntax/src/index.ts +500 -0
  91. package/src/app/api/[locale]/system/check/oxlint/plugins/restricted-syntax/test.tsx +74 -0
  92. package/src/app/api/[locale]/system/check/oxlint/plugins/shared/config-loader.ts +305 -0
  93. package/src/app/api/[locale]/system/check/oxlint/repository.ts +959 -0
  94. package/src/app/api/[locale]/system/check/oxlint/route.ts +21 -0
  95. package/src/app/api/[locale]/system/check/oxlint/types.ts +193 -0
  96. package/src/app/api/[locale]/system/check/test-project/bun.lock +449 -0
  97. package/src/app/api/[locale]/system/check/test-project/check.config.ts +989 -0
  98. package/src/app/api/[locale]/system/check/test-project/package.json +20 -0
  99. package/src/app/api/[locale]/system/check/test-project/src/constants.ts +6 -0
  100. package/src/app/api/[locale]/system/check/test-project/src/greet.ts +18 -0
  101. package/src/app/api/[locale]/system/check/test-project/src/test-issues/a11y-issues.tsx +107 -0
  102. package/src/app/api/[locale]/system/check/test-project/src/test-issues/eslint-issues.tsx +37 -0
  103. package/src/app/api/[locale]/system/check/test-project/src/test-issues/general-issues.ts +137 -0
  104. package/src/app/api/[locale]/system/check/test-project/src/test-issues/i18n-issues.tsx +129 -0
  105. package/src/app/api/[locale]/system/check/test-project/src/test-issues/jsx-capitalization-issues.tsx +131 -0
  106. package/src/app/api/[locale]/system/check/test-project/src/test-issues/nextjs-issues.tsx +95 -0
  107. package/src/app/api/[locale]/system/check/test-project/src/test-issues/promise-issues.ts +76 -0
  108. package/src/app/api/[locale]/system/check/test-project/src/test-issues/react-issues.tsx +95 -0
  109. package/src/app/api/[locale]/system/check/test-project/src/test-issues/restricted-syntax-issues.tsx +61 -0
  110. package/src/app/api/[locale]/system/check/test-project/src/test-issues/typescript-issues.ts +80 -0
  111. package/src/app/api/[locale]/system/check/test-project/src/utils/calculate.ts +27 -0
  112. package/src/app/api/[locale]/system/check/test-project/tsconfig.json +38 -0
  113. package/src/app/api/[locale]/system/check/test-project/tsconfig.tsbuildinfo +1 -0
  114. package/src/app/api/[locale]/system/check/typecheck/definition.ts +369 -0
  115. package/src/app/api/[locale]/system/check/typecheck/enum.ts +37 -0
  116. package/src/app/api/[locale]/system/check/typecheck/i18n/de/index.ts +159 -0
  117. package/src/app/api/[locale]/system/check/typecheck/i18n/en/index.ts +150 -0
  118. package/src/app/api/[locale]/system/check/typecheck/i18n/pl/index.ts +155 -0
  119. package/src/app/api/[locale]/system/check/typecheck/repository.ts +919 -0
  120. package/src/app/api/[locale]/system/check/typecheck/route.ts +22 -0
  121. package/src/app/api/[locale]/system/check/typecheck/utils.ts +168 -0
  122. package/src/app/api/[locale]/system/check/vibe-check/definition.ts +568 -0
  123. package/src/app/api/[locale]/system/check/vibe-check/enum.ts +69 -0
  124. package/src/app/api/[locale]/system/check/vibe-check/i18n/de/index.ts +192 -0
  125. package/src/app/api/[locale]/system/check/vibe-check/i18n/en/index.ts +189 -0
  126. package/src/app/api/[locale]/system/check/vibe-check/i18n/pl/index.ts +192 -0
  127. package/src/app/api/[locale]/system/check/vibe-check/repository.ts +545 -0
  128. package/src/app/api/[locale]/system/check/vibe-check/route.test.ts +1142 -0
  129. package/src/app/api/[locale]/system/check/vibe-check/route.ts +21 -0
  130. package/src/app/api/[locale]/system/generated/endpoint.ts +313 -0
  131. package/src/app/api/[locale]/system/generated/endpoints.ts +156 -0
  132. package/src/app/api/[locale]/system/generated/route-handlers.ts +224 -0
  133. package/src/app/api/[locale]/system/generators/endpoint/definition.ts +193 -0
  134. package/src/app/api/[locale]/system/generators/endpoint/i18n/de/index.ts +48 -0
  135. package/src/app/api/[locale]/system/generators/endpoint/i18n/en/index.ts +48 -0
  136. package/src/app/api/[locale]/system/generators/endpoint/i18n/pl/index.ts +50 -0
  137. package/src/app/api/[locale]/system/generators/endpoint/repository.ts +291 -0
  138. package/src/app/api/[locale]/system/generators/endpoint/route.ts +21 -0
  139. package/src/app/api/[locale]/system/generators/endpoints/definition.ts +246 -0
  140. package/src/app/api/[locale]/system/generators/endpoints/i18n/de/index.ts +54 -0
  141. package/src/app/api/[locale]/system/generators/endpoints/i18n/en/index.ts +52 -0
  142. package/src/app/api/[locale]/system/generators/endpoints/i18n/pl/index.ts +54 -0
  143. package/src/app/api/[locale]/system/generators/endpoints/options-repository.ts +463 -0
  144. package/src/app/api/[locale]/system/generators/endpoints/repository.ts +383 -0
  145. package/src/app/api/[locale]/system/generators/endpoints/route.ts +18 -0
  146. package/src/app/api/[locale]/system/generators/endpoints-index/definition.ts +194 -0
  147. package/src/app/api/[locale]/system/generators/endpoints-index/i18n/de/index.ts +71 -0
  148. package/src/app/api/[locale]/system/generators/endpoints-index/i18n/en/index.ts +69 -0
  149. package/src/app/api/[locale]/system/generators/endpoints-index/i18n/pl/index.ts +71 -0
  150. package/src/app/api/[locale]/system/generators/endpoints-index/repository.ts +294 -0
  151. package/src/app/api/[locale]/system/generators/endpoints-index/route.ts +18 -0
  152. package/src/app/api/[locale]/system/generators/generate-all/definition.ts +355 -0
  153. package/src/app/api/[locale]/system/generators/generate-all/i18n/de/index.ts +96 -0
  154. package/src/app/api/[locale]/system/generators/generate-all/i18n/en/index.ts +94 -0
  155. package/src/app/api/[locale]/system/generators/generate-all/i18n/pl/index.ts +96 -0
  156. package/src/app/api/[locale]/system/generators/generate-all/repository.ts +257 -0
  157. package/src/app/api/[locale]/system/generators/generate-all/route.ts +20 -0
  158. package/src/app/api/[locale]/system/generators/i18n/de/index.ts +15 -0
  159. package/src/app/api/[locale]/system/generators/i18n/en/index.ts +14 -0
  160. package/src/app/api/[locale]/system/generators/i18n/pl/index.ts +15 -0
  161. package/src/app/api/[locale]/system/generators/route-handlers/definition.ts +198 -0
  162. package/src/app/api/[locale]/system/generators/route-handlers/i18n/de/index.ts +48 -0
  163. package/src/app/api/[locale]/system/generators/route-handlers/i18n/en/index.ts +48 -0
  164. package/src/app/api/[locale]/system/generators/route-handlers/i18n/pl/index.ts +50 -0
  165. package/src/app/api/[locale]/system/generators/route-handlers/repository.ts +277 -0
  166. package/src/app/api/[locale]/system/generators/route-handlers/route.ts +17 -0
  167. package/src/app/api/[locale]/system/generators/shared/utils.ts +233 -0
  168. package/src/app/api/[locale]/system/help/definition.ts +445 -0
  169. package/src/app/api/[locale]/system/help/i18n/de/index.ts +267 -0
  170. package/src/app/api/[locale]/system/help/i18n/en/index.ts +262 -0
  171. package/src/app/api/[locale]/system/help/i18n/pl/index.ts +265 -0
  172. package/src/app/api/[locale]/system/help/interactive/definition.ts +125 -0
  173. package/src/app/api/[locale]/system/help/interactive/i18n/de/index.ts +22 -0
  174. package/src/app/api/[locale]/system/help/interactive/i18n/en/index.ts +19 -0
  175. package/src/app/api/[locale]/system/help/interactive/i18n/pl/index.ts +22 -0
  176. package/src/app/api/[locale]/system/help/interactive/repository.ts +1025 -0
  177. package/src/app/api/[locale]/system/help/interactive/route.ts +53 -0
  178. package/src/app/api/[locale]/system/help/list/definition.ts +372 -0
  179. package/src/app/api/[locale]/system/help/list/repository.ts +110 -0
  180. package/src/app/api/[locale]/system/help/list/route.ts +21 -0
  181. package/src/app/api/[locale]/system/help/repository.ts +212 -0
  182. package/src/app/api/[locale]/system/help/route.ts +16 -0
  183. package/src/app/api/[locale]/system/i18n/de/index.ts +68 -0
  184. package/src/app/api/[locale]/system/i18n/en/index.ts +65 -0
  185. package/src/app/api/[locale]/system/i18n/pl/index.ts +66 -0
  186. package/src/app/api/[locale]/system/release-tool/definition.ts +3104 -0
  187. package/src/app/api/[locale]/system/release-tool/i18n/de/index.ts +813 -0
  188. package/src/app/api/[locale]/system/release-tool/i18n/en/index.ts +797 -0
  189. package/src/app/api/[locale]/system/release-tool/i18n/pl/index.ts +810 -0
  190. package/src/app/api/[locale]/system/release-tool/repository/asset-zipper.ts +128 -0
  191. package/src/app/api/[locale]/system/release-tool/repository/changelog-generator.ts +212 -0
  192. package/src/app/api/[locale]/system/release-tool/repository/ci-detector.ts +566 -0
  193. package/src/app/api/[locale]/system/release-tool/repository/config.ts +113 -0
  194. package/src/app/api/[locale]/system/release-tool/repository/constants.ts +407 -0
  195. package/src/app/api/[locale]/system/release-tool/repository/dependency-manager.ts +527 -0
  196. package/src/app/api/[locale]/system/release-tool/repository/git-service.ts +403 -0
  197. package/src/app/api/[locale]/system/release-tool/repository/hook-runner.ts +100 -0
  198. package/src/app/api/[locale]/system/release-tool/repository/index.ts +1 -0
  199. package/src/app/api/[locale]/system/release-tool/repository/notification-service.ts +638 -0
  200. package/src/app/api/[locale]/system/release-tool/repository/package-service.ts +169 -0
  201. package/src/app/api/[locale]/system/release-tool/repository/publisher.ts +253 -0
  202. package/src/app/api/[locale]/system/release-tool/repository/quality-runner.ts +428 -0
  203. package/src/app/api/[locale]/system/release-tool/repository/release-creator.ts +293 -0
  204. package/src/app/api/[locale]/system/release-tool/repository/release-executor.ts +1198 -0
  205. package/src/app/api/[locale]/system/release-tool/repository/snyk-service.ts +136 -0
  206. package/src/app/api/[locale]/system/release-tool/repository/utils.ts +642 -0
  207. package/src/app/api/[locale]/system/release-tool/repository/validation.ts +288 -0
  208. package/src/app/api/[locale]/system/release-tool/repository/version-service.ts +297 -0
  209. package/src/app/api/[locale]/system/release-tool/route.ts +21 -0
  210. package/src/app/api/[locale]/system/unified-interface/README.md +328 -0
  211. package/src/app/api/[locale]/system/unified-interface/cli/README.md +349 -0
  212. package/src/app/api/[locale]/system/unified-interface/cli/auth/cli-handler.ts +95 -0
  213. package/src/app/api/[locale]/system/unified-interface/cli/auth/cli-user.ts +146 -0
  214. package/src/app/api/[locale]/system/unified-interface/cli/auth/session-file.ts +266 -0
  215. package/src/app/api/[locale]/system/unified-interface/cli/env.ts +26 -0
  216. package/src/app/api/[locale]/system/unified-interface/cli/i18n/de/index.ts +157 -0
  217. package/src/app/api/[locale]/system/unified-interface/cli/i18n/en/index.ts +155 -0
  218. package/src/app/api/[locale]/system/unified-interface/cli/i18n/pl/index.ts +158 -0
  219. package/src/app/api/[locale]/system/unified-interface/cli/runtime/debug.ts +595 -0
  220. package/src/app/api/[locale]/system/unified-interface/cli/runtime/entry-point.ts +129 -0
  221. package/src/app/api/[locale]/system/unified-interface/cli/runtime/environment.ts +155 -0
  222. package/src/app/api/[locale]/system/unified-interface/cli/runtime/execution-errors.ts +452 -0
  223. package/src/app/api/[locale]/system/unified-interface/cli/runtime/parsing.ts +297 -0
  224. package/src/app/api/[locale]/system/unified-interface/cli/runtime/route-executor.ts +859 -0
  225. package/src/app/api/[locale]/system/unified-interface/cli/setup/i18n/de/index.ts +12 -0
  226. package/src/app/api/[locale]/system/unified-interface/cli/setup/i18n/en/index.ts +11 -0
  227. package/src/app/api/[locale]/system/unified-interface/cli/setup/i18n/pl/index.ts +12 -0
  228. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/definition.ts +262 -0
  229. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/i18n/de/index.ts +54 -0
  230. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/i18n/en/index.ts +52 -0
  231. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/i18n/pl/index.ts +54 -0
  232. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/repository.ts +421 -0
  233. package/src/app/api/[locale]/system/unified-interface/cli/setup/install/route.ts +25 -0
  234. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/definition.ts +181 -0
  235. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/i18n/de/index.ts +61 -0
  236. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/i18n/en/index.ts +59 -0
  237. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/i18n/pl/index.ts +61 -0
  238. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/repository.ts +195 -0
  239. package/src/app/api/[locale]/system/unified-interface/cli/setup/status/route.ts +22 -0
  240. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/definition.ts +188 -0
  241. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/i18n/de/index.ts +54 -0
  242. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/i18n/en/index.ts +52 -0
  243. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/i18n/pl/index.ts +54 -0
  244. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/repository.ts +209 -0
  245. package/src/app/api/[locale]/system/unified-interface/cli/setup/uninstall/route.ts +24 -0
  246. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/definition.ts +200 -0
  247. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/i18n/de/index.ts +54 -0
  248. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/i18n/en/index.ts +52 -0
  249. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/i18n/pl/index.ts +54 -0
  250. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/repository.ts +113 -0
  251. package/src/app/api/[locale]/system/unified-interface/cli/setup/update/route.ts +22 -0
  252. package/src/app/api/[locale]/system/unified-interface/cli/vibe-runtime.ts +304 -0
  253. package/src/app/api/[locale]/system/unified-interface/cli/widgets/core/base-renderer.ts +270 -0
  254. package/src/app/api/[locale]/system/unified-interface/cli/widgets/core/registry.ts +309 -0
  255. package/src/app/api/[locale]/system/unified-interface/cli/widgets/core/types.ts +126 -0
  256. package/src/app/api/[locale]/system/unified-interface/cli/widgets/i18n/de/index.ts +67 -0
  257. package/src/app/api/[locale]/system/unified-interface/cli/widgets/i18n/en/index.ts +65 -0
  258. package/src/app/api/[locale]/system/unified-interface/cli/widgets/i18n/pl/index.ts +67 -0
  259. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/accordion.ts +74 -0
  260. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/avatar.ts +39 -0
  261. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/badge.ts +54 -0
  262. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-output.ts +298 -0
  263. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-quality-files.ts +89 -0
  264. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-quality-list.ts +298 -0
  265. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/code-quality-summary.ts +96 -0
  266. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/container.ts +186 -0
  267. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-card.ts +65 -0
  268. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-cards.ts +570 -0
  269. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-list.ts +80 -0
  270. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/data-table.ts +385 -0
  271. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/editable-text.ts +99 -0
  272. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/empty-state.ts +55 -0
  273. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/errors.ts +67 -0
  274. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/grouped-list.ts +729 -0
  275. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/link-card.ts +87 -0
  276. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/link-list.ts +112 -0
  277. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/link.ts +59 -0
  278. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/loading.ts +50 -0
  279. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/markdown.ts +131 -0
  280. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/metric.ts +291 -0
  281. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/section.ts +120 -0
  282. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/stats-grid.ts +149 -0
  283. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/tabs.ts +61 -0
  284. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/text.ts +78 -0
  285. package/src/app/api/[locale]/system/unified-interface/cli/widgets/implementations/title.ts +42 -0
  286. package/src/app/api/[locale]/system/unified-interface/cli/widgets/renderers/response-renderer.ts +418 -0
  287. package/src/app/api/[locale]/system/unified-interface/cli/widgets/renderers/schema-handler.ts +534 -0
  288. package/src/app/api/[locale]/system/unified-interface/i18n/de/index.ts +42 -0
  289. package/src/app/api/[locale]/system/unified-interface/i18n/en/index.ts +40 -0
  290. package/src/app/api/[locale]/system/unified-interface/i18n/pl/index.ts +43 -0
  291. package/src/app/api/[locale]/system/unified-interface/mcp/README.md +114 -0
  292. package/src/app/api/[locale]/system/unified-interface/mcp/converter.ts +146 -0
  293. package/src/app/api/[locale]/system/unified-interface/mcp/i18n/de/index.ts +182 -0
  294. package/src/app/api/[locale]/system/unified-interface/mcp/i18n/en/index.ts +179 -0
  295. package/src/app/api/[locale]/system/unified-interface/mcp/i18n/pl/index.ts +181 -0
  296. package/src/app/api/[locale]/system/unified-interface/mcp/registry.ts +343 -0
  297. package/src/app/api/[locale]/system/unified-interface/mcp/serve/definition.ts +147 -0
  298. package/src/app/api/[locale]/system/unified-interface/mcp/serve/repository.ts +38 -0
  299. package/src/app/api/[locale]/system/unified-interface/mcp/serve/route.ts +14 -0
  300. package/src/app/api/[locale]/system/unified-interface/mcp/server/protocol-handler.ts +309 -0
  301. package/src/app/api/[locale]/system/unified-interface/mcp/server/server.ts +154 -0
  302. package/src/app/api/[locale]/system/unified-interface/mcp/server/stdio-transport.ts +193 -0
  303. package/src/app/api/[locale]/system/unified-interface/mcp/types.ts +246 -0
  304. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/create-form.ts +1510 -0
  305. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/create.ts +581 -0
  306. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/endpoint-to-metadata.ts +52 -0
  307. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definition/loader.ts +152 -0
  308. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/definitions/registry.ts +265 -0
  309. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/permissions/registry.ts +680 -0
  310. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/executor.ts +220 -0
  311. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/handler.ts +325 -0
  312. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/multi.ts +184 -0
  313. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/request-validator.ts +201 -0
  314. package/src/app/api/[locale]/system/unified-interface/shared/endpoints/route/single.ts +58 -0
  315. package/src/app/api/[locale]/system/unified-interface/shared/env/define-env-client.ts +49 -0
  316. package/src/app/api/[locale]/system/unified-interface/shared/env/define-env.ts +47 -0
  317. package/src/app/api/[locale]/system/unified-interface/shared/env/validation-logger.ts +58 -0
  318. package/src/app/api/[locale]/system/unified-interface/shared/field/enum.ts +110 -0
  319. package/src/app/api/[locale]/system/unified-interface/shared/field/specialized.ts +339 -0
  320. package/src/app/api/[locale]/system/unified-interface/shared/field/utils.test.ts +408 -0
  321. package/src/app/api/[locale]/system/unified-interface/shared/field/utils.ts +1349 -0
  322. package/src/app/api/[locale]/system/unified-interface/shared/field-config/endpoint-field-types.ts +107 -0
  323. package/src/app/api/[locale]/system/unified-interface/shared/field-config/field-config-types.ts +268 -0
  324. package/src/app/api/[locale]/system/unified-interface/shared/logger/colors.ts +114 -0
  325. package/src/app/api/[locale]/system/unified-interface/shared/logger/endpoint.ts +169 -0
  326. package/src/app/api/[locale]/system/unified-interface/shared/logger/file-logger.ts +88 -0
  327. package/src/app/api/[locale]/system/unified-interface/shared/logger/formatters.ts +177 -0
  328. package/src/app/api/[locale]/system/unified-interface/shared/server-only/auth/base-auth-handler.ts +82 -0
  329. package/src/app/api/[locale]/system/unified-interface/shared/server-only/auth/factory.ts +33 -0
  330. package/src/app/api/[locale]/system/unified-interface/shared/server-only/server-only.ts +4 -0
  331. package/src/app/api/[locale]/system/unified-interface/shared/types/actions.ts +289 -0
  332. package/src/app/api/[locale]/system/unified-interface/shared/types/endpoint.ts +1167 -0
  333. package/src/app/api/[locale]/system/unified-interface/shared/types/enums.ts +382 -0
  334. package/src/app/api/[locale]/system/unified-interface/shared/types/platform.ts +34 -0
  335. package/src/app/api/[locale]/system/unified-interface/shared/types/types.ts +80 -0
  336. package/src/app/api/[locale]/system/unified-interface/shared/types/ui-config.ts +76 -0
  337. package/src/app/api/[locale]/system/unified-interface/shared/utils/error-types.ts +27 -0
  338. package/src/app/api/[locale]/system/unified-interface/shared/utils/path.ts +63 -0
  339. package/src/app/api/[locale]/system/unified-interface/shared/utils/scanner.ts +241 -0
  340. package/src/app/api/[locale]/system/unified-interface/shared/widgets/actions.ts +256 -0
  341. package/src/app/api/[locale]/system/unified-interface/shared/widgets/configs.ts +1158 -0
  342. package/src/app/api/[locale]/system/unified-interface/shared/widgets/helpers.ts +80 -0
  343. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/accordion.ts +82 -0
  344. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/avatar.ts +75 -0
  345. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/badge.ts +89 -0
  346. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/code-output.ts +302 -0
  347. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/code-quality-list.ts +202 -0
  348. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/container.ts +129 -0
  349. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-card.ts +81 -0
  350. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-cards.ts +258 -0
  351. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-list.ts +123 -0
  352. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/data-table.ts +387 -0
  353. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/editable-text.ts +89 -0
  354. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/empty-state.ts +78 -0
  355. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/errors.ts +93 -0
  356. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/grouped-list.ts +448 -0
  357. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/index.ts +38 -0
  358. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/link-card.ts +130 -0
  359. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/link-list.ts +127 -0
  360. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/link.ts +68 -0
  361. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/loading.ts +81 -0
  362. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/markdown.ts +176 -0
  363. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/metric-card.ts +241 -0
  364. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/section.ts +90 -0
  365. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/stats-grid.ts +71 -0
  366. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/tabs.ts +80 -0
  367. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/text.ts +105 -0
  368. package/src/app/api/[locale]/system/unified-interface/shared/widgets/logic/title.ts +72 -0
  369. package/src/app/api/[locale]/system/unified-interface/shared/widgets/types.ts +240 -0
  370. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/field-helpers.ts +137 -0
  371. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/formatting.ts +437 -0
  372. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/url.ts +40 -0
  373. package/src/app/api/[locale]/system/unified-interface/shared/widgets/utils/widget-helpers.ts +465 -0
  374. package/src/app/api/[locale]/user/auth/enum.ts +16 -0
  375. package/src/app/api/[locale]/user/auth/i18n/de/index.ts +227 -0
  376. package/src/app/api/[locale]/user/auth/i18n/en/index.ts +205 -0
  377. package/src/app/api/[locale]/user/auth/i18n/pl/index.ts +219 -0
  378. package/src/app/api/[locale]/user/auth/types.ts +110 -0
  379. package/src/app/api/[locale]/user/enum.ts +64 -0
  380. package/src/app/api/[locale]/user/private/i18n/de/index.ts +3 -0
  381. package/src/app/api/[locale]/user/private/i18n/en/index.ts +1 -0
  382. package/src/app/api/[locale]/user/private/i18n/pl/index.ts +3 -0
  383. package/src/app/api/[locale]/user/types.ts +118 -0
  384. package/src/app/api/[locale]/user/user-roles/enum.ts +112 -0
  385. package/src/app/api/[locale]/user/user-roles/i18n/de/index.ts +85 -0
  386. package/src/app/api/[locale]/user/user-roles/i18n/en/index.ts +83 -0
  387. package/src/app/api/[locale]/user/user-roles/i18n/pl/index.ts +86 -0
  388. package/src/app/api/[locale]/user/user-roles/types.ts +34 -0
  389. package/src/app/api/i18n/de/index.ts +6 -0
  390. package/src/app/api/i18n/en/index.ts +5 -0
  391. package/src/app/api/i18n/pl/index.ts +5 -0
  392. package/src/app/i18n/de/index.ts +6 -0
  393. package/src/app/i18n/en/index.ts +5 -0
  394. package/src/app/i18n/pl/index.ts +5 -0
@@ -0,0 +1,680 @@
1
+ /**
2
+ * Permissions Registry
3
+ * Single source for ALL permission and access control logic
4
+ * Consolidates platform access, user role checks, and endpoint filtering
5
+ * Used by all adapters (definitions, definition, route-execution)
6
+ */
7
+
8
+ import type { ResponseType } from "next-vibe/shared/types/response.schema";
9
+ import { ErrorResponseTypes } from "next-vibe/shared/types/response.schema";
10
+
11
+ import type { JwtPayloadType } from "@/app/api/[locale]/user/auth/types";
12
+ import {
13
+ filterPlatformMarkers,
14
+ filterUserPermissionRoles,
15
+ PlatformMarker,
16
+ type PlatformMarkerValue,
17
+ UserPermissionRole,
18
+ type UserPermissionRoleValue,
19
+ UserRole,
20
+ type UserRoleValue,
21
+ } from "@/app/api/[locale]/user/user-roles/enum";
22
+ import { envClient } from "@/config/env-client";
23
+
24
+ import type { EndpointLogger } from "../../logger/endpoint";
25
+ import type { CreateApiEndpointAny } from "../../types/endpoint";
26
+ import { Platform } from "../../types/platform";
27
+ import type { InferJwtPayloadTypeFromRoles } from "../route/handler";
28
+
29
+ /**
30
+ * Platform access check result
31
+ */
32
+ interface PlatformAccessResult {
33
+ allowed: boolean;
34
+ reason?: string;
35
+ blockedByRole?: UserRoleValue;
36
+ }
37
+
38
+ /**
39
+ * User role check result
40
+ */
41
+ interface UserRoleCheckResult {
42
+ allowed: boolean;
43
+ reason?: string;
44
+ userRoles?: readonly (typeof UserPermissionRoleValue)[];
45
+ requiredRoles?: readonly (typeof UserPermissionRoleValue)[];
46
+ }
47
+
48
+ /**
49
+ * Interface for Permissions Registry
50
+ * Public API - only methods that should be called from outside
51
+ */
52
+ interface IPermissionsRegistry {
53
+ // === Access Control ===
54
+ /**
55
+ * Validate endpoint access - consolidated platform and permission checking
56
+ * Returns ResponseType with detailed error information
57
+ * Used by handler.ts and loader.ts for consistent access validation
58
+ */
59
+ validateEndpointAccess(
60
+ endpoint: CreateApiEndpointAny,
61
+ user: JwtPayloadType,
62
+ platform: Platform,
63
+ ): ResponseType<true>;
64
+
65
+ // === Endpoint Discovery & Filtering ===
66
+ /**
67
+ * Check if endpoint is accessible on platform (used by definitions registry)
68
+ */
69
+ checkPlatformAccess(
70
+ allowedRoles: readonly UserRoleValue[],
71
+ platform: Platform,
72
+ ): PlatformAccessResult;
73
+
74
+ /**
75
+ * Filter endpoints by user permissions (used by definitions, MCP, AI)
76
+ * Requires logger to fetch user roles from DB (not from JWT/cookies)
77
+ */
78
+ filterEndpointsByPermissions(
79
+ endpoints: CreateApiEndpointAny[],
80
+ user: JwtPayloadType,
81
+ platform: Platform,
82
+ logger: EndpointLogger,
83
+ ): CreateApiEndpointAny[];
84
+
85
+ /**
86
+ * Get endpoint count by category for user (used by definitions registry)
87
+ */
88
+ getEndpointCountByCategory(
89
+ endpoints: CreateApiEndpointAny[],
90
+ user: JwtPayloadType,
91
+ platform: Platform,
92
+ logger: EndpointLogger,
93
+ ): Record<string, number>;
94
+ }
95
+
96
+ /**
97
+ * Permissions Registry Class
98
+ * Consolidates ALL permission, authentication, and validation logic
99
+ */
100
+ class PermissionsRegistry implements IPermissionsRegistry {
101
+ /**
102
+ * Check if endpoint is accessible on the given platform
103
+ * Enforces _OFF platform markers for platform exclusion
104
+ */
105
+ checkPlatformAccess(
106
+ allowedRoles: readonly UserRoleValue[],
107
+ platform: Platform,
108
+ ): PlatformAccessResult {
109
+ const platformMarkers = filterPlatformMarkers(allowedRoles);
110
+
111
+ // Check production environment restrictions
112
+ if (
113
+ envClient.NODE_ENV === "production" &&
114
+ platformMarkers.includes(PlatformMarker.PRODUCTION_OFF)
115
+ ) {
116
+ return {
117
+ allowed: false,
118
+ reason: "Endpoint is disabled in production environment",
119
+ blockedByRole: PlatformMarker.PRODUCTION_OFF,
120
+ };
121
+ }
122
+
123
+ // Check platform-specific _OFF restrictions
124
+ const platformStr = String(platform).toLowerCase();
125
+
126
+ switch (platformStr) {
127
+ case "cli":
128
+ if (platformMarkers.includes(PlatformMarker.CLI_OFF)) {
129
+ return {
130
+ allowed: false,
131
+ reason: `Endpoint is not accessible via ${platformStr.toUpperCase()} platform`,
132
+ blockedByRole: PlatformMarker.CLI_OFF,
133
+ };
134
+ }
135
+ break;
136
+
137
+ case "mcp":
138
+ if (
139
+ platformMarkers.includes(PlatformMarker.MCP_OFF) ||
140
+ platformMarkers.includes(PlatformMarker.CLI_OFF)
141
+ ) {
142
+ return {
143
+ allowed: false,
144
+ reason: `Endpoint is not accessible via ${platformStr.toUpperCase()} platform`,
145
+ blockedByRole: PlatformMarker.MCP_OFF,
146
+ };
147
+ }
148
+ break;
149
+
150
+ case "cli-package":
151
+ // CLI_PACKAGE can only access endpoints with CLI_AUTH_BYPASS marker
152
+ // This restricts npm package users to unauthenticated endpoints only
153
+ if (platformMarkers.includes(PlatformMarker.CLI_OFF)) {
154
+ return {
155
+ allowed: false,
156
+ reason: "Endpoint is not accessible via CLI_PACKAGE platform",
157
+ blockedByRole: PlatformMarker.CLI_OFF,
158
+ };
159
+ }
160
+ if (!platformMarkers.includes(PlatformMarker.CLI_AUTH_BYPASS)) {
161
+ return {
162
+ allowed: false,
163
+ reason:
164
+ "Endpoint requires authentication which is not available in CLI_PACKAGE mode",
165
+ blockedByRole: PlatformMarker.CLI_AUTH_BYPASS,
166
+ };
167
+ }
168
+ break;
169
+
170
+ case "ai":
171
+ if (platformMarkers.includes(PlatformMarker.AI_TOOL_OFF)) {
172
+ return {
173
+ allowed: false,
174
+ reason: "Endpoint is not accessible via AI tools",
175
+ blockedByRole: PlatformMarker.AI_TOOL_OFF,
176
+ };
177
+ }
178
+ break;
179
+
180
+ case "web":
181
+ case "next":
182
+ case "trpc":
183
+ if (platformMarkers.includes(PlatformMarker.WEB_OFF)) {
184
+ return {
185
+ allowed: false,
186
+ reason: "Endpoint is not accessible via Web platform",
187
+ blockedByRole: PlatformMarker.WEB_OFF,
188
+ };
189
+ }
190
+ break;
191
+
192
+ case "mobile":
193
+ case "native":
194
+ // Mobile follows web rules for now
195
+ if (platformMarkers.includes(PlatformMarker.WEB_OFF)) {
196
+ return {
197
+ allowed: false,
198
+ reason: "Endpoint is not accessible via Mobile platform",
199
+ blockedByRole: PlatformMarker.WEB_OFF,
200
+ };
201
+ }
202
+ break;
203
+ }
204
+
205
+ return { allowed: true };
206
+ }
207
+
208
+ /**
209
+ * Check if user has required permission roles for the endpoint
210
+ */
211
+ checkUserRoles(
212
+ user: InferJwtPayloadTypeFromRoles<readonly UserRoleValue[]>,
213
+ permissionRoles: readonly (typeof UserPermissionRoleValue)[],
214
+ userRoles: (typeof UserPermissionRoleValue)[],
215
+ ): UserRoleCheckResult {
216
+ // If no permission roles defined, endpoint is open to all
217
+ if (permissionRoles.length === 0) {
218
+ return { allowed: true };
219
+ }
220
+
221
+ // Check if PUBLIC is allowed (anyone can access)
222
+ if (permissionRoles.includes(UserPermissionRole.PUBLIC)) {
223
+ return { allowed: true };
224
+ }
225
+
226
+ // For public users (not authenticated), check if PUBLIC is allowed
227
+ if (user.isPublic) {
228
+ return {
229
+ allowed: false,
230
+ reason:
231
+ "Authentication required - endpoint does not allow public access",
232
+ userRoles: [],
233
+ requiredRoles: permissionRoles,
234
+ };
235
+ }
236
+
237
+ // Check if user has any of the required roles
238
+ const hasRequiredRole = permissionRoles.some((requiredRole) =>
239
+ userRoles.includes(requiredRole),
240
+ );
241
+
242
+ if (!hasRequiredRole) {
243
+ return {
244
+ allowed: false,
245
+ reason: "User does not have required role for this endpoint",
246
+ userRoles,
247
+ requiredRoles: permissionRoles,
248
+ };
249
+ }
250
+
251
+ return {
252
+ allowed: true,
253
+ userRoles,
254
+ requiredRoles: permissionRoles,
255
+ };
256
+ }
257
+
258
+ /**
259
+ * Full access check combining platform and user role checks (PRIVATE - used internally)
260
+ */
261
+ private async checkFullAccess(
262
+ allowedRoles: readonly UserRoleValue[],
263
+ platform: Platform | string,
264
+ user: InferJwtPayloadTypeFromRoles<readonly UserRoleValue[]>,
265
+ userRoles: (typeof UserPermissionRoleValue)[],
266
+ logger: EndpointLogger,
267
+ ): Promise<ResponseType<true>> {
268
+ // Separate concerns: filter platform markers and permission roles
269
+ const platformMarkers = filterPlatformMarkers(allowedRoles);
270
+ const permissionRoles = filterUserPermissionRoles(allowedRoles);
271
+
272
+ logger.debug("Access check - separated concerns", {
273
+ platformMarkers,
274
+ permissionRoles,
275
+ platform,
276
+ });
277
+
278
+ // 1. Check platform access first
279
+ const platformAccess = this.checkPlatformAccess(
280
+ allowedRoles,
281
+ platform as Platform,
282
+ );
283
+ if (!platformAccess.allowed) {
284
+ logger.warn("Platform access denied", {
285
+ platform,
286
+ reason: platformAccess.reason,
287
+ blockedByRole: platformAccess.blockedByRole,
288
+ });
289
+
290
+ return {
291
+ success: false,
292
+ message:
293
+ "app.api.system.unifiedInterface.shared.permissions.errors.platformAccessDenied",
294
+ errorType: ErrorResponseTypes.FORBIDDEN,
295
+ messageParams: {
296
+ platform: String(platform),
297
+ reason: platformAccess.reason || "Platform not allowed",
298
+ },
299
+ };
300
+ }
301
+
302
+ // 2. Check if CLI auth bypass is allowed (skip role check if true)
303
+ if (this.allowsCliAuthBypass(platformMarkers)) {
304
+ logger.debug("CLI auth bypass enabled for endpoint", {
305
+ userId: user.isPublic ? "public" : user.id,
306
+ platformMarkers,
307
+ });
308
+ return { success: true, data: true };
309
+ }
310
+
311
+ // 3. Check user role permissions
312
+ const roleAccess = this.checkUserRoles(user, permissionRoles, userRoles);
313
+ if (!roleAccess.allowed) {
314
+ logger.warn("User role access denied", {
315
+ userId: user.isPublic ? "public" : user.id,
316
+ reason: roleAccess.reason,
317
+ userRoles: roleAccess.userRoles
318
+ ? (roleAccess.userRoles as string[]).join(", ")
319
+ : undefined,
320
+ requiredRoles: roleAccess.requiredRoles
321
+ ? (roleAccess.requiredRoles as string[]).join(", ")
322
+ : undefined,
323
+ });
324
+
325
+ return {
326
+ success: false,
327
+ message:
328
+ "app.api.system.unifiedInterface.shared.permissions.errors.insufficientRoles",
329
+ errorType: ErrorResponseTypes.FORBIDDEN,
330
+ messageParams: {
331
+ userRoles: (roleAccess.userRoles || []).join(", ") || "none",
332
+ requiredRoles: (roleAccess.requiredRoles || []).join(", "),
333
+ },
334
+ };
335
+ }
336
+
337
+ return { success: true, data: true };
338
+ }
339
+
340
+ /**
341
+ * Validate endpoint access - consolidated platform and permission checking
342
+ * Returns ResponseType with detailed error information
343
+ * Used by handler.ts and loader.ts for consistent access validation
344
+ */
345
+ validateEndpointAccess(
346
+ endpoint: CreateApiEndpointAny,
347
+ user: JwtPayloadType,
348
+ platform: Platform,
349
+ ): ResponseType<true> {
350
+ // Safety check: if allowedRoles is undefined or not an array, deny access
351
+ if (!endpoint.allowedRoles || !Array.isArray(endpoint.allowedRoles)) {
352
+ return {
353
+ success: false,
354
+ message:
355
+ "app.api.system.unifiedInterface.shared.permissions.errors.definitionError",
356
+ errorType: ErrorResponseTypes.INTERNAL_ERROR,
357
+ messageParams: {
358
+ error: "Endpoint allowedRoles is not properly configured",
359
+ },
360
+ };
361
+ }
362
+
363
+ // 1. Check platform access first
364
+ const platformAccess = this.checkPlatformAccess(
365
+ endpoint.allowedRoles,
366
+ platform,
367
+ );
368
+ if (!platformAccess.allowed) {
369
+ return {
370
+ success: false,
371
+ message:
372
+ "app.api.system.unifiedInterface.shared.permissions.errors.platformAccessDenied",
373
+ errorType: ErrorResponseTypes.FORBIDDEN,
374
+ messageParams: {
375
+ platform: String(platform),
376
+ reason: platformAccess.reason || "Platform not allowed",
377
+ },
378
+ };
379
+ }
380
+
381
+ // 2. Check user permissions
382
+ const hasPermission = this.hasEndpointPermission(endpoint, user, platform);
383
+ if (!hasPermission) {
384
+ return {
385
+ success: false,
386
+ message:
387
+ "app.api.system.unifiedInterface.shared.permissions.errors.insufficientRoles",
388
+ errorType: ErrorResponseTypes.FORBIDDEN,
389
+ messageParams: {
390
+ userId: user.isPublic ? "public" : user.id,
391
+ requiredRoles: endpoint.allowedRoles.join(", "),
392
+ userRoles: user.roles?.join(", ") || "none",
393
+ },
394
+ };
395
+ }
396
+
397
+ return {
398
+ success: true,
399
+ data: true,
400
+ };
401
+ }
402
+
403
+ /**
404
+ * Check if user has permission for endpoint on specific platform
405
+ * Uses OPT-OUT logic:
406
+ * - Endpoint is accessible by default if user has the required role
407
+ * - Endpoint can opt-out of specific platforms using CLI_OFF, AI_TOOL_OFF, WEB_OFF
408
+ */
409
+ private hasEndpointPermission(
410
+ endpoint: CreateApiEndpointAny,
411
+ user: JwtPayloadType,
412
+ platform: Platform,
413
+ ): boolean {
414
+ // Safety check: if allowedRoles is undefined or not an array, deny access
415
+ if (!endpoint.allowedRoles || !Array.isArray(endpoint.allowedRoles)) {
416
+ return false;
417
+ }
418
+
419
+ // Check platform opt-out first
420
+ if (this.isEndpointOptedOutOfPlatform(endpoint, platform)) {
421
+ return false;
422
+ }
423
+
424
+ // Check for CLI auth bypass - if enabled, allow access without role check
425
+ const platformMarkers = filterPlatformMarkers(endpoint.allowedRoles);
426
+ if (this.allowsCliAuthBypass(platformMarkers)) {
427
+ return true;
428
+ }
429
+
430
+ // Filter out opt-out roles from allowed roles for permission check
431
+ const effectiveAllowedRoles = endpoint.allowedRoles.filter(
432
+ (role: UserRoleValue[number]) => !this.isOptOutRole(role),
433
+ );
434
+
435
+ // Extract user permission roles from effective allowed roles
436
+ const permissionRoles = filterUserPermissionRoles(effectiveAllowedRoles);
437
+
438
+ // Special handling for PUBLIC role
439
+ // PUBLIC role is exclusive to public/unauthenticated users (user.isPublic === true)
440
+ // Public users have empty roles array, so we check isPublic flag instead
441
+ if (user.isPublic && permissionRoles.includes(UserPermissionRole.PUBLIC)) {
442
+ return true;
443
+ }
444
+
445
+ // Check if user has any of the required roles
446
+ // User roles come from JWT payload which was populated from DB during login/signup
447
+ const userRoles = user.roles || [];
448
+
449
+ const hasRequiredRole = effectiveAllowedRoles.some((requiredRole) =>
450
+ userRoles.includes(requiredRole),
451
+ );
452
+
453
+ return hasRequiredRole;
454
+ }
455
+
456
+ /**
457
+ * Filter endpoints by user permissions
458
+ * Requires logger to fetch user roles from DB (not from JWT/cookies)
459
+ * Note: Currently uses JWT-based permission check, but logger is required
460
+ * for future enhancement to fetch roles from DB
461
+ */
462
+ filterEndpointsByPermissions(
463
+ endpoints: CreateApiEndpointAny[],
464
+ user: JwtPayloadType,
465
+ platform: Platform,
466
+ logger: EndpointLogger,
467
+ ): CreateApiEndpointAny[] {
468
+ logger.debug("[Permissions Registry] Filtering endpoints by permissions", {
469
+ totalEndpoints: endpoints.length,
470
+ platform,
471
+ isPublic: user.isPublic,
472
+ });
473
+
474
+ const filtered = endpoints.filter((endpoint) =>
475
+ this.hasEndpointPermission(endpoint, user, platform),
476
+ );
477
+
478
+ logger.debug("[Permissions Registry] Filtered endpoints", {
479
+ totalEndpoints: endpoints.length,
480
+ filteredEndpoints: filtered.length,
481
+ });
482
+
483
+ return filtered;
484
+ }
485
+
486
+ /**
487
+ * Get available endpoints count by category for user
488
+ */
489
+ getEndpointCountByCategory(
490
+ endpoints: CreateApiEndpointAny[],
491
+ user: JwtPayloadType,
492
+ platform: Platform = Platform.AI,
493
+ logger: EndpointLogger,
494
+ ): Record<string, number> {
495
+ const filtered = this.filterEndpointsByPermissions(
496
+ endpoints,
497
+ user,
498
+ platform,
499
+ logger,
500
+ );
501
+ const counts: Record<string, number> = {};
502
+
503
+ for (const endpoint of filtered) {
504
+ const category = endpoint.category;
505
+ if (category) {
506
+ counts[category] = (counts[category] || 0) + 1;
507
+ }
508
+ }
509
+
510
+ return counts;
511
+ }
512
+
513
+ /**
514
+ * Get available endpoints count by role (PRIVATE - used internally)
515
+ */
516
+ private getEndpointCountByRole(
517
+ endpoints: CreateApiEndpointAny[],
518
+ ): Record<string, number> {
519
+ const counts: Record<string, number> = {};
520
+
521
+ for (const endpoint of endpoints) {
522
+ // Safety check: skip if allowedRoles is undefined or not an array
523
+ if (!endpoint?.allowedRoles || !Array.isArray(endpoint.allowedRoles)) {
524
+ continue;
525
+ }
526
+
527
+ for (const role of endpoint.allowedRoles) {
528
+ // Only count actual user roles, not opt-out roles
529
+ const roleValue = role as UserRoleValue[number];
530
+ if (!this.isOptOutRole(roleValue)) {
531
+ counts[roleValue] = (counts[roleValue] || 0) + 1;
532
+ }
533
+ }
534
+ }
535
+
536
+ return counts;
537
+ }
538
+
539
+ /**
540
+ * Check if endpoint allows CLI auth bypass (PRIVATE - used internally)
541
+ */
542
+ private allowsCliAuthBypass(
543
+ platformMarkers: readonly (typeof PlatformMarkerValue)[],
544
+ ): boolean {
545
+ return platformMarkers.includes(PlatformMarker.CLI_AUTH_BYPASS);
546
+ }
547
+
548
+ /**
549
+ * Get role priority for permission hierarchy (PRIVATE - used internally)
550
+ */
551
+ private getRolePriority(role: typeof UserPermissionRoleValue): number {
552
+ const priorities: Record<typeof UserPermissionRoleValue, number> = {
553
+ [UserPermissionRole.PUBLIC]: 0,
554
+ [UserPermissionRole.CUSTOMER]: 5,
555
+ [UserPermissionRole.PARTNER_EMPLOYEE]: 20,
556
+ [UserPermissionRole.PARTNER_ADMIN]: 50,
557
+ [UserPermissionRole.ADMIN]: 100,
558
+ };
559
+
560
+ return priorities[role];
561
+ }
562
+
563
+ /**
564
+ * Check if role A can access role B's resources (PRIVATE - used internally)
565
+ */
566
+ private canAccessRole(
567
+ userRole: typeof UserPermissionRoleValue,
568
+ requiredRole: typeof UserPermissionRoleValue,
569
+ ): boolean {
570
+ // Opt-out roles can't be used for access checks
571
+ if (this.isOptOutRole(requiredRole)) {
572
+ return false;
573
+ }
574
+ const userPriority = this.getRolePriority(userRole);
575
+ const requiredPriority = this.getRolePriority(requiredRole);
576
+ return userPriority >= requiredPriority;
577
+ }
578
+
579
+ /**
580
+ * Check if user can execute batch operations (PRIVATE - used internally)
581
+ */
582
+ private canExecuteBatchOperations(user: JwtPayloadType): boolean {
583
+ return !user.isPublic;
584
+ }
585
+
586
+ /**
587
+ * Get maximum tools per message for user (PRIVATE - used internally)
588
+ */
589
+ private getMaxToolsPerMessage(user: JwtPayloadType): number {
590
+ if (user.isPublic) {
591
+ return 3; // Limited for public users
592
+ }
593
+
594
+ return 10; // Default max tools per request for authenticated users
595
+ }
596
+
597
+ /**
598
+ * Get platforms endpoint is available on (PRIVATE - used internally)
599
+ */
600
+ private getAvailablePlatforms(endpoint: CreateApiEndpointAny): Platform[] {
601
+ const platforms: Platform[] = [];
602
+
603
+ // Safety check
604
+ if (!endpoint?.allowedRoles || !Array.isArray(endpoint.allowedRoles)) {
605
+ return platforms;
606
+ }
607
+
608
+ if (!endpoint.allowedRoles.includes(UserRole.CLI_OFF)) {
609
+ platforms.push(Platform.CLI);
610
+ // CLI_PACKAGE only available for endpoints with CLI_AUTH_BYPASS
611
+ // (unauthenticated endpoints that don't require local auth)
612
+ if (endpoint.allowedRoles.includes(PlatformMarker.CLI_AUTH_BYPASS)) {
613
+ platforms.push(Platform.CLI_PACKAGE);
614
+ }
615
+ }
616
+ if (!endpoint.allowedRoles.includes(UserRole.AI_TOOL_OFF)) {
617
+ platforms.push(Platform.AI);
618
+ }
619
+ if (!endpoint.allowedRoles.includes(UserRole.WEB_OFF)) {
620
+ // WEB_OFF disables all web platforms (TRPC, NEXT_PAGE, NEXT_API)
621
+ platforms.push(Platform.TRPC);
622
+ platforms.push(Platform.NEXT_PAGE);
623
+ platforms.push(Platform.NEXT_API);
624
+ }
625
+
626
+ return platforms;
627
+ }
628
+
629
+ /**
630
+ * Check if endpoint is opted out of specific platform
631
+ */
632
+ private isEndpointOptedOutOfPlatform(
633
+ endpoint: CreateApiEndpointAny,
634
+ platform: Platform,
635
+ ): boolean {
636
+ // Safety check
637
+ if (!endpoint?.allowedRoles || !Array.isArray(endpoint.allowedRoles)) {
638
+ return false;
639
+ }
640
+
641
+ // Check if endpoint is disabled in production environment
642
+ if (
643
+ process.env.NODE_ENV === "production" &&
644
+ endpoint.allowedRoles.includes(UserRole.PRODUCTION_OFF)
645
+ ) {
646
+ return true;
647
+ }
648
+
649
+ // Normalize platform to lowercase string
650
+ const platformStr = String(platform).toLowerCase();
651
+
652
+ switch (platformStr) {
653
+ case "cli":
654
+ return endpoint.allowedRoles.includes(UserRole.CLI_OFF);
655
+ case "ai":
656
+ return endpoint.allowedRoles.includes(UserRole.AI_TOOL_OFF);
657
+ case "web":
658
+ return endpoint.allowedRoles.includes(UserRole.WEB_OFF);
659
+ default:
660
+ return false;
661
+ }
662
+ }
663
+
664
+ /**
665
+ * Check if role is an opt-out role
666
+ */
667
+ private isOptOutRole(role: UserRoleValue[number]): boolean {
668
+ return (
669
+ role === UserRole.CLI_OFF ||
670
+ role === UserRole.AI_TOOL_OFF ||
671
+ role === UserRole.WEB_OFF ||
672
+ role === UserRole.PRODUCTION_OFF
673
+ );
674
+ }
675
+ }
676
+
677
+ /**
678
+ * Singleton instance
679
+ */
680
+ export const permissionsRegistry = new PermissionsRegistry();