feat: importer IMVU accounts and settings from the console (#14)
Release / release (push) Successful in 4s
CI / test (push) Successful in 1m25s
CI / image (apps/api/Dockerfile, t5de-hub-api) (push) Successful in 6s
CI / image (apps/web/Dockerfile, t5de-hub-web) (push) Successful in 14s

Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #14.
This commit is contained in:
dhkatz authored and dhkatz committed 2026-11-07 19:00:01 +00:00
1 parent 7ece681eef
commit e6a97be894
16 files changed
+5538 -13

No files matched your search

+143 -2
View File
@@ -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<typeof createApp>["app"];