From 066beff888190ed8d9d97957018c10f690ba7373 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:28:53 +0000 Subject: [PATCH 01/19] feat(auth): record when each session signed in --- packages/database/auth/auth-options.ts | 10 ++++++++++ packages/database/auth/fresh-sign-in.ts | 20 ++++++++++++++++++++ packages/database/package.json | 1 + packages/database/schema.ts | 1 + 4 files changed, 32 insertions(+) create mode 100644 packages/database/auth/fresh-sign-in.ts diff --git a/packages/database/auth/auth-options.ts b/packages/database/auth/auth-options.ts index 8e7e197e70f..513d48c3325 100644 --- a/packages/database/auth/auth-options.ts +++ b/packages/database/auth/auth-options.ts @@ -31,6 +31,7 @@ import { normalizeSignInEmail, } from "./domain-utils.ts"; import { DrizzleAdapter } from "./drizzle-adapter.ts"; +import { signInTimestamp } from "./fresh-sign-in.ts"; import { GoogleOneTapProvider } from "./google-one-tap.ts"; import { verifyPasskeySignIn } from "./passkeys.ts"; import { @@ -499,6 +500,9 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { session.user.email = token.email ?? null; session.user.image = token.picture ?? null; } + if (typeof token?.authTime === "number") { + (session as { authTime?: number }).authTime = token.authTime; + } return session; }, @@ -533,6 +537,7 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { if (!dbUser) { if (user) { token.id = user?.id; + token.authTime = signInTimestamp(); } return token; } @@ -544,6 +549,11 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { email: dbUser.email, picture: dbUser.image, sessionVersion: dbUser.authSessionVersion, + ...(user + ? { authTime: signInTimestamp() } + : typeof token.authTime === "number" + ? { authTime: token.authTime } + : {}), }; } diff --git a/packages/database/auth/fresh-sign-in.ts b/packages/database/auth/fresh-sign-in.ts new file mode 100644 index 00000000000..c491001489e --- /dev/null +++ b/packages/database/auth/fresh-sign-in.ts @@ -0,0 +1,20 @@ +export const FRESH_SIGN_IN_SECONDS = 10 * 60; +const CLOCK_SKEW_SECONDS = 60; + +export function signInTimestamp(now = Date.now()) { + return Math.floor(now / 1000); +} + +/** + * Whether a session's sign-in happened in the last ten minutes. The time is + * stamped into the encrypted session token when someone signs in, so a client + * cannot set it. + */ +export function isFreshSignIn(authTime: unknown, now = Date.now()) { + if (typeof authTime !== "number" || !Number.isFinite(authTime)) return false; + const nowSeconds = signInTimestamp(now); + return ( + authTime <= nowSeconds + CLOCK_SKEW_SECONDS && + nowSeconds - authTime <= FRESH_SIGN_IN_SECONDS + ); +} diff --git a/packages/database/package.json b/packages/database/package.json index 742838e3420..12bdec0eb8d 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -66,6 +66,7 @@ "./auth/domain-utils": "./auth/domain-utils.ts", "./auth/auth-challenges": "./auth/auth-challenges.ts", "./auth/passkeys": "./auth/passkeys.ts", + "./auth/fresh-sign-in": "./auth/fresh-sign-in.ts", "./auth/security-emails": "./auth/security-emails.ts", "./auth/google-one-tap": "./auth/google-one-tap.ts", "./auth/request-site": "./auth/request-site.ts", diff --git a/packages/database/schema.ts b/packages/database/schema.ts index ee8a29d4471..61a5e8f014b 100644 --- a/packages/database/schema.ts +++ b/packages/database/schema.ts @@ -123,6 +123,7 @@ export const users = mysqlTable( dashboard?: { pageSize?: number; }; + passkeyPromptDismissedAt?: string; } | null>() .default(null), activeOrganizationId: nanoId( From ba571c51e03a9dd8954ef81ea34e43f81cdb2be4 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:28:53 +0000 Subject: [PATCH 02/19] feat(auth): let a fresh sign-in add a passkey and snooze the offer --- apps/web/actions/auth/passkeys.ts | 34 +++++++++++++++++++++++++- apps/web/lib/passkey-prompt.ts | 40 +++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 apps/web/lib/passkey-prompt.ts diff --git a/apps/web/actions/auth/passkeys.ts b/apps/web/actions/auth/passkeys.ts index 385f4a2d0af..7c45777a48b 100644 --- a/apps/web/actions/auth/passkeys.ts +++ b/apps/web/actions/auth/passkeys.ts @@ -1,11 +1,13 @@ "use server"; +import { db } from "@cap/database"; import { hasStepUpGrant, issueStepUpCode, issueStepUpGrant, verifyStepUpCode, } from "@cap/database/auth/auth-challenges"; +import { isFreshSignIn } from "@cap/database/auth/fresh-sign-in"; import { createPasskeyRegistrationOptions, createPasskeySignInOptions, @@ -20,12 +22,15 @@ import { sendPasskeyAddedNotice, sendPasskeyRemovedNotice, } from "@cap/database/auth/security-emails"; -import { getCurrentUser } from "@cap/database/auth/session"; +import { getCurrentUser, getSession } from "@cap/database/auth/session"; +import { users } from "@cap/database/schema"; import type { PublicKeyCredentialCreationOptionsJSON, PublicKeyCredentialRequestOptionsJSON, } from "@simplewebauthn/server"; +import { eq, sql } from "drizzle-orm"; import { isRateLimited, RATE_LIMIT_IDS } from "@/lib/rate-limit"; +import { userPreferencesObject } from "@/lib/user-preferences-sql"; export type PasskeyListItem = { id: string; @@ -169,3 +174,30 @@ export async function removePasskey(passkeyId: string) { if (removed) await sendPasskeyRemovedNotice(user.email, removed.name); return { removed: removed !== null }; } + +export async function getPasskeyRegistrationOptionsAfterSignIn(): Promise< + | { status: "ok"; options: PublicKeyCredentialCreationOptionsJSON } + | { status: "verify" | "limit" | "rate_limited" } +> { + const user = await requireUser(); + if (await isPasskeyLimited(user.id)) return { status: "rate_limited" }; + const session = (await getSession()) as { + user?: { id?: string }; + authTime?: number; + } | null; + if (session?.user?.id !== user.id || !isFreshSignIn(session?.authTime)) { + return { status: "verify" }; + } + const options = await createPasskeyRegistrationOptions(user); + return options ? { status: "ok", options } : { status: "limit" }; +} + +export async function dismissPasskeyPrompt() { + const user = await requireUser(); + await db() + .update(users) + .set({ + preferences: sql`JSON_SET(${userPreferencesObject()}, '$.passkeyPromptDismissedAt', ${new Date().toISOString()})`, + }) + .where(eq(users.id, user.id)); +} diff --git a/apps/web/lib/passkey-prompt.ts b/apps/web/lib/passkey-prompt.ts new file mode 100644 index 00000000000..ecb2b731327 --- /dev/null +++ b/apps/web/lib/passkey-prompt.ts @@ -0,0 +1,40 @@ +import "server-only"; + +import { isFreshSignIn } from "@cap/database/auth/fresh-sign-in"; +import { countPasskeys } from "@cap/database/auth/passkeys"; +import { getSession } from "@cap/database/auth/session"; +import type { users } from "@cap/database/schema"; + +export const PASSKEY_PROMPT_SNOOZE_MS = 30 * 24 * 60 * 60 * 1000; + +type PromptUser = Pick; + +export function passkeyPromptSnoozed( + preferences: PromptUser["preferences"], + now = Date.now(), +) { + const dismissedAt = preferences?.passkeyPromptDismissedAt; + if (typeof dismissedAt !== "string") return false; + const dismissed = Date.parse(dismissedAt); + return ( + Number.isFinite(dismissed) && now - dismissed < PASSKEY_PROMPT_SNOOZE_MS + ); +} + +export async function shouldOfferPasskey(user: PromptUser, now = Date.now()) { + try { + if (passkeyPromptSnoozed(user.preferences, now)) return false; + const session = (await getSession()) as { + user?: { id?: string }; + authTime?: number; + } | null; + if (session?.user?.id !== user.id) return false; + if (!isFreshSignIn(session.authTime, now)) return false; + return (await countPasskeys(user.id)) === 0; + } catch (error) { + console.error("[passkeys] Could not decide on the passkey prompt", { + error: error instanceof Error ? error.message : String(error), + }); + return false; + } +} From a075068012ad49ab224775f819208eb059b90496 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:28:53 +0000 Subject: [PATCH 03/19] feat(web): offer a passkey after signing in --- .../dashboard/_components/PasskeyPrompt.tsx | 134 ++++++++++++++++++ apps/web/app/(org)/dashboard/layout.tsx | 5 + 2 files changed, 139 insertions(+) create mode 100644 apps/web/app/(org)/dashboard/_components/PasskeyPrompt.tsx diff --git a/apps/web/app/(org)/dashboard/_components/PasskeyPrompt.tsx b/apps/web/app/(org)/dashboard/_components/PasskeyPrompt.tsx new file mode 100644 index 00000000000..7013fce4b4f --- /dev/null +++ b/apps/web/app/(org)/dashboard/_components/PasskeyPrompt.tsx @@ -0,0 +1,134 @@ +"use client"; + +import { + Button, + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@cap/ui"; +import { + browserSupportsWebAuthn, + platformAuthenticatorIsAvailable, + startRegistration, +} from "@simplewebauthn/browser"; +import { Fingerprint } from "lucide-react"; +import { useRouter } from "next/navigation"; +import { useEffect, useState } from "react"; +import { toast } from "sonner"; +import { + completePasskeyRegistration, + dismissPasskeyPrompt, + getPasskeyRegistrationOptionsAfterSignIn, +} from "@/actions/auth/passkeys"; +import { isPasskeyCancellation } from "@/lib/passkey-errors"; + +export function PasskeyPrompt() { + const router = useRouter(); + const [open, setOpen] = useState(false); + const [pending, setPending] = useState(false); + + useEffect(() => { + let cancelled = false; + if (!browserSupportsWebAuthn()) return; + platformAuthenticatorIsAvailable() + .then((available) => { + if (available && !cancelled) setOpen(true); + }) + .catch(() => {}); + return () => { + cancelled = true; + }; + }, []); + + const notNow = () => { + setOpen(false); + dismissPasskeyPrompt().catch(() => {}); + }; + + const addPasskey = async () => { + setPending(true); + try { + const options = await getPasskeyRegistrationOptionsAfterSignIn(); + if (options.status !== "ok") { + setOpen(false); + if (options.status === "verify") { + toast.message( + "You can add a passkey any time from Settings, Account.", + ); + } else if (options.status === "rate_limited") { + toast.error("Too many attempts. Try again in a minute."); + } + return; + } + let response: Awaited>; + try { + response = await startRegistration({ optionsJSON: options.options }); + } catch (error) { + if (!isPasskeyCancellation(error)) { + toast.error("Your passkey couldn't be created. Try again."); + } + return; + } + const result = await completePasskeyRegistration( + JSON.stringify(response), + ); + if (result.status === "registered") { + setOpen(false); + toast.success("Passkey added. Use it next time you sign in."); + router.refresh(); + return; + } + toast.error( + result.status === "duplicate" + ? "That passkey is already on your account." + : "Your passkey couldn't be added. Try again from Settings, Account.", + ); + } catch { + toast.error("Your passkey couldn't be added. Try again."); + } finally { + setPending(false); + } + }; + + return ( + { + if (!next && !pending) notNow(); + }} + > + + } + description="Next time, sign in with Face ID, Touch ID, Windows Hello or your password manager instead of waiting for an email code." + > + Sign in faster with a passkey + + + + + + + + ); +} diff --git a/apps/web/app/(org)/dashboard/layout.tsx b/apps/web/app/(org)/dashboard/layout.tsx index 3ffd8036eb2..19aa549447c 100644 --- a/apps/web/app/(org)/dashboard/layout.tsx +++ b/apps/web/app/(org)/dashboard/layout.tsx @@ -7,6 +7,7 @@ import { cookies } from "next/headers"; import { redirect } from "next/navigation"; import { AuthContextProvider } from "@/app/Layout/AuthContext"; import { resolveCurrentUser } from "@/app/Layout/current-user"; +import { shouldOfferPasskey } from "@/lib/passkey-prompt"; import { runPromise } from "@/lib/server"; import { getShareableLinkUsage } from "@/lib/shareable-link-quota"; import DashboardInner from "./_components/DashboardInner"; @@ -14,6 +15,7 @@ import { DashboardPasteImport } from "./_components/DashboardPasteImport"; import MobileTab from "./_components/MobileTab"; import DesktopNav from "./_components/Navbar/Desktop"; import MobileNav from "./_components/Navbar/Mobile"; +import { PasskeyPrompt } from "./_components/PasskeyPrompt"; import { DashboardContexts } from "./Contexts"; import { UploadingProvider } from "./caps/UploadingContext"; import { @@ -51,6 +53,7 @@ export default async function DashboardLayout({ const hasName = Boolean(user.name && user.name.length > 0); const pendingInviteIdPromise = getPendingInviteIdForUser(user.email); + const offerPasskeyPromise = shouldOfferPasskey(user); const dashboardDataPromise = hasName ? getDashboardData(user) : null; // Fail-open: the meter is informational and must never take the shell down. const shareableLinkUsagePromise = @@ -93,6 +96,7 @@ export default async function DashboardLayout({ } const shareableLinkUsage = await shareableLinkUsagePromise; + const offerPasskey = await offerPasskeyPromise; let activeOrganization = organizationSelect.find( (organization) => @@ -124,6 +128,7 @@ export default async function DashboardLayout({ shareableLinkUsage={shareableLinkUsage} > + {offerPasskey && }
From 29718500aef6850bea63dc3aa0a79ee32e6276e7 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:28:53 +0000 Subject: [PATCH 04/19] test(auth): cover the passkey offer after sign-in --- .../integration/passkeys-database.test.ts | 97 +++++++++++++++++++ apps/web/__tests__/unit/auth-options.test.ts | 34 +++++++ 2 files changed, 131 insertions(+) diff --git a/apps/web/__tests__/integration/passkeys-database.test.ts b/apps/web/__tests__/integration/passkeys-database.test.ts index 7557d6a559a..4be52be3588 100644 --- a/apps/web/__tests__/integration/passkeys-database.test.ts +++ b/apps/web/__tests__/integration/passkeys-database.test.ts @@ -47,6 +47,7 @@ const fixture = vi.hoisted(() => ({ GOOGLE_CLIENT_SECRET: "google-secret", } as Record, currentUser: null as unknown, + session: null as unknown, securityCodes: [] as { email: string; code: string }[], passkeyNotices: [] as { email: string; name: string }[], removedNotices: [] as { email: string; name: string }[], @@ -82,7 +83,9 @@ vi.mock("@simplewebauthn/server", async (importOriginal) => { }); vi.mock("@cap/database/auth/session", () => ({ getCurrentUser: async () => fixture.currentUser, + getSession: async () => fixture.session, })); +vi.mock("server-only", () => ({})); vi.mock("@cap/database/auth/security-emails", () => ({ sendAccountSecurityCode: async (email: string, code: string) => { fixture.securityCodes.push({ email, code }); @@ -1063,6 +1066,100 @@ describe.runIf(Boolean(databaseUrl))( expect(await listPasskeys(user.id)).toHaveLength(0); }); + it("lets a fresh sign-in add a passkey from the prompt without a code", async () => { + const { + completePasskeyRegistration, + getPasskeyRegistrationOptionsAfterSignIn, + } = await actions(); + const user = await makeUser(); + const other = await makeUser(); + fixture.currentUser = user; + const now = Math.floor(Date.now() / 1000); + + fixture.session = { user: { id: user.id }, authTime: now - 11 * 60 }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + fixture.session = { user: { id: user.id } }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + fixture.session = { user: { id: user.id }, authTime: now + 600 }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + fixture.session = { user: { id: other.id }, authTime: now }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + + fixture.session = { user: { id: user.id }, authTime: now - 60 }; + const options = await getPasskeyRegistrationOptionsAfterSignIn(); + if (options.status !== "ok") throw new Error("No options."); + const result = await completePasskeyRegistration( + JSON.stringify( + new SoftwareAuthenticator(user.id).register( + options.options.challenge, + ), + ), + ); + expect(result.status).toBe("registered"); + expect(await listPasskeys(user.id)).toHaveLength(1); + }); + + it("offers the prompt only after a fresh sign-in, without passkeys, unless snoozed", async () => { + const { dismissPasskeyPrompt } = await actions(); + const { shouldOfferPasskey } = await import("@/lib/passkey-prompt"); + const user = await makeUser(); + const now = Math.floor(Date.now() / 1000); + const fresh = { user: { id: user.id }, authTime: now - 30 }; + + fixture.session = fresh; + expect(await shouldOfferPasskey(await reloadUser(user.id))).toBe(true); + fixture.session = { user: { id: user.id }, authTime: now - 11 * 60 }; + expect(await shouldOfferPasskey(await reloadUser(user.id))).toBe(false); + fixture.session = null; + expect(await shouldOfferPasskey(await reloadUser(user.id))).toBe(false); + + fixture.session = fresh; + fixture.currentUser = user; + await dismissPasskeyPrompt(); + const snoozed = await reloadUser(user.id); + expect(typeof snoozed.preferences?.passkeyPromptDismissedAt).toBe( + "string", + ); + expect(await shouldOfferPasskey(snoozed)).toBe(false); + const later = Date.now() + 31 * 24 * 60 * 60 * 1000; + fixture.session = { + user: { id: user.id }, + authTime: Math.floor(later / 1000) - 30, + }; + expect(await shouldOfferPasskey(snoozed, later)).toBe(true); + + const withPasskey = await makeUser(); + await registerPasskey(withPasskey); + fixture.session = { user: { id: withPasskey.id }, authTime: now - 30 }; + expect(await shouldOfferPasskey(await reloadUser(withPasskey.id))).toBe( + false, + ); + }); + + it("keeps other preferences when snoozing the prompt", async () => { + const { dismissPasskeyPrompt } = await actions(); + const user = await makeUser(); + await database() + .update(users) + .set({ preferences: { dashboard: { pageSize: 30 } } as never }) + .where(eq(users.id, user.id)); + fixture.currentUser = user; + await dismissPasskeyPrompt(); + const saved = await reloadUser(user.id); + expect(saved.preferences?.dashboard?.pageSize).toBe(30); + expect(typeof saved.preferences?.passkeyPromptDismissedAt).toBe( + "string", + ); + }); + it("rejects every action without a session", async () => { const passkeyActions = await actions(); fixture.currentUser = null; diff --git a/apps/web/__tests__/unit/auth-options.test.ts b/apps/web/__tests__/unit/auth-options.test.ts index 6b73bac3b81..faae4f85cac 100644 --- a/apps/web/__tests__/unit/auth-options.test.ts +++ b/apps/web/__tests__/unit/auth-options.test.ts @@ -736,6 +736,40 @@ describe("authOptions", () => { expect(mocks.select).not.toHaveBeenCalled(); }); + it("stamps the sign-in time only when someone signs in", async () => { + const options = authOptions(CONTEXT); + const callbacks = callbacksFor(options); + const account = { ...WORKOS_ACCOUNT, provider: "google" }; + await callbacks.signIn({ + user: AUTHENTICATED_USER, + account, + profile: PROFILE, + }); + const before = Math.floor(Date.now() / 1000); + const signedIn = await callbacks.jwt({ + token: { id: "old-user", email: PROFILE.email }, + user: AUTHENTICATED_USER, + account, + }); + const after = Math.floor(Date.now() / 1000); + expect(signedIn.authTime).toBeGreaterThanOrEqual(before); + expect(signedIn.authTime).toBeLessThanOrEqual(after); + + const refreshed = await callbacks.jwt({ token: { ...signedIn } }); + expect(refreshed.authTime).toBe(signedIn.authTime); + + const legacy = await callbacks.jwt({ + token: { email: AUTHENTICATED_USER.email } as never, + }); + expect(legacy.authTime).toBeUndefined(); + + const session = await options.callbacks?.session?.({ + session: { user: {}, expires: "" }, + token: { id: AUTHENTICATED_USER.id, authTime: 1234 }, + } as never); + expect((session as { authTime?: number }).authTime).toBe(1234); + }); + it.each(["workos", "google", "apple"])( "anchors %s tokens to the authenticated user ID instead of token email", async (provider) => { From 08d98333b84df1887f0052d626b20d15d6b1482e Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:55:22 +0000 Subject: [PATCH 05/19] fix(auth): allow the no-code route only for an account's first passkey --- apps/web/actions/auth/passkeys.ts | 6 ++- packages/database/auth/auth-challenges.ts | 2 + packages/database/auth/passkeys.ts | 50 +++++++++++++++-------- 3 files changed, 38 insertions(+), 20 deletions(-) diff --git a/apps/web/actions/auth/passkeys.ts b/apps/web/actions/auth/passkeys.ts index 7c45777a48b..1a51055efbb 100644 --- a/apps/web/actions/auth/passkeys.ts +++ b/apps/web/actions/auth/passkeys.ts @@ -188,8 +188,10 @@ export async function getPasskeyRegistrationOptionsAfterSignIn(): Promise< if (session?.user?.id !== user.id || !isFreshSignIn(session?.authTime)) { return { status: "verify" }; } - const options = await createPasskeyRegistrationOptions(user); - return options ? { status: "ok", options } : { status: "limit" }; + const options = await createPasskeyRegistrationOptions(user, { + firstPasskeyOnly: true, + }); + return options ? { status: "ok", options } : { status: "verify" }; } export async function dismissPasskeyPrompt() { diff --git a/packages/database/auth/auth-challenges.ts b/packages/database/auth/auth-challenges.ts index e762ace5458..5af214ddb29 100644 --- a/packages/database/auth/auth-challenges.ts +++ b/packages/database/auth/auth-challenges.ts @@ -10,6 +10,7 @@ export type AuthChallengePurpose = | "passkey_sign_in" | "passkey_step_up" | "passkey_registration" + | "passkey_first_registration" | "step_up_email_code" | "step_up_email_code_sent" | "step_up_grant"; @@ -321,6 +322,7 @@ export async function spendPasskeySetup( inArray(authChallenges.purpose, [ "step_up_grant", "passkey_registration", + "passkey_first_registration", ]), ), ); diff --git a/packages/database/auth/passkeys.ts b/packages/database/auth/passkeys.ts index a8f5f5102c7..16750309232 100644 --- a/packages/database/auth/passkeys.ts +++ b/packages/database/auth/passkeys.ts @@ -379,12 +379,15 @@ export async function countPasskeys(userId: User.UserId) { return row?.total ?? 0; } -export async function createPasskeyRegistrationOptions(user: { - id: User.UserId; - email: string; - name: string | null; - lastName: string | null; -}): Promise { +export async function createPasskeyRegistrationOptions( + user: { + id: User.UserId; + email: string; + name: string | null; + lastName: string | null; + }, + options: { firstPasskeyOnly?: boolean } = {}, +): Promise { const existing = await db() .select({ credentialId: userPasskeys.credentialId, @@ -393,11 +396,13 @@ export async function createPasskeyRegistrationOptions(user: { .from(userPasskeys) .where(eq(userPasskeys.userId, user.id)); if (existing.length >= MAX_PASSKEYS_PER_USER) return null; + const { firstPasskeyOnly = false } = options; + if (firstPasskeyOnly && existing.length > 0) return null; const { rpID, rpName } = passkeyRelyingParty(); const displayName = [user.name, user.lastName].filter(Boolean).join(" ").trim() || user.email; - const options = await generateRegistrationOptions({ + const registration = await generateRegistrationOptions({ rpName, rpID, userID: webAuthnUserId(user.id), @@ -416,11 +421,13 @@ export async function createPasskeyRegistrationOptions(user: { supportedAlgorithmIDs: [-8, -7, -257], }); await storeChallenge({ - purpose: "passkey_registration", - challenge: options.challenge, + purpose: firstPasskeyOnly + ? "passkey_first_registration" + : "passkey_registration", + challenge: registration.challenge, userId: user.id, }); - return options; + return registration; } export type PasskeyRegistrationResult = @@ -483,21 +490,28 @@ export async function verifyPasskeyRegistration( if (locked?.authSessionVersion !== account.authSessionVersion) { return "reset"; } - if ( - !(await consumeChallenge({ - purpose: "passkey_registration", + const claimedSetup = await consumeChallenge({ + purpose: "passkey_registration", + challenge, + userId, + database: tx, + }); + const claimedFirst = + !claimedSetup && + (await consumeChallenge({ + purpose: "passkey_first_registration", challenge, userId, database: tx, - })) - ) { - return "reset"; - } + })); + if (!claimedSetup && !claimedFirst) return "reset"; const [row] = await tx .select({ total: count() }) .from(userPasskeys) .where(eq(userPasskeys.userId, userId)); - if ((row?.total ?? 0) >= MAX_PASSKEYS_PER_USER) return "limit"; + const existing = row?.total ?? 0; + if (claimedFirst && existing > 0) return "reset"; + if (existing >= MAX_PASSKEYS_PER_USER) return "limit"; await tx.insert(userPasskeys).values({ id, userId, From 267790f144a2855a57cc0fc1cae7cf030e3c0bf6 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 22:55:22 +0000 Subject: [PATCH 06/19] test(auth): cover the first-passkey-only rule and its races --- .../integration/passkeys-database.test.ts | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/apps/web/__tests__/integration/passkeys-database.test.ts b/apps/web/__tests__/integration/passkeys-database.test.ts index 4be52be3588..e28f6e170d1 100644 --- a/apps/web/__tests__/integration/passkeys-database.test.ts +++ b/apps/web/__tests__/integration/passkeys-database.test.ts @@ -1107,6 +1107,66 @@ describe.runIf(Boolean(databaseUrl))( expect(await listPasskeys(user.id)).toHaveLength(1); }); + it("lets a fresh sign-in add only the account's first passkey", async () => { + const { + completePasskeyRegistration, + getPasskeyRegistrationOptionsAfterSignIn, + } = await actions(); + const now = Math.floor(Date.now() / 1000); + + const owner = await makeUser(); + await registerPasskey(owner); + fixture.currentUser = owner; + fixture.session = { user: { id: owner.id }, authTime: now - 30 }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + expect(await listPasskeys(owner.id)).toHaveLength(1); + + const late = await makeUser(); + fixture.currentUser = late; + fixture.session = { user: { id: late.id }, authTime: now - 30 }; + const pending = await getPasskeyRegistrationOptionsAfterSignIn(); + if (pending.status !== "ok") throw new Error("No options."); + await registerPasskey(late); + expect( + ( + await completePasskeyRegistration( + JSON.stringify( + new SoftwareAuthenticator(late.id).register( + pending.options.challenge, + ), + ), + ) + ).status, + ).toBe("invalid"); + expect(await listPasskeys(late.id)).toHaveLength(1); + + const racing = await makeUser(); + fixture.currentUser = racing; + fixture.session = { user: { id: racing.id }, authTime: now - 30 }; + const challenges = []; + for (let index = 0; index < 3; index++) { + const options = await getPasskeyRegistrationOptionsAfterSignIn(); + if (options.status !== "ok") throw new Error("No options."); + challenges.push(options.options.challenge); + } + const results = await Promise.all( + challenges.map((challenge) => + verifyPasskeyRegistration( + racing.id, + JSON.stringify( + new SoftwareAuthenticator(racing.id).register(challenge), + ), + ), + ), + ); + expect( + results.filter((result) => result.status === "registered"), + ).toHaveLength(1); + expect(await listPasskeys(racing.id)).toHaveLength(1); + }); + it("offers the prompt only after a fresh sign-in, without passkeys, unless snoozed", async () => { const { dismissPasskeyPrompt } = await actions(); const { shouldOfferPasskey } = await import("@/lib/passkey-prompt"); From 77c6d1bf70ab5ca63afe89a16f97fb5cceb29ade Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:48:53 +0000 Subject: [PATCH 07/19] feat(database): mark passkeys that can confirm identity --- .../0065_passkey_confirms_identity.sql | 1 + .../migrations/meta/0065_snapshot.json | 6650 +++++++++++++++++ .../database/migrations/meta/_journal.json | 7 + packages/database/schema.ts | 1 + 4 files changed, 6659 insertions(+) create mode 100644 packages/database/migrations/0065_passkey_confirms_identity.sql create mode 100644 packages/database/migrations/meta/0065_snapshot.json diff --git a/packages/database/migrations/0065_passkey_confirms_identity.sql b/packages/database/migrations/0065_passkey_confirms_identity.sql new file mode 100644 index 00000000000..9e07c4ff05f --- /dev/null +++ b/packages/database/migrations/0065_passkey_confirms_identity.sql @@ -0,0 +1 @@ +ALTER TABLE `user_passkeys` ADD `confirmsIdentity` boolean DEFAULT true NOT NULL; \ No newline at end of file diff --git a/packages/database/migrations/meta/0065_snapshot.json b/packages/database/migrations/meta/0065_snapshot.json new file mode 100644 index 00000000000..47c8b3eabc7 --- /dev/null +++ b/packages/database/migrations/meta/0065_snapshot.json @@ -0,0 +1,6650 @@ +{ + "version": "5", + "dialect": "mysql", + "id": "de8d211d-65bf-4a95-8871-3f391d31e5d0", + "prevId": "8ac84ca4-d730-45c1-82f8-48ed8ca42cf5", + "tables": { + "accounts": { + "name": "accounts", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_in": { + "name": "expires_in", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "refresh_token_expires_in": { + "name": "refresh_token_expires_in", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_type": { + "name": "token_type", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "tempColumn": { + "name": "tempColumn", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_id_idx": { + "name": "user_id_idx", + "columns": ["userId"], + "isUnique": false + }, + "provider_account_id_idx": { + "name": "provider_account_id_idx", + "columns": ["providerAccountId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "accounts_id": { + "name": "accounts_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "agent_api_authorization_codes": { + "name": "agent_api_authorization_codes", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "codeHash": { + "name": "codeHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "codeChallenge": { + "name": "codeChallenge", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "redirectUri": { + "name": "redirectUri", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "scopes": { + "name": "scopes", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "consumedAt": { + "name": "consumedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "code_hash_idx": { + "name": "code_hash_idx", + "columns": ["codeHash"], + "isUnique": true + }, + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + }, + "user_created_at_idx": { + "name": "user_created_at_idx", + "columns": ["userId", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "agent_api_authorization_codes_id": { + "name": "agent_api_authorization_codes_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "agent_api_idempotency": { + "name": "agent_api_idempotency", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "operation": { + "name": "operation", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyHash": { + "name": "keyHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "requestHash": { + "name": "requestHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "statusCode": { + "name": "statusCode", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "response": { + "name": "response", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "user_operation_key_idx": { + "name": "user_operation_key_idx", + "columns": ["userId", "operation", "keyHash"], + "isUnique": true + }, + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "agent_api_idempotency_id": { + "name": "agent_api_idempotency_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "agent_api_keys": { + "name": "agent_api_keys", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tokenHash": { + "name": "tokenHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Cap CLI'" + }, + "scopes": { + "name": "scopes", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "revokedAt": { + "name": "revokedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "lastUsedAt": { + "name": "lastUsedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "token_hash_idx": { + "name": "token_hash_idx", + "columns": ["tokenHash"], + "isUnique": true + }, + "user_created_at_idx": { + "name": "user_created_at_idx", + "columns": ["userId", "createdAt"], + "isUnique": false + }, + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "agent_api_keys_id": { + "name": "agent_api_keys_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "agent_api_operations": { + "name": "agent_api_operations", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "kind": { + "name": "kind", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resourceId": { + "name": "resourceId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resultResourceId": { + "name": "resultResourceId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'queued'" + }, + "payload": { + "name": "payload", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "result": { + "name": "result", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "errorCode": { + "name": "errorCode", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "errorMessage": { + "name": "errorMessage", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "completedAt": { + "name": "completedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "user_created_at_idx": { + "name": "user_created_at_idx", + "columns": ["userId", "createdAt"], + "isUnique": false + }, + "state_updated_at_idx": { + "name": "state_updated_at_idx", + "columns": ["state", "updatedAt"], + "isUnique": false + }, + "resource_id_idx": { + "name": "resource_id_idx", + "columns": ["resourceId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "agent_api_operations_id": { + "name": "agent_api_operations_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "auth_api_keys": { + "name": "auth_api_keys", + "columns": { + "id": { + "name": "id", + "type": "varchar(36)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'unknown'" + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "user_id_created_at_idx": { + "name": "user_id_created_at_idx", + "columns": ["userId", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "auth_api_keys_id": { + "name": "auth_api_keys_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "auth_challenges": { + "name": "auth_challenges", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "purpose": { + "name": "purpose", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secretHash": { + "name": "secretHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "attempts": { + "name": "attempts", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "expiresAt": { + "name": "expiresAt", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "secret_hash_idx": { + "name": "secret_hash_idx", + "columns": ["secretHash"], + "isUnique": true + }, + "user_purpose_idx": { + "name": "user_purpose_idx", + "columns": ["userId", "purpose"], + "isUnique": false + }, + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "auth_challenges_id": { + "name": "auth_challenges_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "comments": { + "name": "comments", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "varchar(6)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "timestamp": { + "name": "timestamp", + "type": "float", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "authorId": { + "name": "authorId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "parentCommentId": { + "name": "parentCommentId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mediaKey": { + "name": "mediaKey", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mediaDuration": { + "name": "mediaDuration", + "type": "float", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "mediaMeta": { + "name": "mediaMeta", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "video_type_created_idx": { + "name": "video_type_created_idx", + "columns": ["videoId", "type", "createdAt", "id"], + "isUnique": false + }, + "author_id_idx": { + "name": "author_id_idx", + "columns": ["authorId"], + "isUnique": false + }, + "parent_comment_id_idx": { + "name": "parent_comment_id_idx", + "columns": ["parentCommentId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "comments_id": { + "name": "comments_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_api_keys": { + "name": "developer_api_keys", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyType": { + "name": "keyType", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyPrefix": { + "name": "keyPrefix", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyHash": { + "name": "keyHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "encryptedKey": { + "name": "encryptedKey", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "lastUsedAt": { + "name": "lastUsedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "revokedAt": { + "name": "revokedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "key_hash_idx": { + "name": "key_hash_idx", + "columns": ["keyHash"], + "isUnique": true + }, + "app_key_type_idx": { + "name": "app_key_type_idx", + "columns": ["appId", "keyType"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_api_keys_appId_developer_apps_id_fk": { + "name": "developer_api_keys_appId_developer_apps_id_fk", + "tableFrom": "developer_api_keys", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_api_keys_id": { + "name": "developer_api_keys_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_app_domains": { + "name": "developer_app_domains", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "domain": { + "name": "domain", + "type": "varchar(253)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": {}, + "foreignKeys": { + "developer_app_domains_appId_developer_apps_id_fk": { + "name": "developer_app_domains_appId_developer_apps_id_fk", + "tableFrom": "developer_app_domains", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_app_domains_id": { + "name": "developer_app_domains_id", + "columns": ["id"] + } + }, + "uniqueConstraints": { + "app_domain_unique": { + "name": "app_domain_unique", + "columns": ["appId", "domain"] + } + }, + "checkConstraint": {} + }, + "developer_apps": { + "name": "developer_apps", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment": { + "name": "environment", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "logoUrl": { + "name": "logoUrl", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deletedAt": { + "name": "deletedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "owner_deleted_idx": { + "name": "owner_deleted_idx", + "columns": ["ownerId", "deletedAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "developer_apps_id": { + "name": "developer_apps_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_credit_accounts": { + "name": "developer_credit_accounts", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "balanceMicroCredits": { + "name": "balanceMicroCredits", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "stripeCustomerId": { + "name": "stripeCustomerId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripePaymentMethodId": { + "name": "stripePaymentMethodId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "autoTopUpEnabled": { + "name": "autoTopUpEnabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "autoTopUpThresholdMicroCredits": { + "name": "autoTopUpThresholdMicroCredits", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "autoTopUpAmountCents": { + "name": "autoTopUpAmountCents", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "app_id_unique": { + "name": "app_id_unique", + "columns": ["appId"], + "isUnique": true + }, + "owner_idx": { + "name": "owner_idx", + "columns": ["ownerId"], + "isUnique": false + }, + "auto_top_up_idx": { + "name": "auto_top_up_idx", + "columns": ["autoTopUpEnabled"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_credit_accounts_appId_developer_apps_id_fk": { + "name": "developer_credit_accounts_appId_developer_apps_id_fk", + "tableFrom": "developer_credit_accounts", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_credit_accounts_id": { + "name": "developer_credit_accounts_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_credit_transactions": { + "name": "developer_credit_transactions", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "accountId": { + "name": "accountId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "amountMicroCredits": { + "name": "amountMicroCredits", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "balanceAfterMicroCredits": { + "name": "balanceAfterMicroCredits", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "referenceId": { + "name": "referenceId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "referenceType": { + "name": "referenceType", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "account_type_created_idx": { + "name": "account_type_created_idx", + "columns": ["accountId", "type", "createdAt"], + "isUnique": false + }, + "account_created_idx": { + "name": "account_created_idx", + "columns": ["accountId", "createdAt"], + "isUnique": false + }, + "account_ref_dedup_idx": { + "name": "account_ref_dedup_idx", + "columns": ["accountId", "referenceId", "referenceType"], + "isUnique": false + }, + "reference_type_id_idx": { + "name": "reference_type_id_idx", + "columns": ["referenceType", "referenceId"], + "isUnique": false + } + }, + "foreignKeys": { + "dev_credit_txn_account_fk": { + "name": "dev_credit_txn_account_fk", + "tableFrom": "developer_credit_transactions", + "tableTo": "developer_credit_accounts", + "columnsFrom": ["accountId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_credit_transactions_id": { + "name": "developer_credit_transactions_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_daily_storage_snapshots": { + "name": "developer_daily_storage_snapshots", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "snapshotDate": { + "name": "snapshotDate", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "totalDurationMinutes": { + "name": "totalDurationMinutes", + "type": "float", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "videoCount": { + "name": "videoCount", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "microCreditsCharged": { + "name": "microCreditsCharged", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "processedAt": { + "name": "processedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": {}, + "foreignKeys": { + "developer_daily_storage_snapshots_appId_developer_apps_id_fk": { + "name": "developer_daily_storage_snapshots_appId_developer_apps_id_fk", + "tableFrom": "developer_daily_storage_snapshots", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_daily_storage_snapshots_id": { + "name": "developer_daily_storage_snapshots_id", + "columns": ["id"] + } + }, + "uniqueConstraints": { + "app_date_unique": { + "name": "app_date_unique", + "columns": ["appId", "snapshotDate"] + } + }, + "checkConstraint": {} + }, + "developer_delivery_daily": { + "name": "developer_delivery_daily", + "columns": { + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "day": { + "name": "day", + "type": "date", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "tier": { + "name": "tier", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "seconds": { + "name": "seconds", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "bytes": { + "name": "bytes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "requests": { + "name": "requests", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "abandonedBytes": { + "name": "abandonedBytes", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "final": { + "name": "final", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "finalizedAt": { + "name": "finalizedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "day_idx": { + "name": "day_idx", + "columns": ["day"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_delivery_daily_appId_developer_apps_id_fk": { + "name": "developer_delivery_daily_appId_developer_apps_id_fk", + "tableFrom": "developer_delivery_daily", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_delivery_daily_appId_day_tier_pk": { + "name": "developer_delivery_daily_appId_day_tier_pk", + "columns": ["appId", "day", "tier"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_delivery_log_files": { + "name": "developer_delivery_log_files", + "columns": { + "logFile": { + "name": "logFile", + "type": "varchar(191)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "etag": { + "name": "etag", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "logHour": { + "name": "logHour", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "parts": { + "name": "parts", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "processedAt": { + "name": "processedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "log_hour_idx": { + "name": "log_hour_idx", + "columns": ["logHour"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "developer_delivery_log_files_logFile": { + "name": "developer_delivery_log_files_logFile", + "columns": ["logFile"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_transcripts": { + "name": "developer_transcripts", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "externalUserId": { + "name": "externalUserId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Untitled'" + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sourceType": { + "name": "sourceType", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sourceUrl": { + "name": "sourceUrl", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requestedAt": { + "name": "requestedAt", + "type": "timestamp(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "s3Key": { + "name": "s3Key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "resultKey": { + "name": "resultKey", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "sourceBytes": { + "name": "sourceBytes", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "durationSeconds": { + "name": "durationSeconds", + "type": "float", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requestedLanguage": { + "name": "requestedLanguage", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "language": { + "name": "language", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "text": { + "name": "text", + "type": "mediumtext", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "wordCount": { + "name": "wordCount", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "reservedMicroCredits": { + "name": "reservedMicroCredits", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "billedMicroCredits": { + "name": "billedMicroCredits", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "errorCode": { + "name": "errorCode", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "errorMessage": { + "name": "errorMessage", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "runId": { + "name": "runId", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "queuedAt": { + "name": "queuedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "startedAt": { + "name": "startedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completedAt": { + "name": "completedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deletedAt": { + "name": "deletedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "dev_transcripts_app_list_idx": { + "name": "dev_transcripts_app_list_idx", + "columns": ["appId", "deletedAt", "createdAt", "id"], + "isUnique": false + }, + "dev_transcripts_app_user_idx": { + "name": "dev_transcripts_app_user_idx", + "columns": ["appId", "externalUserId", "createdAt"], + "isUnique": false + }, + "dev_transcripts_app_status_idx": { + "name": "dev_transcripts_app_status_idx", + "columns": ["appId", "status", "createdAt"], + "isUnique": false + }, + "dev_transcripts_status_updated_idx": { + "name": "dev_transcripts_status_updated_idx", + "columns": ["status", "updatedAt"], + "isUnique": false + }, + "dev_transcripts_app_completed_idx": { + "name": "dev_transcripts_app_completed_idx", + "columns": [ + "appId", + "status", + "completedAt", + "durationSeconds", + "billedMicroCredits" + ], + "isUnique": false + }, + "dev_transcripts_app_status_held_idx": { + "name": "dev_transcripts_app_status_held_idx", + "columns": [ + "appId", + "status", + "createdAt", + "deletedAt", + "reservedMicroCredits" + ], + "isUnique": false + }, + "dev_transcripts_app_video_idx": { + "name": "dev_transcripts_app_video_idx", + "columns": ["appId", "videoId", "requestedAt", "id"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_transcripts_appId_developer_apps_id_fk": { + "name": "developer_transcripts_appId_developer_apps_id_fk", + "tableFrom": "developer_transcripts", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_transcripts_id": { + "name": "developer_transcripts_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_video_imports": { + "name": "developer_video_imports", + "columns": { + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyId": { + "name": "keyId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sourceUrl": { + "name": "sourceUrl", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'downloading'" + }, + "bytes": { + "name": "bytes", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "errorCode": { + "name": "errorCode", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "startedAt": { + "name": "startedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "finishedAt": { + "name": "finishedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "dev_imports_app_state_idx": { + "name": "dev_imports_app_state_idx", + "columns": ["appId", "state"], + "isUnique": false + }, + "dev_imports_key_created_idx": { + "name": "dev_imports_key_created_idx", + "columns": ["keyId", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_video_imports_appId_developer_apps_id_fk": { + "name": "developer_video_imports_appId_developer_apps_id_fk", + "tableFrom": "developer_video_imports", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_video_imports_videoId": { + "name": "developer_video_imports_videoId", + "columns": ["videoId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_videos": { + "name": "developer_videos", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "externalUserId": { + "name": "externalUserId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Untitled'" + }, + "duration": { + "name": "duration", + "type": "float", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "width": { + "name": "width", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "height": { + "name": "height", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fps": { + "name": "fps", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "s3Key": { + "name": "s3Key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "transcriptionStatus": { + "name": "transcriptionStatus", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'uploading'" + }, + "playbackId": { + "name": "playbackId", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "maxResolutionTier": { + "name": "maxResolutionTier", + "type": "varchar(8)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'1080p'" + }, + "renditions": { + "name": "renditions", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "storedBytes": { + "name": "storedBytes", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "errorReason": { + "name": "errorReason", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "processing": { + "name": "processing", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "storagePaidUntil": { + "name": "storagePaidUntil", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deletedAt": { + "name": "deletedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "filesDeletedAt": { + "name": "filesDeletedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "app_created_idx": { + "name": "app_created_idx", + "columns": ["appId", "createdAt"], + "isUnique": false + }, + "app_user_idx": { + "name": "app_user_idx", + "columns": ["appId", "externalUserId"], + "isUnique": false + }, + "app_deleted_idx": { + "name": "app_deleted_idx", + "columns": ["appId", "deletedAt"], + "isUnique": false + }, + "playback_id_idx": { + "name": "playback_id_idx", + "columns": ["playbackId"], + "isUnique": true + }, + "files_pending_idx": { + "name": "files_pending_idx", + "columns": ["filesDeletedAt", "deletedAt"], + "isUnique": false + }, + "app_storage_idx": { + "name": "app_storage_idx", + "columns": [ + "appId", + "deletedAt", + "status", + "maxResolutionTier", + "width", + "height", + "storagePaidUntil", + "duration", + "createdAt" + ], + "isUnique": false + }, + "first_month_due_idx": { + "name": "first_month_due_idx", + "columns": ["storagePaidUntil", "status", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_videos_appId_developer_apps_id_fk": { + "name": "developer_videos_appId_developer_apps_id_fk", + "tableFrom": "developer_videos", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_videos_id": { + "name": "developer_videos_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "developer_webhook_endpoints": { + "name": "developer_webhook_endpoints", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "appId": { + "name": "appId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "url": { + "name": "url", + "type": "varchar(2048)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secretPrefix": { + "name": "secretPrefix", + "type": "varchar(12)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "encryptedSecret": { + "name": "encryptedSecret", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "events": { + "name": "events", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "enabled": { + "name": "enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "disabledReason": { + "name": "disabledReason", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastDeliveryAt": { + "name": "lastDeliveryAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastDeliveryStatus": { + "name": "lastDeliveryStatus", + "type": "varchar(16)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastResponseStatus": { + "name": "lastResponseStatus", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastErrorCode": { + "name": "lastErrorCode", + "type": "varchar(32)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "consecutiveFailures": { + "name": "consecutiveFailures", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "failingSince": { + "name": "failingSince", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deletedAt": { + "name": "deletedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "dev_webhooks_app_list_idx": { + "name": "dev_webhooks_app_list_idx", + "columns": ["appId", "deletedAt", "createdAt", "id"], + "isUnique": false + } + }, + "foreignKeys": { + "developer_webhook_endpoints_appId_developer_apps_id_fk": { + "name": "developer_webhook_endpoints_appId_developer_apps_id_fk", + "tableFrom": "developer_webhook_endpoints", + "tableTo": "developer_apps", + "columnsFrom": ["appId"], + "columnsTo": ["id"], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "developer_webhook_endpoints_id": { + "name": "developer_webhook_endpoints_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "directory_users": { + "name": "directory_users", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "directoryId": { + "name": "directoryId", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "directory_users_organization_id_idx": { + "name": "directory_users_organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "directory_users_user_org_idx": { + "name": "directory_users_user_org_idx", + "columns": ["userId", "organizationId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "directory_users_id": { + "name": "directory_users_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "email_change_requests": { + "name": "email_change_requests", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "newEmail": { + "name": "newEmail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "codeHash": { + "name": "codeHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "attempts": { + "name": "attempts", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "expiresAt": { + "name": "expiresAt", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "user_id_idx": { + "name": "user_id_idx", + "columns": ["userId"], + "isUnique": false + }, + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "email_change_requests_id": { + "name": "email_change_requests_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "folders": { + "name": "folders", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "color": { + "name": "color", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'normal'" + }, + "public": { + "name": "public", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdById": { + "name": "createdById", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "parentId": { + "name": "parentId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "spaceId": { + "name": "spaceId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "organization_id_idx": { + "name": "organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "created_by_id_idx": { + "name": "created_by_id_idx", + "columns": ["createdById"], + "isUnique": false + }, + "parent_id_idx": { + "name": "parent_id_idx", + "columns": ["parentId"], + "isUnique": false + }, + "space_id_idx": { + "name": "space_id_idx", + "columns": ["spaceId"], + "isUnique": false + }, + "public_parent_id_idx": { + "name": "public_parent_id_idx", + "columns": ["public", "parentId"], + "isUnique": false + }, + "public_space_parent_id_idx": { + "name": "public_space_parent_id_idx", + "columns": ["public", "spaceId", "parentId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "folders_id": { + "name": "folders_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "imported_videos": { + "name": "imported_videos", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "orgId": { + "name": "orgId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "source_id": { + "name": "source_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "id_idx": { + "name": "id_idx", + "columns": ["id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "imported_videos_orgId_source_source_id_pk": { + "name": "imported_videos_orgId_source_source_id_pk", + "columns": ["orgId", "source", "source_id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "integration_installations": { + "name": "integration_installations", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "externalId": { + "name": "externalId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "displayName": { + "name": "displayName", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "installedByUserId": { + "name": "installedByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "encryptedCredentials": { + "name": "encryptedCredentials", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "provider_external_id_idx": { + "name": "provider_external_id_idx", + "columns": ["provider", "externalId"], + "isUnique": true + }, + "organization_provider_display_name_idx": { + "name": "organization_provider_display_name_idx", + "columns": ["organizationId", "provider", "displayName"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "integration_installations_id": { + "name": "integration_installations_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "loom_migration_imports": { + "name": "loom_migration_imports", + "columns": { + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "requestId": { + "name": "requestId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "loom_migration_imports_request_idx": { + "name": "loom_migration_imports_request_idx", + "columns": ["requestId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "loom_migration_imports_videoId": { + "name": "loom_migration_imports_videoId", + "columns": ["videoId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "loom_migration_requests": { + "name": "loom_migration_requests", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "activeOrganizationId": { + "name": "activeOrganizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "requestedByUserId": { + "name": "requestedByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workspaceName": { + "name": "workspaceName", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customerNote": { + "name": "customerNote", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customerReply": { + "name": "customerReply", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "invitedAt": { + "name": "invitedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "capMessage": { + "name": "capMessage", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expectedVideoCount": { + "name": "expectedVideoCount", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "importedVideoCount": { + "name": "importedVideoCount", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "queuedVideoCount": { + "name": "queuedVideoCount", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "activeImportCount": { + "name": "activeImportCount", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "activeImportLeaseToken": { + "name": "activeImportLeaseToken", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "activeImportLeaseUntil": { + "name": "activeImportLeaseUntil", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastOperatorUserId": { + "name": "lastOperatorUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastOperatorAt": { + "name": "lastOperatorAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "completedAt": { + "name": "completedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updatedAt": { + "name": "updatedAt", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "loom_migration_active_org_idx": { + "name": "loom_migration_active_org_idx", + "columns": ["activeOrganizationId"], + "isUnique": true + }, + "loom_migration_org_created_idx": { + "name": "loom_migration_org_created_idx", + "columns": ["organizationId", "createdAt"], + "isUnique": false + }, + "loom_migration_status_created_idx": { + "name": "loom_migration_status_created_idx", + "columns": ["status", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "loom_migration_requests_id": { + "name": "loom_migration_requests_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "loops_sync_jobs": { + "name": "loops_sync_jobs", + "columns": { + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "revision": { + "name": "revision", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "nextAttemptAt": { + "name": "nextAttemptAt", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "leaseToken": { + "name": "leaseToken", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "leaseUntil": { + "name": "leaseUntil", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "failures": { + "name": "failures", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "lastError": { + "name": "lastError", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "profileHash": { + "name": "profileHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "teammateJoinedAt": { + "name": "teammateJoinedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "syncedEmail": { + "name": "syncedEmail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastSyncedAt": { + "name": "lastSyncedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "loops_sync_due_idx": { + "name": "loops_sync_due_idx", + "columns": ["nextAttemptAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "loops_sync_jobs_userId": { + "name": "loops_sync_jobs_userId", + "columns": ["userId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "mcp_oauth_clients": { + "name": "mcp_oauth_clients", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "clientId": { + "name": "clientId", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "clientName": { + "name": "clientName", + "type": "varchar(100)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "redirectUris": { + "name": "redirectUris", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "activatedAt": { + "name": "activatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "client_id_idx": { + "name": "client_id_idx", + "columns": ["clientId"], + "isUnique": true + }, + "inactive_created_at_idx": { + "name": "inactive_created_at_idx", + "columns": ["activatedAt", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mcp_oauth_clients_id": { + "name": "mcp_oauth_clients_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "mcp_oauth_codes": { + "name": "mcp_oauth_codes", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "clientId": { + "name": "clientId", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "codeHash": { + "name": "codeHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "codeChallenge": { + "name": "codeChallenge", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "redirectUri": { + "name": "redirectUri", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resource": { + "name": "resource", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "consumedAt": { + "name": "consumedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "code_hash_idx": { + "name": "code_hash_idx", + "columns": ["codeHash"], + "isUnique": true + }, + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mcp_oauth_codes_id": { + "name": "mcp_oauth_codes_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "mcp_oauth_registration_quotas": { + "name": "mcp_oauth_registration_quotas", + "columns": { + "windowId": { + "name": "windowId", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "registrations": { + "name": "registrations", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "expires_at_idx": { + "name": "expires_at_idx", + "columns": ["expiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mcp_oauth_registration_quotas_windowId": { + "name": "mcp_oauth_registration_quotas_windowId", + "columns": ["windowId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "mcp_oauth_tokens": { + "name": "mcp_oauth_tokens", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "clientId": { + "name": "clientId", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "familyId": { + "name": "familyId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "resource": { + "name": "resource", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "accessHash": { + "name": "accessHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refreshHash": { + "name": "refreshHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "accessExpiresAt": { + "name": "accessExpiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refreshExpiresAt": { + "name": "refreshExpiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "revokedAt": { + "name": "revokedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "access_hash_idx": { + "name": "access_hash_idx", + "columns": ["accessHash"], + "isUnique": true + }, + "refresh_hash_idx": { + "name": "refresh_hash_idx", + "columns": ["refreshHash"], + "isUnique": true + }, + "family_id_idx": { + "name": "family_id_idx", + "columns": ["familyId"], + "isUnique": false + }, + "client_active_idx": { + "name": "client_active_idx", + "columns": ["clientId", "revokedAt", "refreshExpiresAt"], + "isUnique": false + }, + "refresh_expires_at_idx": { + "name": "refresh_expires_at_idx", + "columns": ["refreshExpiresAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mcp_oauth_tokens_id": { + "name": "mcp_oauth_tokens_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "media_processing_budgets": { + "name": "media_processing_budgets", + "columns": { + "id": { + "name": "id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "reserved_bytes": { + "name": "reserved_bytes", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "limit_bytes": { + "name": "limit_bytes", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "media_budget_expiry_idx": { + "name": "media_budget_expiry_idx", + "columns": ["expires_at"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "media_processing_budgets_id": { + "name": "media_processing_budgets_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "messenger_conversations": { + "name": "messenger_conversations", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "agent": { + "name": "agent", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "mode": { + "name": "mode", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'agent'" + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "anonymousId": { + "name": "anonymousId", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "takeoverByUserId": { + "name": "takeoverByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "takeoverAt": { + "name": "takeoverAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "lastMessageAt": { + "name": "lastMessageAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "user_last_message_idx": { + "name": "user_last_message_idx", + "columns": ["userId", "lastMessageAt"], + "isUnique": false + }, + "anonymous_last_message_idx": { + "name": "anonymous_last_message_idx", + "columns": ["anonymousId", "lastMessageAt"], + "isUnique": false + }, + "mode_last_message_idx": { + "name": "mode_last_message_idx", + "columns": ["mode", "lastMessageAt"], + "isUnique": false + }, + "updated_at_idx": { + "name": "updated_at_idx", + "columns": ["updatedAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "messenger_conversations_id": { + "name": "messenger_conversations_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "messenger_messages": { + "name": "messenger_messages", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "conversationId": { + "name": "conversationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "content": { + "name": "content", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "anonymousId": { + "name": "anonymousId", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "conversation_created_at_idx": { + "name": "conversation_created_at_idx", + "columns": ["conversationId", "createdAt"], + "isUnique": false + }, + "role_created_at_idx": { + "name": "role_created_at_idx", + "columns": ["role", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": { + "messenger_messages_conversationId_messenger_conversations_id_fk": { + "name": "messenger_messages_conversationId_messenger_conversations_id_fk", + "tableFrom": "messenger_messages", + "tableTo": "messenger_conversations", + "columnsFrom": ["conversationId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "messenger_messages_id": { + "name": "messenger_messages_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "messenger_support_emails": { + "name": "messenger_support_emails", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "conversationId": { + "name": "conversationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userEmail": { + "name": "userEmail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "subject": { + "name": "subject", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "message": { + "name": "message", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "support_email_user_created_at_idx": { + "name": "support_email_user_created_at_idx", + "columns": ["userId", "createdAt"], + "isUnique": false + }, + "support_email_conversation_created_at_idx": { + "name": "support_email_conversation_created_at_idx", + "columns": ["conversationId", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": { + "support_email_conversation_fk": { + "name": "support_email_conversation_fk", + "tableFrom": "messenger_support_emails", + "tableTo": "messenger_conversations", + "columnsFrom": ["conversationId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "messenger_support_emails_id": { + "name": "messenger_support_emails_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "mobile_push_claims": { + "name": "mobile_push_claims", + "columns": { + "id": { + "name": "id", + "type": "varchar(128)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "created_at_idx": { + "name": "created_at_idx", + "columns": ["createdAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mobile_push_claims_id": { + "name": "mobile_push_claims_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "mobile_push_tokens": { + "name": "mobile_push_tokens", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "varchar(200)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sessionHash": { + "name": "sessionHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "environment": { + "name": "environment", + "type": "varchar(10)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "token_idx": { + "name": "token_idx", + "columns": ["token"], + "isUnique": true + }, + "user_id_idx": { + "name": "user_id_idx", + "columns": ["userId"], + "isUnique": false + }, + "session_hash_idx": { + "name": "session_hash_idx", + "columns": ["sessionHash"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "mobile_push_tokens_id": { + "name": "mobile_push_tokens_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "notifications": { + "name": "notifications", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "orgId": { + "name": "orgId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "recipientId": { + "name": "recipientId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "varchar(16)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "data": { + "name": "data", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(50)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "dedupKey": { + "name": "dedupKey", + "type": "varchar(128)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "readAt": { + "name": "readAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "org_id_idx": { + "name": "org_id_idx", + "columns": ["orgId"], + "isUnique": false + }, + "type_idx": { + "name": "type_idx", + "columns": ["type"], + "isUnique": false + }, + "read_at_idx": { + "name": "read_at_idx", + "columns": ["readAt"], + "isUnique": false + }, + "created_at_idx": { + "name": "created_at_idx", + "columns": ["createdAt"], + "isUnique": false + }, + "recipient_read_idx": { + "name": "recipient_read_idx", + "columns": ["recipientId", "readAt"], + "isUnique": false + }, + "recipient_created_idx": { + "name": "recipient_created_idx", + "columns": ["recipientId", "createdAt"], + "isUnique": false + }, + "dedup_key_idx": { + "name": "dedup_key_idx", + "columns": ["dedupKey"], + "isUnique": true + }, + "type_recipient_created_idx": { + "name": "type_recipient_created_idx", + "columns": ["type", "recipientId", "createdAt"], + "isUnique": false + }, + "type_recipient_video_created_idx": { + "name": "type_recipient_video_created_idx", + "columns": ["type", "recipientId", "videoId", "createdAt"], + "isUnique": false + }, + "video_id_idx": { + "name": "video_id_idx", + "columns": ["videoId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "notifications_id": { + "name": "notifications_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "organization_directory_sync": { + "name": "organization_directory_sync", + "columns": { + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "requestedAt": { + "name": "requestedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "syncedAt": { + "name": "syncedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "leaseExpiresAt": { + "name": "leaseExpiresAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastError": { + "name": "lastError", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "heldRemovals": { + "name": "heldRemovals", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "removalsApprovedAt": { + "name": "removalsApprovedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "organization_directory_sync_organizationId": { + "name": "organization_directory_sync_organizationId", + "columns": ["organizationId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "organization_invites": { + "name": "organization_invites", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "invitedEmail": { + "name": "invitedEmail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "invitedByUserId": { + "name": "invitedByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "expiresAt": { + "name": "expiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "organization_id_idx": { + "name": "organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "invited_email_idx": { + "name": "invited_email_idx", + "columns": ["invitedEmail"], + "isUnique": false + }, + "invited_by_user_id_idx": { + "name": "invited_by_user_id_idx", + "columns": ["invitedByUserId"], + "isUnique": false + }, + "status_idx": { + "name": "status_idx", + "columns": ["status"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "organization_invites_id": { + "name": "organization_invites_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "organization_members": { + "name": "organization_members", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hasProSeat": { + "name": "hasProSeat", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "organization_id_idx": { + "name": "organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "user_id_organization_id_idx": { + "name": "user_id_organization_id_idx", + "columns": ["userId", "organizationId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "organization_members_id": { + "name": "organization_members_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "organization_sso": { + "name": "organization_sso", + "columns": { + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "purchasedByUserId": { + "name": "purchasedByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "stripeCustomerId": { + "name": "stripeCustomerId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripeSubscriptionId": { + "name": "stripeSubscriptionId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripePriceId": { + "name": "stripePriceId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'unpaid'" + }, + "paidThrough": { + "name": "paidThrough", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "currentPeriodEnd": { + "name": "currentPeriodEnd", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "cancelAtPeriodEnd": { + "name": "cancelAtPeriodEnd", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "checkoutAttemptId": { + "name": "checkoutAttemptId", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checkoutCurrency": { + "name": "checkoutCurrency", + "type": "varchar(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checkoutPriceId": { + "name": "checkoutPriceId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checkoutSessionId": { + "name": "checkoutSessionId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "checkoutStartedAt": { + "name": "checkoutStartedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "sso_stripe_subscription_id_idx": { + "name": "sso_stripe_subscription_id_idx", + "columns": ["stripeSubscriptionId"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "organization_sso_organizationId": { + "name": "organization_sso_organizationId", + "columns": ["organizationId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "organizations": { + "name": "organizations", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "tombstoneAt": { + "name": "tombstoneAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "allowedEmailDomain": { + "name": "allowedEmailDomain", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "defaultVideoVisibility": { + "name": "defaultVideoVisibility", + "type": "varchar(7)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customDomain": { + "name": "customDomain", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "domainVerified": { + "name": "domainVerified", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "iconUrl": { + "name": "iconUrl", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "shareableLinkIconUrl": { + "name": "shareableLinkIconUrl", + "type": "varchar(1024)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "workosOrganizationId": { + "name": "workosOrganizationId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "workosConnectionId": { + "name": "workosConnectionId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "owner_id_tombstone_idx": { + "name": "owner_id_tombstone_idx", + "columns": ["ownerId", "tombstoneAt"], + "isUnique": false + }, + "custom_domain_idx": { + "name": "custom_domain_idx", + "columns": ["customDomain"], + "isUnique": false + }, + "workos_organization_id_idx": { + "name": "workos_organization_id_idx", + "columns": ["workosOrganizationId"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "organizations_id": { + "name": "organizations_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "s3_buckets": { + "name": "s3_buckets", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "region": { + "name": "region", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "endpoint": { + "name": "endpoint", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "bucketName": { + "name": "bucketName", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "accessKeyId": { + "name": "accessKeyId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "secretAccessKey": { + "name": "secretAccessKey", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "('aws')" + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "owner_organization_idx": { + "name": "owner_organization_idx", + "columns": ["ownerId", "organizationId"], + "isUnique": false + }, + "organization_id_idx": { + "name": "organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "organization_active_idx": { + "name": "organization_active_idx", + "columns": ["organizationId", "active", "updatedAt"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "s3_buckets_id": { + "name": "s3_buckets_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "sessions": { + "name": "sessions", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sessionToken": { + "name": "sessionToken", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "session_token_idx": { + "name": "session_token_idx", + "columns": ["sessionToken"], + "isUnique": true + }, + "user_id_idx": { + "name": "user_id_idx", + "columns": ["userId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "sessions_id": { + "name": "sessions_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "shared_videos": { + "name": "shared_videos", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "folderId": { + "name": "folderId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sharedByUserId": { + "name": "sharedByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sharedAt": { + "name": "sharedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + } + }, + "indexes": { + "folder_id_idx": { + "name": "folder_id_idx", + "columns": ["folderId"], + "isUnique": false + }, + "organization_id_idx": { + "name": "organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "shared_by_user_id_idx": { + "name": "shared_by_user_id_idx", + "columns": ["sharedByUserId"], + "isUnique": false + }, + "video_id_organization_id_idx": { + "name": "video_id_organization_id_idx", + "columns": ["videoId", "organizationId"], + "isUnique": false + }, + "video_id_folder_id_idx": { + "name": "video_id_folder_id_idx", + "columns": ["videoId", "folderId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "shared_videos_id": { + "name": "shared_videos_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "signed_baas": { + "name": "signed_baas", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "stripeSubscriptionId": { + "name": "stripeSubscriptionId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "entityName": { + "name": "entityName", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entityType": { + "name": "entityType", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "entityAddress": { + "name": "entityAddress", + "type": "varchar(500)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "signerName": { + "name": "signerName", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "signerTitle": { + "name": "signerTitle", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "noticesEmail": { + "name": "noticesEmail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "signatureData": { + "name": "signatureData", + "type": "longtext", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "signedAt": { + "name": "signedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "emailSentAt": { + "name": "emailSentAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "signed_baa_organization_id_idx": { + "name": "signed_baa_organization_id_idx", + "columns": ["organizationId"], + "isUnique": true + }, + "signed_baa_stripe_subscription_idx": { + "name": "signed_baa_stripe_subscription_idx", + "columns": ["stripeSubscriptionId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "signed_baas_id": { + "name": "signed_baas_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "space_members": { + "name": "space_members", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "spaceId": { + "name": "spaceId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'member'" + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "user_id_idx": { + "name": "user_id_idx", + "columns": ["userId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "space_members_id": { + "name": "space_members_id", + "columns": ["id"] + } + }, + "uniqueConstraints": { + "space_id_user_id_unique": { + "name": "space_id_user_id_unique", + "columns": ["spaceId", "userId"] + } + }, + "checkConstraint": {} + }, + "space_videos": { + "name": "space_videos", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "spaceId": { + "name": "spaceId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "folderId": { + "name": "folderId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "addedById": { + "name": "addedById", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "addedAt": { + "name": "addedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "position": { + "name": "position", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "folder_id_idx": { + "name": "folder_id_idx", + "columns": ["folderId"], + "isUnique": false + }, + "video_id_idx": { + "name": "video_id_idx", + "columns": ["videoId"], + "isUnique": false + }, + "added_by_id_idx": { + "name": "added_by_id_idx", + "columns": ["addedById"], + "isUnique": false + }, + "space_id_video_id_idx": { + "name": "space_id_video_id_idx", + "columns": ["spaceId", "videoId"], + "isUnique": false + }, + "space_id_folder_id_idx": { + "name": "space_id_folder_id_idx", + "columns": ["spaceId", "folderId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "space_videos_id": { + "name": "space_videos_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "spaces": { + "name": "spaces", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "primary": { + "name": "primary", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdById": { + "name": "createdById", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "iconUrl": { + "name": "iconUrl", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "description": { + "name": "description", + "type": "varchar(1000)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "privacy": { + "name": "privacy", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'Private'" + }, + "public": { + "name": "public", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + } + }, + "indexes": { + "organization_id_idx": { + "name": "organization_id_idx", + "columns": ["organizationId"], + "isUnique": false + }, + "created_by_id_idx": { + "name": "created_by_id_idx", + "columns": ["createdById"], + "isUnique": false + }, + "public_organization_id_idx": { + "name": "public_organization_id_idx", + "columns": ["public", "organizationId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "spaces_id": { + "name": "spaces_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "storage_integrations": { + "name": "storage_integrations", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "organizationId": { + "name": "organizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "displayName": { + "name": "displayName", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "status": { + "name": "status", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'active'" + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "encryptedConfig": { + "name": "encryptedConfig", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "googleDriveAccessToken": { + "name": "googleDriveAccessToken", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "googleDriveAccessTokenExpiresAt": { + "name": "googleDriveAccessTokenExpiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "googleDriveTokenRefreshLeaseId": { + "name": "googleDriveTokenRefreshLeaseId", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "googleDriveTokenRefreshLeaseExpiresAt": { + "name": "googleDriveTokenRefreshLeaseExpiresAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "googleDriveStorageQuotaCache": { + "name": "googleDriveStorageQuotaCache", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "owner_provider_idx": { + "name": "owner_provider_idx", + "columns": ["ownerId", "provider"], + "isUnique": false + }, + "owner_active_idx": { + "name": "owner_active_idx", + "columns": ["ownerId", "active"], + "isUnique": false + }, + "organization_provider_idx": { + "name": "organization_provider_idx", + "columns": ["organizationId", "provider"], + "isUnique": false + }, + "organization_active_idx": { + "name": "organization_active_idx", + "columns": ["organizationId", "active", "status"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "storage_integrations_id": { + "name": "storage_integrations_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "storage_objects": { + "name": "storage_objects", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "integrationId": { + "name": "integrationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "objectKey": { + "name": "objectKey", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "objectKeyHash": { + "name": "objectKeyHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerObjectId": { + "name": "providerObjectId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "uploadSessionUrl": { + "name": "uploadSessionUrl", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "uploadStatus": { + "name": "uploadStatus", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'pending'" + }, + "contentType": { + "name": "contentType", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "contentLength": { + "name": "contentLength", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": { + "integration_key_hash_idx": { + "name": "integration_key_hash_idx", + "columns": ["integrationId", "objectKeyHash"], + "isUnique": true + }, + "integration_status_idx": { + "name": "integration_status_idx", + "columns": ["integrationId", "uploadStatus"], + "isUnique": false + }, + "integration_object_key_prefix_idx": { + "name": "integration_object_key_prefix_idx", + "columns": ["integrationId", "`objectKey`(191)"], + "isUnique": false + }, + "video_id_idx": { + "name": "video_id_idx", + "columns": ["videoId"], + "isUnique": false + }, + "owner_id_idx": { + "name": "owner_id_idx", + "columns": ["ownerId"], + "isUnique": false + } + }, + "foreignKeys": { + "storage_objects_integrationId_storage_integrations_id_fk": { + "name": "storage_objects_integrationId_storage_integrations_id_fk", + "tableFrom": "storage_objects", + "tableTo": "storage_integrations", + "columnsFrom": ["integrationId"], + "columnsTo": ["id"], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "storage_objects_id": { + "name": "storage_objects_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "user_passkeys": { + "name": "user_passkeys", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialId": { + "name": "credentialId", + "type": "varchar(1400)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "credentialIdHash": { + "name": "credentialIdHash", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "publicKey": { + "name": "publicKey", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "counter": { + "name": "counter", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "transports": { + "name": "transports", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "deviceType": { + "name": "deviceType", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "backedUp": { + "name": "backedUp", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "confirmsIdentity": { + "name": "confirmsIdentity", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "aaguid": { + "name": "aaguid", + "type": "varchar(36)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "lastUsedAt": { + "name": "lastUsedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "credential_id_hash_idx": { + "name": "credential_id_hash_idx", + "columns": ["credentialIdHash"], + "isUnique": true + }, + "user_id_idx": { + "name": "user_id_idx", + "columns": ["userId"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "user_passkeys_id": { + "name": "user_passkeys_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "users": { + "name": "users", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "lastName": { + "name": "lastName", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "emailVerified": { + "name": "emailVerified", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripeCustomerId": { + "name": "stripeCustomerId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripeSubscriptionId": { + "name": "stripeSubscriptionId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "thirdPartyStripeSubscriptionId": { + "name": "thirdPartyStripeSubscriptionId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripeSubscriptionStatus": { + "name": "stripeSubscriptionStatus", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "stripeSubscriptionPriceId": { + "name": "stripeSubscriptionPriceId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "preferences": { + "name": "preferences", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "('null')" + }, + "activeOrganizationId": { + "name": "activeOrganizationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "onboardingSteps": { + "name": "onboardingSteps", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "onboarding_completed_at": { + "name": "onboarding_completed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "customBucket": { + "name": "customBucket", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "inviteQuota": { + "name": "inviteQuota", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 1 + }, + "defaultOrgId": { + "name": "defaultOrgId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "authSessionVersion": { + "name": "authSessionVersion", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "marketingOrigin": { + "name": "marketingOrigin", + "type": "varchar(20)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'unknown'" + } + }, + "indexes": { + "email_idx": { + "name": "email_idx", + "columns": ["email"], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "users_id": { + "name": "users_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "verification_tokens": { + "name": "verification_tokens", + "columns": { + "identifier": { + "name": "identifier", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "datetime", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verification_tokens_identifier": { + "name": "verification_tokens_identifier", + "columns": ["identifier"] + } + }, + "uniqueConstraints": { + "verification_tokens_token_unique": { + "name": "verification_tokens_token_unique", + "columns": ["token"] + } + }, + "checkConstraint": {} + }, + "video_edits": { + "name": "video_edits", + "columns": { + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "sourceKey": { + "name": "sourceKey", + "type": "varchar(512)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "editSpec": { + "name": "editSpec", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + } + }, + "indexes": {}, + "foreignKeys": { + "video_edits_videoId_videos_id_fk": { + "name": "video_edits_videoId_videos_id_fk", + "tableFrom": "video_edits", + "tableTo": "videos", + "columnsFrom": ["videoId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "video_edits_videoId": { + "name": "video_edits_videoId", + "columns": ["videoId"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "video_processing_jobs": { + "name": "video_processing_jobs", + "columns": { + "video_id": { + "name": "video_id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "owner_id": { + "name": "owner_id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "generation": { + "name": "generation", + "type": "varchar(64)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "manifest_sha256": { + "name": "manifest_sha256", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "state": { + "name": "state", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'committing'" + }, + "attempt_id": { + "name": "attempt_id", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "attempt_count": { + "name": "attempt_count", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "lease_expires_at": { + "name": "lease_expires_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "next_retry_at": { + "name": "next_retry_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "workflow_run_id": { + "name": "workflow_run_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "remote_job_id": { + "name": "remote_job_id", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "verification": { + "name": "verification", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "output": { + "name": "output", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_code": { + "name": "error_code", + "type": "varchar(64)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "error_message": { + "name": "error_message", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "created_at": { + "name": "created_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "updated_at": { + "name": "updated_at", + "type": "datetime(3)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "processing_state_retry_video_idx": { + "name": "processing_state_retry_video_idx", + "columns": ["state", "next_retry_at", "video_id"], + "isUnique": false + }, + "processing_state_lease_video_idx": { + "name": "processing_state_lease_video_idx", + "columns": ["state", "lease_expires_at", "video_id"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "video_processing_jobs_video_id": { + "name": "video_processing_jobs_video_id", + "columns": ["video_id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "video_uploads": { + "name": "video_uploads", + "columns": { + "video_id": { + "name": "video_id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "uploaded": { + "name": "uploaded", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "total": { + "name": "total", + "type": "bigint unsigned", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "started_at": { + "name": "started_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "mode": { + "name": "mode", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "phase": { + "name": "phase", + "type": "varchar(32)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'uploading'" + }, + "processing_progress": { + "name": "processing_progress", + "type": "int", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": 0 + }, + "processing_message": { + "name": "processing_message", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "processing_error": { + "name": "processing_error", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "raw_file_key": { + "name": "raw_file_key", + "type": "varchar(512)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "phase_updated_at_video_id_idx": { + "name": "phase_updated_at_video_id_idx", + "columns": ["phase", "updated_at", "video_id"], + "isUnique": false + }, + "started_at_idx": { + "name": "started_at_idx", + "columns": ["started_at"], + "isUnique": false + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": { + "video_uploads_video_id": { + "name": "video_uploads_video_id", + "columns": ["video_id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "video_viewer_grants": { + "name": "video_viewer_grants", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "videoId": { + "name": "videoId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "invitedByUserId": { + "name": "invitedByUserId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "revokedAt": { + "name": "revokedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": { + "video_email_idx": { + "name": "video_email_idx", + "columns": ["videoId", "email"], + "isUnique": true + } + }, + "foreignKeys": { + "video_viewer_grants_videoId_videos_id_fk": { + "name": "video_viewer_grants_videoId_videos_id_fk", + "tableFrom": "video_viewer_grants", + "tableTo": "videos", + "columnsFrom": ["videoId"], + "columnsTo": ["id"], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "video_viewer_grants_id": { + "name": "video_viewer_grants_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + }, + "videos": { + "name": "videos", + "columns": { + "id": { + "name": "id", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "ownerId": { + "name": "ownerId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "orgId": { + "name": "orgId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "'My Video'" + }, + "bucket": { + "name": "bucket", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "storageIntegrationId": { + "name": "storageIntegrationId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "duration": { + "name": "duration", + "type": "float", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "width": { + "name": "width", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "height": { + "name": "height", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "fps": { + "name": "fps", + "type": "int", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "metadata": { + "name": "metadata", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "public": { + "name": "public", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": true + }, + "settings": { + "name": "settings", + "type": "json", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "transcriptionStatus": { + "name": "transcriptionStatus", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "source": { + "name": "source", + "type": "json", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "('{\"type\":\"MediaConvert\"}')" + }, + "folderId": { + "name": "folderId", + "type": "varchar(15)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": "(now())" + }, + "effectiveCreatedAt": { + "name": "effectiveCreatedAt", + "type": "datetime", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "generated": { + "as": "COALESCE(\n STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(`metadata`, '$.customCreatedAt')), '%Y-%m-%dT%H:%i:%s.%fZ'),\n STR_TO_DATE(JSON_UNQUOTE(JSON_EXTRACT(`metadata`, '$.customCreatedAt')), '%Y-%m-%dT%H:%i:%sZ'),\n `createdAt`\n )", + "type": "stored" + } + }, + "updatedAt": { + "name": "updatedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "onUpdate": true, + "default": "(now())" + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "xStreamInfo": { + "name": "xStreamInfo", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "firstViewEmailSentAt": { + "name": "firstViewEmailSentAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "isScreenshot": { + "name": "isScreenshot", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + }, + "archivedAt": { + "name": "archivedAt", + "type": "timestamp", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "awsRegion": { + "name": "awsRegion", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "awsBucket": { + "name": "awsBucket", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "videoStartTime": { + "name": "videoStartTime", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "audioStartTime": { + "name": "audioStartTime", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "jobId": { + "name": "jobId", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "jobStatus": { + "name": "jobStatus", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "skipProcessing": { + "name": "skipProcessing", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "autoincrement": false, + "default": false + } + }, + "indexes": { + "owner_id_idx": { + "name": "owner_id_idx", + "columns": ["ownerId"], + "isUnique": false + }, + "owner_updated_id_idx": { + "name": "owner_updated_id_idx", + "columns": ["ownerId", "updatedAt", "id"], + "isUnique": false + }, + "is_public_idx": { + "name": "is_public_idx", + "columns": ["public"], + "isUnique": false + }, + "folder_id_idx": { + "name": "folder_id_idx", + "columns": ["folderId"], + "isUnique": false + }, + "storage_integration_id_idx": { + "name": "storage_integration_id_idx", + "columns": ["storageIntegrationId"], + "isUnique": false + }, + "org_owner_folder_idx": { + "name": "org_owner_folder_idx", + "columns": ["orgId", "ownerId", "folderId"], + "isUnique": false + }, + "org_owner_folder_effective_idx": { + "name": "org_owner_folder_effective_idx", + "columns": ["orgId", "ownerId", "folderId", "effectiveCreatedAt"], + "isUnique": false + }, + "org_effective_created_idx": { + "name": "org_effective_created_idx", + "columns": ["orgId", "effectiveCreatedAt"], + "isUnique": false + }, + "org_owner_folder_archived_effective_idx": { + "name": "org_owner_folder_archived_effective_idx", + "columns": [ + "orgId", + "ownerId", + "folderId", + "archivedAt", + "effectiveCreatedAt" + ], + "isUnique": false + }, + "screenshot_transcription_created_idx": { + "name": "screenshot_transcription_created_idx", + "columns": ["isScreenshot", "transcriptionStatus", "createdAt"], + "isUnique": false + } + }, + "foreignKeys": { + "videos_storageIntegrationId_storage_integrations_id_fk": { + "name": "videos_storageIntegrationId_storage_integrations_id_fk", + "tableFrom": "videos", + "tableTo": "storage_integrations", + "columnsFrom": ["storageIntegrationId"], + "columnsTo": ["id"], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "videos_id": { + "name": "videos_id", + "columns": ["id"] + } + }, + "uniqueConstraints": {}, + "checkConstraint": {} + } + }, + "views": {}, + "_meta": { + "schemas": {}, + "tables": {}, + "columns": {} + }, + "internal": { + "tables": {}, + "indexes": { + "integration_object_key_prefix_idx": { + "columns": { + "`objectKey`(191)": { + "isExpression": true + } + } + } + } + } +} diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.json index 1bff70b2c4a..b7b9ca89c0b 100644 --- a/packages/database/migrations/meta/_journal.json +++ b/packages/database/migrations/meta/_journal.json @@ -456,6 +456,13 @@ "when": 1795202295715, "tag": "0064_email_change_requests", "breakpoints": true + }, + { + "idx": 65, + "version": "5", + "when": 1795216422426, + "tag": "0065_passkey_confirms_identity", + "breakpoints": true } ] } diff --git a/packages/database/schema.ts b/packages/database/schema.ts index 4a4a3b6aeba..e3eaad5dc5a 100644 --- a/packages/database/schema.ts +++ b/packages/database/schema.ts @@ -1053,6 +1053,7 @@ export const userPasskeys = mysqlTable( transports: json("transports").$type(), deviceType: varchar("deviceType", { length: 32 }).notNull(), backedUp: boolean("backedUp").notNull().default(false), + confirmsIdentity: boolean("confirmsIdentity").notNull().default(true), aaguid: varchar("aaguid", { length: 36 }), name: varchar("name", { length: 64 }).notNull(), createdAt: timestamp("createdAt").notNull().defaultNow(), From a7bdb0f2aa16fdd8579bcd5b9d5f47266dfc0d1d Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:48:53 +0000 Subject: [PATCH 08/19] fix(auth): keep passkeys added without a code to sign-in only --- packages/database/auth/passkeys.ts | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/packages/database/auth/passkeys.ts b/packages/database/auth/passkeys.ts index 16750309232..1ca94b7a02a 100644 --- a/packages/database/auth/passkeys.ts +++ b/packages/database/auth/passkeys.ts @@ -64,6 +64,7 @@ export type PasskeySummary = { createdAt: Date; lastUsedAt: Date | null; backedUp: boolean; + confirmsIdentity: boolean; }; export function passkeyRelyingParty() { @@ -255,7 +256,12 @@ export async function createPasskeyStepUpOptions( transports: userPasskeys.transports, }) .from(userPasskeys) - .where(eq(userPasskeys.userId, userId)); + .where( + and( + eq(userPasskeys.userId, userId), + eq(userPasskeys.confirmsIdentity, true), + ), + ); if (passkeys.length === 0) return null; const { rpID } = passkeyRelyingParty(); const options = await generateAuthenticationOptions({ @@ -305,6 +311,7 @@ async function verifyPasskeyAssertion( .for("update"); if (!passkey || passkey.credentialId !== response.id) return null; if (userId && passkey.userId !== userId) return null; + if (purpose === "passkey_step_up" && !passkey.confirmsIdentity) return null; const [user] = await tx .select() @@ -436,9 +443,16 @@ export type PasskeyRegistrationResult = | { status: "duplicate" } | { status: "limit" }; +/** + * `allowFirstPasskey` lets a challenge from the no-code route (a fresh + * sign-in) be claimed. Passkeys added that way can sign in but never confirm + * identity, so a briefly stolen session cannot escalate into an account + * change. + */ export async function verifyPasskeyRegistration( userId: User.UserId, raw: unknown, + options: { allowFirstPasskey?: boolean } = {}, ): Promise { const response = parseRegistrationResponse(raw); if (!response) return { status: "invalid" }; @@ -480,6 +494,7 @@ export async function verifyPasskeyRegistration( const createdAt = new Date(); const name = KNOWN_PASSKEY_PROVIDERS[info.aaguid] ?? "Passkey"; + let confirmsIdentity = false; try { const inserted = await db().transaction(async (tx) => { const [locked] = await tx @@ -498,6 +513,7 @@ export async function verifyPasskeyRegistration( }); const claimedFirst = !claimedSetup && + options.allowFirstPasskey === true && (await consumeChallenge({ purpose: "passkey_first_registration", challenge, @@ -505,6 +521,7 @@ export async function verifyPasskeyRegistration( database: tx, })); if (!claimedSetup && !claimedFirst) return "reset"; + confirmsIdentity = claimedSetup; const [row] = await tx .select({ total: count() }) .from(userPasskeys) @@ -522,6 +539,7 @@ export async function verifyPasskeyRegistration( transports: storedTransports(response.response.transports) ?? [], deviceType: info.credentialDeviceType, backedUp: info.credentialBackedUp, + confirmsIdentity, aaguid: info.aaguid, name, createdAt, @@ -544,6 +562,7 @@ export async function verifyPasskeyRegistration( createdAt, lastUsedAt: null, backedUp: info.credentialBackedUp, + confirmsIdentity, }, }; } @@ -572,6 +591,7 @@ export async function listPasskeys( createdAt: userPasskeys.createdAt, lastUsedAt: userPasskeys.lastUsedAt, backedUp: userPasskeys.backedUp, + confirmsIdentity: userPasskeys.confirmsIdentity, }) .from(userPasskeys) .where(eq(userPasskeys.userId, userId)) From 29909dd6af5579e3814b07b3d62db3f4f9ae26db Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:48:53 +0000 Subject: [PATCH 09/19] fix(auth): confirm it's you before removing a passkey --- apps/web/actions/auth/passkeys.ts | 32 ++++++---- .../settings/account/components/Passkeys.tsx | 63 +++++++++++++++---- .../(org)/dashboard/settings/account/page.tsx | 4 +- 3 files changed, 76 insertions(+), 23 deletions(-) diff --git a/apps/web/actions/auth/passkeys.ts b/apps/web/actions/auth/passkeys.ts index 1a51055efbb..a215946d3a4 100644 --- a/apps/web/actions/auth/passkeys.ts +++ b/apps/web/actions/auth/passkeys.ts @@ -38,8 +38,17 @@ export type PasskeyListItem = { createdAt: string; lastUsedAt: string | null; backedUp: boolean; + confirmsIdentity: boolean; }; +async function hasFreshSignIn(userId: string) { + const session = (await getSession()) as { + user?: { id?: string }; + authTime?: number; + } | null; + return session?.user?.id === userId && isFreshSignIn(session?.authTime); +} + async function requireUser() { const user = await getCurrentUser(); if (!user) throw new Error("Unauthorized"); @@ -145,7 +154,9 @@ export async function completePasskeyRegistration( > { const user = await requireUser(); if (await isPasskeyLimited(user.id)) return { status: "rate_limited" }; - const result = await verifyPasskeyRegistration(user.id, response); + const result = await verifyPasskeyRegistration(user.id, response, { + allowFirstPasskey: await hasFreshSignIn(user.id), + }); if (result.status !== "registered") return { status: result.status }; await sendPasskeyAddedNotice(user.email, result.passkey.name); return { @@ -168,11 +179,16 @@ export async function listMyPasskeys(): Promise { })); } -export async function removePasskey(passkeyId: string) { +export async function removePasskey( + passkeyId: string, + grant: string, +): Promise<{ status: "removed" | "missing" | "verify" }> { const user = await requireUser(); + if (!(await hasStepUpGrant(user.id, grant))) return { status: "verify" }; const removed = await deletePasskey(user.id, passkeyId); - if (removed) await sendPasskeyRemovedNotice(user.email, removed.name); - return { removed: removed !== null }; + if (!removed) return { status: "missing" }; + await sendPasskeyRemovedNotice(user.email, removed.name); + return { status: "removed" }; } export async function getPasskeyRegistrationOptionsAfterSignIn(): Promise< @@ -181,13 +197,7 @@ export async function getPasskeyRegistrationOptionsAfterSignIn(): Promise< > { const user = await requireUser(); if (await isPasskeyLimited(user.id)) return { status: "rate_limited" }; - const session = (await getSession()) as { - user?: { id?: string }; - authTime?: number; - } | null; - if (session?.user?.id !== user.id || !isFreshSignIn(session?.authTime)) { - return { status: "verify" }; - } + if (!(await hasFreshSignIn(user.id))) return { status: "verify" }; const options = await createPasskeyRegistrationOptions(user, { firstPasskeyOnly: true, }); diff --git a/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx b/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx index 879dc7724e9..f048dbed687 100644 --- a/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx +++ b/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx @@ -53,6 +53,10 @@ export const Passkeys = ({ const [passkeys, setPasskeys] = useState(initialPasskeys); const [supported, setSupported] = useState(null); const [verifyOpen, setVerifyOpen] = useState(false); + const [verifyPurpose, setVerifyPurpose] = useState<"add" | "remove">("add"); + const [pendingRemove, setPendingRemove] = useState( + null, + ); const [grant, setGrant] = useState(null); const [registering, setRegistering] = useState(false); const [readyOpen, setReadyOpen] = useState(false); @@ -71,6 +75,7 @@ export const Passkeys = ({ if (options.status !== "ok") { if (options.status === "verify") { setGrant(null); + setVerifyPurpose("add"); setVerifyOpen(true); } else if (options.status === "rate_limited") { toast.error("Too many attempts. Try again in a minute."); @@ -122,16 +127,25 @@ export const Passkeys = ({ }; const removeMutation = useMutation({ - mutationFn: async (passkeyId: string) => { - const { removed } = await removePasskey(passkeyId); - if (!removed) throw new Error("Passkey was not removed"); + mutationFn: async (input: { passkey: PasskeyListItem; grant: string }) => { + const result = await removePasskey(input.passkey.id, input.grant); + return result.status; }, - onSuccess: (_, passkeyId) => { + onSuccess: (status, input) => { + if (status === "verify") { + setGrant(null); + setPendingRemove(input.passkey); + setRemoveTarget(null); + setVerifyPurpose("remove"); + setVerifyOpen(true); + return; + } setPasskeys((current) => - current.filter((passkey) => passkey.id !== passkeyId), + current.filter((passkey) => passkey.id !== input.passkey.id), ); setRemoveTarget(null); - toast.success("Passkey removed"); + setPendingRemove(null); + if (status === "removed") toast.success("Passkey removed"); router.refresh(); }, onError: () => { @@ -144,6 +158,18 @@ export const Passkeys = ({ register(grant); return; } + setVerifyPurpose("add"); + setVerifyOpen(true); + }; + + const confirmRemove = (passkey: PasskeyListItem) => { + if (grant) { + removeMutation.mutate({ passkey, grant }); + return; + } + setPendingRemove(passkey); + setRemoveTarget(null); + setVerifyPurpose("remove"); setVerifyOpen(true); }; @@ -199,6 +225,7 @@ export const Passkeys = ({ {passkey.lastUsedAt ? `last used ${formatDate(passkey.lastUsedAt)}` : "never used"} + {passkey.confirmsIdentity ? "" : " · sign-in only"}

@@ -221,11 +248,27 @@ export const Passkeys = ({ open={verifyOpen} onOpenChange={setVerifyOpen} email={email} - canUsePasskey={passkeys.length > 0 && supported === true} - description="Adding a passkey lets it sign in to your account, so we need to check it's you first." + canUsePasskey={ + passkeys.some((passkey) => passkey.confirmsIdentity) && + supported === true + } + description={ + verifyPurpose === "remove" + ? "Removing a passkey changes how you can sign in, so we need to check it's you first." + : "Adding a passkey lets it sign in to your account, so we need to check it's you first." + } onVerified={(stepUpGrant) => { setGrant(stepUpGrant); setVerifyOpen(false); + if (verifyPurpose === "remove") { + if (pendingRemove) { + removeMutation.mutate({ + passkey: pendingRemove, + grant: stepUpGrant, + }); + } + return; + } setReadyOpen(true); }} /> @@ -291,9 +334,7 @@ export const Passkeys = ({ variant="destructive" disabled={removeMutation.isPending} spinner={removeMutation.isPending} - onClick={() => - removeTarget && removeMutation.mutate(removeTarget.id) - } + onClick={() => removeTarget && confirmRemove(removeTarget)} > {removeMutation.isPending ? "Removing..." : "Remove passkey"} diff --git a/apps/web/app/(org)/dashboard/settings/account/page.tsx b/apps/web/app/(org)/dashboard/settings/account/page.tsx index 945291ad598..100fb48837b 100644 --- a/apps/web/app/(org)/dashboard/settings/account/page.tsx +++ b/apps/web/app/(org)/dashboard/settings/account/page.tsx @@ -25,7 +25,9 @@ export default async function SettingsPage() { return (
0} + canUsePasskey={(passkeys ?? []).some( + (passkey) => passkey.confirmsIdentity, + )} emailManaged={emailManaged} /> {user && ( From 3e93775aac11e6108b39b3d8b501f640d4281585 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:48:53 +0000 Subject: [PATCH 10/19] fix(auth): revoke connected MCP apps when signing out of all devices --- .../web/app/(org)/dashboard/settings/account/server.ts | 10 ++++++++++ apps/web/app/api/v1/[...route]/route.ts | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/apps/web/app/(org)/dashboard/settings/account/server.ts b/apps/web/app/(org)/dashboard/settings/account/server.ts index 0e16ee7a400..ef047075d43 100644 --- a/apps/web/app/(org)/dashboard/settings/account/server.ts +++ b/apps/web/app/(org)/dashboard/settings/account/server.ts @@ -8,6 +8,7 @@ import { authApiKeys, authChallenges, emailChangeRequests, + mcpOAuthTokens, organizationMembers, organizations, sessions, @@ -222,6 +223,15 @@ export async function signOutAllDevices() { await tx .delete(authChallenges) .where(eq(authChallenges.userId, currentUser.id)); + await tx + .update(mcpOAuthTokens) + .set({ revokedAt: new Date() }) + .where( + and( + eq(mcpOAuthTokens.userId, currentUser.id), + isNull(mcpOAuthTokens.revokedAt), + ), + ); await tx .update(agentApiKeys) .set({ revokedAt: new Date() }) diff --git a/apps/web/app/api/v1/[...route]/route.ts b/apps/web/app/api/v1/[...route]/route.ts index 8c047e35286..d881def7a3f 100644 --- a/apps/web/app/api/v1/[...route]/route.ts +++ b/apps/web/app/api/v1/[...route]/route.ts @@ -6237,6 +6237,15 @@ const AgentManagementHandlersLive = HttpApiBuilder.group( await tx .delete(Db.authChallenges) .where(eq(Db.authChallenges.userId, principal.id)); + await tx + .update(Db.mcpOAuthTokens) + .set({ revokedAt: new Date() }) + .where( + and( + eq(Db.mcpOAuthTokens.userId, principal.id), + isNull(Db.mcpOAuthTokens.revokedAt), + ), + ); await tx .update(Db.agentApiKeys) .set({ revokedAt: new Date() }) From 67af4517710fc193c5dbfe482fa6089950dfcd1f Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Fri, 20 Nov 2026 23:48:53 +0000 Subject: [PATCH 11/19] test(auth): cover sign-in-only passkeys, removal confirmation and the takeover chain --- .github/workflows/infra-database.yml | 2 + .../integration/passkeys-database.test.ts | 190 +++++++++++++++++- apps/web/__tests__/unit/auth-options.test.ts | 7 + 3 files changed, 190 insertions(+), 9 deletions(-) diff --git a/.github/workflows/infra-database.yml b/.github/workflows/infra-database.yml index dad0efcfecb..6df49f21433 100644 --- a/.github/workflows/infra-database.yml +++ b/.github/workflows/infra-database.yml @@ -31,6 +31,7 @@ on: - "packages/database/migrations/**" - "packages/database/auth/**" - "apps/web/actions/auth/**" + - "apps/web/lib/passkey-prompt.ts" - ".github/workflows/infra-database.yml" push: branches: [main] @@ -61,6 +62,7 @@ on: - "packages/database/migrations/**" - "packages/database/auth/**" - "apps/web/actions/auth/**" + - "apps/web/lib/passkey-prompt.ts" - ".github/workflows/infra-database.yml" permissions: diff --git a/apps/web/__tests__/integration/passkeys-database.test.ts b/apps/web/__tests__/integration/passkeys-database.test.ts index e28f6e170d1..b994c6a6cc7 100644 --- a/apps/web/__tests__/integration/passkeys-database.test.ts +++ b/apps/web/__tests__/integration/passkeys-database.test.ts @@ -7,7 +7,12 @@ import nodeCrypto, { sign, webcrypto, } from "node:crypto"; -import { authChallenges, userPasskeys, users } from "@cap/database/schema"; +import { + authChallenges, + mcpOAuthTokens, + userPasskeys, + users, +} from "@cap/database/schema"; import { Organisation, User } from "@cap/web-domain"; import { isoCBOR } from "@simplewebauthn/server/helpers"; import { and, eq, inArray } from "drizzle-orm"; @@ -20,6 +25,7 @@ import { issueStepUpGrant, STEP_UP_CODE_MAX_ATTEMPTS, STEP_UP_CODES_PER_DAY, + storeChallenge, verifyStepUpCode, } from "../../../../packages/database/auth/auth-challenges"; import { @@ -982,30 +988,195 @@ describe.runIf(Boolean(databaseUrl))( expect(confirmed.status).toBe("ok"); }); - it("removes only the signed-in account's passkeys", async () => { + it("removes a passkey only after confirming it's you, and only your own", async () => { const { removePasskey } = await actions(); const user = await makeUser(); const other = await makeUser(); await registerPasskey(other); const [otherPasskey] = await listPasskeys(other.id); if (!otherPasskey) throw new Error("Missing passkey."); - fixture.currentUser = user; const noticesBefore = fixture.removedNotices.length; - expect(await removePasskey(otherPasskey.id)).toEqual({ - removed: false, + + fixture.currentUser = user; + const userGrant = await issueStepUpGrant(user.id); + expect(await removePasskey(otherPasskey.id, userGrant)).toEqual({ + status: "missing", + }); + + fixture.currentUser = other; + expect(await removePasskey(otherPasskey.id, "")).toEqual({ + status: "verify", + }); + expect(await removePasskey(otherPasskey.id, userGrant)).toEqual({ + status: "verify", }); expect(await listPasskeys(other.id)).toHaveLength(1); expect(fixture.removedNotices).toHaveLength(noticesBefore); - fixture.currentUser = other; - expect(await removePasskey(otherPasskey.id)).toEqual({ - removed: true, + + const otherGrant = await issueStepUpGrant(other.id); + expect(await removePasskey(otherPasskey.id, otherGrant)).toEqual({ + status: "removed", }); + expect(await listPasskeys(other.id)).toHaveLength(0); expect(fixture.removedNotices.at(-1)).toEqual({ email: other.email, name: "iCloud Keychain", }); }); + it("makes passkeys added without a code sign-in only", async () => { + const { + completePasskeyRegistration, + getPasskeyRegistrationOptionsAfterSignIn, + getPasskeyStepUpOptions, + verifyPasskeyForStepUp, + } = await actions(); + const { startEmailChange } = await import( + "@/actions/auth/email-change" + ); + const user = await makeUser(); + fixture.currentUser = user; + fixture.session = { + user: { id: user.id }, + authTime: Math.floor(Date.now() / 1000) - 30, + }; + const options = await getPasskeyRegistrationOptionsAfterSignIn(); + if (options.status !== "ok") throw new Error("No options."); + const attacker = new SoftwareAuthenticator(user.id); + expect( + ( + await completePasskeyRegistration( + JSON.stringify(attacker.register(options.options.challenge)), + ) + ).status, + ).toBe("registered"); + const [stored] = await listPasskeys(user.id); + expect(stored?.confirmsIdentity).toBe(false); + + expect( + (await verifyPasskeySignIn(attacker.assert(await signInChallenge()))) + ?.id, + ).toBe(user.id); + + expect(await getPasskeyStepUpOptions()).toEqual({ status: "none" }); + const forced = await createPasskeyStepUpOptions(user.id); + expect(forced).toBeNull(); + const smuggled = b64url(randomBytes(32)); + await storeChallenge({ + purpose: "passkey_step_up", + challenge: smuggled, + userId: user.id, + }); + expect(await verifyPasskeyForStepUp(attacker.assert(smuggled))).toEqual( + { status: "invalid" }, + ); + expect( + await startEmailChange("", `attacker-${id()}@example.com`), + ).toEqual({ status: "verify" }); + + const confirmed = await issueStepUpGrant(user.id); + const settingsOptions = await createPasskeyRegistrationOptions(user); + if (!settingsOptions) throw new Error("No options."); + expect( + ( + await verifyPasskeyRegistration( + user.id, + JSON.stringify( + new SoftwareAuthenticator(user.id).register( + settingsOptions.challenge, + ), + ), + ) + ).status, + ).toBe("registered"); + expect(typeof confirmed).toBe("string"); + const stepUp = await createPasskeyStepUpOptions(user.id); + expect(stepUp?.allowCredentials).toHaveLength(1); + expect(stepUp?.allowCredentials?.[0]?.id).not.toBe( + attacker.credentialId, + ); + }); + + it("closes the no-code route once the sign-in is no longer fresh", async () => { + const { + completePasskeyRegistration, + getPasskeyRegistrationOptionsAfterSignIn, + } = await actions(); + const user = await makeUser(); + fixture.currentUser = user; + const now = Math.floor(Date.now() / 1000); + fixture.session = { user: { id: user.id }, authTime: now - 30 }; + const options = await getPasskeyRegistrationOptionsAfterSignIn(); + if (options.status !== "ok") throw new Error("No options."); + fixture.session = { user: { id: user.id }, authTime: now - 11 * 60 }; + expect( + ( + await completePasskeyRegistration( + JSON.stringify( + new SoftwareAuthenticator(user.id).register( + options.options.challenge, + ), + ), + ) + ).status, + ).toBe("invalid"); + expect(await listPasskeys(user.id)).toHaveLength(0); + }); + + it("refuses a no-code passkey once the account has one, even if a setup survived", async () => { + const user = await makeUser(); + await registerPasskey(user); + const survivor = b64url(randomBytes(32)); + await storeChallenge({ + purpose: "passkey_first_registration", + challenge: survivor, + userId: user.id, + }); + expect( + ( + await verifyPasskeyRegistration( + user.id, + JSON.stringify( + new SoftwareAuthenticator(user.id).register(survivor), + ), + { allowFirstPasskey: true }, + ) + ).status, + ).toBe("invalid"); + expect(await listPasskeys(user.id)).toHaveLength(1); + }); + + it("signing out of all devices also revokes connected MCP apps", async () => { + const { signOutAllDevices } = await import( + "@/app/(org)/dashboard/settings/account/server" + ); + const user = await makeUser(); + const tokenId = id(); + await database() + .insert(mcpOAuthTokens) + .values({ + id: tokenId, + userId: user.id, + clientId: "client", + familyId: id(), + resource: "https://cap.test/mcp", + accessHash: randomUUID().replaceAll("-", ""), + refreshHash: randomUUID().replaceAll("-", ""), + accessExpiresAt: new Date(Date.now() + 3_600_000), + refreshExpiresAt: new Date(Date.now() + 86_400_000), + }); + fixture.currentUser = user; + await signOutAllDevices(); + const [token] = await database() + .select() + .from(mcpOAuthTokens) + .where(eq(mcpOAuthTokens.id, tokenId)); + expect(token?.revokedAt).toBeInstanceOf(Date); + await database() + .delete(mcpOAuthTokens) + .where(eq(mcpOAuthTokens.id, tokenId)); + }); + it("signing out of all devices removes passkeys and pending checks", async () => { const { signOutAllDevices } = await import( "@/app/(org)/dashboard/settings/account/server" @@ -1158,6 +1329,7 @@ describe.runIf(Boolean(databaseUrl))( JSON.stringify( new SoftwareAuthenticator(racing.id).register(challenge), ), + { allowFirstPasskey: true }, ), ), ); @@ -1231,7 +1403,7 @@ describe.runIf(Boolean(databaseUrl))( () => passkeyActions.getPasskeyRegistrationOptions("x"), () => passkeyActions.completePasskeyRegistration("{}"), () => passkeyActions.listMyPasskeys(), - () => passkeyActions.removePasskey("x"), + () => passkeyActions.removePasskey("x", "y"), ]) { await expect(call()).rejects.toThrow("Unauthorized"); } diff --git a/apps/web/__tests__/unit/auth-options.test.ts b/apps/web/__tests__/unit/auth-options.test.ts index 064382214be..0ec33189da3 100644 --- a/apps/web/__tests__/unit/auth-options.test.ts +++ b/apps/web/__tests__/unit/auth-options.test.ts @@ -758,6 +758,13 @@ describe("authOptions", () => { const refreshed = await callbacks.jwt({ token: { ...signedIn } } as never); expect(refreshed.authTime).toBe(signedIn.authTime); + const updated = await callbacks.jwt({ + token: { ...signedIn }, + trigger: "update", + session: { authTime: after + 100_000 }, + } as never); + expect(updated.authTime).toBe(signedIn.authTime); + const legacy = await callbacks.jwt({ token: { email: AUTHENTICATED_USER.email }, } as never); From 8315fe81905cf933aa817ced3a50fedf5bc266ce Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:01:11 +0000 Subject: [PATCH 12/19] perf(database): index MCP tokens by user for sign-out revocation --- .../database/migrations/0065_passkey_confirms_identity.sql | 3 ++- packages/database/migrations/meta/0065_snapshot.json | 7 ++++++- packages/database/migrations/meta/_journal.json | 2 +- packages/database/schema.ts | 1 + 4 files changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/database/migrations/0065_passkey_confirms_identity.sql b/packages/database/migrations/0065_passkey_confirms_identity.sql index 9e07c4ff05f..3eba4d3ba86 100644 --- a/packages/database/migrations/0065_passkey_confirms_identity.sql +++ b/packages/database/migrations/0065_passkey_confirms_identity.sql @@ -1 +1,2 @@ -ALTER TABLE `user_passkeys` ADD `confirmsIdentity` boolean DEFAULT true NOT NULL; \ No newline at end of file +ALTER TABLE `user_passkeys` ADD `confirmsIdentity` boolean DEFAULT true NOT NULL;--> statement-breakpoint +CREATE INDEX `user_revoked_idx` ON `mcp_oauth_tokens` (`userId`,`revokedAt`); \ No newline at end of file diff --git a/packages/database/migrations/meta/0065_snapshot.json b/packages/database/migrations/meta/0065_snapshot.json index 47c8b3eabc7..caa3f13b472 100644 --- a/packages/database/migrations/meta/0065_snapshot.json +++ b/packages/database/migrations/meta/0065_snapshot.json @@ -1,7 +1,7 @@ { "version": "5", "dialect": "mysql", - "id": "de8d211d-65bf-4a95-8871-3f391d31e5d0", + "id": "20f6d4bd-01f4-42f4-acad-195abcebd6d9", "prevId": "8ac84ca4-d730-45c1-82f8-48ed8ca42cf5", "tables": { "accounts": { @@ -3393,6 +3393,11 @@ "columns": ["familyId"], "isUnique": false }, + "user_revoked_idx": { + "name": "user_revoked_idx", + "columns": ["userId", "revokedAt"], + "isUnique": false + }, "client_active_idx": { "name": "client_active_idx", "columns": ["clientId", "revokedAt", "refreshExpiresAt"], diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.json index b7b9ca89c0b..7ff79a601dd 100644 --- a/packages/database/migrations/meta/_journal.json +++ b/packages/database/migrations/meta/_journal.json @@ -460,7 +460,7 @@ { "idx": 65, "version": "5", - "when": 1795216422426, + "when": 1795218854374, "tag": "0065_passkey_confirms_identity", "breakpoints": true } diff --git a/packages/database/schema.ts b/packages/database/schema.ts index e3eaad5dc5a..a4a1f4406c3 100644 --- a/packages/database/schema.ts +++ b/packages/database/schema.ts @@ -1271,6 +1271,7 @@ export const mcpOAuthTokens = mysqlTable( uniqueIndex("access_hash_idx").on(table.accessHash), uniqueIndex("refresh_hash_idx").on(table.refreshHash), index("family_id_idx").on(table.familyId), + index("user_revoked_idx").on(table.userId, table.revokedAt), index("client_active_idx").on( table.clientId, table.revokedAt, From b5ee46668e89adddaa97c21be7e353586c707eea Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:08:52 +0000 Subject: [PATCH 13/19] fix(auth): void pending MCP codes when signing out of all devices Sign-out now marks unused authorization codes as consumed in both the settings and agent API paths, and code issue, exchange and refresh take the account row lock first. Issuing a code also checks the session version under that lock, so a request racing sign-out can't mint one. --- .../dashboard/settings/account/server.ts | 10 +++++++ apps/web/app/api/v1/[...route]/route.ts | 9 ++++++ apps/web/app/mcp/authorize/actions.ts | 2 +- apps/web/lib/mcp-auth.ts | 30 +++++++++++++++++-- .../0065_passkey_confirms_identity.sql | 1 + .../migrations/meta/0065_snapshot.json | 7 ++++- .../database/migrations/meta/_journal.json | 2 +- packages/database/schema.ts | 1 + 8 files changed, 56 insertions(+), 6 deletions(-) diff --git a/apps/web/app/(org)/dashboard/settings/account/server.ts b/apps/web/app/(org)/dashboard/settings/account/server.ts index ef047075d43..b9ec95e2cd0 100644 --- a/apps/web/app/(org)/dashboard/settings/account/server.ts +++ b/apps/web/app/(org)/dashboard/settings/account/server.ts @@ -8,6 +8,7 @@ import { authApiKeys, authChallenges, emailChangeRequests, + mcpOAuthCodes, mcpOAuthTokens, organizationMembers, organizations, @@ -232,6 +233,15 @@ export async function signOutAllDevices() { isNull(mcpOAuthTokens.revokedAt), ), ); + await tx + .update(mcpOAuthCodes) + .set({ consumedAt: new Date() }) + .where( + and( + eq(mcpOAuthCodes.userId, currentUser.id), + isNull(mcpOAuthCodes.consumedAt), + ), + ); await tx .update(agentApiKeys) .set({ revokedAt: new Date() }) diff --git a/apps/web/app/api/v1/[...route]/route.ts b/apps/web/app/api/v1/[...route]/route.ts index d881def7a3f..6d36a6afd5d 100644 --- a/apps/web/app/api/v1/[...route]/route.ts +++ b/apps/web/app/api/v1/[...route]/route.ts @@ -6246,6 +6246,15 @@ const AgentManagementHandlersLive = HttpApiBuilder.group( isNull(Db.mcpOAuthTokens.revokedAt), ), ); + await tx + .update(Db.mcpOAuthCodes) + .set({ consumedAt: new Date() }) + .where( + and( + eq(Db.mcpOAuthCodes.userId, principal.id), + isNull(Db.mcpOAuthCodes.consumedAt), + ), + ); await tx .update(Db.agentApiKeys) .set({ revokedAt: new Date() }) diff --git a/apps/web/app/mcp/authorize/actions.ts b/apps/web/app/mcp/authorize/actions.ts index cc9ffacc30f..b70e1326d92 100644 --- a/apps/web/app/mcp/authorize/actions.ts +++ b/apps/web/app/mcp/authorize/actions.ts @@ -39,7 +39,7 @@ export async function authorizeMcpClient(formData: FormData) { if (decision === "approve") { callback.searchParams.set( "code", - await createMcpAuthorizationCode(user.id, request), + await createMcpAuthorizationCode(user, request), ); } else { callback.searchParams.set("error", "access_denied"); diff --git a/apps/web/lib/mcp-auth.ts b/apps/web/lib/mcp-auth.ts index d61ea1fdaa2..6521ae2fb5d 100644 --- a/apps/web/lib/mcp-auth.ts +++ b/apps/web/lib/mcp-auth.ts @@ -150,12 +150,34 @@ export const validateMcpAuthorizationRequest = async ( return { ...parsed, clientName: client.clientName }; }; +type Transaction = Parameters< + Parameters["transaction"]>[0] +>[0]; + +// Every path that issues MCP credentials takes this lock first. "Sign out of +// all devices" bumps the same row, so issuing and signing out never interleave. +const lockAccount = async ( + tx: Transaction, + userId: typeof users.$inferSelect.id, +) => { + const [account] = await tx + .select({ authSessionVersion: users.authSessionVersion }) + .from(users) + .where(eq(users.id, userId)) + .limit(1) + .for("update"); + return account ?? null; +}; + export const createMcpAuthorizationCode = async ( - userId: typeof mcpOAuthCodes.$inferInsert.userId, + user: Pick, request: McpAuthorizationRequest, ) => { const code = token("cap_mcp_code_"); await db().transaction(async (tx) => { + const account = await lockAccount(tx, user.id); + if (account?.authSessionVersion !== user.authSessionVersion) + throw new Error("Session expired"); const activated = await tx .update(mcpOAuthClients) .set({ activatedAt: new Date() }) @@ -164,7 +186,7 @@ export const createMcpAuthorizationCode = async ( throw new Error("Client registration expired"); await tx.insert(mcpOAuthCodes).values({ id: nanoId(), - userId, + userId: user.id, clientId: request.clientId, codeHash: hashAgentSecret(code), codeChallenge: request.codeChallenge, @@ -182,7 +204,7 @@ const affectedRows = (result: unknown) => { }; const mintMcpTokens = async ( - tx: Parameters["transaction"]>[0]>[0], + tx: Transaction, input: { userId: typeof mcpOAuthTokens.$inferInsert.userId; clientId: string; @@ -245,6 +267,7 @@ export const exchangeMcpCode = async (params: URLSearchParams) => { !verifyAgentCodeChallenge(verifier, grant.codeChallenge) ) return null; + if (!(await lockAccount(tx, grant.userId))) return null; const now = new Date(); const consumed = await tx .update(mcpOAuthCodes) @@ -293,6 +316,7 @@ export const refreshMcpTokens = async (params: URLSearchParams) => { return null; } if (row.refreshExpiresAt.getTime() <= Date.now()) return null; + if (!(await lockAccount(tx, row.userId))) return null; const now = new Date(); const revoked = await tx .update(mcpOAuthTokens) diff --git a/packages/database/migrations/0065_passkey_confirms_identity.sql b/packages/database/migrations/0065_passkey_confirms_identity.sql index 3eba4d3ba86..d32b2451cfe 100644 --- a/packages/database/migrations/0065_passkey_confirms_identity.sql +++ b/packages/database/migrations/0065_passkey_confirms_identity.sql @@ -1,2 +1,3 @@ ALTER TABLE `user_passkeys` ADD `confirmsIdentity` boolean DEFAULT true NOT NULL;--> statement-breakpoint +CREATE INDEX `user_consumed_idx` ON `mcp_oauth_codes` (`userId`,`consumedAt`);--> statement-breakpoint CREATE INDEX `user_revoked_idx` ON `mcp_oauth_tokens` (`userId`,`revokedAt`); \ No newline at end of file diff --git a/packages/database/migrations/meta/0065_snapshot.json b/packages/database/migrations/meta/0065_snapshot.json index caa3f13b472..bd128082371 100644 --- a/packages/database/migrations/meta/0065_snapshot.json +++ b/packages/database/migrations/meta/0065_snapshot.json @@ -1,7 +1,7 @@ { "version": "5", "dialect": "mysql", - "id": "20f6d4bd-01f4-42f4-acad-195abcebd6d9", + "id": "b303592d-54ac-4370-ae15-4f84f46fefc9", "prevId": "8ac84ca4-d730-45c1-82f8-48ed8ca42cf5", "tables": { "accounts": { @@ -3240,6 +3240,11 @@ "name": "expires_at_idx", "columns": ["expiresAt"], "isUnique": false + }, + "user_consumed_idx": { + "name": "user_consumed_idx", + "columns": ["userId", "consumedAt"], + "isUnique": false } }, "foreignKeys": {}, diff --git a/packages/database/migrations/meta/_journal.json b/packages/database/migrations/meta/_journal.json index 7ff79a601dd..cdc84e66957 100644 --- a/packages/database/migrations/meta/_journal.json +++ b/packages/database/migrations/meta/_journal.json @@ -460,7 +460,7 @@ { "idx": 65, "version": "5", - "when": 1795218854374, + "when": 1795219397974, "tag": "0065_passkey_confirms_identity", "breakpoints": true } diff --git a/packages/database/schema.ts b/packages/database/schema.ts index a4a1f4406c3..b67c64bea97 100644 --- a/packages/database/schema.ts +++ b/packages/database/schema.ts @@ -1249,6 +1249,7 @@ export const mcpOAuthCodes = mysqlTable( (table) => [ uniqueIndex("code_hash_idx").on(table.codeHash), index("expires_at_idx").on(table.expiresAt), + index("user_consumed_idx").on(table.userId, table.consumedAt), ], ); From a4d467daf675e438d72ce7bd2f12875b0a9e1044 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:08:52 +0000 Subject: [PATCH 14/19] test(auth): cover MCP codes and refresh across sign-out --- .../integration/passkeys-database.test.ts | 152 ++++++++++++++++++ apps/web/__tests__/unit/mcp-auth.test.ts | 7 +- 2 files changed, 157 insertions(+), 2 deletions(-) diff --git a/apps/web/__tests__/integration/passkeys-database.test.ts b/apps/web/__tests__/integration/passkeys-database.test.ts index b994c6a6cc7..57295a4a1d0 100644 --- a/apps/web/__tests__/integration/passkeys-database.test.ts +++ b/apps/web/__tests__/integration/passkeys-database.test.ts @@ -9,6 +9,8 @@ import nodeCrypto, { } from "node:crypto"; import { authChallenges, + mcpOAuthClients, + mcpOAuthCodes, mcpOAuthTokens, userPasskeys, users, @@ -1177,6 +1179,156 @@ describe.runIf(Boolean(databaseUrl))( .where(eq(mcpOAuthTokens.id, tokenId)); }); + describe("MCP authorization codes and sign-out", () => { + const redirectUri = "https://client.test/callback"; + const resource = "https://cap.test/api/mcp"; + const clients: string[] = []; + + async function issueCode( + user: Pick< + Awaited>, + "id" | "authSessionVersion" + >, + ) { + const { createMcpAuthorizationCode } = await import("@/lib/mcp-auth"); + const clientId = `cap_mcp_client_${id()}`; + clients.push(clientId); + await database() + .insert(mcpOAuthClients) + .values({ + id: id(), + clientId, + clientName: "Test client", + redirectUris: [redirectUri], + }); + const verifier = nodeCrypto.randomBytes(32).toString("base64url"); + const code = await createMcpAuthorizationCode(user, { + clientId, + redirectUri, + codeChallenge: nodeCrypto + .createHash("sha256") + .update(verifier) + .digest("base64url"), + state: null, + resource, + }); + return new URLSearchParams({ + grant_type: "authorization_code", + code, + client_id: clientId, + redirect_uri: redirectUri, + code_verifier: verifier, + resource, + }); + } + + async function liveTokens(userId: User.UserId) { + const rows = await database() + .select({ revokedAt: mcpOAuthTokens.revokedAt }) + .from(mcpOAuthTokens) + .where(eq(mcpOAuthTokens.userId, userId)); + return rows.filter((row) => row.revokedAt === null).length; + } + + afterAll(async () => { + if (createdUsers.length > 0) { + await database() + .delete(mcpOAuthTokens) + .where(inArray(mcpOAuthTokens.userId, createdUsers)); + await database() + .delete(mcpOAuthCodes) + .where(inArray(mcpOAuthCodes.userId, createdUsers)); + } + if (clients.length > 0) + await database() + .delete(mcpOAuthClients) + .where(inArray(mcpOAuthClients.clientId, clients)); + }); + + it("a pending code can't be exchanged after signing out of all devices", async () => { + const { signOutAllDevices } = await import( + "@/app/(org)/dashboard/settings/account/server" + ); + const { exchangeMcpCode } = await import("@/lib/mcp-auth"); + const user = await makeUser(); + const params = await issueCode(user); + fixture.currentUser = user; + await signOutAllDevices(); + expect(await exchangeMcpCode(params)).toBeNull(); + expect(await liveTokens(user.id)).toBe(0); + }); + + it("a code can't be issued from a session that was signed out", async () => { + const { signOutAllDevices } = await import( + "@/app/(org)/dashboard/settings/account/server" + ); + const user = await makeUser(); + fixture.currentUser = user; + await signOutAllDevices(); + await expect(issueCode(user)).rejects.toThrow("Session expired"); + const codes = await database() + .select({ id: mcpOAuthCodes.id }) + .from(mcpOAuthCodes) + .where(eq(mcpOAuthCodes.userId, user.id)); + expect(codes).toHaveLength(0); + }); + + it("a token from before sign-out can't be refreshed", async () => { + const { signOutAllDevices } = await import( + "@/app/(org)/dashboard/settings/account/server" + ); + const { exchangeMcpCode, refreshMcpTokens } = await import( + "@/lib/mcp-auth" + ); + const user = await makeUser(); + const params = await issueCode(user); + const tokens = await exchangeMcpCode(params); + expect(tokens?.refresh_token).toBeTruthy(); + fixture.currentUser = user; + await signOutAllDevices(); + expect( + await refreshMcpTokens( + new URLSearchParams({ + grant_type: "refresh_token", + refresh_token: tokens?.refresh_token ?? "", + client_id: params.get("client_id") ?? "", + resource, + }), + ), + ).toBeNull(); + expect(await liveTokens(user.id)).toBe(0); + }); + + it("an exchange or refresh racing sign-out never leaves a live token", async () => { + const { signOutAllDevices } = await import( + "@/app/(org)/dashboard/settings/account/server" + ); + const { exchangeMcpCode, refreshMcpTokens } = await import( + "@/lib/mcp-auth" + ); + for (let round = 0; round < 6; round++) { + const user = await makeUser(); + const params = await issueCode(user); + const pending = await issueCode(user); + const tokens = await exchangeMcpCode(params); + fixture.currentUser = user; + await Promise.all([ + exchangeMcpCode(pending), + refreshMcpTokens( + new URLSearchParams({ + grant_type: "refresh_token", + refresh_token: tokens?.refresh_token ?? "", + client_id: params.get("client_id") ?? "", + resource, + }), + ), + signOutAllDevices(), + ]); + expect(await liveTokens(user.id)).toBe(0); + } + }); + }); + it("signing out of all devices removes passkeys and pending checks", async () => { const { signOutAllDevices } = await import( "@/app/(org)/dashboard/settings/account/server" diff --git a/apps/web/__tests__/unit/mcp-auth.test.ts b/apps/web/__tests__/unit/mcp-auth.test.ts index ba89ac047d1..b7a2bb4bc17 100644 --- a/apps/web/__tests__/unit/mcp-auth.test.ts +++ b/apps/web/__tests__/unit/mcp-auth.test.ts @@ -24,7 +24,10 @@ vi.mock("@cap/database", () => ({ limit: () => Object.assign(Promise.resolve([databaseState.selected]), { for: async () => [ - { registrations: databaseState.quotaCount }, + { + registrations: databaseState.quotaCount, + authSessionVersion: 0, + }, ], }), }), @@ -134,7 +137,7 @@ describe("MCP OAuth authorization", () => { expect(request).not.toBeNull(); if (!request) return; const code = await createMcpAuthorizationCode( - User.UserId.make("owner"), + { id: User.UserId.make("owner"), authSessionVersion: 0 }, request, ); expect(code).toMatch(/^cap_mcp_code_[A-Za-z0-9_-]{43}$/); From 1898cd0bbd644c1c33c42a4215f56dface9286f7 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:21:45 +0000 Subject: [PATCH 15/19] fix(auth): don't let a passkey sign-in add a passkey without a code The session token now records how the person signed in. The no-code first-passkey route and the dashboard prompt refuse passkey sign-ins and sessions with no recorded method, so removing a sign-in-only passkey can't be followed by adding another from a passkey session. --- apps/web/actions/auth/passkeys.ts | 8 ++------ apps/web/lib/passkey-prompt.ts | 10 +++------ packages/database/auth/auth-options.ts | 17 ++++++++++++++-- packages/database/auth/fresh-sign-in.ts | 27 +++++++++++++++++++++++++ 4 files changed, 47 insertions(+), 15 deletions(-) diff --git a/apps/web/actions/auth/passkeys.ts b/apps/web/actions/auth/passkeys.ts index a215946d3a4..6686fc87707 100644 --- a/apps/web/actions/auth/passkeys.ts +++ b/apps/web/actions/auth/passkeys.ts @@ -7,7 +7,7 @@ import { issueStepUpGrant, verifyStepUpCode, } from "@cap/database/auth/auth-challenges"; -import { isFreshSignIn } from "@cap/database/auth/fresh-sign-in"; +import { canAddFirstPasskeyWithoutCode } from "@cap/database/auth/fresh-sign-in"; import { createPasskeyRegistrationOptions, createPasskeySignInOptions, @@ -42,11 +42,7 @@ export type PasskeyListItem = { }; async function hasFreshSignIn(userId: string) { - const session = (await getSession()) as { - user?: { id?: string }; - authTime?: number; - } | null; - return session?.user?.id === userId && isFreshSignIn(session?.authTime); + return canAddFirstPasskeyWithoutCode(await getSession(), userId); } async function requireUser() { diff --git a/apps/web/lib/passkey-prompt.ts b/apps/web/lib/passkey-prompt.ts index ecb2b731327..e43634893d5 100644 --- a/apps/web/lib/passkey-prompt.ts +++ b/apps/web/lib/passkey-prompt.ts @@ -1,6 +1,6 @@ import "server-only"; -import { isFreshSignIn } from "@cap/database/auth/fresh-sign-in"; +import { canAddFirstPasskeyWithoutCode } from "@cap/database/auth/fresh-sign-in"; import { countPasskeys } from "@cap/database/auth/passkeys"; import { getSession } from "@cap/database/auth/session"; import type { users } from "@cap/database/schema"; @@ -24,12 +24,8 @@ export function passkeyPromptSnoozed( export async function shouldOfferPasskey(user: PromptUser, now = Date.now()) { try { if (passkeyPromptSnoozed(user.preferences, now)) return false; - const session = (await getSession()) as { - user?: { id?: string }; - authTime?: number; - } | null; - if (session?.user?.id !== user.id) return false; - if (!isFreshSignIn(session.authTime, now)) return false; + if (!canAddFirstPasskeyWithoutCode(await getSession(), user.id, now)) + return false; return (await countPasskeys(user.id)) === 0; } catch (error) { console.error("[passkeys] Could not decide on the passkey prompt", { diff --git a/packages/database/auth/auth-options.ts b/packages/database/auth/auth-options.ts index 513d48c3325..c41767161d8 100644 --- a/packages/database/auth/auth-options.ts +++ b/packages/database/auth/auth-options.ts @@ -503,6 +503,9 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { if (typeof token?.authTime === "number") { (session as { authTime?: number }).authTime = token.authTime; } + if (typeof token?.authMethod === "string") { + (session as { authMethod?: string }).authMethod = token.authMethod; + } return session; }, @@ -538,6 +541,7 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { if (user) { token.id = user?.id; token.authTime = signInTimestamp(); + token.authMethod = account?.provider; } return token; } @@ -550,9 +554,18 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { picture: dbUser.image, sessionVersion: dbUser.authSessionVersion, ...(user - ? { authTime: signInTimestamp() } + ? { + authTime: signInTimestamp(), + authMethod: account?.provider, + } : typeof token.authTime === "number" - ? { authTime: token.authTime } + ? { + authTime: token.authTime, + authMethod: + typeof token.authMethod === "string" + ? token.authMethod + : undefined, + } : {}), }; } diff --git a/packages/database/auth/fresh-sign-in.ts b/packages/database/auth/fresh-sign-in.ts index c491001489e..a8f8913e064 100644 --- a/packages/database/auth/fresh-sign-in.ts +++ b/packages/database/auth/fresh-sign-in.ts @@ -18,3 +18,30 @@ export function isFreshSignIn(authTime: unknown, now = Date.now()) { nowSeconds - authTime <= FRESH_SIGN_IN_SECONDS ); } + +type SignInSession = { + user?: { id?: string }; + authTime?: unknown; + authMethod?: unknown; +} | null; + +/** + * Whether this session may add the account's first passkey without a code: + * the same account, signed in within the last ten minutes, by a method other + * than a passkey. A passkey sign-in proves the account already had a passkey, + * so it must never reopen the no-code route after that passkey is removed. + * Sessions without a recorded method are refused. + */ +export function canAddFirstPasskeyWithoutCode( + session: unknown, + userId: string, + now = Date.now(), +) { + const current = session as SignInSession; + return ( + current?.user?.id === userId && + typeof current.authMethod === "string" && + current.authMethod !== "passkey" && + isFreshSignIn(current.authTime, now) + ); +} From 30e25374d4a64fb188298ab9136a17e3f9538fc7 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:21:45 +0000 Subject: [PATCH 16/19] fix(auth): share one sign-out-everywhere and void CLI login codes Settings, the agent API and the mobile account deletion request now call revokeAllCredentials, which also voids pending CLI login codes and clears email change requests on the mobile path. CLI code issue and exchange take the account row lock, and issuing re-checks the session version, matching MCP. --- .../dashboard/settings/account/server.ts | 55 +-------------- apps/web/app/api/mobile/[...route]/route.ts | 29 +------- apps/web/app/api/v1/[...route]/route.ts | 50 +------------- apps/web/app/cli/authorize/page.tsx | 19 ++++-- apps/web/lib/agent-token.ts | 8 +++ packages/database/auth/revoke-credentials.ts | 68 +++++++++++++++++++ packages/database/package.json | 1 + 7 files changed, 99 insertions(+), 131 deletions(-) create mode 100644 packages/database/auth/revoke-credentials.ts diff --git a/apps/web/app/(org)/dashboard/settings/account/server.ts b/apps/web/app/(org)/dashboard/settings/account/server.ts index b9ec95e2cd0..db2b8327e40 100644 --- a/apps/web/app/(org)/dashboard/settings/account/server.ts +++ b/apps/web/app/(org)/dashboard/settings/account/server.ts @@ -1,23 +1,17 @@ "use server"; import { db } from "@cap/database"; +import { revokeAllCredentials } from "@cap/database/auth/revoke-credentials"; import { getCurrentUser } from "@cap/database/auth/session"; import { nanoId } from "@cap/database/helpers"; import { agentApiKeys, - authApiKeys, - authChallenges, - emailChangeRequests, - mcpOAuthCodes, - mcpOAuthTokens, organizationMembers, organizations, - sessions, - userPasskeys, users, } from "@cap/database/schema"; import type { Organisation } from "@cap/web-domain"; -import { and, desc, eq, isNull, or, sql } from "drizzle-orm"; +import { and, desc, eq, isNull, or } from "drizzle-orm"; import { revalidatePath } from "next/cache"; import { agentScopeProfiles, @@ -208,48 +202,5 @@ export async function signOutAllDevices() { const currentUser = await getCurrentUser(); if (!currentUser) throw new Error("Unauthorized"); - await db().transaction(async (tx) => { - await tx - .update(users) - .set({ authSessionVersion: sql`${users.authSessionVersion} + 1` }) - .where(eq(users.id, currentUser.id)); - await tx.delete(sessions).where(eq(sessions.userId, currentUser.id)); - await tx.delete(authApiKeys).where(eq(authApiKeys.userId, currentUser.id)); - await tx - .delete(userPasskeys) - .where(eq(userPasskeys.userId, currentUser.id)); - await tx - .delete(emailChangeRequests) - .where(eq(emailChangeRequests.userId, currentUser.id)); - await tx - .delete(authChallenges) - .where(eq(authChallenges.userId, currentUser.id)); - await tx - .update(mcpOAuthTokens) - .set({ revokedAt: new Date() }) - .where( - and( - eq(mcpOAuthTokens.userId, currentUser.id), - isNull(mcpOAuthTokens.revokedAt), - ), - ); - await tx - .update(mcpOAuthCodes) - .set({ consumedAt: new Date() }) - .where( - and( - eq(mcpOAuthCodes.userId, currentUser.id), - isNull(mcpOAuthCodes.consumedAt), - ), - ); - await tx - .update(agentApiKeys) - .set({ revokedAt: new Date() }) - .where( - and( - eq(agentApiKeys.userId, currentUser.id), - isNull(agentApiKeys.revokedAt), - ), - ); - }); + await db().transaction((tx) => revokeAllCredentials(tx, currentUser.id)); } diff --git a/apps/web/app/api/mobile/[...route]/route.ts b/apps/web/app/api/mobile/[...route]/route.ts index b154a786cb2..c691b24bdeb 100644 --- a/apps/web/app/api/mobile/[...route]/route.ts +++ b/apps/web/app/api/mobile/[...route]/route.ts @@ -6,6 +6,7 @@ import { isEmailBlockedFromSignup, normalizeSignInEmail, } from "@cap/database/auth/domain-utils"; +import { revokeAllCredentials } from "@cap/database/auth/revoke-credentials"; import { decrypt, encrypt, @@ -699,33 +700,7 @@ const requestAccountDeletion = Effect.fn("Mobile.requestAccountDeletion")( const database = yield* Database; yield* database.use((db) => - db.transaction(async (tx) => { - await tx - .update(Db.users) - .set({ - authSessionVersion: sql`${Db.users.authSessionVersion} + 1`, - }) - .where(eq(Db.users.id, user.id)); - await tx.delete(Db.sessions).where(eq(Db.sessions.userId, user.id)); - await tx - .delete(Db.authApiKeys) - .where(eq(Db.authApiKeys.userId, user.id)); - await tx - .delete(Db.userPasskeys) - .where(eq(Db.userPasskeys.userId, user.id)); - await tx - .delete(Db.authChallenges) - .where(eq(Db.authChallenges.userId, user.id)); - await tx - .update(Db.agentApiKeys) - .set({ revokedAt: new Date() }) - .where( - and( - eq(Db.agentApiKeys.userId, user.id), - isNull(Db.agentApiKeys.revokedAt), - ), - ); - }), + db.transaction((tx) => revokeAllCredentials(tx, user.id)), ); return { success: true as const }; diff --git a/apps/web/app/api/v1/[...route]/route.ts b/apps/web/app/api/v1/[...route]/route.ts index 6d36a6afd5d..50aaa1099ef 100644 --- a/apps/web/app/api/v1/[...route]/route.ts +++ b/apps/web/app/api/v1/[...route]/route.ts @@ -1,5 +1,6 @@ import { createHash, createHmac } from "node:crypto"; import { HeadBucketCommand, S3Client } from "@aws-sdk/client-s3"; +import { revokeAllCredentials } from "@cap/database/auth/revoke-credentials"; import { decrypt, encrypt, @@ -6216,54 +6217,7 @@ const AgentManagementHandlersLive = HttpApiBuilder.group( .limit(1) .for("update"); if (!account) return { state: "not_found" }; - await tx - .update(Db.users) - .set({ - authSessionVersion: sql`${Db.users.authSessionVersion} + 1`, - }) - .where(eq(Db.users.id, principal.id)); - await tx - .delete(Db.sessions) - .where(eq(Db.sessions.userId, principal.id)); - await tx - .delete(Db.authApiKeys) - .where(eq(Db.authApiKeys.userId, principal.id)); - await tx - .delete(Db.userPasskeys) - .where(eq(Db.userPasskeys.userId, principal.id)); - await tx - .delete(Db.emailChangeRequests) - .where(eq(Db.emailChangeRequests.userId, principal.id)); - await tx - .delete(Db.authChallenges) - .where(eq(Db.authChallenges.userId, principal.id)); - await tx - .update(Db.mcpOAuthTokens) - .set({ revokedAt: new Date() }) - .where( - and( - eq(Db.mcpOAuthTokens.userId, principal.id), - isNull(Db.mcpOAuthTokens.revokedAt), - ), - ); - await tx - .update(Db.mcpOAuthCodes) - .set({ consumedAt: new Date() }) - .where( - and( - eq(Db.mcpOAuthCodes.userId, principal.id), - isNull(Db.mcpOAuthCodes.consumedAt), - ), - ); - await tx - .update(Db.agentApiKeys) - .set({ revokedAt: new Date() }) - .where( - and( - eq(Db.agentApiKeys.userId, principal.id), - isNull(Db.agentApiKeys.revokedAt), - ), - ); + await revokeAllCredentials(tx, principal.id); return { state: "success", response: mutationResponse( diff --git a/apps/web/app/cli/authorize/page.tsx b/apps/web/app/cli/authorize/page.tsx index 3d9218a73ca..eb7c355ae57 100644 --- a/apps/web/app/cli/authorize/page.tsx +++ b/apps/web/app/cli/authorize/page.tsx @@ -1,8 +1,9 @@ import { db } from "@cap/database"; import { getCurrentUser } from "@cap/database/auth/session"; import { nanoId } from "@cap/database/helpers"; -import { agentApiAuthorizationCodes } from "@cap/database/schema"; +import { agentApiAuthorizationCodes, users } from "@cap/database/schema"; import { Logo } from "@cap/ui"; +import { eq } from "drizzle-orm"; import { redirect } from "next/navigation"; import { buildAgentCallbackUrl, @@ -102,9 +103,18 @@ export default async function CliAuthorizePage(props: { throw new Error("Too many authorization attempts. Try again later."); } const code = createAgentAuthorizationCode(); - await db() - .insert(agentApiAuthorizationCodes) - .values({ + await db().transaction(async (tx) => { + // "Sign out of all devices" bumps this row, so a code can't be issued + // from a session that was signed out while this request ran. + const [account] = await tx + .select({ authSessionVersion: users.authSessionVersion }) + .from(users) + .where(eq(users.id, currentUser.id)) + .limit(1) + .for("update"); + if (account?.authSessionVersion !== currentUser.authSessionVersion) + throw new Error("Session expired"); + await tx.insert(agentApiAuthorizationCodes).values({ id: nanoId(), userId: currentUser.id, codeHash: hashAgentSecret(code), @@ -113,6 +123,7 @@ export default async function CliAuthorizePage(props: { scopes: submitted.scopes, expiresAt: new Date(Date.now() + 5 * 60 * 1000), }); + }); const callback = buildAgentCallbackUrl(submitted.redirectUri, { state: submitted.state, code, diff --git a/apps/web/lib/agent-token.ts b/apps/web/lib/agent-token.ts index 4f3034be0e8..8120e48e06a 100644 --- a/apps/web/lib/agent-token.ts +++ b/apps/web/lib/agent-token.ts @@ -82,6 +82,14 @@ export const exchangeAgentAuthorizationCode = Effect.fn( ) { return { state: "invalid" as const }; } + // Same row lock as "Sign out of all devices", so the two never interleave. + const [account] = await tx + .select({ id: Db.users.id }) + .from(Db.users) + .where(eq(Db.users.id, grant.userId)) + .limit(1) + .for("update"); + if (!account) return { state: "invalid" as const }; const consumed = await tx .update(Db.agentApiAuthorizationCodes) diff --git a/packages/database/auth/revoke-credentials.ts b/packages/database/auth/revoke-credentials.ts new file mode 100644 index 00000000000..8294814765e --- /dev/null +++ b/packages/database/auth/revoke-credentials.ts @@ -0,0 +1,68 @@ +import { and, eq, isNull, sql } from "drizzle-orm"; +import type { db } from "../index.ts"; +import { + agentApiAuthorizationCodes, + agentApiKeys, + authApiKeys, + authChallenges, + emailChangeRequests, + mcpOAuthCodes, + mcpOAuthTokens, + sessions, + userPasskeys, + users, +} from "../schema.ts"; + +type Transaction = Pick, "update" | "delete">; + +/** + * Signs the account out everywhere: browser sessions, desktop and mobile keys, + * CLI keys, MCP apps, passkeys and every pending check or code. Run it inside + * the caller's transaction. Bumping the session version first takes the + * account row lock that every credential issuer also takes, so nothing issued + * concurrently can survive. + */ +export async function revokeAllCredentials( + tx: Transaction, + userId: typeof users.$inferSelect.id, +) { + const now = new Date(); + await tx + .update(users) + .set({ authSessionVersion: sql`${users.authSessionVersion} + 1` }) + .where(eq(users.id, userId)); + await tx.delete(sessions).where(eq(sessions.userId, userId)); + await tx.delete(authApiKeys).where(eq(authApiKeys.userId, userId)); + await tx.delete(userPasskeys).where(eq(userPasskeys.userId, userId)); + await tx + .delete(emailChangeRequests) + .where(eq(emailChangeRequests.userId, userId)); + await tx.delete(authChallenges).where(eq(authChallenges.userId, userId)); + await tx + .update(mcpOAuthCodes) + .set({ consumedAt: now }) + .where( + and(eq(mcpOAuthCodes.userId, userId), isNull(mcpOAuthCodes.consumedAt)), + ); + await tx + .update(mcpOAuthTokens) + .set({ revokedAt: now }) + .where( + and(eq(mcpOAuthTokens.userId, userId), isNull(mcpOAuthTokens.revokedAt)), + ); + await tx + .update(agentApiAuthorizationCodes) + .set({ consumedAt: now }) + .where( + and( + eq(agentApiAuthorizationCodes.userId, userId), + isNull(agentApiAuthorizationCodes.consumedAt), + ), + ); + await tx + .update(agentApiKeys) + .set({ revokedAt: now }) + .where( + and(eq(agentApiKeys.userId, userId), isNull(agentApiKeys.revokedAt)), + ); +} diff --git a/packages/database/package.json b/packages/database/package.json index 4bdf311902a..e5599e0badf 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -71,6 +71,7 @@ "./auth/security-emails": "./auth/security-emails.ts", "./auth/google-one-tap": "./auth/google-one-tap.ts", "./auth/request-site": "./auth/request-site.ts", + "./auth/revoke-credentials": "./auth/revoke-credentials.ts", "./auth/session": "./auth/session.ts", "./auth/sso": "./auth/sso.ts", "./auth/sso-state": "./auth/sso-state.ts", From e6e598a8a0f7275ae8a1ee2da2cc2d67dd0a7128 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:21:45 +0000 Subject: [PATCH 17/19] test(auth): cover passkey sign-ins, sign-in method and CLI codes on sign-out --- .../integration/passkeys-database.test.ts | 167 ++++++++++++++++-- apps/web/__tests__/unit/auth-options.test.ts | 8 +- 2 files changed, 161 insertions(+), 14 deletions(-) diff --git a/apps/web/__tests__/integration/passkeys-database.test.ts b/apps/web/__tests__/integration/passkeys-database.test.ts index 57295a4a1d0..1d660ff1678 100644 --- a/apps/web/__tests__/integration/passkeys-database.test.ts +++ b/apps/web/__tests__/integration/passkeys-database.test.ts @@ -8,6 +8,7 @@ import nodeCrypto, { webcrypto, } from "node:crypto"; import { + agentApiAuthorizationCodes, authChallenges, mcpOAuthClients, mcpOAuthCodes, @@ -1040,6 +1041,7 @@ describe.runIf(Boolean(databaseUrl))( fixture.currentUser = user; fixture.session = { user: { id: user.id }, + authMethod: "email", authTime: Math.floor(Date.now() / 1000) - 30, }; const options = await getPasskeyRegistrationOptionsAfterSignIn(); @@ -1107,10 +1109,18 @@ describe.runIf(Boolean(databaseUrl))( const user = await makeUser(); fixture.currentUser = user; const now = Math.floor(Date.now() / 1000); - fixture.session = { user: { id: user.id }, authTime: now - 30 }; + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 30, + }; const options = await getPasskeyRegistrationOptionsAfterSignIn(); if (options.status !== "ok") throw new Error("No options."); - fixture.session = { user: { id: user.id }, authTime: now - 11 * 60 }; + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 11 * 60, + }; expect( ( await completePasskeyRegistration( @@ -1148,6 +1158,69 @@ describe.runIf(Boolean(databaseUrl))( expect(await listPasskeys(user.id)).toHaveLength(1); }); + it("a passkey sign-in can't reopen the no-code route after its passkey is removed", async () => { + const { + completePasskeyRegistration, + getPasskeyRegistrationOptionsAfterSignIn, + } = await actions(); + const { shouldOfferPasskey } = await import("@/lib/passkey-prompt"); + const user = await makeUser(); + fixture.currentUser = user; + const now = Math.floor(Date.now() / 1000); + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 30, + }; + const first = await getPasskeyRegistrationOptionsAfterSignIn(); + if (first.status !== "ok") throw new Error("No options."); + const attacker = new SoftwareAuthenticator(user.id); + expect( + ( + await completePasskeyRegistration( + JSON.stringify(attacker.register(first.options.challenge)), + ) + ).status, + ).toBe("registered"); + expect( + (await verifyPasskeySignIn(attacker.assert(await signInChallenge()))) + ?.id, + ).toBe(user.id); + await database() + .delete(userPasskeys) + .where(eq(userPasskeys.userId, user.id)); + const leftover = await getPasskeyRegistrationOptionsAfterSignIn(); + if (leftover.status !== "ok") throw new Error("No options."); + + fixture.session = { + user: { id: user.id }, + authMethod: "passkey", + authTime: now - 30, + }; + expect(await shouldOfferPasskey(user)).toBe(false); + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + expect( + ( + await completePasskeyRegistration( + JSON.stringify( + new SoftwareAuthenticator(user.id).register( + leftover.options.challenge, + ), + ), + ) + ).status, + ).not.toBe("registered"); + + fixture.session = { user: { id: user.id }, authTime: now - 30 }; + expect(await shouldOfferPasskey(user)).toBe(false); + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + expect(await listPasskeys(user.id)).toHaveLength(0); + }); + it("signing out of all devices also revokes connected MCP apps", async () => { const { signOutAllDevices } = await import( "@/app/(org)/dashboard/settings/account/server" @@ -1258,6 +1331,35 @@ describe.runIf(Boolean(databaseUrl))( expect(await liveTokens(user.id)).toBe(0); }); + it("signing out of all devices voids pending CLI login codes", async () => { + const { signOutAllDevices } = await import( + "@/app/(org)/dashboard/settings/account/server" + ); + const user = await makeUser(); + const codeId = id(); + await database() + .insert(agentApiAuthorizationCodes) + .values({ + id: codeId, + userId: user.id, + codeHash: randomUUID().replaceAll("-", ""), + codeChallenge: "c".repeat(43), + redirectUri: "http://127.0.0.1:53682/callback", + scopes: ["caps:read"], + expiresAt: new Date(Date.now() + 5 * 60_000), + }); + fixture.currentUser = user; + await signOutAllDevices(); + const [code] = await database() + .select({ consumedAt: agentApiAuthorizationCodes.consumedAt }) + .from(agentApiAuthorizationCodes) + .where(eq(agentApiAuthorizationCodes.id, codeId)); + expect(code?.consumedAt).toBeInstanceOf(Date); + await database() + .delete(agentApiAuthorizationCodes) + .where(eq(agentApiAuthorizationCodes.id, codeId)); + }); + it("a code can't be issued from a session that was signed out", async () => { const { signOutAllDevices } = await import( "@/app/(org)/dashboard/settings/account/server" @@ -1399,7 +1501,11 @@ describe.runIf(Boolean(databaseUrl))( fixture.currentUser = user; const now = Math.floor(Date.now() / 1000); - fixture.session = { user: { id: user.id }, authTime: now - 11 * 60 }; + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 11 * 60, + }; expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ status: "verify", }); @@ -1407,16 +1513,28 @@ describe.runIf(Boolean(databaseUrl))( expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ status: "verify", }); - fixture.session = { user: { id: user.id }, authTime: now + 600 }; + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now + 600, + }; expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ status: "verify", }); - fixture.session = { user: { id: other.id }, authTime: now }; + fixture.session = { + user: { id: other.id }, + authMethod: "email", + authTime: now, + }; expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ status: "verify", }); - fixture.session = { user: { id: user.id }, authTime: now - 60 }; + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 60, + }; const options = await getPasskeyRegistrationOptionsAfterSignIn(); if (options.status !== "ok") throw new Error("No options."); const result = await completePasskeyRegistration( @@ -1440,7 +1558,11 @@ describe.runIf(Boolean(databaseUrl))( const owner = await makeUser(); await registerPasskey(owner); fixture.currentUser = owner; - fixture.session = { user: { id: owner.id }, authTime: now - 30 }; + fixture.session = { + user: { id: owner.id }, + authMethod: "email", + authTime: now - 30, + }; expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ status: "verify", }); @@ -1448,7 +1570,11 @@ describe.runIf(Boolean(databaseUrl))( const late = await makeUser(); fixture.currentUser = late; - fixture.session = { user: { id: late.id }, authTime: now - 30 }; + fixture.session = { + user: { id: late.id }, + authMethod: "email", + authTime: now - 30, + }; const pending = await getPasskeyRegistrationOptionsAfterSignIn(); if (pending.status !== "ok") throw new Error("No options."); await registerPasskey(late); @@ -1467,7 +1593,11 @@ describe.runIf(Boolean(databaseUrl))( const racing = await makeUser(); fixture.currentUser = racing; - fixture.session = { user: { id: racing.id }, authTime: now - 30 }; + fixture.session = { + user: { id: racing.id }, + authMethod: "email", + authTime: now - 30, + }; const challenges = []; for (let index = 0; index < 3; index++) { const options = await getPasskeyRegistrationOptionsAfterSignIn(); @@ -1496,11 +1626,19 @@ describe.runIf(Boolean(databaseUrl))( const { shouldOfferPasskey } = await import("@/lib/passkey-prompt"); const user = await makeUser(); const now = Math.floor(Date.now() / 1000); - const fresh = { user: { id: user.id }, authTime: now - 30 }; + const fresh = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 30, + }; fixture.session = fresh; expect(await shouldOfferPasskey(await reloadUser(user.id))).toBe(true); - fixture.session = { user: { id: user.id }, authTime: now - 11 * 60 }; + fixture.session = { + user: { id: user.id }, + authMethod: "email", + authTime: now - 11 * 60, + }; expect(await shouldOfferPasskey(await reloadUser(user.id))).toBe(false); fixture.session = null; expect(await shouldOfferPasskey(await reloadUser(user.id))).toBe(false); @@ -1516,13 +1654,18 @@ describe.runIf(Boolean(databaseUrl))( const later = Date.now() + 31 * 24 * 60 * 60 * 1000; fixture.session = { user: { id: user.id }, + authMethod: "email", authTime: Math.floor(later / 1000) - 30, }; expect(await shouldOfferPasskey(snoozed, later)).toBe(true); const withPasskey = await makeUser(); await registerPasskey(withPasskey); - fixture.session = { user: { id: withPasskey.id }, authTime: now - 30 }; + fixture.session = { + user: { id: withPasskey.id }, + authMethod: "email", + authTime: now - 30, + }; expect(await shouldOfferPasskey(await reloadUser(withPasskey.id))).toBe( false, ); diff --git a/apps/web/__tests__/unit/auth-options.test.ts b/apps/web/__tests__/unit/auth-options.test.ts index 0ec33189da3..9402af0662d 100644 --- a/apps/web/__tests__/unit/auth-options.test.ts +++ b/apps/web/__tests__/unit/auth-options.test.ts @@ -754,16 +754,19 @@ describe("authOptions", () => { const after = Math.floor(Date.now() / 1000); expect(signedIn.authTime).toBeGreaterThanOrEqual(before); expect(signedIn.authTime).toBeLessThanOrEqual(after); + expect(signedIn.authMethod).toBe("google"); const refreshed = await callbacks.jwt({ token: { ...signedIn } } as never); expect(refreshed.authTime).toBe(signedIn.authTime); + expect(refreshed.authMethod).toBe("google"); const updated = await callbacks.jwt({ token: { ...signedIn }, trigger: "update", - session: { authTime: after + 100_000 }, + session: { authTime: after + 100_000, authMethod: "email" }, } as never); expect(updated.authTime).toBe(signedIn.authTime); + expect(updated.authMethod).toBe("google"); const legacy = await callbacks.jwt({ token: { email: AUTHENTICATED_USER.email }, @@ -772,9 +775,10 @@ describe("authOptions", () => { const session = await options.callbacks?.session?.({ session: { user: {}, expires: "" }, - token: { id: AUTHENTICATED_USER.id, authTime: 1234 }, + token: { id: AUTHENTICATED_USER.id, authTime: 1234, authMethod: "email" }, } as never); expect((session as { authTime?: number }).authTime).toBe(1234); + expect((session as { authMethod?: string }).authMethod).toBe("email"); }); it.each(["workos", "google", "apple"])( From 521a712180f46fc1758f184a638953f32a61fcd9 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:27:17 +0000 Subject: [PATCH 18/19] test(mobile): expect the shared revocation on account deletion requests --- .../unit/mobile-account-deletion.test.ts | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/apps/web/__tests__/unit/mobile-account-deletion.test.ts b/apps/web/__tests__/unit/mobile-account-deletion.test.ts index cb41eadf797..ce36b3ccf16 100644 --- a/apps/web/__tests__/unit/mobile-account-deletion.test.ts +++ b/apps/web/__tests__/unit/mobile-account-deletion.test.ts @@ -150,20 +150,48 @@ describe("mobile account deletion request", () => { }), ); - it("signs the account out of every session, app key and agent key", async () => { + it("signs the account out of every session, app key, agent key and connected app", async () => { expect((await request()).status).toBe(200); expect(mocks.deletes).toEqual([ "sessions", "auth_api_keys", "user_passkeys", + "email_change_requests", "auth_challenges", ]); expect(mocks.updates.map(({ table }) => table)).toEqual([ "users", + "mcp_oauth_codes", + "mcp_oauth_tokens", + "agent_api_authorization_codes", "agent_api_keys", ]); expect(mocks.updates[1]).toEqual({ + table: "mcp_oauth_codes", + value: { consumedAt: expect.any(Date) }, + where: { + sql: "(`mcp_oauth_codes`.`userId` = ? and `mcp_oauth_codes`.`consumedAt` is null)", + params: ["user-1"], + }, + }); + expect(mocks.updates[2]).toEqual({ + table: "mcp_oauth_tokens", + value: { revokedAt: expect.any(Date) }, + where: { + sql: "(`mcp_oauth_tokens`.`userId` = ? and `mcp_oauth_tokens`.`revokedAt` is null)", + params: ["user-1"], + }, + }); + expect(mocks.updates[3]).toEqual({ + table: "agent_api_authorization_codes", + value: { consumedAt: expect.any(Date) }, + where: { + sql: "(`agent_api_authorization_codes`.`userId` = ? and `agent_api_authorization_codes`.`consumedAt` is null)", + params: ["user-1"], + }, + }); + expect(mocks.updates[4]).toEqual({ table: "agent_api_keys", value: { revokedAt: expect.any(Date) }, where: { From 1b26808bfc6c13d8f58a7b19faab67ca9ce8ba24 Mon Sep 17 00:00:00 2001 From: Richie McIlroy <33632126+richiemcilroy@users.noreply.github.com> Date: Sat, 21 Nov 2026 00:35:20 +0000 Subject: [PATCH 19/19] fix(passkeys): show a passkey added from the prompt in the Settings list The list kept its first props, so a passkey added through the dashboard prompt on the Account page stayed hidden until a full reload. Take the server's list whenever router.refresh() delivers a new one. --- .../dashboard/settings/account/components/Passkeys.tsx | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx b/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx index f048dbed687..a97fa014f04 100644 --- a/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx +++ b/apps/web/app/(org)/dashboard/settings/account/components/Passkeys.tsx @@ -51,6 +51,13 @@ export const Passkeys = ({ }) => { const router = useRouter(); const [passkeys, setPasskeys] = useState(initialPasskeys); + // A passkey added elsewhere (the dashboard prompt) arrives through + // router.refresh() as a new prop, so take the server's list when it changes. + const [syncedPasskeys, setSyncedPasskeys] = useState(initialPasskeys); + if (syncedPasskeys !== initialPasskeys) { + setSyncedPasskeys(initialPasskeys); + setPasskeys(initialPasskeys); + } const [supported, setSupported] = useState(null); const [verifyOpen, setVerifyOpen] = useState(false); const [verifyPurpose, setVerifyPurpose] = useState<"add" | "remove">("add");