bundle-offers-app/app/routes/webhooks.compliance.tsx
metatroncubeswdev 365e45406a Bundle Offers Shopify app: discount function, admin, storefront, deploy stack
Rust discount function (one automatic discount evaluating all offers in priority
order, parity with the Odoo engine), React Router admin with Polaris, theme app
extension and app proxy pages, webhooks incl. GDPR, managed-pricing limits, and
a Docker Compose stack (Postgres + Caddy HTTPS) for a single VPS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 21:35:58 -04:00

28 lines
1.2 KiB
TypeScript

import type { ActionFunctionArgs } from "react-router";
import { authenticate } from "../shopify.server";
import db from "../db.server";
// Mandatory GDPR webhooks. Bundle Offers stores no customer personal data: only order ids, order names and
// amounts for analytics (no names, emails or addresses). customers/data_request and customers/redact have
// nothing to return or erase; shop/redact (48 h after uninstall) deletes everything about the shop.
export const action = async ({ request }: ActionFunctionArgs) => {
const { shop, topic } = await authenticate.webhook(request);
switch (topic) {
case "CUSTOMERS_DATA_REQUEST":
case "CUSTOMERS_REDACT":
break;
case "SHOP_REDACT": {
const row = await db.shop.findUnique({ where: { domain: shop }, select: { id: true } });
if (row) {
await db.orderStat.deleteMany({ where: { shopId: row.id } });
await db.shop.delete({ where: { id: row.id } }); // cascades to offers, usage and audit log
}
await db.session.deleteMany({ where: { shop } });
break;
}
default:
return new Response("Unhandled topic", { status: 404 });
}
return new Response();
};