| 1 | import { RelayApi } from "@t3tools/contracts/relay"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import * as FetchHttpClient from "effect/http/FetchHttpClient"; |
| 4 | import * as HttpClient from "effect/http/HttpClient"; |
| 5 | import * as HttpClientRequest from "effect/http/HttpClientRequest"; |
| 6 | import * as HttpApiClient from "effect/http-api/HttpApiClient"; |
| 7 | |
| 8 | /** |
| 9 | * A typed RelayApi client that authenticates as this environment, for the |
| 10 | * environment-credential endpoints (link preferences, held webhooks). |
| 11 | */ |
| 12 | export const makeRelayEnvironmentClient = (connection: { |
| 13 | readonly url: string; |
| 14 | readonly environmentCredential: string; |
| 15 | }) => |
| 16 | HttpApiClient.make(RelayApi, { |
| 17 | baseUrl: connection.url, |
| 18 | transformClient: HttpClient.mapRequest( |
| 19 | HttpClientRequest.setHeader("authorization", `Bearer ${connection.environmentCredential}`), |
| 20 | ), |
| 21 | }).pipe(Effect.provide(FetchHttpClient.layer)); |