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;AAAA,MACtB,oBAAsB,EAAA,IAAA;AAAA,MACtB,gBAAkB,EAAA,IAAA;AAAA,MAClB,eAAA,EAAiB,MAAO,CAAA,QAAA,EAAU,cAAkB,IAAA,cAAA;AAAA,MACpD,mBAAA,EACE,MAAO,CAAA,QAAA,EAAU,kBAAsB,IAAA,kBAAA;AAAA,MACzC,mBAAA,EACE,MAAO,CAAA,QAAA,EAAU,kBAAsB,IAAA,kBAAA;AAAA,MACzC,YAAA,EAAc,MAAO,CAAA,QAAA,EAAU,WAAe,IAAA;AAAA;AAChD,GACF;AACF","file":"index.mjs","sourcesContent":["// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\n\nexport function orySdkUrl() {\n  let baseUrl\n\n  if (process.env[\"NEXT_PUBLIC_ORY_SDK_URL\"]) {\n    baseUrl = process.env[\"NEXT_PUBLIC_ORY_SDK_URL\"]\n  }\n\n  if (!baseUrl) {\n    throw new Error(\n      \"You need to set environment variable `NEXT_PUBLIC_ORY_SDK_URL` to your Ory Network SDK URL.\",\n    )\n  }\n\n  return baseUrl.replace(/\\/$/, \"\")\n}\n\nexport function isProduction() {\n  return (\n    [\"production\", \"prod\"].indexOf(\n      process.env[\"VERCEL_ENV\"] || process.env[\"NODE_ENV\"] || \"\",\n    ) > -1\n  )\n}\n\nexport function guessPotentiallyProxiedOrySdkUrl(options?: {\n  knownProxiedUrl?: string\n}) {\n  if (isProduction()) {\n    // In production, we use the production custom domain\n    return orySdkUrl()\n  }\n\n  if (process.env[\"VERCEL_ENV\"]) {\n    // We are in vercel\n\n    // The domain name of the generated deployment URL. Example: *.vercel.app. The value does not include the protocol scheme https://.\n    //\n    // This is only available for preview deployments on Vercel.\n    if (!isProduction() && process.env[\"VERCEL_URL\"]) {\n      return `https://${process.env[\"VERCEL_URL\"]}`.replace(/\\/$/, \"\")\n    }\n\n    // This is sometimes set by the render server.\n    if (process.env[\"__NEXT_PRIVATE_ORIGIN\"]) {\n      return process.env[\"__NEXT_PRIVATE_ORIGIN\"].replace(/\\/$/, \"\")\n    }\n  }\n\n  // Unable to figure out the SDK URL. Either because we are not using Vercel or because we are on a local machine.\n  // Let's try to use the window location.\n  if (typeof window !== \"undefined\") {\n    return window.location.origin\n  }\n\n  if (options?.knownProxiedUrl) {\n    return options.knownProxiedUrl\n  }\n\n  // We tried everything. Let's use the SDK URL.\n  const final = orySdkUrl()\n  console.warn(\n    `Unable to determine a suitable SDK URL for setting up the Next.js integration of Ory Elements. Will proceed using default Ory SDK URL \"${final}\". This is likely not what you want for local development and your authentication and login may not work.`,\n  )\n\n  return final\n}\n","// Copyright © 2024 Ory Corp\n// SPDX-License-Identifier: Apache-2.0\nimport { OryConfig } from \"../types\"\nimport { isProduction } from \"./sdk\"\n\n/**\n * Enhances the Ory config with defaults and SDK URL. The SDK URL is determined as follows:\n *\n * 1. If `forceSdkUrl` is provided, it is used.\n * 2. If `forceSdkUrl` is not provided, the following environment variables are checked:\n *   - `NEXT_PUBLIC_ORY_SDK_URL`\n *   - `ORY_SDK_URL`\n *   - `__NEXT_PRIVATE_ORIGIN` (if not in production)\n *   - `VERCEL_URL` (if not in production)\n *   - `window.location.origin` (if not in production)\n *   - If none of the above are set, an error is thrown.\n *\n * @param config - The Ory config to enhance\n * @param forceSdkUrl - An optional URL to override the SDK URL. If not provided, the SDK URL is determined as described above.\n */\nexport function enhanceOryConfig(\n  config: Partial<OryConfig>,\n  forceSdkUrl?: string,\n) {\n  let sdkUrl =\n    forceSdkUrl ??\n    process.env[\"NEXT_PUBLIC_ORY_SDK_URL\"] ??\n    process.env[\"ORY_SDK_URL\"]\n\n  if (!forceSdkUrl && !isProduction()) {\n    if (process.env[\"__NEXT_PRIVATE_ORIGIN\"]) {\n      sdkUrl = process.env[\"__NEXT_PRIVATE_ORIGIN\"].replace(/\\/$/, \"\")\n    } else if (process.env[\"VERCEL_URL\"]) {\n      sdkUrl = `https://${process.env[\"VERCEL_URL\"]}`.replace(/\\/$/, \"\")\n    } else if (typeof window !== \"undefined\") {\n      sdkUrl = window.location.origin\n    }\n  }\n\n  if (!sdkUrl) {\n    throw new Error(\n      \"Unable to determine SDK URL. Please set NEXT_PUBLIC_ORY_SDK_URL and/or ORY_SDK_URL or force the SDK URL using `useOryConfig(config, 'https://my-ory-sdk-url.com')`.\",\n    )\n  }\n\n  return {\n    name: config.override?.applicationName ?? \"Default name\",\n    sdk: {\n      url: sdkUrl,\n    },\n    project: {\n      registration_enabled: true,\n      verification_enabled: true,\n      recovery_enabled: true,\n      recovery_ui_url: config.override?.recoveryUiPath ?? \"/ui/recovery\",\n      registration_ui_url:\n        config.override?.registrationUiPath ?? \"/ui/registration\",\n      verification_ui_url:\n        config.override?.verificationUiPath ?? \"/ui/verification\",\n      login_ui_url: config.override?.loginUiPath ?? \"/ui/login\",\n    },\n  }\n}\n"]}