| 1 | import * as Lambda from "@/AWS/Lambda"; |
| 2 | import * as Neon from "@/Neon"; |
| 3 | import * as Effect from "effect/Effect"; |
| 4 | import * as Layer from "effect/Layer"; |
| 5 | import * as Redacted from "effect/Redacted"; |
| 6 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 7 | import * as HttpServerResponse from "effect/http/HttpServerResponse"; |
| 8 | import { |
| 9 | backendAuth, |
| 10 | backendDataApi, |
| 11 | backendGateway, |
| 12 | } from "./backend-resources.ts"; |
| 13 | |
| 14 | const bindings = Layer.mergeAll( |
| 15 | Neon.ConnectAuthHttp, |
| 16 | Neon.QueryDataApiHttp, |
| 17 | Neon.QueryAIGatewayHttp, |
| 18 | ).pipe(Layer.provide(FetchHttpClient.layer)); |
| 19 | |
| 20 | export default class BackendHttpLambda extends Lambda.Function<BackendHttpLambda>()( |
| 21 | "BackendHttpLambda", |
| 22 | { |
| 23 | main: import.meta.url, |
| 24 | functionUrl: true, |
| 25 | }, |
| 26 | Effect.gen(function* () { |
| 27 | const auth = yield* Neon.ConnectAuth(backendAuth); |
| 28 | const data = yield* Neon.QueryDataApi(backendDataApi); |
| 29 | const ai = yield* Neon.QueryAIGateway(backendGateway); |
| 30 | return { |
| 31 | fetch: Effect.gen(function* () { |
| 32 | return yield* HttpServerResponse.json({ |
| 33 | authUrl: yield* auth.baseUrl, |
| 34 | jwksUrl: yield* auth.jwksUrl, |
| 35 | dataUrl: yield* data.baseUrl, |
| 36 | aiUrl: yield* ai.baseUrl, |
| 37 | hasToken: Redacted.value(yield* ai.token).length > 0, |
| 38 | }); |
| 39 | }), |
| 40 | }; |
| 41 | }).pipe(Effect.provide(bindings)), |
| 42 | ) {} |