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 7557d6a559a..1d660ff1678 100644 --- a/apps/web/__tests__/integration/passkeys-database.test.ts +++ b/apps/web/__tests__/integration/passkeys-database.test.ts @@ -7,7 +7,15 @@ import nodeCrypto, { sign, webcrypto, } from "node:crypto"; -import { authChallenges, userPasskeys, users } from "@cap/database/schema"; +import { + agentApiAuthorizationCodes, + authChallenges, + mcpOAuthClients, + mcpOAuthCodes, + 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 +28,7 @@ import { issueStepUpGrant, STEP_UP_CODE_MAX_ATTEMPTS, STEP_UP_CODES_PER_DAY, + storeChallenge, verifyStepUpCode, } from "../../../../packages/database/auth/auth-challenges"; import { @@ -47,6 +56,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 +92,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 }); @@ -979,30 +991,446 @@ 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 }, + authMethod: "email", + 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 }, + authMethod: "email", + authTime: now - 30, + }; + const options = await getPasskeyRegistrationOptionsAfterSignIn(); + if (options.status !== "ok") throw new Error("No options."); + fixture.session = { + user: { id: user.id }, + authMethod: "email", + 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("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" + ); + 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)); + }); + + 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("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" + ); + 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" @@ -1063,6 +1491,202 @@ 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 }, + authMethod: "email", + 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 }, + authMethod: "email", + authTime: now + 600, + }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + fixture.session = { + user: { id: other.id }, + authMethod: "email", + authTime: now, + }; + expect(await getPasskeyRegistrationOptionsAfterSignIn()).toEqual({ + status: "verify", + }); + + 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( + JSON.stringify( + new SoftwareAuthenticator(user.id).register( + options.options.challenge, + ), + ), + ); + expect(result.status).toBe("registered"); + 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 }, + authMethod: "email", + 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 }, + authMethod: "email", + 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 }, + authMethod: "email", + 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), + ), + { allowFirstPasskey: true }, + ), + ), + ); + 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"); + const user = await makeUser(); + const now = Math.floor(Date.now() / 1000); + 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 }, + 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); + + 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 }, + 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 }, + authMethod: "email", + 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; @@ -1074,7 +1698,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 6b73bac3b81..9402af0662d 100644 --- a/apps/web/__tests__/unit/auth-options.test.ts +++ b/apps/web/__tests__/unit/auth-options.test.ts @@ -736,6 +736,51 @@ 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); + 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, 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 }, + } as never); + expect(legacy.authTime).toBeUndefined(); + + const session = await options.callbacks?.session?.({ + session: { user: {}, expires: "" }, + 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"])( "anchors %s tokens to the authenticated user ID instead of token email", async (provider) => { 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}$/); 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: { diff --git a/apps/web/actions/auth/passkeys.ts b/apps/web/actions/auth/passkeys.ts index 385f4a2d0af..6686fc87707 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 { canAddFirstPasskeyWithoutCode } 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; @@ -33,8 +38,13 @@ export type PasskeyListItem = { createdAt: string; lastUsedAt: string | null; backedUp: boolean; + confirmsIdentity: boolean; }; +async function hasFreshSignIn(userId: string) { + return canAddFirstPasskeyWithoutCode(await getSession(), userId); +} + async function requireUser() { const user = await getCurrentUser(); if (!user) throw new Error("Unauthorized"); @@ -140,7 +150,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 { @@ -163,9 +175,37 @@ 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< + | { status: "ok"; options: PublicKeyCredentialCreationOptionsJSON } + | { status: "verify" | "limit" | "rate_limited" } +> { + const user = await requireUser(); + if (await isPasskeyLimited(user.id)) return { status: "rate_limited" }; + if (!(await hasFreshSignIn(user.id))) return { status: "verify" }; + const options = await createPasskeyRegistrationOptions(user, { + firstPasskeyOnly: true, + }); + return options ? { status: "ok", options } : { status: "verify" }; +} + +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/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 && }
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..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,8 +51,19 @@ 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"); + const [pendingRemove, setPendingRemove] = useState( + null, + ); const [grant, setGrant] = useState(null); const [registering, setRegistering] = useState(false); const [readyOpen, setReadyOpen] = useState(false); @@ -71,6 +82,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 +134,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 +165,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 +232,7 @@ export const Passkeys = ({ {passkey.lastUsedAt ? `last used ${formatDate(passkey.lastUsedAt)}` : "never used"} + {passkey.confirmsIdentity ? "" : " ยท sign-in only"}

@@ -221,11 +255,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 +341,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 && ( diff --git a/apps/web/app/(org)/dashboard/settings/account/server.ts b/apps/web/app/(org)/dashboard/settings/account/server.ts index 0e16ee7a400..db2b8327e40 100644 --- a/apps/web/app/(org)/dashboard/settings/account/server.ts +++ b/apps/web/app/(org)/dashboard/settings/account/server.ts @@ -1,21 +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, 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, @@ -206,30 +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(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 8c047e35286..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,36 +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.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/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/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/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/apps/web/lib/passkey-prompt.ts b/apps/web/lib/passkey-prompt.ts new file mode 100644 index 00000000000..e43634893d5 --- /dev/null +++ b/apps/web/lib/passkey-prompt.ts @@ -0,0 +1,36 @@ +import "server-only"; + +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"; + +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; + 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", { + error: error instanceof Error ? error.message : String(error), + }); + return false; + } +} 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/auth-options.ts b/packages/database/auth/auth-options.ts index 8e7e197e70f..c41767161d8 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,12 @@ 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; + } + if (typeof token?.authMethod === "string") { + (session as { authMethod?: string }).authMethod = token.authMethod; + } return session; }, @@ -533,6 +540,8 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { if (!dbUser) { if (user) { token.id = user?.id; + token.authTime = signInTimestamp(); + token.authMethod = account?.provider; } return token; } @@ -544,6 +553,20 @@ export const authOptions = (ssoContext?: SsoAuthContext): NextAuthOptions => { email: dbUser.email, picture: dbUser.image, sessionVersion: dbUser.authSessionVersion, + ...(user + ? { + authTime: signInTimestamp(), + authMethod: account?.provider, + } + : typeof token.authTime === "number" + ? { + 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 new file mode 100644 index 00000000000..a8f8913e064 --- /dev/null +++ b/packages/database/auth/fresh-sign-in.ts @@ -0,0 +1,47 @@ +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 + ); +} + +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) + ); +} diff --git a/packages/database/auth/passkeys.ts b/packages/database/auth/passkeys.ts index a8f5f5102c7..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() @@ -379,12 +386,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 +403,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 +428,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 = @@ -429,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" }; @@ -473,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 @@ -483,21 +505,30 @@ 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 && + options.allowFirstPasskey === true && + (await consumeChallenge({ + purpose: "passkey_first_registration", challenge, userId, database: tx, - })) - ) { - return "reset"; - } + })); + if (!claimedSetup && !claimedFirst) return "reset"; + confirmsIdentity = claimedSetup; 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, @@ -508,6 +539,7 @@ export async function verifyPasskeyRegistration( transports: storedTransports(response.response.transports) ?? [], deviceType: info.credentialDeviceType, backedUp: info.credentialBackedUp, + confirmsIdentity, aaguid: info.aaguid, name, createdAt, @@ -530,6 +562,7 @@ export async function verifyPasskeyRegistration( createdAt, lastUsedAt: null, backedUp: info.credentialBackedUp, + confirmsIdentity, }, }; } @@ -558,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)) 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/migrations/0065_passkey_confirms_identity.sql b/packages/database/migrations/0065_passkey_confirms_identity.sql new file mode 100644 index 00000000000..d32b2451cfe --- /dev/null +++ b/packages/database/migrations/0065_passkey_confirms_identity.sql @@ -0,0 +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 new file mode 100644 index 00000000000..bd128082371 --- /dev/null +++ b/packages/database/migrations/meta/0065_snapshot.json @@ -0,0 +1,6660 @@ +{ + "version": "5", + "dialect": "mysql", + "id": "b303592d-54ac-4370-ae15-4f84f46fefc9", + "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 + }, + "user_consumed_idx": { + "name": "user_consumed_idx", + "columns": ["userId", "consumedAt"], + "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 + }, + "user_revoked_idx": { + "name": "user_revoked_idx", + "columns": ["userId", "revokedAt"], + "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..cdc84e66957 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": 1795219397974, + "tag": "0065_passkey_confirms_identity", + "breakpoints": true } ] } diff --git a/packages/database/package.json b/packages/database/package.json index 1dc023367c1..e5599e0badf 100644 --- a/packages/database/package.json +++ b/packages/database/package.json @@ -67,9 +67,11 @@ "./auth/auth-challenges": "./auth/auth-challenges.ts", "./auth/passkeys": "./auth/passkeys.ts", "./auth/email-change": "./auth/email-change.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", + "./auth/revoke-credentials": "./auth/revoke-credentials.ts", "./auth/session": "./auth/session.ts", "./auth/sso": "./auth/sso.ts", "./auth/sso-state": "./auth/sso-state.ts", diff --git a/packages/database/schema.ts b/packages/database/schema.ts index 3699f767763..b67c64bea97 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( @@ -1052,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(), @@ -1247,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), ], ); @@ -1269,6 +1272,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,