@crombolo/api-management 0.17.0 → 0.18.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/api-management",
3
- "version": "0.17.0",
3
+ "version": "0.18.0",
4
4
  "description": "Umbraco-compatible Management API handlers for crombolo.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@crombolo/core": "0.17.0",
32
- "@crombolo/contracts": "0.17.0"
31
+ "@crombolo/core": "0.18.0",
32
+ "@crombolo/contracts": "0.18.0"
33
33
  }
34
34
  }
@@ -1,47 +1,35 @@
1
1
  /**
2
2
  * Health checks, telemetry, profiling and the server's troubleshooting and
3
- * upgrade-check answers. Telemetry and profiling are fixed: nothing is
4
- * collected or sent, and there is no profiler. docs/diagnostics.md.
3
+ * upgrade-check answers. Telemetry and profiling are gone — nothing is
4
+ * collected or sent, and there is no profiler — so their endpoints answer 410.
5
+ * docs/diagnostics.md.
5
6
  */
6
7
  import { invalidSkipTake, notFound, problemDetails, problemResponse } from '@crombolo/core'
7
8
  import type { DiagnosticsPort } from '../ports-diagnostics.ts'
8
9
  import type { ManagementApiRouter } from '../router.ts'
9
10
  import { paging } from './content-type.ts'
10
- import { readBody } from './document.ts'
11
-
12
- const TELEMETRY_LEVEL = 'Minimal'
13
11
 
14
12
  const badRequest = (title: string, detail: string) => problemDetails({ title, detail, status: 400 })
15
13
 
14
+ /** An operation for something this server has not got, and never will: 410, with why. */
15
+ const gone = (title: string, detail: string) => () =>
16
+ problemResponse(problemDetails({ title, detail, status: 410 }))
17
+
18
+ const telemetryGone = gone(
19
+ 'Telemetry is not collected',
20
+ 'This site collects no telemetry and sends nothing anywhere.',
21
+ )
22
+ const profilingGone = gone(
23
+ 'There is no profiler',
24
+ 'This site has no profiler to read or switch on.',
25
+ )
26
+
16
27
  export function registerTelemetryAndProfilingHandlers(router: ManagementApiRouter): void {
17
- router.handle('GetTelemetry', (ctx) => {
18
- const page = paging(ctx)
19
- if (!page) return problemResponse(invalidSkipTake())
20
- const items = [{ telemetryLevel: TELEMETRY_LEVEL }]
21
- return Response.json({
22
- total: items.length,
23
- items: items.slice(page.skip, page.skip + page.take),
24
- })
25
- })
26
- router.handle('GetTelemetryLevel', () => Response.json({ telemetryLevel: TELEMETRY_LEVEL }))
27
- router.handle('PostTelemetryLevel', async (ctx) => {
28
- const { telemetryLevel } = await readBody(ctx)
29
- if (telemetryLevel === TELEMETRY_LEVEL) return new Response(null, { status: 200 })
30
- return problemResponse(
31
- badRequest(
32
- 'Telemetry cannot be raised',
33
- 'This site collects no telemetry and sends nothing anywhere, so the level stays at Minimal.',
34
- ),
35
- )
36
- })
37
- router.handle('GetProfilingStatus', () => Response.json({ enabled: false }))
38
- router.handle('PutProfilingStatus', async (ctx) => {
39
- const { enabled } = await readBody(ctx)
40
- if (enabled === false) return new Response(null, { status: 200 })
41
- return problemResponse(
42
- badRequest('Profiling is not available', 'This site has no profiler to switch on.'),
43
- )
44
- })
28
+ router.handle('GetTelemetry', telemetryGone)
29
+ router.handle('GetTelemetryLevel', telemetryGone)
30
+ router.handle('PostTelemetryLevel', telemetryGone)
31
+ router.handle('GetProfilingStatus', profilingGone)
32
+ router.handle('PutProfilingStatus', profilingGone)
45
33
  }
46
34
 
47
35
  export function registerDiagnosticsHandlers(
@@ -6,7 +6,7 @@
6
6
  * when its story in docs/stories/ lands. Counted
7
7
  * separately by `coverage:api`.
8
8
  */
9
- import { invalidSkipTake, notFound, problemResponse } from '@crombolo/core'
9
+ import { invalidSkipTake, notFound, problemDetails, problemResponse } from '@crombolo/core'
10
10
  import type { ManagementApiRouter } from '../router.ts'
11
11
  import { paging } from './content-type.ts'
12
12
 
@@ -34,10 +34,8 @@ const SIBLINGS = [
34
34
  /** Lookups of one thing in an empty area: there is nothing to find. */
35
35
  const NOT_FOUND: string[] = []
36
36
 
37
- /** Fixed bodies. Umbraco's news dashboard relays umbraco.com; there is no feed to relay here. */
38
- const FIXED: Record<string, unknown> = {
39
- GetNewsDashboard: { items: [] },
40
- }
37
+ /** Fixed bodies. */
38
+ const FIXED: Record<string, unknown> = {}
41
39
 
42
40
  export const EMPTY_SETTINGS_OPERATIONS: readonly string[] = [
43
41
  ...PAGED,
@@ -64,4 +62,15 @@ export function registerSettingsStubHandlers(router: ManagementApiRouter): void
64
62
  for (const [operation, body] of Object.entries(FIXED)) {
65
63
  router.handle(operation, () => Response.json(body))
66
64
  }
65
+ // Umbraco's news dashboard relays umbraco.com's feed. There is no feed here,
66
+ // and the dashboard is not vendored, so the operation is gone rather than empty.
67
+ router.handle('GetNewsDashboard', () =>
68
+ problemResponse(
69
+ problemDetails({
70
+ title: 'There is no news feed',
71
+ detail: 'This site relays no news from anywhere.',
72
+ status: 410,
73
+ }),
74
+ ),
75
+ )
67
76
  }