Phase 4a (docs/imports.md): the hub's side of IMVU imports. **Grants** - A creator picks one of their linked IMVU accounts and a catalog with imports on. They choose the whole shop (with exclusions) or listed products, listed or unlisted, and agree to a versioned consent text (`imports.ts` `consent`). - The catalog's team (`import:accept`) accepts or declines, and the creator is notified. Accepting queues what people already asked for, plus a grant's listed products. - The creator can change what's covered or withdraw it; the team (`import:withdraw`, which moderators also have) can end it. - Withdrawn products are removed the way moderation removes products: their hosting is dropped and their files go in the catalogs' changes feed. If another catalog's active grant still covers a product, it's only delisted from this catalog. - Unlinking an IMVU account, or someone else linking it, suspends its grants. **Requests** - Anyone signed in can ask for an IMVU product (an ID or a shop link). The answer is one of: - `added`: already imported, and now in their library - `queued`: delivered to their library once imported - `suggested`: the creator grants by listed products, and will see the request - `counted`: no grant covers it yet - Creators see request counts for their accounts, and moderators see the most-requested creators. - At most 50 requests a day per person. **Importer** - Importers sign in with `Authorization: Importer <catalog>:<key>`; turning imports on returns the key once. The catalog's importer can be paused (`import:pause`). - Importers claim jobs, get `t5de-import` tokens for a revision, and report outcomes. - Claims time out after 30 minutes. Failures retry after 1 min, 10 min, 1 h, then daily, and fail for good after 5 attempts. - `POST /catalog/revisions` takes `importToken` instead of `uploadToken`. The result is a published product owned by the creator (`product.imvu_product`, `product_revision.imvu_revision`). If another catalog already imported the same IMVU revision, this catalog hosts it too. - Every hour, the API rechecks a batch of imported products with IMVU (each at most once a day). A product gone from IMVU, or now another creator's, is withdrawn. One rated AP becomes adult. If it's still covered, a recheck job looks for new revisions. **Website** - `/imports`: ask for a product; bring your products; change or withdraw a grant; what people asked for. It's linked from the account page. - The console's catalog page has an Imports card leading to `/console/catalogs/:id/imports`: - importer on, off, pause and resume, and a new key - pending grants to accept or decline - grants to end - the queue, filtered by status, with retry - Notification text for the two new notification types. **Checks** - **Tests:** `test/imports.test.ts` covers the whole flow, from grant to withdrawal. All 58 API tests pass, and type checks pass. - **Scratch hub:** through the console forms, I turned imports on (the key was shown once), paused and resumed. I checked that importer claims accept the key and refuse a wrong one, that `/imports` renders, and that a request while IMVU is unreachable says "IMVU didn't answer." - **IMVU fields not checked live:** `api.imvu.com` times out from the dev machine. The product fields (`product_name`, `creator_cid`, `creator_name`, `rating`, `is_purchasable`) are what the design recorded; the spike will check them. **Formatting** - `two-factor-card.tsx`, `signin-form.tsx` and `console-nav.tsx` are only reformatted. I'd run Prettier on them at its default 80 columns in #12, but the repo is wrapped at about 120. **Still to do (4b and later)** - admin-recorded grants, proofs and unclaimed creators (and claiming them) - `GET /imports/available` for the proxy's shop button - t5de-catalog accepting `t5de-import` tokens on uploads - the spike, then `t5de-importer` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Phase 4a (docs/imports.md): the hub's side of IMVU imports. **Grants** - A creator picks one of their linked IMVU accounts and a catalog with imports on. They choose the whole shop (with exclusions) or listed products, listed or unlisted, and agree to a versioned consent text (`imports.ts` `consent`). - The catalog's team (`import:accept`) accepts or declines, and the creator is notified. Accepting queues what people already asked for, plus a grant's listed products. - The creator can change what's covered or withdraw it; the team (`import:withdraw`, which moderators also have) can end it. - Withdrawn products are removed the way moderation removes products: their hosting is dropped and their files go in the catalogs' changes feed. If another catalog's active grant still covers a product, it's only delisted from this catalog. - Unlinking an IMVU account, or someone else linking it, suspends its grants. **Requests** - Anyone signed in can ask for an IMVU product (an ID or a shop link). The answer is one of: - `added`: already imported, and now in their library - `queued`: delivered to their library once imported - `suggested`: the creator grants by listed products, and will see the request - `counted`: no grant covers it yet - Creators see request counts for their accounts, and moderators see the most-requested creators. - At most 50 requests a day per person. **Importer** - Importers sign in with `Authorization: Importer <catalog>:<key>`; turning imports on returns the key once. The catalog's importer can be paused (`import:pause`). - Importers claim jobs, get `t5de-import` tokens for a revision, and report outcomes. - Claims time out after 30 minutes. Failures retry after 1 min, 10 min, 1 h, then daily, and fail for good after 5 attempts. - `POST /catalog/revisions` takes `importToken` instead of `uploadToken`. The result is a published product owned by the creator (`product.imvu_product`, `product_revision.imvu_revision`). If another catalog already imported the same IMVU revision, this catalog hosts it too. - Every hour, the API rechecks a batch of imported products with IMVU (each at most once a day). A product gone from IMVU, or now another creator's, is withdrawn. One rated AP becomes adult. If it's still covered, a recheck job looks for new revisions. **Website** - `/imports`: ask for a product; bring your products; change or withdraw a grant; what people asked for. It's linked from the account page. - The console's catalog page has an Imports card leading to `/console/catalogs/:id/imports`: - importer on, off, pause and resume, and a new key - pending grants to accept or decline - grants to end - the queue, filtered by status, with retry - Notification text for the two new notification types. **Checks** - **Tests:** `test/imports.test.ts` covers the whole flow, from grant to withdrawal. All 58 API tests pass, and type checks pass. - **Scratch hub:** through the console forms, I turned imports on (the key was shown once), paused and resumed. I checked that importer claims accept the key and refuse a wrong one, that `/imports` renders, and that a request while IMVU is unreachable says "IMVU didn't answer." - **IMVU fields not checked live:** `api.imvu.com` times out from the dev machine. The product fields (`product_name`, `creator_cid`, `creator_name`, `rating`, `is_purchasable`) are what the design recorded; the spike will check them. **Formatting** - `two-factor-card.tsx`, `signin-form.tsx` and `console-nav.tsx` are only reformatted. I'd run Prettier on them at its default 80 columns in #12, but the repo is wrapped at about 120. **Still to do (4b and later)** - admin-recorded grants, proofs and unclaimed creators (and claiming them) - `GET /imports/available` for the proxy's shop button - t5de-catalog accepting `t5de-import` tokens on uploads - the spike, then `t5de-importer` 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: dhkatz <[email protected]>
128 lines
5.3 KiB
TypeScript
128 lines
5.3 KiB
TypeScript
import type { Metadata } from "next";
|
|
import Link from "next/link";
|
|
import { redirect } from "next/navigation";
|
|
import { caseKinds } from "@/components/cases";
|
|
import { ActionForm, SubmitButton } from "@/components/forms";
|
|
import { PageHeader } from "@/components/status";
|
|
import { DateTime } from "@/components/time";
|
|
import { buttonVariants } from "@/components/ui/button";
|
|
import { Card, CardContent } from "@/components/ui/card";
|
|
import { api, getMe, unwrap, type NotificationEntry } from "@/lib/api";
|
|
import { cn } from "@/lib/utils";
|
|
import { markAllRead } from "../console/cases/actions";
|
|
|
|
export const metadata: Metadata = { title: "Notifications" };
|
|
|
|
export default async function Notifications({ searchParams }: { searchParams: Promise<{ before?: string | string[] }> }) {
|
|
const me = await getMe();
|
|
if (!me) redirect("/signin?next=/notifications");
|
|
const raw = (await searchParams).before;
|
|
const before = typeof raw === "string" && /^\d+$/.test(raw) ? Number(raw) : undefined;
|
|
const data = unwrap(await api.notifications.get({ query: before ? { before } : {} }));
|
|
|
|
return (
|
|
<>
|
|
<div className="flex flex-wrap items-start justify-between gap-4">
|
|
<PageHeader title="Notifications">
|
|
{data.unread > 0 ? `${data.unread} unread.` : "You're up to date."}
|
|
</PageHeader>
|
|
{data.unread > 0 && (
|
|
<ActionForm action={markAllRead}>
|
|
<SubmitButton variant="outline" pendingLabel="Marking…">
|
|
Mark all as read
|
|
</SubmitButton>
|
|
</ActionForm>
|
|
)}
|
|
</div>
|
|
<Card>
|
|
<CardContent>
|
|
{data.notifications.length === 0 ? (
|
|
<p className="text-sm text-muted-foreground">Nothing yet.</p>
|
|
) : (
|
|
<ul className="divide-y">
|
|
{data.notifications.map((n) => {
|
|
const { text, href } = describe(n);
|
|
return (
|
|
<li key={n.id} className={cn("flex flex-wrap items-baseline gap-x-3 gap-y-1 py-3 first:pt-0 last:pb-0", n.read && "text-muted-foreground")}>
|
|
{!n.read && <span className="size-2 shrink-0 self-center rounded-full bg-foreground" aria-label="Unread" />}
|
|
<span className="min-w-0 flex-1 text-sm">
|
|
{href ? (
|
|
<Link href={href} className="underline-offset-4 hover:underline">
|
|
{text}
|
|
</Link>
|
|
) : (
|
|
text
|
|
)}
|
|
</span>
|
|
<span className="text-xs text-muted-foreground">
|
|
<DateTime iso={n.at} />
|
|
</span>
|
|
</li>
|
|
);
|
|
})}
|
|
</ul>
|
|
)}
|
|
</CardContent>
|
|
</Card>
|
|
{data.before && (
|
|
<div className="mt-4">
|
|
<Link href={`/notifications?before=${data.before}`} className={buttonVariants({ variant: "outline" })}>
|
|
Older
|
|
</Link>
|
|
</div>
|
|
)}
|
|
</>
|
|
);
|
|
}
|
|
|
|
/** A notification in words, and where it leads. */
|
|
function describe(n: NotificationEntry): { text: string; href?: string } {
|
|
const d = n.data as Record<string, unknown>;
|
|
const s = (k: string) => (typeof d[k] === "string" ? (d[k] as string) : "");
|
|
const why = s("reason") ? `: “${s("reason")}”` : "";
|
|
switch (n.type) {
|
|
case "product_edited": {
|
|
const what =
|
|
s("kind") === "lock"
|
|
? "changed the locks on"
|
|
: s("kind") === "revert"
|
|
? "undid a change to"
|
|
: `changed the ${(d.fields as string[] | undefined)?.join(", ") ?? "info"} of`;
|
|
return { text: `${s("by") || "A moderator"} ${what} ${s("name")}${why}`, href: `/products/${s("product")}/edit` };
|
|
}
|
|
case "product_removed":
|
|
return { text: `Moderation removed ${s("name")}${why}. You can appeal it from your audit log.`, href: `/console/audit?product=${s("product")}` };
|
|
case "product_restored":
|
|
return { text: `Moderation restored ${s("name")}${why}`, href: `/products/${s("product")}` };
|
|
case "case_decided": {
|
|
const status = s("status") === "resolved" ? "resolved" : "declined";
|
|
const res = s("resolution") ? `: “${s("resolution")}”` : "";
|
|
return { text: `Your ${caseKinds[s("kind")]?.toLowerCase() ?? "case"} was ${status}${res}`, href: `/console/cases/${d.case}` };
|
|
}
|
|
case "case_note":
|
|
return { text: `${s("by") || "Someone"} replied on your ${caseKinds[s("kind")]?.toLowerCase() ?? "case"}`, href: `/console/cases/${d.case}` };
|
|
case "membership_decided": {
|
|
const status = s("status");
|
|
const text =
|
|
status === "member"
|
|
? `You're a member of ${s("name")}`
|
|
: status === "banned"
|
|
? `${s("name")} banned you`
|
|
: `${s("name")} declined your request to join`;
|
|
return { text, href: `/catalogs/${s("catalog")}` };
|
|
}
|
|
case "import_grant_decided":
|
|
return {
|
|
text:
|
|
s("decision") === "accept"
|
|
? `${s("name")} accepted importing your IMVU products`
|
|
: `${s("name")} declined importing your IMVU products${why}`,
|
|
href: "/imports",
|
|
};
|
|
case "import_grant_ended":
|
|
return { text: `${s("name")} stopped importing your IMVU products${why}`, href: "/imports" };
|
|
default:
|
|
return { text: n.type };
|
|
}
|
|
}
|