// Compile-time contract tests for the admin auth types. `tsc --noEmit` is the // runner: every Expect<...> must resolve to true, and the @ts-expect-error // lines must actually fail without the directive. type Equal = (() => T extends A ? 1 : 2) extends () => T extends B ? 1 : 2 ? true : false type Expect = T const challenge: AdminMfaChallenge = { mfaRequired: true, pendingToken: "pending", expiresIn: 300, methods: ["webauthn", "totp", "recovery"], } type _ChallengeFlag = Expect> type _ChallengeMethods = Expect> type _AuthMethodIncludesPassword = Expect> declare const response: AdminLoginResponse<{ id: string }> if (response.mfaRequired) { const pending: string = response.pendingToken const methods: AdminMfaMethod[] = response.methods // @ts-expect-error a challenge carries no session token response.token } else { const token: string = response.token const user: { id: string } = response.user const amr: AdminAuthMethod[] | undefined = response.amr } const descriptor: AdminWebAuthnDescriptor = { type: "public-key", id: "abc" } const requestOptions: AdminWebAuthnRequestOptions = { challenge: "abc", rpId: "admin.example.com", allowCredentials: [descriptor], timeout: 60000, userVerification: "preferred", } const credential: AdminWebAuthnCredentialJSON = { id: "abc", rawId: "abc", type: "public-key", response: { clientDataJSON: "e30", signature: "sig" }, } type _AssertionSignature = Expect> const view: AdminWebAuthnCredentialView = { id: "1", label: "YubiKey", createdAt: "2026-01-01T00:00:00Z", backupEligible: false, backupState: false, } // The session branch must stay assignable without a factor. const session: AdminLoginSession<{ id: string }> = { token: "t", user: { id: "1" } }