Files
t3code/apps/server/src/auth/Services/BootstrapCredentialService.ts
T
3405a64dd8 bump effect to latest beta (#1866)
Co-authored-by: Claude Opus 4.6 (1M context) <[email protected]>
Co-authored-by: Julius Marminge <[email protected]>
Co-authored-by: codex <[email protected]>
2026-04-10 01:51:31 -07:00

58 lines
1.9 KiB
TypeScript

import type { AuthPairingLink, ServerAuthBootstrapMethod } from "@t3tools/contracts";
import { Data, DateTime, Duration, Context } from "effect";
import type { Effect, Stream } from "effect";
export type BootstrapCredentialRole = "owner" | "client";
export interface BootstrapGrant {
readonly method: ServerAuthBootstrapMethod;
readonly role: BootstrapCredentialRole;
readonly subject: string;
readonly label?: string;
readonly expiresAt: DateTime.DateTime;
}
export class BootstrapCredentialError extends Data.TaggedError("BootstrapCredentialError")<{
readonly message: string;
readonly status?: 401 | 500;
readonly cause?: unknown;
}> {}
export interface IssuedBootstrapCredential {
readonly id: string;
readonly credential: string;
readonly label?: string;
readonly expiresAt: DateTime.Utc;
}
export type BootstrapCredentialChange =
| {
readonly type: "pairingLinkUpserted";
readonly pairingLink: AuthPairingLink;
}
| {
readonly type: "pairingLinkRemoved";
readonly id: string;
};
export interface BootstrapCredentialServiceShape {
readonly issueOneTimeToken: (input?: {
readonly ttl?: Duration.Duration;
readonly role?: BootstrapCredentialRole;
readonly subject?: string;
readonly label?: string;
}) => Effect.Effect<IssuedBootstrapCredential, BootstrapCredentialError>;
readonly listActive: () => Effect.Effect<
ReadonlyArray<AuthPairingLink>,
BootstrapCredentialError
>;
readonly streamChanges: Stream.Stream<BootstrapCredentialChange>;
readonly revoke: (id: string) => Effect.Effect<boolean, BootstrapCredentialError>;
readonly consume: (credential: string) => Effect.Effect<BootstrapGrant, BootstrapCredentialError>;
}
export class BootstrapCredentialService extends Context.Service<
BootstrapCredentialService,
BootstrapCredentialServiceShape
>()("t3/auth/Services/BootstrapCredentialService") {}