The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 04:45 UTC
| 1 | /** |
| 2 | * The server's `IssueTrackerHost`: standalone tracker credentials out of the secret store, one |
| 3 | * per tracker kind. The name is stable across releases so a saved key survives upgrades. |
| 4 | * |
| 5 | * @module issue/IssueTrackerHostLive |
| 6 | */ |
| 7 | import * as Effect from "effect/Effect"; |
| 8 | import * as Layer from "effect/Layer"; |
| 9 | import * as Option from "effect/Option"; |
| 10 | import type { IssueTrackerKind } from "@t3tools/contracts"; |
| 11 | import { IssueTrackerError } from "@t3tools/source-control-core/server/IssueTracker"; |
| 12 | import * as IssueTrackerHost from "@t3tools/source-control-core/server/IssueTrackerHost"; |
| 13 | |
| 14 | import * as ServerSecretStore from "../auth/ServerSecretStore.ts"; |
| 15 | |
| 16 | export function issueTrackerSecretName(tracker: IssueTrackerKind): string { |
| 17 | return `issue-tracker-${Buffer.from(tracker, "utf8").toString("base64url")}-token`; |
| 18 | } |
| 19 | |
| 20 | const decoder = new TextDecoder(); |
| 21 | |
| 22 | const make = Effect.gen(function* () { |
| 23 | const secrets = yield* ServerSecretStore.ServerSecretStore; |
| 24 | return IssueTrackerHost.IssueTrackerHost.of({ |
| 25 | credentials: { |
| 26 | get: (tracker) => |
| 27 | secrets.get(issueTrackerSecretName(tracker)).pipe( |
| 28 | Effect.map(Option.map((bytes) => decoder.decode(bytes))), |
| 29 | Effect.mapError( |
| 30 | (cause) => |
| 31 | new IssueTrackerError({ |
| 32 | tracker, |
| 33 | operation: "readCredential", |
| 34 | reason: "failed", |
| 35 | detail: "The stored credential could not be read.", |
| 36 | cause, |
| 37 | }), |
| 38 | ), |
| 39 | ), |
| 40 | }, |
| 41 | }); |
| 42 | }); |
| 43 | |
| 44 | export const layer = Layer.effect(IssueTrackerHost.IssueTrackerHost, make); |