@antelopejs/dms-api 0.5.1 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -6
- package/dist/automation/query-request-logs.js.map +1 -1
- package/dist/automation/route-unhealthy.js.map +1 -1
- package/dist/db/models/request_log.model.js.map +1 -1
- package/dist/db/models/request_log.search.js +3 -3
- package/dist/db/models/request_log.search.js.map +1 -1
- package/dist/db/tables/request_log.table.js.map +1 -1
- package/dist/guards.d.ts +22 -0
- package/dist/guards.js +57 -0
- package/dist/guards.js.map +1 -0
- package/dist/index.js.map +1 -1
- package/dist/pages/blocks.d.ts +2 -2
- package/dist/pages/blocks.js +2 -2
- package/dist/pages/blocks.js.map +1 -1
- package/dist/pages/index.js.map +1 -1
- package/dist/pages/logs.js.map +1 -1
- package/dist/pages/module.js +8 -2
- package/dist/pages/module.js.map +1 -1
- package/dist/pages/overview.js.map +1 -1
- package/dist/pages/request-table.js.map +1 -1
- package/dist/pages/routes.js.map +1 -1
- package/dist/pages/settings.js +1 -3
- package/dist/pages/settings.js.map +1 -1
- package/dist/routes/logs.js.map +1 -1
- package/dist/routes/routes.js.map +1 -1
- package/dist/routes/settings.d.ts +2 -1
- package/dist/routes/settings.js +1 -1
- package/dist/routes/settings.js.map +1 -1
- package/dist/services/activity.js.map +1 -1
- package/dist/services/attention.js +1 -1
- package/dist/services/attention.js.map +1 -1
- package/dist/services/health-rules.js.map +1 -1
- package/dist/services/introspection/auth.js +1 -2
- package/dist/services/introspection/auth.js.map +1 -1
- package/dist/services/introspection/decorators.d.ts +3 -1
- package/dist/services/introspection/decorators.js +28 -17
- package/dist/services/introspection/decorators.js.map +1 -1
- package/dist/services/introspection/errors.d.ts +1 -1
- package/dist/services/introspection/errors.js +0 -2
- package/dist/services/introspection/errors.js.map +1 -1
- package/dist/services/introspection/index.d.ts +1 -1
- package/dist/services/introspection/index.js +24 -18
- package/dist/services/introspection/index.js.map +1 -1
- package/dist/services/introspection/probe.js.map +1 -1
- package/dist/services/links.js +4 -4
- package/dist/services/links.js.map +1 -1
- package/dist/services/live.d.ts +3 -2
- package/dist/services/live.js.map +1 -1
- package/dist/services/overview-lists.d.ts +4 -4
- package/dist/services/overview-lists.js.map +1 -1
- package/dist/services/overview.d.ts +4 -4
- package/dist/services/overview.js.map +1 -1
- package/dist/services/request-log/capture.d.ts +5 -14
- package/dist/services/request-log/capture.js +28 -76
- package/dist/services/request-log/capture.js.map +1 -1
- package/dist/services/request-log/console-traffic.d.ts +12 -0
- package/dist/services/request-log/console-traffic.js +69 -0
- package/dist/services/request-log/console-traffic.js.map +1 -0
- package/dist/services/request-log/list.d.ts +1 -1
- package/dist/services/request-log/list.js.map +1 -1
- package/dist/services/request-log/read.js.map +1 -1
- package/dist/services/request-log/redaction.js +7 -6
- package/dist/services/request-log/redaction.js.map +1 -1
- package/dist/services/request-log/util.d.ts +6 -3
- package/dist/services/request-log/util.js +17 -30
- package/dist/services/request-log/util.js.map +1 -1
- package/dist/services/route-catalog.js +2 -2
- package/dist/services/route-catalog.js.map +1 -1
- package/dist/services/route-contract.d.ts +6 -1
- package/dist/services/route-contract.js +11 -12
- package/dist/services/route-contract.js.map +1 -1
- package/dist/services/route-health.d.ts +5 -1
- package/dist/services/route-health.js +4 -1
- package/dist/services/route-health.js.map +1 -1
- package/dist/services/route-statistics.d.ts +3 -4
- package/dist/services/route-statistics.js.map +1 -1
- package/dist/services/routes-sync.d.ts +2 -2
- package/dist/services/routes-sync.js +1 -2
- package/dist/services/routes-sync.js.map +1 -1
- package/dist/services/scope.js +1 -1
- package/dist/services/scope.js.map +1 -1
- package/dist/services/settings-form.d.ts +4 -3
- package/dist/services/settings-form.js +1 -1
- package/dist/services/settings-form.js.map +1 -1
- package/dist/services/settings.js.map +1 -1
- package/dist/services/statistics-write.js +4 -7
- package/dist/services/statistics-write.js.map +1 -1
- package/dist/services/traffic-samples.js.map +1 -1
- package/dist/services/traffic.js +2 -1
- package/dist/services/traffic.js.map +1 -1
- package/dist/services/window.js +1 -1
- package/dist/services/window.js.map +1 -1
- package/dist/types/constants.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +1 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/json.d.ts +2 -0
- package/dist/types/json.js +3 -0
- package/dist/types/json.js.map +1 -0
- package/frontend-vue/app/components/blocks/HealthHero.vue +8 -117
- package/frontend-vue/app/components/blocks/RequestDetail.vue +18 -153
- package/frontend-vue/app/components/blocks/RouteDocumentation.vue +2 -151
- package/frontend-vue/app/components/blocks/RouteHeader.vue +7 -8
- package/frontend-vue/app/components/blocks/RouteTester.vue +58 -1682
- package/frontend-vue/app/components/blocks/RouteTree.vue +16 -81
- package/frontend-vue/app/components/internal/HealthHeroMetrics.vue +50 -0
- package/frontend-vue/app/components/internal/RequestGeneral.vue +32 -0
- package/frontend-vue/app/components/internal/RequestTiming.vue +85 -0
- package/frontend-vue/app/components/internal/RouteInternals.vue +159 -0
- package/frontend-vue/app/components/internal/RouteTesterRequest.vue +225 -0
- package/frontend-vue/app/components/internal/RouteTesterResponse.vue +272 -0
- package/frontend-vue/app/components/internal/RouteTreeFooter.vue +62 -0
- package/frontend-vue/app/components/internal/routeTester/context.ts +8 -0
- package/frontend-vue/app/components/internal/routeTester/useTesterExtras.ts +284 -0
- package/frontend-vue/app/components/internal/routeTester/useTesterFlow.ts +637 -0
- package/frontend-vue/app/components/internal/routeTester/useTesterState.ts +601 -0
- package/frontend-vue/app/utils/health.ts +73 -0
- package/frontend-vue/app/utils/requestDrawer.ts +49 -0
- package/frontend-vue/app/utils/routeExplorer.ts +34 -0
- package/frontend-vue/app/utils/testerMasks.ts +34 -0
- package/frontend-vue/app/utils/testerRequest.ts +14 -38
- package/frontend-vue/build/backend-boundary.ts +122 -0
- package/frontend-vue/dms.frontend.build.ts +2 -0
- package/frontend-vue/eslint.config.mjs +13 -0
- package/frontend-vue/package.json +6 -3
- package/frontend-vue/pnpm-lock.yaml +348 -153
- package/frontend-vue/tests/apiErrorPresentation.test.ts +115 -0
- package/frontend-vue/tests/backend-boundary.test.ts +180 -0
- package/frontend-vue/tests/dmsServer.test.ts +11 -23
- package/frontend-vue/tests/registration.test.ts +22 -6
- package/frontend-vue/tests/stubs/server.ts +19 -0
- package/frontend-vue/tests/testerRequest.test.ts +14 -0
- package/frontend-vue/vitest.config.ts +16 -0
- package/package.json +16 -4
- package/skills/dms-api/SKILL.md +1 -1
- package/skills/dms-api/cases.json +47 -0
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
2
|
+
import { effectScope, ref } from 'vue'
|
|
3
|
+
import { useApiErrorPresenter } from '#dms-core/app/composables/useApiErrorPresenter'
|
|
4
|
+
import { useTesterState } from '../app/components/internal/routeTester/useTesterState'
|
|
5
|
+
import { useTesterFlow } from '../app/components/internal/routeTester/useTesterFlow'
|
|
6
|
+
|
|
7
|
+
afterEach(() => {
|
|
8
|
+
vi.unstubAllGlobals()
|
|
9
|
+
vi.unstubAllEnvs()
|
|
10
|
+
})
|
|
11
|
+
|
|
12
|
+
describe('tester error presentation', () => {
|
|
13
|
+
it.each(['send', 'source', 'replay'])(
|
|
14
|
+
'shows one translated warning for a JSON 403 during %s',
|
|
15
|
+
async (failureAt) => {
|
|
16
|
+
vi.stubEnv('SSR', false)
|
|
17
|
+
const notices: unknown[] = []
|
|
18
|
+
const response = new Response(
|
|
19
|
+
JSON.stringify({
|
|
20
|
+
message: 'error.read_only_demo',
|
|
21
|
+
severity: 'warning',
|
|
22
|
+
}),
|
|
23
|
+
{ status: 403, headers: { 'content-type': 'application/json' } },
|
|
24
|
+
)
|
|
25
|
+
const failure = Object.assign(new Error('Forbidden'), {
|
|
26
|
+
response,
|
|
27
|
+
data: await response.clone().json(),
|
|
28
|
+
})
|
|
29
|
+
const messages = {
|
|
30
|
+
'error.read_only_demo': 'Read-only demo, changes are not saved',
|
|
31
|
+
'error.500.description': 'Something went wrong',
|
|
32
|
+
}
|
|
33
|
+
vi.stubGlobal('getPluginI18n', () => ({
|
|
34
|
+
i18n: {
|
|
35
|
+
tm: (key: string) =>
|
|
36
|
+
Object.hasOwn(messages, key) ? Reflect.get(messages, key) : {},
|
|
37
|
+
rt: (message: string) => message,
|
|
38
|
+
},
|
|
39
|
+
}))
|
|
40
|
+
const presented = ref(new WeakMap())
|
|
41
|
+
vi.stubGlobal('useDmsState', () => presented)
|
|
42
|
+
vi.stubGlobal('useApiErrorPresenter', useApiErrorPresenter)
|
|
43
|
+
vi.stubGlobal('fetch', async () => response)
|
|
44
|
+
vi.stubGlobal('window', { location: { origin: 'https://demo.example' } })
|
|
45
|
+
vi.stubGlobal('useI18n', () => ({ t: (key: string) => key }))
|
|
46
|
+
vi.stubGlobal('useRegionalFormat', () => ({ formatLocale: ref('en') }))
|
|
47
|
+
vi.stubGlobal('useDateFormat', () => ref('en'))
|
|
48
|
+
vi.stubGlobal('useToast', () => ({
|
|
49
|
+
add: (notice: unknown) => {
|
|
50
|
+
notices.push(notice)
|
|
51
|
+
return { id: notices.length }
|
|
52
|
+
},
|
|
53
|
+
}))
|
|
54
|
+
vi.stubGlobal('useConfirm', () => ({ confirm: async () => true }))
|
|
55
|
+
vi.stubGlobal('useDmsUserSession', () => ({ loggedIn: ref(true) }))
|
|
56
|
+
vi.stubGlobal('useDmsRoute', () => ({ query: {} }))
|
|
57
|
+
vi.stubGlobal('useDmsRouter', () => ({ replace: vi.fn() }))
|
|
58
|
+
vi.stubGlobal('useAuthFetch', () => ({
|
|
59
|
+
$authFetch: async () => {
|
|
60
|
+
if (failureAt === 'source') throw failure
|
|
61
|
+
return {
|
|
62
|
+
value: 'tester.token',
|
|
63
|
+
expiresAt: new Date(Date.now() + 120_000).toISOString(),
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
}))
|
|
67
|
+
vi.stubGlobal('useRouteDetail', () => ({
|
|
68
|
+
data: ref({
|
|
69
|
+
ref: 'GET /api/items',
|
|
70
|
+
method: 'GET',
|
|
71
|
+
path: '/api/items',
|
|
72
|
+
pathParams: [],
|
|
73
|
+
auth: { status: 'public' },
|
|
74
|
+
contract: {},
|
|
75
|
+
}),
|
|
76
|
+
pending: ref(false),
|
|
77
|
+
selection: {},
|
|
78
|
+
}))
|
|
79
|
+
vi.stubGlobal('useApiOrigin', () => ref('https://demo.example'))
|
|
80
|
+
vi.stubGlobal('useApiData', () => ({
|
|
81
|
+
data: ref(null),
|
|
82
|
+
error: ref(failure),
|
|
83
|
+
execute: async () => {},
|
|
84
|
+
}))
|
|
85
|
+
const scope = effectScope()
|
|
86
|
+
const tester = scope.run(() => {
|
|
87
|
+
const state = useTesterState({ fetchUrl: '/routes', queryKey: 'route' })
|
|
88
|
+
state.session.activeRef = 'GET /api/items'
|
|
89
|
+
return { ...state, ...useTesterFlow(state) }
|
|
90
|
+
})
|
|
91
|
+
if (!tester) throw new Error('Tester setup failed')
|
|
92
|
+
try {
|
|
93
|
+
if (failureAt !== 'send')
|
|
94
|
+
useApiErrorPresenter().presentError(failure, {
|
|
95
|
+
fallbackKey: 'error.500.description',
|
|
96
|
+
})
|
|
97
|
+
if (failureAt === 'replay')
|
|
98
|
+
await tester.replay('log-1', 'GET /api/items')
|
|
99
|
+
else await tester.send()
|
|
100
|
+
expect(notices).toEqual([
|
|
101
|
+
expect.objectContaining({
|
|
102
|
+
title: 'Read-only demo, changes are not saved',
|
|
103
|
+
color: 'warning',
|
|
104
|
+
}),
|
|
105
|
+
])
|
|
106
|
+
expect(tester.sending.value).toBe(false)
|
|
107
|
+
expect(tester.session.inFlight).toBeNull()
|
|
108
|
+
expect(tester.result.value).toBeNull()
|
|
109
|
+
expect(tester.history.value).toEqual([])
|
|
110
|
+
} finally {
|
|
111
|
+
scope.stop()
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
)
|
|
115
|
+
})
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mkdirSync,
|
|
3
|
+
mkdtempSync,
|
|
4
|
+
realpathSync,
|
|
5
|
+
rmSync,
|
|
6
|
+
symlinkSync,
|
|
7
|
+
writeFileSync,
|
|
8
|
+
} from 'node:fs'
|
|
9
|
+
import { tmpdir } from 'node:os'
|
|
10
|
+
import { dirname, join } from 'node:path'
|
|
11
|
+
import { build as viteBuild, type Plugin } from 'vite'
|
|
12
|
+
import { afterAll, beforeAll, describe, expect, it } from 'vitest'
|
|
13
|
+
import { backendBoundary } from '../build/backend-boundary'
|
|
14
|
+
|
|
15
|
+
/** A scratch repository: the backend package at its root, a dependency installed under it, and the frontend module inside it. */
|
|
16
|
+
let repository: string
|
|
17
|
+
let frontend: string
|
|
18
|
+
|
|
19
|
+
function write(file: string, text: string): void {
|
|
20
|
+
mkdirSync(dirname(file), { recursive: true })
|
|
21
|
+
writeFileSync(file, text)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
beforeAll(() => {
|
|
25
|
+
repository = realpathSync(mkdtempSync(join(tmpdir(), 'dms-api-boundary-')))
|
|
26
|
+
const backend = repository
|
|
27
|
+
frontend = join(backend, 'frontend-vue')
|
|
28
|
+
write(
|
|
29
|
+
join(backend, 'package.json'),
|
|
30
|
+
JSON.stringify({ name: '@antelopejs/dms-api' }),
|
|
31
|
+
)
|
|
32
|
+
write(join(backend, 'src/backend.ts'), 'export const secret = 1\n')
|
|
33
|
+
write(join(backend, 'src/nested/deep.ts'), 'export const deep = 6\n')
|
|
34
|
+
write(join(backend, 'dist/built.js'), 'export const built = 2\n')
|
|
35
|
+
write(join(backend, 'dist/src/nested.js'), 'export const nested = 4\n')
|
|
36
|
+
write(join(backend, 'srcx/sibling.ts'), 'export const sibling = 5\n')
|
|
37
|
+
write(
|
|
38
|
+
join(repository, 'node_modules/other/package.json'),
|
|
39
|
+
JSON.stringify({ name: 'other' }),
|
|
40
|
+
)
|
|
41
|
+
write(
|
|
42
|
+
join(repository, 'node_modules/other/src/shared.ts'),
|
|
43
|
+
'export const shared = 3\n',
|
|
44
|
+
)
|
|
45
|
+
mkdirSync(frontend, { recursive: true })
|
|
46
|
+
symlinkSync(join(backend, 'src/backend.ts'), join(frontend, 'linked.ts'))
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
afterAll(() => {
|
|
50
|
+
rmSync(repository, { recursive: true, force: true })
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
interface BuildOptions {
|
|
54
|
+
extra?: Plugin[]
|
|
55
|
+
alias?: Record<string, string>
|
|
56
|
+
preserveSymlinks?: boolean
|
|
57
|
+
external?: string[]
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** Builds a frontend entry made of `source` with the boundary plugin, and returns the bundled code. */
|
|
61
|
+
async function build(
|
|
62
|
+
source: string,
|
|
63
|
+
options: BuildOptions = {},
|
|
64
|
+
): Promise<string> {
|
|
65
|
+
write(join(frontend, 'entry.ts'), source)
|
|
66
|
+
const result = await viteBuild({
|
|
67
|
+
root: frontend,
|
|
68
|
+
configFile: false,
|
|
69
|
+
logLevel: 'silent',
|
|
70
|
+
plugins: [backendBoundary(), ...(options.extra ?? [])],
|
|
71
|
+
resolve: {
|
|
72
|
+
alias: options.alias ?? {},
|
|
73
|
+
preserveSymlinks: options.preserveSymlinks ?? false,
|
|
74
|
+
},
|
|
75
|
+
build: {
|
|
76
|
+
write: false,
|
|
77
|
+
rollupOptions: { external: options.external ?? [] },
|
|
78
|
+
lib: { entry: join(frontend, 'entry.ts'), formats: ['es'] },
|
|
79
|
+
},
|
|
80
|
+
})
|
|
81
|
+
return JSON.stringify(result)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** A plugin that answers the import `request` with the module id `id`. */
|
|
85
|
+
function resolver(request: string, id: string): Plugin {
|
|
86
|
+
return {
|
|
87
|
+
name: 'test-resolver',
|
|
88
|
+
resolveId: (source) => (source === request ? { id } : null),
|
|
89
|
+
load: (loaded) =>
|
|
90
|
+
loaded === id || loaded.startsWith('\0') ? 'export default 1\n' : null,
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const backendFile = () => join(repository, 'src/backend.ts')
|
|
95
|
+
|
|
96
|
+
describe('the backend boundary of the frontend build', () => {
|
|
97
|
+
it('fails on an import of the backend source, naming both files', async () => {
|
|
98
|
+
const failure = build(
|
|
99
|
+
'import { secret } from "../src/backend.ts"\nexport { secret }\n',
|
|
100
|
+
)
|
|
101
|
+
await expect(failure).rejects.toThrow(/Backend boundary/)
|
|
102
|
+
await expect(failure).rejects.toThrow(join(frontend, 'entry.ts'))
|
|
103
|
+
await expect(failure).rejects.toThrow(backendFile())
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('fails on a file deeper under the backend source', async () => {
|
|
107
|
+
await expect(
|
|
108
|
+
build('import { deep } from "../src/nested/deep.ts"\nexport { deep }\n'),
|
|
109
|
+
).rejects.toThrow(/Backend boundary/)
|
|
110
|
+
})
|
|
111
|
+
|
|
112
|
+
it('fails on an alias that points into the backend source', async () => {
|
|
113
|
+
await expect(
|
|
114
|
+
build(
|
|
115
|
+
'import { secret } from "@backend/backend.ts"\nexport { secret }\n',
|
|
116
|
+
{
|
|
117
|
+
alias: { '@backend': join(repository, 'src') },
|
|
118
|
+
},
|
|
119
|
+
),
|
|
120
|
+
).rejects.toThrow(/Backend boundary/)
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('fails on a symlink to the backend source that the resolver returns', async () => {
|
|
124
|
+
await expect(
|
|
125
|
+
build('import { secret } from "./linked.ts"\nexport { secret }\n', {
|
|
126
|
+
extra: [resolver('./linked.ts', join(frontend, 'linked.ts'))],
|
|
127
|
+
preserveSymlinks: true,
|
|
128
|
+
}),
|
|
129
|
+
).rejects.toThrow(/Backend boundary/)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
it('fails on an id that names the backend source with a query or a hash', async () => {
|
|
133
|
+
for (const suffix of ['?raw', '#fragment']) {
|
|
134
|
+
await expect(
|
|
135
|
+
build('import secret from "virtual-backend"\nexport { secret }\n', {
|
|
136
|
+
extra: [resolver('virtual-backend', `${backendFile()}${suffix}`)],
|
|
137
|
+
}),
|
|
138
|
+
).rejects.toThrow(/Backend boundary/)
|
|
139
|
+
}
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it('fails on a backend source import declared external', async () => {
|
|
143
|
+
await expect(
|
|
144
|
+
build('import { secret } from "../src/backend.ts"\nexport { secret }\n', {
|
|
145
|
+
external: [backendFile()],
|
|
146
|
+
}),
|
|
147
|
+
).rejects.toThrow(/Backend boundary/)
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
it('passes the built output, a virtual module and the source of a dependency', async () => {
|
|
151
|
+
expect(
|
|
152
|
+
await build(
|
|
153
|
+
'import { built } from "../dist/built.js"\nexport { built }\n',
|
|
154
|
+
),
|
|
155
|
+
).toMatch(/built/)
|
|
156
|
+
expect(
|
|
157
|
+
await build('import value from "virtual:thing"\nexport { value }\n', {
|
|
158
|
+
extra: [resolver('virtual:thing', '\0virtual:thing')],
|
|
159
|
+
}),
|
|
160
|
+
).toMatch(/value/)
|
|
161
|
+
expect(
|
|
162
|
+
await build(
|
|
163
|
+
'import { shared } from "../node_modules/other/src/shared.ts"\nexport { shared }\n',
|
|
164
|
+
),
|
|
165
|
+
).toMatch(/shared/)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
it('passes a sibling folder named like src and a src folder inside dist', async () => {
|
|
169
|
+
expect(
|
|
170
|
+
await build(
|
|
171
|
+
'import { sibling } from "../srcx/sibling.ts"\nexport { sibling }\n',
|
|
172
|
+
),
|
|
173
|
+
).toMatch(/sibling/)
|
|
174
|
+
expect(
|
|
175
|
+
await build(
|
|
176
|
+
'import { nested } from "../dist/src/nested.js"\nexport { nested }\n',
|
|
177
|
+
),
|
|
178
|
+
).toMatch(/nested/)
|
|
179
|
+
})
|
|
180
|
+
})
|
|
@@ -1,38 +1,26 @@
|
|
|
1
|
-
import { describe, expect, it
|
|
1
|
+
import { describe, expect, it } from 'vitest'
|
|
2
|
+
import setup from '../dms.server'
|
|
2
3
|
import { testerRoute } from '../server/tester'
|
|
3
4
|
|
|
4
|
-
// The frontend server (dms-frontend 0.6) serves no tester route of its own:
|
|
5
|
-
// the module's `dms.server.ts` is the only one to declare it.
|
|
6
|
-
|
|
7
|
-
vi.mock('#dms/server', () => ({
|
|
8
|
-
defineDmsServer: (setup: unknown) => setup,
|
|
9
|
-
}))
|
|
10
|
-
|
|
11
5
|
interface Registration {
|
|
12
|
-
method:
|
|
6
|
+
method: string
|
|
13
7
|
path: string
|
|
14
8
|
handler: unknown
|
|
15
|
-
options:
|
|
9
|
+
options: object | undefined
|
|
16
10
|
}
|
|
17
11
|
|
|
18
|
-
|
|
19
|
-
const { default: setup } = await import('../dms.server')
|
|
12
|
+
function registrations(): Registration[] {
|
|
20
13
|
const routes: Registration[] = []
|
|
21
|
-
|
|
22
|
-
registerRoute: (
|
|
23
|
-
method
|
|
24
|
-
|
|
25
|
-
handler: unknown,
|
|
26
|
-
options?: unknown,
|
|
27
|
-
) => routes.push({ method, path, handler, options }),
|
|
28
|
-
}
|
|
29
|
-
;(setup as unknown as (server: unknown) => void)(server)
|
|
14
|
+
setup({
|
|
15
|
+
registerRoute: (method, path, handler, options) =>
|
|
16
|
+
routes.push({ method, path, handler, options }),
|
|
17
|
+
})
|
|
30
18
|
return routes
|
|
31
19
|
}
|
|
32
20
|
|
|
33
21
|
describe('dms.server.ts', () => {
|
|
34
|
-
it("serves the tester's POST under the module's own namespace, and nothing else",
|
|
35
|
-
expect(
|
|
22
|
+
it("serves the tester's POST under the module's own namespace, and nothing else", () => {
|
|
23
|
+
expect(registrations()).toEqual([
|
|
36
24
|
{
|
|
37
25
|
method: 'POST',
|
|
38
26
|
path: '/api/_dms-api/tester',
|
|
@@ -1,10 +1,23 @@
|
|
|
1
1
|
import { expect, it, vi } from 'vitest'
|
|
2
|
-
import frontendModule from '../dms.frontend'
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/** Loads the module entry with the DMS's auto-imported helpers it calls on load. */
|
|
4
|
+
async function loadModule() {
|
|
5
|
+
vi.stubGlobal('defineDmsPlugin', <T>(setup: T) => setup)
|
|
6
|
+
vi.stubGlobal('defineDmsMiddleware', <T>(handler: T) => handler)
|
|
7
|
+
const [
|
|
8
|
+
{ default: frontendModule },
|
|
9
|
+
{ default: displays },
|
|
10
|
+
{ default: defaultRoute },
|
|
11
|
+
] = await Promise.all([
|
|
12
|
+
import('../dms.frontend'),
|
|
13
|
+
import('../app/plugins/displays'),
|
|
14
|
+
import('../app/middleware/defaultRoute'),
|
|
15
|
+
])
|
|
16
|
+
return { frontendModule, displays, defaultRoute }
|
|
17
|
+
}
|
|
6
18
|
|
|
7
19
|
it('registers the blocks the backend pages name, and nothing else', async () => {
|
|
20
|
+
const { frontendModule, displays, defaultRoute } = await loadModule()
|
|
8
21
|
const registerComponent = vi.fn()
|
|
9
22
|
const registerPlugin = vi.fn()
|
|
10
23
|
const registerMiddleware = vi.fn()
|
|
@@ -40,10 +53,13 @@ it('registers the blocks the backend pages name, and nothing else', async () =>
|
|
|
40
53
|
expect(new Set(names).size).toBe(names.length)
|
|
41
54
|
// Universal: the cell displays draw in the server render too.
|
|
42
55
|
expect(registerPlugin).toHaveBeenCalledTimes(1)
|
|
43
|
-
expect(registerPlugin
|
|
56
|
+
expect(registerPlugin).toHaveBeenCalledWith(displays, { clientOnly: false })
|
|
44
57
|
// One middleware, on every visit: the Routes page opened without a route
|
|
45
58
|
// lands on one, on the server too. The request drawer and its URL are the DMS's.
|
|
46
59
|
expect(registerMiddleware).toHaveBeenCalledTimes(1)
|
|
47
|
-
expect(registerMiddleware
|
|
48
|
-
|
|
60
|
+
expect(registerMiddleware).toHaveBeenCalledWith(
|
|
61
|
+
'dms-api-default-route',
|
|
62
|
+
defaultRoute,
|
|
63
|
+
{ global: true },
|
|
64
|
+
)
|
|
49
65
|
})
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Stand-in for the `#dms/server` alias the DMS frontend loader provides, which
|
|
3
|
+
* only exists in the workspace it generates. Its `defineDmsServer` returns the
|
|
4
|
+
* setup it is given, as this one does.
|
|
5
|
+
*/
|
|
6
|
+
export interface DmsServer {
|
|
7
|
+
registerRoute(
|
|
8
|
+
method: string,
|
|
9
|
+
path: string,
|
|
10
|
+
handler: (event: never) => unknown,
|
|
11
|
+
options?: object,
|
|
12
|
+
): void
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type DmsServerSetup = (server: DmsServer) => void
|
|
16
|
+
|
|
17
|
+
export function defineDmsServer(setup: DmsServerSetup): DmsServerSetup {
|
|
18
|
+
return setup
|
|
19
|
+
}
|
|
@@ -126,6 +126,20 @@ describe('sending through the proxy', () => {
|
|
|
126
126
|
})
|
|
127
127
|
})
|
|
128
128
|
|
|
129
|
+
it('retains a failed Response and its JSON reason for the core presenter', async () => {
|
|
130
|
+
const response = new Response(
|
|
131
|
+
JSON.stringify({ message: 'error.read_only_demo', severity: 'warning' }),
|
|
132
|
+
{ status: 403, headers: { 'content-type': 'application/json' } },
|
|
133
|
+
)
|
|
134
|
+
vi.stubGlobal('fetch', async () => response)
|
|
135
|
+
await expect(
|
|
136
|
+
sendTesterRequest('/api/private', 'https://dms.example', GET),
|
|
137
|
+
).rejects.toMatchObject({
|
|
138
|
+
response,
|
|
139
|
+
data: { message: 'error.read_only_demo', severity: 'warning' },
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
129
143
|
it('tells a cancelled call from an unreachable server', async () => {
|
|
130
144
|
vi.stubGlobal(
|
|
131
145
|
'fetch',
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
+
import { fileURLToPath } from 'node:url'
|
|
2
|
+
import vue from '@vitejs/plugin-vue'
|
|
1
3
|
import { defineConfig } from 'vitest/config'
|
|
2
4
|
|
|
3
5
|
export default defineConfig({
|
|
6
|
+
plugins: [vue()],
|
|
7
|
+
resolve: {
|
|
8
|
+
alias: {
|
|
9
|
+
'#dms-core': fileURLToPath(
|
|
10
|
+
new URL(
|
|
11
|
+
'../node_modules/@antelopejs/dms/frontend-vue/layers/dms-core',
|
|
12
|
+
import.meta.url,
|
|
13
|
+
),
|
|
14
|
+
),
|
|
15
|
+
'#dms/server': fileURLToPath(
|
|
16
|
+
new URL('./tests/stubs/server.ts', import.meta.url),
|
|
17
|
+
),
|
|
18
|
+
},
|
|
19
|
+
},
|
|
4
20
|
test: {
|
|
5
21
|
environment: 'node',
|
|
6
22
|
include: ['tests/**/*.test.ts'],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/dms-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "API console for the AntelopeJS DMS: API health, request logs, per-route statistics, inferred contracts and a request tester.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"build": "rimraf dist && tsc",
|
|
35
35
|
"dev": "ajs project dev -w -p playground",
|
|
36
36
|
"lint:fix": "oxlint --fix --max-warnings=1000000 && oxfmt . && pnpm --dir frontend-vue lint:fix",
|
|
37
|
-
"lint": "oxlint &&
|
|
37
|
+
"lint": "oxlint && pnpm --dir frontend-vue lint && antelopejs-check-interface-ranges",
|
|
38
38
|
"typecheck": "tsc -p tests",
|
|
39
39
|
"test": "vitest run && pnpm --dir frontend-vue test",
|
|
40
40
|
"format": "oxfmt . && pnpm --dir frontend-vue format",
|
|
@@ -42,7 +42,17 @@
|
|
|
42
42
|
"release": "pnpm --dir frontend-vue install --frozen-lockfile && release-it",
|
|
43
43
|
"prepack": "pnpm run build",
|
|
44
44
|
"knip": "knip --dependencies",
|
|
45
|
-
"knip:all": "knip"
|
|
45
|
+
"knip:all": "knip",
|
|
46
|
+
"prepare": "if git rev-parse --is-inside-work-tree >/dev/null 2>&1 && command -v lefthook >/dev/null 2>&1; then lefthook install; fi",
|
|
47
|
+
"checks": "antelopejs-checks",
|
|
48
|
+
"size": "antelopejs-check-size",
|
|
49
|
+
"ratchet": "antelopejs-ratchet",
|
|
50
|
+
"sync": "antelopejs-sync",
|
|
51
|
+
"ratchet:update": "antelopejs-ratchet --update",
|
|
52
|
+
"sync:check": "antelopejs-sync --check",
|
|
53
|
+
"format:check": "oxfmt --check .",
|
|
54
|
+
"suppressions": "antelopejs-suppressions",
|
|
55
|
+
"suppressions:update": "antelopejs-suppressions --update"
|
|
46
56
|
},
|
|
47
57
|
"dependencies": {
|
|
48
58
|
"@antelopejs/interface-api": ">=0.0.15 <1.0.0",
|
|
@@ -56,9 +66,11 @@
|
|
|
56
66
|
},
|
|
57
67
|
"devDependencies": {
|
|
58
68
|
"@antelopejs/core": "1.17.1",
|
|
59
|
-
"@antelopejs/
|
|
69
|
+
"@antelopejs/dms": ">=0.13.1 <1.0.0",
|
|
70
|
+
"@antelopejs/tooling-configs": "^0.2.17",
|
|
60
71
|
"@types/node": "^24.0.0",
|
|
61
72
|
"knip": "^6.34.0",
|
|
73
|
+
"lefthook": "^2.2.2",
|
|
62
74
|
"oxfmt": "^0.66.0",
|
|
63
75
|
"oxlint": "1.81.0",
|
|
64
76
|
"oxlint-tsgolint": "^7.0.2001",
|
package/skills/dms-api/SKILL.md
CHANGED
|
@@ -25,7 +25,7 @@ Monitors the project's own HTTP API: it captures each request of the routes in s
|
|
|
25
25
|
- Its own calls, the DMS's calls and Tester calls are never counted in statistics or health.
|
|
26
26
|
- cURL snippets use the DMS `apiBaseUrl`: set it to the public API origin.
|
|
27
27
|
- The Tester forwards calls through the module's own frontend server route `POST /api/_dms-api/tester` (`frontend-vue/dms.server.ts`); dms-frontend 0.6 has no built-in tester route.
|
|
28
|
-
-
|
|
28
|
+
- It needs `@antelopejs/dms` 0.11 or later (`interface-dms` 0.9 or later) and `@antelopejs/dms-frontend` 0.9; 0.5.0 is the DMS 0.10 line.
|
|
29
29
|
- A route reads "Auth unknown" when the check happens inside the handler; guard with the DMS auth decorators or name the middleware in `authMiddlewareCallbacks`.
|
|
30
30
|
- Each block is its own permission (`@AuthUserWithPermission(<block>)`): grant roles the blocks they need.
|
|
31
31
|
- Request logs can hold application data; secret-looking keys are always redacted.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 1,
|
|
3
|
+
"cases": [
|
|
4
|
+
{
|
|
5
|
+
"id": "api-slow-routes",
|
|
6
|
+
"area": "modules",
|
|
7
|
+
"style": "clean",
|
|
8
|
+
"prompt": "Which API routes are the slowest, and why does this one fail?",
|
|
9
|
+
"expect": {
|
|
10
|
+
"skills": ["dms-api"],
|
|
11
|
+
"acceptable": ["dms", "api-interface"]
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"id": "dms-api-route-500-casual",
|
|
16
|
+
"area": "modules",
|
|
17
|
+
"style": "casual",
|
|
18
|
+
"prompt": "one route keeps failing in prod, where are the request logs with the body",
|
|
19
|
+
"expect": {
|
|
20
|
+
"skills": ["dms-api"],
|
|
21
|
+
"acceptable": ["dms", "api-interface"]
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"id": "dms-api-retention-slowness",
|
|
26
|
+
"area": "modules",
|
|
27
|
+
"style": "clean",
|
|
28
|
+
"prompt": "Keep the request logs for 14 days and flag requests slower than 800 ms in the API console. What do I set?",
|
|
29
|
+
"expect": {
|
|
30
|
+
"skills": ["dms-api"],
|
|
31
|
+
"acceptable": ["dms", "dms-project"],
|
|
32
|
+
"mustMention": ["requestLogRetention", "requestSlownessThreshold"]
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
"id": "dms-api-not-controller",
|
|
37
|
+
"area": "modules",
|
|
38
|
+
"style": "clean",
|
|
39
|
+
"prompt": "Write a controller with a POST /orders route that reads the JSON body and returns a 201 result.",
|
|
40
|
+
"expect": {
|
|
41
|
+
"skills": ["api-interface"],
|
|
42
|
+
"acceptable": ["core-interface"],
|
|
43
|
+
"avoid": ["dms-api"]
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
]
|
|
47
|
+
}
|