"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.webhookUninstall = void 0;

var _firebase = require("../helpers/firebase");

var _utils = require("../helpers/utils");

const webhookUninstall = async (req, res, config) => (0, _utils.handler)(_utils.verifyWebhook, async data => {
  const shop = data.get("x-shopify-shop-domain");
  const admin = await (0, _firebase.getFirebase)(config);

  try {
    await (0, _firebase.removeFirebaseShop)(config, admin, shop); // TODO removeShopifyWebhooks

    console.log(`Uninstalled ${shop}`);
    res.status(200).json({
      status: "success",
      body: `Uninstalled ${shop}`
    });
  } catch (err) {
    console.log(err.message);
    res.status(200).json({
      status: "error",
      body: err.message
    });
  }
})(req, res, config);

exports.webhookUninstall = webhookUninstall;
//# sourceMappingURL=uninstall.js.map