@origen-ui/admin-cli 1.0.0

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 (430) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +17 -0
  3. package/bin/og-admin.mjs +131 -0
  4. package/package.json +28 -0
  5. package/templates/current/clean/.codebuddy/AGENTS.md +18 -0
  6. package/templates/current/clean/.codebuddy/rules/01-feature-architecture.md +12 -0
  7. package/templates/current/clean/.codebuddy/rules/02-vue-typescript.md +12 -0
  8. package/templates/current/clean/.codebuddy/rules/03-component-policy.md +30 -0
  9. package/templates/current/clean/.codebuddy/rules/04-api-auth-router.md +12 -0
  10. package/templates/current/clean/.codebuddy/rules/05-style.md +12 -0
  11. package/templates/current/clean/.codebuddy/rules/06-quality.md +12 -0
  12. package/templates/current/clean/.codebuddy/skills/build-admin-feature/SKILL.md +17 -0
  13. package/templates/current/clean/.codebuddy/skills/style-og-origen-ui/SKILL.md +14 -0
  14. package/templates/current/clean/.codebuddy/skills/use-og-dialog/SKILL.md +15 -0
  15. package/templates/current/clean/.codebuddy/skills/use-og-editor/SKILL.md +28 -0
  16. package/templates/current/clean/.codebuddy/skills/use-og-form/SKILL.md +15 -0
  17. package/templates/current/clean/.codebuddy/skills/use-og-form-table/SKILL.md +28 -0
  18. package/templates/current/clean/.codebuddy/skills/use-og-http/SKILL.md +16 -0
  19. package/templates/current/clean/.codebuddy/skills/use-og-router-tabs/SKILL.md +14 -0
  20. package/templates/current/clean/.codebuddy/skills/use-og-search/SKILL.md +17 -0
  21. package/templates/current/clean/.codebuddy/skills/use-og-table/SKILL.md +19 -0
  22. package/templates/current/clean/.codebuddy/skills/use-og-upload/SKILL.md +28 -0
  23. package/templates/current/clean/.codex/AGENTS.md +15 -0
  24. package/templates/current/clean/.codex/rules/01-feature-architecture.md +6 -0
  25. package/templates/current/clean/.codex/rules/02-vue-typescript.md +6 -0
  26. package/templates/current/clean/.codex/rules/03-component-policy.md +24 -0
  27. package/templates/current/clean/.codex/rules/04-api-auth-router.md +6 -0
  28. package/templates/current/clean/.codex/rules/05-style.md +6 -0
  29. package/templates/current/clean/.codex/rules/06-quality.md +6 -0
  30. package/templates/current/clean/.codex/skills/build-admin-feature/SKILL.md +14 -0
  31. package/templates/current/clean/.codex/skills/build-admin-feature/references/component-selection.md +25 -0
  32. package/templates/current/clean/.codex/skills/style-og-origen-ui/SKILL.md +11 -0
  33. package/templates/current/clean/.codex/skills/style-og-origen-ui/agents/openai.yaml +4 -0
  34. package/templates/current/clean/.codex/skills/use-og-dialog/SKILL.md +12 -0
  35. package/templates/current/clean/.codex/skills/use-og-dialog/agents/openai.yaml +4 -0
  36. package/templates/current/clean/.codex/skills/use-og-editor/SKILL.md +25 -0
  37. package/templates/current/clean/.codex/skills/use-og-form/SKILL.md +12 -0
  38. package/templates/current/clean/.codex/skills/use-og-form-table/SKILL.md +25 -0
  39. package/templates/current/clean/.codex/skills/use-og-http/SKILL.md +13 -0
  40. package/templates/current/clean/.codex/skills/use-og-http/agents/openai.yaml +4 -0
  41. package/templates/current/clean/.codex/skills/use-og-router-tabs/SKILL.md +11 -0
  42. package/templates/current/clean/.codex/skills/use-og-search/SKILL.md +14 -0
  43. package/templates/current/clean/.codex/skills/use-og-table/SKILL.md +16 -0
  44. package/templates/current/clean/.codex/skills/use-og-upload/SKILL.md +25 -0
  45. package/templates/current/clean/.cursor/AGENTS.md +18 -0
  46. package/templates/current/clean/.cursor/rules/01-feature-architecture.mdc +12 -0
  47. package/templates/current/clean/.cursor/rules/02-vue-typescript.mdc +12 -0
  48. package/templates/current/clean/.cursor/rules/03-component-policy.mdc +30 -0
  49. package/templates/current/clean/.cursor/rules/04-api-auth-router.mdc +12 -0
  50. package/templates/current/clean/.cursor/rules/05-style.mdc +12 -0
  51. package/templates/current/clean/.cursor/rules/06-quality.mdc +12 -0
  52. package/templates/current/clean/.cursor/skills/build-admin-feature/SKILL.md +14 -0
  53. package/templates/current/clean/.cursor/skills/style-og-origen-ui/SKILL.md +11 -0
  54. package/templates/current/clean/.cursor/skills/use-og-dialog/SKILL.md +12 -0
  55. package/templates/current/clean/.cursor/skills/use-og-editor/SKILL.md +25 -0
  56. package/templates/current/clean/.cursor/skills/use-og-form/SKILL.md +12 -0
  57. package/templates/current/clean/.cursor/skills/use-og-form-table/SKILL.md +25 -0
  58. package/templates/current/clean/.cursor/skills/use-og-http/SKILL.md +13 -0
  59. package/templates/current/clean/.cursor/skills/use-og-router-tabs/SKILL.md +11 -0
  60. package/templates/current/clean/.cursor/skills/use-og-search/SKILL.md +14 -0
  61. package/templates/current/clean/.cursor/skills/use-og-table/SKILL.md +16 -0
  62. package/templates/current/clean/.cursor/skills/use-og-upload/SKILL.md +25 -0
  63. package/templates/current/clean/.env.example +7 -0
  64. package/templates/current/clean/.env.production.example +31 -0
  65. package/templates/current/clean/.qoder/AGENTS.md +15 -0
  66. package/templates/current/clean/.qoder/rules/01-feature-architecture.md +12 -0
  67. package/templates/current/clean/.qoder/rules/02-vue-typescript.md +12 -0
  68. package/templates/current/clean/.qoder/rules/03-component-policy.md +30 -0
  69. package/templates/current/clean/.qoder/rules/04-api-auth-router.md +12 -0
  70. package/templates/current/clean/.qoder/rules/05-style.md +12 -0
  71. package/templates/current/clean/.qoder/rules/06-quality.md +12 -0
  72. package/templates/current/clean/.qoder/skills/build-admin-feature/SKILL.md +14 -0
  73. package/templates/current/clean/.qoder/skills/style-og-origen-ui/SKILL.md +11 -0
  74. package/templates/current/clean/.qoder/skills/use-og-dialog/SKILL.md +12 -0
  75. package/templates/current/clean/.qoder/skills/use-og-editor/SKILL.md +25 -0
  76. package/templates/current/clean/.qoder/skills/use-og-form/SKILL.md +12 -0
  77. package/templates/current/clean/.qoder/skills/use-og-form-table/SKILL.md +25 -0
  78. package/templates/current/clean/.qoder/skills/use-og-http/SKILL.md +13 -0
  79. package/templates/current/clean/.qoder/skills/use-og-router-tabs/SKILL.md +11 -0
  80. package/templates/current/clean/.qoder/skills/use-og-search/SKILL.md +14 -0
  81. package/templates/current/clean/.qoder/skills/use-og-table/SKILL.md +16 -0
  82. package/templates/current/clean/.qoder/skills/use-og-upload/SKILL.md +25 -0
  83. package/templates/current/clean/AGENTS.md +16 -0
  84. package/templates/current/clean/README.md +116 -0
  85. package/templates/current/clean/component-catalog.json +765 -0
  86. package/templates/current/clean/e2e/admin-shell.spec.ts +150 -0
  87. package/templates/current/clean/e2e/demo-shell.spec.ts +328 -0
  88. package/templates/current/clean/evals/component-selection.json +29 -0
  89. package/templates/current/clean/gitignore +3 -0
  90. package/templates/current/clean/index.html +13 -0
  91. package/templates/current/clean/openapi.json +1623 -0
  92. package/templates/current/clean/package.json +65 -0
  93. package/templates/current/clean/playwright.config.ts +31 -0
  94. package/templates/current/clean/playwright.demo.config.ts +25 -0
  95. package/templates/current/clean/recipes/README.md +7 -0
  96. package/templates/current/clean/recipes/remote-crud-dialog-form.json +15 -0
  97. package/templates/current/clean/recipes/remote-crud-dialog-form.vue +66 -0
  98. package/templates/current/clean/scaffold.lock.json +12 -0
  99. package/templates/current/clean/scripts/check-admin-bundle.mjs +214 -0
  100. package/templates/current/clean/scripts/check-admin-scaffold.mjs +168 -0
  101. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +26 -0
  102. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +26 -0
  103. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +26 -0
  104. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +32 -0
  105. package/templates/current/clean/scripts/clean-overlay/src/main.ts +91 -0
  106. package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +25 -0
  107. package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +47 -0
  108. package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +63 -0
  109. package/templates/current/clean/scripts/demo-api.ts +797 -0
  110. package/templates/current/clean/scripts/generate-api.ts +27 -0
  111. package/templates/current/clean/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +38 -0
  112. package/templates/current/clean/scripts/remove-examples.mjs +54 -0
  113. package/templates/current/clean/src/App.vue +67 -0
  114. package/templates/current/clean/src/api/client.spec.ts +66 -0
  115. package/templates/current/clean/src/api/client.ts +72 -0
  116. package/templates/current/clean/src/api/generated/data-contracts.ts +268 -0
  117. package/templates/current/clean/src/api/generated/http-client.ts +266 -0
  118. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +147 -0
  119. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +53 -0
  120. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +66 -0
  121. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +171 -0
  122. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +181 -0
  123. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +169 -0
  124. package/templates/current/clean/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +170 -0
  125. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +98 -0
  126. package/templates/current/clean/src/api/http-adapter.spec.ts +33 -0
  127. package/templates/current/clean/src/api/http-adapter.ts +83 -0
  128. package/templates/current/clean/src/api/index.ts +41 -0
  129. package/templates/current/clean/src/app/createAdminUi.spec.ts +110 -0
  130. package/templates/current/clean/src/app/createAdminUi.ts +78 -0
  131. package/templates/current/clean/src/app/menu.spec.ts +255 -0
  132. package/templates/current/clean/src/app/menu.ts +268 -0
  133. package/templates/current/clean/src/app/menuTypes.ts +17 -0
  134. package/templates/current/clean/src/app/origenUiLocale.spec.ts +14 -0
  135. package/templates/current/clean/src/app/origenUiLocale.ts +65 -0
  136. package/templates/current/clean/src/app/permission.ts +9 -0
  137. package/templates/current/clean/src/app/runtimeConfig.ts +77 -0
  138. package/templates/current/clean/src/demo-api.spec.ts +167 -0
  139. package/templates/current/clean/src/env.d.ts +14 -0
  140. package/templates/current/clean/src/features/appearance/components/ThemePanel.vue +200 -0
  141. package/templates/current/clean/src/features/appearance/composables/useTheme.ts +17 -0
  142. package/templates/current/clean/src/features/appearance/store/theme.ts +140 -0
  143. package/templates/current/clean/src/features/auth/pages/Login.vue +159 -0
  144. package/templates/current/clean/src/features/auth/store/auth.spec.ts +131 -0
  145. package/templates/current/clean/src/features/auth/store/auth.ts +210 -0
  146. package/templates/current/clean/src/features/errors/pages/Forbidden.vue +26 -0
  147. package/templates/current/clean/src/features/errors/pages/NotFound.vue +26 -0
  148. package/templates/current/clean/src/features/errors/pages/ServerError.vue +26 -0
  149. package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +32 -0
  150. package/templates/current/clean/src/features/security/components/DevtoolsProtectionOverlay.vue +56 -0
  151. package/templates/current/clean/src/features/security/devtoolsProtection.spec.ts +211 -0
  152. package/templates/current/clean/src/features/security/devtoolsProtection.ts +242 -0
  153. package/templates/current/clean/src/features/shell/components/AdminWatermark.spec.ts +90 -0
  154. package/templates/current/clean/src/features/shell/components/AdminWatermark.vue +47 -0
  155. package/templates/current/clean/src/features/shell/components/RouteProgress.vue +68 -0
  156. package/templates/current/clean/src/features/shell/composables/useRouteProgress.spec.ts +95 -0
  157. package/templates/current/clean/src/features/shell/composables/useRouteProgress.ts +52 -0
  158. package/templates/current/clean/src/features/shell/store/sidebar.ts +55 -0
  159. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +279 -0
  160. package/templates/current/clean/src/features/system/access/api/rbac.spec.ts +72 -0
  161. package/templates/current/clean/src/features/system/access/api/rbac.ts +272 -0
  162. package/templates/current/clean/src/features/system/access/composables/useAuthorizationRefresh.ts +15 -0
  163. package/templates/current/clean/src/features/workspace/pages/Empty.vue +18 -0
  164. package/templates/current/clean/src/features/workspace/pages/Profile.vue +183 -0
  165. package/templates/current/clean/src/layouts/AdminLayout.vue +61 -0
  166. package/templates/current/clean/src/layouts/BreadcrumbBar.vue +27 -0
  167. package/templates/current/clean/src/layouts/SideMenu.vue +119 -0
  168. package/templates/current/clean/src/layouts/TopBar.vue +301 -0
  169. package/templates/current/clean/src/layouts/WorkspaceTabs.vue +44 -0
  170. package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +31 -0
  171. package/templates/current/clean/src/layouts/topBarMenuSearch.ts +21 -0
  172. package/templates/current/clean/src/locales/en-US.ts +55 -0
  173. package/templates/current/clean/src/locales/index.ts +119 -0
  174. package/templates/current/clean/src/locales/messages.spec.ts +23 -0
  175. package/templates/current/clean/src/locales/zh-CN.ts +55 -0
  176. package/templates/current/clean/src/locales/zh-TW.ts +44 -0
  177. package/templates/current/clean/src/main.ts +91 -0
  178. package/templates/current/clean/src/router/bootstrap.ts +76 -0
  179. package/templates/current/clean/src/router/componentRegistry.ts +25 -0
  180. package/templates/current/clean/src/router/dynamicRoutes.spec.ts +47 -0
  181. package/templates/current/clean/src/router/dynamicRoutes.ts +162 -0
  182. package/templates/current/clean/src/router/guards.ts +5 -0
  183. package/templates/current/clean/src/router/queryEncryption.spec.ts +82 -0
  184. package/templates/current/clean/src/router/queryEncryption.ts +133 -0
  185. package/templates/current/clean/src/router/routeQuery.spec.ts +11 -0
  186. package/templates/current/clean/src/router/routeQuery.ts +3 -0
  187. package/templates/current/clean/src/router/runtimeErrorRecovery.spec.ts +161 -0
  188. package/templates/current/clean/src/router/runtimeErrorRecovery.ts +108 -0
  189. package/templates/current/clean/src/router/staticRoutes.ts +63 -0
  190. package/templates/current/clean/src/router/useRouteQueryDefaults.spec.ts +90 -0
  191. package/templates/current/clean/src/router/useRouteQueryDefaults.ts +51 -0
  192. package/templates/current/clean/src/router/useRouteQueryDefaults.types.ts +19 -0
  193. package/templates/current/clean/src/store/index.ts +3 -0
  194. package/templates/current/clean/src/styles/element/index.scss +33 -0
  195. package/templates/current/clean/src/styles/index.css +39 -0
  196. package/templates/current/clean/src/styles/layout.css +115 -0
  197. package/templates/current/clean/src/styles/shell.css +196 -0
  198. package/templates/current/clean/src/styles/source-package-style-compat.css +1 -0
  199. package/templates/current/clean/src/templates/og-form.ts +48 -0
  200. package/templates/current/clean/src/templates/og-table.ts +212 -0
  201. package/templates/current/clean/src/templates/router.ts +51 -0
  202. package/templates/current/clean/src/templates/templates.spec.ts +90 -0
  203. package/templates/current/clean/src/theme/index.ts +7 -0
  204. package/templates/current/clean/src/utils/__tests__/color-mix.spec.ts +39 -0
  205. package/templates/current/clean/src/utils/color-mix.ts +76 -0
  206. package/templates/current/clean/src/utils/permissions.ts +6 -0
  207. package/templates/current/clean/tsconfig.json +40 -0
  208. package/templates/current/clean/tsconfig.node.json +9 -0
  209. package/templates/current/clean/vite.build-policy.ts +405 -0
  210. package/templates/current/clean/vite.config.ts +37 -0
  211. package/templates/current/examples/.codebuddy/AGENTS.md +18 -0
  212. package/templates/current/examples/.codebuddy/rules/01-feature-architecture.md +12 -0
  213. package/templates/current/examples/.codebuddy/rules/02-vue-typescript.md +12 -0
  214. package/templates/current/examples/.codebuddy/rules/03-component-policy.md +30 -0
  215. package/templates/current/examples/.codebuddy/rules/04-api-auth-router.md +12 -0
  216. package/templates/current/examples/.codebuddy/rules/05-style.md +12 -0
  217. package/templates/current/examples/.codebuddy/rules/06-quality.md +12 -0
  218. package/templates/current/examples/.codebuddy/skills/build-admin-feature/SKILL.md +17 -0
  219. package/templates/current/examples/.codebuddy/skills/style-og-origen-ui/SKILL.md +14 -0
  220. package/templates/current/examples/.codebuddy/skills/use-og-dialog/SKILL.md +15 -0
  221. package/templates/current/examples/.codebuddy/skills/use-og-editor/SKILL.md +28 -0
  222. package/templates/current/examples/.codebuddy/skills/use-og-form/SKILL.md +15 -0
  223. package/templates/current/examples/.codebuddy/skills/use-og-form-table/SKILL.md +28 -0
  224. package/templates/current/examples/.codebuddy/skills/use-og-http/SKILL.md +16 -0
  225. package/templates/current/examples/.codebuddy/skills/use-og-router-tabs/SKILL.md +14 -0
  226. package/templates/current/examples/.codebuddy/skills/use-og-search/SKILL.md +17 -0
  227. package/templates/current/examples/.codebuddy/skills/use-og-table/SKILL.md +19 -0
  228. package/templates/current/examples/.codebuddy/skills/use-og-upload/SKILL.md +28 -0
  229. package/templates/current/examples/.codex/AGENTS.md +15 -0
  230. package/templates/current/examples/.codex/rules/01-feature-architecture.md +6 -0
  231. package/templates/current/examples/.codex/rules/02-vue-typescript.md +6 -0
  232. package/templates/current/examples/.codex/rules/03-component-policy.md +24 -0
  233. package/templates/current/examples/.codex/rules/04-api-auth-router.md +6 -0
  234. package/templates/current/examples/.codex/rules/05-style.md +6 -0
  235. package/templates/current/examples/.codex/rules/06-quality.md +6 -0
  236. package/templates/current/examples/.codex/skills/build-admin-feature/SKILL.md +14 -0
  237. package/templates/current/examples/.codex/skills/build-admin-feature/references/component-selection.md +25 -0
  238. package/templates/current/examples/.codex/skills/style-og-origen-ui/SKILL.md +11 -0
  239. package/templates/current/examples/.codex/skills/style-og-origen-ui/agents/openai.yaml +4 -0
  240. package/templates/current/examples/.codex/skills/use-og-dialog/SKILL.md +12 -0
  241. package/templates/current/examples/.codex/skills/use-og-dialog/agents/openai.yaml +4 -0
  242. package/templates/current/examples/.codex/skills/use-og-editor/SKILL.md +25 -0
  243. package/templates/current/examples/.codex/skills/use-og-form/SKILL.md +12 -0
  244. package/templates/current/examples/.codex/skills/use-og-form-table/SKILL.md +25 -0
  245. package/templates/current/examples/.codex/skills/use-og-http/SKILL.md +13 -0
  246. package/templates/current/examples/.codex/skills/use-og-http/agents/openai.yaml +4 -0
  247. package/templates/current/examples/.codex/skills/use-og-router-tabs/SKILL.md +11 -0
  248. package/templates/current/examples/.codex/skills/use-og-search/SKILL.md +14 -0
  249. package/templates/current/examples/.codex/skills/use-og-table/SKILL.md +16 -0
  250. package/templates/current/examples/.codex/skills/use-og-upload/SKILL.md +25 -0
  251. package/templates/current/examples/.cursor/AGENTS.md +18 -0
  252. package/templates/current/examples/.cursor/rules/01-feature-architecture.mdc +12 -0
  253. package/templates/current/examples/.cursor/rules/02-vue-typescript.mdc +12 -0
  254. package/templates/current/examples/.cursor/rules/03-component-policy.mdc +30 -0
  255. package/templates/current/examples/.cursor/rules/04-api-auth-router.mdc +12 -0
  256. package/templates/current/examples/.cursor/rules/05-style.mdc +12 -0
  257. package/templates/current/examples/.cursor/rules/06-quality.mdc +12 -0
  258. package/templates/current/examples/.cursor/skills/build-admin-feature/SKILL.md +14 -0
  259. package/templates/current/examples/.cursor/skills/style-og-origen-ui/SKILL.md +11 -0
  260. package/templates/current/examples/.cursor/skills/use-og-dialog/SKILL.md +12 -0
  261. package/templates/current/examples/.cursor/skills/use-og-editor/SKILL.md +25 -0
  262. package/templates/current/examples/.cursor/skills/use-og-form/SKILL.md +12 -0
  263. package/templates/current/examples/.cursor/skills/use-og-form-table/SKILL.md +25 -0
  264. package/templates/current/examples/.cursor/skills/use-og-http/SKILL.md +13 -0
  265. package/templates/current/examples/.cursor/skills/use-og-router-tabs/SKILL.md +11 -0
  266. package/templates/current/examples/.cursor/skills/use-og-search/SKILL.md +14 -0
  267. package/templates/current/examples/.cursor/skills/use-og-table/SKILL.md +16 -0
  268. package/templates/current/examples/.cursor/skills/use-og-upload/SKILL.md +25 -0
  269. package/templates/current/examples/.env.example +7 -0
  270. package/templates/current/examples/.env.production.example +31 -0
  271. package/templates/current/examples/.qoder/AGENTS.md +15 -0
  272. package/templates/current/examples/.qoder/rules/01-feature-architecture.md +12 -0
  273. package/templates/current/examples/.qoder/rules/02-vue-typescript.md +12 -0
  274. package/templates/current/examples/.qoder/rules/03-component-policy.md +30 -0
  275. package/templates/current/examples/.qoder/rules/04-api-auth-router.md +12 -0
  276. package/templates/current/examples/.qoder/rules/05-style.md +12 -0
  277. package/templates/current/examples/.qoder/rules/06-quality.md +12 -0
  278. package/templates/current/examples/.qoder/skills/build-admin-feature/SKILL.md +14 -0
  279. package/templates/current/examples/.qoder/skills/style-og-origen-ui/SKILL.md +11 -0
  280. package/templates/current/examples/.qoder/skills/use-og-dialog/SKILL.md +12 -0
  281. package/templates/current/examples/.qoder/skills/use-og-editor/SKILL.md +25 -0
  282. package/templates/current/examples/.qoder/skills/use-og-form/SKILL.md +12 -0
  283. package/templates/current/examples/.qoder/skills/use-og-form-table/SKILL.md +25 -0
  284. package/templates/current/examples/.qoder/skills/use-og-http/SKILL.md +13 -0
  285. package/templates/current/examples/.qoder/skills/use-og-router-tabs/SKILL.md +11 -0
  286. package/templates/current/examples/.qoder/skills/use-og-search/SKILL.md +14 -0
  287. package/templates/current/examples/.qoder/skills/use-og-table/SKILL.md +16 -0
  288. package/templates/current/examples/.qoder/skills/use-og-upload/SKILL.md +25 -0
  289. package/templates/current/examples/AGENTS.md +16 -0
  290. package/templates/current/examples/README.md +116 -0
  291. package/templates/current/examples/component-catalog.json +765 -0
  292. package/templates/current/examples/e2e/admin-shell.spec.ts +150 -0
  293. package/templates/current/examples/e2e/demo-shell.spec.ts +328 -0
  294. package/templates/current/examples/evals/component-selection.json +29 -0
  295. package/templates/current/examples/gitignore +3 -0
  296. package/templates/current/examples/index.html +13 -0
  297. package/templates/current/examples/openapi.json +1623 -0
  298. package/templates/current/examples/package.json +65 -0
  299. package/templates/current/examples/playwright.config.ts +31 -0
  300. package/templates/current/examples/playwright.demo.config.ts +25 -0
  301. package/templates/current/examples/recipes/README.md +7 -0
  302. package/templates/current/examples/recipes/remote-crud-dialog-form.json +15 -0
  303. package/templates/current/examples/recipes/remote-crud-dialog-form.vue +66 -0
  304. package/templates/current/examples/scaffold.lock.json +12 -0
  305. package/templates/current/examples/scripts/check-admin-bundle.mjs +214 -0
  306. package/templates/current/examples/scripts/check-admin-scaffold.mjs +168 -0
  307. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +26 -0
  308. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +26 -0
  309. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +26 -0
  310. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +32 -0
  311. package/templates/current/examples/scripts/clean-overlay/src/main.ts +91 -0
  312. package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +25 -0
  313. package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +47 -0
  314. package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +63 -0
  315. package/templates/current/examples/scripts/demo-api.ts +797 -0
  316. package/templates/current/examples/scripts/generate-api.ts +27 -0
  317. package/templates/current/examples/scripts/performance/baselines/bundle-gzip-v2-pre-entry-unification.json +38 -0
  318. package/templates/current/examples/scripts/remove-examples.mjs +54 -0
  319. package/templates/current/examples/src/App.vue +67 -0
  320. package/templates/current/examples/src/api/client.spec.ts +66 -0
  321. package/templates/current/examples/src/api/client.ts +72 -0
  322. package/templates/current/examples/src/api/generated/data-contracts.ts +268 -0
  323. package/templates/current/examples/src/api/generated/http-client.ts +266 -0
  324. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/206/205/345/256/271/346/226/207/347/253/240.ts +147 -0
  325. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/345/256/241/350/256/241.ts +53 -0
  326. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/346/226/207/344/273/266/344/270/212/344/274/240.ts +66 -0
  327. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/347/224/250/346/210/267.ts +171 -0
  328. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/217/234/345/215/225.ts +181 -0
  329. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/247/222/350/211/262.ts +169 -0
  330. package/templates/current/examples/src/api/generated//347/263/273/347/273/237/347/256/241/347/220/206/350/256/242/345/215/225/350/215/211/347/250/277.ts +170 -0
  331. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +98 -0
  332. package/templates/current/examples/src/api/http-adapter.spec.ts +33 -0
  333. package/templates/current/examples/src/api/http-adapter.ts +83 -0
  334. package/templates/current/examples/src/api/index.ts +41 -0
  335. package/templates/current/examples/src/app/createAdminUi.spec.ts +110 -0
  336. package/templates/current/examples/src/app/createAdminUi.ts +78 -0
  337. package/templates/current/examples/src/app/menu.spec.ts +255 -0
  338. package/templates/current/examples/src/app/menu.ts +268 -0
  339. package/templates/current/examples/src/app/menuTypes.ts +17 -0
  340. package/templates/current/examples/src/app/origenUiLocale.spec.ts +14 -0
  341. package/templates/current/examples/src/app/origenUiLocale.ts +65 -0
  342. package/templates/current/examples/src/app/permission.ts +9 -0
  343. package/templates/current/examples/src/app/runtimeConfig.ts +77 -0
  344. package/templates/current/examples/src/demo-api.spec.ts +167 -0
  345. package/templates/current/examples/src/env.d.ts +14 -0
  346. package/templates/current/examples/src/features/appearance/components/ThemePanel.vue +200 -0
  347. package/templates/current/examples/src/features/appearance/composables/useTheme.ts +17 -0
  348. package/templates/current/examples/src/features/appearance/store/theme.ts +140 -0
  349. package/templates/current/examples/src/features/auth/pages/Login.vue +159 -0
  350. package/templates/current/examples/src/features/auth/store/auth.spec.ts +131 -0
  351. package/templates/current/examples/src/features/auth/store/auth.ts +210 -0
  352. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +26 -0
  353. package/templates/current/examples/src/features/errors/pages/NotFound.vue +26 -0
  354. package/templates/current/examples/src/features/errors/pages/ServerError.vue +26 -0
  355. package/templates/current/examples/src/features/errors/pages/error-pages.spec.ts +32 -0
  356. package/templates/current/examples/src/features/feature-composables.spec.ts +208 -0
  357. package/templates/current/examples/src/features/security/components/DevtoolsProtectionOverlay.vue +56 -0
  358. package/templates/current/examples/src/features/security/devtoolsProtection.spec.ts +211 -0
  359. package/templates/current/examples/src/features/security/devtoolsProtection.ts +242 -0
  360. package/templates/current/examples/src/features/shell/components/AdminWatermark.spec.ts +90 -0
  361. package/templates/current/examples/src/features/shell/components/AdminWatermark.vue +47 -0
  362. package/templates/current/examples/src/features/shell/components/RouteProgress.vue +68 -0
  363. package/templates/current/examples/src/features/shell/composables/useRouteProgress.spec.ts +95 -0
  364. package/templates/current/examples/src/features/shell/composables/useRouteProgress.ts +52 -0
  365. package/templates/current/examples/src/features/shell/store/sidebar.ts +55 -0
  366. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +279 -0
  367. package/templates/current/examples/src/features/system/access/api/rbac.spec.ts +72 -0
  368. package/templates/current/examples/src/features/system/access/api/rbac.ts +272 -0
  369. package/templates/current/examples/src/features/system/access/composables/useAuthorizationRefresh.ts +15 -0
  370. package/templates/current/examples/src/features/system/audit/composables/useAuditManagement.ts +117 -0
  371. package/templates/current/examples/src/features/system/audit/pages/AuditList.vue +20 -0
  372. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +189 -0
  373. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +327 -0
  374. package/templates/current/examples/src/features/system/menus/pages/MenuList.vue +49 -0
  375. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +112 -0
  376. package/templates/current/examples/src/features/system/roles/composables/useRoleManagement.ts +198 -0
  377. package/templates/current/examples/src/features/system/roles/pages/RoleList.vue +45 -0
  378. package/templates/current/examples/src/features/system/users/components/UserEditorForm.vue +101 -0
  379. package/templates/current/examples/src/features/system/users/composables/useUserManagement.ts +233 -0
  380. package/templates/current/examples/src/features/system/users/pages/UserList.vue +49 -0
  381. package/templates/current/examples/src/features/workspace/pages/Dashboard.spec.ts +32 -0
  382. package/templates/current/examples/src/features/workspace/pages/Dashboard.vue +297 -0
  383. package/templates/current/examples/src/features/workspace/pages/Empty.vue +18 -0
  384. package/templates/current/examples/src/features/workspace/pages/Profile.vue +183 -0
  385. package/templates/current/examples/src/layouts/AdminLayout.vue +61 -0
  386. package/templates/current/examples/src/layouts/BreadcrumbBar.vue +27 -0
  387. package/templates/current/examples/src/layouts/SideMenu.vue +119 -0
  388. package/templates/current/examples/src/layouts/TopBar.vue +301 -0
  389. package/templates/current/examples/src/layouts/WorkspaceTabs.vue +44 -0
  390. package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +31 -0
  391. package/templates/current/examples/src/layouts/topBarMenuSearch.ts +21 -0
  392. package/templates/current/examples/src/locales/en-US.ts +55 -0
  393. package/templates/current/examples/src/locales/index.ts +119 -0
  394. package/templates/current/examples/src/locales/messages.spec.ts +23 -0
  395. package/templates/current/examples/src/locales/zh-CN.ts +55 -0
  396. package/templates/current/examples/src/locales/zh-TW.ts +44 -0
  397. package/templates/current/examples/src/main.ts +91 -0
  398. package/templates/current/examples/src/router/bootstrap.ts +76 -0
  399. package/templates/current/examples/src/router/componentRegistry.ts +83 -0
  400. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +109 -0
  401. package/templates/current/examples/src/router/dynamicRoutes.ts +162 -0
  402. package/templates/current/examples/src/router/guards.ts +5 -0
  403. package/templates/current/examples/src/router/queryEncryption.spec.ts +82 -0
  404. package/templates/current/examples/src/router/queryEncryption.ts +133 -0
  405. package/templates/current/examples/src/router/routeQuery.spec.ts +11 -0
  406. package/templates/current/examples/src/router/routeQuery.ts +3 -0
  407. package/templates/current/examples/src/router/runtimeErrorRecovery.spec.ts +161 -0
  408. package/templates/current/examples/src/router/runtimeErrorRecovery.ts +108 -0
  409. package/templates/current/examples/src/router/staticRoutes.ts +63 -0
  410. package/templates/current/examples/src/router/useRouteQueryDefaults.spec.ts +90 -0
  411. package/templates/current/examples/src/router/useRouteQueryDefaults.ts +51 -0
  412. package/templates/current/examples/src/router/useRouteQueryDefaults.types.ts +19 -0
  413. package/templates/current/examples/src/store/index.ts +3 -0
  414. package/templates/current/examples/src/styles/element/index.scss +33 -0
  415. package/templates/current/examples/src/styles/index.css +39 -0
  416. package/templates/current/examples/src/styles/layout.css +115 -0
  417. package/templates/current/examples/src/styles/shell.css +196 -0
  418. package/templates/current/examples/src/styles/source-package-style-compat.css +1 -0
  419. package/templates/current/examples/src/templates/og-form.ts +48 -0
  420. package/templates/current/examples/src/templates/og-table.ts +212 -0
  421. package/templates/current/examples/src/templates/router.ts +51 -0
  422. package/templates/current/examples/src/templates/templates.spec.ts +90 -0
  423. package/templates/current/examples/src/theme/index.ts +7 -0
  424. package/templates/current/examples/src/utils/__tests__/color-mix.spec.ts +39 -0
  425. package/templates/current/examples/src/utils/color-mix.ts +76 -0
  426. package/templates/current/examples/src/utils/permissions.ts +6 -0
  427. package/templates/current/examples/tsconfig.json +40 -0
  428. package/templates/current/examples/tsconfig.node.json +9 -0
  429. package/templates/current/examples/vite.build-policy.ts +405 -0
  430. package/templates/current/examples/vite.config.ts +37 -0
@@ -0,0 +1,210 @@
1
+ import type { ApiBusinessError } from '@origen-ui/http'
2
+ import type { Permission } from '@origen-ui/shared'
3
+ import { ApiBusinessError as ApiBusinessErrorClass } from '@origen-ui/http'
4
+ import { hasCodePermission } from '@origen-ui/permission/codes'
5
+ import { defineStore } from 'pinia'
6
+ import { apiClient, tokenManager } from '../../../api/client'
7
+
8
+ export interface AdminUser {
9
+ id: string
10
+ username: string
11
+ displayName: string
12
+ email?: string
13
+ avatar?: string
14
+ }
15
+
16
+ export interface AdminSession {
17
+ token: string
18
+ user: AdminUser
19
+ permissions: string[]
20
+ roleIds: string[]
21
+ authorizationRevision: number
22
+ }
23
+
24
+ export interface LoginCredentials {
25
+ username: string
26
+ password: string
27
+ }
28
+
29
+ interface LoginPayload {
30
+ token?: string
31
+ accessToken?: string
32
+ refreshToken?: string
33
+ user?: unknown
34
+ permissions?: unknown
35
+ roleIds?: unknown
36
+ authorizationRevision?: unknown
37
+ }
38
+
39
+ const PROFILE_KEY = 'og-admin-session-profile'
40
+
41
+ function isRecord(value: unknown): value is Record<string, unknown> {
42
+ return typeof value === 'object' && value !== null && !Array.isArray(value)
43
+ }
44
+
45
+ function readString(value: unknown): string | undefined {
46
+ return typeof value === 'string' && value.trim() ? value : undefined
47
+ }
48
+
49
+ function readStrings(value: unknown): string[] {
50
+ return Array.isArray(value)
51
+ ? value.filter((item): item is string => typeof item === 'string' && item.trim().length > 0)
52
+ : []
53
+ }
54
+
55
+ function normalizeUser(value: unknown, fallbackUsername: string): AdminUser {
56
+ const record = isRecord(value) ? value : {}
57
+ const username = readString(record.username) ?? readString(record.name) ?? fallbackUsername
58
+ return {
59
+ id: readString(record.id) ?? username,
60
+ username,
61
+ displayName:
62
+ readString(record.displayName) ??
63
+ readString(record.nickname) ??
64
+ readString(record.name) ??
65
+ username,
66
+ email: readString(record.email),
67
+ avatar: readString(record.avatar),
68
+ }
69
+ }
70
+
71
+ function readCachedProfile(): Omit<AdminSession, 'token'> | undefined {
72
+ if (typeof localStorage === 'undefined') return undefined
73
+ try {
74
+ const parsed: unknown = JSON.parse(localStorage.getItem(PROFILE_KEY) ?? 'null')
75
+ if (!isRecord(parsed) || !isRecord(parsed.user)) return undefined
76
+ return {
77
+ user: normalizeUser(parsed.user, 'admin'),
78
+ permissions: readStrings(parsed.permissions),
79
+ roleIds: readStrings(parsed.roleIds),
80
+ authorizationRevision:
81
+ typeof parsed.authorizationRevision === 'number' ? parsed.authorizationRevision : 0,
82
+ }
83
+ } catch {
84
+ localStorage.removeItem(PROFILE_KEY)
85
+ return undefined
86
+ }
87
+ }
88
+
89
+ function cacheProfile(session: AdminSession): void {
90
+ if (typeof localStorage !== 'undefined') {
91
+ localStorage.setItem(
92
+ PROFILE_KEY,
93
+ JSON.stringify({
94
+ user: session.user,
95
+ permissions: session.permissions,
96
+ roleIds: session.roleIds,
97
+ authorizationRevision: session.authorizationRevision,
98
+ }),
99
+ )
100
+ }
101
+ }
102
+
103
+ function parseLoginPayload(value: unknown): LoginPayload {
104
+ if (!isRecord(value)) throw new Error('登录响应格式无效')
105
+ return {
106
+ token: readString(value.token),
107
+ accessToken: readString(value.accessToken),
108
+ refreshToken: readString(value.refreshToken),
109
+ user: value.user,
110
+ permissions: value.permissions,
111
+ roleIds: value.roleIds,
112
+ authorizationRevision: value.authorizationRevision,
113
+ }
114
+ }
115
+
116
+ function parseProfile(value: unknown, fallbackUsername: string): Omit<AdminSession, 'token'> {
117
+ const record = isRecord(value) ? value : {}
118
+ const nestedUser = record.user
119
+ return {
120
+ user: normalizeUser(nestedUser ?? record, fallbackUsername),
121
+ permissions: readStrings(
122
+ record.permissions ?? (isRecord(nestedUser) ? nestedUser.permissions : undefined),
123
+ ),
124
+ roleIds: readStrings(record.roleIds ?? (isRecord(nestedUser) ? nestedUser.roleIds : undefined)),
125
+ authorizationRevision:
126
+ typeof record.authorizationRevision === 'number' ? record.authorizationRevision : 0,
127
+ }
128
+ }
129
+
130
+ function errorMessage(error: unknown): string {
131
+ if (error instanceof ApiBusinessErrorClass || error instanceof Error) return error.message
132
+ return '请求失败'
133
+ }
134
+
135
+ export const useAuthStore = defineStore('admin-auth', {
136
+ state: (): { session: AdminSession | null } => ({ session: null }),
137
+ getters: {
138
+ grantedPermissions(): Set<string> {
139
+ return new Set(this.session?.permissions ?? [])
140
+ },
141
+ },
142
+ actions: {
143
+ hasPermission(permission: Permission): boolean {
144
+ return hasCodePermission(this.session?.permissions, permission)
145
+ },
146
+
147
+ async login(credentials: LoginCredentials): Promise<AdminSession> {
148
+ try {
149
+ const response = await apiClient.post<unknown>('/auth/login', credentials, {
150
+ retry: 0,
151
+ silent: true,
152
+ })
153
+ const payload = parseLoginPayload(response)
154
+ const token = payload.accessToken ?? payload.token
155
+ if (!token) throw new Error('登录响应缺少访问令牌')
156
+ const session: AdminSession = {
157
+ token,
158
+ user: normalizeUser(payload.user, credentials.username),
159
+ permissions: readStrings(payload.permissions),
160
+ roleIds: readStrings(payload.roleIds),
161
+ authorizationRevision:
162
+ typeof payload.authorizationRevision === 'number' ? payload.authorizationRevision : 0,
163
+ }
164
+ tokenManager.setTokens(token, payload.refreshToken)
165
+ this.session = session
166
+ cacheProfile(session)
167
+ return session
168
+ } catch (error: unknown) {
169
+ throw new Error(errorMessage(error))
170
+ }
171
+ },
172
+
173
+ logout(): void {
174
+ tokenManager.clear()
175
+ this.session = null
176
+ if (typeof localStorage !== 'undefined') localStorage.removeItem(PROFILE_KEY)
177
+ },
178
+
179
+ async fetchSession(): Promise<AdminSession | null> {
180
+ const token = tokenManager.getAccessToken()
181
+ if (!token) {
182
+ this.session = null
183
+ return null
184
+ }
185
+ const cached = readCachedProfile()
186
+ if (token === 'mock-admin-token' || token === 'mock-token') {
187
+ this.logout()
188
+ return null
189
+ }
190
+ try {
191
+ const profile = parseProfile(
192
+ await apiClient.get<unknown>('/auth/profile', { retry: 0, silent: true }),
193
+ cached?.user.username ?? 'admin',
194
+ )
195
+ this.session = { token, ...profile }
196
+ cacheProfile(this.session)
197
+ return this.session
198
+ } catch {
199
+ this.logout()
200
+ return null
201
+ }
202
+ },
203
+
204
+ async refreshAuthorization(): Promise<AdminSession | null> {
205
+ return this.fetchSession()
206
+ },
207
+ },
208
+ })
209
+
210
+ export type AdminApiBusinessError = ApiBusinessError
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { ElButton, ElResult } from 'element-plus'
3
+ import { useRouter } from 'vue-router'
4
+
5
+ defineOptions({ name: 'ForbiddenPage' })
6
+
7
+ const router = useRouter()
8
+ </script>
9
+
10
+ <template>
11
+ <main class="error-page">
12
+ <ElResult icon="warning" title="403" sub-title="抱歉,你没有访问此页面的权限。">
13
+ <template #extra>
14
+ <ElButton type="primary" @click="router.push('/workspace')"> 回到工作台 </ElButton>
15
+ </template>
16
+ </ElResult>
17
+ </main>
18
+ </template>
19
+
20
+ <style scoped>
21
+ .error-page {
22
+ display: grid;
23
+ min-height: 100vh;
24
+ place-items: center;
25
+ }
26
+ </style>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { ElButton, ElResult } from 'element-plus'
3
+ import { useRouter } from 'vue-router'
4
+
5
+ defineOptions({ name: 'NotFoundPage' })
6
+
7
+ const router = useRouter()
8
+ </script>
9
+
10
+ <template>
11
+ <main class="error-page">
12
+ <ElResult icon="warning" title="404" sub-title="你访问的页面不存在或已经被移除。">
13
+ <template #extra>
14
+ <ElButton type="primary" @click="router.push('/workspace')"> 回到工作台 </ElButton>
15
+ </template>
16
+ </ElResult>
17
+ </main>
18
+ </template>
19
+
20
+ <style scoped>
21
+ .error-page {
22
+ display: grid;
23
+ min-height: 100vh;
24
+ place-items: center;
25
+ }
26
+ </style>
@@ -0,0 +1,26 @@
1
+ <script setup lang="ts">
2
+ import { ElButton, ElResult } from 'element-plus'
3
+ import { useRouter } from 'vue-router'
4
+
5
+ defineOptions({ name: 'ServerErrorPage' })
6
+
7
+ const router = useRouter()
8
+ </script>
9
+
10
+ <template>
11
+ <main class="error-page">
12
+ <ElResult icon="error" title="500" sub-title="服务暂时不可用,请稍后再试。">
13
+ <template #extra>
14
+ <ElButton type="primary" @click="router.push('/workspace')"> 回到工作台 </ElButton>
15
+ </template>
16
+ </ElResult>
17
+ </main>
18
+ </template>
19
+
20
+ <style scoped>
21
+ .error-page {
22
+ display: grid;
23
+ min-height: 100vh;
24
+ place-items: center;
25
+ }
26
+ </style>
@@ -0,0 +1,32 @@
1
+ import { mount } from '@vue/test-utils'
2
+ import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import Forbidden from './Forbidden.vue'
4
+ import NotFound from './NotFound.vue'
5
+ import ServerError from './ServerError.vue'
6
+
7
+ const { push } = vi.hoisted(() => ({
8
+ push: vi.fn(),
9
+ }))
10
+
11
+ vi.mock('vue-router', () => ({
12
+ useRouter: () => ({ push }),
13
+ }))
14
+
15
+ describe('clean error page navigation', () => {
16
+ beforeEach(() => {
17
+ push.mockReset()
18
+ })
19
+
20
+ it.each([
21
+ ['403', Forbidden],
22
+ ['404', NotFound],
23
+ ['500', ServerError],
24
+ ])('returns to the empty workspace from the %s page', async (_status, component) => {
25
+ const wrapper = mount(component)
26
+
27
+ await wrapper.get('button').trigger('click')
28
+
29
+ expect(push).toHaveBeenCalledOnce()
30
+ expect(push).toHaveBeenCalledWith('/workspace')
31
+ })
32
+ })
@@ -0,0 +1,56 @@
1
+ <script setup lang="ts">
2
+ import { nextTick, useTemplateRef, watch } from 'vue'
3
+
4
+ defineOptions({ name: 'DevtoolsProtectionOverlay' })
5
+
6
+ const props = defineProps<{
7
+ blocked: boolean
8
+ }>()
9
+
10
+ const overlay = useTemplateRef<HTMLElement>('overlay')
11
+
12
+ watch(
13
+ () => props.blocked,
14
+ async (blocked) => {
15
+ if (!blocked) return
16
+ await nextTick()
17
+ overlay.value?.focus()
18
+ },
19
+ { immediate: true },
20
+ )
21
+ </script>
22
+
23
+ <template>
24
+ <Teleport to="body">
25
+ <section
26
+ v-if="blocked"
27
+ ref="overlay"
28
+ class="devtools-protection-overlay"
29
+ role="alertdialog"
30
+ aria-label="当前页面暂不可用"
31
+ aria-modal="true"
32
+ tabindex="-1"
33
+ >
34
+ <p>当前页面暂不可用</p>
35
+ </section>
36
+ </Teleport>
37
+ </template>
38
+
39
+ <style scoped>
40
+ .devtools-protection-overlay {
41
+ position: fixed;
42
+ z-index: 2147483647;
43
+ inset: 0;
44
+ display: grid;
45
+ place-items: center;
46
+ margin: 0;
47
+ background: var(--el-bg-color, #fff);
48
+ color: var(--el-text-color-primary, #303133);
49
+ cursor: not-allowed;
50
+ }
51
+
52
+ .devtools-protection-overlay p {
53
+ margin: 0;
54
+ font-size: 16px;
55
+ }
56
+ </style>
@@ -0,0 +1,211 @@
1
+ import { describe, expect, it, vi } from 'vitest'
2
+ import {
3
+ createDevtoolsProtection,
4
+ type DevtoolsDetector,
5
+ type KeyboardEventTarget,
6
+ type StorageLike,
7
+ } from './devtoolsProtection'
8
+
9
+ type TestDetector = DevtoolsDetector & {
10
+ callbacks?: { onClose: () => void, onError?: () => void, onOpen: () => void }
11
+ start: ReturnType<typeof vi.fn>
12
+ }
13
+
14
+ function createDetector(): TestDetector {
15
+ const detector: TestDetector = {
16
+ start: vi.fn(),
17
+ stop: vi.fn(),
18
+ }
19
+ detector.start.mockImplementation((callbacks) => {
20
+ detector.callbacks = callbacks
21
+ })
22
+ return detector
23
+ }
24
+
25
+ function createKeyboardTarget(): KeyboardEventTarget & {
26
+ dispatch: (type: 'keydown' | 'keyup', event: Partial<KeyboardEvent>) => void
27
+ } {
28
+ const listeners = new Map<string, EventListener>()
29
+ return {
30
+ addEventListener(type, listener) {
31
+ listeners.set(type, listener)
32
+ },
33
+ dispatch(type, event) {
34
+ listeners.get(type)?.(event as Event)
35
+ },
36
+ removeEventListener(type) {
37
+ listeners.delete(type)
38
+ },
39
+ }
40
+ }
41
+
42
+ function keyboardEvent(key: string, options: Partial<KeyboardEvent> = {}): Partial<KeyboardEvent> {
43
+ return { isComposing: false, repeat: false, shiftKey: false, key, ...options }
44
+ }
45
+
46
+ describe('devtools protection', () => {
47
+ it('blocks when DevTools opens and unblocks after it closes', () => {
48
+ const detector = createDetector()
49
+ const protection = createDevtoolsProtection({
50
+ detector,
51
+ enabled: true,
52
+ keyboardTarget: createKeyboardTarget(),
53
+ storage: null,
54
+ })
55
+
56
+ protection.start()
57
+ detector.callbacks?.onOpen()
58
+ expect(protection.blocked.value).toBe(true)
59
+
60
+ detector.callbacks?.onClose()
61
+ expect(protection.blocked.value).toBe(false)
62
+ })
63
+
64
+ it('does not initialize the detector outside protected builds', () => {
65
+ const detector = createDetector()
66
+ const protection = createDevtoolsProtection({
67
+ detector,
68
+ enabled: false,
69
+ keyboardTarget: createKeyboardTarget(),
70
+ storage: null,
71
+ })
72
+
73
+ protection.start()
74
+ expect(detector.start).not.toHaveBeenCalled()
75
+ expect(protection.blocked.value).toBe(false)
76
+ })
77
+
78
+ it('blocks when the detector fails to initialize', () => {
79
+ const detector = createDetector()
80
+ const protection = createDevtoolsProtection({
81
+ detector,
82
+ enabled: true,
83
+ keyboardTarget: createKeyboardTarget(),
84
+ storage: null,
85
+ })
86
+
87
+ protection.start()
88
+ detector.callbacks?.onError?.()
89
+
90
+ expect(protection.blocked.value).toBe(true)
91
+ })
92
+
93
+ it('unlocks only when Shift is held while K then M are pressed within two seconds', () => {
94
+ const detector = createDetector()
95
+ const keyboardTarget = createKeyboardTarget()
96
+ let time = 0
97
+ const protection = createDevtoolsProtection({
98
+ detector,
99
+ enabled: true,
100
+ keyboardTarget,
101
+ now: () => time,
102
+ storage: null,
103
+ })
104
+
105
+ protection.start()
106
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true }))
107
+ time = 1_999
108
+ keyboardTarget.dispatch('keydown', keyboardEvent('M', { shiftKey: true }))
109
+
110
+ expect(protection.unlocked.value).toBe(true)
111
+ expect(protection.blocked.value).toBe(false)
112
+ expect(detector.stop).toHaveBeenCalledOnce()
113
+ })
114
+
115
+ it('resets the unlock sequence for invalid input, Shift release, repeated keys, composition, and timeout', () => {
116
+ const detector = createDetector()
117
+ const keyboardTarget = createKeyboardTarget()
118
+ let time = 0
119
+ const protection = createDevtoolsProtection({
120
+ detector,
121
+ enabled: true,
122
+ keyboardTarget,
123
+ now: () => time,
124
+ storage: null,
125
+ })
126
+
127
+ protection.start()
128
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true }))
129
+ keyboardTarget.dispatch('keyup', keyboardEvent('Shift'))
130
+ keyboardTarget.dispatch('keydown', keyboardEvent('M', { shiftKey: true }))
131
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true, repeat: true }))
132
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true, isComposing: true }))
133
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true }))
134
+ time = 2_001
135
+ keyboardTarget.dispatch('keydown', keyboardEvent('M', { shiftKey: true }))
136
+
137
+ expect(protection.unlocked.value).toBe(false)
138
+ expect(detector.stop).not.toHaveBeenCalled()
139
+ })
140
+
141
+ it('persists the unlocked session and falls back to in-memory state if storage fails', () => {
142
+ const storage: StorageLike = {
143
+ getItem: vi.fn(() => null),
144
+ setItem: vi.fn(),
145
+ }
146
+ const detector = createDetector()
147
+ const keyboardTarget = createKeyboardTarget()
148
+ const protection = createDevtoolsProtection({
149
+ detector,
150
+ enabled: true,
151
+ keyboardTarget,
152
+ storage,
153
+ })
154
+
155
+ protection.start()
156
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true }))
157
+ keyboardTarget.dispatch('keydown', keyboardEvent('M', { shiftKey: true }))
158
+ expect(storage.setItem).toHaveBeenCalledWith('og-admin-devtools-unlocked', 'true')
159
+
160
+ const stored = createDevtoolsProtection({
161
+ detector: createDetector(),
162
+ enabled: true,
163
+ keyboardTarget: createKeyboardTarget(),
164
+ storage: { getItem: () => 'true', setItem: vi.fn() },
165
+ })
166
+ stored.start()
167
+ expect(stored.unlocked.value).toBe(true)
168
+
169
+ const unavailableKeyboardTarget = createKeyboardTarget()
170
+ const unavailableWithKeyboard = createDevtoolsProtection({
171
+ detector: createDetector(),
172
+ enabled: true,
173
+ keyboardTarget: unavailableKeyboardTarget,
174
+ storage: {
175
+ getItem: () => {
176
+ throw new Error('unavailable')
177
+ },
178
+ setItem: () => {
179
+ throw new Error('unavailable')
180
+ },
181
+ },
182
+ })
183
+ unavailableWithKeyboard.start()
184
+ unavailableKeyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true }))
185
+ unavailableKeyboardTarget.dispatch('keydown', keyboardEvent('M', { shiftKey: true }))
186
+ expect(unavailableWithKeyboard.unlocked.value).toBe(true)
187
+ })
188
+
189
+ it('starts once and removes listeners and detector state on cleanup', () => {
190
+ const detector = createDetector()
191
+ const keyboardTarget = createKeyboardTarget()
192
+ const protection = createDevtoolsProtection({
193
+ detector,
194
+ enabled: true,
195
+ keyboardTarget,
196
+ storage: null,
197
+ })
198
+
199
+ protection.start()
200
+ protection.start()
201
+ expect(detector.start).toHaveBeenCalledOnce()
202
+
203
+ protection.stop()
204
+ protection.stop()
205
+ expect(detector.stop).toHaveBeenCalledOnce()
206
+
207
+ keyboardTarget.dispatch('keydown', keyboardEvent('K', { shiftKey: true }))
208
+ keyboardTarget.dispatch('keydown', keyboardEvent('M', { shiftKey: true }))
209
+ expect(protection.unlocked.value).toBe(false)
210
+ })
211
+ })