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);
var ogTagPreview_exports = {};
__export(ogTagPreview_exports, {
  ogTagPreview: () => ogTagPreview
});
module.exports = __toCommonJS(ogTagPreview_exports);
var import_open_graph_scraper = __toESM(require("open-graph-scraper"));
var import_graphql_server = require("@cedarjs/graphql-server");
var import_og = require("../../lib/og/og");
var import_project = require("../../util/project");
const fetchWithTiming = async (url, headers) => {
  const start = performance.now();
  try {
    const response = await fetch(url, headers);
    const executionTime = performance.now();
    const clone = response.clone();
    const content = await clone.blob();
    const responseTime = performance.now();
    const html = await response.text();
    const size = content.size;
    const metrics = {
      startTime: start,
      executionTime: executionTime - start,
      responseTime: responseTime - start,
      responseSize: size
    };
    return {
      html,
      metrics
    };
  } catch (error) {
    console.error("Fetch error:", error);
    throw error;
  }
};
const ogTagPreview = async ({
  url,
  customUserAgent
}) => {
  customUserAgent ??= "Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; Googlebot/2.1; +http://www.google.com/bot.html) Chrome/W.X.Y.Z Safari/537.36";
  const config = await (0, import_project.getUserProjectConfig)();
  if (!config.experimental?.streamingSsr?.enabled) {
    throw new import_graphql_server.SyntaxError("SSR is not enabled");
  }
  try {
    const {
      html,
      metrics
    } = await fetchWithTiming(url, {
      headers: {
        "User-Agent": customUserAgent
      }
    });
    const customResult = await (0, import_open_graph_scraper.default)({
      html
    });
    const {
      result,
      error
    } = customResult;
    const {
      audits,
      auditedResult
    } = (0, import_og.auditor)(result, error);
    return {
      id: url,
      userAgent: customUserAgent,
      error,
      result: auditedResult,
      audits,
      metrics
    };
  } catch {
    throw new import_graphql_server.SyntaxError(`Unable to preview ${url} with user agent ${customUserAgent}`);
  }
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  ogTagPreview
});
//# sourceMappingURL=ogTagPreview.js.map
