29 lines
840 B
TypeScript
29 lines
840 B
TypeScript
import { NextResponse } from "next/server";
|
|
import {
|
|
listPrintfulStoreProducts,
|
|
normalizePrintfulProduct,
|
|
} from "../../../../lib/printful";
|
|
|
|
export async function GET() {
|
|
try {
|
|
const items = await listPrintfulStoreProducts(50, 0);
|
|
const products = (items || [])
|
|
.map((item) => normalizePrintfulProduct(item as any))
|
|
.filter((product) => Boolean(product?.id))
|
|
.map((product) => ({
|
|
id: product.id,
|
|
name: product.name,
|
|
unitAmount: product.unitAmount,
|
|
currency: product.currency,
|
|
thumbnailUrl: product.thumbnailUrl,
|
|
variantId: product.stripePriceId,
|
|
}));
|
|
return NextResponse.json({ products });
|
|
} catch (err: any) {
|
|
return NextResponse.json(
|
|
{ error: err?.message || "Failed to load Printful products." },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|