"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/webhooks/index.ts
var webhooks_exports = {};
__export(webhooks_exports, {
  WebhookPayloadSchema: () => WebhookPayloadSchema,
  parseWebhookPayload: () => parseWebhookPayload,
  verifyWebhookSignature: () => verifyWebhookSignature
});
module.exports = __toCommonJS(webhooks_exports);

// src/webhooks/verify.ts
var import_crypto = __toESM(require("crypto"));
var import_zod = require("zod");
var WebhookEventSchema = import_zod.z.enum([
  "page.published",
  "entry.published",
  "navigation.updated",
  "theme.updated",
  "site.settings_updated"
]);
var PagePublishedDataSchema = import_zod.z.object({
  pageId: import_zod.z.string(),
  path: import_zod.z.string(),
  slug: import_zod.z.string().optional()
});
var EntryPublishedDataSchema = import_zod.z.object({
  entryId: import_zod.z.string(),
  path: import_zod.z.string(),
  contentType: import_zod.z.string()
});
var NavigationUpdatedDataSchema = import_zod.z.object({
  menuId: import_zod.z.string().optional()
});
var EmptyDataSchema = import_zod.z.object({});
var WebhookDataSchema = import_zod.z.union([
  PagePublishedDataSchema,
  EntryPublishedDataSchema,
  NavigationUpdatedDataSchema,
  EmptyDataSchema
]);
var WebhookPayloadSchema = import_zod.z.object({
  /** Event type */
  event: WebhookEventSchema,
  /** ISO timestamp of when the event occurred */
  timestamp: import_zod.z.string(),
  /** Site ID that triggered the event */
  siteId: import_zod.z.string(),
  /** Event-specific data (shape depends on event type) */
  data: import_zod.z.record(import_zod.z.string(), import_zod.z.unknown()),
  /** Cache invalidation tags (for tag-based revalidation) */
  tags: import_zod.z.array(import_zod.z.string()).optional()
});
function verifyWebhookSignature(payload, signature, secret) {
  const expectedSignature = import_crypto.default.createHmac("sha256", secret).update(payload).digest("hex");
  if (signature.length !== expectedSignature.length) {
    return false;
  }
  return import_crypto.default.timingSafeEqual(
    Buffer.from(signature),
    Buffer.from(expectedSignature)
  );
}
function parseWebhookPayload(body) {
  let parsed;
  try {
    parsed = JSON.parse(body);
  } catch {
    return { success: false, error: "Invalid JSON" };
  }
  const result = WebhookPayloadSchema.safeParse(parsed);
  if (!result.success) {
    return { success: false, error: `Invalid payload: ${result.error.message}` };
  }
  return { success: true, payload: result.data };
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  WebhookPayloadSchema,
  parseWebhookPayload,
  verifyWebhookSignature
});
//# sourceMappingURL=webhooks.js.map