@catamorphic/fastify-plugin 0.0.0-stage → 0.1.0-alpha.30

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 (160) hide show
  1. package/LICENSE.txt +202 -0
  2. package/NOTICE.txt +32 -0
  3. package/README.md +143 -2
  4. package/dist/app-presentation-tools.d.ts +4 -0
  5. package/dist/app-presentation-tools.d.ts.map +1 -0
  6. package/dist/app.d.ts +27 -0
  7. package/dist/app.d.ts.map +1 -0
  8. package/dist/chunk-baagvvm3.js +164 -0
  9. package/dist/chunk-baagvvm3.js.map +10 -0
  10. package/dist/http-identity.d.ts +52 -0
  11. package/dist/http-identity.d.ts.map +1 -0
  12. package/dist/hung-up.d.ts +7 -0
  13. package/dist/hung-up.d.ts.map +1 -0
  14. package/dist/index.d.ts +11 -0
  15. package/dist/index.d.ts.map +1 -0
  16. package/dist/index.js +10884 -0
  17. package/dist/index.js.map +56 -0
  18. package/dist/mcp-shared.d.ts +117 -0
  19. package/dist/mcp-shared.d.ts.map +1 -0
  20. package/dist/mcp.d.ts +6 -0
  21. package/dist/mcp.d.ts.map +1 -0
  22. package/dist/mcp.js +13 -0
  23. package/dist/mcp.js.map +9 -0
  24. package/dist/plugin.d.ts +113 -0
  25. package/dist/plugin.d.ts.map +1 -0
  26. package/dist/project-capabilities.d.ts +25 -0
  27. package/dist/project-capabilities.d.ts.map +1 -0
  28. package/dist/project-mcp-program.d.ts +15 -0
  29. package/dist/project-mcp-program.d.ts.map +1 -0
  30. package/dist/project-mcp-surface.d.ts +16 -0
  31. package/dist/project-mcp-surface.d.ts.map +1 -0
  32. package/dist/request-logging.d.ts +18 -0
  33. package/dist/request-logging.d.ts.map +1 -0
  34. package/dist/routes/agent-capabilities.d.ts +4 -0
  35. package/dist/routes/agent-capabilities.d.ts.map +1 -0
  36. package/dist/routes/agent.d.ts +4 -0
  37. package/dist/routes/agent.d.ts.map +1 -0
  38. package/dist/routes/apps-mcp.d.ts +4 -0
  39. package/dist/routes/apps-mcp.d.ts.map +1 -0
  40. package/dist/routes/apps.d.ts +12 -0
  41. package/dist/routes/apps.d.ts.map +1 -0
  42. package/dist/routes/client-runners.d.ts +11 -0
  43. package/dist/routes/client-runners.d.ts.map +1 -0
  44. package/dist/routes/code-hosts.d.ts +11 -0
  45. package/dist/routes/code-hosts.d.ts.map +1 -0
  46. package/dist/routes/connection-mcp.d.ts +10 -0
  47. package/dist/routes/connection-mcp.d.ts.map +1 -0
  48. package/dist/routes/connections.d.ts +4 -0
  49. package/dist/routes/connections.d.ts.map +1 -0
  50. package/dist/routes/documents.d.ts +11 -0
  51. package/dist/routes/documents.d.ts.map +1 -0
  52. package/dist/routes/environments.d.ts +4 -0
  53. package/dist/routes/environments.d.ts.map +1 -0
  54. package/dist/routes/git-gateway.d.ts +21 -0
  55. package/dist/routes/git-gateway.d.ts.map +1 -0
  56. package/dist/routes/http-gateway.d.ts +13 -0
  57. package/dist/routes/http-gateway.d.ts.map +1 -0
  58. package/dist/routes/me.d.ts +12 -0
  59. package/dist/routes/me.d.ts.map +1 -0
  60. package/dist/routes/memberships.d.ts +12 -0
  61. package/dist/routes/memberships.d.ts.map +1 -0
  62. package/dist/routes/model-gateway.d.ts +12 -0
  63. package/dist/routes/model-gateway.d.ts.map +1 -0
  64. package/dist/routes/notifications.d.ts +4 -0
  65. package/dist/routes/notifications.d.ts.map +1 -0
  66. package/dist/routes/parse.d.ts +5 -0
  67. package/dist/routes/parse.d.ts.map +1 -0
  68. package/dist/routes/personal-environment.d.ts +13 -0
  69. package/dist/routes/personal-environment.d.ts.map +1 -0
  70. package/dist/routes/plugins.d.ts +4 -0
  71. package/dist/routes/plugins.d.ts.map +1 -0
  72. package/dist/routes/project-mcp.d.ts +25 -0
  73. package/dist/routes/project-mcp.d.ts.map +1 -0
  74. package/dist/routes/projects.d.ts +4 -0
  75. package/dist/routes/projects.d.ts.map +1 -0
  76. package/dist/routes/publications.d.ts +15 -0
  77. package/dist/routes/publications.d.ts.map +1 -0
  78. package/dist/routes/run-errors.d.ts +8 -0
  79. package/dist/routes/run-errors.d.ts.map +1 -0
  80. package/dist/routes/runs.d.ts +4 -0
  81. package/dist/routes/runs.d.ts.map +1 -0
  82. package/dist/routes/session-artifacts.d.ts +27 -0
  83. package/dist/routes/session-artifacts.d.ts.map +1 -0
  84. package/dist/routes/session-mailboxes.d.ts +4 -0
  85. package/dist/routes/session-mailboxes.d.ts.map +1 -0
  86. package/dist/routes/session-previews.d.ts +40 -0
  87. package/dist/routes/session-previews.d.ts.map +1 -0
  88. package/dist/routes/session-terminals.d.ts +15 -0
  89. package/dist/routes/session-terminals.d.ts.map +1 -0
  90. package/dist/routes/triggers.d.ts +20 -0
  91. package/dist/routes/triggers.d.ts.map +1 -0
  92. package/dist/routes/watchers.d.ts +4 -0
  93. package/dist/routes/watchers.d.ts.map +1 -0
  94. package/dist/routes/webhooks.d.ts +11 -0
  95. package/dist/routes/webhooks.d.ts.map +1 -0
  96. package/dist/routes/workflow-enablements.d.ts +4 -0
  97. package/dist/routes/workflow-enablements.d.ts.map +1 -0
  98. package/dist/routes/workflows.d.ts +4 -0
  99. package/dist/routes/workflows.d.ts.map +1 -0
  100. package/dist/schemas.d.ts +17776 -0
  101. package/dist/schemas.d.ts.map +1 -0
  102. package/dist/session-artifact-tools.d.ts +5 -0
  103. package/dist/session-artifact-tools.d.ts.map +1 -0
  104. package/dist/session-event-stream.d.ts +45 -0
  105. package/dist/session-event-stream.d.ts.map +1 -0
  106. package/dist/spa.d.ts +24 -0
  107. package/dist/spa.d.ts.map +1 -0
  108. package/dist/telemetry.d.ts +4 -0
  109. package/dist/telemetry.d.ts.map +1 -0
  110. package/package.json +73 -4
  111. package/src/app-presentation-tools.ts +46 -0
  112. package/src/app.ts +115 -0
  113. package/src/http-identity.ts +145 -0
  114. package/src/hung-up.ts +13 -0
  115. package/src/index.ts +25 -0
  116. package/src/mcp-shared.ts +331 -0
  117. package/src/mcp.ts +10 -0
  118. package/src/plugin.ts +332 -0
  119. package/src/project-capabilities.ts +153 -0
  120. package/src/project-mcp-program.ts +607 -0
  121. package/src/project-mcp-surface.ts +881 -0
  122. package/src/request-logging.ts +47 -0
  123. package/src/routes/agent-capabilities.ts +109 -0
  124. package/src/routes/agent.ts +1566 -0
  125. package/src/routes/apps-mcp.ts +303 -0
  126. package/src/routes/apps.ts +692 -0
  127. package/src/routes/client-runners.ts +251 -0
  128. package/src/routes/code-hosts.ts +247 -0
  129. package/src/routes/connection-mcp.ts +135 -0
  130. package/src/routes/connections.ts +494 -0
  131. package/src/routes/documents.ts +538 -0
  132. package/src/routes/environments.ts +72 -0
  133. package/src/routes/git-gateway.ts +106 -0
  134. package/src/routes/http-gateway.ts +141 -0
  135. package/src/routes/me.ts +122 -0
  136. package/src/routes/memberships.ts +173 -0
  137. package/src/routes/model-gateway.ts +134 -0
  138. package/src/routes/notifications.ts +101 -0
  139. package/src/routes/parse.ts +32 -0
  140. package/src/routes/personal-environment.ts +146 -0
  141. package/src/routes/plugins.ts +341 -0
  142. package/src/routes/project-mcp.ts +394 -0
  143. package/src/routes/projects.ts +708 -0
  144. package/src/routes/publications.ts +222 -0
  145. package/src/routes/run-errors.ts +86 -0
  146. package/src/routes/runs.ts +253 -0
  147. package/src/routes/session-artifacts.ts +293 -0
  148. package/src/routes/session-mailboxes.ts +80 -0
  149. package/src/routes/session-previews.ts +224 -0
  150. package/src/routes/session-terminals.ts +209 -0
  151. package/src/routes/triggers.ts +241 -0
  152. package/src/routes/watchers.ts +94 -0
  153. package/src/routes/webhooks.ts +171 -0
  154. package/src/routes/workflow-enablements.ts +331 -0
  155. package/src/routes/workflows.ts +323 -0
  156. package/src/schemas.ts +2735 -0
  157. package/src/session-artifact-tools.ts +170 -0
  158. package/src/session-event-stream.ts +122 -0
  159. package/src/spa.ts +135 -0
  160. package/src/telemetry.ts +93 -0
@@ -0,0 +1,494 @@
1
+ import {
2
+ CONNECTION_ALIAS_PATTERN,
3
+ CONNECTION_NAME_PATTERN,
4
+ ConnectionNameTakenError,
5
+ ConnectionNotFoundError,
6
+ ConnectionPermissionDeniedError,
7
+ ConnectionUnavailableError,
8
+ } from "@catamorphic/core";
9
+ import type { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
10
+ import type { ZodTypeProvider } from "fastify-type-provider-zod";
11
+ import { z } from "zod";
12
+ import type { RouteContext } from "../app.js";
13
+ import { resolveIdentity } from "../http-identity.js";
14
+ import {
15
+ AuthorizationChallengeSchema,
16
+ ConnectionBindingSchema,
17
+ ConnectionRecordSchema,
18
+ ErrorSchema,
19
+ ProjectIdParamsSchema,
20
+ } from "../schemas.js";
21
+
22
+ const EnvironmentParams = ProjectIdParamsSchema.extend({
23
+ environment: z.string().min(1),
24
+ });
25
+ const BindingParams = EnvironmentParams.extend({
26
+ alias: z.string().regex(CONNECTION_ALIAS_PATTERN),
27
+ });
28
+ const AuditEventSchema = z.object({
29
+ id: z.string(),
30
+ projectId: z.string().uuid().nullable(),
31
+ connectionId: z.string().uuid().nullable(),
32
+ allocationId: z.string().uuid().nullable(),
33
+ actorExternalUserId: z.string().nullable(),
34
+ eventType: z.string(),
35
+ outcome: z.string(),
36
+ action: z.string().nullable(),
37
+ argumentsDigest: z.string().nullable(),
38
+ metadata: z.unknown(),
39
+ createdAt: z.string().datetime(),
40
+ });
41
+
42
+ export function registerConnectionRoutes(
43
+ app: FastifyInstance,
44
+ ctx: RouteContext,
45
+ ): void {
46
+ const typed = app.withTypeProvider<ZodTypeProvider>();
47
+ const service = () => ctx.core?.connections;
48
+ const apiBase = (request: FastifyRequest) =>
49
+ ctx.publicApiBase ??
50
+ `${request.protocol}://${request.host}${app.prefix}`.replace(/\/$/, "");
51
+
52
+ typed.route({
53
+ method: "GET",
54
+ url: "/connection-providers",
55
+ schema: {
56
+ response: {
57
+ 200: z.array(z.object({ kind: z.string(), displayName: z.string() })),
58
+ 503: ErrorSchema,
59
+ },
60
+ },
61
+ handler: async (_request, reply) => {
62
+ const connections = service();
63
+ return connections
64
+ ? reply.send(connections.providerCatalog())
65
+ : reply.status(503).send({ error: "Connections not configured" });
66
+ },
67
+ });
68
+
69
+ typed.route({
70
+ method: "GET",
71
+ url: "/projects/:projectId/connections",
72
+ schema: {
73
+ params: ProjectIdParamsSchema,
74
+ response: { 200: z.array(ConnectionRecordSchema), 503: ErrorSchema },
75
+ },
76
+ handler: async (request, reply) => {
77
+ const connections = service();
78
+ if (!connections)
79
+ return reply.status(503).send({ error: "Connections not configured" });
80
+ return reply.send(
81
+ await connections.list({
82
+ identity: resolveIdentity(request),
83
+ projectId: request.params.projectId,
84
+ }),
85
+ );
86
+ },
87
+ });
88
+
89
+ // Named service connections (ADR 0172): created by a connection
90
+ // administrator, authorized (and rotated) through the provider's own
91
+ // challenge, and bound to Environments by name in `.work/project.json`.
92
+ typed.route({
93
+ method: "GET",
94
+ url: "/service-connections",
95
+ schema: {
96
+ querystring: z.object({ projectId: z.string().uuid().optional() }),
97
+ response: {
98
+ 200: z.array(ConnectionRecordSchema),
99
+ 403: ErrorSchema,
100
+ 503: ErrorSchema,
101
+ },
102
+ },
103
+ handler: async (request, reply) => {
104
+ const connections = service();
105
+ if (!connections)
106
+ return reply.status(503).send({ error: "Connections not configured" });
107
+ try {
108
+ return reply.send(
109
+ await connections.listServices({
110
+ identity: resolveIdentity(request),
111
+ ...(request.query.projectId
112
+ ? { projectId: request.query.projectId }
113
+ : {}),
114
+ }),
115
+ );
116
+ } catch (error) {
117
+ return handleConnectionError(error, reply);
118
+ }
119
+ },
120
+ });
121
+
122
+ typed.route({
123
+ method: "POST",
124
+ url: "/service-connections",
125
+ schema: {
126
+ body: z.object({
127
+ name: z.string().regex(CONNECTION_NAME_PATTERN),
128
+ providerKind: z.string().min(1),
129
+ principalKind: z.enum(["tenant_service", "project_service"]),
130
+ /** Required for a `project_service` connection. */
131
+ projectId: z.string().uuid().optional(),
132
+ label: z.string().min(1).max(200).optional(),
133
+ }),
134
+ response: {
135
+ 201: ConnectionRecordSchema,
136
+ 400: ErrorSchema,
137
+ 403: ErrorSchema,
138
+ 409: ErrorSchema,
139
+ 503: ErrorSchema,
140
+ },
141
+ },
142
+ handler: async (request, reply) => {
143
+ const connections = service();
144
+ if (!connections)
145
+ return reply.status(503).send({ error: "Connections not configured" });
146
+ if (
147
+ request.body.principalKind === "project_service" &&
148
+ !request.body.projectId
149
+ ) {
150
+ return reply
151
+ .status(400)
152
+ .send({ error: "A project service connection names its project" });
153
+ }
154
+ if (
155
+ !connections
156
+ .providerCatalog()
157
+ .some((provider) => provider.kind === request.body.providerKind)
158
+ ) {
159
+ return reply.status(400).send({
160
+ error: `Unknown connection provider '${request.body.providerKind}'`,
161
+ });
162
+ }
163
+ try {
164
+ const record = await connections.createService({
165
+ identity: resolveIdentity(request),
166
+ name: request.body.name,
167
+ providerKind: request.body.providerKind,
168
+ principalKind: request.body.principalKind,
169
+ ...(request.body.projectId
170
+ ? { projectId: request.body.projectId }
171
+ : {}),
172
+ ...(request.body.label ? { label: request.body.label } : {}),
173
+ });
174
+ return reply.status(201).send(record);
175
+ } catch (error) {
176
+ return handleConnectionError(error, reply);
177
+ }
178
+ },
179
+ });
180
+
181
+ typed.route({
182
+ method: "POST",
183
+ url: "/service-connections/:connectionId/authorize",
184
+ schema: {
185
+ params: z.object({ connectionId: z.string().uuid() }),
186
+ response: {
187
+ 200: z.object({
188
+ authorizationId: z.string().min(1),
189
+ challenge: AuthorizationChallengeSchema,
190
+ }),
191
+ 403: ErrorSchema,
192
+ 404: ErrorSchema,
193
+ 409: ErrorSchema,
194
+ 503: ErrorSchema,
195
+ },
196
+ },
197
+ handler: async (request, reply) => {
198
+ const connections = service();
199
+ if (!connections)
200
+ return reply.status(503).send({ error: "Connections not configured" });
201
+ try {
202
+ return reply.send(
203
+ await connections.beginServiceAuthorization({
204
+ identity: resolveIdentity(request),
205
+ connectionId: request.params.connectionId,
206
+ // A service authorization always returns to this server's own
207
+ // callback, the redirect a pre-registered OAuth client lists.
208
+ redirectUri: `${apiBase(request)}/connection-authorizations/callback`,
209
+ }),
210
+ );
211
+ } catch (error) {
212
+ return handleConnectionError(error, reply);
213
+ }
214
+ },
215
+ });
216
+
217
+ typed.route({
218
+ method: "DELETE",
219
+ url: "/projects/:projectId/environments/:environment/connections/:alias/attachment",
220
+ schema: {
221
+ params: BindingParams,
222
+ response: {
223
+ 204: z.null(),
224
+ 403: ErrorSchema,
225
+ 503: ErrorSchema,
226
+ },
227
+ },
228
+ handler: async (request, reply) => {
229
+ const connections = service();
230
+ if (!connections)
231
+ return reply.status(503).send({ error: "Connections not configured" });
232
+ try {
233
+ await connections.detachMember({
234
+ identity: resolveIdentity(request),
235
+ projectId: request.params.projectId,
236
+ environment: request.params.environment,
237
+ alias: request.params.alias,
238
+ });
239
+ return reply.status(204).send(null);
240
+ } catch (error) {
241
+ return handleConnectionError(error, reply);
242
+ }
243
+ },
244
+ });
245
+
246
+ typed.route({
247
+ method: "GET",
248
+ url: "/projects/:projectId/connection-audit",
249
+ schema: {
250
+ params: ProjectIdParamsSchema,
251
+ querystring: z.object({
252
+ limit: z.coerce.number().int().min(1).max(500).optional(),
253
+ }),
254
+ response: {
255
+ 200: z.array(AuditEventSchema),
256
+ 403: ErrorSchema,
257
+ 503: ErrorSchema,
258
+ },
259
+ },
260
+ handler: async (request, reply) => {
261
+ const connections = service();
262
+ if (!connections)
263
+ return reply.status(503).send({ error: "Connections not configured" });
264
+ try {
265
+ return reply.send(
266
+ await connections.listAudit({
267
+ identity: resolveIdentity(request),
268
+ projectId: request.params.projectId,
269
+ limit: request.query.limit,
270
+ }),
271
+ );
272
+ } catch (error) {
273
+ return handleConnectionError(error, reply);
274
+ }
275
+ },
276
+ });
277
+
278
+ typed.route({
279
+ method: "GET",
280
+ url: "/projects/:projectId/environments/:environment/connections",
281
+ schema: {
282
+ params: EnvironmentParams,
283
+ response: {
284
+ 200: z.array(ConnectionBindingSchema),
285
+ 403: ErrorSchema,
286
+ 503: ErrorSchema,
287
+ },
288
+ },
289
+ handler: async (request, reply) => {
290
+ const connections = service();
291
+ if (!connections)
292
+ return reply.status(503).send({ error: "Connections not configured" });
293
+ try {
294
+ return reply.send(
295
+ await connections.listBindings({
296
+ identity: resolveIdentity(request),
297
+ projectId: request.params.projectId,
298
+ environment: request.params.environment,
299
+ }),
300
+ );
301
+ } catch (error) {
302
+ return handleConnectionError(error, reply);
303
+ }
304
+ },
305
+ });
306
+
307
+ typed.route({
308
+ method: "POST",
309
+ url: "/projects/:projectId/environments/:environment/connections/:alias/authorize",
310
+ schema: {
311
+ params: BindingParams,
312
+ body: z.object({ redirectUri: z.string().url() }),
313
+ response: {
314
+ 200: z.object({
315
+ authorizationId: z.string().min(1),
316
+ challenge: AuthorizationChallengeSchema,
317
+ }),
318
+ 403: ErrorSchema,
319
+ 409: ErrorSchema,
320
+ 503: ErrorSchema,
321
+ },
322
+ },
323
+ handler: async (request, reply) => {
324
+ const connections = service();
325
+ if (!connections)
326
+ return reply.status(503).send({ error: "Connections not configured" });
327
+ try {
328
+ return reply.send(
329
+ await connections.beginAuthorization({
330
+ identity: resolveIdentity(request),
331
+ projectId: request.params.projectId,
332
+ environment: request.params.environment,
333
+ alias: request.params.alias,
334
+ redirectUri: request.body.redirectUri,
335
+ }),
336
+ );
337
+ } catch (error) {
338
+ return handleConnectionError(error, reply);
339
+ }
340
+ },
341
+ });
342
+
343
+ typed.route({
344
+ method: "POST",
345
+ url: "/connection-authorizations/complete",
346
+ schema: {
347
+ body: z.object({
348
+ state: z.string().min(1),
349
+ callback: z.record(z.string(), z.string()),
350
+ }),
351
+ response: {
352
+ 200: ConnectionRecordSchema,
353
+ 403: ErrorSchema,
354
+ 409: ErrorSchema,
355
+ 503: ErrorSchema,
356
+ },
357
+ },
358
+ handler: async (request, reply) => {
359
+ const connections = service();
360
+ if (!connections)
361
+ return reply.status(503).send({ error: "Connections not configured" });
362
+ try {
363
+ return reply.send(
364
+ await connections.completeAuthorization({
365
+ identity: resolveIdentity(request),
366
+ state: request.body.state,
367
+ callback: request.body.callback,
368
+ }),
369
+ );
370
+ } catch (error) {
371
+ return handleConnectionError(error, reply);
372
+ }
373
+ },
374
+ });
375
+
376
+ typed.route({
377
+ method: "POST",
378
+ url: "/connection-authorizations/status",
379
+ schema: {
380
+ body: z.object({ state: z.string().min(1) }),
381
+ response: {
382
+ 200: z.object({ status: z.string() }),
383
+ 409: ErrorSchema,
384
+ 503: ErrorSchema,
385
+ },
386
+ },
387
+ handler: async (request, reply) => {
388
+ const connections = service();
389
+ if (!connections)
390
+ return reply.status(503).send({ error: "Connections not configured" });
391
+ try {
392
+ return reply.send(
393
+ await connections.authorizationStatus({
394
+ identity: resolveIdentity(request),
395
+ state: request.body.state,
396
+ }),
397
+ );
398
+ } catch (error) {
399
+ return handleConnectionError(error, reply);
400
+ }
401
+ },
402
+ });
403
+
404
+ typed.route({
405
+ method: "GET",
406
+ url: "/connection-authorizations/callback",
407
+ config: { public: true },
408
+ schema: {
409
+ querystring: z.object({
410
+ state: z.string().min(1),
411
+ code: z.string().optional(),
412
+ iss: z.string().optional(),
413
+ error: z.string().optional(),
414
+ error_description: z.string().optional(),
415
+ }),
416
+ response: {
417
+ 200: ConnectionRecordSchema,
418
+ 409: ErrorSchema,
419
+ 503: ErrorSchema,
420
+ },
421
+ },
422
+ handler: async (request, reply) => {
423
+ const connections = service();
424
+ if (!connections)
425
+ return reply.status(503).send({ error: "Connections not configured" });
426
+ try {
427
+ if (request.query.error) {
428
+ throw new ConnectionUnavailableError(
429
+ "authorization",
430
+ "Authorization was declined",
431
+ );
432
+ }
433
+ return reply.send(
434
+ await connections.completeAuthorizationCallback({
435
+ state: request.query.state,
436
+ callback: {
437
+ ...(request.query.code ? { code: request.query.code } : {}),
438
+ ...(request.query.iss ? { iss: request.query.iss } : {}),
439
+ },
440
+ }),
441
+ );
442
+ } catch (error) {
443
+ return handleConnectionError(error, reply);
444
+ }
445
+ },
446
+ });
447
+
448
+ typed.route({
449
+ method: "DELETE",
450
+ url: "/connections/:connectionId",
451
+ schema: {
452
+ params: z.object({ connectionId: z.string().uuid() }),
453
+ response: {
454
+ 204: z.null(),
455
+ 403: ErrorSchema,
456
+ 404: ErrorSchema,
457
+ 503: ErrorSchema,
458
+ },
459
+ },
460
+ handler: async (request, reply) => {
461
+ const connections = service();
462
+ if (!connections)
463
+ return reply.status(503).send({ error: "Connections not configured" });
464
+ try {
465
+ await connections.revoke({
466
+ identity: resolveIdentity(request),
467
+ connectionId: request.params.connectionId,
468
+ });
469
+ return reply.status(204).send(null);
470
+ } catch (error) {
471
+ return handleConnectionError(error, reply);
472
+ }
473
+ },
474
+ });
475
+ }
476
+
477
+ function handleConnectionError(
478
+ error: unknown,
479
+ reply: FastifyReply,
480
+ ): FastifyReply {
481
+ if (error instanceof ConnectionPermissionDeniedError) {
482
+ return reply.status(403).send({ error: error.message });
483
+ }
484
+ if (error instanceof ConnectionNotFoundError) {
485
+ return reply.status(404).send({ error: error.message });
486
+ }
487
+ if (error instanceof ConnectionNameTakenError) {
488
+ return reply.status(409).send({ error: error.message });
489
+ }
490
+ if (error instanceof ConnectionUnavailableError) {
491
+ return reply.status(409).send({ error: error.message });
492
+ }
493
+ throw error;
494
+ }