@origen-ui/admin-cli 1.1.0 → 2.0.1

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 (159) hide show
  1. package/README.md +11 -7
  2. package/package.json +18 -2
  3. package/templates/current/clean/CHANGELOG.md +103 -0
  4. package/templates/current/clean/component-catalog.json +58 -17
  5. package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
  6. package/templates/current/clean/e2e/demo-shell.spec.ts +90 -46
  7. package/templates/current/clean/package.json +35 -21
  8. package/templates/current/clean/playwright.config.ts +1 -0
  9. package/templates/current/clean/playwright.demo.config.ts +1 -1
  10. package/templates/current/clean/scaffold.lock.json +2 -2
  11. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  12. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  13. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  14. package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  15. package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
  16. package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  17. package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  18. package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  19. package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
  20. package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  21. package/templates/current/clean/scripts/demo-api.ts +84 -8
  22. package/templates/current/clean/scripts/generate-api.ts +87 -3
  23. package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
  24. package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
  25. package/templates/current/clean/src/api/generated/http-client.ts +28 -26
  26. 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
  27. 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
  28. 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
  29. 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
  30. 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
  31. 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
  32. 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
  33. package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
  34. package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
  35. package/templates/current/clean/src/app/errorMessage.ts +53 -0
  36. package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
  37. package/templates/current/clean/src/app/menu.spec.ts +39 -0
  38. package/templates/current/clean/src/app/menu.ts +48 -12
  39. package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
  40. package/templates/current/clean/src/demo-api.spec.ts +311 -0
  41. package/templates/current/clean/src/features/auth/pages/Login.vue +8 -2
  42. package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
  43. package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
  44. package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
  45. package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
  46. package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
  47. package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
  48. package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
  49. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  50. package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  51. package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
  52. package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
  53. package/templates/current/clean/src/layouts/TopBar.vue +37 -6
  54. package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
  55. package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
  56. package/templates/current/clean/src/locales/en-US.json +30 -3
  57. package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
  58. package/templates/current/clean/src/locales/index.ts +39 -26
  59. package/templates/current/clean/src/locales/zh-CN.json +30 -3
  60. package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
  61. package/templates/current/clean/src/locales/zh-TW.json +30 -3
  62. package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
  63. package/templates/current/clean/src/main.ts +23 -14
  64. package/templates/current/clean/src/router/bootstrap.ts +10 -16
  65. package/templates/current/clean/src/router/componentCache.ts +12 -0
  66. package/templates/current/clean/src/router/componentRegistry.ts +2 -13
  67. package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
  68. package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
  69. package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
  70. package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
  71. package/templates/current/clean/src/router/paths.spec.ts +50 -0
  72. package/templates/current/clean/src/router/paths.ts +21 -0
  73. package/templates/current/clean/src/router/staticRoutes.ts +6 -6
  74. package/templates/current/clean/src/templates/og-table.ts +2 -4
  75. package/templates/current/clean/tsconfig.json +0 -1
  76. package/templates/current/clean/vite.build-policy.ts +55 -8
  77. package/templates/current/clean/vite.config.ts +30 -0
  78. package/templates/current/examples/CHANGELOG.md +103 -0
  79. package/templates/current/examples/component-catalog.json +58 -17
  80. package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
  81. package/templates/current/examples/e2e/demo-shell.spec.ts +90 -46
  82. package/templates/current/examples/package.json +35 -21
  83. package/templates/current/examples/playwright.config.ts +1 -0
  84. package/templates/current/examples/playwright.demo.config.ts +1 -1
  85. package/templates/current/examples/scaffold.lock.json +2 -2
  86. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
  87. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
  88. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
  89. package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
  90. package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
  91. package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
  92. package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
  93. package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
  94. package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
  95. package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
  96. package/templates/current/examples/scripts/demo-api.ts +84 -8
  97. package/templates/current/examples/scripts/generate-api.ts +87 -3
  98. package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
  99. package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
  100. package/templates/current/examples/src/api/generated/http-client.ts +28 -26
  101. 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
  102. 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
  103. 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
  104. 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
  105. 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
  106. 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
  107. 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
  108. package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
  109. package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
  110. package/templates/current/examples/src/app/errorMessage.ts +53 -0
  111. package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
  112. package/templates/current/examples/src/app/menu.spec.ts +39 -0
  113. package/templates/current/examples/src/app/menu.ts +48 -12
  114. package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
  115. package/templates/current/examples/src/demo-api.spec.ts +311 -0
  116. package/templates/current/examples/src/features/auth/pages/Login.vue +8 -2
  117. package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
  118. package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
  119. package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
  120. package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
  121. package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
  122. package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
  123. package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
  124. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
  125. package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
  126. package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
  127. package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
  128. package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
  129. package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
  130. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
  131. package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
  132. package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
  133. package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
  134. package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
  135. package/templates/current/examples/src/layouts/TopBar.vue +37 -6
  136. package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
  137. package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
  138. package/templates/current/examples/src/locales/en-US.json +30 -3
  139. package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
  140. package/templates/current/examples/src/locales/index.ts +39 -26
  141. package/templates/current/examples/src/locales/zh-CN.json +30 -3
  142. package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
  143. package/templates/current/examples/src/locales/zh-TW.json +30 -3
  144. package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
  145. package/templates/current/examples/src/main.ts +24 -22
  146. package/templates/current/examples/src/router/bootstrap.ts +10 -16
  147. package/templates/current/examples/src/router/componentCache.ts +18 -0
  148. package/templates/current/examples/src/router/componentRegistry.ts +1 -18
  149. package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
  150. package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
  151. package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
  152. package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
  153. package/templates/current/examples/src/router/paths.spec.ts +50 -0
  154. package/templates/current/examples/src/router/paths.ts +21 -0
  155. package/templates/current/examples/src/router/staticRoutes.ts +3 -3
  156. package/templates/current/examples/src/templates/og-table.ts +2 -4
  157. package/templates/current/examples/tsconfig.json +0 -1
  158. package/templates/current/examples/vite.build-policy.ts +55 -8
  159. package/templates/current/examples/vite.config.ts +30 -0
@@ -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: {
@@ -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
+ })
@@ -3,6 +3,8 @@ import { ElAlert, ElButton, ElCard, ElForm, ElFormItem, ElInput } from 'element-
3
3
  import { reactive, shallowRef } from 'vue'
4
4
  import { useI18n } from 'vue-i18n'
5
5
  import { useRoute, useRouter } from 'vue-router'
6
+ import { translateAdminError } from '../../../app/errorMessage'
7
+ import { HOME_ROUTE } from '../../../router/paths'
6
8
  import { useAuthStore } from '../store/auth'
7
9
 
8
10
  defineOptions({ name: 'LoginPage' })
@@ -24,10 +26,14 @@ async function submit(): Promise<void> {
24
26
  errorMessage.value = ''
25
27
  try {
26
28
  await auth.login(form)
27
- const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '/dashboard'
29
+ const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : HOME_ROUTE
28
30
  await router.push(redirect)
29
31
  } catch (error: unknown) {
30
- errorMessage.value = error instanceof Error ? error.message : t('auth.loginFailed')
32
+ errorMessage.value = translateAdminError(error, {
33
+ domain: 'auth',
34
+ fallbackKey: 'auth.loginFailed',
35
+ fallback: t('auth.loginFailed'),
36
+ })
31
37
  } finally {
32
38
  loading.value = false
33
39
  }
@@ -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>
@@ -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: 'NotFoundPage' })
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="404" sub-title="你访问的页面不存在或已经被移除。">
15
+ <ElResult icon="warning" :title="t('errors.notFound.code')" :sub-title="t('errors.notFound.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.notFound.backHome') }}
19
+ </ElButton>
15
20
  </template>
16
21
  </ElResult>
17
22
  </main>
@@ -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: 'ServerErrorPage' })
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="error" title="500" sub-title="服务暂时不可用,请稍后再试。">
15
+ <ElResult icon="error" :title="t('errors.serverError.code')" :sub-title="t('errors.serverError.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.serverError.backHome') }}
19
+ </ElButton>
15
20
  </template>
16
21
  </ElResult>
17
22
  </main>
@@ -1,9 +1,18 @@
1
1
  import { mount } from '@vue/test-utils'
2
2
  import { beforeEach, describe, expect, it, vi } from 'vitest'
3
+ import { createI18n } from 'vue-i18n'
4
+ import zhCN from '../../../locales/zh-CN.json'
5
+ import { HOME_ROUTE } from '../../../router/paths'
3
6
  import Forbidden from './Forbidden.vue'
4
7
  import NotFound from './NotFound.vue'
5
8
  import ServerError from './ServerError.vue'
6
9
 
10
+ const i18n = createI18n({
11
+ legacy: false,
12
+ locale: 'zh-CN',
13
+ messages: { 'zh-CN': zhCN },
14
+ })
15
+
7
16
  const { push } = vi.hoisted(() => ({
8
17
  push: vi.fn(),
9
18
  }))
@@ -22,11 +31,11 @@ describe('clean error page navigation', () => {
22
31
  ['404', NotFound],
23
32
  ['500', ServerError],
24
33
  ])('returns to the empty workspace from the %s page', async (_status, component) => {
25
- const wrapper = mount(component)
34
+ const wrapper = mount(component, { global: { plugins: [i18n] } })
26
35
 
27
36
  await wrapper.get('button').trigger('click')
28
37
 
29
38
  expect(push).toHaveBeenCalledOnce()
30
- expect(push).toHaveBeenCalledWith('/workspace')
39
+ expect(push).toHaveBeenCalledWith(HOME_ROUTE)
31
40
  })
32
41
  })
@@ -2,7 +2,7 @@ import type { PageResult } from '@origen-ui/shared'
2
2
  import type { AdminMessageKey } from '../../../../locales'
3
3
  import type { PageRequest, RbacRole, RbacStatus, RbacUser } from './rbac'
4
4
  import { apiClient } from '../../../../api/client'
5
- import { getAdminI18n } from '../../../../locales'
5
+ import { translateAdminMessage } from '../../../../locales'
6
6
 
7
7
  export type AdminRecordStatus = RbacStatus
8
8
 
@@ -248,11 +248,7 @@ export function createRoleDraft(row?: AdminRoleRecord): AdminRoleDraft {
248
248
  }
249
249
 
250
250
  function rbacText(key: string, named?: Record<string, unknown>): string {
251
- const global = getAdminI18n()?.global as unknown as
252
- | { t: (key: string, named?: Record<string, unknown>) => string } |
253
- undefined
254
- if (!global) return key
255
- return named ? global.t(key as AdminMessageKey, named) : global.t(key as AdminMessageKey)
251
+ return translateAdminMessage(key, { named })
256
252
  }
257
253
 
258
254
  function requiredString(value: unknown, labelKey: string): string {
@@ -1,7 +1,6 @@
1
1
  import type { PageResult, SelectOption } from '@origen-ui/shared'
2
- import type { AdminMessageKey } from '../../../../locales'
3
2
  import { apiClient } from '../../../../api/client'
4
- import { getAdminI18n } from '../../../../locales'
3
+ import { translateAdminMessage } from '../../../../locales'
5
4
 
6
5
  export type RbacStatus = 'active' | 'suspended'
7
6
  export type MenuKind = 'directory' | 'page' | 'button'
@@ -35,6 +34,8 @@ export interface RbacMenu {
35
34
  kind: MenuKind
36
35
  code: string
37
36
  title: string
37
+ /** Optional i18n key resolved by the app title resolver; falls back to `title`. */
38
+ titleKey?: string
38
39
  path?: string
39
40
  componentKey?: string
40
41
  icon?: string
@@ -45,12 +46,14 @@ export interface RbacMenu {
45
46
  cache: boolean
46
47
  tabHidden: boolean
47
48
  redirect?: string
49
+ /** Optimistic-lock revision; assigned on create and incremented on every update. */
50
+ version: number
48
51
  createdAt: string
49
52
  updatedAt: string
50
53
  children?: RbacMenu[]
51
54
  }
52
55
 
53
- export type RbacMenuDraft = Omit<RbacMenu, 'id' | 'createdAt' | 'updatedAt'>
56
+ export type RbacMenuDraft = Omit<RbacMenu, 'id' | 'createdAt' | 'updatedAt' | 'version'>
54
57
 
55
58
  export interface RbacAuditEvent {
56
59
  id: string
@@ -74,8 +77,7 @@ export interface RbacPageCapability {
74
77
  }
75
78
 
76
79
  export function rbacText(key: string): string {
77
- const global = getAdminI18n()?.global as unknown as { t: (key: string) => string } | undefined
78
- return global?.t(key as AdminMessageKey) ?? key
80
+ return translateAdminMessage(key)
79
81
  }
80
82
 
81
83
  export interface PageRequest<TQuery extends object> {
@@ -231,15 +233,23 @@ export async function createMenu(draft: RbacMenuDraft, signal: AbortSignal): Pro
231
233
  return apiClient.post<RbacMenu>('/system/menus', draft, { signal, silent: true })
232
234
  }
233
235
 
236
+ /** Business code returned by the server when a menu update loses a version race. */
237
+ export const MENU_VERSION_CONFLICT_CODE = 40901
238
+
234
239
  export async function updateMenu(
235
240
  menuId: string,
236
241
  draft: RbacMenuDraft,
242
+ version: number,
237
243
  signal: AbortSignal,
238
244
  ): Promise<RbacMenu> {
239
- return apiClient.put<RbacMenu>(`/system/menus/${encodeURIComponent(menuId)}`, draft, {
240
- signal,
241
- silent: true,
242
- })
245
+ return apiClient.put<RbacMenu>(
246
+ `/system/menus/${encodeURIComponent(menuId)}`,
247
+ { ...draft, version },
248
+ {
249
+ signal,
250
+ silent: true,
251
+ },
252
+ )
243
253
  }
244
254
 
245
255
  export async function setMenusStatus(