feat: recorded import grants, unclaimed creators and claiming (#15)
Release / release (push) Successful in 3s
CI / test (push) Successful in 1m24s
CI / image (apps/api/Dockerfile, t5de-hub-api) (push) Successful in 7s
CI / image (apps/web/Dockerfile, t5de-hub-web) (push) Successful in 13s

Co-authored-by: dhkatz <[email protected]>
This commit was merged in pull request #15.
This commit is contained in:
dhkatz authored and dhkatz committed 2026-11-07 22:49:06 +00:00
1 parent e6a97be894
commit 8f6dacba10
18 files changed
+5222 -26

No files matched your search

+92 -2
View File
@@ -401,6 +401,7 @@ export function createApp({
exclude: r.grant.exclude,
listed: r.grant.listed,
consentKind: r.grant.consentKind as "verified" | "recorded",
consentProven: r.grant.proofCheckedAt !== null, // recorded, and the creator put the code in their tagline
consentVersion: r.grant.consentVersion,
status: r.grant.status as "pending" | "active" | "declined" | "suspended" | "withdrawn",
statusReason: r.grant.statusReason,
@@ -498,7 +499,7 @@ export function createApp({
url: `${(webURL ?? "").replace(/\/+$/, "")}/catalogs/${i.catalogId}?invite=${i.code}`,
});
type ConsoleSection = "overview" | "products" | "catalogs" | "cases" | "people" | "blocks" | "audit" | "settings";
type ConsoleSection = "overview" | "products" | "catalogs" | "cases" | "people" | "imports" | "blocks" | "audit" | "settings";
/** Tokens as their owner sees them (never the hash), with their scopes' names. */
const tokenViews = async (rows: (typeof schema.apiToken.$inferSelect)[]) => {
@@ -1026,10 +1027,21 @@ export function createApp({
canLink: links.length < me.linkCap,
// Two-factor sign-in: on or off, and what needs it (sensitive permissions the person holds).
twoFactor: { enabled: me.twoFactorEnabled, neededFor: await sensitiveHeld(me) },
// Unclaimed creators for IMVU accounts they've linked: what an admin recorded for them, theirs to claim.
claims: (await imports.claimable(me.id)).map((c) => ({ imvuId: c.imvuId!, username: c.username ?? "", products: c.products, grants: c.grants })),
};
},
{ signedIn: true },
)
.post(
"/account/claims/:imvu",
async ({ me, params }) => {
const r = await productCall(() => imports.claimCreator(me.id, params.imvu));
await audited(me, "import.claim", String(params.imvu), r, { person: me.id });
return r;
},
{ scripted: true, params: imvuIdParam },
)
.post(
"/account/links",
async ({ me, body, set }) => {
@@ -1984,6 +1996,79 @@ export function createApp({
},
)
// Recorded grants (docs/imports.md): admins record consent for creators who won't make an account.
.get(
"/console/imports",
async ({ me }) => {
if (!(await perms.can(me, "import:grant-on-behalf", hubScope))) throw new Problem(403, "forbidden", "Not yours to see.");
const rows = await imports.recordedGrants();
return {
grants: rows.map((r) => ({
...grantView(r),
evidence: r.grant.evidence,
recordedBy: r.recordedByName ?? "",
proofCode: r.grant.proofCode,
proofCheckedAt: r.grant.proofCheckedAt?.toISOString() ?? null,
claimed: r.claimed,
})),
creators: await imports.topRequested(),
catalogs: await imports.catalogs(),
consent,
};
},
{ signedIn: true },
)
.post(
"/console/imports/grants",
async ({ me, body, set }) => {
await need(me, "import:grant-on-behalf", hubScope);
const who = body.imvu.trim();
const found = await imvuCall(me, () => (/^\d{1,12}$/.test(who) ? imvu.byId(Number(who)) : imvu.byUsername(who)));
const g = await productCall(() => imports.recordGrant(me.id, found, body));
await audited(
me,
"import.grant_record",
g.id,
{ imvu: g.imvuId, imvuName: found.username, scope: g.scope, products: g.products.length, evidence: g.evidence },
{ catalog: g.catalogId, person: g.creatorId },
);
set.status = 201;
return { grant: grantView({ grant: g, imvuName: found.username }) };
},
{
scripted: true,
body: t.Object({
catalog: t.String({ maxLength: 20 }),
imvu: t.String({ minLength: 1, maxLength: 64 }),
scope: t.String({ maxLength: 20 }),
products: t.Optional(t.Array(t.Integer({ minimum: 1 }), { maxItems: 1000 })),
exclude: t.Optional(t.Array(t.Integer({ minimum: 1 }), { maxItems: 1000 })),
listed: t.Optional(t.Boolean()),
evidence: t.String({ maxLength: 1000 }),
}),
},
)
.post(
"/console/imports/grants/:id/proof",
async ({ me, params }) => {
await need(me, "import:grant-on-behalf", hubScope);
return { code: await productCall(() => imports.proofCode(params.id, linkCode())) };
},
{ scripted: true },
)
.post(
"/console/imports/grants/:id/proof/check",
async ({ me, params }) => {
await need(me, "import:grant-on-behalf", hubScope);
const g = await productCall(() => imports.grant(params.id));
const found = await imvuCall(me, () => imvu.byId(g.imvuId));
const checked = await productCall(() => imports.checkProof(g.id, found.tagline));
await audited(me, "import.grant_proof", g.id, { imvu: g.imvuId }, { catalog: g.catalogId, person: g.creatorId });
return { grant: grantView({ grant: checked, imvuName: found.username }) };
},
{ scripted: true },
)
// 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 })
@@ -2012,7 +2097,11 @@ export function createApp({
"/imports/grants/:id",
async ({ me, params, body }) => {
const g = await productCall(() => imports.grant(params.id));
if (g.creatorId !== me.id) throw new Problem(403, "forbidden", "Only its creator changes a grant.");
if (g.creatorId !== me.id) {
// A recorded grant's creator hasn't claimed it: admins change it for them.
if (!(await imports.unclaimed(g))) throw new Problem(403, "forbidden", "Only its creator changes a grant.");
await need(me, "import:grant-on-behalf", hubScope);
}
const { grant, withdrawn } = await productCall(() => imports.updateGrant(g.id, body));
await audited(
me,
@@ -3122,6 +3211,7 @@ export function createApp({
if (mod || scope.catalogs.length || scope.products.length || (await cases.list(me, { limit: 1 })).length)
sections.push("cases");
if (mod) sections.push("people");
if (await perms.can(me, "import:grant-on-behalf", hubScope)) sections.push("imports");
if (await perms.can(me, "product:remove", hubScope)) sections.push("blocks");
if (sections.length > 1 || scope.rooms.length) sections.push("audit");
if (me.role === "admin") sections.push("settings");