More work on deployment
This commit is contained in:
@@ -0,0 +1,6 @@
|
|||||||
|
PRINTFUL_AUTH=RGI4WiWeQkrEYek3obwxZL6c424LAJsUimDX1bHF
|
||||||
|
PRINTFUL_STORE_ID=15619272
|
||||||
|
|
||||||
|
WEBFLOW_AUTH=115ded1e97162f5d4835bcb87e236fe4bce1ad602f519bca8179394092a8c6f6
|
||||||
|
WEBFLOW_SITE_ID=6737d2c9511d414861f1726e
|
||||||
|
WEBFLOW_COLLECTION_ID=675a3fbe966e58ea9aa7110f
|
||||||
@@ -31,5 +31,8 @@ FROM base
|
|||||||
# Copy built application
|
# Copy built application
|
||||||
COPY --from=build /app /app
|
COPY --from=build /app /app
|
||||||
|
|
||||||
|
RUN apt-get update && apt-get install -y sqlite3 && rm -rf /var/lib/apt/lists/*
|
||||||
|
|
||||||
# Start the server by default, this can be overwritten at runtime
|
# Start the server by default, this can be overwritten at runtime
|
||||||
|
CMD [ "bun", "run", "db:seed:prod" ]
|
||||||
CMD [ "bun", "run", "start" ]
|
CMD [ "bun", "run", "start" ]
|
||||||
|
|||||||
@@ -9,7 +9,11 @@ export class ProductRecords {
|
|||||||
private db: Database;
|
private db: Database;
|
||||||
|
|
||||||
constructor() {
|
constructor() {
|
||||||
this.db = new Database("./database/data.db");
|
const dbPath = Bun.env.NODE_ENV === "production" ?
|
||||||
|
"/data/data.db" :
|
||||||
|
"./data/data.db";
|
||||||
|
|
||||||
|
this.db = new Database(dbPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
findFromWebflow(webflowProductId: number): ProductRecord | undefined {
|
findFromWebflow(webflowProductId: number): ProductRecord | undefined {
|
||||||
@@ -23,3 +23,7 @@ primary_region = 'ord'
|
|||||||
memory = '1gb'
|
memory = '1gb'
|
||||||
cpu_kind = 'shared'
|
cpu_kind = 'shared'
|
||||||
cpus = 1
|
cpus = 1
|
||||||
|
|
||||||
|
[[mounts]]
|
||||||
|
source = "data"
|
||||||
|
destination = "/data"
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Printful } from "./printful.ts"
|
import { Printful } from "./printful.ts"
|
||||||
import { ProductRecords } from "./database/product-records.ts"
|
import { ProductRecords } from "./data/product-records.ts"
|
||||||
import { Webflow } from "./webflow.ts";
|
import { Webflow } from "./webflow.ts";
|
||||||
|
|
||||||
const productRecords = new ProductRecords();
|
const productRecords = new ProductRecords();
|
||||||
@@ -14,6 +14,7 @@ const server = Bun.serve({
|
|||||||
"/webhook/printful": {
|
"/webhook/printful": {
|
||||||
async POST(req) {
|
async POST(req) {
|
||||||
const payload: Printful.Webhook.EventPayload = await req.json()
|
const payload: Printful.Webhook.EventPayload = await req.json()
|
||||||
|
console.log(JSON.stringify(payload));
|
||||||
switch (payload.type) {
|
switch (payload.type) {
|
||||||
case Printful.Webhook.Event.ProductUpdated:
|
case Printful.Webhook.Event.ProductUpdated:
|
||||||
const printfulProduct = await Printful.getSyncProduct(payload.data.sync_product.id)
|
const printfulProduct = await Printful.getSyncProduct(payload.data.sync_product.id)
|
||||||
|
|||||||
+2
-1
@@ -4,7 +4,8 @@
|
|||||||
"@types/bun": "^1.2.11"
|
"@types/bun": "^1.2.11"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"db:seed": "sqlite3 ./database/data.db < ./database/seed.sql",
|
"db:seed:dev": "sqlite3 ./data/data.db < ./data/seed.sql",
|
||||||
|
"db:seed:prod": "sqlite3 /data/data.db < ./data/seed.sql",
|
||||||
"start": "bun run main.ts"
|
"start": "bun run main.ts"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+8
-1
@@ -1,4 +1,4 @@
|
|||||||
import { ProductRecords } from "./database/product-records";
|
import { ProductRecords } from "./data/product-records";
|
||||||
import { Printful } from "./printful"
|
import { Printful } from "./printful"
|
||||||
|
|
||||||
export namespace Webflow {
|
export namespace Webflow {
|
||||||
@@ -71,6 +71,7 @@ export namespace Webflow {
|
|||||||
const foundSizes = Array.from(new Set(printfulVariants.map(v => v.size)));
|
const foundSizes = Array.from(new Set(printfulVariants.map(v => v.size)));
|
||||||
|
|
||||||
// CREATE WEBFLOW PRODUCT
|
// CREATE WEBFLOW PRODUCT
|
||||||
|
console.log("CREATE WEBFLOW PRODUCT");
|
||||||
let addProductResponse = await fetch(`${API_URL}/products`, {
|
let addProductResponse = await fetch(`${API_URL}/products`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -108,11 +109,13 @@ export namespace Webflow {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
addProductResponse = await addProductResponse.json();
|
addProductResponse = await addProductResponse.json();
|
||||||
|
console.log(JSON.stringify(addProductResponse));
|
||||||
|
|
||||||
const webflowProductId = addProductResponse["product"]["id"];
|
const webflowProductId = addProductResponse["product"]["id"];
|
||||||
const printfulProductId = printfulProduct.result.sync_product.id;
|
const printfulProductId = printfulProduct.result.sync_product.id;
|
||||||
|
|
||||||
// CREATE WEBFLOW PRODUCT SKUs
|
// CREATE WEBFLOW PRODUCT SKUs
|
||||||
|
console.log("CREATE SKUS");
|
||||||
let createSkuResponse = await fetch(`${API_URL}/products/${webflowProductId}/skus`, {
|
let createSkuResponse = await fetch(`${API_URL}/products/${webflowProductId}/skus`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -124,10 +127,12 @@ export namespace Webflow {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
createSkuResponse = await createSkuResponse.json();
|
createSkuResponse = await createSkuResponse.json();
|
||||||
|
console.log(JSON.stringify(createSkuResponse));
|
||||||
|
|
||||||
const responseSkus = [addProductResponse["sku"], ...createSkuResponse["skus"]];
|
const responseSkus = [addProductResponse["sku"], ...createSkuResponse["skus"]];
|
||||||
|
|
||||||
// SYNC WEBFLOW/PRINTFUL PRODUCT AND VARIANT IDs
|
// SYNC WEBFLOW/PRINTFUL PRODUCT AND VARIANT IDs
|
||||||
|
console.log("SYNC PRODUCT IDs");
|
||||||
let modifyPrintfulProductResponse = await fetch(`${Printful.API_URL}/store/products/${printfulProductId}`, {
|
let modifyPrintfulProductResponse = await fetch(`${Printful.API_URL}/store/products/${printfulProductId}`, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: {
|
headers: {
|
||||||
@@ -146,8 +151,10 @@ export namespace Webflow {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
modifyPrintfulProductResponse = await modifyPrintfulProductResponse.json();
|
modifyPrintfulProductResponse = await modifyPrintfulProductResponse.json();
|
||||||
|
console.log(JSON.stringify(modifyPrintfulProductResponse));
|
||||||
|
|
||||||
// CACHE WEBFLOW/PRINTFUL PRODUCT ASSOCIATION
|
// CACHE WEBFLOW/PRINTFUL PRODUCT ASSOCIATION
|
||||||
|
console.log("CACHING PRODUCT ASSOCIATION");
|
||||||
productRecords.add({ printfulProductId, webflowProductId });
|
productRecords.add({ printfulProductId, webflowProductId });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user