Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

environmentHttp.ts

686 lines23.1 KB

1import * as Context from "effect/Context";
2import type * as DateTime from "effect/DateTime";
3import * as Schema from "effect/Schema";
4import * as HttpApi from "effect/http-api/HttpApi";
5import * as HttpApiEndpoint from "effect/http-api/HttpApiEndpoint";
6import * as HttpApiGroup from "effect/http-api/HttpApiGroup";
7import * as HttpApiMiddleware from "effect/http-api/HttpApiMiddleware";
8import * as HttpApiSchema from "effect/http-api/HttpApiSchema";
9import * as HttpServerRespondable from "effect/http/HttpServerRespondable";
10import * as HttpServerResponse from "effect/http/HttpServerResponse";
11​
12import {
13 AuthAccessTokenResult,
14 AuthBrowserSessionRequest,
15 AuthBrowserSessionResult,
16 AuthClientSession,
17 AuthCreatePairingCredentialInput,
18 AuthPairingCredentialResult,
19 AuthPairingLink,
20 AuthRevokeClientSessionInput,
21 AuthRevokePairingLinkInput,
22 AuthEnvironmentScope,
23 AuthTokenExchangeRequest,
24 AuthSessionState,
25 AuthWebSocketTicketResult,
26 ServerAuthSessionMethod,
27} from "./auth.ts";
28import {
29 ExecutionEnvironmentDescriptor,
30 ORCHESTRATION_PROTOCOL_HEADER,
31 ORCHESTRATION_PROTOCOL_VERSION_TEXT,
32} from "./environment.ts";
33import {
34 DpopFailureReason,
35 AuthSessionId,
36 ThreadId,
37 TrimmedNonEmptyString,
38} from "./baseSchemas.ts";
39import {
40 OrchestrationV2ShellSnapshot,
41 OrchestrationV2ThreadBoundedSnapshot,
42 OrchestrationV2ThreadDetailSnapshot,
43 OrchestrationV2ThreadHistoryPage,
44} from "./orchestrationV2.ts";
45import { Project, ProjectMutation, ProjectSnapshot } from "./project.ts";
46import {
47 PullRequestDiffInput,
48 PullRequestDiffResult,
49 PullRequestOperationError,
50 PullRequestUnavailableError,
51} from "./pullRequest.ts";
52import {
53 RelayCloudEnvironmentHealthRequest,
54 RelayCloudMintCredentialRequest,
55 RelayEnvironmentConfigRequest,
56 RelayEnvironmentHealthResponse,
57 RelayEnvironmentLinkProof,
58 RelayEnvironmentMintResponse,
59 RelayLinkProofRequest,
60} from "./relay.ts";
61​
62const OptionalBearerHeaders = Schema.Struct({
63 authorization: Schema.optionalKey(Schema.String),
64 dpop: Schema.optionalKey(Schema.String),
65});
66​
67const OrchestrationProtocolHeaders = Schema.Struct({
68 authorization: Schema.optionalKey(Schema.String),
69 dpop: Schema.optionalKey(Schema.String),
70 [ORCHESTRATION_PROTOCOL_HEADER]: Schema.Literal(ORCHESTRATION_PROTOCOL_VERSION_TEXT),
71});
72​
73const OptionalDpopProofHeaders = Schema.Struct({
74 dpop: Schema.optionalKey(Schema.String),
75});
76​
77export const EnvironmentRequestInvalidReason = Schema.Literals([
78 "invalid_scope",
79 "scope_not_granted",
80 "invalid_command",
81 "invalid_history_cursor",
82]);
83export type EnvironmentRequestInvalidReason = typeof EnvironmentRequestInvalidReason.Type;
84​
85export const EnvironmentAuthInvalidReason = Schema.Literals([
86 "missing_credential",
87 "invalid_credential",
88]);
89export type EnvironmentAuthInvalidReason = typeof EnvironmentAuthInvalidReason.Type;
90​
91export const EnvironmentOperationForbiddenReason = Schema.Literals([
92 "current_session_revoke_not_allowed",
93]);
94export type EnvironmentOperationForbiddenReason = typeof EnvironmentOperationForbiddenReason.Type;
95​
96export const EnvironmentInternalErrorReason = Schema.Literals([
97 "bootstrap_validation_failed",
98 "browser_session_issuance_failed",
99 "browser_session_cookie_failed",
100 "access_token_issuance_failed",
101 "websocket_ticket_issuance_failed",
102 "pairing_credential_issuance_failed",
103 "pairing_links_load_failed",
104 "pairing_link_revoke_failed",
105 "client_sessions_load_failed",
106 "client_session_revoke_failed",
107 "project_snapshot_failed",
108 "project_mutation_failed",
109 "orchestration_snapshot_failed",
110 "orchestration_thread_snapshot_failed",
111 "orchestration_thread_bounded_snapshot_failed",
112 "orchestration_thread_history_failed",
113 "internal_error",
114]);
115export type EnvironmentInternalErrorReason = typeof EnvironmentInternalErrorReason.Type;
116​
117export class EnvironmentRequestInvalidError extends Schema.TaggedError<EnvironmentRequestInvalidError>()(
118 "EnvironmentRequestInvalidError",
119 {
120 code: Schema.Literal("invalid_request"),
121 reason: EnvironmentRequestInvalidReason,
122 traceId: TrimmedNonEmptyString,
123 },
124 { httpApiStatus: 400 },
125) {
126 [HttpServerRespondable.symbol]() {
127 return HttpServerResponse.schemaJson(EnvironmentRequestInvalidError)(this, { status: 400 });
128 }
129​
130 override get message(): string {
131 return `The environment rejected the request (${this.reason}).`;
132 }
134​
135export class EnvironmentAuthInvalidError extends Schema.TaggedError<EnvironmentAuthInvalidError>()(
136 "EnvironmentAuthInvalidError",
137 {
138 code: Schema.Literal("auth_invalid"),
139 reason: EnvironmentAuthInvalidReason,
140 // Older servers do not send a DPoP failure category.
141 dpopFailureReason: Schema.optionalKey(DpopFailureReason),
142 traceId: TrimmedNonEmptyString,
143 },
144 { httpApiStatus: 401 },
145) {
146 [HttpServerRespondable.symbol]() {
147 return HttpServerResponse.schemaJson(EnvironmentAuthInvalidError)(this, { status: 401 });
148 }
149​
150 override get message(): string {
151 return `The environment rejected this client's credentials (${this.reason}).`;
152 }
154​
155export class EnvironmentScopeRequiredError extends Schema.TaggedError<EnvironmentScopeRequiredError>()(
156 "EnvironmentScopeRequiredError",
157 {
158 code: Schema.Literal("insufficient_scope"),
159 requiredScope: AuthEnvironmentScope,
160 traceId: TrimmedNonEmptyString,
161 },
162 { httpApiStatus: 403 },
163) {
164 [HttpServerRespondable.symbol]() {
165 return HttpServerResponse.schemaJson(EnvironmentScopeRequiredError)(this, { status: 403 });
166 }
167​
168 override get message(): string {
169 return `This request needs the ${this.requiredScope} scope, which this client does not have.`;
170 }
172​
173export class EnvironmentOperationForbiddenError extends Schema.TaggedError<EnvironmentOperationForbiddenError>()(
174 "EnvironmentOperationForbiddenError",
175 {
176 code: Schema.Literal("operation_forbidden"),
177 reason: EnvironmentOperationForbiddenReason,
178 traceId: TrimmedNonEmptyString,
179 },
180 { httpApiStatus: 403 },
181) {
182 [HttpServerRespondable.symbol]() {
183 return HttpServerResponse.schemaJson(EnvironmentOperationForbiddenError)(this, { status: 403 });
184 }
185​
186 override get message(): string {
187 return `The environment refused this operation (${this.reason}).`;
188 }
190​
191export class EnvironmentInternalError extends Schema.TaggedError<EnvironmentInternalError>()(
192 "EnvironmentInternalError",
193 {
194 code: Schema.Literal("internal_error"),
195 reason: EnvironmentInternalErrorReason,
196 traceId: TrimmedNonEmptyString,
197 },
198 { httpApiStatus: 500 },
199) {
200 [HttpServerRespondable.symbol]() {
201 return HttpServerResponse.schemaJson(EnvironmentInternalError)(this, { status: 500 });
202 }
203​
204 override get message(): string {
205 return `The environment failed to answer this request (${this.reason}).`;
206 }
208​
209export const EnvironmentResourceNotFoundReason = Schema.Literals(["thread_not_found"]);
210export type EnvironmentResourceNotFoundReason = typeof EnvironmentResourceNotFoundReason.Type;
211​
212export class EnvironmentResourceNotFoundError extends Schema.TaggedError<EnvironmentResourceNotFoundError>()(
213 "EnvironmentResourceNotFoundError",
214 {
215 code: Schema.Literal("not_found"),
216 reason: EnvironmentResourceNotFoundReason,
217 traceId: TrimmedNonEmptyString,
218 },
219 { httpApiStatus: 404 },
220) {
221 [HttpServerRespondable.symbol]() {
222 return HttpServerResponse.schemaJson(EnvironmentResourceNotFoundError)(this, { status: 404 });
223 }
224​
225 override get message(): string {
226 return `The environment could not find what this request named (${this.reason}).`;
227 }
229​
230export const EnvironmentHttpCommonError = Schema.Union([
231 EnvironmentRequestInvalidError,
232 EnvironmentAuthInvalidError,
233 EnvironmentScopeRequiredError,
234 EnvironmentOperationForbiddenError,
235 EnvironmentResourceNotFoundError,
236 EnvironmentInternalError,
237]);
238export type EnvironmentHttpCommonError = typeof EnvironmentHttpCommonError.Type;
239​
240const EnvironmentAuthenticationErrors = [
241 EnvironmentAuthInvalidError,
242 EnvironmentInternalError,
243] as const;
244​
245export class EnvironmentHttpBadRequestError extends Schema.TaggedError<EnvironmentHttpBadRequestError>()(
246 "EnvironmentHttpBadRequestError",
247 {
248 message: Schema.String,
249 },
250 { httpApiStatus: 400 },
251) {
252 [HttpServerRespondable.symbol]() {
253 return HttpServerResponse.schemaJson(EnvironmentHttpBadRequestError)(this, { status: 400 });
254 }
256​
257export class EnvironmentHttpUnauthorizedError extends Schema.TaggedError<EnvironmentHttpUnauthorizedError>()(
258 "EnvironmentHttpUnauthorizedError",
259 {
260 message: Schema.String,
261 },
262 { httpApiStatus: 401 },
263) {
264 [HttpServerRespondable.symbol]() {
265 return HttpServerResponse.schemaJson(EnvironmentHttpUnauthorizedError)(this, { status: 401 });
266 }
268​
269export class EnvironmentHttpForbiddenError extends Schema.TaggedError<EnvironmentHttpForbiddenError>()(
270 "EnvironmentHttpForbiddenError",
271 {
272 message: Schema.String,
273 },
274 { httpApiStatus: 403 },
275) {
276 [HttpServerRespondable.symbol]() {
277 return HttpServerResponse.schemaJson(EnvironmentHttpForbiddenError)(this, { status: 403 });
278 }
280​
281export class EnvironmentHttpInternalServerError extends Schema.TaggedError<EnvironmentHttpInternalServerError>()(
282 "EnvironmentHttpInternalServerError",
283 {
284 message: Schema.String,
285 },
286 { httpApiStatus: 500 },
287) {
288 [HttpServerRespondable.symbol]() {
289 return HttpServerResponse.schemaJson(EnvironmentHttpInternalServerError)(this, { status: 500 });
290 }
292​
293export class EnvironmentHttpConflictError extends Schema.TaggedError<EnvironmentHttpConflictError>()(
294 "EnvironmentHttpConflictError",
295 {
296 message: Schema.String,
297 },
298 { httpApiStatus: 409 },
299) {
300 [HttpServerRespondable.symbol]() {
301 return HttpServerResponse.schemaJson(EnvironmentHttpConflictError)(this, { status: 409 });
302 }
304​
305export class EnvironmentCloudEndpointUnavailableError extends Schema.TaggedError<EnvironmentCloudEndpointUnavailableError>()(
306 "EnvironmentCloudEndpointUnavailableError",
307 {
308 message: Schema.String,
309 endpointRuntimeStatus: Schema.Unknown,
310 },
311 { httpApiStatus: 503 },
312) {
313 [HttpServerRespondable.symbol]() {
314 return HttpServerResponse.schemaJson(EnvironmentCloudEndpointUnavailableError)(this, {
315 status: 503,
316 });
317 }
319const EnvironmentSessionCreationErrors = [
320 EnvironmentAuthInvalidError,
321 EnvironmentInternalError,
322] as const;
323const EnvironmentTokenExchangeErrors = [
324 EnvironmentRequestInvalidError,
325 EnvironmentAuthInvalidError,
326 EnvironmentInternalError,
327] as const;
328const EnvironmentScopedOperationErrors = [
329 EnvironmentScopeRequiredError,
330 EnvironmentInternalError,
331] as const;
332const EnvironmentPairingCredentialErrors = [
333 EnvironmentRequestInvalidError,
334 ...EnvironmentScopedOperationErrors,
335] as const;
336const EnvironmentSessionRevokeErrors = [
337 EnvironmentScopeRequiredError,
338 EnvironmentOperationForbiddenError,
339 EnvironmentInternalError,
340] as const;
341const EnvironmentProjectSnapshotErrors = [
342 EnvironmentScopeRequiredError,
343 EnvironmentInternalError,
344] as const;
345const EnvironmentOrchestrationSnapshotErrors = [
346 EnvironmentScopeRequiredError,
347 EnvironmentInternalError,
348] as const;
349const EnvironmentOrchestrationThreadSnapshotErrors = [
350 EnvironmentScopeRequiredError,
351 EnvironmentResourceNotFoundError,
352 EnvironmentInternalError,
353] as const;
354const EnvironmentProjectMutationErrors = [
355 EnvironmentRequestInvalidError,
356 EnvironmentScopeRequiredError,
357 EnvironmentInternalError,
358] as const;
359​
360export interface EnvironmentSessionPrincipalShape {
361 readonly sessionId: AuthSessionId;
362 readonly subject: string;
363 readonly method: ServerAuthSessionMethod;
364 readonly scopes: ReadonlySet<AuthEnvironmentScope>;
365 readonly proofKeyThumbprint?: string;
366 readonly expiresAt?: DateTime.DateTime;
368​
369export class EnvironmentAuthenticatedPrincipal extends Context.Service<
370 EnvironmentAuthenticatedPrincipal,
371 EnvironmentSessionPrincipalShape
372>()("@t3tools/contracts/environmentHttp/EnvironmentAuthenticatedPrincipal") {}
373​
374export class EnvironmentAuthenticatedAuth extends HttpApiMiddleware.Service<
375 EnvironmentAuthenticatedAuth,
376 { provides: EnvironmentAuthenticatedPrincipal }
377>()("EnvironmentAuthenticatedAuth", {
378 error: EnvironmentAuthenticationErrors,
379}) {}
380​
381const EnvironmentHttpCloudErrors = [
382 EnvironmentHttpBadRequestError,
383 EnvironmentHttpUnauthorizedError,
384 EnvironmentHttpForbiddenError,
385 EnvironmentHttpConflictError,
386 EnvironmentHttpInternalServerError,
387 EnvironmentScopeRequiredError,
388] as const;
389​
390export const EnvironmentCloudRelayConfigResult = Schema.Struct({
391 ok: Schema.Boolean,
392 endpointRuntimeStatus: Schema.Unknown,
393});
394export type EnvironmentCloudRelayConfigResult = typeof EnvironmentCloudRelayConfigResult.Type;
395​
396export const EnvironmentCloudLinkStateResult = Schema.Struct({
397 linked: Schema.Boolean,
398 cloudUserId: Schema.NullOr(Schema.String),
399 relayUrl: Schema.NullOr(Schema.String),
400 relayIssuer: Schema.NullOr(Schema.String),
401 // A managed Cloudflare tunnel is provisioned for this link. False for a
402 // publish-only link (activity publishing without a relay-managed tunnel), so
403 // clients can present the two capabilities as independent settings.
404 // Optional so newer clients tolerate older environment servers.
405 managedTunnelActive: Schema.optional(Schema.Boolean),
406 publishAgentActivity: Schema.Boolean,
407});
408export type EnvironmentCloudLinkStateResult = typeof EnvironmentCloudLinkStateResult.Type;
409​
410export const EnvironmentCloudPreferencesRequest = Schema.Struct({
411 publishAgentActivity: Schema.Boolean,
412});
413export type EnvironmentCloudPreferencesRequest = typeof EnvironmentCloudPreferencesRequest.Type;
414​
415export const AuthPairingLinkRevokeResult = Schema.Struct({
416 revoked: Schema.Boolean,
417});
418export type AuthPairingLinkRevokeResult = typeof AuthPairingLinkRevokeResult.Type;
419​
420export const AuthClientSessionRevokeResult = Schema.Struct({
421 revoked: Schema.Boolean,
422});
423export type AuthClientSessionRevokeResult = typeof AuthClientSessionRevokeResult.Type;
424​
425export const AuthOtherClientSessionsRevokeResult = Schema.Struct({
426 revokedCount: Schema.Number,
427});
428export type AuthOtherClientSessionsRevokeResult = typeof AuthOtherClientSessionsRevokeResult.Type;
429​
430class EnvironmentMetadataHttpApi extends HttpApiGroup.make("metadata").add(
431 HttpApiEndpoint.get("descriptor", "/.well-known/t3/environment", {
432 success: ExecutionEnvironmentDescriptor,
433 }),
434) {}
435​
436class EnvironmentAuthHttpApi extends HttpApiGroup.make("auth")
437 .add(
438 HttpApiEndpoint.get("session", "/api/auth/session", {
439 headers: OptionalBearerHeaders,
440 success: AuthSessionState,
441 error: [EnvironmentInternalError],
442 }),
443 )
444 .add(
445 HttpApiEndpoint.post("browserSession", "/api/auth/browser-session", {
446 payload: AuthBrowserSessionRequest,
447 success: AuthBrowserSessionResult,
448 error: EnvironmentSessionCreationErrors,
449 }),
450 )
451 .add(
452 HttpApiEndpoint.post("token", "/oauth/token", {
453 headers: OptionalDpopProofHeaders,
454 payload: AuthTokenExchangeRequest,
455 success: AuthAccessTokenResult,
456 error: EnvironmentTokenExchangeErrors,
457 }),
458 )
459 .add(
460 HttpApiEndpoint.post("webSocketTicket", "/api/auth/websocket-ticket", {
461 headers: OptionalBearerHeaders,
462 success: AuthWebSocketTicketResult,
463 error: [EnvironmentInternalError],
464 }).middleware(EnvironmentAuthenticatedAuth),
465 )
466 .add(
467 HttpApiEndpoint.post("pairingCredential", "/api/auth/pairing-token", {
468 headers: OptionalBearerHeaders,
469 payload: AuthCreatePairingCredentialInput,
470 success: AuthPairingCredentialResult,
471 error: EnvironmentPairingCredentialErrors,
472 }).middleware(EnvironmentAuthenticatedAuth),
473 )
474 .add(
475 HttpApiEndpoint.get("pairingLinks", "/api/auth/pairing-links", {
476 headers: OptionalBearerHeaders,
477 success: Schema.Array(AuthPairingLink),
478 error: EnvironmentScopedOperationErrors,
479 }).middleware(EnvironmentAuthenticatedAuth),
480 )
481 .add(
482 HttpApiEndpoint.post("revokePairingLink", "/api/auth/pairing-links/revoke", {
483 headers: OptionalBearerHeaders,
484 payload: AuthRevokePairingLinkInput,
485 success: AuthPairingLinkRevokeResult,
486 error: EnvironmentScopedOperationErrors,
487 }).middleware(EnvironmentAuthenticatedAuth),
488 )
489 .add(
490 HttpApiEndpoint.get("clients", "/api/auth/clients", {
491 headers: OptionalBearerHeaders,
492 success: Schema.Array(AuthClientSession),
493 error: EnvironmentScopedOperationErrors,
494 }).middleware(EnvironmentAuthenticatedAuth),
495 )
496 .add(
497 HttpApiEndpoint.post("revokeClient", "/api/auth/clients/revoke", {
498 headers: OptionalBearerHeaders,
499 payload: AuthRevokeClientSessionInput,
500 success: AuthClientSessionRevokeResult,
501 error: EnvironmentSessionRevokeErrors,
502 }).middleware(EnvironmentAuthenticatedAuth),
503 )
504 .add(
505 HttpApiEndpoint.post("revokeOtherClients", "/api/auth/clients/revoke-others", {
506 headers: OptionalBearerHeaders,
507 success: AuthOtherClientSessionsRevokeResult,
508 error: EnvironmentScopedOperationErrors,
509 }).middleware(EnvironmentAuthenticatedAuth),
510 ) {}
511​
512const EnvironmentOrchestrationThreadSnapshotParams = Schema.Struct({
513 threadId: ThreadId,
514});
515​
516const EnvironmentOrchestrationThreadHistoryQuery = Schema.Struct({
517 cursor: TrimmedNonEmptyString,
518});
519​
520const EnvironmentOrchestrationThreadHistoryErrors = [
521 EnvironmentRequestInvalidError,
522 EnvironmentScopeRequiredError,
523 EnvironmentResourceNotFoundError,
524 EnvironmentInternalError,
525] as const;
526​
527class EnvironmentOrchestrationHttpApi extends HttpApiGroup.make("orchestration")
528 .add(
529 HttpApiEndpoint.get("shellSnapshot", "/api/orchestration/shell", {
530 headers: OrchestrationProtocolHeaders,
531 success: OrchestrationV2ShellSnapshot,
532 error: EnvironmentOrchestrationSnapshotErrors,
533 }).middleware(EnvironmentAuthenticatedAuth),
534 )
535 .add(
536 HttpApiEndpoint.get("threadSnapshot", "/api/orchestration/threads/:threadId", {
537 headers: OrchestrationProtocolHeaders,
538 params: EnvironmentOrchestrationThreadSnapshotParams,
539 success: OrchestrationV2ThreadDetailSnapshot,
540 error: EnvironmentOrchestrationThreadSnapshotErrors,
541 }).middleware(EnvironmentAuthenticatedAuth),
542 )
543 .add(
544 HttpApiEndpoint.get("threadBoundedSnapshot", "/api/orchestration/threads/:threadId/bounded", {
545 headers: OrchestrationProtocolHeaders,
546 params: EnvironmentOrchestrationThreadSnapshotParams,
547 success: OrchestrationV2ThreadBoundedSnapshot,
548 error: EnvironmentOrchestrationThreadSnapshotErrors,
549 }).middleware(EnvironmentAuthenticatedAuth),
550 )
551 .add(
552 HttpApiEndpoint.get("threadHistoryPage", "/api/orchestration/threads/:threadId/history", {
553 headers: OrchestrationProtocolHeaders,
554 params: EnvironmentOrchestrationThreadSnapshotParams,
555 query: EnvironmentOrchestrationThreadHistoryQuery,
556 success: OrchestrationV2ThreadHistoryPage,
557 error: EnvironmentOrchestrationThreadHistoryErrors,
558 }).middleware(EnvironmentAuthenticatedAuth),
559 ) {}
560​
561class EnvironmentProjectsHttpApi extends HttpApiGroup.make("projects")
562 .add(
563 HttpApiEndpoint.get("snapshot", "/api/projects", {
564 headers: OptionalBearerHeaders,
565 success: ProjectSnapshot,
566 error: EnvironmentProjectSnapshotErrors,
567 }).middleware(EnvironmentAuthenticatedAuth),
568 )
569 .add(
570 HttpApiEndpoint.post("mutate", "/api/projects/mutate", {
571 headers: OptionalBearerHeaders,
572 payload: ProjectMutation,
573 success: Project,
574 error: EnvironmentProjectMutationErrors,
575 }).middleware(EnvironmentAuthenticatedAuth),
576 ) {}
577​
578/** Large, compressible pull-request payloads travel over HTTP rather than the RPC socket. */
579class EnvironmentPullRequestsHttpApi extends HttpApiGroup.make("pullRequests").add(
580 HttpApiEndpoint.post("diff", "/api/pull-requests/diff", {
581 headers: OptionalBearerHeaders,
582 payload: PullRequestDiffInput,
583 success: PullRequestDiffResult,
584 error: [
585 PullRequestUnavailableError,
586 PullRequestOperationError,
587 EnvironmentAuthInvalidError,
588 EnvironmentScopeRequiredError,
589 EnvironmentInternalError,
590 ],
591 }).middleware(EnvironmentAuthenticatedAuth),
592) {}
593​
594class EnvironmentConnectHttpApi extends HttpApiGroup.make("connect")
595 .add(
596 HttpApiEndpoint.post("linkProof", "/api/connect/link-proof", {
597 headers: OptionalBearerHeaders,
598 payload: RelayLinkProofRequest,
599 success: RelayEnvironmentLinkProof,
600 error: EnvironmentHttpCloudErrors,
601 }).middleware(EnvironmentAuthenticatedAuth),
602 )
603 .add(
604 HttpApiEndpoint.post("relayConfig", "/api/connect/relay-config", {
605 headers: OptionalBearerHeaders,
606 payload: RelayEnvironmentConfigRequest,
607 success: EnvironmentCloudRelayConfigResult,
608 error: [...EnvironmentHttpCloudErrors, EnvironmentCloudEndpointUnavailableError],
609 }).middleware(EnvironmentAuthenticatedAuth),
610 )
611 .add(
612 HttpApiEndpoint.get("linkState", "/api/connect/link-state", {
613 headers: OptionalBearerHeaders,
614 success: EnvironmentCloudLinkStateResult,
615 error: EnvironmentHttpCloudErrors,
616 }).middleware(EnvironmentAuthenticatedAuth),
617 )
618 .add(
619 HttpApiEndpoint.post("unlink", "/api/connect/unlink", {
620 headers: OptionalBearerHeaders,
621 success: EnvironmentCloudRelayConfigResult,
622 error: EnvironmentHttpCloudErrors,
623 }).middleware(EnvironmentAuthenticatedAuth),
624 )
625 .add(
626 HttpApiEndpoint.post("preferences", "/api/connect/preferences", {
627 headers: OptionalBearerHeaders,
628 payload: EnvironmentCloudPreferencesRequest,
629 success: EnvironmentCloudLinkStateResult,
630 error: EnvironmentHttpCloudErrors,
631 }).middleware(EnvironmentAuthenticatedAuth),
632 )
633 .add(
634 HttpApiEndpoint.post("health", "/api/t3-connect/health", {
635 payload: RelayCloudEnvironmentHealthRequest,
636 success: RelayEnvironmentHealthResponse,
637 error: EnvironmentHttpCloudErrors,
638 }),
639 )
640 .add(
641 HttpApiEndpoint.post("mintCredential", "/api/connect/mint-credential", {
642 payload: RelayCloudMintCredentialRequest,
643 success: RelayEnvironmentMintResponse,
644 error: EnvironmentHttpCloudErrors,
645 }),
646 )
647 .add(
648 HttpApiEndpoint.post("t3MintCredential", "/api/t3-connect/mint-credential", {
649 payload: RelayCloudMintCredentialRequest,
650 success: RelayEnvironmentMintResponse,
651 error: EnvironmentHttpCloudErrors,
652 }),
653 ) {}
654​
655/**
656 * Public entry point for webhook tasks. Unauthenticated by design: the token
657 * in the path, and an optional body signature, are the credential. The handler
658 * reads the raw body itself so a signature is checked over the exact bytes.
659 */
660const WebhookParams = Schema.Struct({
661 hookId: TrimmedNonEmptyString,
662 token: TrimmedNonEmptyString,
663});
664const WebhookAccepted = Schema.Struct({ deliveryId: TrimmedNonEmptyString }).pipe(
665 HttpApiSchema.status(202),
666);
667const webhookEndpoint = {
668 params: WebhookParams,
669 success: WebhookAccepted,
670} as const;
671const WEBHOOK_PATH = "/api/hooks/:hookId/:token";
672​
673class EnvironmentWebhooksHttpApi extends HttpApiGroup.make("webhooks")
674 .add(HttpApiEndpoint.post("webhookPost", WEBHOOK_PATH, webhookEndpoint))
675 .add(HttpApiEndpoint.put("webhookPut", WEBHOOK_PATH, webhookEndpoint))
676 .add(HttpApiEndpoint.patch("webhookPatch", WEBHOOK_PATH, webhookEndpoint))
677 .add(HttpApiEndpoint.get("webhookGet", WEBHOOK_PATH, webhookEndpoint)) {}
678​
679export class EnvironmentHttpApi extends HttpApi.make("environment")
680 .add(EnvironmentMetadataHttpApi)
681 .add(EnvironmentAuthHttpApi)
682 .add(EnvironmentOrchestrationHttpApi)
683 .add(EnvironmentPullRequestsHttpApi)
684 .add(EnvironmentProjectsHttpApi)
685 .add(EnvironmentConnectHttpApi)
686 .add(EnvironmentWebhooksHttpApi) {}