refactor(provider): return canonical auth methods

Make the provider auth service own the canonical Methods DTO and align the server test cleanup pattern with the other HttpApi slices.
This commit is contained in:
Kit Langton
2026-04-14 09:23:16 -04:00
parent 0bb986359b
commit 0dcaec3b7b
3 changed files with 13 additions and 8 deletions

View File

@@ -99,7 +99,7 @@ export namespace ProviderAuth {
type Hook = NonNullable<Hooks["auth"]>
export interface Interface {
readonly methods: () => Effect.Effect<Record<ProviderID, Method[]>>
readonly methods: () => Effect.Effect<Record<ProviderID, ReadonlyArray<Method>>>
readonly authorize: (input: {
providerID: ProviderID
method: number
@@ -138,9 +138,9 @@ export namespace ProviderAuth {
const methods = Effect.fn("ProviderAuth.methods")(function* () {
const hooks = (yield* InstanceState.get(state)).hooks
return Record.map(hooks, (item) =>
item.methods.map(
(method): Method => ({
return Schema.decodeUnknownSync(Methods)(
Record.map(hooks, (item) =>
item.methods.map((method) => ({
type: method.type,
label: method.label,
prompts: method.prompts?.map((prompt) => {
@@ -161,7 +161,7 @@ export namespace ProviderAuth {
when: prompt.when,
}
}),
}),
})),
),
)
})

View File

@@ -2,7 +2,7 @@ import { AppLayer } from "@/effect/app-runtime"
import { memoMap } from "@/effect/run-service"
import { ProviderAuth } from "@/provider/auth"
import { lazy } from "@/util/lazy"
import { Effect, Layer, Schema } from "effect"
import { Effect, Layer } from "effect"
import { HttpRouter, HttpServer } from "effect/unstable/http"
import { HttpApi, HttpApiBuilder, HttpApiEndpoint, HttpApiGroup, OpenApi } from "effect/unstable/httpapi"
import type { Handler } from "hono"
@@ -40,7 +40,7 @@ const Api = HttpApi.make("provider")
const auth = Effect.fn("ProviderHttpApi.auth")(function* () {
const svc = yield* ProviderAuth.Service
return Schema.decodeUnknownSync(ProviderAuth.Methods)(yield* svc.methods())
return yield* svc.methods()
})
const ProviderLive = HttpApiBuilder.group(Api, "provider", (handlers) => handlers.handle("auth", auth))

View File

@@ -1,12 +1,17 @@
import { describe, expect, test } from "bun:test"
import { afterEach, describe, expect, test } from "bun:test"
import path from "path"
import fs from "fs/promises"
import { Instance } from "../../src/project/instance"
import { Server } from "../../src/server/server"
import { tmpdir } from "../fixture/fixture"
import { Log } from "../../src/util/log"
Log.init({ print: false })
afterEach(async () => {
await Instance.disposeAll()
})
describe("experimental provider httpapi", () => {
test("lists provider auth methods and serves docs", async () => {
await using tmp = await tmpdir({