Improve printful secret hash
This commit is contained in:
@@ -21,8 +21,9 @@ function printError(err: unknown): never {
|
||||
try {
|
||||
console.log("Registering printful webhook...");
|
||||
const printful = new PrintfulClient({
|
||||
token: env.PRINTFUL_AUTH,
|
||||
storeId: env.PRINTFUL_STORE_ID,
|
||||
token: env.PRINTFUL_AUTH,
|
||||
webhookSecret: env.PRINTFUL_WEBHOOK_SECRET
|
||||
});
|
||||
|
||||
await printful.Webhooks.create(PRINTFUL_WEBHOOK_URL, [
|
||||
|
||||
@@ -27,8 +27,9 @@ const validateEquality = (wValue: any, pValue: any): Validation => {
|
||||
};
|
||||
|
||||
const printful = new PrintfulClient({
|
||||
token: env.PRINTFUL_AUTH,
|
||||
storeId: env.PRINTFUL_STORE_ID,
|
||||
token: env.PRINTFUL_AUTH,
|
||||
webhookSecret: env.PRINTFUL_WEBHOOK_SECRET
|
||||
});
|
||||
|
||||
const webflow = new WebflowClient({
|
||||
@@ -70,11 +71,6 @@ for (const wProduct of wProducts) {
|
||||
),
|
||||
];
|
||||
|
||||
// if (!validateEquality(sku.fieldData.name, pVariant.name).isValid) {
|
||||
// sku.fieldData.name = pVariant.name;
|
||||
// await webflow.Products.Skus.update(wProduct.product.id, sku.id, sku);
|
||||
// }
|
||||
|
||||
const errors = validations.filter((v) => !v.isValid);
|
||||
if (errors.length) {
|
||||
++invalidCount;
|
||||
|
||||
@@ -324,8 +324,8 @@ export const app = new Elysia()
|
||||
// WEBHOOKS
|
||||
.post("/webhooks/printful", async ({ body, query }) => {
|
||||
// https://webflow.com/integrations/printful
|
||||
const verified = crypto.timingSafeEqual(Buffer.from(query.secret, "hex"), Buffer.from(env.PRINTFUL_WEBHOOK_SECRET, "hex"));
|
||||
if (!verified) throw status(400, "Invalid secret");
|
||||
if (!s.Commerce.Printful.Util.verifySecret(query.secret))
|
||||
throw status(400, "Invalid secret");
|
||||
|
||||
const payload = body as Printful.Webhook.EventPayload;
|
||||
|
||||
@@ -379,7 +379,7 @@ export const app = new Elysia()
|
||||
}
|
||||
}, { query: t.Object({ secret: t.String() }) })
|
||||
.post("/webhooks/webflow", async ({ request, body }) => {
|
||||
if (!s.Commerce.Webflow.Util.verifyWebflowSignature(request, body))
|
||||
if (!s.Commerce.Webflow.Util.verifySecret(request, body))
|
||||
throw status(400, "Invalid signature");
|
||||
|
||||
const payload = body as Webflow.Webhook.EventPayload;
|
||||
|
||||
@@ -20,8 +20,9 @@ export const WOrderStatusSchema = t.Union([
|
||||
|
||||
export class CommerceService {
|
||||
readonly Printful = new PrintfulClient({
|
||||
token: env.PRINTFUL_AUTH,
|
||||
storeId: env.PRINTFUL_STORE_ID,
|
||||
token: env.PRINTFUL_AUTH,
|
||||
webhookSecret: env.PRINTFUL_WEBHOOK_SECRET
|
||||
});
|
||||
readonly Webflow = new WebflowClient({
|
||||
siteId: env.WEBFLOW_SITE_ID,
|
||||
|
||||
Reference in New Issue
Block a user