This commit is contained in:
Dominic Ferrando
2025-09-13 18:53:02 -04:00
parent 368c6d4107
commit ed3fd73510
5 changed files with 219 additions and 273 deletions
+9 -3
View File
@@ -121,7 +121,7 @@ export namespace Printful {
}[]
}
export async function getSyncProduct(syncProductId: number): Promise<SyncProduct> {
export async function get(syncProductId: number): Promise<SyncProduct> {
const payload: MetaDataSingle<SyncProduct> = await (
await fetch(`${Printful.API_URL}/store/products/${syncProductId}`, {
method: "GET",
@@ -135,7 +135,7 @@ export namespace Printful {
return payload.result;
}
export async function getSyncProducts(): Promise<SyncProduct[]> {
export async function getAll(): Promise<SyncProduct[]> {
const payload: MetaDataMulti<SyncProduct["sync_product"]> = await (
await fetch(`${Printful.API_URL}/store/products`, {
method: "GET",
@@ -148,9 +148,15 @@ export namespace Printful {
// need to fetch variants
const syncProducts = await Promise.all(
payload.result.map(p => getSyncProduct(p.id))
payload.result.map(p => get(p.id))
);
return syncProducts;
}
export function getVariantPreviewUrl(syncVariant: Printful.Products.SyncProduct["sync_variants"][number]): string {
const previewFile = syncVariant.files.find(f => f.type === "preview");
return previewFile?.preview_url ?? syncVariant.product.image;
}
}
}