@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.
- package/README.md +41 -9
- package/package.json +26 -2
- package/templates/current/clean/.node-version +1 -0
- package/templates/current/clean/CHANGELOG.md +125 -0
- package/templates/current/clean/README.md +2 -1
- package/templates/current/clean/component-catalog.json +58 -17
- package/templates/current/clean/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/clean/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/clean/package.json +39 -25
- package/templates/current/clean/playwright.config.ts +1 -0
- package/templates/current/clean/playwright.demo.config.ts +1 -1
- package/templates/current/clean/pnpm-workspace.yaml +18 -0
- package/templates/current/clean/scaffold.lock.json +2 -2
- package/templates/current/clean/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/clean/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/clean/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/scripts/demo-api.ts +88 -12
- package/templates/current/clean/scripts/generate-api.ts +87 -3
- package/templates/current/clean/scripts/remove-examples.mjs +4 -4
- package/templates/current/clean/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/clean/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/clean/src/api/generated/http-client.ts +28 -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
- 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
- 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
- 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
- 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
- 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
- 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
- package/templates/current/clean/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/clean/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/clean/src/app/errorMessage.ts +53 -0
- package/templates/current/clean/src/app/menu-host.spec.ts +77 -0
- package/templates/current/clean/src/app/menu.spec.ts +39 -0
- package/templates/current/clean/src/app/menu.ts +48 -12
- package/templates/current/clean/src/app/runtimeConfig.ts +1 -1
- package/templates/current/clean/src/demo-api.spec.ts +314 -3
- package/templates/current/clean/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/clean/src/features/auth/store/auth.ts +6 -19
- package/templates/current/clean/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/clean/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/clean/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/clean/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/clean/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/clean/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/clean/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/clean/src/layouts/TopBar.vue +37 -6
- package/templates/current/clean/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/clean/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/clean/src/locales/en-US.json +30 -3
- package/templates/current/clean/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/clean/src/locales/index.ts +39 -26
- package/templates/current/clean/src/locales/zh-CN.json +30 -3
- package/templates/current/clean/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/clean/src/locales/zh-TW.json +30 -3
- package/templates/current/clean/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/clean/src/main.ts +23 -14
- package/templates/current/clean/src/router/bootstrap.ts +10 -16
- package/templates/current/clean/src/router/componentCache.ts +12 -0
- package/templates/current/clean/src/router/componentRegistry.ts +2 -13
- package/templates/current/clean/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/clean/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/clean/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/clean/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/clean/src/router/paths.spec.ts +50 -0
- package/templates/current/clean/src/router/paths.ts +21 -0
- package/templates/current/clean/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/clean/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/clean/src/router/routeQuery.ts +4 -1
- package/templates/current/clean/src/router/staticRoutes.ts +6 -6
- package/templates/current/clean/src/templates/og-table.ts +2 -4
- package/templates/current/clean/tsconfig.json +0 -1
- package/templates/current/clean/vite.build-policy.ts +55 -8
- package/templates/current/clean/vite.config.ts +30 -0
- package/templates/current/examples/.node-version +1 -0
- package/templates/current/examples/CHANGELOG.md +125 -0
- package/templates/current/examples/README.md +2 -1
- package/templates/current/examples/component-catalog.json +58 -17
- package/templates/current/examples/e2e/admin-shell.spec.ts +6 -0
- package/templates/current/examples/e2e/demo-shell.spec.ts +94 -50
- package/templates/current/examples/package.json +39 -25
- package/templates/current/examples/playwright.config.ts +1 -0
- package/templates/current/examples/playwright.demo.config.ts +1 -1
- package/templates/current/examples/pnpm-workspace.yaml +18 -0
- package/templates/current/examples/scaffold.lock.json +2 -2
- package/templates/current/examples/scripts/check-admin-scaffold.mjs +5 -1
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/Forbidden.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/NotFound.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/ServerError.vue +7 -2
- package/templates/current/examples/scripts/clean-overlay/src/features/errors/pages/error-pages.spec.ts +11 -2
- package/templates/current/examples/scripts/clean-overlay/src/main.ts +23 -14
- package/templates/current/examples/scripts/clean-overlay/src/router/componentCache.ts +12 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/componentRegistry.ts +2 -13
- package/templates/current/examples/scripts/clean-overlay/src/router/dynamicRoutes.spec.ts +34 -4
- package/templates/current/examples/scripts/clean-overlay/src/router/paths.ts +21 -0
- package/templates/current/examples/scripts/clean-overlay/src/router/staticRoutes.ts +6 -6
- package/templates/current/examples/scripts/demo-api.ts +88 -12
- package/templates/current/examples/scripts/generate-api.ts +87 -3
- package/templates/current/examples/scripts/remove-examples.mjs +4 -4
- package/templates/current/examples/scripts/vite-build-policy.spec.ts +1 -0
- package/templates/current/examples/src/api/generated/data-contracts.ts +2 -5
- package/templates/current/examples/src/api/generated/http-client.ts +28 -26
- 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
- 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
- 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
- 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
- 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
- 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
- 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
- package/templates/current/examples/src/api/generated//350/256/244/350/257/201.ts +3 -6
- package/templates/current/examples/src/app/errorMessage.spec.ts +76 -0
- package/templates/current/examples/src/app/errorMessage.ts +53 -0
- package/templates/current/examples/src/app/menu-host.spec.ts +77 -0
- package/templates/current/examples/src/app/menu.spec.ts +39 -0
- package/templates/current/examples/src/app/menu.ts +48 -12
- package/templates/current/examples/src/app/runtimeConfig.ts +1 -1
- package/templates/current/examples/src/demo-api.spec.ts +314 -3
- package/templates/current/examples/src/features/auth/pages/Login.vue +9 -2
- package/templates/current/examples/src/features/auth/store/auth.ts +6 -19
- package/templates/current/examples/src/features/errors/pages/Forbidden.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/NotFound.vue +2 -1
- package/templates/current/examples/src/features/errors/pages/ServerError.vue +2 -1
- package/templates/current/examples/src/features/feature-composables.spec.ts +11 -1
- package/templates/current/examples/src/features/system/access/api/admin-repository.ts +2 -6
- package/templates/current/examples/src/features/system/access/api/rbac.ts +19 -9
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.spec.ts +134 -0
- package/templates/current/examples/src/features/system/access/composables/useAuthorizationPolling.ts +96 -0
- package/templates/current/examples/src/features/system/menus/components/MenuEditorForm.vue +115 -28
- package/templates/current/examples/src/features/system/menus/composables/useMenuManagement.ts +162 -66
- package/templates/current/examples/src/features/system/menus/menuDraft.spec.ts +204 -0
- package/templates/current/examples/src/features/system/menus/menuDraft.ts +116 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.spec.ts +268 -0
- package/templates/current/examples/src/features/system/menus/menuTreePrecheck.ts +317 -0
- package/templates/current/examples/src/features/system/roles/components/RoleEditorForm.vue +1 -0
- package/templates/current/examples/src/features/workspace/pages/Profile.vue +1 -1
- package/templates/current/examples/src/layouts/AdminLayout.vue +3 -0
- package/templates/current/examples/src/layouts/TopBar.vue +37 -6
- package/templates/current/examples/src/layouts/topBarMenuSearch.spec.ts +24 -1
- package/templates/current/examples/src/layouts/topBarMenuSearch.ts +10 -0
- package/templates/current/examples/src/locales/en-US.json +30 -3
- package/templates/current/examples/src/locales/en-US.runtime.ts +2 -0
- package/templates/current/examples/src/locales/index.ts +39 -26
- package/templates/current/examples/src/locales/zh-CN.json +30 -3
- package/templates/current/examples/src/locales/zh-CN.runtime.ts +2 -0
- package/templates/current/examples/src/locales/zh-TW.json +30 -3
- package/templates/current/examples/src/locales/zh-TW.runtime.ts +2 -0
- package/templates/current/examples/src/main.ts +24 -22
- package/templates/current/examples/src/router/bootstrap.ts +10 -16
- package/templates/current/examples/src/router/componentCache.ts +18 -0
- package/templates/current/examples/src/router/componentRegistry.ts +1 -18
- package/templates/current/examples/src/router/dynamicMenuRefresh.spec.ts +101 -0
- package/templates/current/examples/src/router/dynamicMenuRefresh.ts +24 -0
- package/templates/current/examples/src/router/dynamicRoutes.spec.ts +20 -2
- package/templates/current/examples/src/router/dynamicRoutes.ts +14 -3
- package/templates/current/examples/src/router/paths.spec.ts +50 -0
- package/templates/current/examples/src/router/paths.ts +21 -0
- package/templates/current/examples/src/router/queryEncryption.spec.ts +10 -1
- package/templates/current/examples/src/router/routeQuery.spec.ts +2 -1
- package/templates/current/examples/src/router/routeQuery.ts +4 -1
- package/templates/current/examples/src/router/staticRoutes.ts +3 -3
- package/templates/current/examples/src/templates/og-table.ts +2 -4
- package/templates/current/examples/tsconfig.json +0 -1
- package/templates/current/examples/vite.build-policy.ts +55 -8
- package/templates/current/examples/vite.config.ts +30 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'vitest'
|
|
2
|
-
import { componentCacheNames } from './
|
|
3
|
-
import { componentRegistry
|
|
2
|
+
import { componentCacheNames } from './componentCache'
|
|
3
|
+
import { componentRegistry } from './componentRegistry'
|
|
4
|
+
import { routeTransformer } from './dynamicRoutes'
|
|
4
5
|
import { staticRoutes } from './staticRoutes'
|
|
5
6
|
|
|
6
7
|
describe('clean dynamic component registry', () => {
|
|
@@ -16,6 +17,23 @@ describe('clean dynamic component registry', () => {
|
|
|
16
17
|
expect(route?.componentKey).toBe('workspace')
|
|
17
18
|
expect(componentRegistry.has('workspace')).toBe(true)
|
|
18
19
|
})
|
|
20
|
+
|
|
21
|
+
it('rejects flat parentPath entries whose parent route does not exist', () => {
|
|
22
|
+
expect(() =>
|
|
23
|
+
routeTransformer([
|
|
24
|
+
{ code: 'orphan', path: 'orphan', parentPath: '/missing', title: 'Orphan' },
|
|
25
|
+
]),
|
|
26
|
+
).toThrow('Unresolved dynamic route parent path: /missing')
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
it('rejects duplicate route codes with an explicit error', () => {
|
|
30
|
+
expect(() =>
|
|
31
|
+
routeTransformer([
|
|
32
|
+
{ code: 'dup', path: '/first', title: 'First' },
|
|
33
|
+
{ code: 'dup', path: '/second', title: 'Second' },
|
|
34
|
+
]),
|
|
35
|
+
).toThrow('Duplicate dynamic route code: dup')
|
|
36
|
+
})
|
|
19
37
|
})
|
|
20
38
|
|
|
21
39
|
describe('clean keep-alive cache names', () => {
|
|
@@ -25,7 +43,13 @@ describe('clean keep-alive cache names', () => {
|
|
|
25
43
|
|
|
26
44
|
it('generates cache.name from the component name mapping for cached dynamic routes', () => {
|
|
27
45
|
const [workspace] = routeTransformer([
|
|
28
|
-
{
|
|
46
|
+
{
|
|
47
|
+
code: 'workspace',
|
|
48
|
+
path: '/workspace',
|
|
49
|
+
title: 'Workspace',
|
|
50
|
+
componentKey: 'workspace',
|
|
51
|
+
cache: true,
|
|
52
|
+
},
|
|
29
53
|
])
|
|
30
54
|
|
|
31
55
|
expect(workspace?.meta?.cache).toEqual({ enabled: true, name: 'EmptyPage' })
|
|
@@ -33,7 +57,13 @@ describe('clean keep-alive cache names', () => {
|
|
|
33
57
|
|
|
34
58
|
it('omits cache meta when the source disables caching', () => {
|
|
35
59
|
const [workspace] = routeTransformer([
|
|
36
|
-
{
|
|
60
|
+
{
|
|
61
|
+
code: 'workspace',
|
|
62
|
+
path: '/workspace',
|
|
63
|
+
title: 'Workspace',
|
|
64
|
+
componentKey: 'workspace',
|
|
65
|
+
cache: false,
|
|
66
|
+
},
|
|
37
67
|
])
|
|
38
68
|
|
|
39
69
|
expect(workspace?.meta?.cache).toBeUndefined()
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { RouteMenuItem } from '@origen-ui/router'
|
|
2
|
+
import type { RouteLocationRaw } from 'vue-router'
|
|
3
|
+
|
|
4
|
+
/** 授权后的默认首页路由;与 staticRoutes 根路由 redirect 由 paths.spec 钉住一致。 */
|
|
5
|
+
export const HOME_ROUTE = '/workspace'
|
|
6
|
+
|
|
7
|
+
/** staticRoutes 中 404 兜底页的路由名。 */
|
|
8
|
+
export const NOT_FOUND_ROUTE_NAME = '404'
|
|
9
|
+
|
|
10
|
+
/** 深度优先取菜单树中首个可导航入口;isReachable 用于剔除重定向到已裁撤路由的目录项。 */
|
|
11
|
+
export function firstMenuTarget(
|
|
12
|
+
items: readonly RouteMenuItem[],
|
|
13
|
+
isReachable: (to: RouteLocationRaw) => boolean = () => true,
|
|
14
|
+
): RouteLocationRaw | undefined {
|
|
15
|
+
for (const item of items) {
|
|
16
|
+
if (item.to && isReachable(item.to)) return item.to
|
|
17
|
+
const child = firstMenuTarget(item.children, isReachable)
|
|
18
|
+
if (child) return child
|
|
19
|
+
}
|
|
20
|
+
return undefined
|
|
21
|
+
}
|
|
@@ -26,7 +26,7 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
26
26
|
path: '/login',
|
|
27
27
|
name: 'login',
|
|
28
28
|
component: Login,
|
|
29
|
-
meta: { adapter: {
|
|
29
|
+
meta: { adapter: { titleKey: 'auth.login', ...hiddenPublic } },
|
|
30
30
|
},
|
|
31
31
|
{
|
|
32
32
|
path: '/profile',
|
|
@@ -34,10 +34,10 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
34
34
|
component: Profile,
|
|
35
35
|
meta: {
|
|
36
36
|
adapter: {
|
|
37
|
-
|
|
37
|
+
titleKey: 'menu.profile',
|
|
38
38
|
icon: 'profile',
|
|
39
39
|
menu: { order: 20 },
|
|
40
|
-
breadcrumb: {
|
|
40
|
+
breadcrumb: { labelKey: 'menu.profile' },
|
|
41
41
|
cache: { enabled: true, name: 'ProfilePage' },
|
|
42
42
|
},
|
|
43
43
|
},
|
|
@@ -46,18 +46,18 @@ export const staticRoutes: RouteRecordRaw[] = [
|
|
|
46
46
|
path: '/403',
|
|
47
47
|
name: '403',
|
|
48
48
|
component: Forbidden,
|
|
49
|
-
meta: { adapter: {
|
|
49
|
+
meta: { adapter: { titleKey: 'errors.forbidden.title', ...hiddenPublic } },
|
|
50
50
|
},
|
|
51
51
|
{
|
|
52
52
|
path: '/404',
|
|
53
53
|
name: '404',
|
|
54
54
|
component: NotFound,
|
|
55
|
-
meta: { adapter: {
|
|
55
|
+
meta: { adapter: { titleKey: 'errors.notFound.title', ...hiddenPublic } },
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
58
|
path: '/500',
|
|
59
59
|
name: '500',
|
|
60
60
|
component: ServerError,
|
|
61
|
-
meta: { adapter: {
|
|
61
|
+
meta: { adapter: { titleKey: 'errors.serverError.title', ...hiddenPublic } },
|
|
62
62
|
},
|
|
63
63
|
]
|
|
@@ -36,6 +36,7 @@ interface DemoMenu {
|
|
|
36
36
|
kind: MenuKind
|
|
37
37
|
code: string
|
|
38
38
|
title: string
|
|
39
|
+
titleKey?: string
|
|
39
40
|
path?: string
|
|
40
41
|
componentKey?: string
|
|
41
42
|
icon?: string
|
|
@@ -46,6 +47,7 @@ interface DemoMenu {
|
|
|
46
47
|
cache: boolean
|
|
47
48
|
tabHidden: boolean
|
|
48
49
|
redirect?: string
|
|
50
|
+
version: number
|
|
49
51
|
createdAt: string
|
|
50
52
|
updatedAt: string
|
|
51
53
|
}
|
|
@@ -108,6 +110,40 @@ function failure(message: string, code = 40001): DemoApiResponse {
|
|
|
108
110
|
return envelope(null, message, code)
|
|
109
111
|
}
|
|
110
112
|
|
|
113
|
+
/**
|
|
114
|
+
* 菜单写路径的结构完整性校验:父级必须存在、不得指向自身或后代(成环后行从
|
|
115
|
+
* 树中不可达),button 必须挂页面且不能拥有子级,带 button 子级的行不能改出 page。
|
|
116
|
+
* 版本冲突业务码 40901 须与 rbac.ts 的 MENU_VERSION_CONFLICT_CODE 保持一致。
|
|
117
|
+
*/
|
|
118
|
+
function menuStructureError(
|
|
119
|
+
menus: readonly DemoMenu[],
|
|
120
|
+
selfId: string | undefined,
|
|
121
|
+
parentId: string | undefined,
|
|
122
|
+
kind: MenuKind,
|
|
123
|
+
): string | undefined {
|
|
124
|
+
if (kind === 'button' && !parentId) return 'Button permission requires a parent menu.'
|
|
125
|
+
if (kind === 'button' && selfId && menus.some((menu) => menu.parentId === selfId))
|
|
126
|
+
return 'Menus with children cannot become button permissions.'
|
|
127
|
+
if (kind !== 'page' && menus.some((menu) => menu.parentId === selfId && menu.kind === 'button'))
|
|
128
|
+
return 'Menus with button children must remain pages.'
|
|
129
|
+
if (!parentId) return undefined
|
|
130
|
+
const parent = menus.find((menu) => menu.id === parentId)
|
|
131
|
+
if (!parent) return 'Menu parent not found.'
|
|
132
|
+
if (parent.kind === 'button') return 'Button permission menus cannot have child menus.'
|
|
133
|
+
if (selfId) {
|
|
134
|
+
if (parentId === selfId) return 'Menu parent cannot be the menu itself.'
|
|
135
|
+
const visited = new Set<string>([parentId])
|
|
136
|
+
let cursorId: string | undefined = parent.parentId
|
|
137
|
+
while (cursorId && !visited.has(cursorId)) {
|
|
138
|
+
visited.add(cursorId)
|
|
139
|
+
if (cursorId === selfId) return 'Menu parent cannot be one of its descendants.'
|
|
140
|
+
cursorId = menus.find((item) => item.id === cursorId)?.parentId
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
if (kind === 'button' && parent.kind !== 'page') return 'Button permission must attach to a page menu.'
|
|
144
|
+
return undefined
|
|
145
|
+
}
|
|
146
|
+
|
|
111
147
|
function asRecord(value: unknown): Record<string, unknown> {
|
|
112
148
|
return typeof value === 'object' && value !== null && !Array.isArray(value)
|
|
113
149
|
? (value as Record<string, unknown>)
|
|
@@ -214,7 +250,7 @@ function initialState() {
|
|
|
214
250
|
const users: DemoUser[] = [
|
|
215
251
|
{
|
|
216
252
|
id: 'user-admin',
|
|
217
|
-
username: 'admin',
|
|
253
|
+
username: 'demo-admin',
|
|
218
254
|
name: 'Demo Administrator',
|
|
219
255
|
email: 'admin@example.test',
|
|
220
256
|
department: 'Platform',
|
|
@@ -243,6 +279,7 @@ function initialState() {
|
|
|
243
279
|
kind: 'page',
|
|
244
280
|
code: 'dashboard',
|
|
245
281
|
title: 'Dashboard',
|
|
282
|
+
titleKey: 'menu.dashboard',
|
|
246
283
|
path: '/dashboard',
|
|
247
284
|
componentKey: 'dashboard',
|
|
248
285
|
icon: 'dashboard',
|
|
@@ -252,6 +289,7 @@ function initialState() {
|
|
|
252
289
|
visible: true,
|
|
253
290
|
cache: true,
|
|
254
291
|
tabHidden: false,
|
|
292
|
+
version: 1,
|
|
255
293
|
createdAt: NOW,
|
|
256
294
|
updatedAt: NOW,
|
|
257
295
|
},
|
|
@@ -260,6 +298,7 @@ function initialState() {
|
|
|
260
298
|
kind: 'directory',
|
|
261
299
|
code: 'system',
|
|
262
300
|
title: 'System',
|
|
301
|
+
titleKey: 'menu.system',
|
|
263
302
|
path: '/system',
|
|
264
303
|
componentKey: 'outlet',
|
|
265
304
|
icon: 'system',
|
|
@@ -269,6 +308,7 @@ function initialState() {
|
|
|
269
308
|
cache: false,
|
|
270
309
|
tabHidden: false,
|
|
271
310
|
redirect: '/system/users',
|
|
311
|
+
version: 1,
|
|
272
312
|
createdAt: NOW,
|
|
273
313
|
updatedAt: NOW,
|
|
274
314
|
},
|
|
@@ -278,6 +318,7 @@ function initialState() {
|
|
|
278
318
|
kind: 'page',
|
|
279
319
|
code: 'users',
|
|
280
320
|
title: 'Users',
|
|
321
|
+
titleKey: 'menu.users',
|
|
281
322
|
path: 'users',
|
|
282
323
|
componentKey: 'user-list',
|
|
283
324
|
permission: 'system:user:read',
|
|
@@ -286,6 +327,7 @@ function initialState() {
|
|
|
286
327
|
visible: true,
|
|
287
328
|
cache: true,
|
|
288
329
|
tabHidden: false,
|
|
330
|
+
version: 1,
|
|
289
331
|
createdAt: NOW,
|
|
290
332
|
updatedAt: NOW,
|
|
291
333
|
},
|
|
@@ -295,6 +337,7 @@ function initialState() {
|
|
|
295
337
|
kind: 'page',
|
|
296
338
|
code: 'roles',
|
|
297
339
|
title: 'Roles',
|
|
340
|
+
titleKey: 'menu.roles',
|
|
298
341
|
path: 'roles',
|
|
299
342
|
componentKey: 'role-list',
|
|
300
343
|
permission: 'system:role:read',
|
|
@@ -303,6 +346,7 @@ function initialState() {
|
|
|
303
346
|
visible: true,
|
|
304
347
|
cache: true,
|
|
305
348
|
tabHidden: false,
|
|
349
|
+
version: 1,
|
|
306
350
|
createdAt: NOW,
|
|
307
351
|
updatedAt: NOW,
|
|
308
352
|
},
|
|
@@ -312,6 +356,7 @@ function initialState() {
|
|
|
312
356
|
kind: 'page',
|
|
313
357
|
code: 'menus',
|
|
314
358
|
title: 'Menus',
|
|
359
|
+
titleKey: 'menu.menus',
|
|
315
360
|
path: 'menus',
|
|
316
361
|
componentKey: 'menu-list',
|
|
317
362
|
permission: 'system:menu:read',
|
|
@@ -320,6 +365,7 @@ function initialState() {
|
|
|
320
365
|
visible: true,
|
|
321
366
|
cache: true,
|
|
322
367
|
tabHidden: false,
|
|
368
|
+
version: 1,
|
|
323
369
|
createdAt: NOW,
|
|
324
370
|
updatedAt: NOW,
|
|
325
371
|
},
|
|
@@ -329,6 +375,7 @@ function initialState() {
|
|
|
329
375
|
kind: 'page',
|
|
330
376
|
code: 'audit',
|
|
331
377
|
title: 'Audit log',
|
|
378
|
+
titleKey: 'menu.audit',
|
|
332
379
|
path: 'audit',
|
|
333
380
|
componentKey: 'audit-list',
|
|
334
381
|
permission: 'system:audit:read',
|
|
@@ -337,6 +384,7 @@ function initialState() {
|
|
|
337
384
|
visible: true,
|
|
338
385
|
cache: false,
|
|
339
386
|
tabHidden: false,
|
|
387
|
+
version: 1,
|
|
340
388
|
createdAt: NOW,
|
|
341
389
|
updatedAt: NOW,
|
|
342
390
|
},
|
|
@@ -429,7 +477,7 @@ export function createDemoApi(): DemoApi {
|
|
|
429
477
|
const body = asRecord(request.body)
|
|
430
478
|
|
|
431
479
|
if (method === 'POST' && path === '/auth/login') {
|
|
432
|
-
if (body.username !== 'admin' || body.password !== '
|
|
480
|
+
if (body.username !== 'demo-admin' || body.password !== 'demo-password')
|
|
433
481
|
return failure('Invalid demo credentials.', 40101)
|
|
434
482
|
return envelope({
|
|
435
483
|
accessToken: ADMIN_TOKEN,
|
|
@@ -437,7 +485,7 @@ export function createDemoApi(): DemoApi {
|
|
|
437
485
|
refreshToken: REFRESH_TOKEN,
|
|
438
486
|
user: {
|
|
439
487
|
id: 'user-admin',
|
|
440
|
-
username: 'admin',
|
|
488
|
+
username: 'demo-admin',
|
|
441
489
|
displayName: 'Demo Administrator',
|
|
442
490
|
email: 'admin@example.test',
|
|
443
491
|
},
|
|
@@ -455,7 +503,7 @@ export function createDemoApi(): DemoApi {
|
|
|
455
503
|
return envelope({
|
|
456
504
|
user: {
|
|
457
505
|
id: 'user-admin',
|
|
458
|
-
username: 'admin',
|
|
506
|
+
username: 'demo-admin',
|
|
459
507
|
displayName: 'Demo Administrator',
|
|
460
508
|
email: 'admin@example.test',
|
|
461
509
|
},
|
|
@@ -654,13 +702,23 @@ export function createDemoApi(): DemoApi {
|
|
|
654
702
|
}
|
|
655
703
|
|
|
656
704
|
if (method === 'POST' && path === '/system/menus') {
|
|
705
|
+
const kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
|
|
706
|
+
const parentId =
|
|
707
|
+
typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined
|
|
708
|
+
const code = String(body.code ?? '').trim()
|
|
709
|
+
const title = String(body.title ?? '').trim()
|
|
710
|
+
if (!code) return failure('Menu code is required.', 40001)
|
|
711
|
+
if (!title) return failure('Menu title is required.', 40001)
|
|
712
|
+
const structureError = menuStructureError(state.menus, undefined, parentId, kind)
|
|
713
|
+
if (structureError) return failure(structureError, 40001)
|
|
657
714
|
const id = `menu-${state.nextId++}`
|
|
658
715
|
const menu: DemoMenu = {
|
|
659
716
|
id,
|
|
660
|
-
parentId
|
|
661
|
-
kind
|
|
662
|
-
code
|
|
663
|
-
title
|
|
717
|
+
parentId,
|
|
718
|
+
kind,
|
|
719
|
+
code,
|
|
720
|
+
title,
|
|
721
|
+
titleKey: typeof body.titleKey === 'string' && body.titleKey ? body.titleKey : undefined,
|
|
664
722
|
path: typeof body.path === 'string' && body.path ? body.path : undefined,
|
|
665
723
|
componentKey:
|
|
666
724
|
typeof body.componentKey === 'string' && body.componentKey
|
|
@@ -675,6 +733,7 @@ export function createDemoApi(): DemoApi {
|
|
|
675
733
|
cache: body.cache !== false,
|
|
676
734
|
tabHidden: body.tabHidden === true,
|
|
677
735
|
redirect: typeof body.redirect === 'string' && body.redirect ? body.redirect : undefined,
|
|
736
|
+
version: 1,
|
|
678
737
|
createdAt: NOW,
|
|
679
738
|
updatedAt: NOW,
|
|
680
739
|
}
|
|
@@ -709,6 +768,7 @@ export function createDemoApi(): DemoApi {
|
|
|
709
768
|
const next = status(body.status)
|
|
710
769
|
for (const menu of state.menus.filter((item) => ids.has(item.id))) {
|
|
711
770
|
menu.status = next
|
|
771
|
+
menu.version += 1
|
|
712
772
|
menu.updatedAt = new Date().toISOString()
|
|
713
773
|
revise('menu.status', 'menu', menu.id, menu.title || menu.code, `Set status to ${next}.`)
|
|
714
774
|
}
|
|
@@ -720,11 +780,26 @@ export function createDemoApi(): DemoApi {
|
|
|
720
780
|
if (!menu) return failure('Menu not found.', 40401)
|
|
721
781
|
if (method === 'GET') return envelope(cloneMenu(menu))
|
|
722
782
|
if (method === 'PUT') {
|
|
723
|
-
|
|
783
|
+
const kind = body.kind === 'directory' || body.kind === 'button' ? body.kind : 'page'
|
|
784
|
+
const parentId =
|
|
724
785
|
typeof body.parentId === 'string' && body.parentId ? body.parentId : undefined
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
786
|
+
const code = String(body.code ?? menu.code).trim()
|
|
787
|
+
const title = String(body.title ?? menu.title).trim()
|
|
788
|
+
if (!code) return failure('Menu code is required.', 40001)
|
|
789
|
+
if (!title) return failure('Menu title is required.', 40001)
|
|
790
|
+
const structureError = menuStructureError(state.menus, menu.id, parentId, kind)
|
|
791
|
+
if (structureError) return failure(structureError, 40001)
|
|
792
|
+
if (body.version !== undefined) {
|
|
793
|
+
const clientVersion = Number(body.version)
|
|
794
|
+
if (!Number.isInteger(clientVersion) || clientVersion !== menu.version)
|
|
795
|
+
return failure('Menu was modified by someone else. Refresh and retry.', 40901)
|
|
796
|
+
}
|
|
797
|
+
menu.parentId = parentId
|
|
798
|
+
menu.kind = kind
|
|
799
|
+
menu.code = code
|
|
800
|
+
menu.title = title
|
|
801
|
+
menu.titleKey =
|
|
802
|
+
typeof body.titleKey === 'string' && body.titleKey ? body.titleKey : undefined
|
|
728
803
|
menu.path = typeof body.path === 'string' && body.path ? body.path : undefined
|
|
729
804
|
menu.componentKey =
|
|
730
805
|
typeof body.componentKey === 'string' && body.componentKey ? body.componentKey : undefined
|
|
@@ -738,6 +813,7 @@ export function createDemoApi(): DemoApi {
|
|
|
738
813
|
menu.tabHidden = body.tabHidden === true
|
|
739
814
|
menu.redirect =
|
|
740
815
|
typeof body.redirect === 'string' && body.redirect ? body.redirect : undefined
|
|
816
|
+
menu.version += 1
|
|
741
817
|
menu.updatedAt = new Date().toISOString()
|
|
742
818
|
revise('menu.update', 'menu', menu.id, menu.title || menu.code, 'Updated demo menu.')
|
|
743
819
|
return envelope(cloneMenu(menu))
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readdir, readFile, writeFile } from 'node:fs/promises'
|
|
1
2
|
import path from 'node:path'
|
|
2
3
|
import { fileURLToPath } from 'node:url'
|
|
3
4
|
// 使用 swagger-typescript-api 从 OpenAPI 规范生成 API 客户端
|
|
@@ -6,10 +7,11 @@ import { generateApi } from 'swagger-typescript-api'
|
|
|
6
7
|
/* eslint-disable node/prefer-global/process */
|
|
7
8
|
|
|
8
9
|
const __dirname = path.dirname(fileURLToPath(import.meta.url))
|
|
10
|
+
const outputDirectory = path.resolve(__dirname, '../src/api/generated')
|
|
9
11
|
|
|
10
12
|
generateApi({
|
|
11
13
|
name: 'Api.ts',
|
|
12
|
-
output:
|
|
14
|
+
output: outputDirectory,
|
|
13
15
|
input: path.resolve(__dirname, '../openapi.json'),
|
|
14
16
|
modular: true,
|
|
15
17
|
moduleNameFirstTag: true,
|
|
@@ -18,10 +20,92 @@ generateApi({
|
|
|
18
20
|
singleHttpClient: true,
|
|
19
21
|
cleanOutput: true,
|
|
20
22
|
})
|
|
23
|
+
.then(() => normalizeGeneratedApi(outputDirectory))
|
|
21
24
|
.then(() => {
|
|
22
25
|
process.stdout.write('API client generated successfully!\n')
|
|
23
26
|
})
|
|
24
|
-
.catch((
|
|
25
|
-
console.error('Failed to generate API client:',
|
|
27
|
+
.catch((error) => {
|
|
28
|
+
console.error('Failed to generate API client:', error)
|
|
26
29
|
process.exit(1)
|
|
27
30
|
})
|
|
31
|
+
|
|
32
|
+
async function normalizeGeneratedApi(directory: string) {
|
|
33
|
+
for (const entry of await readdir(directory, { withFileTypes: true })) {
|
|
34
|
+
if (!entry.isFile() || !entry.name.endsWith('.ts')) continue
|
|
35
|
+
const filePath = path.join(directory, entry.name)
|
|
36
|
+
const source = await readFile(filePath, 'utf8')
|
|
37
|
+
const normalized = normalizeGeneratedSource(source, entry.name)
|
|
38
|
+
if (normalized !== source) await writeFile(filePath, normalized, 'utf8')
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function normalizeGeneratedSource(source: string, fileName: string) {
|
|
43
|
+
let normalized = source
|
|
44
|
+
.replace(/^\/\* eslint-disable \*\/\r?\n/u, '')
|
|
45
|
+
.replace(/^\/\* tslint:disable \*\/\r?\n/u, '')
|
|
46
|
+
.replace(/^\/\/ @ts-nocheck\r?\n/u, '')
|
|
47
|
+
.replace(/\bany\b/gu, 'unknown')
|
|
48
|
+
|
|
49
|
+
if (fileName === 'http-client.ts') normalized = normalizeHttpClient(normalized)
|
|
50
|
+
return normalized
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function normalizeHttpClient(source: string) {
|
|
54
|
+
let normalized = source.replace(
|
|
55
|
+
' return value.map((v: unknown) => this.encodeQueryParam(key, v)).join("&");',
|
|
56
|
+
' if (!Array.isArray(value)) return "";\n return value.map((v) => this.encodeQueryParam(key, v)).join("&");',
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
const formatterStart = normalized.indexOf(' private contentFormatters:')
|
|
60
|
+
const formatterEnd = normalized.indexOf('\n\n protected mergeRequestParams', formatterStart)
|
|
61
|
+
if (formatterStart < 0 || formatterEnd < 0)
|
|
62
|
+
throw new Error('Generated HTTP client formatters changed unexpectedly.')
|
|
63
|
+
|
|
64
|
+
const formatter = ` private contentFormatters: Record<ContentType, (input: unknown) => BodyInit | null> = {
|
|
65
|
+
[ContentType.Json]: (input: unknown) =>
|
|
66
|
+
input === null || typeof input === "undefined"
|
|
67
|
+
? null
|
|
68
|
+
: JSON.stringify(input) ?? null,
|
|
69
|
+
[ContentType.JsonApi]: (input: unknown) =>
|
|
70
|
+
input === null || typeof input === "undefined"
|
|
71
|
+
? null
|
|
72
|
+
: JSON.stringify(input) ?? null,
|
|
73
|
+
[ContentType.Text]: (input: unknown) =>
|
|
74
|
+
typeof input === "string" ? input : JSON.stringify(input) ?? null,
|
|
75
|
+
[ContentType.FormData]: (input: unknown) => {
|
|
76
|
+
if (input instanceof FormData) {
|
|
77
|
+
return input;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const record = isRecord(input) ? input : {};
|
|
81
|
+
return Object.keys(record).reduce((formData, key) => {
|
|
82
|
+
const property = record[key];
|
|
83
|
+
formData.append(
|
|
84
|
+
key,
|
|
85
|
+
property instanceof Blob
|
|
86
|
+
? property
|
|
87
|
+
: typeof property === "object" && property !== null
|
|
88
|
+
? JSON.stringify(property) ?? ""
|
|
89
|
+
: String(property),
|
|
90
|
+
);
|
|
91
|
+
return formData;
|
|
92
|
+
}, new FormData());
|
|
93
|
+
},
|
|
94
|
+
[ContentType.UrlEncoded]: (input: unknown) =>
|
|
95
|
+
this.toQueryString(isRecord(input) ? input : {}),
|
|
96
|
+
};`
|
|
97
|
+
normalized = `${normalized.slice(0, formatterStart)}${formatter}${normalized.slice(formatterEnd)}`
|
|
98
|
+
|
|
99
|
+
const classMarker = 'export class HttpClient<SecurityDataType = unknown> {'
|
|
100
|
+
if (!normalized.includes('function isRecord(value: unknown): value is Record<string, unknown>')) {
|
|
101
|
+
normalized = normalized.replace(
|
|
102
|
+
classMarker,
|
|
103
|
+
`function isRecord(value: unknown): value is Record<string, unknown> {
|
|
104
|
+
return typeof value === "object" && value !== null;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
${classMarker}`,
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
return normalized
|
|
111
|
+
}
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { existsSync } from 'node:fs'
|
|
3
3
|
import { cp, rm } from 'node:fs/promises'
|
|
4
|
-
import {
|
|
4
|
+
import { resolve } from 'node:path'
|
|
5
5
|
import process from 'node:process'
|
|
6
|
-
import {
|
|
6
|
+
import { REPOSITORY_ROOT } from '../../lib/repository-root.mjs'
|
|
7
7
|
|
|
8
8
|
const args = new Set(process.argv.slice(2))
|
|
9
9
|
const rootIndex = process.argv.indexOf('--root')
|
|
10
10
|
const root = rootIndex >= 0 ? resolve(process.argv[rootIndex + 1] || '.') : process.cwd()
|
|
11
11
|
const dryRun = args.has('--dry-run')
|
|
12
12
|
const overlayIndex = process.argv.indexOf('--overlay')
|
|
13
|
+
const repositoryRoot = REPOSITORY_ROOT
|
|
13
14
|
const repositoryOverlay = resolve(
|
|
14
|
-
|
|
15
|
-
'..',
|
|
15
|
+
repositoryRoot,
|
|
16
16
|
'apps',
|
|
17
17
|
'admin',
|
|
18
18
|
'scaffold',
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
// @ts-nocheck
|
|
4
1
|
/*
|
|
5
2
|
* ---------------------------------------------------------------
|
|
6
3
|
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
@@ -11,7 +8,7 @@
|
|
|
11
8
|
*/
|
|
12
9
|
|
|
13
10
|
export interface LoginCredentials {
|
|
14
|
-
/**
|
|
11
|
+
/** 用户名 */
|
|
15
12
|
username: string;
|
|
16
13
|
/** 密码 */
|
|
17
14
|
password: string;
|
|
@@ -27,7 +24,7 @@ export interface LoginResponse {
|
|
|
27
24
|
permissions?: string[];
|
|
28
25
|
/** 角色ID列表 */
|
|
29
26
|
roleIds?: string[];
|
|
30
|
-
/**
|
|
27
|
+
/** 授权版本号 */
|
|
31
28
|
authorizationRevision?: number;
|
|
32
29
|
}
|
|
33
30
|
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars */
|
|
2
|
-
/* tslint:disable */
|
|
3
|
-
// @ts-nocheck
|
|
4
1
|
/*
|
|
5
2
|
* ---------------------------------------------------------------
|
|
6
3
|
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
|
|
@@ -10,7 +7,7 @@
|
|
|
10
7
|
* ---------------------------------------------------------------
|
|
11
8
|
*/
|
|
12
9
|
|
|
13
|
-
export type QueryParamsType = Record<string | number,
|
|
10
|
+
export type QueryParamsType = Record<string | number, unknown>;
|
|
14
11
|
export type ResponseFormat = keyof Omit<Body, "body" | "bodyUsed">;
|
|
15
12
|
|
|
16
13
|
export interface FullRequestParams extends Omit<RequestInit, "body"> {
|
|
@@ -62,6 +59,10 @@ export enum ContentType {
|
|
|
62
59
|
Text = "text/plain",
|
|
63
60
|
}
|
|
64
61
|
|
|
62
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
63
|
+
return typeof value === "object" && value !== null;
|
|
64
|
+
}
|
|
65
|
+
|
|
65
66
|
export class HttpClient<SecurityDataType = unknown> {
|
|
66
67
|
public baseUrl: string = "/api";
|
|
67
68
|
private securityData: SecurityDataType | null = null;
|
|
@@ -85,7 +86,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
85
86
|
this.securityData = data;
|
|
86
87
|
};
|
|
87
88
|
|
|
88
|
-
protected encodeQueryParam(key: string, value:
|
|
89
|
+
protected encodeQueryParam(key: string, value: unknown) {
|
|
89
90
|
const encodedKey = encodeURIComponent(key);
|
|
90
91
|
return `${encodedKey}=${encodeURIComponent(typeof value === "number" ? value : `${value}`)}`;
|
|
91
92
|
}
|
|
@@ -96,7 +97,8 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
96
97
|
|
|
97
98
|
protected addArrayQueryParam(query: QueryParamsType, key: string) {
|
|
98
99
|
const value = query[key];
|
|
99
|
-
|
|
100
|
+
if (!Array.isArray(value)) return "";
|
|
101
|
+
return value.map((v) => this.encodeQueryParam(key, v)).join("&");
|
|
100
102
|
}
|
|
101
103
|
|
|
102
104
|
protected toQueryString(rawQuery?: QueryParamsType): string {
|
|
@@ -118,38 +120,38 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
118
120
|
return queryString ? `?${queryString}` : "";
|
|
119
121
|
}
|
|
120
122
|
|
|
121
|
-
private contentFormatters: Record<ContentType, (input:
|
|
122
|
-
[ContentType.Json]: (input:
|
|
123
|
-
input
|
|
124
|
-
?
|
|
125
|
-
: input,
|
|
126
|
-
[ContentType.JsonApi]: (input:
|
|
127
|
-
input
|
|
128
|
-
?
|
|
129
|
-
: input,
|
|
130
|
-
[ContentType.Text]: (input:
|
|
131
|
-
input
|
|
132
|
-
|
|
133
|
-
: input,
|
|
134
|
-
[ContentType.FormData]: (input: any) => {
|
|
123
|
+
private contentFormatters: Record<ContentType, (input: unknown) => BodyInit | null> = {
|
|
124
|
+
[ContentType.Json]: (input: unknown) =>
|
|
125
|
+
input === null || typeof input === "undefined"
|
|
126
|
+
? null
|
|
127
|
+
: JSON.stringify(input) ?? null,
|
|
128
|
+
[ContentType.JsonApi]: (input: unknown) =>
|
|
129
|
+
input === null || typeof input === "undefined"
|
|
130
|
+
? null
|
|
131
|
+
: JSON.stringify(input) ?? null,
|
|
132
|
+
[ContentType.Text]: (input: unknown) =>
|
|
133
|
+
typeof input === "string" ? input : JSON.stringify(input) ?? null,
|
|
134
|
+
[ContentType.FormData]: (input: unknown) => {
|
|
135
135
|
if (input instanceof FormData) {
|
|
136
136
|
return input;
|
|
137
137
|
}
|
|
138
138
|
|
|
139
|
-
|
|
140
|
-
|
|
139
|
+
const record = isRecord(input) ? input : {};
|
|
140
|
+
return Object.keys(record).reduce((formData, key) => {
|
|
141
|
+
const property = record[key];
|
|
141
142
|
formData.append(
|
|
142
143
|
key,
|
|
143
144
|
property instanceof Blob
|
|
144
145
|
? property
|
|
145
146
|
: typeof property === "object" && property !== null
|
|
146
|
-
? JSON.stringify(property)
|
|
147
|
-
:
|
|
147
|
+
? JSON.stringify(property) ?? ""
|
|
148
|
+
: String(property),
|
|
148
149
|
);
|
|
149
150
|
return formData;
|
|
150
151
|
}, new FormData());
|
|
151
152
|
},
|
|
152
|
-
[ContentType.UrlEncoded]: (input:
|
|
153
|
+
[ContentType.UrlEncoded]: (input: unknown) =>
|
|
154
|
+
this.toQueryString(isRecord(input) ? input : {}),
|
|
153
155
|
};
|
|
154
156
|
|
|
155
157
|
protected mergeRequestParams(
|
|
@@ -193,7 +195,7 @@ export class HttpClient<SecurityDataType = unknown> {
|
|
|
193
195
|
}
|
|
194
196
|
};
|
|
195
197
|
|
|
196
|
-
public request = async <T =
|
|
198
|
+
public request = async <T = unknown, E = unknown>({
|
|
197
199
|
body,
|
|
198
200
|
secure,
|
|
199
201
|
path,
|