feat: IMVU imports on the hub: grants, requests and the importer's job queue (#13)
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]>
This commit was merged in pull request #13.
This commit is contained in:
1 parent
eca1884918
commit
7ece681eef
24 files changed
+6565
-158
No files matched your search
@@ -289,6 +289,9 @@ export const catalog = pgTable(
|
||||
uploads: text("uploads").notNull().default("anyone"), // who may upload: "anyone", "members", "team"
|
||||
mirrors: text("mirrors").notNull().default("approve"), // mirroring others' revisions: "auto", "approve", "off"
|
||||
keyHash: text("key_hash").notNull(), // sha256 of its key, hex
|
||||
// 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
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
@@ -393,10 +396,13 @@ export const product = pgTable(
|
||||
// Removed by moderation: gone everywhere (no page, no files, out of libraries and rooms).
|
||||
removedAt: timestamp("removed_at", { withTimezone: true }),
|
||||
removedReason: text("removed_reason"),
|
||||
// Imported from IMVU (docs/imports.md): the IMVU product, one hub product each.
|
||||
imvuProduct: bigint("imvu_product", { mode: "number" }),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [
|
||||
uniqueIndex("product_imvu_product").on(t.imvuProduct),
|
||||
index("product_creator").on(t.creatorId),
|
||||
index("product_created").on(t.createdAt),
|
||||
index("product_tags").using("gin", t.tags),
|
||||
@@ -440,6 +446,7 @@ export const productRevision = pgTable(
|
||||
token: text("token").notNull(), // the hub's t5de-revision token
|
||||
uploadedBy: text("uploaded_by").references(() => user.id, { onDelete: "set null" }),
|
||||
retracted: boolean("retracted").notNull().default(false),
|
||||
imvuRevision: integer("imvu_revision"), // imported: the IMVU revision it came from
|
||||
createdAt: createdAt(),
|
||||
},
|
||||
(t) => [primaryKey({ columns: [t.productId, t.number] }), index("product_revision_files").using("gin", t.files)],
|
||||
@@ -708,3 +715,99 @@ export const apiToken = pgTable(
|
||||
},
|
||||
(t) => [uniqueIndex("api_token_hash").on(t.hash), index("api_token_user").on(t.userId)],
|
||||
);
|
||||
|
||||
// ---- imports (docs/imports.md) ----
|
||||
|
||||
// A creator's consent for one catalog to import their IMVU products: the whole shop (less exclusions) or listed ones.
|
||||
export const importGrant = pgTable(
|
||||
"import_grant",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
catalogId: text("catalog_id")
|
||||
.notNull()
|
||||
.references(() => catalog.id, { onDelete: "cascade" }),
|
||||
creatorId: text("creator_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
imvuId: bigint("imvu_id", { mode: "number" }).notNull(), // the IMVU account whose products these are
|
||||
scope: text("scope").notNull(), // "shop", "products"
|
||||
products: jsonb("products").$type<number[]>().notNull().default([]), // scope "products": the IMVU product IDs
|
||||
exclude: jsonb("exclude").$type<number[]>().notNull().default([]), // scope "shop": left out
|
||||
listed: boolean("listed").notNull().default(true), // imported products are listed
|
||||
consentVersion: integer("consent_version").notNull(),
|
||||
consentedAt: timestamp("consented_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
consentKind: text("consent_kind").notNull().default("verified"), // "verified" (the creator), "recorded" (an admin)
|
||||
evidence: text("evidence").notNull().default(""), // recorded: how they agreed
|
||||
recordedBy: text("recorded_by").references(() => user.id, { onDelete: "set null" }),
|
||||
// "pending" (the catalog's team hasn't accepted), "active", "declined", "suspended", "withdrawn".
|
||||
status: text("status").notNull().default("pending"),
|
||||
statusReason: text("status_reason").notNull().default(""),
|
||||
decidedAt: timestamp("decided_at", { withTimezone: true }),
|
||||
decidedBy: text("decided_by").references(() => user.id, { onDelete: "set null" }),
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [index("import_grant_catalog").on(t.catalogId, t.status), index("import_grant_imvu").on(t.imvuId, t.status)],
|
||||
);
|
||||
|
||||
// Someone asking for an IMVU product (or, with imvuProduct 0, a creator's whole shop) on T5DE. One per person and target.
|
||||
export const importRequest = pgTable(
|
||||
"import_request",
|
||||
{
|
||||
userId: text("user_id")
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: "cascade" }),
|
||||
imvuCreator: bigint("imvu_creator", { mode: "number" }).notNull(),
|
||||
imvuProduct: bigint("imvu_product", { mode: "number" }).notNull(), // 0: the whole shop
|
||||
createdAt: createdAt(),
|
||||
fulfilledAt: timestamp("fulfilled_at", { withTimezone: true }), // the product reached their library
|
||||
},
|
||||
(t) => [
|
||||
primaryKey({ columns: [t.userId, t.imvuCreator, t.imvuProduct] }),
|
||||
index("import_request_creator").on(t.imvuCreator),
|
||||
index("import_request_product").on(t.imvuProduct),
|
||||
],
|
||||
);
|
||||
|
||||
// One product for a catalog's importer to import or re-check.
|
||||
export const importJob = pgTable(
|
||||
"import_job",
|
||||
{
|
||||
id: text("id").primaryKey(),
|
||||
catalogId: text("catalog_id")
|
||||
.notNull()
|
||||
.references(() => catalog.id, { onDelete: "cascade" }),
|
||||
grantId: text("grant_id")
|
||||
.notNull()
|
||||
.references(() => importGrant.id, { onDelete: "cascade" }),
|
||||
imvuProduct: bigint("imvu_product", { mode: "number" }).notNull(),
|
||||
kind: text("kind").notNull(), // "import", "recheck"
|
||||
status: text("status").notNull().default("queued"), // "queued", "claimed", "done", "failed"
|
||||
imvuRevision: integer("imvu_revision"), // done: the revision imported (or found unchanged)
|
||||
reason: text("reason").notNull().default(""), // why it failed (last attempt)
|
||||
attempts: integer("attempts").notNull().default(0),
|
||||
claimedAt: timestamp("claimed_at", { withTimezone: true }),
|
||||
nextAt: timestamp("next_at", { withTimezone: true }).notNull().defaultNow(), // queued: not before
|
||||
createdAt: createdAt(),
|
||||
updatedAt: updatedAt(),
|
||||
},
|
||||
(t) => [
|
||||
index("import_job_queue").on(t.catalogId, t.status, t.nextAt),
|
||||
// One open job per product and catalog.
|
||||
uniqueIndex("import_job_open")
|
||||
.on(t.catalogId, t.imvuProduct)
|
||||
.where(sql`${t.status} in ('queued', 'claimed')`),
|
||||
],
|
||||
);
|
||||
|
||||
// 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(),
|
||||
found: boolean("found").notNull(), // IMVU shows it publicly
|
||||
name: text("name").notNull().default(""),
|
||||
creatorId: bigint("creator_id", { mode: "number" }).notNull().default(0),
|
||||
creatorName: text("creator_name").notNull().default(""),
|
||||
rating: text("rating").notNull().default("general"), // "general", "adult" (IMVU's AP)
|
||||
purchasable: boolean("purchasable").notNull().default(true),
|
||||
checkedAt: timestamp("checked_at", { withTimezone: true }).notNull().defaultNow(),
|
||||
});
|
||||
Reference in new issue
Block a user