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

+1 -1
View File
@@ -302,7 +302,7 @@ test("the console is for everyone who controls something; its audit log shows on
expect(ownerConsole.sections).toEqual(["overview", "catalogs", "cases", "audit"]);
expect(ownerConsole.moderation).toBeNull();
expect((await call(maker, "GET", "/api/v1/console")).json.sections).toEqual(["overview", "products", "cases", "audit"]);
expect((await call(admin, "GET", "/api/v1/console")).json.sections).toEqual(["overview", "products", "catalogs", "cases", "people", "blocks", "audit", "settings"]);
expect((await call(admin, "GET", "/api/v1/console")).json.sections).toEqual(["overview", "products", "catalogs", "cases", "people", "imports", "blocks", "audit", "settings"]);
// The owner sees their catalog's entries, not the other catalog's; the maker sees their product's.
const ownerLog = (await call(owner, "GET", "/api/v1/console/audit")).json.entries;
+84
View File
@@ -314,3 +314,87 @@ test("the importer's key, IMVU accounts with sealed passwords, and settings", as
// Passwords never show on the console.
expect(JSON.stringify(await page())).not.toContain(sealed);
});
test("recorded grants, unclaimed creators, proof, and claiming", async () => {
const admin = rootAdmin;
const owner = await person("shelver");
const fan = await person("fanatic");
accounts.set(701, { id: 701, username: "QuietMaker", tagline: "", ageVerified: false, accessPass: false, picture: null });
imvuProducts.set(9201, imvuProduct("Quiet Coat", 701));
imvuProducts.set(9202, imvuProduct("Quiet Hat", 701));
const reg = await call(owner, "POST", "/api/v1/catalogs", { name: "Recorded Shelf", url: "https://recorded.example.test", contact: "[email protected]", visibility: "public", membership: "open" });
const catalogID = reg.json.catalog.id as string;
const catalogAuth = { Authorization: `Catalog ${catalogID}:${reg.json.key}` };
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}` };
// Only those who may grant on behalf record; evidence is required; creators on T5DE grant themselves.
const body = { catalog: catalogID, imvu: "QuietMaker", scope: "shop", exclude: [9202], evidence: "Discord DM, 2026-11-07" };
expect((await call(owner, "POST", "/api/v1/console/imports/grants", body)).status).toBe(403);
expect((await call(owner, "GET", "/api/v1/console/imports")).status).toBe(403);
expect((await call(admin, "POST", "/api/v1/console/imports/grants", { ...body, evidence: " " })).json.error).toBe("invalid");
await person("onhub", 801); // a creator on T5DE, with their IMVU account linked
expect((await call(admin, "POST", "/api/v1/console/imports/grants", { ...body, imvu: "801" })).json.error).toBe("linked");
const recorded = await call(admin, "POST", "/api/v1/console/imports/grants", body);
expect(recorded.status).toBe(201);
expect(recorded.json.grant).toMatchObject({ status: "pending", consentKind: "recorded", consentProven: false, imvuName: "QuietMaker" });
const grantID = recorded.json.grant.id as string;
expect((await call(admin, "POST", "/api/v1/console/imports/grants", body)).json.error).toBe("exists");
// The console lists it; the catalog's team sees it named, and accepts as for any grant.
const consoleView = (await call(admin, "GET", "/api/v1/console/imports")).json;
expect(consoleView.grants).toEqual([expect.objectContaining({ id: grantID, evidence: "Discord DM, 2026-11-07", recordedBy: "root", claimed: false, proofCode: null })]);
expect((await call(owner, "GET", `/api/v1/catalogs/${catalogID}/importer`)).json.grants[0]).toMatchObject({ imvuName: "QuietMaker", consentKind: "recorded" });
expect((await call(owner, "POST", `/api/v1/imports/grants/${grantID}/accept`)).json.grant.status).toBe("active");
// Proof without an account: a code in the creator's IMVU tagline.
expect((await call(admin, "POST", `/api/v1/console/imports/grants/${grantID}/proof/check`)).json.error).toBe("no_code");
const code = (await call(admin, "POST", `/api/v1/console/imports/grants/${grantID}/proof`)).json.code as string;
expect(code).toMatch(/^t5de-/);
expect((await call(admin, "POST", `/api/v1/console/imports/grants/${grantID}/proof`)).json.code).toBe(code);
expect((await call(admin, "POST", `/api/v1/console/imports/grants/${grantID}/proof/check`)).json.error).toBe("not_found");
accounts.get(701)!.tagline = `hi ${code}`;
expect((await call(admin, "POST", `/api/v1/console/imports/grants/${grantID}/proof/check`)).json.grant.consentProven).toBe(true);
// Imported products belong to the unclaimed creator.
expect((await call(fan, "POST", "/api/v1/imports/requests", { imvuProduct: 9201 })).json).toEqual({ status: "queued" });
const [job] = (await call(undefined, "POST", "/api/v1/importer/jobs/claim", {}, importer)).json.jobs;
const tok = await call(undefined, "POST", `/api/v1/importer/jobs/${job.id}/token`, { imvuRevision: 1 }, importer);
const regd = await call(undefined, "POST", "/api/v1/catalog/revisions", { importToken: tok.json.token, files: [file("index.xml", 31)], rating: "general", parent: 0, name: "x" }, catalogAuth);
expect(regd.status).toBe(201);
const productID = regd.json.product as string;
expect((await call(fan, "GET", `/api/v1/products/${productID}`)).json.product).toMatchObject({ name: "Quiet Coat", creatorUsername: "imvu_701" });
// Admins change it for them; others can't.
expect((await call(fan, "PATCH", `/api/v1/imports/grants/${grantID}`, { exclude: [] })).status).toBe(403);
expect((await call(admin, "PATCH", `/api/v1/imports/grants/${grantID}`, { exclude: [] })).json.grant.exclude).toEqual([]);
// Nobody signs up as an unclaimed creator.
const squat = await fetch(base + "/api/auth/sign-up/email", {
method: "POST",
headers: { Origin: webURL, "Content-Type": "application/json" },
body: JSON.stringify({ email: "[email protected]", password: "a long password", name: "squat", username: "imvu_702" }),
});
expect(squat.status).toBe(400);
// The creator joins and links the account: the grant stands, and they're offered the claim.
const quiet = await person("quiet", 701);
expect((await call(quiet, "GET", "/api/v1/imports/grants")).json.grants).toEqual([]);
expect((await call(admin, "GET", "/api/v1/console/imports")).json.grants[0]).toMatchObject({ status: "active", claimed: false });
expect((await call(quiet, "GET", "/api/v1/account")).json.claims).toEqual([{ imvuId: 701, username: "QuietMaker", products: 1, grants: 1 }]);
expect((await call(fan, "POST", "/api/v1/account/claims/701")).json.error).toBe("not_linked");
expect((await call(quiet, "POST", "/api/v1/account/claims/701")).json).toEqual({ products: 1, grants: 1 });
// Now it's theirs: their product and grant; the placeholder is gone; admins no longer change it.
expect((await call(fan, "GET", `/api/v1/products/${productID}`)).json.product.creatorUsername).toBe("quiet");
expect((await call(quiet, "GET", "/api/v1/imports/grants")).json.grants.map((g: any) => g.id)).toEqual([grantID]);
expect((await call(quiet, "GET", "/api/v1/account")).json.claims).toEqual([]);
expect((await call(admin, "GET", "/api/v1/console/imports")).json.grants[0].claimed).toBe(true);
expect((await call(admin, "PATCH", `/api/v1/imports/grants/${grantID}`, { exclude: [9202] })).status).toBe(403);
expect((await call(quiet, "PATCH", `/api/v1/imports/grants/${grantID}`, { exclude: [9202] })).status).toBe(200);
expect((await call(quiet, "POST", "/api/v1/account/claims/701")).status).toBe(404);
const actions = (await call(admin, "GET", "/api/v1/console/audit")).json.entries.map((e: any) => e.action);
expect(actions).toEqual(expect.arrayContaining(["import.grant_record", "import.grant_proof", "import.claim"]));
});