fix(imports): keep imported products IMVU hides behind a 401
Pull request / title (pull_request) Successful in 1s
CI / test (pull_request) Successful in 1m13s
CI / image (apps/api/Dockerfile, t5de-hub-api) (pull_request) Skipped
CI / image (apps/web/Dockerfile, t5de-hub-web) (pull_request) Skipped

Checked against the live API: the product fields imports use are right, but
anonymous callers get 401 alike for Access Pass products, deleted ones and IDs
that never existed. The daily recheck treated that as gone, so a product that
became AP would have been taken away. A 401 now keeps what was last seen; only
a 404 means gone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
dhkatzandClaude Opus 5.5 committed 2026-11-06 06:45:57 -08:00
1 parent 7d708aebdb
commit b53fb564b4
4 files changed
+44 -9

No files matched your search

+16 -5
View File
@@ -39,7 +39,7 @@ export type ImvuProduct = {
};
export class NoSuchImvuUser extends Error {
constructor() {
constructor(readonly status = 404) {
super("no such IMVU account");
}
}
@@ -83,13 +83,24 @@ export class ImvuClient {
* Access Pass ones). Throws ImvuUnavailable if IMVU can't be reached.
*/
async product(id: number): Promise<ImvuProduct | null> {
if (!Number.isSafeInteger(id) || id <= 0) return null;
const p = await this.lookup(id);
return typeof p === "string" ? null : p;
}
/**
* Like product(), but tells "missing" (404) from "hidden": IMVU answers 401 alike for Access Pass products,
* deleted ones and IDs that never existed, so a hidden product may still exist.
*/
async lookup(id: number): Promise<ImvuProduct | "missing" | "hidden"> {
if (!Number.isSafeInteger(id) || id <= 0) return "missing";
let answer: unknown;
try {
return parseProduct(await this.get(`/product/product-${id}`, [401, 403]), id);
answer = await this.get(`/product/product-${id}`, [401, 403]);
} catch (e) {
if (e instanceof NoSuchImvuUser) return null;
if (e instanceof NoSuchImvuUser) return e.status === 404 ? "missing" : "hidden";
throw e;
}
return parseProduct(answer, id) ?? "missing";
}
private async wait() {
@@ -111,7 +122,7 @@ export class ImvuClient {
} catch (e) {
throw new ImvuUnavailable(String(e));
}
if (response.status === 404 || missing.includes(response.status)) throw new NoSuchImvuUser();
if (response.status === 404 || missing.includes(response.status)) throw new NoSuchImvuUser(response.status);
if (!response.ok) throw new ImvuUnavailable(`IMVU answered ${response.status}`);
return response.json();
}