33fb9a8452
- Order confirmation, shipped, and cancelled email templates - Uses @react-email/components for professional HTML emails - Sends admin and customer notifications - Integrates with Resend for email delivery - Webhook handlers for ORDER_CREATED, ORDER_FULFILLED, ORDER_CANCELLED - Docker image optimized for production - Persistent auth data storage via PVC
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import { NextApiHandler } from "next";
|
|
import { ExtensionPOSTAttributes } from "@saleor/app-sdk/types";
|
|
import { verifyJWT } from "@saleor/app-sdk/auth";
|
|
import { createClient } from "@/lib/create-graphq-client";
|
|
import { ProductTimestampsDocument } from "../../../generated/graphql";
|
|
|
|
const handler: NextApiHandler = async (req, res) => {
|
|
const { appId, accessToken, saleorApiUrl, ...contextParams } =
|
|
req.body as ExtensionPOSTAttributes;
|
|
|
|
res.setHeader("Content-Type", "text/plain");
|
|
|
|
try {
|
|
await verifyJWT({
|
|
appId,
|
|
token: accessToken,
|
|
saleorApiUrl,
|
|
});
|
|
} catch (e) {
|
|
return res.status(401).send("Not authorized");
|
|
}
|
|
|
|
if (!contextParams.productId) {
|
|
return res.status(200).send("Missing product ID");
|
|
}
|
|
|
|
const client = createClient(saleorApiUrl, async () => ({ token: accessToken }));
|
|
const productTimestamps = await client.query(ProductTimestampsDocument, {
|
|
id: contextParams.productId,
|
|
});
|
|
|
|
if (productTimestamps.data?.product) {
|
|
return res
|
|
.status(200)
|
|
.send(
|
|
`This product was created at ${productTimestamps.data.product.created} and last updated at ${productTimestamps.data.product.updatedAt}`
|
|
);
|
|
}
|
|
};
|
|
|
|
export default handler;
|