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ACf,IAAA,OAAO;AAAA,MACL,OAAA,EAAS,KAAA;AAAA,MACT,GAAA,EAAK,WAAA;AAAA,MACL,KAAA,EAAO;AAAA,KACT;AAAA,EACF;AACF;AAQO,IAAM,wBAAA,GAA2B,CAAC,WAAA,KAA8C;AACrF,EAAA,MAAM,iBAAA,GAAoB,OAAA,CAAQ,GAAA,CAAI,wBAAA,EAA0B,MAAK,IAAK,EAAA;AAC1E,EAAA,MAAM,cAAA,GAAiB,iBAAA,CACpB,KAAA,CAAM,GAAG,CAAA,CACT,GAAA,CAAI,CAAA,CAAA,KAAK,CAAA,CAAE,IAAA,EAAM,CAAA,CACjB,MAAA,CAAO,OAAO,CAAA;AAEjB,EAAA,OAAO,iBAAA,CAAkB;AAAA,IACvB,WAAA;AAAA,IACA,cAAA;AAAA,IACA,iBAAiB,OAAA,CAAQ,GAAA,CAAI,QAAA,KAAa,YAAA,IAAgB,eAAe,MAAA,KAAW;AAAA,GACrF,CAAA;AACH","file":"index.mjs","sourcesContent":["interface VerifyManifestOptions {\n  /**\n   * The URL of the manifest to verify\n   */\n  manifestUrl: string;\n  \n  /**\n   * List of allowed domains (without protocol)\n   * If empty or contains \"*\", all domains are allowed\n   */\n  allowedDomains?: string[];\n  \n  /**\n   * Whether to allow all domains (overrides allowedDomains if true)\n   * @default process.env.NODE_ENV !== \"production\"\n   */\n  allowAllDomains?: boolean;\n}\n\ninterface VerifyManifestResult {\n  /**\n   * Whether the manifest URL is allowed\n   */\n  allowed: boolean;\n  \n  /**\n   * The normalized manifest URL\n   */\n  url: string;\n  \n  /**\n   * Error message if verification failed\n   */\n  error?: string;\n}\n\n/**\n * Verifies if a manifest URL is allowed based on domain restrictions\n * @param options Verification options\n * @returns Verification result\n */\nexport const verifyManifestUrl = (\n  options: VerifyManifestOptions\n): VerifyManifestResult => {\n  const { manifestUrl, allowedDomains = [], allowAllDomains = process.env.NODE_ENV !== \"production\" } = options;\n  \n  if (!manifestUrl) {\n    return {\n      allowed: false,\n      url: \"\",\n      error: \"URL is required\"\n    };\n  }\n\n  try {\n    const url = new URL(manifestUrl);\n    \n    // In development or if no domains are specified, allow all\n    const isAllowed = allowAllDomains || \n      allowedDomains.length === 0 ||\n      allowedDomains.includes(\"*\") ||\n      allowedDomains.some(domain => {\n        try {\n          const domainUrl = domain.startsWith(\"http\") \n            ? new URL(domain) \n            : new URL(`https://${ domain }`);\n          return url.hostname === domainUrl.hostname;\n        } catch {\n          return false;\n        }\n      });\n    \n    if (!isAllowed) {\n      return {\n        allowed: false,\n        url: manifestUrl,\n        error: \"Domain not allowed\"\n      };\n    }\n    \n    return {\n      allowed: true,\n      url: manifestUrl\n    };\n    \n  } catch (_error) {\n    return {\n      allowed: false,\n      url: manifestUrl,\n      error: \"Invalid URL\"\n    };\n  }\n}\n\n/**\n * Verifies a manifest URL from environment configuration\n * Uses MANIFEST_ALLOWED_DOMAINS environment variable for domain restrictions\n * @param manifestUrl The manifest URL to verify\n * @returns Verification result\n */\nexport const verifyManifestUrlFromEnv = (manifestUrl: string): VerifyManifestResult => {\n  const allowedDomainsRaw = process.env.MANIFEST_ALLOWED_DOMAINS?.trim() || \"\";\n  const allowedDomains = allowedDomainsRaw\n    .split(\",\")\n    .map(d => d.trim())\n    .filter(Boolean);\n    \n  return verifyManifestUrl({\n    manifestUrl,\n    allowedDomains,\n    allowAllDomains: process.env.NODE_ENV !== \"production\" || allowedDomains.length === 0\n  });\n}\n"]}