more cleanup
This commit is contained in:
@@ -3,6 +3,10 @@
|
||||
"module": "index.ts",
|
||||
"type": "module",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "bun run --hot src/index.ts",
|
||||
"start": "bun run src/index.ts"
|
||||
},
|
||||
"dependencies": {
|
||||
"@elysiajs/cors": "^1.4.2",
|
||||
"elysia": "^1.4.28",
|
||||
|
||||
@@ -1,17 +1,16 @@
|
||||
<script lang="ts">
|
||||
import type { Printful } from "@blade-and-brawn/commerce";
|
||||
import { PUBLIC_API_URL } from "$env/static/public";
|
||||
import { onMount } from "svelte";
|
||||
|
||||
const { data } = $props();
|
||||
|
||||
const apiUrl = "http://localhost:3000";
|
||||
|
||||
const synchronizer = $state({
|
||||
isSyncing: false,
|
||||
syncingIds: [] as number[],
|
||||
poll: async function () {
|
||||
const res = (await (
|
||||
await fetch(`${apiUrl}/products/sync`)
|
||||
await fetch(`${PUBLIC_API_URL}/products/sync`)
|
||||
).json()) as any;
|
||||
if (res.data) {
|
||||
synchronizer.isSyncing = res.data.isSyncing;
|
||||
@@ -26,13 +25,16 @@
|
||||
},
|
||||
syncAll: async () => {
|
||||
synchronizer.startPolling();
|
||||
await fetch(`${apiUrl}/products/sync`, { method: "POST" });
|
||||
await fetch(`${PUBLIC_API_URL}/products/sync`, { method: "POST" });
|
||||
},
|
||||
sync: async (printfulProductId: number) => {
|
||||
synchronizer.startPolling();
|
||||
await fetch(`${apiUrl}/products/sync/${printfulProductId}`, {
|
||||
method: "POST",
|
||||
});
|
||||
await fetch(
|
||||
`${PUBLIC_API_URL}/products/sync/${printfulProductId}`,
|
||||
{
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -84,7 +86,7 @@
|
||||
onclick={async () => {
|
||||
const productData = (await (
|
||||
await fetch(
|
||||
`${apiUrl}/products/${printfulProduct.id}`,
|
||||
`${PUBLIC_API_URL}/products/${printfulProduct.id}`,
|
||||
)
|
||||
).json()) as any;
|
||||
console.log(productData);
|
||||
|
||||
@@ -5,6 +5,11 @@
|
||||
"apps/*",
|
||||
"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": {
|
||||
"typescript": "^5.9.3"
|
||||
},
|
||||
|
||||
@@ -35,32 +35,28 @@ export class PrintfulService {
|
||||
const allSyncProducts: Printful.Products.SyncProduct[] = [];
|
||||
|
||||
while (true) {
|
||||
try {
|
||||
const res = await fetch(
|
||||
`${env().API_URL}/store/products?offset=${offset}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: { ...env().AUTH_HEADERS },
|
||||
},
|
||||
const res = await fetch(
|
||||
`${env().API_URL}/store/products?offset=${offset}`,
|
||||
{
|
||||
method: "GET",
|
||||
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;
|
||||
|
||||
@@ -78,10 +78,9 @@ export class SyncService {
|
||||
mainPrintfulProduct.colors.add(productColor);
|
||||
}
|
||||
} catch (error) {
|
||||
throw error;
|
||||
} finally {
|
||||
this.state.isSyncing = false;
|
||||
this.state.syncingIds = [];
|
||||
throw error;
|
||||
}
|
||||
|
||||
// TODO: Validate main printful products
|
||||
@@ -278,10 +277,10 @@ export class SyncService {
|
||||
existingWebflowProduct.skus.find(
|
||||
(sku) =>
|
||||
sku.fieldData["sku-values"]?.[
|
||||
"color"
|
||||
"color"
|
||||
] === printfulVariant.color &&
|
||||
sku.fieldData["sku-values"]?.[
|
||||
"size"
|
||||
"size"
|
||||
] === printfulVariant.size,
|
||||
);
|
||||
if (associatedWebflowSku) {
|
||||
@@ -308,18 +307,6 @@ export class SyncService {
|
||||
}
|
||||
}
|
||||
} 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) {
|
||||
console.error(err.message, err.payload);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user