19 lines
1.0 KiB
TypeScript
19 lines
1.0 KiB
TypeScript
import type { ActionFunctionArgs } from "react-router";
|
|
import { authenticate } from "../shopify.server";
|
|
import db from "../db.server";
|
|
import { forgetSubscriptions } from "../lib/partner.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 Offerlyst 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}`);
|
|
|
|
forgetSubscriptions();
|
|
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();
|
|
};
|