Improve environment variable handling
This commit is contained in:
@@ -0,0 +1,14 @@
|
|||||||
|
function requireEnv(key: string): string {
|
||||||
|
const val = Bun.env[key];
|
||||||
|
if (!val) throw new Error(`Missing required environment variable: ${key}`);
|
||||||
|
return val;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const env = {
|
||||||
|
PRINTFUL_AUTH: requireEnv("PRINTFUL_AUTH"),
|
||||||
|
PRINTFUL_STORE_ID: requireEnv("PRINTFUL_STORE_ID"),
|
||||||
|
WEBFLOW_SITE_ID: requireEnv("WEBFLOW_SITE_ID"),
|
||||||
|
WEBFLOW_COLLECTION_ID: requireEnv("WEBFLOW_COLLECTION_ID"),
|
||||||
|
WEBFLOW_AUTH: requireEnv("WEBFLOW_AUTH"),
|
||||||
|
WEBFLOW_WEBHOOK_SECRET: requireEnv("WEBFLOW_WEBHOOK_SECRET")
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@ import {
|
|||||||
ProductSyncer,
|
ProductSyncer,
|
||||||
WebflowClient,
|
WebflowClient,
|
||||||
} from "@blade-and-brawn/commerce";
|
} from "@blade-and-brawn/commerce";
|
||||||
|
import { env } from "../env";
|
||||||
|
|
||||||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
@@ -26,15 +27,15 @@ const validateEquality = (wValue: any, pValue: any): Validation => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const printful = new PrintfulClient({
|
const printful = new PrintfulClient({
|
||||||
token: Bun.env.PRINTFUL_AUTH!,
|
token: env.PRINTFUL_AUTH,
|
||||||
storeId: Bun.env.PRINTFUL_STORE_ID!,
|
storeId: env.PRINTFUL_STORE_ID,
|
||||||
});
|
});
|
||||||
|
|
||||||
const webflow = new WebflowClient({
|
const webflow = new WebflowClient({
|
||||||
siteId: Bun.env.WEBFLOW_SITE_ID!,
|
siteId: env.WEBFLOW_SITE_ID,
|
||||||
collectionsId: Bun.env.WEBFLOW_COLLECTION_ID!,
|
collectionsId: env.WEBFLOW_COLLECTION_ID,
|
||||||
token: Bun.env.WEBFLOW_AUTH!,
|
token: env.WEBFLOW_AUTH,
|
||||||
webhookSecret: Bun.env.WEBFLOW_WEBHOOK_SECRET!,
|
webhookSecret: env.WEBFLOW_WEBHOOK_SECRET,
|
||||||
});
|
});
|
||||||
|
|
||||||
const syncer = new ProductSyncer(printful, webflow);
|
const syncer = new ProductSyncer(printful, webflow);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import {
|
|||||||
} from "@blade-and-brawn/commerce";
|
} from "@blade-and-brawn/commerce";
|
||||||
import zipcodesUs from "zipcodes-us";
|
import zipcodesUs from "zipcodes-us";
|
||||||
import z from "zod";
|
import z from "zod";
|
||||||
|
import { env } from "./env";
|
||||||
|
|
||||||
// SERVICES
|
// SERVICES
|
||||||
// -----------
|
// -----------
|
||||||
@@ -28,15 +29,15 @@ const levelCalculator = new LevelCalculator(
|
|||||||
);
|
);
|
||||||
|
|
||||||
const printful = new PrintfulClient({
|
const printful = new PrintfulClient({
|
||||||
token: Bun.env.PRINTFUL_AUTH!,
|
token: env.PRINTFUL_AUTH,
|
||||||
storeId: Bun.env.PRINTFUL_STORE_ID!,
|
storeId: env.PRINTFUL_STORE_ID,
|
||||||
});
|
});
|
||||||
|
|
||||||
const webflow = new WebflowClient({
|
const webflow = new WebflowClient({
|
||||||
siteId: Bun.env.WEBFLOW_SITE_ID!,
|
siteId: env.WEBFLOW_SITE_ID,
|
||||||
collectionsId: Bun.env.WEBFLOW_COLLECTION_ID!,
|
collectionsId: env.WEBFLOW_COLLECTION_ID,
|
||||||
token: Bun.env.WEBFLOW_AUTH!,
|
token: env.WEBFLOW_AUTH,
|
||||||
webhookSecret: Bun.env.WEBFLOW_WEBHOOK_SECRET!,
|
webhookSecret: env.WEBFLOW_WEBHOOK_SECRET,
|
||||||
});
|
});
|
||||||
|
|
||||||
const productSyncer = new ProductSyncer(printful, webflow);
|
const productSyncer = new ProductSyncer(printful, webflow);
|
||||||
|
|||||||
Reference in New Issue
Block a user