diff --git a/apps/api/src/app.ts b/apps/api/src/app.ts index 1378f56..993f495 100644 --- a/apps/api/src/app.ts +++ b/apps/api/src/app.ts @@ -28,6 +28,7 @@ import { Realtime } from "./realtime"; import { isAdultRoom, Rooms } from "./rooms"; import { Signer } from "./keys"; import { Blocks, isSha256 } from "./blocks"; +import { fingerprint as keyFingerprint, Importers, maxAccounts, settingsBounds, type ImporterAccount } from "./importer"; import { consent, Imports, type Grant } from "./imports"; import { availableTo, BlockedUpload, ProductError, Products, type EditRights, type ProductViewer } from "./products"; import { @@ -199,6 +200,7 @@ export function createApp({ const cases = new Cases(db, perms); const blocks = new Blocks(db); const imports = new Imports(db, signer, imvu); + const importers = new Importers(db); const notifications = new Notifications(db, (userId, message) => realtime.notify(userId, message)); /** Tells a product's creator that someone else changed it. */ @@ -376,6 +378,18 @@ export function createApp({ } }; + const importerAccountView = (a: ImporterAccount) => ({ + id: a.id, + imvuId: a.imvuId, + username: a.username, + state: a.state as "waiting" | "received" | "ok" | "sign_in_failed" | "needs_password", + stateMessage: a.stateMessage, + stateAt: a.stateAt.toISOString(), + accessPass: a.accessPass, + ageVerified: a.ageVerified, + createdAt: a.createdAt.toISOString(), + }); + const grantView = (r: { grant: Grant; catalogName?: string | null; imvuName?: string | null }) => ({ id: r.grant.id, catalog: r.grant.catalogId, @@ -1933,6 +1947,43 @@ export function createApp({ }, ) + // The importer program's setup (docs/imports.md "IMVU accounts"): its key, its config, its accounts' states. + .post( + "/importer/hello", + async ({ request, body }) => { + const c = await imports.importerFor(request.headers.get("authorization")); + if (!c) throw new Problem(401, "forbidden", "Not an importer of an approved catalog with imports on."); + const r = await productCall(() => importers.hello(c, body.version, body.publicKey)); + if (r.changed) await audited(null, "catalog.importer_hello", c.id, { version: body.version, fingerprint: keyFingerprint(body.publicKey) }); + const [fresh] = await db.select().from(catalog).where(eq(catalog.id, c.id)); + return importers.config(fresh!); + }, + { body: t.Object({ version: t.String({ maxLength: 40 }), publicKey: t.String({ maxLength: 1200 }) }) }, + ) + .get("/importer/config", async ({ request }) => { + const c = await imports.importerFor(request.headers.get("authorization")); + if (!c) throw new Problem(401, "forbidden", "Not an importer of an approved catalog with imports on."); + return importers.config(c); + }) + .post( + "/importer/accounts/:id", + async ({ request, params, body }) => { + const c = await imports.importerFor(request.headers.get("authorization")); + if (!c) throw new Problem(401, "forbidden", "Not an importer of an approved catalog with imports on."); + const a = await productCall(() => importers.report(c, params.id, body)); + return { account: importerAccountView(a) }; + }, + { + params: t.Object({ id: t.String({ maxLength: 20 }) }), + body: t.Object({ + received: t.Optional(t.Boolean()), + state: t.Optional(t.Union([t.Literal("ok"), t.Literal("sign_in_failed"), t.Literal("needs_password")])), + accessPass: t.Optional(t.Boolean()), + message: t.Optional(t.String({ maxLength: 300 })), + }), + }, + ) + // Imports (docs/imports.md): grants, requests, and each catalog's importer. .get("/imports/catalogs", async () => ({ catalogs: await imports.catalogs(), consent })) .get("/imports/grants", async ({ me }) => ({ grants: (await imports.grantsOf(me.id)).map(grantView) }), { signedIn: true }) @@ -2080,13 +2131,25 @@ export function createApp({ }) .from(schema.importJob) .where(eq(schema.importJob.catalogId, c.id)); + const run = await perms.can(me, "import:run", scope); return { importer: c.importer as "off" | "on" | "paused", + program: { + version: c.importerVersion, + seenAt: c.importerSeenAt?.toISOString() ?? null, + fingerprint: c.importerFingerprint, + // Passwords are sealed for this key in the browser; only those who may add accounts get it. + publicKey: run ? c.importerPublicKey : null, + }, + settings: c.importerSettings, + settingsBounds, + maxAccounts, + accounts: (await importers.accounts(c.id)).map(importerAccountView), grants: grants.map(grantView), jobs: jobs.map((j) => ({ ...jobView(j.job), name: j.name ?? "" })), counts: counts ?? { queued: 0, claimed: 0, failed: 0, done: 0 }, permissions: { - run: await perms.can(me, "import:run", scope), + run, pause: await perms.can(me, "import:pause", scope), accept: await perms.can(me, "import:accept", scope), withdraw: await perms.can(me, "import:withdraw", scope), @@ -2132,6 +2195,84 @@ export function createApp({ }, { scripted: true, params: catalogParam }, ) + .get( + "/catalogs/:id/importer/imvu-account", + async ({ me, params, query }) => { + await need(me, "import:run", catalogScope(params.id)); + const u = await imvuCall(me, () => imvu.byUsername(query.username)); + return { imvuId: u.id, username: u.username, picture: u.picture, accessPass: u.accessPass, ageVerified: u.ageVerified }; + }, + { signedIn: true, params: catalogParam, query: t.Object({ username: t.String({ minLength: 1, maxLength: 64 }) }) }, + ) + .post( + "/catalogs/:id/importer/accounts", + async ({ me, params, body, set }) => { + await need(me, "import:run", catalogScope(params.id)); + const u = await imvuCall(me, () => imvu.byId(body.imvuId)); + const a = await productCall(() => + importers.addAccount( + params.id, + { imvuId: u.id, username: u.username, accessPass: u.accessPass, ageVerified: u.ageVerified, sealed: body.sealed, fingerprint: body.fingerprint }, + me.id, + ), + ); + await audited(me, "catalog.importer_account", params.id, { change: "add", imvuId: a.imvuId, username: a.username }); + set.status = 201; + return { account: importerAccountView(a) }; + }, + { + scripted: true, + params: catalogParam, + body: t.Object({ imvuId: t.Integer({ minimum: 1 }), sealed: t.String({ maxLength: 1000 }), fingerprint: t.String({ maxLength: 64 }) }), + }, + ) + .put( + "/catalogs/:id/importer/accounts/:account/password", + async ({ me, params, body }) => { + await need(me, "import:run", catalogScope(params.id)); + const a = await productCall(() => importers.setPassword(params.id, params.account, body.sealed, body.fingerprint)); + await audited(me, "catalog.importer_account", params.id, { change: "password", imvuId: a.imvuId, username: a.username }); + return { account: importerAccountView(a) }; + }, + { + scripted: true, + params: t.Object({ id: t.String({ pattern: "^[a-z2-7]{10}$" }), account: t.String({ maxLength: 20 }) }), + body: t.Object({ sealed: t.String({ maxLength: 1000 }), fingerprint: t.String({ maxLength: 64 }) }), + }, + ) + .post( + "/catalogs/:id/importer/accounts/:account/move", + async ({ me, params, body }) => { + await need(me, "import:run", catalogScope(params.id)); + await productCall(() => importers.moveAccount(params.id, params.account, body.direction)); + return { accounts: (await importers.accounts(params.id)).map(importerAccountView) }; + }, + { + scripted: true, + params: t.Object({ id: t.String({ pattern: "^[a-z2-7]{10}$" }), account: t.String({ maxLength: 20 }) }), + body: t.Object({ direction: t.Union([t.Literal("up"), t.Literal("down")]) }), + }, + ) + .delete( + "/catalogs/:id/importer/accounts/:account", + async ({ me, params, set }) => { + await need(me, "import:run", catalogScope(params.id)); + const a = await productCall(() => importers.removeAccount(params.id, params.account)); + await audited(me, "catalog.importer_account", params.id, { change: "remove", imvuId: a.imvuId, username: a.username }); + set.status = 204; + }, + { scripted: true, params: t.Object({ id: t.String({ pattern: "^[a-z2-7]{10}$" }), account: t.String({ maxLength: 20 }) }) }, + ) + .post( + "/catalogs/:id/importer/settings", + async ({ me, params, body }) => { + await need(me, "import:run", catalogScope(params.id)); + const settings = await productCall(() => importers.setSettings(params.id, body)); + await audited(me, "catalog.importer_settings", params.id, settings); + return { settings }; + }, + { scripted: true, params: catalogParam, body: t.Object({ rate: t.Number(), concurrency: t.Integer() }) }, + ) .post( "/catalogs/:id/importer/jobs/:job/retry", async ({ me, params }) => { @@ -3260,7 +3401,7 @@ export function createApp({ .get("/health", () => ({ ok: true })) .use(api); - return { app, realtime, age, rooms, products, signer, hosted, decorations, imports }; + return { app, realtime, age, rooms, products, signer, hosted, decorations, imports, importers }; } export type App = ReturnType["app"]; diff --git a/apps/api/src/importer.ts b/apps/api/src/importer.ts new file mode 100644 index 0000000..260f007 --- /dev/null +++ b/apps/api/src/importer.ts @@ -0,0 +1,215 @@ +// A catalog's importer program and the IMVU accounts it signs in with (docs/imports.md "IMVU accounts"). The importer +// sends its RSA public key; the console seals each account's password in the browser for that key; the hub keeps the +// sealed copy only until the importer has it. Everything but what the importer needs to reach the hub is set here, +// from the console. The routes are in app.ts. +import { createHash, createPublicKey } from "node:crypto"; +import { and, asc, eq, lt, sql, schema, type Database, type ImporterSettings } from "@t5de/db"; +import { newProductID, ProductError, type Catalog } from "./products"; + +const { catalog, importerAccount } = schema; + +export type ImporterAccount = typeof importerAccount.$inferSelect; +export type AccountState = "waiting" | "received" | "ok" | "sign_in_failed" | "needs_password"; + +/** A sealed password the importer hasn't fetched within this long is dropped. */ +export const sealedFor = 7 * 24 * 60 * 60 * 1000; +/** Accounts a catalog's importer may have. */ +export const maxAccounts = 10; +/** Settings' bounds. */ +export const settingsBounds = { rate: { min: 0.2, max: 10 }, concurrency: { min: 1, max: 8 } } as const; + +/** sha256 of the key's SPKI, hex: what the console shows (shortened) and seals are checked against. */ +export const fingerprint = (spkiBase64: string) => createHash("sha256").update(Buffer.from(spkiBase64, "base64")).digest("hex"); + +/** Checks an importer's public key: base64 SPKI of an RSA key of 3072 to 4096 bits. */ +function checkPublicKey(spki: string) { + if (!/^[A-Za-z0-9+/]+={0,2}$/.test(spki)) throw new ProductError(400, "invalid", "The public key isn't base64."); + let bits: number | undefined; + try { + const key = createPublicKey({ key: Buffer.from(spki, "base64"), format: "der", type: "spki" }); + if (key.asymmetricKeyType !== "rsa") throw new Error("not RSA"); + bits = key.asymmetricKeyDetails?.modulusLength; + } catch { + throw new ProductError(400, "invalid", "The public key isn't an RSA key (SPKI)."); + } + if (!bits || bits < 3072 || bits > 4096) throw new ProductError(400, "invalid", "The public key must be RSA with 3072 to 4096 bits."); +} + +/** Checks a sealed password: base64 of one RSA-OAEP block (384 or 512 bytes). */ +function checkSealed(sealed: string) { + const bytes = /^[A-Za-z0-9+/]+={0,2}$/.test(sealed) ? Buffer.from(sealed, "base64").length : 0; + if (bytes !== 384 && bytes !== 512) throw new ProductError(400, "invalid", "That isn't a sealed password."); +} + +export class Importers { + constructor(private readonly db: Database) {} + + private async catalogOf(catalogId: string): Promise { + const [c] = await this.db.select().from(catalog).where(eq(catalog.id, catalogId)); + if (!c) throw new ProductError(404, "not_found", "No such catalog."); + return c; + } + + // ---- the importer program ---- + + /** + * The importer says hello: its version and public key. A new key (a new install) can't read passwords sealed for + * the old one, so those accounts need their passwords again. + */ + async hello(c: Catalog, version: string, publicKey: string): Promise<{ changed: boolean }> { + checkPublicKey(publicKey); + const print = fingerprint(publicKey); + const changed = c.importerFingerprint !== print; + await this.db.transaction(async (tx) => { + await tx + .update(catalog) + .set({ importerPublicKey: publicKey, importerFingerprint: print, importerVersion: version, importerSeenAt: new Date() }) + .where(eq(catalog.id, c.id)); + if (changed && c.importerFingerprint) + await tx + .update(importerAccount) + .set({ sealed: null, sealedFor: null, sealedAt: null, state: "needs_password", stateMessage: "The importer's key changed.", stateAt: new Date() }) + .where(eq(importerAccount.catalogId, c.id)); + }); + return { changed }; + } + + /** What the importer runs with: paused or not, its settings, and its accounts in order (sealed passwords too). */ + async config(c: Catalog) { + await this.db.update(catalog).set({ importerSeenAt: new Date() }).where(eq(catalog.id, c.id)); + const accounts = await this.accounts(c.id); + return { + paused: c.importer === "paused", + settings: c.importerSettings, + fingerprint: c.importerFingerprint, + accounts: accounts.map((a) => ({ + id: a.id, + imvuId: a.imvuId, + username: a.username, + // Only a password sealed for the key the importer has now. + sealed: a.sealed && a.sealedFor === c.importerFingerprint ? a.sealed : null, + })), + }; + } + + /** The importer reports on an account: it has the sealed password, and how signing in went. */ + async report(c: Catalog, id: string, r: { received?: boolean; state?: "ok" | "sign_in_failed" | "needs_password"; accessPass?: boolean; message?: string }) { + const [a] = await this.db + .select() + .from(importerAccount) + .where(and(eq(importerAccount.id, id), eq(importerAccount.catalogId, c.id))); + if (!a) throw new ProductError(404, "not_found", "No such account."); + const set: Partial = {}; + if (r.received && a.sealed) Object.assign(set, { sealed: null, sealedFor: null, sealedAt: null, state: "received", stateMessage: "", stateAt: new Date() }); + if (r.state) Object.assign(set, { state: r.state, stateMessage: (r.message ?? "").slice(0, 300), stateAt: new Date() }); + if (r.accessPass !== undefined) set.accessPass = r.accessPass; + if (Object.keys(set).length === 0) return a; + const [updated] = await this.db.update(importerAccount).set(set).where(eq(importerAccount.id, a.id)).returning(); + return updated!; + } + + // ---- the console ---- + + async accounts(catalogId: string): Promise { + return this.db + .select() + .from(importerAccount) + .where(eq(importerAccount.catalogId, catalogId)) + .orderBy(asc(importerAccount.position), asc(importerAccount.createdAt)); + } + + /** Adds an account, its password sealed for the importer's key (which must be the one the console showed). */ + async addAccount( + catalogId: string, + a: { imvuId: number; username: string; accessPass: boolean; ageVerified: boolean; sealed: string; fingerprint: string }, + byId: string, + ): Promise { + const c = await this.catalogOf(catalogId); + this.checkSeal(c, a.sealed, a.fingerprint); + const existing = await this.accounts(c.id); + if (existing.some((x) => x.imvuId === a.imvuId)) + throw new ProductError(409, "exists", "The importer has that account already: enter its password again instead."); + if (existing.length >= maxAccounts) throw new ProductError(409, "too_many", `An importer can have at most ${maxAccounts} accounts.`); + const [row] = await this.db + .insert(importerAccount) + .values({ + id: newProductID(), + catalogId: c.id, + imvuId: a.imvuId, + username: a.username, + position: existing.length ? Math.max(...existing.map((x) => x.position)) + 1 : 0, + sealed: a.sealed, + sealedFor: a.fingerprint, + sealedAt: new Date(), + accessPass: a.accessPass, + ageVerified: a.ageVerified, + addedBy: byId, + }) + .returning(); + return row!; + } + + /** A new password for an account. */ + async setPassword(catalogId: string, id: string, sealed: string, print: string): Promise { + const c = await this.catalogOf(catalogId); + this.checkSeal(c, sealed, print); + const [row] = await this.db + .update(importerAccount) + .set({ sealed, sealedFor: print, sealedAt: new Date(), state: "waiting", stateMessage: "", stateAt: new Date() }) + .where(and(eq(importerAccount.id, id), eq(importerAccount.catalogId, c.id))) + .returning(); + if (!row) throw new ProductError(404, "not_found", "No such account."); + return row; + } + + private checkSeal(c: Catalog, sealed: string, print: string) { + if (!c.importerFingerprint) throw new ProductError(409, "no_importer", "Start the importer first: passwords are sealed for its key."); + if (print !== c.importerFingerprint) + throw new ProductError(409, "importer_key_changed", "The importer's key changed since this page was loaded. Load it again and retry."); + checkSealed(sealed); + } + + /** Removes an account; the importer forgets it on its next look at its config. */ + async removeAccount(catalogId: string, id: string): Promise { + const [row] = await this.db + .delete(importerAccount) + .where(and(eq(importerAccount.id, id), eq(importerAccount.catalogId, catalogId))) + .returning(); + if (!row) throw new ProductError(404, "not_found", "No such account."); + return row; + } + + /** Moves an account one place earlier or later in the order the importer tries them. */ + async moveAccount(catalogId: string, id: string, direction: "up" | "down"): Promise { + const list = await this.accounts(catalogId); + const i = list.findIndex((a) => a.id === id); + if (i < 0) throw new ProductError(404, "not_found", "No such account."); + const j = direction === "up" ? i - 1 : i + 1; + if (j < 0 || j >= list.length) return; + [list[i], list[j]] = [list[j]!, list[i]!]; + await this.db.transaction(async (tx) => { + for (const [n, a] of list.entries()) await tx.update(importerAccount).set({ position: n }).where(eq(importerAccount.id, a.id)); + }); + } + + async setSettings(catalogId: string, s: ImporterSettings): Promise { + const { rate, concurrency } = settingsBounds; + if (!(s.rate >= rate.min && s.rate <= rate.max)) throw new ProductError(400, "invalid", `Requests a second: ${rate.min} to ${rate.max}.`); + if (!Number.isInteger(s.concurrency) || s.concurrency < concurrency.min || s.concurrency > concurrency.max) + throw new ProductError(400, "invalid", `Jobs at once: ${concurrency.min} to ${concurrency.max}.`); + const settings = { rate: Math.round(s.rate * 10) / 10, concurrency: s.concurrency }; + const [c] = await this.db.update(catalog).set({ importerSettings: settings }).where(eq(catalog.id, catalogId)).returning(); + if (!c) throw new ProductError(404, "not_found", "No such catalog."); + return c.importerSettings; + } + + /** Drops sealed passwords no importer fetched in time; their accounts need their passwords again. */ + async expireSealed(): Promise { + const rows = await this.db + .update(importerAccount) + .set({ sealed: null, sealedFor: null, sealedAt: null, state: "needs_password", stateMessage: "The importer didn't fetch the password within 7 days.", stateAt: new Date() }) + .where(and(sql`${importerAccount.sealed} is not null`, lt(importerAccount.sealedAt, new Date(Date.now() - sealedFor)))) + .returning({ id: importerAccount.id }); + return rows.length; + } +} diff --git a/apps/api/src/index.ts b/apps/api/src/index.ts index e1444c5..3b0bbc1 100644 --- a/apps/api/src/index.ts +++ b/apps/api/src/index.ts @@ -63,7 +63,7 @@ for (const id of providers) { } const ageService = new AgeService(db, providers.map((id) => ageProviders[id]!())); -const { app, age, rooms, products, imports } = createApp({ db, auth, imvu, age: ageService, apiURL, webURL, settings }); +const { app, age, rooms, products, imports, importers } = createApp({ db, auth, imvu, age: ageService, apiURL, webURL, settings }); app.listen({ port, hostname: env.HOST ?? "0.0.0.0" }); // Age answers that can change (IMVU's) are checked again when they expire, a few at a time; revisions missing their @@ -90,5 +90,11 @@ const importRecheck = () => .recheck(200) .then((r) => (r.queued || r.withdrawn.length) && console.log(`imports: ${r.queued} rechecks queued, ${r.withdrawn.length} withdrawn`)) .catch((e) => console.error("import rechecks:", e)); -setInterval(importRecheck, 60 * 60 * 1000); +setInterval(() => { + importRecheck(); + importers + .expireSealed() + .then((n) => n && console.log(`imports: ${n} sealed importer passwords expired`)) + .catch((e) => console.error("importer passwords:", e)); +}, 60 * 60 * 1000); console.log(`t5de-hub API on ${apiURL} (website ${webURL})`); diff --git a/apps/api/test/imports.test.ts b/apps/api/test/imports.test.ts index 96d6190..06694cf 100644 --- a/apps/api/test/imports.test.ts +++ b/apps/api/test/imports.test.ts @@ -56,6 +56,7 @@ afterAll(async () => { }); type Person = { cookie: string; name: string }; +let rootAdmin: Person; // the first person: an admin async function call(p: Person | undefined, method: string, path: string, body?: unknown, headers: Record = {}) { const res = await fetch(base + path, { method, @@ -95,6 +96,7 @@ const imvuProduct = (name: string, creator: number, rating = "GA") => ({ product test("grants, requests, the importer's jobs, and withdrawal", async () => { const admin = await person("root"); + rootAdmin = admin; const owner = await person("shelf"); const maker = await person("maker", 501); const fan = await person("fan"); @@ -217,3 +219,98 @@ test("IMVU's 401 keeps what was last seen; 404 is gone", async () => { imvuProducts.delete(9500); expect(await imports.info(9500, true)).toBeUndefined(); }); + +test("the importer's key, IMVU accounts with sealed passwords, and settings", async () => { + const admin = rootAdmin; + const owner = await person("keeper"); + const outsider = await person("outsider"); + accounts.set(601, { id: 601, username: "ImportBot", tagline: "", ageVerified: true, accessPass: true, picture: null }); + accounts.set(602, { id: 602, username: "SpareBot", tagline: "", ageVerified: false, accessPass: false, picture: null }); + + const reg = await call(owner, "POST", "/api/v1/catalogs", { name: "Keeper Shelf", url: "https://keeper.example.test", contact: "k@example.test", visibility: "public", membership: "open" }); + const catalogID = reg.json.catalog.id as string; + expect((await call(admin, "POST", `/api/v1/console/catalogs/${catalogID}/approve`)).status).toBe(200); + const on = await call(owner, "POST", `/api/v1/catalogs/${catalogID}/importer`, { enabled: true }); + const importer = { Authorization: `Importer ${catalogID}:${on.json.key}` }; + const page = async () => (await call(owner, "GET", `/api/v1/catalogs/${catalogID}/importer`)).json; + + // Before the importer has said hello there's no key to seal for. + expect((await page()).program).toMatchObject({ version: "", seenAt: null, fingerprint: null, publicKey: null }); + const keys = async () => { + const pair = (await crypto.subtle.generateKey( + { name: "RSA-OAEP", modulusLength: 3072, publicExponent: new Uint8Array([1, 0, 1]), hash: "SHA-256" }, + true, + ["encrypt", "decrypt"], + )) as CryptoKeyPair; + return { pair, spki: Buffer.from(await crypto.subtle.exportKey("spki", pair.publicKey)).toString("base64") }; + }; + // As the console's browser does: the account's ID and password, sealed for the importer's key. + const seal = async (spki: string, imvuId: number, password: string) => { + const key = await crypto.subtle.importKey("spki", Buffer.from(spki, "base64"), { name: "RSA-OAEP", hash: "SHA-256" }, false, ["encrypt"]); + const data = new TextEncoder().encode(JSON.stringify({ imvuId, password })); + return Buffer.from(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, key, data)).toString("base64"); + }; + const unseal = async (pair: CryptoKeyPair, sealed: string) => + JSON.parse(new TextDecoder().decode(await crypto.subtle.decrypt({ name: "RSA-OAEP" }, pair.privateKey, Buffer.from(sealed, "base64")))); + + const k1 = await keys(); + expect((await call(owner, "POST", `/api/v1/catalogs/${catalogID}/importer/accounts`, { imvuId: 601, sealed: await seal(k1.spki, 601, "x"), fingerprint: "00" })).json.error).toBe("no_importer"); + expect((await call(undefined, "POST", "/api/v1/importer/hello", { version: "0.1.0", publicKey: "not a key" }, importer)).status).toBe(400); + const hello = await call(undefined, "POST", "/api/v1/importer/hello", { version: "0.1.0", publicKey: k1.spki }, importer); + expect(hello.status).toBe(200); + expect(hello.json).toMatchObject({ paused: false, settings: { rate: 2, concurrency: 2 }, accounts: [] }); + const shown = (await page()).program; + expect(shown).toMatchObject({ version: "0.1.0", publicKey: k1.spki }); + expect(shown.fingerprint).toBe(hello.json.fingerprint); + expect(shown.seenAt).not.toBeNull(); + + // The console looks the account up, then adds it with the password sealed for that key. + expect((await call(outsider, "GET", `/api/v1/catalogs/${catalogID}/importer/imvu-account?username=ImportBot`)).status).toBe(403); + const found = (await call(owner, "GET", `/api/v1/catalogs/${catalogID}/importer/imvu-account?username=ImportBot`)).json; + expect(found).toMatchObject({ imvuId: 601, username: "ImportBot", accessPass: true, ageVerified: true }); + const add = (imvuId: number, sealed: string, fingerprint = shown.fingerprint) => + call(owner, "POST", `/api/v1/catalogs/${catalogID}/importer/accounts`, { imvuId, sealed, fingerprint }); + expect((await add(601, "bm90IHNlYWxlZA==")).json.error).toBe("invalid"); + expect((await add(601, await seal(k1.spki, 601, "pw1"), "ff".repeat(32))).json.error).toBe("importer_key_changed"); + const added = await add(601, await seal(k1.spki, 601, "pw1")); + expect(added.status).toBe(201); + expect(added.json.account).toMatchObject({ username: "ImportBot", state: "waiting", accessPass: true }); + expect((await add(601, await seal(k1.spki, 601, "pw1"))).json.error).toBe("exists"); + expect((await add(602, await seal(k1.spki, 602, "pw2"))).status).toBe(201); + + // The importer gets the sealed passwords, in order, and can read them; the hub drops each once it has it. + const config = (await call(undefined, "GET", "/api/v1/importer/config", undefined, importer)).json; + expect(config.accounts.map((a: any) => a.username)).toEqual(["ImportBot", "SpareBot"]); + expect(await unseal(k1.pair, config.accounts[0].sealed)).toEqual({ imvuId: 601, password: "pw1" }); + const first = config.accounts[0].id as string; + expect((await call(undefined, "POST", `/api/v1/importer/accounts/${first}`, { received: true }, importer)).json.account.state).toBe("received"); + expect((await call(undefined, "GET", "/api/v1/importer/config", undefined, importer)).json.accounts[0].sealed).toBeNull(); + await call(undefined, "POST", `/api/v1/importer/accounts/${first}`, { state: "ok", accessPass: true }, importer); + expect((await call(undefined, "POST", `/api/v1/importer/accounts/${first}`, { state: "ok" }, { Authorization: `Importer ${catalogID}:wrong` })).status).toBe(401); + + // The order can change; settings are bounded. + await call(owner, "POST", `/api/v1/catalogs/${catalogID}/importer/accounts/${first}/move`, { direction: "down" }); + expect((await page()).accounts.map((a: any) => [a.username, a.state])).toEqual([["SpareBot", "waiting"], ["ImportBot", "ok"]]); + expect((await call(owner, "POST", `/api/v1/catalogs/${catalogID}/importer/settings`, { rate: 50, concurrency: 2 })).status).toBe(400); + expect((await call(owner, "POST", `/api/v1/catalogs/${catalogID}/importer/settings`, { rate: 0.5, concurrency: 4 })).json.settings).toEqual({ rate: 0.5, concurrency: 4 }); + expect((await call(undefined, "GET", "/api/v1/importer/config", undefined, importer)).json.settings).toEqual({ rate: 0.5, concurrency: 4 }); + + // A new install (a new key) can't read the old seals: every account needs its password again. + const k2 = await keys(); + expect((await call(undefined, "POST", "/api/v1/importer/hello", { version: "0.1.1", publicKey: k2.spki }, importer)).json.accounts.every((a: any) => a.sealed === null)).toBe(true); + const after = await page(); + expect(after.accounts.map((a: any) => a.state)).toEqual(["needs_password", "needs_password"]); + const spare = after.accounts[0].id as string; + const again = await call(owner, "PUT", `/api/v1/catalogs/${catalogID}/importer/accounts/${spare}/password`, { sealed: await seal(k2.spki, 602, "pw3"), fingerprint: after.program.fingerprint }); + expect(again.json.account.state).toBe("waiting"); + const sealed = (await call(undefined, "GET", "/api/v1/importer/config", undefined, importer)).json.accounts[0].sealed; + expect(await unseal(k2.pair, sealed)).toEqual({ imvuId: 602, password: "pw3" }); + + // Removed accounts leave the importer's config; it's all audited. + expect((await call(owner, "DELETE", `/api/v1/catalogs/${catalogID}/importer/accounts/${spare}`)).status).toBe(204); + expect((await call(undefined, "GET", "/api/v1/importer/config", undefined, importer)).json.accounts.map((a: any) => a.username)).toEqual(["ImportBot"]); + const actions = (await call(owner, "GET", "/api/v1/console/audit")).json.entries.map((e: any) => e.action); + expect(actions).toEqual(expect.arrayContaining(["catalog.importer_hello", "catalog.importer_account", "catalog.importer_settings"])); + // Passwords never show on the console. + expect(JSON.stringify(await page())).not.toContain(sealed); +}); diff --git a/apps/web/app/console/catalogs/[id]/imports/importer-account-form.tsx b/apps/web/app/console/catalogs/[id]/imports/importer-account-form.tsx new file mode 100644 index 0000000..abaa5a3 --- /dev/null +++ b/apps/web/app/console/catalogs/[id]/imports/importer-account-form.tsx @@ -0,0 +1,186 @@ +"use client"; +// Adds an IMVU account to the catalog's importer, or gives one a new password (docs/imports.md "IMVU accounts"). +// The account is looked up and shown for confirmation first; then the password is sealed here, in the browser, for +// the importer's public key, so the hub only ever has the sealed copy. +import { useRouter } from "next/navigation"; +import { useState, useTransition } from "react"; +import { Tag } from "@/components/status"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { shortFingerprint } from "@/lib/importer"; +import { lookupImporterAccount, saveImporterAccount, type ImvuAccountInfo } from "../../actions"; + +/** Seals {imvuId, password} for the importer's key: RSA-OAEP with SHA-256, base64. */ +async function seal(publicKey: string, imvuId: number, password: string): Promise { + if (!globalThis.crypto?.subtle) throw new Error("This browser can't encrypt here (the page needs HTTPS)."); + const spki = Uint8Array.from(atob(publicKey), (c) => c.charCodeAt(0)); + const key = await crypto.subtle.importKey("spki", spki, { name: "RSA-OAEP", hash: "SHA-256" }, false, ["encrypt"]); + const data = new TextEncoder().encode(JSON.stringify({ imvuId, password })); + const sealed = new Uint8Array(await crypto.subtle.encrypt({ name: "RSA-OAEP" }, key, data)); + let s = ""; + for (const b of sealed) s += String.fromCharCode(b); + return btoa(s); +} + +export function ImporterAccountForm({ + catalogId, + publicKey, + fingerprint, + version, + account, +}: { + catalogId: string; + publicKey: string; + fingerprint: string; + version: string; + /** Set to give an existing account a new password. */ + account?: { id: string; imvuId: number; username: string }; +}) { + const router = useRouter(); + const [username, setUsername] = useState(account?.username ?? ""); + const [password, setPassword] = useState(""); + const [found, setFound] = useState(null); + const [error, setError] = useState(""); + const [notice, setNotice] = useState(""); + const [pending, start] = useTransition(); + const [saving, setSaving] = useState(false); // the confirm step, not the lookup + + const check = (e: React.FormEvent) => { + e.preventDefault(); + setError(""); + setNotice(""); + if (!username.trim() || !password) return setError("Give the account's username and password."); + if (password.length > 128) return setError("That password is too long."); + start(async () => { + const r = await lookupImporterAccount(catalogId, username); + if ("error" in r) return setError(r.error); + if (account && r.ok.imvuId !== account.imvuId) + return setError( + `${account.username} is another IMVU account now (ID ${r.ok.imvuId}). Remove it and add that one.`, + ); + setFound(r.ok); + }); + }; + + const confirm = () => { + if (!found) return; + setSaving(true); + start(async () => { + try { + await save(found); + } finally { + setSaving(false); + } + }); + }; + + const save = async (found: ImvuAccountInfo) => { + let sealed: string; + try { + sealed = await seal(publicKey, found.imvuId, password); + } catch (e) { + setFound(null); + return setError(e instanceof Error ? e.message : "The password couldn't be encrypted."); + } + const r = await saveImporterAccount(catalogId, { imvuId: found.imvuId, account: account?.id, sealed, fingerprint }); + setFound(null); + if ("error" in r) return setError(r.error); + setPassword(""); + if (!account) setUsername(""); + setNotice( + account + ? "Saved. The importer picks the new password up within a minute." + : `${found.username} added. The importer picks it up within a minute.`, + ); + router.refresh(); + }; + + return ( + <> +
+ {!account && ( + setUsername(e.target.value)} + placeholder="IMVU username" + aria-label="IMVU username" + autoComplete="off" + maxLength={64} + className="min-w-44 flex-1" + /> + )} + {/* No name: the password is never sent as a form field, only sealed. */} + setPassword(e.target.value)} + placeholder={account ? `New password for ${account.username}` : "Password"} + aria-label="Password" + autoComplete="new-password" + className="min-w-44 flex-1" + /> + +
+ {error &&

{error}

} + {notice &&

{notice}

} + + !open && !pending && setFound(null)}> + + + {account ? "New Password for This Account?" : "Add This Account?"} + The importer signs in to IMVU with it to import products. + + {found && ( +
+ {found.picture ? ( + + ) : ( + + {found.username.slice(0, 1)} + + )} +
+

{found.username}

+

IMVU ID {found.imvuId}

+
+ {found.accessPass ? Access Pass : No Access Pass} + {found.ageVerified ? Age verified : Not age verified} +
+
+
+ )} + {found && !found.accessPass && ( +

+ Without Access Pass, the importer can't see AP products, so it can't import them with this + account. +

+ )} +

+ The password is encrypted in this browser for your importer (key {shortFingerprint(fingerprint)} + {version ? `, version ${version}` : ""}) and kept only there. T5DE's hub never sees it. +

+ + }>Cancel + + +
+
+ + ); +} diff --git a/apps/web/app/console/catalogs/[id]/imports/page.tsx b/apps/web/app/console/catalogs/[id]/imports/page.tsx index 4637556..748c0f0 100644 --- a/apps/web/app/console/catalogs/[id]/imports/page.tsx +++ b/apps/web/app/console/catalogs/[id]/imports/page.tsx @@ -9,7 +9,9 @@ import { Input } from "@/components/ui/input"; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; import { api, unwrap, type ImportGrant } from "@/lib/api"; import { ConsoleNav, requireConsole } from "../../../console-nav"; -import { decideGrant, retryJob, setImporter } from "../../actions"; +import { shortFingerprint } from "@/lib/importer"; +import { changeImporterAccount, decideGrant, retryJob, setImporter, setImporterSettings } from "../../actions"; +import { ImporterAccountForm } from "./importer-account-form"; export const metadata: Metadata = { title: "Imports" }; @@ -27,6 +29,13 @@ const jobTone = { failed: "danger", done: "online", } as const; +const accountState = { + waiting: { tone: "neutral", label: "waiting for the importer" }, + received: { tone: "strong", label: "not tried yet" }, + ok: { tone: "online", label: "signed in" }, + sign_in_failed: { tone: "danger", label: "sign-in failed" }, + needs_password: { tone: "danger", label: "needs its password" }, +} as const; const imvuPage = (id: number) => `https://www.imvu.com/shop/product.php?products_id=${id}`; export default async function CatalogImports({ @@ -73,6 +82,19 @@ export default async function CatalogImports({ ? "With imports on, creators can bring their IMVU products here, and your importer (t5de-importer, run beside the catalog) imports what they allow." : `The importer signs in with the catalog's ID (${id}) and its importer key. ${data.counts.queued} queued, ${data.counts.claimed} working, ${data.counts.failed} failed, ${data.counts.done} done.`} + {data.importer !== "off" && ( +

+ {data.program.seenAt ? ( + <> + Importer {data.program.version || "(no version)"}, last heard from{" "} + + {data.program.fingerprint && <>, key {shortFingerprint(data.program.fingerprint)}}. + + ) : ( + "The importer hasn't connected yet." + )} +

+ )} {(can.run || can.pause) && ( @@ -126,6 +148,160 @@ export default async function CatalogImports({ )} + {data.importer !== "off" && ( + + + IMVU Accounts + + The importer signs in to IMVU with these, in this order, moving to the next when one fails. Without an + account it imports only what IMVU shows signed out; AP products need one with Access Pass. Passwords are + encrypted in your browser for the importer and kept only by it. + + + + {data.accounts.length > 0 && ( +
    + {data.accounts.map((a, i) => { + const st = accountState[a.state]; + return ( +
  1. +
    + {i + 1}. + {a.username} + (IMVU {a.imvuId}) + {st.label} + {a.accessPass ? Access Pass : No Access Pass} + {a.stateMessage && {a.stateMessage}} +
    + {can.run && ( +
    + +
    + {i > 0 && ( + + Up + + )} + {i < data.accounts.length - 1 && ( + + Down + + )} + + Remove + +
    +
    + {data.program.publicKey && data.program.fingerprint && ( +
    + + New password + +
    + +
    +
    + )} +
    + )} +
  2. + ); + })} +
+ )} + {can.run && + (!data.program.publicKey || !data.program.fingerprint ? ( +

+ Start the importer to add accounts: passwords are encrypted for its key, which it sends when it + connects. +

+ ) : data.accounts.length >= data.maxAccounts ? ( +

+ An importer can have at most {data.maxAccounts} accounts. +

+ ) : ( + + ))} + {!can.run && data.accounts.length === 0 &&

None yet.

} +
+
+ )} + + {data.importer !== "off" && ( + + + Importer Settings + The importer picks changes up within a minute. + + + +
+ + + {can.run && Save} +
+
+
+
+ )} + {pending.length > 0 && ( diff --git a/apps/web/app/console/catalogs/actions.ts b/apps/web/app/console/catalogs/actions.ts index 63da204..d0b8b5f 100644 --- a/apps/web/app/console/catalogs/actions.ts +++ b/apps/web/app/console/catalogs/actions.ts @@ -1,7 +1,7 @@ "use server"; // Managing a catalog from the console: settings, key, team, members, invitations, what it hosts, suspension. import { revalidatePath } from "next/cache"; -import { api, unwrap } from "@/lib/api"; +import { api, ApiError, unwrap } from "@/lib/api"; import { attempt, field, type ActionState } from "@/lib/actions"; /** Runs a change to a catalog, then shows its pages again. */ @@ -173,3 +173,89 @@ export async function retryJob(_: ActionState, form: FormData): Promise(fn: () => Promise): Promise<{ error: string } | { ok: T }> { + try { + return { ok: await fn() }; + } catch (e) { + if (e instanceof ApiError) return { error: e.message }; + throw e; + } +} + +/** Looks an IMVU account up for the confirmation dialog (public info only). */ +export async function lookupImporterAccount(id: string, username: string) { + return answered(async () => + unwrap(await api.catalogs({ id }).importer["imvu-account"].get({ query: { username: username.trim() } })), + ); +} + +/** + * Adds an account, or gives one a new password (account set). The password arrives sealed in the browser for the + * importer's key; it never passes through here readable. + */ +export async function saveImporterAccount( + id: string, + a: { imvuId: number; account?: string; sealed: string; fingerprint: string }, +) { + const r = await answered(async () => { + if (a.account) + unwrap( + await api + .catalogs({ id }) + .importer.accounts({ account: a.account }) + .password.put({ sealed: a.sealed, fingerprint: a.fingerprint }), + ); + else unwrap(await api.catalogs({ id }).importer.accounts.post({ imvuId: a.imvuId, sealed: a.sealed, fingerprint: a.fingerprint })); + return true; + }); + revalidatePath(`/console/catalogs/${id}/imports`); + return r; +} + +/** Moves an account up or down, or removes it. */ +export async function changeImporterAccount(_: ActionState, form: FormData): Promise { + const id = field(form, "id"); + const account = field(form, "account"); + return attempt(async () => { + const intent = field(form, "intent"); + if (intent === "remove") { + unwrap(await api.catalogs({ id }).importer.accounts({ account }).delete()); + revalidatePath(`/console/catalogs/${id}/imports`); + return "Removed. The importer forgets it within a minute."; + } + unwrap( + await api + .catalogs({ id }) + .importer.accounts({ account }) + .move.post({ direction: intent === "up" ? "up" : "down" }), + ); + revalidatePath(`/console/catalogs/${id}/imports`); + }); +} + +/** The importer's settings. */ +export async function setImporterSettings(_: ActionState, form: FormData): Promise { + const id = field(form, "id"); + return attempt(async () => { + unwrap( + await api.catalogs({ id }).importer.settings.post({ + rate: Number(field(form, "rate")), + concurrency: Number(field(form, "concurrency")), + }), + ); + revalidatePath(`/console/catalogs/${id}/imports`); + return "Saved. The importer picks it up within a minute."; + }); +} diff --git a/apps/web/components/ui/dialog.tsx b/apps/web/components/ui/dialog.tsx new file mode 100644 index 0000000..932b98c --- /dev/null +++ b/apps/web/components/ui/dialog.tsx @@ -0,0 +1,72 @@ +"use client" + +import * as React from "react" +import { Dialog as DialogPrimitive } from "@base-ui/react/dialog" +import { cn } from "cn" + +function Dialog(props: DialogPrimitive.Root.Props) { + return +} + +function DialogContent({ + className, + children, + ...props +}: DialogPrimitive.Popup.Props) { + return ( + + + + {children} + + + ) +} + +function DialogHeader({ className, ...props }: React.ComponentProps<"div">) { + return
+} + +function DialogFooter({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ) +} + +function DialogTitle({ className, ...props }: DialogPrimitive.Title.Props) { + return ( + + ) +} + +function DialogDescription({ className, ...props }: DialogPrimitive.Description.Props) { + return ( + + ) +} + +const DialogClose = DialogPrimitive.Close + +export { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } diff --git a/apps/web/lib/importer.ts b/apps/web/lib/importer.ts new file mode 100644 index 0000000..e6ef426 --- /dev/null +++ b/apps/web/lib/importer.ts @@ -0,0 +1,6 @@ +// Shared by the console's importer page and its client parts. + +/** The start of a key's fingerprint, for people to compare: "1a2b 3c4d 5e6f 7a8b". */ +export function shortFingerprint(hex: string): string { + return (hex.slice(0, 16).match(/.{4}/g) ?? []).join(" "); +} diff --git a/docs/imports.md b/docs/imports.md index be6f844..014397a 100644 --- a/docs/imports.md +++ b/docs/imports.md @@ -149,10 +149,15 @@ passwords never reach the hub readable, and are kept only by the importer. importer confirms it has it (or after 7 days). - Several accounts, in an order the team sets: the importer uses the first that signs in and moves to the next when one fails. It reports each account's state (`ok`, `sign_in_failed`, `needs_password`, plus whether IMVU shows it - Access Pass) with `POST /api/v1/importer/accounts/:id`, shown on the console. + Access Pass) with `POST /api/v1/importer/accounts/:id`, shown on the console. Before that an account is `waiting` + (sealed, not yet with the importer) or `received`. At most 10 accounts. - If the importer's key pair changes (a new install), passwords sealed for the old key can't be read: those accounts show "needs password" until re-entered. -- Removing an account tells the importer to forget it. Adding and removing are audited (`catalog.importer_account`). +- Removing an account tells the importer to forget it. Adding, new passwords and removing are audited + (`catalog.importer_account`), as are settings (`catalog.importer_settings`) and a new importer key pair + (`catalog.importer_hello`). +- Built (2026-11-07): all of the above on the hub and the console, except the importer's report of AP products' info + (with the importer). - What the importer sees with an account (creator, name, rating of AP products) it reports to the hub with the job (`POST /api/v1/importer/jobs/:id {product: {creatorId, name, rating}}`), trusted from that catalog's importer only, for products IMVU hides from the hub. @@ -173,6 +178,17 @@ passwords never reach the hub readable, and are kept only by the importer. | `POST /api/v1/catalogs/:id/importer` | `{enabled?}` (`import:run`; turning on returns the importer `key`, shown once) and `{paused?}` (`import:pause`) | | `POST /api/v1/catalogs/:id/importer/key` | (`import:run`) → `{key}`: a new importer key | | `POST /api/v1/catalogs/:id/importer/jobs/:job/retry` | (`import:run`) a failed or done job queued again | +| `GET /api/v1/catalogs/:id/importer/imvu-account?username=` | (`import:run`) `{imvuId, username, picture, accessPass, ageVerified}`: IMVU's public info, for the confirmation dialog | +| `POST /api/v1/catalogs/:id/importer/accounts` | (`import:run`) `{imvuId, sealed, fingerprint}` → 201 `{account}`. `fingerprint` must be the importer's key's (409 `importer_key_changed`; 409 `no_importer` before it has said hello); one per IMVU account (409 `exists`), at most 10. | +| `PUT /api/v1/catalogs/:id/importer/accounts/:account/password` | (`import:run`) `{sealed, fingerprint}`: a new password | +| `POST /api/v1/catalogs/:id/importer/accounts/:account/move` | (`import:run`) `{direction: "up" \| "down"}` | +| `DELETE /api/v1/catalogs/:id/importer/accounts/:account` | (`import:run`) | +| `POST /api/v1/catalogs/:id/importer/settings` | (`import:run`) `{rate (0.2-10 requests a second to IMVU), concurrency (1-8 jobs at once)}` | + +`GET /api/v1/catalogs/:id/importer` also has `program: {version, seenAt, fingerprint, publicKey}` (`publicKey` only +with `import:run`), `settings`, and `accounts: [{id, imvuId, username, state, stateMessage, stateAt, accessPass, +ageVerified}]` (state: `waiting` for the importer, `received`, `ok`, `sign_in_failed`, `needs_password`). Never a +password, sealed or not. For importers (`Authorization: Importer :`) in products.md. diff --git a/docs/products.md b/docs/products.md index 242628f..f0edbf3 100644 --- a/docs/products.md +++ b/docs/products.md @@ -85,6 +85,9 @@ catalog's). Only approved catalogs with imports on and not paused. | `POST /api/v1/importer/jobs/claim` | `{limit}` (1-20) → `{jobs: [{id, kind, imvuProduct, lastRevision}]}`; claimed jobs not reported within 30 minutes go back to the queue | | `POST /api/v1/importer/jobs/:id/token` | `{imvuRevision}` → `{token, url}`: a `t5de-import` token and the catalog's upload URL | | `POST /api/v1/importer/jobs/:id` | `{status: "done" \| "failed" \| "unchanged", imvuRevision?, reason?}` | +| `POST /api/v1/importer/hello` | `{version, publicKey}` (base64 SPKI, RSA 3072 to 4096 bits) → the config, as below. Sent at start. A new key means passwords sealed for the old one can't be read: the catalog's accounts then need their passwords again (imports.md "IMVU accounts"). | +| `GET /api/v1/importer/config` | `{paused, settings: {rate, concurrency}, fingerprint, accounts: [{id, imvuId, username, sealed}]}`, accounts in the order to try them. `sealed` (or null): `{imvuId, password}` as JSON, RSA-OAEP (SHA-256) for the importer's key, base64; check `imvuId`. Polled every minute; accounts no longer listed are forgotten. | +| `POST /api/v1/importer/accounts/:id` | `{received?, state? ("ok" \| "sign_in_failed" \| "needs_password"), accessPass?, message?}`: `received` once the password is stored (the hub drops its sealed copy), then how signing in went | ### For people (website, signed in; the proxy with its bearer token) diff --git a/packages/db/drizzle/0017_importer_accounts.sql b/packages/db/drizzle/0017_importer_accounts.sql new file mode 100644 index 0000000..6fd7412 --- /dev/null +++ b/packages/db/drizzle/0017_importer_accounts.sql @@ -0,0 +1,27 @@ +CREATE TABLE "importer_account" ( + "id" text PRIMARY KEY NOT NULL, + "catalog_id" text NOT NULL, + "imvu_id" bigint NOT NULL, + "username" text NOT NULL, + "position" integer NOT NULL, + "sealed" text, + "sealed_for" text, + "sealed_at" timestamp with time zone, + "state" text DEFAULT 'waiting' NOT NULL, + "state_message" text DEFAULT '' NOT NULL, + "state_at" timestamp with time zone DEFAULT now() NOT NULL, + "access_pass" boolean DEFAULT false NOT NULL, + "age_verified" boolean DEFAULT false NOT NULL, + "added_by" text, + "created_at" timestamp with time zone DEFAULT now() NOT NULL, + "updated_at" timestamp with time zone DEFAULT now() NOT NULL +); +--> statement-breakpoint +ALTER TABLE "catalog" ADD COLUMN "importer_public_key" text;--> statement-breakpoint +ALTER TABLE "catalog" ADD COLUMN "importer_fingerprint" text;--> statement-breakpoint +ALTER TABLE "catalog" ADD COLUMN "importer_version" text DEFAULT '' NOT NULL;--> statement-breakpoint +ALTER TABLE "catalog" ADD COLUMN "importer_seen_at" timestamp with time zone;--> statement-breakpoint +ALTER TABLE "catalog" ADD COLUMN "importer_settings" jsonb DEFAULT '{"rate":2,"concurrency":2}'::jsonb NOT NULL;--> statement-breakpoint +ALTER TABLE "importer_account" ADD CONSTRAINT "importer_account_catalog_id_catalog_id_fk" FOREIGN KEY ("catalog_id") REFERENCES "public"."catalog"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint +ALTER TABLE "importer_account" ADD CONSTRAINT "importer_account_added_by_user_id_fk" FOREIGN KEY ("added_by") REFERENCES "public"."user"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint +CREATE UNIQUE INDEX "importer_account_imvu" ON "importer_account" USING btree ("catalog_id","imvu_id"); \ No newline at end of file diff --git a/packages/db/drizzle/meta/0017_snapshot.json b/packages/db/drizzle/meta/0017_snapshot.json new file mode 100644 index 0000000..f5fd7d3 --- /dev/null +++ b/packages/db/drizzle/meta/0017_snapshot.json @@ -0,0 +1,4418 @@ +{ + "id": "0e71e01a-0c76-4670-98d7-2d57729543c8", + "prevId": "4a41c72b-7d55-4b2e-90a7-a49dcb2ead03", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.account": { + "name": "account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "account_id": { + "name": "account_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "provider_id": { + "name": "provider_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "access_token_expires_at": { + "name": "access_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "refresh_token_expires_at": { + "name": "refresh_token_expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "account_user": { + "name": "account_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "account_user_id_user_id_fk": { + "name": "account_user_id_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.age_check": { + "name": "age_check", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "method": { + "name": "method", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "over_eighteen": { + "name": "over_eighteen", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "provider_ref": { + "name": "provider_ref", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "age_check_user": { + "name": "age_check_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "age_check_imvu": { + "name": "age_check_imvu", + "columns": [ + { + "expression": "imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "age_check_provider_ref": { + "name": "age_check_provider_ref", + "columns": [ + { + "expression": "provider", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "provider_ref", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "age_check_user_id_user_id_fk": { + "name": "age_check_user_id_user_id_fk", + "tableFrom": "age_check", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.api_token": { + "name": "api_token", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "grants": { + "name": "grants", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "last_used_at": { + "name": "last_used_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "api_token_hash": { + "name": "api_token_hash", + "columns": [ + { + "expression": "hash", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "api_token_user": { + "name": "api_token_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "api_token_user_id_user_id_fk": { + "name": "api_token_user_id_user_id_fk", + "tableFrom": "api_token", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.audit": { + "name": "audit", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "at": { + "name": "at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "actor_id": { + "name": "actor_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "action": { + "name": "action", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "target": { + "name": "target", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "detail": { + "name": "detail", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + } + }, + "indexes": { + "audit_at": { + "name": "audit_at", + "columns": [ + { + "expression": "at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "audit_tags": { + "name": "audit_tags", + "columns": [ + { + "expression": "tags", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "audit_actor_id_user_id_fk": { + "name": "audit_actor_id_user_id_fk", + "tableFrom": "audit", + "tableTo": "user", + "columnsFrom": [ + "actor_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.case_note": { + "name": "case_note", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "case_id": { + "name": "case_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "by_id": { + "name": "by_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "body": { + "name": "body", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "internal": { + "name": "internal", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "case_note_case": { + "name": "case_note_case", + "columns": [ + { + "expression": "case_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "case_note_case_id_moderation_case_id_fk": { + "name": "case_note_case_id_moderation_case_id_fk", + "tableFrom": "case_note", + "tableTo": "moderation_case", + "columnsFrom": [ + "case_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "case_note_by_id_user_id_fk": { + "name": "case_note_by_id_user_id_fk", + "tableFrom": "case_note", + "tableTo": "user", + "columnsFrom": [ + "by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog": { + "name": "catalog", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "contact": { + "name": "contact", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "visibility": { + "name": "visibility", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "membership": { + "name": "membership", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "status_reason": { + "name": "status_reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "max_rating": { + "name": "max_rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'adult'" + }, + "uploads": { + "name": "uploads", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'anyone'" + }, + "mirrors": { + "name": "mirrors", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'approve'" + }, + "key_hash": { + "name": "key_hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "importer": { + "name": "importer", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'off'" + }, + "importer_key_hash": { + "name": "importer_key_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importer_public_key": { + "name": "importer_public_key", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importer_fingerprint": { + "name": "importer_fingerprint", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "importer_version": { + "name": "importer_version", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "importer_seen_at": { + "name": "importer_seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "importer_settings": { + "name": "importer_settings", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{\"rate\":2,\"concurrency\":2}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_url": { + "name": "catalog_url", + "columns": [ + { + "expression": "url", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_owner_id_user_id_fk": { + "name": "catalog_owner_id_user_id_fk", + "tableFrom": "catalog", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog_change": { + "name": "catalog_change", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_change_catalog": { + "name": "catalog_change_catalog", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_change_catalog_id_catalog_id_fk": { + "name": "catalog_change_catalog_id_catalog_id_fk", + "tableFrom": "catalog_change", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog_invite": { + "name": "catalog_invite", + "schema": "", + "columns": { + "code": { + "name": "code", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_by": { + "name": "created_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "max_uses": { + "name": "max_uses", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "uses": { + "name": "uses", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "revoked_at": { + "name": "revoked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_invite_catalog": { + "name": "catalog_invite_catalog", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_invite_catalog_id_catalog_id_fk": { + "name": "catalog_invite_catalog_id_catalog_id_fk", + "tableFrom": "catalog_invite", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_invite_created_by_user_id_fk": { + "name": "catalog_invite_created_by_user_id_fk", + "tableFrom": "catalog_invite", + "tableTo": "user", + "columnsFrom": [ + "created_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.catalog_member": { + "name": "catalog_member", + "schema": "", + "columns": { + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "invite": { + "name": "invite", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "catalog_member_user": { + "name": "catalog_member_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "catalog_member_catalog_id_catalog_id_fk": { + "name": "catalog_member_catalog_id_catalog_id_fk", + "tableFrom": "catalog_member", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_member_user_id_user_id_fk": { + "name": "catalog_member_user_id_user_id_fk", + "tableFrom": "catalog_member", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "catalog_member_decided_by_user_id_fk": { + "name": "catalog_member_decided_by_user_id_fk", + "tableFrom": "catalog_member", + "tableTo": "user", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "catalog_member_catalog_id_user_id_pk": { + "name": "catalog_member_catalog_id_user_id_pk", + "columns": [ + "catalog_id", + "user_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.device_code": { + "name": "device_code", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "device_code": { + "name": "device_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_code": { + "name": "user_code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "last_polled_at": { + "name": "last_polled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "polling_interval": { + "name": "polling_interval", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "client_id": { + "name": "client_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "device_code_user_id_user_id_fk": { + "name": "device_code_user_id_user_id_fk", + "tableFrom": "device_code", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.file_block": { + "name": "file_block", + "schema": "", + "columns": { + "sha256": { + "name": "sha256", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "by_id": { + "name": "by_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "file_block_by_id_user_id_fk": { + "name": "file_block_by_id_user_id_fk", + "tableFrom": "file_block", + "tableTo": "user", + "columnsFrom": [ + "by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room": { + "name": "hosted_room", + "schema": "", + "columns": { + "n": { + "name": "n", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "owner_id": { + "name": "owner_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "owner_imvu_id": { + "name": "owner_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "room_pid": { + "name": "room_pid", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'general'" + }, + "max_users": { + "name": "max_users", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "scene": { + "name": "scene", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "scene_hash": { + "name": "scene_hash", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "closed": { + "name": "closed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "privacy": { + "name": "privacy", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'public'" + }, + "moderators": { + "name": "moderators", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "image_hash": { + "name": "image_hash", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosted_room_owner": { + "name": "hosted_room_owner", + "columns": [ + { + "expression": "owner_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "hosted_room_created": { + "name": "hosted_room_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosted_room_owner_id_user_id_fk": { + "name": "hosted_room_owner_id_user_id_fk", + "tableFrom": "hosted_room", + "tableTo": "user", + "columnsFrom": [ + "owner_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_ban": { + "name": "hosted_room_ban", + "schema": "", + "columns": { + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "by_imvu_id": { + "name": "by_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "until": { + "name": "until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "hosted_room_ban_n_hosted_room_n_fk": { + "name": "hosted_room_ban_n_hosted_room_n_fk", + "tableFrom": "hosted_room_ban", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_ban_n_imvu_id_pk": { + "name": "hosted_room_ban_n_imvu_id_pk", + "columns": [ + "n", + "imvu_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_favorite": { + "name": "hosted_room_favorite", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "hosted_room_favorite_user_id_user_id_fk": { + "name": "hosted_room_favorite_user_id_user_id_fk", + "tableFrom": "hosted_room_favorite", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "hosted_room_favorite_n_hosted_room_n_fk": { + "name": "hosted_room_favorite_n_hosted_room_n_fk", + "tableFrom": "hosted_room_favorite", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_favorite_user_id_n_pk": { + "name": "hosted_room_favorite_user_id_n_pk", + "columns": [ + "user_id", + "n" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_image": { + "name": "hosted_room_image", + "schema": "", + "columns": { + "n": { + "name": "n", + "type": "integer", + "primaryKey": true, + "notNull": true + }, + "content_type": { + "name": "content_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "data": { + "name": "data", + "type": "bytea", + "primaryKey": false, + "notNull": true + }, + "hash": { + "name": "hash", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "hosted_room_image_n_hosted_room_n_fk": { + "name": "hosted_room_image_n_hosted_room_n_fk", + "tableFrom": "hosted_room_image", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_rating": { + "name": "hosted_room_rating", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosted_room_rating_room": { + "name": "hosted_room_rating_room", + "columns": [ + { + "expression": "n", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosted_room_rating_user_id_user_id_fk": { + "name": "hosted_room_rating_user_id_user_id_fk", + "tableFrom": "hosted_room_rating", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "hosted_room_rating_n_hosted_room_n_fk": { + "name": "hosted_room_rating_n_hosted_room_n_fk", + "tableFrom": "hosted_room_rating", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_rating_user_id_n_pk": { + "name": "hosted_room_rating_user_id_n_pk", + "columns": [ + "user_id", + "n" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosted_room_visit": { + "name": "hosted_room_visit", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "n": { + "name": "n", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "at": { + "name": "at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosted_room_visit_at": { + "name": "hosted_room_visit_at", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosted_room_visit_user_id_user_id_fk": { + "name": "hosted_room_visit_user_id_user_id_fk", + "tableFrom": "hosted_room_visit", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "hosted_room_visit_n_hosted_room_n_fk": { + "name": "hosted_room_visit_n_hosted_room_n_fk", + "tableFrom": "hosted_room_visit", + "tableTo": "hosted_room", + "columnsFrom": [ + "n" + ], + "columnsTo": [ + "n" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosted_room_visit_user_id_n_pk": { + "name": "hosted_room_visit_user_id_n_pk", + "columns": [ + "user_id", + "n" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hosting": { + "name": "hosting", + "schema": "", + "columns": { + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "hosting_product": { + "name": "hosting_product", + "columns": [ + { + "expression": "product_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "hosting_catalog_id_catalog_id_fk": { + "name": "hosting_catalog_id_catalog_id_fk", + "tableFrom": "hosting", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "hosting_catalog_id_product_id_number_pk": { + "name": "hosting_catalog_id_product_id_number_pk", + "columns": [ + "catalog_id", + "product_id", + "number" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.hub_setting": { + "name": "hub_setting", + "schema": "", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.import_grant": { + "name": "import_grant", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "products": { + "name": "products", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "exclude": { + "name": "exclude", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "listed": { + "name": "listed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "consent_version": { + "name": "consent_version", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "consented_at": { + "name": "consented_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "consent_kind": { + "name": "consent_kind", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'verified'" + }, + "evidence": { + "name": "evidence", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "recorded_by": { + "name": "recorded_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'pending'" + }, + "status_reason": { + "name": "status_reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "decided_by": { + "name": "decided_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "import_grant_catalog": { + "name": "import_grant_catalog", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "import_grant_imvu": { + "name": "import_grant_imvu", + "columns": [ + { + "expression": "imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "import_grant_catalog_id_catalog_id_fk": { + "name": "import_grant_catalog_id_catalog_id_fk", + "tableFrom": "import_grant", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "import_grant_creator_id_user_id_fk": { + "name": "import_grant_creator_id_user_id_fk", + "tableFrom": "import_grant", + "tableTo": "user", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "import_grant_recorded_by_user_id_fk": { + "name": "import_grant_recorded_by_user_id_fk", + "tableFrom": "import_grant", + "tableTo": "user", + "columnsFrom": [ + "recorded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "import_grant_decided_by_user_id_fk": { + "name": "import_grant_decided_by_user_id_fk", + "tableFrom": "import_grant", + "tableTo": "user", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.import_job": { + "name": "import_job", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "grant_id": { + "name": "grant_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_product": { + "name": "imvu_product", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'queued'" + }, + "imvu_revision": { + "name": "imvu_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "attempts": { + "name": "attempts", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "claimed_at": { + "name": "claimed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "next_at": { + "name": "next_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "import_job_queue": { + "name": "import_job_queue", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "next_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "import_job_open": { + "name": "import_job_open", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "imvu_product", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "where": "\"import_job\".\"status\" in ('queued', 'claimed')", + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "import_job_catalog_id_catalog_id_fk": { + "name": "import_job_catalog_id_catalog_id_fk", + "tableFrom": "import_job", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "import_job_grant_id_import_grant_id_fk": { + "name": "import_job_grant_id_import_grant_id_fk", + "tableFrom": "import_job", + "tableTo": "import_grant", + "columnsFrom": [ + "grant_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.import_request": { + "name": "import_request", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_creator": { + "name": "imvu_creator", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "imvu_product": { + "name": "imvu_product", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "fulfilled_at": { + "name": "fulfilled_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "import_request_creator": { + "name": "import_request_creator", + "columns": [ + { + "expression": "imvu_creator", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "import_request_product": { + "name": "import_request_product", + "columns": [ + { + "expression": "imvu_product", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "import_request_user_id_user_id_fk": { + "name": "import_request_user_id_user_id_fk", + "tableFrom": "import_request", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "import_request_user_id_imvu_creator_imvu_product_pk": { + "name": "import_request_user_id_imvu_creator_imvu_product_pk", + "columns": [ + "user_id", + "imvu_creator", + "imvu_product" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.importer_account": { + "name": "importer_account", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "catalog_id": { + "name": "catalog_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "position": { + "name": "position", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "sealed": { + "name": "sealed", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sealed_for": { + "name": "sealed_for", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "sealed_at": { + "name": "sealed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'waiting'" + }, + "state_message": { + "name": "state_message", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "state_at": { + "name": "state_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "access_pass": { + "name": "access_pass", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "age_verified": { + "name": "age_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "added_by": { + "name": "added_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "importer_account_imvu": { + "name": "importer_account_imvu", + "columns": [ + { + "expression": "catalog_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "importer_account_catalog_id_catalog_id_fk": { + "name": "importer_account_catalog_id_catalog_id_fk", + "tableFrom": "importer_account", + "tableTo": "catalog", + "columnsFrom": [ + "catalog_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "importer_account_added_by_user_id_fk": { + "name": "importer_account_added_by_user_id_fk", + "tableFrom": "importer_account", + "tableTo": "user", + "columnsFrom": [ + "added_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.imvu_link": { + "name": "imvu_link", + "schema": "", + "columns": { + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "pairwise_id": { + "name": "pairwise_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "linked_at": { + "name": "linked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "show_badge": { + "name": "show_badge", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "show_presence": { + "name": "show_presence", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "list_rooms": { + "name": "list_rooms", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "imvu_link_user": { + "name": "imvu_link_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "imvu_link_user_id_user_id_fk": { + "name": "imvu_link_user_id_user_id_fk", + "tableFrom": "imvu_link", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "imvu_link_pairwise_id_unique": { + "name": "imvu_link_pairwise_id_unique", + "nullsNotDistinct": false, + "columns": [ + "pairwise_id" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.imvu_product_info": { + "name": "imvu_product_info", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "bigint", + "primaryKey": true, + "notNull": true + }, + "found": { + "name": "found", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "creator_id": { + "name": "creator_id", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "creator_name": { + "name": "creator_name", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'general'" + }, + "purchasable": { + "name": "purchasable", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.jwks": { + "name": "jwks", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "alg": { + "name": "alg", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "crv": { + "name": "crv", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.library": { + "name": "library", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "stay_on": { + "name": "stay_on", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "added_at": { + "name": "added_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "library_user_id_user_id_fk": { + "name": "library_user_id_user_id_fk", + "tableFrom": "library", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "library_product_id_product_id_fk": { + "name": "library_product_id_product_id_fk", + "tableFrom": "library", + "tableTo": "product", + "columnsFrom": [ + "product_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "library_user_id_product_id_pk": { + "name": "library_user_id_product_id_pk", + "columns": [ + "user_id", + "product_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.link_challenge": { + "name": "link_challenge", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "imvu_id": { + "name": "imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "link_challenge_user_id_user_id_fk": { + "name": "link_challenge_user_id_user_id_fk", + "tableFrom": "link_challenge", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "link_challenge_user_id_imvu_id_pk": { + "name": "link_challenge_user_id_imvu_id_pk", + "columns": [ + "user_id", + "imvu_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.moderation_case": { + "name": "moderation_case", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'open'" + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "opened_by": { + "name": "opened_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "assignee": { + "name": "assignee", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "resolution": { + "name": "resolution", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "decided_by": { + "name": "decided_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "decided_at": { + "name": "decided_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "moderation_case_status": { + "name": "moderation_case_status", + "columns": [ + { + "expression": "status", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "moderation_case_opened_by": { + "name": "moderation_case_opened_by", + "columns": [ + { + "expression": "opened_by", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "moderation_case_tags": { + "name": "moderation_case_tags", + "columns": [ + { + "expression": "tags", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "moderation_case_opened_by_user_id_fk": { + "name": "moderation_case_opened_by_user_id_fk", + "tableFrom": "moderation_case", + "tableTo": "user", + "columnsFrom": [ + "opened_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "moderation_case_assignee_user_id_fk": { + "name": "moderation_case_assignee_user_id_fk", + "tableFrom": "moderation_case", + "tableTo": "user", + "columnsFrom": [ + "assignee" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + }, + "moderation_case_decided_by_user_id_fk": { + "name": "moderation_case_decided_by_user_id_fk", + "tableFrom": "moderation_case", + "tableTo": "user", + "columnsFrom": [ + "decided_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.notification": { + "name": "notification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "data": { + "name": "data", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'{}'::jsonb" + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "read_at": { + "name": "read_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "notification_user": { + "name": "notification_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "notification_user_id_user_id_fk": { + "name": "notification_user_id_user_id_fk", + "tableFrom": "notification", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product": { + "name": "product", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "creator_id": { + "name": "creator_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "latest": { + "name": "latest", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "status": { + "name": "status", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'published'" + }, + "published_at": { + "name": "published_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "listed": { + "name": "listed", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "tags": { + "name": "tags", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "category": { + "name": "category", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "locked": { + "name": "locked", + "type": "jsonb", + "primaryKey": false, + "notNull": true, + "default": "'[]'::jsonb" + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "removed_at": { + "name": "removed_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "removed_reason": { + "name": "removed_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "imvu_product": { + "name": "imvu_product", + "type": "bigint", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_imvu_product": { + "name": "product_imvu_product", + "columns": [ + { + "expression": "imvu_product", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + }, + "product_creator": { + "name": "product_creator", + "columns": [ + { + "expression": "creator_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "product_created": { + "name": "product_created", + "columns": [ + { + "expression": "created_at", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "product_tags": { + "name": "product_tags", + "columns": [ + { + "expression": "tags", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "product_creator_id_user_id_fk": { + "name": "product_creator_id_user_id_fk", + "tableFrom": "product", + "tableTo": "user", + "columnsFrom": [ + "creator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "restrict", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product_info_change": { + "name": "product_info_change", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "by_id": { + "name": "by_id", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "kind": { + "name": "kind", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "changes": { + "name": "changes", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "reason": { + "name": "reason", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "revert_of": { + "name": "revert_of", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_info_change_product": { + "name": "product_info_change_product", + "columns": [ + { + "expression": "product_id", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "product_info_change_product_id_product_id_fk": { + "name": "product_info_change_product_id_product_id_fk", + "tableFrom": "product_info_change", + "tableTo": "product", + "columnsFrom": [ + "product_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "product_info_change_by_id_user_id_fk": { + "name": "product_info_change_by_id_user_id_fk", + "tableFrom": "product_info_change", + "tableTo": "user", + "columnsFrom": [ + "by_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.product_revision": { + "name": "product_revision", + "schema": "", + "columns": { + "product_id": { + "name": "product_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "number": { + "name": "number", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "files": { + "name": "files", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "rating": { + "name": "rating", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "parent": { + "name": "parent", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "parent_info": { + "name": "parent_info", + "type": "jsonb", + "primaryKey": false, + "notNull": false + }, + "notes": { + "name": "notes", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "uploaded_by": { + "name": "uploaded_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "retracted": { + "name": "retracted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "imvu_revision": { + "name": "imvu_revision", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "product_revision_files": { + "name": "product_revision_files", + "columns": [ + { + "expression": "files", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "gin", + "with": {} + } + }, + "foreignKeys": { + "product_revision_product_id_product_id_fk": { + "name": "product_revision_product_id_product_id_fk", + "tableFrom": "product_revision", + "tableTo": "product", + "columnsFrom": [ + "product_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "product_revision_uploaded_by_user_id_fk": { + "name": "product_revision_uploaded_by_user_id_fk", + "tableFrom": "product_revision", + "tableTo": "user", + "columnsFrom": [ + "uploaded_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "product_revision_product_id_number_pk": { + "name": "product_revision_product_id_number_pk", + "columns": [ + "product_id", + "number" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.role_assignment": { + "name": "role_assignment", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope_type": { + "name": "scope_type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "scope_id": { + "name": "scope_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "granted_by": { + "name": "granted_by", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "role_assignment_scope": { + "name": "role_assignment_scope", + "columns": [ + { + "expression": "scope_type", + "isExpression": false, + "asc": true, + "nulls": "last" + }, + { + "expression": "scope_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "role_assignment_user_id_user_id_fk": { + "name": "role_assignment_user_id_user_id_fk", + "tableFrom": "role_assignment", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "role_assignment_granted_by_user_id_fk": { + "name": "role_assignment_granted_by_user_id_fk", + "tableFrom": "role_assignment", + "tableTo": "user", + "columnsFrom": [ + "granted_by" + ], + "columnsTo": [ + "id" + ], + "onDelete": "set null", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "role_assignment_user_id_role_scope_type_scope_id_pk": { + "name": "role_assignment_user_id_role_scope_type_scope_id_pk", + "columns": [ + "user_id", + "role", + "scope_type", + "scope_id" + ] + } + }, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.room": { + "name": "room", + "schema": "", + "columns": { + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_imvu_id": { + "name": "owner_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "image_url": { + "name": "image_url", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "privacy": { + "name": "privacy", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "content_rating": { + "name": "content_rating", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "''" + }, + "access_pass": { + "name": "access_pass", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "occupancy": { + "name": "occupancy", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "capacity": { + "name": "capacity", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "expired": { + "name": "expired", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "checked_at": { + "name": "checked_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "seen_at": { + "name": "seen_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "room_owner": { + "name": "room_owner", + "columns": [ + { + "expression": "owner_imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.room_decoration": { + "name": "room_decoration", + "schema": "", + "columns": { + "instance_id": { + "name": "instance_id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "owner_imvu_id": { + "name": "owner_imvu_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "contents": { + "name": "contents", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "room_decoration_owner": { + "name": "room_decoration_owner", + "columns": [ + { + "expression": "owner_imvu_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.session": { + "name": "session", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "ip_address": { + "name": "ip_address", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_agent": { + "name": "user_agent", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "impersonated_by": { + "name": "impersonated_by", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "session_user": { + "name": "session_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "session_user_id_user_id_fk": { + "name": "session_user_id_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "session_token_unique": { + "name": "session_token_unique", + "nullsNotDistinct": false, + "columns": [ + "token" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.signing_key": { + "name": "signing_key", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "public_key": { + "name": "public_key", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "private_key": { + "name": "private_key", + "type": "jsonb", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.two_factor": { + "name": "two_factor", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "secret": { + "name": "secret", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "backup_codes": { + "name": "backup_codes", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "verified": { + "name": "verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "failed_verification_count": { + "name": "failed_verification_count", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "locked_until": { + "name": "locked_until", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + } + }, + "indexes": { + "two_factor_user": { + "name": "two_factor_user", + "columns": [ + { + "expression": "user_id", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + }, + "two_factor_secret": { + "name": "two_factor_secret", + "columns": [ + { + "expression": "secret", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": { + "two_factor_user_id_user_id_fk": { + "name": "two_factor_user_id_user_id_fk", + "tableFrom": "two_factor", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "email_verified": { + "name": "email_verified", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "username": { + "name": "username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "display_username": { + "name": "display_username", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'user'" + }, + "banned": { + "name": "banned", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "ban_reason": { + "name": "ban_reason", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "ban_expires": { + "name": "ban_expires", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": false + }, + "link_cap": { + "name": "link_cap", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 10 + }, + "approved": { + "name": "approved", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "two_factor_enabled": { + "name": "two_factor_enabled", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + } + }, + "indexes": { + "user_username_lower": { + "name": "user_username_lower", + "columns": [ + { + "expression": "lower(\"username\")", + "asc": true, + "isExpression": true, + "nulls": "last" + } + ], + "isUnique": true, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + }, + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + } + }, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + }, + "public.verification": { + "name": "verification", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "expires_at": { + "name": "expires_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": { + "verification_identifier": { + "name": "verification_identifier", + "columns": [ + { + "expression": "identifier", + "isExpression": false, + "asc": true, + "nulls": "last" + } + ], + "isUnique": false, + "concurrently": false, + "method": "btree", + "with": {} + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {}, + "policies": {}, + "checkConstraints": {}, + "isRLSEnabled": false + } + }, + "enums": {}, + "schemas": {}, + "sequences": {}, + "roles": {}, + "policies": {}, + "views": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/packages/db/drizzle/meta/_journal.json b/packages/db/drizzle/meta/_journal.json index 15a11f5..ad76fd6 100644 --- a/packages/db/drizzle/meta/_journal.json +++ b/packages/db/drizzle/meta/_journal.json @@ -120,6 +120,13 @@ "when": 1793935614967, "tag": "0016_imports", "breakpoints": true + }, + { + "idx": 17, + "version": "7", + "when": 1794073227716, + "tag": "0017_importer_accounts", + "breakpoints": true } ] } \ No newline at end of file diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index df8593d..5f5c0af 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -11,7 +11,7 @@ import { fileURLToPath } from "node:url"; import * as schema from "./schema"; export { schema }; -export type { AuditTags, DecorationItem, FileEntry, InfoChange, ParentInfo, RoomModerator, SceneItem, TokenGrant } from "./schema"; +export type { AuditTags, DecorationItem, FileEntry, ImporterSettings, InfoChange, ParentInfo, RoomModerator, SceneItem, TokenGrant } from "./schema"; export * from "drizzle-orm"; const migrationsFolder = fileURLToPath(new URL("../drizzle", import.meta.url)); diff --git a/packages/db/src/schema.ts b/packages/db/src/schema.ts index 2c9fcf2..b53e5e5 100644 --- a/packages/db/src/schema.ts +++ b/packages/db/src/schema.ts @@ -292,6 +292,14 @@ export const catalog = pgTable( // Imports (docs/imports.md): "off", "on" or "paused" (the hub hands its importer no jobs); the importer's key. importer: text("importer").notNull().default("off"), importerKeyHash: text("importer_key_hash"), // sha256, hex + // The importer program (docs/imports.md "IMVU accounts"): its RSA public key (SPKI, base64) that IMVU passwords + // are sealed for, the key's fingerprint (sha256 of the SPKI, hex), its version, when it last called, and its + // settings, set on the console. + importerPublicKey: text("importer_public_key"), + importerFingerprint: text("importer_fingerprint"), + importerVersion: text("importer_version").notNull().default(""), + importerSeenAt: timestamp("importer_seen_at", { withTimezone: true }), + importerSettings: jsonb("importer_settings").$type().notNull().default({ rate: 2, concurrency: 2 }), createdAt: createdAt(), updatedAt: updatedAt(), }, @@ -800,6 +808,38 @@ export const importJob = pgTable( ], ); +/** An importer's settings: requests a second to IMVU, and jobs worked on at once. */ +export type ImporterSettings = { rate: number; concurrency: number }; + +// An IMVU account a catalog's importer signs in with (docs/imports.md "IMVU accounts"). Its password is never stored +// readable: the console seals it in the browser for the importer's public key, and the hub keeps that sealed copy +// only until the importer has it. +export const importerAccount = pgTable( + "importer_account", + { + id: text("id").primaryKey(), + catalogId: text("catalog_id") + .notNull() + .references(() => catalog.id, { onDelete: "cascade" }), + imvuId: bigint("imvu_id", { mode: "number" }).notNull(), + username: text("username").notNull(), + position: integer("position").notNull(), // the importer tries accounts in this order + sealed: text("sealed"), // the password sealed for the importer (RSA-OAEP, base64), until it has it + sealedFor: text("sealed_for"), // the fingerprint of the key it was sealed for + sealedAt: timestamp("sealed_at", { withTimezone: true }), + // "waiting" (sealed, not yet with the importer), "received", "ok", "sign_in_failed", "needs_password" + state: text("state").notNull().default("waiting"), + stateMessage: text("state_message").notNull().default(""), + stateAt: timestamp("state_at", { withTimezone: true }).notNull().defaultNow(), + accessPass: boolean("access_pass").notNull().default(false), // as IMVU shows it (the importer's report wins) + ageVerified: boolean("age_verified").notNull().default(false), + addedBy: text("added_by").references(() => user.id, { onDelete: "set null" }), + createdAt: createdAt(), + updatedAt: updatedAt(), + }, + (t) => [uniqueIndex("importer_account_imvu").on(t.catalogId, t.imvuId)], +); + // IMVU products' public info, as imports and requests need it (looked up again after a day). export const imvuProductInfo = pgTable("imvu_product_info", { id: bigint("id", { mode: "number" }).primaryKey(),