more cleanup

This commit is contained in:
Dominic Ferrando
2026-06-14 14:19:46 -04:00
parent 05dc26adb5
commit 5bb762961a
5 changed files with 42 additions and 48 deletions
+4
View File
@@ -3,6 +3,10 @@
"module": "index.ts", "module": "index.ts",
"type": "module", "type": "module",
"private": true, "private": true,
"scripts": {
"dev": "bun run --hot src/index.ts",
"start": "bun run src/index.ts"
},
"dependencies": { "dependencies": {
"@elysiajs/cors": "^1.4.2", "@elysiajs/cors": "^1.4.2",
"elysia": "^1.4.28", "elysia": "^1.4.28",
+10 -8
View File
@@ -1,17 +1,16 @@
<script lang="ts"> <script lang="ts">
import type { Printful } from "@blade-and-brawn/commerce"; import type { Printful } from "@blade-and-brawn/commerce";
import { PUBLIC_API_URL } from "$env/static/public";
import { onMount } from "svelte"; import { onMount } from "svelte";
const { data } = $props(); const { data } = $props();
const apiUrl = "http://localhost:3000";
const synchronizer = $state({ const synchronizer = $state({
isSyncing: false, isSyncing: false,
syncingIds: [] as number[], syncingIds: [] as number[],
poll: async function () { poll: async function () {
const res = (await ( const res = (await (
await fetch(`${apiUrl}/products/sync`) await fetch(`${PUBLIC_API_URL}/products/sync`)
).json()) as any; ).json()) as any;
if (res.data) { if (res.data) {
synchronizer.isSyncing = res.data.isSyncing; synchronizer.isSyncing = res.data.isSyncing;
@@ -26,13 +25,16 @@
}, },
syncAll: async () => { syncAll: async () => {
synchronizer.startPolling(); synchronizer.startPolling();
await fetch(`${apiUrl}/products/sync`, { method: "POST" }); await fetch(`${PUBLIC_API_URL}/products/sync`, { method: "POST" });
}, },
sync: async (printfulProductId: number) => { sync: async (printfulProductId: number) => {
synchronizer.startPolling(); synchronizer.startPolling();
await fetch(`${apiUrl}/products/sync/${printfulProductId}`, { await fetch(
method: "POST", `${PUBLIC_API_URL}/products/sync/${printfulProductId}`,
}); {
method: "POST",
},
);
}, },
}); });
@@ -84,7 +86,7 @@
onclick={async () => { onclick={async () => {
const productData = (await ( const productData = (await (
await fetch( await fetch(
`${apiUrl}/products/${printfulProduct.id}`, `${PUBLIC_API_URL}/products/${printfulProduct.id}`,
) )
).json()) as any; ).json()) as any;
console.log(productData); console.log(productData);
+5
View File
@@ -5,6 +5,11 @@
"apps/*", "apps/*",
"packages/*" "packages/*"
], ],
"scripts": {
"dev:api": "bun run --filter @blade-and-brawn/api dev",
"dev:portal": "bun run --filter @blade-and-brawn/portal dev",
"build:portal": "bun run --filter @blade-and-brawn/portal build"
},
"peerDependencies": { "peerDependencies": {
"typescript": "^5.9.3" "typescript": "^5.9.3"
}, },
+20 -24
View File
@@ -35,32 +35,28 @@ export class PrintfulService {
const allSyncProducts: Printful.Products.SyncProduct[] = []; const allSyncProducts: Printful.Products.SyncProduct[] = [];
while (true) { while (true) {
try { const res = await fetch(
const res = await fetch( `${env().API_URL}/store/products?offset=${offset}`,
`${env().API_URL}/store/products?offset=${offset}`, {
{ method: "GET",
method: "GET", headers: { ...env().AUTH_HEADERS },
headers: { ...env().AUTH_HEADERS }, },
}, );
if (!res.ok) {
throw new FetchError(
"Failed to get all Printful products",
res,
); );
if (!res.ok) {
throw new FetchError(
"Failed to get all Printful products",
res,
);
}
const payload =
(await res.json()) as Printful.Products.MetaDataMulti<Printful.Products.SyncProduct>;
allSyncProducts.push(...payload.result);
offset = allSyncProducts.length;
if (allSyncProducts.length >= payload.paging.total) break;
} catch (error) {
throw error;
} }
const payload =
(await res.json()) as Printful.Products.MetaDataMulti<Printful.Products.SyncProduct>;
allSyncProducts.push(...payload.result);
offset = allSyncProducts.length;
if (allSyncProducts.length >= payload.paging.total) break;
} }
return allSyncProducts; return allSyncProducts;
+3 -16
View File
@@ -78,10 +78,9 @@ export class SyncService {
mainPrintfulProduct.colors.add(productColor); mainPrintfulProduct.colors.add(productColor);
} }
} catch (error) { } catch (error) {
throw error;
} finally {
this.state.isSyncing = false; this.state.isSyncing = false;
this.state.syncingIds = []; this.state.syncingIds = [];
throw error;
} }
// TODO: Validate main printful products // TODO: Validate main printful products
@@ -278,10 +277,10 @@ export class SyncService {
existingWebflowProduct.skus.find( existingWebflowProduct.skus.find(
(sku) => (sku) =>
sku.fieldData["sku-values"]?.[ sku.fieldData["sku-values"]?.[
"color" "color"
] === printfulVariant.color && ] === printfulVariant.color &&
sku.fieldData["sku-values"]?.[ sku.fieldData["sku-values"]?.[
"size" "size"
] === printfulVariant.size, ] === printfulVariant.size,
); );
if (associatedWebflowSku) { if (associatedWebflowSku) {
@@ -308,18 +307,6 @@ export class SyncService {
} }
} }
} catch (err) { } catch (err) {
// SYNC IMAGES
// for (const sku of existingWebflowProduct.skus) {
// const skuColor = sku.fieldData["sku-values"]?.["color"]?.toLowerCase() ?? "None";
// const skuSlug = `${existingWebflowProduct.product.fieldData.slug}-${skuColor}`;
// const skuImageUrls = await this.getProductImageUrls(skuSlug);
//
// sku.fieldData["main-image"] = skuImageUrls[0] ?? sku.fieldData["main-image"];
// sku.fieldData["more-images"] = skuImageUrls.slice(1).map(url => ({ url }));
//
// await WebflowService.Products.Skus.update(existingWebflowProduct.product.id, sku.id, sku);
// }
//
if (err instanceof FetchError) { if (err instanceof FetchError) {
console.error(err.message, err.payload); console.error(err.message, err.payload);
} }