@origen-ui/admin-cli 1.1.0 → 2.0.2

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 (175) hide show
  1. package/README.md +41 -9
  2. package/package.json +26 -2
  3. package/templates/current/clean/.node-version +1 -0
  4. package/templates/current/clean/CHANGELOG.md +125 -0
  5. package/templates/current/clean/README.md +2 -1
  6. package/templates/current/clean/component-catalog.json +58 -17
  7. package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
  8. package/templates/current/clean/e2e/demo-shell.spec.ts +94 -50
  9. package/templates/current/clean/package.json +39 -25
  10. package/templates/current/clean/playwright.config.ts +1 -0
  11. package/templates/current/clean/playwright.demo.config.ts +1 -1
  12. package/templates/current/clean/pnpm-workspace.yaml +18 -0
  13. package/templates/current/clean/scaffold.lock.json +2 -2
  14. package/templates/current/clean/scripts/check-admin-scaffold.mjs +5 -1
  15. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  16. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  17. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  18. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  19. package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
  20. package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  21. package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  22. package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  23. package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
  24. package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  25. package/templates/current/clean/scripts/demo-api.ts +88 -12
  26. package/templates/current/clean/scripts/generate-api.ts +87 -3
  27. package/templates/current/clean/scripts/remove-examples.mjs +4 -4
  28. package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
  29. package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
  30. package/templates/current/clean/src/api/generated/http-client.ts +28 -26
  31. 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 +5 -8
  32. 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 +1 -4
  33. 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 +2 -5
  34. 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 +8 -10
  35. 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 +11 -12
  36. 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 +8 -10
  37. 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 +8 -10
  38. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
  39. package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
  40. package/templates/current/clean/src/app/errorMessage.ts +53 -0
  41. package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
  42. package/templates/current/clean/src/app/menu.spec.ts +39 -0
  43. package/templates/current/clean/src/app/menu.ts +48 -12
  44. package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
  45. package/templates/current/clean/src/demo-api.spec.ts +314 -3
  46. package/templates/current/clean/src/features/auth/pages/Login.vue +9 -2
  47. package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
  48. package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
  49. package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
  50. package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
  51. package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
  52. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
  53. package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
  54. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  55. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  56. package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
  57. package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
  58. package/templates/current/clean/src/layouts/TopBar.vue +37 -6
  59. package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
  60. package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
  61. package/templates/current/clean/src/locales/en-US.json +30 -3
  62. package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
  63. package/templates/current/clean/src/locales/index.ts +39 -26
  64. package/templates/current/clean/src/locales/zh-CN.json +30 -3
  65. package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
  66. package/templates/current/clean/src/locales/zh-TW.json +30 -3
  67. package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
  68. package/templates/current/clean/src/main.ts +23 -14
  69. package/templates/current/clean/src/router/bootstrap.ts +10 -16
  70. package/templates/current/clean/src/router/componentCache.ts +12 -0
  71. package/templates/current/clean/src/router/componentRegistry.ts +2 -13
  72. package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
  73. package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
  74. package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
  75. package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
  76. package/templates/current/clean/src/router/paths.spec.ts +50 -0
  77. package/templates/current/clean/src/router/paths.ts +21 -0
  78. package/templates/current/clean/src/router/queryEncryption.spec.ts +10 -1
  79. package/templates/current/clean/src/router/routeQuery.spec.ts +2 -1
  80. package/templates/current/clean/src/router/routeQuery.ts +4 -1
  81. package/templates/current/clean/src/router/staticRoutes.ts +6 -6
  82. package/templates/current/clean/src/templates/og-table.ts +2 -4
  83. package/templates/current/clean/tsconfig.json +0 -1
  84. package/templates/current/clean/vite.build-policy.ts +55 -8
  85. package/templates/current/clean/vite.config.ts +30 -0
  86. package/templates/current/examples/.node-version +1 -0
  87. package/templates/current/examples/CHANGELOG.md +125 -0
  88. package/templates/current/examples/README.md +2 -1
  89. package/templates/current/examples/component-catalog.json +58 -17
  90. package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
  91. package/templates/current/examples/e2e/demo-shell.spec.ts +94 -50
  92. package/templates/current/examples/package.json +39 -25
  93. package/templates/current/examples/playwright.config.ts +1 -0
  94. package/templates/current/examples/playwright.demo.config.ts +1 -1
  95. package/templates/current/examples/pnpm-workspace.yaml +18 -0
  96. package/templates/current/examples/scaffold.lock.json +2 -2
  97. package/templates/current/examples/scripts/check-admin-scaffold.mjs +5 -1
  98. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  99. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  100. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  101. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  102. package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
  103. package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  104. package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  105. package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  106. package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
  107. package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  108. package/templates/current/examples/scripts/demo-api.ts +88 -12
  109. package/templates/current/examples/scripts/generate-api.ts +87 -3
  110. package/templates/current/examples/scripts/remove-examples.mjs +4 -4
  111. package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
  112. package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
  113. package/templates/current/examples/src/api/generated/http-client.ts +28 -26
  114. 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 +5 -8
  115. 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 +1 -4
  116. 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 +2 -5
  117. 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 +8 -10
  118. 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 +11 -12
  119. 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 +8 -10
  120. 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 +8 -10
  121. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
  122. package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
  123. package/templates/current/examples/src/app/errorMessage.ts +53 -0
  124. package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
  125. package/templates/current/examples/src/app/menu.spec.ts +39 -0
  126. package/templates/current/examples/src/app/menu.ts +48 -12
  127. package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
  128. package/templates/current/examples/src/demo-api.spec.ts +314 -3
  129. package/templates/current/examples/src/features/auth/pages/Login.vue +9 -2
  130. package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
  131. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
  132. package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
  133. package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
  134. package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
  135. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
  136. package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
  137. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  138. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  139. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
  140. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
  141. package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
  142. package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
  143. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
  144. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
  145. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
  146. package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
  147. package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
  148. package/templates/current/examples/src/layouts/TopBar.vue +37 -6
  149. package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
  150. package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
  151. package/templates/current/examples/src/locales/en-US.json +30 -3
  152. package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
  153. package/templates/current/examples/src/locales/index.ts +39 -26
  154. package/templates/current/examples/src/locales/zh-CN.json +30 -3
  155. package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
  156. package/templates/current/examples/src/locales/zh-TW.json +30 -3
  157. package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
  158. package/templates/current/examples/src/main.ts +24 -22
  159. package/templates/current/examples/src/router/bootstrap.ts +10 -16
  160. package/templates/current/examples/src/router/componentCache.ts +18 -0
  161. package/templates/current/examples/src/router/componentRegistry.ts +1 -18
  162. package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
  163. package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
  164. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
  165. package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
  166. package/templates/current/examples/src/router/paths.spec.ts +50 -0
  167. package/templates/current/examples/src/router/paths.ts +21 -0
  168. package/templates/current/examples/src/router/queryEncryption.spec.ts +10 -1
  169. package/templates/current/examples/src/router/routeQuery.spec.ts +2 -1
  170. package/templates/current/examples/src/router/routeQuery.ts +4 -1
  171. package/templates/current/examples/src/router/staticRoutes.ts +3 -3
  172. package/templates/current/examples/src/templates/og-table.ts +2 -4
  173. package/templates/current/examples/tsconfig.json +0 -1
  174. package/templates/current/examples/vite.build-policy.ts +55 -8
  175. package/templates/current/examples/vite.config.ts +30 -0
@@ -31,6 +31,16 @@ describe('parseMenuResponse', () => {
31
31
  ])
32
32
  })
33
33
 
34
+ it('requires titleKey for array and items system menu responses', () => {
35
+ const menu = { code: 'dashboard', path: '/dashboard', title: 'Dashboard' }
36
+ expect(() => parseMenuResponse([menu], { requireTitleKey: true })).toThrow(
37
+ 'Missing RBAC menu title key',
38
+ )
39
+ expect(() => parseMenuResponse({ items: [menu] }, { requireTitleKey: true })).toThrow(
40
+ 'Missing RBAC menu title key',
41
+ )
42
+ })
43
+
34
44
  it('maps a paged RBAC response into runtime menu nodes', () => {
35
45
  const menus = parseMenuResponse({
36
46
  list: [
@@ -135,6 +145,33 @@ describe('parseMenuResponse', () => {
135
145
  ])
136
146
  })
137
147
 
148
+ it('requires titleKey when parsing paginated system menus', () => {
149
+ expect(() =>
150
+ parseMenuResponse(
151
+ {
152
+ list: [
153
+ {
154
+ id: 'users',
155
+ kind: 'page',
156
+ code: 'users',
157
+ title: 'Users',
158
+ path: '/users',
159
+ order: 1,
160
+ status: 'active',
161
+ visible: true,
162
+ cache: false,
163
+ tabHidden: false,
164
+ },
165
+ ],
166
+ total: 1,
167
+ page: 1,
168
+ pageSize: 20,
169
+ },
170
+ { requireTitleKey: true },
171
+ ),
172
+ ).toThrow('Missing RBAC menu title key')
173
+ })
174
+
138
175
  it('rejects malformed paged menu payloads', () => {
139
176
  expect(() => parseMenuResponse({ list: {}, total: 1, page: 1, pageSize: 20 })).toThrow(
140
177
  'Menu page response',
@@ -172,6 +209,7 @@ describe('parseMenuResponse', () => {
172
209
  kind: 'directory',
173
210
  code: 'system',
174
211
  title: 'System',
212
+ titleKey: 'menu.system',
175
213
  path: '/system',
176
214
  order: 20,
177
215
  status: 'active',
@@ -192,6 +230,7 @@ describe('parseMenuResponse', () => {
192
230
  kind: 'page',
193
231
  code: 'users',
194
232
  title: 'Users',
233
+ titleKey: 'menu.users',
195
234
  path: 'users',
196
235
  componentKey: 'user-list',
197
236
  order: 10,
@@ -1,5 +1,6 @@
1
1
  import type { BackendMenuNode } from './menuTypes'
2
2
  import { apiClient } from '../api/client'
3
+ import { readHostInjection } from './embedded'
3
4
 
4
5
  function isRecord(value: unknown): value is Record<string, unknown> {
5
6
  return typeof value === 'object' && value !== null && !Array.isArray(value)
@@ -30,7 +31,7 @@ function readMenuPageResponse(value: unknown): MenuPageResponse | undefined {
30
31
  return { list: value.list, total: value.total, page: value.page, pageSize: value.pageSize }
31
32
  }
32
33
 
33
- function readNode(value: unknown, index: string): BackendMenuNode {
34
+ function readNode(value: unknown, index: string, requireTitleKey = false): BackendMenuNode {
34
35
  if (!isRecord(value)) throw new TypeError(`Invalid menu node at ${index}`)
35
36
  if (
36
37
  typeof value.code !== 'string' ||
@@ -39,6 +40,8 @@ function readNode(value: unknown, index: string): BackendMenuNode {
39
40
  ) {
40
41
  throw new TypeError(`Invalid menu node fields at ${index}`)
41
42
  }
43
+ if (requireTitleKey && !(typeof value.titleKey === 'string' && value.titleKey))
44
+ throw new TypeError(`Missing RBAC menu title key at ${index}`)
42
45
  return {
43
46
  code: value.code,
44
47
  path: value.path,
@@ -58,7 +61,7 @@ function readNode(value: unknown, index: string): BackendMenuNode {
58
61
  redirect: typeof value.redirect === 'string' ? value.redirect : undefined,
59
62
  children: Array.isArray(value.children)
60
63
  ? value.children.map((child, childIndex) =>
61
- readNode(child, `${index}.children[${childIndex}]`),
64
+ readNode(child, `${index}.children[${childIndex}]`, requireTitleKey),
62
65
  )
63
66
  : undefined,
64
67
  }
@@ -86,7 +89,11 @@ interface RbacMenuNode {
86
89
  children?: readonly RbacMenuNode[]
87
90
  }
88
91
 
89
- function readRbacMenuNode(value: unknown, index: string): RbacMenuNode {
92
+ function readRbacMenuNode(
93
+ value: unknown,
94
+ index: string,
95
+ requireTitleKey = false,
96
+ ): RbacMenuNode {
90
97
  if (!isRecord(value)) throw new TypeError(`Invalid RBAC menu at ${index}`)
91
98
 
92
99
  const kind = value.kind
@@ -113,6 +120,8 @@ function readRbacMenuNode(value: unknown, index: string): RbacMenuNode {
113
120
  throw new TypeError(`Invalid RBAC menu path at ${index}`)
114
121
  if (value.children !== undefined && !Array.isArray(value.children))
115
122
  throw new TypeError(`Invalid RBAC menu children at ${index}`)
123
+ if (requireTitleKey && kind !== 'button' && !(typeof value.titleKey === 'string' && value.titleKey))
124
+ throw new TypeError(`Missing RBAC menu title key at ${index}`)
116
125
 
117
126
  return {
118
127
  id: value.id,
@@ -133,12 +142,15 @@ function readRbacMenuNode(value: unknown, index: string): RbacMenuNode {
133
142
  tabHidden: value.tabHidden,
134
143
  redirect: typeof value.redirect === 'string' ? value.redirect : undefined,
135
144
  children: value.children?.map((child, childIndex) =>
136
- readRbacMenuNode(child, `${index}.children[${childIndex}]`),
145
+ readRbacMenuNode(child, `${index}.children[${childIndex}]`, requireTitleKey),
137
146
  ),
138
147
  }
139
148
  }
140
149
 
141
- function parseRbacMenuPage(value: Record<string, unknown>): readonly BackendMenuNode[] {
150
+ function parseRbacMenuPage(
151
+ value: Record<string, unknown>,
152
+ options: { requireTitleKey?: boolean } = {},
153
+ ): readonly BackendMenuNode[] {
142
154
  if (
143
155
  !Array.isArray(value.list) ||
144
156
  typeof value.total !== 'number' ||
@@ -157,7 +169,9 @@ function parseRbacMenuPage(value: Record<string, unknown>): readonly BackendMenu
157
169
  }
158
170
  }
159
171
  collect(
160
- value.list.map((row, index) => readRbacMenuNode(row, `menus.list[${index}]`)),
172
+ value.list.map((row, index) =>
173
+ readRbacMenuNode(row, `menus.list[${index}]`, options.requireTitleKey === true),
174
+ ),
161
175
  undefined,
162
176
  )
163
177
 
@@ -209,8 +223,11 @@ function parseRbacMenuPage(value: Record<string, unknown>): readonly BackendMenu
209
223
  })
210
224
  }
211
225
 
212
- export function parseMenuResponse(value: unknown): readonly BackendMenuNode[] {
213
- if (isRecord(value) && Object.hasOwn(value, 'list')) return parseRbacMenuPage(value)
226
+ export function parseMenuResponse(
227
+ value: unknown,
228
+ options: { requireTitleKey?: boolean } = {},
229
+ ): readonly BackendMenuNode[] {
230
+ if (isRecord(value) && Object.hasOwn(value, 'list')) return parseRbacMenuPage(value, options)
214
231
  const rows = Array.isArray(value)
215
232
  ? value
216
233
  : isRecord(value) && Array.isArray(value.items)
@@ -218,7 +235,9 @@ export function parseMenuResponse(value: unknown): readonly BackendMenuNode[] {
218
235
  : undefined
219
236
  if (!rows)
220
237
  throw new TypeError('Menu response must be an array, contain items, or be a menu page.')
221
- return rows.map((row, index) => readNode(row, `menus[${index}]`))
238
+ return rows.map((row, index) =>
239
+ readNode(row, `menus[${index}]`, options.requireTitleKey === true),
240
+ )
222
241
  }
223
242
 
224
243
  export async function fetchMenus(
@@ -233,7 +252,7 @@ export async function fetchMenus(
233
252
  })
234
253
  const firstResponse = await request(1, 100)
235
254
  const firstPage = readMenuPageResponse(firstResponse)
236
- if (!firstPage) return parseMenuResponse(firstResponse)
255
+ if (!firstPage) return parseMenuResponse(firstResponse, { requireTitleKey: true })
237
256
  if (firstPage.page !== 1)
238
257
  throw new TypeError('Menu response did not return the requested first page.')
239
258
  if (
@@ -245,7 +264,7 @@ export async function fetchMenus(
245
264
  }
246
265
 
247
266
  const pageCount = Math.ceil(firstPage.total / firstPage.pageSize)
248
- if (pageCount <= 1) return parseMenuResponse(firstResponse)
267
+ if (pageCount <= 1) return parseMenuResponse(firstResponse, { requireTitleKey: true })
249
268
 
250
269
  const responses = await Promise.all(
251
270
  Array.from({ length: pageCount - 1 }, (_, index) => request(index + 2, firstPage.pageSize)),
@@ -268,5 +287,22 @@ export async function fetchMenus(
268
287
  return page
269
288
  })
270
289
  const rows = [...firstPage.list, ...pages.flatMap((page) => page.list)]
271
- return parseMenuResponse({ list: rows, total: rows.length, page: 1, pageSize: rows.length || 1 })
290
+ return parseMenuResponse(
291
+ { list: rows, total: rows.length, page: 1, pageSize: rows.length || 1 },
292
+ { requireTitleKey: true },
293
+ )
294
+ }
295
+
296
+ /**
297
+ * 嵌入模式菜单装载:优先取主壳聚合下发的 backendMenus。主壳注入属于不可信
298
+ * 输入,与 fetchMenus 走同一套严格解析,畸形数据在进入 routeTransformer 前
299
+ * 统一失败,而不是静默生成错误路由;主壳未下发时回落到经主壳网关拉取自身
300
+ * 菜单,独立模式不受影响。
301
+ */
302
+ export async function loadMenusFromHost(): Promise<BackendMenuNode[]> {
303
+ const menus = readHostInjection().backendMenus
304
+ if (Array.isArray(menus) && menus.length > 0) {
305
+ return [...parseMenuResponse(menus)]
306
+ }
307
+ return [...(await fetchMenus())]
272
308
  }
@@ -60,7 +60,7 @@ export const appRuntimeConfig: AdminRuntimeConfig = {
60
60
  enabled: true,
61
61
  key: 'og-admin-workspace',
62
62
  scope: 'admin',
63
- version: 2,
63
+ version: 4,
64
64
  },
65
65
  },
66
66
  origenUi: {
@@ -32,7 +32,7 @@ describe('admin demo API', () => {
32
32
  api.handle({
33
33
  method: 'POST',
34
34
  path: '/api/auth/login',
35
- body: { username: 'admin', password: 'wrong' },
35
+ body: { username: 'demo-admin', password: 'wrong' },
36
36
  }).body,
37
37
  ).toMatchObject({ code: 40101, data: null })
38
38
  const login = data<{
@@ -43,7 +43,7 @@ describe('admin demo API', () => {
43
43
  api.handle({
44
44
  method: 'POST',
45
45
  path: '/auth/login',
46
- body: { username: 'admin', password: 'admin123' },
46
+ body: { username: 'demo-admin', password: 'demo-password' },
47
47
  }),
48
48
  )
49
49
  expect(login.accessToken).toBe('demo-admin-token')
@@ -52,7 +52,7 @@ describe('admin demo API', () => {
52
52
  expect(api.handle({ method: 'GET', path: '/auth/profile' }).body.code).toBe(40101)
53
53
  expect(
54
54
  data<{ user: { username: string } }>(request(api, 'GET', '/auth/profile')).user.username,
55
- ).toBe('admin')
55
+ ).toBe('demo-admin')
56
56
  expect(
57
57
  data<{ token: string }>(
58
58
  api.handle({
@@ -165,3 +165,314 @@ describe('admin demo API', () => {
165
165
  expect(data<{ total: number }>(request(restarted, 'GET', '/system/roles')).total).toBe(2)
166
166
  })
167
167
  })
168
+
169
+ describe('demo menu guardrails', () => {
170
+ it('rejects button menus whose parent is missing or not a page', () => {
171
+ const api = createDemoApi()
172
+ expect(
173
+ request(api, 'POST', '/system/menus', {
174
+ kind: 'button',
175
+ code: 'ghost-button',
176
+ title: 'Ghost',
177
+ permission: 'system:demo:ghost',
178
+ }).body.code,
179
+ ).toBe(40001)
180
+ expect(
181
+ request(api, 'POST', '/system/menus', {
182
+ kind: 'button',
183
+ parentId: 'menu-system',
184
+ code: 'ghost-button',
185
+ title: 'Ghost',
186
+ permission: 'system:demo:ghost',
187
+ }).body.code,
188
+ ).toBe(40001)
189
+ expect(
190
+ request(api, 'POST', '/system/menus', {
191
+ kind: 'button',
192
+ parentId: 'menu-nowhere',
193
+ code: 'ghost-button',
194
+ title: 'Ghost',
195
+ permission: 'system:demo:ghost',
196
+ }).body.code,
197
+ ).toBe(40001)
198
+ })
199
+
200
+ it('creates button menus under page parents, persists titleKey, and enforces version races', () => {
201
+ const api = createDemoApi()
202
+ const created = data<{ id: string, version: number, titleKey?: string }>(
203
+ request(api, 'POST', '/system/menus', {
204
+ kind: 'button',
205
+ parentId: 'menu-dashboard',
206
+ code: 'dashboard-export',
207
+ title: 'Export',
208
+ permission: 'workspace:dashboard:export',
209
+ titleKey: 'menus.export.title',
210
+ }),
211
+ )
212
+ expect(created.version).toBe(1)
213
+ expect(created.titleKey).toBe('menus.export.title')
214
+ const stale = request(api, 'PUT', `/system/menus/${created.id}`, {
215
+ kind: 'button',
216
+ parentId: 'menu-dashboard',
217
+ code: 'dashboard-export',
218
+ title: 'Export v2',
219
+ permission: 'workspace:dashboard:export',
220
+ version: 0,
221
+ })
222
+ expect(stale.body.code).toBe(40901)
223
+ const fresh = data<{ version: number }>(
224
+ request(api, 'PUT', `/system/menus/${created.id}`, {
225
+ kind: 'button',
226
+ parentId: 'menu-dashboard',
227
+ code: 'dashboard-export',
228
+ title: 'Export v2',
229
+ permission: 'workspace:dashboard:export',
230
+ version: 1,
231
+ }),
232
+ )
233
+ expect(fresh.version).toBe(2)
234
+ })
235
+
236
+ it('rejects page and directory children under button menus on POST and PUT', () => {
237
+ const api = createDemoApi()
238
+ const button = data<{ id: string }>(
239
+ request(api, 'POST', '/system/menus', {
240
+ kind: 'button',
241
+ parentId: 'menu-dashboard',
242
+ code: 'dashboard-export-child-test',
243
+ title: 'Export',
244
+ permission: 'workspace:dashboard:export',
245
+ }),
246
+ )
247
+
248
+ for (const kind of ['page', 'directory'] as const) {
249
+ expect(
250
+ request(api, 'POST', '/system/menus', {
251
+ kind,
252
+ parentId: button.id,
253
+ code: `invalid-${kind}-post`,
254
+ title: `Invalid ${kind}`,
255
+ }).body.code,
256
+ ).toBe(40001)
257
+ }
258
+
259
+ const page = data<{ id: string }>(
260
+ request(api, 'POST', '/system/menus', {
261
+ kind: 'page',
262
+ code: 'page-for-button-parent-test',
263
+ title: 'Page for button parent test',
264
+ path: '/page-for-button-parent-test',
265
+ componentKey: 'dashboard',
266
+ }),
267
+ )
268
+ const directory = data<{ id: string }>(
269
+ request(api, 'POST', '/system/menus', {
270
+ kind: 'directory',
271
+ code: 'directory-for-button-parent-test',
272
+ title: 'Directory for button parent test',
273
+ }),
274
+ )
275
+
276
+ for (const menu of [page, directory]) {
277
+ expect(
278
+ request(api, 'PUT', `/system/menus/${menu.id}`, {
279
+ kind: menu === page ? 'page' : 'directory',
280
+ parentId: button.id,
281
+ }).body.code,
282
+ ).toBe(40001)
283
+ }
284
+ })
285
+
286
+ it('rejects turning a menu with page or directory children into a button', () => {
287
+ const api = createDemoApi()
288
+ const page = data<{ id: string }>(
289
+ request(api, 'POST', '/system/menus', {
290
+ kind: 'page',
291
+ code: 'page-with-child-test',
292
+ title: 'Page with child',
293
+ path: '/page-with-child-test',
294
+ componentKey: 'dashboard',
295
+ }),
296
+ )
297
+ const directory = data<{ id: string }>(
298
+ request(api, 'POST', '/system/menus', {
299
+ kind: 'directory',
300
+ code: 'directory-with-child-test',
301
+ title: 'Directory with child',
302
+ }),
303
+ )
304
+
305
+ for (const [menu, childKind] of [
306
+ [page, 'page'],
307
+ [directory, 'directory'],
308
+ ] as const) {
309
+ data(
310
+ request(api, 'POST', '/system/menus', {
311
+ kind: childKind,
312
+ parentId: menu.id,
313
+ code: `${childKind}-child-${menu.id}`,
314
+ title: `${childKind} child`,
315
+ ...(childKind === 'page'
316
+ ? { path: `/${childKind}-child-${menu.id}`, componentKey: 'dashboard' }
317
+ : {}),
318
+ }),
319
+ )
320
+
321
+ expect(
322
+ request(api, 'PUT', `/system/menus/${menu.id}`, {
323
+ kind: 'button',
324
+ parentId: 'menu-dashboard',
325
+ code: `${childKind}-with-child-button-${menu.id}`,
326
+ title: `${childKind} button`,
327
+ permission: 'workspace:dashboard:export',
328
+ }).body.code,
329
+ ).toBe(40001)
330
+ }
331
+ })
332
+
333
+ it('keeps page titleKey through the runtime menu payload', () => {
334
+ const api = createDemoApi()
335
+ data(
336
+ request(api, 'POST', '/system/menus', {
337
+ kind: 'page',
338
+ code: 'coverage-page',
339
+ title: 'Coverage',
340
+ path: '/coverage',
341
+ componentKey: 'dashboard',
342
+ titleKey: 'menus.coverage.title',
343
+ }),
344
+ )
345
+ const runtime = data<{ list: Array<{ code: string, titleKey?: string }> }>(
346
+ request(api, 'GET', '/system/menus', undefined, 'page=1&pageSize=50'),
347
+ )
348
+ expect(
349
+ runtime.list.some(
350
+ (menu) => menu.code === 'coverage-page' && menu.titleKey === 'menus.coverage.title',
351
+ ),
352
+ ).toBe(true)
353
+ })
354
+
355
+ it('rejects structural menu writes: ghost parents, self or descendant parents, empty fields', () => {
356
+ const api = createDemoApi()
357
+ expect(
358
+ request(api, 'POST', '/system/menus', {
359
+ kind: 'page',
360
+ code: 'orphan',
361
+ title: 'Orphan',
362
+ path: '/orphan',
363
+ parentId: 'menu-nowhere',
364
+ }).body.code,
365
+ ).toBe(40001)
366
+ expect(
367
+ request(api, 'POST', '/system/menus', { kind: 'page', code: '', title: 'NoCode' })
368
+ .body.code,
369
+ ).toBe(40001)
370
+ const page = data<{ id: string }>(
371
+ request(api, 'POST', '/system/menus', {
372
+ kind: 'page',
373
+ code: 'self-test',
374
+ title: 'Self',
375
+ path: '/self-test',
376
+ componentKey: 'dashboard',
377
+ }),
378
+ )
379
+ expect(
380
+ request(api, 'PUT', `/system/menus/${page.id}`, {
381
+ kind: 'page',
382
+ parentId: page.id,
383
+ code: 'self-test',
384
+ title: 'Self',
385
+ path: '/self-test',
386
+ }).body.code,
387
+ ).toBe(40001)
388
+ const child = data<{ id: string }>(
389
+ request(api, 'POST', '/system/menus', {
390
+ kind: 'page',
391
+ code: 'child-page',
392
+ title: 'Child',
393
+ path: 'child',
394
+ parentId: page.id,
395
+ componentKey: 'dashboard',
396
+ }),
397
+ )
398
+ expect(
399
+ request(api, 'PUT', `/system/menus/${page.id}`, {
400
+ kind: 'page',
401
+ parentId: child.id,
402
+ code: 'self-test',
403
+ title: 'Self',
404
+ path: '/self-test',
405
+ }).body.code,
406
+ ).toBe(40001)
407
+ })
408
+
409
+ it('rejects kind conversions that orphan button children and tolerates legacy clients without version', () => {
410
+ const api = createDemoApi()
411
+ const page = data<{ id: string }>(
412
+ request(api, 'POST', '/system/menus', {
413
+ kind: 'page',
414
+ code: 'with-buttons',
415
+ title: 'Host',
416
+ path: '/with-buttons',
417
+ componentKey: 'dashboard',
418
+ }),
419
+ )
420
+ data(
421
+ request(api, 'POST', '/system/menus', {
422
+ kind: 'button',
423
+ parentId: page.id,
424
+ code: 'host-write',
425
+ title: 'Write',
426
+ permission: 'system:demo:write',
427
+ }),
428
+ )
429
+ expect(
430
+ request(api, 'PUT', `/system/menus/${page.id}`, {
431
+ kind: 'directory',
432
+ code: 'with-buttons',
433
+ title: 'Host',
434
+ }).body.code,
435
+ ).toBe(40001)
436
+ const legacy = data<{ version: number }>(
437
+ request(api, 'PUT', `/system/menus/${page.id}`, {
438
+ kind: 'page',
439
+ code: 'with-buttons',
440
+ title: 'Host v2',
441
+ path: '/with-buttons',
442
+ }),
443
+ )
444
+ expect(legacy.version).toBeGreaterThan(1)
445
+ expect(
446
+ request(api, 'PUT', `/system/menus/${page.id}`, {
447
+ kind: 'page',
448
+ code: 'with-buttons',
449
+ title: 'Host v3',
450
+ path: '/with-buttons',
451
+ version: 'nope',
452
+ }).body.code,
453
+ ).toBe(40901)
454
+ })
455
+
456
+ it('bumps version on status changes so open editors conflict instead of reverting', () => {
457
+ const api = createDemoApi()
458
+ const created = data<{ id: string, version: number }>(
459
+ request(api, 'POST', '/system/menus', {
460
+ kind: 'page',
461
+ code: 'status-bump',
462
+ title: 'Status',
463
+ path: '/status-bump',
464
+ componentKey: 'dashboard',
465
+ }),
466
+ )
467
+ data(request(api, 'PATCH', '/system/menus/status', { ids: [created.id], status: 'suspended' }))
468
+ expect(
469
+ request(api, 'PUT', `/system/menus/${created.id}`, {
470
+ kind: 'page',
471
+ code: 'status-bump',
472
+ title: 'Status v2',
473
+ path: '/status-bump',
474
+ version: created.version,
475
+ }).body.code,
476
+ ).toBe(40901)
477
+ })
478
+ })
@@ -1,8 +1,11 @@
1
1
  <script setup lang="ts">
2
+ import { getRouteQueryString } from '@origen-ui/router'
2
3
  import { ElAlert, ElButton, ElCard, ElForm, ElFormItem, ElInput } from 'element-plus'
3
4
  import { reactive, shallowRef } from 'vue'
4
5
  import { useI18n } from 'vue-i18n'
5
6
  import { useRoute, useRouter } from 'vue-router'
7
+ import { translateAdminError } from '../../../app/errorMessage'
8
+ import { HOME_ROUTE } from '../../../router/paths'
6
9
  import { useAuthStore } from '../store/auth'
7
10
 
8
11
  defineOptions({ name: 'LoginPage' })
@@ -24,10 +27,14 @@ async function submit(): Promise<void> {
24
27
  errorMessage.value = ''
25
28
  try {
26
29
  await auth.login(form)
27
- const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/dashboard'
30
+ const redirect = getRouteQueryString(route.query.redirect) ?? HOME_ROUTE
28
31
  await router.push(redirect)
29
32
  } catch (error: unknown) {
30
- errorMessage.value = error instanceof Error ? error.message : t('auth.loginFailed')
33
+ errorMessage.value = translateAdminError(error, {
34
+ domain: 'auth',
35
+ fallbackKey: 'auth.loginFailed',
36
+ fallback: t('auth.loginFailed'),
37
+ })
31
38
  } finally {
32
39
  loading.value = false
33
40
  }
@@ -1,19 +1,9 @@
1
1
  import type { ApiBusinessError } from '@origen-ui/http'
2
2
  import type { Permission } from '@origen-ui/shared'
3
- import type { AdminMessageKey } from '../../../locales'
4
- import { ApiBusinessError as ApiBusinessErrorClass } from '@origen-ui/http'
5
3
  import { hasCodePermission } from '@origen-ui/permission/codes'
6
4
  import { defineStore } from 'pinia'
7
5
  import { apiClient, tokenManager } from '../../../api/client'
8
- import { getAdminI18n } from '../../../locales'
9
-
10
- function translate(key: string): string {
11
- const global = getAdminI18n()?.global as unknown as
12
- | { te?: (key: string) => boolean, t: (key: string) => string } |
13
- undefined
14
- if (!global) return key
15
- return global.te?.(key) ? global.t(key as AdminMessageKey) : key
16
- }
6
+ import { adminErrorKey, createAdminError } from '../../../app/errorMessage'
17
7
 
18
8
  export interface AdminUser {
19
9
  id: string
@@ -111,7 +101,7 @@ function cacheProfile(session: AdminSession): void {
111
101
  }
112
102
 
113
103
  function parseLoginPayload(value: unknown): LoginPayload {
114
- if (!isRecord(value)) throw new Error(translate('auth.invalidResponse'))
104
+ if (!isRecord(value)) throw createAdminError('auth.invalidResponse')
115
105
  return {
116
106
  token: readString(value.token),
117
107
  accessToken: readString(value.accessToken),
@@ -137,11 +127,6 @@ function parseProfile(value: unknown, fallbackUsername: string): Omit<AdminSessi
137
127
  }
138
128
  }
139
129
 
140
- function errorMessage(error: unknown): string {
141
- if (error instanceof ApiBusinessErrorClass || error instanceof Error) return error.message
142
- return translate('auth.requestFailed')
143
- }
144
-
145
130
  export const useAuthStore = defineStore('admin-auth', {
146
131
  state: (): { session: AdminSession | null } => ({ session: null }),
147
132
  getters: {
@@ -162,7 +147,7 @@ export const useAuthStore = defineStore('admin-auth', {
162
147
  })
163
148
  const payload = parseLoginPayload(response)
164
149
  const token = payload.accessToken ?? payload.token
165
- if (!token) throw new Error(translate('auth.missingToken'))
150
+ if (!token) throw createAdminError('auth.missingToken')
166
151
  const session: AdminSession = {
167
152
  token,
168
153
  user: normalizeUser(payload.user, credentials.username),
@@ -176,7 +161,9 @@ export const useAuthStore = defineStore('admin-auth', {
176
161
  cacheProfile(session)
177
162
  return session
178
163
  } catch (error: unknown) {
179
- throw new Error(errorMessage(error))
164
+ const key = adminErrorKey(error, { domain: 'auth', fallbackKey: 'auth.loginFailed' })
165
+ console.error('[admin] login failed', error)
166
+ throw createAdminError(key, error)
180
167
  }
181
168
  },
182
169
 
@@ -1,17 +1,22 @@
1
1
  <script setup lang="ts">
2
2
  import { ElButton, ElResult } from 'element-plus'
3
+ import { useI18n } from 'vue-i18n'
3
4
  import { useRouter } from 'vue-router'
5
+ import { HOME_ROUTE } from '../../../router/paths'
4
6
 
5
7
  defineOptions({ name: 'ForbiddenPage' })
6
8
 
7
9
  const router = useRouter()
10
+ const { t } = useI18n()
8
11
  </script>
9
12
 
10
13
  <template>
11
14
  <main class="error-page">
12
- <ElResult icon="warning" title="403" sub-title="抱歉,你没有访问此页面的权限。">
15
+ <ElResult icon="warning" :title="t('errors.forbidden.code')" :sub-title="t('errors.forbidden.message')">
13
16
  <template #extra>
14
- <ElButton type="primary" @click="router.push('/workspace')"> 回到工作台 </ElButton>
17
+ <ElButton type="primary" @click="router.push(HOME_ROUTE)">
18
+ {{ t('errors.forbidden.backHome') }}
19
+ </ElButton>
15
20
  </template>
16
21
  </ElResult>
17
22
  </main>