bundle-offers-app/app/routes/webhooks.app.uninstalled.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

17 lines
970 B
TypeScript

import type { ActionFunctionArgs } from "react-router";
import { authenticate } from "../shopify.server";
import db from "../db.server";
// The access token is already revoked here, so the app can't call the Admin API. Shopify removes the app's
// functions with the app, so the automatic discount stops applying, and it deletes app-owned ($app and
// app-data) metafields. We mark the shop and keep its data for 48 h, until shop/redact deletes it.
// The in-app "Remove all Bundle Offers data" action (Settings) deletes the discount explicitly.
export const action = async ({ request }: ActionFunctionArgs) => {
const { shop, session, topic } = await authenticate.webhook(request);
console.log(`Received ${topic} webhook for ${shop}`);
await db.shop.updateMany({ where: { domain: shop }, data: { uninstalledAt: new Date(), discountNodeId: null, nextSyncAt: null } });
if (session) await db.session.deleteMany({ where: { shop } });
return new Response();
};